1 11 package org.eclipse.swt.ole.win32; 12 13 import org.eclipse.swt.*; 14 import org.eclipse.swt.internal.ole.win32.*; 15 import org.eclipse.swt.graphics.*; 16 import org.eclipse.swt.widgets.*; 17 import org.eclipse.swt.internal.win32.*; 18 19 42 public class OleControlSite extends OleClientSite 43 { 44 private COMObject iOleControlSite; 46 private COMObject iDispatch; 47 48 private OlePropertyChangeSink olePropertyChangeSink; 50 51 private OleEventSink[] oleEventSink = new OleEventSink[0]; 53 private GUID[] oleEventSinkGUID = new GUID[0]; 54 private int[] oleEventSinkIUnknown = new int[0]; 55 56 private CONTROLINFO currentControlInfo; 58 private int[] sitePropertyIds = new int[0]; 59 private Variant[] sitePropertyValues = new Variant[0]; 60 61 static int SWT_RESTORECARET; 63 64 86 public OleControlSite(Composite parent, int style, String progId) { 87 super(parent, style); 88 try { 89 90 appClsid = getClassID(progId); 92 if (appClsid == null) OLE.error(OLE.ERROR_INVALID_CLASSID); 93 94 int licinfo = getLicenseInfo(appClsid); 95 if (licinfo == 0) { 96 97 tempStorage = createTempStorage(); 99 100 int[] address = new int[1]; 102 int result = COM.OleCreate(appClsid, COM.IIDIUnknown, COM.OLERENDER_DRAW, null, 0, tempStorage.getAddress(), address); 103 if (result != COM.S_OK) 104 OLE.error(OLE.ERROR_CANNOT_CREATE_OBJECT, result); 105 106 objIUnknown = new IUnknown(address[0]); 107 108 } else { 109 int[] ppvObject = new int[1]; 111 try { 112 int result = COM.CoGetClassObject(appClsid, COM.CLSCTX_INPROC_HANDLER | COM.CLSCTX_INPROC_SERVER, 0, COM.IIDIClassFactory2, ppvObject); 113 if (result != COM.S_OK) { 114 OLE.error(OLE.ERROR_CANNOT_ACCESS_CLASSFACTORY, result); 115 } 116 IClassFactory2 classFactory = new IClassFactory2(ppvObject[0]); 117 ppvObject = new int[1]; 119 result = classFactory.CreateInstanceLic(0, 0, COM.IIDIUnknown, licinfo, ppvObject); 120 classFactory.Release(); 121 if (result != COM.S_OK) 122 OLE.error(OLE.ERROR_CANNOT_CREATE_LICENSED_OBJECT, result); 123 } finally { 124 COM.SysFreeString(licinfo); 125 } 126 127 objIUnknown = new IUnknown(ppvObject[0]); 128 129 ppvObject = new int[1]; 131 if (objIUnknown.QueryInterface(COM.IIDIPersistStorage, ppvObject) == COM.S_OK) { 132 IPersistStorage persist = new IPersistStorage(ppvObject[0]); 133 tempStorage = createTempStorage(); 134 persist.InitNew(tempStorage.getAddress()); 135 persist.Release(); 136 } 137 } 138 139 addObjectReferences(); 141 142 setSiteProperty(COM.DISPID_AMBIENT_USERMODE, new Variant(true)); 144 setSiteProperty(COM.DISPID_AMBIENT_UIDEAD, new Variant(false)); 145 146 if (COM.OleRun(objIUnknown.getAddress()) == OLE.S_OK) state= STATE_RUNNING; 147 148 } catch (SWTError e) { 149 dispose(); 150 disposeCOMInterfaces(); 151 throw e; 152 } 153 } 154 165 public void addEventListener(int eventID, OleListener listener) { 166 if (listener == null) OLE.error (SWT.ERROR_NULL_ARGUMENT); 167 GUID riid = getDefaultEventSinkGUID(objIUnknown); 168 if (riid != null) { 169 addEventListener(objIUnknown.getAddress(), riid, eventID, listener); 170 } 171 172 } 173 static GUID getDefaultEventSinkGUID(IUnknown unknown) { 174 int[] ppvObject = new int[1]; 176 if (unknown.QueryInterface(COM.IIDIProvideClassInfo2, ppvObject) == COM.S_OK) { 177 IProvideClassInfo2 pci2 = new IProvideClassInfo2(ppvObject[0]); 178 GUID riid = new GUID(); 179 int result = pci2.GetGUID(COM.GUIDKIND_DEFAULT_SOURCE_DISP_IID, riid); 180 pci2.Release(); 181 if (result == COM.S_OK) return riid; 182 } 183 184 if (unknown.QueryInterface(COM.IIDIProvideClassInfo, ppvObject) == COM.S_OK) { 186 IProvideClassInfo pci = new IProvideClassInfo(ppvObject[0]); 187 int[] ppTI = new int[1]; 188 int[] ppEI = new int[1]; 189 int result = pci.GetClassInfo(ppTI); 190 pci.Release(); 191 192 if (result == COM.S_OK && ppTI[0] != 0) { 193 ITypeInfo classInfo = new ITypeInfo(ppTI[0]); 194 int[] ppTypeAttr = new int[1]; 195 result = classInfo.GetTypeAttr(ppTypeAttr); 196 if (result == COM.S_OK && ppTypeAttr[0] != 0) { 197 TYPEATTR typeAttribute = new TYPEATTR(); 198 COM.MoveMemory(typeAttribute, ppTypeAttr[0], TYPEATTR.sizeof); 199 classInfo.ReleaseTypeAttr(ppTypeAttr[0]); 200 int implMask = COM.IMPLTYPEFLAG_FDEFAULT | COM.IMPLTYPEFLAG_FSOURCE | COM.IMPLTYPEFLAG_FRESTRICTED; 201 int implBits = COM.IMPLTYPEFLAG_FDEFAULT | COM.IMPLTYPEFLAG_FSOURCE; 202 203 for (int i = 0; i < typeAttribute.cImplTypes; i++) { 204 int[] pImplTypeFlags = new int[1]; 205 if (classInfo.GetImplTypeFlags(i, pImplTypeFlags) == COM.S_OK) { 206 if ((pImplTypeFlags[0] & implMask) == implBits) { 207 int[] pRefType = new int[1]; 208 if (classInfo.GetRefTypeOfImplType(i, pRefType) == COM.S_OK) { 209 classInfo.GetRefTypeInfo(pRefType[0], ppEI); 210 } 211 } 212 } 213 } 214 } 215 classInfo.Release(); 216 217 if (ppEI[0] != 0) { 218 ITypeInfo eventInfo = new ITypeInfo(ppEI[0]); 219 ppTypeAttr = new int[1]; 220 result = eventInfo.GetTypeAttr(ppTypeAttr); 221 GUID riid = null; 222 if (result == COM.S_OK && ppTypeAttr[0] != 0) { 223 riid = new GUID(); 224 COM.MoveMemory(riid, ppTypeAttr[0], GUID.sizeof); 225 eventInfo.ReleaseTypeAttr(ppTypeAttr[0]); 226 } 227 eventInfo.Release(); 228 return riid; 229 } 230 } 231 } 232 return null; 233 } 234 235 248 public void addEventListener(OleAutomation automation, int eventID, OleListener listener) { 249 if (listener == null || automation == null) OLE.error (SWT.ERROR_NULL_ARGUMENT); 250 int address = automation.getAddress(); 251 IUnknown unknown = new IUnknown(address); 252 GUID riid = getDefaultEventSinkGUID(unknown); 253 if (riid != null) { 254 addEventListener(address, riid, eventID, listener); 255 } 256 257 } 258 272 public void addEventListener(OleAutomation automation, String eventSinkId, int eventID, OleListener listener) { 273 if (listener == null || automation == null || eventSinkId == null) OLE.error (SWT.ERROR_NULL_ARGUMENT); 274 int address = automation.getAddress(); 275 if (address == 0) return; 276 char[] buffer = (eventSinkId +"\0").toCharArray(); 277 GUID guid = new GUID(); 278 if (COM.IIDFromString(buffer, guid) != COM.S_OK) return; 279 addEventListener(address, guid, eventID, listener); 280 } 281 282 void addEventListener(int iunknown, GUID guid, int eventID, OleListener listener) { 283 if (listener == null || iunknown == 0 || guid == null) OLE.error (SWT.ERROR_NULL_ARGUMENT); 284 int index = -1; 286 for (int i = 0; i < oleEventSinkGUID.length; i++) { 287 if (COM.IsEqualGUID(oleEventSinkGUID[i], guid)) { 288 if (iunknown == oleEventSinkIUnknown[i]) { 289 index = i; 290 break; 291 } 292 } 293 } 294 if (index != -1) { 295 oleEventSink[index].addListener(eventID, listener); 296 } else { 297 int oldLength = oleEventSink.length; 298 OleEventSink[] newOleEventSink = new OleEventSink[oldLength + 1]; 299 GUID[] newOleEventSinkGUID = new GUID[oldLength + 1]; 300 int[] newOleEventSinkIUnknown = new int[oldLength + 1]; 301 System.arraycopy(oleEventSink, 0, newOleEventSink, 0, oldLength); 302 System.arraycopy(oleEventSinkGUID, 0, newOleEventSinkGUID, 0, oldLength); 303 System.arraycopy(oleEventSinkIUnknown, 0, newOleEventSinkIUnknown, 0, oldLength); 304 oleEventSink = newOleEventSink; 305 oleEventSinkGUID = newOleEventSinkGUID; 306 oleEventSinkIUnknown = newOleEventSinkIUnknown; 307 308 oleEventSink[oldLength] = new OleEventSink(this, iunknown, guid); 309 oleEventSinkGUID[oldLength] = guid; 310 oleEventSinkIUnknown[oldLength] = iunknown; 311 oleEventSink[oldLength].AddRef(); 312 oleEventSink[oldLength].connect(); 313 oleEventSink[oldLength].addListener(eventID, listener); 314 315 } 316 } 317 protected void addObjectReferences() { 318 319 super.addObjectReferences(); 320 321 connectPropertyChangeSink(); 323 324 int[] ppvObject = new int[1]; 326 if (objIUnknown.QueryInterface(COM.IIDIOleControl, ppvObject) == COM.S_OK) { 327 IOleControl objIOleControl = new IOleControl(ppvObject[0]); 328 currentControlInfo = new CONTROLINFO(); 331 objIOleControl.GetControlInfo(currentControlInfo); 332 objIOleControl.Release(); 333 } 334 } 335 345 public void addPropertyListener(int propertyID, OleListener listener) { 346 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); 347 olePropertyChangeSink.addListener(propertyID, listener); 348 } 349 350 private void connectPropertyChangeSink() { 351 olePropertyChangeSink = new OlePropertyChangeSink(this); 352 olePropertyChangeSink.AddRef(); 353 olePropertyChangeSink.connect(objIUnknown); 354 } 355 protected void createCOMInterfaces () { 356 super.createCOMInterfaces(); 357 358 iOleControlSite = new COMObject(new int[]{2, 0, 0, 0, 1, 1, 3, 2, 1, 0}){ 360 public int method0(int[] args) {return QueryInterface(args[0], args[1]);} 361 public int method1(int[] args) {return AddRef();} 362 public int method2(int[] args) {return Release();} 363 public int method3(int[] args) {return OnControlInfoChanged();} 364 public int method8(int[] args) {return OnFocus(args[0]);} 369 }; 371 372 iDispatch = new COMObject(new int[]{2, 0, 0, 1, 3, 5, 8}){ 373 public int method0(int[] args) {return QueryInterface(args[0], args[1]);} 374 public int method1(int[] args) {return AddRef();} 375 public int method2(int[] args) {return Release();} 376 public int method6(int[] args) {return Invoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);} 380 }; 381 } 382 private void disconnectEventSinks() { 383 384 for (int i = 0; i < oleEventSink.length; i++) { 385 OleEventSink sink = oleEventSink[i]; 386 sink.disconnect(); 387 sink.Release(); 388 } 389 oleEventSink = new OleEventSink[0]; 390 oleEventSinkGUID = new GUID[0]; 391 oleEventSinkIUnknown = new int[0]; 392 } 393 private void disconnectPropertyChangeSink() { 394 395 if (olePropertyChangeSink != null) { 396 olePropertyChangeSink.disconnect(objIUnknown); 397 olePropertyChangeSink.Release(); 398 } 399 olePropertyChangeSink = null; 400 } 401 protected void disposeCOMInterfaces() { 402 super.disposeCOMInterfaces(); 403 404 if (iOleControlSite != null) 405 iOleControlSite.dispose(); 406 iOleControlSite = null; 407 408 if (iDispatch != null) 409 iDispatch.dispose(); 410 iDispatch = null; 411 } 412 public Color getBackground () { 413 414 if (objIUnknown != null) { 415 OleAutomation oleObject= new OleAutomation(this); 417 Variant varBackColor = oleObject.getProperty(COM.DISPID_BACKCOLOR); 418 oleObject.dispose(); 419 420 if (varBackColor != null){ 421 int[] colorRef = new int[1]; 422 if (COM.OleTranslateColor(varBackColor.getInt(), getDisplay().hPalette, colorRef) == COM.S_OK) 423 return Color.win32_new(getDisplay(), colorRef[0]); 424 } 425 } 426 427 return super.getBackground(); 428 } 429 public Font getFont () { 430 431 if (objIUnknown != null) { 432 OleAutomation oleObject= new OleAutomation(this); 433 Variant varDispFont = oleObject.getProperty(COM.DISPID_FONT); 434 oleObject.dispose(); 435 436 if (varDispFont != null){ 437 OleAutomation iDispFont = varDispFont.getAutomation(); 438 Variant lfFaceName = iDispFont.getProperty(COM.DISPID_FONT_NAME); 439 Variant lfHeight = iDispFont.getProperty(COM.DISPID_FONT_SIZE); 440 Variant lfItalic = iDispFont.getProperty(COM.DISPID_FONT_ITALIC); 441 Variant lfBold = iDispFont.getProperty(COM.DISPID_FONT_BOLD); 443 iDispFont.dispose(); 444 445 if (lfFaceName != null && 446 lfHeight != null && 447 lfItalic != null && 448 lfBold != null){ 449 int style = 3 * lfBold.getInt() + 2 * lfItalic.getInt(); 450 Font font = new Font(getShell().getDisplay(), lfFaceName.getString(), lfHeight.getInt(), style); 451 return font; 452 } 453 } 454 } 455 456 return super.getFont(); 457 } 458 public Color getForeground () { 459 460 if (objIUnknown != null) { 461 OleAutomation oleObject= new OleAutomation(this); 463 Variant varForeColor = oleObject.getProperty(COM.DISPID_FORECOLOR); 464 oleObject.dispose(); 465 466 if (varForeColor != null){ 467 int[] colorRef = new int[1]; 468 if (COM.OleTranslateColor(varForeColor.getInt(), getDisplay().hPalette, colorRef) == COM.S_OK) 469 return Color.win32_new(getDisplay(), colorRef[0]); 470 } 471 } 472 473 return super.getForeground(); 474 } 475 protected int getLicenseInfo(GUID clsid) { 476 int[] ppvObject = new int[1]; 477 478 if (COM.CoGetClassObject(clsid, COM.CLSCTX_INPROC_HANDLER | COM.CLSCTX_INPROC_SERVER, 0, COM.IIDIClassFactory2, ppvObject) != COM.S_OK) { 479 return 0; 480 } 481 IClassFactory2 classFactory = new IClassFactory2(ppvObject[0]); 482 LICINFO licinfo = new LICINFO(); 483 if (classFactory.GetLicInfo(licinfo) != COM.S_OK) { 484 classFactory.Release(); 485 return 0; 486 } 487 int[] pBstrKey = new int[1]; 488 if (licinfo != null && licinfo.fRuntimeKeyAvail) { 489 if (classFactory.RequestLicKey(0, pBstrKey) == COM.S_OK) { 490 classFactory.Release(); 491 return pBstrKey[0]; 492 } 493 } 494 classFactory.Release(); 495 return 0; 496 } 497 504 public Variant getSiteProperty(int dispId){ 505 for (int i = 0; i < sitePropertyIds.length; i++) { 506 if (sitePropertyIds[i] == dispId) { 507 return sitePropertyValues[i]; 508 } 509 } 510 return null; 511 } 512 protected int GetWindow(int phwnd) { 513 514 if (phwnd == 0) 515 return COM.E_INVALIDARG; 516 if (frame == null) { 517 COM.MoveMemory(phwnd, new int[] {0}, 4); 518 return COM.E_NOTIMPL; 519 } 520 521 COM.MoveMemory(phwnd, new int[] {handle}, 4); 523 return COM.S_OK; 524 } 525 private int Invoke(int dispIdMember, int riid, int lcid, int dwFlags, int pDispParams, int pVarResult, int pExcepInfo, int pArgErr) { 526 if (pVarResult == 0 || dwFlags != COM.DISPATCH_PROPERTYGET) { 527 if (pExcepInfo != 0) COM.MoveMemory(pExcepInfo, new int[] {0}, 4); 528 if (pArgErr != 0) COM.MoveMemory(pArgErr, new int[] {0}, 4); 529 return COM.DISP_E_MEMBERNOTFOUND; 530 } 531 Variant result = getSiteProperty(dispIdMember); 532 if (result != null) { 533 if (pVarResult != 0) result.getData(pVarResult); 534 return COM.S_OK; 535 } 536 switch (dispIdMember) { 537 case COM.DISPID_AMBIENT_SUPPORTSMNEMONICS : 539 case COM.DISPID_AMBIENT_SHOWGRABHANDLES : 540 case COM.DISPID_AMBIENT_SHOWHATCHING : 541 if (pVarResult != 0) COM.MoveMemory(pVarResult, new int[] {0}, 4); 542 if (pExcepInfo != 0) COM.MoveMemory(pExcepInfo, new int[] {0}, 4); 543 if (pArgErr != 0) COM.MoveMemory(pArgErr, new int[] {0}, 4); 544 return COM.S_FALSE; 545 546 case COM.DISPID_AMBIENT_OFFLINEIFNOTCONNECTED : 548 case COM.DISPID_AMBIENT_BACKCOLOR : 549 case COM.DISPID_AMBIENT_FORECOLOR : 550 case COM.DISPID_AMBIENT_FONT : 551 case COM.DISPID_AMBIENT_LOCALEID : 552 case COM.DISPID_AMBIENT_SILENT : 553 case COM.DISPID_AMBIENT_MESSAGEREFLECT : 554 if (pVarResult != 0) COM.MoveMemory(pVarResult, new int[] {0}, 4); 555 if (pExcepInfo != 0) COM.MoveMemory(pExcepInfo, new int[] {0}, 4); 556 if (pArgErr != 0) COM.MoveMemory(pArgErr, new int[] {0}, 4); 557 return COM.E_NOTIMPL; 558 559 default : 560 if (pVarResult != 0) COM.MoveMemory(pVarResult, new int[] {0}, 4); 561 if (pExcepInfo != 0) COM.MoveMemory(pExcepInfo, new int[] {0}, 4); 562 if (pArgErr != 0) COM.MoveMemory(pArgErr, new int[] {0}, 4); 563 return COM.DISP_E_MEMBERNOTFOUND; 564 } 565 } 566 private int OnControlInfoChanged() { 567 int[] ppvObject = new int[1]; 568 if (objIUnknown.QueryInterface(COM.IIDIOleControl, ppvObject) == COM.S_OK) { 569 IOleControl objIOleControl = new IOleControl(ppvObject[0]); 570 currentControlInfo = new CONTROLINFO(); 573 objIOleControl.GetControlInfo(currentControlInfo); 574 objIOleControl.Release(); 575 } 576 return COM.S_OK; 577 } 578 void onFocusIn(Event e) { 579 if (objIOleInPlaceObject == null) return; 580 doVerb(OLE.OLEIVERB_UIACTIVATE); 581 if (isFocusControl()) return; 582 int[] phwnd = new int[1]; 583 objIOleInPlaceObject.GetWindow(phwnd); 584 if (phwnd[0] == 0) return; 585 OS.SetFocus(phwnd[0]); 586 } 587 void onFocusOut(Event e) { 588 if (objIOleInPlaceObject != null) { 589 596 int threadId = OS.GetCurrentThreadId(); 597 GUITHREADINFO lpgui1 = new GUITHREADINFO(); 598 lpgui1.cbSize = GUITHREADINFO.sizeof; 599 OS.GetGUIThreadInfo(threadId, lpgui1); 600 objIOleInPlaceObject.UIDeactivate(); 601 if (lpgui1.hwndCaret != 0) { 602 GUITHREADINFO lpgui2 = new GUITHREADINFO(); 603 lpgui2.cbSize = GUITHREADINFO.sizeof; 604 OS.GetGUIThreadInfo(threadId, lpgui2); 605 if (lpgui2.hwndCaret == 0 && lpgui1.hwndCaret == OS.GetFocus()) { 606 if (SWT_RESTORECARET == 0) { 607 SWT_RESTORECARET = OS.RegisterWindowMessage (new TCHAR (0, "SWT_RESTORECARET", true)); 608 } 609 615 if (OS.SendMessage (lpgui1.hwndCaret, SWT_RESTORECARET, 0, 0) == 0) { 616 int width = lpgui1.right - lpgui1.left; 617 int height = lpgui1.bottom - lpgui1.top; 618 OS.CreateCaret (lpgui1.hwndCaret, 0, width, height); 619 OS.SetCaretPos (lpgui1.left, lpgui1.top); 620 OS.ShowCaret (lpgui1.hwndCaret); 621 } 622 } 623 } 624 } 625 } 626 private int OnFocus(int fGotFocus) { 627 return COM.S_OK; 628 } 629 protected int OnUIDeactivate(int fUndoable) { 630 state = STATE_INPLACEACTIVE; 633 return COM.S_OK; 634 } 635 protected int QueryInterface(int riid, int ppvObject) { 636 int result = super.QueryInterface(riid, ppvObject); 637 if (result == COM.S_OK) 638 return result; 639 if (riid == 0 || ppvObject == 0) 640 return COM.E_INVALIDARG; 641 GUID guid = new GUID(); 642 COM.MoveMemory(guid, riid, GUID.sizeof); 643 if (COM.IsEqualGUID(guid, COM.IIDIOleControlSite)) { 644 COM.MoveMemory(ppvObject, new int[] {iOleControlSite.getAddress()}, 4); 645 AddRef(); 646 return COM.S_OK; 647 } 648 if (COM.IsEqualGUID(guid, COM.IIDIDispatch)) { 649 COM.MoveMemory(ppvObject, new int[] {iDispatch.getAddress()}, 4); 650 AddRef(); 651 return COM.S_OK; 652 } 653 COM.MoveMemory(ppvObject, new int[] {0}, 4); 654 return COM.E_NOINTERFACE; 655 } 656 protected int Release() { 657 int result = super.Release(); 658 if (result == 0) { 659 for (int i = 0; i < sitePropertyIds.length; i++) { 660 sitePropertyValues[i].dispose(); 661 } 662 sitePropertyIds = new int[0]; 663 sitePropertyValues = new Variant[0]; 664 } 665 return result; 666 } 667 protected void releaseObjectInterfaces() { 668 669 disconnectEventSinks(); 670 671 disconnectPropertyChangeSink(); 672 673 super.releaseObjectInterfaces(); 674 } 675 686 public void removeEventListener(int eventID, OleListener listener) { 687 checkWidget(); 688 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); 689 690 GUID riid = getDefaultEventSinkGUID(objIUnknown); 691 if (riid != null) { 692 removeEventListener(objIUnknown.getAddress(), riid, eventID, listener); 693 } 694 } 695 713 public void removeEventListener(OleAutomation automation, GUID guid, int eventID, OleListener listener) { 714 checkWidget(); 715 if (automation == null || listener == null || guid == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); 716 removeEventListener(automation.getAddress(), guid, eventID, listener); 717 } 718 733 public void removeEventListener(OleAutomation automation, int eventID, OleListener listener) { 734 checkWidget(); 735 if (automation == null || listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); 736 int address = automation.getAddress(); 737 IUnknown unknown = new IUnknown(address); 738 GUID riid = getDefaultEventSinkGUID(unknown); 739 if (riid != null) { 740 removeEventListener(address, riid, eventID, listener); 741 } 742 } 743 void removeEventListener(int iunknown, GUID guid, int eventID, OleListener listener) { 744 if (listener == null || guid == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); 745 for (int i = 0; i < oleEventSink.length; i++) { 746 if (COM.IsEqualGUID(oleEventSinkGUID[i], guid)) { 747 if (iunknown == oleEventSinkIUnknown[i]) { 748 oleEventSink[i].removeListener(eventID, listener); 749 if (!oleEventSink[i].hasListeners()) { 750 oleEventSink[i].disconnect(); 752 oleEventSink[i].Release(); 753 int oldLength = oleEventSink.length; 754 if (oldLength == 1) { 755 oleEventSink = new OleEventSink[0]; 756 oleEventSinkGUID = new GUID[0]; 757 oleEventSinkIUnknown = new int[0]; 758 } else { 759 OleEventSink[] newOleEventSink = new OleEventSink[oldLength - 1]; 760 System.arraycopy(oleEventSink, 0, newOleEventSink, 0, i); 761 System.arraycopy(oleEventSink, i + 1, newOleEventSink, i, oldLength - i - 1); 762 oleEventSink = newOleEventSink; 763 764 GUID[] newOleEventSinkGUID = new GUID[oldLength - 1]; 765 System.arraycopy(oleEventSinkGUID, 0, newOleEventSinkGUID, 0, i); 766 System.arraycopy(oleEventSinkGUID, i + 1, newOleEventSinkGUID, i, oldLength - i - 1); 767 oleEventSinkGUID = newOleEventSinkGUID; 768 769 int[] newOleEventSinkIUnknown = new int[oldLength - 1]; 770 System.arraycopy(oleEventSinkIUnknown, 0, newOleEventSinkIUnknown, 0, i); 771 System.arraycopy(oleEventSinkIUnknown, i + 1, newOleEventSinkIUnknown, i, oldLength - i - 1); 772 oleEventSinkIUnknown = newOleEventSinkIUnknown; 773 } 774 } 775 return; 776 } 777 } 778 } 779 } 780 789 public void removePropertyListener(int propertyID, OleListener listener) { 790 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); 791 olePropertyChangeSink.removeListener(propertyID, listener); 792 } 793 public void setBackground (Color color) { 794 795 super.setBackground(color); 796 797 if (objIUnknown != null) { 799 OleAutomation oleObject= new OleAutomation(this); 800 oleObject.setProperty(COM.DISPID_BACKCOLOR, new Variant(color.handle)); 801 oleObject.dispose(); 802 } 803 } 804 public void setFont (Font font) { 805 806 super.setFont(font); 807 808 if (objIUnknown != null) { 810 811 OleAutomation oleObject= new OleAutomation(this); 812 Variant varDispFont = oleObject.getProperty(COM.DISPID_FONT); 813 oleObject.dispose(); 814 815 if (varDispFont != null){ 816 OleAutomation iDispFont = varDispFont.getAutomation(); 817 FontData[] fdata = font.getFontData(); 818 iDispFont.setProperty(COM.DISPID_FONT_NAME, new Variant(fdata[0].getName())); 819 iDispFont.setProperty(COM.DISPID_FONT_SIZE, new Variant(fdata[0].getHeight())); 820 iDispFont.setProperty(COM.DISPID_FONT_ITALIC, new Variant(fdata[0].getStyle() & SWT.ITALIC)); 821 iDispFont.setProperty(COM.DISPID_FONT_BOLD, new Variant((fdata[0].getStyle() & SWT.BOLD))); 823 iDispFont.dispose(); 824 } 825 } 826 827 return; 828 } 829 public void setForeground (Color color) { 830 831 super.setForeground(color); 832 833 if (objIUnknown != null) { 835 OleAutomation oleObject= new OleAutomation(this); 836 oleObject.setProperty(COM.DISPID_FORECOLOR, new Variant(color.handle)); 837 oleObject.dispose(); 838 } 839 } 840 850 public void setSiteProperty(int dispId, Variant value){ 851 for (int i = 0; i < sitePropertyIds.length; i++) { 852 if (sitePropertyIds[i] == dispId) { 853 if (sitePropertyValues[i] != null) { 854 sitePropertyValues[i].dispose(); 855 } 856 if (value != null) { 857 sitePropertyValues[i] = value; 858 } else { 859 int oldLength = sitePropertyIds.length; 860 int[] newSitePropertyIds = new int[oldLength - 1]; 861 Variant[] newSitePropertyValues = new Variant[oldLength - 1]; 862 System.arraycopy(sitePropertyIds, 0, newSitePropertyIds, 0, i); 863 System.arraycopy(sitePropertyIds, i + 1, newSitePropertyIds, i, oldLength - i - 1); 864 System.arraycopy(sitePropertyValues, 0, newSitePropertyValues, 0, i); 865 System.arraycopy(sitePropertyValues, i + 1, newSitePropertyValues, i, oldLength - i - 1); 866 sitePropertyIds = newSitePropertyIds; 867 sitePropertyValues = newSitePropertyValues; 868 } 869 return; 870 } 871 } 872 int oldLength = sitePropertyIds.length; 873 int[] newSitePropertyIds = new int[oldLength + 1]; 874 Variant[] newSitePropertyValues = new Variant[oldLength + 1]; 875 System.arraycopy(sitePropertyIds, 0, newSitePropertyIds, 0, oldLength); 876 System.arraycopy(sitePropertyValues, 0, newSitePropertyValues, 0, oldLength); 877 newSitePropertyIds[oldLength] = dispId; 878 newSitePropertyValues[oldLength] = value; 879 sitePropertyIds = newSitePropertyIds; 880 sitePropertyValues = newSitePropertyValues; 881 } 882 } 883 | Popular Tags |