1 'encoding UTF-8 Do not remove or change this line!
2 '**************************************************************************
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: init_tools.inc,v $
13 '* last change: $Author: obo $ $Date: 2008-07-25 07:44:24 $
15 '* This file is part of OpenOffice.org.
17 '* OpenOffice.org is free software: you can redistribute it and/or modify
18 '* it under the terms of the GNU Lesser General Public License version 3
19 '* only, as published by the Free Software Foundation.
21 '* OpenOffice.org is distributed in the hope that it will be useful,
22 '* but WITHOUT ANY WARRANTY; without even the implied warranty of
23 '* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 '* GNU Lesser General Public License version 3 for more details
25 '* (a copy is included in the LICENSE file that accompanied this code).
27 '* You should have received a copy of the GNU Lesser General Public License
28 '* version 3 along with OpenOffice.org. If not, see
29 '* <http://www.openoffice.org/license.html>
30 '* for a copy of the LGPLv3 License.
32 '/******************************************************************************
34 '* owner : joerg.skottke@sun.com
36 '* short description : Tools to put the office into a defined state
38 '\******************************************************************************
40 function hInitSingleDoc() as boolean
42 '///<h3>Make sure exactly one single writer document is open</h3>
43 '///<i>The wizards cannot be triggered correctly from the backing window.
44 '///+ As a workaround this function checks the amount of open documents and
45 '///+ creates exactly one unchanged Writer document</i><br><br>
47 '///<u>Parameter(s):</u><br>
49 '///+<li>No input parameters</li>
53 '///<u>Returns:</u><br>
55 '///+<li>Errorcondition (Boolean)</li>
57 '///+<li>TRUE: Exactly one Writer document is open</li>
58 '///+<li>FALSE: Any error</li>
62 const CFN = "hInitSingleDoc::"
63 dim cOldApplication as string
65 '///<u>Description:</u>
67 '///+<li>Close all documents until we are on the backing window</li>
68 do while ( getDocumentCount > 0 )
72 '///+<li>Save the previous gApplication</li>
73 cOldApplication = gApplication
75 '///+<li>Set gApplication to WRITER</li>
76 gApplication = "WRITER"
78 '///+<li>Open one new Writer document</li>
81 '///+<li>Verify that exactly one document is open</li>
82 if ( getDocumentCount = 1 ) then
83 printlog( CFN & "A single unchanged writer document is open" )
84 hInitSingleDoc() = true
86 printlog( CFN & "Failed to open just one single writer document" )
87 hInitSingleDoc() = false
90 '///+<li>Restore gApplication</li>
91 gApplication = cOldApplication
96 '*******************************************************************************
98 function hInitBackingMode() as boolean
100 use "global\tools\includes\optional\t_docfuncs.inc"
102 '///<h3>Make that we are on the backing window (no open documents)</h3>
103 '///<i>Close all open documents</i><br><br>
105 '///<u>Parameter(s):</u><br>
107 '///+<li>No input parameters</li>
111 '///<u>Returns:</u><br>
113 '///+<li>Errorcondition (Boolean)</li>
115 '///+<li>TRUE: No open documents are present</li>
116 '///+<li>FALSE: Any error</li>
120 const CFN = "hInitBackingMode::"
122 '///<u>Description:</u>
124 '///+<li>Close all documents until we are on the backing window</li>
125 do while ( getDocumentCount > 0 )
129 '///+<li>verify that we do not have any open documents left (redundant check)</li>
130 if ( getDocumentCount = 0 ) then
131 printlog( CFN & "Office is in backing mode." )
132 hInitBackingMode() = true
134 printlog( CFN & "Office is in undefined state." )
135 hInitBackingMode() = false
141 '*******************************************************************************
143 function hInitWriteDocIdentifier( cString as string ) as boolean
146 '///<h3>Write a specific string to an open writer document</h3>
147 '///<i>This function verifies that exactly one document is open, that this is a
148 '///+ Writer document and writes the string to the document</i><br><br>
150 '///<u>Parameter(s):</u><br>
153 '///+<li>A free form string (String) which serves as identifier for the document</li>
155 '///+<li>The first character should be uppercase</li>
161 '///<u>Returns:</u><br>
163 '///+<li>Errorcondition (Boolean)</li>
165 '///+<li>TRUE: The string was written correctly</li>
166 '///+<li>FALSE: Too many open documents</li>
167 '///+<li>FALSE: Not a Writer document</li>
168 '///+<li>FALSE: Any other error</li>
172 const CFN = "hInitWriteDocIdentifier::"
174 '///<u>Description:</u>
176 '///+<li>Verify number of open documents</li>
177 if ( getDocumentCount <> 1 ) then
178 printlog( CFN & "Incorrect document count" )
179 hInitWriteDocIdentifier() = false
183 '///+<li>Verify that it is a writer document</li>
184 kontext "DocumentWriter"
185 if ( not DocumentWriter.exists() ) then
186 printlog( CFN & "Open document is not a text document" )
187 hInitWriteDocIdentifier() = false
191 '///+<li>Write the string</li>
192 kontext "DocumentWriter"
193 DocumentWriter.typeKeys( "<MOD1 END>" )
194 DocumentWriter.typeKeys( "<MOD1 SHIFT HOME>" )
195 DocumentWriter.typeKeys( "<DELETE>" )
196 DocumentWriter.typekeys( cString )
198 '///+<li>Verify the string</li>
199 DocumentWriter.typeKeys( "<MOD1 END>" )
200 DocumentWriter.typeKeys( "<MOD1 SHIFT HOME>" )
202 if ( getClipboardText = cString ) then
203 printlog( CFN & "Document has been successfully modified." )
204 hInitWriteDocIdentifier() = true
206 printlog( CFN & "Could not verify document identification string" )
207 hInitWriteDocIdentifier() = false