-
Notifications
You must be signed in to change notification settings - Fork 71
/
EditControl.ahk
1952 lines (1742 loc) · 52.7 KB
/
EditControl.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: Edit Library v1.1
Group: Introduction
This library is designed for use on the standard edit control.
Group: Issues/Consideration
A few considerations...
- Although many of the functions work on all types of edit
controls -- single-line, multiline, and combo boxes (contains a single-line
edit control) -- there are several functions that only work on one type of
edit control. See the documentation for each function for more information.
- AutoHotkey supports the creation and manipulation of the standard edit
control. For this reason, there are a small number functions that were
intentionally left out of this library because they provide no additional
value to what the standard AutoHotkey commands provide.
- The edit control does not support several key messages that are needed by
this library. Absent messages include EM_GETSELTEXT, EM_GETTEXTRANGE, and
EM_FINDTEXT. These messages have been replaced with AutoHotkey commands or
with other messages. Although the substitute code/messages are very
capable, they are not quite as efficient (memory and/or speed) as the
messages they replace (if they existed). These inefficiencies are not
really noticable if the control only contains a limited amount of text
(~512K or less), but they become more pronounced with increasing text sizes.
Efficiency also depends on the where work in the control is being done. For
example, extracting text from the top of the control uses less resources
that extracting text from the end of the control.
Group: Credit
This library was inspired by the Edit mini-library created by *Lexikos* and
the HiEditor library created by *majkinetor*. Some of the syntax and code
ideas were extracted from these libraries. Thank to these authors for
sharing their work.
Group: Functions
*/
;-----------------------------
;
; Function: Edit_CanUndo
;
; Description:
;
; Returns TRUE if there are any actions in the edit control's undo queue,
; otherwise FALSE.
;
;
;-------------------------------------------------------------------------------
Edit_CanUndo(hEdit) {
Static EM_CANUNDO:=0xC6
SendMessage EM_CANUNDO,0,0,,ahk_id %hEdit%
Return ErrorLevel
}
;-----------------------------
;
; Function: Edit_CharFromPos
;
; Description:
;
; Gets information about the character and/or line closest to a specified
; point in the the client area of the edit control.
;
;
; Parameters:
;
; X, Y - The coordinates of a point in the edit control's client area
; relative to the upper-left corner of the client area.
;
; r_CharPos - The zero-based index of the character nearest the specified
; point. [Optional] This index is relative to the beginning of the
; control, not the beginning of the line. If the specified point is beyond
; the last character in the edit control, the return value indicates the
; last character in the control. See the Remarks section for more
; information.
;
; r_LineIdx - Zero-based index of the line that contains the character.
; [Optional] For single-line edit controls, this value is zero. The index
; indicates the line delimiter if the specified point is beyond the last
; visible character in a line. See the Remarks section for more
; information.
;
;
; Returns:
;
; The value of the r_CharPos variable.
;
;
; Remarks:
;
; If the specified point is outside the bounds of the edit control, all output
; variables (Return, r_CharPos, and r_LineIdx) are set to -1.
;
;-------------------------------------------------------------------------------
Edit_CharFromPos(hEdit,X,Y,ByRef r_CharPos="",ByRef r_LineIdx="") {
Static EM_CHARFROMPOS:=0xD7
SendMessage EM_CHARFROMPOS,0,(Y<<16)|X,,ahk_id %hEdit%
;-- Out of bounds?
if (ErrorLevel=0xFFFFFFFF)
{
r_CharPos:=-1
r_LineIdx:=-1
Return r_CharPos
}
;-- Extract values (UShort)
r_CharPos:=ErrorLevel & 0xFFFF ;-- LOWORD
r_LineIdx:=ErrorLevel>>16 ;-- HIWORD
;-- Convert to UInt using known UInt values as reference
FirstLine:=Edit_GetFirstVisibleLine(hEdit)-1
if (FirstLine>r_LineIdx)
r_LineIdx:=r_LineIdx+(65536*Floor((FirstLine+(65535-r_LineIdx))/65536))
FirstCharPos:=Edit_LineIndex(hEdit,FirstLine<0 ? 0:FirstLine)
if (FirstCharPos>r_CharPos)
r_CharPos:=r_CharPos+(65536*Floor((FirstCharPos+(65535-r_CharPos))/65536))
Return r_CharPos
}
;-----------------------------
;
; Function: Edit_Clear
;
; Description:
;
; Delete (clear) the current selection, if any, from the edit control.
;
;
; Remarks:
;
; Undo can be used to reverse this action.
;
;-------------------------------------------------------------------------------
Edit_Clear(hEdit) {
Static WM_CLEAR:=0x303
SendMessage WM_CLEAR,0,0,,ahk_id %hEdit%
}
;-----------------------------
;
; Function: Edit_Convert2DOS
;
; Description:
;
; Converts Unix, DOS/Unix mix, and Mac file formats to DOS format.
;
;-------------------------------------------------------------------------------
Edit_Convert2DOS(p_Text) {
StringReplace p_Text,p_Text,`r`n,`n,All ;-- Convert DOS to Unix
StringReplace p_Text,p_Text,`r,`n,All ;-- Convert Mac to Unix
StringReplace p_Text,p_Text,`n,`r`n,All ;-- Convert Unix to DOS
Return p_Text
}
;-----------------------------
;
; Function: Edit_Convert2Mac
;
; Description:
;
; Convert DOS, DOS/Unix mix, and Unix file formats to Mac format.
;
;-------------------------------------------------------------------------------
Edit_Convert2Mac(p_Text) {
StringReplace p_Text,p_Text,`r`n,`r,All ;-- Convert DOS to Mac
StringReplace p_Text,p_Text,`n,`r,All ;-- Convert Unix to Mac
if StrLen(p_Text)
if p_Text not Contains `r
p_Text .= "`r"
Return p_Text
}
;-----------------------------
;
; Function: Edit_Convert2Unix
;
; Description:
;
; Convert DOS, DOS/Unix mix, and Mac formats to Unix format.
;
;-------------------------------------------------------------------------------
Edit_Convert2Unix(p_Text) {
StringReplace p_Text,p_Text,`r`n,`n,All ;-- Convert DOS to Unix
StringReplace p_Text,p_Text,`r,`n,All ;-- Convert Mac to Unix
if StrLen(p_Text)
if p_Text not Contains `n
p_Text .= "`n"
Return p_Text
}
;-----------------------------
;
; Function: Edit_ConvertCase
;
; Description:
;
; Convert case of selected text.
;
;
; Parameters:
;
; p_Case - Set to "Upper", "Lower", "Capitalize", or "Toggle".
;
;-------------------------------------------------------------------------------
Edit_ConvertCase(hEdit,p_Case)
{
;-- Collect current select postions
Edit_GetSel(hEdit,l_StartSelPos,l_EndSelPos)
if (l_StartSelPos=l_EndSelPos) ;-- Nothing selected
Return
;-- Collect selected text
l_SelectedText:=Edit_GetSelText(hEdit)
if l_SelectedText is Space
Return
;-- Convert
if p_Case in U,Upper,Uppercase
StringUpper l_SelectedText,l_SelectedText
else
if p_Case in L,Lower,Lowercase
StringLower l_SelectedText,l_SelectedText
else
if p_Case in C,Capitalize,Title,TitleCase
StringLower l_SelectedText,l_SelectedText,T
else
if p_Case in T,Toggle,ToggleCase,I,Invert,InvertCase
{
t_SelectedText=
Loop Parse,l_SelectedText
{
t_Char:=A_LoopField
l_Asc:=Asc(t_Char)
if l_Asc between 65 and 90
t_Char:=Chr(l_Asc+32)
else
if l_Asc between 97 and 122
t_Char:=Chr(l_Asc-32)
t_SelectedText .= t_Char
}
l_SelectedText:=t_SelectedText
}
;-- Replace selected text with converted text
Edit_ReplaceSel(hEdit,l_SelectedText)
;-- Reselect to the user's original positions
Edit_SetSel(hEdit,l_StartSelPos,l_EndSelPos)
}
;-----------------------------
;
; Function: Edit_Copy
;
; Description:
;
; Copy the current selection to the clipboard in CF_TEXT format.
;
;-------------------------------------------------------------------------------
Edit_Copy(hEdit)
{
Static WM_COPY:=0x301
SendMessage WM_COPY,0,0,,ahk_id %hEdit%
}
;-----------------------------
;
; Function: Edit_Cut
;
; Description:
;
; Delete the current selection, if any, and copy the deleted text to the
; clipboard in CF_TEXT format.
;
;-------------------------------------------------------------------------------
Edit_Cut(hEdit)
{
Static WM_CUT:=0x300
SendMessage WM_CUT,0,0,,ahk_id %hEdit%
}
;-----------------------------
;
; Function: Edit_EmptyUndoBuffer
;
; Description:
;
; Resets the undo flag of the edit control. The undo flag is set whenever an
; operation within the edit control can be undone.
;
;-------------------------------------------------------------------------------
Edit_EmptyUndoBuffer(hEdit)
{
Static EM_EMPTYUNDOBUFFER:=0xCD
SendMessage EM_EMPTYUNDOBUFFER,0,0,,ahk_id %hEdit%
}
;-----------------------------
;
; Function: Edit_FindText
;
; Description:
;
; Find text within the edit control.
;
;
; Parameters:
;
; p_SearchText - Search text.
;
; p_Min, p_Max - Zero-based search range within the edit control. p_Min is
; the character index of the first character in the range and p_Max is the
; character index immediately following the last character in the range.
; (Ex: To search the first 5 characters of the text, set p_Min to 0 and
; p_Max to 5) Set p_Max to -1 to search to the end of the text. To search
; backward, the roles and descriptions of the p_Min and p_Max are
; reversed. (Ex: To search the first 5 characters of the control in
; reverse, set p_Min to 5 and p_Max to 0)
;
; p_Flags - Valid flags are as follows:
;
; (Start code)
; Flag Description
; ---- -----------
; MatchCase Search is case sensitive. This flag is ignored if the
; "RegEx" flag is also defined.
;
; RegEx Regular expression search.
;
; Static [Advanced feature]
; Text collected from the edit control remains in memory is
; used to satisfy the search request. The text remains in
; memory until the "Reset" flag is used or until the
; "Static" flag is not used.
;
; Advantages: Search time is reduced 10 to 60 percent
; (or more) depending on the size of the text in the control.
; There is no speed increase on the first use of the "Static"
; flag.
;
; Disadvantages: Any changes in the edit control are not
; reflected in the search.
;
; Bottom line: Don't use this flag unless performing multiple
; search requests on a control that will not be modified
; while searching.
;
;
; Reset [Advanced feature]
; Clears the saved text created by the "Static" flag so that
; the next use of the "Static" flag will get the text directly
; from the edit control. To clear the saved memory without
; performing a search, use the following syntax:
;
; Edit_FindText("","",0,0,"Reset")
; (end)
;
;
; r_RegExOutput - Variable that contains the part of the source text that
; matched the RegEx pattern. [Optional]
;
;
; Returns:
;
; Zero-based character index of the first character of the match or -1 if
; no match is found.
;
;
; Programming Notes:
;
; Searching using regular expressions (RegEx) can produce results that have a
; dynamic number of characters. For this reason, searching for the "next"
; pattern (forward or backward) may produce different results from developer
; developer depending on how values of p_Min and p_Max are determined.
;
;-------------------------------------------------------------------------------
Edit_FindText(hEdit,p_SearchText,p_Min=0,p_Max=-1,p_Flags="",ByRef r_RegExOut="")
{
Static s_Text
;-- Initialize
r_RegExOut:=""
if InStr(p_Flags,"Reset")
s_Text:=""
;-- Anything to search?
if StrLen(p_SearchText)=0
Return -1
l_MaxLen:=Edit_GetTextLength(hEdit)
if (l_MaxLen=0)
Return -1
;-- Parameters
if (p_Min<0 or p_Max>l_MaxLen)
p_Min:=l_MaxLen
if (p_Max<0 or p_Max>l_MaxLen)
p_Max:=l_MaxLen
;-- Anything to search?
if (p_Min=p_Max)
Return -1
;-- Get text
if InStr(p_Flags,"Static")
{
if StrLen(s_Text)=0
s_Text:=Edit_GetText(hEdit)
l_Text:=SubStr(s_Text,(p_Max>p_Min) ? p_Min+1:p_Max+1,(p_Max>p_Min) ? p_Max:p_Min)
}
else
{
s_Text:=""
l_Text:=Edit_GetTextRange(hEdit,(p_Max>p_Min) ? p_Min:p_Max,(p_Max>p_Min) ? p_Max:p_Min)
}
;-- Look for it
if InStr(p_Flags,"RegEx")=0 ;-- Not RegEx
l_FoundPos:=InStr(l_Text,p_SearchText,InStr(p_Flags,"MatchCase"),(p_Max>p_Min) ? 1:0)-1
else ;-- RegEx
{
p_SearchText:=RegExReplace(p_SearchText,"^P\)?","",1) ;-- Remove P or P)
if (p_Max>p_Min) ;-- Search forward
{
l_FoundPos:=RegExMatch(l_Text,p_SearchText,r_RegExOut,1)-1
if ErrorLevel
{
outputdebug,
(ltrim join`s
Function: %A_ThisFunc% - RegExMatch error.
ErrorLevel=%ErrorLevel%
)
l_FoundPos:=-1
}
}
else ;-- Search backward
{
;-- Programming notes:
;
; - The first search begins from the user-defined minimum
; position. This will establish the true minimum position to
; begin search calculations. If nothing is found, no
; additional searching is necessary.
;
; - The RE_MinPos, RE_MaxPos, and RE_StartPos variables contain
; 1-based values.
;
RE_MinPos :=1
RE_MaxPos :=StrLen(l_Text)
RE_StartPos :=RE_MinPos
Saved_FoundPos:=-1
Saved_RegExOut:=""
loop
{
;-- Positional search. Last found match (if any) wins
l_FoundPos:=RegExMatch(l_Text,p_SearchText,r_RegExOut,RE_StartPos)-1
if ErrorLevel
{
outputdebug,
(ltrim join`s
Function: %A_ThisFunc% - RegExMatch error.
ErrorLevel=%ErrorLevel%
)
l_FoundPos:=-1
Break
}
;-- If found, update saved and RE_MinPos, else update RE_MaxPos
if (l_FoundPos>-1)
{
Saved_FoundPos:=l_FoundPos
Saved_RegExOut:=r_RegExOut
RE_MinPos :=l_FoundPos+2
}
else
RE_MaxPos:=RE_StartPos-1
;-- Are we done?
if (RE_MinPos>RE_MaxPos or RE_MinPos>StrLen(l_Text))
{
l_FoundPos:=Saved_FoundPos
r_RegExOut:=Saved_RegExOut
Break
}
;-- Calculate new start position
RE_StartPos:=RE_MinPos+Floor((RE_MaxPos-RE_MinPos)/2)
}
}
}
;-- Adjust FoundPos
if (l_FoundPos>-1)
l_FoundPos += (p_Max>p_Min) ? p_Min:p_Max
Return l_FoundPos
}
;--- Clears the saved text created by the "Static" flag.
Edit_FindTextReset()
{
Edit_FindText("","",0,0,"Reset")
}
;-----------------------------
;
; Function: Edit_FmtLines
;
; Description:
;
; Sets a flag that determines whether a multiline edit control includes soft
; line-break characters. A soft line break consists of two carriage returns
; and a line feed and is inserted at the end of a line that is broken because
; of word wrapping.
;
;
; Parameters:
;
; p_Flag - Set to TRUE to insert soft line-break characters characters, FALSE
; to removes them.
;
;
; Returns:
;
; The value of p_Flag.
;
;
; Remarks:
;
; This message has no effect on the display of the text within the edit
; control. It affects the buffer returned by the EM_GETHANDLE message and
; the text returned by the WM_GETTEXT message. Since the WM_GETTEXT message
; is used by other functions in this library, be sure to un-format the text as
; soon as possible. Example of use:
;
; (Start code)
; Edit_FmtLines(hEdit,True)
; FormattedText:=Edit_GetText(hEdit)
; Edit_FmtLines(hEdit,False)
; (end)
;
;-------------------------------------------------------------------------------
Edit_FmtLines(hEdit,p_Flag)
{
Static EM_FMTLINES:=0xC8
SendMessage EM_FMTLINES,p_Flag,0,,ahk_id %hEdit%
Return ErrorLevel
}
;-----------------------------
;
; Function: Edit_GetFirstVisibleLine
;
; Description:
;
; Returns the zero-based index of the uppermost visible line. For single-line
; edit controls, the return value is the zero-based index of the first visible
; character.
;
;-------------------------------------------------------------------------------
Edit_GetFirstVisibleLine(hEdit)
{
Static EM_GETFIRSTVISIBLELINE:=0xCE
SendMessage EM_GETFIRSTVISIBLELINE,0,0,,ahk_id %hEdit%
Return ErrorLevel
}
;-----------------------------
;
; Function: Edit_GetLastVisibleLine
;
; Description:
;
; Returns the zero-based line index of the last visible line on the edit
; control.
;
;
; Remarks:
;
; To calculate the total number of visible lines, use the following...
;
; (start code)
; Edit_GetLastVisibleLine(hEdit) - Edit_GetFirstVisibleLine(hEdit) + 1
; (end)
;
;-------------------------------------------------------------------------------
Edit_GetLastVisibleLine(hEdit)
{
Edit_GetRect(hEdit,Left,Top,Right,Bottom)
Return Edit_LineFromPos(hEdit,0,Bottom-1)
}
;-----------------------------
;
; Function: Edit_GetLimitText
;
; Description:
;
; Returns the current text limit for the edit control.
;
;
; Remarks:
;
; Windows NT+: The maximum text length is 0x7FFFFFFE characters for
; single-line edit controls and -1 for multiline edit controls.
;
;-------------------------------------------------------------------------------
Edit_GetLimitText(hEdit)
{
Static EM_GETLIMITTEXT:=0xD5
SendMessage EM_GETLIMITTEXT,0,0,,ahk_id %hEdit%
Return ErrorLevel<<32>>32
}
;-----------------------------
;
; Function: Edit_GetLine
;
; Description:
;
; Get the text of the desired line from the edit control.
;
;
; Parameters:
;
; p_LineIdx - The zero-based index of the line to retrieve. [Optional] Use
; -1 (the default) to get the current line. This parameter is ignored if
; used for a single-line edit control.
;
; p_Length - Length of the line or length of the text to be extracted.
; [Optional] Use -1 (the default) to automatically determine the length
; of the line.
;
;
; Returns:
;
; The text of the specified line. The return value is an empty string if the
; line number specified by the p_LineIdx parameter is greater than the number
; of lines in the Edit control.
;
;-------------------------------------------------------------------------------
Edit_GetLine(hEdit,p_LineIdx=-1,p_Length=-1)
{
Static EM_GETLINE:=0xC4
if (p_LineIdx<0)
p_LineIdx:=Edit_LineFromChar(hEdit,Edit_LineIndex(hEdit))
if (p_Length>-1)
l_Length:=p_Length
else
l_Length:=Edit_LineLength(hEdit,p_LineIdx)
if l_Length=0
Return
VarSetCapacity(l_Text,l_Length=1 ? 2:l_Length,0)
NumPut(l_Length=1 ? 2:l_Length,l_Text,0,"UShort")
SendMessage EM_GETLINE,p_LineIdx,&l_Text,,ahk_id %hEdit%
Return l_Length=1 ? SubStr(l_Text,1,1):l_Text
}
;-----------------------------
;
; Function: Edit_GetLineCount
;
; Description:
;
; Returns an integer specifying the total number of text lines in a multiline
; edit control. If the control has no text, the return value is 1. The
; return value will never be less than 1.
;
;
; Remarks:
;
; The value returned is for the number of lines in the edit control. Very long
; lines (>1024) or word wrap may introduce additional lines to the control.
;
;-------------------------------------------------------------------------------
Edit_GetLineCount(hEdit)
{
Static EM_GETLINECOUNT:=0xBA
SendMessage EM_GETLINECOUNT,0,0,,ahk_id %hEdit%
Return ErrorLevel
}
;-----------------------------
;
; Function: Edit_GetMargins
;
; Description:
;
; Gets the widths of the left and right margins for the edit control. If
; defined, these values are returned in the r_LeftMargin and r_RightMargin
; variables.
;
;
; Parameters:
;
; r_LeftMargin - Left margin, in pixels. [Optional]
; r_RightMargin - Right margin, in pixels. [Optional]
;
;
; Returns:
;
; The edit control's left margin
;
;-------------------------------------------------------------------------------
Edit_GetMargins(hEdit,ByRef r_LeftMargin="",ByRef r_RightMargin="") {
Static EM_GETMARGINS:=0xD4
SendMessage EM_GETMARGINS,0,0,,ahk_id %hEdit%
r_LeftMargin :=ErrorLevel & 0xFFFF ;-- LOWORD of result
r_RightMargin:=ErrorLevel>>16 ;-- HIWORD of result
Return r_LeftMargin ; ##### --------------------------------------- Really?
}
;-----------------------------
;
; Function: Edit_GetModify
;
; Description:
;
; Gets the state of the edit control's modification flag. The flag indicates
; whether the contents of the edit control have been modified. Returns TRUE
; if the control has been modified, otherwise FALSE.
;
;-------------------------------------------------------------------------------
Edit_GetModify(hEdit)
{
Static EM_GETMODIFY:=0xB8
SendMessage EM_GETMODIFY,0,0,,ahk_id %hEdit%
Return ErrorLevel
}
;-----------------------------
;
; Function: Edit_GetRect
;
; Description:
;
; Gets the formatting rectangle of the edit control.
;
;
; Parameters:
;
; r_Left..r_Bottom - Output variables. [Optional]
;
;
; Returns:
;
; Space separated rectangle.
;
;-------------------------------------------------------------------------------
Edit_GetRect(hEdit,ByRef r_Left="",ByRef r_Top="",ByRef r_Right="",ByRef r_Bottom="")
{
Static EM_GETRECT:=0xB2
VarSetCapacity(RECT_Structure,16,0)
SendMessage EM_GETRECT,0,&RECT_Structure,,ahk_id %hEdit%
r_Left :=NumGet(RECT_Structure,0,"Int")
r_Top :=NumGet(RECT_Structure,4,"Int")
r_Right :=NumGet(RECT_Structure,8,"Int")
r_Bottom:=NumGet(RECT_Structure,12,"Int")
Return r_Left . A_Space . r_Top . A_Space . r_Right . A_Space . r_Bottom
}
;-----------------------------
;
; Function: Edit_GetSel
;
; Description:
;
; Gets the starting and ending character positions of the current selection in
; the edit control. If defined, these values are returned in
; the r_StartSelPos and r_EndSelPos variables.
;
;
; Parameters:
;
; r_StartSelPos - Starting position of the selection. [Optional]
; r_EndSelPos - Ending position of the selection. [Optional]
;
;
; Returns:
;
; Starting position of the selection.
;
;-------------------------------------------------------------------------------
Edit_GetSel(hEdit,ByRef r_StartSelPos="",ByRef r_EndSelPos="")
{
Static EM_GETSEL:=0xB0
VarSetCapacity(l_StartSelPos,4,0)
VarSetCapacity(l_EndSelPos,4,0)
SendMessage EM_GETSEL,&l_StartSelPos,&l_EndSelPos,,ahk_id %hEdit%
r_StartSelPos:=NumGet(l_StartSelPos)
r_EndSelPos :=NumGet(l_EndSelPos)
Return r_StartSelPos
}
;-----------------------------
;
; Function: Edit_GetSelText
;
; Description:
;
; Returns the currently selected text (if any).
;
;
; Remarks:
;
; Since the edit control does not support the EM_GETSELTEXT message, the
; EM_GETLINE (if the selection is on one line) and the WM_GETTEXT messages are
; used instead.
;
;-------------------------------------------------------------------------------
Edit_GetSelText(hEdit)
{
Edit_GetSel(hEdit,l_StartSelPos,l_EndSelPos)
if (l_StartSelPos=l_EndSelPos)
Return
;-- Get line indexes of the selection
l_FirstSelectedLine:=Edit_LineFromChar(hEdit,l_StartSelPos)
l_LastSelectedLine :=Edit_LineFromChar(hEdit,l_EndSelPos)
;-- Get selected text
l_FirstPos:=Edit_LineIndex(hEdit,l_FirstSelectedLine)
if (l_FirstSelectedLine=l_LastSelectedLine)
and (l_EndSelPos<=l_FirstPos+Edit_LineLength(hEdit,l_FirstSelectedLine))
Return SubStr(Edit_GetLine(hEdit,l_FirstSelectedLine,l_EndSelPos-l_FirstPos),l_StartSelPos-l_FirstPos+1)
else
Return SubStr(Edit_GetText(hEdit,l_EndSelPos),l_StartSelPos+1)
}
;-----------------------------
;
; Function: Edit_GetText
;
; Description:
;
; Returns all text from the control up to p_Length length. If p_Length=-1
; (the default), all text is returned.
;
;
; Remarks:
;
; This function is similar to the AutoHotkey *GUIControlGet* command (for AHK
; GUI's) and the *ControlGetText* command except that end-of-line (EOL)
; characters from the retrieved text are not automatically converted
; (CR+LF to LF). If needed, use the <Edit_Convert2Unix> function to convert
; the text to the AutoHotkey text format.
;
;-------------------------------------------------------------------------------
Edit_GetText(hEdit,p_Length=-1)
{
Static WM_GETTEXT:=0xD
if (p_Length<0)
p_Length:=Edit_GetTextLength(hEdit)
VarSetCapacity(l_Text,p_Length+1,0)
SendMessage WM_GETTEXT,p_Length+1,&l_Text,,ahk_id %hEdit%
return l_Text
}
;-----------------------------
;
; Function: Edit_GetTextLength
;
; Description:
;
; Returns the length, in characters, of the text in the edit control.
;
;-------------------------------------------------------------------------------
Edit_GetTextLength(hEdit)
{
Static WM_GETTEXTLENGTH:=0xE
SendMessage WM_GETTEXTLENGTH,0,0,,ahk_id %hEdit%
Return ErrorLevel
}
;-----------------------------
;
; Function: Edit_GetTextRange
;
; Description:
;
; Get a range of characters.
;
;
; Parameters:
;
; p_Min - Character position index immediately preceding the first character
; in the range.
;
; p_Max - Character position immediately following the last character in the
; range. Set to -1 to indicate the end of the text.
;
;
; Remarks:
;
; Since the edit control does not support the EM_GETTEXTRANGE message, the
; <Edit_GetText> function (WM_GETTEXT message) is used to collect the desired
; range of characters.
;
;-------------------------------------------------------------------------------
Edit_GetTextRange(hEdit,p_Min=0,p_Max=-1)
{
Return SubStr(Edit_GetText(hEdit,p_Max),p_Min+1)
}
;-----------------------------
;
; Function: Edit_IsMultiline
;
; Description:
;
; Returns TRUE if the edit control is multiline, otherwise FALSE.
;
;-------------------------------------------------------------------------------
Edit_IsMultiline(hEdit)
{
Static ES_MULTILINE:=0x4
Return Edit_IsStyle(hEdit,ES_MULTILINE)
}
;-----------------------------
;
; Function: Edit_IsReadOnly
;
; Description:
;
; Returns TRUE if the ES_READONLY style has been set, otherwise FALSE.
;
;-------------------------------------------------------------------------------
Edit_IsReadOnly(hEdit) {
Static ES_READONLY:=0x800