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: t_control_objects.inc,v $
13 '* last change: $Author: jsk $ $Date: 2008-06-20 07:57:33 $
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 : Functions to manipulate controls by accessing them as objects
38 '*******************************************************************************
40 ' #0 checkRadioButtons ' check a group of RBs where the sel. RB is given by number
41 ' #0 checkRadioButton ' check a singe RB where the state is specified directly
42 ' #0 checkCheckbox ' check a single checkbox
43 ' #0 setCheckBox ' sets checkbox to status provided in reference file
44 ' #0 checkComboBox ' compares an index to one provided in a reference-file
45 ' #0 setComboBox ' selects an index provided by a reference file
46 ' #0 checkListBox ' compares an index to one provided in a reference-file
47 ' #0 setListBox ' selects an index provided by a reference file
48 ' #0 checkListItem ' check that a listitem is correct
49 ' #1 hSetControlValue ' Change the value of a EntryField (failsafe)
51 '\******************************************************************************
53 function checkRadioButtons( _file as string , sKey as string , control1 as object , control2 as object , optional control3 as object , optional control4 as object ) as integer
55 '///<h3>EXPERIMENTAL: Get/Set function for some control types</h3>
56 '///<i>This is a function that allows to change the state/content of a
57 '///+ control via a configuration file. This function is experimental
58 '///+ and should not be used.<br>
59 '///+ This function checks if the correct radiobutton of a group is selected.
60 '///+ at least two radiobuttons must be provided, the third and fouth are optional.
61 '///+ The value for sKey in the reference file must be of type integer</i><br>
66 ' lowercase sKey for comparision
69 ' get the reference value for sKey as string
70 _sItem = hGetFileData( _file , sKey )
73 _iItem = val( _sItem )
75 ' check which one of the up to four radiobuttons is selected.
79 if ( control1.isChecked() = true ) then
80 checkRadioButtons() = true
81 printlog( " * Radiobutton 1 selected: ok" )
83 warnlog( "The wrong radiobutton is selected" )
87 if ( control2.isChecked() = true ) then
88 checkRadioButtons() = true
89 printlog( " * Radiobutton 2 selected: ok" )
91 warnlog( "The wrong radiobutton is selected" )
95 if ( isMissing( control3 ) = false ) then
96 if ( control3.isChecked() = true ) then
97 checkRadioButtons() = true
98 printlog( " * Radiobutton 3 selected: ok" )
100 warnlog( "The wrong radiobutton is selected" )
103 warnlog( "referencing to non-existing control." )
104 checkRadioButtons() = false
108 if ( isMissing( control4 ) = false ) then
109 if ( control4.isChecked() = true ) then
110 checkRadioButtons() = true
111 printlog( " * Radiobutton 4 selected: ok" )
113 warnlog( "The wrong radiobutton is selected" )
116 warnlog( "referencing to non-existing control." )
117 checkRadioButtons() = false
121 warnlog( "Maximum of four connected radiobuttons allowed." )
122 checkRadioButtons() = false
127 '*******************************************************************************
129 function checkRadioButton( _file as string , sKey as string , control as object ) as boolean
131 '///<h3>EXPERIMENTAL: Get/Set function for some control types</h3>
132 '///<i>This is a function that allows to change the state/content of a
133 '///+ control via a configuration file. This function is experimental
134 '///+ and should not be used.<br>
136 ' a wrapper. The routine is identical to checkCheckBox.
138 checkRadioButton = checkCheckBox( _file , sKey , control )
142 '*******************************************************************************
144 function checkCheckBox( _file as string , sKey as string , control as object , optional cBugID as string ) as boolean
146 '///<h3>EXPERIMENTAL: Get/Set function for some control types</h3>
147 '///<i>This is a function that allows to change the state/content of a
148 '///+ control via a configuration file. This function is experimental
149 '///+ and should not be used.<br>
151 dim bIsChecked as boolean
152 dim sIsChecked as string
153 dim _sIsChecked as string
155 if ( ismissing( cBugID ) ) then
158 if ( sKey = "*" ) then
159 sKey = control.name()
163 _sIsChecked = lcase( hGetFileData( _file , sKey ) )
165 if ( _sIsChecked <> "disabled" ) then
167 ' look if the control is present on the current dialog
168 if ( control.exists() and _
169 control.IsVisible() and _
170 control.IsEnabled() ) then
172 ' find out whether it is checked or not, create strings for errormessage
173 bIsChecked = control.isChecked()
174 if ( bIsChecked = true ) then
175 sIsChecked = "checked"
177 sIsChecked = "unchecked"
181 keycompare( sIsChecked , _sIsChecked , sKey , cBugID )
182 checkCheckBox() = control.isChecked()
186 warnlog( "Control <" & sKey & "> could not be accessed." )
192 if ( control.IsEnabled() ) then
193 warnlog( "The control should be disabled but it is not: " & sKey )
200 '*******************************************************************************
202 function setCheckBox( _file as string , sKey as string , control as object , optional bverbose as boolean ) as boolean
204 '///<h3>EXPERIMENTAL: Get/Set function for some control types</h3>
205 '///<i>This is a function that allows to change the state/content of a
206 '///+ control via a configuration file. This function is experimental
207 '///+ and should not be used.<br>
209 dim sIsChecked as string
210 dim _sIsChecked as string
212 if ( sKey = "*" ) then
213 sKey = control.name()
215 if ( ismissing( bverbose ) ) then
220 _sIsChecked = lcase( hGetFileData( _file , sKey ) )
222 if ( _sIsChecked <> "disabled" ) then
224 if ( control.exists() and _
225 control.IsVisible() and _
226 control.IsEnabled() ) then
228 select case _sIsChecked
235 setCheckBox() = false
242 printlog( " * " & sKey )
247 ' warn if the control could not be used (only works in rare cases)
248 warnlog( "Control <" & sKey & "> is not accessible." )
254 if ( control.IsEnabled() ) then
255 warnlog( "The control should be disabled but it is not: " & sKey )
262 '*******************************************************************************
264 function checkComboBox( _file as string , sKey as string , control as object ) as boolean
266 '///<h3>EXPERIMENTAL: Get/Set function for some control types</h3>
267 '///<i>This is a function that allows to change the state/content of a
268 '///+ control via a configuration file. This function is experimental
269 '///+ and should not be used.<br>
271 dim controltext as string ' current state
272 dim _controltext as string ' reference
274 if ( sKey = "*" ) then
275 sKey = control.name()
280 if ( control.exists() = true and control.IsVisible = true ) then
282 _controltext = lcase( hGetFileData( _file , skey ) )
283 controltext = control.getSelText()
284 keycompare( controltext , _controltext , sKey )
285 checkComboBox() = control.isEnabled()
289 warnlog( "Control <" & sKey & "> could not be accessed." )
295 '*******************************************************************************
297 function setComboBox( _file as string , sKey as string , control as object , optional bverbose as boolean ) as integer
299 '///<h3>EXPERIMENTAL: Get/Set function for some control types</h3>
300 '///<i>This is a function that allows to change the state/content of a
301 '///+ control via a configuration file. This function is experimental
302 '///+ and should not be used.<br>
304 dim _controltext as string ' reference string retrieved from _file
306 if ( ismissing( bverbose ) ) then
309 if ( sKey = "*" ) then
310 sKey = control.name()
315 if ( control.exists() = true and control.IsVisible = true ) then
317 _controltext = hGetFileData( _file , sKey )
318 control.settext( _controltext )
319 setComboBox() = _controltext
320 if ( bverbose = true ) then
321 printlog( " * " & sKey )
326 warnlog( "Control <" & sKey & "> is not accessible." )
332 '*******************************************************************************
334 function checkEntryField( _file as string , sKey as string , control as object , optional cBugID as string ) as boolean
336 '///<h3>EXPERIMENTAL: Get/Set function for some control types</h3>
337 '///<i>This is a function that allows to change the state/content of a
338 '///+ control via a configuration file. This function is experimental
339 '///+ and should not be used.<br>
341 dim controltext as string ' current state
342 dim _controltext as string ' reference
344 if ( ismissing( cBugID ) ) then
347 if ( sKey = "*" ) then
348 sKey = control.name()
351 ' lowercase the name (or alias) of the control which will be tested
354 ' get the expected setting for the control from the reference file
355 _controltext = lcase( hGetFileData( _file , skey ) )
357 ' if the reference file specifies that the control should be disabled
358 ' the routine tries to access it - expecting to fail. In this case we write
359 ' a string into the EF
360 if ( _controltext <> "disabled" ) then
362 if ( control.exists() and _
363 control.IsVisible() and _
364 control.IsEnabled() ) then
366 controltext = lcase( control.getText() )
367 keycompare( controltext , _controltext , sKey , cBugID )
368 checkEntryField() = control.isEnabled()
372 warnlog( "Control <" & sKey & "> could not be accessed." )
378 if ( control.IsEnabled() ) then
379 warnlog( "The control should be disabled but it is not: " & sKey )
386 '*******************************************************************************
388 function setEntryField( _file as string , sKey as string , control as object , optional bverbose as boolean ) as string
390 '///<h3>EXPERIMENTAL: Get/Set function for some control types</h3>
391 '///<i>This is a function that allows to change the state/content of a
392 '///+ control via a configuration file. This function is experimental
393 '///+ and should not be used.<br>
395 ' this is the text that will be written into the entryfield
396 dim _controltext as string
398 if ( ismissing( bverbose ) ) then
401 if ( sKey = "*" ) then
402 sKey = lcase( control.name() )
405 ' get the string from the reference file
406 _controltext = lcase( hGetFileData( _file , sKey ) )
408 if ( _controltext <> "disabled" ) then
410 ' we can only access the control if it is present + visible
411 if ( control.exists() and _
412 control.IsVisible() and _
413 control.IsEnabled() ) then
415 control.setText( lcase( _controltext ) )
416 setEntryField() = _controltext
419 printlog( " * " & sKey )
424 warnlog( "Control <" & sKey & "> is not accessible." )
430 if ( control.IsEnabled() ) then
431 warnlog( "The control should be disabled but it is not: " & sKey )
438 '*******************************************************************************
440 function checkListBox( _file as string , sKey as string , control as object ) as boolean
442 '///<h3>EXPERIMENTAL: Get/Set function for some control types</h3>
443 '///<i>This is a function that allows to change the state/content of a
444 '///+ control via a configuration file. This function is experimental
445 '///+ and should not be used.<br>
447 dim controltext as string ' current state
448 dim _controltext as string ' reference
450 if ( sKey = "*" ) then
451 sKey = control.name()
456 if ( control.exists() = true and control.IsVisible = true ) then
458 _controltext = lcase( hGetFileData( _file , skey ) )
459 controltext = control.getSelIndex()
460 keycompare( controltext , _controltext , sKey )
461 checkListBox() = control.isEnabled()
465 warnlog( "Control <" & sKey & "> could not be accessed." )
471 '*******************************************************************************
473 function setListBox( _file as string , sKey as string , control as object , optional bverbose as boolean ) as integer
475 '///<h3>EXPERIMENTAL: Get/Set function for some control types</h3>
476 '///<i>This is a function that allows to change the state/content of a
477 '///+ control via a configuration file. This function is experimental
478 '///+ and should not be used.<br>
480 dim _controltext as string ' reference
482 ' if name of the control is '*' get the name from the control itself
483 if ( ismissing( bverbose ) ) then
486 if ( sKey = "*" ) then
487 sKey = control.name()
490 ' change the key to lowercase
493 if ( control.exists() = true and control.IsVisible = true ) then
495 _controltext = hGetFileData( _file , sKey )
496 control.select( val( _controltext ) )
497 setListBox() = control.getselindex()
498 if ( bverbose = true ) then
499 printlog( " * " & sKey )
504 warnlog( "Control <" & sKey & "> is not accessible." )
510 '*******************************************************************************
512 function checkListItem( _file as string , _iIndex as integer , sKey as string , control as object ) as boolean
514 '///<h3>EXPERIMENTAL: Get/Set function for some control types</h3>
515 '///<i>This is a function that allows to change the state/content of a
516 '///+ control via a configuration file. This function is experimental
517 '///+ and should not be used.<br>
519 dim controltext as string ' current state
520 dim _controltext as string ' reference
525 if ( control.exists() = true and control.IsVisible() = true ) then
527 control.select( _iIndex )
528 controltext = control.getSelText()
529 _controltext = hGetFileData( _file , skey )
532 keycompare( controltext , _controltext , sKey )
534 checkListItem() = control.isEnabled()
538 printlog( "Control <" & sKey & "> could not be found." )
545 '*******************************************************************************
547 function hSetControlValue( oObject as object, cValue as string ) as integer
549 '///<h3>Enter some text into a EntryField/TextField</h3>
550 '///<i>This extends .setText() to provide a returnvalue</i><br>
551 '///<i>The function runs silent as long as no errors occur</i><br>
554 '///+<li>Control Object (Object)</li>
556 '///+<li>The object must exist</li>
557 '///+<li>The object must be enabled</li>
558 '///+<li>The object must be visible</li>
560 '///+<li>String (string)</li>
562 '///+<li>Any string, including empty strings (=delete)</li>
567 '///+<li>Status of the control (integer)</li>
569 '///+<li>0 = EntryField was updated correctly</li>
570 '///+<li>1 = Object does not exist</li>
571 '///+<li>2 = Object it not visible</li>
572 '///+<li>3 = Object is disabled</li>
575 '///<u>Description</u>:
578 const CFN = "hSetControlValue::"
580 '///+<li>Verify that the control exists</li>
581 if ( oObject.exists() ) then
583 '///+<li>Verify that the object is visible</li>
584 if ( oObject.isVisible() ) then
586 '///+<li>Verify that the control is enabled</li>
587 if ( oObject.isEnabled() ) then
588 oObject.setText( cValue )
591 irc = 3 ' control disabled
592 printlog( CFN & "Control is disabled: ID: " & oObject )
595 irc = 2 ' control not visible
596 printlog( CFN & "Control is not visible: ID: " & oObject )
599 irc = 1 ' control does not exist
600 printlog( CFN & "Control does not exist: ID: " & oObject )
603 hSetControlValue() = irc