comparison dwt/browser/MozillaDelegate.d @ 286:44258e0b6687

More fixes for xpcom
author John Reimer<terminal.node@gmail.com>
date Tue, 05 Aug 2008 10:11:58 -0700
parents 93409d9838c5
children 3f4a5c7d138f
comparison
equal deleted inserted replaced
280:e72345914350 286:44258e0b6687
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * John Reimer <terminal.node@gmail.com>
10 *******************************************************************************/ 12 *******************************************************************************/
11 module dwt.browser.MozillaDelegate; 13 module dwt.browser.MozillaDelegate;
12 14
13 import dwt.dwthelper.utils; 15 import dwt.dwthelper.utils;
14 16
22 import dwt.widgets.Listener; 24 import dwt.widgets.Listener;
23 import dwt.widgets.Widget; 25 import dwt.widgets.Widget;
24 26
25 class MozillaDelegate { 27 class MozillaDelegate {
26 Browser browser; 28 Browser browser;
27 int /*long*/ mozillaHandle, embedHandle; 29 gpointer mozillaHandle;
30 GtkWidget* embedHandle;
28 bool hasFocus; 31 bool hasFocus;
29 Listener listener; 32 Listener listener;
30 static Callback eventCallback; 33 //static Callback eventCallback;
31 static int /*long*/ eventProc; 34 // static int /*long*/ eventProc;
32 static final int STOP_PROPOGATE = 1; 35 static const gpointer STOP_PROPOGATE = cast(gpointer)1;
33 36
34 static bool IsLinux; 37 static bool IsLinux;
35 static { 38 static this {
36 String osName = System.getProperty ("os.name").toLowerCase (); //$NON-NLS-1$ 39 String osName = System.getProperty ("os.name"); //$NON-NLS-1$
37 IsLinux = osName.startsWith ("linux"); //$NON-NLS-1$ 40 IsLinux = tango.text.Util.containsPattern(osName, "linux"); //$NON-NLS-1$
38 } 41 }
39 42
40 MozillaDelegate (Browser browser) { 43 this (Browser browser) {
41 super (); 44 super ();
42 if (!IsLinux) { 45 if (!IsLinux) {
43 browser.dispose (); 46 browser.dispose ();
44 DWT.error (DWT.ERROR_NO_HANDLES, null, " [Unsupported platform]"); //$NON-NLS-1$ 47 DWT.error (DWT.ERROR_NO_HANDLES, null, " [Unsupported platform]"); //$NON-NLS-1$
45 } 48 }
46 this.browser = browser; 49 this.browser = browser;
47 } 50 }
48 51
49 static int /*long*/ eventProc (int /*long*/ handle, int /*long*/ gdkEvent, int /*long*/ pointer) { 52 static extern(C) int eventProc (GtkWidget* handle, GdkEvent* gdkEvent, gpointer pointer) {
50 int /*long*/ parent = OS.gtk_widget_get_parent (handle); 53 GtkWidget* parent = OS.gtk_widget_get_parent (handle);
51 parent = OS.gtk_widget_get_parent (parent); 54 parent = OS.gtk_widget_get_parent (parent);
52 if (parent is 0) return 0; 55 if (parent is null) return 0;
53 Widget widget = Display.getCurrent ().findWidget (parent); 56 Widget widget = Display.getCurrent ().findWidget (parent);
54 if (widget !is null && widget instanceof Browser) { 57 if (widget !is null && (cast(Browser)widget !is null) {
55 return ((Mozilla)((Browser)widget).webBrowser).delegate.gtk_event (handle, gdkEvent, pointer); 58 return (cast(Mozilla)(cast(Browser)widget).webBrowser).mozDelegate.gtk_event (handle, gdkEvent, pointer);
56 } 59 }
57 return 0; 60 return 0;
58 } 61 }
59 62
60 static Browser findBrowser (int /*long*/ handle) { 63 static Browser findBrowser (GtkWidget* handle) {
61 /* 64 /*
62 * Note. On GTK, Mozilla is embedded into a GtkHBox handle 65 * Note. On GTK, Mozilla is embedded into a GtkHBox handle
63 * and not directly into the parent Composite handle. 66 * and not directly into the parent Composite handle.
64 */ 67 */
65 int /*long*/ parent = OS.gtk_widget_get_parent (handle); 68 GtkWidget* parent = OS.gtk_widget_get_parent (handle);
66 Display display = Display.getCurrent (); 69 Display display = Display.getCurrent ();
67 return (Browser)display.findWidget (parent); 70 return cast(Browser)display.findWidget (parent);
68 } 71 }
69 72 /*
70 static char[] mbcsToWcs (String codePage, byte [] buffer) { 73 static char[] mbcsToWcs (String codePage, byte [] buffer) {
71 return Converter.mbcsToWcs (codePage, buffer); 74 return Converter.mbcsToWcs (codePage, buffer);
72 } 75 }
73 76
74 static byte[] wcsToMbcs (String codePage, String string, bool terminate) { 77 static byte[] wcsToMbcs (String codePage, String string, bool terminate) {
75 return Converter.wcsToMbcs (codePage, string, terminate); 78 return Converter.wcsToMbcs (codePage, string, terminate);
76 } 79 }
77 80 */
78 int /*long*/ getHandle () { 81 GtkWidget* getHandle () {
79 /* 82 /*
80 * Bug in Mozilla Linux GTK. Embedding Mozilla into a GtkFixed 83 * Bug in Mozilla Linux GTK. Embedding Mozilla into a GtkFixed
81 * handle causes problems with some Mozilla plug-ins. For some 84 * handle causes problems with some Mozilla plug-ins. For some
82 * reason, the Flash plug-in causes the child of the GtkFixed 85 * reason, the Flash plug-in causes the child of the GtkFixed
83 * handle to be resized to 1 when the Flash document is loaded. 86 * handle to be resized to 1 when the Flash document is loaded.
94 97
95 String getLibraryName () { 98 String getLibraryName () {
96 return "libxpcom.so"; //$NON-NLS-1$ 99 return "libxpcom.so"; //$NON-NLS-1$
97 } 100 }
98 101
102 /*
99 String getSWTInitLibraryName () { 103 String getSWTInitLibraryName () {
100 return "swt-xpcominit"; //$NON-NLS-1$ 104 return "swt-xpcominit"; //$NON-NLS-1$
101 } 105 }
102 106 */
103 int /*long*/ gtk_event (int /*long*/ handle, int /*long*/ gdkEvent, int /*long*/ pointer) { 107
104 GdkEvent event = new GdkEvent (); 108 int gtk_event (GtkWidget* handle, GdkEvent* event, gpointer pointer) {
105 OS.memmove (event, gdkEvent, GdkEvent.sizeof);
106 if (event.type is OS.GDK_BUTTON_PRESS) { 109 if (event.type is OS.GDK_BUTTON_PRESS) {
107 if (!hasFocus) browser.setFocus (); 110 if (!hasFocus) browser.setFocus ();
108 } 111 }
109 112
110 /* 113 /*
119 if (hasFocus) return; 122 if (hasFocus) return;
120 hasFocus = true; 123 hasFocus = true;
121 listener = new Listener () { 124 listener = new Listener () {
122 public void handleEvent (Event event) { 125 public void handleEvent (Event event) {
123 if (event.widget is browser) return; 126 if (event.widget is browser) return;
124 ((Mozilla)browser.webBrowser).Deactivate (); 127 (cast(Mozilla)(browser.webBrowser)).Deactivate ();
125 hasFocus = false; 128 hasFocus = false;
126 browser.getDisplay ().removeFilter (DWT.FocusIn, this); 129 browser.getDisplay ().removeFilter (DWT.FocusIn, this);
127 browser.getShell ().removeListener (DWT.Deactivate, this); 130 browser.getShell ().removeListener (DWT.Deactivate, this);
128 listener = null; 131 listener = null;
129 } 132 }
136 int shellStyle = browser.getShell ().getStyle (); 139 int shellStyle = browser.getShell ().getStyle ();
137 if ((shellStyle & DWT.ON_TOP) !is 0 && (((shellStyle & DWT.NO_FOCUS) is 0) || ((browser.getStyle () & DWT.NO_FOCUS) is 0))) { 140 if ((shellStyle & DWT.ON_TOP) !is 0 && (((shellStyle & DWT.NO_FOCUS) is 0) || ((browser.getStyle () & DWT.NO_FOCUS) is 0))) {
138 browser.getDisplay ().asyncExec (new Runnable () { 141 browser.getDisplay ().asyncExec (new Runnable () {
139 public void run () { 142 public void run () {
140 if (browser is null || browser.isDisposed ()) return; 143 if (browser is null || browser.isDisposed ()) return;
141 ((Mozilla)browser.webBrowser).Activate (); 144 (cast(Mozilla)(browser.webBrowser)).Activate ();
142 } 145 }
143 }); 146 });
144 } 147 }
145 } 148 }
146 149
147 bool hookEnterExit () { 150 bool hookEnterExit () {
148 return false; 151 return false;
149 } 152 }
150 153
151 void init () { 154 void init () { /*
152 if (eventCallback is null) { 155 if (eventCallback is null) {
153 eventCallback = new Callback (getClass (), "eventProc", 3); //$NON-NLS-1$ 156 eventCallback = new Callback (getClass (), "eventProc", 3); //$NON-NLS-1$
154 eventProc = eventCallback.getAddress (); 157 eventProc = eventCallback.getAddress ();
155 if (eventProc is 0) { 158 if (eventProc is null) {
156 browser.dispose (); 159 browser.dispose ();
157 Mozilla.error (DWT.ERROR_NO_MORE_CALLBACKS); 160 Mozilla.error (DWT.ERROR_NO_MORE_CALLBACKS);
158 } 161 }
159 } 162 } */
160 163
161 /* 164 /*
162 * Feature in Mozilla. GtkEvents such as key down, key pressed may be consumed 165 * Feature in Mozilla. GtkEvents such as key down, key pressed may be consumed
163 * by Mozilla and never be received by the parent embedder. The workaround 166 * by Mozilla and never be received by the parent embedder. The workaround
164 * is to find the top Mozilla gtk widget that receives all the Mozilla GtkEvents, 167 * is to find the top Mozilla gtk widget that receives all the Mozilla GtkEvents,
165 * i.e. the first child of the parent embedder. Then hook event callbacks and 168 * i.e. the first child of the parent embedder. Then hook event callbacks and
166 * forward the event to the parent embedder before Mozilla received and consumed 169 * forward the event to the parent embedder before Mozilla received and consumed
167 * them. 170 * them.
168 */ 171 */
169 int /*long*/ list = OS.gtk_container_get_children (embedHandle); 172 GList* list = OS.gtk_container_get_children (embedHandle);
170 if (list !is 0) { 173 if (list !is null) {
171 mozillaHandle = OS.g_list_data (list); 174 mozillaHandle = OS.g_list_data (list);
172 OS.g_list_free (list); 175 OS.g_list_free (list);
173 176
174 if (mozillaHandle !is 0) { 177 if (mozillaHandle !is null) {
175 /* Note. Callback to get events before Mozilla receives and consumes them. */ 178 /* Note. Callback to get events before Mozilla receives and consumes them. */
176 OS.g_signal_connect (mozillaHandle, OS.event, eventProc, 0); 179 OS.g_signal_connect (mozillaHandle, OS.event, cast(GCallback)&eventProc, null);
177 180
178 /* 181 /*
179 * Note. Callback to get the events not consumed by Mozilla - and to block 182 * Note. Callback to get the events not consumed by Mozilla - and to block
180 * them so that they don't get propagated to the parent handle twice. 183 * them so that they don't get propagated to the parent handle twice.
181 * This hook is set after Mozilla and is therefore called after Mozilla's 184 * This hook is set after Mozilla and is therefore called after Mozilla's
182 * handler because GTK dispatches events in their order of registration. 185 * handler because GTK dispatches events in their order of registration.
183 */ 186 */
184 OS.g_signal_connect (mozillaHandle, OS.key_press_event, eventProc, STOP_PROPOGATE); 187 OS.g_signal_connect (mozillaHandle, OS.key_press_event, cast(GCallback)&eventProc, STOP_PROPOGATE);
185 OS.g_signal_connect (mozillaHandle, OS.key_release_event, eventProc, STOP_PROPOGATE); 188 OS.g_signal_connect (mozillaHandle, OS.key_release_event, cast(GCallback)&eventProc, STOP_PROPOGATE);
186 OS.g_signal_connect (mozillaHandle, OS.button_press_event, eventProc, STOP_PROPOGATE); 189 OS.g_signal_connect (mozillaHandle, OS.button_press_event, cast(GCallback)&eventProc, STOP_PROPOGATE);
187 } 190 }
188 } 191 }
189 } 192 }
190 193
191 bool needsSpinup () { 194 bool needsSpinup () {
199 listener = null; 202 listener = null;
200 } 203 }
201 browser = null; 204 browser = null;
202 } 205 }
203 206
204 void setSize (int /*long*/ embedHandle, int width, int height) { 207 void setSize (GtkWidget* embedHandle, int width, int height) {
205 OS.gtk_widget_set_size_request (embedHandle, width, height); 208 OS.gtk_widget_set_size_request (embedHandle, width, height);
206 } 209 }
207 210
208 } 211 }