summaryrefslogtreecommitdiff
path: root/testautomation/global/tools/includes/required/t_tools1.inc
blob: 0840771add874259c3769431d0c2a8e2d1228450 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
'encoding UTF-8  Do not remove or change this line!
'**************************************************************************
'* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
'* 
'* Copyright 2008 by Sun Microsystems, Inc.
'*
'* OpenOffice.org - a multi-platform office productivity suite
'*
'* $RCSfile: t_tools1.inc,v $
'*
'* $Revision: 1.1 $
'*
'* last change: $Author: jsi $ $Date: 2008-06-13 10:27:11 $
'*
'* This file is part of OpenOffice.org.
'*
'* OpenOffice.org is free software: you can redistribute it and/or modify
'* it under the terms of the GNU Lesser General Public License version 3
'* only, as published by the Free Software Foundation.
'*
'* OpenOffice.org is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'* GNU Lesser General Public License version 3 for more details
'* (a copy is included in the LICENSE file that accompanied this code).
'*
'* You should have received a copy of the GNU Lesser General Public License
'* version 3 along with OpenOffice.org.  If not, see
'* <http://www.openoffice.org/license.html>
'* for a copy of the LGPLv3 License.
'*
'/************************************************************************
'*
'* owner : helge.delfs@sun.com
'*
'* short description : Tools (1)
'*
'***************************************************************************************
'*
' #1 GetClipboardText                   'Returns the correct clipboard text (also if there is a 'RETURN' at it's end.
' #1 hDoubleClickInList
' #0 hMouseClick
' #1 wielange
' #1 sleep
' #1 WaitInSek
' #1 WaitInMilliSek
' #1 DialogTest                         'Creates snapshots
' #0 DialogTest2                        'Creates snapshots
' #1 hFindeImDokument                   'Searches for a string with the 'Search&Replace'-dlg in a document.
' #1 hFindeMehrImDokument               'Same as 'hFindeImDokument' but needs an integer how often the search-phrase must be found until the boolean gives TRUE back.
' #1 ErgebnisSchreiben
' #1 TextInDatei
' #1 hGetUIFiltername                   'Extracts the UI filtername from configuration.
' #1 hGetFilternameExtension            'Extracts the filtername extension from configuration.
' #1 TrimTab                            'trimming strings
' #1 lTrimTab                           'trimming strings
' #1 rTrimTab                           'trimming strings
' #1 TrimString                         'Cuts all ASCII characters which are defined by a parameter (e.g. 32 space will be deleted)
' #1 ActiveDeactivateAsianSupport       'Acivates/Deactivates the Asian support in StarOffice
' #1 ActiveDeactivateCTLSupport         'Acivates/Deactivates the CTL support in StarOffice
' #1 GetDecimalSeperator                'Reads from Tools / Options the used . or , which is being used as seperator
' #1 sResetTheOffice                    'Save language information - throw away user directory - restore language information
'*
'\*************************************************************************************

function GetClipboardText as string
'/// Returns the correct clipboard text (also if there is a 'RETURN' at it's end.
   Dim i% : Dim CBText$
   Dim Zwischen$

   wait 500
   GetClipboardText = ""
   CBText$ = GetClipboard

   if CBText$ = "" then
      GetClipboardText = ""
      exit function
   end if

   if asc ( Right( CBText$, 1 )) = 10 then
      Zwischen$ = Mid( CBText$, 1, len(CBText$)-1 )
      if Zwischen$ <> "" then
         if asc ( Right( Zwischen$, 1 )) = 13 then
            GetClipboardText = Mid( Zwischen$, 1, len(Zwischen$)-1 )
         else
            GetClipboardText = Zwischen$
         end if
      else
         GetClipboardText = Zwischen$
      end if
   else
      if asc ( Right( CBText$, 1 )) = 13 then
         Zwischen$ = Mid( CBText$, 1, len(CBText$)-1 )
         if asc ( Right( Zwischen$, 1 )) = 10 then
            GetClipboardText = Mid( Zwischen$, 1, len(Zwischen$)-1 )
         else
            GetClipboardText = Zwischen$
         end if
      else
         GetClipboardText = CBText$
      end if
   end if
end function

'-------------------------------------------------------------------------

function hDoubleClickInList ( window, Selektion as String, optional bFocus as boolean ) as Boolean
'/// hDoubleClickInList
'///+ Makes a double click onto an entry in a list (tested only in <i>style lists</i>)
'///+ window: name of list ///'
'///+ selektion: string to find in list ///'
'///+ bFocus: TRUE: activate the window with mouseclick before leaving ///'
'///+ ReturnValue: if found: TRUE; else FALSE ///'

    Dim i as Integer
    Dim AlterWert as String
    Dim NeuerWert as String

    NeuerWert = "!=!  !=!"                ' init with dummy value
    window.TypeKeys "<Home>"
    if window.gettext <> Selektion then         
        for i=1 to 100 step 2
            window.MouseDown 5, i +1
            window.MouseUp 5, i +1
            AlterWert = window.GetText
            window.TypeKeys "<Down>"
            NeuerWert = Window.GetText
            window.TypeKeys "<Up>"
            if AlterWert = Selektion then
                window.MouseDown 5, i +1
                window.MouseUp 5, i +1
                if Window.GetText = Selektion then     ' catch if <down> had any effects
                    window.MouseDoubleClick 5, i +1
                    if (isMissing (bFocus) = FALSE) then ' if optional parameter provided
                        window.MouseDown 5, i +1
                        window.MouseUp 5, i +1
                    endif
                    i = 202
                else
                    i=0                                 ' start at top of list
                end if
            else
                if AlterWert = NeuerWert then
                    Warnlog "'" + Selektion + "' wasn't found in list!"
                    i = 202
                else
                    if i > 98 then i=40                  ' list not at end, but scrolled
                end if
            end if
        next i
        if i < 200 OR i > 100 then
            hDoubleClickInList = FALSE
        else
            hDoubleClickInList = TRUE
        end if
    else
        window.TypeKeys "<Return>"
        hDoubleClickInList = TRUE
    endif
end function

'-------------------------------------------------------------------------

sub hMouseClick ( window, xPos, yPos )
' Author: Thorsten Ziehm (26.09.2000)
'/// hMouseClick
'///+ Do a mouse click on a named window.
'/// <i>Input</i>:
'///+ window : The object on which the mouse click should be make (document, listbox, window)
'///+ xPos : x-position (relativ to the size of the window (1:100)
'///+ yPos : y-position (relativ to the size of the window (1:100)
   window.MouseDown ( xPos, yPos )
   window.MouseUp ( xPos, yPos )
end sub

'-------------------------------------------------------------------------

function wielange (StrtTime, optional iFormat as integer) as String
    ' Author: Michael Friedrichs
    '/// wielange
    '///+ Returns the time between a start- and an end timeframe.
    '///+  iFormat: 0: default; 1: mysql ///'
    
    Dim Zeitspanne
    Dim Zeitspannesek
    Dim Zeitspannemin
    Dim Zeitspanneh
    dim sTemp as string
    
    if isMissing(iFormat) then
        'dim iFormat as integer
        iFormat = 0
    endif
    
    Zeitspanne = Now() - StrtTime
    Zeitspannesek = Zeitspanne / 1.15741E-05 + 1
    Zeitspanneh = Fix(Zeitspannesek / 3600)
    Zeitspannesek = Zeitspannesek - Zeitspanneh * 3600
    Zeitspannemin = Fix(Zeitspannesek / 60)
    Zeitspannesek = Zeitspannesek - Zeitspannemin * 60
    Zeitspannesek = Fix(Zeitspannesek)
    select case iFormat
        case 0: sTemp = "" & Zeitspanneh & "h " & Zeitspannemin & "m " & Zeitspannesek & "s"
        case 1: if Zeitspanneh < 10 then         ' mysql format for status.inc
                    sTemp = "0" & Zeitspanneh & ":"
                else
                    sTemp = "" & Zeitspanneh & ":"
                end if
                if Zeitspannemin < 10 then
                    sTemp = "" & sTemp & "0" & Zeitspannemin & ":"
                else
                    sTemp = "" & sTemp & Zeitspannemin & ":"
                end if
                if Zeitspannesek < 10 then
                    sTemp = "" & sTemp & "0" & Zeitspannesek
                else
                    sTemp = "" & sTemp & Zeitspannesek
                end if
        case default: qaErrorLog "t_tools1.inc::wielange: optional parameter iFormat out of range!"
                      sTemp = ""
    end select
    wielange = sTemp
end function

'-------------------------------------------------------------------------

sub WaitInSek ( Sekunden )
' Author: Thorsten Ziehm
'/// WaitInSek
'///+ Wait exactly x second(s) (using GetSystemTicks)
  Dim i : Dim t0 : Dim t1
   t0 = GetSystemTicks()
   for i=1 to 10000*Sekunden
      t1 = GetSystemTicks()
      if t1-t0 > 1000*Sekunden then i=11000*Sekunden
   next i
end sub

'-------------------------------------------------------------------------

sub WaitInMilliSek ( Milli )
' Author: Thorsten Ziehm
'/// WaitInMilliSek
'///+ Wait exactly x millisecond(s) (using GetSystemTicks)
  Dim i : Dim t0 : Dim t1
   t0 = GetSystemTicks()
   for i=1 to 1000*Milli
     t1 = GetSystemTicks
     if t1-t0 > Milli then i=1001*Milli
   next i
end sub

'-------------------------------------------------------------------------

sub sleep ( i% )
'/// sleep
'///+ simple sleep routine which uses seconds.
'   WaitInSek ( i% )
   wait i%*1000
end sub

'-------------------------------------------------------------------------

sub DialogTest( Window, optional iNumber as integer)
'/// DialogTest
'///+ Make <i>SnapShots</i>
'/// <b>Window</b> : the name of the window as declared in qa/qatesttool/global/win/*
'/// <i>Optional Parameter</i> <b>iNumber</b> : Number to distinguish windows which dynamical change their content but not their ID///'
'///+ the number has to be provided by the testscript creator ///'
   Dim Ergebnis as Integer
   Dim Ausgabe as String
   Dim UndRaus as Boolean
   Dim sCount as string

   ' evaluate optional parameter
   if isMissing(iNumber) then
        'just one picture
        sCount = ""
   else
        'there will be more pictures with the same ID
        sCount = "_"+iNumber
   endif
   
   if gDasNicht=0 then
      ' In Place Translation Feature: not used anymore;
      ' The matching of the strings on the later migration step never worked.
      ' Just kept here for historical reasons
      Ausgabe = ""
      UndRaus = FALSE
      while UndRaus = FALSE
         Ausgabe = translate
         if Ausgabe <> "" OR Ausgabe <> "1" then
            if Left ( Ausgabe, 1 ) = "0" then
               Ausgabe = Right ( Ausgabe, Len( Ausgabe )- 2 )
               AnhaengenAnDatei ( gOfficePath + "trans_output.txt", Ausgabe )
            end if
         end if
         if Ausgabe = "1" then UndRaus = TRUE
      wend
   else
      ' Usual window check
      try
         if Not window.Exists(2) then
            Warnlog "   - Window nicht existent:" + window.Name + " " + window.ID
            exit sub
         end if
         'To get a history, of what windows are covered, use the following line
         '      AnhaengenAnDatei ( ConvertPath (gOfficePath + "user\work\wieviel.txt"), window.Name + " " + sCount + " : " + window.ID )
      catch
         ExceptLog
      endcatch
   end if

   if gbSnapShot = TRUE then
      'Make Screenshot from dialog and save as HelpID.bmp
      Dim Dummy as String, sName as String, sPicName as String

      'get window ID
      Dummy = Window
      'set filename
      sName = Dummy + sCount + ".bmp"

      'save with respect to application and language
      sCapturePath = ConvertPath (gOfficePath + "user\work\screenshots"+iSprache+"\")
      sPicName = sCapturePath + lCase(gApplication)
      'create directory if it doesn't exist
      if hDirectoryExists(sPicName) <> TRUE then
            mkdir (sPicName)
      end if
      sPicName = sPicName + sName
      try
        sleep 1
        window.SnapShot( sPicName )
      catch
        warnlog "t_tools1.inc::DialogTest Failed to save screenshot: '" + sPicName + "'"
      endcatch
      printlog sPicName
   end if
end sub

'-----------------------------------------------------------

sub DialogTest2( Window, i% )
    'deprecated TBO:2006/03/16
    DialogTest( Window, i% )
end sub

'-------------------------------------------------------------------------

function hFindeImDokument ( Passage$ , Optional A, optional bRegEx ) as boolean
' Author: Joerg Sievers (13.11.2001)
'/// hFindeImDokument
'/// Searches via 'Search&Replace'-Dlg in StarOffice Writer, -Clac,
'///+ -HTML, -GlobalDoc for the string <b>EXACT MATCH</b>.
'///+ Only ONE TIME and THE FIRST search phrase will be found!
'/// <i>Optional Parameter</i> <b>a</b> : If you do not want a warnlog message
'/// <i>Optional Parameter</i> <b>bRegEx</b> : if you look fort an regular expression
 Dim WhatIsIn as string
 Dim bSilent as boolean
 
   bSilent = NOT isMissing(a)
   gApplication = UCase ( gApplication )
   hFindeImDokument = FALSE

   select case gApplication

      case "CALC"        : Kontext "DocumentCalc"
                           DocumentCalc.TypeKeys "<MOD1 HOME>"

      case "WRITER"      : Kontext "DocumentWriter"
                           DocumentWriter.TypeKeys "<MOD1 HOME>"

      case "NACHRICHT"   : Kontext "DokumentNachrichten"
                           DokumentNachrichten.TypeKeys "<MOD1 HOME>"

      case "HTMLDOKUMENT": Kontext "DocumentWriterWeb"
                           DocumentWriterWeb.TypeKeys "<MOD1 HOME>"

      case "GLOBALDOC"   : Kontext "DocumentMasterDoc"
                           DocumentMasterDoc.TypeKeys "<MOD1 HOME>"

   end select

  SetClipboard ""
  EditSearchAndReplace
  Kontext "FindAndReplace"
  if SimilaritySearch.IsVisible = False then
    More.Click
  end if 
  if MatchCase.IsChecked = False then
    MatchCase.Check
  end if
  if SimilaritySearch.IsChecked = TRUE then
    SimilaritySearch.UnCheck
    if NOT bSilent then    
        warnlog "'Similarity search' checkbox was enabled! It shouldn't be the default!"
    endif
  end if
  if IsMissing(bRegEx) <> TRUE then
    RegularExpressions.Check
  end if
  SearchFor.Settext Passage$
  SearchNow.Click
  Kontext
  if NOT Active.Exists(2) then
      Kontext "FindAndReplace"
    More.Click 
    FindAndReplace.Cancel
     EditCopy
     WhatIsIn = GetClipboardText
     if WhatIsIn <> Passage$ then
      if NOT bSilent then
       warnlog "The search-request for '" & Passage$ & "' has been fault! (Found: '"& WhatIsIn & "')"
      end if
      else
       hFindeImDokument = TRUE
     end if
  else
   try
      Kontext
       if Active.Exists(1) then 
                      Active.OK
       end if
       if NOT bSilent then
           warnlog "The search-request for '" & Passage$ & "' has been fault! (Found: '"& WhatIsIn & "')"           
       end if
       Kontext "FindAndReplace"
       if SimilaritySearch.IsVisible = False then
        More.Click
       endif
       if MatchCase.IsChecked then
        MatchCase.UnCheck
       endif
       if SimilaritySearch.IsChecked = TRUE then
            SimilaritySearch.UnCheck
            if NOT bSilent then
                warnlog "'Similarity search' checkbox was enabled! It shouldn't be the default!"
            endif
       end if
       if IsMissing(bRegEx) <> TRUE then
        RegularExpressions.UnCheck
       endif
       More.Click
       FindAndReplace.Cancel
    catch
      Active.Yes
       Kontext
        if bSilent then
           if Active.Exists then printlog "> "+Active.GetText
        endif
        if Active.Exists then Active.OK
        if NOT bSilent then
           warnlog "The search-request for '" & Passage$ & "' has been fault! (Found: '"& WhatIsIn & "')"
        endif
        Kontext "FindAndReplace"
        if SimilaritySearch.IsVisible = False then
            More.Click
        endif
        if MatchCase.IsChecked then
            MatchCase.UnCheck
        endif
        if SimilaritySearch.IsChecked = TRUE then
            SimilaritySearch.UnCheck
            if NOT bSilent then
                warnlog "'Similarity search' checkbox was enabled! It shouldn't be the default!"
            endif
        end if
        if IsMissing(bRegEx) <> TRUE then
            RegulaererAusdruck.UnCheck
        endif
        More.Click
        FindAndReplace.Cancel
    endcatch
  end if
end function

'-------------------------------------------------------------------------

function hFindeMehrImDokument ( Passage as string , WieOft as integer ) as boolean
' Author: Joerg Sievers (26.07.2000)
'/// hFindeMehrImDokument
'/// Searches per 'Search&Replace'-Dlg in StarOffice Writer, -Clac,
'///+-HTML, -GlobalDoc for the string <b>EXACT MATCH</b>.
'/// You have to give the function the number how often the phrase
'///+should be found in the document as an additional parameter (as integer).
'/// Only when exact the number of the phrase will be found correctly
'///+the function gives back TRUE.
'/// <i>see also</i> : hFindeImDokument (TOOLS.INC)
   Dim i as integer
   gApplication = UCase ( gApplication )

   hFindeMehrImDokument = FALSE

   select case gApplication

      case "CALC"        : Kontext "DocumentCalc"
                           DocumentCalc.TypeKeys "<MOD1 HOME>"

      case "WRITER"      : Kontext "DocumentWriter"
                           DocumentWriter.TypeKeys "<MOD1 HOME>"

      case "NACHRICHT"   : Kontext "DokumentNachrichten"
                           DokumentNachrichten.TypeKeys "<MOD1 HOME>"

      case "HTMLDOKUMENT": Kontext "DocumentWriter"
                           DocumentWriter.TypeKeys "<MOD1 HOME>"

      case "GLOBALDOC"   : Kontext "DocumentMasterDoc"
                           DocumentMasterDoc.TypeKeys "<MOD1 HOME>"

   end select

   SetClipboard ""
   EditSearchAndReplace

 For i = 1 to WieOft
  Kontext "FindAndReplace"
   if NOT MatchCase.IsChecked then MatchCase.Check
   SearchFor.Settext Passage
   SearchNow.Click
  Kontext
   if NOT Active.Exists(2) then
     FindAndReplace.Cancel
      EditCopy
      if GetClipboardText <> Passage then
        warnlog "The search-request for '" & Passage & "' has been fault!"
        i = WieOft
       else
        if i = WieOft then
          hFindeImDokument = TRUE
          printlog "Searchphrase found " & i & " time(s)."
        end if
      end if
    else
     try
       Active.OK
        Kontext
         if Active.Exists then Active.OK
         warnlog "The search-request for '" & Passage & "' has been fault!"
          i = WieOft
          Kontext "FindAndReplace"
           if MatchCase.IsChecked then MatchCase.UnCheck
           FindAndReplace.Cancel
      catch
        Active.Yes
         Kontext
          if Active.Exists then Active.OK
          warnlog "The search-request for '" & Passage & "' has been fault!"
          i = WieOft
          Kontext "FindAndReplace"
           if MatchCase.IsChecked then MatchCase.UnCheck
           FindAndReplace.Cancel
      endcatch
   end if
  Next i
  Kontext "FindAndReplace"
   if FindAndReplace.Exists(2) then
     FindAndReplace.Cancel
   end if
end function

'-------------------------------------------------------------------------

sub ErgebnisSchreiben ( Window, Name$ )
'/// ErgebnisSchreiben
'///+ Used in context with making screenshots.
  Dim FileNum% : Dim i%
  Dim Datei$
  Dim Text$ : Dim Text2$

  Datei$ = sCapturePath + "Ergebis.txt"
  Text2$ = Window.Name
  Text$ = Text2$ +  "    =>   " + Name$

  FileNum% = FreeFile
  Open Datei$ for Append  as #FileNum%
  Print #FileNum%, Text$
  Close #FileNum%
end sub

'-------------------------------------------------------------------------

sub TextInDatei ( TextText$, Datei$ )
'/// TextInDatei
  Dim FileNum%

  FileNum% = FreeFile
  Open Datei$ for Append  as #FileNum%
  Print #FileNum%, TextText$
  Close #FileNum%
end sub

'-------------------------------------------------------------------------

function hGetUIFiltername( vFiltername as string ) as string
'/// Returns the in the UI used filter name.
'///+ <b>INPUT</b>: 'internal', language independent filter name from FilterFactory.
'///+ <u>Examples</u>:<ul><li>hGetUIFiltername(&quot;StarOffice XML (Draw)&quot;) - Draw OOo 1.x/SO6.0/SO7 UI Filtername</li>
'///+ <li>sUIFiltername = hGetUIFiltername(&quot;StarOffice XML (Impress)&quot;) - Impress OOo 1.x/SO6.0/SO7 UI Filtername</li></ul>
'/// The 'internal' name can be found in the *.xcu in 
'///+ ..../share/registry/res/en-US/org/openoffice/TypeDetection/Filter.xcu.
'/// See also: hGetFilternameExtension
    Dim i as integer 
    Dim oOpenUNOService as object
    Dim oFilterName as object
    Dim oUno as object

    oUno = hGetUNOService(TRUE)
    
    oOpenUNOService = oUno.createInstance("com.sun.star.document.FilterFactory")
      try
          oFilterName = oOpenUNOService.getByName(vFiltername)

          for i=0 to ubound(oFilterName)
            if oFilterName(i).Name = "UIName" then
                          hGetUIFiltername = oFilterName(i).Value
                  end if       
          next i
      catch
          warnlog "t_tools1.inc::hGetUIFiltername('" + vFiltername + "'): Filtername is not available."
          hGetUIFiltername = ""
      endcatch
end function

'-------------------------------------------------------------------------

function hGetFilternameExtension ( vFilterName as string)
'/// Returns the in the UI used filter name extension(s) <u>as an <b>array</b></u>. 
'///+ <b>Important</b>: Also returns it <u>as an array</u> if there comes a string from the UNO API call.
'/// <u>Input</u>: 'internal', language independent name
'/// The 'internal' name can be found in the *.xcu in 
'///+ ../share/registry/modules/org/openoffice/TypeDetection/Types/fcfg_[Application_name]_types.xcu file(s).
'/// List of some 'internal' filter names for OOo 2.0/SO8:
'///+<TABLE BORDER=1><TR><TH>Filter</TH><TH><i>internal</i> name</TH><TH>Note</TH></TR>
'///+<TR><TD>Spreadsheet (default)</TD><TD>calc8</TD><TD>-</TD></TR>
'///+<TR><TD>Text document (default)</TD><TD>writer8</TD><TD>-</TD></TR>
'///+<TR><TD>Master document (default)</TD><TD>writerglobal8</TD><TD>-</TD></TR>
'///+<TR><TD>Drawing (default)</TD><TD>draw8</TD><TD>-</TD></TR>
'///+<TR><TD>Presentation (default)</TD><TD>impress8</TD><TD>-</TD></TR>
'///+<TR><TD>Formula/Math (default)</TD><TD>math8</TD><TD>-</TD></TR>
'///+<TR><TD>HTML</TD><TD>writer_web_HTML</TD><TD>two extensions!</TD></TR>
'///+<TR><TD>Text</TD><TD>writer_text</TD><TD>-</TD></TR>
'///+<TR><TD>StarWriter 5.0</TD><TD>writer_StarWriter_50</TD><TD>-</TD></TR>
'///+<TR><TD>StarCalc 5.0</TD><TD>calc_StarCalc_50</TD><TD>-</TD></TR>
'///+</TABLE><br>
' (rewritten, compatible routine; July 2004)
    Dim i as integer 
    Dim x as integer
    Dim oOpenUNOService as object
    Dim oFilterNameExtension as object
    Dim oUno as object    
    dim a as integer
    Dim aExtensions() as string
 
    'Initializize UNO comminication
    oUno = hGetUNOService(TRUE)
    
    'Using the TypeDetection service
    oOpenUNOService = oUno.createInstance("com.sun.star.document.TypeDetection")
      'Getting the Extension by given (internal; language- and product 
    'independent) filter name
    oFilterNameExtension = oOpenUNOService.getByName(vFiltername)

    'using ubound to count the nodes
      for i=0 to ubound(oFilterNameExtension)
              'if the node name is 'Extensions'...
        if oFilterNameExtension(i).Name = "Extensions" then
            '...if it's an array...
            if IsArray(oFilterNameExtension(i).Value) then
                'create dimension of the integer a 
                a = 10
                're-dimension the array with the integer a                
                Redim aExtensions(a) as string
                'return the array into an array
                aExtensions() = oFilterNameExtension(i).Value()                
            else            
                '...otherwise 'build' an array with only
                'one entry in (0)
                Redim aExtensions(0) as string                
                aExtensions(0) = oFilterNameExtension(i).Value                
            end if
              endif
      next i    
    'put the results into the return value of this function into an array.
    hGetFilternameExtension = aExtensions()
end function

'-------------------------------------------------------------------------

function TrimTab ( sTrimmer as String ) as String
'/// TrimTab
'/// <u>Input</u>: the original text
'/// Returns the string without &lt;tab&gt;s at the beginning and the end of a string.
   Dim sInterim as String

   sInterim = sTrimmer
   sInterim = lTrimTab ( sInterim )
   TrimTab = rTrimTab ( sInterim )

end function

'-------------------------------------------------------------------------

function lTrimTab ( slTrimmer as String ) as String
'/// lTrimTab
'/// <u>Input</u>: the original text
'/// Returns the string without &lt;tab&gt;s at the beginning.
'/// Cuts &lt;Tab's&gt; at the beginning of a string ( left )
   Dim i, iLen as Integer
   Dim sInterim as String

   iLen = len ( slTrimmer )
   sInterim = slTrimmer

   for i=1 to iLen
      if Asc ( left ( sInterim, 1 ) ) = 9 then
         sInterim = Right ( sInterim, len ( sInterim ) - 1 )
      else
         i=iLen+1
      end if
   next i
   lTrimTab = sInterim
end function

'-------------------------------------------------------------------------

function rTrimTab ( srTrimmer as String ) as String
'/// rTrimTab
'/// Input: the original text
'/// Returns the string without &lt;tab&gt;s at the end.
'/// Cuts &lt;Tab's&gt; at the beginning of a string ( right )

   Dim i, iLen as Integer
   Dim sInterim as String

   iLen = len ( srTrimmer )
   sInterim = srTrimmer

   for i=1 to iLen
      if Asc ( right ( sInterim, 1 ) ) = 9 then
         sInterim = left ( sInterim, len ( sInterim ) - 1 )
      else
         i=iLen+1
      end if
   next i
   rTrimTab = sInterim
end function

'-------------------------------------------------------------------------

function TrimString (Content as String, delim as integer) as String
' Author: Frank Heitbrock (26.07.2002)
'/// TrimString
'/// <u>Input</u>: The  String, the delimiter which should be cut from the string.
'/// Returns the String without the delimiter.
'/// <u>Example</u>:
'///+ Content = &quot;&nbsp;H&nbsp;a&nbsp;l&nbsp;l&nbsp;o&nbsp;&quot;, delim = 32 (ascii for space character)
'///+ Return = &quot;Hallo&quot;
   dim strlen as integer, i as integer, k as integer
   dim CharBuff(1 to 100) as String
   dim ResultStr as String
   ' at first cut the empty strings left and right of the String
   Content = lTrim(Content)
   Content = rTrim(Content)
   ' now we search for all appropriate ascii characters in the middle of the String and delete them
   strlen = len(Content)
   k = 1
   for i = 1 to strlen
      if mid(Content, i, 1) <> chr(delim) then
         CharBuff(k) = mid(Content, i, 1)
         k = k +1
      end if
   next i
   for i = 1 to k
      ResultStr = ResultStr + CharBuff(i)
   next i
   TrimString = ResultStr

end function

'-------------------------------------------------------------------------

function ActiveDeactivateAsianSupport ( WhatState as Boolean ) as Boolean
' Author: Thorsten Ziehm
'/// ActiveDeactivateAsianSupport
'/// <u>Input</u>: TRUE or FALSE
'///+ TRUE: The Asian support will be enabled.
'///+ FALSE:  The Asian support will be disabled.
'/// <u>Return:</u>
'///+ TRUE/FALSE for the last state of the checkbox in the office UI.
   ToolsOptions
   hToolsOptions ( "LanguageSettings", "Languages" )

   IF Aktivieren.IsEnabled then        'the checkbox is disabled in asian versions
       ActiveDeactivateAsianSupport = Aktivieren.IsChecked         ' the function gets the old state of the checkbox
    
       if WhatState = TRUE then
          try
              Aktivieren.Check
          catch       
          endcatch      
       else
          Aktivieren.UnCheck
       end if
       gAsianSup = WhatState    ' Set the global variable
    
       Kontext "ExtrasOptionenDlg"
       ExtrasOptionenDlg.OK
       Sleep (3)
   else
       ActiveDeactivateAsianSupport = TRUE
       If WhatState = FALSE then
           warnlog "Deactivating of asian language support is not possible, because it is disabled in cjk versions"
       end if
       Kontext "ExtrasOptionenDlg"
       ExtrasOptionenDlg.OK
       Sleep (3)
   end if

end function

'-------------------------------------------------------------------------

function ActiveDeactivateCTLSupport ( WhatState as Boolean ) as Boolean
' Author: Hercule Li (March 2004)
'/// ActiveDeactivateCTLSupport
'/// <u>Input</u>: TRUE or FALSE
'/// TRUE :  The CTL will be enabled.
'/// FALSE:  The CTL will be disabled.
'/// <u>Return:</u>
'/// TRUE/FALSE for the last state of the checkbox in the office UI.
   ToolsOptions
   hToolsOptions ( "LanguageSettings", "Languages" )

    IF ComplexScriptEnabled.IsEnabled then        'the checkbox is disabled in CTL versions    
       ActiveDeactivateCTLSupport = ComplexScriptEnabled.IsChecked      ' the function gets the old state of the checkbox
    
       if WhatState = TRUE then
           ComplexScriptEnabled.Check
       else
           ComplexScriptEnabled.UnCheck
       end if
       gCTLSup = WhatState    ' Set the global variable
    
       Kontext "ExtrasOptionenDlg"
       ExtrasOptionenDlg.OK
       Sleep (3)
    else
       ActiveDeactivateCTLSupport = TRUE
       If WhatState = FALSE then
           warnlog "Deactivating of CTL language support is not possible, because it is disabled in ctl versions"
       end if
       Kontext "ExtrasOptionenDlg"
       ExtrasOptionenDlg.OK
       Sleep (3)
   end if

end function

'-------------------------------------------------------------------------

function GetDecimalSeperator ( optional sDummy$ ) as String
'/// <u>Precondition</u>: Measuring unit has to be set to centimeter (cm) before using this function. (see: fSetMeasurementToCM())    
'///+ <u>Input</u>: Number with fractionmark from <i>NumericField</i> as string     
'///+ <u>Output</u>: A dot (.) or a comma (,) as string
    Dim sCheckForSeparator as string
    Const cWhereIsThisFunction = "qa::qatesttool::global::tools::inc::t_tools1.inc::GetDecimalSeperator: " 
    Dim bDotOrCommaIncluded as boolean    
        
    'Setting the determination of a dot or a comma to FALSE until it was successfull.
    bDotOrCommaIncluded = FALSE
    
    if IsMissing(sDummy$) then
        '/// Opening a new document depending on <i>gApplication</i> value and closing it at the end.
        Call hNewDocument
        '/// Tools / Options / (Modul: gApplication) / General tabpage.
        ToolsOptions            
        '///+ <ol><li>Reading the string of the tabulator numeric field</li> 
        select case UCase(gApplication)
            case "WRITER",  "TEXTDOKUMENT"    : Call hToolsOptions("TEXTDOCUMENT","GENERAL")
                                                sCheckForSeparator = Tabulatorenabstand.GetText
            case "CALC", "TABELLENDOKUMENT"   : Call hToolsOptions("SPREADSHEET","GENERAL")
                                                sCheckForSeparator = Tabulator.GetText
            case "IMPRESS", "PRAESENTATION"   : Call hToolsOptions("PRESENTATION","GENERAL")
                                                sCheckForSeparator = Tabulatorenabstand.GetText                  
            case "DRAW", "ZEICHNUNG"          : Call hToolsOptions("DRAWING","GENERAL")
                                                sCheckForSeparator = Tabulatorenabstand.GetText
            case "GLOBALDOC", "GLOBALDOKUMENT": Call hToolsOptions("TEXTDOCUMENT","GENERAL")
                                                sCheckForSeparator = Tabulatorenabstand.GetText   
            case "HTML", "HTMLDOKUMENT"       : Call hToolsOptions("TEXTDOCUMENT","GENERAL")
                                                sCheckForSeparator = Tabulatorenabstand.GetText
            case else                         : warnlog cWhereIsThisFunction & "For this module ("& gApplication &") no decimal seperator setting exists."
        end select               
        Kontext "ExtrasOptionenDlg"
        ExtrasOptionenDlg.OK       
        if Instr(sCheckForSeparator, ",") > 0 then
            GetDecimalSeperator = ","
            bDotOrCommaIncluded = TRUE
        endif        
        if Instr(sCheckForSeparator, ".") > 0 then
            GetDecimalSeperator = "."
            bDotOrCommaIncluded = TRUE
        endif        
        Call hCloseDocument
    else            
        '///+ <li>or determining the seperator depending on the OPTIONAL value (string).</li></ol>
        'Get position of fraction mark / get IT
        if InStr (sDummy$, ",") > 0 then 
            GetDecimalSeperator = ","
            bDotOrCommaIncluded = TRUE    
        endif
        if InStr (sDummy$, ".") > 0 then 
            GetDecimalSeperator = "."
            bDotOrCommaIncluded = TRUE
        endif
    endif
    
    '/// If the determination failed the dot will be used (default) as decimal seperator.    
    if bDotOrCommaIncluded = FALSE then
        warnlog cWhereIsThisFunction & "Unable to determine decimal separator. Setting dot (.) as default."
        GetDecimalSeperator = "."                
    endif
    printlog "Info: Decimal Seperator is a '" & GetDecimalSeperator & "'." 
end function

sub sResetTheOffice as boolean
    Dim uno
    Dim ap
    Dim xViewRoot
    Dim apara(1) As new com.sun.star.beans.PropertyValue
    Dim temp()
    Dim i,x as integer
    Dim sString as string
    Dim fDeleteList(32000) as string
    Dim sLanguage as string
    Dim bError as boolean
    Dim sDefaultLocale as string
    Dim sDefaultLocaleCJK as string
    Dim sDefaultLocaleCTL as string
    Dim sfgetL10Nvalue as string    
    Dim SetupXML as String
    Dim SetupXMLNet as string
    Dim SetupXMLDefault as string
    Dim sLanOutIni as string

        sString = "qa:qatesttool:calc:options:inc:coption1.inc:: "
        sResetTheOffice = TRUE
        
    ' only run on UNIX platforms; there is a problem with the quickstarter on win32
    if ("unx" = gPlatgroup) then
        try
            SetupXML = gOfficePath & ConvertPath("user\registry\data\org\openoffice\Setup.xcu") 
            ' function 'fgetL10Nvalue' is also in this library
            sLanOutIni = fgetL10Nvalue(SetupXML)
        catch
            try
                ' BugID 98315 -> looking in networkpath for the language until bug will be fixed.
                    SetupXMLNet = gNetzOfficePath & ConvertPath("share\registry\data\org\openoffice\Setup.xcu")
                    sLanOutIni = fgetL10Nvalue(SetupXMLNet)            
            catch
                try
                    ' It is an English FAT version 645m9s2 or higher.                
                        SetupXMLDefault = gOfficePath & ConvertPath("share\registry\data\org\openoffice\Setup.xcu")
                        sLanOutIni = fgetL10Nvalue(SetupXMLDefault)
                catch
                        warnlog sString & SetupXML & " not found => can't get the correct Office-Language!."
                        sResetTheOffice = FALSE
                        Exit sub
                endcatch
            endcatch
        endcatch
            
        uno=hGetUnoService()
        
        'Get UI language
        try
            ap=uno.createInstance("com.sun.star.configuration.ConfigurationProvider")
            apara(0).Name="nodepath"
            apara(0).Value="/org.openoffice.Office.Linguistic/General"
            apara(1).Name="lazywrite"
            apara(1).Value=False
            xViewRoot=ap.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess",aPara()) 
            sLanguage = sfgetL10Nvalue 
            sDefaultLocale = xViewRoot.getPropertyValue("DefaultLocale")
            sDefaultLocaleCJK = xViewRoot.getPropertyValue("DefaultLocale_CJK")
            sDefaultLocaleCTL = xViewRoot.getPropertyValue("DefaultLocale_CTL")
            printlog "Old UI language: '" + sLanOutIni + "'"
            printlog "Old default locale: '" + sDefaultLocale + "'"
            printlog "Old default locale CJK: '" + sDefaultLocaleCJK + "'"
            printlog "Old default locale CTL: '" + sDefaultLocaleCTL + "'"
            xViewRoot.dispose()
            bError = FALSE
        catch
            warnlog sString + "Failed to read UI language."
            bError = TRUE
        endcatch
    
        if NOT bError then
            'Close OOo
            try
                ' To prevent restarting of OOo, the try/catch is around this and
                ' to prevent messages about communication errors
                printlog ResetApplication
                FileExit "SynchronMode", TRUE
                try
                    ' It is no error, if this fails - so it gets its own try/catch
                    kontext
                    if active.exists(5) then
                        active.no 'discard changes
                    endif
                catch
                endcatch
                bError = FALSE
            catch
                warnlog sString + "Failed to close OOo."
                bError = TRUE
            endcatch
            sleep 10 'To wait until OOo is realy away
        endif
    
        'only act, if no error and if language <> ''
         if (NOT bError AND sLanguage <> "") then
             'Remove user directory
            try
                if (right(gOfficePath,1)=gPathSigne) then
                    'Dir doesn't work, is a path singe is at the end
                    gOfficePath = left(gOfficePath,len(gOfficePath)-1)
                endif
                printlog "Going to delete directory: '" + gOfficePath + "'"
                if (dir(gOfficePath) = "") then
                    qaErrorlog "Directory is already deleted."
                else
                    rmDir (gOfficePath)
                    if (dir(gOfficePath) <> "") then
                        warnlog "Directory wasn't deleted."
                    endif
                endif
                bError = FALSE
            catch
                warnlog sString + "Failed to delete user directory."
                bError = TRUE
            endcatch
        endif
    
        'Start OOo and restore language
        'Needs only to be done, if UI language wasn't the default (!= "")
        if ((sLanguage & sDefaultLocale & sDefaultLocaleCJK & sDefaultLocaleCTL) <> "") then
            try
                hStartTheOffice
                Call hDisableQuickstarter
                'Here we need the Exit from a running Quickstarter...            
                Call ExitRestartTheOffice
                uno=hGetUnoService()
                ap=uno.createInstance("com.sun.star.configuration.ConfigurationProvider")
                apara(0).Name="nodepath"
                apara(0).Value="/org.openoffice.Office.Linguistic/General"
                apara(1).Name="lazywrite"
                apara(1).Value=False
                xViewRoot=ap.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess",aPara())
                if (sLanOutIni <> "") then                
                    printlog "Old UI language: '" + sLanOutIni + "'"
                    xViewRoot.setPropertyValue("UILocale", sLanOutIni)
                    xViewRoot.commitChanges()
                endif
                if (sDefaultLocale <> "") then
                    printlog "Old default locale: '" + sDefaultLocale + "'"
                    xViewRoot.setPropertyValue("DefaultLocale", sDefaultLocale)
                    xViewRoot.commitChanges()
                endif
                if (sDefaultLocaleCJK <> "") then
                    printlog "Old default locale CJK: '" + sDefaultLocaleCJK + "'"
                    xViewRoot.setPropertyValue("DefaultLocale_CJK", sDefaultLocaleCJK)
                    xViewRoot.commitChanges()
                endif
                if (sDefaultLocaleCTL <> "") then
                    printlog "Old default locale CTL: '" + sDefaultLocaleCTL + "'"
                    xViewRoot.setPropertyValue("DefaultLocale_CTL", sDefaultLocaleCTL)
                    xViewRoot.commitChanges()
                endif
                if xViewRoot.hasPendingChanges() then
                    warnlog(sFileFunction+"Changes still pending...")
                endif
                xViewRoot.dispose()            
            catch
                warnlog sString + "Failed to set UI language."
                exit sub
            endcatch
        endif
        
        Call ExitRestartTheOffice
    endif
end sub

'-------------------------------------------------------------------------

sub raiseApplication
' Try to solve focus problem on MacOS X; After calling this function, OOo should be most front;
    Dim i as integer
    Dim a as integer
    Dim b as integer
    Dim tBundle as string
    Dim aPath

    ' Calling just the .app with open on MacOS X via shell command
    if gPlatform = lcase("osx") then
        aPath = split(gNetzOfficePath, gPathSigne)
        a=0
        ' make sure 'Contents' is just one time in path
        for i=0 to uBound(aPath)
            if "Contents" = aPath(i) then
                a=a+1
            endif
        next i
        ' exit if not
        if a<>1 then
             exit sub
        end if
        i=inStr(gNetzOfficePath, "Contents")
        tBundle=left(gNetzOfficePath, i-2)
        shell("open",1 ,tBundle, true)
    end if
end sub