-
Notifications
You must be signed in to change notification settings - Fork 3
/
GuiTextBox.cls
1522 lines (1323 loc) · 40.8 KB
/
GuiTextBox.cls
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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "GuiTextBox"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
' If you copy and paste code
' don't forget to set default property to vartext (changed from text)
Implements IControlIndex
Public WithEvents glistN As gList
Attribute glistN.VB_VarHelpID = -1
Private mprompt As String
Private mark1 As Long, mark2 As Long
Private mkind As String, mPartColor As Long
Public SkipProcAtExitFocus As Boolean, MoveOnEnter As Boolean
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalReAlloc Lib "kernel32" (ByVal hMem As Long, ByVal dwBytes As Long, ByVal wFlags As Long) As Long
Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Const GMEM_DDESHARE = &H2000
Private Const GMEM_DISCARDABLE = &H100
Private Const GMEM_DISCARDED = &H4000
Private Const GMEM_FIXED = &H0
Private Const GMEM_INVALID_HANDLE = &H8000
Private Const GMEM_LOCKCOUNT = &HFF
Private Const GMEM_MODIFY = &H80
Private Const GMEM_MOVEABLE = &H2
Private Const GMEM_NOCOMPACT = &H10
Private Const GMEM_NODISCARD = &H20
Private Const GMEM_NOT_BANKED = &H1000
Private Const GMEM_NOTIFY = &H4000
Private Const GMEM_SHARE = &H2000
Private Const GMEM_VALID_FLAGS = &H7F72
Private Const GMEM_ZEROINIT = &H40
Private Const GPTR = (GMEM_FIXED Or GMEM_ZEROINIT)
Private Const GMEM_LOWER = GMEM_NOT_BANKED
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private Declare Function GetClipboardData Lib "user32" _
(ByVal wFormat As Long) As Long
Private Declare Function SetClipboardData Lib "user32" _
(ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function OpenClipboard Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" _
() As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" _
(ByVal wFormat As Long) As Long
Private Pad$
' for Gui purposes
Public ctrlName As String
Private mesCtrlName As String, sp As String, sp1 As String, sp2 As String
Dim mIndex As Long, mStayOpen As Boolean
Dim Callback As GuiM2000
Dim white As Long, black As Long, dimm1 As Long, dimm2 As Long
Dim tParam As DRAWTEXTPARAMS
Private Declare Sub PutMem2 Lib "msvbvm60" (ByVal addr As Long, ByVal NewVal As Integer)
Private Declare Function GetStringTypeExW Lib "kernel32.dll" (ByVal Locale As Long, ByVal dwInfoType As Long, ByVal lpSrcStr As Long, ByVal cchSrc As Long, ByRef lpCharType As Integer) As Long
Public NumberOnly As Boolean
Public NumberIntOnly As Boolean
Friend Property Get GetCallBack() As GuiM2000
Set GetCallBack = Callback
End Property
Friend Sub Construct(there As GuiM2000, Name$)
mIndex = -1
Set Callback = there
On Error Resume Next
ctrlName = GetTag$
Set glistN = there.Controls.Add("m2000.glist", ctrlName)
there.AddGuiControl Me
glistN.Dynamic
there.Controls(ctrlName).TabStop = True
mesCtrlName = Name$
End Sub
Friend Sub ConstructArray(there As GuiM2000, Name$, i As Long)
Set Callback = there
On Error Resume Next
ctrlName = GetTag$
Set glistN = there.Controls.Add("m2000.glist", ctrlName)
mIndex = i
there.AddGuiControl Me
glistN.Dynamic
there.Controls(ctrlName).TabStop = True
mesCtrlName = Name$
End Sub
Public Property Get Text() As String
If glistN.listcount = 0 Then
glistN.AddItem mprompt
Else
Text = glistN.list(0)
End If
End Property
Public Property Get vartext() As String
Attribute vartext.VB_UserMemId = 0
If glistN.listcount = 0 Then
glistN.AddItem ""
Else
vartext = Mid$(glistN.list(0), 1 + Len(mprompt))
End If
End Property
Public Property Let vartext(ByVal RHS As String)
glistN.restrictLines = 1
glistN.HeadLine = vbNullString ' no info
glistN.HeadlineHeight = 0
If glistN.listcount = 0 Then
glistN.AddItem mprompt + RHS
Else
glistN.list(0) = mprompt + RHS
End If
glistN.SelStart = Len(mprompt + RHS) + 1
glistN.ShowMe
End Property
Public Property Let Text(ByVal RHS As String)
'Dim oldright As Long
'oldright = glistN.LeftMarginPixels
On Error Resume Next
If glistN Is Nothing Then Exit Property
glistN.restrictLines = 1
glistN.HeadLine = vbNullString ' no info
glistN.HeadlineHeight = 0
If glistN.listcount = 0 Then
glistN.AddItem RHS
Else
glistN.list(0) = RHS
End If
'glistN.LeftMarginPixels = oldright
glistN.ShowMe2
End Property
Public Property Get Info() As String
Info = glistN.HeadLine
End Property
Public Property Let Info(ByVal RHS As String)
locked = False
If RHS = vbNullString Then
glistN.InfoDropBarClick = False
Text = Text
Else
glistN.restrictLines = 0
glistN.HeadLineHeightMinimum = glistN.HeightPixels
glistN.HeadLine = RHS
glistN.InfoDropBarClick = True
glistN.ShowMe
locked = True
End If
End Property
Public Property Get top() As Variant
top = Callback.Controls(ctrlName).top
End Property
Public Property Let top(ByVal RHS As Variant)
Callback.Controls(ctrlName).top = RHS
End Property
Public Property Get Left() As Variant
Left = Callback.Controls(ctrlName).Left
End Property
Public Property Let Left(ByVal RHS As Variant)
Callback.Controls(ctrlName).Left = RHS
End Property
Public Sub SetUp()
black = 0
dimm1 = rgb(100, 200, 160)
dimm2 = rgb(200, 120, 60)
Dim ff As New StdFont
With Callback
white = .Controls(1).ForeColor
ff.Name = .CtrlFontName
ff.charset = Form1.DIS.Font.charset
ff.Size = .CtrlFontSize
ff.bold = .CtrlFontBold
End With
MoveOnEnter = True
With glistN
.NoEscapeKey = True
.bypassfirstClick = True
.enabled = True
Info = vbNullString
If .listcount = 0 Then Text = vbNullString
.NoCaretShow = True
.VerticalCenterText = True
If Not .CenterText Then .LeftMarginPixels = 8 Else .LeftMarginPixels = 0
.BackColor = rgb(200, 120, 60)
Set .Font = ff
.ForeColor = white
.dcolor = Callback.Controls(1).dcolor
.ShowMe
End With
locked = False
enabled = True
Retired
End Sub
Public Property Get Prompt() As String
Prompt = mprompt
End Property
Public Property Let Prompt(ByVal RHS As String)
mprompt = RHS
glistN.PromptLineIdent = Len(RHS)
Text = RHS
End Property
Private Sub Class_Initialize()
sp1 = ",+-*/=<>^!.&[]{}()^;""" + "'!"
sp = " " + ChrW(9) + ChrW(160)
sp2 = sp1 + sp
End Sub
Private Sub Class_Terminate()
Set glistN = Nothing
End Sub
Private Sub glistN_CaretDeal(Deal As Long)
If Deal = 0 Then
glistN.Noflashingcaret = True
glistN.NoCaretShow = True
glistN.ShowMe2
Deal = 1
Else
glistN.Noflashingcaret = False
glistN.NoCaretShow = False
glistN.ShowMe2
Deal = 0
End If
End Sub
Private Sub glistN_Fkey(A As Integer)
If A > 1000 Then
Callback.SendFKEY A - 1000
Else
Callback.SendFKEY A
End If
End Sub
Private Sub glistN_GetRealX1(mHdc As Long, ByVal ExtSelStart As Long, ByVal that As String, retvalue As Long, ok As Boolean)
retvalue = RealX1(mHdc, ExtSelStart, that)
ok = True
End Sub
Private Sub glistN_OutPopUp(X As Single, y As Single, myButton As Integer)
If (myButton And &H2) = 2 Then
If mIndex >= 0 Then
Callback.Callback mesCtrlName + ".PopUp(" + Str(mIndex) + "," + Str(X + Callback.Controls(ctrlName).Left) + "," + Str(y + Callback.Controls(ctrlName).top) + "," + Str(myButton) + "," + Str(glistN.ListIndex + 1) + ")"
Else
Callback.Callback mesCtrlName + ".PopUp(" + Str(X + Callback.Controls(ctrlName).Left) + "," + Str(y + Callback.Controls(ctrlName).top) + "," + Str(myButton) + "," + Str(glistN.ListIndex + 1) + ")"
End If
End If
End Sub
Private Sub glistN_RegisterGlist(this As gList)
If Not glistN.Spinner Then this.NoWheel = True
On Error Resume Next
Set LastGlist = this
If Err.Number > 0 Then this.NoWheel = True
End Sub
Private Sub glistN_ChangeListItem(item As Long, content As String)
'If Not enabled Then Exit Sub
Dim this As String, thispos As Long, VR(2)
thispos = glistN.SelStart - Len(mprompt)
this = Mid$(content, 1 + Len(mprompt))
If NumberOnly Then
If NLtrim$(this) = vbNullString Then
ElseIf Not ValidNum(this, False, NumberIntOnly) Then
this = Mid$(glistN.list(item), 1 + Len(mprompt))
End If
End If
If Len(this) < thispos Then thispos = Len(this) + 1
'' RaiseEvent ValidString(this, thispos)
VR(0) = this
VR(1) = thispos
If mIndex >= 0 Then
Callback.CallbackNow mesCtrlName + ".ValidString(" + Str(mIndex) + ")", VR()
Else
Callback.CallbackNow mesCtrlName + ".ValidString()", VR()
End If
thispos = VR(1) + Len(mprompt)
content = mprompt + VR(0)
If thispos <> glistN.SelStart And VR(0) <> "" Then glistN.SelStart = thispos: glistN.ShowMe
End Sub
Private Sub glistN_CtrlPlusF1()
If mIndex >= 0 Then
Callback.Callback mesCtrlName + ".About(" + Str(mIndex) + ")"
Else
Callback.Callback mesCtrlName + ".About()"
End If
End Sub
Public Sub ResetPan()
glistN.PanPos = 0
End Sub
Private Sub glistN_ChangeSelStart(thisselstart As Long)
If thisselstart <= Len(mprompt) Then thisselstart = Len(mprompt) + 1
'glistN.ShowPan
With glistN
'.ShowPan
.ShowMe2
'.ExternalCursor thisselstart, .list(.ListIndex), .forecolor
End With
End Sub
Public Property Get ThisKind() As String
ThisKind = mkind
End Property
Public Property Let ThisKind(ByVal RHS As String)
mkind = RHS
glistN.LastLinePart = " " & RHS
End Property
Public Property Get enabled() As Boolean
enabled = glistN.EditFlag
End Property
Public Property Let enabled(ByVal RHS As Boolean)
glistN.EditFlag = RHS
glistN.Arrows2Tab = Not RHS
glistN.NoCaretShow = Not RHS
glistN.NoBarClick = Not RHS
End Property
'
Private Sub glistN_CheckGotFocus()
Callback.RealHover = ctrlName
If Not locked Then
If glistN.ListIndex < 0 And glistN.listcount > 0 Then glistN.ListindexPrivateUse = 0
' RaiseEvent GotFocus
If enabled Then
glistN.FadeLastLinePart = mPartColor
If glistN.BackStyle <> 1 Then
glistN.ForeColor = black
glistN.BackColor = white
End If
glistN.NoCaretShow = False:
glistN.PanPos = 0
Else
glistN.FadeLastLinePart = black
If glistN.BackStyle <> 1 Then
glistN.ForeColor = white
glistN.BackColor = dimm1
End If
glistN.NoCaretShow = True
End If
Callback.LastActive = ctrlName
glistN.ShowMe
End If
End Sub
Public Sub Retired()
If mStayOpen Then
glistN.FadeLastLinePart = mPartColor
If glistN.BackStyle <> 1 Then
glistN.ForeColor = black
glistN.BackColor = white
End If
glistN.NoCaretShow = False
Else
If glistN.BackStyle <> 1 Then
glistN.FadeLastLinePart = 0
glistN.ForeColor = white
glistN.BackColor = dimm2
End If
glistN.NoCaretShow = True
End If
glistN.PanPos = 0: glistN.ShowMe
End Sub
Private Sub glistN_CheckLostFocus()
If Not locked Then
Callback.LastActive = ctrlName
If mStayOpen Then
glistN.NoCaretShow = True
glistN.HideTheCaret
If glistN.Visible Then glistN.PanPos = 0: glistN.PrepareToShow
Exit Sub
End If
If Not SkipProcAtExitFocus Then
If glistN.BackStyle <> 1 Then
glistN.ForeColor = white
glistN.BackColor = dimm2
End If
glistN.NoCaretShow = True: glistN.PanPos = 0: glistN.ShowMe
End If
End If
' RaiseEvent LostFocus
End Sub
Private Sub glistN_HeaderSelected(Button As Integer)
' INFO SELECTED
Text = Text
End Sub
Private Sub glistN_KeyDown(keycode As Integer, shift As Integer)
If MoveOnEnter Then
If keycode = 13 Then
If shift = 1 Then
glistN.Goback
Else
glistN.GoON
End If
Exit Sub
keycode = 0
End If
End If
Dim VR(2)
VR(0) = keycode
VR(1) = shift
If mIndex >= 0 Then
Callback.CallbackNow mesCtrlName + ".KeyDown(" + Str(mIndex) + ")", VR()
Else
Callback.CallbackNow mesCtrlName + ".KeyDown()", VR()
End If
keycode = VR(0)
shift = VR(1)
If keycode = vbKeyF10 And shift <> 0 Then
keycode = 0
If mIndex >= 0 Then
Callback.Callback mesCtrlName + ".PopUp(" + Str(mIndex) + "," + Str(MOUSEX(Callback.Left)) + "," + Str(MOUSEY(Callback.top)) + "," + Str(2) + "," + Str(glistN.ListIndex + 1) + ")"
Else
Callback.Callback mesCtrlName + ".PopUp(" + Str(MOUSEX(Callback.Left)) + "," + Str(MOUSEY(Callback.top)) + "," + Str(2) + "," + Str(glistN.ListIndex + 1) + ")"
End If
Exit Sub
End If
If keycode = vbKeyUp Then
ElseIf keycode = vbKeyDown Then
ElseIf keycode = vbKeyV And (shift And 3) = 2 Then
If Not enabled Then Exit Sub
Pad$ = GetTextData(13)
If Pad$ = vbNullString Then Pad$ = Clipboard.GetText(1)
If Pad$ <> "" Then
If (glistN.maxchar - Len(mprompt)) > 0 Then
vartext = Mid$(Pad$, 1, (glistN.maxchar - Len(mprompt)))
Else
vartext = Pad$
End If
End If
End If
End Sub
Public Property Get SelStart() As Long
SelStart = glistN.SelStart
End Property
Public Property Let SelStart(ByVal RHS As Long)
glistN.SelStart = RHS
End Property
Property Let Visible(ByVal RHS As Boolean)
If Not glistN Is Nothing Then
glistN.Visible = RHS
End If
End Property
Property Get Visible() As Boolean
If Not glistN Is Nothing Then
Visible = glistN.Visible
End If
End Property
Public Sub SetFocus()
On Error Resume Next
glistN.SetFocus
End Sub
Private Sub glistN_RTL(thisHDC As Long, item As Long, where As Long, mark10 As Long, mark20 As Long, offset As Long)
offset = RealX1(thisHDC, where, Text, where, mark10)
End Sub
Function RealX1(mHdc As Long, ByVal ExtSelStart As Long, ByVal that$, Optional nValue As Long = 0, Optional found As Long = 0) As Long
If ExtSelStart <= 0 Then ExtSelStart = 1
Dim ww$(), Col() As Long, items&, i, c As String
Dim rleftacc As Long, original As Long, rx1 As Long, direction As Long
Dim OldValue As Long, orx1 As Long, j As Long, nrtl As Boolean
If Len(that$) = 0 Then
nValue = 1: Exit Function
End If
original = ExtSelStart
ReDim ww$(0)
ww$(0) = that$
Dim M1 As Long, M2 As Long
Dim dummy As RECT, R As RECT, tabw As Long, offset As Long, hRgn As Long, estX As Long
tabw = tParam.iTabLength * glistN.AveCharWith
glistN.UserControlTextMetricsPixels that$, R.Right, R.Bottom
dummy = R
dummy.top = glistN.HeadlineHeightTwips + 1
dummy.Bottom = dummy.top + R.Bottom
R = dummy
offset = 0
estX = 0
'hRgn = CreateRectRgnIndirect(dummy)
'SelectClipRgn mHdc, hRgn
If found > 0 Then
rx1 = LowWord(GetTabbedTextExtent(mHdc, StrPtr(that$), Len(that$), 1, tabw))
If rx1 < found Then
c = Right$(that$, 1)
nValue = 1
RTL3 c, nValue, mark1, mark2, nrtl, M1, M2
If mark1 <> 0 And mark2 <> 0 Then
nValue = Len(that$)
RTL3 that$, nValue, mark1, mark2, nrtl, M1, M2
nValue = mark1
GoTo finish
Else
nValue = Len(ww(i))
RTL3 ww(i), nValue, mark1, mark2, nrtl, M1, M2
If mark1 <> 0 And mark2 <> 0 And nValue >= mark2 Then
If nValue <= mark2 + 1 Then
nValue = mark1
GoTo finish
Else
nValue = nValue + 1
ExtSelStart = nValue
End If
Else
nValue = Len(that$) + 1
GoTo finish
End If
End If
End If
End If
For i = 0 To items&
c = ww$(i)
R.Left = offset
rleftacc = offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), Len(c), 1, tabw, 0))
If Len(c) >= ExtSelStart - estX Or (found > 0 And rleftacc > found) Then
If Not Len(c) >= ExtSelStart - estX Then
ExtSelStart = Len(c) + estX
End If
nValue = ExtSelStart - estX
RTL3 c, nValue, mark1, mark2, nrtl, M1, M2
If nrtl Then
If M2 - M1 > 0 Then Mid$(c, M1, M2 - M1 + 1) = StrReverse(Mid$(c, M1, M2 - M1 + 1))
End If
If mark1 = 0 Or mark2 = 0 Then
If nValue > 1 Then
j = nValue - 1
RTL3 c, j, mark1, mark2, nrtl, M1, M2
If mark1 <> 0 And mark2 <> 0 And j >= mark1 And j <= mark2 Then
If i = items& Then
If found > 0 Then
rx1 = offset
If mark1 > 1 Then
offset = offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), mark1 - 1, 1, tabw, 0))
End If
c = Mid$(ww(i), mark1, mark2 - mark1 + 1)
If nrtl Then
M1 = M1 - mark1 + 1
M2 = M2 - mark1 + 1
If M2 - M1 > 0 Then Mid$(c, M1, M2 - M1 + 1) = StrReverse(Mid$(c, M1, M2 - M1 + 1))
End If
If found > offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), Len(c$), 1, tabw, 0)) Then
nValue = mark1 + estX
Exit For
Else
offset = rx1
c = ww$(i)
End If
nValue = j + estX
End If
GoTo here1
Else
nValue = mark2 - 1 + estX 'j - (nValue > mark2)
If nValue <= 0 Then nValue = 1
If mark1 > 1 Then
rx1 = offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), mark2, 1, tabw, 0))
If found > 0 Then
If rx1 <= found Then
nValue = mark1 + estX
RealX1 = rx1
Exit For
End If
End If
RealX1 = offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), mark1 - 1, 1, tabw, 0))
End If
Exit For
End If
End If
End If
ElseIf mark1 <> 0 And mark2 <> 0 And nValue = mark2 + 1 Then
If found > 0 Then
rx1 = offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), mark2, 1, tabw, 0))
If found > rx1 Then
nValue = mark1 + estX
RealX1 = rx1
Exit For
End If
nValue = mark2
End If
GoTo here1
End If
If mark1 <> 0 And mark2 <> 0 And nValue >= mark1 And nValue <= mark2 Then
here1:
If mark1 > 1 Then
offset = offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), mark1 - 1, 1, tabw, 0))
End If
If mark1 = nValue And found > 0 Then
If offset > found Then
j = mark1 - 2
If j >= 1 Then
Do While found < R.Left + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), j, 1, tabw, 0))
j = j - 1
If j = 0 Then j = 1: Exit Do
Loop
Else
GoTo nortl
End If
RTL3 c, j, mark1, mark2, nrtl, M1, M2
If mark1 <> 0 And mark2 <> 0 Then
nValue = mark2 - (j - mark1) + estX
Else
nValue = j + 1 + estX
End If
RealX1 = offset
Exit For
End If
End If
c = Mid$(ww(i), mark1, mark2 - mark1 + 1)
If nrtl Then
M1 = M1 - mark1 + 1
M2 = M2 - mark1 + 1
If M2 - M1 > 0 Then Mid$(c, M1, M2 - M1 + 1) = StrReverse(Mid$(c, M1, M2 - M1 + 1))
End If
If nValue = mark2 + 1 Then
If found > 0 Then
For j = mark2 - mark1 + 1 To 1 Step -1
If found > offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), j, 1, tabw, 0)) Then
If j > 1 Then
If LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), j, 1, tabw, 0)) > LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), j - 1, 1, tabw, 0)) < 0 Then
nValue = mark2 - (j) + estX
offset = found
Exit For
End If
End If
nValue = mark2 - (j - 1) + estX
offset = found
Exit For
End If
Next j
If j = 0 Then
nValue = mark1 - 1 + estX - 1
If nValue <= 0 Then nValue = 1
End If
Else
nValue = mark1 - 1 + estX - 1
If nValue <= 0 Then nValue = 1
End If
RealX1 = offset
Exit For
ElseIf found > 0 And mark1 = nValue Then
If found > offset Then
nValue = mark2
GoTo conthere
Else
nValue = mark2 + 1 + estX
RealX1 = offset
End If
Else
conthere:
rleftacc = offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), Len(c), 1, tabw, 0))
If nValue > mark1 Then
rx1 = rleftacc - 1 - LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), nValue - mark1, 1, tabw, 0))
Else
rx1 = rleftacc - 1
End If
End If
If found > 0 Then
rx1 = rx1 + 1
If found < rx1 Then
original = nValue
For j = nValue To mark2
rx1 = rleftacc - LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), j - mark1 + 1, 1, tabw, 0))
original = original + 1
If found >= rx1 Then Exit For
Next j
j = original
If nrtl Then
nValue = M2 - ((j + 1 - mark1) - M1) + mark1 + estX
Else
If j > mark2 Then
nValue = mark2 + 1 + estX
If nValue = 0 Then nValue = 1
RealX1 = rx1
Exit For
Else
nValue = j
RTL3 c, nValue, mark1, mark2, nrtl, M1, M2
If nrtl And j >= M1 And j <= M2 Then
nValue = nValue + 2 + estX
Else
nValue = j + estX
End If
End If
RealX1 = rx1 + 1
End If
Else
original = nValue
For j = nValue - 1 To mark1 + 1 Step -1
rx1 = rleftacc - LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), j - mark1, 1, tabw, 0))
If found <= rx1 Then Exit For
original = j
Next j
j = original
If nrtl Then
nValue = M2 - ((j + 1 - mark1) - M1) + mark1 + estX
Else
If j < mark1 Then
j = mark1
End If
If nrtl And j - mark1 >= M1 And j - mark1 <= M2 Then
nValue = nValue + estX
Else
nValue = j + estX
End If
End If
RealX1 = rx1
End If
If found = 0 Then
If Mid$(that$, nValue, 1) = " " Then
c = Mid$(that$, nValue + 1, 1)
If Len(c) > 0 Then
RTL3 c, (1), mark1, mark2, nrtl, M1, M2
If mark1 = 0 Or mark2 = 0 Then
nValue = nValue + 1
'If nvalue1 < 1 Then nvalue1 = 1
End If
End If
End If
End If
Exit For
End If
If found = 0 And nrtl Then
'nValue = ExtSelStart
Else
nValue = mark2 - (nValue - mark1) + (nValue <> mark2) + estX - 1
End If
If nValue = mark1 And items& = 1 Then
rx1 = 0
End If
If nValue = 0 Then nValue = mark2
RealX1 = rx1
Else ' NO RTL
nortl:
c = Myleft$(c, ExtSelStart - estX - 1)
rx1 = offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), Len(c), 1, tabw, 0))
If found > 0 Then
If found < rx1 Then
nValue = ExtSelStart - 1
If nValue - estX - 1 < 1 Then
RealX1 = offset
Else
c = Myleft$(c, nValue - estX - 1)
j = Len(c)
RTL3 c, j, mark1, mark2, nrtl, M1, M2 ' found=0
If mark1 <> 0 And mark2 <> 0 Then
If j <= mark2 And j >= mark1 Then
nValue = mark2 - (j - mark1) + estX
Else
'nValue = nValue + estX - 1
End If
Else
' nValue = Len(c) + estX
End If
rx1 = offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), Len(c), 1, tabw, 0))
End If
RealX1 = rx1
Exit For
Else
RealX1 = rx1
nValue = original
End If
Else
RealX1 = rx1
nValue = ExtSelStart
End If
Exit For
End If
RealX1 = rx1
' nValue = ExtSelStart
Exit For
ElseIf i = items& Then
nValue = ExtSelStart - estX
RTL3 c, nValue, mark1, mark2, nrtl, M1, M2
If mark1 <> 0 And mark2 <> 0 Then
If mark2 = Len(c) Then
c = Myleft$(ww(i), mark1 - 1)
If Len(c) = 0 Then
rleftacc = offset
ElseIf nrtl And M2 = mark2 Then
rleftacc = offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), Len(c), 1, tabw, 0))
c = ww(i)
If M2 - M1 > 0 Then c = Mid$(c, M1, M2 - M1 + 1)
rleftacc = rleftacc + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), Len(c), 1, tabw, 0))
nValue = M1 - 1
Else
rleftacc = offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), Len(c), 1, tabw, 0))
End If
ElseIf found > 0 Then
rleftacc = offset + LowWord(TabbedTextOut(mHdc, R.Left, R.top, StrPtr(c), nValue, 1, tabw, 0))
If rleftacc < found Then
nValue = original
End If
RealX1 = found
GoTo finish
End If
End If
End If
offset = rleftacc
estX = estX + Len(ww(i))
Next i
If i = items& + 1 Then
RealX1 = offset
nValue = estX
End If
finish:
'SelectClipRgn mHdc, &H0
'DeleteObject hRgn
End Function
Private Sub RTL3(what As String, where As Long, mark10 As Long, mark20 As Long, numhandle As Boolean, M1 As Long, M2 As Long)
numhandle = False
M1 = 0
M2 = 0
mark10 = 0
mark20 = 0
Dim A2() As Integer, R As Long, ii As Long
Dim wr$
Dim mcharpos As Long
If Len(what) = 0 Then Exit Sub
If where = -1 Then mcharpos = Len(what) Else mcharpos = where - 1
If mcharpos > Len(what) Then Exit Sub
ReDim A2(Len(what) + 10)
If GetStringTypeExW(&HB, 2, StrPtr(what), Len(what), A2(0)) = 0 Then Exit Sub
For ii = mcharpos To 0 Step -1
If ii < Len(what) Then
If A2(ii) = 9 Then
If mark10 > 0 Then Exit For
Exit Sub
End If
If A2(ii) = 2 Then
mark10 = ii + 1
End If
If mark10 > 0 And A2(ii) = 1 Then
Exit For
End If
End If
Next ii
If mark10 = 0 Then Exit Sub
For ii = mark10 - 1 To Len(what) - 1
If A2(ii) = 1 Then
Exit For
End If
If ii >= 0 Then
If A2(ii) = 7 Then
For R = ii + 1 To Len(what) - 1
If A2(R) = 1 Then Exit For
If A2(R) = 9 Then
Exit For
End If
If A2(R) <> 7 And A2(R) < 11 Then
If (A2(R) And 2) = 2 Then
ii = R
R = -1
Exit For
End If
If mark20 > mcharpos Then: R = 0: Exit For
End If
Next R
If R = 0 Then
Exit For
ElseIf R <> -1 Then
ii = R - 1
End If
End If
If (A2(ii) And 2) = 2 And A2(ii) < 11 And A2(ii) <> 10 Then
mark20 = ii + 1
If mark20 > 0 And A2(ii) = 1 Then
Exit For
End If
End If
End If
If A2(ii) = 9 Then
If mark20 > 0 Then mark20 = ii
Exit For
End If
Next ii
'If mark10 > 0 And mark20 > 0 Then
there11:
If mcharpos > 0 Then
If A2(mcharpos) = 3 And A2(mcharpos - 1) <> 3 Then
M1 = mcharpos
M2 = mcharpos
Else
M1 = mcharpos - 1
M2 = mcharpos - 1