Added user-manual option (FIXME: Needs comment)
[privoxy.git] / w32taskbar.c
1 const char w32taskbar_rcs[] = "$Id: w32taskbar.c,v 1.6 2002/03/26 22:57:10 jongfoster 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-2002 members of
10  *                the Privoxy team.  http://www.privoxy.org/
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.6  2002/03/26 22:57:10  jongfoster
36  *    Web server name should begin www.
37  *
38  *    Revision 1.5  2002/03/24 12:03:47  jongfoster
39  *    Name change
40  *
41  *    Revision 1.4  2001/11/16 00:46:31  jongfoster
42  *    Fixing compiler warnings
43  *
44  *    Revision 1.3  2001/05/22 18:56:28  oes
45  *    CRLF -> LF
46  *
47  *    Revision 1.2  2001/05/20 15:07:54  jongfoster
48  *    File is now ignored if _WIN_CONSOLE is defined.
49  *
50  *    Revision 1.1.1.1  2001/05/15 13:59:08  oes
51  *    Initial import of version 2.9.3 source tree
52  *
53  *
54  *********************************************************************/
55 \f
56
57 #include "config.h"
58
59 #include <stdio.h>
60
61 #ifndef STRICT
62 #define STRICT
63 #endif
64 #include <windows.h>
65
66 #include "w32taskbar.h"
67 #include "w32res.h"
68 #include "w32log.h"
69
70 const char w32taskbar_h_rcs[] = W32TASKBAR_H_VERSION;
71
72 #ifndef _WIN_CONSOLE /* entire file */
73
74 #define WM_TRAYMSG WM_USER+1
75
76 static HMENU g_hmenuTray;
77 static HWND g_hwndTrayX;
78
79 static LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
80
81
82 /*********************************************************************
83  *
84  * Function    :  CreateTrayWindow
85  *
86  * Description :  Creates and returns the invisible window responsible
87  *                for processing tray messages.
88  *
89  * Parameters  :
90  *          1  :  hInstance = instance handle of this application
91  *
92  * Returns     :  Handle of the systray window.
93  *
94  *********************************************************************/
95 HWND CreateTrayWindow(HINSTANCE hInstance)
96 {
97    WNDCLASS wc;
98    static const char *szWndName = "PrivoxyTrayWindow";
99
100    wc.style          = 0;
101    wc.lpfnWndProc    = TrayProc;
102    wc.cbClsExtra     = 0;
103    wc.cbWndExtra     = 0;
104    wc.hInstance      = hInstance;
105    wc.hIcon          = 0;
106    wc.hCursor        = 0;
107    wc.hbrBackground  = 0;
108    wc.lpszMenuName   = 0;
109    wc.lpszClassName  = szWndName;
110
111    RegisterClass(&wc);
112
113    g_hwndTrayX = CreateWindow(szWndName, szWndName,
114       WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
115       CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
116
117    ShowWindow(g_hwndTrayX, SW_HIDE);
118    UpdateWindow(g_hwndTrayX);
119
120    g_hmenuTray = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
121
122    return g_hwndTrayX;
123
124 }
125
126
127 /*********************************************************************
128  *
129  * Function    :  TraySetIcon
130  *
131  * Description :  Sets the tray icon to the specified shape.
132  *
133  * Parameters  :
134  *          1  :  hwnd = handle of the systray window
135  *          2  :  uID = user message number to notify systray window
136  *          3  :  hicon = set the current icon to this handle
137  *
138  * Returns     :  Same value as `Shell_NotifyIcon'.
139  *
140  *********************************************************************/
141 BOOL TraySetIcon(HWND hwnd, UINT uID, HICON hicon)
142 {
143    NOTIFYICONDATA nid;
144
145    memset(&nid, 0, sizeof(nid));
146
147    nid.cbSize = sizeof(nid);
148    nid.hWnd = hwnd;
149    nid.uID = uID;
150    nid.uFlags = NIF_ICON;
151    nid.uCallbackMessage = 0;
152    nid.hIcon = hicon;
153
154    return( Shell_NotifyIcon(NIM_MODIFY, &nid) );
155
156 }
157
158
159 /*********************************************************************
160  *
161  * Function    :  TrayAddIcon
162  *
163  * Description :  Adds a tray icon.
164  *
165  * Parameters  :
166  *          1  :  hwnd = handle of the systray window
167  *          2  :  uID = user message number to notify systray window
168  *          3  :  hicon = handle of icon to add to systray window
169  *          4  :  pszToolTip = tool tip when mouse hovers over systray window
170  *
171  * Returns     :  Same as `Shell_NotifyIcon'.
172  *
173  *********************************************************************/
174 BOOL TrayAddIcon(HWND hwnd, UINT uID, HICON hicon, const char *pszToolTip)
175 {
176    NOTIFYICONDATA nid;
177
178    memset(&nid, 0, sizeof(nid));
179
180    nid.cbSize = sizeof(nid);
181    nid.hWnd = hwnd;
182    nid.uID = uID;
183    nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
184    nid.uCallbackMessage = WM_TRAYMSG;
185    nid.hIcon = hicon;
186
187    if (pszToolTip)
188    {
189       strcpy(nid.szTip, pszToolTip);
190    }
191
192    return( Shell_NotifyIcon(NIM_ADD, &nid) );
193
194 }
195
196
197 /*********************************************************************
198  *
199  * Function    :  TrayDeleteIcon
200  *
201  * Description :  Deletes a tray icon.
202  *
203  * Parameters  :
204  *          1  :  hwnd = handle of the systray window
205  *          2  :  uID = user message number to notify systray window
206  *
207  * Returns     :  Same as `Shell_NotifyIcon'.
208  *
209  *********************************************************************/
210 BOOL TrayDeleteIcon(HWND hwnd, UINT uID)
211 {
212    NOTIFYICONDATA nid;
213
214    memset(&nid, 0, sizeof(nid));
215
216    nid.cbSize = sizeof(nid);
217    nid.hWnd = hwnd;
218    nid.uID = uID;
219
220    return( Shell_NotifyIcon(NIM_DELETE, &nid) );
221
222 }
223
224
225 /*********************************************************************
226  *
227  * Function    :  TrayProc
228  *
229  * Description :  Call back procedure processes tray messages.
230  *
231  * Parameters  :
232  *          1  :  hwnd = handle of the systray window
233  *          2  :  msg = message number
234  *          3  :  wParam = first param for this message
235  *          4  :  lParam = next param for this message
236  *
237  * Returns     :  Appropriate M$ window message handler codes.
238  *
239  *********************************************************************/
240 LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
241 {
242    switch (msg)
243    {
244       case WM_CREATE:
245          return 0;
246
247       case WM_CLOSE:
248          PostQuitMessage(0);
249          return 0;
250
251       case WM_TRAYMSG:
252       {
253          /* UINT uID = (UINT) wParam; */
254          UINT uMouseMsg = (UINT) lParam;
255
256          if (uMouseMsg == WM_RBUTTONDOWN)
257          {
258             POINT pt;
259             HMENU hmenu = GetSubMenu(g_hmenuTray,0);
260             GetCursorPos(&pt);
261             SetForegroundWindow(g_hwndLogFrame);
262             TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y, 0, g_hwndLogFrame, NULL);
263             PostMessage(g_hwndLogFrame, WM_NULL, 0, 0 ) ;
264          }
265          else if (uMouseMsg == WM_LBUTTONDBLCLK)
266          {
267             ShowLogWindow(TRUE);
268          }
269       }
270       return 0;
271
272       default:
273          /* DO NOTHING */
274          break;
275    }
276
277    return DefWindowProc(hwnd, msg, wParam, lParam);
278
279 }
280
281
282 #endif /* ndef _WIN_CONSOLE - entire file */
283
284 /*
285   Local Variables:
286   tab-width: 3
287   end:
288 */