Hi Guys,

I've just wrapped wxRichTextPrintout and I'm using it to handle a print preview more precisely. I'm using Kubuntu.

The printpreview works fine, but when I press the "close" button in preview, the PreviewFrame does not close and I get:

"*** glibc detected *** /usr/bin/perl: double free or corruption (!pr +ev): 0x000000000261cb80 ***"

The book says that "close" and "destroy" should both be handled automatically.  Code follows.

You'll need to have the most recent version of wxPerl to show this.

I would be grateful for your thoughts.

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); our $gl_installation_path = ''; our $gl_i_frame_ptr; sub new { my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_ +; my %RTC_Buttons = ( preview=>1, ); $style = wxDEFAULT_FRAME_STYLE unless defined $style; $self = $self->SUPER::new( undef, wxID_ANY, "Rich Text Control", w +xDefaultPosition, wxDefaultSize, $style, "" ); $self->SetTitle("Rich Text Control"); $self->{sizer} = Wx::BoxSizer->new( wxVERTICAL ); my $i_RTC_Panel=RichText_Obj->new($self, "first panel", \%RTC_Butt +ons,[800, 300]); $self->{sizer}->Add( $i_RTC_Panel, 1, wxGROW|wxALL, 5 ); $self->SetSizerAndFit( $self->{sizer} ); $self->Layout(); return $self; } package RichText_Obj; use Wx qw[:everything]; sub new{ my ($class, $parent, $name, $buttons_ptr, $size) = @_; $size = wxDefaultSize unless defined $size; my $i_RTC_panel = Wx::Panel->new( $parent, wxID_ANY, wxDefaultPosi +tion, wxDefaultSize, wxTAB_TRAVERSAL, "" ); $i_RTC_panel->{Ctl_Post_Exam_Report_Szr_1} = Wx::BoxSizer->new(wxV +ERTICAL); # Top level in RTC Object; $i_RTC_panel->{Ctl_Post_Exam_Report_Szr_2} = Wx::BoxSizer->new(wxH +ORIZONTAL); # Button bar for RTC Object; $i_RTC_panel->{name} = $name; # General Parameters my @loc_parameters_arr; $#loc_parameters_arr=0; # Remove el +ements from array. @loc_parameters_arr = ("", "", 1, "", -1, -1, "", "", \$i_RTC_panel->{Ctl_Post_Exam_Report_Szr_2}, \$i_RTC_panel, ""); $loc_parameters_arr [12]= ''; $loc_parameters_arr [13]= ''; # Preview Button if ($$buttons_ptr{preview}){ $loc_parameters_arr [0]= \$i_RTC_panel->{Ctl_Report_Preview_Te +xt_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_RTC_panel->{Ctl_Report_Text_Txt} = Wx::RichTextCtrl->new( $i_RT +C_panel, -1, '', [-1, -1], $size ); $i_RTC_panel->{Ctl_Report_Text_Txt} -> SetBackgroundColour(wxWHITE +); $i_RTC_panel->{Ctl_Report_Text_Txt} -> SetForegroundColour(wxBLACK +); $i_RTC_panel->{Ctl_Post_Exam_Report_Szr_1}->Add($i_RTC_panel->{Ctl +_Post_Exam_Report_Szr_2}, 0, 0, 0); $i_RTC_panel->{Ctl_Post_Exam_Report_Szr_1}->Add($i_RTC_panel->{Ctl +_Report_Text_Txt}, 0, 0, 0); my $XML_handler = Wx::RichTextXMLHandler->new; my $HTML_handler = Wx::RichTextHTMLHandler->new; my $RTC_Buffer = $i_RTC_panel->{Ctl_Report_Text_Txt}->GetBuffer(); $RTC_Buffer ->AddHandler($XML_handler); $RTC_Buffer ->AddHandler($HTML_handler); $i_RTC_panel->{printing}= Wx::RichTextPrinting->new('Wx::Demo +Printing', $i_RTC_panel); $i_RTC_panel->{printout}= Wx::RichTextPrintout->new('Wx::Demo +Printing'); $i_RTC_panel->{printout}->GetRichTextBuffer(); $i_RTC_panel->{printout}->GetDC; $i_RTC_panel->SetSizerAndFit( $i_RTC_panel->{Ctl_Post_Exam_Report_ +Szr_1} ); $i_RTC_panel->Layout(); return $i_RTC_panel; } 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; # Creat +e hourglass within current scope. Hourglass is deleted on exit. my $loc_self_ptr=shift; # pointer t +o control (Pass by reference) my $loc_ID=shift; # ID u +sed to over-ride wxID_ANY my $loc_enabled=shift; # Enab +led or disabled my $loc_max_length=shift; # Not +used, set to null my $loc_minsize_x=shift; # Hold +s minimum size of control (x-axis) my $loc_minsize_y=shift; # Hold +s minimum size of control (y-axis) my $loc_validation_string=shift; # Not +used, set to null my $loc_tooltip=shift; # Hold +s tooltip already translated. my $loc_sizer_ptr=shift; # pointer to s +izer (Pass by reference) my $loc_panel_ptr=shift; # pointer to p +anel (Pass by reference) my $loc_control_value=shift; # Labe +l for button or bitmap my $loc_button_event_ptr=shift; # E +vent (pointer.) my $loc_gbposition_ptr=shift; # Gri +dbag position details (pointer.) my $loc_gbspan_ptr=shift; # Gri +dbag span details (pointer.) my $bitmap_path = $gl_installation_path.$loc_control_value; if( $loc_ID eq ""){ if ($gl_installation_path ne ""){ $$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, wxID_ANY, "Preview", wxDefaultPos +ition, wxDefaultSize, ); } } else{ $$loc_self_ptr = Wx::Button-> new($$loc_panel_ptr, $loc_ID, __trim($loc_control_value), wxDe +faultPosition, wxDefaultSize, ); } if ($loc_enabled == 1){ + # Set Enable according to parameter. $$loc_self_ptr->Enable(1); } else{ $$loc_self_ptr->Disable(); } if ($loc_minsize_x ne "") { # Set minim +um 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_too +ltip)}; #Set tooltip 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, $$l +oc_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 "") { # Se +t button press event Wx::Event::EVT_BUTTON( $$loc_panel_ptr , $$loc_self_ptr, $loc_ +button_event_ptr ); } }; } sub on_click_richtext_preview{ my($self) = @_; # Set up header and footer. my $pv = $self->{printing}; $pv->SetHeaderText('Wx::Demo Richtext Printing', wxRICHTEXT_PAGE_ +ALL, wxRICHTEXT_PAGE_LEFT); $pv->SetFooterText('Page @PAGENUM@ of @PAGESCNT@', wxRICHTEXT_PAG +E_ALL, wxRICHTEXT_PAGE_RIGHT); $pv->SetShowOnFirstPage(0); # we can only set header / footer margins using wxRichTextHeaderFo +oterData my $hfdata = $pv->GetHeaderFooterData; $hfdata->SetMargins(100,100); $pv->SetHeaderFooterData($hfdata); # Create Printout Object my $po = $self->{printout}; $po->SetRichTextBuffer($self->{Ctl_Report_Text_Txt}->GetBuffer()); # Create Preview object my $preview = Wx::PrintPreview->new($po,$po,$pv->GetPrintData); $preview ->SetZoom(200); my $frame = Wx::PreviewFrame->new( $preview, $self, "Printing Demo + Preview", wxDefaultPosition,[1360,768],wxNO_BORDER); $frame->Initialize(); my $state = $frame->Show(1); # Destroy $frame; #$pv->PreviewBuffer($self->{Ctl_Report_Text_Txt}->GetBuffer()); } 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(); }

In reply to wxPreviewFrame error on closing by Steve_BZ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.