[PB5.20Beta17] Editor Set colour of string?

Windows specific forum
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

[PB5.20Beta17] Editor Set colour of string?

Post by IdeasVacuum »

OK, I have a slew of text in an EditorGadget(), word-wrap on. The following Procedure works perfectly, changing the colour of a selection of the text:

Code: Select all

Procedure EditorColour(iGadget.i, iColour.i, iStart.i, iEnd.i)
;-------------------------------------------------------------
  format.CHARFORMAT2
  format\cbSize = SizeOf(CHARFORMAT2)
  format\dwMask = #CFM_COLOR
  format\crTextColor = iColour

               SendMessage_(GadgetID(iGadget), #EM_SETSEL, iStart, iEnd)
               SendMessage_(GadgetID(iGadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
               SendMessage_(GadgetID(iGadget), #EM_SETSEL, 0, 0)
EndProcedure
However, the selection I wish to change is a hyperlink (which defaults to ugly #Blue). The hyperlink does not change colour using the above, so how do you change it?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [PB5.20Beta17] Editor Set colour of string?

Post by IdeasVacuum »

....A good alternative would be to use a WebGadget(), but how do you get a link to launch a web page in the default browser and not in the WebGadget?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [PB5.20Beta17] Editor Set colour of string?

Post by IdeasVacuum »

Ah, for the WebGadget, a call back is the solution:

Code: Select all

Procedure NavigationCallback(iGadget.i, sUrl.s)
;----------------------------------------------

               If sUrl = "http://www.purebasic.com/"

                              RunProgram(sUrl)
                        ProcedureReturn(#False)
               Else
                        ProcedureReturn(#True)
               EndIf
EndProcedure
The code above runs the web page in the default browser. So, at the end of the day, WebGadget() is a better solution than EditorGadget().
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: [PB5.20Beta17] Editor Set colour of string?

Post by rsts »

RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: [PB5.20Beta17] Editor Set colour of string?

Post by RASHAD »

Maybe :idea:

Code: Select all


LoadFont(0,"Tahoma",12,#PB_Font_HighQuality)
;LoadFont(1,"Tahoma",12,#PB_Font_HighQuality|#PB_Font_Underline)
 
OpenWindow(1,0,0,400,500,"Hyperlink Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
EditorGadget(1,10,10,380,480,#WS_CLIPSIBLINGS)
AddGadgetItem(1,-1,"In case of emergecy Visit PureBasic to get help")
AddGadgetItem(1,-1,"Have fun")
HyperLinkGadget(2,160,12,106,22,"Visit PureBasic", #Red,#PB_HyperLink_Underline|#WS_CLIPSIBLINGS)
SetGadgetColor(2,#PB_Gadget_BackColor,#White)
SetGadgetColor(2,#PB_Gadget_FrontColor,#Gray)
BringWindowToTop_(GadgetID(2))
SetGadgetFont(1,FontID(0))
SetGadgetFont(2,FontID(0))

Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
      
      Case #PB_Event_Menu
          Select EventMenu()
           Case 1            
          EndSelect
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1            
          EndSelect
          

      Case #WM_LBUTTONDOWN

      Case #WM_LBUTTONUP,#PB_Event_LeftClick
             GetWindowRect_(GadgetID(2),r.RECT) 
             GetCursorPos_(p.POINT) 
             If PtInRect_(r,p\y << 32 + p\x)
                ShellExecute_(0,"open","http://www.purebasic.com",0,0,#SW_SHOWNORMAL)
             EndIf
             
  EndSelect 

Until Quit = 1
End

Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [PB5.20Beta17] Editor Set colour of string?

Post by IdeasVacuum »

Nice one Rashad, but using a WebGadget in this case is much easier 8)

rst, that is similar to Freak's code on how to place a hyperlink in an EditorGadget, and find it even when the text is wrapped, which I originally used - but, that just allows the default API #Blue link colour. Using a WebGadget, I have complete control of the colour - starting colour, roll-over colour, followed colour, active colour - a mini disco, yea!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply