forked from philpw99/Stash_Helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUIListViewEx.au3
5953 lines (5268 loc) · 222 KB
/
GUIListViewEx.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
#include-once
; #INDEX# ============================================================================================================
; Title .........: GUIListViewEx
; AutoIt Version : 3.3.10 +
; Language ......: English
; Description ...: Permits insertion, deletion, moving, dragging, sorting, editing and colouring of items within ListViews
; Remarks .......: - It is important to use _GUIListViewEx_Close when a enabled ListView is deleted to free the memory used
; by the $aGLVEx_Data array which shadows the ListView contents.
; - _GUIListViewEx_EventMonitor must be placed in the script idel loop if editing or using colour
; - Windows message handlers required:
; - WM_NOTIFY: All UDF functions
; - WM_MOUSEMOVE and WM_LBUTTONUP: Only needed if dragging
; - WM_SYSCOMMAND: Permits immediate [X] GUI closure while editing
; - If the script already has WM_NOTIFY, WM_MOUSEMOVE, WM_LBUTTONUP or WM_SYSCOMMAND handlers then only set
; unregistered messages in _GUIListViewEx_MsgRegister and call the relevant _GUIListViewEx_WM_#####_Handler
; from within the existing handler
; - Uses 2 undocumented functions within GUIListView UDF to set and colour insert mark (thanks rover)
; - Enabling user colours significantly slows ListView redrawing
; Author ........: Melba23
; Credits .......: martin (basic drag code), Array.au3 authors (array functions), KaFu and ProgAndy (font function)
; LarsJ (colouring code)
; ====================================================================================================================
;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
; #INCLUDES# =========================================================================================================
#include <GuiListView.au3>
#include <GUIImageList.au3>
#include <WinAPISys.au3>
; #GLOBAL VARIABLES# =================================================================================================
; Array to hold registered ListView data
Global $aGLVEx_Data[1][27] = [[0, 0, -1, "", -1, -1, -1, -1, _WinAPI_GetSystemMetrics(2), False, _
-1, -1, False, "", 0, True, 0, -1, -1, 0, 0, 0, 0, "08"]]
; [0][0] = ListView Count [n][0] = ListView handle
; [0][1] = Active Index [n][1] = Native ListView ControlID / 0
; [0][2] = Active Column [n][2] = Shadow array
; [0][3] = Row Depth [n][3] = Shadow array count element (0/1) & 2D return (+ 2)
; [0][4] = Curr ToolTip Row [n][4] = Sort status
; [0][5] = Curr ToolTip Col [n][5] = Drag image flag
; [0][6] = Prev ToolTip Row [n][6] = Checkbox array flag
; [0][7] = Prev ToolTip Col [n][7] = Editable columns data
; [0][8] = VScrollbar width [n][8] = Editable header flag
; [0][9] = SysClose flag [n][9] = Continue edit on click flag
; [0][10] = RtClick Row [n][10] = Item depth for scrolling
; [0][11] = RtClick Col [n][11] = Do not "select all" on edit flag
; [0][12] = Colour Handler Flag [n][12] = Drag/drop status flag
; [0][13] = Active Colour Array [n][13] = Header drag style flag
; [0][14] = Curr Redraw Handle [n][14] = Edit width array
; [0][15] = Allow Redraw Flag [n][15] = ToolTip column range
; [0][16] = KeyCode [n][16] = ToolTip display time
; [0][17] = Active Row [n][17] = ToolTip mode
; [0][18] = Active Column [n][18] = Colour array
; [0][19] = Sort Flag [n][19] - Colour flag
; [0][20] = Curr header handle [n][20] - Active row
; [0][21] = Curr header font [n][21] - Active column
; [0][22] = Colour redraw flag [n][22] - Single cell flag
; [0][23] = Start edit keycode [n][23] - Default user colours
; [0][24] = Separator char [n][24] - Header colour flag (handle)
; [n][25] - Header data array
; [n][26] - Edit field colour
; Variables for UDF handlers
Global $hGLVEx_SrcHandle, $cGLVEx_SrcID, $iGLVEx_SrcIndex, $aGLVEx_SrcArray, $aGLVEx_SrcColArray
Global $hGLVEx_TgtHandle, $cGLVEx_TgtID, $iGLVEx_TgtIndex, $aGLVEx_TgtArray, $aGLVEx_TgtColArray
Global $iGLVEx_Dragging = 0, $iGLVEx_DraggedIndex, $hGLVEx_DraggedImage = 0, $sGLVEx_DragEvent
Global $iGLVEx_InsertIndex = -1, $iGLVEx_LastY, $fGLVEx_BarUnder, $fGVLEx_Resized = -1
; Variables for UDF edit
Global $hGLVEx_Editing, $cGLVEx_EditID = 9999, $fGLVEx_EditClickFlag = 0, $fGLVEx_HeaderEdit = False
; Flags for user selection indication
Global $fGLVEx_SelChangeFlag = 0, $fGLVEx_UserSelFlag = 0
; Predefined user colours [Normal text, normal field, selected cell text, selected cell field] - BGR
Global $aGLVEx_DefColours[4] = ["0x000000", "0xFEFEFE", "0xFFFFFF", "0xCC6600"]
; #CURRENT# ==========================================================================================================
; _GUIListViewEx_Init: Enables UDF functions for the ListView and sets various flags
; _GUIListViewEx_Close: Disables all UDF functions for the specified ListView and clears all memory used
; _GUIListViewEx_SetActive: Set specified ListView as active for non-specific UDF functions
; _GUIListViewEx_GetActive: Get index number of active ListView for non-specific UDF functions
; _GUIListViewEx_ReadToArray: Creates an array from the current ListView content to be loaded in _Init function
; _GUIListViewEx_ReturnArray: Returns an array of the current content, checkbox state, colour of the ListView
; _GUIListViewEx_SaveListView: Saves ListView header data, ListView content, checkbox state and colour data to file
; _GUIListViewEx_LoadListView: Loads ListView header data, ListView content, checkbox state and colour data from file
; _GUIListViewEx_Up: Moves selected row(s) in active ListView up 1 row
; _GUIListViewEx_Down: Moves selected row(s) in active ListView down 1 row
; _GUIListViewEx_Insert: Inserts data in row below selected row in active ListView
; _GUIListViewEx_InsertSpec: Inserts data in specified row in specified ListView
; _GUIListViewEx_Delete: Deletes selected row(s) in active ListView
; _GUIListViewEx_DeleteSpec: Deletes specified row(s) in specified ListView
; _GUIListViewEx_InsertCol: Inserts blank column to right of selected column in active ListView
; _GUIListViewEx_InsertColSpec: Inserts specified blank column in specified ListView
; _GUIListViewEx_DeleteCol: Deletes selected column in active ListView
; _GUIListViewEx_DeleteColSpec: Deletes specified column in specified ListView
; _GUIListViewEx_SortCol: Sort specified column in specified ListView
; _GUIListViewEx_SetEditStatus: Sets edit on doubleclick mode for specified column(s)
; _GUIListViewEx_SetEditKey: Sets key(s) required to begin edit of selected item
; _GUIListViewEx_EditItem: Manual edit of specified ListView item
; _GUIListViewEx_EditWidth: Set required widths for column edit/combo when editing
; _GUIListViewEx_ChangeItem: Programatic change of specified ListView item
; _GUIListViewEx_LoadHdrData: Sets header title, text and back colour (if enabled), and sets edit mode (if enabled)
; _GUIListViewEx_EditHeader: Manual edit of specified ListView header
; _GUIListViewEx_LoadColour: Uses array to set text/back colours for user colour enabled ListViews
; _GUIListViewEx_SetDefColours: Sets default colours for user colour/single cell select enabled ListViews
; _GUIListViewEx_SetColour: Sets text and/or back colour for user colour enabled ListViews
; _GUIListViewEx_BlockReDraw: Prevents ListView redrawing during looped Insert/Delete/Change calls
; _GUIListViewEx_UserSort: Sets user defined function to sort specified columns
; _GUIListViewEx_SelectItem: Programatically select row - and item if single selection available - in active ListView
; _GUIListViewEx_GetLastSelItem: Get last selected item in active or specified ListView
; _GUIListViewEx_ContextPos: Returns LV index and row/col of last right click
; _GUIListViewEx_ToolTipInit: Defines column(s) which will display a tooltip when clicked
; _GUIListViewEx_EventMonitor: Check for edit, sort, drag/drop and tooltip events - auto colour redraw - returns event results
; _GUIListViewEx_MsgRegister: Registers Windows messages required for the UDF
; _GUIListViewEx_WM_NOTIFY_Handler: Windows message handler for WM_NOTIFY - needed for all UDF functions
; _GUIListViewEx_WM_MOUSEMOVE_Handler: Windows message handler for WM_MOUSEMOVE - needed for drag
; _GUIListViewEx_WM_LBUTTONUP_Handler: Windows message handler for WM_LBUTTONUP - needed for drag
; _GUIListViewEx_WM_SYSCOMMAND_Handler: Windows message handler for WM_SYSCOMMAND - speeds GUI closure when editing
; ====================================================================================================================
; #INTERNAL_USE_ONLY#=================================================================================================
; __GUIListViewEx_ExpandRange: Expands ranges into an array of values
; __GUIListViewEx_HighLight: Highlights specified ListView item and ensures it is visible
; __GUIListViewEx_GetLVFont: Gets font details for ListView to be edited
; __GUIListViewEx_EditProcess: Runs ListView editing process
; __GUIListViewEx_EditCoords: Ensures item in view then locates and sizes edit control
; __GUIListViewEx_ReWriteLV: Deletes all ListView content and refills to match array
; __GUIListViewEx_GetLVCoords: Gets screen coords for ListView
; __GUIListViewEx_GetCursorWnd: Gets handle of control under the mouse cursor
; __GUIListViewEx_Array_Add: Adds a specified value at the end of an array
; __GUIListViewEx_Array_Insert: Adds a value at the specified index of an array
; __GUIListViewEx_Array_Delete: Deletes a specified index from an array
; __GUIListViewEx_Array_Swap: Swaps specified elements within an array
; __GUIListViewEx_ToolTipHide: Called by Adlib to hide tooltip displayed by _GUIListViewEx_ToolTipShow
; __GUIListViewEx_MakeString: Convert data/check/colour arrays to strings for saving
; __GUIListViewEx_MakeArray: Convert data/check/colour strings to arrays for loading
; __GUIListViewEx_ColSort: Sort columns even if colour enabled
; __GUIListViewEx_RedrawWindow: Redraw ListView after update
; __GUIListViewEx_CheckUserEditKey: Check keys pressed in ListView
; ====================================================================================================================
; #FUNCTION# =========================================================================================================
; Name...........: _GUIListViewEx_Init
; Description ...: Enables UDF functions for the ListView and sets various flags
; Syntax.........: _GUIListViewEx_Init($hLV, [$aArray = ""[, $iStart = 0[, $iColour[, $fImage[, $iAdded]]]]])
; Parameters ....: $hLV - Handle or ControlID of ListView
; $aArray - Name of array used to fill ListView. "" for empty ListView
; $iStart - 0 = ListView data starts in [0] element of array (default)
; 1 = Count in [0] element
; $iColour - RGB colour for insert mark (default = black)
; $fImage - True = Shadow image of dragged item when dragging
; False = No shadow image (default)
; $iAdded - 0 - No added features (default). To get added features add any of the following values
; + 1 - Sortable by clicking on column headers
; + 2 - Do not "select all" when editing item text
; + 4 - Continue edit within same ListView by triple mouse-click on editable column
; + 8 - Headers editable by Ctrl-click (only if column editable)
; + 16 - User coloured header
; + 32 - User coloured items
; + 64 - No external drag
; + 128 - No external drop
; + 256 - No delete on external drag/drop
; + 512 - No internal drag/drop
; + 1024 - Single cell highlight (forces single row selection)
; Requirement(s).: v3.3.10 +
; Return values .: Index number of ListView for use in other GUIListViewEx functions
; Author ........: Melba23
; Modified ......:
; Remarks .......: - If the ListView is the only one enabled, it is automatically set as active
; - If no array is passed a shadow array is created automatically
; - The $iStart parameter determines if a count element will be returned by other GUIListViewEx functions
; - The _GUIListViewEx_ReadToArray function will read an existing ListView into an array
; - Only first item of a multiple selection is shadow imaged when dragging (API limitation)
; - Use the _GUIListViewEx_SetEditStatus function to make columns editable
; Example........: Yes
;=====================================================================================================================
Func _GUIListViewEx_Init($hLV, $aArray = "", $iStart = 0, $iColour = 0, $fImage = False, $iAdded = 0)
Local $iLV_Index = 0
; See if there is a blank line available in the array
For $i = 1 To $aGLVEx_Data[0][0]
If $aGLVEx_Data[$i][0] = 0 Then
$iLV_Index = $i
ExitLoop
EndIf
Next
; If no blank line found then increase array size
If $iLV_Index = 0 Then
$aGLVEx_Data[0][0] += 1
ReDim $aGLVEx_Data[$aGLVEx_Data[0][0] + 1][UBound($aGLVEx_Data, 2)]
$iLV_Index = $aGLVEx_Data[0][0]
EndIf
; Store ListView handle and ControlID (if it exists)
If IsHWnd($hLV) Then
$aGLVEx_Data[$iLV_Index][0] = $hLV
$aGLVEx_Data[$iLV_Index][1] = 0
Else
$aGLVEx_Data[$iLV_Index][0] = GUICtrlGetHandle($hLV)
$aGLVEx_Data[$iLV_Index][1] = $hLV
EndIf
; Store separator char
$aGLVEx_Data[0][24] = Opt("GUIDataSeparatorChar")
; Store ListView content in shadow array
$aGLVEx_Data[$iLV_Index][2] = _GUIListViewEx_ReadToArray($hLV, 1)
;Set no selected row or column
$aGLVEx_Data[$iLV_Index][20] = -1
$aGLVEx_Data[$iLV_Index][21] = -1
; Store array count flag
$aGLVEx_Data[$iLV_Index][3] = $iStart
; Store 1D/2D array return type flag
If IsArray($aArray) Then
If UBound($aArray, 0) = 2 Then $aGLVEx_Data[$iLV_Index][3] += 2
EndIf
; Create and store editable array
Local $aEditable[4][UBound($aGLVEx_Data[$iLV_Index][2], 2)]
$aGLVEx_Data[$iLV_Index][7] = $aEditable
; Set insert mark colour after conversion to BGR
_GUICtrlListView_SetInsertMarkColor($hLV, BitOR(BitShift(BitAND($iColour, 0x000000FF), -16), BitAND($iColour, 0x0000FF00), BitShift(BitAND($iColour, 0x00FF0000), 16)))
; If drag image required
If $fImage Then
$aGLVEx_Data[$iLV_Index][5] = 1
EndIf
; If sortable, store sort array
If BitAND($iAdded, 1) Then
Local $aLVSortState[_GUICtrlListView_GetColumnCount($hLV)]
$aGLVEx_Data[$iLV_Index][4] = $aLVSortState
Else
$aGLVEx_Data[$iLV_Index][4] = 0
EndIf
; If do not "select all" on opening edit
If BitAND($iAdded, 2) Then
; Set flag
$aGLVEx_Data[$iLV_Index][11] = 1
EndIf
; If continue edit on click
If BitAND($iAdded, 4) Then
; Set flag
$aGLVEx_Data[$iLV_Index][9] = 1
EndIf
; If header editable on Ctrl-click set flag
If BitAND($iAdded, 8) Then
$aGLVEx_Data[$iLV_Index][8] = 1
EndIf
; Create default header data array
Local $iCols = _GUICtrlListView_GetColumnCount($hLV)
Local $aHdrData[4][$iCols], $aRet
; If user coloured headers
If BitAND($iAdded, 16) Then
; Get header handle to act as flag
Local $hHeader = _GUICtrlListView_GetHeader($hLV)
$aGLVEx_Data[$iLV_Index][24] = $hHeader
; Read in current header titles
For $i = 0 To $iCols - 1
$aRet = _GUICtrlListView_GetColumn($hLV, $i)
$aHdrData[0][$i] = $aRet[5]
Next
EndIf
; Store array
$aGLVEx_Data[$iLV_Index][25] = $aHdrData
; Load default colours
$aGLVEx_Data[$iLV_Index][23] = $aGLVEx_DefColours
$aGLVEx_Data[$iLV_Index][26] = $aGLVEx_DefColours[1]
; If user coloured items
If BitAND($iAdded, 32) Then
Local $aColArray = $aGLVEx_Data[$iLV_Index][2]
For $i = 1 To UBound($aColArray, 1) - 1
For $j = 0 To UBound($aColArray, 2) - 1
$aColArray[$i][$j] = ";"
Next
Next
$aGLVEx_Data[$iLV_Index][18] = $aColArray
; Set user colour flag
$aGLVEx_Data[$iLV_Index][19] = 1
EndIf
; If no external drag
If BitAND($iAdded, 64) Then
$aGLVEx_Data[$iLV_Index][12] = 1
EndIf
; If no external drop
If BitAND($iAdded, 128) Then
$aGLVEx_Data[$iLV_Index][12] += 2
EndIf
; If no delete on external drag/drop
If BitAND($iAdded, 256) Then
$aGLVEx_Data[$iLV_Index][12] += 4
EndIf
; If no internal drag/drop
If BitAND($iAdded, 512) Then
$aGLVEx_Data[$iLV_Index][12] += 8
EndIf
; Set flag for no drag/drop at all
If BitAND($aGLVEx_Data[$iLV_Index][12], 8) And BitAND($aGLVEx_Data[$iLV_Index][12], 2) And BitAND($aGLVEx_Data[$iLV_Index][12], 1) Then
$aGLVEx_Data[$iLV_Index][12] += 16
EndIf
; If single cell selection
If BitAND($iAdded, 1024) Then
; Force single selection style
Local $iStyle = _WinAPI_GetWindowLong($aGLVEx_Data[$iLV_Index][0], $GWL_STYLE)
_WinAPI_SetWindowLong($aGLVEx_Data[$iLV_Index][0], $GWL_STYLE, BitOR($iStyle, $LVS_SINGLESEL))
; Set flag
$aGLVEx_Data[$iLV_Index][22] = 1
; Load default colours
$aGLVEx_Data[$iLV_Index][23] = $aGLVEx_DefColours
EndIf
; If checkbox extended style
If BitAND(_GUICtrlListView_GetExtendedListViewStyle($hLV), 4) Then ; $LVS_EX_CHECKBOXES
$aGLVEx_Data[$iLV_Index][6] = 1
EndIf
; If header drag extended style
If BitAND(_GUICtrlListView_GetExtendedListViewStyle($hLV), 0x00000010) Then ; $LVS_EX_HEADERDRAGDROP
$aGLVEx_Data[$iLV_Index][13] = 1
EndIf
; Measure item depth for scroll - if empty reset when filled later
Local $aRect = _GUICtrlListView_GetItemRect($aGLVEx_Data[$iLV_Index][0], 0)
$aGLVEx_Data[$iLV_Index][10] = $aRect[3] - $aRect[1]
; If only 1 current ListView then activate
Local $iListView_Count = 0
For $i = 1 To $iLV_Index
If $aGLVEx_Data[$i][0] Then $iListView_Count += 1
Next
If $iListView_Count = 1 Then _GUIListViewEx_SetActive($iLV_Index)
; Return ListView index
Return $iLV_Index
EndFunc ;==>_GUIListViewEx_Init
; #FUNCTION# =========================================================================================================
; Name...........: _GUIListViewEx_Close
; Description ...: Disables all UDF functions for the specified ListView and clears all memory used
; Syntax.........: _GUIListViewEx_Close($iLV_Index)
; Parameters ....: $iLV_Index - Index number of ListView to close as returned by _GUIListViewEx_Init
; 0 (default) = Closes all ListViews
; Requirement(s).: v3.3.10 +
; Return values .: Success: 1
; Failure: 0 and @error set to 1 - Invalid index number
; Author ........: Melba23
; Modified ......:
; Remarks .......:
; Example........: Yes
;=====================================================================================================================
Func _GUIListViewEx_Close($iLV_Index = 0)
Local $iEditKeyCode
; Check valid index
If $iLV_Index < 1 Or $iLV_Index > $aGLVEx_Data[0][0] Then Return SetError(1, 0, 0)
If $iLV_Index = 0 Then
; Reinitialise data array - retaining selected edit key
$iEditKeyCode = $aGLVEx_Data[0][23]
Global $aGLVEx_Data[1][UBound($aGLVEx_Data, 2)] = [[0, 0, -1, "", -1, -1, -1, -1, _WinAPI_GetSystemMetrics(2), False, _
-1, -1, False, "", 0, True, 0, -1, -1, 0, 0, 0, 0, $iEditKeyCode]]
; Note delimiter character reset when ListView next initialised
Else
; Reset all data for ListView
For $i = 0 To UBound($aGLVEx_Data, 2) - 1
$aGLVEx_Data[$iLV_Index][$i] = 0
Next
; Cancel active index if set to this ListView
If $aGLVEx_Data[0][1] = $iLV_Index Then
$aGLVEx_Data[0][1] = 0
EndIf
EndIf
Return 1
EndFunc ;==>_GUIListViewEx_Close
; #FUNCTION# =========================================================================================================
; Name...........: _GUIListViewEx_SetActive
; Description ...: Set specified ListView as active for non-specific UDF functions
; Syntax.........: _GUIListViewEx_SetActive($iLV_Index)
; Parameters ....: $iLV_Index - Index number of ListView as returned by _GUIListViewEx_Init
; An index of 0 clears any current setting
; Requirement(s).: v3.3.10 +
; Return values .: Success: Returns previous active index number, 0 = no previously active ListView
; Failure: -1 and @error set to 1 - Invalid index number
; Author ........: Melba23
; Modified ......:
; Remarks .......: ListViews can also be activated by clicking on them
; Example........: Yes
;=====================================================================================================================
Func _GUIListViewEx_SetActive($iLV_Index)
; Check valid index
If $iLV_Index < 0 Or $iLV_Index > $aGLVEx_Data[0][0] Then Return SetError(1, 0, -1)
Local $iCurr_Index = $aGLVEx_Data[0][1]
If $iLV_Index Then
; Store index of specified ListView
$aGLVEx_Data[0][1] = $iLV_Index
; Set values for specified ListView
$hGLVEx_SrcHandle = $aGLVEx_Data[$iLV_Index][0]
$cGLVEx_SrcID = $aGLVEx_Data[$iLV_Index][1]
Else
; Clear active index
$aGLVEx_Data[0][1] = 0
$hGLVEx_SrcHandle = 0
$cGLVEx_SrcID = 0
EndIf
Return $iCurr_Index
EndFunc ;==>_GUIListViewEx_SetActive
; #FUNCTION# =========================================================================================================
; Name...........: _GUIListViewEx_GetActive
; Description ...: Get index number of ListView active for non-specific UDF functions
; Syntax.........: _GUIListViewEx_GetActive()
; Parameters ....: None
; Requirement(s).: v3.3.10 +
; Return values .: Success: Index number as returned by _GUIListViewEx_Init, 0 = no active ListView
; Author ........: Melba23
; Modified ......:
; Remarks .......:
; Example........: Yes
;=====================================================================================================================
Func _GUIListViewEx_GetActive()
Return $aGLVEx_Data[0][1]
EndFunc ;==>_GUIListViewEx_GetActive
; #FUNCTION# =========================================================================================================
; Name...........: _GUIListViewEx_ReadToArray
; Description ...: Creates an array from the current ListView content to be loaded in _Init function
; Syntax.........: _GUIListViewEx_ReadToArray($hLV[, $iCount = 0])
; Parameters ....: $hLV - ControlID or handle of ListView
; $iCount - 0 (default) = ListView data starts in [0] element of array, 1 = Count in [0] element
; Requirement(s).: v3.3.10 +
; Return values .: Success: 2D array of current ListView content
; If ListView empty then [0] count element or an empty array
; Failure: Returns null string and sets @error as follows:
; 1 = Invalid ListView ControlID or handle
; Author ........: Melba23
; Modified ......:
; Remarks .......: - Note that this function requires the handle/ControlID of the ListView, not the UDF index
; - If returned array is used in _GUIListViewEx_Init the $iStart parameters must match in the 2 functions
; Example........: Yes
;=====================================================================================================================
Func _GUIListViewEx_ReadToArray($hLV, $iStart = 0)
Local $aLVArray = "", $aRow
; Use the ListView handle
If Not IsHWnd($hLV) Then
$hLV = GUICtrlGetHandle($hLV)
If Not IsHWnd($hLV) Then
Return SetError(1, 0, "")
EndIf
EndIf
; Get ListView row count
Local $iRows = _GUICtrlListView_GetItemCount($hLV)
; Get ListView column count
Local $iCols = _GUICtrlListView_GetColumnCount($hLV)
; Check for empty ListView with no count
If ($iRows + $iStart <> 0) And $iCols <> 0 Then
; Create 2D array to hold ListView content and add count - count overwritten if not needed
Local $aLVArray[$iRows + $iStart][$iCols] = [[$iRows]]
; Read ListView content into array
For $i = 0 To $iRows - 1
; Read the row content
$aRow = _GUICtrlListView_GetItemTextArray($hLV, $i)
For $j = 1 To $aRow[0]
; Add to the ListView content array
$aLVArray[$i + $iStart][$j - 1] = $aRow[$j]
Next
Next
Else
; Empty ListView
Local $aLVArray[1][1]
; Set count if required
If $iStart = 1 Then $aLVArray[0][0] = 0
EndIf
; Return array
Return $aLVArray
EndFunc ;==>_GUIListViewEx_ReadToArray
; #FUNCTION# =========================================================================================================
; Name...........: _GUIListViewEx_ReturnArray
; Description ...: Returns an array reflecting the current content of an activated ListView
; Syntax.........: _GUIListViewEx_ReturnArray($iLV_Index[, $iMode])
; Parameters ....: $iLV_Index - Index number of ListView as returned by _GUIListViewEx_Init
; $iMode - 0 = Content of ListView
; 1 - State of the checkboxes
; 2 - User colours (if initialised)
; 3 - Content of ListView forced to 2D for saving
; 4 - ListView header titles
; 5 - Header colours (if initialised)
; Requirement(s).: v3.3.10 +
; Return values .: Success: Array of current ListView content - _GUIListViewEx_Init parameters determine:
; For modes 0/1:
; Count in [0]/[0][0] element if $iStart = 1 when intialised
; 1D/2D array type - as array used to initialise
; If no array passed then single col => 1D; multiple column => 2D
; For mode 2/3
; Always 0-based 2D array
; For mode 4/5
; Always 0-based 1D array
; Failure: Returns empty string and sets @error as follows:
; 1 = Invalid index number
; 2 = Empty array (no items in ListView)
; 3 = $iMode set to 1 but no checkbox style
; 4 = $iMode set to 2 but user colours not initialised
; 5 = $iMode set to 5 but header colours not initialised
; 6 = Invalid $iMode
; Author ........: Melba23
; Modified ......:
; Remarks .......: Colours returned as "text;back" - empty values use default colours
; Example........: Yes
;=====================================================================================================================
Func _GUIListViewEx_ReturnArray($iLV_Index, $iMode = 0)
; Check valid index
If $iLV_Index < 1 Or $iLV_Index > $aGLVEx_Data[0][0] Then Return SetError(1, 0, "")
; Get ListView handle
Local $hLV = $aGLVEx_Data[$iLV_Index][0]
; Get column order
Local $sOrder = _GUICtrlListView_GetColumnOrder($hLV)
Local $aColOrder[1]
If $sOrder = "" Then
$aColOrder[0] = 0
Else
$aColOrder = StringSplit($sOrder, $aGLVEx_Data[0][24])
EndIf
; Extract array and get size
Local $aData_Colour = $aGLVEx_Data[$iLV_Index][2]
; Check for empty array
If $aColOrder[0] = 0 Then
$aData_Colour = ""
Return SetError(2, 0, "")
EndIf
Local $iDim_1 = UBound($aData_Colour, 1), $iDim_2 = UBound($aData_Colour, 2)
Local $aCheck[$iDim_1], $aHeader[$iDim_2], $aHdrData
; Adjust array depending on mode required
Switch $iMode
Case 0, 3 ; Content
; Array already filled
Case 1 ; Checkbox state
If $aGLVEx_Data[$iLV_Index][6] Then
For $i = 1 To $iDim_1 - 1
$aCheck[$i] = _GUICtrlListView_GetItemChecked($hLV, $i - 1)
Next
; Remove count element if required
If BitAND($aGLVEx_Data[$iLV_Index][3], 1) = 0 Then
; Delete count element
__GUIListViewEx_Array_Delete($aCheck, 0, True)
EndIf
Return $aCheck
Else
Return SetError(3, 0, "")
EndIf
Case 2 ; Colour values
If $aGLVEx_Data[$iLV_Index][19] Then
; Load colour array
$aData_Colour = $aGLVEx_Data[$iLV_Index][18]
; Convert to RGB
For $i = 0 To UBound($aData_Colour, 1) - 1
For $j = 0 To UBound($aData_Colour, 2) - 1
$aData_Colour[$i][$j] = StringRegExpReplace($aData_Colour[$i][$j], "0x(.{2})(.{2})(.{2})", "0x$3$2$1")
Next
Next
$aData_Colour[0][0] = $iDim_1 - 1
Else
Return SetError(4, 0, "")
EndIf
Case 4 ; Headers
If $aGLVEx_Data[$iLV_Index][24] Then
; Header colour enabled, so read from header data
$aHdrData = $aGLVEx_Data[$iLV_Index][25]
For $i = 0 To $iDim_2 - 1
$aHeader[$i] = $aHdrData[0][$i]
Next
Else
; Read normal headers
Local $aRet
For $i = 0 To $iDim_2 - 1
$aRet = _GUICtrlListView_GetColumn($hLV, $i)
$aHeader[$i] = $aRet[5]
Next
EndIf
Case 5 ; Header colours
If $aGLVEx_Data[$iLV_Index][24] Then
; Header colour enabled, so read from header data
$aHdrData = $aGLVEx_Data[$iLV_Index][25]
For $i = 0 To $iDim_2 - 1
$aHeader[$i] = $aHdrData[1][$i]
Next
Else
Return SetError(5, 0, "")
EndIf
Case Else
Return SetError(6, 0, "")
EndSwitch
; Check if columns can be reordered
If $aGLVEx_Data[$iLV_Index][13] And UBound($aData_Colour, 2) Then
Switch $iMode
Case 0, 2, 3 ; 2D data/colour array
; Create temp array
Local $aData_Colour_Ordered[$iDim_1][$iDim_2]
; Check we are not dealing with an empty array with no data to transfer
If $iDim_1 <> 1 Or $iDim_2 <> 0 Then
; Fill temp array in correct column order
$aData_Colour_Ordered[0][0] = $aData_Colour[0][0]
For $i = 1 To $iDim_1 - 1
For $j = 0 To $iDim_2 - 1
$aData_Colour_Ordered[$i][$j] = $aData_Colour[$i][$aColOrder[$j + 1]]
Next
Next
EndIf
; Reset main and delete temp
$aData_Colour = $aData_Colour_Ordered
$aData_Colour_Ordered = ""
Case 4, 5 ; 1D header array
; Create return array
Local $aHeader_Ordered[$iDim_2]
; Check we are not dealing with an empty array
If $iDim_1 <> 1 Or $iDim_2 <> 0 Then
; Fill return array in correct column order
For $i = 0 To $iDim_2 - 1
$aHeader_Ordered[$i] = $aHeader[$aColOrder[$i + 1]]
Next
EndIf
; Return reordered array
Return $aHeader_Ordered
EndSwitch
Else
; No reordering
If $iMode = 4 Then
; Return header array
Return $aHeader
EndIf
EndIf
; Remove count element of array if required - always for colour return
Local $iCount = 1
If BitAND($aGLVEx_Data[$iLV_Index][3], 1) = 0 Or $iMode = 2 Then
$iCount = 0
; Delete count element
__GUIListViewEx_Array_Delete($aData_Colour, 0, True)
EndIf
; Now check if 1D array to be returned - always 2D for colour return and forced content
If BitAND($aGLVEx_Data[$iLV_Index][3], 2) = 0 And $iMode < 2 Then
If UBound($aData_Colour, 1) = 0 Then
Local $aData_Colour[0]
Else
; Get number of 2D elements
Local $iCols = UBound($aData_Colour, 2)
; Create 1D array - count will be overwritten if not needed
Local $aData_Colour_1D[UBound($aData_Colour)] = [$aData_Colour[0][0]]
; Fill with concatenated lines
For $i = $iCount To UBound($aData_Colour_1D) - 1
Local $aLine = ""
For $j = 0 To $iCols - 1
$aLine &= $aData_Colour[$i][$j] & $aGLVEx_Data[0][24]
Next
$aData_Colour_1D[$i] = StringTrimRight($aLine, 1)
Next
; Reset array
$aData_Colour = $aData_Colour_1D
EndIf
EndIf
; Return array
Return $aData_Colour
EndFunc ;==>_GUIListViewEx_ReturnArray
; #FUNCTION# =========================================================================================================
; Name...........: _GUIListViewEx_SaveListView
; Description ...: Saves ListView header data, ListView content, checkbox state and colour data to file
; Syntax.........: _GUIListViewEx_SaveListView($iLV_Index, $sFileName)
; Parameters ....: $iLV_Index - Index number of ListView as returned by _GUIListViewEx_Init
; $sFileName - File in which to save data
; Requirement(s).: v3.3.10 +
; Return values .: Success: 1
; Failure: 0 and sets @error as follows:
; 1 = Invalid index number
; 2 = File not written - @extended set:
; 1 = File not opened
; 2 = Data not written
; Author ........: Melba23
; Modified ......:
; Remarks .......:
; Example........: Yes
;=====================================================================================================================
Func _GUIListViewEx_SaveListView($iLV_Index, $sFileName)
; Check valid index
If $iLV_Index < 1 Or $iLV_Index > $aGLVEx_Data[0][0] Then Return SetError(1, 0, 0)
; Get ListView parameters
Local $hLV_Handle = $aGLVEx_Data[$iLV_Index][0]
Local $iStart = BitAND($aGLVEx_Data[$iLV_Index][3], 1)
; Get header data
Local $sHeader = "", $aRet
If $aGLVEx_Data[$iLV_Index][24] Then
; Header colour enabled, so also read from header data
Local $aHdrData = $aGLVEx_Data[$iLV_Index][25]
; Create string
For $i = 0 To _GUICtrlListView_GetColumnCount($hLV_Handle) - 1
$aRet = _GUICtrlListView_GetColumn($hLV_Handle, $i)
$sHeader &= $aHdrData[0][$i] & @CR & $aRet[4] & @CR & $aHdrData[1][$i] & @CR & $aHdrData[2][$i] & @CR & $aHdrData[3][$i] & @LF
Next
Else
; Read normal headers and add blank unused elements
For $i = 0 To _GUICtrlListView_GetColumnCount($hLV_Handle) - 1
$aRet = _GUICtrlListView_GetColumn($hLV_Handle, $i)
$sHeader &= $aRet[5] & @CR & $aRet[4] & @CR & @CR & @CR & @LF
Next
EndIf
$sHeader = StringTrimRight($sHeader, 1)
; Get data/check/colour content
Local $aData = _GUIListViewEx_ReturnArray($iLV_Index, 3) ; Force 2D return
If $iStart Then
_ArrayDelete($aData, 0)
EndIf
Local $aCheck = _GUIListViewEx_ReturnArray($iLV_Index, 1)
If $iStart Then
_ArrayDelete($aCheck, 0)
EndIf
Local $aColour = _GUIListViewEx_ReturnArray($iLV_Index, 2)
; Get edit data
Local $aEditable = $aGLVEx_Data[$iLV_Index][7]
; Get sort data
Local $aSortable = $aGLVEx_Data[$iLV_Index][4]
; Convert to strings
Local $sData = "", $sCheck = "", $sColour = "", $sEditable = "", $sSortable = ""
If IsArray($aData) Then
$sData = __GUIListViewEx_MakeString($aData)
EndIf
If IsArray($aCheck) Then
$sCheck = __GUIListViewEx_MakeString($aCheck)
EndIf
If IsArray($aColour) Then
$sColour = __GUIListViewEx_MakeString($aColour)
EndIf
If IsArray($aEditable) Then
$sEditable = __GUIListViewEx_MakeString($aEditable)
EndIf
If IsArray($aSortable) Then
$sSortable = __GUIListViewEx_MakeString($aSortable)
EndIf
; Write data to file
Local $iError = 0
Local $hFile = FileOpen($sFileName, $FO_OVERWRITE)
If @error Then
$iError = 1
Else
FileWrite($hFile, $sHeader & ChrW(0xEF0F) & $sData & ChrW(0xEF0F) & $sCheck & ChrW(0xEF0F) & $sColour & ChrW(0xEF0F) & $sEditable & ChrW(0xEF0F) & $sSortable)
If @error Then
$iError = 2
EndIf
EndIf
FileClose($hFile)
If $iError Then Return SetError(2, $iError, 0)
Return 1
EndFunc ;==>_GUIListViewEx_SaveListView
; #FUNCTION# =========================================================================================================
; Name...........: _GUIListViewEx_LoadListView
; Description ...: Loads ListView header data, ListView content, checkbox state and colour data from file
; Syntax.........: _GUIListViewEx_LoadListView($iLV_Index, $sFileName[, $iDims = 2])
; Parameters ....: $iLV_Index - Index number of ListView as returned by _GUIListViewEx_Init
; $sFileName - File from which to load data
; $iDims - Force 1/2D return array - normally set by initialising array
; Requirement(s).: v3.3.10 +
; Return values .: Success: 1
; Failure: 0 and sets @error as follows:
; 1 = Invalid index number
; 2 = Invalid $iDims parameter
; 3 = File not read
; 4 = No data to load
; Author ........: Melba23
; Modified ......:
; Remarks .......:
; Example........: Yes
;=====================================================================================================================
Func _GUIListViewEx_LoadListView($iLV_Index, $sFileName, $iDims = 2)
; Check valid index
If $iLV_Index < 1 Or $iLV_Index > $aGLVEx_Data[0][0] Then Return SetError(1, 0, 0)
; Check valid $iDims parameter
Switch $iDims
Case 1, 2
; OK
Case Else
Return SetError(2, 0, 0)
EndSwitch
; Get ListView parameters
Local $hLV_Handle = $aGLVEx_Data[$iLV_Index][0]
Local $cLV_CID = $aGLVEx_Data[$iLV_Index][1]
Local $iStart = BitAND($aGLVEx_Data[$iLV_Index][3], 1)
; Read content
Local $sContent = FileRead($sFileName)
If @error Then Return SetError(3, 0, 0)
; Split into separate sections
Local $aSplit = StringSplit($sContent, ChrW(0xEF0F), $STR_ENTIRESPLIT)
; Load arrays - checking there is some data to load
Local $aHeader = __GUIListViewEx_MakeArray($aSplit[1])
If Not IsArray($aHeader) Then Return SetError(4, 0, 0)
Local $aData = __GUIListViewEx_MakeArray($aSplit[2])
If Not IsArray($aData) Then Return SetError(4, 0, 0)
Local $aCheck = __GUIListViewEx_MakeArray($aSplit[3])
Local $aColour = __GUIListViewEx_MakeArray($aSplit[4])
Local $aEditable = __GUIListViewEx_MakeArray($aSplit[5])
Local $aSortable = __GUIListViewEx_MakeArray($aSplit[6])
; If required, convert data and colour arrays into 2D for load
If UBound($aData, 0) = 1 Then
Local $aTempData[UBound($aData)][1]
Local $aTempCol[UBound($aData)][1]
For $i = 0 To UBound($aData) - 1
$aTempData[$i][0] = $aData[$i]
$aTempCol[$i][0] = $aColour[$i]
Next
$aData = $aTempData
$aColour = $aTempCol
EndIf
; Create and fill header data array
Local $aHdrData[4][UBound($aHeader)]
For $i = 0 To UBound($aHeader) - 1
$aHdrData[0][$i] = $aHeader[$i][0]
$aHdrData[1][$i] = $aHeader[$i][2]
$aHdrData[2][$i] = $aHeader[$i][3]
$aHdrData[3][$i] = $aHeader[$i][4]
Next
; Store array
$aGLVEx_Data[$iLV_Index][25] = $aHdrData
; Set no colour redraw flag and prevent any normal redraw
$aGLVEx_Data[0][12] = 1
$aGLVEx_Data[0][15] = False
_GUICtrlListView_BeginUpdate($hLV_Handle)
; Clear current content of ListView
_GUICtrlListView_DeleteAllItems($hLV_Handle)
; Check correct number of columns
Local $iCol_Count = _GUICtrlListView_GetColumnCount($hLV_Handle)
If $iCol_Count < UBound($aHeader) Then
; Add columns
For $i = $iCol_Count To UBound($aHeader) - 1
_GUICtrlListView_AddColumn($hLV_Handle, "", 100)
Next
EndIf
If $iCol_Count > UBound($aHeader) Then
; Delete columns
For $i = $iCol_Count To UBound($aHeader) Step -1
_GUICtrlListView_DeleteColumn($hLV_Handle, $i)
Next
EndIf
; Reset header titles and widths
For $i = 0 To UBound($aHeader) - 1
_GUICtrlListView_SetColumn($hLV_Handle, $i, $aHeader[$i][0], $aHeader[$i][1])
Next
; Load ListView content
If $cLV_CID Then
; Native ListView
Local $sLine, $iLastCol = UBound($aData, 2) - 1
For $i = 0 To UBound($aData) - 1
$sLine = ""
For $j = 0 To $iLastCol
$sLine &= $aData[$i][$j] & $aGLVEx_Data[0][24]
Next
GUICtrlCreateListViewItem(StringTrimRight($sLine, 1), $cLV_CID)
Next
Else
; UDF ListView
_GUICtrlListView_AddArray($hLV_Handle, $aData)
EndIf
_GUICtrlListView_EndUpdate($hLV_Handle)
; Add required count row to shadow array
_ArrayInsert($aData, 0, UBound($aData))
; Store content array
$aGLVEx_Data[$iLV_Index][2] = $aData
; Store editable array
$aGLVEx_Data[$iLV_Index][7] = $aEditable
; Store sortable array
$aGLVEx_Data[$iLV_Index][4] = $aSortable
; Set 1/2D return flag as required
$aGLVEx_Data[$iLV_Index][3] = $iStart + (($iDims = 2) ? (2) : (0))
; Reset checkboxes if required
If IsArray($aCheck) Then
; Reset checkboxes
For $i = 0 To UBound($aCheck) - 1
If $aCheck[$i] = "True" Then
_GUICtrlListView_SetItemChecked($hLV_Handle, $i, True)
EndIf
Next
EndIf
; Clear no colour redraw flag and allow normal redraw
$aGLVEx_Data[0][12] = 0
$aGLVEx_Data[0][15] = True
; Reset data colours if required
If $aGLVEx_Data[$iLV_Index][19] Then
If IsArray($aColour) Then
; Load colour
_GUIListViewEx_LoadColour($iLV_Index, $aColour)
Else
; Create empty array
$aColour = $aData
For $i = 0 To UBound($aData) - 1
For $j = 0 To UBound($aData, 2) - 1
$aColour[$i][$j] = ";"
Next
Next
$aGLVEx_Data[$iLV_Index][18] = $aColour
EndIf
EndIf
; Redraw ListView
__GUIListViewEx_RedrawWindow($iLV_Index)
; Set active
$aGLVEx_Data[0][1] = $iLV_Index
Return 1
EndFunc ;==>_GUIListViewEx_LoadListView
; #FUNCTION# =========================================================================================================
; Name...........: _GUIListViewEx_Up
; Description ...: Moves selected item(s) in active ListView up 1 row
; Syntax.........: _GUIListViewEx_Up()
; Parameters ....: None
; Requirement(s).: v3.3.10 +
; Return values .: Success: Array of active ListView with count in [0] element
; Failure: Returns "" and sets @error as follows:
; 1 = No ListView active
; 2 = No item selected
; 3 = Item already at top
; 4 = Empty ListView
; Author ........: Melba23