Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Findrx in multilline text control with extended ASCII symbol
#1
Pressing "find" in below dialog focusses on the first occurrence of 'abc'
But in line 3 there is an symbol that looks like a pipe (ASCII extended symbol 179) it causes incorrect selection of 'abc'
(remove the symbol on line 3 and it works)

Is there a solution/workaround? (I tried converting to other encoding and replacing characters outside basic ASCII with space: [^\x00-\x7F] used this regex)


Function test_find_setcaret_multiline2
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90CC0AC8 0x0 0 0 258 172 "Dialog" "4"
;3 Edit 0x54321044 0x200 21 2 230 102 ""
;6 Edit 0x54021846 0x204 3 2 18 104 ""
;4 Edit 0x54030080 0x200 58 111 96 12 ""
;5 Button 0x54032000 0x0 4 110 48 14 "find"
;7 Static 0x54000000 0x0 20 136 228 12 "│    <- Extended ASCII Code:   [91]179]   https://www.asciitable.com/"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "3 6 4"
str e3 e6 e4
e3=
;test line 1
;test line 2
;│
;test abc line 3
;test line 4
;test line 5
e4=
;abc
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam
int- main_dlg
main_dlg=hDlg
sel message
,case WM_INITDIALOG
,,str t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
,,int i j k
,,SetTimer hDlg 1 50 &sub.Timer
,,int- black;black=ColorFromRGB(0 0 0)
,,int- blue;blue=ColorFromRGB(0 0 200)
,,__Font-- fnt_multiline fnt_title
,,fnt_multiline.CreateNew(hDlg "Courier New" 8 0)
,,fnt_multiline.SetDialogFont(hDlg F"6 3")
,,DT_SetTextColor hDlg black F"3"
,,DT_SetTextColor hDlg blue F"6"
,,sub.SetLineNumbers(hDlg 0)
,,DT_SetAutoSizeControls(hDlg "3s 6sv 5mv 4mv")
,case WM_DESTROY
,case WM_ACTIVATE
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam    
,case EN_CHANGE<<16|3
,,sub.SetLineNumbers(hDlg 0)
,case 5
,,act id(3 hDlg)
,,t0.getwintext(id(3 hDlg)) ;; TEXT
,,t1.getwintext(id(4 hDlg)) ;; KEYWORD
,,ARRAY(CHARRANGE) charranges
,,findrx(t0 F"\Q{t1}\E" 0 1|4|8 charranges)        
,,_s.left(t0 charranges[0 0].cpMin)
,,k=numlines(_s)
,,SendDlgItemMessage hDlg 6 WM_VSCROLL MakeInt(SB_THUMBPOSITION k) 0
,,SendDlgItemMessage hDlg 3 WM_VSCROLL MakeInt(SB_THUMBPOSITION k) 0
,,SendMessage(id(3 hDlg) EM_SETSEL charranges[0 0].cpMin charranges[0 0].cpMax)
,,out F"selected range: {charranges[0 0].cpMin} - {charranges[0 0].cpMax}"
ret 1


#sub SetLineNumbers
function int'hDlg int'firstboot_set
int i
str get_lns set_lns
get_lns.getwintext(id(3 hDlg)) ;; TEXTVIEW
ARRAY(str) ln_arr.create(numlines(get_lns))
for i 0 ln_arr.len
,ln_arr[i]=i+1
_s=ln_arr
_s.setwintext(id(6 hDlg)) ;; LINENUMBERS

#sub Timer
function
int- main_dlg
int pos=GetScrollPos(id(3 main_dlg) SB_VERT) ;; TEXTVIEW MULTILINE
SendDlgItemMessage main_dlg 6 WM_VSCROLL MakeInt(SB_THUMBPOSITION pos) 0 ;; LINENUMBERS
#2
Use this member function to convert string offsets from UTF-8 to UTF-16.
Member function str.IndexToUtf16
Code:
Copy      Help
function# index

if(index<0 or index>this.len) end ES_BADARG
if(index=0) ret
ret MultiByteToWideChar(_unicode 0 this.lpstr index 0 0)

Code:
Copy      Help
,,SendMessageW(id(3 hDlg) EM_SETSEL t0.IndexToUtf16(charranges[0 0].cpMin) t0.IndexToUtf16(charranges[0 0].cpMax))
#3
This works!
Thank you!
#4
Sorry to ask this again, but in an RTF control it doesn't work. (works perfect in normal multiline control).
Is there a workaround for an RTF control?
I also tried: SendMessage(id(3 hDlg) EM_EXSETSEL 0 t0.IndexToUtf16(&charranges))

(The RTF control is used for plain text.)

Function test_find_setcaret_multiline2     (now with plain text in RTF control)
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90CC0AC8 0x0 0 0 258 172 "Dialog" "4"
;6 Edit 0x54021846 0x204 3 2 18 104 ""
;4 Edit 0x54030080 0x200 58 111 96 12 ""
;5 Button 0x54032000 0x0 4 110 48 14 "find"
;7 Static 0x54000000 0x0 20 136 228 12 "│    <- Extended ASCII Code:   [91]179]   https://www.asciitable.com/"
;3 RichEdit20A 0x54233044 0x200 22 2 200 102 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "6 4 3"
str e6 e4 re3
re3=
;test line 1
;test line 2
;│
;test abc line 3
;test line 4
;test abcline 5
e4=
;abc
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam
int- main_dlg
main_dlg=hDlg
sel message
,case WM_INITDIALOG
,,str t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
,,int i j k
,,SetTimer hDlg 1 50 &sub.Timer
,,int- black;black=ColorFromRGB(0 0 0)
,,int- blue;blue=ColorFromRGB(0 0 200)
,,__Font-- fnt_multiline fnt_title
,,fnt_multiline.CreateNew(hDlg "Courier New" 8 0)
,,fnt_multiline.SetDialogFont(hDlg F"6 3")
,,DT_SetTextColor hDlg black F"3"
,,DT_SetTextColor hDlg blue F"6"
,,sub.SetLineNumbers(hDlg 0)
,,DT_SetAutoSizeControls(hDlg "3s 6sv 5mv 4mv")
,case WM_DESTROY
,case WM_ACTIVATE
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam    
,case EN_CHANGE<<16|3
,,sub.SetLineNumbers(hDlg 0)
,case 5
,,act id(3 hDlg)
,,t0.getwintext(id(3 hDlg)) ;; TEXT
,,t1.getwintext(id(4 hDlg)) ;; KEYWORD
,,ARRAY(CHARRANGE) charranges
,,findrx(t0 F"\Q{t1}\E" 0 1|4|8 charranges)        
,,_s.left(t0 charranges[0 0].cpMin)
,,k=numlines(_s)
,,SendDlgItemMessage hDlg 6 WM_VSCROLL MakeInt(SB_THUMBPOSITION k) 0
,,SendDlgItemMessage hDlg 3 WM_VSCROLL MakeInt(SB_THUMBPOSITION k) 0
,,SendMessageW(id(3 hDlg) EM_SETSEL t0.IndexToUtf16(charranges[0 0].cpMin) t0.IndexToUtf16(charranges[0 0].cpMax))
,,out F"selected range: {charranges[0 0].cpMin} - {charranges[0 0].cpMax}"
ret 1


#sub SetLineNumbers
function int'hDlg int'firstboot_set
int i
str get_lns set_lns
get_lns.getwintext(id(3 hDlg)) ;; TEXTVIEW
ARRAY(str) ln_arr.create(numlines(get_lns))
for i 0 ln_arr.len
,ln_arr[i]=i+1
_s=ln_arr
_s.setwintext(id(6 hDlg)) ;; LINENUMBERS

#sub Timer
function
int- main_dlg
int pos=GetScrollPos(id(3 main_dlg) SB_VERT) ;; TEXTVIEW MULTILINE
SendDlgItemMessage main_dlg 6 WM_VSCROLL MakeInt(SB_THUMBPOSITION pos) 0 ;; LINENUMBERS
#5
1. RichEdit20A -> RichEdit20W.
2. Inside Richedit controls, newlines are \n instead of \r\n. A workaround:

Code:
Copy      Help
,,t0.findreplace("[]" "[10]")
#6
Thank you!


Forum Jump:


Users browsing this thread: 1 Guest(s)