AAC-Pvoice
view release on metacpan or search on metacpan
lib/AAC/Pvoice/Panel.pm view on Meta::CPAN
package AAC::Pvoice::Panel;
use strict;
use warnings;
our $VERSION = sprintf("%d.%02d", q$Revision: 1.15 $=~/(\d+)\.(\d+)/);
use Wx qw(:everything);
use Wx::Perl::Carp;
use Wx::Event qw(EVT_PAINT EVT_UPDATE_UI);
use base qw(Wx::Panel);
#----------------------------------------------------------------------
sub new
{
my $class = shift;
$_[2] ||= wxDefaultPosition;
$_[3] ||= wxDefaultSize;
$_[4] ||= wxTAB_TRAVERSAL;
my $self = $class->SUPER::new(@_[0..4]);
$self->SetBackgroundColour(wxWHITE);
$self->{parent} = $_[0];
$self->{position} = $_[2];
$self->{size} = $_[3];
$self->{disabletextrow} = $_[5] || 0;
$self->{itemspacing} = $_[6] || 0;
$self->{selectionborder}= $_[7] || int($self->{itemspacing}/2)||1;
$self->{disabletitle} = $_[8] || 0;
$self->{tls} = Wx::FlexGridSizer->new(0,1);
$self->{totalrows} = 0;
$self->{lastrow} = 0;
$self->{currentpage} = 0;
$self->{unfinished} = 1;
$self->RoundCornerRadius(10);
my ($x, $y);
# to get the right dimensions for the items, we maximize the
# frame, show it, get the dimensions, and hide it again
if (ref($self->{parent}) =~ /Frame/)
{
if ($self->{parent}->IsMaximized)
{
($x, $y) = @{$self->{size}};
}
else
{
$self->{parent}->Maximize(1);
$self->{parent}->Show(1);
($x, $y) = ( $self->GetSize()->GetWidth(),
$self->GetSize()->GetHeight() );
$self->{parent}->Show(0);
}
}
else
{
# if our parent isn't a frame, we're not able to maximize
# it, so we just get the dimensions of the parent
($x, $y) = @{$self->{size}};
}
$self->{realx} = $x;
$self->{realy} = $y;
$self->xsize($x);
$self->ysize($y);
unless ($self->{disabletitle})
{
# to be able to calculate the useable y-size, we need to add the
# title and get its height. Since we don't know what the title
# will be, we'll simple draw an empty title.
$self->TitleFont(Wx::Font->new( 18, # font size
wxDECORATIVE, # font family
wxNORMAL, # style
wxNORMAL, # weight
0,
'Comic Sans MS', # face name
wxFONTENCODING_SYSTEM)) unless $self->TitleFont;
$self->AddTitle('');
lib/AAC/Pvoice/Panel.pm view on Meta::CPAN
sub Append
{
my $self = shift;
my $row = shift;
my $unselectable = shift;
$self->{tls}->Add($row, # what to add
0, # unused
wxALIGN_CENTRE, # style
0); # padding
# setup the input event handling unless we're in editmode
unless ($self->{editmode})
{
$row->{input} = AAC::Pvoice::Input->newchild($row);
$row->{input}->Next( sub{$self->Next});
$row->{input}->Select(sub{$self->Select});
my $index=0;
foreach my $child ($row->GetChildren)
{
$child->{input} = AAC::Pvoice::Input->newchild($child);
$child->{input}->Next( sub{$self->Next});
$child->{input}->Select(sub{$self->Select});
if ((defined $row->{ids}->[$index]) && ($child->GetId == $row->{ids}->[$index]))
{
my $action = $row->{actions}->[$index];
$self->{input}->SetupMouse($child, sub{$self->SetSelectionBorder($child)}, $action, sub{$self->SetNormalBorder($child)});
$index++;
}
}
}
$self->{totalrows}++ if not $unselectable;
$self->{lastrow}++;
push @{$self->{rows}}, $row if not $unselectable;
push @{$self->{unselectablerows}}, $row if $unselectable;
}
sub PauseInput
{
my $self = shift;
my $bool = shift;
$self->{input}->PauseMonitor($bool);
$self->{input}->PauseAutoscan($bool);
$self->{input}->Pause($bool);
}
sub Clear
{
my $self = shift;
$self->{tls}->Remove($_) for (0..$self->{lastrow});
foreach my $row (@{$self->{rows}})
{
$_->Destroy for $row->GetChildren();
$row->Destroy
}
$_->Destroy for @{$self->{unselectablerows}};
$self->{text}->Destroy if exists $self->{text};
$self->{title}->Destroy if exists $self->{title};
$self->{rows} = [];
$self->{unselectablerows} = [];
$self->SUPER::Clear();
$self->{totalrows} = 0;
$self->{lastrow} = 0;
$self->Refresh;
}
sub Finalize
{
my $self = shift;
my $dc = Wx::WindowDC->new($self);
$self->DrawBackground($dc);
unless ($self->{disabletextrow})
{
# Create the TextControl
my $font = Wx::Font->new( 24, # font size
wxSWISS, # font family
wxNORMAL, # style
wxNORMAL, # weight
0,
'Comic Sans MS',# face name
wxFONTENCODING_SYSTEM);
$font->SetUnderlined(1);
$self->{ta} = Wx::TextAttr->new( Wx::Colour->new(0,0,0), # textcol
Wx::Colour->new(255,255,255),# backgr.
$font); # font
my $rowsizer = Wx::GridSizer->new(1,0);
$self->{text} = Wx::TextCtrl->new( $self, # parent
-1, # id
'', # text
wxDefaultPosition,# position
[4*($self->{realx}/5),60], # size
wxTE_RICH|
wxTE_MULTILINE); # style
# set the text-attributes
$self->{text}->SetDefaultStyle($self->{ta});
$rowsizer->Add($self->{text}, # what to add
0, # unused
wxALIGN_CENTRE|wxALL, # style
$self->{itemspacing}); # padding
$self->{tls}->Add($rowsizer, 0, wxALIGN_CENTRE, 0);
$self->{textrowsizer} = $rowsizer;
$self->{text}->SetValue(my $x = $self->RetrieveText);
$self->{text}->SetStyle(0, length($self->{text}->GetValue), $self->{ta});
$self->{text}->Refresh(); # Added to test it on the Mercury...added text
# isn't visible there...
}
$self->{title}->SetBackgroundColour($self->BackgroundColour) unless $self->{disabletitle};
$self->{tls}->AddGrowableCol(0);
$self->Layout;
# Select the first row
$self->{selectedrow} = 0;
$self->{selecteditem} = 0;
$self->SetSelectionBorder($self->{rows}->[$self->{selectedrow}]) if $self->{rowcolumnscanning} && not $self->{editmode};
$self->{rowselection} = 1;
$self->Refresh;
$self->Update();
$self->{unfinished} = 0;
( run in 3.387 seconds using v1.01-cache-2.11-cpan-364913b4093 )