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_menu.inc,v $
13 '* last change: $Author: jsi $ $Date: 2008-06-13 10:27:10 $
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 : thorsten.bosbach@sun.com
36 '* short description : wrappers for accessing menues (context-, bar-, button- menues)
38 '\******************************************************************************
40 function hMenuItemGetCount as Integer
42 '/// OUTPUT: number of entries in the activated menu (without seperators) ///'
43 '///+ menu left open ///'
44 dim iCurrentMenuItem as integer
45 dim iValidMenuItems as integer
50 for iCurrentMenuItem = 1 to MenuGetItemCount
51 if ( NOT MenuIsSeperator ( iCurrentMenuItem ) ) then
52 iValidMenuItems = iValidMenuItems + 1
55 hMenuItemGetCount = iValidMenuItems
59 '*******************************************************************************
61 function hMenuSelectNr ( EintragsNr as Integer ) as String
63 '/// Selects the given nr. of <b>enabled</b> menu entry.
64 '/// <u>Note</u>: If there are disabled menu items are included the routine ignores them!
65 '///INPUT : number of entry from the top (>=1) OR
66 '///INPUT : number of entry from the bottom (<=-1)
67 '///INPUT : 0 to close menu
68 '///+ OUTPUT: text of the entry
70 Dim i, j, RealEnd, Ende as Integer
76 RealEnd = MenuGetItemCount
78 if Ende > RealEnd then
79 Warnlog "hMenuSelectNr canceled: Entry number "+ Ende +" does not exists, because there are only " + RealEnd + " entries! "
85 if MenuIsSeperator ( i+j ) then
90 if ((RealEnd + Ende) < 0) then
91 Warnlog "hMenuSelectNr canceled: Entry number "+ Ende +" does not exists, because there are only " + RealEnd + " entries! "
96 for i=-1 to Ende step -1
97 if MenuIsSeperator (RealEnd +i+j) then
103 if EintragsNr = 0 then
107 nID = MenuGetItemID ( EintragsNr+j )
108 hMenuSelectNr = MenuGetItemText ( nID )
113 '*******************************************************************************
115 function hMenuItemCheck ( EintragsNr as Integer ) as String
117 '/// check the menu item (if it is checked, it stays checked) ///'
118 '///+ INPUT : number of entry from the top (>=1)///'
119 '///+ OUTPUT: text of the entry ///'
120 Dim i as Integer, j as Integer, RealEnd as Integer, Ende as Integer, nID as Integer
123 RealEnd = hMenuItemGetCount
125 if Ende > RealEnd then
126 Warnlog "hMenuItemCheck canceled: Entry number "+ Ende +" does not exists, because there are only " + RealEnd + " entries! "
132 if MenuIsSeperator ( i+j ) then
136 nID = MenuGetItemID ( EintragsNr+j )
137 hMenuItemCheck = MenuGetItemText ( nID )
138 if NOT MenuIsItemChecked ( nID ) then
146 '*******************************************************************************
148 function hMenuItemUnCheck ( EintragsNr as Integer ) as String
150 '/// UNcheck the menu item (if it is UNchecked, it stays UNchecked) ///'
151 '///+ INPUT : number of entry from the top (>=1)///'
152 '///+ OUTPUT: text of the entry ///'
153 Dim i, j, RealEnd, Ende, nID as Integer
156 RealEnd = hMenuItemGetCount
157 if Ende > RealEnd then
158 Warnlog "hMenuItemUnCheck canceled: Entry number "+ Ende +" does not exists, because there are only " + RealEnd + " entries! "
164 if MenuIsSeperator ( i+j ) then
168 nID = MenuGetItemID ( EintragsNr+j )
169 hMenuItemUnCheck = MenuGetItemText ( nID )
170 if MenuIsItemChecked ( nID ) then
178 '*******************************************************************************
180 function hMenuFindSelect(MenuID as variant, SelectSlot as Boolean, ExpectedNr as integer, optional VerboseWrongPosition as Boolean) as Boolean
182 '/// Find specified MenuID in Menu, check if its found on the expected place, ///'
183 '/// if not - report the correct slot, and if specified to do so - Select the correct slot. ///'
184 '///+ INPUT: MenuID: the string-name of the menu-entry we are lookin for. ///'
185 '///+ INPUT: TRUE, if the slot should be called, ///'
186 '///+ FALSE, if the slot shouldn't be called. ///'
187 '///+ INPUT: Optional: TRUE, if errors should be reported. ///'
188 '///+ FALSE, silent mode for errors. ///'
189 '///+ INPUT: Optional: The Expected Number of entry from the top (>=1) ///'
190 '///+ OUTPUT: If not found at the expected place - the correct Entry-number is reported ///'
193 Dim RealId as Integer
194 Dim RealPosition as Integer
195 Dim MenuIDAsNumber as integer
196 Dim MenuIDAsString as string
197 Dim RealEnd as Integer
200 Dim StringType as Boolean
202 '/// find out if we are going to search for an ID, or a string (.uno:) ///'
203 if IsNumeric(MenuID) then
204 MenuIDAsNumber = MenuID
207 MenuIDAsString = MenuID
211 RealEnd = MenuGetItemCount
212 if ExpectedNr > RealEnd then
213 Warnlog "Entry number "+ ExpectedNr +" is higher than the number of entries (" + RealEnd + ") in this menu! "
216 if StringType = FALSE then 'Search for the number.
218 nID = MenuGetItemID ( ExpectedNr )
219 if nID <> MenuID then
220 if VerboseWrongPosition = TRUE then
221 warnlog " the questioned ID (" + MenuID + ") were not found on position " + ExpectedNr
225 nID = MenuGetItemID (i)
226 printlog "For the position '" + i + "', the ItemCommand was: " + MenuGetItemCommand (MenuGetItemID (i)) + " and the ID was: " + MenuGetItemID (i) + "."
229 RealID = MenuGetItemID (i)
231 if VerboseWrongPosition = TRUE then
232 warnlog "The real Position (Separators included) was: " + i
239 RealPosition = ExpectedNr
240 RealId = MenuGetItemID (ExpectedNr)
246 hMenuFindSelect = TRUE
248 printlog "the slot was found, but the tester had choosen NOT to open the slot"
249 hMenuFindSelect = TRUE
253 if VerboseWrongPosition = TRUE then
254 warnlog "The slot was NOT found. Has either been removed, or it's a bug."
256 hMenuFindSelect = FALSE
260 else 'StringType = TRUE : Seach for the .uno; -name.
261 nID = lCase(MenuGetItemCommand (MenuGetItemID (ExpectedNr)))
263 if nID <> lCase(MenuID) then
264 if VerboseWrongPosition = TRUE then
265 warnlog " the questioned ID (" + MenuID + ") were not found on position " + ExpectedNr
269 nID = MenuGetItemCommand (MenuGetItemID (i))
270 printlog "For the position '" + i + "', the ItemCommand was: " + nID + " and the ID was: " + MenuGetItemID (i) + "."
273 RealID = MenuGetItemID (i)
275 if VerboseWrongPosition = TRUE then
276 warnlog "The real Position (Separators included) was: " + i
283 RealPosition = ExpectedNr
284 RealId = MenuGetItemID (ExpectedNr)
289 hMenuFindSelect = TRUE
291 printlog "the slot was found, but the tester had choosen NOT to open the slot"
292 hMenuFindSelect = TRUE
296 if VerboseWrongPosition = TRUE then
297 warnlog "The slot was NOT found. Has either been removed, or it's a bug."
299 hMenuFindSelect = FALSE
302 endif 'StringType = TRUE
303 wait 500 'Wait 0,5 seconds in case we just have called a Submenu.
307 '*******************************************************************************
309 function hMenuItemIsChecked ( EintragsNr as Integer ) as Boolean
311 '/// is the the menu item checked ? ///'
312 '///+ INPUT : number of entry from the top (>=1)///'
313 '///+ OUTPUT: True = yes!, False = no! ///'
315 Dim i, j, Ende, RealEnd, nID as Integer
318 RealEnd = hMenuItemGetCount
319 if Ende > RealEnd then
320 Warnlog "hMenuItemIsChecked canceled: Entry number "+ Ende +" does not exists, because there are only " + RealEnd + " entries! "
326 if MenuIsSeperator ( i+j ) then
330 nID = MenuGetItemID ( EintragsNr + j )
331 hMenuItemIsChecked = MenuIsItemChecked ( nID )
335 '*******************************************************************************
337 function hMenuItemIsEnabled ( EintragsNr as Integer ) as Boolean
339 '/// is the the menu item enabled (not greyed out) ? ///'
340 '///+ INPUT : number of entry from the top (>=1)///'
341 '///+ OUTPUT: True = yes!, False = no! ///'
342 '///+ menu left open ///'
344 Dim i, j, Ende, RealEnd, nID as Integer
347 RealEnd = MenuGetItemCount
348 if Ende > RealEnd then
349 Warnlog "hMenuItemIsEnabled canceled: Entry number "+ Ende +" does not exists, because there are only " + RealEnd + " entries! "
355 if MenuIsSeperator ( i+j ) then
359 nID = MenuGetItemID ( EintragsNr + j )
360 hMenuItemIsEnabled = MenuIsItemEnabled ( nID )
364 '*******************************************************************************
366 function hMenuItemGetText ( EintragsNr as Integer ) as String
368 '///+ INPUT : number of entry from the top (>=1)///'
369 '///+ OUTPUT: text of item without tilde ///'
370 '///+ menu left open ///'
372 Dim i, j, RealEnd, Ende, nID as Integer
375 RealEnd = MenuGetItemCount
376 if Ende > RealEnd then
377 Warnlog "hMenuItemGetText canceled: Entry number "+ Ende +" does not exists, because there are only " + RealEnd + " entries! "
383 if MenuIsSeperator ( i+j ) then
387 nID = MenuGetItemID ( EintragsNr + j )
388 hMenuItemGetText = hhEntferneTilde ( MenuGetItemText ( nID ) )
392 '*******************************************************************************
396 '/// close menue ///'
397 '///+ after a hMenuClose you have to execute Kontext.UseMenu again
398 '///+ if you want to open any other menu.
403 '*******************************************************************************
405 function hhEntferneTilde ( sEintrag as String ) as String
407 '///+ INPUT : string with tilde ///'
408 '///+ OUTPUT: string without tilde ///'
411 i = Instr ( 1, sEintrag, "~", 1 )
413 hhEntferneTilde = Left ( sEintrag, i-1 ) + Right ( sEintrag, ( Len(sEintrag) - i ) )
415 hhEntferneTilde = sEintrag
420 '*******************************************************************************
422 function hMenuGetItemCommand ( EintragsNr as Integer ) as String
424 '/// <u>hMenuGetItemCommand(Nr)</u> ///
425 '///+ To read the slot/UNO slot which is behind a menu item. ///
426 '///+ Seperators will be ignored for the input INTEGER!
430 Dim RealEnd as integer
431 Dim DasEnde as integer
434 RealEnd = MenuGetItemCount
435 if DasEnde > RealEnd then
436 warnlog "Parameter (" & DasEnde & ") bigger than items in menu (" & RealEnd & ") , 'hMenuGetItemCommand' canceled."
440 if MenuIsSeperator ( i+j ) then
444 nID = MenuGetItemID ( EintragsNr+j )
445 hMenuGetItemCommand = MenuGetItemCommand ( nID )
450 '*******************************************************************************
452 function hMenuGetItemId ( EintragsNr as Integer ) as integer
454 '///+ To read the Slot ID which is behind a menu item. ///
455 '///+ Seperators will be ignored for the input INTEGER!
459 Dim RealEnd as integer
460 Dim DasEnde as integer
462 RealEnd = MenuGetItemCount
463 if DasEnde > RealEnd then
464 warnlog "Parameter (" & DasEnde & ") bigger than items in menu (" & RealEnd & ") , 'hMenuGetItemId' canceled."
468 if MenuIsSeperator ( i+j ) then
472 hMenuGetItemId = MenuGetItemID ( EintragsNr+j )
477 '*******************************************************************************
479 '/// Functions for the lower part of the 'Window' Menu ///'
480 '///+ philosophie: you can't do any actions on the first document -> it get's the number 0 and it doesn't count ///'
481 '///+ so the first window you can work with gets the number 1 and counting starts with 1 ... ///'
482 '///<b> function hUseMenu () </b>///'
483 '///+ very global function: depends on 'gApplication' just activates the menu-bar ///'
484 '///<b> function hWindowGetIndex () as integer </b>///'
485 '///+ returns the number of the active window ///'
486 '///<b> function hWindowGetText (optional iWindow as integer) as string </b>///'
487 '///+ returns the text of the menu entry without the tilde: ///'
488 '///+ w/ calling parameter: the active window ///'
489 '///+ w/o calling parameter: the window i ///'
490 '///<b> function hWindowSelect (iWindow as integer) </b>///'
491 '///+ switches to the window i ///'
492 '///+ calling parameter: id of the window to activate ///'
494 '*******************************************************************************
496 function hWindowGetIndex () as integer
498 '///<b> function hWindowGetIndex () as integer </b>///'
499 '///+ returns the number of the active window ///'
501 dim iMenues as integer ' takes the number of entries in the windows menue
502 dim iNotWindows as integer ' number of open windows
503 dim iKandidate as integer
506 iNotWindows = GetDocumentCount()
509 iMenues = hMenuItemGetCount
510 hMenuSelectNr(iMenues-1) ' 'windows' ist usually the one before the last
513 iMenues = hMenuItemGetCount
514 for i = ((iMenues - iNotWindows) + 1) to iMenues
515 if (hMenuItemIsChecked (i)) then
516 if (iKandidate = 0) then
519 Warnlog "unexpected error 4711 - more than one window active??!! hWindowGetIndex () "
523 iMenues = (iKandidate - (iMenues - iNotWindows) - 1)
526 hWindowGetIndex = iMenues
530 '*******************************************************************************
532 function hWindowGetText (optional iWindow as integer) as string
534 '///<b> function hWindowGetText (optional iWindow as integer) as string </b>///'
535 '///+ returns the text of the menu entry without the tilde: ///'
536 '///+ w/ calling parameter: the active window ///'
537 '///+ w/o calling parameter: the window i ///'
539 dim iMenues as integer ' takes the number of entries in the windows menue
540 dim iNotWindows as integer ' number of open windows
543 if (isMissing(iWindow) = FALSE) then
546 iUseWindow = hWindowGetIndex()
549 iNotWindows = GetDocumentCount()
552 iMenues = hMenuItemGetCount
553 hMenuSelectNr(iMenues-1) ' 'windows' ist usually the one before the last
556 iMenues = hMenuItemGetCount
557 hWindowGetText = hMenuItemGetTextMitTilde (iUseWindow + (iMenues - iNotWindows) + 1)
558 hWindowGetText = hhEntferneTilde(hWindowGetText)
563 '*******************************************************************************
565 function hWindowSelect (iWindow as integer)
567 '///<b> function hWindowSelect (iWindow as integer) </b>///'
568 '///+ switches to the window i ///'
569 '///+ calling parameter: id of the window to activate ///'
571 dim iMenues as integer ' takes the number of entries in the windows menue
572 dim iNotWindows as integer ' number of open windows
574 iNotWindows = GetDocumentCount ()
577 'ActivateDocument iNumber as integer ' is a testtool command, but there is no system that stays behind iNumber :-[
578 iMenues = hMenuItemGetCount
579 hMenuSelectNr(iMenues-1) ' 'windows' ist usually the one before the last
582 iMenues = hMenuItemGetCount
583 hMenuSelectNr (iWindow + 1 + (iMenues - iNotWindows))
587 '*******************************************************************************
591 '///<b> function hUseMenu () </b>///'
592 '///+ very global function: depends on 'gApplication' just activates the menu-bar ///'
594 Select Case Ucase(gApplication)
597 Kontext "DocumentWriter"
598 DocumentWriter.UseMenu
600 Case "MASTERDOCUMENT"
602 Kontext "DocumentMasterDoc"
603 DocumentMasterDoc.UseMenu
607 Kontext "DocumentWriterWeb"
608 DocumentWriterWeb.UseMenu
610 case "CALC" ' there are 2 entries over :-( usually only one, html 0 :-((((
612 Kontext "DocumentCalc"
617 Kontext "DocumentDraw"
622 Kontext "DocumentImpress"
623 DocumentImpress.UseMenu
627 Kontext "DocumentMath"
642 Kontext "DocumentBackground"
643 DocumentBackground.UseMenu
649 '*******************************************************************************
651 function hOpenContextMenu()
653 '/// very global function: depends on 'gApplication' just opens the Context Menu ///'
655 Select Case Ucase(gApplication)
658 Kontext "DocumentWriter"
659 DocumentWriter.openContextMenu
661 Case "MASTERDOCUMENT"
663 Kontext "DocumentMasterDoc"
664 DocumentMasterDoc.openContextMenu
668 Kontext "DocumentWriterWeb"
669 DocumentWriterWeb.openContextMenu
673 Kontext "DocumentCalc"
674 DocumentCalc.openContextMenu
678 Kontext "DocumentDraw"
679 DocumentDraw.openContextMenu
683 Kontext "DocumentImpress"
684 DocumentImpress.openContextMenu
688 Kontext "DocumentMath"
689 DocumentMath.openContextMenu
695 '*******************************************************************************
697 function hGetWindowCaption(sApplication as string, optional bAll as boolean)
699 '///<b> function hGetWindowCaption () </b>///'
700 '///+ just returns the string from the application main window ///'
701 '///+ If optional parameter = true, thenn go throught all applications and get caption; return array ///'
704 dim aApplication() as string
705 dim aTemp(10) as string
706 dim iTimes as integer
709 aApplication = array("SWRITER","SGLOBAL","SWEB","SCALC","SDRAW","SIMPRESS","SMATH","BASIC","BACK")
710 if (isMissing(bAll) OR (NOT bAll)) then
713 iTimes = uBound(aApplication())
714 sApplication = aApplication(0)
717 Select Case Ucase(sApplication)
720 Kontext "DocumentWriter"
722 sTemp = DocumentWriter.caption
727 Kontext "DocumentMasterDoc"
729 sTemp = DocumentMasterDoc.caption
734 Kontext "DocumentWriterWeb"
736 sTemp = DocumentWriterWeb.caption
741 Kontext "DocumentCalc"
743 sTemp = DocumentCalc.caption
748 Kontext "DocumentDraw"
750 sTemp = DocumentDraw.caption
755 Kontext "DocumentImpress"
757 sTemp = DocumentImpress.caption
762 Kontext "DocumentMath"
764 sTemp = DocumentMath.caption
771 sTemp = BasicIDE.caption
776 Kontext "DocumentBackground"
778 sTemp = DocumentBackground.caption
782 qaErrorLog "sApplication not defined: '" + sApplication + "'"
787 sApplication=aApplication(i+1)
792 hGetWindowCaption = aTemp()
794 hGetWindowCaption = sTemp
799 '*******************************************************************************
801 function fSplitWindowTitle(sInString as string)
803 dim a, b, x, i as integer
804 dim sTemp() as string
805 dim sTempReturn(2) as string
806 dim sTempReturn2(3) as string
807 dim bTestToolCommunication as boolean
808 dim bDebugVersion as boolean ' aka 'nonpro'
809 dim bError as boolean
811 ' a) 'Untitled2 - OpenOffice.org Draw' (2)
812 ' b) 'Untitled1 - OpenOffice.org Writer TTD :localhost[1034]' (4)
813 ' c) 'Untitled1 - StarOffice Writer [680m72(Build:8863)]' (3)
814 ' d) 'Untitled2 - StarOffice Draw [680m72(Build:8863)] TTD :localhost[1034]' (5)
816 bTestToolCommunication = FALSE
817 bDebugVersion = FALSE
819 if (sInString <> "") then
820 ' ' - ' separates Filename from Vendor
821 a = instr(sInString, " - ") ' get Document file name or Untitledi
823 if (instr(a+1,sInString, " - ") > a) then
827 sTempReturn(0) = left(sInString, a-1) ' (0) Filename
833 ' seperate second string by spaces
834 sTemp() = split(right(sInString, len(sInString)-(a+2)), " ") ' Parts are now separated by spaces
837 sTempReturn(1) = sTemp(1) ' (1) Application
838 sTempReturn(2) = sTemp(0) ' (2) Vendor
840 ' if ']' at end... (b,c,d)
841 if (right(sInString,1) = "]") then
842 ' if ')' at second last position it is a nonpro!
843 if (right(sInString,2) = ")]") then
844 ' normal detection works with spaces... (c)
847 ' remove TestTool communication string (b,d)
848 ' it is the last 2 space seperated parts!
849 bTestToolCommunication = TRUE
850 if (left(sTemp(2),1)="[") then
855 ' normal detection with spaces works... (a)
858 ' sanity checks, to warn if assumptions are not met!
861 if ((bTestToolCommunication) OR (bDebugVersion)) then
862 qaErrorLog "t_menu.inc::fSplitWindowTitle: Unknown count of Window Title Strings! 1"
866 if ((bTestToolCommunication) OR (NOT bDebugVersion)) then
867 qaErrorLog "t_menu.inc::fSplitWindowTitle: Unknown count of Window Title Strings! 2"
871 if ((NOT bTestToolCommunication) OR (bDebugVersion)) then
872 qaErrorLog "t_menu.inc::fSplitWindowTitle: Unknown count of Window Title Strings! 3"
876 '***** Warning: Indention error *****
878 if ((NOT bTestToolCommunication) OR (NOT bDebugVersion)) then
881 '***** Warning: Indention error *****
882 qaErrorLog "t_menu.inc::fSplitWindowTitle: Unknown count of Window Title Strings! 4"
886 qaErrorLog "t_menu.inc::fSplitWindowTitle: Unknown count of Window Title Strings! 0"
894 if (x > 1) then ' there is more to evaluate
895 ' save the current computed values
897 '***** Warning: Indention error *****
898 sTempReturn2(i) = sTempReturn(i)
900 ' make return array bigger
901 redim sTempReturn(4) as string
904 '***** Warning: Indention error *****
905 sTempReturn(i) = sTempReturn2(i)
907 ' set remaining values, if exist
908 ' debug version string
909 if bDebugVersion then
910 '***** Warning: Indention error *****
911 sTempReturn(3) = mid(sTemp(2),2,len(sTemp(2))-2) ' optional (3) Debug Version
913 '***** Warning: Indention error *****
916 ' TestTool Communication string
917 if bTestToolCommunication then
918 '***** Warning: Indention error *****
919 ' if true, then always the two last strings
920 sTempReturn(4) = sTemp(x-1) + " " + sTemp(x) ' optional (4) TestTool Communication
922 '***** Warning: Indention error *****
927 redim sTempReturn(0) as string
931 fSplitWindowTitle = sTempReturn()