diff --git a/CppTrial-pg019.pl b/CppTrial-pg019.pl new file mode 100644 index 0000000..83194ce --- /dev/null +++ b/CppTrial-pg019.pl @@ -0,0 +1,41 @@ +#!/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. - Last Modified 9/23/2012 + +use 5.010; +use strict; +use warnings; + +use Wx qw(:everything); +use Wx::Event qw(EVT_MOTION); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg19.pl', + wxDefaultPosition, wxDefaultSize); +$frame->Show; + +# Example specific code + my $cutIcon = Wx::Icon->new( "cut.xpm", wxBITMAP_TYPE_XPM, -1, -1); + $frame->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"); + + $frame->SetMenuBar($menuBar); + + my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); + $frame->SetStatusBar($statusBar); + $statusBar->SetStatusText("Welcome to wxWidgets!", 0); +$app->MainLoop; diff --git a/CppTrial-pg065.pl b/CppTrial-pg065.pl new file mode 100644 index 0000000..2e1aad9 --- /dev/null +++ b/CppTrial-pg065.pl @@ -0,0 +1,47 @@ +#!/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. - Last Modified 9/23/2012 + +use 5.010; +use strict; +use warnings; + +use Wx qw(:everything); +use Wx::MDI; + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new( undef, -1, + 'CppTrial-pg065.pl', + wxDefaultPosition, wxDefaultSize ); +mdiChildFrame($frame); +$frame->Show; +$app->MainLoop; + +# Example specific code +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); + +} diff --git a/CppTrial-pg073.pl b/CppTrial-pg073.pl new file mode 100644 index 0000000..81360ef --- /dev/null +++ b/CppTrial-pg073.pl @@ -0,0 +1,50 @@ +#!/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. - Last Modified 9/23/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg073.pl', + wxDefaultPosition, wxDefaultSize); +Wx::InitAllImageHandlers(); +Notebook($frame); +$frame->Show; +$app->MainLoop; + +#Example specific code +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); +} + + diff --git a/CppTrial-pg077.pl b/CppTrial-pg077.pl new file mode 100644 index 0000000..86f48d1 --- /dev/null +++ b/CppTrial-pg077.pl @@ -0,0 +1,38 @@ +#!/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. - Last Modfied 9/23/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg077.pl', + wxDefaultPosition, wxDefaultSize); +scrolledWindow($frame); +$frame->Show; +$app->MainLoop; + +# Example specific code +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); +} + diff --git a/CppTrial-pg081.pl b/CppTrial-pg081.pl new file mode 100644 index 0000000..4d25943 --- /dev/null +++ b/CppTrial-pg081.pl @@ -0,0 +1,42 @@ +#!/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. - Last Modified 9/23/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); + + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg081.pl', + wxDefaultPosition, wxDefaultSize); +SplitterWindow($frame); +$frame->Show; +$app->MainLoop; + +# Example specific code +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); +} diff --git a/CppTrial-pg086.pl b/CppTrial-pg086.pl new file mode 100644 index 0000000..9c9800d --- /dev/null +++ b/CppTrial-pg086.pl @@ -0,0 +1,164 @@ +#!/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. - Last Modified 9/23/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg086.pl', + wxDefaultPosition, Wx::Size->new(500,700)); +assortedControls($frame); +$frame->Show; +$app->MainLoop; + +# Example specific code +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)); +} diff --git a/CppTrial-pg124.pl b/CppTrial-pg124.pl new file mode 100644 index 0000000..ee0d874 --- /dev/null +++ b/CppTrial-pg124.pl @@ -0,0 +1,46 @@ +#!/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. - Last Modified 9/23/2012 + +use 5.010; + +use strict; +use warnings; +use Wx qw(:everything); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg124.pl', + wxDefaultPosition, wxDefaultSize); +Wx::InitAllImageHandlers(); +ToolBar($frame); +$frame->Show; +$app->MainLoop; + +# Example specific code +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); + +} diff --git a/CppTrial-pg133.pl b/CppTrial-pg133.pl new file mode 100644 index 0000000..ec6588e --- /dev/null +++ b/CppTrial-pg133.pl @@ -0,0 +1,33 @@ +#!/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. - Last Modified 9/23/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_MOTION); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg133.pl', + wxDefaultPosition, wxDefaultSize,); +EVT_MOTION($frame,\&OnMotion); +$frame->Show; +$app->MainLoop; + +# Example specific code +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); + } +} diff --git a/CppTrial-pg135.pl b/CppTrial-pg135.pl new file mode 100644 index 0000000..55a81f7 --- /dev/null +++ b/CppTrial-pg135.pl @@ -0,0 +1,45 @@ +#!/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. - Last Modified 9/23/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg135.pl', + wxDefaultPosition, wxDefaultSize,); +EVT_PAINT($frame,\&OnPaint); +$frame->Show; +$app->MainLoop; + +# Example specific code +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); # Centered on the window, try resizing... +} + diff --git a/CppTrial-pg150.pl b/CppTrial-pg150.pl new file mode 100644 index 0000000..501ac99 --- /dev/null +++ b/CppTrial-pg150.pl @@ -0,0 +1,60 @@ +#!/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. - Last Modified 9/23/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg150.pl', + wxDefaultPosition, wxDefaultSize); +EVT_PAINT($frame,\&OnPaint); +$frame->Show; +$app->MainLoop; + +# Example specific code +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); # Centered in frame + my $pt=Wx::Point->new(160,275); + CppDrawText($dc, "Test Text", $pt); # Text at fixed position +} + +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; + +} diff --git a/CppTrial-pg151.pl b/CppTrial-pg151.pl new file mode 100644 index 0000000..dd69328 --- /dev/null +++ b/CppTrial-pg151.pl @@ -0,0 +1,78 @@ +#!/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. - Last Modified 9/23/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg151.pl', + wxDefaultPosition, wxDefaultSize); +EVT_PAINT($frame,\&OnPaint); +$frame->Show; +$app->MainLoop; + +# Example specific code +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); # Centered on frame + my $pt1=Wx::Point->new(160,275); + CppDrawText($dc, "Test Text", $pt1); # Fixed position + my $pt2=Wx::Point->new(200,375); + CppDrawRotatedText($dc, "Test Text", $pt2); # Fixed position +} + +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; + +} diff --git a/CppTrial-pg152.pl b/CppTrial-pg152.pl new file mode 100644 index 0000000..5d600cf --- /dev/null +++ b/CppTrial-pg152.pl @@ -0,0 +1,103 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg152.pl', + wxDefaultPosition, wxDefaultSize); +EVT_PAINT($frame,\&OnPaint); +$frame->Show; +$app->MainLoop; + +# Example specific code +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); # Centered on frame + + my $pt1=Wx::Point->new(160,275); # Fixed position + CppDrawText($dc, "Test Text", $pt1); + + my $pt2=Wx::Point->new(200,375); # Fixed position + CppDrawRotatedText($dc, "Test Text", $pt2); + + my $pt3=Wx::Point->new(0,50); # Centered on frame + 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; + +} diff --git a/CppTrial-pg154.pl b/CppTrial-pg154.pl new file mode 100644 index 0000000..365354e --- /dev/null +++ b/CppTrial-pg154.pl @@ -0,0 +1,60 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg154.pl', + wxDefaultPosition, wxDefaultSize); +EVT_PAINT($frame,\&OnPaint); +$frame->Show; +$app->MainLoop; + +# Example specific code +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); +} + + + diff --git a/CppTrial-pg155.pl b/CppTrial-pg155.pl new file mode 100644 index 0000000..caaee84 --- /dev/null +++ b/CppTrial-pg155.pl @@ -0,0 +1,49 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg155.pl', + wxDefaultPosition, wxDefaultSize); +EVT_PAINT($frame,\&OnPaint); +$frame->Show; +$app->MainLoop; + +# Example specific code +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); +} diff --git a/CppTrial-pg156.pl b/CppTrial-pg156.pl new file mode 100644 index 0000000..e8af58e --- /dev/null +++ b/CppTrial-pg156.pl @@ -0,0 +1,52 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg156.pl', + wxDefaultPosition, wxDefaultSize); +EVT_PAINT($frame,\&OnPaint); +$frame->Show; +$app->MainLoop; + +# Example specific code +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); +} diff --git a/CppTrial-pg157.pl b/CppTrial-pg157.pl new file mode 100644 index 0000000..75dde1d --- /dev/null +++ b/CppTrial-pg157.pl @@ -0,0 +1,55 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +Wx::InitAllImageHandlers(); +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg157.pl', + wxDefaultPosition, wxDefaultSize); +EVT_PAINT($frame,\&OnPaint); +$frame->Show; +$app->MainLoop; + +# Example specific code +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; + +} diff --git a/CppTrial-pg158.pl b/CppTrial-pg158.pl new file mode 100644 index 0000000..b9e2f3f --- /dev/null +++ b/CppTrial-pg158.pl @@ -0,0 +1,63 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +Wx::InitAllImageHandlers(); +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg158.pl', + wxDefaultPosition, wxDefaultSize); +EVT_PAINT($frame,\&OnPaint); +$frame->Show; +$app->MainLoop; + +# Example specific code +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; + +} diff --git a/CppTrial-pg159A.pl b/CppTrial-pg159A.pl new file mode 100644 index 0000000..ca48c66 --- /dev/null +++ b/CppTrial-pg159A.pl @@ -0,0 +1,51 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg159A.pl', + wxDefaultPosition, wxDefaultSize); +EVT_PAINT($frame,\&OnPaint); +$frame->Show; +$app->MainLoop; + +# Example Specific code +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 + +} diff --git a/CppTrial-pg159B.pl b/CppTrial-pg159B.pl new file mode 100644 index 0000000..ce74ef2 --- /dev/null +++ b/CppTrial-pg159B.pl @@ -0,0 +1,38 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(:everything); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg159B.pl', + wxDefaultPosition, wxDefaultSize); +EVT_MOTION($frame,\&OnMotion,); +$frame->Show; +$app->MainLoop; + +# Example specific code +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 + +} diff --git a/CppTrial-pg195.pl b/CppTrial-pg195.pl new file mode 100644 index 0000000..e766c1f --- /dev/null +++ b/CppTrial-pg195.pl @@ -0,0 +1,52 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $dialog = Wx::Dialog->new(undef, -1, "Sizer Dialog Example", + wxDefaultPosition, wxDefaultSize, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); +mydialog($dialog); +$dialog->Show; +$app->MainLoop; + +# Example specific code +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); + +} diff --git a/CppTrial-pg196.pl b/CppTrial-pg196.pl new file mode 100644 index 0000000..9670f54 --- /dev/null +++ b/CppTrial-pg196.pl @@ -0,0 +1,48 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $dialog = Wx::Dialog->new(undef, -1, "Static Box Sizer Dialog Example", + wxDefaultPosition, wxDefaultSize, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); +mydialog($dialog); +$dialog->Show; +$app->MainLoop; + +# Example specific code +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); + +} diff --git a/CppTrial-pg197.pl b/CppTrial-pg197.pl new file mode 100644 index 0000000..c22f515 --- /dev/null +++ b/CppTrial-pg197.pl @@ -0,0 +1,60 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $dialog = Wx::Dialog->new(undef, -1, "Grid Sizer Dialog Example", + wxDefaultPosition, wxDefaultSize, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); +mydialog($dialog); +$dialog->Show; +$app->MainLoop; + +# Example specific code +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); + +} diff --git a/CppTrial-pg199.pl b/CppTrial-pg199.pl new file mode 100644 index 0000000..e6c2ad8 --- /dev/null +++ b/CppTrial-pg199.pl @@ -0,0 +1,61 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $dialog = Wx::Dialog->new(undef, -1, "Flex Grid Sizer Dialog Example", + wxDefaultPosition, wxDefaultSize, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); +mydialog($dialog); +$dialog->Show; +$app->MainLoop; + +# Example specific code +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); + +} diff --git a/CppTrial-pg201.pl b/CppTrial-pg201.pl new file mode 100644 index 0000000..ed28cec --- /dev/null +++ b/CppTrial-pg201.pl @@ -0,0 +1,52 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $dialog = Wx::Dialog->new(undef, -1, "Grid Bag Sizer Dialog Example", + wxDefaultPosition, wxDefaultSize, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); +mydialog($dialog); +$dialog->Show; +$app->MainLoop; + +# Example specific code +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); + +} diff --git a/CppTrial-pg202.pl b/CppTrial-pg202.pl new file mode 100644 index 0000000..ea47ce7 --- /dev/null +++ b/CppTrial-pg202.pl @@ -0,0 +1,47 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $dialog = Wx::Dialog->new(undef, -1, "Standard Dialog Button Sizer Example", + wxDefaultPosition, wxDefaultSize, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); +mydialog($dialog); +$dialog->Show; +$app->MainLoop; + +# Example specific code +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(); +} diff --git a/CppTrial-pg207A.pl b/CppTrial-pg207A.pl new file mode 100644 index 0000000..8c1d4e7 --- /dev/null +++ b/CppTrial-pg207A.pl @@ -0,0 +1,48 @@ +#!/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. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg207A.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (200, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + + my $stdDialog = Wx::MessageDialog->new($self, "Message Box Caption", + "Message Box Text", wxNO_DEFAULT | wxYES_NO | + wxCANCEL | wxICON_INFORMATION); + + my $selection = $stdDialog->ShowModal(); + + given ($selection) { + when ([wxID_YES]) {$self->Wx::LogStatus ("You pressed: \"Yes\" ")} + when ([wxID_NO]) {$self->Wx::LogStatus ("You pressed: \"No\" ")} + when ([wxID_CANCEL]) {$self->Wx::LogStatus ("You pressed: \"Cancel\" ")} + } +} diff --git a/CppTrial-pg207B.pl b/CppTrial-pg207B.pl new file mode 100644 index 0000000..3da5509 --- /dev/null +++ b/CppTrial-pg207B.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl + +# CppTrial-pg207B.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 207(B) - Message Box Dialog +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg207B.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (200, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + +# Example Specific code +sub myStdDialogs { + my ( $self ) = @_; + + my $stdDialog = Wx::MessageBox("Message Box Text", + "Message Box Caption", wxNO_DEFAULT | wxOK | wxYES_NO | + wxCANCEL | wxICON_INFORMATION, $self); + +# Note: Wx::MessageBox returns different button IDs from Wx::MessageDialog - pg207A + + given ($stdDialog) { + when ([wxYES]) {$self->Wx::LogStatus ("You pressed: \"Yes\" ")} + when ([wxNO]) {$self->Wx::LogStatus ("You pressed: \"No\" ")} + when ([wxCANCEL]) {$self->Wx::LogStatus ("You pressed: \"Cancel\" ")} + when ([wxOK]) {$self->Wx::LogStatus ("You pressed: \"Ok\" ")}; + + } +} diff --git a/CppTrial-pg209.pl b/CppTrial-pg209.pl new file mode 100644 index 0000000..1ed742d --- /dev/null +++ b/CppTrial-pg209.pl @@ -0,0 +1,80 @@ +#!/usr/bin/perl + +# CppTrial-pg209.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 209 - Progress Dialog +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg209.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (250, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + + my $continue = 1; + my $max = 10; + + my $myProgressDialog = Wx::ProgressDialog->new("Progress Dialog Example", + "An Information Message", $max, $self, + wxPD_CAN_ABORT | + wxPD_APP_MODAL | + wxPD_ELAPSED_TIME | + wxPD_ESTIMATED_TIME | + wxPD_REMAINING_TIME); + + for ( my $i = 0; $i <= $max; $i++) { + Wx::Sleep(1); + + if ($i == $max) { + $continue = $myProgressDialog->Update($i, "That's all, folks!"); + } + elsif ($i == $max/2) { + $continue = $myProgressDialog->Update($i, "Only a half left (very long message)!"); + } + else { + $continue = $myProgressDialog->Update($i); + } + + if (! $continue) { + if ( Wx::MessageBox("Do you really want to cancel?", + "Progress Dialog Question", wxYES_NO | + wxICON_QUESTION, $self) == wxYES ) { + last; + } + else { + $self->Wx::LogStatus ("Progress Dialog Resumed"); + $myProgressDialog->Resume(); + } + } + } + + if (! $continue) { + $self->Wx::LogStatus ("Progress Dialog Aborted!"); + } + else { + $self->Wx::LogStatus ("Countdown from %d Finished", $max); + } +} diff --git a/CppTrial-pg210.pl b/CppTrial-pg210.pl new file mode 100644 index 0000000..1875ea4 --- /dev/null +++ b/CppTrial-pg210.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +# CppTrial-pg210.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 210 - Busy Info Box +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_MOTION); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg210.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); + $frame->SetStatusBar($statusBar); + my @widths = (250, 100, -1); + $statusBar->SetFieldsCount($#widths+1); + $statusBar->SetStatusWidths(@widths); + $statusBar->SetStatusText("Ready", 0); + +# &myStdDialogs($frame); + EVT_MOTION($frame, \&myStdDialogs); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self, $event ) = @_; + + $self->Wx::LogStatus ("Display Busy Info Box"); + + Wx::Window::Disable($self); + + my $info = Wx::BusyInfo->new("Counting, please wait..."); #bug - not displaying text in box + + Wx::Sleep(1); + + Wx::Window::Enable($self); + $self->Wx::LogStatus ("Removed Busy Info Box"); + +} diff --git a/CppTrial-pg211.pl b/CppTrial-pg211.pl new file mode 100644 index 0000000..a7c9b0c --- /dev/null +++ b/CppTrial-pg211.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl + +# CppTrial-pg211.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 211 - Application Tips Dialog +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_MOTION); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg211.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (250, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self) = @_; + +# Display an Application Tip Dialog Box +# Tips are stored in the file "tips.txt", one tip per line +# Randomly select the first tip to be displayed +# Return a flag that can be used to control display of tips in the future + + my $index = int( rand(9) ); + my $tipProvider = Wx::CreateFileTipProvider("tips.txt", $index); + my $showAtStartup = Wx::ShowTip($self, $tipProvider, 1); + +} diff --git a/CppTrial-pg215.pl b/CppTrial-pg215.pl new file mode 100644 index 0000000..6c87084 --- /dev/null +++ b/CppTrial-pg215.pl @@ -0,0 +1,53 @@ +#!/usr/bin/perl + +# CppTrial-pg215.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 215 - File Dialog +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_MOTION); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg215.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (250, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + + my $caption = "Choose A File"; + my $wildcard = "*.*"; + my $defaultDir = "~/Projects/perlprojects/wx.proj"; + my $defaultFilename = ""; + + my $fileDialog = Wx::FileDialog->new($self, $caption, $defaultDir, + $defaultFilename, $wildcard, wxOPEN); + + my $fileDialogStatus = $fileDialog->ShowModal(); + + my $selecteddir = $fileDialog->GetDirectory(); + my $selectedfile = $fileDialog->GetFilename(); +# print $selecteddir, "\n", $selectedfile, "\n"; + + if ( $fileDialogStatus == wxID_OK ) {$self->Wx::LogStatus ("You pressed: \"Open\" ")}; + if ( $fileDialogStatus == wxID_CANCEL ) {$self->Wx::LogStatus ("You pressed: \"Cancel\" ")}; +} diff --git a/CppTrial-pg218.pl b/CppTrial-pg218.pl new file mode 100644 index 0000000..98c8354 --- /dev/null +++ b/CppTrial-pg218.pl @@ -0,0 +1,51 @@ +#!/usr/bin/perl + +# CppTrial-pg218.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 218 - Directory Dialog +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_MOTION); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg218.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (250, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + + my $caption = "Choose A Directory"; + my $defaultPath = "/"; + + my $dirDialog = Wx::DirDialog->new($self, $caption, $defaultPath, + wxDD_NEW_DIR_BUTTON); + + my $dirDialogStatus = $dirDialog->ShowModal(); + + my $selecteddir = $dirDialog->GetPath(); +# print $selecteddir, "\n"; + + if ( $dirDialogStatus == wxID_OK ) {$self->Wx::LogStatus ("You pressed: \"Open\" ")}; + if ( $dirDialogStatus == wxID_CANCEL ) {$self->Wx::LogStatus ("You pressed: \"Cancel\" ")}; +} diff --git a/CppTrial-pg221.pl b/CppTrial-pg221.pl new file mode 100644 index 0000000..40373ca --- /dev/null +++ b/CppTrial-pg221.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +# CppTrial-pg221.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 221 - Color Selection Dialog +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_MOTION); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg221.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (250, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + + my $colourDialog = Wx::ColourDialog->new($self); + + my $colorDialogStatus = $colourDialog->ShowModal(); + + my $colourdata = $colourDialog->GetColourData(); + my $selectedColour = $colourdata->GetColour(); + $self->SetBackgroundColour($selectedColour); + $self->Refresh(); + + if ( $colorDialogStatus == wxID_OK ) {$self->Wx::LogStatus ("You pressed: \"Ok\" ")}; + if ( $colorDialogStatus == wxID_CANCEL ) {$self->Wx::LogStatus ("You pressed: \"Cancel\" ")}; +} diff --git a/CppTrial-pg224.pl b/CppTrial-pg224.pl new file mode 100644 index 0000000..9e2993b --- /dev/null +++ b/CppTrial-pg224.pl @@ -0,0 +1,66 @@ +#!/usr/bin/perl + +# CppTrial-pg224.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 224 - Font Selection Dialog +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg224.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (250, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +EVT_PAINT($frame, \&myStdDialogs); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self, $event ) = @_; + + my $font = Wx::Font->new(18, wxFONTFAMILY_ROMAN, wxNORMAL, wxNORMAL); + + my $fontData = Wx::FontData->new(); + $fontData->SetInitialFont($font); + $fontData->SetColour(wxGREEN); + + my $fontDialog = Wx::FontDialog->new($self, $fontData); + + my $fontDialogStatus = $fontDialog->ShowModal(); + + $fontData = $fontDialog->GetFontData(); + my $selectedfont = $fontData->GetChosenFont(); + my $selectedcolour = $fontData->GetColour(); +# +# Code added to provide something to display, drag dialog off of frame to see text displayed +# + my $dc = Wx::PaintDC->new($self); + my $pt=Wx::Point->new(100,200); + $dc->SetFont($selectedfont); + $dc->SetBackgroundMode(wxTRANSPARENT); + $dc->SetTextForeground($selectedcolour); + $dc->SetTextBackground(wxWHITE); + $dc->DrawText("Font Selection Sample",$pt->x, $pt->y); + $self->Refresh(); + +# +# Loop until Cancel is Selected +# + if ( $fontDialogStatus == wxID_CANCEL ) {die "Font Selection Terminated"}; +} diff --git a/CppTrial-pg225.pl b/CppTrial-pg225.pl new file mode 100644 index 0000000..b38c8b4 --- /dev/null +++ b/CppTrial-pg225.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +# CppTrial-pg225.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 225 - Single Choice Dialog +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg225.pl', + wxDefaultPosition, wxDefaultSize); + +#Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (250, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + + my @choices = ("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"); + + my $singleChoiceDialog = Wx::SingleChoiceDialog->new($self, + "This is a small sample\nA single-choice convenience dialog", + "Please select a value", \@choices); + + $singleChoiceDialog->SetSelection(2); + + if( $singleChoiceDialog->ShowModal() == wxID_OK) { + Wx::MessageBox($singleChoiceDialog->GetStringSelection(), + "Got String", wxOK | wxICON_INFORMATION, $self); + } +} diff --git a/CppTrial-pg226.pl b/CppTrial-pg226.pl new file mode 100644 index 0000000..b7ad7c1 --- /dev/null +++ b/CppTrial-pg226.pl @@ -0,0 +1,52 @@ +#!/usr/bin/perl + +# CppTrial-pg226.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 226 - Multiple Choice Dialog +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg226.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (250, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + + my @choices = ("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"); + + my $multiChoiceDialog = Wx::MultiChoiceDialog->new($self, + "A Multi-choice convenience dialog", + "Please select several values", \@choices); + + if( $multiChoiceDialog->ShowModal() == wxID_OK) { + my @selections = $multiChoiceDialog->GetSelections(); # Returns list of index numbers + my $count = $#selections +1; # Index into @choices for text + my $msg = ""; + foreach my $selection (@selections) { + $msg .= $selection . " : " . $choices[$selection] . "\n"; + } + Wx::MessageBox($msg, "Selections", wxOK | wxICON_INFORMATION, $self); + } +} diff --git a/CppTrial-pg227.pl b/CppTrial-pg227.pl new file mode 100644 index 0000000..1c622cd --- /dev/null +++ b/CppTrial-pg227.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl + +# CppTrial-pg227.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 227 - Number Entry Dialog (**Alternate Implementation - GetNumberFromUser**) +# Could not get NumberEntryDialog, TextEntryDialog, or PasswordEntryDialog to load +# Instead used GetNumberFromUser Function +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg227.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button pushes +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (250, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + +# +# Not sure where the initial value of 20 is comming from.... +# + my $getNumberFromUser = Wx::GetNumberFromUser( # Appears to not support min/max bounds + "Number Entry Dialog Example", + "Enter A Number:", + "Number Entry", 50, wxOK | wxCANCEL, $self); +# +# Returns -1 upon Cancel +# + Wx::MessageBox("$getNumberFromUser", "Entered Number:", wxOK | wxICON_INFORMATION, $self); +} diff --git a/CppTrial-pg228A.pl b/CppTrial-pg228A.pl new file mode 100644 index 0000000..700d4f7 --- /dev/null +++ b/CppTrial-pg228A.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +# CppTrial-pg228A.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 228 - Text Entry Dialog (**Alternate Implementation - GetTextFromUser**) +# Could not get NumberEntryDialog, TextEntryDialog, or PasswordEntryDialog to load +# Instead used GetTextFromUser Function +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg228A.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (250, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + +# +# Not sure where the initial value of 20 is comming from.... +# + my $getTextFromUser = Wx::GetTextFromUser( + "This is some text, actually a lot of text\nEven two rows of text", + "Enter a String: ", wxOK | wxCANCEL, $self); +# +# Returns empty string upon Cancel +# + Wx::MessageBox("$getTextFromUser", "Entered String", wxOK | wxICON_INFORMATION, $self); +} diff --git a/CppTrial-pg228B.pl b/CppTrial-pg228B.pl new file mode 100644 index 0000000..1057357 --- /dev/null +++ b/CppTrial-pg228B.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +# CppTrial-pg228B.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 228 - Password Entry Dialog (**Alternate Implementation - GetPasswordFromUser**) +# Could not get NumberEntryDialog, TextEntryDialog, or PasswordEntryDialog to load +# Instead used GetPasswordFromUser Function +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg228B.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (250, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + +# +# Not sure where the initial value of 20 is comming from.... +# + my $getPasswordFromUser = Wx::GetPasswordFromUser( + "This is some text, actually a lot of text\nEven two rows of text", + "Enter a Password: ", wxOK | wxCANCEL, $self); +# +# Returns empty string upon Cancel +# + Wx::MessageBox("$getPasswordFromUser", "Entered Password:", wxOK | wxICON_INFORMATION, $self); +} diff --git a/CppTrial-pg245.pl b/CppTrial-pg245.pl new file mode 100644 index 0000000..1cbfc16 --- /dev/null +++ b/CppTrial-pg245.pl @@ -0,0 +1,98 @@ +#!/usr/bin/perl + +# CppTrial-pg245.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 245 - Personal Records Dialog +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $dialog = Wx::Dialog->new(undef, -1, "Personal Records Dialog Example", + wxDefaultPosition, wxDefaultSize, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); + +mydialog($dialog); + +$dialog->Show; +$app->MainLoop; + +# Example specific code +sub mydialog { + my ($dialog)= @_; + + my ($ID_NAME, $ID_AGE, $ID_SEX, $ID_VOTE, $ID_RESET, $ID_OK, $ID_CANCEL, $ID_HELP) = (1..8); + my ($wxEmptyString, $true) = ("", 1); + + my $topSizer = Wx::BoxSizer->new(wxVERTICAL); + $dialog->SetSizer($topSizer); + + my $boxSizer = Wx::BoxSizer->new(wxVERTICAL); + $topSizer->Add($boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5); + + my $desc = Wx::StaticText->new($dialog, wxID_STATIC, + "Please enter your name, age, and sex, and specify whether you wish to\nvote in a general election.", + wxDefaultPosition, wxDefaultSize, 0); + $boxSizer->Add($desc, 0, wxALIGN_LEFT | wxALL, 5); + + my $nameCtrl = Wx::TextCtrl->new($dialog, $ID_NAME, "Maylee", + wxDefaultPosition, wxDefaultSize, 0); + $boxSizer->Add($nameCtrl, 0, wxGROW | wxALL, 5); + + my $ageSexVoteBox = Wx::BoxSizer->new(wxHORIZONTAL); + $boxSizer->Add($ageSexVoteBox, 0, wxGROW | wxALL, 5); + + my $ageLabel = Wx::StaticText->new($dialog, wxID_STATIC, "&Age:", wxDefaultPosition, wxDefaultSize, 0); + $ageSexVoteBox->Add($ageLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + + my $ageSpin = Wx::SpinCtrl->new($dialog, $ID_AGE, $wxEmptyString, wxDefaultPosition, + Wx::Size->new(60, -1), wxSP_ARROW_KEYS, 0, 120, 50); + $ageSexVoteBox->Add($ageSpin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + + my $sexLabel = Wx::StaticText->new($dialog, wxID_STATIC, "&Sex:", wxDefaultPosition, wxDefaultSize, 0); + $ageSexVoteBox->Add($sexLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + + my @sexStrings = ("Male", "Female"); + my $sexChoice = Wx::Choice->new($dialog, $ID_SEX, wxDefaultPosition, + Wx::Size->new(85,-1), \@sexStrings); + $sexChoice->SetStringSelection("Female"); + $ageSexVoteBox->Add($sexChoice, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + + $ageSexVoteBox->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5); # Spacer Box + + my $voteCheckBox = Wx::CheckBox->new($dialog, $ID_VOTE, "&Vote", + wxDefaultPosition, wxDefaultSize, 0); + $voteCheckBox->SetValue($true); + $ageSexVoteBox->Add($voteCheckBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + + my $line = Wx::StaticLine->new($dialog, wxID_STATIC, wxDefaultPosition, + wxDefaultSize, wxLI_HORIZONTAL); + $boxSizer->Add($line, 0, wxGROW | wxALL, 5); + + my $okCancelBox = Wx::BoxSizer->new(wxHORIZONTAL); + $boxSizer->Add($okCancelBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + + my $reset = Wx::Button->new($dialog, $ID_RESET, "&Reset", + wxDefaultPosition, wxDefaultSize, 0); + $okCancelBox->Add($reset, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + + my $ok = Wx::Button->new($dialog, $ID_OK, "&Ok", + wxDefaultPosition, wxDefaultSize, 0); + $ok->SetDefault(); + $okCancelBox->Add($ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + + my $cancel = Wx::Button->new($dialog, $ID_CANCEL, "&Cancel", + wxDefaultPosition, wxDefaultSize, 0); + $okCancelBox->Add($cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + + my $help = Wx::Button->new($dialog, $ID_HELP, "&Help", + wxDefaultPosition, wxDefaultSize, 0); + $okCancelBox->Add($help, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + + $topSizer->Fit($dialog); + $topSizer->SetSizeHints($dialog); # Return values not processed in this example +} diff --git a/CppTrial-pg283.pl b/CppTrial-pg283.pl new file mode 100644 index 0000000..72795c0 --- /dev/null +++ b/CppTrial-pg283.pl @@ -0,0 +1,61 @@ +#!/usr/bin/perl + +# CppTrial-pg283.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 283 - Drawing a masked image +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg283.pl', + wxDefaultPosition, wxDefaultSize); +EVT_PAINT($frame,\&OnPaint); +$frame->Show; +$app->MainLoop; + +# Example specific code +sub OnPaint { + my ( $self, $event) = @_; + + my $memdc = Wx::MemoryDC->new(); + + my $bitMap = Wx::Bitmap->new(400,400); + $memdc->SelectObject($bitMap); + + my $brush1 = Wx::Brush->new(wxBLUE, wxSOLID); + $memdc->SetBackground($brush1); + $memdc->Clear(); # Fill DC with background brush color + + my $pen1 = Wx::Pen->new(wxRED,1,wxSOLID); + $memdc->SetPen($pen1); + my $brush2 = Wx::Brush->new(wxRED,wxSOLID); + $memdc->SetBrush($brush2); + $memdc->DrawRectangle(50, 50, 200, 200); # Red rectangle on blue background + + + my $image = $bitMap->ConvertToImage(); + $image->SetMaskColour(255, 0, 0); + $image->SetMask(1); + +# my $dispBitMap = Wx::Bitmap->new($image, -1); # Constructor not supported by wxPerl +# $dc->DrawBitmap($dispBitMap, 0, 0, 1); # Can't display $image +# +# Code added for display purposes - many book examples are only fragments +# + my $bmp = Wx::Bitmap->new("test2.bmp", wxBITMAP_TYPE_BMP); + $bmp->SetMask(Wx::Mask->new($bmp, wxBLUE)); +# Wx:StaticBitMap->new($memdc, -1, $bmp, [300,120]); + + my $dcPaint = Wx::PaintDC->new($self); + $dcPaint->Blit(0, 0, 400, 400, $memdc, 0, 0, wxCOPY, 1); + + $memdc->SelectObject(wxNullBitmap); + +} diff --git a/CppTrial-pg293.pl b/CppTrial-pg293.pl new file mode 100644 index 0000000..80dc507 --- /dev/null +++ b/CppTrial-pg293.pl @@ -0,0 +1,62 @@ +#!/usr/bin/perl + +# CppTrial-pg293.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 293 - Writing Text to the Clipboard +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); + + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg293.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (200, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +myStdDialogs($frame); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + + use Wx::DND; # Loads all of the Clipboard + # and Drag and Drop packages + # Like - Wx::DataObjectSimple + + my $textDataObject1 = Wx::TextDataObject->new("Save this string to the clipboard"); + + wxTheClipboard->Open; + wxTheClipboard->SetData( $textDataObject1 ); + wxTheClipboard->Close; + + wxTheClipboard->Open; + my $text; + if( wxTheClipboard->IsSupported( wxDF_TEXT ) ) { + my $textDataObject2 = Wx::TextDataObject->new; + my $ok = wxTheClipboard->GetData( $textDataObject2 ); + if( $ok ) { + $self->Wx::LogStatus( "Pasted and Retrieved text" ); + $text = $textDataObject2->GetText; + } + else { + $self->Wx::LogStatus( "Error pasting and Retrieving text" ); + $text = ''; + } + } + Wx::MessageBox($text); +} diff --git a/CppTrial-pg294.pl b/CppTrial-pg294.pl new file mode 100644 index 0000000..e621780 --- /dev/null +++ b/CppTrial-pg294.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl + +# CppTrial-pg294.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 294 - Writing a bitmap/image to the Clipboard +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $frame = Wx::Frame->new(undef, -1, + 'CppTrial-pg294.pl', + wxDefaultPosition, wxDefaultSize); + +# Use status bar to indicate button presses +Wx::InitAllImageHandlers(); +my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); +$frame->SetStatusBar($statusBar); +my @widths = (200, 100, -1); +$statusBar->SetFieldsCount($#widths+1); +$statusBar->SetStatusWidths(@widths); +$statusBar->SetStatusText("Ready", 0); + +EVT_PAINT($frame, \&myStdDialogs); + +$frame->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self, $event ) = @_; + + use Wx::DND; # Loads all of the Clipboard + # and Drag and Drop packages + # Like - Wx::DataObjectSimple + + my $bmp = Wx::Bitmap->new("logo.png", wxBITMAP_TYPE_PNG); + my $bmpObject1 = Wx::BitmapDataObject->new($bmp); + + wxTheClipboard->Open; + wxTheClipboard->SetData( $bmpObject1 ); # Put the bitmap object on the clipboard + wxTheClipboard->Close; + + wxTheClipboard->Open; + my $bitmap = wxNullBitmap; + if( wxTheClipboard->IsSupported( wxDF_BITMAP ) ) { + my $bmpObject2 = Wx::BitmapDataObject->new($bitmap); + my $ok = wxTheClipboard->GetData( $bmpObject2 ); # Get the bitmap object from the clipboard + if( $ok ) { + $self->Wx::LogStatus("Pasted and Retrieved bitmap" ); + $bitmap = $bmpObject2->GetBitmap(); + } + else { + $self->Wx::LogStatus("Error pasting bitmap" ); + $bitmap = wxNullBitmap; + } + wxTheClipboard->Close; +} +# +# Use a paint event to get the bitmap to draw on screen +# + 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->DrawBitmap($bitmap, 30, 100, 1); +} diff --git a/CppTrial-pg340.pl b/CppTrial-pg340.pl new file mode 100644 index 0000000..239855d --- /dev/null +++ b/CppTrial-pg340.pl @@ -0,0 +1,52 @@ +#!/usr/bin/perl + +# CppTrial-pg340.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 340 - HTML Window - Displays an HTML file +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); +use Wx::Html; # Html package not loaded by "use Wx qw(:everything)" + # Html pulls in all of the HTML modules +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $dialog = Wx::Dialog->new(undef, -1, + 'CppTrial-pg340.pl', + wxDefaultPosition, wxDefaultSize, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); +Wx::InitAllImageHandlers(); +myStdDialogs($dialog); +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + + my $topSizer = Wx::BoxSizer->new(wxVERTICAL); + + my $html = Wx::HtmlWindow->new($self, wxID_ANY, wxDefaultPosition, + Wx::Size->new(600,400), wxHW_SCROLLBAR_NEVER); + + $html->SetBorders(5); + $html->LoadPage("pg342.html"); +# +# GetInternalRepresentation() not supported under wxPerl +# + $topSizer->Add($html, 1, wxALL, 10); + + my $staticLine = Wx::StaticLine->new($self, wxID_ANY); + $topSizer->Add($staticLine, 0, wxEXPAND | wxLEFT | wxRIGHT, 10); + + my $button = Wx::Button->new($self, wxID_OK, "Ok"); + $button->SetDefault(); + $topSizer->Add($button, 0, wxALL | wxALIGN_RIGHT, 15); + + $self->SetSizer($topSizer); + $topSizer->Fit($self); + $self->ShowModal(); + +} diff --git a/CppTrial-pg347.pl b/CppTrial-pg347.pl new file mode 100644 index 0000000..70cec33 --- /dev/null +++ b/CppTrial-pg347.pl @@ -0,0 +1,51 @@ +#!/usr/bin/perl + +# CppTrial-pg347.pl +# Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor +# C++ Example from pg 347 - Simple Grid Example +# Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 + +use 5.010; +use strict; +use warnings; +use Wx qw(:everything); +use Wx::Event qw(EVT_PAINT); +use Wx::Grid; # Package not loaded by "use Wx qw(:everything)" + +# create the WxApplication +my $app = Wx::SimpleApp->new; +my $dialog = Wx::Dialog->new(undef, -1, + 'CppTrial-pg347.pl', + wxDefaultPosition, wxDefaultSize, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); +Wx::InitAllImageHandlers(); +myStdDialogs($dialog); +$dialog->Show; +$app->MainLoop; + +# Example specific code +sub myStdDialogs { + my ( $self ) = @_; + + my $grid = Wx::Grid->new($self, wxID_ANY, wxDefaultPosition, + Wx::Size->new(400,300)); + + $grid->CreateGrid(8, 10); # 8 rows by 10 columns + $grid->SetRowSize(0, 60); # row size in pixels + $grid->SetColSize(0, 120); # column size in pixels + + $grid->SetCellValue(0, 0, "wxGrid is Good"); # A1 + + $grid->SetCellValue(0, 3, "This is Read-only"); # D1 + $grid->SetReadOnly(0, 3); + + $grid->SetCellValue(3, 3, "Green on Grey"); # D4 + $grid->SetCellTextColour(3, 3, wxGREEN); + $grid->SetCellBackgroundColour(3, 3, wxLIGHT_GREY); + + $grid->SetColFormatFloat(5, 6, 2); + $grid->SetCellValue(0, 5, "3.1415"); # F1 + + $grid->Fit(); + $self->SetClientSize($grid->GetSize); +} diff --git a/FILE-INDEX.txt b/FILE-INDEX.txt new file mode 100644 index 0000000..1054f1d --- /dev/null +++ b/FILE-INDEX.txt @@ -0,0 +1,70 @@ +---------------------------------------------------------------------------------------------------- + +Index of Example Files from : Cross Platform GUI Programming with wxWidgets +by: Smart, Hock, and Csomor - The "wxBook" +Ported to wxPerl by: James M. Lynes, Jr., September 26,2012 +---------------------------------------------------------------------------------------------------- + +1. CppTrial-pg019.pl : # C++ Example from pg 19 - Create a basic frame with menus and status bar +2. CppTrial-pg065.pl : # C++ Example from pg 65 - MDI Child Frame Example +3. CppTrial-pg073.pl : # C++ Example from pg 73 - Notebook Example +4. CppTrial-pg077.pl : # C++ Example from pg 77 - Scrolled Window Example +5. CppTrial-pg081.pl : # C++ Example from pg 81 - Splitter Window Example +6. CppTrial-pg086.pl : # C++ Example from pg 86 - 20 Assorted Static & Non-Static Controls Examples +7. CppTrial-pg124.pl : # C++ Example from pg 124 - Tool Bar Example +8. CppTrial-pg133.pl : # C++ Example from pg 133 - Drawing on Windows with wxClientDC +9. CppTrial-pg135.pl : # C++ Example from pg 135 - Drawing on Windows with wxPaintDC +10. CppTrial-pg150.pl : # C++ Example from pg 150 - Drawing Text - Extends pg 135 example +11. CppTrial-pg151.pl : # C++ Example from pg 151 - Drawing Text Rotated - Extends pg 150 & 135 examples +12. CppTrial-pg152.pl : # C++ Example from pg 152 - Centering Text - Extends pg 151, 150, & 135 examples +13. CppTrial-pg154.pl : # C++ Example from pg 154 - Drawing multiple lines - Extends pg 135 example +14. CppTrial-pg155.pl : # C++ Example from pg 155 - Drawing polygons - Extends pg 154 example +15. CppTrial-pg156.pl : # C++ Example from pg 156 - Drawing Splines - Extends pg 155 example +16. CppTrial-pg157.pl : # C++ Example from pg 157 - Drawing Bitmaps - Extends pg 150 example +17. CppTrial-pg158.pl : # C++ Example from pg 158 - Copy(Tile) Bitmaps Between Device Contexts - Extends pg 157 example +18. CppTrial-pg159A.pl : # C++ Example from pg 159A - Filling arbitrary areas - Extends pg 135 example +19. CppTrial-pg159B.pl : # C++ Example from pg 159B - Logical Functions - Extends pg 135 example +20. CppTrial-pg195.pl : # C++ Example from pg 195 - Sizers -Dialog with streatching text control +21. CppTrial-pg196.pl : # C++ Example from pg 196 - Sizers -Dialog with static box sizer and check box +22. CppTrial-pg197.pl : # C++ Example from pg 197 - Sizers -Dialog with grid sizer +23. CppTrial-pg199.pl : # C++ Example from pg 199 - Sizers -Dialog with flex grid sizer +24. CppTrial-pg201.pl : # C++ Example from pg 201 - Sizers -Dialog with grid bag sizer +25. CppTrial-pg202.pl : # C++ Example from pg 202 - Sizers -Dialog with Standard Dialog Button Sizer +26. CppTrial-pg207A.pl : # C++ Example from pg 207(A) - Message Dialog Dialog +27. CppTrial-pg207B.pl : # C++ Example from pg 207(B) - Message Box Dialog +28. CppTrial-pg209.pl : # C++ Example from pg 209 - Progress Dialog +29. CppTrial-pg210.pl : # C++ Example from pg 210 - Busy Info Box +30. CppTrial-pg211.pl : # C++ Example from pg 211 - Application Tips Dialog +31. CppTrial-pg215.pl : # C++ Example from pg 215 - File Dialog +32. CppTrial-pg218.pl : # C++ Example from pg 218 - Directory Dialog +33. CppTrial-pg221.pl : # C++ Example from pg 221 - Color Selection Dialog +34. CppTrial-pg224.pl : # C++ Example from pg 224 - Font Selection Dialog +35. CppTrial-pg225.pl : # C++ Example from pg 225 - Single Choice Dialog +36. CppTrial-pg226.pl : # C++ Example from pg 226 - Multiple Choice Dialog +37. CppTrial-pg227.pl : # C++ Example from pg 227 - Number Entry Dialog (**Alt Implementation - GetNumberFromUser**) +38. CppTrial-pg228A.pl : # C++ Example from pg 228 - Text Entry Dialog (**Alt Implementation - GetTextFromUser**) +39. CppTrial-pg228B.pl : # C++ Example from pg 228 - Password Entry Dialog (**Alt Implementation - GetPasswordFromUser**) +40. CppTrial-pg245.pl : # C++ Example from pg 245 - Personal Records Dialog +41. CppTrial-pg283.pl : # C++ Example from pg 283 - Drawing a masked image +42. CppTrial-pg293.pl : # C++ Example from pg 293 - Writing Text to the Clipboard +43. CppTrial-pg294.pl : # C++ Example from pg 294 - Writing a bitmap/image to the Clipboard +44. CppTrial-pg340.pl : # C++ Example from pg 340 - HTML Window - Displays an HTML file +45. CppTrial-pg347.pl : # C++ Example from pg 347 - Simple Grid Example + +Additional support files used by the example code +------------------------------------------------- +cut.xpm +copy.xpm +print.xpm +tips.txt +logo.png +padre_logo_64x64.png +pg342.html +test2.bmp + +Documentation Files +------------------- +README.txt +FILE-INDEX.txt + + diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..c1e7a3a --- /dev/null +++ b/README.txt @@ -0,0 +1,135 @@ +A Compilation of wxPerl Ports of the C++ Examples from "The wxBook" +--------------------------------------------------------------------------------- +Ported and compiled by James M. Lynes, Jr. April-May 2011 & August-September 2012. + +Major Modifications implemented in September 2012. Setup code for each example was +greatly simplified using wx::SimpleApp as suggested by Mattia Barbon. + +Introduction +------------ +While I have many years in real-time control system software development, I am new to +Ubuntu, Perl, and wxPerl. It is probably best to not try to learn all of these at the +same time, but that's where I am at. + +I purchased a copy of "The wxBook" - "Cross-Platform GUI Programming with wxWidgets" +by Smart, Hock, & Csomar. After two complete read-throughs, I downloaded a copy of +wxIndustrialControls(Appendix E - www.koansoftware.com) and began a port of their +LCD Display program. I soon realized that I did not understand enough about the +relationship between C++ and wxPerl to complete this port. + +To get past this learning curve I decided to port the C++ examples from the wxBook +to wxPerl. Over 45 examples have been ported so far. Each port was kept as close +to the C++ example code as possible. However, changes were made where required +by differences in wxPerl syntax or implementation. Also, code +was added where necessary to provide screen output of the example topic. + +The examples were coded to be clear to someone new to wxPerl(like myself) and it +is not my desire to trade clarity for efficiency. I believe in coding for the next +guy that has to maintain my code - KISS. Almost all programs deal with a single topic +unlike some of the other examples available on-line. The single topic implementation +should be easier for a beginner to grasp. I think this style would have shortened +my learning process. An exception is CppTrial-pg086.pl which consists of 20 short +Static and Non-Static Control examples. Most of these are 3-4 lines long and +don't need to be discussed individually. + +As much as possible the setup code was kept the same from example to example. The +specific example code was isolated to a subroutine in the bottom half of the +program. These example code subroutines were called directly and via OnPaint and +OnMotion events as necessary to generate screen output of the example results. +You will notice that the setup code did evolve somewhat as the porting +progressed(and has since evolved more). An example of the learning curve in action! + + +Lessons Learned +--------------- +The 2300+ page wx.pdf manual is hard to use on my relatively slow Thinkpad R31. The +search feature is so slow as to be unusable. So, page through the index to find your +topic, add 28(+/-) to the page number, then jump directly to that page. + +Not all features in wxwidgets are implemented in wxPerl. Look for wxPerl specific +notes in wx.pdf. A digest of all of these notes would be useful. + +wxwidgets features that use "wxArraySomething" will instead use a wxPerl list - @list +or a list reference \@list or array syntax [x,y]. + +use Wx qw(:everything) doesn't really load all modules- like the Grid, HTML and Clipboard +modules. Substantial time can be spent locating the module that exports the function +that you need. It would be nice to have an index of all the modules and their +exporters, as well as all constant definitions. Any input on this topic would be welcome. + +Case matters! C++ wxFunction() becomes wxPerl Wx::Function->new(). wx is not Wx. +WxFunction is not Wx::Function. Typos will cause module loading errors. + +The PADRE debugger locks up from time to time. Save your work often. + + +Porting Environment +------------------- +All porting was done using Ubuntu 10.10, Perl 5.10.1, and the PADRE IDE. Modifications +were done with gedit. + + +RESOURCES +--------- +These resources were found to be useful in porting the wxBook examples. Many thanks +to their authors. + +"Cross-Platform GUI Programming with wxWidgets" Smart, Hock, & Csomar - The "wxBook" +(Buy this book! It's well worth the cost) + +"Learning Perl" - Schwartz, Phoenix, & d Foy + +"Programming Perl" - Christiansen, d Foy, Wall, & Orwant + +"Perl Cookbook" - Christiansen & Torkington + +perldoc (perldoc perltoc) - On-line Man Pages + +"wxWidgets 2.8.10: A Portable C++ and Python GUI Toolkit" + Smart, Roebling, Zeitlin, Dunn et. al. - PDF Format (Wx.pdf) + +"wxWidgets 2.8.7: A Portable C++ and Python GUI Toolkit" + Smart, Roebling, Zeitlin, Dunn et. al. - HTML Format(many files) + +Numerous Demo and Example Programs by Mattia Barbon - (Sourceforge.net) + +Tutorials from the Perl Monks ( +www.perlmonks.org) + Three by Boo Radley + A Simple Socket Server Using "inetd" - Samizdat + +Tutorials from the wxPerl Wiki: + C++ Docs for Perl Programmers + WxPerl Tablet (i.e. The Cheat-sheet) + Download with Progress Bar + Memory DC + Mini Image Demo + Tiled Background Image + wxPerl GUI for a Twitter Script + +The PADRE IDE and Included Sample Programs + +www.perlmonks.org + +wxperl.sourceforge.net + +wiki.wxperl.info + +www.wxwidgets.org + +www.perl.org + +www.nntp.perl.org/group/perl.wxperl.users/2012/ + +search.cpan.org + +And others that were read, but the references were not recorded.... + +Original version uploaded to www.perlmonks.org August 2012 - two large files. +(This) github initial version uploaded September 2012 - separate files. + +I hope you find this information useful. + +James M. Lynes, Jr. - Lakeland, Florida September 2012 + + diff --git a/copy.xpm b/copy.xpm new file mode 100644 index 0000000..47565c1 --- /dev/null +++ b/copy.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static char *copy_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 4 1", +" c None", +". c Black", +"X c Gray100", +"o c #000080", +/* pixels */ +" ", +" ...... ", +" .XXXX.. ", +" .XXXX.X. ", +" .X..X.oooooo ", +" .XXXXXoXXXXoo ", +" .X....oXXXXoXo ", +" .XXXXXoX..Xoooo", +" .X....oXXXXXXXo", +" .XXXXXoX.....Xo", +" ......oXXXXXXXo", +" oX.....Xo", +" oXXXXXXXo", +" ooooooooo", +" " +}; diff --git a/cut.xpm b/cut.xpm new file mode 100644 index 0000000..bfe7e95 --- /dev/null +++ b/cut.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char *cut_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 3 1", +" c None", +". c Black", +"X c #000080", +/* pixels */ +" ", +" . . ", +" . . ", +" . . ", +" .. .. ", +" . . ", +" ... ", +" . ", +" X.X ", +" X XXX ", +" XXX X X ", +" X X X X ", +" X X X X ", +" X X XX ", +" XX " +}; diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..73d83ca Binary files /dev/null and b/logo.png differ diff --git a/padre_logo_64x64.png b/padre_logo_64x64.png new file mode 100644 index 0000000..61df291 Binary files /dev/null and b/padre_logo_64x64.png differ diff --git a/pg342.html b/pg342.html new file mode 100644 index 0000000..3c2a964 --- /dev/null +++ b/pg342.html @@ -0,0 +1,34 @@ + + + + + + + + + +
+
+
wxHTML Library Sample 0.2.0
+
+
+
+ Copyright (c) 1999 Vaclav Slavic

+ + + + + + +
+ Vaclav Slavik

+

+ +
+ + Licenced under wxWindows Library Licence, Version 3. + +
+

+ + diff --git a/print.xpm b/print.xpm new file mode 100644 index 0000000..3c2e2be --- /dev/null +++ b/print.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static char *print_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 5 1", +" c None", +". c Black", +"X c Gray100", +"o c #808000", +"O c Yellow", +/* pixels */ +" ", +" ......... ", +" .XXXXXXXX. ", +" .X.....X. ", +" .XXXXXXXX. ", +" .X.....X.... ", +" .XXXXXXXX. . .", +" .......... . ..", +". . . .", +"............. .", +". ooo . . ", +". OOO ... ", +"............. . ", +" . . . ", +" ........... " +}; diff --git a/test2.bmp b/test2.bmp new file mode 100644 index 0000000..3a65473 Binary files /dev/null and b/test2.bmp differ diff --git a/tips.txt b/tips.txt new file mode 100644 index 0000000..9a165ba --- /dev/null +++ b/tips.txt @@ -0,0 +1,10 @@ +This is Application Tip #1... +This is Application Tip #2... +This is Application Tip #3... +This is Application Tip #4... +This is Application Tip #5... +This is Application Tip #6... +This is Application Tip #7... +This is Application Tip #8... +This is Application Tip #9... +This is Application Tip #10...