#!/usr/bin/perl # CppTrial-pg019.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 19 - Create a basic frame with menus and status bar # Ported to wxPerl by James M. Lynes Jr. - 5/18/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_MOTION); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg19.pl', wxDefaultPosition, wxDefaultSize, ); my $cutIcon = Wx::Icon->new( "cut.xpm", wxBITMAP_TYPE_XPM, -1, -1); $self->SetIcon($cutIcon); my $fileMenu = Wx::Menu->new(); my $helpMenu = Wx::Menu->new(); $fileMenu->Append(wxID_EXIT, "E&xit\tAlt-X", "Quit This Program"); $helpMenu->Append(wxID_ABOUT, "&About...\tF1", "Show About Dialog"); my $menuBar = Wx::MenuBar->new(); $menuBar->Append($fileMenu, "&File"); $menuBar->Append($helpMenu, "&Help"); $self->SetMenuBar($menuBar); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP); $self->SetStatusBar($statusBar); $statusBar->SetStatusText("Welcome to wxWidgets!", 0); return $self; } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg065.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 65 - MDI Child Frame Example # Ported to wxPerl by James M. Lynes Jr. - 5/23/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::MDI; sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg065.pl', wxDefaultPosition, wxDefaultSize); &mdiChildFrame($self); return $self; } sub mdiChildFrame { my ( $self ) = @_; my $ID_MYFRAME = 1; my $ID_MYCHILD1 = 2; my $ID_MYCHILD2 = 3; my $ID_MYCHILD3 = 4; my $ID_MYCHILD4 = 5; my $parentFrame = Wx::MDIParentFrame->new($self, $ID_MYFRAME, "MDI Parent Window"); my $childFrame1 = Wx::MDIChildFrame->new($parentFrame, $ID_MYCHILD1, "Child 1"); my $childFrame2 = Wx::MDIChildFrame->new($parentFrame, $ID_MYCHILD2, "Child 2"); my $childFrame3 = Wx::MDIChildFrame->new($parentFrame, $ID_MYCHILD3, "Child 3"); my $childFrame4 = Wx::MDIChildFrame->new($parentFrame, $ID_MYCHILD4, "Child 4"); $childFrame1->Show(1); $childFrame2->Show(1); $childFrame3->Show(1); $childFrame4->Show(1); $parentFrame->Show(1); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg073.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 73 - Notebook Example # Ported to wxPerl by James M. Lynes Jr. - 4/11/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; #use Wx::Window; sub new { my ($class) = @_; Wx::InitAllImageHandlers(); my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg073.pl', wxDefaultPosition, wxDefaultSize); &Notebook($self); return $self; } sub Notebook { my ( $self ) = @_; my $noteBook = Wx::Notebook->new($self, -1, wxDefaultPosition, wxDefaultSize); my $imageList = Wx::ImageList->new(16, 16, 1, 3); my $cutxpm = Wx::Bitmap->new( "cut.xpm", wxBITMAP_TYPE_XPM ); my $copyxpm = Wx::Bitmap->new( "copy.xpm", wxBITMAP_TYPE_XPM ); my $printxpm = Wx::Bitmap->new( "print.xpm", wxBITMAP_TYPE_XPM ); $imageList->Add($cutxpm); $imageList->Add($copyxpm); $imageList->Add($printxpm); $noteBook->SetImageList($imageList); my $window1 = Wx::Panel->new($noteBook, wxID_ANY); my $window2 = Wx::Panel->new($noteBook, wxID_ANY); my $window3 = Wx::Panel->new($noteBook, wxID_ANY); $noteBook->AddPage($window1, "Tab One", 1, 0); $noteBook->AddPage($window2, "Tab Two", 0, 1); $noteBook->AddPage($window3, "Tab Three", 0, 2); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg077.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 77 - Scrolled Window Example # Ported to wxPerl by James M. Lynes Jr. - 5/23/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg077.pl', wxDefaultPosition, wxDefaultSize); &scrolledWindow($self); return $self; } sub scrolledWindow { my ( $self ) = @_; my $scrolledWindow = Wx::ScrolledWindow->new($self, wxID_ANY, Wx::Point->new(0, 0), Wx::Size->new(400, 400), wxVSCROLL | wxHSCROLL); my $pixelsPerUnitX = 10; my $pixelsPerUnitY = 10; my $noUnitsX = 1000; my $noUnitsY = 1000; $scrolledWindow->SetScrollbars($pixelsPerUnitX, $pixelsPerUnitY, $noUnitsX, $noUnitsY); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg081.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 81 - Splitter Window Example # Ported to wxPerl by James M. Lynes Jr. - 4/11/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg081.pl', wxDefaultPosition, wxDefaultSize); &SplitterWindow($self); return $self; } sub SplitterWindow { my ( $self ) = @_; my $splitterWindow = Wx::SplitterWindow->new($self, -1, Wx::Point->new(0, 0), Wx::Size->new(400, 400), wxSP_3D); my $leftWindow = Wx::ScrolledWindow->new($splitterWindow); $leftWindow->SetScrollbars(20, 20, 50, 50); $leftWindow->SetBackgroundColour(wxRED); $leftWindow->Show(1); my $rightWindow = Wx::ScrolledWindow->new($splitterWindow); $rightWindow->SetScrollbars(20, 20, 50, 50); $rightWindow->SetBackgroundColour(wxCYAN); $rightWindow->Show(0); # Right Window is Hidden $splitterWindow->Initialize($leftWindow); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg086.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 86 - 20 Assorted Static & Non-Static Controls Examples # Several small examples combined into one source file covers pg86 - pg116 # Ported to wxPerl by James M. Lynes Jr. - 5/23/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg086.pl', wxDefaultPosition, Wx::Size->new(500,700)); &assortedControls($self); return $self; } sub assortedControls { my ( $self ) = @_; # Create a panel to place all of the controls on my $panel= Wx::Panel->new($self, wxID_ANY, wxDefaultPosition, wxDefaultSize); # pg86----- Plain Button my $button = Wx::Button->new($panel, wxID_OK, "Ok", Wx::Point->new(10, 10), wxDefaultSize); # pg89----- Bitmap Button my $bmp1 = Wx::Bitmap->new("print.xpm", wxBITMAP_TYPE_XPM); my $picButton = Wx::BitmapButton->new($panel, wxID_OK, $bmp1, Wx::Point->new(150, 10), wxDefaultSize, wxBU_AUTODRAW); # pg91----- Choice Control my $ID_CHOICEBOX = 1; my @strings1 = ("One", "Two", "Three", "Four", "Five"); my $choice = Wx::Choice->new($panel, $ID_CHOICEBOX, Wx::Point->new(250, 10), wxDefaultSize, \@strings1); # pg92----- ComboBox Control my $ID_COMBOBOX = 2; my @strings2 = ("Apple", "Orange", "Pear", "Grapefruit"); my $combo = Wx::ComboBox->new($panel, $ID_COMBOBOX, "Apple", Wx::Point->new(10,50), wxDefaultSize, \@strings2, wxCB_DROPDOWN); # pg94----- CheckBox Control my $ID_CHECKBOX = 3; my $checkBox = Wx::CheckBox->new($panel, $ID_CHECKBOX, "&Check Me", Wx::Point->new(10,200), wxDefaultSize); $checkBox->SetValue(1); # pg95----- ListBox Control my $ID_LISTBOX = 4; my @strings3 = ("First String", "Second String", "Third String", "Fourth String", "Fifth String", "Sixth String"); my $listbox = Wx::ListBox->new($panel, $ID_LISTBOX, Wx::Point->new(200,200), Wx::Size->new(180,80), \@strings3, wxLB_SINGLE); # pg96----- CheckListBox Control my $ID_CHECKLISTBOX = 5; my @strings4 = ("1st String", "2nd String", "3rd String", "4th String", "5th String", "6th String"); my $checklistbox = Wx::CheckListBox->new($panel, $ID_CHECKLISTBOX, Wx::Point->new(200,300), Wx::Size->new(180,80), \@strings4, wxLB_SINGLE); # pg99----- RadioBox Control my $ID_RADIOBOX = 6; my @strings5 = ("&One", "&Two", "T&hree", "&Four", "F&ive","&Six"); my $radiobox = Wx::RadioBox->new($panel, $ID_RADIOBOX, "RadioBox", Wx::Point->new(10,300), wxDefaultSize, \@strings5, 3, wxRA_SPECIFY_COLS); # pg101---- Radio Button Control (Spacing forced for display purposes - Sizers want to use whole window) my $ID_RADIOBUTTON1 = 7; my $ID_RADIOBUTTON2 = 8; my $radioButton1 = Wx::RadioButton->new($panel, $ID_RADIOBUTTON1, "&Male", Wx::Point->new(10,400), wxDefaultSize, wxRB_GROUP); $radioButton1->SetValue(1); my $radioButton2 = Wx::RadioButton->new($panel, $ID_RADIOBUTTON2, "&Female", Wx::Point->new(75,400)); my $topSizer = Wx::BoxSizer->new(wxHORIZONTAL); my $boxSizer = Wx::BoxSizer->new(wxHORIZONTAL); $boxSizer->Add($radioButton1, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); $boxSizer->Add($radioButton2, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); # $topSizer->Add($boxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); # $self->SetSizer($topSizer); # pg102---- ScrollBar Control my $ID_SCROLLBAR = 9; my $scrollbar = Wx::ScrollBar->new($panel, $ID_SCROLLBAR, Wx::Point->new(10,450), Wx::Size->new(200,20), wxSB_HORIZONTAL); # pg103---- Spin Button Control my $ID_SPINBUTTON = 10; my $spinbutton = Wx::SpinButton->new($panel, $ID_SPINBUTTON, Wx::Point->new(330,400), wxDefaultSize, wxSP_VERTICAL); # pg105---- Spin Control my $ID_SPINCONTROL = 11; my $spincontrol = Wx::SpinCtrl->new($panel, $ID_SPINCONTROL, "5", Wx::Point->new(250,450), wxDefaultSize, wxSP_ARROW_KEYS, 0, 100, 5); # pg106---- Slider Control my $ID_SLIDERCONTROL = 12; my $slidercontrol = Wx::Slider->new($panel, $ID_SLIDERCONTROL, 16, 0, 40, Wx::Point->new(10,500), Wx::Size->new(200, -1), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS); # pg108---- Text Control (w/pg109 also) my $ID_TEXTCONTROL = 13; my $textcontrol = Wx::TextCtrl->new($panel, $ID_TEXTCONTROL, "", Wx::Point->new(250,500), Wx::Size->new(240, 100), wxTE_MULTILINE); $textcontrol->SetDefaultStyle(Wx::TextAttr->new(wxRED)); $textcontrol->AppendText("Red Text\n"); $textcontrol->SetDefaultStyle(Wx::TextAttr->new(wxNullColour, wxLIGHT_GREY)); $textcontrol->AppendText("Red on Gray Text\n"); $textcontrol->SetDefaultStyle(Wx::TextAttr->new(wxBLUE)); $textcontrol->AppendText("Blue on Gray Text\n"); # pg111---- Toggle Button my $ID_TOGGLEBUTTON = 14; my $togglebutton = Wx::ToggleButton->new($panel, $ID_TOGGLEBUTTON, "&Toggle Button", Wx::Point->new(10,550), wxDefaultSize); $togglebutton->SetValue(1); # pg112---- Guage Control my $ID_GAUGE = 15; my $gauge = Wx::Gauge->new($panel, $ID_GAUGE, 200, Wx::Point->new(10,600), wxDefaultSize, wxGA_HORIZONTAL); $gauge->SetValue(50); # pg113---- Static Text Control my $ID_STATICTEXT = 16; my $statictext = Wx::StaticText->new($panel, $ID_STATICTEXT, "This is my &static text label", Wx::Point->new(250,600), wxDefaultSize, wxALIGN_LEFT); # pg114---- Static Bitmap Control my $ID_STATICBITMAP = 17; my $bmp2 = Wx::Bitmap->new("print.xpm", wxBITMAP_TYPE_XPM); my $staticbitmap = Wx::StaticBitmap->new($panel, $ID_STATICBITMAP, $bmp2, Wx::Point->new(175, 600), wxDefaultSize); # pg115---- Static Line Control my $ID_STATICLINE = 18; my $staticline = Wx::StaticLine->new($panel, $ID_STATICLINE, Wx::Point->new(10, 650), Wx::Size->new(450,-1), wxLI_HORIZONTAL); # pg116---- Static Box Control my $ID_STATICBOX = 19; my $staticbox = Wx::StaticBox->new($panel, $ID_STATICBOX, "&Static Box", Wx::Point->new(350, 10), Wx::Size->new(100, 100)); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg124.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 124 - Tool Bar Example # Ported to wxPerl by James M. Lynes Jr. - 4/12/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; Wx::InitAllImageHandlers(); my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg124.pl', wxDefaultPosition, wxDefaultSize); &ToolBar($self); return $self; } sub ToolBar { my ( $self ) = @_; my $toolBar = Wx::ToolBar->new($self, -1, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL | wxNO_BORDER); my $cutxpm = Wx::Bitmap->new( "cut.xpm", wxBITMAP_TYPE_XPM ); my $copyxpm = Wx::Bitmap->new( "copy.xpm", wxBITMAP_TYPE_XPM ); my $printxpm = Wx::Bitmap->new( "print.xpm", wxBITMAP_TYPE_XPM ); $toolBar->AddTool(wxID_CUT, $cutxpm, "cut"); $toolBar->AddTool(wxID_COPY, $copyxpm, "Copy"); $toolBar->AddTool(wxID_PRINT, $printxpm, "Print"); $toolBar->AddSeparator(); my $ID_COMBOBOX = 1; my $comboBox = Wx::ComboBox->new($toolBar, $ID_COMBOBOX); $toolBar->AddControl($comboBox); $toolBar->Realize(); $self->SetToolBar($toolBar); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg133.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 133 - Drawing on Windows with wxClientDC # Ported to wxPerl by James M. Lynes Jr. - 4/10/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_MOTION); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg133.pl', wxDefaultPosition, wxDefaultSize, ); EVT_MOTION($self,\&OnMotion); return $self; } sub OnMotion { my ( $self, $event) = @_; if($event->Dragging) { # True if mouse button pressed & mouse moving my $dc = Wx::ClientDC->new($self); my $pen = Wx::Pen->new(wxRED,1,wxSOLID); $dc->SetPen($pen); $dc->DrawPoint($event->GetPosition->x,$event->GetPosition->y); $dc->SetPen(wxNullPen); } } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg135.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/18/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg135.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); my $sz=$self->GetClientSize(); my $szx=$sz->x; my $szy=$sz->y; my $w=100; my $h=50; my $x=($szx - $w)/2; my $y=($szy - $h)/2; $dc->DrawRectangle($x,$y,$w,$h); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg150.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 150 - Drawing Text - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/21/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg150.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); my $sz=$self->GetClientSize(); my $szx=$sz->x; my $szy=$sz->y; my $w=100; my $h=50; my $x=($szx - $w)/2; my $y=($szy - $h)/2; $dc->DrawRectangle($x,$y,$w,$h); my $pt=Wx::Point->new(160,275); CppDrawText($dc, "Test Text", $pt); } sub CppDrawText { my ( $dc, $text, $pt) = @_; my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxNORMAL); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxBLACK); $dc->SetTextBackground(wxWHITE); $dc->DrawText($text,$pt->x, $pt->y); return; } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg151.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 151 - Drawing Text Rotated - Extends pg 150 & 135 examples # C++ Example from pg 150 - Drawing Text - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/21/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg151.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); my $sz=$self->GetClientSize(); my $szx=$sz->x; my $szy=$sz->y; my $w=100; my $h=50; my $x=($szx - $w)/2; my $y=($szy - $h)/2; $dc->DrawRectangle($x,$y,$w,$h); my $pt1=Wx::Point->new(160,275); CppDrawText($dc, "Test Text", $pt1); my $pt2=Wx::Point->new(200,375); CppDrawRotatedText($dc, "Test Text", $pt2); } sub CppDrawText { my ( $dc, $text, $pt) = @_; my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxBOLD); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxBLACK); $dc->SetTextBackground(wxWHITE); $dc->DrawText($text,$pt->x, $pt->y); return; } sub CppDrawRotatedText { my ( $dc, $text, $pt) = @_; my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxNORMAL); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxGREEN); $dc->SetTextBackground(wxWHITE); for (my $angle=0; $angle<360; $angle +=45) { $dc->DrawRotatedText($text,$pt->x, $pt->y, $angle); } return; } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg152.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 152 - Centering Text - Extends pg 151, 150, & 135 examples # C++ Example from pg 151 - Drawing Text Rotated - Extends pg 150, & 135 examples # C++ Example from pg 150 - Drawing Text - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/21/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg152.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); my $sz=$self->GetClientSize(); my $szx=$sz->x; my $szy=$sz->y; my $w=100; my $h=50; my $x=($szx - $w)/2; my $y=($szy - $h)/2; $dc->DrawRectangle($x,$y,$w,$h); my $pt1=Wx::Point->new(160,275); CppDrawText($dc, "Test Text", $pt1); my $pt2=Wx::Point->new(200,375); CppDrawRotatedText($dc, "Test Text", $pt2); my $pt3=Wx::Point->new(0,50); CppDrawCenteredText("Centered Text", $dc, $pt3, $self); } sub CppDrawText { my ( $dc, $text, $pt) = @_; my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxBOLD); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxBLACK); $dc->SetTextBackground(wxWHITE); $dc->DrawText($text,$pt->x, $pt->y); return; } sub CppDrawRotatedText { my ( $dc, $text, $pt) = @_; my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxNORMAL); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxGREEN); $dc->SetTextBackground(wxWHITE); for (my $angle=0; $angle<360; $angle +=45) { $dc->DrawRotatedText($text,$pt->x, $pt->y, $angle); } return; } sub CppDrawCenteredText { my ( $text, $dc, $pt, $self) = @_; my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxBOLD); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxBLUE); $dc->SetTextBackground(wxWHITE); my $sz=$self->GetClientSize(); my @te=$dc->GetTextExtent($text); my $x=($sz->x - $te[0])/2; my $y=$pt->y; $dc->DrawText($text, $x, $y); return; } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg154.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 154 - Drawing multiple lines - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/25/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg154.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); my @points; my $x=0; my $y=0; for my $i(0..9) { my $pt1=Wx::Point->new($x,$y); my $pt2=Wx::Point->new($x+100,$y); push(@points, $pt1, $pt2); # print "$i-> $x, $y / ", $x+100, ",", $y, "\n"; $dc->DrawLine($pt1->x, $pt1->y, $pt2->x, $pt2->y); $x=$x + 10; $y=$y + 20; } # print "@points\n"; my $offsetx = 100; my $offsety = 250; $dc->DrawLines(\@points, $offsetx, $offsety); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg155.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 155 - Drawing polygons - Extends pg 154 example # C++ Example from pg 154 - Drawing single & multiple lines - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/25/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg155.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxCROSSDIAG_HATCH); $dc->SetBrush($brush); my @points; my $pt0=Wx::Point->new(100, 60); my $pt1=Wx::Point->new(60, 150); my $pt2=Wx::Point->new(160,100); my $pt3=Wx::Point->new(40, 100); my $pt4=Wx::Point->new(140, 150); push(@points, $pt0, $pt1, $pt2, $pt3, $pt4); print "@points\n"; $dc->DrawPolygon(\@points, 0, 30); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg156.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 156 - Drawing Splines - Extends pg 155 example # C++ Example from pg 155 - Drawing polygons - Extends pg 154 example # C++ Example from pg 154 - Drawing single & multiple lines - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/26/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg156.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxCROSSDIAG_HATCH); $dc->SetBrush($brush); my @pts; my $pts0=Wx::Point->new(10, 100); my $pts1=Wx::Point->new(200, 200); my $pts2=Wx::Point->new(50, 230); push(@pts, $pts0, $pts1, $pts2); $dc->DrawSpline(\@pts); my @points; my $pt0=Wx::Point->new(100, 60); my $pt1=Wx::Point->new(60, 150); my $pt2=Wx::Point->new(160,100); my $pt3=Wx::Point->new(40, 100); my $pt4=Wx::Point->new(140, 150); push(@points, $pt0, $pt1, $pt2, $pt3, $pt4); $dc->DrawSpline(\@points); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg157.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 157 - Drawing Bitmaps - Extends pg 150 example # C++ Example from pg 150 - Drawing Text - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/26/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { Wx::InitAllImageHandlers(); my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg157.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); my $font = Wx::Font->new(10, wxFONTFAMILY_ROMAN, wxNORMAL, wxNORMAL); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxBLACK); $dc->SetTextBackground(wxWHITE); my $msg = "Some text will appear mixed in the image's shadow..."; my $bmp = Wx::Bitmap->new("padre_logo_64x64.png", wxBITMAP_TYPE_PNG); my $y = 75; for (0..9) { $y += $dc->GetCharHeight() +5; $dc->DrawText($msg, 10, $y); } $dc->DrawBitmap($bmp, 150, 175, 1); return; } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg158.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 158 - Copy(Tile) Bitmaps Between Device Contexts - Extends pg 157 example # C++ Example from pg 157 - Drawing Bitmaps - Extends pg 150 example # C++ Example from pg 150 - Drawing Text - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/26/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { Wx::InitAllImageHandlers(); my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg158.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dcPaint = Wx::PaintDC->new($self); #OnPaint Event Requires a PaintDC my $dcSource = Wx::MemoryDC->new(); my $dcDest = Wx::MemoryDC->new(); my $destWidth = 350; my $destHeight = 400; my $bmpDest = Wx::Bitmap->new($destWidth, $destHeight); my $bmpSource = Wx::Bitmap->new("padre_logo_64x64.png", wxBITMAP_TYPE_PNG); my $sourceWidth = $bmpSource->GetWidth(); my $sourceHeight = $bmpSource->GetHeight(); $dcDest->SelectObject($bmpDest); $dcDest->SetBackground(wxWHITE_BRUSH); $dcDest->Clear(); $dcSource->SelectObject($bmpSource); for (my $i = 0; $i < $destWidth; $i += $sourceWidth) { for (my $j = 0; $j < $destHeight; $j += $sourceHeight) { $dcDest->Blit($i, $j, $sourceWidth, $sourceHeight, $dcSource, 0, 0, wxCOPY, 1); } } $dcPaint->Blit(0,0,$destWidth,$destHeight,$dcDest,0,0,wxCOPY,1); #Copy to PaintDC for display $dcDest->SelectObject(wxNullBitmap); $dcSource->SelectObject(wxNullBitmap); return; } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg159A.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 159A - Filling arbitrary areas - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/27/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg159A.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxRED,5,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxGREEN,wxSOLID); $dc->SetBrush($brush); $dc->DrawRectangle(0, 0, 400, 450); $dc->DrawRectangle(20, 20, 100, 100); $dc->DrawRectangle(200, 200, 100, 100); $dc->DrawRectangle(20, 300, 100, 100); # 4 Rects filled green # wxFLOOD_SURFACE - Fill area of given color $dc->SetBrush(wxBLACK_BRUSH); $dc->FloodFill(250, 250, wxGREEN, wxFLOOD_SURFACE); # Center Rect filled black # wxFLOOD_BORDER - Fill area within given color border $dc->SetBrush(wxCYAN_BRUSH); $dc->FloodFill(100, 350, wxRED, wxFLOOD_BORDER); # Bottom Rect filled cyan $dc->SetBrush(wxBLUE_BRUSH); $dc->FloodFill(6, 6, wxRED, wxFLOOD_BORDER); # Large Rect filled blue } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg159B.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 159B - Logical Functions - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/27/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(:everything); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg159B.pl', wxDefaultPosition, wxDefaultSize, ); EVT_MOTION($self,\&OnMotion,); return $self; } sub OnMotion { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); $dc->SetLogicalFunction(wxINVERT); # Invert Pixels $dc->DrawCircle(200, 200, 50); # Circle appears and erases as mouse moves } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg195.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 195 - Sizers -Dialog with streatching text control # Ported to wxPerl by James M. Lynes Jr. - 5/03/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Sizer Dialog Example", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; # Create two Sizers my $topSizer = Wx::BoxSizer->new(wxVERTICAL); my $buttonSizer = Wx::BoxSizer->new(wxHORIZONTAL); # Create a Text Control, and OK and CANCEL Buttons my $textCtrl = Wx::TextCtrl->new($dialog, wxID_ANY, "Stretching Text Control...", wxDefaultPosition, Wx::Size->new(100, 60), wxTE_MULTILINE); my $buttOk = Wx::Button->new($dialog, wxID_OK, "OK"); my $buttCancel = Wx::Button->new($dialog, wxID_CANCEL, "Cancel"); # Associate Text Control and buttons with Sizers $topSizer->Add($textCtrl, 1, wxEXPAND, wxALL, 10); $buttonSizer->Add($buttOk, 0, wxALL, 10); $buttonSizer->Add($buttCancel, 0, wxALL, 10); # Associate Button Sizer with TopSizer $topSizer->Add($buttonSizer, 0, wxALIGN_CENTER); $dialog->SetSizer($topSizer); $topSizer->Fit($dialog); $topSizer->SetSizeHints($dialog); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg196.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 196 - Sizers -Dialog with static box sizer and check box # Ported to wxPerl by James M. Lynes Jr. - 5/03/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Static Box Sizer Dialog Example", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; # Create two Sizers and a Static Box my $topLevel = Wx::BoxSizer->new(wxVERTICAL); my $staticBox = Wx::StaticBox->new($dialog, wxID_ANY, "General Settings"); my $staticSizer = Wx::StaticBoxSizer->new($staticBox, wxVERTICAL); # Create a Check Box my $checkBox = Wx::CheckBox->new($dialog, -1, "&Show Splash Screen", wxDefaultPosition, wxDefaultSize); # Associate Check Box Control with Sizers $topLevel->Add($staticSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5); $staticSizer->Add($checkBox, 0, wxALIGN_LEFT | wxALL, 5); # Associate Button Sizer with TopSizer $dialog->SetSizer($topLevel); $topLevel->Fit($dialog); $topLevel->SetSizeHints($dialog); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg197.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 197 - Sizers -Dialog with grid sizer # Ported to wxPerl by James M. Lynes Jr. - 5/03/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Grid Sizer Dialog Example", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; # Create a Grid Sizers my $gridSizer = Wx::GridSizer->new(2, 3, 0, 0); $dialog->SetSizer($gridSizer); # Create Buttons and add to GridSizer my $button1 = Wx::Button->new($dialog , -1, "One"); $gridSizer->Add($button1, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button2 = Wx::Button->new($dialog , -1, "Two (the second button)"); $gridSizer->Add($button2, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button3 = Wx::Button->new($dialog , -1, "Three"); $gridSizer->Add($button3, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button4 = Wx::Button->new($dialog , -1, "Four"); $gridSizer->Add($button4, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button5 = Wx::Button->new($dialog , -1, "Five"); $gridSizer->Add($button5, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button6 = Wx::Button->new($dialog , -1, "Six"); $gridSizer->Add($button6, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); $gridSizer->Fit($dialog); $gridSizer->SetSizeHints($dialog); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg199.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 199 - Sizers -Dialog with flex grid sizer # Ported to wxPerl by James M. Lynes Jr. - 5/03/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Flex Grid Sizer Dialog Example", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; # Create a Grid Sizers make column 0 growable my $flexGridSizer = Wx::FlexGridSizer->new(2, 3, 0, 0); $dialog->SetSizer($flexGridSizer); $flexGridSizer->AddGrowableCol(0); # Create Buttons and add to FlexGridSizer my $button1 = Wx::Button->new($dialog , -1, "One"); $flexGridSizer->Add($button1, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button2 = Wx::Button->new($dialog , -1, "Two (the second button)"); $flexGridSizer->Add($button2, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button3 = Wx::Button->new($dialog , -1, "Three"); $flexGridSizer->Add($button3, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button4 = Wx::Button->new($dialog , -1, "Four"); $flexGridSizer->Add($button4, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button5 = Wx::Button->new($dialog , -1, "Five"); $flexGridSizer->Add($button5, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button6 = Wx::Button->new($dialog , -1, "Six"); $flexGridSizer->Add($button6, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); $flexGridSizer->Fit($dialog); $flexGridSizer->SetSizeHints($dialog); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg201.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 201 - Sizers -Dialog with grid bag sizer # Ported to wxPerl by James M. Lynes Jr. - 5/03/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Grid Bag Sizer Dialog Example", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; # Create a Grid Bag Sizers make column 2 and row 3 growable my $gridBagSizer = Wx::GridBagSizer->new(); $dialog->SetSizer($gridBagSizer); # Create Buttons and add to GridBagSizer my $b1 = Wx::Button->new($dialog , -1, "One (0,0)"); $gridBagSizer->Add($b1, Wx::GBPosition->new(0, 0)); my $b2 = Wx::Button->new($dialog , -1, "Two (2, 2)"); $gridBagSizer->Add($b2, Wx::GBPosition->new(2, 2), Wx::GBSpan->new(1, 2), wxGROW); my $b3 = Wx::Button->new($dialog , -1, "Three (3, 2)"); $gridBagSizer->Add($b3, Wx::GBPosition->new(3, 2)); my $b4 = Wx::Button->new($dialog , -1, "Four (3, 3)"); $gridBagSizer->Add($b4, Wx::GBPosition->new(3, 3)); $gridBagSizer->AddGrowableRow(3); $gridBagSizer->AddGrowableCol(2); $gridBagSizer->Fit($dialog); $gridBagSizer->SetSizeHints($dialog); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg202.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 202 - Sizers -Dialog with Standard Dialog Button Sizer # Ported to wxPerl by James M. Lynes Jr. - 5/03/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Standard Dialog Button Sizer Example", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; # Create Sizer my $topSizer = Wx::BoxSizer->new(wxVERTICAL); $dialog->SetSizer($topSizer); # Create an OK, CANCEL, and HELP Buttons my $buttOk = Wx::Button->new($dialog, wxID_OK, "OK"); my $buttCancel = Wx::Button->new($dialog, wxID_CANCEL, "Cancel"); my $buttHelp = Wx::Button->new($dialog, wxID_HELP, "Help"); # Associate buttons with Sizers my $buttonSizer = Wx::StdDialogButtonSizer->new(); $topSizer->Add($buttonSizer, 0, wxEXPAND | wxALL, 10); $buttonSizer->AddButton($buttOk); $buttonSizer->AddButton($buttCancel); $buttonSizer->AddButton($buttHelp); $buttonSizer->Realize(); } ---------------------------------------------------------------------------------------------------- #!/usr/bin/perl # CppTrial-pg207A.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor # C++ Example from pg 207(A) - Message Dialog Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/4/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg207B.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP); $self->SetStatusBar($statusBar); my @widths = (200, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; use Switch;