comparison gtk/win32/gtkwin32dep.c @ 14574:333989477bcd

[gaim-migrate @ 17298] On win32, ensure that conversation windows are initially put in a sane place (instead of just [0,0]). This can easily be extended to any other problematic windows. I should have done this a long time ago to prevent countless bug reports. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Sun, 17 Sep 2006 23:13:55 +0000
parents 14933d9055a0
children 7fb8a8583c73
comparison
equal deleted inserted replaced
14573:9cbf4d3ef444 14574:333989477bcd
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * 23 *
24 */ 24 */
25 #define _WIN32_IE 0x500 25 #define _WIN32_IE 0x500
26 #ifndef WINVER
27 #define WINVER 0x0500 /* W2K */
28 #endif
26 #include <windows.h> 29 #include <windows.h>
27 #include <io.h> 30 #include <io.h>
28 #include <stdlib.h> 31 #include <stdlib.h>
29 #include <stdio.h> 32 #include <stdio.h>
30 #include <winuser.h> 33 #include <winuser.h>
31 34
32 #include <glib.h> 35 #include <glib.h>
33 #include <glib/gstdio.h> 36 #include <glib/gstdio.h>
34 #include <gtk/gtk.h> 37 #include <gtk/gtk.h>
38 #include <gdk/gdkwin32.h>
35 39
36 #include "gaim.h" 40 #include "gaim.h"
37 #include "debug.h" 41 #include "debug.h"
38 #include "notify.h" 42 #include "notify.h"
39 43
43 #include "untar.h" 47 #include "untar.h"
44 48
45 #include <libintl.h> 49 #include <libintl.h>
46 50
47 #include "gtkwin32dep.h" 51 #include "gtkwin32dep.h"
52
53 #include "win32dep.h"
48 54
49 #include "wspell.h" 55 #include "wspell.h"
50 56
51 /* 57 /*
52 * GLOBALS 58 * GLOBALS
145 if(!ShellExecuteExW(&wsinfo)) 151 if(!ShellExecuteExW(&wsinfo))
146 gaim_debug_error("gtkwgaim", "Error opening URI: %s error: %d\n", 152 gaim_debug_error("gtkwgaim", "Error opening URI: %s error: %d\n",
147 uri, (int) wsinfo.hInstApp); 153 uri, (int) wsinfo.hInstApp);
148 154
149 g_free(w_uri); 155 g_free(w_uri);
150 } else { 156 } else {
151 SHELLEXECUTEINFOA sinfo; 157 SHELLEXECUTEINFOA sinfo;
152 gchar *locale_uri; 158 gchar *locale_uri;
153 159
154 locale_uri = g_locale_from_utf8(uri, -1, NULL, NULL, NULL); 160 locale_uri = g_locale_from_utf8(uri, -1, NULL, NULL, NULL);
155 161
246 wgaim_remove_idlehooks(); 252 wgaim_remove_idlehooks();
247 253
248 } 254 }
249 255
250 /* DLL initializer */ 256 /* DLL initializer */
251 BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { 257 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
252 gtkgaimdll_hInstance = hinstDLL; 258 gtkgaimdll_hInstance = hinstDLL;
253 return TRUE; 259 return TRUE;
254 } 260 }
261
262 typedef HMONITOR WINAPI gaim_MonitorFromWindow(HWND, DWORD);
263 typedef BOOL WINAPI gaim_GetMonitorInfo(HMONITOR, LPMONITORINFO);
264
265 static gboolean
266 get_WorkingAreaRectForWindow(HWND hwnd, RECT *workingAreaRc) {
267 static gaim_MonitorFromWindow *the_MonitorFromWindow;
268 static gaim_GetMonitorInfo *the_GetMonitorInfo;
269 static gboolean initialized = FALSE;
270
271 HMONITOR monitor;
272 MONITORINFO info;
273
274 if(!initialized) {
275 the_MonitorFromWindow = (gaim_MonitorFromWindow*)
276 wgaim_find_and_loadproc("user32", "MonitorFromWindow");
277 the_GetMonitorInfo = (gaim_GetMonitorInfo*)
278 wgaim_find_and_loadproc("user32", "GetMonitorInfoA");
279 initialized = TRUE;
280 }
281
282 if(!the_MonitorFromWindow)
283 return FALSE;
284
285 if(!the_GetMonitorInfo)
286 return FALSE;
287
288 monitor = the_MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY);
289
290 info.cbSize = sizeof(info);
291 if(!the_GetMonitorInfo(monitor, &info))
292 return FALSE;
293
294 CopyRect(workingAreaRc, &(info.rcWork));
295 return TRUE;
296 }
297
298 void gtkwgaim_ensure_onscreen(GtkWidget *win) {
299 RECT windowRect, workingAreaRect, intersectionRect;
300 HWND hwnd = GDK_WINDOW_HWND(win->window);
301
302 g_return_if_fail(hwnd != NULL);
303 GetWindowRect(hwnd, &windowRect);
304
305 gaim_debug_info("win32placement",
306 "Window RECT: L:%ld R:%ld T:%ld B:%ld\n",
307 windowRect.left, windowRect.right,
308 windowRect.top, windowRect.bottom);
309
310 if(!get_WorkingAreaRectForWindow(hwnd, &workingAreaRect)) {
311 gaim_debug_info("win32placement",
312 "Couldn't get multimonitor working area\n");
313 if(!SystemParametersInfo(SPI_GETWORKAREA, 0, &workingAreaRect, FALSE)) {
314 /* I don't think this will ever happen */
315 workingAreaRect.left = 0;
316 workingAreaRect.top = 0;
317 workingAreaRect.bottom = GetSystemMetrics(SM_CYSCREEN);
318 workingAreaRect.right = GetSystemMetrics(SM_CXSCREEN);
319 }
320 }
321
322 gaim_debug_info("win32placement",
323 "Working Area RECT: L:%ld R:%ld T:%ld B:%ld\n",
324 workingAreaRect.left, workingAreaRect.right,
325 workingAreaRect.top, workingAreaRect.bottom);
326
327 /** If the conversation window doesn't intersect perfectly with the working area,
328 * move it to the top left corner of the working area */
329 if(!(IntersectRect(&intersectionRect, &windowRect, &workingAreaRect)
330 && EqualRect(&intersectionRect, &windowRect))) {
331 gaim_debug_info("win32placement",
332 "conversation window out of working area, relocating\n");
333 MoveWindow(hwnd, workingAreaRect.left, workingAreaRect.top,
334 (windowRect.right - windowRect.left),
335 (windowRect.bottom - windowRect.top), TRUE);
336 }
337 }
338