comparison src/win32/win32dep.c @ 3950:c25cf0495533

[gaim-migrate @ 4129] Moved systray functionality to systray.c committer: Tailor Script <tailor@pidgin.im>
author Herman Bloggs <hermanator12002@yahoo.com>
date Mon, 11 Nov 2002 21:57:19 +0000
parents 41e7544a9c67
children d9287e87ba56
comparison
equal deleted inserted replaced
3949:ee562d745d07 3950:c25cf0495533
11 #include <glib.h> 11 #include <glib.h>
12 #include "gaim.h" 12 #include "gaim.h"
13 13
14 #include "stdafx.h" 14 #include "stdafx.h"
15 #include "resource.h" 15 #include "resource.h"
16 #include "MinimizeToTray.h"
17 #include "systray.h"
16 18
17 /* 19 /*
18 * DEFINES & MACROS 20 * DEFINES & MACROS
19 */ 21 */
20 #define WM_TRAYMESSAGE WM_USER 22
21 #define GAIM_SYSTRAY_HINT "Gaim Instant Messenger"
22 23
23 /* 24 /*
24 * LOCALS 25 * LOCALS
25 */ 26 */
26 static char install_dir[MAXPATHLEN]; 27 static char install_dir[MAXPATHLEN];
27 static char lib_dir[MAXPATHLEN]; 28 static char lib_dir[MAXPATHLEN];
28 static char locale_dir[MAXPATHLEN]; 29 static char locale_dir[MAXPATHLEN];
29 static int bhide_icon; 30 static int bhide_icon;
30 31
32
31 /* 33 /*
32 * GLOBALS 34 * GLOBALS
33 */ 35 */
34 HINSTANCE gaimexe_hInstance = 0; 36 HINSTANCE gaimexe_hInstance = 0;
35 HINSTANCE gaimdll_hInstance = 0; 37 HINSTANCE gaimdll_hInstance = 0;
36 38
39
37 /* 40 /*
38 * STATIC CODE 41 * STATIC CODE
39 */ 42 */
40 43
41 static void ShowNotifyIcon(HWND hWnd,BOOL bAdd)
42 {
43 NOTIFYICONDATA nid;
44 ZeroMemory(&nid,sizeof(nid));
45 nid.cbSize=sizeof(NOTIFYICONDATA);
46 nid.hWnd=hWnd;
47 nid.uID=0;
48 nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP;
49 nid.uCallbackMessage=WM_TRAYMESSAGE;
50 nid.hIcon=LoadIcon(gaimexe_hInstance,MAKEINTRESOURCE(IDI_ICON2));
51 lstrcpy(nid.szTip,TEXT(GAIM_SYSTRAY_HINT));
52
53 if(bAdd)
54 Shell_NotifyIcon(NIM_ADD,&nid);
55 else
56 Shell_NotifyIcon(NIM_DELETE,&nid);
57 }
58 44
59 static GdkFilterReturn traymsg_filter_func( GdkXEvent *xevent, GdkEvent *event, gpointer data)
60 {
61 MSG *msg = (MSG*)xevent;
62
63 if( msg->lParam == WM_LBUTTONDBLCLK ) {
64 RestoreWndFromTray(msg->hwnd);
65 bhide_icon = TRUE;
66 return GDK_FILTER_REMOVE;
67 }
68
69 if( msg->lParam == WM_LBUTTONUP ) {
70 if(bhide_icon) {
71 ShowNotifyIcon(msg->hwnd,FALSE);
72 bhide_icon = FALSE;
73 }
74 }
75 return GDK_FILTER_REMOVE;
76 }
77 45
78 /* 46 /*
79 * PUBLIC CODE 47 * PUBLIC CODE
80 */ 48 */
49
50 /* Misc Wingaim functions */
51 HINSTANCE wgaim_hinstance(void) {
52 return gaimexe_hInstance;
53 }
81 54
82 /* Determine Gaim Paths during Runtime */ 55 /* Determine Gaim Paths during Runtime */
83 56
84 char* wgaim_install_dir(void) { 57 char* wgaim_install_dir(void) {
85 HMODULE hmod; 58 HMODULE hmod;
115 strcpy(locale_dir, wgaim_install_dir()); 88 strcpy(locale_dir, wgaim_install_dir());
116 strcat(locale_dir, G_DIR_SEPARATOR_S "locale"); 89 strcat(locale_dir, G_DIR_SEPARATOR_S "locale");
117 return (char*)&locale_dir; 90 return (char*)&locale_dir;
118 } 91 }
119 92
120 /* Systray related routines */
121
122 GdkFilterReturn wgaim_window_filter( GdkXEvent *xevent, GdkEvent *event, gpointer data)
123 {
124 MSG *msg = (MSG*)xevent;
125
126 switch( msg->message ) {
127 case WM_SYSCOMMAND:
128 if( msg->wParam == SC_MINIMIZE ) {
129 MinimizeWndToTray(msg->hwnd);
130 ShowNotifyIcon(msg->hwnd,TRUE);
131
132 SetWindowLong(msg->hwnd,DWL_MSGRESULT,0);
133 return GDK_FILTER_REMOVE;
134 }
135 break;
136 case WM_CLOSE:
137 MinimizeWndToTray(msg->hwnd);
138 ShowNotifyIcon(msg->hwnd,TRUE);
139 return GDK_FILTER_REMOVE;
140 }
141
142 return GDK_FILTER_CONTINUE;
143 }
144
145 /* Windows Initializations */ 93 /* Windows Initializations */
146 94
147 void wgaim_init(void) { 95 void wgaim_init(void) {
148 WORD wVersionRequested; 96 WORD wVersionRequested;
149 WSADATA wsaData; 97 WSADATA wsaData;
150 int err; 98 int err;
151 char* locale=0; 99 char* locale=0;
152 char newenv[128]; 100 char newenv[128];
153 101
154 debug_printf("wgaim_init\n"); 102 debug_printf("wgaim_init\n");
103
104 /* Initialize Wingaim systray icon */
105 wgaim_systray_init();
106
155 /* 107 /*
156 * Winsock init 108 * Winsock init
157 */ 109 */
158 wVersionRequested = MAKEWORD( 2, 2 ); 110 wVersionRequested = MAKEWORD( 2, 2 );
159 111
172 debug_printf("Could not find a usable WinSock DLL. Oh well.\n"); 124 debug_printf("Could not find a usable WinSock DLL. Oh well.\n");
173 WSACleanup( ); 125 WSACleanup( );
174 return 1; 126 return 1;
175 } 127 }
176 128
177 /* Filter to catch systray events */
178 gdk_add_client_message_filter (GDK_POINTER_TO_ATOM (WM_TRAYMESSAGE),
179 traymsg_filter_func,
180 NULL);
181 /* get default locale */ 129 /* get default locale */
182 locale = g_win32_getlocale(); 130 locale = g_win32_getlocale();
183 debug_printf("Language profile used: %s\n", locale); 131 debug_printf("Language profile used: %s\n", locale);
184 132
185 /* 133 /*
206 /* winsock cleanup */ 154 /* winsock cleanup */
207 WSACleanup( ); 155 WSACleanup( );
208 156
209 /* IdleTracker cleanup */ 157 /* IdleTracker cleanup */
210 IdleTrackerTerm(); 158 IdleTrackerTerm();
159
160 /* Remove systray icon */
161 wgaim_systray_cleanup();
211 } 162 }
212 163
164 /* DLL initializer */
213 BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { 165 BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) {
214 gaimdll_hInstance = hinstDLL; 166 gaimdll_hInstance = hinstDLL;
215 return TRUE; 167 return TRUE;
216 } 168 }