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_macro_tools.inc,v $
13 '* last change: $Author: rt $ $Date: 2008-07-31 19:26:13 $
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 : Helper functions for Macro tests
38 '\******************************************************************************
40 function hInsertMacroFromFile( cMacroId as string, optional cSource as string ) as integer
42 '///<h3>Paste a macro (taken from a file) to the basic IDE</h3>
43 '///<i>uses: framework/tools/input/macros.txt</i><br>
44 '///<i>Starting point: Basic IDE</i><br>
45 '///<u>Note</u>: Overwrites any existing macros in the current module<br>
48 '///+<li>Name (ID) of the macro to be inserted (string)</li>
50 '///+<li>Allowed is any string that corresponds to a section in the source file</li>
55 '///+<li>Number of lines inserted (integer)</li>
57 '///+<li>0: Error, no lines inserted</li>
58 '///+<li>> 0: Number of lines</li>
61 '///<u>Description</u>:
64 const CFN = "hInsertMacroFromFile::"
66 '///+<li>Find the path to the source file</li>
68 if ( IsMissing( cSource ) ) then
69 cFile = convertpath( gTesttoolPath & "global/input/macros.txt" )
71 cFile = convertpath( cSource )
74 '///+<li>Determine the required array size</li>
75 dim iArraySize as integer
76 iArraySize = hListFileGetSize( cFile )
78 dim aInstructionList( iArraySize ) as string
80 dim iInstructionCount as integer
81 dim iCurrentInstruction as integer
85 '///+<li>retrieve the macro from the file with ID as section</li>
86 iInstructionCount = hGetDataFileSection( cFile, _
90 '///+<li>Delete all content from the BASIC IDE edit window</li>
93 '///+<li>Insert the code into the IDE line by line</li>
96 for iCurrentInstruction = 1 to iInstructionCount
98 EditWindow.TypeKeys( "<HOME>" )
99 EditWindow.TypeKeys( aInstructionList( iCurrentInstruction ) )
100 EditWindow.TypeKeys( "<RETURN>" )
102 next iCurrentInstruction
103 printlog( CFN & "Inserted macro: " & cMacroId )
104 hInsertMacroFromFile() = iInstructionCount
108 printlog( CFN & "IDE is not empty, will not insert macro" )
109 hInsertMacroFromFile() = 0
116 '*******************************************************************************
118 function hMacroOrganizerRunMacro( cMacroName as string ) as integer
120 '///<h3>Execute a macro by name</h3>
121 '///<i>Starting point: Any document</i><br>
122 '///+<i>The function runs silent</i><br>
125 '///+<li>Name of the macro to be run (string)</li>
127 '///+<li>Any macro that can run by itself (main)</li>
132 '///+<li>Position of the macro in the treelist (integer)</li>
134 '///+<li>0 = error</li>
135 '///+<li>1-n = position of macro</li>
138 '///<u>Description</u>:
142 const CFN = "hMacroOrganizerRunMacro::"
144 '///+<li>Go to Tools/Macros/Organize Macros/OpenOffice.org Basic</li>
145 printlog( CFN & "Enter with option: " & cMacroName )
148 '///+<li>Find the Macro</li>
150 hExpandAllNodes( MakroAus )
151 irc = hSelectNodeByName( MakroAus , cMacroName )
152 hExpandNode( MakroAus, irc )
153 hSelectNextNode( MakroAus )
155 if ( MakroAus.getSelText() = cMacroName ) then
156 printlog( CFN & "Matching object found: " & cMacroName )
162 '///+<li>Run the macro</li>
164 if ( Ausfuehren.exists( 1 ) ) then
165 if ( Ausfuehren.isEnabled( 1 ) ) then
168 printlog( CFN & "Could not execute macro, button is disabled" )
173 printlog( CFN & "Control does not exist/context failed" )
178 hMacroOrganizerRunMacro() = irc
179 printlog( CFN & "Exit with result: " & irc )