-
Notifications
You must be signed in to change notification settings - Fork 1
/
LibreOfficeWriter_Helper.au3
2799 lines (2499 loc) · 181 KB
/
LibreOfficeWriter_Helper.au3
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
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include-once
; Main LibreOffice Includes
#include "LibreOffice_Constants.au3"
; Common includes for Writer
#include "LibreOfficeWriter_Constants.au3"
#include "LibreOfficeWriter_Internal.au3"
; Other includes for Writer
#include "LibreOfficeWriter_Font.au3"
#include "LibreOfficeWriter_Page.au3"
; #INDEX# =======================================================================================================================
; Title .........: LibreOffice UDF
; AutoIt Version : v3.3.16.1
; Description ...: Functions used for creating, modifying and retrieving data for use in various functions in LibreOffice UDF.
; Author(s) .....: donnyh13, mLipok
; Dll ...........:
;
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
; _LOWriter_ComError_UserFunction
; _LOWriter_ConvertColorFromLong
; _LOWriter_ConvertColorToLong
; _LOWriter_ConvertFromMicrometer
; _LOWriter_ConvertToMicrometer
; _LOWriter_DateFormatKeyCreate
; _LOWriter_DateFormatKeyDelete
; _LOWriter_DateFormatKeyExists
; _LOWriter_DateFormatKeyGetString
; _LOWriter_DateFormatKeyList
; _LOWriter_DateStructCreate
; _LOWriter_DateStructModify
; _LOWriter_FindFormatModifyAlignment
; _LOWriter_FindFormatModifyEffects
; _LOWriter_FindFormatModifyFont
; _LOWriter_FindFormatModifyHyphenation
; _LOWriter_FindFormatModifyIndent
; _LOWriter_FindFormatModifyOverline
; _LOWriter_FindFormatModifyPageBreak
; _LOWriter_FindFormatModifyPosition
; _LOWriter_FindFormatModifyRotateScaleSpace
; _LOWriter_FindFormatModifySpacing
; _LOWriter_FindFormatModifyStrikeout
; _LOWriter_FindFormatModifyTxtFlowOpt
; _LOWriter_FindFormatModifyUnderline
; _LOWriter_FormatKeyCreate
; _LOWriter_FormatKeyDelete
; _LOWriter_FormatKeyExists
; _LOWriter_FormatKeyGetStandard
; _LOWriter_FormatKeyGetString
; _LOWriter_FormatKeyList
; _LOWriter_PathConvert
; _LOWriter_SearchDescriptorCreate
; _LOWriter_SearchDescriptorModify
; _LOWriter_SearchDescriptorSimilarityModify
; _LOWriter_VersionGet
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_ComError_UserFunction
; Description ...: Set a UserFunction to receive the Fired COM Error Error outside of the UDF.
; Syntax ........: _LOWriter_ComError_UserFunction([$vUserFunction = Default[, $vParam1 = Null[, $vParam2 = Null[, $vParam3 = Null[, $vParam4 = Null[, $vParam5 = Null]]]]]])
; Parameters ....: $vUserFunction - [optional] a Function or Keyword. Default value is Default. Accepts a Function, or the Keyword Default and Null. If set to a User function, the function may have up to 5 required parameters.
; $vParam1 - [optional] a variant value. Default is Null. Any optional parameter to be called with the user function.
; $vParam2 - [optional] a variant value. Default is Null. Any optional parameter to be called with the user function.
; $vParam3 - [optional] a variant value. Default is Null. Any optional parameter to be called with the user function.
; $vParam4 - [optional] a variant value. Default is Null. Any optional parameter to be called with the user function.
; $vParam5 - [optional] a variant value. Default is Null. Any optional parameter to be called with the user function.
; Return values .: Success: 1 or UserFunction.
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $vUserFunction Not a Function, or Default keyword, or Null Keyword.
; --Success--
; @Error 0 @Extended 0 Return 1 = Successfully set the UserFunction.
; @Error 0 @Extended 0 Return 2 = Successfully cleared the set UserFunction.
; @Error 0 @Extended 0 Return Function = Returning the set UserFunction.
; Author ........: mLipok
; Modified ......: donnyh13 - Added a clear UserFunction without error option. Also added parameters option.
; Remarks .......: The first parameter passed to the User function will always be the COM Error object. See below.
; Every COM Error will be passed to that function. The user can then read the following properties. (As Found in the COM Reference section in Autoit HelpFile.) Using the first parameter in the UserFunction.
; For Example MyFunc($oMyError)
; $oMyError.number The Windows HRESULT value from a COM call
; $oMyError.windescription The FormatWinError() text derived from .number
; $oMyError.source Name of the Object generating the error (contents from ExcepInfo.source)
; $oMyError.description Source Object's description of the error (contents from ExcepInfo.description)
; $oMyError.helpfile Source Object's helpfile for the error (contents from ExcepInfo.helpfile)
; $oMyError.helpcontext Source Object's helpfile context id number (contents from ExcepInfo.helpcontext)
; $oMyError.lastdllerror The number returned from GetLastError()
; $oMyError.scriptline The script line on which the error was generated
; NOTE: Not all properties will necessarily contain data, some will be blank.
; If MsgBox or ConsoleWrite functions are passed to this function, the error details will be displayed using that function automatically.
; If called with Default keyword, the current UserFunction, if set, will be returned.
; If called with Null keyword, the currently set UserFunction is cleared and only the internal ComErrorHandler will be called for COM Errors.
; The stored UserFunction (besides MsgBox and ConsoleWrite) will be called as follows: UserFunc($oComError,$vParam1,$vParam2,$vParam3,$vParam4,$vParam5)
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_ComError_UserFunction($vUserFunction = Default, $vParam1 = Null, $vParam2 = Null, $vParam3 = Null, $vParam4 = Null, $vParam5 = Null)
#forceref $vParam1, $vParam2, $vParam3, $vParam4, $vParam5
; If user does not set a function, UDF must use internal function to avoid AutoItError.
Local Static $vUserFunction_Static = Default
Local $avUserFuncWParams[@NumParams]
If $vUserFunction = Default Then
; just return stored static User Function variable
Return SetError($__LO_STATUS_SUCCESS, 0, $vUserFunction_Static)
ElseIf IsFunc($vUserFunction) Then
; If User called Parameters, then add to array.
If @NumParams > 1 Then
$avUserFuncWParams[0] = $vUserFunction
For $i = 1 To @NumParams - 1
$avUserFuncWParams[$i] = Eval("vParam" & $i)
; set static variable
Next
$vUserFunction_Static = $avUserFuncWParams
Else
$vUserFunction_Static = $vUserFunction
EndIf
Return SetError($__LO_STATUS_SUCCESS, 0, 1)
ElseIf $vUserFunction = Null Then
; Clear User Function.
$vUserFunction_Static = Default
Return SetError($__LO_STATUS_SUCCESS, 0, 2)
Else
; return error as an incorrect parameter was passed to this function
Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
EndIf
EndFunc ;==>_LOWriter_ComError_UserFunction
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_ConvertColorFromLong
; Description ...: Convert Long color code to Hex, RGB, HSB or CMYK.
; Syntax ........: _LOWriter_ConvertColorFromLong([$iHex = Null[, $iRGB = Null[, $iHSB = Null[, $iCMYK = Null]]]])
; Parameters ....: $iHex - [optional] an integer value. Default is Null. Convert Long Color Integer to Hexadecimal.
; $iRGB - [optional] an integer value. Default is Null. Convert Long Color Integer to R.G.B.
; $iHSB - [optional] an integer value. Default is Null. Convert Long Color Integer to H.S.B.
; $iCMYK - [optional] an integer value. Default is Null. Convert Long Color Integer to C.M.Y.K.
; Return values .: Success: String or Array.
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = No parameters set.
; @Error 1 @Extended 2 Return 0 = No parameters set to an integer.
; --Success--
; @Error 0 @Extended 1 Return String. Long integer converted To Hexadecimal (as a String). (Without the "0x" prefix)
; @Error 0 @Extended 2 Return Array. Array containing Long integer converted To Red, Green, Blue,(RGB). $Array[0] = R, $Array[1] = G, etc.
; @Error 0 @Extended 3 Return Array. Array containing Long integer converted To Hue, Saturation, Brightness, (HSB). $Array[0] = H, $Array[1] = S, etc.
; @Error 0 @Extended 4 Return Array. Array containing Long integer converted To Cyan, Magenta, Yellow, Black, (CMYK). $Array[0] = C, $Array[1] = M, etc.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: To retrieve a Hexadecimal color value, call the Long Color code in $iHex, To retrieve a R(ed)G(reen)B(lue) color value, call Null in $iHex, and call the Long color code into $iRGB, etc. for the other color types.
; Hex returns as a string variable, all others (RGB, HSB, CMYK) return an array.
; The Hexadecimal figure returned doesn't contain the usual "0x", as LibeOffice does not implement it in its numbering system.
; Related .......: _LOWriter_ConvertColorToLong
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_ConvertColorFromLong($iHex = Null, $iRGB = Null, $iHSB = Null, $iCMYK = Null)
Local $nRed, $nGreen, $nBlue, $nResult, $nMaxRGB, $nMinRGB, $nHue, $nSaturation, $nBrightness, $nCyan, $nMagenta, $nYellow, $nBlack
Local $dHex
Local $aiReturn[0]
If (@NumParams = 0) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
Select
Case IsInt($iHex) ; Long TO Hex
$nRed = BitAND(BitShift($iHex, 16), 0xff)
$nGreen = BitAND(BitShift($iHex, 8), 0xff)
$nBlue = BitAND($iHex, 0xff)
$dHex = Hex($nRed, 2) & Hex($nGreen, 2) & Hex($nBlue, 2)
Return SetError($__LO_STATUS_SUCCESS, 1, $dHex)
Case IsInt($iRGB) ; Long to RGB
$nRed = BitAND(BitShift($iRGB, 16), 0xff)
$nGreen = BitAND(BitShift($iRGB, 8), 0xff)
$nBlue = BitAND($iRGB, 0xff)
ReDim $aiReturn[3]
$aiReturn[0] = $nRed
$aiReturn[1] = $nGreen
$aiReturn[2] = $nBlue
Return SetError($__LO_STATUS_SUCCESS, 2, $aiReturn)
Case IsInt($iHSB) ; Long TO HSB
$nRed = (Mod(($iHSB / 65536), 256)) / 255
$nGreen = (Mod(($iHSB / 256), 256)) / 255
$nBlue = (Mod($iHSB, 256)) / 255
; get Max RGB Value
$nResult = ($nRed > $nGreen) ? ($nRed) : ($nGreen)
$nMaxRGB = ($nResult > $nBlue) ? ($nResult) : ($nBlue)
; get Min RGB Value
$nResult = ($nRed < $nGreen) ? ($nRed) : ($nGreen)
$nMinRGB = ($nResult < $nBlue) ? ($nResult) : ($nBlue)
; Determine Brightness
$nBrightness = $nMaxRGB
; Determine Hue
$nHue = 0
Select
Case $nRed = $nGreen = $nBlue ; Red, Green, and Blue are equal.
$nHue = 0
Case ($nRed >= $nGreen) And ($nGreen >= $nBlue) ; Red Highest, Blue Lowest
$nHue = (60 * (($nGreen - $nBlue) / ($nRed - $nBlue)))
Case ($nRed >= $nBlue) And ($nBlue >= $nGreen) ; Red Highest, Green Lowest
$nHue = (60 * (6 - (($nBlue - $nGreen) / ($nRed - $nGreen))))
Case ($nGreen >= $nRed) And ($nRed >= $nBlue) ; Green Highest, Blue Lowest
$nHue = (60 * (2 - (($nRed - $nBlue) / ($nGreen - $nBlue))))
Case ($nGreen >= $nBlue) And ($nBlue >= $nRed) ; Green Highest, Red Lowest
$nHue = (60 * (2 + (($nBlue - $nRed) / ($nGreen - $nRed))))
Case ($nBlue >= $nGreen) And ($nGreen >= $nRed) ; Blue Highest, Red Lowest
$nHue = (60 * (4 - (($nGreen - $nRed) / ($nBlue - $nRed))))
Case ($nBlue >= $nRed) And ($nRed >= $nGreen) ; Blue Highest, Green Lowest
$nHue = (60 * (4 + (($nRed - $nGreen) / ($nBlue - $nGreen))))
EndSelect
; Determine Saturation
$nSaturation = ($nMaxRGB = 0) ? (0) : (($nMaxRGB - $nMinRGB) / $nMaxRGB)
$nHue = ($nHue > 0) ? (Round($nHue)) : (0)
$nSaturation = Round(($nSaturation * 100))
$nBrightness = Round(($nBrightness * 100))
ReDim $aiReturn[3]
$aiReturn[0] = $nHue
$aiReturn[1] = $nSaturation
$aiReturn[2] = $nBrightness
Return SetError($__LO_STATUS_SUCCESS, 3, $aiReturn)
Case IsInt($iCMYK) ; Long to CMYK
$nRed = (Mod(($iCMYK / 65536), 256))
$nGreen = (Mod(($iCMYK / 256), 256))
$nBlue = (Mod($iCMYK, 256))
$nRed = Round(($nRed / 255), 3)
$nGreen = Round(($nGreen / 255), 3)
$nBlue = Round(($nBlue / 255), 3)
; get Max RGB Value
$nResult = ($nRed > $nGreen) ? ($nRed) : ($nGreen)
$nMaxRGB = ($nResult > $nBlue) ? ($nResult) : ($nBlue)
$nBlack = (1 - $nMaxRGB)
$nCyan = ((1 - $nRed - $nBlack) / (1 - $nBlack))
$nMagenta = ((1 - $nGreen - $nBlack) / (1 - $nBlack))
$nYellow = ((1 - $nBlue - $nBlack) / (1 - $nBlack))
$nCyan = Round(($nCyan * 100))
$nMagenta = Round(($nMagenta * 100))
$nYellow = Round(($nYellow * 100))
$nBlack = Round(($nBlack * 100))
ReDim $aiReturn[4]
$aiReturn[0] = $nCyan
$aiReturn[1] = $nMagenta
$aiReturn[2] = $nYellow
$aiReturn[3] = $nBlack
Return SetError($__LO_STATUS_SUCCESS, 4, $aiReturn)
Case Else
Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0) ; no parameters set to an integer
EndSelect
EndFunc ;==>_LOWriter_ConvertColorFromLong
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_ConvertColorToLong
; Description ...: Convert Hex, RGB, HSB or CMYK to Long color code.
; Syntax ........: _LOWriter_ConvertColorToLong([$vVal1 = Null[, $vVal2 = Null[, $vVal3 = Null[, $vVal4 = Null]]]])
; Parameters ....: $vVal1 - [optional] a variant value. Default is Null. See remarks.
; $vVal2 - [optional] a variant value. Default is Null. See remarks.
; $vVal3 - [optional] a variant value. Default is Null. See remarks.
; $vVal4 - [optional] a variant value. Default is Null. See remarks.
; Return values .: Success: Integer.
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = No parameters set.
; @Error 1 @Extended 2 Return 0 = One parameter called, but not in String format(Hex).
; @Error 1 @Extended 3 Return 0 = Hex parameter contains non Hex characters.
; @Error 1 @Extended 4 Return 0 = Hex parameter not 6 characters long.
; @Error 1 @Extended 5 Return 0 = Hue parameter contains more than just digits.
; @Error 1 @Extended 6 Return 0 = Saturation parameter contains more than just digits.
; @Error 1 @Extended 7 Return 0 = Brightness parameter contains more than just digits.
; @Error 1 @Extended 8 Return 0 = Three parameters called but not all Integers (RGB) and not all Strings (HSB).
; @Error 1 @Extended 9 Return 0 = Four parameters called but not all Integers(CMYK).
; @Error 1 @Extended 10 Return 0 = Too many or too few parameters called.
; --Success--
; @Error 0 @Extended 1 Return Integer. Long Int. Color code converted from Hexadecimal.
; @Error 0 @Extended 2 Return Integer. Long Int. Color code converted from Red, Green, Blue, (RGB).
; @Error 0 @Extended 3 Return Integer. Long Int. Color code converted from (H)ue, (S)aturation, (B)rightness,
; @Error 0 @Extended 4 Return Integer. Long Int. Color code converted from (C)yan, (M)agenta, (Y)ellow, Blac(k)
; Author ........: donnyh13
; Modified ......:
; Remarks .......: To Convert a Hex(adecimal) color code, call the Hex code in $vVal1 in String Format.
; To convert a R(ed) G(reen) B(lue color, call R value in $vVal1 as an Integer, G in $vVal2 as an Integer, and B in $vVal3 as an Integer.
; To convert a H(ue) S(aturation) B(rightness) color, call H in $vVal1 as a String, S in $vVal2 as a String, and B in $vVal3 as a string.
; To convert C(yan) M(agenta) Y(ellow) Blac(k) call C in $vVal1 as an Integer, M in $vVal2 as an Integer, Y in $vVal3 as an Integer, and K in $vVal4 as an Integer format.
; The Hexadecimal figure entered cannot contain the usual "0x", as LibeOffice does not implement it in its numbering system.
; Related .......: _LOWriter_ConvertColorFromLong
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_ConvertColorToLong($vVal1 = Null, $vVal2 = Null, $vVal3 = Null, $vVal4 = Null) ; RGB = Int, CMYK = Int, HSB = String, Hex = String.
Local Const $STR_STRIPALL = 8
Local $iRed, $iGreen, $iBlue, $iLong, $iHue, $iSaturation, $iBrightness
Local $dHex
Local $nMaxRGB, $nMinRGB, $nChroma, $nHuePre, $nCyan, $nMagenta, $nYellow, $nBlack
If (@NumParams = 0) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
Switch @NumParams
Case 1 ;Hex
If Not IsString($vVal1) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0) ; not a string
$vVal1 = StringStripWS($vVal1, $STR_STRIPALL)
$dHex = $vVal1
; From Hex to RGB
If (StringLen($dHex) = 6) Then
If StringRegExp($dHex, "[^0-9a-fA-F]") Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0) ; $dHex contains non Hex characters.
$iRed = BitAND(BitShift("0x" & $dHex, 16), 0xFF)
$iGreen = BitAND(BitShift("0x" & $dHex, 8), 0xFF)
$iBlue = BitAND("0x" & $dHex, 0xFF)
$iLong = BitShift($iRed, -16) + BitShift($iGreen, -8) + $iBlue
Return SetError($__LO_STATUS_SUCCESS, 1, $iLong) ; Long from Hex
Else
Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0) ; Wrong length of string.
EndIf
Case 3 ;RGB and HSB; HSB is all strings, RGB all Integers.
If (IsInt($vVal1) And IsInt($vVal2) And IsInt($vVal3)) Then ; RGB
$iRed = $vVal1
$iGreen = $vVal2
$iBlue = $vVal3
; RGB to Long
$iLong = BitShift($iRed, -16) + BitShift($iGreen, -8) + $iBlue
Return SetError($__LO_STATUS_SUCCESS, 2, $iLong) ; Long from RGB
ElseIf IsString($vVal1) And IsString($vVal2) And IsString($vVal3) Then ; Hue Saturation and Brightness (HSB)
; HSB to RGB
$vVal1 = StringStripWS($vVal1, $STR_STRIPALL)
$vVal2 = StringStripWS($vVal2, $STR_STRIPALL)
$vVal3 = StringStripWS($vVal3, $STR_STRIPALL) ; Strip WS so I can check string length in HSB conversion.
$iHue = Number($vVal1)
If (StringLen($vVal1)) <> (StringLen($iHue)) Then Return SetError($__LO_STATUS_INPUT_ERROR, 5, 0) ; String contained more than just digits
$iSaturation = Number($vVal2)
If (StringLen($vVal2)) <> (StringLen($iSaturation)) Then Return SetError($__LO_STATUS_INPUT_ERROR, 6, 0) ; String contained more than just digits
$iBrightness = Number($vVal3)
If (StringLen($vVal3)) <> (StringLen($iBrightness)) Then Return SetError($__LO_STATUS_INPUT_ERROR, 7, 0) ; String contained more than just digits
$nMaxRGB = ($iBrightness / 100)
$nChroma = (($iSaturation / 100) * ($iBrightness / 100))
$nMinRGB = ($nMaxRGB - $nChroma)
$nHuePre = ($iHue >= 300) ? (($iHue - 360) / 60) : ($iHue / 60)
Switch $nHuePre
Case (-1) To 1.0
$iRed = $nMaxRGB
If $nHuePre < 0 Then
$iGreen = $nMinRGB
$iBlue = ($iGreen - $nHuePre * $nChroma)
Else
$iBlue = $nMinRGB
$iGreen = ($iBlue + $nHuePre * $nChroma)
EndIf
Case 1.1 To 3.0
$iGreen = $nMaxRGB
If (($nHuePre - 2) < 0) Then
$iBlue = $nMinRGB
$iRed = ($iBlue - ($nHuePre - 2) * $nChroma)
Else
$iRed = $nMinRGB
$iBlue = ($iRed + ($nHuePre - 2) * $nChroma)
EndIf
Case 3.1 To 5
$iBlue = $nMaxRGB
If (($nHuePre - 4) < 0) Then
$iRed = $nMinRGB
$iGreen = ($iRed - ($nHuePre - 4) * $nChroma)
Else
$iGreen = $nMinRGB
$iRed = ($iGreen + ($nHuePre - 4) * $nChroma)
EndIf
EndSwitch
$iRed = Round(($iRed * 255))
$iGreen = Round(($iGreen * 255))
$iBlue = Round(($iBlue * 255))
$iLong = BitShift($iRed, -16) + BitShift($iGreen, -8) + $iBlue
Return SetError($__LO_STATUS_SUCCESS, 3, $iLong) ; Return Long from HSB
Else
Return SetError($__LO_STATUS_INPUT_ERROR, 8, 0) ; Wrong parameters
EndIf
Case 4 ;CMYK
If Not (IsInt($vVal1) And IsInt($vVal2) And IsInt($vVal3) And IsInt($vVal4)) Then Return SetError($__LO_STATUS_INPUT_ERROR, 9, 0) ; CMYK not integers.
; CMYK to RGB
$nCyan = ($vVal1 / 100)
$nMagenta = ($vVal2 / 100)
$nYellow = ($vVal3 / 100)
$nBlack = ($vVal4 / 100)
$iRed = Round((255 * (1 - $nBlack) * (1 - $nCyan)))
$iGreen = Round((255 * (1 - $nBlack) * (1 - $nMagenta)))
$iBlue = Round((255 * (1 - $nBlack) * (1 - $nYellow)))
$iLong = BitShift($iRed, -16) + BitShift($iGreen, -8) + $iBlue
Return SetError($__LO_STATUS_SUCCESS, 4, $iLong) ; Long from CMYK
Case Else
Return SetError($__LO_STATUS_INPUT_ERROR, 10, 0) ; wrong number of Parameters
EndSwitch
EndFunc ;==>_LOWriter_ConvertColorToLong
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_ConvertFromMicrometer
; Description ...: Convert from Micrometer to Inch, Centimeter, Millimeter, or Printer's Points.
; Syntax ........: _LOWriter_ConvertFromMicrometer([$nInchOut = Null[, $nCentimeterOut = Null[, $nMillimeterOut = Null[, $nPointsOut = Null]]]])
; Parameters ....: $nInchOut - [optional] a general number value. Default is Null. The Micrometers to convert to Inches. See remarks.
; $nCentimeterOut - [optional] a general number value. Default is Null. The Micrometers to convert to Centimeters. See remarks.
; $nMillimeterOut - [optional] a general number value. Default is Null. The Micrometers to convert to Millimeters. See remarks.
; $nPointsOut - [optional] a general number value. Default is Null. The Micrometers to convert to Printer's Points. See remarks.
; Return values .: Success: Number
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $nInchOut not a number.
; @Error 1 @Extended 2 Return 0 = $nCentimeterOut not a number.
; @Error 1 @Extended 3 Return 0 = $nMillimeterOut not a number.
; @Error 1 @Extended 4 Return 0 = $nPointsOut not a number.
; @Error 1 @Extended 5 Return 0 = No parameters set to other than Null.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Error converting from Micrometers to Inch.
; @Error 3 @Extended 2 Return 0 = Error converting from Micrometers to Centimeter.
; @Error 3 @Extended 3 Return 0 = Error converting from Micrometers to Millimeter.
; @Error 3 @Extended 4 Return 0 = Error converting from Micrometers to Printer's Points.
; --Success--
; @Error 0 @Extended 1 Return Number. Converted from Micrometers to Inch.
; @Error 0 @Extended 2 Return Number. Converted from Micrometers to Centimeter.
; @Error 0 @Extended 3 Return Number. Converted from Micrometers to Millimeter.
; @Error 0 @Extended 4 Return Number. Converted from Micrometers to Printer's Points.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: To skip a parameter, set it to Null.
; If you are converting to Inches, place the Micrometers in $nInchOut, if converting to Millimeters, $nInchOut and $nCentimeter are set to Null, and $nMillimetersOut is set.
; A Micrometer is 1000th of a centimeter, and is used in almost all Libre Office functions that contain a measurement parameter.
; Related .......: _LOWriter_ConvertToMicrometer
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_ConvertFromMicrometer($nInchOut = Null, $nCentimeterOut = Null, $nMillimeterOut = Null, $nPointsOut = Null)
Local $nReturnValue
If ($nInchOut <> Null) Then
If Not IsNumber($nInchOut) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
$nReturnValue = __LOWriter_UnitConvert($nInchOut, $__LOCONST_CONVERT_UM_INCH)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
Return SetError($__LO_STATUS_SUCCESS, 1, $nReturnValue)
EndIf
If ($nCentimeterOut <> Null) Then
If Not IsNumber($nCentimeterOut) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
$nReturnValue = __LOWriter_UnitConvert($nCentimeterOut, $__LOCONST_CONVERT_UM_CM)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
Return SetError($__LO_STATUS_SUCCESS, 2, $nReturnValue)
EndIf
If ($nMillimeterOut <> Null) Then
If Not IsNumber($nMillimeterOut) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
$nReturnValue = __LOWriter_UnitConvert($nMillimeterOut, $__LOCONST_CONVERT_UM_MM)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 3, 0)
Return SetError($__LO_STATUS_SUCCESS, 3, $nReturnValue)
EndIf
If ($nPointsOut <> Null) Then
If Not IsNumber($nPointsOut) Then Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0)
$nReturnValue = __LOWriter_UnitConvert($nPointsOut, $__LOCONST_CONVERT_UM_PT)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 4, 0)
Return SetError($__LO_STATUS_SUCCESS, 4, $nReturnValue)
EndIf
Return SetError($__LO_STATUS_INPUT_ERROR, 5, 0) ; NO Unit set.
EndFunc ;==>_LOWriter_ConvertFromMicrometer
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_ConvertToMicrometer
; Description ...: Convert from Inch, Centimeter, Millimeter, or Printer's Points to Micrometer.
; Syntax ........: _LOWriter_ConvertToMicrometer([$nInchIn = Null[, $nCentimeterIn = Null[, $nMillimeterIn = Null[, $nPointsIn = Null]]]])
; Parameters ....: $nInchIn - [optional] a general number value. Default is Null. The Inches to convert to Micrometers. See remarks.
; $nCentimeterIn - [optional] a general number value. Default is Null. The Centimeters to convert to Micrometers. See remarks.
; $nMillimeterIn - [optional] a general number value. Default is Null. The Millimeters to convert to Micrometers. See remarks.
; $nPointsIn - [optional] a general number value. Default is Null. The Printer's Points to convert to Micrometers. See remarks.
; Return values .: Success: Integer
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $nInchIn not a number.
; @Error 1 @Extended 2 Return 0 = $nCentimeterIn not a number.
; @Error 1 @Extended 3 Return 0 = $nMillimeterIn not a number.
; @Error 1 @Extended 4 Return 0 = $nPointsIn not a number.
; @Error 1 @Extended 5 Return 0 = No parameters set to other than Null.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Error converting from Inches to Micrometers.
; @Error 3 @Extended 2 Return 0 = Error converting from Centimeters to Micrometers.
; @Error 3 @Extended 3 Return 0 = Error converting from Millimeters to Micrometers.
; @Error 3 @Extended 4 Return 0 = Error converting from Printer's Points to Micrometers.
; --Success--
; @Error 0 @Extended 1 Return Integer. Converted Inches to Micrometers.
; @Error 0 @Extended 2 Return Integer. Converted Centimeters to Micrometers.
; @Error 0 @Extended 3 Return Integer. Converted Millimeters to Micrometers.
; @Error 0 @Extended 4 Return Integer. Converted Printer's Points to Micrometers.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: To skip a parameter, set it to Null. If you are converting from Inches, call inches in $nInchIn, if converting from Centimeters, $nInchIn is called with Null, and $nCentimeters is set.
; A Micrometer is 1000th of a centimeter, and is used in almost all Libre Office functions that contain a measurement parameter.
; Related .......: _LOWriter_ConvertFromMicrometer
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_ConvertToMicrometer($nInchIn = Null, $nCentimeterIn = Null, $nMillimeterIn = Null, $nPointsIn = Null)
Local $nReturnValue
If ($nInchIn <> Null) Then
If Not IsNumber($nInchIn) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
$nReturnValue = __LOWriter_UnitConvert($nInchIn, $__LOCONST_CONVERT_INCH_UM)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
Return SetError($__LO_STATUS_SUCCESS, 1, $nReturnValue)
EndIf
If ($nCentimeterIn <> Null) Then
If Not IsNumber($nCentimeterIn) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
$nReturnValue = __LOWriter_UnitConvert($nCentimeterIn, $__LOCONST_CONVERT_CM_UM)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
Return SetError($__LO_STATUS_SUCCESS, 2, $nReturnValue)
EndIf
If ($nMillimeterIn <> Null) Then
If Not IsNumber($nMillimeterIn) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
$nReturnValue = __LOWriter_UnitConvert($nMillimeterIn, $__LOCONST_CONVERT_MM_UM)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 3, 0)
Return SetError($__LO_STATUS_SUCCESS, 3, $nReturnValue)
EndIf
If ($nPointsIn <> Null) Then
If Not IsNumber($nPointsIn) Then Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0)
$nReturnValue = __LOWriter_UnitConvert($nPointsIn, $__LOCONST_CONVERT_PT_UM)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 4, 0)
Return SetError($__LO_STATUS_SUCCESS, 4, $nReturnValue)
EndIf
Return SetError($__LO_STATUS_INPUT_ERROR, 5, 0) ; NO Unit set.
EndFunc ;==>_LOWriter_ConvertToMicrometer
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DateFormatKeyCreate
; Description ...: Create a Date/Time Format Key.
; Syntax ........: _LOWriter_DateFormatKeyCreate(ByRef $oDoc, $sFormat)
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; $sFormat - a string value. The Date/Time format String to create.
; Return values .: Success: Integer
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $sFormat not a String.
; --Initialization Errors--
; @Error 2 @Extended 1 Return 0 = Failed to Create "com.sun.star.lang.Locale" Object.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Failed to retrieve Number Formats Object.
; @Error 3 @Extended 2 Return 0 = Failed to Create or Retrieve the Format key.
; --Success--
; @Error 0 @Extended 0 Return Integer = Success. Format Key was successfully created, returning Format Key integer.
; @Error 0 @Extended 1 Return Integer = Success. Format Key already existed, returning Format Key integer.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......: _LOWriter_DateFormatKeyDelete
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DateFormatKeyCreate(ByRef $oDoc, $sFormat)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $iFormatKey
Local $tLocale
Local $oFormats
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsString($sFormat) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
$tLocale = __LOWriter_CreateStruct("com.sun.star.lang.Locale")
If Not IsObj($tLocale) Then Return SetError($__LO_STATUS_INIT_ERROR, 1, 0)
$oFormats = $oDoc.getNumberFormats()
If Not IsObj($oFormats) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
$iFormatKey = $oFormats.queryKey($sFormat, $tLocale, False)
If ($iFormatKey > -1) Then Return SetError($__LO_STATUS_SUCCESS, 1, $iFormatKey) ; Format already existed
$iFormatKey = $oFormats.addNew($sFormat, $tLocale)
If ($iFormatKey > -1) Then Return SetError($__LO_STATUS_SUCCESS, 0, $iFormatKey) ; Format created
Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0) ; Failed to create or retrieve Format
EndFunc ;==>_LOWriter_DateFormatKeyCreate
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DateFormatKeyDelete
; Description ...: Delete a User-Created Date/Time Format Key from a Document.
; Syntax ........: _LOWriter_DateFormatKeyDelete(ByRef $oDoc, $iFormatKey)
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; $iFormatKey - an integer value. The User-Created Date/Time format Key to delete.
; Return values .: Success: 1
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $iFormatKey not an Integer.
; @Error 1 @Extended 3 Return 0 = Format Key called in $iFormatKey not found in Document.
; @Error 1 @Extended 4 Return 0 = Format Key called in $iFormatKey not User-Created.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Failed to retrieve Number Formats Object.
; @Error 3 @Extended 2 Return 0 = Failed to delete the format key.
; --Success--
; @Error 0 @Extended 0 Return 1 = Success. Format Key was successfully deleted.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......: _LOWriter_DateFormatKeyCreate
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DateFormatKeyDelete(ByRef $oDoc, $iFormatKey)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $oFormats
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsInt($iFormatKey) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not _LOWriter_DateFormatKeyExists($oDoc, $iFormatKey) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0) ; Key not found.
$oFormats = $oDoc.getNumberFormats()
If Not IsObj($oFormats) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
If ($oFormats.getbykey($iFormatKey).UserDefined() = False) Then Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0) ; Key not User Created.
$oFormats.removeByKey($iFormatKey)
Return (_LOWriter_DateFormatKeyExists($oDoc, $iFormatKey) = False) ? (SetError($__LO_STATUS_SUCCESS, 0, 1)) : (SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0))
EndFunc ;==>_LOWriter_DateFormatKeyDelete
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DateFormatKeyExists
; Description ...: Check if a Document contains a Date/Time Format Key Already or not.
; Syntax ........: _LOWriter_DateFormatKeyExists(ByRef $oDoc, $iFormatKey)
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; $iFormatKey - an integer value. The Date Format Key to check for.
; Return values .: Success: Boolean
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $iFormatKey not an Integer.
; @Error 1 @Extended 3 Return 0 = $iFormatType Parameter for internal Function not an Integer. UDF needs fixed.
; --Initialization Errors--
; @Error 2 @Extended 1 Return 0 = Failed to Create "com.sun.star.lang.Locale" Object.
; @Error 2 @Extended 2 Return 0 = Failed to retrieve Number Formats Object.
; @Error 2 @Extended 3 Return 0 = Failed to obtain Array of Date/Time Formats.
; --Success--
; @Error 0 @Extended 0 Return True = Success. Date/Time Format already exists in document.
; @Error 0 @Extended 0 Return False = Success. Date/Time Format does not exist in document.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......: _LOWriter_DateFormatKeyCreate, _LOWriter_DateFormatKeyDelete
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DateFormatKeyExists(ByRef $oDoc, $iFormatKey)
Local $vReturn
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsInt($iFormatKey) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
$vReturn = _LOWriter_FormatKeyExists($oDoc, $iFormatKey, $LOW_FORMAT_KEYS_DATE_TIME)
Return SetError(@error, @extended, $vReturn)
EndFunc ;==>_LOWriter_DateFormatKeyExists
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DateFormatKeyGetString
; Description ...: Retrieve a Date/Time Format Key String.
; Syntax ........: _LOWriter_DateFormatKeyGetString(ByRef $oDoc, $iFormatKey)
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; $iFormatKey - an integer value. The Date/Time Format Key to retrieve the string for.
; Return values .: Success: String
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $iFormatKey not an Integer.
; @Error 1 @Extended 3 Return 0 = $iFormatKey not found in Document.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Failed to retrieve requested Format Key Object.
; --Success--
; @Error 0 @Extended 0 Return String = Success. Returning Format Key's Format String.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......: _LOWriter_DateFormatKeyList
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DateFormatKeyGetString(ByRef $oDoc, $iFormatKey)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $oFormatKey
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsInt($iFormatKey) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not _LOWriter_DateFormatKeyExists($oDoc, $iFormatKey) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
$oFormatKey = $oDoc.getNumberFormats().getByKey($iFormatKey)
If Not IsObj($oFormatKey) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0) ; Failed to retrieve Key
Return SetError($__LO_STATUS_SUCCESS, 0, $oFormatKey.FormatString())
EndFunc ;==>_LOWriter_DateFormatKeyGetString
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DateFormatKeyList
; Description ...: Retrieve an Array of Date/Time Format Keys.
; Syntax ........: _LOWriter_DateFormatKeyList(ByRef $oDoc[, $bIsUser = False[, $bUserOnly = False[, $bDateOnly = False[, $bTimeOnly = False]]]])
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; $bIsUser - [optional] a boolean value. Default is False. If True, Adds a third column to the return Array with a boolean, whether each Key is user-created or not.
; $bUserOnly - [optional] a boolean value. Default is False. If True, only user-created Date/Time Format Keys are returned.
; $bDateOnly - [optional] a boolean value. Default is False. If True, Only Date FormatKeys are returned.
; $bTimeOnly - [optional] a boolean value. Default is False. If True, Only Time Format Keys are returned.
; Return values .: Success: Array
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $bIsUser not a Boolean.
; @Error 1 @Extended 3 Return 0 = $bUserOnly not a Boolean.
; @Error 1 @Extended 4 Return 0 = $bDateOnly not a Boolean.
; @Error 1 @Extended 5 Return 0 = $bTimeOnly not a Boolean.
; @Error 1 @Extended 6 Return 0 = Both $bDateOnly and $bTimeOnly set to True. Set one or both to false.
; --Initialization Errors--
; @Error 2 @Extended 1 Return 0 = Failed to create "com.sun.star.lang.Locale" Object.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Failed to retrieve Number Formats Object.
; @Error 3 @Extended 2 Return 0 = Failed to obtain Array of Date/Time Formats.
; --Success--
; @Error 0 @Extended ? Return Array = Success. Returning a 2 or three column Array, depending on current $bIsUser setting. See remarks. @Extended is set to the number of Keys returned.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: Column One (Array[0][0]) will contain the Format Key integer,
; Column two (Array[0][1]) will contain the Format String
; And if $bIsUser is set to True, Column Three (Array[0][2]) will contain a Boolean, True if the Format Key is User created, else false.
; Related .......: _LOWriter_DateFormatKeyCreate, _LOWriter_DateFormatKeyDelete, _LOWriter_DateFormatKeyGetString
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DateFormatKeyList(ByRef $oDoc, $bIsUser = False, $bUserOnly = False, $bDateOnly = False, $bTimeOnly = False)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $oFormats
Local $aiFormatKeys
Local $avDTFormats[0][3]
Local $tLocale
Local $iColumns = 3, $iCount = 0, $iQueryType = $LOW_FORMAT_KEYS_DATE_TIME
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsBool($bIsUser) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not IsBool($bUserOnly) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
If Not IsBool($bDateOnly) Then Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0)
If Not IsBool($bTimeOnly) Then Return SetError($__LO_STATUS_INPUT_ERROR, 5, 0)
If ($bDateOnly = True) And ($bTimeOnly = True) Then Return SetError($__LO_STATUS_INPUT_ERROR, 6, 0)
$iColumns = ($bIsUser = True) ? ($iColumns) : (2)
$iQueryType = ($bDateOnly = True) ? ($LOW_FORMAT_KEYS_DATE) : ($iQueryType)
$iQueryType = ($bTimeOnly = True) ? ($LOW_FORMAT_KEYS_TIME) : ($iQueryType)
$tLocale = __LOWriter_CreateStruct("com.sun.star.lang.Locale")
If Not IsObj($tLocale) Then Return SetError($__LO_STATUS_INIT_ERROR, 1, 0)
$oFormats = $oDoc.getNumberFormats()
If Not IsObj($oFormats) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
$aiFormatKeys = $oFormats.queryKeys($iQueryType, $tLocale, False)
If Not IsArray($aiFormatKeys) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
ReDim $avDTFormats[UBound($aiFormatKeys)][$iColumns]
For $i = 0 To UBound($aiFormatKeys) - 1
If ($bUserOnly = True) Then
If ($oFormats.getbykey($aiFormatKeys[$i]).UserDefined() = True) Then
$avDTFormats[$iCount][0] = $aiFormatKeys[$i]
$avDTFormats[$iCount][1] = $oFormats.getbykey($aiFormatKeys[$i]).FormatString()
If ($bIsUser = True) Then $avDTFormats[$iCount][2] = $oFormats.getbykey($aiFormatKeys[$i]).UserDefined()
$iCount += 1
EndIf
Else
$avDTFormats[$i][0] = $aiFormatKeys[$i]
$avDTFormats[$i][1] = $oFormats.getbykey($aiFormatKeys[$i]).FormatString()
If ($bIsUser = True) Then $avDTFormats[$i][2] = $oFormats.getbykey($aiFormatKeys[$i]).UserDefined()
EndIf
Sleep((IsInt($i / $__LOWCONST_SLEEP_DIV)) ? (10) : (0))
Next
If ($bUserOnly = True) Then ReDim $avDTFormats[$iCount][$iColumns]
Return SetError($__LO_STATUS_SUCCESS, UBound($avDTFormats), $avDTFormats)
EndFunc ;==>_LOWriter_DateFormatKeyList
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DateStructCreate
; Description ...: Create a Date Structure for inserting a Date into certain other functions.
; Syntax ........: _LOWriter_DateStructCreate([$iYear = Null[, $iMonth = Null[, $iDay = Null[, $iHours = Null[, $iMinutes = Null[, $iSeconds = Null[, $iNanoSeconds = Null[, $bIsUTC = Null]]]]]]]])
; Parameters ....: $iYear - [optional] an integer value. Default is Null. The Year, in 4 digit integer format.
; $iMonth - [optional] an integer value (0-12). Default is Null. The Month, in 2 digit integer format. Set to 0 for Void date.
; $iDay - [optional] an integer value (0-31). Default is Null. The Day, in 2 digit integer format. Set to 0 for Void date.
; $iHours - [optional] an integer value (0-23). Default is Null. The Hour, in 2 digit integer format.
; $iMinutes - [optional] an integer value (0-59). Default is Null. Minutes, in 2 digit integer format.
; $iSeconds - [optional] an integer value (0-59). Default is Null. Seconds, in 2 digit integer format.
; $iNanoSeconds - [optional] an integer value (0-999,999,999). Default is Null. Nano-Second, in integer format. Min 0, Max 999,999,999.
; $bIsUTC - [optional] a boolean value. Default is Null. If true: time zone is UTC Else false: unknown time zone. Libre Office version 4.1 and up.
; Return values .: Success: Structure.
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $iYear not an Integer.
; @Error 1 @Extended 2 Return 0 = $iYear not 4 digits long.
; @Error 1 @Extended 3 Return 0 = $iMonth not an Integer, less than 0, or greater than 12.
; @Error 1 @Extended 4 Return 0 = $iDay not an Integer, less than 0, or greater than 31.
; @Error 1 @Extended 5 Return 0 = $iHours not an Integer, less than 0, or greater than 23.
; @Error 1 @Extended 6 Return 0 = $iMinutes not an Integer, less than 0, or greater than 59.
; @Error 1 @Extended 7 Return 0 = $iSeconds not an Integer, less than 0, or greater than 59.
; @Error 1 @Extended 8 Return 0 = $iNanoSeconds not an Integer, less than 0, or greater than 999999999.
; @Error 1 @Extended 9 Return 0 = $bIsUTC not a Boolean.
; --Initialization Errors--
; @Error 2 @Extended 1 Return 0 = Failed to create "com.sun.star.util.DateTime" Object.
; --Version Related Errors--
; @Error 7 @Extended 1 Return 0 = Current Libre Office version lower than 4.1.
; --Success--
; @Error 0 @Extended 0 Return Structure = Success. Successfully created the Date/Time Structure, Returning its Object.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......: _LOWriter_DateStructModify
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DateStructCreate($iYear = Null, $iMonth = Null, $iDay = Null, $iHours = Null, $iMinutes = Null, $iSeconds = Null, $iNanoSeconds = Null, $bIsUTC = Null)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $tDateStruct
$tDateStruct = __LOWriter_CreateStruct("com.sun.star.util.DateTime")
If Not IsObj($tDateStruct) Then Return SetError($__LO_STATUS_INIT_ERROR, 1, 0)
If ($iYear <> Null) Then
If Not IsInt($iYear) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not (StringLen($iYear) = 4) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
$tDateStruct.Year = $iYear
Else
$tDateStruct.Year = @YEAR
EndIf
If ($iMonth <> Null) Then
If Not __LOWriter_IntIsBetween($iMonth, 0, 12) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
$tDateStruct.Month = $iMonth
Else
$tDateStruct.Month = @MON
EndIf
If ($iDay <> Null) Then
If Not __LOWriter_IntIsBetween($iDay, 0, 31) Then Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0)
$tDateStruct.Day = $iDay
Else
$tDateStruct.Day = @MDAY
EndIf
If ($iHours <> Null) Then
If Not __LOWriter_IntIsBetween($iHours, 0, 23) Then Return SetError($__LO_STATUS_INPUT_ERROR, 5, 0)
$tDateStruct.Hours = $iHours
Else
$tDateStruct.Hours = @HOUR
EndIf
If ($iMinutes <> Null) Then
If Not __LOWriter_IntIsBetween($iMinutes, 0, 59) Then Return SetError($__LO_STATUS_INPUT_ERROR, 6, 0)
$tDateStruct.Minutes = $iMinutes
Else
$tDateStruct.Minutes = @MIN
EndIf
If ($iSeconds <> Null) Then
If Not __LOWriter_IntIsBetween($iSeconds, 0, 59) Then Return SetError($__LO_STATUS_INPUT_ERROR, 7, 0)
$tDateStruct.Seconds = $iSeconds
Else
$tDateStruct.Seconds = @SEC
EndIf
If ($iNanoSeconds <> Null) Then
If Not __LOWriter_IntIsBetween($iNanoSeconds, 0, 999999999) Then Return SetError($__LO_STATUS_INPUT_ERROR, 8, 0)
$tDateStruct.NanoSeconds = $iNanoSeconds
Else
$tDateStruct.NanoSeconds = 0
EndIf
If ($bIsUTC <> Null) Then
If Not IsBool($bIsUTC) Then Return SetError($__LO_STATUS_INPUT_ERROR, 9, 0)
If Not __LOWriter_VersionCheck(4.1) Then Return SetError($__LO_STATUS_VER_ERROR, 1, 0)
$tDateStruct.IsUTC = $bIsUTC
Else
If __LOWriter_VersionCheck(4.1) Then $tDateStruct.IsUTC = False
EndIf
Return SetError($__LO_STATUS_SUCCESS, 0, $tDateStruct)
EndFunc ;==>_LOWriter_DateStructCreate
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DateStructModify
; Description ...: Set or retrieve Date Structure settings.
; Syntax ........: _LOWriter_DateStructModify(ByRef $tDateStruct[, $iYear = Null[, $iMonth = Null[, $iDay = Null[, $iHours = Null[, $iMinutes = Null[, $iSeconds = Null[, $iNanoSeconds = Null[, $bIsUTC = Null]]]]]]]])
; Parameters ....: $tDateStruct - [in/out] a dll struct value. The Date Structure to modify, returned from a _LOWriter_DateStructCreate, or setting retrieval function. Structure will be directly modified.
; $iYear - [optional] an integer value. Default is Null. The Year, in 4 digit integer format.
; $iMonth - [optional] an integer value (0-12). Default is Null. The Month, in 2 digit integer format. Set to 0 for Void date.
; $iDay - [optional] an integer value (0-31). Default is Null. The Day, in 2 digit integer format. Set to 0 for Void date.
; $iHours - [optional] an integer value (0-23). Default is Null. The Hour, in 2 digit integer format.
; $iMinutes - [optional] an integer value (0-59). Default is Null. Minutes, in 2 digit integer format.
; $iSeconds - [optional] an integer value (0-59). Default is Null. Seconds, in 2 digit integer format.
; $iNanoSeconds - [optional] an integer value (0-999,999,999). Default is Null. Nano-Second, in integer format.
; $bIsUTC - [optional] a boolean value. Default is Null. If true: time zone is UTC Else false: unknown time zone. Libre Office version 4.1 and up.
; Return values .: Success: 1 or Array
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $tDateStruct not an Object.
; @Error 1 @Extended 2 Return 0 = $iYear not an Integer.
; @Error 1 @Extended 3 Return 0 = $iYear not 4 digits long.
; @Error 1 @Extended 4 Return 0 = $iMonth not an Integer, less than 0, or greater than 12.
; @Error 1 @Extended 5 Return 0 = $iDay not an Integer, less than 0, or greater than 31.
; @Error 1 @Extended 6 Return 0 = $iHours not an Integer, less than 0, or greater than 23.
; @Error 1 @Extended 7 Return 0 = $iMinutes not an Integer, less than 0, or greater than 59.
; @Error 1 @Extended 8 Return 0 = $iSeconds not an Integer, less than 0, or greater than 59.
; @Error 1 @Extended 9 Return 0 = $iNanoSeconds not an Integer, less than 0, or greater than 999999999.
; @Error 1 @Extended 10 Return 0 = $bIsUTC not a Boolean.
; --Property Setting Errors--
; @Error 4 @Extended ? Return 0 = Some settings were not successfully set. Use BitAND to test @Extended for the following values:
; | 1 = Error setting $iYear
; | 2 = Error setting $iMonth
; | 4 = Error setting $iDay
; | 8 = Error setting $iHours
; | 16 = Error setting $iMinutes
; | 32 = Error setting $iSeconds
; | 64 = Error setting $iNanoSeconds
; | 128 = Error setting $bIsUTC
; --Version Related Errors--
; @Error 7 @Extended 1 Return 0 = Current Libre Office version lower than 4.1.
; --Success--
; @Error 0 @Extended 0 Return 1 = Success. Settings were successfully set.
; @Error 0 @Extended 1 Return Array = Success. All optional parameters were set to Null, returning current settings in a 7 or 8 Element Array with values in order of function parameters. If current Libre Office version is less than 4.1, the Array will contain 7 elements, as $bIsUTC will be eliminated.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: Call this function with only the required parameters (or with all other parameters set to Null keyword), to get the current settings.
; Call any optional parameter with Null keyword to skip it.
; Related .......: _LOWriter_DateStructCreate
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DateStructModify(ByRef $tDateStruct, $iYear = Null, $iMonth = Null, $iDay = Null, $iHours = Null, $iMinutes = Null, $iSeconds = Null, $iNanoSeconds = Null, $bIsUTC = Null)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $iError = 0
Local $avMod[7]
If Not IsObj($tDateStruct) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If __LOWriter_VarsAreNull($iYear, $iMonth, $iDay, $iHours, $iMinutes, $iSeconds, $iNanoSeconds, $bIsUTC) Then
If __LOWriter_VersionCheck(4.1) Then
__LOWriter_ArrayFill($avMod, $tDateStruct.Year(), $tDateStruct.Month(), $tDateStruct.Day(), $tDateStruct.Hours(), _
$tDateStruct.Minutes(), $tDateStruct.Seconds(), $tDateStruct.NanoSeconds(), $tDateStruct.IsUTC())
Else
__LOWriter_ArrayFill($avMod, $tDateStruct.Year(), $tDateStruct.Month(), $tDateStruct.Day(), $tDateStruct.Hours(), _
$tDateStruct.Minutes(), $tDateStruct.Seconds(), $tDateStruct.NanoSeconds())
EndIf
Return SetError($__LO_STATUS_SUCCESS, 1, $avMod)
EndIf
If ($iYear <> Null) Then
If Not IsInt($iYear) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not (StringLen($iYear) = 4) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
$tDateStruct.Year = $iYear
$iError = ($tDateStruct.Year() = $iYear) ? ($iError) : (BitOR($iError, 1))
EndIf
If ($iMonth <> Null) Then
If Not __LOWriter_IntIsBetween($iMonth, 0, 12) Then Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0)