2
* Miro - an RSS based video player application
3
* Copyright (C) 2005-2009 Participatory Culture Foundation
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* In addition, as a special exception, the copyright holders give
20
* permission to link the code of portions of this program with the OpenSSL
23
* You must obey the GNU General Public License in all respects for all of
24
* the code used other than OpenSSL. If you modify file(s) with this
25
* exception, you may extend this exception to your version of the file(s),
26
* but you are not obligated to do so. If you do not wish to do so, delete
27
* this exception statement from your version. If you delete this exception
28
* statement from all source files in the program, then also delete it here.
39
* Fix focus problems between GTK and XULRunner. GTK likes to keep it's
40
* top-level window focused and handle which widget is focused internally.
41
* XULRunner just let's child windows get focus.
47
* Override the Window proc for top-level GTK windows that contain an embedded
48
* XULRunnerBrowser. This is needed because GTK's focus model is much
49
* different than XULRunner's.
51
LRESULT CALLBACK ToplevelFocusHackWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
54
GdkWindow* window = gdk_window_lookup((GdkNativeWindow)hwnd);
55
WNDPROC old_window_proc = (WNDPROC)GetProp(hwnd,
56
"ToplevelFocusHackOldProc");
58
if (!old_window_proc) {
59
return DefWindowProc(hwnd, uMsg, wParam, lParam);
61
return CallWindowProc(old_window_proc, hwnd, uMsg, wParam, lParam);
66
case WM_MOUSEACTIVATE:
67
// Mouse click on a non-browser widget. Ensure that the top-level
68
// window has the keyboard focus.
69
// (We know it can't be a browser widget, because we handle
70
// WM_MOUSEACTIVATE in BrowserFocusHackWndProc()).
71
gdk_window_focus(window, 0);
75
// GTK's toplevel window is losing focus to a child window.
76
// This is probably a XULRunner window. Handle the event so that
77
// the window doesn't think it's lost focus.
78
if (wParam && IsChild(hwnd, (HWND)wParam)) {
85
// The Window is about to be destroyed -- Cleanup
86
SetWindowLongPtr(hwnd, GWL_WNDPROC, (LONG_PTR)old_window_proc);
87
RemoveProp(hwnd, "ToplevelFocusHackOldProc");
90
return CallWindowProc(old_window_proc, hwnd, uMsg, wParam, lParam);
93
LRESULT CALLBACK BrowserFocusHackWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
97
WNDPROC old_window_proc = (WNDPROC)GetProp(hwnd,
98
"BrowserFocusHackOldProc");
99
if (!old_window_proc) {
100
return DefWindowProc(hwnd, uMsg, wParam, lParam);
103
case WM_MOUSEACTIVATE:
104
// The user clicked on a xulrunner browser. Have the GTK widget
107
// NOTE: the window that we are handling messages for is the child
108
// ofthe actual GTK widget. See browser.py for info on why this
110
parent = GetParent(hwnd);
112
window = gdk_window_lookup((GdkNativeWindow)parent);
114
GtkWidget* browser_widget;
115
gdk_window_get_user_data(window, (gpointer*)&browser_widget);
116
if (browser_widget) {
117
gtk_widget_grab_focus(browser_widget);
123
// The Window is about to be destroyed -- Cleanup
124
SetWindowLongPtr(hwnd, GWL_WNDPROC, (LONG_PTR)old_window_proc);
125
RemoveProp(hwnd, "BrowserFocusHackOldProc");
128
return CallWindowProc(old_window_proc, hwnd, uMsg, wParam, lParam);
131
static void install_toplevel_focus_fix(HWND hwnd)
133
HWND root_window = GetAncestor(hwnd, GA_ROOT);
134
if (GetProp(root_window, "ToplevelFocusHackOldProc") != NULL) {
135
/* We already installed the fix, maybe there are 2 browser's
139
WNDPROC old_proc = (WNDPROC) SetWindowLongPtr(root_window,
140
GWL_WNDPROC, (LONG_PTR)ToplevelFocusHackWndProc);
141
SetProp(root_window,"ToplevelFocusHackOldProc", (void *)old_proc);
145
static void install_browser_focus_fix(HWND hwnd)
148
WNDPROC old_proc = (WNDPROC) SetWindowLongPtr(hwnd,
149
GWL_WNDPROC, (LONG_PTR)BrowserFocusHackWndProc);
150
SetProp(hwnd, "BrowserFocusHackOldProc", (HANDLE)old_proc);
153
void install_focus_fixes(HWND hwnd)
155
install_toplevel_focus_fix(hwnd);
156
install_browser_focus_fix(hwnd);