1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*******************************************************************************
* Copyright (c) 2003, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.browser;
import org.eclipse.swt.SWT;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.gtk.GTK;
import org.eclipse.swt.widgets.*;
class MozillaDelegate {
Browser browser;
static boolean gtkLoaded;
static boolean IsLinux;
static {
String osName = System.getProperty ("os.name").toLowerCase (); //$NON-NLS-1$
IsLinux = osName.startsWith ("linux"); //$NON-NLS-1$
}
MozillaDelegate (Browser browser) {
super ();
if (!IsLinux) {
browser.dispose ();
SWT.error (SWT.ERROR_NO_HANDLES, null, " [Unsupported platform]"); //$NON-NLS-1$
}
this.browser = browser;
if (!gtkLoaded) {
gtkLoaded = true;
try {
Library.loadLibrary ("swt-gtk"); //$NON-NLS-1$
} catch (UnsatisfiedLinkError e) {
browser.dispose ();
SWT.error (SWT.ERROR_NO_HANDLES, e);
}
}
}
static Browser findBrowser (int handle) {
Display display = Display.getCurrent ();
Shell[] shells = display.getShells ();
Browser browser = null;
for (int i = 0; i < shells.length; i++) {
browser = findBrowser (shells[i], handle);
if (browser != null) break;
}
return browser;
}
static Browser findBrowser (Control control, int gtkHandle) {
if (control instanceof Browser) {
Browser browser = (Browser)control;
WebBrowser webBrowser = browser.webBrowser;
if (webBrowser instanceof Mozilla) {
if (((Mozilla)webBrowser).embedHandle == gtkHandle) return browser;
}
}
if (control instanceof Composite) {
Composite composite = (Composite)control;
Control[] children = composite.getChildren ();
for (int i = 0; i < children.length; i++) {
Browser browser = findBrowser (children[i], gtkHandle);
if (browser != null) return browser;
}
}
return null;
}
public static char[] mbcsToWcs (String codePage, byte [] buffer) {
return Converter.mbcsToWcs (codePage, buffer);
}
public static byte[] wcsToMbcs (String codePage, String string, boolean terminate) {
return Converter.wcsToMbcs (codePage, string, terminate);
}
int getHandle() {
if (Mozilla.BrowserCount == 1) {
GTK.gtk_init_check (new int[1], null);
final Display display = browser.getDisplay ();
display.asyncExec (new Runnable () {
public void run () {
if (Mozilla.BrowserCount == 0) return;
while (GTK.gtk_events_pending () != 0) {
GTK.gtk_main_iteration ();
}
display.timerExec (25, this);
}
});
}
browser.getShell ().setFocus ();
int result = GTK.gtk_plug_new (browser.embeddedHandle);
GTK.gtk_widget_show (result);
return result;
}
void onDispose (int embedHandle) {
GTK.gtk_widget_destroy (embedHandle);
while (GTK.gtk_events_pending () != 0) {
GTK.gtk_main_iteration ();
}
}
void setSize(int embedHandle, int width, int height) {
// TODO?
}
}
|