97
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 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 module dwt.ole.win32.OleControlSite;
|
|
12
|
|
13 import dwt.DWT;
|
|
14 import dwt.DWTError;
|
|
15 import dwt.DWTException;
|
|
16 import dwt.graphics.Color;
|
|
17 import dwt.graphics.Font;
|
|
18 import dwt.graphics.FontData;
|
|
19 import dwt.internal.ole.win32.COM;
|
|
20 import dwt.internal.win32.OS;
|
|
21 import dwt.widgets.Composite;
|
|
22 import dwt.widgets.Event;
|
|
23
|
|
24 import dwt.ole.win32.OleClientSite;
|
|
25
|
|
26 class OleControlSite : OleClientSite {
|
|
27 }
|
|
28 /++
|
|
29 /**
|
|
30 * OleControlSite provides a site to manage an embedded ActiveX Control within a container.
|
|
31 *
|
|
32 * <p>In addition to the behaviour provided by OleClientSite, this object provides the following:
|
|
33 * <ul>
|
|
34 * <li>events from the ActiveX control
|
|
35 * <li>notification of property changes from the ActiveX control
|
|
36 * <li>simplified access to well known properties of the ActiveX Control (e.g. font, background color)
|
|
37 * <li>expose ambient properties of the container to the ActiveX Control
|
|
38 * </ul>
|
|
39 *
|
|
40 * <p>This object implements the OLE Interfaces IOleControlSite, IDispatch, and IPropertyNotifySink.
|
|
41 *
|
|
42 * <p>Note that although this class is a subclass of <code>Composite</code>,
|
|
43 * it does not make sense to add <code>Control</code> children to it,
|
|
44 * or set a layout on it.
|
|
45 * </p><p>
|
|
46 * <dl>
|
|
47 * <dt><b>Styles</b> <dd>BORDER
|
|
48 * <dt><b>Events</b> <dd>Dispose, Move, Resize
|
|
49 * </dl>
|
|
50 *
|
|
51 */
|
|
52 public class OleControlSite extends OleClientSite
|
|
53 {
|
|
54 // interfaces for this container
|
|
55 private COMObject iOleControlSite;
|
|
56 private COMObject iDispatch;
|
|
57
|
|
58 // supporting Property Change attributes
|
|
59 private OlePropertyChangeSink olePropertyChangeSink;
|
|
60
|
|
61 // supporting Event Sink attributes
|
|
62 private OleEventSink[] oleEventSink = new OleEventSink[0];
|
|
63 private GUID[] oleEventSinkGUID = new GUID[0];
|
|
64 private int[] oleEventSinkIUnknown = new int[0];
|
|
65
|
|
66 // supporting information for the Control COM object
|
|
67 private CONTROLINFO currentControlInfo;
|
|
68 private int[] sitePropertyIds = new int[0];
|
|
69 private Variant[] sitePropertyValues = new Variant[0];
|
|
70
|
|
71 // work around for IE destroying the caret
|
|
72 static int SWT_RESTORECARET;
|
|
73
|
|
74 /**
|
|
75 * Create an OleControlSite child widget using style bits
|
|
76 * to select a particular look or set of properties.
|
|
77 *
|
|
78 * @param parent a composite widget; must be an OleFrame
|
|
79 * @param style the bitwise OR'ing of widget styles
|
|
80 * @param progId the unique program identifier which has been registered for this ActiveX Control;
|
|
81 * the value of the ProgID key or the value of the VersionIndependentProgID key specified
|
|
82 * in the registry for this Control (for example, the VersionIndependentProgID for
|
|
83 * Internet Explorer is Shell.Explorer)
|
|
84 *
|
|
85 *@exception IllegalArgumentException <ul>
|
|
86 * <li>ERROR_NULL_ARGUMENT when the parent is null
|
|
87 *</ul>
|
|
88 * @exception DWTException <ul>
|
|
89 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
|
|
90 * <li>ERROR_INVALID_CLASSID when the progId does not map to a registered CLSID
|
|
91 * <li>ERROR_CANNOT_CREATE_OBJECT when failed to create OLE Object
|
|
92 * <li>ERROR_CANNOT_ACCESS_CLASSFACTORY when Class Factory could not be found
|
|
93 * <li>ERROR_CANNOT_CREATE_LICENSED_OBJECT when failed to create a licensed OLE Object
|
|
94 * </ul>
|
|
95 */
|
|
96 public OleControlSite(Composite parent, int style, String progId) {
|
|
97 super(parent, style);
|
|
98 try {
|
|
99
|
|
100 // check for licensing
|
|
101 appClsid = getClassID(progId);
|
|
102 if (appClsid is null) OLE.error(OLE.ERROR_INVALID_CLASSID);
|
|
103
|
|
104 int licinfo = getLicenseInfo(appClsid);
|
|
105 if (licinfo is 0) {
|
|
106
|
|
107 // Open a storage object
|
|
108 tempStorage = createTempStorage();
|
|
109
|
|
110 // Create ole object with storage object
|
|
111 int[] address = new int[1];
|
|
112 int result = COM.OleCreate(appClsid, COM.IIDIUnknown, COM.OLERENDER_DRAW, null, 0, tempStorage.getAddress(), address);
|
|
113 if (result !is COM.S_OK)
|
|
114 OLE.error(OLE.ERROR_CANNOT_CREATE_OBJECT, result);
|
|
115
|
|
116 objIUnknown = new IUnknown(address[0]);
|
|
117
|
|
118 } else {
|
|
119 // Prepare the ClassFactory
|
|
120 int[] ppvObject = new int[1];
|
|
121 try {
|
|
122 int result = COM.CoGetClassObject(appClsid, COM.CLSCTX_INPROC_HANDLER | COM.CLSCTX_INPROC_SERVER, 0, COM.IIDIClassFactory2, ppvObject);
|
|
123 if (result !is COM.S_OK) {
|
|
124 OLE.error(OLE.ERROR_CANNOT_ACCESS_CLASSFACTORY, result);
|
|
125 }
|
|
126 IClassFactory2 classFactory = new IClassFactory2(ppvObject[0]);
|
|
127 // Create Com Object
|
|
128 ppvObject = new int[1];
|
|
129 result = classFactory.CreateInstanceLic(0, 0, COM.IIDIUnknown, licinfo, ppvObject);
|
|
130 classFactory.Release();
|
|
131 if (result !is COM.S_OK)
|
|
132 OLE.error(OLE.ERROR_CANNOT_CREATE_LICENSED_OBJECT, result);
|
|
133 } finally {
|
|
134 COM.SysFreeString(licinfo);
|
|
135 }
|
|
136
|
|
137 objIUnknown = new IUnknown(ppvObject[0]);
|
|
138
|
|
139 // Prepare a storage medium
|
|
140 ppvObject = new int[1];
|
|
141 if (objIUnknown.QueryInterface(COM.IIDIPersistStorage, ppvObject) is COM.S_OK) {
|
|
142 IPersistStorage persist = new IPersistStorage(ppvObject[0]);
|
|
143 tempStorage = createTempStorage();
|
|
144 persist.InitNew(tempStorage.getAddress());
|
|
145 persist.Release();
|
|
146 }
|
|
147 }
|
|
148
|
|
149 // Init sinks
|
|
150 addObjectReferences();
|
|
151
|
|
152 // Init site properties
|
|
153 setSiteProperty(COM.DISPID_AMBIENT_USERMODE, new Variant(true));
|
|
154 setSiteProperty(COM.DISPID_AMBIENT_UIDEAD, new Variant(false));
|
|
155
|
|
156 if (COM.OleRun(objIUnknown.getAddress()) is OLE.S_OK) state= STATE_RUNNING;
|
|
157
|
|
158 } catch (DWTError e) {
|
|
159 dispose();
|
|
160 disposeCOMInterfaces();
|
|
161 throw e;
|
|
162 }
|
|
163 }
|
|
164 /**
|
|
165 * Adds the listener to receive events.
|
|
166 *
|
|
167 * @param eventID the id of the event
|
|
168 *
|
|
169 * @param listener the listener
|
|
170 *
|
|
171 * @exception IllegalArgumentException <ul>
|
|
172 * <li>ERROR_NULL_ARGUMENT when listener is null</li>
|
|
173 * </ul>
|
|
174 */
|
|
175 public void addEventListener(int eventID, OleListener listener) {
|
|
176 if (listener is null) OLE.error (DWT.ERROR_NULL_ARGUMENT);
|
|
177 GUID riid = getDefaultEventSinkGUID(objIUnknown);
|
|
178 if (riid !is null) {
|
|
179 addEventListener(objIUnknown.getAddress(), riid, eventID, listener);
|
|
180 }
|
|
181
|
|
182 }
|
|
183 static GUID getDefaultEventSinkGUID(IUnknown unknown) {
|
|
184 // get Event Sink I/F from IProvideClassInfo2
|
|
185 int[] ppvObject = new int[1];
|
|
186 if (unknown.QueryInterface(COM.IIDIProvideClassInfo2, ppvObject) is COM.S_OK) {
|
|
187 IProvideClassInfo2 pci2 = new IProvideClassInfo2(ppvObject[0]);
|
|
188 GUID riid = new GUID();
|
|
189 int result = pci2.GetGUID(COM.GUIDKIND_DEFAULT_SOURCE_DISP_IID, riid);
|
|
190 pci2.Release();
|
|
191 if (result is COM.S_OK) return riid;
|
|
192 }
|
|
193
|
|
194 // get Event Sink I/F from IProvideClassInfo
|
|
195 if (unknown.QueryInterface(COM.IIDIProvideClassInfo, ppvObject) is COM.S_OK) {
|
|
196 IProvideClassInfo pci = new IProvideClassInfo(ppvObject[0]);
|
|
197 int[] ppTI = new int[1];
|
|
198 int[] ppEI = new int[1];
|
|
199 int result = pci.GetClassInfo(ppTI);
|
|
200 pci.Release();
|
|
201
|
|
202 if (result is COM.S_OK && ppTI[0] !is 0) {
|
|
203 ITypeInfo classInfo = new ITypeInfo(ppTI[0]);
|
|
204 int[] ppTypeAttr = new int[1];
|
|
205 result = classInfo.GetTypeAttr(ppTypeAttr);
|
|
206 if (result is COM.S_OK && ppTypeAttr[0] !is 0) {
|
|
207 TYPEATTR typeAttribute = new TYPEATTR();
|
|
208 COM.MoveMemory(typeAttribute, ppTypeAttr[0], TYPEATTR.sizeof);
|
|
209 classInfo.ReleaseTypeAttr(ppTypeAttr[0]);
|
|
210 int implMask = COM.IMPLTYPEFLAG_FDEFAULT | COM.IMPLTYPEFLAG_FSOURCE | COM.IMPLTYPEFLAG_FRESTRICTED;
|
|
211 int implBits = COM.IMPLTYPEFLAG_FDEFAULT | COM.IMPLTYPEFLAG_FSOURCE;
|
|
212
|
|
213 for (int i = 0; i < typeAttribute.cImplTypes; i++) {
|
|
214 int[] pImplTypeFlags = new int[1];
|
|
215 if (classInfo.GetImplTypeFlags(i, pImplTypeFlags) is COM.S_OK) {
|
|
216 if ((pImplTypeFlags[0] & implMask) is implBits) {
|
|
217 int[] pRefType = new int[1];
|
|
218 if (classInfo.GetRefTypeOfImplType(i, pRefType) is COM.S_OK) {
|
|
219 classInfo.GetRefTypeInfo(pRefType[0], ppEI);
|
|
220 }
|
|
221 }
|
|
222 }
|
|
223 }
|
|
224 }
|
|
225 classInfo.Release();
|
|
226
|
|
227 if (ppEI[0] !is 0) {
|
|
228 ITypeInfo eventInfo = new ITypeInfo(ppEI[0]);
|
|
229 ppTypeAttr = new int[1];
|
|
230 result = eventInfo.GetTypeAttr(ppTypeAttr);
|
|
231 GUID riid = null;
|
|
232 if (result is COM.S_OK && ppTypeAttr[0] !is 0) {
|
|
233 riid = new GUID();
|
|
234 COM.MoveMemory(riid, ppTypeAttr[0], GUID.sizeof);
|
|
235 eventInfo.ReleaseTypeAttr(ppTypeAttr[0]);
|
|
236 }
|
|
237 eventInfo.Release();
|
|
238 return riid;
|
|
239 }
|
|
240 }
|
|
241 }
|
|
242 return null;
|
|
243 }
|
|
244
|
|
245 /**
|
|
246 * Adds the listener to receive events.
|
|
247 *
|
|
248 * @since 2.0
|
|
249 *
|
|
250 * @param automation the automation object that provides the event notification
|
|
251 * @param eventID the id of the event
|
|
252 * @param listener the listener
|
|
253 *
|
|
254 * @exception IllegalArgumentException <ul>
|
|
255 * <li>ERROR_NULL_ARGUMENT when listener is null</li>
|
|
256 * </ul>
|
|
257 */
|
|
258 public void addEventListener(OleAutomation automation, int eventID, OleListener listener) {
|
|
259 if (listener is null || automation is null) OLE.error (DWT.ERROR_NULL_ARGUMENT);
|
|
260 int address = automation.getAddress();
|
|
261 IUnknown unknown = new IUnknown(address);
|
|
262 GUID riid = getDefaultEventSinkGUID(unknown);
|
|
263 if (riid !is null) {
|
|
264 addEventListener(address, riid, eventID, listener);
|
|
265 }
|
|
266
|
|
267 }
|
|
268 /**
|
|
269 * Adds the listener to receive events.
|
|
270 *
|
|
271 * @since 3.2
|
|
272 *
|
|
273 * @param automation the automation object that provides the event notification
|
|
274 * @param eventSinkId the GUID of the event sink
|
|
275 * @param eventID the id of the event
|
|
276 * @param listener the listener
|
|
277 *
|
|
278 * @exception IllegalArgumentException <ul>
|
|
279 * <li>ERROR_NULL_ARGUMENT when listener is null</li>
|
|
280 * </ul>
|
|
281 */
|
|
282 public void addEventListener(OleAutomation automation, String eventSinkId, int eventID, OleListener listener) {
|
|
283 if (listener is null || automation is null || eventSinkId is null) OLE.error (DWT.ERROR_NULL_ARGUMENT);
|
|
284 int address = automation.getAddress();
|
|
285 if (address is 0) return;
|
|
286 char[] buffer = (eventSinkId +"\0").toCharArray();
|
|
287 GUID guid = new GUID();
|
|
288 if (COM.IIDFromString(buffer, guid) !is COM.S_OK) return;
|
|
289 addEventListener(address, guid, eventID, listener);
|
|
290 }
|
|
291
|
|
292 void addEventListener(int iunknown, GUID guid, int eventID, OleListener listener) {
|
|
293 if (listener is null || iunknown is 0 || guid is null) OLE.error (DWT.ERROR_NULL_ARGUMENT);
|
|
294 // have we connected to this kind of event sink before?
|
|
295 int index = -1;
|
|
296 for (int i = 0; i < oleEventSinkGUID.length; i++) {
|
|
297 if (COM.IsEqualGUID(oleEventSinkGUID[i], guid)) {
|
|
298 if (iunknown is oleEventSinkIUnknown[i]) {
|
|
299 index = i;
|
|
300 break;
|
|
301 }
|
|
302 }
|
|
303 }
|
|
304 if (index !is -1) {
|
|
305 oleEventSink[index].addListener(eventID, listener);
|
|
306 } else {
|
|
307 int oldLength = oleEventSink.length;
|
|
308 OleEventSink[] newOleEventSink = new OleEventSink[oldLength + 1];
|
|
309 GUID[] newOleEventSinkGUID = new GUID[oldLength + 1];
|
|
310 int[] newOleEventSinkIUnknown = new int[oldLength + 1];
|
|
311 System.arraycopy(oleEventSink, 0, newOleEventSink, 0, oldLength);
|
|
312 System.arraycopy(oleEventSinkGUID, 0, newOleEventSinkGUID, 0, oldLength);
|
|
313 System.arraycopy(oleEventSinkIUnknown, 0, newOleEventSinkIUnknown, 0, oldLength);
|
|
314 oleEventSink = newOleEventSink;
|
|
315 oleEventSinkGUID = newOleEventSinkGUID;
|
|
316 oleEventSinkIUnknown = newOleEventSinkIUnknown;
|
|
317
|
|
318 oleEventSink[oldLength] = new OleEventSink(this, iunknown, guid);
|
|
319 oleEventSinkGUID[oldLength] = guid;
|
|
320 oleEventSinkIUnknown[oldLength] = iunknown;
|
|
321 oleEventSink[oldLength].AddRef();
|
|
322 oleEventSink[oldLength].connect();
|
|
323 oleEventSink[oldLength].addListener(eventID, listener);
|
|
324
|
|
325 }
|
|
326 }
|
|
327 protected void addObjectReferences() {
|
|
328
|
|
329 super.addObjectReferences();
|
|
330
|
|
331 // Get property change notification from control
|
|
332 connectPropertyChangeSink();
|
|
333
|
|
334 // Get access to the Control object
|
|
335 int[] ppvObject = new int[1];
|
|
336 if (objIUnknown.QueryInterface(COM.IIDIOleControl, ppvObject) is COM.S_OK) {
|
|
337 IOleControl objIOleControl = new IOleControl(ppvObject[0]);
|
|
338 // ask the control for its info in case users
|
|
339 // need to act on it
|
|
340 currentControlInfo = new CONTROLINFO();
|
|
341 objIOleControl.GetControlInfo(currentControlInfo);
|
|
342 objIOleControl.Release();
|
|
343 }
|
|
344 }
|
|
345 /**
|
|
346 * Adds the listener to receive events.
|
|
347 *
|
|
348 * @param propertyID the identifier of the property
|
|
349 * @param listener the listener
|
|
350 *
|
|
351 * @exception IllegalArgumentException <ul>
|
|
352 * <li>ERROR_NULL_ARGUMENT when listener is null</li>
|
|
353 * </ul>
|
|
354 */
|
|
355 public void addPropertyListener(int propertyID, OleListener listener) {
|
|
356 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
357 olePropertyChangeSink.addListener(propertyID, listener);
|
|
358 }
|
|
359
|
|
360 private void connectPropertyChangeSink() {
|
|
361 olePropertyChangeSink = new OlePropertyChangeSink(this);
|
|
362 olePropertyChangeSink.AddRef();
|
|
363 olePropertyChangeSink.connect(objIUnknown);
|
|
364 }
|
|
365 protected void createCOMInterfaces () {
|
|
366 super.createCOMInterfaces();
|
|
367
|
|
368 // register each of the interfaces that this object implements
|
|
369 iOleControlSite = new COMObject(new int[]{2, 0, 0, 0, 1, 1, 3, 2, 1, 0}){
|
|
370 public int method0(int[] args) {return QueryInterface(args[0], args[1]);}
|
|
371 public int method1(int[] args) {return AddRef();}
|
|
372 public int method2(int[] args) {return Release();}
|
|
373 public int method3(int[] args) {return OnControlInfoChanged();}
|
|
374 // method4 LockInPlaceActive - not implemented
|
|
375 // method5 GetExtendedControl - not implemented
|
|
376 // method6 TransformCoords - not implemented
|
|
377 // method7 Translate Accelerator - not implemented
|
|
378 public int method8(int[] args) {return OnFocus(args[0]);}
|
|
379 // method9 ShowPropertyFrame - not implemented
|
|
380 };
|
|
381
|
|
382 iDispatch = new COMObject(new int[]{2, 0, 0, 1, 3, 5, 8}){
|
|
383 public int method0(int[] args) {return QueryInterface(args[0], args[1]);}
|
|
384 public int method1(int[] args) {return AddRef();}
|
|
385 public int method2(int[] args) {return Release();}
|
|
386 // method3 GetTypeInfoCount - not implemented
|
|
387 // method4 GetTypeInfo - not implemented
|
|
388 // method5 GetIDsOfNames - not implemented
|
|
389 public int method6(int[] args) {return Invoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);}
|
|
390 };
|
|
391 }
|
|
392 private void disconnectEventSinks() {
|
|
393
|
|
394 for (int i = 0; i < oleEventSink.length; i++) {
|
|
395 OleEventSink sink = oleEventSink[i];
|
|
396 sink.disconnect();
|
|
397 sink.Release();
|
|
398 }
|
|
399 oleEventSink = new OleEventSink[0];
|
|
400 oleEventSinkGUID = new GUID[0];
|
|
401 oleEventSinkIUnknown = new int[0];
|
|
402 }
|
|
403 private void disconnectPropertyChangeSink() {
|
|
404
|
|
405 if (olePropertyChangeSink !is null) {
|
|
406 olePropertyChangeSink.disconnect(objIUnknown);
|
|
407 olePropertyChangeSink.Release();
|
|
408 }
|
|
409 olePropertyChangeSink = null;
|
|
410 }
|
|
411 protected void disposeCOMInterfaces() {
|
|
412 super.disposeCOMInterfaces();
|
|
413
|
|
414 if (iOleControlSite !is null)
|
|
415 iOleControlSite.dispose();
|
|
416 iOleControlSite = null;
|
|
417
|
|
418 if (iDispatch !is null)
|
|
419 iDispatch.dispose();
|
|
420 iDispatch = null;
|
|
421 }
|
|
422 public Color getBackground () {
|
|
423
|
|
424 if (objIUnknown !is null) {
|
|
425 // !! We are getting the OLE_COLOR - should we change this to the COLORREF value?
|
|
426 OleAutomation oleObject= new OleAutomation(this);
|
|
427 Variant varBackColor = oleObject.getProperty(COM.DISPID_BACKCOLOR);
|
|
428 oleObject.dispose();
|
|
429
|
|
430 if (varBackColor !is null){
|
|
431 int[] colorRef = new int[1];
|
|
432 if (COM.OleTranslateColor(varBackColor.getInt(), getDisplay().hPalette, colorRef) is COM.S_OK)
|
|
433 return Color.win32_new(getDisplay(), colorRef[0]);
|
|
434 }
|
|
435 }
|
|
436
|
|
437 return super.getBackground();
|
|
438 }
|
|
439 public Font getFont () {
|
|
440
|
|
441 if (objIUnknown !is null) {
|
|
442 OleAutomation oleObject= new OleAutomation(this);
|
|
443 Variant varDispFont = oleObject.getProperty(COM.DISPID_FONT);
|
|
444 oleObject.dispose();
|
|
445
|
|
446 if (varDispFont !is null){
|
|
447 OleAutomation iDispFont = varDispFont.getAutomation();
|
|
448 Variant lfFaceName = iDispFont.getProperty(COM.DISPID_FONT_NAME);
|
|
449 Variant lfHeight = iDispFont.getProperty(COM.DISPID_FONT_SIZE);
|
|
450 Variant lfItalic = iDispFont.getProperty(COM.DISPID_FONT_ITALIC);
|
|
451 //Variant lfCharSet = iDispFont.getProperty(COM.DISPID_FONT_CHARSET);
|
|
452 Variant lfBold = iDispFont.getProperty(COM.DISPID_FONT_BOLD);
|
|
453 iDispFont.dispose();
|
|
454
|
|
455 if (lfFaceName !is null &&
|
|
456 lfHeight !is null &&
|
|
457 lfItalic !is null &&
|
|
458 lfBold !is null){
|
|
459 int style = 3 * lfBold.getInt() + 2 * lfItalic.getInt();
|
|
460 Font font = new Font(getShell().getDisplay(), lfFaceName.getString(), lfHeight.getInt(), style);
|
|
461 return font;
|
|
462 }
|
|
463 }
|
|
464 }
|
|
465
|
|
466 return super.getFont();
|
|
467 }
|
|
468 public Color getForeground () {
|
|
469
|
|
470 if (objIUnknown !is null) {
|
|
471 // !! We are getting the OLE_COLOR - should we change this to the COLORREF value?
|
|
472 OleAutomation oleObject= new OleAutomation(this);
|
|
473 Variant varForeColor = oleObject.getProperty(COM.DISPID_FORECOLOR);
|
|
474 oleObject.dispose();
|
|
475
|
|
476 if (varForeColor !is null){
|
|
477 int[] colorRef = new int[1];
|
|
478 if (COM.OleTranslateColor(varForeColor.getInt(), getDisplay().hPalette, colorRef) is COM.S_OK)
|
|
479 return Color.win32_new(getDisplay(), colorRef[0]);
|
|
480 }
|
|
481 }
|
|
482
|
|
483 return super.getForeground();
|
|
484 }
|
|
485 protected int getLicenseInfo(GUID clsid) {
|
|
486 int[] ppvObject = new int[1];
|
|
487
|
|
488 if (COM.CoGetClassObject(clsid, COM.CLSCTX_INPROC_HANDLER | COM.CLSCTX_INPROC_SERVER, 0, COM.IIDIClassFactory2, ppvObject) !is COM.S_OK) {
|
|
489 return 0;
|
|
490 }
|
|
491 IClassFactory2 classFactory = new IClassFactory2(ppvObject[0]);
|
|
492 LICINFO licinfo = new LICINFO();
|
|
493 if (classFactory.GetLicInfo(licinfo) !is COM.S_OK) {
|
|
494 classFactory.Release();
|
|
495 return 0;
|
|
496 }
|
|
497 int[] pBstrKey = new int[1];
|
|
498 if (licinfo !is null && licinfo.fRuntimeKeyAvail) {
|
|
499 if (classFactory.RequestLicKey(0, pBstrKey) is COM.S_OK) {
|
|
500 classFactory.Release();
|
|
501 return pBstrKey[0];
|
|
502 }
|
|
503 }
|
|
504 classFactory.Release();
|
|
505 return 0;
|
|
506 }
|
|
507 /**
|
|
508 *
|
|
509 * Get the control site property specified by the dispIdMember.
|
|
510 *
|
|
511 * @since 2.1
|
|
512 *
|
|
513 */
|
|
514 public Variant getSiteProperty(int dispId){
|
|
515 for (int i = 0; i < sitePropertyIds.length; i++) {
|
|
516 if (sitePropertyIds[i] is dispId) {
|
|
517 return sitePropertyValues[i];
|
|
518 }
|
|
519 }
|
|
520 return null;
|
|
521 }
|
|
522 protected int GetWindow(int phwnd) {
|
|
523
|
|
524 if (phwnd is 0)
|
|
525 return COM.E_INVALIDARG;
|
|
526 if (frame is null) {
|
|
527 COM.MoveMemory(phwnd, new int[] {0}, 4);
|
|
528 return COM.E_NOTIMPL;
|
|
529 }
|
|
530
|
|
531 // Copy the Window's handle into the memory passed in
|
|
532 COM.MoveMemory(phwnd, new int[] {handle}, 4);
|
|
533 return COM.S_OK;
|
|
534 }
|
|
535 private int Invoke(int dispIdMember, int riid, int lcid, int dwFlags, int pDispParams, int pVarResult, int pExcepInfo, int pArgErr) {
|
|
536 if (pVarResult is 0 || dwFlags !is COM.DISPATCH_PROPERTYGET) {
|
|
537 if (pExcepInfo !is 0) COM.MoveMemory(pExcepInfo, new int[] {0}, 4);
|
|
538 if (pArgErr !is 0) COM.MoveMemory(pArgErr, new int[] {0}, 4);
|
|
539 return COM.DISP_E_MEMBERNOTFOUND;
|
|
540 }
|
|
541 Variant result = getSiteProperty(dispIdMember);
|
|
542 if (result !is null) {
|
|
543 if (pVarResult !is 0) result.getData(pVarResult);
|
|
544 return COM.S_OK;
|
|
545 }
|
|
546 switch (dispIdMember) {
|
|
547 // indicate a false result
|
|
548 case COM.DISPID_AMBIENT_SUPPORTSMNEMONICS :
|
|
549 case COM.DISPID_AMBIENT_SHOWGRABHANDLES :
|
|
550 case COM.DISPID_AMBIENT_SHOWHATCHING :
|
|
551 if (pVarResult !is 0) COM.MoveMemory(pVarResult, new int[] {0}, 4);
|
|
552 if (pExcepInfo !is 0) COM.MoveMemory(pExcepInfo, new int[] {0}, 4);
|
|
553 if (pArgErr !is 0) COM.MoveMemory(pArgErr, new int[] {0}, 4);
|
|
554 return COM.S_FALSE;
|
|
555
|
|
556 // not implemented
|
|
557 case COM.DISPID_AMBIENT_OFFLINEIFNOTCONNECTED :
|
|
558 case COM.DISPID_AMBIENT_BACKCOLOR :
|
|
559 case COM.DISPID_AMBIENT_FORECOLOR :
|
|
560 case COM.DISPID_AMBIENT_FONT :
|
|
561 case COM.DISPID_AMBIENT_LOCALEID :
|
|
562 case COM.DISPID_AMBIENT_SILENT :
|
|
563 case COM.DISPID_AMBIENT_MESSAGEREFLECT :
|
|
564 if (pVarResult !is 0) COM.MoveMemory(pVarResult, new int[] {0}, 4);
|
|
565 if (pExcepInfo !is 0) COM.MoveMemory(pExcepInfo, new int[] {0}, 4);
|
|
566 if (pArgErr !is 0) COM.MoveMemory(pArgErr, new int[] {0}, 4);
|
|
567 return COM.E_NOTIMPL;
|
|
568
|
|
569 default :
|
|
570 if (pVarResult !is 0) COM.MoveMemory(pVarResult, new int[] {0}, 4);
|
|
571 if (pExcepInfo !is 0) COM.MoveMemory(pExcepInfo, new int[] {0}, 4);
|
|
572 if (pArgErr !is 0) COM.MoveMemory(pArgErr, new int[] {0}, 4);
|
|
573 return COM.DISP_E_MEMBERNOTFOUND;
|
|
574 }
|
|
575 }
|
|
576 private int OnControlInfoChanged() {
|
|
577 int[] ppvObject = new int[1];
|
|
578 if (objIUnknown.QueryInterface(COM.IIDIOleControl, ppvObject) is COM.S_OK) {
|
|
579 IOleControl objIOleControl = new IOleControl(ppvObject[0]);
|
|
580 // ask the control for its info in case users
|
|
581 // need to act on it
|
|
582 currentControlInfo = new CONTROLINFO();
|
|
583 objIOleControl.GetControlInfo(currentControlInfo);
|
|
584 objIOleControl.Release();
|
|
585 }
|
|
586 return COM.S_OK;
|
|
587 }
|
|
588 void onFocusIn(Event e) {
|
|
589 if (objIOleInPlaceObject is null) return;
|
|
590 doVerb(OLE.OLEIVERB_UIACTIVATE);
|
|
591 if (isFocusControl()) return;
|
|
592 int[] phwnd = new int[1];
|
|
593 objIOleInPlaceObject.GetWindow(phwnd);
|
|
594 if (phwnd[0] is 0) return;
|
|
595 OS.SetFocus(phwnd[0]);
|
|
596 }
|
|
597 void onFocusOut(Event e) {
|
|
598 if (objIOleInPlaceObject !is null) {
|
|
599 /*
|
|
600 * Bug in Windows. When IE7 loses focus and UIDeactivate()
|
|
601 * is called, IE destroys the caret even though it is
|
|
602 * no longer owned by IE. If focus has moved to a control
|
|
603 * that shows a caret then the caret disappears. The fix
|
|
604 * is to detect this case and restore the caret.
|
|
605 */
|
|
606 int threadId = OS.GetCurrentThreadId();
|
|
607 GUITHREADINFO lpgui1 = new GUITHREADINFO();
|
|
608 lpgui1.cbSize = GUITHREADINFO.sizeof;
|
|
609 OS.GetGUIThreadInfo(threadId, lpgui1);
|
|
610 objIOleInPlaceObject.UIDeactivate();
|
|
611 if (lpgui1.hwndCaret !is 0) {
|
|
612 GUITHREADINFO lpgui2 = new GUITHREADINFO();
|
|
613 lpgui2.cbSize = GUITHREADINFO.sizeof;
|
|
614 OS.GetGUIThreadInfo(threadId, lpgui2);
|
|
615 if (lpgui2.hwndCaret is 0 && lpgui1.hwndCaret is OS.GetFocus()) {
|
|
616 if (SWT_RESTORECARET is 0) {
|
|
617 SWT_RESTORECARET = OS.RegisterWindowMessage (new TCHAR (0, "SWT_RESTORECARET", true));
|
|
618 }
|
|
619 /*
|
|
620 * If the caret was not restored by DWT, put it back using
|
|
621 * the information from GUITHREADINFO. Note that this will
|
|
622 * not be correct when the caret has a bitmap. There is no
|
|
623 * API to query the bitmap that the caret is using.
|
|
624 */
|
|
625 if (OS.SendMessage (lpgui1.hwndCaret, SWT_RESTORECARET, 0, 0) is 0) {
|
|
626 int width = lpgui1.right - lpgui1.left;
|
|
627 int height = lpgui1.bottom - lpgui1.top;
|
|
628 OS.CreateCaret (lpgui1.hwndCaret, 0, width, height);
|
|
629 OS.SetCaretPos (lpgui1.left, lpgui1.top);
|
|
630 OS.ShowCaret (lpgui1.hwndCaret);
|
|
631 }
|
|
632 }
|
|
633 }
|
|
634 }
|
|
635 }
|
|
636 private int OnFocus(int fGotFocus) {
|
|
637 return COM.S_OK;
|
|
638 }
|
|
639 protected int OnUIDeactivate(int fUndoable) {
|
|
640 // controls don't need to do anything for
|
|
641 // border space or menubars
|
|
642 state = STATE_INPLACEACTIVE;
|
|
643 return COM.S_OK;
|
|
644 }
|
|
645 protected int QueryInterface(int riid, int ppvObject) {
|
|
646 int result = super.QueryInterface(riid, ppvObject);
|
|
647 if (result is COM.S_OK)
|
|
648 return result;
|
|
649 if (riid is 0 || ppvObject is 0)
|
|
650 return COM.E_INVALIDARG;
|
|
651 GUID guid = new GUID();
|
|
652 COM.MoveMemory(guid, riid, GUID.sizeof);
|
|
653 if (COM.IsEqualGUID(guid, COM.IIDIOleControlSite)) {
|
|
654 COM.MoveMemory(ppvObject, new int[] {iOleControlSite.getAddress()}, 4);
|
|
655 AddRef();
|
|
656 return COM.S_OK;
|
|
657 }
|
|
658 if (COM.IsEqualGUID(guid, COM.IIDIDispatch)) {
|
|
659 COM.MoveMemory(ppvObject, new int[] {iDispatch.getAddress()}, 4);
|
|
660 AddRef();
|
|
661 return COM.S_OK;
|
|
662 }
|
|
663 COM.MoveMemory(ppvObject, new int[] {0}, 4);
|
|
664 return COM.E_NOINTERFACE;
|
|
665 }
|
|
666 protected int Release() {
|
|
667 int result = super.Release();
|
|
668 if (result is 0) {
|
|
669 for (int i = 0; i < sitePropertyIds.length; i++) {
|
|
670 sitePropertyValues[i].dispose();
|
|
671 }
|
|
672 sitePropertyIds = new int[0];
|
|
673 sitePropertyValues = new Variant[0];
|
|
674 }
|
|
675 return result;
|
|
676 }
|
|
677 protected void releaseObjectInterfaces() {
|
|
678
|
|
679 disconnectEventSinks();
|
|
680
|
|
681 disconnectPropertyChangeSink();
|
|
682
|
|
683 super.releaseObjectInterfaces();
|
|
684 }
|
|
685 /**
|
|
686 * Removes the listener.
|
|
687 *
|
|
688 * @param eventID the event identifier
|
|
689 *
|
|
690 * @param listener the listener
|
|
691 *
|
|
692 * @exception IllegalArgumentException <ul>
|
|
693 * <li>ERROR_NULL_ARGUMENT when listener is null</li>
|
|
694 * </ul>
|
|
695 */
|
|
696 public void removeEventListener(int eventID, OleListener listener) {
|
|
697 checkWidget();
|
|
698 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
699
|
|
700 GUID riid = getDefaultEventSinkGUID(objIUnknown);
|
|
701 if (riid !is null) {
|
|
702 removeEventListener(objIUnknown.getAddress(), riid, eventID, listener);
|
|
703 }
|
|
704 }
|
|
705 /**
|
|
706 * Removes the listener.
|
|
707 *
|
|
708 * @since 2.0
|
|
709 * @deprecated - use OleControlSite.removeEventListener(OleAutomation, int, OleListener)
|
|
710 *
|
|
711 * @param automation the automation object that provides the event notification
|
|
712 *
|
|
713 * @param guid the identifier of the events COM interface
|
|
714 *
|
|
715 * @param eventID the event identifier
|
|
716 *
|
|
717 * @param listener the listener
|
|
718 *
|
|
719 * @exception IllegalArgumentException <ul>
|
|
720 * <li>ERROR_NULL_ARGUMENT when listener is null</li>
|
|
721 * </ul>
|
|
722 */
|
|
723 public void removeEventListener(OleAutomation automation, GUID guid, int eventID, OleListener listener) {
|
|
724 checkWidget();
|
|
725 if (automation is null || listener is null || guid is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
726 removeEventListener(automation.getAddress(), guid, eventID, listener);
|
|
727 }
|
|
728 /**
|
|
729 * Removes the listener.
|
|
730 *
|
|
731 * @since 2.0
|
|
732 *
|
|
733 * @param automation the automation object that provides the event notification
|
|
734 *
|
|
735 * @param eventID the event identifier
|
|
736 *
|
|
737 * @param listener the listener
|
|
738 *
|
|
739 * @exception IllegalArgumentException <ul>
|
|
740 * <li>ERROR_NULL_ARGUMENT when listener is null</li>
|
|
741 * </ul>
|
|
742 */
|
|
743 public void removeEventListener(OleAutomation automation, int eventID, OleListener listener) {
|
|
744 checkWidget();
|
|
745 if (automation is null || listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
746 int address = automation.getAddress();
|
|
747 IUnknown unknown = new IUnknown(address);
|
|
748 GUID riid = getDefaultEventSinkGUID(unknown);
|
|
749 if (riid !is null) {
|
|
750 removeEventListener(address, riid, eventID, listener);
|
|
751 }
|
|
752 }
|
|
753 void removeEventListener(int iunknown, GUID guid, int eventID, OleListener listener) {
|
|
754 if (listener is null || guid is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
755 for (int i = 0; i < oleEventSink.length; i++) {
|
|
756 if (COM.IsEqualGUID(oleEventSinkGUID[i], guid)) {
|
|
757 if (iunknown is oleEventSinkIUnknown[i]) {
|
|
758 oleEventSink[i].removeListener(eventID, listener);
|
|
759 if (!oleEventSink[i].hasListeners()) {
|
|
760 //free resources associated with event sink
|
|
761 oleEventSink[i].disconnect();
|
|
762 oleEventSink[i].Release();
|
|
763 int oldLength = oleEventSink.length;
|
|
764 if (oldLength is 1) {
|
|
765 oleEventSink = new OleEventSink[0];
|
|
766 oleEventSinkGUID = new GUID[0];
|
|
767 oleEventSinkIUnknown = new int[0];
|
|
768 } else {
|
|
769 OleEventSink[] newOleEventSink = new OleEventSink[oldLength - 1];
|
|
770 System.arraycopy(oleEventSink, 0, newOleEventSink, 0, i);
|
|
771 System.arraycopy(oleEventSink, i + 1, newOleEventSink, i, oldLength - i - 1);
|
|
772 oleEventSink = newOleEventSink;
|
|
773
|
|
774 GUID[] newOleEventSinkGUID = new GUID[oldLength - 1];
|
|
775 System.arraycopy(oleEventSinkGUID, 0, newOleEventSinkGUID, 0, i);
|
|
776 System.arraycopy(oleEventSinkGUID, i + 1, newOleEventSinkGUID, i, oldLength - i - 1);
|
|
777 oleEventSinkGUID = newOleEventSinkGUID;
|
|
778
|
|
779 int[] newOleEventSinkIUnknown = new int[oldLength - 1];
|
|
780 System.arraycopy(oleEventSinkIUnknown, 0, newOleEventSinkIUnknown, 0, i);
|
|
781 System.arraycopy(oleEventSinkIUnknown, i + 1, newOleEventSinkIUnknown, i, oldLength - i - 1);
|
|
782 oleEventSinkIUnknown = newOleEventSinkIUnknown;
|
|
783 }
|
|
784 }
|
|
785 return;
|
|
786 }
|
|
787 }
|
|
788 }
|
|
789 }
|
|
790 /**
|
|
791 * Removes the listener.
|
|
792 *
|
|
793 * @param listener the listener
|
|
794 *
|
|
795 * @exception IllegalArgumentException <ul>
|
|
796 * <li>ERROR_NULL_ARGUMENT when listener is null</li>
|
|
797 * </ul>
|
|
798 */
|
|
799 public void removePropertyListener(int propertyID, OleListener listener) {
|
|
800 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
|
|
801 olePropertyChangeSink.removeListener(propertyID, listener);
|
|
802 }
|
|
803 public void setBackground (Color color) {
|
|
804
|
|
805 super.setBackground(color);
|
|
806
|
|
807 //set the background of the ActiveX Control
|
|
808 if (objIUnknown !is null) {
|
|
809 OleAutomation oleObject= new OleAutomation(this);
|
|
810 oleObject.setProperty(COM.DISPID_BACKCOLOR, new Variant(color.handle));
|
|
811 oleObject.dispose();
|
|
812 }
|
|
813 }
|
|
814 public void setFont (Font font) {
|
|
815
|
|
816 super.setFont(font);
|
|
817
|
|
818 //set the font of the ActiveX Control
|
|
819 if (objIUnknown !is null) {
|
|
820
|
|
821 OleAutomation oleObject= new OleAutomation(this);
|
|
822 Variant varDispFont = oleObject.getProperty(COM.DISPID_FONT);
|
|
823 oleObject.dispose();
|
|
824
|
|
825 if (varDispFont !is null){
|
|
826 OleAutomation iDispFont = varDispFont.getAutomation();
|
|
827 FontData[] fdata = font.getFontData();
|
|
828 iDispFont.setProperty(COM.DISPID_FONT_NAME, new Variant(fdata[0].getName()));
|
|
829 iDispFont.setProperty(COM.DISPID_FONT_SIZE, new Variant(fdata[0].getHeight()));
|
|
830 iDispFont.setProperty(COM.DISPID_FONT_ITALIC, new Variant(fdata[0].getStyle() & DWT.ITALIC));
|
|
831 //iDispFont.setProperty(COM.DISPID_FONT_CHARSET, new Variant(fdata[0].getCharset));
|
|
832 iDispFont.setProperty(COM.DISPID_FONT_BOLD, new Variant((fdata[0].getStyle() & DWT.BOLD)));
|
|
833 iDispFont.dispose();
|
|
834 }
|
|
835 }
|
|
836
|
|
837 return;
|
|
838 }
|
|
839 public void setForeground (Color color) {
|
|
840
|
|
841 super.setForeground(color);
|
|
842
|
|
843 //set the foreground of the ActiveX Control
|
|
844 if (objIUnknown !is null) {
|
|
845 OleAutomation oleObject= new OleAutomation(this);
|
|
846 oleObject.setProperty(COM.DISPID_FORECOLOR, new Variant(color.handle));
|
|
847 oleObject.dispose();
|
|
848 }
|
|
849 }
|
|
850 /**
|
|
851 * Sets the control site property specified by the dispIdMember to a new value.
|
|
852 * The value will be disposed by the control site when it is no longer required
|
|
853 * using Variant.dispose. Passing a value of null will clear the dispId value.
|
|
854 *
|
|
855 * @param dispId the ID of the property as specified by the IDL of the ActiveX Control
|
|
856 * @param value The new value for the property as expressed in a Variant.
|
|
857 *
|
|
858 * @since 2.1
|
|
859 */
|
|
860 public void setSiteProperty(int dispId, Variant value){
|
|
861 for (int i = 0; i < sitePropertyIds.length; i++) {
|
|
862 if (sitePropertyIds[i] is dispId) {
|
|
863 if (sitePropertyValues[i] !is null) {
|
|
864 sitePropertyValues[i].dispose();
|
|
865 }
|
|
866 if (value !is null) {
|
|
867 sitePropertyValues[i] = value;
|
|
868 } else {
|
|
869 int oldLength = sitePropertyIds.length;
|
|
870 int[] newSitePropertyIds = new int[oldLength - 1];
|
|
871 Variant[] newSitePropertyValues = new Variant[oldLength - 1];
|
|
872 System.arraycopy(sitePropertyIds, 0, newSitePropertyIds, 0, i);
|
|
873 System.arraycopy(sitePropertyIds, i + 1, newSitePropertyIds, i, oldLength - i - 1);
|
|
874 System.arraycopy(sitePropertyValues, 0, newSitePropertyValues, 0, i);
|
|
875 System.arraycopy(sitePropertyValues, i + 1, newSitePropertyValues, i, oldLength - i - 1);
|
|
876 sitePropertyIds = newSitePropertyIds;
|
|
877 sitePropertyValues = newSitePropertyValues;
|
|
878 }
|
|
879 return;
|
|
880 }
|
|
881 }
|
|
882 int oldLength = sitePropertyIds.length;
|
|
883 int[] newSitePropertyIds = new int[oldLength + 1];
|
|
884 Variant[] newSitePropertyValues = new Variant[oldLength + 1];
|
|
885 System.arraycopy(sitePropertyIds, 0, newSitePropertyIds, 0, oldLength);
|
|
886 System.arraycopy(sitePropertyValues, 0, newSitePropertyValues, 0, oldLength);
|
|
887 newSitePropertyIds[oldLength] = dispId;
|
|
888 newSitePropertyValues[oldLength] = value;
|
|
889 sitePropertyIds = newSitePropertyIds;
|
|
890 sitePropertyValues = newSitePropertyValues;
|
|
891 }
|
|
892 }
|
|
893 ++/
|