-
Notifications
You must be signed in to change notification settings - Fork 72
/
class_SpreadSheet.ahk
1753 lines (1459 loc) · 55.6 KB
/
class_SpreadSheet.ahk
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
/*
Title: SpreadSheet
SpreadSheet control is extremelly fast and small Excell like control, developed in Assembler.
(See SpreadSheet.png)
*/
/*
Function: Add
Add control to the Gui
Parameters:
HParent - Parent's handle.
X..H - Control coordinates.
Style - White separated list of control styles.
Handler - Notification handler, optional.
DllPath - Path to the dll, by default look at the working folder.
Styles:
VSCROLL HSCROLL STATUS GRIDLINES ROWSELECT CELLEDIT GRIDMODE COLSIZE ROWSIZE WINSIZE MULTISELECT
Handler:
> result := Handler(HCtrl, Event, EArg, Col, Row)
HCtrl - Handle of the speradsheet control that sends the notification.
Event - Event that ocured. Can be *S* (select), *EB* (before edit), *EA* (after edit), *UB* (before update), *UA* (after update), *C* (click) and *D* (draw)
EArg - Event argument. Depends on event. See below.
Col - Column of the associated cell.
Row - Row of the associated cell.
result - Handler result, depends on event. See bellow.
Event types and returns:
Handler's _EArg_ parameter is specific to each event:
S - Current splitt window number. Return 1 to prevent selection.
EA - User input. Return 1 to discard user input.
C - B (Button) or H (Hyperlink). Return value isn't used.
EB,UB,UB - Empty (argument isn't used). Return value isn't used.
D - Pointer to DRAWITEMSTRUCT. See <http://msdn.microsoft.com/en-us/library/bb775802(VS.85).aspx>.
Returns:
Control's handle.
*/
SS_Add(HParent,X,Y,W,H, Style="", Handler="", DllPath=""){
static MODULEID
static WS_CLIPCHILDREN=0x2000000, WS_VISIBLE=0x10000000, WS_CHILD=0x40000000
static VSCROLL=0x0001, HSCROLL=0x0002, STATUS=0x0004, GRIDLINES=0x0008, ROWSELECT=0x0010, CELLEDIT=0x0020, GRIDMODE=0x0040, COLSIZE=0x0080, ROWSIZE=0x0100, WINSIZE=0x0200, MULTISELECT=0x0400
;standard registering procedure
if !MODULEID {
ifEqual, DllPath,,SetEnv, DllPath, SprSht.dll
if !DllCall("LoadLibrary", "str", DllPath)
return A_ThisFunc "> Can't load library - " DllPath
old := OnMessage(0x4E, "SS_onNotify"), MODULEID := 260609
if old != SS_onNotify
SS("oldNotify", RegisterCallback(old))
}
;parse style
hStyle := 0
loop, parse, style, %A_Tab%%A_Space%
IfEqual, A_LoopField,, continue
else hStyle |= %A_LOOPFIELD%
hCtrl := DllCall("CreateWindowEx"
, "Uint", 0x200 ; WS_EX_CLIENTEDGE
, "str", "SPREAD_SHEET" ; ClassName
, "str", "" ; WindowName
, "Uint", WS_CLIPCHILDREN | WS_CHILD | WS_VISIBLE | hStyle
, "int", x ; Left
, "int", y ; Top
, "int", w ; Width
, "int", h ; Height
, "Uint", HParent ; hWndParent
, "Uint", MODULEID ; hMenu
, "Uint", 0 ; hInstance
, "Uint", 0, "Uint")
ifEqual, hCtrl, 0, return A_ThisFunc "> Error creating control"
if IsFunc(Handler)
SS(hCtrl "Handler", Handler)
return hCtrl
}
/*
Function: BlankCell
Erase the cell.
*/
SS_BlankCell(hCtrl, Col="", Row="") {
static SPRM_BLANKCELL=0x477 ;Blank a cell. wParam=col, lParam=row
if Col=
SS_GetCurrentCell(hCtrl, Col, Row)
SendMessage,SPRM_BLANKCELL,Col,Row,, ahk_id %hCtrl%
return ErrorLevel
}
/*
Function: CreateCombo
Creates COMBOBOX cell type.
Parameters:
Content - | separated list of ComboBox items.
Height - Height of the combo box.
Returns:
Handle of the ComboBox. Use it with _txt_ parameter of the <CetCell> function.
*/
SS_CreateCombo(hCtrl, Content, Height=150) {
static SPRM_CREATECOMBO=0x491 ;Creates a ComboBox. wPatam=Height, lParam=0
ifEqual, Content,, return A_ThisFunc "> Content can't be empty"
SendMessage,SPRM_CREATECOMBO,Height,0,,ahk_id %hCtrl%
hListBox := ErrorLevel
old := A_DetectHiddenWindows
DetectHiddenWindows, on
loop, parse, content, |
Control, Add, %A_LoopField%,, ahk_id %hListBox%
DetectHiddenWindows, %old%
return hListBox
}
/*
Function: ConvertDate
Converts date from / to integer.
Parameters:
Date - Integer or textual representation of the date.
RefreshFormat - Set to TRUE to refresh control's date format that is stored internaly on first call.
Returns:
If Date is integer the return value is the date string, otherwise the retun value is integer representation of the date.
*/
SS_ConvertDate(hCtrl, Date, RefreshFormat=false) {
static format
var := 16010101, format .= (format="") || RefreshFormat ? SS_GetDateFOrmat(hCtrl) : ""
if Date is integer
{
EnvAdd, var, %Date%, D
FormatTime, var, %var%, %format%
return var
}
else {
loop, parse, format
{
if A_LoopField not in d,M,y
continue
ifEqual, A_LoopField, y, SetEnv, y, % y SubStr(Date, A_Index, 1)
ifEqual, A_LoopField, d, SetEnv, d, % d SubStr(Date, A_Index, 1)
ifEqual, A_LoopField, m, SetEnv, m, % m SubStr(Date, A_Index, 1)
}
time := y m d
EnvSub, time, %var%, D
return time
}
}
/*
Function: DeleteCell
Delete cell.
Remarks:
Its misterious to me what is the difference between this one and <BlankCell>.
*/
SS_DeleteCell(hCtrl, Col="", Row="") {
static SPRM_DELETECELL=0x493 ;Deletes a cell. wParam=col, lParam=row
if Col=
SS_GetCurrentCell(hCtrl, Col, Row)
SendMessage,SPRM_DELETECELL,Col,Row,, ahk_id %hCtrl%
return ErrorLevel
}
/*
Function: DeleteCol
Delete column.
Parameters:
Col - Column index. Of omited, current column is used.
*/
SS_DeleteCol(hCtrl, Col="") {
static SPRM_DELETECOL=0x46E ;Delete col. wParam=col, lParam=0
if Col=
Col := SS_GetCurrentCol(hCtrl)
SendMessage,SPRM_DELETECOL,Col,,, ahk_id %hCtrl%
return ErrorLevel
}
/*
/*
Function: DeleteRow
Delete row.
Parameters:
Row - Row index. Of omited, current row is used.
*/
SS_DeleteRow(hCtrl, Row="") {
static SPRM_DELETEROW=0x470 ;Delete row. wParam=row, lParam=0
if Row =
Row := SS_GetCurrentRow(hCtrl)
SendMessage,SPRM_DELETEROW,Row,,, ahk_id %hCtrl%
return ErrorLevel
}
/*
Function: ExpandCell
Expand a cell to cover more than one cell.
Parameters:
Left, Top, Right, Bottom - Coordinates of the expanded cell.
*/
SS_ExpandCell(hCtrl, Left, Top, Right, Bottom ){
static SPRM_EXPANDCELL=0x48E ;wParam=0, lParam=pointer to RECT struct
VarSetCapacity(RECT, 16), NumPut(Left, RECT), NumPut(Top,RECT,4), NumPut(Right, RECT, 8), NumPut(Bottom, RECT, 12)
SendMessage,SPRM_EXPANDCELL,,&RECT,, ahk_id %hCtrl%
return ERRORLEVEL
}
/*
Function: GetCell
Get the cell parameters.
Parameters:
Col, Row - Cell coordinates. If set to empty current cell coordinates will be used.
pQ - Query parameter. See <SetCell> for the list of possible cell parameters (txt, data, w, h, bg, fg, type, state, txtal, imgal, fnt)
o1 .. o5 - Reference to variables to receive output in order specified in pQ parameter.
Returns:
o1, so you don't need to use reference variables to grab only 1 field i.e. state := SS_GetCell(hctrl, 1,1, "state").
*/
SS_GetCell(hCtrl, Col, Row, pQ, ByRef o1="", ByRef o2="", ByRef o3="", ByRef o4="", ByRef o5=""){
static SPRM_GETCELLDATA=0x482 ;wParam=0, lParam=Pointer to SPR_ITEM struct
static SPRIF_TYPE=0x40,SPRIF_DATA=0x200,SPRIF_WIDTH=0x80,SPRIF_BACKCOLOR=1,SPRIF_TEXTCOLOR=2,SPRIF_TEXTALIGN=4,SPRIF_HEIGHT=0x100,SPRIF_STATE=0x20,SPRIF_FONT=0x10,SPRIF_IMAGEALIGN=8,SPRIF_COMPILE=0x80000000, SPRIF_DOUBLE=0x400, SPRIF_SINGLE=0x800
static data="DATA", txt="DATA", w="WIDTH", h="HEIGHT", bg="BACKCOLOR", fg="TEXTCOLOR", state="STATE", txtal="TEXTALIGN", imgal="IMAGEALIGN", font="FONT", type="TYPE"
static EMPTY=0, COLHDR=1, ROWHDR=2, WINHDR=3, TEXT=4, TEXTMULTILINE=5, INTEGER=6, FLOAT=7, FORMULA=8, GRAPH=9, HYPERLINK=10, CHECKBOX=11, COMBOBOX=12, OWNERDRAWBLOB=13, OWNERDRAWINTEGER=14, EXPANDED=15, BUTTON=16, WIDEBUTTON=0x20, DATE=0x30, FORCETEXT=0x44, FORCETYPE=0x40, FIXEDSIZE=0x80
static _state=14.1,_bg=16,_fg=20,_txtal=24.1,_imgal=25.1,_fnt=26.1,_type=27.1, _txt=36,_data=36, _w=28, _h=32
;use col="-1" internally to pass ITEM pointer via row param if I have it already via different means (for instance onNotify)
if Col=
SS_GetCurrentCell(hCtrl, Col, Row)
flag := SPRIF_TYPE
StringSplit, a, pQ, %A_Space%, %A_Space%%A_Tab%
loop, %a0%
{
f := a%A_Index%, f := %f%, f := SPRIF_%f%
ifEqual,f, ,return A_ThisFunc ">Invalid parameter - " a%A_Index%
flag |= f
}
VarSetCapacity(ITEM, 40, 0), pItem := &ITEM
NumPut(flag, ITEM), NumPut(Col, ITEM, 4), NumPut(Row,ITEM, 8)
SendMessage,SPRM_GETCELLDATA,,&ITEM,, ahk_id %hCtrl%
type := NumGet(pITEM+27, 0, "UChar") & ~0xF0 ;get base type
pData := NumGet(pITEM+36)
loop, %a0%
{
field := a%A_Index%, offset := _%field%, t := SubStr(offset, -1)
v := NumGet(pITEM + floor(offset), 0, t = ".1" ? "UChar" : "Uint")
if (field="txt"){
if type in %INTEGER%,%OWNERDRAWINTEGER%
v := NumGet(pData+0)
else if type in %FLOAT%,%FORMULA%
v := SS_getCellFloat(hCtrl, col, row)
else if (type=COMBOBOX)
v := NumGet(pData+4)
else v := SS_strAtAdr(pData + (type=CHECKBOX || type=OWNERDRAWBLOB ? 4 : 0))
}
if (field="data")
if type in %CHECKBOX%,%COMBOBOX%,%OWNERDRAWBLOB%
v := NumGet(pData+0)
if SubStr(field, -1) = "al"
field := "align"
if field in type,state,align
fun := "SS_get" field, v := %fun%( v )
o%A_Index% := v
}
return o1
}
/*
Function: GetCellArray
Get all cell parameters into array.
Parameters:
V - Array prefix. The array is used to return data back. See <SetCell> for the list of possible cell parameters.
Col, Row - Cell coordinates. If omited current cell coordinates will be used.
Remarks:
To get individual fields, its faster to use <GetCell>. Also, this function creates global variables.
*/
SS_GetCellArray(hCtrl, V, Col="", Row=""){
local ITEM, flag, pData, type, flag
static SPRM_GETCELLDATA=0x482 ;wParam=0, lParam=Pointer to SPR_ITEM struct
static EMPTY=0, COLHDR=1, ROWHDR=2, WINHDR=3, TEXT=4, TEXTMULTILINE=5, INTEGER=6, FLOAT=7, FORMULA=8, GRAPH=9, HYPERLINK=10, CHECKBOX=11, COMBOBOX=12, OWNERDRAWBLOB=13, OWNERDRAWINTEGER=14, EXPANDED=15, BUTTON=16, WIDEBUTTON=0x20, DATE=0x30, FORCETEXT=0x44, FORCETYPE=0x40, FIXEDSIZE=0x80
static SPRIF_TYPE=0x40,SPRIF_DATA=0x200,SPRIF_WIDTH=0x80,SPRIF_BACKCOLOR=1,SPRIF_TEXTCOLOR=2,SPRIF_TEXTALIGN=4,SPRIF_HEIGHT=0x100,SPRIF_STATE=0x20,SPRIF_FONT=0x10,SPRIF_IMAGEALIGN=8,SPRIF_COMPILE=0x80000000, SPRIF_DOUBLE=0x400, SPRIF_SINGLE=0x800
flag := SPRIF_BACKCOLOR | SPRIF_TEXTCOLOR | SPRIF_TEXTALIGN | SPRIF_IMAGEALIGN | SPRIF_FONT | SPRIF_TYPE | SPRIF_STATE | SPRIF_DATA
if Col=
SS_GetCurrentCell(hCtrl, Col, Row)
VarSetCapacity(ITEM, 40, 0)
NumPut(flag, ITEM, 0), NumPut(Col, ITEM, 4), NumPut(Row, ITEM, 8)
SendMessage,SPRM_GETCELLDATA,,&ITEM,, ahk_id %hCtrl%
%V%_state := NumGet(ITEM, 14, "UChar"), %V%_state := SS_getState(%V%_state) ;state db ? 14
;FORMAT struct
%V%_bg := NumGet(ITEM, 16) ;bckcol dd ? 0 ;Back color
%V%_fg := NumGet(ITEM, 20) ;txtcol dd ? 4 ;Text color
%V%_txtal := NumGet(ITEM, 24,"UChar"), %V%_txtal := SS_getAlign(%V%_txtal) ;txtal db ? 8 ;Text alignment and decimals
%V%_imgal := NumGet(ITEM, 25,"UChar"), %V%_imgal := SS_getAlign(%V%_imgal) ;imgal db ? 9 ;Image alignment and imagelist/control index
%V%_fnt := NumGet(ITEM, 26,"UChar") ;fnt db ? 10 ;Font index (0-15)
type := NumGet(ITEM, 27,"UChar")
%V%_type := SS_getType(type) ;tpe db ? 11 26 ;Cell type
pData := NumGet(ITEM, 36), %V%_data := ""
type &= ~0xF0
ifEqual, type, %EXPANDED%, return
if type in %CHECKBOX%,%COMBOBOX%,%OWNERDRAWBLOB%
{
%V%_data:= NumGet(pData+0)
%V%_txt := type=COMBOBOX ? NumGet(pData+4) : SS_strAtAdr(pData + 4)
}
else if type in %FLOAT%,%FORMULA%
%V%_txt := SS_getCellFloat(hCtrl, col, row)
else if type in %INTEGER%,%OWNERDRAWINTEGER%
%V%_txt := NumGet(pData+0)
else
%V%_txt := SS_strAtAdr(pData) ;copy text
}
/* Function: GetCellBlob
Returns pointer to the current cell BLOB.
Parameters:
EArg - D event handlers event argument (pointer to DRAWITEM struct).
GetText? - Set to true to return text instead of binary data.
*/
SS_GetCellBLOB(EArg, GetText=false) {
pData := NumGet( NumGet(EArg+44)+36 )
return GetText ? DllCall("MulDiv","UInt",pData+4,"UInt",1,"UInt",1, "str") : pData
}
/*
Function: GetCellData
Get the cell data.
Parameters:
Col, Row - Cell coordinates. If omited, current cell will be used.
Remarks:
This funcion also returns data for OVERDRAWINTEGER type. Its faster to use to get the integer then other functions.
*/
SS_GetCellData(hCtrl, Col="", Row="") {
static SPRM_GETCELLDATA=0x482, SPRIF_DATA=0x200, init
if !init
init++, VarSetCapacity(ITEM, 40, 0), NumPut(SPRIF_DATA, ITEM)
if Col=
SS_GetCurrentCell(hCtrl, Col, Row)
NumPut(Col, ITEM, 4), NumPut(Row, ITEM, 8)
SendMessage,SPRM_GETCELLDATA,,&ITEM,, ahk_id %hCtrl%
return NumGet( NumGet(ITEM, 36) )
}
/*
Function: GetCellRect
Get the current cells rect in active splitt.
Returns:
Handle of active splitt window.
*/
SS_GetCellRect(hCtrl, ByRef top, ByRef left, ByRef right, ByRef bottom){
static SPRM_GETCELLRECT=0x469 ; wParam=0, lParam=pointer to RECT struct.
VarSetCapacity(RECT, 16)
SendMessage,SPRM_GETCELLRECT,0,&RECT,, ahk_id %hCtrl%
left := NumGet(RECT, 0)
top := NumGet(RECT, 4)
right := NumGet(RECT, 8)
bottom := NumGet(RECT, 12)
return ERRORLEVEL
}
/*
Function: GetCellText
Get cell text
Parameters:
Col, Row - Coordinates of the cell. If omited, current cell will be used.
Remarks:
This function retrieves any kind of text from all types of cells, no matter the internal representation.
For ComboBox selected item will be returned and for CheckBox 1 or 0.
*/
SS_GetCellText(hCtrl, Col="", Row=""){
;fast version for GetCell but only for text
static EMPTY=0, COLHDR=1, ROWHDR=2, WINHDR=3, TEXT=4, TEXTMULTILINE=5, INTEGER=6, FLOAT=7, FORMULA=8, GRAPH=9, HYPERLINK=10, CHECKBOX=11, COMBOBOX=12, OWNERDRAWBLOB=13, OWNERDRAWINTEGER=14, EXPANDED=15, BUTTON=16, WIDEBUTTON=0x20, DATE=0x30, FORCETEXT=0x44, FORCETYPE=0x40, FIXEDSIZE=0x80
static SPRM_GETCELLDATA=0x482, SPRIF_DATA=0x200, SPRIF_TYPE=0x40
static ITEM, init
if !init
init++, VarSetCapacity(ITEM, 40, 0), NumPut(SPRIF_DATA | SPRIF_TYPE, ITEM)
if Col=
SS_GetCurrentCell(hCtrl, Col, Row)
NumPut(Col, ITEM, 4), NumPut(Row, ITEM, 8)
SendMessage,SPRM_GETCELLDATA,,&ITEM,, ahk_id %hCtrl%
type := NumGet(ITEM, 27, "UChar") & ~0xF0 ;get base type
if type=%COLHDR%
return SS_strAtAdr( NumGet(ITEM, 36)+2 )
if type in %TEXT%,%TEXTMULTILINE%,%HYPERLINK%,%CHECKBOX%,%OWNERDRAWBLOB% ;GRAPH and FORMULA don't return text, I don't know how to get their text.
return SS_strAtAdr( NumGet(ITEM, 36) + (type=CHECKBOX || type=OWNERDRAWBLOB ? 4 : 0))
if type in %INTEGER%,%COMBOBOX%,%OWNERDRAWINTEGER%
{
pData := NumGet(ITEM, 36), txt := NumGet( pData+0 )
if (type=COMBOBOX) ;combobox, get the item from the listbox
{
hCombo := NumGet(pData + 4)
old := A_DetectHiddenWindows
DetectHiddenWindows, on
ControlGet, lst, list,,, ahk_id %hCombo%
DetectHiddenWindows, %old%
loop, parse, lst, `n
if (A_index = txt+1) {
txt := A_LoopField
break
}
}
return txt
}
if type in %FLOAT%,%FORMULA%
return SS_getCellFloat(hCtrl, col, row)
}
/*
Function: GetCellType
Get cell data type
Parameters:
Col, Row - Coordinates. If omited, current cell will be used
Flag - Used internaly. 1 to return numeric type, 2 to return numeric base type without modifiers
Returns:
Number (not text for now)
*/
SS_GetCellType(hCtrl, Col="", Row="", Flag=0) {
static SPRM_GETCELLTYPE=0x48F ;wParam=col, lParam=row. Returns cell type.
if Col=
SS_GetCurrentCell(hCtrl, Col, Row)
SendMessage,SPRM_GETCELLTYPE,Col,Row,, ahk_id %hCtrl%
return !Flag ? SS_getTYpe(ErrorLevel) : Flag=1 ? ErrorLevel : ErrorLevel & ~0xF0
}
/*
Function: GetColCount
Get number of columns
*/
SS_GetColCount(hCtrl){
static SPRM_GETCOLCOUNT=0x472
SendMessage,SPRM_GETCOLCOUNT,0,0,, ahk_id %hCtrl%
return ErrorLevel
}
/*
Function: GetColWidth
Get column width.
*/
SS_GetColWidth(hCtrl, col){
static SPRM_GETCOLWIDTH=0x47E ;wParam=col, lParam=0. Returns column width.
SendMessage,SPRM_GETCOLWIDTH,col,,, ahk_id %hCtrl%
return ERRORLEVEL
}
/*
Function: GetCurrentCell
Get current cell in active window.
Parameters:
Col, Row - Reference to variables to receive output.
*/
SS_GetCurrentCell(hCtrl, ByRef Col, ByRef Row) {
static SPRM_GETCURRENTCELL=0x47A ; wParam=0, lParam=0. Returns Hiword=row, Loword=col
SendMessage,SPRM_GETCURRENTCELL,,,, ahk_id %hCtrl%
VarSetCapacity(s, 4), NumPut(ERRORLEVEL, s), col := NumGet(s, 0, "UShort"), row := NumGet(s, 2, "UShort")
}
/*
Function: GetCurrentCol
Get current column in active window.
Returns:
Current column index.
*/
SS_GetCurrentCol(hCtrl) {
static SPRM_GETCURRENTCELL=0x47A ;wParam=0, lParam=0. Returns Hiword=row, Loword=col
SendMessage,SPRM_GETCURRENTCELL,,,, ahk_id %hCtrl%
VarSetCapacity(s, 4), NumPut(ERRORLEVEL, s)
return NumGet(s, 0, "UShort")
}
/*
Function: GetCurrentRow
Get current row in active window.
Returns:
Current row index.
*/
SS_GetCurrentRow(hCtrl) {
static SPRM_GETCURRENTCELL=0x47A ;GwParam=0, lParam=0. Returns Hiword=row, Loword=col
SendMessage,SPRM_GETCURRENTCELL,,,, ahk_id %hCtrl%
VarSetCapacity(s, 4), NumPut(ERRORLEVEL, s)
return NumGet(s, 2, "UShort")
}
/*
Function: GetCurrentWin
Get active splitt window.
*/
SS_GetCurrentWin(hCtrl){
static SPRM_GETCURRENTWIN=0x478 ; wParam=0, lParam=0
SendMessage,SPRM_GETCURRENTWIN,,,, ahk_id %hCtrl%
return ERRORLEVEL
}
/*
Function: GetDateFormat
Get date format.
*/
SS_GetDateFormat(hCtrl) {
static SPRM_GETDATEFORMAT=0x494 ;Returns date format string. wParam=0, lParam=0
SendMessage,SPRM_GETDATEFORMAT,,,, ahk_id %hCtrl%
return SS_strAtAdr(ErrorLevel)
}
/*
Function: GetGlobalFields
Get individual global parameters from the control.
Parameters:
Fields - White space separated list of field names to get.
v1 .. v7 - Field values, respecting the order of names in fields argument.
Example:
> SS_GetGlobalFields(hCtrl, "nrows ncols", rows, cols)
*/
SS_GetGlobalFields(hCtrl, Fields, ByRef v1="", ByRef v2="", ByRef v3="", ByRef v4="", ByRef v5="", ByRef v6="", ByRef v7="") {
static SPRM_SETGLOBAL=0x489, SPRM_GETGLOBAL=0x488 ; wParam=0, lParam=cols
static colhdrbtn=0,rowhdrbtn=4,winhdrbtn=8,lockcol=12,hdrgrdcol=16,grdcol=20,bcknfcol=24,txtnfcol=28,bckfocol=32,txtfocol=36,ncols=40,nrows=44,ghdrwt=48,ghdrht=52,gcellw=56,gcellht=60
static _bg=0, _fg=4, _txtal=8.1, _imgal=9.1, _fnt=10.1, _tpe=11.1
static colhdr=64, rowhdr=76, winhdr=88, cell=100
static LEFT=0x10, CENTER=0x20, RIGHT=0x30, MIDDLE=0x40, BOTTOM=0x80, GLOBAL=0xF0, MASK=0xF0, XMASK=0x30, YMASK=0xC0
static alignments := "LEFT CENTER RIGHT MIDDLE BOTTOM"
VarSetCapacity(GLOBAL, 112, 0)
SendMessage,SPRM_GETGLOBAL,0,&GLOBAL,, ahk_id %hCtrl%
loop, parse, Fields, %A_Space%%A_Tab%
{
field := A_LoopField
if (j := InStr(field, "_"))
offset := SubStr(field, 1, j-1), offset := %offset%, _ := SubStr(field, j), _ := %_%, offset += floor(_), t := SubStr(_, -1)
else offset := %field%
ifEqual, offset, ,return A_ThisFunc "> Invalid field name - " field
v := NumGet(GLOBAL, offset, t=".1" ? "UChar" : "Uint" )
if InStr(field, "al") {
v%a_index% := ""
loop, parse, alignments, %A_Space%
if ( v & %A_LOOPFIELD% )
v%a_index% .= A_LOOPFIELD " "
} else
v%a_index% := v
}
return ERRORLEVEL
}
/*
Function: GetLockCol
Get lock cols in active splitt.
*/
SS_GetLockCol(hCtrl){
static SPRM_GETLOCKCOL=0x46A ; wParam=0, lParam=0
SendMessage,SPRM_GETLOCKCOL,,,, ahk_id %hCtrl%
return ERRORLEVEL
}
/*
Function: GetLockRow
Get lock rows in active splitt.
*/
SS_GetLockRow(hCtrl){
static SPRM_GETLOCKROW=0x46C ; wParam=0, lParam=0
SendMessage,SPRM_GETLOCKROW,,,, ahk_id %hCtrl%
return ERRORLEVEL
}
/*
Function: GetMultiSel
Get multiselection.
Parameters:
Top, Left, Right, Bottm - Reference to variables to receive the output. You can omit any you don't need.
*/
SS_GetMultiSel(hCtrl, ByRef Top="", ByRef Left="", ByRef Right="", ByRef Bottom=""){
static SPRM_GETMULTISEL=0x484 ;wParam=0, lParam=pointer to a RECT struct.
VarSetCapacity(RECT, 16)
SendMessage,SPRM_GETMULTISEL,0,&RECT,, ahk_id %hCtrl%
Left := NumGet(RECT, 0), Top := NumGet(RECT, 4), Right := NumGet(RECT, 8), Bottom := NumGet(RECT, 12)
return ERRORLEVEL
}
/*
Function: GetRowCount
Get number of rows.
*/
SS_GetRowCount(hCtrl){
static SPRM_GETROWCOUNT=0x474
SendMessage,SPRM_GETROWCOUNT,0,0,, ahk_id %hCtrl%
return ErrorLevel
}
/*
Function: GetRowHeight
Returns row height.
*/
SS_GetRowHeight(hCtrl, Row) {
static SPRM_GETROWHEIGHT=0x480 ;wParam=row, lParam=0
SendMessage,SPRM_GETROWHEIGHT,Row,,, ahk_id %hCtrl%
return ErrorLevel
}
/*
Function: ImportLine
Import a line of data.
Parameters:
DataLine - Text containing the data.
SepChar - Data separator, by default ";".
*/
SS_ImportLine(hCtrl, DataLine, SepChar=";") {
static SPRM_IMPORTLINE=0x48A ; wParam=SepChar, lParam=pointer to data line.
SendMessage,SPRM_IMPORTLINE,asc(SepChar),&DataLine,, ahk_id %hCtrl%
return ERRORLEVEL
}
/*
Function: InsertCol
Insert column.
Parameters:
Col - Column index after which to insert column. By deault -1 means to append it.
*/
SS_InsertCol(hCtrl, Col=-1) {
static SPRM_INSERTCOL=0x46F ;wParam=col, lParam=0
if Col=-1
Col := SS_GetColCount(hCtrl)+1
SendMessage,SPRM_INSERTCOL,Col,,, ahk_id %hCtrl%
return ErrorLevel
}
/*
Function: InsertRow
Insert row.
Parameters:
Row - Position after which to insert row. By deault -1 means to append it.
*/
SS_InsertRow(hCtrl, Row=-1) {
static SPRM_INSERTROW=0x471 ;wParam=row, lParam=0
if Row=-1
row := SS_GetRowCount(hCtrl)+1
SendMessage,SPRM_INSERTROW,Row,,, ahk_id %hCtrl%
return ErrorLevel
}
/*
Function: LoadFile
Load a file.
Parameters:
File - File name.
*/
SS_LoadFile(hCtrl, File) {
static SPRM_LOADFILE=0x48B ;wParam=0, lParam=pointer to filename
SendMessage,SPRM_LOADFILE,,&File,, ahk_id %hCtrl%
return ERRORLEVEL
}
/*
Function: NewSheet
Clears the sheet.
*/
SS_NewSheet(hCtrl) {
static SPRM_NEWSHEET=0x48D ; wParam=0, lParam=0
SendMessage,SPRM_NEWSHEET,,,, ahk_id %hCtrl%
return ErrorLevel
}
/*
Function: ReCalc
Recalculates the sheet.
*/
SS_ReCalc(hCtrl){
static SPRM_RECALC=0x476
SendMessage,SPRM_RECALC,,,, ahk_id %hCtrl%
return ERRORLEVEL
}
/*
Function: Redraw
Redraw the control.
*/
SS_Redraw(hCtrl){
static RDW_ALLCHILDREN:=0x80, RDW_INVALIDATE:=0x1
return DllCall("RedrawWindow", "uint", hCtrl, "uint", 0, "uint", 0, "uint", RDW_INVALIDATE | RDW_ALLCHILDREN)
}
/*
Function: SaveFile
Save a file.
*/
SS_SaveFile(hCtrl, File){
static SPRM_SAVEFILE=0x48C ;wParam=0, lParam=pointer to filename
SendMessage,SPRM_SAVEFILE,,&File,, ahk_id %hCtrl%
return ERRORLEVEL
}
/*
Function: ScrollCell
Scrolls current cell into view.
*/
SS_ScrollCell(hCtrl) {
static SPRM_SCROLLCELL=0x492
SendMessage,SPRM_SCROLLCELL,,,, ahk_id %hCtrl%
return ERRORLEVEL
}
/*
Function: SetCell
Set content of the cell.
Parameters:
Col, Row - Cell coordinates.
o1 .. o11 - Named parameters.
Named Parameters:
type - Type of the cell. See bellow for list of types. You will generally use type when setting up cells initially and omit it when changing existing cells.
w, h - Width, height of the cell.
bg, fg - Background, foreground color.
state - Cell state.
txtal - Text alignment and decimals. See aligment section for list of kewords. Use number to set FLOAT precision (1-12, all, sci).
imgal - Image alignment and imagelist/control index .
fnt - Cell font index (0-15).
Type Dependent Named Parameters:
txt - String (TEXT,CHECKBOX,*HDR), Number (INTEGER), hwndCombo (COMBOBOX), Formula Definition (FORMULA), Graph Definition (GRAPH)
data - 0-based selected index, 0 by default (COMBOBOX), 1|0 (CHECKBOX), size (OVERDRAWBLOB, return)
Types:
o TEXT TEXTMULTILINE INTEGER(32b) FLOAT(32b-80b) HYPERLINK CHECKBOX COMBOBOX FORMULA GRAPH
o OWNERDRAWINTEGER - Ownerdraw integer. You can implement D (draw) event.
o OWNERDRAWBLOB - Ownerdraw BLOB. You can put any binary data as cell's BLOB content. There is special support for textual BLOBs.
o EMPTY - The cell contains formatting only.
o COLHDR ROWHDR WINHDR - Column, row and window (splitt) header.
o EXPANDED - Part of expanded cell, internally used.
Type Modifiers:
BUTTON - The cell contains button. Can be combined with TEXT or TEXTMULTILINE.
WIDEBUTTON - The cell will be entirely covered by button. Can be combined with TEXT or TEXTMULTILINE.
DATE - Can be combined with INTEGER.
FORCETYPE - The cell will preserve its type when edited.
Can be combined with TEXT, INTEGER, FLOAT, TEXTMULTILINE, BUTTON, WIDEBUTTON or HYPERLINK.
FIXEDSIZE - Will force a 15 by 15 pixel image. To be combined with BUTTON, CHECKBOX or COMBOBOX.
Can be combined with BUTTON, CHECKBOX or COMBOBOX .
States:
LOCKED - Cell is locked for editing.
HIDDEN - Cell content is not displayed.
REDRAW - Cell is being redrawn.
RECALC - Cell is being recalculated.
ERROR - There are 4 error states: ERROR DIV0 UNDERFLOW OVERFLOW.
Aligments:
LEFT RIGHT MIDDLE - X aligments.
TOP CENTER BOTTOM - Y aligments.
AUTO - Text left middle, numbers right middle.
GLOBAL - If you omit aligment attribute, this one will be used.
*/
SS_SetCell(hCtrl, Col="", Row="", o1="", o2="", o3="", o4="", o5="", o6="", o7="", o8="", o9="", o10="", o11=""){
static SPRM_SETCELLDATA=0x483, SPRM_GETCELLDATA=0x482, SPRM_GETCELLTYPE=0x48F, WM_DRAWITEM := 0x02B, initOverDraw
static EMPTY=0, COLHDR=1, ROWHDR=2, WINHDR=3, TEXT=4, TEXTMULTILINE=5, INTEGER=6, FLOAT=7, FORMULA=8, GRAPH=9, HYPERLINK=10, CHECKBOX=11, COMBOBOX=12, OWNERDRAWBLOB=13, OWNERDRAWINTEGER=14, BUTTON=16, WIDEBUTTON=0x20, DATE=0x30, FORCETEXT=0x44, FORCETYPE=0x40, FIXEDSIZE=0x80
static SPRIF_TYPE=0x40,SPRIF_DATA=0x200,SPRIF_WIDTH=0x80,SPRIF_BACKCOLOR=1,SPRIF_TEXTCOLOR=2,SPRIF_TEXTALIGN=4,SPRIF_HEIGHT=0x100,SPRIF_STATE=0x20,SPRIF_FONT=0x10,SPRIF_IMAGEALIGN=8,SPRIF_COMPILE=0x80000000, SPRIF_DOUBLE=0x400, SPRIF_SINGLE=0x800
static TOP=0, LEFT=0x10, CENTER=0x20, RIGHT=0x30, MIDDLE=0x40, BOTTOM=0x80, GLOBAL=0xF0, ALL=13, SCI=14 ;aligments
static LOCKED=1, HIDDEN=2, REDRAW=8
;named parameters: txt, data, w, h, bg, fg, type, state, txtal, imgal, fnt
txt := "~`a "
loop, 10 {
ifEqual, o%A_Index%,,break
j := InStr( o%A_index%, "=" ), prop := SubStr( o%A_index%, 1, j-1 ), %prop% := SubStr( o%A_index%, j+1, StrLen(o%A_Index%))
if prop in type,state,imgal,txtal
{
p := "h" prop, s := %prop%, %p% := 0
loop, parse, s, %A_Tab%%A_Space%
if A_LoopField is integer
%p% |= A_LoopField
else %p% |= %A_LOOPFIELD%
}
}
flag := 0
,flag |= (data!=""||txt!="~`a ") ? SPRIF_DATA : 0
,flag |= (type!="") ? SPRIF_TYPE : 0
,flag |= (w != "") ? SPRIF_WIDTH : 0
,flag |= (h != "") ? SPRIF_HEIGHT : 0
,flag |= (bg!= "") ? SPRIF_BACKCOLOR : 0
,flag |= (fg!= "") ? SPRIF_TEXTCOLOR : 0
,flag |= (state !="") ? SPRIF_STATE : 0
,flag |= (txtal != "") ? SPRIF_TEXTALIGN : 0
,flag |= (imgal != "") ? SPRIF_IMAGEALIGN : 0
,flag |= (fnt != "") ? SPRIF_FONT : 0
VarSetCapacity(ITEM, 40, 0), NumPut(Col, ITEM, 4), NumPut(Row, ITEM, 8)
if type = ;user is changing the cell
{
bChange := true
SendMessage,SPRM_GETCELLTYPE,Col,Row,, ahk_id %hCtrl%
hType := ErrorLevel
}
type := hType & ~0xF0 ;get the base type
if type in %FORMULA%,%GRAPH%
flag |= SPRIF_COMPILE
if type = %FLOAT%
flag |= SPRIF_SINGLE, NumPut(txt, txt, 0, "Float")
if type in %INTEGER%,%OWNERDRAWINTEGER%
NumPut(txt,txt)
if type in %OWNERDRAWINTEGER%,%OWNERDRAWBLOB%
{
if !initOverDraw
{
old := OnMessage(WM_DRAWITEM, "SS_onDrawItem")
if old != SS_onDrawItem
SS("oldDrawItem", RegisterCallback(old))
}
if type=%OWNERDRAWBLOB%
data := StrLen(txt)+3 ;first word is size of the blob + 1 for \0 of txt.
}
if type in %COMBOBOX%,%CHECKBOX%,%OWNERDRAWBLOB%
{
; in this case both txt and data must be set at the same time, so if user didn't provide one, get it.
if (bChange && (txt="~`a " || data=""))
{
NumPut(SPRIF_DATA, ITEM)
SendMessage,SPRM_GETCELLDATA,,&ITEM,, ahk_id %hCtrl%
pData := NumGet(ITEM, 36)
if (data != "")
txt := type=COMBOBOX ? NumGet(pData+4) : SS_strAtAdr(pData + 4)
else data := NumGet(pData,36)
}
ifEqual, txt, ~`a , SetEnv, txt
if (type = COMBOBOX)
NumPut(txt,txt) ;put combobox handle as txt
txt := "1234" txt, NumPut(data, txt) ;make the room for the data and insert index
}
NumPut(flag, ITEM)
NumPut(hState,ITEM, 14)
;FORMAT struct
NumPut(bg, ITEM, 16)
NumPut(fg, ITEM, 20)
NumPut(htxtal,ITEM, 24,"UChar")
NumPut(himgal,ITEM, 25,"UChar")
NumPut(fnt, ITEM, 26,"UChar")
NumPut(hType, ITEM, 27,"UChar")
NumPut(w, ITEM, 28)
NumPut(h, ITEM, 32)
NumPut(&txt, ITEM, 36)
SendMessage,SPRM_SETCELLDATA,,&ITEM,, ahk_id %hCtrl%
return ErrorLevel
}
/*
Function: SetCellData
Set the data of the cell.
Parameters:
Data - Data to set.
Col,Row - Cell coordinates. If omited current cell will be used.
*/
SS_SetCellData(hCtrl, Data, Col="", Row="") {
static SPRM_SETCELLDATA=0x483, SPRM_GETCELLDATA=0x482, SPRIF_DATA=0x200, init
if !init
init++, VarSetCapacity(ITEM, 40, 0), NumPut(SPRIF_DATA, ITEM)
if Col=
SS_GetCurrentCell(hCtrl, Col, Row)
NumPut(Col, ITEM, 4), NumPut(Row, ITEM, 8)
SendMessage,SPRM_GETCELLDATA,,&ITEM,, ahk_id %hCtrl%
NumPut( Data, NumGet(ITEM, 36)+0)
SendMessage,SPRM_SETCELLDATA,,&ITEM,, ahk_id %hCtrl%
}
/*
Function: SetCellBLOB
Set the cell binary data.
Parameters:
BLOB - Reference to binary data to set. First word contains BLOB size.
Col, Row - Cell coordinates. If omited current cell coordinates will be used.
*/
SS_SetCellBLOB(hCtrl, ByRef BLOB, Col="", Row="") {
static SPRM_SETCELLDATA=0x483, SPRIF_DATA=0x200, init
if !init
init++, VarSetCapacity(ITEM, 40, 0), NumPut(SPRIF_DATA, ITEM)
if Col=
SS_GetCurrentCell(hCtrl, Col, Row)
NumPut(Col, ITEM, 4), NumPut(Row, ITEM, 8), NumPut(&BLOB, ITEM, 36)
SendMessage,SPRM_SETCELLDATA,,&ITEM,, ahk_id %hCtrl%
return ErrorLevel
}
/*
Function: SetCellString
Set the text of the selected cell.
Parameters:
Txt - Text to set, by default empty.
Type - Type. If omited current cell type will be used.
*/
SS_SetCellString(hCtrl, Txt="", Type=""){
static SPRM_SETCELLSTRING=0x47D ; wParam=type, lParam=pointer to string.
if Type=
Type := SS_GetCellType(hCtrl, "", "", 1)
SendMessage,SPRM_SETCELLSTRING,Type,&txt,, ahk_id %hCtrl%
return ERRORLEVEL
}
/*
Function: SetColWidth
Set column width.
*/
SS_SetColWidth(hCtrl, Col, Width){
static SPRM_SETCOLWIDTH=0x47F
SendMessage,SPRM_SETCOLWIDTH,Col,Width,, ahk_id %hCtrl%
return ERRORLEVEL
}
/*
Function: SetCurrentCell
Set current cell in the active window.
Parameters: