Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sets the color for specific text within the RichEdit control
#15
Code:
Copy      Help
out
str template=
;For ┋Counter Variable┋ = ┋Lower Limit┋ To ┋Upper Limit┋
;,$P[I]
;Next

ARRAY(str) a
if(!findrx(template "┋(.+?)┋" 0 4 a)) end
ARRAY(POINT) aa
if(!findrx(template "┋(.+?)┋" 0 4 aa)) end
ARRAY(int) tpos
for int'j 0 aa.len
,tpos[]= aa[0 j].x
ARRAY(str) c.create(a.len+1)
c[0]="5"
str dd
dd.formata("BEGIN DIALOG[]0 '''' 0x90C80AC8 0x0 0 0 490 %i ''Manual Text Input''[]" a.len*30+40)
int i idEdit(5) y(8)
for i 0 a.len
,dd.formata("%i Edit 0x54030080 0x200 8 %i 121 13[]" idEdit y)
,c[i+1]=a[0 i]
,if(i)
,,c[0].formata(" %i" idEdit)
,y+20
,idEdit+1
y+10
_s=
;1 Button 0x54030001 0x4 20 108 48 14 "OK"
;2 Button 0x54030000 0x4 80 108 48 14 "Cancel"
;3 Scintilla 0x54000000 0x20000 136 8 346 114 ""
;END DIALOG
dd.formata(_s)
;out dd
c.insert(i+1)
c[0].formata(" %i" 3)

int sci
int indicBlue(0) indicOrange(1)

if(!ShowDialog(dd &sub.DlgProc &c[0])) end

mes c[c.len-1]

#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,sub.Sci(SCI.SCI_SETHSCROLLBAR 0 0);;hide horz scrollbar
,sub.SetFont(sci "Segoe UI" 12);;set font name and size
,sub.DefineIndicator(indicBlue 0xFF0000)
,sub.DefineIndicator(indicOrange 0x00e0ff)
,sub.SetText(template) ;;set e3 text
,;;;Customize the context menu
,sub.Sci(SCI.SCI_USEPOPUP 0 0)
,case WM_CONTEXTMENU
,sel GetDlgCtrlID(wParam)
,,case 3
,,sel ShowMenu("1 Copy[]2 Paste" hDlg)
,,,case 1 SendMessage wParam SCI.SCI_COPY 0 0
,,,case 2 SendMessage wParam SCI.SCI_PASTE 0 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case else
,word loword;  word hiword
,loword=wParam&0xFFFF
,hiword=wParam>>16
,sel hiword
,,case 768 ;;EN_CHANGE
,,DT_GetControls(hDlg)
,,sub.ClearIndicator(indicBlue)
,,sub.ClearIndicator(indicOrange)
,,sub.RR(template c _s)
,,sub.SetText(_s)
,,for i 1 c.len-1
,,,if(empty(c[i]))
,,,,DT_SetControl(hDlg loword a[0 i-1])
,,,,break
,,,if(i=1)
,,,,tpos[i-1]=find(_s c[i] tpos[i-1])
,,,else
,,,,tpos[i-1]=find(_s c[i] tpos[i-2]+c[i-1].len)
,,,if(loword= i+4)
,,,,sub.SetIndicator(indicBlue c[i] tpos[i-1])
,,,else
,,,,sub.SetIndicator(indicOrange c[i] tpos[i-1])    
,,case 256 ;;EN_SETFOCUS
,,DT_GetControls(hDlg)
,,sub.ClearIndicator(indicBlue)
,,sub.ClearIndicator(indicOrange)
,,for i 1 c.len-1
,,,str text2; sub.GetText(text2)
,,,if(i=1)
,,,,tpos[i-1]=find(text2 c[i] tpos[i-1])            
,,,else
,,,,tpos[i-1]=find(text2 c[i] tpos[i-2]+c[i-1].len)
,,,if(loword= i+4)
,,,,sub.SetIndicator(indicBlue c[i] tpos[i-1])
,,,else
,,,,sub.SetIndicator(indicOrange c[i] tpos[i-1])    
ret 1

#sub RR v
function str'template ARRAY(str)'c str&r [&pos]
int i
ARRAY(POINT) b
findrx(template "┋(.+?)┋" 0 4 b)
int j
for i 0 b.len
,POINT& p=b[0 i]
,r.geta(template j p.x-j)
,r+c[i+1]
,j=p.y
r.geta(template j)

#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)

#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)

#sub DefineIndicator v
function indicator color
sub.Sci(SCI.SCI_INDICSETSTYLE indicator 16)
sub.Sci(SCI.SCI_INDICSETFORE indicator color)
sub.Sci(SCI.SCI_INDICSETUNDER indicator 1)
sub.Sci(SCI.SCI_INDICSETALPHA indicator 128)

#sub SetIndicator v
function indicator $s [spos]
sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
sub.Sci(SCI.SCI_INDICATORFILLRANGE spos len(s))

#sub ClearIndicator v
function indicator
sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
sub.Sci(SCI.SCI_INDICATORCLEARRANGE 0 SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0))

#sub GetText v
function str&text
int n=SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0)
text.fix(SendMessage(sci SCI.SCI_GETTEXT n+1 text.all(n)))

#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)

#sub SetFont
function hwnd [$fontName] [fontSize]
int h=hwnd
if(!empty(fontName)) SendMessage(h SCI.SCI_STYLESETFONT 32 fontName)
if(fontSize) SendMessage(h SCI.SCI_STYLESETSIZE 32 fontSize)
;save <code> styles
type __QDISTYLE colText colBack !bold !italic !underline !eol
ARRAY(__QDISTYLE) a.create(32)
int i
for i 1 18
,__QDISTYLE& r=a[i]
,r.colText=SendMessage(h SCI.SCI_STYLEGETFORE i 0)
,r.colBack=SendMessage(h SCI.SCI_STYLEGETBACK i 0)
,r.bold=SendMessage(h SCI.SCI_STYLEGETBOLD i 0)
,r.italic=SendMessage(h SCI.SCI_STYLEGETITALIC i 0)
,r.underline=SendMessage(h SCI.SCI_STYLEGETUNDERLINE i 0)
,r.eol=SendMessage(h SCI.SCI_STYLEGETEOLFILLED i 0)
;set other styles the same as the default style 32. It clears <code> styles etc, that is why we save/restore them.
SendMessage(h SCI.SCI_STYLECLEARALL 0 0)
;restore
for i 1 18
,&r=a[i]
,SendMessage(h SCI.SCI_STYLESETFORE i r.colText)
,SendMessage(h SCI.SCI_STYLESETBACK i r.colBack)
,SendMessage(h SCI.SCI_STYLESETBOLD i r.bold)
,SendMessage(h SCI.SCI_STYLESETITALIC i r.italic)
,SendMessage(h SCI.SCI_STYLESETUNDERLINE i r.underline)
,SendMessage(h SCI.SCI_STYLESETEOLFILLED i r.eol)
SendMessage(h SCI.SCI_STYLESETVISIBLE 31 0)


Messages In This Thread
RE: Sets the color for specific text within the RichEdit control - by Kevin - 10-17-2022, 02:45 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)