| /******************************************************************************* |
| * 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) { |
| } |
| } |