[10604] | 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
|
---|
[21602] | 11 | #include <os2wrap.h> // Odin32 OS/2 api wrappers
|
---|
[10604] | 12 |
|
---|
[21602] | 13 | #include <win32api.h>
|
---|
| 14 |
|
---|
[10604] | 15 | #include <string.h>
|
---|
| 16 |
|
---|
[21591] | 17 | #include "systray_os2.h"
|
---|
[10604] | 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 |
|
---|
| 27 | static HWND hwndTrayServer = 0;
|
---|
| 28 |
|
---|
[21591] | 29 | static MRESULT EXPENTRY SYSTRAY_Old_WndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
[10604] | 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:
|
---|
[21602] | 45 | PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
| 46 | (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_LBUTTONDBLCLK_W);
|
---|
[10604] | 47 | return (MRESULT)FALSE;
|
---|
| 48 | case WM_BUTTON2DBLCLK|0x2000:
|
---|
[21602] | 49 | PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
| 50 | (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_RBUTTONDBLCLK_W);
|
---|
[10604] | 51 | return (MRESULT)FALSE;
|
---|
| 52 | case WM_BUTTON3DBLCLK|0x2000:
|
---|
[21602] | 53 | PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
| 54 | (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_MBUTTONDBLCLK_W);
|
---|
[10604] | 55 | return (MRESULT)FALSE;
|
---|
| 56 | case WM_BUTTON1UP|0x2000:
|
---|
[21602] | 57 | PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
| 58 | (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_LBUTTONUP_W);
|
---|
[10604] | 59 | return (MRESULT)FALSE;
|
---|
| 60 | case WM_BUTTON2UP|0x2000:
|
---|
[21602] | 61 | PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
| 62 | (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_RBUTTONUP_W);
|
---|
[10604] | 63 | return (MRESULT)FALSE;
|
---|
| 64 | case WM_BUTTON3UP|0x2000:
|
---|
[21602] | 65 | PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
| 66 | (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_MBUTTONUP_W);
|
---|
[10604] | 67 | return (MRESULT)FALSE;
|
---|
| 68 | case WM_BUTTON1DOWN|0x2000:
|
---|
[21602] | 69 | PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
| 70 | (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_LBUTTONDOWN_W);
|
---|
[10604] | 71 | return (MRESULT)FALSE;
|
---|
| 72 | case WM_BUTTON2DOWN|0x2000:
|
---|
[21602] | 73 | PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
| 74 | (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_RBUTTONDOWN_W);
|
---|
[10604] | 75 | return (MRESULT)FALSE;
|
---|
| 76 | case WM_BUTTON3DOWN|0x2000:
|
---|
[21602] | 77 | PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
---|
| 78 | (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)WM_MBUTTONDOWN_W);
|
---|
[10604] | 79 | return (MRESULT)FALSE;
|
---|
| 80 | }
|
---|
| 81 | return WinDefWindowProc( hWnd , msg , mp1 , mp2 );
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[21591] | 84 | static const char * const systraysupclass = "Odin32SystraySupport";
|
---|
[10604] | 85 |
|
---|
[21591] | 86 | static BOOL SYSTRAY_Old_RegisterClass(void)
|
---|
[10604] | 87 | {
|
---|
[21591] | 88 | //WinRegisterClass( hab, systraysupclass, SYSTRAY_Old_WndProc, 0, sizeof(ULONG) );
|
---|
| 89 | WinRegisterClass(0, systraysupclass, SYSTRAY_Old_WndProc, 0, sizeof(ULONG) );
|
---|
[10604] | 90 | return TRUE;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 |
|
---|
[21591] | 94 | static BOOL SYSTRAY_Old_ItemInit(SystrayItem *ptrayItem)
|
---|
[10604] | 95 | {
|
---|
| 96 | ULONG fcf = FCF_TITLEBAR;
|
---|
| 97 |
|
---|
[21592] | 98 | if (!SYSTRAY_Old_RegisterClass())
|
---|
[10604] | 99 | {
|
---|
| 100 | return FALSE;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[21592] | 103 | ptrayItem->hWndFrame = WinCreateStdWindow(HWND_DESKTOP, 0, &fcf, NULL,
|
---|
| 104 | "", 0, NULLHANDLE, 0, NULL);
|
---|
| 105 | if (!ptrayItem->hWndFrame)
|
---|
| 106 | {
|
---|
[10604] | 107 | return FALSE;
|
---|
| 108 | }
|
---|
| 109 | ptrayItem->hWndClient = WinCreateWindow(ptrayItem->hWndFrame, systraysupclass, "",
|
---|
| 110 | 0, 0, 0, 0, 0, ptrayItem->hWndFrame,
|
---|
[21592] | 111 | HWND_TOP, FID_CLIENT, ptrayItem, NULL);
|
---|
| 112 | if (!ptrayItem->hWndClient)
|
---|
| 113 | {
|
---|
[10604] | 114 | return FALSE;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[21592] | 117 | WinDdeInitiate(ptrayItem->hWndClient, SZAPP, SZTOPIC, NULL);
|
---|
[10604] | 118 | if (hwndTrayServer)
|
---|
[21592] | 119 | WinPostMsg(hwndTrayServer, WM_TRAYICON,
|
---|
| 120 | (MPARAM)ptrayItem->hWndClient, (MPARAM)NULL);
|
---|
[10604] | 121 |
|
---|
[21592] | 122 | return (hwndTrayServer != NULLHANDLE);
|
---|
[10604] | 123 | }
|
---|
| 124 |
|
---|
[21591] | 125 | static void SYSTRAY_Old_ItemTerm(SystrayItem *ptrayItem)
|
---|
[10604] | 126 | {
|
---|
[21590] | 127 | HPOINTER hIcon = (HPOINTER)WinSendMsg(ptrayItem->hWndFrame, WM_QUERYICON, NULL, NULL);
|
---|
| 128 | if (hIcon != NULLHANDLE)
|
---|
| 129 | WinDestroyPointer(hIcon);
|
---|
| 130 |
|
---|
[10604] | 131 | WinDestroyWindow(ptrayItem->hWndFrame);
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[21592] | 134 | static void SYSTRAY_Old_ItemUpdate(SystrayItem *ptrayItem, ULONG uFlags)
|
---|
[10604] | 135 | {
|
---|
[21592] | 136 | // uFlags = 0 means it's the first time, add everything
|
---|
[10604] | 137 |
|
---|
[21592] | 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().
|
---|
[10604] | 145 |
|
---|
[21592] | 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 | }
|
---|
[10604] | 170 | }
|
---|
| 171 |
|
---|
[21591] | 172 | BOOL 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;
|
---|
[21592] | 181 | SYSTRAY_ItemUpdate = SYSTRAY_Old_ItemUpdate;
|
---|
[21591] | 182 |
|
---|
| 183 | return TRUE;
|
---|
| 184 | }
|
---|
| 185 |
|
---|