2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package complex
.persistent_window_states
;
21 import com
.sun
.star
.awt
.Rectangle
;
22 import com
.sun
.star
.awt
.PosSize
;
23 import com
.sun
.star
.frame
.XComponentLoader
;
24 import com
.sun
.star
.awt
.XWindow
;
25 import com
.sun
.star
.beans
.PropertyValue
;
26 import com
.sun
.star
.beans
.PropertyState
;
27 import com
.sun
.star
.uno
.UnoRuntime
;
28 import com
.sun
.star
.frame
.XFrame
;
29 import com
.sun
.star
.frame
.FrameSearchFlag
;
30 import helper
.WindowListener
;
33 * Load and resize a document.
36 public class DocumentHandle
{
37 // the component loader to load a document
38 private final XComponentLoader xCompLoader
;
41 private XWindow xWin
= null;
42 // a own window listener
43 private final WindowListener wl
;
47 * @param xCompLoader A loader to load a document
49 public DocumentHandle(XComponentLoader xCompLoader
) {
50 this.xCompLoader
= xCompLoader
;
51 wl
= new WindowListener();
55 * Load/Create a document.
56 * @param docName The name of a document as file URL
57 * @param hidden If true, the document is loaded hidden.
58 * @return The size of the opened/created document.
60 public Rectangle
loadDocument(String docName
, boolean hidden
)
64 PropertyValue
[] szArgs
= null;
66 szArgs
= new PropertyValue
[1];
67 PropertyValue Arg
= new PropertyValue();
69 Arg
.Value
= hidden?
"True":"False";
71 Arg
.State
= PropertyState
.DEFAULT_VALUE
;
75 szArgs
= new PropertyValue
[0];
78 // get the current active window
79 XFrame xCurFrame
= UnoRuntime
.queryInterface(XFrame
.class, xCompLoader
);
82 XFrame xFrame
= xCurFrame
.findFrame("_blank", FrameSearchFlag
.CREATE
);
84 // load document in this frame
85 XComponentLoader xFrameLoader
= UnoRuntime
.queryInterface(XComponentLoader
.class, xFrame
);
86 xFrameLoader
.loadComponentFromURL(docName
, "_self", 0, szArgs
);
87 // wait for the document to load.
88 util
.utils
.pause(10000);
90 xWin
= xFrame
.getContainerWindow();
91 xWin
.addWindowListener(wl
);
93 catch(com
.sun
.star
.io
.IOException e
) {
97 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
101 catch(java
.lang
.Exception e
) {
102 System
.out
.println("DH3");
106 return xWin
.getPosSize();
111 * Get the size of the current window.
112 * @return The size of the window as Rectangle.
114 public Rectangle
getDocumentPosSize() {
115 return xWin
.getPosSize();
119 * Resize the window in defined steps:
122 * X-Position +10 pixel;
123 * Y-Position +10 pixel
124 * @return True if resize worked.
126 public boolean resizeDocument() {
127 Rectangle newPosSize
= xWin
.getPosSize();
128 newPosSize
.Width
= newPosSize
.Width
- 20;
129 newPosSize
.Height
= newPosSize
.Height
- 20;
130 newPosSize
.X
= newPosSize
.X
+ 80;
131 newPosSize
.Y
= newPosSize
.Y
+ 80;
132 return resizeDocument(newPosSize
);
136 * Resize window to the given Rectangle
137 * @param newPosSize The new position and size of the window.
138 * @return True if resize worked.
140 private boolean resizeDocument(Rectangle newPosSize
){
142 xWin
.setPosSize(newPosSize
.X
, newPosSize
.Y
, newPosSize
.Width
,
143 newPosSize
.Height
, PosSize
.POSSIZE
);
144 util
.utils
.pause(3000);
145 return wl
.resizedTrigger
;