SystemTray::Applet::Win32 - Windows support for SystemTray::Applet


SystemTray-Applet-Win32 documentation Contained in the SystemTray-Applet-Win32 distribution.

Index


Code Index:

NAME

Top

SystemTray::Applet::Win32 - Windows support for SystemTray::Applet

VERSION

Top

Version 0.02

SYNOPSIS

Top

This module provides windows support for SystemTray::Applet.

    use SystemTray::Applet::Win32;

    my $foo = SystemTray::Applet::Win32->create( "text" => "hello world" );

By default the console window is hidden during program execution. If you want to leave it visible then pass 0 to the module import.

    use SystemTray::Applet::Win32 qw(0);

FUNCTIONS

Top

function1

init

 $self->init();

Initialize the toolkit env. Creates the notification icon

start

 $self->start();

Start the gui up by starting the win32 mainloop. Never returns.

create_icon

 $self->create_icon("an_icon.jpg" );

Create an icon from a file and return it. Supports whatever Win32::GUI::Icon does.

display

 $self->display();

Display the icon with the text as hovertext if we have an icon or hovertext with no icon if none is specified.

schedule

 $self->schedule();

Schedule the callback.

_order

This specifies the priority used by SystemTray::Applet->new when loading plugin. Win32 is 1 as if it is installed we should probably use it.

AUTHOR

Top

Peter Sinnott, <psinnott at cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-systemtray-applet-win32 at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SystemTray-Applet-Win32. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc SystemTray::Applet::Win32




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=SystemTray-Applet-Win32

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/SystemTray-Applet-Win32

* CPAN Ratings

http://cpanratings.perl.org/d/SystemTray-Applet-Win32

* Search CPAN

http://search.cpan.org/dist/SystemTray-Applet-Win32

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


SystemTray-Applet-Win32 documentation Contained in the SystemTray-Applet-Win32 distribution.
package SystemTray::Applet::Win32;

use warnings;
use strict;

use base qw( SystemTray::Applet );

use Win32::GUI();

# this helps the applet die gracefully if windows shuts down
$SIG{QUIT} = "DEFAULT";

sub import
{
    my ( $class , $hidden ) = @_;
    
    if( !defined($hidden))
    {
        $hidden = 1;
    }
    
    if( $hidden )
    {
        my ($DOS) = Win32::GUI::GetPerlWindow();
        Win32::GUI::Hide($DOS);
    }
}

END
{
    my ($DOS) = Win32::GUI::GetPerlWindow();
    Win32::GUI::Show($DOS);
}

our $VERSION = '0.02';



sub init
{
	my ( $self ) = @_;

        my $rand = int(rand(1000000));
        $self->{"win32"}->{"id"} = $rand;
        $self->{"win32"}->{"window"} = Win32::GUI::Window->new( -name => 'Main$rand', -width => 100, -height => 100);
        $self->{"win32"}->{"popup"} = Win32::GUI::Menu->new("Options" => "Options", ">Quit" => {-name => "Quit" , -onClick => sub { return -1; } } );
        $self->{"win32"}->{"notify_icon"} = $self->{"win32"}->{"window"}->AddNotifyIcon(-name => "_NI$rand" );
        
        eval "package main; sub _NI" . $rand . "_RightClick { SystemTray::Applet::Win32::_RightClick(\$self);}";
        print $@ . "\n";
        
        eval "package main; sub _Timerd" . $rand . "_Timer { SystemTray::Applet::Win32::_Timer(\$self);}";
        print $@ . "\n";
        
        if( $self->{"frequency"} != -1 )
        {
            $self->{"win32"}->{"timer"} = $self->{"win32"}->{"window"}->AddTimer( "_Timerd$rand" , $self->{"frequency"} * 1000 );
        }
	else
	{
            $self->{"win32"}->{"timer"} = $self->{"win32"}->{"window"}->AddTimer( "_Timerd$rand" , 0 );
	}
        
	return $self;
}

sub _Timer
{
    my ( $self ) = @_;
        
    $self->{"callback"}->($self);
    if( $self->{"frequency"} != -1 )
    {
        $self->{"win32"}->{"timer"}->Interval($self->{"frequency"} * 1000);
    }
}


sub _RightClick
{	
   my ( $self ) = @_;
   
   my ( $x, $y ) = Win32::GUI::GetCursorPos;
   Win32::GUI::TrackPopupMenu($self->{"win32"}->{"window"}->{-handle}, $self->{"win32"}->{"popup"}->{Options}, $x , $y );
}


sub start
{
	Win32::GUI::Dialog();
	exit(0);
}


sub create_icon
{
	my ( $self , $icon ) = @_;

	if( defined( $icon ) )
	{
		return Win32::GUI::Icon->new($icon);
	}	
	else
	{
		return undef;
	}
}


sub display
{
    my ( $self ) = @_;

    if( defined($self->{"icon"}) )
    {
        $self->{"win32"}->{"notify_icon"}->Change( -name => "_NI" . $self->{"win32"}->{"id"} , -icon => $self->{"icon"} , -tip => $self->{"text"} );
    }
    else
    {
        $self->{"win32"}->{"notify_icon"}->Change( -name => "_NI" . $self->{"win32"}->{"id"} , -tip => $self->{"text"} );   
    }
}


sub schedule
{
	my ( $self ) = @_;
	
	if( $self->{"frequency"} != -1 )
	{       
		$self->{"win32"}->{"timer"}->Interval( $self->{"frequency"} * 1000 );
	}
        else
        {
                $self->{"win32"}->{"timer"}->Interval(0);
        }
}


sub _order
{
	return 1;
}

1; # End of SystemTray::Applet::Win32