source: trunk/src/shell32/systray_os2.c@ 22015

Last change on this file since 22015 was 21602, checked in by dmik, 14 years ago

shell32: systray: Added support for the "TaskbarCreated" system notificaiton message that Windows broadcasts to all top-level windows when the taskbar (xcenter in case of OS/2) is (re)started. This allows applications supporting this message (including Java applications) recreate their taskbar icons.

File size: 6.5 KB
Line 
1/*
2 * OS/2 System Tray support. For usage with SysTray/WPS by MadInt
3 * or System Tray widget for XCenter/eCenter.
4 *
5 * author: ErOs2
6 * date: 1 May 2004
7 *
8 */
9
10#define INCL_WIN
11#include <os2wrap.h> // Odin32 OS/2 api wrappers
12
13#include <win32api.h>
14
15#include <string.h>
16
17#include "systray_os2.h"
18
19#define WM_TRAYADDME (WM_USER+1)
20#define WM_TRAYDELME (WM_USER+2)
21#define WM_TRAYICON (WM_USER+3)
22#define WM_TRAYEXIT (0xCD20)
23
24#define SZAPP "SystrayServer"
25#define SZTOPIC "TRAY"
26
27static HWND hwndTrayServer = 0;
28
29static MRESULT EXPENTRY SYSTRAY_Old_WndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
30{
31 SystrayItem *ptrayItem = (SystrayItem *)WinQueryWindowULong(hWnd, QWL_USER);
32
33 switch ( msg )
34 {
35 case WM_CREATE:
36 WinSetWindowULong(hWnd, QWL_USER, (ULONG)mp1);
37 ptrayItem = (SystrayItem *)mp1;
38 return (MRESULT)FALSE;
39 case WM_DDE_INITIATEACK:
40 hwndTrayServer = (HWND)mp1;
41 if(hwndTrayServer)
42 WinPostMsg(hwndTrayServer,WM_TRAYADDME,(MPARAM)hWnd,(MPARAM)NULL);
43 return (MRESULT)TRUE;
44 case WM_BUTTON1DBLCLK|0x2000:
45 PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
46 (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_LBUTTONDBLCLK_W);
47 return (MRESULT)FALSE;
48 case WM_BUTTON2DBLCLK|0x2000:
49 PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
50 (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_RBUTTONDBLCLK_W);
51 return (MRESULT)FALSE;
52 case WM_BUTTON3DBLCLK|0x2000:
53 PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
54 (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_MBUTTONDBLCLK_W);
55 return (MRESULT)FALSE;
56 case WM_BUTTON1UP|0x2000:
57 PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
58 (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_LBUTTONUP_W);
59 return (MRESULT)FALSE;
60 case WM_BUTTON2UP|0x2000:
61 PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
62 (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_RBUTTONUP_W);
63 return (MRESULT)FALSE;
64 case WM_BUTTON3UP|0x2000:
65 PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
66 (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_MBUTTONUP_W);
67 return (MRESULT)FALSE;
68 case WM_BUTTON1DOWN|0x2000:
69 PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
70 (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_LBUTTONDOWN_W);
71 return (MRESULT)FALSE;
72 case WM_BUTTON2DOWN|0x2000:
73 PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
74 (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_RBUTTONDOWN_W);
75 return (MRESULT)FALSE;
76 case WM_BUTTON3DOWN|0x2000:
77 PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
78 (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_MBUTTONDOWN_W);
79 return (MRESULT)FALSE;
80 }
81 return WinDefWindowProc( hWnd , msg , mp1 , mp2 );
82}
83
84static const char * const systraysupclass = "Odin32SystraySupport";
85
86static BOOL SYSTRAY_Old_RegisterClass(void)
87{
88 //WinRegisterClass( hab, systraysupclass, SYSTRAY_Old_WndProc, 0, sizeof(ULONG) );
89 WinRegisterClass(0, systraysupclass, SYSTRAY_Old_WndProc, 0, sizeof(ULONG) );
90 return TRUE;
91}
92
93
94static BOOL SYSTRAY_Old_ItemInit(SystrayItem *ptrayItem)
95{
96 ULONG fcf = FCF_TITLEBAR;
97
98 if (!SYSTRAY_Old_RegisterClass())
99 {
100 return FALSE;
101 }
102
103 ptrayItem->hWndFrame = WinCreateStdWindow(HWND_DESKTOP, 0, &fcf, NULL,
104 "", 0, NULLHANDLE, 0, NULL);
105 if (!ptrayItem->hWndFrame)
106 {
107 return FALSE;
108 }
109 ptrayItem->hWndClient = WinCreateWindow(ptrayItem->hWndFrame, systraysupclass, "",
110 0, 0, 0, 0, 0, ptrayItem->hWndFrame,
111 HWND_TOP, FID_CLIENT, ptrayItem, NULL);
112 if (!ptrayItem->hWndClient)
113 {
114 return FALSE;
115 }
116
117 WinDdeInitiate(ptrayItem->hWndClient, SZAPP, SZTOPIC, NULL);
118 if (hwndTrayServer)
119 WinPostMsg(hwndTrayServer, WM_TRAYICON,
120 (MPARAM)ptrayItem->hWndClient, (MPARAM)NULL);
121
122 return (hwndTrayServer != NULLHANDLE);
123}
124
125static void SYSTRAY_Old_ItemTerm(SystrayItem *ptrayItem)
126{
127 HPOINTER hIcon = (HPOINTER)WinSendMsg(ptrayItem->hWndFrame, WM_QUERYICON, NULL, NULL);
128 if (hIcon != NULLHANDLE)
129 WinDestroyPointer(hIcon);
130
131 WinDestroyWindow(ptrayItem->hWndFrame);
132}
133
134static void SYSTRAY_Old_ItemUpdate(SystrayItem *ptrayItem, ULONG uFlags)
135{
136 // uFlags = 0 means it's the first time, add everything
137
138 if (uFlags == 0 || (uFlags & NIF_ICON))
139 {
140 // Windows seems to make a copy of icons displayed in the tray area. At
141 // least, calling DestroyIcon() after passing the icon handle to
142 // Shell_NotifyIcon() doesn't harm the icon displayed in the tray.
143 // Behave similarly on OS/2 (some applications do call DestroyIcon()).
144 // The copy is deleted in SYSTRAY_Old_ItemTerm().
145
146 POINTERINFO Info;
147 HPOINTER hIcon = NULLHANDLE;
148 BOOL brc;
149 brc = WinQueryPointerInfo(ptrayItem->notifyIcon.hIcon, &Info);
150 if (brc)
151 {
152 hIcon = WinCreatePointerIndirect(HWND_DESKTOP, &Info);
153 if (hIcon != NULLHANDLE)
154 {
155 WinSendMsg(ptrayItem->hWndFrame, WM_SETICON,
156 MPFROMLONG(hIcon), MPVOID);
157 if (hwndTrayServer)
158 WinPostMsg(hwndTrayServer, WM_TRAYICON,
159 (MPARAM)ptrayItem->hWndClient, (MPARAM)NULL);
160 }
161 }
162 }
163 if (uFlags == 0 || (uFlags & NIF_TIP))
164 {
165 WinSetWindowText(ptrayItem->hWndFrame, ptrayItem->notifyIcon.szTip);
166 if (hwndTrayServer)
167 WinPostMsg(hwndTrayServer, WM_TRAYICON,
168 (MPARAM)ptrayItem->hWndClient, (MPARAM)NULL);
169 }
170}
171
172BOOL SYSTRAY_Init(void)
173{
174 // try the new xsystray API first
175 if (SYSTRAY_Ex_Init())
176 return TRUE;
177
178 // fallback to the old API
179 SYSTRAY_ItemInit = SYSTRAY_Old_ItemInit;
180 SYSTRAY_ItemTerm = SYSTRAY_Old_ItemTerm;
181 SYSTRAY_ItemUpdate = SYSTRAY_Old_ItemUpdate;
182
183 return TRUE;
184}
185
Note: See TracBrowser for help on using the repository browser.