- Timestamp:
- May 24, 2004, 10:47:03 AM (21 years ago)
- Location:
- trunk/src/shell32
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shell32/systray.c
r10507 r10604 1 1 /* 2 * 2 * Systray 3 3 * 4 * Copyright 1999 Kai Morich<kai.morich@bigfoot.de>4 * Copyright 1999 Kai Morich <kai.morich@bigfoot.de> 5 5 * 6 6 * Manage the systray window. That it actually appears in the docking 7 7 * area of KDE or GNOME is delegated to windows/x11drv/wnd.c, 8 8 * X11DRV_WND_DockWindow. 9 * 10 * Modified by ErOs2 for usage with systray_os2.c 9 11 * 10 12 */ … … 24 26 #include "heap.h" 25 27 #include "config.h" 28 #include "winuser32.h" 26 29 27 30 DEFAULT_DEBUG_CHANNEL(shell); 31 32 28 33 29 34 typedef struct SystrayItem { … … 37 42 static int firstSystray=TRUE; /* defer creation of window class until first systray item is created */ 38 43 39 static BOOL SYSTRAY_Delete(PNOTIFYICONDATAA pnid); 40 41 42 #define ICON_SIZE GetSystemMetrics(SM_CXSMICON) 43 /* space around icon (forces icon to center of KDE systray area) */ 44 #define ICON_BORDER 4 45 44 BOOL SYSTRAY_ItemInit(SystrayItem *ptrayItem); 45 void SYSTRAY_ItemTerm(SystrayItem *ptrayItem); 46 void SYSTRAY_ItemSetMessage(SystrayItem *ptrayItem, ULONG uCallbackMessage); 47 void SYSTRAY_ItemSetIcon(SystrayItem *ptrayItem, HICON hIcon); 48 void SYSTRAY_ItemSetTip(SystrayItem *ptrayItem, CHAR* szTip, int modify); 46 49 47 50 … … 51 54 if (pnid1->uID != pnid2->uID) return FALSE; 52 55 return TRUE; 53 }54 55 static LRESULT CALLBACK SYSTRAY_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)56 {57 HDC hdc;58 PAINTSTRUCT ps;59 60 switch (message) {61 case WM_PAINT:62 {63 RECT rc;64 SystrayItem *ptrayItem = systray;65 66 while (ptrayItem) {67 if (ptrayItem->hWnd==hWnd) {68 if (ptrayItem->notifyIcon.hIcon) {69 hdc = BeginPaint(hWnd, &ps);70 GetClientRect(hWnd, &rc);71 if (!DrawIconEx(hdc, rc.left+ICON_BORDER, rc.top+ICON_BORDER, ptrayItem->notifyIcon.hIcon,72 ICON_SIZE, ICON_SIZE, 0, 0, DI_DEFAULTSIZE|DI_NORMAL)) {73 ERR("Paint(SystrayWindow 0x%08x) failed -> removing SystrayItem %p\n", hWnd, ptrayItem);74 SYSTRAY_Delete(&ptrayItem->notifyIcon);75 }76 }77 break;78 }79 ptrayItem = ptrayItem->nextTrayItem;80 }81 EndPaint(hWnd, &ps);82 }83 break;84 85 case WM_MOUSEMOVE:86 case WM_LBUTTONDOWN:87 case WM_LBUTTONUP:88 case WM_RBUTTONDOWN:89 case WM_RBUTTONUP:90 case WM_MBUTTONDOWN:91 case WM_MBUTTONUP:92 {93 MSG msg;94 SystrayItem *ptrayItem = systray;95 96 while ( ptrayItem ) {97 if (ptrayItem->hWnd == hWnd) {98 msg.hwnd=hWnd;99 msg.message=message;100 msg.wParam=wParam;101 msg.lParam=lParam;102 msg.time = GetMessageTime ();103 msg.pt.x = LOWORD(GetMessagePos ());104 msg.pt.y = HIWORD(GetMessagePos ());105 106 SendMessageA(ptrayItem->hWndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);107 }108 ptrayItem = ptrayItem->nextTrayItem;109 }110 }111 /* fall through */112 113 case WM_LBUTTONDBLCLK:114 case WM_RBUTTONDBLCLK:115 case WM_MBUTTONDBLCLK:116 {117 SystrayItem *ptrayItem = systray;118 119 while (ptrayItem) {120 if (ptrayItem->hWnd == hWnd) {121 if (ptrayItem->notifyIcon.hWnd && ptrayItem->notifyIcon.uCallbackMessage) {122 if (!PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,123 (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)message)) {124 ERR("PostMessage(SystrayWindow 0x%08x) failed -> removing SystrayItem %p\n", hWnd, ptrayItem);125 SYSTRAY_Delete(&ptrayItem->notifyIcon);126 }127 }128 break;129 }130 ptrayItem = ptrayItem->nextTrayItem;131 }132 }133 break;134 135 default:136 return (DefWindowProcA(hWnd, message, wParam, lParam));137 }138 return (0);139 140 }141 142 143 BOOL SYSTRAY_RegisterClass(void)144 {145 WNDCLASSA wc;146 147 wc.style = CS_SAVEBITS;148 wc.lpfnWndProc = (WNDPROC)SYSTRAY_WndProc;149 wc.cbClsExtra = 0;150 wc.cbWndExtra = 0;151 wc.hInstance = 0;152 wc.hIcon = 0;153 wc.hCursor = LoadCursorA(0, IDC_ARROWA);154 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);155 wc.lpszMenuName = NULL;156 wc.lpszClassName = "WineSystray";157 158 if (!RegisterClassA(&wc)) {159 ERR("RegisterClass(WineSystray) failed\n");160 return FALSE;161 }162 return TRUE;163 }164 165 166 BOOL SYSTRAY_ItemInit(SystrayItem *ptrayItem)167 {168 RECT rect;169 170 /* Register the class if this is our first tray item. */171 if ( firstSystray ) {172 firstSystray = FALSE;173 if ( !SYSTRAY_RegisterClass() ) {174 ERR( "RegisterClass(WineSystray) failed\n" );175 return FALSE;176 }177 }178 #ifdef __WIN32OS2__179 //SvL: Disabled system tray for now180 // Integrate with OS/2 WPS (WarpCenter tray?)181 dprintf(("WARNING: SHELL32: SYSTRAY_ItemInit: ignored"));182 return FALSE;183 #else184 185 /* Initialize the window size. */186 rect.left = 0;187 rect.top = 0;188 rect.right = ICON_SIZE+2*ICON_BORDER;189 rect.bottom = ICON_SIZE+2*ICON_BORDER;190 191 ZeroMemory( ptrayItem, sizeof(SystrayItem) );192 /* Create tray window for icon. */193 ptrayItem->hWnd = CreateWindowExA( WS_EX_TRAYWINDOW,194 "WineSystray", "Wine-Systray",195 WS_VISIBLE,196 CW_USEDEFAULT, CW_USEDEFAULT,197 rect.right-rect.left, rect.bottom-rect.top,198 0, 0, 0, 0 );199 if ( !ptrayItem->hWnd ) {200 ERR( "CreateWindow(WineSystray) failed\n" );201 return FALSE;202 }203 204 /* Create tooltip for icon. */205 ptrayItem->hWndToolTip = CreateWindowA( TOOLTIPS_CLASSA,NULL,TTS_ALWAYSTIP,206 CW_USEDEFAULT, CW_USEDEFAULT,207 CW_USEDEFAULT, CW_USEDEFAULT,208 ptrayItem->hWnd, 0, 0, 0 );209 if ( !ptrayItem->hWndToolTip ) {210 ERR( "CreateWindow(TOOLTIP) failed\n" );211 return FALSE;212 }213 return TRUE;214 #endif215 }216 217 218 static void SYSTRAY_ItemTerm(SystrayItem *ptrayItem)219 {220 if(ptrayItem->notifyIcon.hIcon)221 DestroyIcon(ptrayItem->notifyIcon.hIcon);222 if(ptrayItem->hWndToolTip)223 DestroyWindow(ptrayItem->hWndToolTip);224 if(ptrayItem->hWnd)225 DestroyWindow(ptrayItem->hWnd);226 return;227 }228 229 230 void SYSTRAY_ItemSetMessage(SystrayItem *ptrayItem, UINT uCallbackMessage)231 {232 ptrayItem->notifyIcon.uCallbackMessage = uCallbackMessage;233 }234 235 236 void SYSTRAY_ItemSetIcon(SystrayItem *ptrayItem, HICON hIcon)237 {238 ptrayItem->notifyIcon.hIcon = CopyIcon(hIcon);239 InvalidateRect(ptrayItem->hWnd, NULL, TRUE);240 }241 242 243 void SYSTRAY_ItemSetTip(SystrayItem *ptrayItem, CHAR* szTip, int modify)244 {245 TTTOOLINFOA ti;246 247 strncpy(ptrayItem->notifyIcon.szTip, szTip, sizeof(ptrayItem->notifyIcon.szTip));248 ptrayItem->notifyIcon.szTip[sizeof(ptrayItem->notifyIcon.szTip)-1]=0;249 250 ti.cbSize = sizeof(TTTOOLINFOA);251 ti.uFlags = 0;252 ti.hwnd = ptrayItem->hWnd;253 ti.hinst = 0;254 ti.uId = 0;255 ti.lpszText = ptrayItem->notifyIcon.szTip;256 ti.rect.left = 0;257 ti.rect.top = 0;258 ti.rect.right = ICON_SIZE+2*ICON_BORDER;259 ti.rect.bottom = ICON_SIZE+2*ICON_BORDER;260 261 if(modify)262 SendMessageA(ptrayItem->hWndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);263 else264 SendMessageA(ptrayItem->hWndToolTip, TTM_ADDTOOLA, 0, (LPARAM)&ti);265 56 } 266 57 … … 283 74 (*ptrayItem)->notifyIcon.uID = pnid->uID; /* only needed for callback message */ 284 75 (*ptrayItem)->notifyIcon.hWnd = pnid->hWnd; /* only needed for callback message */ 285 SYSTRAY_ItemSetIcon (*ptrayItem, (pnid->uFlags&NIF_ICON) ? pnid->hIcon:0);76 SYSTRAY_ItemSetIcon (*ptrayItem, (pnid->uFlags&NIF_ICON) ?GetOS2Icon(pnid->hIcon) :0); 286 77 SYSTRAY_ItemSetMessage(*ptrayItem, (pnid->uFlags&NIF_MESSAGE)?pnid->uCallbackMessage:0); 287 78 SYSTRAY_ItemSetTip (*ptrayItem, (pnid->uFlags&NIF_TIP) ?pnid->szTip :"", FALSE); 288 79 289 TRACE("%p: 0x%08x %s\n", (*ptrayItem), (*ptrayItem)->notifyIcon.hWnd, 290 (*ptrayItem)->notifyIcon.szTip); 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 ); 291 83 return TRUE; 292 84 } … … 300 92 if ( SYSTRAY_ItemIsEqual(pnid, &ptrayItem->notifyIcon) ) { 301 93 if (pnid->uFlags & NIF_ICON) 302 SYSTRAY_ItemSetIcon(ptrayItem, pnid->hIcon);94 SYSTRAY_ItemSetIcon(ptrayItem, GetOS2Icon(pnid->hIcon) ); 303 95 if (pnid->uFlags & NIF_MESSAGE) 304 96 SYSTRAY_ItemSetMessage(ptrayItem, pnid->uCallbackMessage); … … 306 98 SYSTRAY_ItemSetTip(ptrayItem, pnid->szTip, TRUE); 307 99 308 TRACE(" %p: 0x%08x %s\n", ptrayItem, ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.szTip);100 TRACE("SYSTRAY_Modify %p: 0x%08x %s\n", ptrayItem, ptrayItem->notifyIcon.hWnd, pnid->szTip); 309 101 return TRUE; 310 102 } … … 345 137 346 138 /************************************************************************* 347 * Shell_NotifyIconA 139 * Shell_NotifyIconA [SHELL32.297][SHELL32.296] 348 140 */ 349 141 BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid ) 350 142 { 351 #ifdef __WIN32OS2__352 //SvL: Disabled system tray for now353 // Integrate with OS/2 WPS (WarpCenter tray?)354 dprintf(("Shell_NotifyIconA %x: ignored", dwMessage));355 return TRUE;356 #else357 143 BOOL flag=FALSE; 358 144 TRACE("enter %d %d %ld\n", pnid->hWnd, pnid->uID, dwMessage); … … 370 156 TRACE("leave %d %d %ld=%d\n", pnid->hWnd, pnid->uID, dwMessage, flag); 371 157 return flag; 372 #endif373 158 } 374 159 375 160 /************************************************************************* 376 * Shell_NotifyIconW 161 * Shell_NotifyIconW [SHELL32.298] 377 162 */ 378 163 BOOL WINAPI Shell_NotifyIconW (DWORD dwMessage, PNOTIFYICONDATAW pnid ) 379 164 { 380 165 BOOL ret; 381 166 382 383 167 PNOTIFYICONDATAA p = HeapAlloc(GetProcessHeap(),0,sizeof(NOTIFYICONDATAA)); 168 memcpy(p, pnid, sizeof(NOTIFYICONDATAA)); 384 169 WideCharToMultiByte( CP_ACP, 0, pnid->szTip, -1, p->szTip, sizeof(p->szTip), NULL, NULL ); 385 170 p->szTip[sizeof(p->szTip)-1] = 0; 386 171 387 172 ret = Shell_NotifyIconA(dwMessage, p ); 388 173 389 390 174 HeapFree(GetProcessHeap(),0,p); 175 return ret; 391 176 } 177 178 179 #ifdef __WIN32OS2__ 180 181 BOOL 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 191 BOOL DoWin32CharToOem(const char *s, char *t) 192 { 193 return CharToOemA( s , t ); 194 } 195 196 #endif
Note:
See TracChangeset
for help on using the changeset viewer.