Page 1 of 1
[PB5.20Beta17] Editor Set colour of string?
Posted: Sat Sep 07, 2013 12:17 am
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?
Re: [PB5.20Beta17] Editor Set colour of string?
Posted: Sat Sep 07, 2013 2:56 am
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?
Re: [PB5.20Beta17] Editor Set colour of string?
Posted: Sat Sep 07, 2013 3:18 am
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().
Re: [PB5.20Beta17] Editor Set colour of string?
Posted: Sat Sep 07, 2013 6:34 am
by rsts
Re: [PB5.20Beta17] Editor Set colour of string?
Posted: Sat Sep 07, 2013 8:44 am
by RASHAD
Maybe
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
Re: [PB5.20Beta17] Editor Set colour of string?
Posted: Mon Sep 09, 2013 11:44 pm
by IdeasVacuum
Nice one Rashad, but using a WebGadget in this case is much easier
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!