Maintain OS/2 version a little after all the recent changes:
[privoxy.git] / w32taskbar.c
1 const char w32taskbar_rcs[] = "$Id: w32taskbar.c,v 1.3 2001/05/22 18:56:28 oes Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/w32taskbar.c,v $
5  *
6  * Purpose     :  Functions for creating, setting and destroying the
7  *                workspace tray icon
8  *
9  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
10  *                IJBSWA team.  http://ijbswa.sourceforge.net
11  *
12  *                Written by and Copyright (C) 1999 Adam Lock
13  *                <locka@iol.ie>
14  *
15  *                This program is free software; you can redistribute it 
16  *                and/or modify it under the terms of the GNU General
17  *                Public License as published by the Free Software
18  *                Foundation; either version 2 of the License, or (at
19  *                your option) any later version.
20  *
21  *                This program is distributed in the hope that it will
22  *                be useful, but WITHOUT ANY WARRANTY; without even the
23  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
24  *                PARTICULAR PURPOSE.  See the GNU General Public
25  *                License for more details.
26  *
27  *                The GNU General Public License should be included with
28  *                this file.  If not, you can view it at
29  *                http://www.gnu.org/copyleft/gpl.html
30  *                or write to the Free Software Foundation, Inc., 59
31  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
32  *
33  * Revisions   :
34  *    $Log: w32taskbar.c,v $
35  *    Revision 1.3  2001/05/22 18:56:28  oes
36  *    CRLF -> LF
37  *
38  *    Revision 1.2  2001/05/20 15:07:54  jongfoster
39  *    File is now ignored if _WIN_CONSOLE is defined.
40  *
41  *    Revision 1.1.1.1  2001/05/15 13:59:08  oes
42  *    Initial import of version 2.9.3 source tree
43  *
44  *
45  *********************************************************************/
46 \f
47
48 #include "config.h"
49
50 #include <stdio.h>
51
52 #include <windows.h>
53
54 #include "w32taskbar.h"
55 #include "w32res.h"
56 #include "w32log.h"
57
58 const char w32taskbar_h_rcs[] = W32TASKBAR_H_VERSION;
59
60 #ifndef _WIN_CONSOLE /* entire file */
61
62 #define WM_TRAYMSG WM_USER+1
63
64 static HMENU g_hmenuTray;
65 static HWND g_hwndTrayX;
66
67 static LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
68
69
70 /*********************************************************************
71  *
72  * Function    :  CreateTrayWindow
73  *
74  * Description :  Creates and returns the invisible window responsible for processing tray messages.
75  *
76  * Parameters  :
77  *          1  :  hInstance = instance handle of this application
78  *
79  * Returns     :  Handle of the systray window.
80  *
81  *********************************************************************/
82 HWND CreateTrayWindow(HINSTANCE hInstance)
83 {
84    WNDCLASS wc;
85    static const char *szWndName = "JunkbusterTrayWindow";
86
87    wc.style          = 0;
88    wc.lpfnWndProc    = TrayProc;
89    wc.cbClsExtra     = 0;
90    wc.cbWndExtra     = 0;
91    wc.hInstance      = hInstance;
92    wc.hIcon          = 0;
93    wc.hCursor        = 0;
94    wc.hbrBackground  = 0;
95    wc.lpszMenuName   = 0;
96    wc.lpszClassName  = szWndName;
97
98    RegisterClass(&wc);
99
100    g_hwndTrayX = CreateWindow(szWndName, szWndName,
101       WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
102       CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
103
104    ShowWindow(g_hwndTrayX, SW_HIDE);
105    UpdateWindow(g_hwndTrayX);
106
107    g_hmenuTray = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
108
109    return g_hwndTrayX;
110
111 }
112
113
114 /*********************************************************************
115  *
116  * Function    :  TraySetIcon
117  *
118  * Description :  Sets the tray icon to the specified shape.
119  *
120  * Parameters  :
121  *          1  :  hwnd = handle of the systray window
122  *          2  :  uID = user message number to notify systray window
123  *          3  :  hicon = set the current icon to this handle
124  *
125  * Returns     :  Same value as `Shell_NotifyIcon'.
126  *
127  *********************************************************************/
128 BOOL TraySetIcon(HWND hwnd, UINT uID, HICON hicon)
129 {
130    NOTIFYICONDATA nid;
131
132    memset(&nid, 0, sizeof(nid));
133
134    nid.cbSize = sizeof(nid);
135    nid.hWnd = hwnd;
136    nid.uID = uID;
137    nid.uFlags = NIF_ICON;
138    nid.uCallbackMessage = 0;
139    nid.hIcon = hicon;
140
141    return( Shell_NotifyIcon(NIM_MODIFY, &nid) );
142
143 }
144
145
146 /*********************************************************************
147  *
148  * Function    :  TrayAddIcon
149  *
150  * Description :  Adds a tray icon.
151  *
152  * Parameters  :
153  *          1  :  hwnd = handle of the systray window
154  *          2  :  uID = user message number to notify systray window
155  *          3  :  hicon = handle of icon to add to systray window
156  *          4  :  pszToolTip = tool tip when mouse hovers over systray window
157  *
158  * Returns     :  Same as `Shell_NotifyIcon'.
159  *
160  *********************************************************************/
161 BOOL TrayAddIcon(HWND hwnd, UINT uID, HICON hicon, const char *pszToolTip)
162 {
163    NOTIFYICONDATA nid;
164
165    memset(&nid, 0, sizeof(nid));
166
167    nid.cbSize = sizeof(nid);
168    nid.hWnd = hwnd;
169    nid.uID = uID;
170    nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
171    nid.uCallbackMessage = WM_TRAYMSG;
172    nid.hIcon = hicon;
173
174    if (pszToolTip)
175    {
176       strcpy(nid.szTip, pszToolTip);
177    }
178
179    return( Shell_NotifyIcon(NIM_ADD, &nid) );
180
181 }
182
183
184 /*********************************************************************
185  *
186  * Function    :  TrayDeleteIcon
187  *
188  * Description :  Deletes a tray icon.
189  *
190  * Parameters  :
191  *          1  :  hwnd = handle of the systray window
192  *          2  :  uID = user message number to notify systray window
193  *
194  * Returns     :  Same as `Shell_NotifyIcon'.
195  *
196  *********************************************************************/
197 BOOL TrayDeleteIcon(HWND hwnd, UINT uID)
198 {
199    NOTIFYICONDATA nid;
200
201    memset(&nid, 0, sizeof(nid));
202
203    nid.cbSize = sizeof(nid);
204    nid.hWnd = hwnd;
205    nid.uID = uID;
206
207    return( Shell_NotifyIcon(NIM_DELETE, &nid) );
208
209 }
210
211
212 /*********************************************************************
213  *
214  * Function    :  TrayProc
215  *
216  * Description :  Call back procedure processes tray messages.
217  *
218  * Parameters  :
219  *          1  :  hwnd = handle of the systray window
220  *          2  :  msg = message number
221  *          3  :  wParam = first param for this message
222  *          4  :  lParam = next param for this message
223  *
224  * Returns     :  Appropriate M$ window message handler codes.
225  *
226  *********************************************************************/
227 LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
228 {
229    switch (msg)
230    {
231       case WM_CREATE:
232          return 0;
233
234       case WM_CLOSE:
235          PostQuitMessage(0);
236          return 0;
237
238       case WM_TRAYMSG:
239       {
240          /* UINT uID = (UINT) wParam; */
241          UINT uMouseMsg = (UINT) lParam;
242
243          if (uMouseMsg == WM_RBUTTONDOWN)
244          {
245             POINT pt;
246             HMENU hmenu = GetSubMenu(g_hmenuTray,0);
247             GetCursorPos(&pt);
248             SetForegroundWindow(g_hwndLogFrame);
249             TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y, 0, g_hwndLogFrame, NULL);
250             PostMessage(g_hwndLogFrame, WM_NULL, 0, 0 ) ;
251          }
252          else if (uMouseMsg == WM_LBUTTONDBLCLK)
253          {
254             ShowLogWindow(TRUE);
255          }
256       }
257       return 0;
258
259       default:
260          /* DO NOTHING */
261          break;
262    }
263
264    return DefWindowProc(hwnd, msg, wParam, lParam);
265
266 }
267
268
269 #endif /* ndef _WIN_CONSOLE - entire file */
270
271 /*
272   Local Variables:
273   tab-width: 3
274   end:
275 */