Sun, 17 Sep 2006 23:13:55 +0000
[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.
| 14286 | 1 | /* |
| 2 | * gaim | |
| 3 | * | |
| 4 | * File: gtkwin32dep.c | |
| 5 | * Date: June, 2002 | |
| 6 | * Description: Windows dependant code for Gaim | |
| 7 | * | |
| 8 | * Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com> | |
| 9 | * | |
| 10 | * This program is free software; you can redistribute it and/or modify | |
| 11 | * it under the terms of the GNU General Public License as published by | |
| 12 | * the Free Software Foundation; either version 2 of the License, or | |
| 13 | * (at your option) any later version. | |
| 14 | * | |
| 15 | * This program is distributed in the hope that it will be useful, | |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 | * GNU General Public License for more details. | |
| 19 | * | |
| 20 | * You should have received a copy of the GNU General Public License | |
| 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 | |
| 23 | * | |
| 24 | */ | |
| 25 | #define _WIN32_IE 0x500 | |
|
14636
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
26 | #ifndef WINVER |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
27 | #define WINVER 0x0500 /* W2K */ |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
28 | #endif |
| 14286 | 29 | #include <windows.h> |
| 30 | #include <io.h> | |
| 31 | #include <stdlib.h> | |
| 32 | #include <stdio.h> | |
| 33 | #include <winuser.h> | |
| 34 | ||
| 35 | #include <glib.h> | |
| 36 | #include <glib/gstdio.h> | |
| 37 | #include <gtk/gtk.h> | |
|
14636
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
38 | #include <gdk/gdkwin32.h> |
| 14286 | 39 | |
| 40 | #include "gaim.h" | |
| 41 | #include "debug.h" | |
| 42 | #include "notify.h" | |
| 43 | ||
| 44 | #include "resource.h" | |
| 45 | #include "idletrack.h" | |
| 46 | #include "zlib.h" | |
| 47 | #include "untar.h" | |
| 48 | ||
| 49 | #include <libintl.h> | |
| 50 | ||
| 51 | #include "gtkwin32dep.h" | |
| 52 | ||
|
14636
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
53 | #include "win32dep.h" |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
54 | |
| 14286 | 55 | #include "wspell.h" |
| 56 | ||
| 57 | /* | |
| 58 | * GLOBALS | |
| 59 | */ | |
| 60 | HINSTANCE gaimexe_hInstance = 0; | |
| 61 | HINSTANCE gtkgaimdll_hInstance = 0; | |
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
62 | HWND messagewin_hwnd; |
| 14286 | 63 | |
| 64 | /* | |
| 65 | * PUBLIC CODE | |
| 66 | */ | |
| 67 | ||
| 68 | HINSTANCE gtkwgaim_hinstance(void) { | |
| 69 | return gaimexe_hInstance; | |
| 70 | } | |
| 71 | ||
| 72 | int gtkwgaim_gz_decompress(const char* in, const char* out) { | |
| 73 | gzFile fin; | |
| 74 | FILE *fout; | |
| 75 | char buf[1024]; | |
| 76 | int ret; | |
| 77 | ||
| 78 | if((fin = gzopen(in, "rb"))) { | |
| 79 | if(!(fout = g_fopen(out, "wb"))) { | |
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
80 | gaim_debug_error("gtkwgaim_gz_decompress", "Error opening file: %s\n", out); |
| 14286 | 81 | gzclose(fin); |
| 82 | return 0; | |
| 83 | } | |
| 84 | } | |
| 85 | else { | |
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
86 | gaim_debug_error("gtkwgaim_gz_decompress", "gzopen failed to open: %s\n", in); |
| 14286 | 87 | return 0; |
| 88 | } | |
| 89 | ||
| 90 | while((ret = gzread(fin, buf, 1024))) { | |
| 91 | if(fwrite(buf, 1, ret, fout) < ret) { | |
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
92 | gaim_debug_error("wgaim_gz_decompress", "Error writing %d bytes to file\n", ret); |
| 14286 | 93 | gzclose(fin); |
| 94 | fclose(fout); | |
| 95 | return 0; | |
| 96 | } | |
| 97 | } | |
| 98 | fclose(fout); | |
| 99 | gzclose(fin); | |
| 100 | ||
| 101 | if(ret < 0) { | |
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
102 | gaim_debug_error("gtkwgaim_gz_decompress", "gzread failed while reading: %s\n", in); |
| 14286 | 103 | return 0; |
| 104 | } | |
| 105 | ||
| 106 | return 1; | |
| 107 | } | |
| 108 | ||
| 109 | int gtkwgaim_gz_untar(const char* filename, const char* destdir) { | |
| 110 | char tmpfile[_MAX_PATH]; | |
| 111 | char template[]="wgaimXXXXXX"; | |
| 112 | ||
| 113 | sprintf(tmpfile, "%s%s%s", g_get_tmp_dir(), G_DIR_SEPARATOR_S, _mktemp(template)); | |
| 114 | if(gtkwgaim_gz_decompress(filename, tmpfile)) { | |
| 115 | int ret; | |
| 116 | if(untar(tmpfile, destdir, UNTAR_FORCE | UNTAR_QUIET)) | |
| 117 | ret = 1; | |
| 118 | else { | |
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
119 | gaim_debug_error("gtkwgaim_gz_untar", "Failure untaring %s\n", tmpfile); |
| 14286 | 120 | ret = 0; |
| 121 | } | |
| 122 | g_unlink(tmpfile); | |
| 123 | return ret; | |
| 124 | } | |
| 125 | else { | |
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
126 | gaim_debug_error("gtkwgaim_gz_untar", "Failed to gz decompress %s\n", filename); |
| 14286 | 127 | return 0; |
| 128 | } | |
| 129 | } | |
| 130 | ||
| 131 | void gtkwgaim_notify_uri(const char *uri) { | |
| 132 | ||
| 133 | /* We'll allow whatever URI schemes are supported by the | |
| 134 | * default http browser. | |
| 135 | */ | |
| 136 | ||
| 137 | if (G_WIN32_HAVE_WIDECHAR_API()) { | |
| 138 | SHELLEXECUTEINFOW wsinfo; | |
| 139 | wchar_t *w_uri; | |
| 140 | ||
| 141 | w_uri = g_utf8_to_utf16(uri, -1, NULL, NULL, NULL); | |
| 142 | ||
| 143 | memset(&wsinfo, 0, sizeof(wsinfo)); | |
| 144 | wsinfo.cbSize = sizeof(wsinfo); | |
| 145 | wsinfo.fMask = SEE_MASK_CLASSNAME; | |
| 146 | wsinfo.lpVerb = L"open"; | |
| 147 | wsinfo.lpFile = w_uri; | |
| 148 | wsinfo.nShow = SW_SHOWNORMAL; | |
| 149 | wsinfo.lpClass = L"http"; | |
| 150 | ||
| 151 | if(!ShellExecuteExW(&wsinfo)) | |
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
152 | gaim_debug_error("gtkwgaim", "Error opening URI: %s error: %d\n", |
| 14286 | 153 | uri, (int) wsinfo.hInstApp); |
| 154 | ||
| 155 | g_free(w_uri); | |
|
14636
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
156 | } else { |
| 14286 | 157 | SHELLEXECUTEINFOA sinfo; |
| 158 | gchar *locale_uri; | |
| 159 | ||
| 160 | locale_uri = g_locale_from_utf8(uri, -1, NULL, NULL, NULL); | |
| 161 | ||
| 162 | memset(&sinfo, 0, sizeof(sinfo)); | |
| 163 | sinfo.cbSize = sizeof(sinfo); | |
| 164 | sinfo.fMask = SEE_MASK_CLASSNAME; | |
| 165 | sinfo.lpVerb = "open"; | |
| 166 | sinfo.lpFile = locale_uri; | |
| 167 | sinfo.nShow = SW_SHOWNORMAL; | |
| 168 | sinfo.lpClass = "http"; | |
| 169 | ||
| 170 | if(!ShellExecuteExA(&sinfo)) | |
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
171 | gaim_debug_error("gtkwgaim", "Error opening URI: %s error: %d\n", |
| 14286 | 172 | uri, (int) sinfo.hInstApp); |
| 173 | ||
| 174 | g_free(locale_uri); | |
| 175 | } | |
| 176 | } | |
| 177 | ||
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
178 | #define WM_FOCUS_REQUEST (WM_APP + 13) |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
179 | |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
180 | static LRESULT CALLBACK message_window_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
181 | |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
182 | if (msg == WM_FOCUS_REQUEST) { |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
183 | gaim_debug_info("gtkwgaim", "Got external Buddy List focus request."); |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
184 | gaim_blist_set_visible(TRUE); |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
185 | return TRUE; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
186 | } |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
187 | |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
188 | return DefWindowProc(hwnd, msg, wparam, lparam); |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
189 | } |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
190 | |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
191 | static HWND wgaim_message_window_init(void) { |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
192 | HWND win_hwnd; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
193 | WNDCLASSEX wcx; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
194 | LPCTSTR wname; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
195 | |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
196 | wname = TEXT("WingaimMsgWinCls"); |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
197 | |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
198 | wcx.cbSize = sizeof(wcx); |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
199 | wcx.style = 0; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
200 | wcx.lpfnWndProc = message_window_handler; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
201 | wcx.cbClsExtra = 0; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
202 | wcx.cbWndExtra = 0; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
203 | wcx.hInstance = gtkwgaim_hinstance(); |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
204 | wcx.hIcon = NULL; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
205 | wcx.hCursor = NULL; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
206 | wcx.hbrBackground = NULL; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
207 | wcx.lpszMenuName = NULL; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
208 | wcx.lpszClassName = wname; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
209 | wcx.hIconSm = NULL; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
210 | |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
211 | RegisterClassEx(&wcx); |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
212 | |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
213 | /* Create the window */ |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
214 | if(!(win_hwnd = CreateWindow(wname, TEXT("WingaimMsgWin"), 0, 0, 0, 0, 0, |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
215 | NULL, NULL, gtkwgaim_hinstance(), 0))) { |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
216 | gaim_debug_error("gtkwgaim", |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
217 | "Unable to create message window.\n"); |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
218 | return NULL; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
219 | } |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
220 | |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
221 | return win_hwnd; |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
222 | } |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
223 | |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
224 | |
| 14286 | 225 | void gtkwgaim_init(HINSTANCE hint) { |
| 226 | gaim_debug_info("gtkwgaim", "gtkwgaim_init start\n"); | |
| 227 | ||
| 228 | gaimexe_hInstance = hint; | |
| 229 | ||
| 230 | /* IdleTracker Initialization */ | |
| 231 | if(!wgaim_set_idlehooks()) | |
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
232 | gaim_debug_error("gtkwgaim", "Failed to initialize idle tracker\n"); |
| 14286 | 233 | |
| 234 | wgaim_gtkspell_init(); | |
| 235 | gaim_debug_info("gtkwgaim", "GTK+ :%u.%u.%u\n", | |
| 236 | gtk_major_version, gtk_minor_version, gtk_micro_version); | |
| 237 | ||
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
238 | messagewin_hwnd = wgaim_message_window_init(); |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
239 | |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
240 | gaim_debug_info("gtkwgaim", "gtkwgaim_init end\n"); |
| 14286 | 241 | } |
| 242 | ||
| 243 | /* Windows Cleanup */ | |
| 244 | ||
| 245 | void gtkwgaim_cleanup(void) { | |
|
14319
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
246 | gaim_debug_info("gtkwgaim", "gtkwgaim_cleanup\n"); |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
247 | |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
248 | if(messagewin_hwnd) |
|
b9a35c4948dc
[gaim-migrate @ 16939]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
249 | DestroyWindow(messagewin_hwnd); |
| 14286 | 250 | |
| 251 | /* Idle tracker cleanup */ | |
| 252 | wgaim_remove_idlehooks(); | |
| 253 | ||
| 254 | } | |
| 255 | ||
| 256 | /* DLL initializer */ | |
|
14636
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
257 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { |
| 14286 | 258 | gtkgaimdll_hInstance = hinstDLL; |
| 259 | return TRUE; | |
| 260 | } | |
|
14636
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
261 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
262 | typedef HMONITOR WINAPI gaim_MonitorFromWindow(HWND, DWORD); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
263 | typedef BOOL WINAPI gaim_GetMonitorInfo(HMONITOR, LPMONITORINFO); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
264 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
265 | static gboolean |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
266 | get_WorkingAreaRectForWindow(HWND hwnd, RECT *workingAreaRc) { |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
267 | static gaim_MonitorFromWindow *the_MonitorFromWindow; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
268 | static gaim_GetMonitorInfo *the_GetMonitorInfo; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
269 | static gboolean initialized = FALSE; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
270 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
271 | HMONITOR monitor; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
272 | MONITORINFO info; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
273 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
274 | if(!initialized) { |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
275 | the_MonitorFromWindow = (gaim_MonitorFromWindow*) |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
276 | wgaim_find_and_loadproc("user32", "MonitorFromWindow"); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
277 | the_GetMonitorInfo = (gaim_GetMonitorInfo*) |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
278 | wgaim_find_and_loadproc("user32", "GetMonitorInfoA"); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
279 | initialized = TRUE; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
280 | } |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
281 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
282 | if(!the_MonitorFromWindow) |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
283 | return FALSE; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
284 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
285 | if(!the_GetMonitorInfo) |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
286 | return FALSE; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
287 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
288 | monitor = the_MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
289 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
290 | info.cbSize = sizeof(info); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
291 | if(!the_GetMonitorInfo(monitor, &info)) |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
292 | return FALSE; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
293 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
294 | CopyRect(workingAreaRc, &(info.rcWork)); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
295 | return TRUE; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
296 | } |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
297 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
298 | void gtkwgaim_ensure_onscreen(GtkWidget *win) { |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
299 | RECT windowRect, workingAreaRect, intersectionRect; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
300 | HWND hwnd = GDK_WINDOW_HWND(win->window); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
301 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
302 | g_return_if_fail(hwnd != NULL); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
303 | GetWindowRect(hwnd, &windowRect); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
304 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
305 | gaim_debug_info("win32placement", |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
306 | "Window RECT: L:%ld R:%ld T:%ld B:%ld\n", |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
307 | windowRect.left, windowRect.right, |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
308 | windowRect.top, windowRect.bottom); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
309 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
310 | if(!get_WorkingAreaRectForWindow(hwnd, &workingAreaRect)) { |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
311 | gaim_debug_info("win32placement", |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
312 | "Couldn't get multimonitor working area\n"); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
313 | if(!SystemParametersInfo(SPI_GETWORKAREA, 0, &workingAreaRect, FALSE)) { |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
314 | /* I don't think this will ever happen */ |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
315 | workingAreaRect.left = 0; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
316 | workingAreaRect.top = 0; |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
317 | workingAreaRect.bottom = GetSystemMetrics(SM_CYSCREEN); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
318 | workingAreaRect.right = GetSystemMetrics(SM_CXSCREEN); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
319 | } |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
320 | } |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
321 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
322 | gaim_debug_info("win32placement", |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
323 | "Working Area RECT: L:%ld R:%ld T:%ld B:%ld\n", |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
324 | workingAreaRect.left, workingAreaRect.right, |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
325 | workingAreaRect.top, workingAreaRect.bottom); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
326 | |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
327 | /** If the conversation window doesn't intersect perfectly with the working area, |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
328 | * move it to the top left corner of the working area */ |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
329 | if(!(IntersectRect(&intersectionRect, &windowRect, &workingAreaRect) |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
330 | && EqualRect(&intersectionRect, &windowRect))) { |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
331 | gaim_debug_info("win32placement", |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
332 | "conversation window out of working area, relocating\n"); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
333 | MoveWindow(hwnd, workingAreaRect.left, workingAreaRect.top, |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
334 | (windowRect.right - windowRect.left), |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
335 | (windowRect.bottom - windowRect.top), TRUE); |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
336 | } |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
337 | } |
|
5306c329992c
[gaim-migrate @ 17298]
Daniel Atallah <datallah@pidgin.im>
parents:
14319
diff
changeset
|
338 |