source: trunk/src/shell32/systray.c@ 10604

Last change on this file since 10604 was 10604, checked in by sandervl, 21 years ago

ER: OS2 Systray implementation

File size: 5.4 KB
Line 
1/*
2 * Systray
3 *
4 * Copyright 1999 Kai Morich <kai.morich@bigfoot.de>
5 *
6 * Manage the systray window. That it actually appears in the docking
7 * area of KDE or GNOME is delegated to windows/x11drv/wnd.c,
8 * X11DRV_WND_DockWindow.
9 *
10 * Modified by ErOs2 for usage with systray_os2.c
11 *
12 */
13
14#ifndef __WIN32OS2__
15#include <unistd.h>
16#endif
17#include <stdlib.h>
18#include <string.h>
19
20#include "winnls.h"
21#include "shlobj.h"
22#include "shellapi.h"
23#include "shell32_main.h"
24#include "commctrl.h"
25#include "debugtools.h"
26#include "heap.h"
27#include "config.h"
28#include "winuser32.h"
29
30DEFAULT_DEBUG_CHANNEL(shell);
31
32
33
34typedef struct SystrayItem {
35 HWND hWnd;
36 HWND hWndToolTip;
37 NOTIFYICONDATAA notifyIcon;
38 struct SystrayItem *nextTrayItem;
39} SystrayItem;
40
41static SystrayItem *systray=NULL;
42static int firstSystray=TRUE; /* defer creation of window class until first systray item is created */
43
44BOOL SYSTRAY_ItemInit(SystrayItem *ptrayItem);
45void SYSTRAY_ItemTerm(SystrayItem *ptrayItem);
46void SYSTRAY_ItemSetMessage(SystrayItem *ptrayItem, ULONG uCallbackMessage);
47void SYSTRAY_ItemSetIcon(SystrayItem *ptrayItem, HICON hIcon);
48void SYSTRAY_ItemSetTip(SystrayItem *ptrayItem, CHAR* szTip, int modify);
49
50
51static BOOL SYSTRAY_ItemIsEqual(PNOTIFYICONDATAA pnid1, PNOTIFYICONDATAA pnid2)
52{
53 if (pnid1->hWnd != pnid2->hWnd) return FALSE;
54 if (pnid1->uID != pnid2->uID) return FALSE;
55 return TRUE;
56}
57
58
59static BOOL SYSTRAY_Add(PNOTIFYICONDATAA pnid)
60{
61 SystrayItem **ptrayItem = &systray;
62
63 /* Find last element. */
64 while( *ptrayItem ) {
65 if ( SYSTRAY_ItemIsEqual(pnid, &(*ptrayItem)->notifyIcon) )
66 return FALSE;
67 ptrayItem = &((*ptrayItem)->nextTrayItem);
68 }
69 /* Allocate SystrayItem for element and add to end of list. */
70 (*ptrayItem) = ( SystrayItem *)malloc( sizeof(SystrayItem) );
71
72 /* Initialize and set data for the tray element. */
73 SYSTRAY_ItemInit( (*ptrayItem) );
74 (*ptrayItem)->notifyIcon.uID = pnid->uID; /* only needed for callback message */
75 (*ptrayItem)->notifyIcon.hWnd = pnid->hWnd; /* only needed for callback message */
76 SYSTRAY_ItemSetIcon (*ptrayItem, (pnid->uFlags&NIF_ICON) ?GetOS2Icon(pnid->hIcon) :0);
77 SYSTRAY_ItemSetMessage(*ptrayItem, (pnid->uFlags&NIF_MESSAGE)?pnid->uCallbackMessage:0);
78 SYSTRAY_ItemSetTip (*ptrayItem, (pnid->uFlags&NIF_TIP) ?pnid->szTip :"", FALSE);
79
80 TRACE("SYSTRAY_Add %p: 0x%08x 0x%08x 0x%08x %s\n", (*ptrayItem), (*ptrayItem)->notifyIcon.hWnd,
81 pnid->uCallbackMessage, (*ptrayItem)->notifyIcon.uCallbackMessage,
82 pnid->szTip );
83 return TRUE;
84}
85
86
87static BOOL SYSTRAY_Modify(PNOTIFYICONDATAA pnid)
88{
89 SystrayItem *ptrayItem = systray;
90
91 while ( ptrayItem ) {
92 if ( SYSTRAY_ItemIsEqual(pnid, &ptrayItem->notifyIcon) ) {
93 if (pnid->uFlags & NIF_ICON)
94 SYSTRAY_ItemSetIcon(ptrayItem, GetOS2Icon(pnid->hIcon) );
95 if (pnid->uFlags & NIF_MESSAGE)
96 SYSTRAY_ItemSetMessage(ptrayItem, pnid->uCallbackMessage);
97 if (pnid->uFlags & NIF_TIP)
98 SYSTRAY_ItemSetTip(ptrayItem, pnid->szTip, TRUE);
99
100 TRACE("SYSTRAY_Modify %p: 0x%08x %s\n", ptrayItem, ptrayItem->notifyIcon.hWnd, pnid->szTip);
101 return TRUE;
102 }
103 ptrayItem = ptrayItem->nextTrayItem;
104 }
105 return FALSE; /* not found */
106}
107
108
109static BOOL SYSTRAY_Delete(PNOTIFYICONDATAA pnid)
110{
111 SystrayItem **ptrayItem = &systray;
112
113 while (*ptrayItem) {
114 if (SYSTRAY_ItemIsEqual(pnid, &(*ptrayItem)->notifyIcon)) {
115 SystrayItem *next = (*ptrayItem)->nextTrayItem;
116 TRACE("%p: 0x%08x %s\n", *ptrayItem, (*ptrayItem)->notifyIcon.hWnd, (*ptrayItem)->notifyIcon.szTip);
117 SYSTRAY_ItemTerm(*ptrayItem);
118
119 free(*ptrayItem);
120 *ptrayItem = next;
121
122 return TRUE;
123 }
124 ptrayItem = &((*ptrayItem)->nextTrayItem);
125 }
126
127 return FALSE; /* not found */
128}
129
130/*************************************************************************
131 *
132 */
133BOOL SYSTRAY_Init(void)
134{
135 return TRUE;
136}
137
138/*************************************************************************
139 * Shell_NotifyIconA [SHELL32.297][SHELL32.296]
140 */
141BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid )
142{
143 BOOL flag=FALSE;
144 TRACE("enter %d %d %ld\n", pnid->hWnd, pnid->uID, dwMessage);
145 switch(dwMessage) {
146 case NIM_ADD:
147 flag = SYSTRAY_Add(pnid);
148 break;
149 case NIM_MODIFY:
150 flag = SYSTRAY_Modify(pnid);
151 break;
152 case NIM_DELETE:
153 flag = SYSTRAY_Delete(pnid);
154 break;
155 }
156 TRACE("leave %d %d %ld=%d\n", pnid->hWnd, pnid->uID, dwMessage, flag);
157 return flag;
158}
159
160/*************************************************************************
161 * Shell_NotifyIconW [SHELL32.298]
162 */
163BOOL WINAPI Shell_NotifyIconW (DWORD dwMessage, PNOTIFYICONDATAW pnid )
164{
165 BOOL ret;
166
167 PNOTIFYICONDATAA p = HeapAlloc(GetProcessHeap(),0,sizeof(NOTIFYICONDATAA));
168 memcpy(p, pnid, sizeof(NOTIFYICONDATAA));
169 WideCharToMultiByte( CP_ACP, 0, pnid->szTip, -1, p->szTip, sizeof(p->szTip), NULL, NULL );
170 p->szTip[sizeof(p->szTip)-1] = 0;
171
172 ret = Shell_NotifyIconA(dwMessage, p );
173
174 HeapFree(GetProcessHeap(),0,p);
175 return ret;
176}
177
178
179#ifdef __WIN32OS2__
180
181BOOL DoWin32PostMessage(HWND w, ULONG m, WPARAM mp1, LPARAM mp2 )
182{
183 TRACE("DoWin32WinPostMsg: HWND 0x%08x MSG 0x%08x ID 0x%08x MMSG 0x%08x\n", w, m, mp1, mp2);
184 if ( w && m )
185 {
186 return PostMessageA( w, m, mp1, mp2 );
187 }
188 return FALSE;
189}
190
191BOOL DoWin32CharToOem(const char *s, char *t)
192{
193 return CharToOemA( s , t );
194}
195
196#endif
Note: See TracBrowser for help on using the repository browser.