Page 2 of 2
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 4:04 pm
by Danilo
netmaestro wrote:Then when i have "BOTH" a Mouse LeftClick + the HyperLinkGadget 's Color = RED
then i execute the following code =
ShellExecute_(0,"open","http://www.purebasic.com",0,0,#SW_SHOWNORMAL)
Code: Select all
Procedure pbsite_linkhandler()
RunProgram("http://www.purebasic.com")
EndProcedure
OpenWindow(0, 0, 0, 270, 160, "HyperlinkGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
HyperLinkGadget(0, 20, 40, 250,20,"PureBasic Website", RGB(255,0,0))
BindGadgetEvent(0, @pbsite_linkhandler(), #PB_EventType_LeftClick)
Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow
I thought the same as netmaestro. Help for HyperLinkGadget does not mention any supported events, but it fires an
event when the hyperlink got clicked.
Classic events, tested on Windows and Mac OS X:
Code: Select all
If OpenWindow(0, 0, 0, 270, 160, "HyperlinkGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
HyperLinkGadget(0, 10, 10, 250,20,"Red HyperLink", RGB(255,0,0))
HyperLinkGadget(1, 10, 30, 250,20,"Arial Underlined Green HyperLink", RGB(0,255,0), #PB_HyperLink_Underline)
SetGadgetColor(0,#PB_Gadget_FrontColor,RGB(0,0,255))
SetGadgetColor(1,#PB_Gadget_FrontColor,RGB(0,0,255))
SetGadgetFont(1, LoadFont(0, "Arial", 12))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
Select EventGadget()
Case 0
If EventType() = #PB_EventType_LeftClick
Debug "http://www.purebasic.com"
EndIf
Case 1
If EventType() = #PB_EventType_LeftClick
Debug "http://www.purearea.net"
EndIf
EndSelect
EndSelect
ForEver
EndIf
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 5:15 pm
by freak
Trying to put a HyperLinkGadget into an EditorGadget is an unnecessarily complex solution to a simple problem. The simple solutions are: use a WebGadget() or if you need editing capabilities, use a ScintillaGadget(). This is crossplatform and requires no hacks. The behavior can even be customized further with scintilla messages:
Code: Select all
ProcedureDLL ScintillaCallBack(Gadget, *scinotify.SCNotification)
If *scinotify\nmhdr\code = #SCN_HOTSPOTCLICK
If *scinotify\position >= 20 And *scinotify\position < 35
ShellExecute_(0,"open","http://www.purebasic.com",0,0,#SW_SHOWNORMAL)
EndIf
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 400, 500, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If InitScintilla()
ScintillaGadget(0, 10, 10, 380, 480, @ScintillaCallBack())
; set text
*Buffer = AllocateMemory(1000)
PokeS(*Buffer, "In case of emergecy Visit PureBasic to get help" + Chr(10) + "Have fun", -1, #PB_Ascii)
ScintillaSendMessage(0, #SCI_SETTEXT, 0, *Buffer)
; normal text style
ScintillaSendMessage(0, #SCI_STYLESETFONT, 0, @"Tahoma")
ScintillaSendMessage(0, #SCI_STYLESETSIZE, 0, 12)
; hyperlink style
ScintillaSendMessage(0, #SCI_STYLESETFONT, 1, @"Tahoma")
ScintillaSendMessage(0, #SCI_STYLESETSIZE, 1, 12)
ScintillaSendMessage(0, #SCI_STYLESETFORE, 1, #Gray)
ScintillaSendMessage(0, #SCI_STYLESETHOTSPOT, 1, #True)
ScintillaSendMessage(0, #SCI_SETHOTSPOTACTIVEFORE, #True, #Red)
ScintillaSendMessage(0, #SCI_SETHOTSPOTACTIVEUNDERLINE, #True)
; apply styles
ScintillaSendMessage(0, #SCI_STARTSTYLING, 20, $FF)
ScintillaSendMessage(0, #SCI_SETSTYLING, 15, 1)
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 6:33 pm
by RASHAD
The manual say nothing about HyperLink() support for any event
Now it looks that it support EventGadget() and EventType(),how come !
Thanks NM and Danilo
I do not think that WebGadget() support different color for the Hilight Color
Because it is hard coded
For ScintillaGadget yes it looks v good but still not so easy you are using a CallBack
After all I think it is the best for now
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 6:59 pm
by Little John
RASHAD wrote:The manual say nothing about HyperLink() support for any event
Now it looks that it support EventGadget() and EventType(),how come !
EventGadget() does of course support the HyperLinkGadget -- otherwise the HyperLinkGadget would not be usable.
Help for EventGadget() wrote:After an event of type #PB_Event_Gadget (returned by WindowEvent() or WaitWindowEvent()), use this function to determine which gadget has been triggered. It returns the #Gadget number.
This applies to the HyperLinkGadget as well as to all other gadgets, no?
Unfortunately, the example in the help for HyperLinkGadget is incomplete.
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 7:05 pm
by freak
The ButtonGadget page also does not specifically mention EventGadget(). I think it is pretty self explanatory that a clickable gadget fires an event when clicked
RASHAD wrote:I do not think that WebGadget() support different color for the Hilight Color
Because it is hard coded
Of course it does. You can modify the link behavior using CSS.
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 7:35 pm
by RASHAD
While this is the first time I noticed what you said about ButtonGadget()

I owe you one
I was using it by logic that it is created to do something
Now why do not you (Andre I mean) make a standard help for all gadgets?
For the second part if I agree with you it still not straight forward task
I prefer ScintillaGadget in this case
(Until now maybe later I will have difficulties with it

)
Thanks freak
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 7:36 pm
by VB6_to_PBx
RASHAD
netmaestro
Danilo
freak
Thanks very much for all the great Code examples you've Posted !!!!

Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Mon Sep 16, 2013 2:47 pm
by IdeasVacuum
Html code, save as, e.g, hyperlinks.html:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">
<title>Hyperlinks</title>
<style type="text/css">
body {margin: 0px; padding: 0px;}
a.hlink_1:link {color:#0000ff;}
a.hlink_1:visited {color:#ff8000;}
a.hlink_1:hover {color:#ff0000;}
a.hlink_1:active {color:#ff00ff;}
</style>
</head>
<body text="#000000" style="background-color:#ffffff; text-align:left; height:400px;">
<div style="background-color:transparent;text-align:left;margin-left:auto;margin-right:auto;position:relative;width:400px;height:400px;">
<div style="position:absolute;left:58px;top:40px;width:244px;height:20px;">
<a class="hlink_1" href="http://www.purebasic.com/" target="_blank" style="text-decoration:underline;">http://www.purebasic.com/</a></span></div>
<div style="position:absolute;left:58px;top:80px;width:265px;height:20px;">
<a class="hlink_1" href="http://www.purebasic.fr/blog/" target="_blank" style="text-decoration:underline;">http://www.purebasic.fr/blog/</a></span></div>
</div>
</body>
</html>