Mercurial > projects > dwt-mac
diff dwt/browser/MozillaDelegate.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | e831403a80a9 f565d3a95c0a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/browser/MozillaDelegate.d Sat Aug 09 17:00:02 2008 +0200 @@ -0,0 +1,146 @@ +/******************************************************************************* + * 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 + * + * Port to the D Programming language: + * Jacob Carlborg <jacob.carlborg@gmail.com> + *******************************************************************************/ +module dwt.browser.MozillaDelegate; + +import dwt.DWT; +import dwt.browser.Browser; +import dwt.dwthelper.string; +import dwt.dwthelper.utils; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Listener; + +class MozillaDelegate { + Browser browser; + Listener listener; + bool hasFocus; + + this (Browser browser) { + super(); + this.browser = browser; + } + + static Browser findBrowser (int handle) { + Display display = Display.getCurrent(); + return cast(Browser) display.findWidget(handle); + } + + static char[] mbcsToWcs (String codePage, byte[] buffer) { + // int encoding = OS.CFStringGetSystemEncoding (); + // int cfString = OS.CFStringCreateWithBytes (OS.kCFAllocatorDefault, buffer, buffer.length, encoding, false); + // char[] chars = null; + // if (cfString !is 0) { + // int length = OS.CFStringGetLength (cfString); + // chars = new char [length]; + // if (length !is 0) { + // CFRange range = new CFRange (); + // range.length = length; + // OS.CFStringGetCharacters (cfString, range, chars); + // } + // OS.CFRelease (cfString); + // } + // return chars; + + //return new String(buffer).toCharArray(); commented by Jacob Carlborg + return cast(char[]) buffer.dup; // FIXME + } + + static byte[] wcsToMbcs (String codePage, String str, bool terminate) { + // char[] chars = new char [String.length()]; + // String.getChars (0, chars.length, chars, 0); + // int cfString = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, chars, chars.length); + // byte[] buffer = null; + // if (cfString !is 0) { + // CFRange range = new CFRange (); + // range.length = chars.length; + // int encoding = OS.CFStringGetSystemEncoding (); + // int[] size = new int[1]; + // int numChars = OS.CFStringGetBytes (cfString, range, encoding, (byte)'?', true, null, 0, size); + // buffer = new byte [size[0] + (terminate ? 1 : 0)]; + // if (numChars !is 0) { + // numChars = OS.CFStringGetBytes (cfString, range, encoding, (byte)'?', true, buffer, size[0], size); + // } + // OS.CFRelease (cfString); + // } + // return buffer; + if (terminate) + str ~= "\0"; + + //return str.getBytes(); commented by Jacob Carlborg + return cast(byte[]) str.dup; // FIXME + } + + int getHandle () { + return browser.view.id; + } + + String getLibraryName () { + return "libxpcom.dylib"; //$NON-NLS-1$ + } + + String getDWTInitLibraryName () { + return "swt-xulrunner"; //$NON-NLS-1$ + } + + void handleFocus () { + if (hasFocus) + return; + hasFocus = true; + (cast(Mozilla) browser.webBrowser).Activate(); + browser.setFocus(); + listener = new class Listener { + public void handleEvent (Event event) { + if (event.widget == browser) + return; + + (cast(Mozilla) browser.webBrowser).Deactivate(); + hasFocus = false; + browser.getDisplay().removeFilter(DWT.FocusIn, this); + browser.getShell().removeListener(DWT.Deactivate, this); + listener = null; + } + + }; + browser.getDisplay().addFilter(DWT.FocusIn, listener); + browser.getShell().addListener(DWT.Deactivate, listener); + } + + void handleMouseDown () { + } + + bool hookEnterExit () { + return true; + } + + void init () { + } + + bool needsSpinup () { + return false; + } + + void onDispose (int embedHandle) { + if (listener !is null) { + browser.getDisplay().removeFilter(DWT.FocusIn, listener); + browser.getShell().removeListener(DWT.Deactivate, listener); + listener = null; + } + browser = null; + } + + void setSize (int embedHandle, int width, int height) { + // TODO + } + +}