Hi,

I thought I'd chip in with a populated template for Steve to test. However, basic testing here brought up a problem. wxRichTextPrinting has no wxRTTI information (there's no IMPLEMENT_CLASS macro) so the wxPerl code ( wxPli_object_2_sv ) throws warnings.

The attached patch wraps wxRichTextPrinting but is not applied to SVN as the wxRichTextPrinting constructor code is none standard. It does what wxPli_object_2_sv would do if wxRichTextPrinting had ClassInfo. I'm fairly sure this is OK because wxRichTextPrinting inherits directly from wxObject and, as there is no need to wrap wxRichTextPrinting to handle Perl virtual methods, I don't think there is anywhere else in the wxPerl code that would attempt to reference the missing class info. My question to Mattia is, this seems wrong and a bit of a hack. Is there a better way to handle it?

I suppose the correct fix is to patch wxRichTextPrinting to implement wxRTTI, but this would not help any existing 2.8.x installations.

Some simple usage has been added to wxDemo in SVN. I've tested the patch building and with the basic wxDemo usage on msw/linux/mac with wxWidgets 2.8.10, and all seems to work OK.

Apologies to Steve if you have already been tackling this. It wasn't my original intention to just wrap the classes, but solving the above problem meant I ended up with the classes more or less wrapped anyway.

Regards

Mark


On 10/04/2010 09:40, Mattia Barbon wrote:
Steve Cookson wrote:

Hi,

I'm not sure whether I should be sending this to the group or directly
to Mattia

Better to the group (it will be in the archives, and there are other
people beside me that have some experience in wrapping wxWidgets classes).

but I'm trying to understand how to print a wxRichTextCtrl from
wxPerl. I understand that wxRichTextPrinting and wxRichTextPrintout
are not implemented yet in wxPerl.

Correct.

So I need to do something to access the original C++ code (maybe wrap
or re-write). Re-writing seems to be an easier route as I don't
understand the Wx XS framework that Mattia uses. However, it would be
a bit anti-social. It would be better to use the current wxPerl
framework.

I wouldn't call it antisocial, but wrapping the C++ code is definitely
more maintainable in the long run.

As far as I can see the wxPerl framework is dll driven and provides an
XS-based interface to the dlls? Is that right?

Correct.

 > There seems to be some
automation/facilitation of the process, but it's not clear to me how
it works. I've also never used XS before.

Are there some instructions about how to do this available?

I'm sure I answered this on the mailing list, but can't find the mails;
I just committed some documentation that should at least get you
started; see lib/Wx/NewClass.pod. I think that wxRichTextPrinting should
be reasonably easy to wrap.

Regards,
Mattia

Index: Changes
===================================================================
--- Changes     (revision 2885)
+++ Changes     (working copy)
@@ -1,5 +1,7 @@
 Revision history for Perl extension Wx.
 
+    - Wrapped wxRichTextPrinting
+
 0.9701_01  Tue Mar 30 22:46:33 CEST 2010
        - 64 Bit build fixes.
        - Wrapped wxMenuBar::MacSetCommonMenuBar, MacInstallMenuBar
Index: ext/richtext/lib/Wx/RichText.pm
===================================================================
--- ext/richtext/lib/Wx/RichText.pm     (revision 2885)
+++ ext/richtext/lib/Wx/RichText.pm     (working copy)
@@ -5,7 +5,7 @@
 ## Modified by:
 ## Created:     05/11/2006
 ## RCS-ID:      $Id$
-## Copyright:   (c) 2006-2007 Mattia Barbon
+## Copyright:   (c) 2006-2007, 2010 Mattia Barbon
 ## Licence:     This program is free software; you can redistribute it and/or
 ##              modify it under the same terms as Perl itself
 #############################################################################
@@ -13,6 +13,7 @@
 package Wx::RichText;
 
 use strict;
+use Wx::Print;
 
 our $VERSION = '0.01';
 
@@ -49,6 +50,8 @@
 package Wx::RichTextBox;     @ISA = qw(Wx::RichTextCompositeObject);
 package Wx::RichTextParagraphLayoutBox; @ISA = qw(Wx::RichTextBox);
 package Wx::RichTextBuffer;  @ISA = qw(Wx::RichTextParagraphLayoutBox);
+package Wx::RichTextPrinting;  @ISA = qw(Wx::Object);
+package Wx::RichTextHeaderFooterData;  @ISA = qw(Wx::Object);
 package Wx::SymbolPickerDialog; @ISA = qw(Wx::Dialog);
 package Wx::RichTextStyleOrganiserDialog; @ISA = qw(Wx::Dialog);
 
Index: ext/richtext/RichText.xs
===================================================================
--- ext/richtext/RichText.xs    (revision 2885)
+++ ext/richtext/RichText.xs    (working copy)
@@ -80,6 +80,8 @@
 
 INCLUDE_COMMAND: $^X -MExtUtils::XSpp::Cmd -e xspp -- -t typemap.xsp -t 
../../typemap.xsp XS/RichTextStyleOrganiserDialog.xsp
 
+INCLUDE_COMMAND: $^X -MExtUtils::XSpp::Cmd -e xspp -- -t typemap.xsp -t 
../../typemap.xsp XS/RichTextPrinting.xsp
+
 MODULE=Wx__RichText PACKAGE=Wx::RichText
 
 void
Index: ext/richtext/t/03_threads.t
===================================================================
--- ext/richtext/t/03_threads.t (revision 2885)
+++ ext/richtext/t/03_threads.t (working copy)
@@ -22,12 +22,18 @@
 my $rtsd2 = Wx::RichTextParagraphStyleDefinition->new;
 my $rtss = Wx::RichTextStyleSheet->new;
 my $rtss2 = Wx::RichTextStyleSheet->new;
+my $rtp = Wx::RichTextPrinting->new;
+my $rtp2 = Wx::RichTextPrinting->new;
+my $rthfd = Wx::RichTextHeaderFooterData->new;
+my $rthfd2 = Wx::RichTextHeaderFooterData->new;
 
 undef $rtr2;
 undef $tae2;
 undef $rta2;
 undef $rtsd2;
 undef $rtss2;
+undef $rtp2;
+undef $rthfd2;
 
 my $t = threads->create
   ( sub {
Index: ext/richtext/typemap
===================================================================
--- ext/richtext/typemap        (revision 2885)
+++ ext/richtext/typemap        (working copy)
@@ -5,7 +5,7 @@
 ## Modified by:
 ## Created:     05/11/2006
 ## RCS-ID:      $Id$
-## Copyright:   (c) 2006-2007, 2009 Mattia Barbon
+## Copyright:   (c) 2006-2007, 2009-2010 Mattia Barbon
 ## Licence:     This program is free software; you can redistribute it and/or
 ##              modify it under the same terms as Perl itself
 #############################################################################
@@ -37,3 +37,11 @@
 wxRichTextHTMLHandler * O_WXOBJECT
 wxSymbolPickerDialog *  O_WXOBJECT
 wxRichTextStyleOrganiserDialog * O_WXOBJECT
+
+wxPrintData *           O_WXOBJECT
+wxPageSetupDialogData * O_WXOBJECT
+wxRichTextPrinting *    O_WXOBJECT_THR
+wxRichTextHeaderFooterData * O_WXOBJECT_THR
+wxRichTextOddEvenPage   T_ENUM
+wxRichTextPageLocation  T_ENUM
+
Index: ext/richtext/typemap.xsp
===================================================================
--- ext/richtext/typemap.xsp    (revision 2885)
+++ ext/richtext/typemap.xsp    (working copy)
@@ -5,7 +5,7 @@
 ## Modified by:
 ## Created:     05/11/2006
 ## RCS-ID:      $Id$
-## Copyright:   (c) 2006-2009 Mattia Barbon
+## Copyright:   (c) 2006-2010 Mattia Barbon
 ## Licence:     This program is free software; you can redistribute it and/or
 ##              modify it under the same terms as Perl itself
 #############################################################################
@@ -14,6 +14,8 @@
 %typemap{wxFontWeight}{simple};
 %typemap{wxBitmapType}{simple};
 %typemap{wxPliRichTextStyleType}{simple};
+%typemap{wxRichTextOddEvenPage}{simple};
+%typemap{wxRichTextPageLocation}{simple};
 %typemap{const wxRichTextAttr&}{reference};
 %typemap{wxRichTextAttr&}{reference};
 %typemap{const wxRichTextRange&}{reference};
@@ -64,3 +66,12 @@
 %typemap{wxRichTextFormattingDialog*}{simple};
 %typemap{wxRichTextFileHandler*}{simple};
 %typemap{wxPlRichTextFileHandler*}{simple};
+%typemap{wxPrintData*}{simple};
+%typemap{const wxPrintData&}{reference};
+%typemap{const wxRichTextBuffer&}{reference};
+%typemap{wxRichTextPrinting*}{simple};
+%typemap{const wxPageSetupDialogData&}{reference};
+%typemap{wxPageSetupDialogData*}{simple};
+%typemap{wxRichTextHeaderFooterData*}{simple};
+%typemap{const wxRichTextHeaderFooterData&}{reference};
+
Index: ext/richtext/XS/RichTextPrinting.xsp
===================================================================
--- ext/richtext/XS/RichTextPrinting.xsp        (revision 0)
+++ ext/richtext/XS/RichTextPrinting.xsp        (revision 0)
@@ -0,0 +1,151 @@
+#############################################################################
+## Name:        ext/richtext/XS/RichTextPrinting.xsp
+## Purpose:     XS++ for Wx::RichTextPrinting
+## Author:      Mark Dootson
+## Modified by:
+## Created:     10/04/2010
+## RCS-ID:      $Id:$
+## Copyright:   (c) 2010 Mark Dootson
+## Licence:     This program is free software; you can redistribute it and/or
+##              modify it under the same terms as Perl itself
+#############################################################################
+
+#if WXPERL_W_VERSION_GE( 2, 8, 0 )
+
+#include <wx/richtext/richtextprint.h>
+
+%{
+
+MODULE=Wx PACKAGE=Wx::RichTextPrinting
+
+void
+wxRichTextPrinting::new(  wxString name = wxT("Printing"), wxWindow 
*parentWindow = NULL )
+  PPCODE:
+    wxRichTextPrinting* rtp = new wxRichTextPrinting( name, parentWindow );
+    SV* retval = sv_newmortal();
+    sv_setref_pv( retval, CHAR_P CLASS, const_cast<wxObject*>( (wxObject*)rtp 
) );
+    wxPli_thread_sv_register( aTHX_ CLASS, rtp, retval );
+    XPUSHs(retval);
+
+%}
+
+%module{Wx};
+
+%name{Wx::RichTextPrinting} class wxRichTextPrinting : public wxObject
+{
+
+    ~wxRichTextPrinting()
+        %code%{  wxPli_thread_sv_unregister( aTHX_ "Wx::RichTextPrinting", 
THIS, ST(0) );
+                 delete THIS; %};
+
+%{
+static void
+wxRichTextPrinting::CLONE()
+  CODE:
+    wxPli_thread_sv_clone( aTHX_ CLASS, (wxPliCloneSV)wxPli_detach_object );
+%}
+
+    bool PreviewFile(const wxString& richTextFile);
+    bool PreviewBuffer(const wxRichTextBuffer& buffer);
+    bool PrintFile(const wxString& richTextFile);
+    bool PrintBuffer(const wxRichTextBuffer& buffer);
+
+    void PageSetup();
+
+    void SetHeaderFooterData(const wxRichTextHeaderFooterData& data);
+    const wxRichTextHeaderFooterData& GetHeaderFooterData() const;
+
+    void SetHeaderText(const wxString& text, wxRichTextOddEvenPage page = 
wxRICHTEXT_PAGE_ALL, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE);
+    wxString GetHeaderText(wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_EVEN, 
wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE) const;
+    void SetFooterText(const wxString& text, wxRichTextOddEvenPage page = 
wxRICHTEXT_PAGE_ALL, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE);
+    wxString GetFooterText(wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_EVEN, 
wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE) const;
+
+    void SetShowOnFirstPage(bool show);
+
+    void SetHeaderFooterFont(const wxFont& font);
+    void SetHeaderFooterTextColour(const wxColour& font);
+
+    wxPrintData *GetPrintData();
+    void SetPrintData(const wxPrintData& printData);
+    
+    wxPageSetupDialogData *GetPageSetupData() const;
+    void SetPageSetupData(const wxPageSetupDialogData& pageSetupData);
+
+    // void SetRichTextBufferPreview(wxRichTextBuffer* buf);
+    // wxRichTextBuffer* GetRichTextBufferPreview() const;
+
+    // void SetRichTextBufferPrinting(wxRichTextBuffer* buf);
+    // wxRichTextBuffer* GetRichTextBufferPrinting() const;
+
+    void SetParentWindow(wxWindow* parent);
+    wxWindow* GetParentWindow() const;
+
+    void SetTitle(const wxString& title);
+    const wxString& GetTitle() const;
+
+    void SetPreviewRect(const wxRect& rect);
+    const wxRect& GetPreviewRect() const;
+    
+};
+
+
+%name{Wx::RichTextHeaderFooterData} class wxRichTextHeaderFooterData : public 
wxObject
+{
+
+    %name{newDefault} wxRichTextHeaderFooterData();
+    %name{newCopy} wxRichTextHeaderFooterData(const 
wxRichTextHeaderFooterData& data);
+
+    ~wxRichTextPrinting()
+        %code%{  wxPli_thread_sv_unregister( aTHX_ 
"Wx::RichTextHeaderFooterData", THIS, ST(0) );
+                 delete THIS; %};
+
+%{
+static void
+wxRichTextPrinting::CLONE()
+  CODE:
+    wxPli_thread_sv_clone( aTHX_ CLASS, (wxPliCloneSV)wxPli_detach_object );
+%}
+
+    // void Init();
+    // void Copy(const wxRichTextHeaderFooterData& data);
+
+    void SetHeaderText(const wxString& text, wxRichTextOddEvenPage page = 
wxRICHTEXT_PAGE_ALL, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE);
+    wxString GetHeaderText(wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_EVEN, 
wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE) const;
+
+    void SetFooterText(const wxString& text, wxRichTextOddEvenPage page = 
wxRICHTEXT_PAGE_ALL, wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE);
+    wxString GetFooterText(wxRichTextOddEvenPage page = wxRICHTEXT_PAGE_EVEN, 
wxRichTextPageLocation location = wxRICHTEXT_PAGE_CENTRE) const;
+
+    void SetText(const wxString& text, int headerFooter, wxRichTextOddEvenPage 
page, wxRichTextPageLocation location);
+    wxString GetText(int headerFooter, wxRichTextOddEvenPage page, 
wxRichTextPageLocation location) const;
+
+    void SetMargins(int headerMargin, int footerMargin);
+    int GetHeaderMargin();
+    int GetFooterMargin();
+
+    void SetShowOnFirstPage(bool showOnFirstPage);
+    bool GetShowOnFirstPage() const;
+    void Clear();
+    
+    void SetFont(const wxFont& font);
+    const wxFont& GetFont() const;
+
+    void SetTextColour(const wxColour& col);
+    const wxColour& GetTextColour() const;
+    
+};
+
+## DECLARE_OVERLOAD( wrth, Wx::RichTextHeaderFooterData )
+
+%{
+void
+wxRichTextHeaderFooterData::new( ... )
+  PPCODE:
+    BEGIN_OVERLOAD()
+        MATCH_VOIDM_REDISP( newDefault )
+        MATCH_REDISP( wxPliOvl_wrth, newCopy )
+    END_OVERLOAD( Wx::RichTextHeaderFooterData::new )
+
+%}
+
+#endif
+
Index: MANIFEST
===================================================================
--- MANIFEST    (revision 2885)
+++ MANIFEST    (working copy)
@@ -489,6 +489,7 @@
 ext/richtext/XS/RichTextCtrl.xsp
 ext/richtext/XS/RichTextFileHandler.xsp
 ext/richtext/XS/RichTextFormattingDialog.xsp
+ext/richtext/XS/RichTextPrinting.xsp
 ext/richtext/XS/RichTextStyle.xsp
 ext/richtext/XS/RichTextStyleCtrl.xsp
 ext/richtext/XS/RichTextStyleOrganiserDialog.xsp

Reply via email to