App-GUI-Notepad

 view release on metacpan or  search on metacpan

lib/App/GUI/Notepad/Frame.pm  view on Meta::CPAN

package App::GUI::Notepad::Frame;

use strict;
use File::Spec  ();
use base qw/Wx::Frame/;
use Wx          qw/:allclasses wxTE_MULTILINE wxID_OK wxSAVE wxOK wxCENTRE wxFONTENCODING_SYSTEM wxMODERN wxNORMAL wxNullColour wxSWISS wxTE_RICH/;
use Wx::Event   qw/EVT_MENU/;


use App::GUI::Notepad::MenuBar;

use vars qw{$VERSION};
BEGIN {
	$VERSION = '0.01';
}

# This is the constructor for the object.
# It creates:
# 			- the menubar
#			- the textctrl which is where the text that is being edited is 
#			is stored
#			- the status bar where non modal messages can be sent to the 
#			user 
# It associates actions to the various menu options, sets the application 
# icon and sets the font for displaying the file to a fixed width font.

sub new {
	my ($class) = shift;
	my ($title, $position, $size) = @_;
	my ($this) = $class->SUPER::new( undef, -1, $title, $position, $size );
	$this->SetIcon( Wx::GetWxPerlIcon() );

	$this->{menubar} = App::GUI::Notepad::MenuBar->new();
	$this->SetMenuBar( $this->{menubar}->menubar() );

	# Associate the various menu options with subroutines that are the 
	# actions to be carried out when the user clicks on the menu item.
	#
    # I wanted to do this in the MenuBar object but this function 
	# EVT_MENU need a reference to the frame and so they are called 
	# here

	EVT_MENU( $this, $this->{menubar}->{ID_NEW},    \&_menu_new    );
	EVT_MENU( $this, $this->{menubar}->{ID_OPEN},   \&_menu_open   );
	EVT_MENU( $this, $this->{menubar}->{ID_SAVE},   \&_menu_save   );
	EVT_MENU( $this, $this->{menubar}->{ID_SAVEAS}, \&_menu_saveas );
	EVT_MENU( $this, $this->{menubar}->{ID_CLOSE},  \&_menu_close  );
	EVT_MENU( $this, $this->{menubar}->{ID_EXIT},   \&_menu_exit   );
	EVT_MENU( $this, $this->{menubar}->{ID_UNDO},   \&_menu_undo   );
	EVT_MENU( $this, $this->{menubar}->{ID_REDO},   \&_menu_redo   );
	EVT_MENU( $this, $this->{menubar}->{ID_CUT},    \&_menu_cut    );
	EVT_MENU( $this, $this->{menubar}->{ID_COPY},   \&_menu_copy   );
	EVT_MENU( $this, $this->{menubar}->{ID_PASTE},  \&_menu_paste  );
	EVT_MENU( $this, $this->{menubar}->{ID_ABOUT},  \&_menu_about  );

	# Create the main text control

	$this->{textctrl} = Wx::TextCtrl->new(
		$this,
		-1,
		"", 
	        [ 0, 0 ], 
		[ 100, 100 ],
		wxTE_MULTILINE | wxTE_RICH,
		);

	# Set the font of the new text control to a fixed width font Courier New
	# This font was chosen because of it's availablity on different platforms.

	my $font = Wx::Font->new(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Courier New");

	my $black = Wx::Colour->new(255,255,255);
	my $white = Wx::Colour->new(0,0,0);
	my $textattr = Wx::TextAttr->new($white, $black, $font);

	$this->{textctrl}->SetDefaultStyle($textattr);


	#Create the statusbar

	$this->CreateStatusBar(2);

	return $this;
}


# This sub is called when the user clicks on menu File item New
# The textctrl and filename is cleared

sub _menu_new {



( run in 1.579 second using v1.01-cache-2.11-cpan-39bf76dae61 )