It is currently Wed Oct 21, 2020 3:02 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Sep 07, 2020 9:03 pm 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
Thanks XCoder on corrections
I am not that good in PB like you..
yes i see now when i do mistakes...
sorry if i bothering you with questions and also i have one more .
next exemple is also from forum and also not work because i get error about not valid
i looked again and again and cannot figured why is not valid..it is supose to highlite keywords from array??
or not ...
here is acode :
Code:
Enumeration
#MainWindow
EndEnumeration
;Gadget enumeration.
Enumeration
#RichEdit
EndEnumeration
;Font enumeration
Enumeration
#FontEdit
EndEnumeration
;Declare constants.
#COLOR_Text = $000000 : #EFFECTS_Text = 0
#COLOR_Symbol = $ff0000 : #EFFECTS_Symbol = #CFE_ITALIC
#NbBasicKeywords = 126; ***NOT 64!
Dim validcharacters(126)
;Load fonts.
LoadFont(#FontEdit, "Times New Roman", 16)
;Declare procedures.
Declare HighlightLine(Line)
Declare InitSyntaxHighlightning()
Declare WindowCallback(hWnd, uMsg, wParam, lParam)
;- Open main window and display gadgets.
OpenWindow(#MainWindow,0,0,400,400,"EDitor", #PB_Window_Invisible | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget,1)
ShowWindow_(WindowID(#MainWindow), #SW_MAXIMIZE)
CreateGadgetList(WindowID(#MainWindow))
EditorGadget(#RichEdit,0,50,3*WindowWidth(#MainWindow)/4,WindowHeight(#MainWindow)-50)
;SetGadgetFont(#RichEdit, UseFont(#FontEdit))
SendMessage_(GadgetID(#RichEdit), #EM_SETBKGNDCOLOR, 0, $b6fcf8); Set background colour.
;Allow the trapping of the EN_CHANGE message which occurs after the contents of the editor gadget
;has changed.
SendMessage_(GadgetID(#RichEdit), #EM_SETEVENTMASK, 0, #ENM_CHANGE)
;ActivateGadget(#RichEdit)
;InitSyntaxHighlightning()
SetWindowCallback(@WindowCallback())
;Main message loop..
Repeat
  EventID=WaitWindowEvent()
Until EventID = #WM_CLOSE
;- Highlight line
;The following procedure scans the given line of text in the richedit control looking for occurrences of
;the word "test". Such words are coloured and set to italic.
Procedure HighlightLine(Line)
  Protected LineText.s, Format.CHARFORMAT, StartPos, Endpos, Left, Right, Flag.b
 
  LineText = LCase(GetGadgetItemText(#RichEdit, Line,0))
  ;Get the character index's of both ends of the line.
  StartPos = SendMessage_(GadgetID(#RichEdit),#EM_LINEINDEX, Line,0)
  EndPos = StartPos + Len(LineText)
  Format\cbSize = SizeOf(CHARFORMAT)
  Format\dwMask = #CFM_COLOR | #CFM_BOLD | #CFM_ITALIC
  Left = StartPos
  Restore BasicKeywords
  For a=1 To 126
    Left = StartPos
    Read.s inst$
    Repeat
      Right = FindString(LineText, inst$, Left-StartPos+1) + StartPos
      If Right = StartPos;No occurrences found.
        Left = EndPos
      Else
        ;******
        Left = Right-1 : Right + Len(inst$)-1
        ;******
        check$=Mid(LineText,right+1,1)
        Debug check$
        If check$=" "
          SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right);Highlight the word.
          Left = Right
          Format\crTextColor = #COLOR_Symbol : Format\dwEffects = #EFFECTS_Symbol
          SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
 
          SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Left+1);Highlight the word.         
          Format\crTextColor = #COLOR_text : Format\dwEffects = #EFFECTS_text
          SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
        Else
          left=right+1
          Debug "yes"
        EndIf
      EndIf
    Until Left = EndPos
ttt:
  Next a
;  Repeat
    ;Identify possible occurrences of "test".
;    Right = FindString(LineText, "test", Left-StartPos+1) + StartPos
;    If Right = StartPos;No occurrences found so colour entire line with the default text colour.
;       Left = EndPos
;    Else
;      SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right-1)
;      Format\crTextColor = #COLOR_Text : Format\dwEffects = #EFFECTS_Text
;      SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
;      Left = Right-1 : Right + 3
;      SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right);Highlight the word "test"
;      Left = Right
;      Format\crTextColor = #COLOR_Symbol : Format\dwEffects = #EFFECTS_Symbol
;      SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
;    EndIf
;  Until Left = EndPos
 
EndProcedure
;- window callback
;The following call back procedure is responsible for syntax highlighting etc.
;It does this by intercepting the #EN_CHANGE command message which fires whenever
;text in the rich edit control has changed. We then examine the entire line containing the text.
Procedure WindowCallback(hWnd, uMsg, wParam, lParam)
Protected ReturnValue, Chr.CHARRANGE, Line, CurrentStartPos
ReturnValue = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_COMMAND
If wParam >>16 = #EN_CHANGE And lparam = GadgetID(#RichEdit)
;The following returns the index (0-based) of the line containing the current character.
SendMessage_(GadgetID(#RichEdit),#EM_GETSEL,@CurrentStartPos, @Line)
Line = SendMessage_(GadgetID(#RichEdit),#EM_LINEFROMCHAR, CurrentStartPos,0)
SendMessage_(GadgetID(#RichEdit), #EM_HIDESELECTION, 1,0)
HighlightLine(Line)
If GetAsyncKeyState_(#VK_RETURN) & 1 = 1;  Bit 0 is set if the enter key was pressed since the last check.
;Investigate the previous line.
HighlightLine(Line-1)
EndIf
SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, CurrentStartPos,CurrentStartPos); Return cursor to its correct position.
SendMessage_(GadgetID(#RichEdit),#EM_SETMODIFY,0,0)
SendMessage_(GadgetID(#RichEdit), #EM_HIDESELECTION, 0,0)
EndIf
EndSelect
ProcedureReturn(Returnvalue)
EndProcedure
Procedure InitSyntaxHighlightning()
; Build the ValidCharacter table to have have a faster routine to detect
; If the char is a considered as a string Or not. Nice improvement :)
For k='0' To '9'
ValidCharacters(k) = 1 ; i receive error here that is not valid ???
Next
For k='A' To 'Z'
ValidCharacters(k) = 1
Next
For k='a' To 'z'
ValidCharacters(k) = 1
Next
ValidCharacters('_') = 1
  DataSection
    BasicKeywords:
 
    Data.s "And", "and"
    Data.s "CallDebugger"     , "calldebugger"
    Data.s "Case"             , "case"
    Data.s "CompilerCase"     , "compilercase"
    Data.s "CompilerDefault"  , "compilerdefault"
    Data.s "CompilerElse"     , "compilerelse"
    Data.s "CompilerEndIf"    , "compilerendif"
    Data.s "CompilerEndSelect", "compilerendselect"
    Data.s "CompilerIf"       , "compilerif"
    Data.s "CompilerSelect"   , "compilerselect"
    Data.s "Data"           , "data"
    Data.s "DataSection"    , "datasection"
    Data.s "Debug"          , "debug"
    Data.s "DebugLevel"     , "debuglevel"
    Data.s "Declare"        , "declare"
    Data.s "DeclareDLL"     , "declaredll"
    Data.s "Default"        , "default"
    Data.s "DefType"        , "deftype"
    Data.s "Dim"            , "dim"
    Data.s "DisableDebugger", "disabledebugger"
    Data.s "Else"         , "else"
    Data.s "ElseIf"       , "elseif"
    Data.s "EnableDebugger", "enabledebugger"
    Data.s "End"         , "end"
    Data.s "EndDataSection", "enddatasection"
    Data.s "EndIf"       , "endif"
    Data.s "EndProcedure", "endprocedure"
    Data.s "EndSelect"   , "endselect"
    Data.s "EndStructure", "endstructure"
    Data.s "EndStructureUnion", "endstructureunion"
    Data.s "FakeEndSelect", "fakeendselect"
    Data.s "FakeReturn"   , "fakereturn"
    Data.s "For"          , "for"
    Data.s "ForEver"      , "forever"
    Data.s "Global", "global"
    Data.s "Gosub", "gosub"
    Data.s "Goto" , "goto"
    Data.s "If", "if"
    Data.s "IncludeBinary", "includebinary"
    Data.s "IncludeFile", "includefile"
    Data.s "IncludePath", "includepath"
    Data.s "NewList", "newlist"
    Data.s "Next", "next"
    Data.s "Or", "or"
    Data.s "Procedure"      , "procedure"
    Data.s "ProcedureDLL"   , "proceduredll"
    Data.s "ProcedureReturn", "procedurereturn"
    Data.s "Protected"      , "protected"
    Data.s "Read", "read"
    Data.s "Repeat", "repeat"
    Data.s "Restore", "restore"
    Data.s "Return", "return"
    Data.s "Select", "select"
    Data.s "Shared", "shared"
    Data.s "Step", "step"
    Data.s "Structure", "structure"
    Data.s "StructureUnion", "structureunion"
   
    Data.s "To", "to"
    Data.s "Until", "until"
    Data.s "Wend" , "wend"
    Data.s "While", "while"
    Data.s "XIncludeFile" , "xincludefile"
    Data.s "XOr" , "xor"
  EndDataSection
EndProcedure 


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Sep 07, 2020 9:10 pm 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
Sorry it is not array than data section
but for better understanding (for me ) is there a way to put keywords in array maybe ?


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Sep 07, 2020 9:49 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4963
Location: Germany
I don't know where you are finding such old codes :lol:

Code:
Enumeration
  #MainWindow
EndEnumeration
;-Gadget enumeration.
Enumeration
  #RichEdit
EndEnumeration
;-Font enumeration
Enumeration
  #FontEdit
EndEnumeration
;-Declare constants.
#COLOR_Text = $000000 : #EFFECTS_Text = 0
#COLOR_Symbol = $ff0000 : #EFFECTS_Symbol = #CFE_ITALIC
#NbBasicKeywords = 126; ***NOT 64!
Global Dim validcharacters(126)
;-Load fonts.
LoadFont(#FontEdit, "Times New Roman", 16)
;-Declare procedures.
Declare HighlightLine(Line)
Declare InitSyntaxHighlightning()
Declare WindowCallback(hWnd, uMsg, wParam, lParam)
;-Open main window and display gadgets.
OpenWindow(#MainWindow, 0, 0, 400, 400,"EDitor", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
;ShowWindow_(WindowID(#MainWindow), #SW_MAXIMIZE)
;CreateGadgetList(WindowID(#MainWindow))
EditorGadget(#RichEdit, 0, 50, 3*WindowWidth(#MainWindow)/4, WindowHeight(#MainWindow)-50)
SetGadgetFont(#RichEdit, FontID(#FontEdit))
SetGadgetColor(#RichEdit, #PB_Gadget_BackColor, $b6fcf8)
;SendMessage_(GadgetID(#RichEdit), #EM_SETBKGNDCOLOR, 0, $b6fcf8); Set background colour.
                                                                ;Allow the trapping of the EN_CHANGE message which occurs after the contents of the editor gadget
                                                                ;has changed.
SendMessage_(GadgetID(#RichEdit), #EM_SETEVENTMASK, 0, #ENM_CHANGE)
;ActivateGadget(#RichEdit)
InitSyntaxHighlightning()
SetWindowCallback(@WindowCallback())
;-Main message loop..
Repeat
  EventID=WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow



;- Highlight line
;The following procedure scans the given line of text in the richedit control looking for occurrences of
;the word "test". Such words are coloured and set to italic.
Procedure HighlightLine(Line)
  Protected LineText.s, Format.CHARFORMAT, StartPos, Endpos, Left, Right, Flag.b
 
  LineText = LCase(GetGadgetItemText(#RichEdit, Line,0))
  ;Get the character index's of both ends of the line.
  StartPos = SendMessage_(GadgetID(#RichEdit),#EM_LINEINDEX, Line,0)
  EndPos = StartPos + Len(LineText)
  Format\cbSize = SizeOf(CHARFORMAT)
  Format\dwMask = #CFM_COLOR | #CFM_BOLD | #CFM_ITALIC
  Left = StartPos
  Restore BasicKeywords
  For a=1 To 126
    Left = StartPos
    Read.s inst$
    Repeat
      Right = FindString(LineText, inst$, Left-StartPos+1) + StartPos
      If Right = StartPos;No occurrences found.
        Left = EndPos
      Else
        ;******
        Left = Right-1 : Right + Len(inst$)-1
        ;******
        check$=Mid(LineText,right+1,1)
        Debug check$
        If check$=" "
          SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right);Highlight the word.
          Left = Right
          Format\crTextColor = #COLOR_Symbol : Format\dwEffects = #EFFECTS_Symbol
          SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
         
          SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Left+1);Highlight the word.         
          Format\crTextColor = #COLOR_text : Format\dwEffects = #EFFECTS_text
          SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
        Else
          left=right+1
          Debug "yes"
        EndIf
      EndIf
    Until Left = EndPos
    ttt:
  Next a
  ;  Repeat
  ;Identify possible occurrences of "test".
  ;    Right = FindString(LineText, "test", Left-StartPos+1) + StartPos
  ;    If Right = StartPos;No occurrences found so colour entire line with the default text colour.
  ;       Left = EndPos
  ;    Else
  ;      SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right-1)
  ;      Format\crTextColor = #COLOR_Text : Format\dwEffects = #EFFECTS_Text
  ;      SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
  ;      Left = Right-1 : Right + 3
  ;      SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right);Highlight the word "test"
  ;      Left = Right
  ;      Format\crTextColor = #COLOR_Symbol : Format\dwEffects = #EFFECTS_Symbol
  ;      SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
  ;    EndIf
  ;  Until Left = EndPos
 
EndProcedure
;- window callback
;The following call back procedure is responsible for syntax highlighting etc.
;It does this by intercepting the #EN_CHANGE command message which fires whenever
;text in the rich edit control has changed. We then examine the entire line containing the text.
Procedure WindowCallback(hWnd, uMsg, wParam, lParam)
  Protected ReturnValue, Chr.CHARRANGE, Line, CurrentStartPos
  ReturnValue = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_COMMAND
      If wParam >>16 = #EN_CHANGE And lparam = GadgetID(#RichEdit)
        ;The following returns the index (0-based) of the line containing the current character.
        SendMessage_(GadgetID(#RichEdit),#EM_GETSEL,@CurrentStartPos, @Line)
        Line = SendMessage_(GadgetID(#RichEdit),#EM_LINEFROMCHAR, CurrentStartPos,0)
        SendMessage_(GadgetID(#RichEdit), #EM_HIDESELECTION, 1,0)
        HighlightLine(Line)
        If GetAsyncKeyState_(#VK_RETURN) & 1 = 1;  Bit 0 is set if the enter key was pressed since the last check.
                                                ;Investigate the previous line.
          HighlightLine(Line-1)
        EndIf
        SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, CurrentStartPos,CurrentStartPos); Return cursor to its correct position.
        SendMessage_(GadgetID(#RichEdit),#EM_SETMODIFY,0,0)
        SendMessage_(GadgetID(#RichEdit), #EM_HIDESELECTION, 0,0)
      EndIf
  EndSelect
  ProcedureReturn(Returnvalue)
EndProcedure

Procedure InitSyntaxHighlightning()
  ; Build the ValidCharacter table to have have a faster routine to detect
  ; If the char is a considered as a string Or not. Nice improvement :)
  For k='0' To '9'
    ValidCharacters(k) = 1 ; i receive error here that is not valid ???
  Next
  For k='A' To 'Z'
    ValidCharacters(k) = 1
  Next
  For k='a' To 'z'
    ValidCharacters(k) = 1
  Next
  ValidCharacters('_') = 1
EndProcedure


DataSection
    BasicKeywords:
   
    Data.s "And", "and"
    Data.s "CallDebugger"     , "calldebugger"
    Data.s "Case"             , "case"
    Data.s "CompilerCase"     , "compilercase"
    Data.s "CompilerDefault"  , "compilerdefault"
    Data.s "CompilerElse"     , "compilerelse"
    Data.s "CompilerEndIf"    , "compilerendif"
    Data.s "CompilerEndSelect", "compilerendselect"
    Data.s "CompilerIf"       , "compilerif"
    Data.s "CompilerSelect"   , "compilerselect"
    Data.s "Data"           , "data"
    Data.s "DataSection"    , "datasection"
    Data.s "Debug"          , "debug"
    Data.s "DebugLevel"     , "debuglevel"
    Data.s "Declare"        , "declare"
    Data.s "DeclareDLL"     , "declaredll"
    Data.s "Default"        , "default"
    Data.s "DefType"        , "deftype"
    Data.s "Dim"            , "dim"
    Data.s "DisableDebugger", "disabledebugger"
    Data.s "Else"         , "else"
    Data.s "ElseIf"       , "elseif"
    Data.s "EnableDebugger", "enabledebugger"
    Data.s "End"         , "end"
    Data.s "EndDataSection", "enddatasection"
    Data.s "EndIf"       , "endif"
    Data.s "EndProcedure", "endprocedure"
    Data.s "EndSelect"   , "endselect"
    Data.s "EndStructure", "endstructure"
    Data.s "EndStructureUnion", "endstructureunion"
    Data.s "FakeEndSelect", "fakeendselect"
    Data.s "FakeReturn"   , "fakereturn"
    Data.s "For"          , "for"
    Data.s "ForEver"      , "forever"
    Data.s "Global", "global"
    Data.s "Gosub", "gosub"
    Data.s "Goto" , "goto"
    Data.s "If", "if"
    Data.s "IncludeBinary", "includebinary"
    Data.s "IncludeFile", "includefile"
    Data.s "IncludePath", "includepath"
    Data.s "NewList", "newlist"
    Data.s "Next", "next"
    Data.s "Or", "or"
    Data.s "Procedure"      , "procedure"
    Data.s "ProcedureDLL"   , "proceduredll"
    Data.s "ProcedureReturn", "procedurereturn"
    Data.s "Protected"      , "protected"
    Data.s "Read", "read"
    Data.s "Repeat", "repeat"
    Data.s "Restore", "restore"
    Data.s "Return", "return"
    Data.s "Select", "select"
    Data.s "Shared", "shared"
    Data.s "Step", "step"
    Data.s "Structure", "structure"
    Data.s "StructureUnion", "structureunion"
   
    Data.s "To", "to"
    Data.s "Until", "until"
    Data.s "Wend" , "wend"
    Data.s "While", "while"
    Data.s "XIncludeFile" , "xincludefile"
    Data.s "XOr" , "xor"
EndDataSection


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Sep 07, 2020 10:23 pm 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
hi
I found it here on forum using Search...
I see you changed it to:

Global Dim validcharacters(126)

so must be Gloabal ..well i dont know that
very interesting program..also Debug jumps on keyword..nice !
thanks ! it work now :D


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Tue Sep 08, 2020 9:17 am 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
Program have one problem
Only first line of editor gadget is colored
it should be line 0


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Tue Sep 08, 2020 11:51 am 
Offline
User
User

Joined: Tue Dec 31, 2013 9:18 pm
Posts: 21
You have an error in line 69:

Code:
check$=Mid(LineText,right+1,1)


right gives a position in the Editor Gadget, but you are using right to set the starting position for extracting text from the string LineText. To get the correct value for the starting position for extracting text from the string LineText you need to subtract StartPos from right:

Code:
check$=Mid(LineText,right+1-StartPos,1)


Another point: In line 56 you have

Code:
Left = StartPos


However, in line 59 you have the same instruction. You can remove line 56 from your code as it is redundant.


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Tue Sep 08, 2020 5:12 pm 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
Thank you very much X-Coder
I will never figured that
and now syntax coloring work in other lines too..
that is great...

I am not sure why is Restore BasicKeywords called every time when
EN_CHANGE even is invoked , is it called every time ?
Is there a way to load keywords one and then use it without restoring?
thanks again !


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Tue Sep 08, 2020 6:59 pm 
Offline
User
User

Joined: Tue Dec 31, 2013 9:18 pm
Posts: 21
aston wrote:
I am not sure why is Restore BasicKeywords called every time when
EN_CHANGE even is invoked , is it called every time ?
Is there a way to load keywords one and then use it without restoring?
thanks again !


The keywords in the data section are not being reloaded every time EN_CHANGE is called. The keywords are loaded once when the program runs. The Help file for PureBasic explains the purpose of the Restore instruction as an instruction that sets the start indicator for the Read instruction to a specified label. So the instruction Restore BasicKeywords ensures that next time the data section is read then the first item following the label BasicKeywords: in the data section is read when the instruction Read.s inst$ runs.


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Wed Sep 09, 2020 1:30 pm 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
Thanks xCoder
I hope that I understand it now .
I will read help...
As i said before it should be possible to read keywords from string array too.
Just one small thing...
there is a label ttt: in a program
it looks to me that is there without purpose or i was wrong again...


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Wed Sep 09, 2020 1:55 pm 
Offline
User
User

Joined: Tue Dec 31, 2013 9:18 pm
Posts: 21
aston wrote:
Just one small thing...
there is a label ttt: in a program
it looks to me that is there without purpose or i was wrong again...


You are right - the label can be removed.


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Sun Sep 27, 2020 6:53 pm 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
Hello
Can i use same routine to highlight in more colors ,for example some keywords in red color
not only in blue ?
thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Sun Sep 27, 2020 7:21 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4963
Location: Germany
Then you have to store the wanted color after each Keyword.
Read it out and use it :wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Wed Sep 30, 2020 9:43 am 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
well not exactly like that
i mean group in RED
and maybe comment in GREEN
so do i need to build more DATA sections?


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Wed Sep 30, 2020 2:08 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4963
Location: Germany
Exactly like that.

Code:
Procedure HighlightLine(Line)
  Protected LineText.s, Format.CHARFORMAT, StartPos, Endpos, Left, Right, Flag.b, COLOR_Symbol.l
 
  LineText = LCase(GetGadgetItemText(#RichEdit, Line,0))
  ;Get the character index's of both ends of the line.
  StartPos = SendMessage_(GadgetID(#RichEdit),#EM_LINEINDEX, Line,0)
  EndPos = StartPos + Len(LineText)
  Format\cbSize = SizeOf(CHARFORMAT)
  Format\dwMask = #CFM_COLOR | #CFM_BOLD | #CFM_ITALIC
  Left = StartPos
 
  Restore BasicKeywords
 
  For a=1 To 4
    Left = StartPos
   
    Read.s inst$
    Read.l COLOR_Symbol
   
    Repeat
      Right = FindString(LineText, inst$, Left-StartPos+1) + StartPos
      If Right = StartPos;No occurrences found.
        Left = EndPos
      Else
        ;******
        Left = Right-1 : Right + Len(inst$)-1
        ;******
        check$=Mid(LineText,right+1,1)
        Debug check$
        If check$=" "
          SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right);Highlight the word.
          Left = Right
          Format\crTextColor = COLOR_Symbol : Format\dwEffects = #EFFECTS_Symbol
          SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
         
          SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Left+1);Highlight the word.         
          Format\crTextColor = #COLOR_text : Format\dwEffects = #EFFECTS_text
          SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
        Else
          left=right+1
          Debug "yes"
        EndIf
      EndIf
    Until Left = EndPos
    ttt:
  Next a
 
EndProcedure

Code:
DataSection
  BasicKeywords:
 
  Data.s "And"
  Data.l #Red
  Data.s "and"
  Data.l #Red
  Data.s "CallDebugger"
  Data.l #Green
  Data.s "calldebugger"
  Data.l #Green
EndDataSection


But it is a waste of memory.
Better something which checks the lcase version of the keyword, then you need half of the space.


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Wed Sep 30, 2020 8:21 pm 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
well yes
it is easiest way if i need just few keywords in RED use this:

Code:
 If check$=" "
          SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right);Highlight the word.
          Left = Right
          Format\crTextColor = COLOR_Symbol : Format\dwEffects = #EFFECTS_Symbol
         if inst$ = "var" : Format\crTextColor = COLOR_RED : Endif  ; new color !red
          SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
         
          SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Left+1);Highlight the word.         
          Format\crTextColor = #COLOR_text : Format\dwEffects = #EFFECTS_text
          SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
        Else


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: Majestic-12 [Bot] and 57 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye