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