?? olecontrolsite.java
字號:
Variant lfFaceName = iDispFont.getProperty(COM.DISPID_FONT_NAME); Variant lfHeight = iDispFont.getProperty(COM.DISPID_FONT_SIZE); Variant lfItalic = iDispFont.getProperty(COM.DISPID_FONT_ITALIC); //Variant lfCharSet = iDispFont.getProperty(COM.DISPID_FONT_CHARSET); Variant lfBold = iDispFont.getProperty(COM.DISPID_FONT_BOLD); iDispFont.dispose(); if (lfFaceName != null && lfHeight != null && lfItalic != null && lfBold != null){ int style = 3 * lfBold.getInt() + 2 * lfItalic.getInt(); Font font = new Font(getShell().getDisplay(), lfFaceName.getString(), lfHeight.getInt(), style); return font; } } } return super.getFont();}public Color getForeground () { if (objIUnknown != null) { // !! We are getting the OLE_COLOR - should we change this to the COLORREF value? OleAutomation oleObject= new OleAutomation(this); Variant varForeColor = oleObject.getProperty(COM.DISPID_FORECOLOR); oleObject.dispose(); if (varForeColor != null){ int[] colorRef = new int[1]; if (COM.OleTranslateColor(varForeColor.getInt(), getDisplay().hPalette, colorRef) == COM.S_OK) return Color.win32_new(getDisplay(), colorRef[0]); } } return super.getForeground();}protected int getLicenseInfo(GUID clsid) { int[] ppvObject = new int[1]; if (COM.CoGetClassObject(clsid, COM.CLSCTX_INPROC_HANDLER | COM.CLSCTX_INPROC_SERVER, 0, COM.IIDIClassFactory2, ppvObject) != COM.S_OK) { return 0; } IClassFactory2 classFactory = new IClassFactory2(ppvObject[0]); LICINFO licinfo = new LICINFO(); if (classFactory.GetLicInfo(licinfo) != COM.S_OK) { classFactory.Release(); return 0; } int[] pBstrKey = new int[1]; if (licinfo != null && licinfo.fRuntimeKeyAvail != 0) { if (classFactory.RequestLicKey(0, pBstrKey) == COM.S_OK) { classFactory.Release(); return pBstrKey[0]; } } classFactory.Release(); return 0;}/** * * Get the control site property specified by the dispIdMember. * * @since 2.1 * */public Variant getSiteProperty(int dispId){ for (int i = 0; i < sitePropertyIds.length; i++) { if (sitePropertyIds[i] == dispId) { return sitePropertyValues[i]; } } return null;}protected int GetWindow(int phwnd) { if (phwnd == 0) return COM.E_INVALIDARG; if (frame == null) { COM.MoveMemory(phwnd, new int[] {0}, 4); return COM.E_NOTIMPL; } // Copy the Window's handle into the memory passed in COM.MoveMemory(phwnd, new int[] {handle}, 4); return COM.S_OK;}private int Invoke(int dispIdMember, int riid, int lcid, int dwFlags, int pDispParams, int pVarResult, int pExcepInfo, int pArgErr) { if (pVarResult == 0 || dwFlags != COM.DISPATCH_PROPERTYGET) { if (pExcepInfo != 0) COM.MoveMemory(pExcepInfo, new int[] {0}, 4); if (pArgErr != 0) COM.MoveMemory(pArgErr, new int[] {0}, 4); return COM.DISP_E_MEMBERNOTFOUND; } Variant result = getSiteProperty(dispIdMember); if (result != null) { if (pVarResult != 0) result.getData(pVarResult); return COM.S_OK; } switch (dispIdMember) { // indicate a false result case COM.DISPID_AMBIENT_SUPPORTSMNEMONICS : case COM.DISPID_AMBIENT_SHOWGRABHANDLES : case COM.DISPID_AMBIENT_SHOWHATCHING : if (pVarResult != 0) COM.MoveMemory(pVarResult, new int[] {0}, 4); if (pExcepInfo != 0) COM.MoveMemory(pExcepInfo, new int[] {0}, 4); if (pArgErr != 0) COM.MoveMemory(pArgErr, new int[] {0}, 4); return COM.S_FALSE; // not implemented case COM.DISPID_AMBIENT_OFFLINEIFNOTCONNECTED : case COM.DISPID_AMBIENT_BACKCOLOR : case COM.DISPID_AMBIENT_FORECOLOR : case COM.DISPID_AMBIENT_FONT : case COM.DISPID_AMBIENT_LOCALEID : case COM.DISPID_AMBIENT_SILENT : case COM.DISPID_AMBIENT_MESSAGEREFLECT : if (pVarResult != 0) COM.MoveMemory(pVarResult, new int[] {0}, 4); if (pExcepInfo != 0) COM.MoveMemory(pExcepInfo, new int[] {0}, 4); if (pArgErr != 0) COM.MoveMemory(pArgErr, new int[] {0}, 4); return COM.E_NOTIMPL; default : if (pVarResult != 0) COM.MoveMemory(pVarResult, new int[] {0}, 4); if (pExcepInfo != 0) COM.MoveMemory(pExcepInfo, new int[] {0}, 4); if (pArgErr != 0) COM.MoveMemory(pArgErr, new int[] {0}, 4); return COM.DISP_E_MEMBERNOTFOUND; }}private int OnControlInfoChanged() { int[] ppvObject = new int[1]; if (objIUnknown.QueryInterface(COM.IIDIOleControl, ppvObject) == COM.S_OK) { IOleControl objIOleControl = new IOleControl(ppvObject[0]); // ask the control for its info in case users // need to act on it currentControlInfo = new CONTROLINFO(); objIOleControl.GetControlInfo(currentControlInfo); objIOleControl.Release(); } return COM.S_OK;}void onFocusIn(Event e) { if (objIOleInPlaceObject == null) return; doVerb(OLE.OLEIVERB_UIACTIVATE); if (isFocusControl()) return; int[] phwnd = new int[1]; objIOleInPlaceObject.GetWindow(phwnd); if (phwnd[0] == 0) return; OS.SetFocus(phwnd[0]);}void onFocusOut(Event e) { if (objIOleInPlaceObject != null) { objIOleInPlaceObject.UIDeactivate(); }}private int OnFocus(int fGotFocus) { return COM.S_OK;}protected int OnUIDeactivate(int fUndoable) { // controls don't need to do anything for // border space or menubars state = STATE_INPLACEACTIVE; return COM.S_OK;}protected int QueryInterface(int riid, int ppvObject) { int result = super.QueryInterface(riid, ppvObject); if (result == COM.S_OK) return result; if (riid == 0 || ppvObject == 0) return COM.E_INVALIDARG; GUID guid = new GUID(); COM.MoveMemory(guid, riid, GUID.sizeof); if (COM.IsEqualGUID(guid, COM.IIDIOleControlSite)) { COM.MoveMemory(ppvObject, new int[] {iOleControlSite.getAddress()}, 4); AddRef(); return COM.S_OK; } if (COM.IsEqualGUID(guid, COM.IIDIDispatch)) { COM.MoveMemory(ppvObject, new int[] {iDispatch.getAddress()}, 4); AddRef(); return COM.S_OK; } COM.MoveMemory(ppvObject, new int[] {0}, 4); return COM.E_NOINTERFACE;}protected int Release() { int result = super.Release(); if (result == 0) { for (int i = 0; i < sitePropertyIds.length; i++) { sitePropertyValues[i].dispose(); } sitePropertyIds = new int[0]; sitePropertyValues = new Variant[0]; } return result;}protected void releaseObjectInterfaces() { disconnectEventSinks(); disconnectPropertyChangeSink(); super.releaseObjectInterfaces();}/** * Removes the listener. * * @param eventID the event identifier * * @param listener the listener * * @exception SWTError * <ul><li>ERROR_NULL_ARGUMENT when listener is null</li></ul> */public void removeEventListener(int eventID, OleListener listener) { checkWidget(); if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); GUID riid = getDefaultEventSinkGUID(objIUnknown); if (riid != null) { removeEventListener(objIUnknown.getAddress(), riid, eventID, listener); }}/** * Removes the listener. * * @since 2.0 * @deprecated - use OleControlSite.removeEventListener(OleAutomation, int, OleListener) * * @param automation the automation object that provides the event notification * * @param guid the identifier of the events COM interface * * @param eventID the event identifier * * @param listener the listener * * @exception SWTError * <ul><li>ERROR_NULL_ARGUMENT when listener is null</li></ul> */public void removeEventListener(OleAutomation automation, GUID guid, int eventID, OleListener listener) { checkWidget(); if (automation == null || listener == null || guid == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); removeEventListener(automation.getAddress(), guid, eventID, listener);}/** * Removes the listener. * * @since 2.0 * * @param automation the automation object that provides the event notification * * @param eventID the event identifier * * @param listener the listener * * @exception SWTError * <ul><li>ERROR_NULL_ARGUMENT when listener is null</li></ul> */public void removeEventListener(OleAutomation automation, int eventID, OleListener listener) { checkWidget(); if (automation == null || listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); int address = automation.getAddress(); IUnknown unknown = new IUnknown(address); GUID riid = getDefaultEventSinkGUID(unknown); if (riid != null) { removeEventListener(address, riid, eventID, listener); }}void removeEventListener(int iunknown, GUID guid, int eventID, OleListener listener) { if (listener == null || guid == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); for (int i = 0; i < oleEventSink.length; i++) { if (COM.IsEqualGUID(oleEventSinkGUID[i], guid)) { if (iunknown == oleEventSinkIUnknown[i]) { oleEventSink[i].removeListener(eventID, listener); if (!oleEventSink[i].hasListeners()) { //free resources associated with event sink oleEventSink[i].disconnect(); oleEventSink[i].Release(); int oldLength = oleEventSink.length; if (oldLength == 1) { oleEventSink = new OleEventSink[0]; oleEventSinkGUID = new GUID[0]; oleEventSinkIUnknown = new int[0]; } else { OleEventSink[] newOleEventSink = new OleEventSink[oldLength - 1]; System.arraycopy(oleEventSink, 0, newOleEventSink, 0, i); System.arraycopy(oleEventSink, i + 1, newOleEventSink, i, oldLength - i - 1); oleEventSink = newOleEventSink; GUID[] newOleEventSinkGUID = new GUID[oldLength - 1]; System.arraycopy(oleEventSinkGUID, 0, newOleEventSinkGUID, 0, i); System.arraycopy(oleEventSinkGUID, i + 1, newOleEventSinkGUID, i, oldLength - i - 1); oleEventSinkGUID = newOleEventSinkGUID; int[] newOleEventSinkIUnknown = new int[oldLength - 1]; System.arraycopy(oleEventSinkIUnknown, 0, newOleEventSinkIUnknown, 0, i); System.arraycopy(oleEventSinkIUnknown, i + 1, newOleEventSinkIUnknown, i, oldLength - i - 1); oleEventSinkIUnknown = newOleEventSinkIUnknown; } } return; } } }}/** * Removes the listener. * * @param listener the listener * * @exception SWTError * <ul><li>ERROR_NULL_ARGUMENT when listener is null</li></ul> */public void removePropertyListener(int propertyID, OleListener listener) { if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); olePropertyChangeSink.removeListener(propertyID, listener);}public void setBackground (Color color) { super.setBackground(color); //set the background of the ActiveX Control if (objIUnknown != null) { OleAutomation oleObject= new OleAutomation(this); oleObject.setProperty(COM.DISPID_BACKCOLOR, new Variant(color.handle)); oleObject.dispose(); }}public void setFont (Font font) { super.setFont(font); //set the font of the ActiveX Control if (objIUnknown != null) { OleAutomation oleObject= new OleAutomation(this); Variant varDispFont = oleObject.getProperty(COM.DISPID_FONT); oleObject.dispose(); if (varDispFont != null){ OleAutomation iDispFont = varDispFont.getAutomation(); FontData[] fdata = font.getFontData(); iDispFont.setProperty(COM.DISPID_FONT_NAME, new Variant(fdata[0].getName())); iDispFont.setProperty(COM.DISPID_FONT_SIZE, new Variant(fdata[0].getHeight())); iDispFont.setProperty(COM.DISPID_FONT_ITALIC, new Variant(fdata[0].getStyle() & SWT.ITALIC)); //iDispFont.setProperty(COM.DISPID_FONT_CHARSET, new Variant(fdata[0].getCharset)); iDispFont.setProperty(COM.DISPID_FONT_BOLD, new Variant((fdata[0].getStyle() & SWT.BOLD))); iDispFont.dispose(); } } return;}public void setForeground (Color color) { super.setForeground(color); //set the foreground of the ActiveX Control if (objIUnknown != null) { OleAutomation oleObject= new OleAutomation(this); oleObject.setProperty(COM.DISPID_FORECOLOR, new Variant(color.handle)); oleObject.dispose(); }}/** * Sets the control site property specified by the dispIdMember to a new value. * The value will be disposed by the control site when it is no longer required * using Variant.dispose. Passing a value of null will clear the dispId value. * * @param dispId the ID of the property as specified by the IDL of the ActiveX Control * @param value The new value for the property as expressed in a Variant. * */public void setSiteProperty(int dispId, Variant value){ for (int i = 0; i < sitePropertyIds.length; i++) { if (sitePropertyIds[i] == dispId) { if (sitePropertyValues[i] != null) { sitePropertyValues[i].dispose(); if (value != null) { sitePropertyValues[i] = value; } else { int oldLength = sitePropertyIds.length; int[] newSitePropertyIds = new int[oldLength - 1]; Variant[] newSitePropertyValues = new Variant[oldLength - 1]; System.arraycopy(sitePropertyIds, 0, newSitePropertyIds, 0, i); System.arraycopy(sitePropertyIds, i + 1, newSitePropertyIds, i, oldLength - i - 1); System.arraycopy(sitePropertyValues, 0, newSitePropertyValues, 0, i); System.arraycopy(sitePropertyValues, i + 1, newSitePropertyValues, i, oldLength - i - 1); sitePropertyIds = newSitePropertyIds; sitePropertyValues = newSitePropertyValues; } return; } } int oldLength = sitePropertyIds.length; int[] newSitePropertyIds = new int[oldLength + 1]; Variant[] newSitePropertyValues = new Variant[oldLength + 1]; System.arraycopy(sitePropertyIds, 0, newSitePropertyIds, 0, oldLength); System.arraycopy(sitePropertyValues, 0, newSitePropertyValues, 0, oldLength); newSitePropertyIds[oldLength] = dispId; newSitePropertyValues[oldLength] = value; sitePropertyIds = newSitePropertyIds; sitePropertyValues = newSitePropertyValues;}}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -