comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:380af2bdd8e5
1 /*******************************************************************************
2 * Copyright (c) 2003, 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *
11 * Port to the D Programming language:
12 * Jacob Carlborg <jacob.carlborg@gmail.com>
13 *******************************************************************************/
14 module dwt.browser.MozillaDelegate;
15
16 import dwt.DWT;
17 import dwt.browser.Browser;
18 import dwt.dwthelper.string;
19 import dwt.dwthelper.utils;
20 import dwt.widgets.Display;
21 import dwt.widgets.Event;
22 import dwt.widgets.Listener;
23
24 class MozillaDelegate {
25 Browser browser;
26 Listener listener;
27 bool hasFocus;
28
29 this (Browser browser) {
30 super();
31 this.browser = browser;
32 }
33
34 static Browser findBrowser (int handle) {
35 Display display = Display.getCurrent();
36 return cast(Browser) display.findWidget(handle);
37 }
38
39 static char[] mbcsToWcs (String codePage, byte[] buffer) {
40 // int encoding = OS.CFStringGetSystemEncoding ();
41 // int cfString = OS.CFStringCreateWithBytes (OS.kCFAllocatorDefault, buffer, buffer.length, encoding, false);
42 // char[] chars = null;
43 // if (cfString !is 0) {
44 // int length = OS.CFStringGetLength (cfString);
45 // chars = new char [length];
46 // if (length !is 0) {
47 // CFRange range = new CFRange ();
48 // range.length = length;
49 // OS.CFStringGetCharacters (cfString, range, chars);
50 // }
51 // OS.CFRelease (cfString);
52 // }
53 // return chars;
54
55 //return new String(buffer).toCharArray(); commented by Jacob Carlborg
56 return cast(char[]) buffer.dup; // FIXME
57 }
58
59 static byte[] wcsToMbcs (String codePage, String str, bool terminate) {
60 // char[] chars = new char [String.length()];
61 // String.getChars (0, chars.length, chars, 0);
62 // int cfString = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, chars, chars.length);
63 // byte[] buffer = null;
64 // if (cfString !is 0) {
65 // CFRange range = new CFRange ();
66 // range.length = chars.length;
67 // int encoding = OS.CFStringGetSystemEncoding ();
68 // int[] size = new int[1];
69 // int numChars = OS.CFStringGetBytes (cfString, range, encoding, (byte)'?', true, null, 0, size);
70 // buffer = new byte [size[0] + (terminate ? 1 : 0)];
71 // if (numChars !is 0) {
72 // numChars = OS.CFStringGetBytes (cfString, range, encoding, (byte)'?', true, buffer, size[0], size);
73 // }
74 // OS.CFRelease (cfString);
75 // }
76 // return buffer;
77 if (terminate)
78 str ~= "\0";
79
80 //return str.getBytes(); commented by Jacob Carlborg
81 return cast(byte[]) str.dup; // FIXME
82 }
83
84 int getHandle () {
85 return browser.view.id;
86 }
87
88 String getLibraryName () {
89 return "libxpcom.dylib"; //$NON-NLS-1$
90 }
91
92 String getDWTInitLibraryName () {
93 return "swt-xulrunner"; //$NON-NLS-1$
94 }
95
96 void handleFocus () {
97 if (hasFocus)
98 return;
99 hasFocus = true;
100 (cast(Mozilla) browser.webBrowser).Activate();
101 browser.setFocus();
102 listener = new class Listener {
103 public void handleEvent (Event event) {
104 if (event.widget == browser)
105 return;
106
107 (cast(Mozilla) browser.webBrowser).Deactivate();
108 hasFocus = false;
109 browser.getDisplay().removeFilter(DWT.FocusIn, this);
110 browser.getShell().removeListener(DWT.Deactivate, this);
111 listener = null;
112 }
113
114 };
115 browser.getDisplay().addFilter(DWT.FocusIn, listener);
116 browser.getShell().addListener(DWT.Deactivate, listener);
117 }
118
119 void handleMouseDown () {
120 }
121
122 bool hookEnterExit () {
123 return true;
124 }
125
126 void init () {
127 }
128
129 bool needsSpinup () {
130 return false;
131 }
132
133 void onDispose (int embedHandle) {
134 if (listener !is null) {
135 browser.getDisplay().removeFilter(DWT.FocusIn, listener);
136 browser.getShell().removeListener(DWT.Deactivate, listener);
137 listener = null;
138 }
139 browser = null;
140 }
141
142 void setSize (int embedHandle, int width, int height) {
143 // TODO
144 }
145
146 }