comparison src/win32/systray.c @ 3946:8ef1360becfe

[gaim-migrate @ 4125] Initial import committer: Tailor Script <tailor@pidgin.im>
author Herman Bloggs <hermanator12002@yahoo.com>
date Mon, 11 Nov 2002 21:50:37 +0000
parents
children 9c2d8579ff3e
comparison
equal deleted inserted replaced
3945:f0b6f924014b 3946:8ef1360becfe
1 /*
2 * systray.c
3 *
4 * Author: Herman Bloggs <hermanator12002@yahoo.com>
5 * Date: November, 2002
6 * Description: Gaim systray functionality
7 */
8 #include <windows.h>
9 #include <gdk/gdkwin32.h>
10 #include "resource.h"
11 #include "gaim.h"
12 #include "win32dep.h"
13 #include "MinimizeToTray.h"
14
15 /*
16 * DEFINES, MACROS & DATA TYPES
17 */
18 #define GAIM_SYSTRAY_HINT _("Gaim Instant Messenger")
19 #define GAIM_SYSTRAY_DISCONN_HINT _("Gaim Instant Messenger - Signed off")
20 #define WM_TRAYMESSAGE WM_USER /* User defined WM Message */
21
22 enum _GAIM_WIN {
23 GAIM_LOGIN_WIN,
24 GAIM_BUDDY_WIN,
25 GAIM_WIN_COUNT
26 };
27
28 typedef enum _GAIM_WIN GAIM_WIN;
29
30 enum _GAIM_STATE {
31 GAIM_STATE_NONE = -1,
32 GAIM_STATE_HIDDEN,
33 GAIM_STATE_SHOWN,
34 GAIM_STATE_COUNT
35 };
36
37 typedef enum _GAIM_STATE GAIM_STATE;
38
39 /*
40 * LOCALS
41 */
42 static HWND systray_hwnd=0;
43 static HICON sysicon_disconn=0;
44 static HICON sysicon_conn=0;
45 static NOTIFYICONDATA wgaim_nid;
46 static GAIM_WIN gaim_main_win=-1;
47 static HWND gaim_windows[GAIM_WIN_COUNT];
48 static GAIM_STATE main_win_state=-1;
49
50 /*
51 * PRIVATE CODE
52 */
53
54 static LRESULT CALLBACK systray_mainmsg_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
55
56 switch(msg) {
57 case WM_CREATE:
58 debug_printf("WM_CREATE\n");
59 break;
60
61 case WM_TIMER:
62 debug_printf("WM_TIMER\n");
63 break;
64
65 case WM_DESTROY:
66 debug_printf("WM_DESTROY\n");
67 break;
68
69 case WM_COMMAND:
70 debug_printf("WM_COMMAND\n");
71 break;
72
73 case WM_TRAYMESSAGE:
74 {
75 if( lparam == WM_LBUTTONDBLCLK ) {
76 /* If Gaim main win is hidden.. restore it */
77 if( main_win_state == GAIM_STATE_HIDDEN ) {
78 RestoreWndFromTray(gaim_windows[gaim_main_win]);
79 }
80 debug_printf("Systray got double click\n");
81 }
82 if( lparam == WM_LBUTTONUP ) {
83 debug_printf("Systray got Left button up\n");
84 }
85 }
86 default:
87 }/* end switch */
88
89 return DefWindowProc(hwnd, msg, wparam, lparam);
90 }
91
92 static HWND create_hidenwin() {
93 WNDCLASSEX wcex;
94 TCHAR wname[32];
95
96 strcpy(wname, "GaimWin");
97
98 wcex.cbSize = sizeof(WNDCLASSEX);
99
100 wcex.style = 0;
101 wcex.lpfnWndProc = (WNDPROC)systray_mainmsg_handler;
102 wcex.cbClsExtra = 0;
103 wcex.cbWndExtra = 0;
104 wcex.hInstance = wgaim_hinstance();
105 wcex.hIcon = NULL;
106 wcex.hCursor = NULL,
107 wcex.hbrBackground = NULL;
108 wcex.lpszMenuName = NULL;
109 wcex.lpszClassName = wname;
110 wcex.hIconSm = NULL;
111
112 RegisterClassEx(&wcex);
113
114 // Create the window
115 return (CreateWindow(wname, "", 0, 0, 0, 0, 0, GetDesktopWindow(), NULL, wgaim_hinstance(), 0));
116 }
117
118 static void systray_init_icon(HWND hWnd, HICON icon) {
119 ZeroMemory(&wgaim_nid,sizeof(wgaim_nid));
120 wgaim_nid.cbSize=sizeof(NOTIFYICONDATA);
121 wgaim_nid.hWnd=hWnd;
122 wgaim_nid.uID=0;
123 wgaim_nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP;
124 wgaim_nid.uCallbackMessage=WM_TRAYMESSAGE;
125 wgaim_nid.hIcon=icon;
126 strcpy(wgaim_nid.szTip,GAIM_SYSTRAY_DISCONN_HINT);
127
128 Shell_NotifyIcon(NIM_ADD,&wgaim_nid);
129 }
130
131 static void systray_change_icon(HICON icon, char* text) {
132 wgaim_nid.hIcon = icon;
133 lstrcpy(wgaim_nid.szTip, text);
134 Shell_NotifyIcon(NIM_MODIFY,&wgaim_nid);
135 }
136
137 static void systray_remove_nid(void) {
138 Shell_NotifyIcon(NIM_DELETE,&wgaim_nid);
139 }
140
141 static void systray_minimize_win(HWND hWnd) {
142 MinimizeWndToTray(hWnd);
143 main_win_state = GAIM_STATE_HIDDEN;
144 }
145
146 static GdkFilterReturn buddywin_filter( GdkXEvent *xevent, GdkEvent *event, gpointer data) {
147
148 MSG *msg = (MSG*)xevent;
149
150 switch( msg->message ) {
151 case WM_SHOWWINDOW:
152 if(msg->wParam) {
153 debug_printf("Buddy window is being shown\n");
154 /* Keep track of the main Gaim window */
155 gaim_main_win = GAIM_BUDDY_WIN;
156 main_win_state = GAIM_STATE_SHOWN;
157 systray_change_icon(sysicon_conn, GAIM_SYSTRAY_HINT);
158 }
159 else
160 debug_printf("Buddy window is being hidden\n");
161 break;
162 case WM_SYSCOMMAND:
163 if( msg->wParam == SC_MINIMIZE ) {
164 systray_minimize_win(msg->hwnd);
165 return GDK_FILTER_REMOVE;
166 }
167 break;
168 case WM_CLOSE:
169 systray_minimize_win(msg->hwnd);
170 debug_printf("Buddy window closed\n");
171 return GDK_FILTER_REMOVE;
172 case WM_DESTROY:
173 debug_printf("Buddy window destroyed\n");
174 break;
175 }
176
177 return GDK_FILTER_CONTINUE;
178 }
179
180 static GdkFilterReturn loginwin_filter( GdkXEvent *xevent, GdkEvent *event, gpointer data) {
181 MSG *msg = (MSG*)xevent;
182
183 switch( msg->message ) {
184 case WM_SHOWWINDOW:
185 if(msg->wParam) {
186 debug_printf("Login window is being shown\n");
187 /* Keep track of the main Gaim window */
188 gaim_main_win = GAIM_LOGIN_WIN;
189 main_win_state = GAIM_STATE_SHOWN;
190 systray_change_icon(sysicon_disconn, GAIM_SYSTRAY_DISCONN_HINT);
191 }
192 else
193 debug_printf("Login window is being hidden\n");
194 break;
195 #if 0
196 case WM_SYSCOMMAND:
197 if( msg->wParam == SC_MINIMIZE ) {
198 systray_minimize_win(msg->hwnd);
199 return GDK_FILTER_REMOVE;
200 }
201 break;
202 #endif
203 case WM_CLOSE:
204 systray_minimize_win(msg->hwnd);
205 debug_printf("Login window closed\n");
206 return GDK_FILTER_REMOVE;
207 case WM_DESTROY:
208 debug_printf("Login window destroyed\n");
209 break;
210 }
211
212 return GDK_FILTER_CONTINUE;
213 }
214
215 /*
216 * PUBLIC CODE
217 */
218
219 /* Create a hidden window and associate it with the systray icon.
220 We use this hidden window to proccess WM_TRAYMESSAGE msgs. */
221 void wgaim_systray_init(void) {
222 /* dummy window to process systray messages */
223 systray_hwnd = create_hidenwin();
224
225 /* Load icons, and init systray notify icon */
226 sysicon_disconn = LoadIcon(wgaim_hinstance(),MAKEINTRESOURCE(IDI_ICON2));
227 sysicon_conn = LoadIcon(wgaim_hinstance(),MAKEINTRESOURCE(IDI_ICON3));
228
229 /* Create icon in systray */
230 systray_init_icon(systray_hwnd, sysicon_disconn);
231 }
232
233 void wgaim_systray_cleanup(void) {
234 systray_remove_nid();
235 }
236
237 /* This function is called after the buddy list has been created */
238 void wgaim_created_blistwin( GtkWidget *blist ) {
239 gdk_window_add_filter (GTK_WIDGET(blist)->window,
240 buddywin_filter,
241 NULL);
242 gaim_main_win = GAIM_BUDDY_WIN;
243 gaim_windows[GAIM_BUDDY_WIN] = GDK_WINDOW_HWND(GTK_WIDGET(blist)->window);
244 }
245
246 /* This function is called after the login window has been created */
247 void wgaim_created_loginwin( GtkWidget *loginwin ) {
248 gdk_window_add_filter (GTK_WIDGET(loginwin)->window,
249 loginwin_filter,
250 NULL);
251 gaim_main_win = GAIM_LOGIN_WIN;
252 gaim_windows[GAIM_LOGIN_WIN] = GDK_WINDOW_HWND(GTK_WIDGET(loginwin)->window);
253 /*systray_init_icon(GDK_WINDOW_HWND(GTK_WIDGET(loginwin)->window), sysicon_disconn);*/
254 }
255