1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     Printing Framework classes
 
   9 // Copyright:   (c) 1998 by Total Control Software
 
  10 // Licence:     wxWindows license
 
  11 /////////////////////////////////////////////////////////////////////////////
 
  18 #include <wx/printdlg.h>
 
  23 //----------------------------------------------------------------------
 
  26 %include my_typemaps.i
 
  28 // Import some definitions of other classes, etc.
 
  37 %pragma(python) code = "import wx"
 
  40 //----------------------------------------------------------------------
 
  53     const wxString& GetPrinterName();
 
  55     wxDuplexMode GetDuplex();
 
  56     wxPaperSize GetPaperId();
 
  57     const wxSize& GetPaperSize();
 
  59     wxPrintQuality GetQuality();
 
  61     void SetNoCopies(int v);
 
  62     void SetCollate(bool flag);
 
  63     void SetOrientation(int orient);
 
  65     void SetPrinterName(const wxString& name);
 
  66     void SetColour(bool colour);
 
  67     void SetDuplex(wxDuplexMode duplex);
 
  68     void SetPaperId(wxPaperSize sizeId);
 
  69     void SetPaperSize(const wxSize& sz);
 
  70     void SetQuality(wxPrintQuality quality);
 
  72 //    // PostScript-specific data
 
  73 //      const wxString& GetPrinterCommand();
 
  74 //      const wxString& GetPrinterOptions();
 
  75 //      const wxString& GetPreviewCommand();
 
  76 //      const wxString& GetFilename();
 
  77 //      const wxString& GetFontMetricPath();
 
  78 //      double GetPrinterScaleX();
 
  79 //      double GetPrinterScaleY();
 
  80 //      long GetPrinterTranslateX();
 
  81 //      long GetPrinterTranslateY();
 
  82 //      wxPrintMode GetPrintMode();
 
  84 //      void SetPrinterCommand(const wxString& command);
 
  85 //      void SetPrinterOptions(const wxString& options);
 
  86 //      void SetPreviewCommand(const wxString& command);
 
  87 //      void SetFilename(const wxString& filename);
 
  88 //      void SetFontMetricPath(const wxString& path);
 
  89 //      void SetPrinterScaleX(double x);
 
  90 //      void SetPrinterScaleY(double y);
 
  91 //      void SetPrinterScaling(double x, double y);
 
  92 //      void SetPrinterTranslateX(long x);
 
  93 //      void SetPrinterTranslateY(long y);
 
  94 //      void SetPrinterTranslation(long x, long y);
 
  95 //      void SetPrintMode(wxPrintMode printMode);
 
  99 //----------------------------------------------------------------------
 
 101 class wxPageSetupDialogData {
 
 103     wxPageSetupDialogData();
 
 104     ~wxPageSetupDialogData();
 
 106     void EnableHelp(bool flag);
 
 107     void EnableMargins(bool flag);
 
 108     void EnableOrientation(bool flag);
 
 109     void EnablePaper(bool flag);
 
 110     void EnablePrinter(bool flag);
 
 111     bool GetDefaultMinMargins();
 
 112     bool GetEnableMargins();
 
 113     bool GetEnableOrientation();
 
 114     bool GetEnablePaper();
 
 115     bool GetEnablePrinter();
 
 116     bool GetEnableHelp();
 
 117     bool GetDefaultInfo();
 
 118     wxPoint GetMarginTopLeft();
 
 119     wxPoint GetMarginBottomRight();
 
 120     wxPoint GetMinMarginTopLeft();
 
 121     wxPoint GetMinMarginBottomRight();
 
 122     wxPaperSize GetPaperId();
 
 123     wxSize GetPaperSize();
 
 125         %new wxPrintData* GetPrintData() {
 
 126             return new wxPrintData(self->GetPrintData());  // force a copy
 
 129     void SetDefaultInfo(bool flag);
 
 130     void SetDefaultMinMargins(bool flag);
 
 131     void SetMarginTopLeft(const wxPoint& pt);
 
 132     void SetMarginBottomRight(const wxPoint& pt);
 
 133     void SetMinMarginTopLeft(const wxPoint& pt);
 
 134     void SetMinMarginBottomRight(const wxPoint& pt);
 
 135     void SetPaperId(wxPaperSize id);
 
 136     void SetPaperSize(const wxSize& size);
 
 137     void SetPrintData(const wxPrintData& printData);
 
 141 class wxPageSetupDialog : public wxDialog {
 
 143     wxPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = NULL);
 
 145     %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
 
 147     wxPageSetupDialogData& GetPageSetupData();
 
 151 //----------------------------------------------------------------------
 
 154 class wxPrintDialogData {
 
 157     ~wxPrintDialogData();
 
 159     void EnableHelp(bool flag);
 
 160     void EnablePageNumbers(bool flag);
 
 161     void EnablePrintToFile(bool flag);
 
 162     void EnableSelection(bool flag);
 
 170         %new wxPrintData* GetPrintData() {
 
 171             return new wxPrintData(self->GetPrintData());  // force a copy
 
 174     bool GetPrintToFile();
 
 176     void SetCollate(bool flag);
 
 177     void SetFromPage(int page);
 
 178     void SetMaxPage(int page);
 
 179     void SetMinPage(int page);
 
 180     void SetNoCopies(int n);
 
 181     void SetPrintData(const wxPrintData& printData);
 
 182     void SetPrintToFile(bool flag);
 
 183     void SetSetupDialog(bool flag);
 
 184     void SetToPage(int page);
 
 188 class wxPrintDialog : public wxDialog {
 
 190     wxPrintDialog(wxWindow* parent, wxPrintDialogData* data = NULL);
 
 192     %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
 
 194     wxPrintDialogData& GetPrintDialogData();
 
 195     %new wxDC* GetPrintDC();
 
 199 //----------------------------------------------------------------------
 
 200 //----------------------------------------------------------------------
 
 201 // Custom wxPrintout class that knows how to call python
 
 205 // Since this one would be tough and ugly to do with the Macros...
 
 206 void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
 
 209     bool doSave = wxPyRestoreThread();
 
 210     if (m_myInst.findCallback("GetPageInfo")) {
 
 211         PyObject* result = m_myInst.callCallbackObj(Py_BuildValue("()"));
 
 212         if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) {
 
 215             val = PyTuple_GetItem(result, 0);
 
 216             if (PyInt_Check(val))    *minPage = PyInt_AsLong(val);
 
 219             val = PyTuple_GetItem(result, 1);
 
 220             if (PyInt_Check(val))    *maxPage = PyInt_AsLong(val);
 
 223             val = PyTuple_GetItem(result, 2);
 
 224             if (PyInt_Check(val))    *pageFrom = PyInt_AsLong(val);
 
 227             val = PyTuple_GetItem(result, 3);
 
 228             if (PyInt_Check(val))    *pageTo = PyInt_AsLong(val);
 
 235             PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers.");
 
 241         wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
 
 243     wxPySaveThread(doSave);
 
 246 void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
 
 247     wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo);
 
 251 IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument);
 
 252 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument);
 
 253 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting);
 
 254 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting);
 
 255 IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting);
 
 256 IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage);
 
 257 IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage);
 
 263 // Now define the custom class for SWIGging
 
 264 %name(wxPrintout) class wxPyPrintout {
 
 266     wxPyPrintout(const char* title = "Printout");
 
 268     void _setSelf(PyObject* self, PyObject* _class);
 
 269     %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPrintout)"
 
 272         void Destroy() { delete self; }
 
 276     void GetPageSizeMM(int *OUTPUT, int *OUTPUT);
 
 277     void GetPageSizePixels(int *OUTPUT, int *OUTPUT);
 
 278     void GetPPIPrinter(int *OUTPUT, int *OUTPUT);
 
 279     void GetPPIScreen(int *OUTPUT, int *OUTPUT);
 
 282     bool base_OnBeginDocument(int startPage, int endPage);
 
 283     void base_OnEndDocument();
 
 284     void base_OnBeginPrinting();
 
 285     void base_OnEndPrinting();
 
 286     void base_OnPreparePrinting();
 
 287     void base_GetPageInfo(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
 
 288     bool base_HasPage(int page);
 
 291 //----------------------------------------------------------------------
 
 295     wxPrinter(wxPrintDialogData* data = NULL);
 
 299     void CreateAbortWindow(wxWindow* parent, wxPyPrintout* printout);
 
 300     wxPrintDialogData& GetPrintDialogData();
 
 301     bool Print(wxWindow *parent, wxPyPrintout *printout, int prompt=TRUE);
 
 302     wxDC* PrintDialog(wxWindow *parent);
 
 303     void ReportError(wxWindow *parent, wxPyPrintout *printout, char* message);
 
 304     bool Setup(wxWindow *parent);
 
 307 //----------------------------------------------------------------------
 
 309 class wxPrintPreview {
 
 311     wxPrintPreview(wxPyPrintout* printout, wxPyPrintout* printoutForPrinting, wxPrintData* data=NULL);
 
 312 //    ~wxPrintPreview();   **** ????
 
 314     wxWindow* GetCanvas();
 
 315     int GetCurrentPage();
 
 316     wxFrame * GetFrame();
 
 319     wxPrintDialogData& GetPrintDialogData();
 
 320     wxPyPrintout * GetPrintout();
 
 321     wxPyPrintout * GetPrintoutForPrinting();
 
 324     bool Print(bool prompt);
 
 325     void SetCanvas(wxWindow* window);
 
 326     void SetCurrentPage(int pageNum);
 
 327     void SetFrame(wxFrame *frame);
 
 328     void SetPrintout(wxPyPrintout *printout);
 
 329     void SetZoom(int percent);
 
 332 //----------------------------------------------------------------------
 
 334 class wxPreviewFrame : public wxFrame {
 
 336     wxPreviewFrame(wxPrintPreview* preview, wxFrame* parent, const wxString& title,
 
 337                    const wxPoint& pos = wxDefaultPosition,
 
 338                    const wxSize&  size = wxDefaultSize,
 
 339                    long style = wxDEFAULT_FRAME_STYLE,
 
 340                    char* name = "frame");
 
 342     %pragma(python) addtomethod = "__init__:#wx._StdFrameCallbacks(self)"
 
 346     // ****  need to use derived class so these can be properly overridden:
 
 347     //void CreateControlBar()
 
 348     //void CreateCanvas()
 
 352 //----------------------------------------------------------------------
 
 353 //----------------------------------------------------------------------
 
 354 //----------------------------------------------------------------------