]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/_printfw.i
Squash exception on exit bug
[wxWidgets.git] / wxPython / src / _printfw.i
index f91b876a0bc37f0b7398775b93b9d035588f8432..1faf7eebc0a9d0672ba4403fef337cb53eec65f4 100644 (file)
 %{
 #include "wx/wxPython/printfw.h"
 
-    static const wxChar* wxPrintoutTitleStr = wxT("Printout");
-    DECLARE_DEF_STRING(PrintoutTitleStr);
-    static const wxChar* wxPreviewCanvasNameStr = wxT("previewcanvas");
-    DECLARE_DEF_STRING(PreviewCanvasNameStr);
-
 %}
 
+MAKE_CONST_WXSTRING2(PrintoutTitleStr, wxT("Printout"));
+MAKE_CONST_WXSTRING2(PreviewCanvasNameStr, wxT("previewcanvas"));
+
 
 //---------------------------------------------------------------------------
 
@@ -34,14 +32,38 @@ enum wxPrintMode
     wxPRINT_MODE_NONE =    0,
     wxPRINT_MODE_PREVIEW = 1,   // Preview in external application
     wxPRINT_MODE_FILE =    2,   // Print to file
-    wxPRINT_MODE_PRINTER = 3    // Send to printer
+    wxPRINT_MODE_PRINTER = 3,   // Send to printer
+    wxPRINT_MODE_STREAM = 4     // Send postscript data into a stream 
 };
 
+enum wxPrintBin
+{
+    wxPRINTBIN_DEFAULT,
+
+    wxPRINTBIN_ONLYONE,
+    wxPRINTBIN_LOWER,
+    wxPRINTBIN_MIDDLE,
+    wxPRINTBIN_MANUAL,
+    wxPRINTBIN_ENVELOPE,
+    wxPRINTBIN_ENVMANUAL,
+    wxPRINTBIN_AUTO,
+    wxPRINTBIN_TRACTOR,
+    wxPRINTBIN_SMALLFMT,
+    wxPRINTBIN_LARGEFMT,
+    wxPRINTBIN_LARGECAPACITY,
+    wxPRINTBIN_CASSETTE,
+    wxPRINTBIN_FORMSOURCE,
+
+    wxPRINTBIN_USER,
+};
 
 
 class wxPrintData : public wxObject {
 public:
+    %nokwargs wxPrintData;
     wxPrintData();
+    wxPrintData(const wxPrintData& data);  // for making copies
+    
     ~wxPrintData();
 
     int GetNoCopies();
@@ -56,8 +78,10 @@ public:
     wxPaperSize GetPaperId();
     const wxSize& GetPaperSize();
 
-    wxPrintQuality GetQuality();
-
+    int GetQuality();
+    wxPrintBin GetBin();
+    wxPrintMode GetPrintMode() const;
+    
     void SetNoCopies(int v);
     void SetCollate(bool flag);
     void SetOrientation(int orient);
@@ -67,24 +91,58 @@ public:
     void SetDuplex(wxDuplexMode duplex);
     void SetPaperId(wxPaperSize sizeId);
     void SetPaperSize(const wxSize& sz);
-    void SetQuality(wxPrintQuality quality);
+    void SetQuality(int quality);
+    void SetBin(wxPrintBin bin);
+    void SetPrintMode(wxPrintMode printMode);
+    wxString GetFilename() const;
+    void SetFilename( const wxString &filename );
+
+    %pythoncode { def __nonzero__(self): return self.Ok() }
+
+    //char* GetPrivData() const;
+    //int GetPrivDataLen() const;
+    //void SetPrivData( char *privData, int len );
+
+    %extend {
+        PyObject* GetPrivData() {
+            PyObject* data;
+            wxPyBlock_t blocked = wxPyBeginBlockThreads();
+            data = PyString_FromStringAndSize(self->GetPrivData(),
+                                              self->GetPrivDataLen());
+            wxPyEndBlockThreads(blocked);
+            return data;
+        }
+
+        void SetPrivData(PyObject* data) {
+            if (! PyString_Check(data)) {
+                wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
+                                                  "Expected string object"));
+                return /* NULL */ ;
+            }
+
+            wxPyBlock_t blocked = wxPyBeginBlockThreads();
+            self->SetPrivData(PyString_AS_STRING(data), PyString_GET_SIZE(data));
+            wxPyEndBlockThreads(blocked);
+        }
+    }
+    
 
+    // NOTE: These are now inside of #if WXWIN_COMPATIBILITY_2_4, so be
+    //       prepared to remove them...
+    
     // PostScript-specific data
     const wxString& GetPrinterCommand();
     const wxString& GetPrinterOptions();
     const wxString& GetPreviewCommand();
-    const wxString& GetFilename();
     const wxString& GetFontMetricPath();
     double GetPrinterScaleX();
     double GetPrinterScaleY();
     long GetPrinterTranslateX();
     long GetPrinterTranslateY();
-    wxPrintMode GetPrintMode();
-
     void SetPrinterCommand(const wxString& command);
     void SetPrinterOptions(const wxString& options);
     void SetPreviewCommand(const wxString& command);
-    void SetFilename(const wxString& filename);
     void SetFontMetricPath(const wxString& path);
     void SetPrinterScaleX(double x);
     void SetPrinterScaleY(double y);
@@ -92,16 +150,17 @@ public:
     void SetPrinterTranslateX(long x);
     void SetPrinterTranslateY(long y);
     void SetPrinterTranslation(long x, long y);
-    void SetPrintMode(wxPrintMode printMode);
 
-    %pythoncode { def __nonzero__(self): return self.Ok() }
 };
 
 //---------------------------------------------------------------------------
 
 class wxPageSetupDialogData : public wxObject {
 public:
+    %nokwargs wxPageSetupDialogData;
     wxPageSetupDialogData();
+    wxPageSetupDialogData(const wxPageSetupDialogData& data);  // for making copies
+    wxPageSetupDialogData(const wxPrintData& data); 
     ~wxPageSetupDialogData();
 
     void EnableHelp(bool flag);
@@ -109,6 +168,7 @@ public:
     void EnableOrientation(bool flag);
     void EnablePaper(bool flag);
     void EnablePrinter(bool flag);
+    
     bool GetDefaultMinMargins();
     bool GetEnableMargins();
     bool GetEnableOrientation();
@@ -124,11 +184,6 @@ public:
     wxSize GetPaperSize();
 
     wxPrintData& GetPrintData();
-//     %addmethods {
-//         %new wxPrintData* GetPrintData() {
-//             return new wxPrintData(self->GetPrintData());  // force a copy
-//         }
-//     }
 
     bool Ok();
 
@@ -140,20 +195,34 @@ public:
     void SetMinMarginBottomRight(const wxPoint& pt);
     void SetPaperId(wxPaperSize id);
     void SetPaperSize(const wxSize& size);
+    
     void SetPrintData(const wxPrintData& printData);
 
+    // Use paper size defined in this object to set the wxPrintData
+    // paper id
+    void CalculateIdFromPaperSize();
+
+    // Use paper id in wxPrintData to set this object's paper size
+    void CalculatePaperSizeFromId();
+
     %pythoncode { def __nonzero__(self): return self.Ok() }
 };
 
 
 
-class wxPageSetupDialog : public wxDialog {
-public:
-    %addtofunc wxPageSetupDialog         "self._setOORInfo(self)"
+// NOTE: Contrary to it's name, this class doesn't derive from wxDialog.  It
+// is a facade in front of a platform-specific (native dialog) provided by the
+// wxPrintFactory.
+
+MustHaveApp(wxPageSetupDialog);
 
+class wxPageSetupDialog : public wxObject
+{
+public:
     wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
 
     wxPageSetupDialogData& GetPageSetupData();
+    wxPageSetupDialogData& GetPageSetupDialogData();
     int ShowModal();
 };
 
@@ -162,7 +231,10 @@ public:
 
 class wxPrintDialogData : public wxObject {
 public:
+    %nokwargs wxPrintDialogData;
     wxPrintDialogData();
+    wxPrintDialogData(const wxPrintData& printData);
+    wxPrintDialogData(const wxPrintDialogData& printData);  // for making copies
     ~wxPrintDialogData();
 
     int GetFromPage() const;
@@ -174,7 +246,10 @@ public:
     bool GetSelection() const;
     bool GetCollate() const;
     bool GetPrintToFile() const;
+
+    // WXWIN_COMPATIBILITY_2_4
     bool GetSetupDialog() const;
+    void SetSetupDialog(bool flag);
 
     void SetFromPage(int v);
     void SetToPage(int v);
@@ -185,7 +260,6 @@ public:
     void SetSelection(bool flag);
     void SetCollate(bool flag);
     void SetPrintToFile(bool flag);
-    void SetSetupDialog(bool flag);
 
     void EnablePrintToFile(bool flag);
     void EnableSelection(bool flag);
@@ -202,28 +276,34 @@ public:
 
     
     wxPrintData& GetPrintData();
-//     %addmethods {
-//         %new wxPrintData* GetPrintData() {
-//             return new wxPrintData(self->GetPrintData());  // force a copy
-//         }
-//     }
     void SetPrintData(const wxPrintData& printData);
 
     %pythoncode { def __nonzero__(self): return self.Ok() }
 };
 
 
-class wxPrintDialog : public wxDialog {
-public:
-    %addtofunc wxPrintDialog         "self._setOORInfo(self)"
 
+MustHaveApp(wxPrintDialog);
+
+
+// NOTE: Contrary to it's name, this class doesn't derive from wxDialog.  It
+// is a facade in front of a platform-specific (native dialog) provided by the
+// wxPrintFactory.
+
+class wxPrintDialog : public wxObject {
+public:
     wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
 
-    wxPrintDialogData& GetPrintDialogData();
+    // TODO?: wxPrintDialog(wxWindow *parent, wxPrintData* data);
+    
+    virtual int ShowModal();
+
+    virtual wxPrintDialogData& GetPrintDialogData();
+    virtual wxPrintData& GetPrintData();
 
     %newobject GetPrintDC;
-    wxDC* GetPrintDC();
-    int ShowModal();
+    virtual wxDC *GetPrintDC();
+
 };
 
 
@@ -239,34 +319,41 @@ enum wxPrinterError
 };
 
 
+MustHaveApp(wxPrinter);
+
 class wxPrinter : public wxObject {
 public:
     wxPrinter(wxPrintDialogData* data = NULL);
     ~wxPrinter();
 
-    void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
-    wxPrintDialogData& GetPrintDialogData();
-    bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=True);
-    wxDC* PrintDialog(wxWindow *parent);
-    void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
-    bool Setup(wxWindow *parent);
-    bool GetAbort();
+    virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPyPrintout *printout);
+    virtual void ReportError(wxWindow *parent, wxPyPrintout *printout, const wxString& message);
+
+    virtual bool Setup(wxWindow *parent);
+    virtual bool Print(wxWindow *parent, wxPyPrintout *printout, bool prompt = true);
+    virtual wxDC* PrintDialog(wxWindow *parent);
+    
+    virtual wxPrintDialogData& GetPrintDialogData() const;
 
+    bool GetAbort();
     static wxPrinterError GetLastError();
 };
 
 
 //---------------------------------------------------------------------------
-// Custom wxPrintout class that knows how to call python
+// Custom wxPrintout class that knows how to call python, See implementation in
+// include/sx/wxPython/printfw.h
+
 %{
 
+IMPLEMENT_ABSTRACT_CLASS(wxPyPrintout, wxPrintout);
 
 // Since this one would be tough and ugly to do with the Macros...
 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
-    bool hadErr = False;
+    bool hadErr = false;
     bool found;
 
-    wxPyBeginBlockThreads();
+    wxPyBlock_t blocked = wxPyBeginBlockThreads();
     if ((found = wxPyCBH_findCallback(m_myInst, "GetPageInfo"))) {
         PyObject* result = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
         if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
@@ -274,22 +361,22 @@ void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *p
 
             val = PyTuple_GetItem(result, 0);
             if (PyInt_Check(val))    *minPage = PyInt_AsLong(val);
-            else hadErr = True;
+            else hadErr = true;
 
             val = PyTuple_GetItem(result, 1);
             if (PyInt_Check(val))    *maxPage = PyInt_AsLong(val);
-            else hadErr = True;
+            else hadErr = true;
 
             val = PyTuple_GetItem(result, 2);
             if (PyInt_Check(val))    *pageFrom = PyInt_AsLong(val);
-            else hadErr = True;
+            else hadErr = true;
 
             val = PyTuple_GetItem(result, 3);
             if (PyInt_Check(val))    *pageTo = PyInt_AsLong(val);
-            else hadErr = True;
+            else hadErr = true;
         }
         else
-            hadErr = True;
+            hadErr = true;
 
         if (hadErr) {
             PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
@@ -297,7 +384,7 @@ void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *p
         }
         Py_DECREF(result);
     }
-    wxPyEndBlockThreads();
+    wxPyEndBlockThreads(blocked);
     if (! found)
         wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
 }
@@ -319,10 +406,13 @@ IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
 %}
 
 
+MustHaveApp(wxPyPrintout);
+
 // Now define the custom class for SWIGging
-%name(Printout) class wxPyPrintout  : public wxObject {
+%rename(Printout) wxPyPrintout;
+class wxPyPrintout  : public wxObject {
 public:
-    %addtofunc wxPyPrintout   "self._setCallbackInfo(self, Printout)"
+    %pythonAppend wxPyPrintout   "self._setCallbackInfo(self, Printout)"
 
     wxPyPrintout(const wxString& title = wxPyPrintoutTitleStr);
     //~wxPyPrintout();      wxPrintPreview object takes ownership...
@@ -373,10 +463,12 @@ public:
 
 
 
+MustHaveApp(wxPreviewCanvas);
+
 class wxPreviewCanvas: public wxScrolledWindow
 {
 public:
-    %addtofunc wxPreviewCanvas   "self._self._setOORInfo(self)"
+    %pythonAppend wxPreviewCanvas   "self._setOORInfo(self)"
 
     wxPreviewCanvas(wxPrintPreview *preview,
                     wxWindow *parent,
@@ -387,9 +479,11 @@ public:
 };
 
 
+MustHaveApp(wxPreviewFrame);
+
 class wxPreviewFrame : public wxFrame {
 public:
-    %addtofunc wxPreviewFrame   "self._self._setOORInfo(self)"
+    %pythonAppend wxPreviewFrame   "self._setOORInfo(self)"
 
     wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
                    const wxPoint& pos = wxDefaultPosition,
@@ -426,10 +520,12 @@ enum {
     wxID_PREVIEW_GOTO
 };
 
+MustHaveApp(wxPreviewControlBar);
+
 class wxPreviewControlBar: public wxPanel
 {
 public:
-    %addtofunc wxPreviewControlBar   "self._self._setOORInfo(self)"
+    %pythonAppend wxPreviewControlBar   "self._setOORInfo(self)"
 
     wxPreviewControlBar(wxPrintPreview *preview,
                         long buttons,
@@ -454,11 +550,17 @@ public:
 
 //---------------------------------------------------------------------------
 
+MustHaveApp(wxPrintPreview);
+
 class wxPrintPreview : public wxObject {
 public:
+    %nokwargs wxPrintPreview;
     wxPrintPreview(wxPyPrintout* printout,
                    wxPyPrintout* printoutForPrinting,
-                   wxPrintData* data=NULL);
+                   wxPrintDialogData *data=NULL);
+    wxPrintPreview(wxPyPrintout* printout,
+                  wxPyPrintout* printoutForPrinting,
+                  wxPrintData* data);
 
     virtual bool SetCurrentPage(int pageNum);
     int GetCurrentPage();
@@ -510,30 +612,30 @@ public:
 
 %{
 
-#define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME)                                    \
-    bool CBNAME(wxPreviewCanvas* a, wxDC& b);                                   \
+#define DEC_PYCALLBACK_BOOL_PREWINDC(CBNAME)                                            \
+    bool CBNAME(wxPreviewCanvas* a, wxDC& b);                                           \
     bool base_##CBNAME(wxPreviewCanvas* a, wxDC& b)
 
 
-#define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME)                     \
-    bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) {                           \
-        bool rval=False;                                                        \
-        bool found;                                                             \
-        wxPyBeginBlockThreads();                                                \
-        if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) {                \
-            PyObject* win = wxPyMake_wxObject(a);                               \
-            PyObject* dc  = wxPyMake_wxObject(&b);                              \
-            rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc));\
-            Py_DECREF(win);                                                     \
-            Py_DECREF(dc);                                                      \
-        }                                                                       \
-        wxPyEndBlockThreads();                                                  \
-        if (! found)                                                            \
-            rval = PCLASS::CBNAME(a, b);                                        \
-        return rval;                                                            \
-    }                                                                           \
-    bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) {                    \
-        return PCLASS::CBNAME(a, b);                                            \
+#define IMP_PYCALLBACK_BOOL_PREWINDC(CLASS, PCLASS, CBNAME)                             \
+    bool CLASS::CBNAME(wxPreviewCanvas* a, wxDC& b) {                                   \
+        bool rval=false;                                                                \
+        bool found;                                                                     \
+        wxPyBlock_t blocked = wxPyBeginBlockThreads();                                         \
+        if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) {                        \
+            PyObject* win = wxPyMake_wxObject(a,false);                                 \
+            PyObject* dc  = wxPyMake_wxObject(&b,false);                                \
+            rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc));      \
+            Py_DECREF(win);                                                             \
+            Py_DECREF(dc);                                                              \
+        }                                                                               \
+        wxPyEndBlockThreads(blocked);                                                   \
+        if (! found)                                                                    \
+            rval = PCLASS::CBNAME(a, b);                                                \
+        return rval;                                                                    \
+    }                                                                                   \
+    bool CLASS::base_##CBNAME(wxPreviewCanvas* a, wxDC& b) {                            \
+        return PCLASS::CBNAME(a, b);                                                    \
     }
 
 
@@ -543,6 +645,11 @@ class wxPyPrintPreview : public wxPrintPreview
 {
     DECLARE_CLASS(wxPyPrintPreview)
 public:
+    wxPyPrintPreview(wxPyPrintout* printout,
+                     wxPyPrintout* printoutForPrinting,
+                     wxPrintDialogData* data=NULL)
+        : wxPrintPreview(printout, printoutForPrinting, data)
+    {}
     wxPyPrintPreview(wxPyPrintout* printout,
                      wxPyPrintout* printoutForPrinting,
                      wxPrintData* data=NULL)
@@ -579,14 +686,19 @@ IMP_PYCALLBACK_VOID_        (wxPyPrintPreview, wxPrintPreview, DetermineScaling)
 %}
 
 
+MustHaveApp(wxPyPrintPreview);
+
 class wxPyPrintPreview : public wxPrintPreview
 {
 public:
-    %addtofunc wxPyPrintPreview   "self._setCallbackInfo(self, PyPrintPreview)"
-
+    %pythonAppend wxPyPrintPreview   "self._setCallbackInfo(self, PyPrintPreview)"
+    %nokwargs wxPyPrintPreview;
+    wxPyPrintPreview(wxPyPrintout* printout,
+                     wxPyPrintout* printoutForPrinting,
+                     wxPrintDialogData* data=NULL);
     wxPyPrintPreview(wxPyPrintout* printout,
                      wxPyPrintout* printoutForPrinting,
-                     wxPrintData* data=NULL);
+                     wxPrintData* data);
 
     void _setCallbackInfo(PyObject* self, PyObject* _class);
     
@@ -634,10 +746,12 @@ IMP_PYCALLBACK_VOID_(wxPyPreviewFrame, wxPreviewFrame, CreateControlBar);
 %}
 
 
+MustHaveApp(wxPyPreviewFrame);
+
 class wxPyPreviewFrame : public wxPreviewFrame
 {
 public:
-    %addtofunc wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)"
+    %pythonAppend wxPyPreviewFrame "self._setCallbackInfo(self, PyPreviewFrame); self._setOORInfo(self)"
 
     wxPyPreviewFrame(wxPrintPreview* preview, wxFrame* parent,
                      const wxString& title,
@@ -688,10 +802,12 @@ IMP_PYCALLBACK_VOID_INT(wxPyPreviewControlBar, wxPreviewControlBar, SetZoomContr
 %}
 
 
+MustHaveApp(wxPyPreviewControlBar);
+
 class wxPyPreviewControlBar : public wxPreviewControlBar
 {
 public:
-    %addtofunc wxPyPreviewControlBar   "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)"
+    %pythonAppend wxPyPreviewControlBar   "self._setCallbackInfo(self, PyPreviewControlBar); self._setOORInfo(self)"
 
     wxPyPreviewControlBar(wxPrintPreview *preview,
                           long buttons,
@@ -709,7 +825,6 @@ public:
     void base_SetZoomControl(int zoom);
 };
 
-
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 %init %{