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