Win32::GUI::HyperLink - A Win32::GUI Hyperlink control |
Win32::GUI::HyperLink - A Win32::GUI Hyperlink control
Win32::GUI::HyperLink is a Win32::GUI::Label that acts as a clickable hyperlink. By default it has a 'hand' Cursor, is drawn in blue text rather than black and the text is dynamically underlined when the mouse moves over the text. The Label can be clicked to launch a hyperlink, and supports onMouseIn and onMouseOut events to allow (for example) the link url to be displayed while the mouse is over the link.
use Win32::GUI::HyperLink;
my $hyperlink = Win32::GUI::HyperLink->new($parent_window, %options);
my $hyperlink = $parent_window->AddHyperLink(%options);
$url = $hyperlink->Url();
$hyperlink->Url($url);
$hyperlink->Launch();
Win32::GUI::HyperLink is a sub-class of Win32::GUI::Label, and so supports all the options and methods of Win32::GUI::Label. See the the Win32::GUI::Label manpage documentation for further information. Anywhere that behaviour differs is highlighted below.
See the HyperLinkDemo.pl script for examples of using the functionality. This demo script can be found in the .../Win32/GUI/demos/HyperLink directory beneath the installation directory.
$hyperlink = Win32::GUI::HyperLink->new($parent, %options);
$hyperlink = $window->AddHyperLink(%options);
Takes any options that the Win32::GUI::Label manpage does with the following changes:
-url => "http://www.perl.com/",
If not supplied will default to -text.
If -text is not supplied, then -text defaults to -url. (If neither -url nor -text are supplied, then you have an empty label!)
-notify is always set to 1.
If a -onClick handler is supplied, then the default action of launching the link when the link is clicked is disabled. See Launch method for how to get this functionality from you own Click handler.
Win32::GUI::HyperLink will call the subroutines
main::NAME_MouseIn
and main::NAME_MouseOut
, if they exist, when the mouse moves over the link,
and when the mouse moves out oif the link respectively, where NAME is
the name of the label, set with the -name option.
$url = $hyperlink->Url();
Get the value of the current link.
$hyperlink->Url($url);
Set the value of the current link.
$hyperlink->Launch();
Launches the link url in the user's default browser. This method is supplied
to make it easy to call the default Click functionality from your
own Click Handler. If you pass a -onClick
option to the constructor
then the default handler is disabled. This allows you to turn off
the default click behaviour by passing a reference to an empty
subroutine:
-onClick => sub {},
If you have your own Click handler, then the default behaviour can be restored
by calling $self->Launch()
from within your handler.
Returns 1
on Success, 0
on failure (and carp
s a warning),
and undef
if there is no link url to try to launch.
Launch()
passes the value of the link url to the operating
system, which launches the link in the user's default browser.
The link is passed to the Windows ShellExecute function, and so any valid executable program or document that has a file association should be successsfully started.
Robert May, <robertmay@cpan.org>
the Win32::GUI manpage v1.02 or later.
This module should be backwards compatable with all prior Win32::GUI::HyperLink releases, including the original (v0.02) release. If you find that it is not, please inform the Author.
use strict; use warnings;
use Win32::GUI 1.02; use Win32::GUI::HyperLink;
# A window my $win = Win32::GUI::Window->new( -title => "HyperLink", -pos => [ 100, 100 ], -size => [ 240, 200 ], );
# Simplest usage $win->AddHyperLink( -text => "http://www.perl.org/", -pos => [10,10], );
$win->Show(); Win32::GUI::Dialog(); exit(0);
See the TODO file from the disribution.
Please report any bugs or feature requests to the Author.
Many thanks to the Win32::GUI developers at http://sourceforge.net/projects/perl-win32-gui/
There was a previous incarnation of Win32::GUI::HyperLink that was posted on win32-gui-users@lists.sourceforge.net in 2001. I am not sure of the original author but it looks like Aldo Calpini.
Some of the ideas here are taken from http://www.codeguru.com/Cpp/controls/staticctrl/article.php/c5803/
Copyright 2005..2009 Robert May, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Win32::GUI::HyperLink - A Win32::GUI Hyperlink control |