Robert May > Win32-GUI-HyperLink-0.14 > Win32::GUI::HyperLink

Download:
Win32-GUI-HyperLink/Win32-GUI-HyperLink-0.14.tar.gz

Dependencies

Annotate this POD

Related Modules

Win32::GUI
more...
By perlmonks.org

CPAN RT

Open  1
View/Report Bugs
Module Version: 0.14   Source  

NAME ^

Win32::GUI::HyperLink - A Win32::GUI Hyperlink control

SYNOPSIS ^

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 Win32::GUI::Label 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.

METHODS ^

new

  $hyperlink = Win32::GUI::HyperLink->new($parent, %options);

  $hyperlink = $window->AddHyperLink(%options);

Takes any options that Win32::GUI::Label does with the following changes:

-url

The Link to launch. e.g. -url => "http://www.perl.com/", If not supplied will default to -text.

-onMouseIn

A code reference to call when the mouse moves over the link text.

-onMouseOut

A code reference to call when the mouse moves off the link text.

-underline

Controls how the text behaves as the mouse moves over and off the link text. Possible values are: 0 Text is not underlined. 1 Text is underlined when the mouse is over the link text. This is the default. 2 Text is always underlined.

Differences to Win32::GUI::Label

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.

Original/Old Event Model (OEM)

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

  $url = $hyperlink->Url();

Get the value of the current link.

  $hyperlink->Url($url);

Set the value of the current link.

Launch

  $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 carps 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.

AUTHOR ^

Robert May, <robertmay@cpan.org>

REQUIRES ^

Win32::GUI v1.02 or later.

COMPATABILITY ^

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.

EXAMPLES ^

  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);

BUGS ^

See the TODO file from the disribution.

Please report any bugs or feature requests to the Author.

ACKNOWLEDGEMENTS ^

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 & LICENSE ^

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.

syntax highlighting: