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