1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/gtk/print.h 3 // Author: Anthony Bretaudeau 4 // Purpose: GTK printing support 5 // Created: 2007-08-25 6 // Copyright: (c) Anthony Bretaudeau 7 // Licence: wxWindows Licence 8 ///////////////////////////////////////////////////////////////////////////// 9 10 #ifndef _WX_GTK_PRINT_H_ 11 #define _WX_GTK_PRINT_H_ 12 13 #include "wx/defs.h" 14 15 #if wxUSE_GTKPRINT 16 17 #include "wx/print.h" 18 #include "wx/printdlg.h" 19 #include "wx/prntbase.h" 20 #include "wx/dc.h" 21 22 typedef struct _GtkPrintOperation GtkPrintOperation; 23 typedef struct _GtkPrintContext GtkPrintContext; 24 typedef struct _GtkPrintSettings GtkPrintSettings; 25 typedef struct _GtkPageSetup GtkPageSetup; 26 27 typedef struct _cairo cairo_t; 28 29 //---------------------------------------------------------------------------- 30 // wxGtkPrintFactory 31 //---------------------------------------------------------------------------- 32 33 class wxGtkPrintFactory: public wxPrintFactory 34 { 35 public: 36 virtual wxPrinterBase *CreatePrinter( wxPrintDialogData *data ) wxOVERRIDE; 37 38 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview, 39 wxPrintout *printout = NULL, 40 wxPrintDialogData *data = NULL ) wxOVERRIDE; 41 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview, 42 wxPrintout *printout, 43 wxPrintData *data ) wxOVERRIDE; 44 45 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent, 46 wxPrintDialogData *data = NULL ) wxOVERRIDE; 47 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent, 48 wxPrintData *data ) wxOVERRIDE; 49 50 virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent, 51 wxPageSetupDialogData * data = NULL ) wxOVERRIDE; 52 53 virtual wxDCImpl* CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) wxOVERRIDE; 54 55 virtual bool HasPrintSetupDialog() wxOVERRIDE; 56 virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data ) wxOVERRIDE; 57 virtual bool HasOwnPrintToFile() wxOVERRIDE; 58 virtual bool HasPrinterLine() wxOVERRIDE; 59 virtual wxString CreatePrinterLine() wxOVERRIDE; 60 virtual bool HasStatusLine() wxOVERRIDE; 61 virtual wxString CreateStatusLine() wxOVERRIDE; 62 63 virtual wxPrintNativeDataBase *CreatePrintNativeData() wxOVERRIDE; 64 }; 65 66 //---------------------------------------------------------------------------- 67 // wxGtkPrintDialog 68 //---------------------------------------------------------------------------- 69 70 class WXDLLIMPEXP_CORE wxGtkPrintDialog: public wxPrintDialogBase 71 { 72 public: 73 wxGtkPrintDialog( wxWindow *parent, 74 wxPrintDialogData* data = NULL ); 75 wxGtkPrintDialog( wxWindow *parent, wxPrintData* data); 76 virtual ~wxGtkPrintDialog(); 77 GetPrintData()78 wxPrintData& GetPrintData() wxOVERRIDE 79 { return m_printDialogData.GetPrintData(); } GetPrintDialogData()80 wxPrintDialogData& GetPrintDialogData() wxOVERRIDE 81 { return m_printDialogData; } 82 83 wxDC *GetPrintDC() wxOVERRIDE; 84 85 virtual int ShowModal() wxOVERRIDE; 86 Validate()87 virtual bool Validate() wxOVERRIDE { return true; } TransferDataToWindow()88 virtual bool TransferDataToWindow() wxOVERRIDE { return true; } TransferDataFromWindow()89 virtual bool TransferDataFromWindow() wxOVERRIDE { return true; } 90 SetShowDialog(bool show)91 void SetShowDialog(bool show) { m_showDialog = show; } GetShowDialog()92 bool GetShowDialog() { return m_showDialog; } 93 94 protected: 95 // Implement some base class methods to do nothing to avoid asserts and 96 // GTK warnings, since this is not a real wxDialog. WXUNUSED(x)97 virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y), 98 int WXUNUSED(width), int WXUNUSED(height), 99 int WXUNUSED(sizeFlags) = wxSIZE_AUTO) wxOVERRIDE {} DoMoveWindow(int WXUNUSED (x),int WXUNUSED (y),int WXUNUSED (width),int WXUNUSED (height))100 virtual void DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), 101 int WXUNUSED(width), int WXUNUSED(height)) wxOVERRIDE {} 102 103 private: 104 wxPrintDialogData m_printDialogData; 105 wxWindow *m_parent; 106 bool m_showDialog; 107 108 wxDECLARE_DYNAMIC_CLASS(wxGtkPrintDialog); 109 }; 110 111 //---------------------------------------------------------------------------- 112 // wxGtkPageSetupDialog 113 //---------------------------------------------------------------------------- 114 115 class WXDLLIMPEXP_CORE wxGtkPageSetupDialog: public wxPageSetupDialogBase 116 { 117 public: 118 wxGtkPageSetupDialog( wxWindow *parent, 119 wxPageSetupDialogData* data = NULL ); 120 virtual ~wxGtkPageSetupDialog(); 121 GetPageSetupDialogData()122 virtual wxPageSetupDialogData& GetPageSetupDialogData() wxOVERRIDE { return m_pageDialogData; } 123 124 virtual int ShowModal() wxOVERRIDE; 125 Validate()126 virtual bool Validate() wxOVERRIDE { return true; } TransferDataToWindow()127 virtual bool TransferDataToWindow() wxOVERRIDE { return true; } TransferDataFromWindow()128 virtual bool TransferDataFromWindow() wxOVERRIDE { return true; } 129 130 protected: 131 // Implement some base class methods to do nothing to avoid asserts and 132 // GTK warnings, since this is not a real wxDialog. WXUNUSED(x)133 virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y), 134 int WXUNUSED(width), int WXUNUSED(height), 135 int WXUNUSED(sizeFlags) = wxSIZE_AUTO) wxOVERRIDE {} DoMoveWindow(int WXUNUSED (x),int WXUNUSED (y),int WXUNUSED (width),int WXUNUSED (height))136 virtual void DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), 137 int WXUNUSED(width), int WXUNUSED(height)) wxOVERRIDE {} 138 139 private: 140 wxPageSetupDialogData m_pageDialogData; 141 wxWindow *m_parent; 142 143 wxDECLARE_DYNAMIC_CLASS(wxGtkPageSetupDialog); 144 }; 145 146 //---------------------------------------------------------------------------- 147 // wxGtkPrinter 148 //---------------------------------------------------------------------------- 149 150 class WXDLLIMPEXP_CORE wxGtkPrinter : public wxPrinterBase 151 { 152 public: 153 wxGtkPrinter(wxPrintDialogData *data = NULL); 154 virtual ~wxGtkPrinter(); 155 156 virtual bool Print(wxWindow *parent, 157 wxPrintout *printout, 158 bool prompt = true) wxOVERRIDE; 159 virtual wxDC* PrintDialog(wxWindow *parent) wxOVERRIDE; 160 virtual bool Setup(wxWindow *parent) wxOVERRIDE; 161 GetPrintContext()162 GtkPrintContext *GetPrintContext() { return m_gpc; } SetPrintContext(GtkPrintContext * context)163 void SetPrintContext(GtkPrintContext *context) {m_gpc = context;} 164 void BeginPrint(wxPrintout *printout, GtkPrintOperation *operation, GtkPrintContext *context); 165 void DrawPage(wxPrintout *printout, GtkPrintOperation *operation, GtkPrintContext *context, int page_nr); 166 167 private: 168 GtkPrintContext *m_gpc; 169 wxDC *m_dc; 170 171 wxDECLARE_DYNAMIC_CLASS(wxGtkPrinter); 172 wxDECLARE_NO_COPY_CLASS(wxGtkPrinter); 173 }; 174 175 //---------------------------------------------------------------------------- 176 // wxGtkPrintNativeData 177 //---------------------------------------------------------------------------- 178 179 class WXDLLIMPEXP_CORE wxGtkPrintNativeData : public wxPrintNativeDataBase 180 { 181 public: 182 wxGtkPrintNativeData(); 183 virtual ~wxGtkPrintNativeData(); 184 185 virtual bool TransferTo( wxPrintData &data ) wxOVERRIDE; 186 virtual bool TransferFrom( const wxPrintData &data ) wxOVERRIDE; 187 Ok()188 virtual bool Ok() const wxOVERRIDE { return IsOk(); } IsOk()189 virtual bool IsOk() const wxOVERRIDE { return true; } 190 GetPrintConfig()191 GtkPrintSettings* GetPrintConfig() { return m_config; } 192 void SetPrintConfig( GtkPrintSettings * config ); 193 GetPrintJob()194 GtkPrintOperation* GetPrintJob() { return m_job; } 195 void SetPrintJob(GtkPrintOperation *job); 196 GetPrintContext()197 GtkPrintContext *GetPrintContext() { return m_context; } SetPrintContext(GtkPrintContext * context)198 void SetPrintContext(GtkPrintContext *context) {m_context = context; } 199 200 201 GtkPageSetup* GetPageSetupFromSettings(GtkPrintSettings* settings); 202 void SetPageSetupToSettings(GtkPrintSettings* settings, GtkPageSetup* page_setup); 203 204 private: 205 // NB: m_config is created and owned by us, but the other objects are not 206 // and their accessors don't change their ref count. 207 GtkPrintSettings *m_config; 208 GtkPrintOperation *m_job; 209 GtkPrintContext *m_context; 210 211 wxDECLARE_DYNAMIC_CLASS(wxGtkPrintNativeData); 212 }; 213 214 //----------------------------------------------------------------------------- 215 // wxGtkPrinterDC 216 //----------------------------------------------------------------------------- 217 218 class WXDLLIMPEXP_CORE wxGtkPrinterDCImpl : public wxDCImpl 219 { 220 public: 221 wxGtkPrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ); 222 virtual ~wxGtkPrinterDCImpl(); 223 Ok()224 bool Ok() const { return IsOk(); } 225 bool IsOk() const wxOVERRIDE; 226 227 virtual void* GetCairoContext() const wxOVERRIDE; 228 virtual void* GetHandle() const wxOVERRIDE; 229 CanDrawBitmap()230 bool CanDrawBitmap() const wxOVERRIDE { return true; } 231 void Clear() wxOVERRIDE; 232 void SetFont( const wxFont& font ) wxOVERRIDE; 233 void SetPen( const wxPen& pen ) wxOVERRIDE; 234 void SetBrush( const wxBrush& brush ) wxOVERRIDE; 235 void SetLogicalFunction( wxRasterOperationMode function ) wxOVERRIDE; 236 void SetBackground( const wxBrush& brush ) wxOVERRIDE; 237 void DestroyClippingRegion() wxOVERRIDE; 238 bool StartDoc(const wxString& message) wxOVERRIDE; 239 void EndDoc() wxOVERRIDE; 240 void StartPage() wxOVERRIDE; 241 void EndPage() wxOVERRIDE; 242 wxCoord GetCharHeight() const wxOVERRIDE; 243 wxCoord GetCharWidth() const wxOVERRIDE; CanGetTextExtent()244 bool CanGetTextExtent() const wxOVERRIDE { return true; } 245 wxSize GetPPI() const wxOVERRIDE; GetDepth()246 virtual int GetDepth() const wxOVERRIDE { return 24; } 247 void SetBackgroundMode(int mode) wxOVERRIDE; 248 #if wxUSE_PALETTE SetPalette(const wxPalette & WXUNUSED (palette))249 void SetPalette(const wxPalette& WXUNUSED(palette)) wxOVERRIDE { } 250 #endif 251 void SetResolution(int ppi); 252 253 // overridden for wxPrinterDC Impl 254 virtual int GetResolution() const wxOVERRIDE; 255 virtual wxRect GetPaperRect() const wxOVERRIDE; 256 257 protected: 258 bool DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, 259 wxFloodFillStyle style=wxFLOOD_SURFACE ) wxOVERRIDE; 260 void DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter) wxOVERRIDE; 261 void DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, wxDirection nDirection = wxEAST) wxOVERRIDE; 262 bool DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const wxOVERRIDE; 263 void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) wxOVERRIDE; 264 void DoCrossHair(wxCoord x, wxCoord y) wxOVERRIDE; 265 void DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) wxOVERRIDE; 266 void DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) wxOVERRIDE; 267 void DoDrawPoint(wxCoord x, wxCoord y) wxOVERRIDE; 268 void DoDrawLines(int n, const wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0) wxOVERRIDE; 269 void DoDrawPolygon(int n, const wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, wxPolygonFillMode fillStyle=wxODDEVEN_RULE) wxOVERRIDE; 270 void DoDrawPolyPolygon(int n, const int count[], const wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, wxPolygonFillMode fillStyle=wxODDEVEN_RULE) wxOVERRIDE; 271 void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) wxOVERRIDE; 272 void DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius = 20.0) wxOVERRIDE; 273 void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) wxOVERRIDE; 274 #if wxUSE_SPLINES 275 void DoDrawSpline(const wxPointList *points) wxOVERRIDE; 276 #endif 277 bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, 278 wxDC *source, wxCoord xsrc, wxCoord ysrc, 279 wxRasterOperationMode rop = wxCOPY, bool useMask = false, 280 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) wxOVERRIDE; 281 void DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) wxOVERRIDE; 282 void DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask = false ) wxOVERRIDE; 283 void DoDrawText(const wxString& text, wxCoord x, wxCoord y ) wxOVERRIDE; 284 void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) wxOVERRIDE; 285 void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) wxOVERRIDE; DoSetDeviceClippingRegion(const wxRegion & WXUNUSED (clip))286 void DoSetDeviceClippingRegion( const wxRegion &WXUNUSED(clip) ) wxOVERRIDE 287 { 288 wxFAIL_MSG( "not implemented" ); 289 } 290 void DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, 291 wxCoord *descent = NULL, 292 wxCoord *externalLeading = NULL, 293 const wxFont *theFont = NULL ) const wxOVERRIDE; 294 bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const wxOVERRIDE; 295 void DoGetSize(int* width, int* height) const wxOVERRIDE; 296 void DoGetSizeMM(int *width, int *height) const wxOVERRIDE; 297 GetPrintData()298 wxPrintData& GetPrintData() { return m_printData; } 299 void SetPrintData(const wxPrintData& data); 300 301 private: 302 wxPrintData m_printData; 303 PangoContext *m_context; 304 PangoLayout *m_layout; 305 PangoFontDescription *m_fontdesc; 306 cairo_t *m_cairo; 307 308 unsigned char m_currentRed; 309 unsigned char m_currentGreen; 310 unsigned char m_currentBlue; 311 unsigned char m_currentAlpha; 312 313 GtkPrintContext *m_gpc; 314 int m_resolution; 315 double m_PS2DEV; 316 double m_DEV2PS; 317 318 wxDECLARE_DYNAMIC_CLASS(wxGtkPrinterDCImpl); 319 wxDECLARE_NO_COPY_CLASS(wxGtkPrinterDCImpl); 320 }; 321 322 // ---------------------------------------------------------------------------- 323 // wxGtkPrintPreview: programmer creates an object of this class to preview a 324 // wxPrintout. 325 // ---------------------------------------------------------------------------- 326 327 class WXDLLIMPEXP_CORE wxGtkPrintPreview : public wxPrintPreviewBase 328 { 329 public: 330 wxGtkPrintPreview(wxPrintout *printout, 331 wxPrintout *printoutForPrinting = NULL, 332 wxPrintDialogData *data = NULL); 333 wxGtkPrintPreview(wxPrintout *printout, 334 wxPrintout *printoutForPrinting, 335 wxPrintData *data); 336 337 virtual ~wxGtkPrintPreview(); 338 339 virtual bool Print(bool interactive) wxOVERRIDE; 340 virtual void DetermineScaling() wxOVERRIDE; 341 342 private: 343 void Init(wxPrintout *printout, 344 wxPrintout *printoutForPrinting, 345 wxPrintData *data); 346 347 // resolution to use in DPI 348 int m_resolution; 349 350 wxDECLARE_CLASS(wxGtkPrintPreview); 351 }; 352 353 #endif // wxUSE_GTKPRINT 354 355 #endif // _WX_GTK_PRINT_H_ 356