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