Mercurial > pidgin.yaz
annotate src/win32/win32dep.c @ 3907:41e7544a9c67
[gaim-migrate @ 4060]
wgaim_cleanup added
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Tue, 05 Nov 2002 23:00:53 +0000 |
parents | 3e508dd31b76 |
children | c25cf0495533 |
rev | line source |
---|---|
3630 | 1 /* |
2 * win32dep.c | |
3 * | |
4 * Author: Herman Bloggs <hermanator12002@yahoo.com> | |
5 * Date: June, 2002 | |
6 * Description: Windows dependant code for Gaim | |
7 */ | |
8 #include <windows.h> | |
9 #include <stdlib.h> | |
10 #include <stdio.h> | |
11 #include <glib.h> | |
12 #include "gaim.h" | |
13 | |
14 #include "stdafx.h" | |
15 #include "resource.h" | |
16 | |
17 /* | |
18 * DEFINES & MACROS | |
19 */ | |
20 #define WM_TRAYMESSAGE WM_USER | |
21 #define GAIM_SYSTRAY_HINT "Gaim Instant Messenger" | |
22 | |
23 /* | |
24 * LOCALS | |
25 */ | |
26 static char install_dir[MAXPATHLEN]; | |
27 static char lib_dir[MAXPATHLEN]; | |
28 static char locale_dir[MAXPATHLEN]; | |
29 static int bhide_icon; | |
30 | |
31 /* | |
32 * GLOBALS | |
33 */ | |
3856
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
34 HINSTANCE gaimexe_hInstance = 0; |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
35 HINSTANCE gaimdll_hInstance = 0; |
3630 | 36 |
37 /* | |
38 * STATIC CODE | |
39 */ | |
40 | |
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; | |
3856
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
50 nid.hIcon=LoadIcon(gaimexe_hInstance,MAKEINTRESOURCE(IDI_ICON2)); |
3630 | 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 | |
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 | |
78 /* | |
79 * PUBLIC CODE | |
80 */ | |
81 | |
3856
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
82 /* Determine Gaim Paths during Runtime */ |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
83 |
3630 | 84 char* wgaim_install_dir(void) { |
85 HMODULE hmod; | |
86 char* buf; | |
87 | |
88 hmod = GetModuleHandle(NULL); | |
89 if( hmod == 0 ) { | |
90 buf = g_win32_error_message( GetLastError() ); | |
91 debug_printf("GetModuleHandle error: %s\n", buf); | |
92 free(buf); | |
93 return NULL; | |
94 } | |
95 if(GetModuleFileName( hmod, (char*)&install_dir, MAXPATHLEN ) == 0) { | |
96 buf = g_win32_error_message( GetLastError() ); | |
97 debug_printf("GetModuleFileName error: %s\n", buf); | |
98 free(buf); | |
99 return NULL; | |
100 } | |
101 buf = g_path_get_dirname( install_dir ); | |
102 strcpy( (char*)&install_dir, buf ); | |
103 free( buf ); | |
104 | |
105 return (char*)&install_dir; | |
106 } | |
107 | |
108 char* wgaim_lib_dir(void) { | |
109 strcpy(lib_dir, wgaim_install_dir()); | |
110 strcat(lib_dir, G_DIR_SEPARATOR_S "plugins"); | |
111 return (char*)&lib_dir; | |
112 } | |
113 | |
114 char* wgaim_locale_dir(void) { | |
115 strcpy(locale_dir, wgaim_install_dir()); | |
116 strcat(locale_dir, G_DIR_SEPARATOR_S "locale"); | |
117 return (char*)&locale_dir; | |
118 } | |
119 | |
3856
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
120 /* Systray related routines */ |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
121 |
3630 | 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 | |
3856
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
145 /* Windows Initializations */ |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
146 |
3630 | 147 void wgaim_init(void) { |
3907
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
148 WORD wVersionRequested; |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
149 WSADATA wsaData; |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
150 int err; |
3856
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
151 char* locale=0; |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
152 char newenv[128]; |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
153 |
3907
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
154 debug_printf("wgaim_init\n"); |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
155 /* |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
156 * Winsock init |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
157 */ |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
158 wVersionRequested = MAKEWORD( 2, 2 ); |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
159 |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
160 err = WSAStartup( wVersionRequested, &wsaData ); |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
161 if ( err != 0 ) { |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
162 return 1; |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
163 } |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
164 |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
165 /* Confirm that the winsock DLL supports 2.2 */ |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
166 /* Note that if the DLL supports versions greater than |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
167 2.2 in addition to 2.2, it will still return 2.2 in |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
168 wVersion since that is the version we requested. */ |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
169 |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
170 if ( LOBYTE( wsaData.wVersion ) != 2 || |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
171 HIBYTE( wsaData.wVersion ) != 2 ) { |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
172 debug_printf("Could not find a usable WinSock DLL. Oh well.\n"); |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
173 WSACleanup( ); |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
174 return 1; |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
175 } |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
176 |
3630 | 177 /* Filter to catch systray events */ |
178 gdk_add_client_message_filter (GDK_POINTER_TO_ATOM (WM_TRAYMESSAGE), | |
179 traymsg_filter_func, | |
180 NULL); | |
3856
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
181 /* get default locale */ |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
182 locale = g_win32_getlocale(); |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
183 debug_printf("Language profile used: %s\n", locale); |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
184 |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
185 /* |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
186 * Aspell config |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
187 */ |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
188 /* Set LANG env var */ |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
189 sprintf(newenv, "LANG=%s", locale); |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
190 if(putenv(newenv)<0) |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
191 debug_printf("putenv failed\n"); |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
192 g_free(locale); |
3905
3e508dd31b76
[gaim-migrate @ 4058]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3856
diff
changeset
|
193 |
3907
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
194 /* |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
195 * IdleTracker Initialization |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
196 */ |
3905
3e508dd31b76
[gaim-migrate @ 4058]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3856
diff
changeset
|
197 if(!IdleTrackerInit()) |
3e508dd31b76
[gaim-migrate @ 4058]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3856
diff
changeset
|
198 debug_printf("IdleTracker failed to initialize\n"); |
3630 | 199 } |
3856
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
200 |
3907
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
201 /* Windows Cleanup */ |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
202 |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
203 void wgaim_cleanup(void) { |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
204 debug_printf("wgaim_cleanup\n"); |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
205 |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
206 /* winsock cleanup */ |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
207 WSACleanup( ); |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
208 |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
209 /* IdleTracker cleanup */ |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
210 IdleTrackerTerm(); |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
211 } |
41e7544a9c67
[gaim-migrate @ 4060]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3905
diff
changeset
|
212 |
3856
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
213 BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
214 gaimdll_hInstance = hinstDLL; |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
215 return TRUE; |
50ac7e205045
[gaim-migrate @ 4008]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
216 } |