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 2000, 2010 Oracle and/or its affiliates.
7 ' OpenOffice.org - a multi-platform office productivity suite
9 ' This file is part of OpenOffice.org.
11 ' OpenOffice.org is free software: you can redistribute it and/or modify
12 ' it under the terms of the GNU Lesser General Public License version 3
13 ' only, as published by the Free Software Foundation.
15 ' OpenOffice.org is distributed in the hope that it will be useful,
16 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ' GNU Lesser General Public License version 3 for more details
19 ' (a copy is included in the LICENSE file that accompanied this code).
21 ' You should have received a copy of the GNU Lesser General Public License
22 ' version 3 along with OpenOffice.org. If not, see
23 ' <http://www.openoffice.org/license.html>
24 ' for a copy of the LGPLv3 License.
26 '/************************************************************************
28 '* owner : gregor.hartmann@oracle.com
30 '* short description : Tools for working with the property browser for formcontrols
32 '\******************************************************************************
34 function hOpenPropertyBrowser() as boolean
36 '///<h3>Open the BASIC property browser</h3>
38 const CFN = "framework::tools::includes::pbrowser_tools.inc::hOpenPropertyBrowser(): "
40 kontext "ControlPropertiesTabControl"
41 if ( ControlPropertiesTabControl.exists() ) then
42 printlog( "Property Browser is already open, no action taken" )
43 hOpenPropertyBrowser() = true
45 if ( hUseAsyncSlot( "ContextProperties" ) <> -1 ) then
46 kontext "ControlPropertiesTabControl"
47 if ( ControlPropertiesTabControl.exists( 2 ) ) then
48 ControlPropertiesTabControl.setPage( TabGeneralControl )
49 hOpenPropertyBrowser() = true
51 warnlog( CFN & "Dialog <ControlPropertiesTabControl> is not available" )
52 hOpenPropertyBrowser() = false
55 warnlog( CFN & "Could not execute <ContextProperties> slot" )
56 hOpenPropertyBrowser() = false
62 '*******************************************************************************
64 function hClosePropertyBrowser() as boolean
66 const CFN = "framework::tools::includes::pbrowser_tools.inc::hClosePropertyBrowser(): "
67 printlog( "Closing Property-Browser (if open)" )
69 kontext "ControlPropertiesTabControl"
70 if ( ControlPropertiesTabControl.exists() ) then
72 hUseAsyncSlot( "ContextProperties" )
74 if ( ControlPropertiesTabControl.notExists( 2 ) ) then
75 hClosePropertyBrowser() = true
77 warnlog( CFN & "Failed to close dialog" )
78 hClosePropertyBrowser() = false
81 printlog( "Property browser is not open, no action taken." )
82 hClosePropertyBrowser() = true
87 '*******************************************************************************
89 function hPBSetControlName( cControl as string ) as boolean
91 '///<h3>Name a control, with limited errorhandling</h3>
93 '///<i>This function was introduced due to a problem with the property-
94 '///browser not being open fast enough or just refusing to accept input</i><br><br>
98 '///+<li>Text to be inserted in the control "NameText" (string)</li>
104 '///+<li>Errorcondition</li>
106 '///+<li>TRUE: The control name was successfully updated</li>
107 '///+<li>FALSE: Control is not visible within current context</li>
112 const CFN = "hPBSetControlName::"
114 '///<u>Description</u>:
116 '///+<li>Test that the control "NameText" exists</li>
118 ' Note: A number of fallbacks are used here because the entryfield "NameText"
119 ' is less than reliable. My hope is that one of the methods succeeds.
120 kontext "TabGeneralControl"
121 if ( NameText.exists() ) then
122 '///+<li>Set the new name</li>
123 hDeleteEntryFieldContent( NameText )
125 ' Name the control and append some Spaces which should be truncated.
126 printlog( CFN & "Naming control: " & cControl )
127 NameText.setText( cControl )
128 TabGeneralControl.typeKeys( "<RETURN>" )
131 if ( NameText.getText() = cControl ) then
132 printlog( CFN & "Name is set ok: " & cControl )
133 hPBSetControlName() = true
137 ' If the name cannot be set this is in 99% of the cases a timing problem.
138 ' Here is a (costly) workaround.
139 qaerrorlog( CFN & "Name not set correctly, retrying" )
141 NameText.setText( cControl )
142 TabGeneralControl.typeKeys( "<RETURN>" )
145 ' Test again, leave function if good
146 if ( NameText.getText() = cControl ) then
147 printlog( CFN & "Name is set ok: " & cControl )
148 hPBSetControlName() = true
152 warnlog( CFN & "Unable to set control name: " & cControl )
153 hPBSetControlName() = false
156 warnlog( "Unable to name the control." )
157 hPBSetControlName() = false
163 '*******************************************************************************
165 function hPBGetControlName( cControl as string ) as boolean
167 '///<h3>Verify that the expected control is open</h3>
168 '///<i>Use hPBSetControlName( string ) to set the name and when you reopen it
169 '///+ verify that you got the right control wit this function</i><br><br>
173 '///+<li>Name of the control (string)</li>
179 '///+<li>Errorcondition (boolean)</li>
181 '///+<li>TRUE: The control has the correct name</li>
182 '///+<li>FALSE: Any other condition</li>
187 '///<u>Description</u>:
190 dim cControlName as string
191 const CFN = "hPBGetControlName::"
193 '///+<li>If "NameText" exists, retrieve its text</li>
194 kontext "TabGeneralControl"
195 if ( TabGeneralControl.exists( 1 ) ) then
196 if ( TabGeneralControl.isVisible() ) then
198 cControlName = NameText.getText()
200 '///+<li>Verify that the name is correct</li>
201 if ( cControlName = cControl ) then
202 printlog( CFN & "The name of the control is correct: " & cControl )
203 hPBGetControlName() = true
205 warnlog( CFN & "Unexpected control name:" )
206 printlog( CFN & "Found....: " & cControlName )
207 printlog( CFN & "Expected.: " & cControl )
208 hPBGetControlName() = false
211 warnlog( CFN & "Dialog present but tabpage could not be accessed (TabGeneralControl)." )
212 hPBGetControlName() = false
215 warnlog( CFN & "Unable to get the name from the control, dialog not accessible (TabGeneralControl)." )
216 hPBGetControlName() = false
222 '*******************************************************************************
224 function hSetPBTabPage( iPage as integer ) as boolean
226 '///<h3>A small helper to switch between tabpages in the property-browser</h3>
230 '///+<li>Page-ID (integer)</li>
232 '///+<li>1 = General page</li>
233 '///+<li>2 = Events page</li>
241 '///+<li>Errorcondition (boolean)</li>
243 '///+<li>TRUE on success</li>
244 '///+<li>FALSE on any error</li>
249 '///<u>Description</u>:
252 const CFN = "hSetPBTabPage::"
253 printlog( CFN & "Enter with option: " & iPage )
255 '///+<li>Switch to the requested page</li>
256 kontext "ControlPropertiesTabControl"
257 if ( not ControlPropertiesTabControl.exists( 3 ) ) then
258 printlog( CFN & "Exit: Control Properties Dialog is not open, aborting" )
259 hSetPBTabPage() = false
263 printlog( CFN & "Control Properties Dialog is open" )
270 printlog( CFN & "Switching to control properties tabpage" )
271 kontext "ControlPropertiesTabControl"
272 ControlPropertiesTabControl.setPage TabGeneralControl
274 kontext "TabGeneralControl"
275 if ( nametext.exists( 5 ) ) then
276 printlog( CFN & "Exit: Control properties are open (true)" )
277 hSetPBTabPage() = true
280 printlog( CFN & "Exit: Failed to open Control Properties (false)" )
281 hSetPBTabPage() = false
287 printlog( CFN & "Switching to event assignment tabpage" )
288 kontext "ControlPropertiesTabControl"
289 ControlPropertiesTabControl.setPage TabEventsControl
291 kontext "TabEventsControl"
292 if ( PBFocusGained.exists( 5 ) ) then
293 printlog( CFN & "Exit: Events page is open (true)" )
294 hSetPBTabPage() = true
297 printlog( CFN & "Exit: Failed to open events-page (false)" )
298 hSetPBTabPage() = false
304 printlog( CFN & "Invalid parameter passed to function: " & iPage )
305 hSerPBTabPage() = false
313 '*******************************************************************************
315 function hDeleteEntryFieldContent( oControl as object ) as boolean
317 printlog( "Original name is: " & oControl.getText() )
319 oControl.typeKeys( "<HOME>" )
320 oControl.typeKeys( "<SHIFT END>" )
321 oControl.typeKeys( "<DELETE>" )
323 if ( oControl.getText() = "" ) then
324 hDeleteEntryFieldContent() = true
326 hDeleteEntryFieldContent() = false