1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/gtk/gnome/gprint.h
3 // Author:      Robert Roebling
4 // Purpose:     GNOME printing support
5 // Created:     09/20/04
6 // RCS-ID:      $Id: gprint.h 46088 2007-05-17 10:51:34Z RR $
7 // Copyright:   Robert Roebling
8 // Licence:     wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef _WX_GTK_GPRINT_H_
12 #define _WX_GTK_GPRINT_H_
13 
14 #include "wx/defs.h"
15 
16 #if wxUSE_LIBGNOMEPRINT
17 
18 #include "wx/print.h"
19 #include "wx/printdlg.h"
20 #include "wx/dc.h"
21 
22 typedef struct _GnomePrintJob GnomePrintJob;
23 typedef struct _GnomePrintContext GnomePrintContext;
24 typedef struct _GnomePrintConfig GnomePrintConfig;
25 
26 //----------------------------------------------------------------------------
27 // wxGnomePrintNativeData
28 //----------------------------------------------------------------------------
29 
30 class wxGnomePrintNativeData: public wxPrintNativeDataBase
31 {
32 public:
33     wxGnomePrintNativeData();
34     virtual ~wxGnomePrintNativeData();
35 
36     virtual bool TransferTo( wxPrintData &data );
37     virtual bool TransferFrom( const wxPrintData &data );
38 
Ok()39     virtual bool Ok() const { return IsOk(); }
IsOk()40     virtual bool IsOk() const { return true; }
41 
GetPrintConfig()42     GnomePrintConfig* GetPrintConfig() { return m_config; }
SetPrintJob(GnomePrintJob * job)43     void SetPrintJob( GnomePrintJob *job ) { m_job = job; }
GetPrintJob()44     GnomePrintJob* GetPrintJob() { return m_job; }
45 
46 
47 private:
48     GnomePrintConfig  *m_config;
49     GnomePrintJob     *m_job;
50 
51     DECLARE_DYNAMIC_CLASS(wxGnomePrintNativeData)
52 };
53 
54 //----------------------------------------------------------------------------
55 // wxGnomePrintFactory
56 //----------------------------------------------------------------------------
57 
58 class wxGnomePrintFactory: public wxPrintFactory
59 {
60 public:
61     virtual wxPrinterBase *CreatePrinter( wxPrintDialogData *data );
62 
63     virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
64                                                     wxPrintout *printout = NULL,
65                                                     wxPrintDialogData *data = NULL );
66     virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
67                                                     wxPrintout *printout,
68                                                     wxPrintData *data );
69 
70     virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
71                                                   wxPrintDialogData *data = NULL );
72     virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
73                                                   wxPrintData *data );
74 
75     virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
76                                                           wxPageSetupDialogData * data = NULL );
77 
78     virtual wxDC* CreatePrinterDC( const wxPrintData& data );
79 
80     virtual bool HasPrintSetupDialog();
81     virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data );
82     virtual bool HasOwnPrintToFile();
83     virtual bool HasPrinterLine();
84     virtual wxString CreatePrinterLine();
85     virtual bool HasStatusLine();
86     virtual wxString CreateStatusLine();
87 
88     virtual wxPrintNativeDataBase *CreatePrintNativeData();
89 };
90 
91 //----------------------------------------------------------------------------
92 // wxGnomePrintDialog
93 //----------------------------------------------------------------------------
94 
95 class wxGnomePrintDialog: public wxPrintDialogBase
96 {
97 public:
98     wxGnomePrintDialog( wxWindow *parent,
99                          wxPrintDialogData* data = NULL );
100     wxGnomePrintDialog( wxWindow *parent, wxPrintData* data);
101     virtual ~wxGnomePrintDialog();
102 
GetPrintData()103     wxPrintData& GetPrintData()
104         { return m_printDialogData.GetPrintData(); }
GetPrintDialogData()105     wxPrintDialogData& GetPrintDialogData()
106         { return m_printDialogData; }
107 
108     wxDC *GetPrintDC();
109 
110     virtual int ShowModal();
111 
112     virtual bool Validate();
113     virtual bool TransferDataToWindow();
114     virtual bool TransferDataFromWindow();
115 
116 protected:
117     // Implement some base class methods to do nothing to avoid asserts and
118     // GTK warnings, since this is not a real wxDialog.
WXUNUSED(x)119     virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y),
120                            int WXUNUSED(width), int WXUNUSED(height),
121                            int WXUNUSED(sizeFlags) = wxSIZE_AUTO) {}
DoMoveWindow(int WXUNUSED (x),int WXUNUSED (y),int WXUNUSED (width),int WXUNUSED (height))122     virtual void DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y),
123                               int WXUNUSED(width), int WXUNUSED(height)) {}
124 
125 private:
126     void Init();
127     wxPrintDialogData   m_printDialogData;
128 
129     DECLARE_DYNAMIC_CLASS(wxGnomePrintDialog)
130 };
131 
132 //----------------------------------------------------------------------------
133 // wxGnomePageSetupDialog
134 //----------------------------------------------------------------------------
135 
136 class wxGnomePageSetupDialog: public wxPageSetupDialogBase
137 {
138 public:
139     wxGnomePageSetupDialog( wxWindow *parent,
140                             wxPageSetupDialogData* data = NULL );
141     virtual ~wxGnomePageSetupDialog();
142 
143     virtual wxPageSetupDialogData& GetPageSetupDialogData();
144 
145     virtual int ShowModal();
146 
147     virtual bool Validate();
148     virtual bool TransferDataToWindow();
149     virtual bool TransferDataFromWindow();
150 
151 protected:
152     // Implement some base class methods to do nothing to avoid asserts and
153     // GTK warnings, since this is not a real wxDialog.
WXUNUSED(x)154     virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y),
155                            int WXUNUSED(width), int WXUNUSED(height),
156                            int WXUNUSED(sizeFlags) = wxSIZE_AUTO) {}
DoMoveWindow(int WXUNUSED (x),int WXUNUSED (y),int WXUNUSED (width),int WXUNUSED (height))157     virtual void DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y),
158                               int WXUNUSED(width), int WXUNUSED(height)) {}
159 
160 private:
161     wxPageSetupDialogData   m_pageDialogData;
162 
163     DECLARE_DYNAMIC_CLASS(wxGnomePageSetupDialog)
164 };
165 
166 //----------------------------------------------------------------------------
167 // wxGnomePrinter
168 //----------------------------------------------------------------------------
169 
170 class wxGnomePrinter: public wxPrinterBase
171 {
172 public:
173     wxGnomePrinter(wxPrintDialogData *data = NULL);
174     virtual ~wxGnomePrinter();
175 
176     virtual bool Print(wxWindow *parent,
177                        wxPrintout *printout,
178                        bool prompt = true);
179     virtual wxDC* PrintDialog(wxWindow *parent);
180     virtual bool Setup(wxWindow *parent);
181 
182 private:
183     bool               m_native_preview;
184 
185 private:
186     DECLARE_DYNAMIC_CLASS(wxGnomePrinter)
187     DECLARE_NO_COPY_CLASS(wxGnomePrinter)
188 };
189 
190 //-----------------------------------------------------------------------------
191 // wxGnomePrintDC
192 //-----------------------------------------------------------------------------
193 
194 class wxGnomePrintDC: public wxDC
195 {
196 public:
197     wxGnomePrintDC( const wxPrintData& data );
198     virtual ~wxGnomePrintDC();
199 
Ok()200     bool Ok() const { return IsOk(); }
201     bool IsOk() const;
202 
CanDrawBitmap()203     bool CanDrawBitmap() const { return true; }
204     void Clear();
205     void SetFont( const wxFont& font );
206     void SetPen( const wxPen& pen );
207     void SetBrush( const wxBrush& brush );
208     void SetLogicalFunction( int function );
209     void SetBackground( const wxBrush& brush );
210     void DestroyClippingRegion();
211     bool StartDoc(const wxString& message);
212     void EndDoc();
213     void StartPage();
214     void EndPage();
215     wxCoord GetCharHeight() const;
216     wxCoord GetCharWidth() const;
CanGetTextExtent()217     bool CanGetTextExtent() const { return true; }
218     wxSize GetPPI() const;
219     void SetAxisOrientation( bool xLeftRight, bool yBottomUp );
220     void SetLogicalOrigin( wxCoord x, wxCoord y );
221     void SetDeviceOrigin( wxCoord x, wxCoord y );
GetDepth()222     virtual int GetDepth() const { return 24; }
SetBackgroundMode(int WXUNUSED (mode))223     void SetBackgroundMode(int WXUNUSED(mode)) { }
SetPalette(const wxPalette & WXUNUSED (palette))224     void SetPalette(const wxPalette& WXUNUSED(palette)) { }
225     static void SetResolution(int ppi);
226     static int GetResolution();
227 
228 protected:
229     bool DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style=wxFLOOD_SURFACE );
230     bool DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const;
231     void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
232     void DoCrossHair(wxCoord x, wxCoord y);
233     void DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc);
234     void DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea);
235     void DoDrawPoint(wxCoord x, wxCoord y);
236     void DoDrawLines(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0);
237     void DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle=wxODDEVEN_RULE);
238     void DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle=wxODDEVEN_RULE);
239     void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
240     void DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius = 20.0);
241     void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
242 #if wxUSE_SPLINES
243     void DoDrawSpline(wxList *points);
244 #endif // wxUSE_SPLINES
245     bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
246             wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop = wxCOPY, bool useMask = false,
247             wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
248     void DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y );
249     void DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask = false  );
250     void DoDrawText(const wxString& text, wxCoord x, wxCoord y );
251     void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
252     void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
DoSetClippingRegionAsRegion(const wxRegion & WXUNUSED (clip))253     void DoSetClippingRegionAsRegion( const wxRegion &WXUNUSED(clip) ) { }
254     void DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
255                      wxCoord *descent = (wxCoord *) NULL,
256                      wxCoord *externalLeading = (wxCoord *) NULL,
257                      wxFont *theFont = (wxFont *) NULL ) const;
258     void DoGetSize(int* width, int* height) const;
259     void DoGetSizeMM(int *width, int *height) const;
260 
261     void SetPrintData(const wxPrintData& data);
GetPrintData()262     wxPrintData& GetPrintData() { return m_printData; }
263 
264 private:
265     static float ms_PSScaleFactor;
266 
267 private:
268     wxPrintData             m_printData;
269     PangoContext           *m_context;
270     PangoLayout            *m_layout;
271     PangoFontDescription   *m_fontdesc;
272 
273     unsigned char           m_currentRed;
274     unsigned char           m_currentGreen;
275     unsigned char           m_currentBlue;
276 
277     int                     m_deviceOffsetY;
278 
279     GnomePrintContext      *m_gpc;
280     GnomePrintJob*          m_job; // only used and destroyed when created with wxPrintData
281 
282     void makeEllipticalPath(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
283 
284 private:
XDEV2LOG(wxCoord x)285     wxCoord XDEV2LOG(wxCoord x) const
286     {
287         return wxRound((double)(x - m_deviceOriginX) / m_scaleX) * m_signX + m_logicalOriginX;
288     }
XDEV2LOGREL(wxCoord x)289     wxCoord XDEV2LOGREL(wxCoord x) const
290     {
291         return wxRound((double)(x) / m_scaleX);
292     }
YDEV2LOG(wxCoord y)293     wxCoord YDEV2LOG(wxCoord y) const
294     {
295         return wxRound((double)(y + m_deviceOriginY - m_deviceOffsetY) / m_scaleY) * m_signY + m_logicalOriginY;
296     }
YDEV2LOGREL(wxCoord y)297     wxCoord YDEV2LOGREL(wxCoord y) const
298     {
299         return wxRound((double)(y) / m_scaleY);
300     }
XLOG2DEV(wxCoord x)301     wxCoord XLOG2DEV(wxCoord x) const
302     {
303         return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX;
304     }
XLOG2DEVREL(wxCoord x)305     wxCoord XLOG2DEVREL(wxCoord x) const
306     {
307         return wxRound((double)(x) * m_scaleX);
308     }
YLOG2DEV(wxCoord y)309     wxCoord YLOG2DEV(wxCoord y) const
310     {
311         return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY - m_deviceOriginY + m_deviceOffsetY;
312     }
YLOG2DEVREL(wxCoord y)313     wxCoord YLOG2DEVREL(wxCoord y) const
314     {
315         return wxRound((double)(y) * m_scaleY);
316     }
317 private:
318     DECLARE_DYNAMIC_CLASS(wxGnomePrintDC)
319     DECLARE_NO_COPY_CLASS(wxGnomePrintDC)
320 };
321 
322 // ----------------------------------------------------------------------------
323 // wxGnomePrintPreview: programmer creates an object of this class to preview a
324 // wxPrintout.
325 // ----------------------------------------------------------------------------
326 
327 class wxGnomePrintPreview : public wxPrintPreviewBase
328 {
329 public:
330     wxGnomePrintPreview(wxPrintout *printout,
331                              wxPrintout *printoutForPrinting = (wxPrintout *) NULL,
332                              wxPrintDialogData *data = (wxPrintDialogData *) NULL);
333     wxGnomePrintPreview(wxPrintout *printout,
334                              wxPrintout *printoutForPrinting,
335                              wxPrintData *data);
336 
337     virtual ~wxGnomePrintPreview();
338 
339     virtual bool Print(bool interactive);
340     virtual void DetermineScaling();
341 
342 private:
343     void Init(wxPrintout *printout, wxPrintout *printoutForPrinting);
344 
345 private:
346     DECLARE_CLASS(wxGnomePrintPreview)
347 };
348 
349 
350 #endif
351     // wxUSE_LIBGNOMEPRINT
352 
353 #endif
354