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