Hi Jeff,

Yes, I think it's the same code.  Mine is:

http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/src/richtext/richtextprin
t.cpp?view=markup

Which is a bit we easier to read.

So far I've done nothing except convert and modify the C++ wxRTC editor into
wxPerl which edits and creates an RTC control and saves an XML file.  It
also calls print the preview from Mattia's Wx::Demo, which I need to modify
to call the Wx::RTCPrinting code.  If that would help you are welcome to it.

I've attached it to the end of this email.  It needs a set of icons, so
either create your own or email me for the ones I have.  I can't remember
where I got mine, it may have been the wxRichText C++ sample code.

Anyhow I'd be happy to collaborate.

Let me know what you think.

Regards

Steve

#!/usr/bin/perl -w -- 

use Wx 0.15 qw[:allclasses];
use strict;

package MyFrame;

use Wx qw[:everything];
use base qw(Wx::Frame);
use base qw(Class::Accessor::Fast);

use Wx qw(:richtextctrl :textctrl :font :sizer :color);
our $gl_installation_path = 'C:\\Documents and Settings\\Steve.Cookson\\My
Documents\\Projects\\RTC\\';
our $gl_self_ptr;
__PACKAGE__->mk_accessors( qw(richtext stylesheet control) );
sub new {
        my( $i_frame, $parent, $id, $title, $pos, $size, $style, $name ) =
@_;

        $style = wxDEFAULT_FRAME_STYLE  unless defined $style;

        $i_frame = $i_frame->SUPER::new( undef, wxID_ANY, "Rich Text
Control", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, "" );
        my $canvas = i_Printing::Canvas->new( $i_frame, -1 );
        $i_frame->{CANVAS} = $canvas;
        $gl_self_ptr = $i_frame;
        $i_frame->SetTitle("Rich Text Control");
        $i_frame->{Ctl_Post_Exam_Report_Szr_1} =
Wx::BoxSizer->new(wxHORIZONTAL);
        $i_frame->{Ctl_Post_Exam_Report_Grid_Szr_2} =
Wx::FlexGridSizer->new(6, 6, 1, 1);
        
        # General Parameters
        my @loc_parameters_arr;
        $#loc_parameters_arr=0;
# Remove elements from array.
        @loc_parameters_arr = ("", "", 1, "", -1, -1, "",
                "",
                \$i_frame->{Ctl_Post_Exam_Report_Szr_1},
                \$i_frame, "");
        $loc_parameters_arr [12]=  '';
        $loc_parameters_arr [13]=  '';
        
        # Bold  Button
        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Bold_Text_Btn}; #
Button name, passed by reference
        $loc_parameters_arr [7]= (("Embolden or un-embolden selected
text"));                # Tooltip
        $loc_parameters_arr [10]= (("Images/wordproccess/edit-bold.png"));
# Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_bold);
        __new_BitmapButton(@loc_parameters_arr);
        
        # Italicize Button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Italic_Text_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Italicize or de-italicise selected
text"));        # Tooltip
        $loc_parameters_arr [10]= (("Images/wordproccess/edit-italic.png"));
# Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_italics);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);

        # Underline Button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Underline_Text_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Underline selected text"));
# Tooltip
        $loc_parameters_arr [10]=
(("Images/wordproccess/edit-underline.png")); # Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_underline);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);
        
        ${$loc_parameters_arr [8]}->Add(20, 20, 0, 0, 0);
# Add spacer between groups of buttons.

        # Left align paragraph button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Left_Align_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Left align paragraph"));
# Tooltip
        $loc_parameters_arr [10]=
(("Images/wordproccess/edit-alignment.png")); # Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_align_left);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);

        # Centre align paragraph button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Centre_Align_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Centre align paragraph"));
# Tooltip
        $loc_parameters_arr [10]=
(("Images/wordproccess/edit-alignment-center.png")); # Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_align_centre);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);

        # Right align paragraph button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Right_Align_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Right align paragraph"));
# Tooltip
        $loc_parameters_arr [10]=
(("Images/wordproccess/edit-alignment-right.png")); # Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_align_right);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);
        
        # Justify align paragraph button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Justify_Align_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Justify align paragraph"));
# Tooltip
        $loc_parameters_arr [10]=
(("Images/wordproccess/edit-alignment-justify.png")); # Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_align_justify);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);

        ${$loc_parameters_arr [8]}->Add(20, 20, 0, 0, 0);
# Add spacer between groups of buttons.
        
        # Indent paragraph button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Indent_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Indent paragraph"));
# Tooltip
        $loc_parameters_arr [10]= (("Images/wordproccess/edit-indent.png"));
# Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_indent);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);

        # Outdent paragraph button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Outdent_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Remove Paragraph Indent"));
# Tooltip
        $loc_parameters_arr [10]=
(("Images/wordproccess/edit-outdent.png")); # Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_outdent);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);

        ${$loc_parameters_arr [8]}->Add(20, 20, 0, 0, 0);
# Add spacer between groups of buttons.

        # Bullet paragraph button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Bullets_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Bullet or remove bullets from selected
paragraphs"));                          # Tooltip
        $loc_parameters_arr [10]= (("Images/wordproccess/edit-list.png")); #
Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_bullets);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);

        ${$loc_parameters_arr [8]}->Add(20, 20, 0, 0, 0);
# Add spacer between groups of buttons.

        # Copy button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Copy_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Copy selection"));
# Tooltip
        $loc_parameters_arr [10]=
(("Images/wordproccess/MyBitmapsFunc_3.png")); # Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_copy);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);

        # Cut button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Cut_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Cut selection"));
# Tooltip
        $loc_parameters_arr [10]=
(("Images/wordproccess/MyBitmapsFunc_2.png"));  # Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_cut);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);

        # Paste button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Cut_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Paste selection"));
# Tooltip
        $loc_parameters_arr [10]=
(("Images/wordproccess/MyBitmapsFunc_4.png"));  # Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_paste);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);

        ${$loc_parameters_arr [8]}->Add(20, 20, 0, 0, 0);
# Add spacer between groups of buttons.

        # Show paragraph setting dialog box

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Paragraph_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Show paragraph setting dialog box"));
# Tooltip
        $loc_parameters_arr [10]=
(("Images/wordproccess/edit-drop-cap.png"));            # Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_paragraph);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);

        # Show font settings dialog box

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Font_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Show font settings dialog box"));
# Tooltip
        $loc_parameters_arr [10]=
(("Images/wordproccess/edit-outline.png")); # Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_font);
# Subroutine to call on event.
        __new_BitmapButton(@loc_parameters_arr);

        # Preview  Button

        $loc_parameters_arr [0]= \$i_frame->{Ctl_Report_Preview_Text_Btn};
# Button name, passed by reference
        $loc_parameters_arr [7]= (("Preview report."));         # Tooltip
        $loc_parameters_arr [10]=
("Images/wordproccess/16px-Document-print-preview.png");                #
Bitmap path
        $loc_parameters_arr [11]= (\&on_click_richtext_preview); #
        __new_BitmapButton(@loc_parameters_arr);
        
        $i_frame->{sizer} = Wx::BoxSizer->new( wxVERTICAL );

        $i_frame->{sizer}->Add($i_frame->{Ctl_Post_Exam_Report_Szr_1}, 0, 0,
0);

        
        $i_frame->{Ctl_Report_Text_Txt} = Wx::RichTextCtrl->new( $i_frame,
-1, '', [-1, -1],
                                          [800, 600] );
        $i_frame->{sizer}->Add( $i_frame->{Ctl_Report_Text_Txt}, 1,
wxGROW|wxALL, 5 );
        my $XML_handler = Wx::RichTextXMLHandler->new;
        my $HTML_handler = Wx::RichTextHTMLHandler->new;
        my $RTC_Buffer = $i_frame->{Ctl_Report_Text_Txt}->GetBuffer();
        $RTC_Buffer ->AddHandler($XML_handler);
        $RTC_Buffer ->AddHandler($HTML_handler);
#       $i_frame->{Ctl_Report_Text_Txt}->LoadFile("output.xml");

        $i_frame->SetSizerAndFit( $i_frame->{sizer} );
        $i_frame->Layout();
        return $i_frame;
}

sub on_click_richtext_bold{
        my ($self, $event) = @_;
        $self->{Ctl_Report_Text_Txt}->ApplyBoldToSelection;
        return $self;
}
sub on_click_richtext_italics{
        my ($self, $event) = @_;
        $self->{Ctl_Report_Text_Txt}->ApplyItalicToSelection;
        return $self;
}
sub on_click_richtext_underline{
        my ($self, $event) = @_;
        $self->{Ctl_Report_Text_Txt}->ApplyUnderlineToSelection;
        return $self;
}
sub on_click_richtext_align_left{
        my ($self, $event) = @_;
 
$self->{Ctl_Report_Text_Txt}->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_LEF
T);
        return $self;
}
sub on_click_richtext_align_centre{
        my ($self, $event) = @_;
 
$self->{Ctl_Report_Text_Txt}->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_CEN
TRE);
        return $self;
}
sub on_click_richtext_align_right{
        my ($self, $event) = @_;
 
$self->{Ctl_Report_Text_Txt}->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_RIG
HT);
        return $self;
}
sub on_click_richtext_align_justify{
        my ($self, $event) = @_;
 
$self->{Ctl_Report_Text_Txt}->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_JUS
TIFIED);
        return $self;
}

sub on_click_richtext_indent{
        my ($self, $event) = @_;
        my $loc_position = $self->{Ctl_Report_Text_Txt} ->
GetCaretPosition();          # Get current position
        my $loc_range = Wx::RichTextRange->new($loc_position,$loc_position);
        if ($self->{Ctl_Report_Text_Txt} -> HasSelection) {
# If there is a selection
                $loc_range = $self->{Ctl_Report_Text_Txt} ->
GetSelectionRange();       # Get current range
        }
        my $loc_indent_style =
$self->{Ctl_Report_Text_Txt}->GetRichTextAttrStyle($loc_position);

        $loc_indent_style ->SetLeftIndent(($loc_indent_style ->
GetLeftIndent()) + 50); # Add 5mm to indent position

 
$self->{Ctl_Report_Text_Txt}->SetStyleRange($loc_range,$loc_indent_style);
        return $self;
}


sub on_click_richtext_outdent{
        my ($self, $event) = @_;
        my $loc_position = $self->{Ctl_Report_Text_Txt} ->
GetCaretPosition();          # Get current position
        my $loc_range = Wx::RichTextRange->new($loc_position,$loc_position);
        if ($self->{Ctl_Report_Text_Txt} -> HasSelection) {
# If there is a selection
                $loc_range = $self->{Ctl_Report_Text_Txt} ->
GetSelectionRange();       # Get current range
        }
        my $loc_indent_style =
$self->{Ctl_Report_Text_Txt}->GetRichTextAttrStyle($loc_position);

        $loc_indent_style ->SetLeftIndent(($loc_indent_style ->
GetLeftIndent()) - 50); # Subtract 5mm to indent position

 
$self->{Ctl_Report_Text_Txt}->SetStyleRange($loc_range,$loc_indent_style);
        return $self;
}
#sub on_click_richtext_preview
#{
#       my ($self, $event) = @_;
#        my $loc_RTC_printing = Wx::RichTextPrinting->new();
#        $loc_RTC_printing
->PreviewBuffer($self->{Ctl_Report_Text_Txt}->GetBuffer());
#        return $self;
#}


sub canvas { $_[0]->{CANVAS} }

sub on_click_richtext_preview {
        my( $this, $event ) = @_;

        my $prev = i_Printing::Printout->new( $this->canvas, "Preview" );
        my $print = i_Printing::Printout->new( $this->canvas, "Print" );
        my $preview = Wx::PrintPreview->new( $prev, $print );
        print $preview -> IsOk(), "\n";
        my $frame = i_Printing::PreviewFrame->new( $preview,
wxTheApp->GetTopWindow,
                                     "Print Preview", [-1, -1],
wxDefaultSize );
        $frame->Initialize();
  
        $frame->Show( 1 );
}
sub on_click_richtext_print{
        my ($self, $event) = @_;
        
 
$self->{Ctl_Report_Text_Txt}->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_JUS
TIFIED);
        return $self;
}
sub on_click_richtext_pagesetup{
        my ($self, $event) = @_;
        
 
$self->{Ctl_Report_Text_Txt}->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_JUS
TIFIED);
        return $self;
}
sub on_click_richtext_copy{
        my ($self, $event) = @_;
        
        $self->{Ctl_Report_Text_Txt}->Copy();
        return $self;
}
sub on_click_richtext_cut{
        my ($self, $event) = @_;
        
        $self->{Ctl_Report_Text_Txt}->Cut();
        return $self;
}
sub on_click_richtext_paste{
        my ($self, $event) = @_;
        
        $self->{Ctl_Report_Text_Txt}->Paste();
        return $self;
}

sub on_click_richtext_bullets{
        my ($self, $event) = @_;
        my $loc_position = $self->{Ctl_Report_Text_Txt} ->
GetCaretPosition();          # Get current position
        my $loc_range = Wx::RichTextRange->new($loc_position,$loc_position);
        if ($self->{Ctl_Report_Text_Txt} -> HasSelection) {
# If there is a selection
                $loc_range = $self->{Ctl_Report_Text_Txt} ->
GetSelectionRange();       # Get current range
        }
        my $loc_style =
$self->{Ctl_Report_Text_Txt}->GetRichTextAttrStyle($loc_position);

        my $loc_RTC_Bullet_Style_Definition =
Wx::RichTextListStyleDefinition->new("Bullet List 1");
        for (my $i=0;$i<10;$i++){
                $loc_RTC_Bullet_Style_Definition -> SetAttributes($i, $i*50,
50, wxTEXT_ATTR_BULLET_STYLE_STANDARD, "standard/Square");
        }
        $loc_RTC_Bullet_Style_Definition -> SetStyle($loc_style);
        
 
$self->{Ctl_Report_Text_Txt}->ApplyStyle($loc_RTC_Bullet_Style_Definition);
        return $self;
}

sub on_click_richtext_paragraph{
        my ($self, $event) = @_;
        my $loc_position = $self->{Ctl_Report_Text_Txt} ->
GetCaretPosition();          # Get current position
        my $loc_range = Wx::RichTextRange->new($loc_position,$loc_position);
        if ($self->{Ctl_Report_Text_Txt} -> HasSelection) {
# If there is a selection
                $loc_range = $self->{Ctl_Report_Text_Txt} ->
GetSelectionRange();       # Get current range
        }
        my $loc_style =
$self->{Ctl_Report_Text_Txt}->GetRichTextAttrStyle($loc_position);
        my $log_pages =
wxRICHTEXT_FORMAT_INDENTS_SPACING|wxRICHTEXT_FORMAT_BULLETS|wxRICHTEXT_FORMA
T_TABS;
        my $dlg_format = Wx::RichTextFormattingDialog -> newFull
($log_pages,$self,"Format Paragraph",wxID_ANY, wxDefaultPosition,
wxDefaultSize,wxDEFAULT_DIALOG_STYLE); # , -1, (("Paragraph details"))
        $dlg_format -> GetStyle ($self->{Ctl_Report_Text_Txt}, $loc_range);
        if ($dlg_format->ShowModal()==wxID_OK){
 
$dlg_format->ApplyStyle($self->{Ctl_Report_Text_Txt},$loc_range,wxRICHTEXT_S
ETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE|wxRICHTEXT_SETSTYLE_PARAGRAPH
S_ONLY)
        }
        
        return $self;
}

sub on_click_richtext_font{
        my ($self, $event) = @_;
        my $loc_position = $self->{Ctl_Report_Text_Txt} ->
GetCaretPosition();          # Get current position
        my $loc_range = Wx::RichTextRange->new($loc_position,$loc_position);
        if ($self->{Ctl_Report_Text_Txt} -> HasSelection) {
# If there is a selection
                $loc_range = $self->{Ctl_Report_Text_Txt} ->
GetSelectionRange();       # Get current range
        }
        my $loc_style =
$self->{Ctl_Report_Text_Txt}->GetRichTextAttrStyle($loc_position);
        my $log_pages = wxRICHTEXT_FORMAT_FONT;
        my $dlg_format = Wx::RichTextFormattingDialog -> newFull
($log_pages,$self,"Format Paragraph",wxID_ANY, wxDefaultPosition,
wxDefaultSize,wxDEFAULT_DIALOG_STYLE); # , -1, (("Paragraph details"))
        $dlg_format -> GetStyle ($self->{Ctl_Report_Text_Txt}, $loc_range);
        if ($dlg_format->ShowModal()==wxID_OK){
 
$dlg_format->ApplyStyle($self->{Ctl_Report_Text_Txt},$loc_range,wxRICHTEXT_S
ETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE|wxRICHTEXT_SETSTYLE_CHARACTER
S_ONLY)
        }
        
        return $self;
}
sub __new_BitmapButton{

# sets field properties, format:
# __new_Button(\$loc_self_ptr, "", $loc_enabled, "", $loc_minsize_x,
$loc_minsize_y, "", $loc_tooltip, \$loc_sizer_ptr, \$loc_panel_ptr,
(("Label"));
        my $loc_bcur = Wx::BusyCursor->new;
# Create hourglass within current scope.  Hourglass is deleted on exit.
        
        my $loc_self_ptr=shift;
# pointer to control (Pass by reference)
        my $loc_ID=shift;
# ID used to over-ride wxID_ANY
        my $loc_enabled=shift;
# Enabled or disabled
        my $loc_max_length=shift;
# Not used, set to null
        my $loc_minsize_x=shift;
# Holds minimum size of control (x-axis)
        my $loc_minsize_y=shift;
# Holds minimum size of control (y-axis)
        my $loc_validation_string=shift;
# Not used, set to null
        my $loc_tooltip=shift;
# Holds tooltip already translated.
        my $loc_sizer_ptr=shift;
# pointer to sizer (Pass by reference)
        my $loc_panel_ptr=shift;
# pointer to panel (Pass by reference)
        my $loc_control_value=shift;
# Label for button
        
        my $loc_button_event_ptr=shift;
# Event (pointer.)
        my $loc_gbposition_ptr=shift;
# Gridbag position details (pointer.)
        my $loc_gbspan_ptr=shift;
# Gridbag span details (pointer.)
        my $bitmap_path = $gl_installation_path.$loc_control_value;
        
        if( $loc_ID eq ""){
            $$loc_self_ptr = Wx::BitmapButton->
                new($$loc_panel_ptr, wxID_ANY, Wx::Bitmap->new($bitmap_path,
wxBITMAP_TYPE_ANY), wxDefaultPosition, [16,16], );
        } else{
            $$loc_self_ptr = Wx::Button->
                new($$loc_panel_ptr, $loc_ID, rim($loc_control_value),
wxDefaultPosition, wxDefaultSize, );        }
        if ($loc_enabled == 1){
# Set Enable according to parameter.
            $$loc_self_ptr->Enable(1);  
        } else{
            $$loc_self_ptr->Disable();  
        }
#       if ($loc_max_length ne "")
{$$loc_self_ptr->SetMaxLength($loc_max_length)};        #Set maximum length
of text control
        if ($loc_minsize_x ne "") {
# Set minimum physical size of field in pixels
                $$loc_self_ptr->SetMinSize(Wx::Size->new($loc_minsize_x,
$loc_minsize_y))
        };
        $$loc_self_ptr->SetSize($$loc_self_ptr->GetBestSize());

        if ($loc_tooltip ne "")
{$$loc_self_ptr->SetToolTipString($loc_tooltip)};       #Set tooltip
#       my $loc_numval = Wx::Perl::TextValidator->new(
$loc_validation_string );       # Set validation string
#       $$loc_self_ptr->SetValidator( $loc_numval );
# Set validation
                
        if (defined $loc_gbposition_ptr and $loc_gbposition_ptr ne '') {
# Add to GridBag Position and Span
            if (defined $loc_gbspan_ptr and $loc_gbspan_ptr ne '' ) {
# Add to GridBag Position
                $$loc_sizer_ptr->Add($$loc_self_ptr, $$loc_gbposition_ptr,
$$loc_gbspan_ptr); # Add to grid
            } else {
                $$loc_sizer_ptr->Add($$loc_self_ptr, $$loc_gbposition_ptr);
# Add to grid
            }
        } else {
            $$loc_sizer_ptr->Add($$loc_self_ptr, 0, 0, 0);
# Add to grid
        }

        if (defined $loc_button_event_ptr) {
# Set button press event
            if ($loc_button_event_ptr ne "") {
# Set button press event
                Wx::Event::EVT_BUTTON( $gl_self_ptr , $$loc_self_ptr,
$loc_button_event_ptr );
            }
        };
}
#
#sub on_click_richtext_font{
#       my ($i_frame, $event) = @_;
#        my $loc_position = $i_frame->{Ctl_Report_Text_Txt} ->
GetCaretPosition();          # Get current position
#        my $loc_range =
Wx::RichTextRange->new($loc_position,$loc_position);
#        if ($i_frame->{Ctl_Report_Text_Txt} -> HasSelection) {
# If there is a selection
#                $loc_range = $i_frame->{Ctl_Report_Text_Txt} ->
GetSelectionRange();       # Get current range
#        }
#        my $loc_style =
$i_frame->{Ctl_Report_Text_Txt}->GetRichTextAttrStyle($loc_position);
#        my $log_pages = wxRICHTEXT_FORMAT_FONT;
#        my $dlg_format = Wx::RichTextFormattingDialog -> newFull
($log_pages,$i_frame,"Format Paragraph",wxID_ANY, wxDefaultPosition,
wxDefaultSize,wxDEFAULT_DIALOG_STYLE); # , -1, (("Paragraph details"))
#        $dlg_format -> GetStyle ($i_frame->{Ctl_Report_Text_Txt},
$loc_range);
#        if ($dlg_format->ShowModal()==wxID_OK){
#
$dlg_format->ApplyStyle($i_frame->{Ctl_Report_Text_Txt},$loc_range,wxRICHTEX
T_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE|wxRICHTEXT_SETSTYLE_CHARAC
TERS_ONLY)
#        }
#        
#        return $i_frame;
#}
#

sub OnPrint {
  my( $this, $event ) = @_;

  my $printer = Wx::Printer->new;
  my $printout = i_Printing::Printout->new( $this->canvas, "Print" );
  $printer->Print( $this, $printout, 1 );

  $printout->Destroy;
}

sub add_to_tags { qw(misc) }
sub title { 'Printing' }

package i_Printing::PreviewFrame;

use strict;
use base 'Wx::PlPreviewFrame';

sub Initialize {
    #Wx::LogMessage( 'i_Printing::PreviewFrame::Initialize' );

    $_[0]->SUPER::Initialize;
}

sub CreateControlBar {
    #Wx::LogMessage( 'i_Printing::PreviewFrame::CreateControlBar' );

    $_[0]->SetPreviewControlBar
      ( i_Printing::ControlBar->new( $_[0]->GetPrintPreview, $_[0] ) );
    $_[0]->GetPreviewControlBar->CreateButtons;
}

package i_Printing::ControlBar;

use strict;
use base 'Wx::PlPreviewControlBar';

sub new {
    #Wx::LogMessage( 'i_Printing::ControlBar::new' );

    $_[0]->SUPER::new( $_[1], 0xffffffff, $_[2], [0, 0], [400, 40] );
}

sub CreateButtons {
    #Wx::LogMessage( 'i_Printing::ControlBar::CreateButtons' );

    shift->SUPER::CreateButtons;
}

package i_Printing::Printout;

use strict;
use base qw(Wx::Printout);

sub new {
  my $class = shift;
  my $canvas = shift;
  my $this = $class->SUPER::new( @_ );

  $this->{CANVAS} = $canvas;

  return $this;
}

sub GetPageInfo {
  my $this = shift;

  #Wx::LogMessage( "GetPageInfo" );

  return ( 1, 2, 1, 2 );
}

sub HasPage {
  my $this = shift;

  #Wx::LogMessage( "HasPage: %d", $_[0] );

  return $_[0] == 1 || $_[0] == 2;
}

sub OnBeginDocument {
  my $this = shift;

  #Wx::LogMessage( "OnBeginDocument: %d, %d", @_ );

  return $this->SUPER::OnBeginDocument( @_ );
}

sub OnEndDocument {
  my $this = shift;

  #Wx::LogMessage( "OnEndDocument" );

  return $this->SUPER::OnEndDocument();
}

sub OnBeginPrinting {
  my $this = shift;

  #Wx::LogMessage( "OnBeginPrinting" );

  return $this->SUPER::OnBeginPrinting();
}

sub OnEndPrinting {
  my $this = shift;

  #Wx::LogMessage( "OnEndPrinting" );

  return $this->SUPER::OnEndPrinting();
}

sub OnPrintPage {
        my( $this, $page ) = @_;
        my $dc = $this->GetDC();
      
        # we need to set the appropriate scale
        my( $x_size, $y_size ) = ( $i_Printing::Canvas::x_size,
                                   $i_Printing::Canvas::y_size );
      
        my( $xmargin, $ymargin ) = ( 50, 50 );
        # total size ( borders on top/bottom, left/right )
        my( $xsize, $ysize ) = ( $x_size + 2 * $xmargin, $y_size + 2 *
$ymargin );
      
        # dc size
        my( $xdc, $ydc ) = $dc->GetSizeWH();
      
        # calculate the scale
        my( $xscale, $yscale ) = ( $xdc / $xsize, $ydc / $ysize );
        my $scale = ( $xscale < $yscale ) ? $xscale : $yscale;
        # center the image
        my( $xoff, $yoff ) = ( ( $xdc - ( $scale * $x_size ) ) / 2.0,
                               ( $ydc - ( $scale * $y_size ) ) / 2.0 );
      
        # set the DC origin / scale
        $dc->SetUserScale( $scale, $scale );
        $dc->SetDeviceOrigin( $xoff, $yoff );
      
        if( $page == 1 ) { $this->{CANVAS}->OnDraw( $dc ); }
        if( $page == 2 ) { } # empty page
}

package i_Printing::Canvas;

use strict;
use base qw(Wx::ScrolledWindow);

use Wx qw(wxCURSOR_PENCIL wxWHITE);
use Wx::Event qw(EVT_MOTION EVT_LEFT_DOWN EVT_LEFT_UP);

use vars qw($x_size $y_size);

( $x_size, $y_size ) = ( 800, 800 );

sub new {
  my $class = shift;
  my $this = $class->SUPER::new( @_ );

  $this->SetScrollbars( 1, 1, $x_size, $y_size );
  $this->SetBackgroundColour( wxWHITE );
  $this->SetCursor( Wx::Cursor->new( wxCURSOR_PENCIL ) );

  return $this;
}

use Wx qw(:font);
use Wx qw(:colour :pen);

sub OnDraw {
        my $this = shift;
        my $dc = shift;
        my $cdc = Wx::ClientDC->new($gl_self_ptr);
        $dc = $cdc;
#  my $font = Wx::Font->new( 20, wxSCRIPT, wxSLANT, wxBOLD );

#  $dc->SetFont( $font );

#  $dc->DrawRotatedText( "Draw Here", 200, 200, 35 );
#
#  $dc->DrawEllipse( 20, 20, 50, 50 );
#  $dc->DrawEllipse( 20, $y_size - 50 - 20, 50, 50 );
#  $dc->DrawEllipse( $x_size - 50 - 20, 20, 50, 50 );
#  $dc->DrawEllipse( $x_size - 50 - 20, $y_size - 50 - 20, 50, 50 );
#
#  $dc->SetPen( Wx::Pen->new( wxRED, 5, 0 ) );
#  # wxGTK does not like DrawLines in this context
#  foreach my $i ( @{$this->{LINES}} ) {
#    my $prev;
#
#    foreach my $j ( @$i ) {
#      if( $j != ${$i}[0] ) {
#        $dc->DrawLine( @$prev, @$j );
##       $dc->DrawLines( $i );
#      }
#      $prev = $j;
#    }
#  }
}

package main;

unless(caller){
        local *Wx::App::OnInit = sub{1};
        my $app = Wx::App->new();
        Wx::InitAllImageHandlers();

        my $frame_1 = MyFrame->new();

        $app->SetTopWindow($frame_1);
        $frame_1->Show(1);
        $app->MainLoop();
}

Reply via email to