⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oleclientsite.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
 */public String getProgramID(){	if (appClsid != null){		int[] lplpszProgID = new int[1];		if (COM.ProgIDFromCLSID(appClsid, lplpszProgID) == COM.S_OK) {			int hMem = lplpszProgID[0];			int length = OS.GlobalSize(hMem);			int ptr = OS.GlobalLock(hMem);			char[] buffer = new char[length];			COM.MoveMemory(buffer, ptr, length);			OS.GlobalUnlock(hMem);			OS.GlobalFree(hMem);			String result = new String(buffer);			// remove null terminator			int index = result.indexOf("\0");			return result.substring(0, index);		}	}	return null;}int ActivateMe(int pViewToActivate) {	if (pViewToActivate == 0) {		int[] ppvObject = new int[1];		if (objIUnknown.QueryInterface(COM.IIDIOleDocument, ppvObject) != COM.S_OK) return COM.E_FAIL;		IOleDocument objOleDocument = new IOleDocument(ppvObject[0]);		if (objOleDocument.CreateView(iOleInPlaceSite.getAddress(), 0, 0, ppvObject) != COM.S_OK) return COM.E_FAIL;		objOleDocument.Release();		objDocumentView = new IOleDocumentView(ppvObject[0]);	} else {		objDocumentView = new IOleDocumentView(pViewToActivate);		objDocumentView.AddRef();		objDocumentView.SetInPlaceSite(iOleInPlaceSite.getAddress());	}	objDocumentView.UIActivate(1);//TRUE	RECT rect = getRect();	objDocumentView.SetRect(rect);	objDocumentView.Show(1);//TRUE	return COM.S_OK;}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[] {frame.handle}, 4);	return COM.S_OK;}RECT getRect() {	Point location = this.getLocation();	Rectangle area = frame.getClientArea();	RECT rect = new RECT();	rect.left   = location.x;	rect.top    = location.y;	rect.right  = location.x + area.width - borderWidths.left - borderWidths.right;	rect.bottom = location.y + area.height - borderWidths.top - borderWidths.bottom;	return rect;}private int GetWindowContext(int ppFrame, int ppDoc, int lprcPosRect, int lprcClipRect, int lpFrameInfo) {		if (frame == null || ppFrame == 0)		return COM.E_NOTIMPL;	// fill in frame handle	int iOleInPlaceFrame = frame.getIOleInPlaceFrame();	COM.MoveMemory(ppFrame, new int[] {iOleInPlaceFrame}, 4);	frame.AddRef();	// null out document handle	if (ppDoc != 0) COM.MoveMemory(ppDoc, new int[] {0}, 4);	// fill in position and clipping info	RECT rect = getRect();	if (lprcPosRect != 0) OS.MoveMemory(lprcPosRect, rect, RECT.sizeof);	if (lprcClipRect != 0) OS.MoveMemory(lprcClipRect, rect, RECT.sizeof);	// get frame info	OLEINPLACEFRAMEINFO frameInfo = new OLEINPLACEFRAMEINFO();	frameInfo.cb = OLEINPLACEFRAMEINFO.sizeof;	frameInfo.fMDIApp = 0;	frameInfo.hwndFrame = frame.handle;	Shell shell = getShell();	Menu menubar = shell.getMenuBar();	if (menubar != null && !menubar.isDisposed()) {		int hwnd = shell.handle;		int cAccel = OS.SendMessage(hwnd, OS.WM_APP, 0, 0);		if (cAccel != 0) {			int hAccel = OS.SendMessage(hwnd, OS.WM_APP+1, 0, 0);			if (hAccel != 0) {				frameInfo.cAccelEntries = cAccel;				frameInfo.haccel = hAccel;			}		}	}	COM.MoveMemory(lpFrameInfo, frameInfo, OLEINPLACEFRAMEINFO.sizeof);		return COM.S_OK;}public boolean isDirty() {	/*	 *  Note: this method must return true unless it is absolutely clear that the	 * contents of the Ole Document do not differ from the contents in the file	 * on the file system.	 */		// Get access to the persistant storage mechanism	int[] address = new int[1];	if (objIOleObject.QueryInterface(COM.IIDIPersistFile, address) != COM.S_OK)		return true;	IPersistStorage permStorage = new IPersistStorage(address[0]);	// Are the contents of the permanent storage different from the file?	int result = permStorage.IsDirty();	permStorage.Release();	if (result == COM.S_FALSE) return false;	return true;}public boolean isFocusControl () {	checkWidget ();	int focusHwnd = OS.GetFocus();	if (objIOleInPlaceObject == null) return (handle == focusHwnd); 	int[] phwnd = new int[1];	objIOleInPlaceObject.GetWindow(phwnd);	while (focusHwnd != 0) {		if (phwnd[0] == focusHwnd) return true;		focusHwnd = OS.GetParent(focusHwnd);	}	return false;}private int OnClose() {	return COM.S_OK;}private int OnDataChange(int pFormatetc, int pStgmed) {	return COM.S_OK;}private void onDispose(Event e) {	inDispose = true;	if (state != STATE_NONE)		doVerb(OLE.OLEIVERB_DISCARDUNDOSTATE);	deactivateInPlaceClient();	releaseObjectInterfaces(); // Note, must release object interfaces before releasing frame	deleteTempStorage();		// remove listeners	removeListener(SWT.Dispose, listener);	removeListener(SWT.FocusIn, listener);	removeListener(SWT.Paint, listener);	removeListener(SWT.Traverse, listener);	removeListener(SWT.KeyDown, listener);	frame.removeListener(SWT.Resize, listener);	frame.removeListener(SWT.Move, listener);		frame.Release();	frame = null;}void onFocusIn(Event e) {	if (inDispose) return;	if (state != STATE_UIACTIVE) doVerb(OLE.OLEIVERB_SHOW);	if (objIOleInPlaceObject == null) return;	if (isFocusControl()) return;	int[] phwnd = new int[1];	objIOleInPlaceObject.GetWindow(phwnd);	if (phwnd[0] == 0) return;	OS.SetFocus(phwnd[0]);}void onFocusOut(Event e) {}private int OnInPlaceActivate() {	state = STATE_INPLACEACTIVE;	frame.setCurrentDocument(this);	if (objIOleObject == null)		return COM.S_OK;	int[] ppvObject = new int[1];	if (objIOleObject.QueryInterface(COM.IIDIOleInPlaceObject, ppvObject) == COM.S_OK) {		objIOleInPlaceObject = new IOleInPlaceObject(ppvObject[0]);	}	return COM.S_OK;}private int OnInPlaceDeactivate() {	if (objIOleInPlaceObject != null) objIOleInPlaceObject.Release();	objIOleInPlaceObject = null;	state = STATE_RUNNING;	redraw();	if (getDisplay().getFocusControl() == null) {		getShell().traverse(SWT.TRAVERSE_TAB_NEXT);	}	return COM.S_OK;}private int OnPosRectChange(int lprcPosRect) {	Point size = getSize();	setExtent(size.x, size.y);	return COM.S_OK;}private void onPaint(Event e) {	if (state == STATE_RUNNING || state == STATE_INPLACEACTIVE) {		SIZE size = getExtent();		Rectangle area = getClientArea();		RECT rect = new RECT();		if (getProgramID().startsWith("Excel.Sheet")) { //$NON-NLS-1$			rect.left = area.x; rect.right = area.x + (area.height * size.cx / size.cy);			rect.top = area.y; rect.bottom = area.y + area.height;		} else {			rect.left = area.x; rect.right = area.x + size.cx;			rect.top = area.y; rect.bottom = area.y + size.cy;		}				int pArea = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, RECT.sizeof);		OS.MoveMemory(pArea, rect, RECT.sizeof);		COM.OleDraw(objIUnknown.getAddress(), aspect, e.gc.handle, pArea);		OS.GlobalFree(pArea);	}}private void onResize(Event e) {	Rectangle area = frame.getClientArea();	setBounds(borderWidths.left, 		      borderWidths.top, 			  area.width - borderWidths.left - borderWidths.right, 			  area.height - borderWidths.top - borderWidths.bottom);	setObjectRects();}private void OnSave() {}private int OnShowWindow(int fShow) {	return COM.S_OK;}private int OnUIActivate() {	if (objIOleInPlaceObject == null) return COM.E_FAIL;	state = STATE_UIACTIVE;	int[] phwnd = new int[1];	if (objIOleInPlaceObject.GetWindow(phwnd) == COM.S_OK) {		OS.SetWindowPos(phwnd[0], OS.HWND_TOP, 0, 0, 0, 0, OS.SWP_NOSIZE | OS.SWP_NOMOVE);	}	return COM.S_OK;}private int OnUIDeactivate(int fUndoable) {	// currently, we are ignoring the fUndoable flag	if (frame == null || frame.isDisposed()) return COM.S_OK;	state = STATE_INPLACEACTIVE;	frame.SetActiveObject(0,0);	redraw();	if (getDisplay().getFocusControl() == frame) {		getShell().traverse(SWT.TRAVERSE_TAB_NEXT);	}	Shell shell = getShell();	Menu menubar = shell.getMenuBar();	if (menubar == null || menubar.isDisposed())		return COM.S_OK;			int shellHandle = shell.handle;	OS.SetMenu(shellHandle, menubar.handle);	return COM.OleSetMenuDescriptor(0, shellHandle, 0, 0, 0);}private void onTraverse(Event event) {	switch (event.detail) {		case SWT.TRAVERSE_ESCAPE:		case SWT.TRAVERSE_RETURN:		case SWT.TRAVERSE_TAB_NEXT:		case SWT.TRAVERSE_TAB_PREVIOUS:		case SWT.TRAVERSE_PAGE_NEXT:		case SWT.TRAVERSE_PAGE_PREVIOUS:		case SWT.TRAVERSE_MNEMONIC:			event.doit = true;			break;	}}private int OnViewChange(int dwAspect, int lindex) {	return COM.S_OK;}protected int QueryInterface(int riid, int ppvObject) {	if (riid == 0 || ppvObject == 0)		return COM.E_NOINTERFACE;	GUID guid = new GUID();	COM.MoveMemory(guid, riid, GUID.sizeof);	if (COM.IsEqualGUID(guid, COM.IIDIUnknown)) {		COM.MoveMemory(ppvObject, new int[] {iUnknown.getAddress()}, 4);		AddRef();		return COM.S_OK;	}	if (COM.IsEqualGUID(guid, COM.IIDIAdviseSink)) {		COM.MoveMemory(ppvObject, new int[] {iAdviseSink.getAddress()}, 4);		AddRef();		return COM.S_OK;	}	if (COM.IsEqualGUID(guid, COM.IIDIOleClientSite)) {		COM.MoveMemory(ppvObject, new int[] {iOleClientSite.getAddress()}, 4);		AddRef();		return COM.S_OK;	}	if (COM.IsEqualGUID(guid, COM.IIDIOleInPlaceSite)) {		COM.MoveMemory(ppvObject, new int[] {iOleInPlaceSite.getAddress()}, 4);		AddRef();		return COM.S_OK;	}// INTENTIONALLY COMMENTED - see bug 35493	//	if (COM.IsEqualGUID(guid, COM.IIDIOleDocumentSite )) {//		String progID = getProgramID();//		if (!progID.startsWith("PowerPoint")) { //$NON-NLS-1$//			COM.MoveMemory(ppvObject, new int[] {iOleDocumentSite.getAddress()}, 4);//			AddRef();//			return COM.S_OK;//		}//	}	COM.MoveMemory(ppvObject, new int[] {0}, 4);	return COM.E_NOINTERFACE;}/** * Returns the status of the specified command.  The status is any bitwise OR'd combination of  * SWTOLE.OLECMDF_SUPPORTED, SWTOLE.OLECMDF_ENABLED, SWTOLE.OLECMDF_LATCHED, SWTOLE.OLECMDF_NINCHED. * You can query the status of a command before invoking it with OleClientSite.exec.  The * OLE Document or ActiveX Control must support the IOleCommandTarget to make use of this method. * * @param cmd the ID of a command; these are the OLE.OLECMDID_ values - a small set of common *            commands * * @return the status of the specified command or 0 if unable to query the OLE Object; these are the *			  OLE.OLECMDF_ values */ public int queryStatus(int cmd) {		if (objIOleCommandTarget == null) {		int[] address = new int[1];		if (objIUnknown.QueryInterface(COM.IIDIOleCommandTarget, address) != COM.S_OK)			return 0;		objIOleCommandTarget = new IOleCommandTarget(address[0]);	}		OLECMD olecmd = new OLECMD();	olecmd.cmdID = cmd;		int result = objIOleCommandTarget.QueryStatus(null, 1, olecmd, null);	if (result != COM.S_OK) return 0;	return olecmd.cmdf;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -