forked from Ixiko/AHK-libs-and-classes-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdit.ahk
4060 lines (3686 loc) · 113 KB
/
Edit.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 v2.0
Group: Introduction
This library is designed for use on the standard Edit control.
Group: Issues/Consideration
A few considerations...
* Some of functions are only for use on single-line Edit controls and some
are only for use on multiline Edit controls. See the documentation for each
function for any restrictions.
* 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. Thanks to these authors for
sharing their work.
Group: Functions
*/
;-----------------------------
;
; Function: Edit_ActivateParent
;
; Description:
;
; Activates (makes foremost) the parent window of the Edit control if needed.
; If the window is minimized, it is automatically restored prior to being
; activated.
;
; Returns:
;
; TRUE if successful, or FALSE otherwise.
;
; Remarks:
;
; This function only actives the parent window of the Edit control. It does
; not give focus to the Edit control. If needed, call <Edit_SetFocus> instead
; of (or in addition to) this function.
;
;-------------------------------------------------------------------------------
Edit_ActivateParent(hEdit)
{
;-- Get handle to the parent window
hParent:=DllCall("GetParent","Ptr",hEdit,"Ptr")
;-- Activate if needed
IfWinNotActive ahk_id %hParent%
{
WinActivate ahk_id %hParent%
;-- Still not active? (relatively rare)
IfWinNotActive ahk_id %hParent%
{
;-- Give the window an additional 250 ms to activate
WinWaitActive ahk_id %hParent%,,0.25
if ErrorLevel
Return False
}
}
Return True
}
;-----------------------------
;
; 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 - [Output] 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 - [Output] 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.
;
; Calls To Other Functions:
;
; * <Edit_GetFirstVisibleLine>
; * <Edit_LineIndex>
;
; Remarks:
;
; If the specified point is outside the bounds of the Edit control, the
; return value and all output variables (r_CharPos and r_LineIdx) are set to
; -1.
;
;-------------------------------------------------------------------------------
Edit_CharFromPos(hEdit,X,Y,ByRef r_CharPos="",ByRef r_LineIdx="")
{
Static Dummy3902
;-- Messages
,EM_CHARFROMPOS :=0xD7
,EM_GETFIRSTVISIBLELINE:=0xCE
,EM_LINEINDEX :=0xBB
;-- Collect character position from coordinates
SendMessage EM_CHARFROMPOS,0,(Y<<16)|X,,ahk_id %hEdit%
;-- Out of bounds?
if (ErrorLevel<<32>>32=-1)
{
r_CharPos:=-1
r_LineIdx:=-1
Return -1
}
;-- Extract values (UShort)
r_CharPos:=ErrorLevel&0xFFFF ;-- LOWORD
r_LineIdx:=ErrorLevel>>16 ;-- HIWORD
;-- Convert from UShort to UInt using known UInt values as reference
SendMessage EM_GETFIRSTVISIBLELINE,0,0,,ahk_id %hEdit%
FirstLine:=ErrorLevel-1
if (FirstLine>r_LineIdx)
r_LineIdx:=r_LineIdx+(65536*Floor((FirstLine+(65535-r_LineIdx))/65536))
SendMessage EM_LINEINDEX,(FirstLine<0) ? 0:FirstLine,0,,ahk_id %hEdit%
FirstCharPos:=ErrorLevel
if (FirstCharPos>r_CharPos)
r_CharPos:=r_CharPos+(65536*Floor((FirstCharPos+(65535-r_CharPos))/65536))
Return r_CharPos
}
;-----------------------------
;
; Function: Edit_Clear
;
; Description:
;
; Clear (delete) 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_ContainsSoftLineBreaks
;
; Description:
;
; Returns TRUE if the Edit control contains any soft line-break characters
; in the text.
;
; Type:
;
; Experimental/Preview. Subject to change.
;
; Calls To Other Functions:
;
; * <Edit_FmtLines>
; * <Edit_GetText>
; * <Edit_IsWordWrap>
;
; Remarks:
;
; This function is resource intensive. The entire document is formatted to
; include soft line-break characters (if any) and then reverted back to the
; original format. Use sparingly. When used on large documents, performance
; can be significantly improved by setting *SetBatchLines* to a high value
; before calling this function. For example:
;
; (start code)
; SetBatchLines 100ms ;-- Large bump in priority
; RC:=Edit_ContainsSoftLineBreaks(hEdit)
; SetBatchLines 10ms ;-- Default priority
; (end)
;
; Warning: There is an extremely remote possiblity that a library function
; that uses the WM_GETTEXT message (Ex: <Edit_GetSelText>) can collect
; formatted text, i.e. text that includes soft line-break characters, while
; this function is running. This can occur if the the thread running this
; function is interrupted by another thread immediately after formatting the
; Edit control to include soft line-break characters. In this scenario, the
; interrupting thread uses a function that uses the WM_GETTEXT message and
; collects formatted text. The chances of this occurring are virtually nil
; for small and medium-sized documents but the chances increase (although
; still very unlikely) as the size of the document increases. To
; significantly reduce the chance of interruption, set *SetBatchLines* to a
; high value (or -1) before calling this function.
;
;-------------------------------------------------------------------------------
Edit_ContainsSoftLineBreaks(hEdit)
{
;-- Bounce if Word Wrap is not enabled
;
; Note 1: The Edit_IsWordWrap function can return a false positive (very
; rare, but possible) but so far, no false negatives have been identified
; so it should be safe to use here.
;
; Note 2: The Edit_IsWordWrap function does a lot of testing to exclude
; invalid conditions (Ex: Is multiline Edit control?) so these same tests
; do not have to be performed here.
;
if not Edit_IsWordWrap(hEdit)
Return FALSE
;-- Get formatted text from the control
Edit_FmtLines(hEdit,True)
l_FormattedText:=Edit_GetText(hEdit)
Edit_FmtLines(hEdit,False)
;-- Any soft line-break characters?
if l_FormattedText Contains `r`r`n
Return True
Return False
}
;-----------------------------
;
; Function: Edit_Convert2DOS
;
; Description:
;
; Converts Unix, DOS/Unix mix, and Mac EOL 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 EOL 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 (SubStr(p_Text,0)<>"`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 (SubStr(p_Text,0)<>"`n")
p_Text.="`n"
Return p_Text
}
;-----------------------------
;
; Function: Edit_ConvertCase
;
; Description:
;
; Convert case of selected text.
;
; Parameters:
;
; p_Case - Set to "Upper", "Lower", "Capitalize", "Sentence", or "Toggle".
;
; Calls To Other Functions:
;
; * <Edit_GetSel>
; * <Edit_GetSelText>
; * <Edit_ReplaceSel>
; * <Edit_SetSel>
;
;-------------------------------------------------------------------------------
Edit_ConvertCase(hEdit,p_Case)
{
StringUpper,p_Case,p_Case,T ;-- Just in case StringCaseSense is On
;-- 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 S,Sentence,Sentencecase
{
StringLower l_SelectedText,l_SelectedText
l_SelectedText:=RegExReplace(l_SelectedText,"((?:^|[.!?]\s+)[a-z])","$u1")
;-- Note: Pattern provided by ManaUser
}
else
if p_Case in T,Toggle,Togglecase,I,Invert,Invertcase
{
t_SelectedText:=""
Loop Parse,l_SelectedText
{
t_Char:=A_LoopField
if t_Char is Upper
StringLower t_Char,t_Char
else
if t_Char is Lower
StringUpper t_Char,t_Char
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_Disable
;
; Description:
;
; Disables ("greys out") an Edit control.
;
; Returns:
;
; TRUE if successful, otherwise FALSE.
;
; Remarks:
;
; For AutoHotkey GUIs, use the *GUIControl* command for improved efficiency.
; Ex: GUIControl 24:Disable,MyEdit
;
;-------------------------------------------------------------------------------
Edit_Disable(hEdit)
{
Control Disable,,,ahk_id %hEdit%
Return ErrorLevel ? False:True
}
;------------------------------
;
; Function: Edit_DisableAllScrollBars
;
; Description:
;
; Disables the horizontal and vertical scroll bars.
;
; Returns:
;
; TRUE if successful, otherwise FALSE.
;
; Calls To Other Functions:
;
; * <Edit_EnableScrollBar>
;
; Remarks:
;
; See <Edit_EnableScrollBar> for more information.
;
;-------------------------------------------------------------------------------
Edit_DisableAllScrollBars(hEdit)
{
Static SB_BOTH:=3,ESB_DISABLE_BOTH:=0x3
Return Edit_EnableScrollBar(hEdit,SB_BOTH,ESB_DISABLE_BOTH)
}
;------------------------------
;
; Function: Edit_DisableHScrollBar
;
; Description:
;
; Disables the horizontal scroll bar.
;
; Returns:
;
; TRUE if successful, otherwise FALSE.
;
; Calls To Other Functions:
;
; * <Edit_EnableScrollBar>
;
; Remarks:
;
; See <Edit_EnableScrollBar> for more information.
;
;-------------------------------------------------------------------------------
Edit_DisableHScrollBar(hEdit)
{
Static SB_HORZ:=0,ESB_DISABLE_BOTH:=0x3
Return Edit_EnableScrollBar(hEdit,SB_HORZ,ESB_DISABLE_BOTH)
}
;------------------------------
;
; Function: Edit_DisableVScrollBar
;
; Description:
;
; Disables the vertical scroll bar.
;
; Returns:
;
; TRUE if successful, otherwise FALSE.
;
; Calls To Other Functions:
;
; * <Edit_EnableScrollBar>
;
; Remarks:
;
; See <Edit_EnableScrollBar> for more information.
;
;-------------------------------------------------------------------------------
Edit_DisableVScrollBar(hEdit)
{
Static SB_VERT:=1,ESB_DISABLE_BOTH:=0x3
Return Edit_EnableScrollBar(hEdit,SB_VERT,ESB_DISABLE_BOTH)
}
;-----------------------------
;
; 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_Enable
;
; Description:
;
; Enables a Edit control if it was previously disabled.
;
; Returns:
;
; TRUE if successful, otherwise FALSE.
;
; Remarks:
;
; For AutoHotkey GUIs, use the *GUIControl* command for improved efficiency.
; Ex: GUIControl 12:Enable,MyEdit
;
;-------------------------------------------------------------------------------
Edit_Enable(hEdit)
{
Control Enable,,,ahk_id %hEdit%
Return ErrorLevel ? False:True
}
;------------------------------
;
; Function: Edit_EnableAllScrollBars
;
; Description:
;
; Enables the horizontal and vertical scroll bars.
;
; Returns:
;
; TRUE if successful, otherwise FALSE.
;
; Calls To Other Functions:
;
; * <Edit_EnableScrollBar>
;
; Remarks:
;
; See <Edit_EnableScrollBar> for more information.
;
;-------------------------------------------------------------------------------
Edit_EnableAllScrollBars(hEdit)
{
Static SB_BOTH:=3,ESB_ENABLE_BOTH:=0x0
Return Edit_EnableScrollBar(hEdit,SB_BOTH,ESB_ENABLE_BOTH)
}
;------------------------------
;
; Function: Edit_EnableHScrollBar
;
; Description:
;
; Enables the horizontal scroll bar.
;
; Returns:
;
; TRUE if successful, otherwise FALSE.
;
; Calls To Other Functions:
;
; * <Edit_EnableScrollBar>
;
; Remarks:
;
; See <Edit_EnableScrollBar> for more information.
;
;-------------------------------------------------------------------------------
Edit_EnableHScrollBar(hEdit)
{
Static SB_HORZ:=0,ESB_ENABLE_BOTH:=0x0
Return Edit_EnableScrollBar(hEdit,SB_HORZ,ESB_ENABLE_BOTH)
}
;------------------------------
;
; Function: Edit_EnableVScrollBar
;
; Description:
;
; Enables the vertical scroll bar.
;
; Returns:
;
; TRUE if successful, otherwise FALSE.
;
; Calls To Other Functions:
;
; * <Edit_EnableScrollBar>
;
; Remarks:
;
; See <Edit_EnableScrollBar> for more information.
;
;-------------------------------------------------------------------------------
Edit_EnableVScrollBar(hEdit)
{
Static SB_VERT:=1,ESB_ENABLE_BOTH:=0x0
Return Edit_EnableScrollBar(hEdit,SB_VERT,ESB_ENABLE_BOTH)
}
;------------------------------
;
; Function: Edit_EnableScrollBar
;
; Description:
;
; Enables or disables one or both scroll bar arrows.
;
; Parameters:
;
; wSBflags - Specifies the scroll bar type. See the function's static
; variables for a list of possible values.
;
; wArrows - Specifies whether the scroll bar arrows are enabled or disabled
; and indicates which arrows are enabled or disabled. See the function's
; static variables for a list of possible values.
;
; Returns:
;
; TRUE if successful, otherwise FALSE.
;
; Remarks:
;
; The function will return FALSE (not successful) if the scroll bar(s) are
; already in the requested state (enabled/disabled). To determine if a scroll
; bar is already enabled, use <Edit_IsHScrollBarEnabled> and/or
; <Edit_IsVScrollBarEnabled>.
;
;-------------------------------------------------------------------------------
Edit_EnableScrollBar(hEdit,wSBflags,wArrows)
{
Static Dummy5401
;-- Scrollbar Type
,SB_HORZ:=0
;-- Enables or disables the arrows on the horizontal scroll bar
; associated with the specified window.
,SB_VERT:=1
;-- Enables or disables the arrows on the vertical scroll bar
; associated with the specified window.
,SB_CTL:=2
;-- Indicates that the scroll bar is a scroll bar control. The
; hWnd must be the handle to the scroll bar control.
,SB_BOTH:=3
;-- Enables or disables the arrows on the horizontal and
; vertical scroll bars associated with the specified window.
;-- Scrollbar Arrows
,ESB_ENABLE_BOTH:=0x0
;-- Enables both arrows on a scroll bar.
,ESB_DISABLE_LEFT:=0x1
;-- Disables the left arrow on a horizontal scroll bar.
,ESB_DISABLE_BOTH:=0x3
;-- Disables both arrows on a scroll bar.
,ESB_DISABLE_DOWN:=0x2
;-- Disables the down arrow on a vertical scroll bar.
,ESB_DISABLE_UP:=0x1
;-- Disables the up arrow on a vertical scroll bar.
,ESB_DISABLE_LTUP:=0x1 ;-- Same as ESB_DISABLE_LEFT
;-- Disables the left arrow on a horizontal scroll bar or the up
; arrow of a vertical scroll bar.
,ESB_DISABLE_RIGHT:=0x2
;-- Disables the right arrow on a horizontal scroll bar.
,ESB_DISABLE_RTDN:=0x2 ;-- Same as ESB_DISABLE_RIGHT
;-- Disables the right arrow on a horizontal scroll bar or the
; down arrow of a vertical scroll bar.
RC:=DllCall("EnableScrollBar"
,"Ptr",hEdit ;-- hWnd
,"UInt",wSBflags ;-- wSBflags
,"UInt",wArrows) ;-- wArrows
Return RC ? True:False
}
;-----------------------------
;
; 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.
;
; Hint: 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.
;
; Calls To Other Functions:
;
; * <Edit_GetText>
; * <Edit_GetTextLength>
; * <Edit_GetTextRange>
;
; 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
; to developer depending on how the 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 not StrLen(p_SearchText)
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 not StrLen(s_Text)
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 not InStr(p_Flags,"RegEx") ;-- 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
}
;-----------------------------
;
; Function: Edit_FindTextReset
;
; Description:
;
; Clears the saved text created by the "Static" flag.
;
; Calls To Other Functions:
;
; * <Edit_FindText>
;
;-------------------------------------------------------------------------------
Edit_FindTextReset()
{
Edit_FindText("","",0,0,"Reset")
}