4
/* Copyright 2004 b8_bavard, INRIA */
6
This file is part of mldonkey.
8
mldonkey is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
mldonkey is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with mldonkey; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
/* Stub code to interface with Shell_NotifyIcon */
30
#include <gdk/gdkwin32.h>
31
#include <gdk-pixbuf/gdk-pixbuf.h>
35
#define WM_TRAYMESSAGE WM_USER /* User defined WM Message */
36
#define SYSTRAY_LBUTTONDBLCLK 0
37
#define SYSTRAY_LBUTTONCLK 1
38
#define SYSTRAY_RBUTTONCLK 2
40
static UINT timerID = 3;
41
static NOTIFYICONDATA nid;
42
static HWND systray_hwnd=0;
43
static HICON systray_hicon=0;
44
static int win32egg_nb=0;
45
static GdkPixbuf **win32egg_pixbuf;
46
static int flipflop=0;
47
LRESULT msg_handler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
49
static UINT taskbarRestartMsg; /* static here means value is kept across multiple calls to this func */
53
taskbarRestartMsg = RegisterWindowMessage("TaskbarCreated");
58
KillTimer(hWnd, timerID);
59
call_caml_systray_clicked(SYSTRAY_LBUTTONCLK);
70
call_caml_systray_clicked(SYSTRAY_RBUTTONCLK);
73
case WM_LBUTTONDBLCLK:
74
KillTimer(hWnd, timerID);
75
call_caml_systray_clicked(SYSTRAY_LBUTTONDBLCLK);
79
SetTimer(hWnd, timerID, GetDoubleClickTime(), NULL);
85
if (msg == taskbarRestartMsg) {
86
/* explorer crashed and left us hanging...
87
This will put the systray icon back in it's place, when it restarts */
88
Shell_NotifyIcon(NIM_ADD,&nid);
94
return DefWindowProc(hWnd, msg, wParam, lParam);
97
/* Create hidden window to process systray messages */
99
static HWND systray_create_hiddenwin(void)
105
strcpy(wname, "Win");
107
wcex.cbSize = sizeof(WNDCLASSEX);
110
wcex.lpfnWndProc = (WNDPROC)msg_handler;
113
wcex.hInstance = GetModuleHandle(NULL);
116
wcex.hbrBackground = NULL;
117
wcex.lpszMenuName = NULL;
118
wcex.lpszClassName = wname;
121
RegisterClassEx(&wcex);
123
/* Create the window */
124
return (CreateWindow(wname, "", 0, 0, 0, 0, 0, GetDesktopWindow(), NULL, GetModuleHandle(NULL), 0));
127
/* taken and modified from gdk/win32/gdkwindow-win32.c */
129
HICON pixmap_to_hicon (GdkPixmap *pixmap, GdkBitmap *mask)
134
HANDLE hpixmap = NULL;
135
HBITMAP hbitmap = NULL;
137
/* Create Drawing Context */
139
HBITMAP hbitmaptmp1 = NULL;
145
gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &w, &h);
147
hpixmap = gdk_win32_drawable_get_handle (pixmap);
149
/* we need the inverted mask for the XOR op */
150
hdc1 = CreateCompatibleDC (NULL);
151
hbitmap = CreateCompatibleBitmap (hdc1, w, h);
152
hbitmaptmp1 = SelectObject (hdc1, hbitmap);
157
HBITMAP hbitmaptmp2 = NULL;
159
hmask = gdk_win32_drawable_get_handle (mask);
161
hdc2 = CreateCompatibleDC (NULL);
162
hbitmaptmp2 = SelectObject (hdc2, hmask);
164
BitBlt (hdc1, 0,0,w,h, hdc2, 0,0, NOTSRCCOPY);
166
SelectObject (hdc2, hbitmaptmp2);
170
GetClipBox (hdc1, &rect);
171
FillRect (hdc1, &rect, GetStockObject (WHITE_BRUSH));
174
SelectObject (hdc1, hbitmaptmp1);
178
ii.xHotspot = ii.yHotspot = 0; /* ignored for icons */
179
ii.hbmMask = hbitmap;
180
ii.hbmColor = hpixmap;
182
hIcon = CreateIconIndirect (&ii);
187
DeleteObject (hbitmap);
192
NOTIFYICONDATA systray_init(GdkPixbuf *pixbuf, char* text)
197
gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pm, &mask, 128);
201
ZeroMemory(&nid,sizeof(nid));
202
systray_hicon = pixmap_to_hicon (pm, mask);
203
systray_hwnd = systray_create_hiddenwin();
205
nid.cbSize=sizeof(NOTIFYICONDATA);
206
nid.hWnd=systray_hwnd;
208
nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP ;
209
nid.uCallbackMessage=WM_TRAYMESSAGE;
210
nid.hIcon=systray_hicon;
213
locenc = g_locale_from_utf8(text, -1, NULL, NULL, NULL);
214
lstrcpy(nid.szTip, locenc);
218
Shell_NotifyIcon(NIM_ADD,&nid);
222
void systray_modify_icon (GdkPixmap *pm, GdkBitmap *mask)
225
systray_hicon = pixmap_to_hicon (pm, mask);
226
nid.hIcon = systray_hicon;
227
Shell_NotifyIcon(NIM_MODIFY,&nid);
230
void systray_modify_tooltip (const char* text)
235
locenc = g_locale_from_utf8(text, -1, NULL, NULL, NULL);
236
lstrcpy(nid.szTip, locenc);
239
Shell_NotifyIcon(NIM_MODIFY,&nid);
242
void systray_remove_nid(void)
244
DestroyWindow(nid.hWnd);
245
Shell_NotifyIcon(NIM_DELETE,&nid);
247
//*********************************************************
248
//*********************************************************
249
//*********************************************************
250
void *adm_new_systray(GdkPixbuf *zpixbuf[],int nb, char *name)
254
win32egg_pixbuf=zpixbuf;
256
systray_init(win32egg_pixbuf[0], name);
261
void adm_delete_systray(void *systray)
263
systray_remove_nid() ;
265
void adm_change_tooltip(void *systray, const char *tips)
267
systray_modify_tooltip (tips ) ;
269
void adm_changeIcon_systray(void)
274
flipflop=flipflop%win32egg_nb;
275
icon=win32egg_pixbuf[flipflop];
278
gdk_pixbuf_render_pixmap_and_mask(icon, &pm, &mask, 128);
281
systray_modify_icon (pm, mask) ;
285
flipflop=flipflop%win32egg_nb;