?? oleclientsite.java
字號(hào):
protected int Release() { refCount--; if (refCount == 0) { disposeCOMInterfaces(); } return refCount;}protected void releaseObjectInterfaces() { if (objIOleInPlaceObject!= null) objIOleInPlaceObject.Release(); objIOleInPlaceObject = null; if (objIOleObject != null) { objIOleObject.Close(COM.OLECLOSE_NOSAVE); objIOleObject.Release(); } objIOleObject = null; if (objDocumentView != null){ objDocumentView.Release(); } objDocumentView = null; if (objIViewObject2 != null) { objIViewObject2.SetAdvise(aspect, 0, 0); objIViewObject2.Release(); } objIViewObject2 = null; if (objIOleCommandTarget != null) objIOleCommandTarget.Release(); objIOleCommandTarget = null; if (objIUnknown != null){ objIUnknown.Release(); } objIUnknown = null; COM.CoFreeUnusedLibraries();}public boolean save(File file, boolean includeOleInfo) { if (includeOleInfo) return saveToStorageFile(file); return saveToTraditionalFile(file);}private boolean saveFromContents(int address, File file) { boolean success = false; IStream tempContents = new IStream(address); tempContents.AddRef(); try { FileOutputStream writer = new FileOutputStream(file); int increment = 1024 * 4; int pv = COM.CoTaskMemAlloc(increment); int[] pcbWritten = new int[1]; while (tempContents.Read(pv, increment, pcbWritten) == COM.S_OK && pcbWritten[0] > 0) { byte[] buffer = new byte[ pcbWritten[0]]; OS.MoveMemory(buffer, pv, pcbWritten[0]); writer.write(buffer); // Note: if file does not exist, this will create the file the // first time it is called success = true; } COM.CoTaskMemFree(pv); writer.close(); } catch (IOException err) { } tempContents.Release(); return success;}private boolean saveFromOle10Native(int address, File file) { boolean success = false; IStream tempContents = new IStream(address); tempContents.AddRef(); // The "\1Ole10Native" stream contains a DWORD header whose value is the length // of the native data that follows. int pv = COM.CoTaskMemAlloc(4); int[] size = new int[1]; int rc = tempContents.Read(pv, 4, null); OS.MoveMemory(size, pv, 4); COM.CoTaskMemFree(pv); if (rc == COM.S_OK && size[0] > 0) { // Read the data byte[] buffer = new byte[size[0]]; pv = COM.CoTaskMemAlloc(size[0]); rc = tempContents.Read(pv, size[0], null); OS.MoveMemory(buffer, pv, size[0]); COM.CoTaskMemFree(pv); // open the file and write data into it try { FileOutputStream writer = new FileOutputStream(file); writer.write(buffer); // Note: if file does not exist, this will create the file writer.close(); success = true; } catch (IOException err) { } } tempContents.Release(); return success;}private int SaveObject() { updateStorage(); return COM.S_OK;}/** * Saves the document to the specified file and includes OLE spcific inforrmation. This method * must <b>only</b> be used for files that have an OLE Storage format. For example, a word file * edited with Word.Document should be saved using this method because there is formating information * that should be stored in the OLE specific Storage format. * * @param file the file to which the changes are to be saved * * @return true if the save was successful */private boolean saveToStorageFile(File file) { // The file will be saved using the formating of the current application - this // may not be the format of the application that was originally used to create the file // e.g. if an Excel file is opened in Word, the Word application will save the file in the // Word format // Note: if the file already exists, some applications will not overwrite the file // In these cases, you should delete the file first (probably save the contents of the file in case the // save fails) if (file == null || file.isDirectory()) return false; if (!updateStorage()) return false; // get access to the persistant storage mechanism int[] address = new int[1]; if (objIOleObject.QueryInterface(COM.IIDIPersistStorage, address) != COM.S_OK) return false; IPersistStorage permStorage = new IPersistStorage(address[0]); try { address = new int[1]; char[] path = (file.getAbsolutePath()+"\0").toCharArray(); int mode = COM.STGM_TRANSACTED | COM.STGM_READWRITE | COM.STGM_SHARE_EXCLUSIVE | COM.STGM_CREATE; int result = COM.StgCreateDocfile(path, mode, 0, address); //Does an AddRef if successful if (result != COM.S_OK) return false; IStorage storage = new IStorage(address[0]); try { if (COM.OleSave(permStorage.getAddress(), storage.getAddress(), false) == COM.S_OK) { if (storage.Commit(COM.STGC_DEFAULT) == COM.S_OK) { return true; } } } finally { storage.Release(); } } finally { permStorage.Release(); } return false;}/** * Saves the document to the specified file. This method must be used for * files that do not have an OLE Storage format. For example, a bitmap file edited with MSPaint * should be saved using this method because bitmap is a standard format that does not include any * OLE specific data. * * @param file the file to which the changes are to be saved * * @return true if the save was successful */private boolean saveToTraditionalFile(File file) { // Note: if the file already exists, some applications will not overwrite the file // In these cases, you should delete the file first (probably save the contents of the file in case the // save fails) if (file == null || file.isDirectory()) return false; if (!updateStorage()) return false; int[] address = new int[1]; // Look for a CONTENTS stream if (tempStorage.OpenStream("CONTENTS", 0, COM.STGM_DIRECT | COM.STGM_READ | COM.STGM_SHARE_EXCLUSIVE, 0, address) == COM.S_OK) //$NON-NLS-1$ return saveFromContents(address[0], file); // Look for Ole 1.0 object stream if (tempStorage.OpenStream("\1Ole10Native", 0, COM.STGM_DIRECT | COM.STGM_READ | COM.STGM_SHARE_EXCLUSIVE, 0, address) == COM.S_OK) //$NON-NLS-1$ return saveFromOle10Native(address[0], file); return false;}private int Scroll(int scrollExtant) { return COM.S_OK;}void setBorderSpace(RECT newBorderwidth) { borderWidths = newBorderwidth; // readjust size and location of client site Rectangle area = frame.getClientArea(); setBounds(borderWidths.left, borderWidths.top, area.width - borderWidths.left - borderWidths.right, area.height - borderWidths.top - borderWidths.bottom); setObjectRects();}private void setExtent(int width, int height){ // Resize the width and height of the embedded/linked OLENatives object // to the specified values. if (objIOleObject == null || isStatic || inUpdate) return; SIZE currentExtent = getExtent(); if (width == currentExtent.cx && height == currentExtent.cy) return; SIZE newExtent = new SIZE(); newExtent.cx = width; newExtent.cy = height; newExtent = xFormPixelsToHimetric(newExtent); // Get the server running first, then do a SetExtent, then show it boolean alreadyRunning = COM.OleIsRunning(objIOleObject.getAddress()); if (!alreadyRunning) COM.OleRun(objIOleObject.getAddress()); if (objIOleObject.SetExtent(aspect, newExtent) == COM.S_OK){ inUpdate = true; objIOleObject.Update(); inUpdate = false; if (!alreadyRunning) // Close server if it wasn't already running upon entering this method. objIOleObject.Close(COM.OLECLOSE_SAVEIFDIRTY); }}public void setIndent(Rectangle newIndent) { indent = new RECT(); indent.left = newIndent.x; indent.right = newIndent.width; indent.top = newIndent.y; indent.bottom = newIndent.height;}private void setObjectRects() { if (objIOleInPlaceObject == null) return; // size the object to fill the available space // leave a border RECT rect = getRect(); objIOleInPlaceObject.SetObjectRects(rect, rect);}private int ShowObject() { /* Tells the container to position the object so it is visible to * the user. This method ensures that the container itself is * visible and not minimized. */ return COM.S_OK;}/** * Displays a dialog with the property information for this OLE Object. The OLE Document or * ActiveX Control must support the ISpecifyPropertyPages interface. * * @param title the name that will appear in the titlebar of the dialog */public void showProperties(String title) { // Get the Property Page information from the OLE Object int[] ppvObject = new int[1]; if (objIUnknown.QueryInterface(COM.IIDISpecifyPropertyPages, ppvObject) != COM.S_OK) return; ISpecifyPropertyPages objISPP = new ISpecifyPropertyPages(ppvObject[0]); CAUUID caGUID = new CAUUID(); int result = objISPP.GetPages(caGUID); objISPP.Release(); if (result != COM.S_OK) return; // create a frame in which to display the pages char[] chTitle = null; if (title != null) { chTitle = new char[title.length()]; title.getChars(0, title.length(), chTitle, 0); } result = COM.OleCreatePropertyFrame(frame.handle, 10, 10, chTitle, 1, new int[] {objIUnknown.getAddress()}, caGUID.cElems, caGUID.pElems, COM.LOCALE_USER_DEFAULT, 0, 0); // free the property page information COM.CoTaskMemFree(caGUID.pElems);}private boolean updateStorage() { if (tempStorage == null) return false; int[] ppv = new int[1]; if (objIUnknown.QueryInterface(COM.IIDIPersistStorage, ppv) != COM.S_OK) return false; IPersistStorage iPersistStorage = new IPersistStorage(ppv[0]); int result = COM.OleSave(iPersistStorage.getAddress(), tempStorage.getAddress(), true); if (result != COM.S_OK){ // OleSave will fail for static objects, so do what OleSave does. COM.WriteClassStg(tempStorage.getAddress(), objClsid); result = iPersistStorage.Save(tempStorage.getAddress(), true); } tempStorage.Commit(COM.STGC_DEFAULT); result = iPersistStorage.SaveCompleted(0); iPersistStorage.Release(); return true;}private SIZE xFormHimetricToPixels(SIZE aSize) { // Return a new Size which is the pixel transformation of a // size in HIMETRIC units. int hDC = OS.GetDC(0); int xppi = OS.GetDeviceCaps(hDC, 88); // logical pixels/inch in x int yppi = OS.GetDeviceCaps(hDC, 90); // logical pixels/inch in y OS.ReleaseDC(0, hDC); int cx = Compatibility.round(aSize.cx * xppi, 2540); // 2540 HIMETRIC units per inch int cy = Compatibility.round(aSize.cy * yppi, 2540); SIZE size = new SIZE(); size.cx = cx; size.cy = cy; return size;}private SIZE xFormPixelsToHimetric(SIZE aSize) { // Return a new size which is the HIMETRIC transformation of a // size in pixel units. int hDC = OS.GetDC(0); int xppi = OS.GetDeviceCaps(hDC, 88); // logical pixels/inch in x int yppi = OS.GetDeviceCaps(hDC, 90); // logical pixels/inch in y OS.ReleaseDC(0, hDC); int cx = Compatibility.round(aSize.cx * 2540, xppi); // 2540 HIMETRIC units per inch int cy = Compatibility.round(aSize.cy * 2540, yppi); SIZE size = new SIZE(); size.cx = cx; size.cy = cy; return size;}}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -