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>
|
---|
12 |
|
---|
13 | #include <string.h>
|
---|
14 |
|
---|
15 | #include <odin.h>
|
---|
16 | #include <winconst.h>
|
---|
17 |
|
---|
18 | #include "systray_os2.h"
|
---|
19 |
|
---|
20 | #define WM_TRAYADDME (WM_USER+1)
|
---|
21 | #define WM_TRAYDELME (WM_USER+2)
|
---|
22 | #define WM_TRAYICON (WM_USER+3)
|
---|
23 | #define WM_TRAYEXIT (0xCD20)
|
---|
24 |
|
---|
25 | #define SZAPP "SystrayServer"
|
---|
26 | #define SZTOPIC "TRAY"
|
---|
27 |
|
---|
28 | static HWND hwndTrayServer = 0;
|
---|
29 |
|
---|
30 | static MRESULT EXPENTRY SYSTRAY_Old_WndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
31 | {
|
---|
32 | SystrayItem *ptrayItem = (SystrayItem *)WinQueryWindowULong(hWnd, QWL_USER);
|
---|
33 |
|
---|
34 | switch ( msg )
|
---|
35 | {
|
---|
36 | case WM_CREATE:
|
---|
37 | WinSetWindowULong(hWnd, QWL_USER, (ULONG)mp1);
|
---|
38 | ptrayItem = (SystrayItem *)mp1;
|
---|
39 | return (MRESULT)FALSE;
|
---|
40 | case WM_DDE_INITIATEACK:
|
---|
41 | hwndTrayServer = (HWND)mp1;
|
---|
42 | if(hwndTrayServer)
|
---|
43 | WinPostMsg(hwndTrayServer,WM_TRAYADDME,(MPARAM)hWnd,(MPARAM)NULL);
|
---|
44 | return (MRESULT)TRUE;
|
---|
45 | case WM_BUTTON1DBLCLK|0x2000:
|
---|
46 | DoWin32PostMessage(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
47 | (MPARAM)ptrayItem->notifyIcon.uID, (MPARAM)WM_LBUTTONDBLCLK_W);
|
---|
48 | return (MRESULT)FALSE;
|
---|
49 | case WM_BUTTON2DBLCLK|0x2000:
|
---|
50 | DoWin32PostMessage(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
51 | (MPARAM)ptrayItem->notifyIcon.uID, (MPARAM)WM_RBUTTONDBLCLK_W);
|
---|
52 | return (MRESULT)FALSE;
|
---|
53 | case WM_BUTTON3DBLCLK|0x2000:
|
---|
54 | DoWin32PostMessage(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
55 | (MPARAM)ptrayItem->notifyIcon.uID, (MPARAM)WM_MBUTTONDBLCLK_W);
|
---|
56 | return (MRESULT)FALSE;
|
---|
57 | case WM_BUTTON1UP|0x2000:
|
---|
58 | DoWin32PostMessage(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
59 | (MPARAM)ptrayItem->notifyIcon.uID, (MPARAM)WM_LBUTTONUP_W);
|
---|
60 | return (MRESULT)FALSE;
|
---|
61 | case WM_BUTTON2UP|0x2000:
|
---|
62 | DoWin32PostMessage(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
63 | (MPARAM)ptrayItem->notifyIcon.uID, (MPARAM)WM_RBUTTONUP_W);
|
---|
64 | return (MRESULT)FALSE;
|
---|
65 | case WM_BUTTON3UP|0x2000:
|
---|
66 | DoWin32PostMessage(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
67 | (MPARAM)ptrayItem->notifyIcon.uID, (MPARAM)WM_MBUTTONUP_W);
|
---|
68 | return (MRESULT)FALSE;
|
---|
69 | case WM_BUTTON1DOWN|0x2000:
|
---|
70 | DoWin32PostMessage(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
71 | (MPARAM)ptrayItem->notifyIcon.uID, (MPARAM)WM_LBUTTONDOWN_W);
|
---|
72 | return (MRESULT)FALSE;
|
---|
73 | case WM_BUTTON2DOWN|0x2000:
|
---|
74 | DoWin32PostMessage(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
75 | (MPARAM)ptrayItem->notifyIcon.uID, (MPARAM)WM_RBUTTONDOWN_W);
|
---|
76 | return (MRESULT)FALSE;
|
---|
77 | case WM_BUTTON3DOWN|0x2000:
|
---|
78 | DoWin32PostMessage(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
79 | (MPARAM)ptrayItem->notifyIcon.uID, (MPARAM)WM_MBUTTONDOWN_W);
|
---|
80 | return (MRESULT)FALSE;
|
---|
81 | }
|
---|
82 | return WinDefWindowProc( hWnd , msg , mp1 , mp2 );
|
---|
83 | }
|
---|
84 |
|
---|
85 | static const char * const systraysupclass = "Odin32SystraySupport";
|
---|
86 |
|
---|
87 | static BOOL SYSTRAY_Old_RegisterClass(void)
|
---|
88 | {
|
---|
89 | //WinRegisterClass( hab, systraysupclass, SYSTRAY_Old_WndProc, 0, sizeof(ULONG) );
|
---|
90 | WinRegisterClass(0, systraysupclass, SYSTRAY_Old_WndProc, 0, sizeof(ULONG) );
|
---|
91 | return TRUE;
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | static BOOL SYSTRAY_Old_ItemInit(SystrayItem *ptrayItem)
|
---|
96 | {
|
---|
97 | ULONG fcf = FCF_TITLEBAR;
|
---|
98 |
|
---|
99 | if ( !SYSTRAY_Old_RegisterClass() )
|
---|
100 | {
|
---|
101 | return FALSE;
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | memset( ptrayItem, 0, sizeof(SystrayItem) );
|
---|
106 | ptrayItem->hWndFrame = WinCreateStdWindow( HWND_DESKTOP, 0, &fcf, NULL,
|
---|
107 | "", 0, NULLHANDLE, 0, NULL );
|
---|
108 | if ( !ptrayItem->hWndFrame ) {
|
---|
109 | return FALSE;
|
---|
110 | }
|
---|
111 | ptrayItem->hWndClient = WinCreateWindow(ptrayItem->hWndFrame, systraysupclass, "",
|
---|
112 | 0, 0, 0, 0, 0, ptrayItem->hWndFrame,
|
---|
113 | HWND_TOP, FID_CLIENT, ptrayItem, NULL );
|
---|
114 | if ( !ptrayItem->hWndClient ) {
|
---|
115 | return FALSE;
|
---|
116 | }
|
---|
117 |
|
---|
118 | WinDdeInitiate(ptrayItem->hWndClient,SZAPP,SZTOPIC,NULL);
|
---|
119 | if (hwndTrayServer)
|
---|
120 | WinPostMsg(hwndTrayServer,WM_TRAYICON,(MPARAM)ptrayItem->hWndClient,(MPARAM)NULL);
|
---|
121 |
|
---|
122 | return (hwndTrayServer!=NULLHANDLE);
|
---|
123 | }
|
---|
124 |
|
---|
125 | static 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 |
|
---|
134 |
|
---|
135 | static void SYSTRAY_Old_ItemSetMessage(SystrayItem *ptrayItem, ULONG uCallbackMessage)
|
---|
136 | {
|
---|
137 | ptrayItem->notifyIcon.uCallbackMessage = uCallbackMessage;
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|
141 | static void SYSTRAY_Old_ItemSetIcon(SystrayItem *ptrayItem, HPOINTER hIcon)
|
---|
142 | {
|
---|
143 | // Windows seems to make a copy of icons displayed in the tray area. At
|
---|
144 | // least, calling DestroyIcon() after passing the icon handle to
|
---|
145 | // Shell_NotifyIcon() doesn't harm the icon displayed in the tray. Behave
|
---|
146 | // similarly on OS/2 (some applications do call DestroyIcon()). The copy is
|
---|
147 | // deleted in SYSTRAY_Old_ItemTerm().
|
---|
148 |
|
---|
149 | POINTERINFO Info;
|
---|
150 | HPOINTER hIcon2 = NULLHANDLE;
|
---|
151 | APIRET arc;
|
---|
152 | arc = WinQueryPointerInfo(hIcon, &Info);
|
---|
153 | if (!arc)
|
---|
154 | return;
|
---|
155 | hIcon2 = WinCreatePointerIndirect(HWND_DESKTOP, &Info);
|
---|
156 | if (hIcon2 == NULLHANDLE)
|
---|
157 | return;
|
---|
158 | hIcon = hIcon2;
|
---|
159 |
|
---|
160 | WinSendMsg( ptrayItem->hWndFrame, WM_SETICON, MPFROMLONG( hIcon ), MPVOID );
|
---|
161 | if (hwndTrayServer)
|
---|
162 | WinPostMsg(hwndTrayServer,WM_TRAYICON,(MPARAM)ptrayItem->hWndClient,(MPARAM)NULL);
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | static void SYSTRAY_Old_ItemSetTip(SystrayItem *ptrayItem, CHAR* szTip, int modify)
|
---|
167 | {
|
---|
168 | char tmp[ 64 ];
|
---|
169 | strncpy(ptrayItem->notifyIcon.szTip, szTip, 64 );
|
---|
170 | ptrayItem->notifyIcon.szTip[ 63 ] = 0;
|
---|
171 | DoWin32CharToOem( ptrayItem->notifyIcon.szTip, tmp );
|
---|
172 | WinSetWindowText( ptrayItem->hWndFrame, tmp );
|
---|
173 | if (hwndTrayServer)
|
---|
174 | WinPostMsg(hwndTrayServer,WM_TRAYICON,(MPARAM)ptrayItem->hWndClient,(MPARAM)NULL);
|
---|
175 | }
|
---|
176 |
|
---|
177 |
|
---|
178 | BOOL SYSTRAY_Init(void)
|
---|
179 | {
|
---|
180 | // try the new xsystray API first
|
---|
181 | if (SYSTRAY_Ex_Init())
|
---|
182 | return TRUE;
|
---|
183 |
|
---|
184 | // fallback to the old API
|
---|
185 | SYSTRAY_ItemInit = SYSTRAY_Old_ItemInit;
|
---|
186 | SYSTRAY_ItemTerm = SYSTRAY_Old_ItemTerm;
|
---|
187 | SYSTRAY_ItemSetMessage = SYSTRAY_Old_ItemSetMessage;
|
---|
188 | SYSTRAY_ItemSetIcon = SYSTRAY_Old_ItemSetIcon;
|
---|
189 | SYSTRAY_ItemSetTip = SYSTRAY_Old_ItemSetTip;
|
---|
190 |
|
---|
191 | return TRUE;
|
---|
192 | }
|
---|
193 |
|
---|