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