1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DocumentHandle.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package complex
.persistent_window_states
;
33 import com
.sun
.star
.awt
.Rectangle
;
34 import com
.sun
.star
.awt
.PosSize
;
35 import com
.sun
.star
.frame
.XComponentLoader
;
36 import com
.sun
.star
.lang
.XComponent
;
37 import com
.sun
.star
.awt
.XWindow
;
38 import com
.sun
.star
.beans
.PropertyValue
;
39 import com
.sun
.star
.beans
.PropertyState
;
40 import com
.sun
.star
.frame
.XController
;
41 import com
.sun
.star
.frame
.FrameSearchFlag
;
42 import com
.sun
.star
.text
.XTextDocument
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.frame
.XFrame
;
45 import com
.sun
.star
.frame
.FrameSearchFlag
;
46 import com
.sun
.star
.frame
.XFramesSupplier
;
47 import helper
.WindowListener
;
50 * Load and resize a document.
53 public class DocumentHandle
{
54 // the component loader to load a document
55 XComponentLoader xCompLoader
= null;
57 XComponent xComp
= null;
60 // a own window listener
61 WindowListener wl
= null;
65 * @param xComponentLoader A loader to load a document
67 public DocumentHandle(XComponentLoader xCompLoader
) {
68 this.xCompLoader
= xCompLoader
;
69 wl
= new WindowListener();
73 * Load/Create a document.
74 * @param docName The name of a document as file URL
75 * @param hidden If true, the document is loaded hidden.
76 * @return The size of the opened/created document.
78 public Rectangle
loadDocument(String docName
, boolean hidden
)
82 PropertyValue
[] szArgs
= null;
84 szArgs
= new PropertyValue
[1];
85 PropertyValue Arg
= new PropertyValue();
87 Arg
.Value
= hidden?
"True":"False";
89 Arg
.State
= PropertyState
.DEFAULT_VALUE
;
93 szArgs
= new PropertyValue
[0];
96 // get the current active window
97 XFrame xCurFrame
= (XFrame
)UnoRuntime
.queryInterface(XFrame
.class, xCompLoader
);
100 XFrame xFrame
= xCurFrame
.findFrame("_blank", FrameSearchFlag
.CREATE
);
102 // load document in this frame
103 XComponentLoader xFrameLoader
= (XComponentLoader
)UnoRuntime
.queryInterface(XComponentLoader
.class, xFrame
);
104 xComp
= xFrameLoader
.loadComponentFromURL(
105 docName
, "_self", 0, szArgs
);
106 // wait for the document to load.
110 catch(java
.lang
.InterruptedException e
) {}
112 xWin
= xFrame
.getContainerWindow();
113 xWin
.addWindowListener(wl
);
115 catch(com
.sun
.star
.io
.IOException e
) {
119 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
123 catch(java
.lang
.Exception e
) {
124 System
.out
.println("DH3");
128 return xWin
.getPosSize();
133 * Get the size of the current window.
134 * @return The size of the window as Rectangle.
136 public Rectangle
getDocumentPosSize() {
137 return xWin
.getPosSize();
141 * Resize the window in defined steps:
144 * X-Position +10 pixel;
145 * Y-Position +10 pixel
146 * @return True if resize worked.
148 public boolean resizeDocument() {
149 Rectangle newPosSize
= xWin
.getPosSize();
150 newPosSize
.Width
= newPosSize
.Width
- 20;
151 newPosSize
.Height
= newPosSize
.Height
- 20;
152 newPosSize
.X
= newPosSize
.X
+ 80;
153 newPosSize
.Y
= newPosSize
.Y
+ 80;
154 return resizeDocument(newPosSize
);
158 * Resize window to the given Rectangle
159 * @param newPosSize The new position and size of the window.
160 * @return True if resize worked.
162 public boolean resizeDocument(Rectangle newPosSize
){
164 xWin
.setPosSize(newPosSize
.X
, newPosSize
.Y
, newPosSize
.Width
,
165 newPosSize
.Height
, PosSize
.POSSIZE
);
169 catch(java
.lang
.InterruptedException e
) {}
170 return wl
.resizedTrigger
;