Mercurial > pidgin
comparison gtk/gtkdocklet-win32.c @ 14681:2c1781ea074c
[gaim-migrate @ 17433]
Depluginize the docklet.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 05 Oct 2006 23:24:00 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
14680:fa285d018c71 | 14681:2c1781ea074c |
---|---|
1 /* | |
2 * System tray icon (aka docklet) plugin for Gaim | |
3 * | |
4 * Copyright (C) 2002-3 Robert McQueen <robot101@debian.org> | |
5 * Copyright (C) 2003 Herman Bloggs <hermanator12002@yahoo.com> | |
6 * Inspired by a similar plugin by: | |
7 * John (J5) Palmieri <johnp@martianrock.com> | |
8 * | |
9 * This program is free software; you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation; either version 2 of the | |
12 * License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
22 * 02111-1307, USA. | |
23 */ | |
24 | |
25 #include <windows.h> | |
26 #include <gdk/gdkwin32.h> | |
27 #include <gdk/gdk.h> | |
28 | |
29 #include "internal.h" | |
30 #include "gtkblist.h" | |
31 #include "gtkprefs.h" | |
32 #include "debug.h" | |
33 | |
34 #include "gaim.h" | |
35 #include "gtkdialogs.h" | |
36 | |
37 #include "resource.h" | |
38 #include "MinimizeToTray.h" | |
39 #include "gtkwin32dep.h" | |
40 #include "docklet.h" | |
41 | |
42 /* | |
43 * DEFINES, MACROS & DATA TYPES | |
44 */ | |
45 #define WM_TRAYMESSAGE WM_USER /* User defined WM Message */ | |
46 | |
47 /* | |
48 * LOCALS | |
49 */ | |
50 static HWND systray_hwnd=0; | |
51 static HICON sysicon_disconn=0; | |
52 static HICON sysicon_conn=0; | |
53 static HICON sysicon_away=0; | |
54 static HICON sysicon_pend=0; | |
55 static HICON sysicon_awypend=0; | |
56 static HICON sysicon_blank=0; | |
57 static NOTIFYICONDATA wgaim_nid; | |
58 | |
59 | |
60 static LRESULT CALLBACK systray_mainmsg_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { | |
61 static UINT taskbarRestartMsg; /* static here means value is kept across multiple calls to this func */ | |
62 | |
63 switch(msg) { | |
64 case WM_CREATE: | |
65 gaim_debug(GAIM_DEBUG_INFO, "tray icon", "WM_CREATE\n"); | |
66 taskbarRestartMsg = RegisterWindowMessage("TaskbarCreated"); | |
67 break; | |
68 | |
69 case WM_TIMER: | |
70 gaim_debug(GAIM_DEBUG_INFO, "tray icon", "WM_TIMER\n"); | |
71 break; | |
72 | |
73 case WM_DESTROY: | |
74 gaim_debug(GAIM_DEBUG_INFO, "tray icon", "WM_DESTROY\n"); | |
75 break; | |
76 | |
77 case WM_TRAYMESSAGE: | |
78 { | |
79 int type = 0; | |
80 | |
81 /* We'll use Double Click - Single click over on linux */ | |
82 if( lparam == WM_LBUTTONDBLCLK ) | |
83 type = 1; | |
84 else if( lparam == WM_MBUTTONUP ) | |
85 type = 2; | |
86 else if( lparam == WM_RBUTTONUP ) | |
87 type = 3; | |
88 else | |
89 break; | |
90 | |
91 docklet_clicked(type); | |
92 break; | |
93 } | |
94 default: | |
95 if (msg == taskbarRestartMsg) { | |
96 /* explorer crashed and left us hanging... | |
97 This will put the systray icon back in it's place, when it restarts */ | |
98 Shell_NotifyIcon(NIM_ADD,&wgaim_nid); | |
99 } | |
100 break; | |
101 }/* end switch */ | |
102 | |
103 return DefWindowProc(hwnd, msg, wparam, lparam); | |
104 } | |
105 | |
106 /* Create hidden window to process systray messages */ | |
107 static HWND systray_create_hiddenwin() { | |
108 WNDCLASSEX wcex; | |
109 TCHAR wname[32]; | |
110 | |
111 strcpy(wname, "GaimWin"); | |
112 | |
113 wcex.cbSize = sizeof(WNDCLASSEX); | |
114 | |
115 wcex.style = 0; | |
116 wcex.lpfnWndProc = (WNDPROC)systray_mainmsg_handler; | |
117 wcex.cbClsExtra = 0; | |
118 wcex.cbWndExtra = 0; | |
119 wcex.hInstance = gtkwgaim_hinstance(); | |
120 wcex.hIcon = NULL; | |
121 wcex.hCursor = NULL, | |
122 wcex.hbrBackground = NULL; | |
123 wcex.lpszMenuName = NULL; | |
124 wcex.lpszClassName = wname; | |
125 wcex.hIconSm = NULL; | |
126 | |
127 RegisterClassEx(&wcex); | |
128 | |
129 /* Create the window */ | |
130 return (CreateWindow(wname, "", 0, 0, 0, 0, 0, GetDesktopWindow(), NULL, gtkwgaim_hinstance(), 0)); | |
131 } | |
132 | |
133 static void systray_init_icon(HWND hWnd, HICON icon) { | |
134 ZeroMemory(&wgaim_nid,sizeof(wgaim_nid)); | |
135 wgaim_nid.cbSize=sizeof(NOTIFYICONDATA); | |
136 wgaim_nid.hWnd=hWnd; | |
137 wgaim_nid.uID=0; | |
138 wgaim_nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP; | |
139 wgaim_nid.uCallbackMessage=WM_TRAYMESSAGE; | |
140 wgaim_nid.hIcon=icon; | |
141 lstrcpy(wgaim_nid.szTip, "Gaim"); | |
142 Shell_NotifyIcon(NIM_ADD,&wgaim_nid); | |
143 docklet_embedded(); | |
144 } | |
145 | |
146 static void systray_change_icon(HICON icon) { | |
147 wgaim_nid.hIcon = icon; | |
148 Shell_NotifyIcon(NIM_MODIFY,&wgaim_nid); | |
149 } | |
150 | |
151 static void systray_remove_nid(void) { | |
152 Shell_NotifyIcon(NIM_DELETE,&wgaim_nid); | |
153 } | |
154 | |
155 static void wgaim_tray_update_icon(DockletStatus icon) { | |
156 switch (icon) { | |
157 case DOCKLET_STATUS_OFFLINE: | |
158 systray_change_icon(sysicon_disconn); | |
159 break; | |
160 case DOCKLET_STATUS_CONNECTING: | |
161 break; | |
162 case DOCKLET_STATUS_ONLINE: | |
163 systray_change_icon(sysicon_conn); | |
164 break; | |
165 case DOCKLET_STATUS_ONLINE_PENDING: | |
166 systray_change_icon(sysicon_pend); | |
167 break; | |
168 case DOCKLET_STATUS_AWAY: | |
169 systray_change_icon(sysicon_away); | |
170 break; | |
171 case DOCKLET_STATUS_AWAY_PENDING: | |
172 systray_change_icon(sysicon_awypend); | |
173 break; | |
174 } | |
175 } | |
176 | |
177 static void wgaim_tray_blank_icon() { | |
178 systray_change_icon(sysicon_blank); | |
179 } | |
180 | |
181 static void wgaim_tray_set_tooltip(gchar *tooltip) { | |
182 if (tooltip) { | |
183 char *locenc = NULL; | |
184 locenc = g_locale_from_utf8(tooltip, -1, NULL, NULL, NULL); | |
185 lstrcpyn(wgaim_nid.szTip, locenc, sizeof(wgaim_nid.szTip)/sizeof(TCHAR)); | |
186 g_free(locenc); | |
187 } else { | |
188 lstrcpy(wgaim_nid.szTip, "Gaim"); | |
189 } | |
190 Shell_NotifyIcon(NIM_MODIFY, &wgaim_nid); | |
191 } | |
192 | |
193 void wgaim_tray_minimize(GaimGtkBuddyList *gtkblist) { | |
194 MinimizeWndToTray(GDK_WINDOW_HWND(gtkblist->window->window)); | |
195 } | |
196 | |
197 void wgaim_tray_maximize(GaimGtkBuddyList *gtkblist) { | |
198 RestoreWndFromTray(GDK_WINDOW_HWND(gtkblist->window->window)); | |
199 } | |
200 | |
201 | |
202 static void wgaim_tray_create() { | |
203 OSVERSIONINFO osinfo; | |
204 /* dummy window to process systray messages */ | |
205 systray_hwnd = systray_create_hiddenwin(); | |
206 | |
207 osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | |
208 GetVersionEx(&osinfo); | |
209 | |
210 /* Load icons, and init systray notify icon | |
211 * NOTE: Windows < XP only supports displaying 4-bit images in the Systray, | |
212 * 2K and ME will use the highest color depth that the desktop will support, | |
213 * but will scale it back to 4-bits for display. | |
214 * That is why we use custom 4-bit icons for pre XP Windowses */ | |
215 if ((osinfo.dwMajorVersion == 5 && osinfo.dwMinorVersion > 0) || | |
216 (osinfo.dwMajorVersion >= 6)) | |
217 { | |
218 sysicon_disconn = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_OFFLINE_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
219 sysicon_conn = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
220 sysicon_away = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_AWAY_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
221 sysicon_pend = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_PEND_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
222 sysicon_awypend = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_AWAYPEND_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
223 } else { | |
224 sysicon_disconn = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_OFFLINE_TRAY_ICON_4BIT), IMAGE_ICON, 16, 16, 0); | |
225 sysicon_conn = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_TRAY_ICON_4BIT), IMAGE_ICON, 16, 16, 0); | |
226 sysicon_away = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_AWAY_TRAY_ICON_4BIT), IMAGE_ICON, 16, 16, 0); | |
227 sysicon_pend = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_PEND_TRAY_ICON_4BIT), IMAGE_ICON, 16, 16, 0); | |
228 sysicon_awypend = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_AWAYPEND_TRAY_ICON_4BIT), IMAGE_ICON, 16, 16, 0); | |
229 } | |
230 sysicon_blank = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_BLANK_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
231 | |
232 /* Create icon in systray */ | |
233 systray_init_icon(systray_hwnd, sysicon_disconn); | |
234 | |
235 gaim_signal_connect(gaim_gtk_blist_get_handle(), "gtkblist-hiding", | |
236 &handle, GAIM_CALLBACK(wgaim_tray_minimize), NULL); | |
237 gaim_signal_connect(gaim_gtk_blist_get_handle(), "gtkblist-unhiding", | |
238 &handle, GAIM_CALLBACK(wgaim_tray_maximize), NULL); | |
239 | |
240 gaim_debug(GAIM_DEBUG_INFO, "tray icon", "created\n"); | |
241 } | |
242 | |
243 static void wgaim_tray_destroy() { | |
244 gaim_signals_disconnect_by_handle(&handle); | |
245 systray_remove_nid(); | |
246 DestroyWindow(systray_hwnd); | |
247 docklet_remove(); | |
248 } | |
249 | |
250 static struct docklet_ui_ops wgaim_tray_ops = | |
251 { | |
252 wgaim_tray_create, | |
253 wgaim_tray_destroy, | |
254 wgaim_tray_update_icon, | |
255 wgaim_tray_blank_icon, | |
256 wgaim_tray_set_tooltip, | |
257 NULL | |
258 }; | |
259 | |
260 /* Used by docklet's plugin load func */ | |
261 void docklet_ui_init() { | |
262 docklet_set_ui_ops(&wgaim_tray_ops); | |
263 } |