1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/cmndata.cpp
3 // Purpose: Common GDI data
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #if wxUSE_PRINTING_ARCHITECTURE
28 #include "wx/cmndata.h"
31 #if defined(__WXMSW__)
32 #include "wx/msw/wrapcdlg.h"
35 #include "wx/string.h"
39 #include "wx/gdicmn.h"
42 #include "wx/prntbase.h"
43 #include "wx/printdlg.h"
47 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
48 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
49 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
51 // ============================================================================
53 // ============================================================================
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 wxPrintData::wxPrintData()
61 m_bin
= wxPRINTBIN_DEFAULT
;
62 m_media
= wxPRINTMEDIA_DEFAULT
;
63 m_printMode
= wxPRINT_MODE_PRINTER
;
64 m_printOrientation
= wxPORTRAIT
;
65 m_printOrientationReversed
= false;
67 m_printCollate
= false;
70 m_printerName
= wxEmptyString
;
72 m_duplexMode
= wxDUPLEX_SIMPLEX
;
73 m_printQuality
= wxPRINT_QUALITY_HIGH
;
75 // we intentionally don't initialize paper id and size at all, like this
76 // the default system settings will be used for them
77 m_paperId
= wxPAPER_NONE
;
78 m_paperSize
= wxDefaultSize
;
83 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
86 wxPrintData::wxPrintData(const wxPrintData
& printData
)
94 void wxPrintData::SetPrivData( char *privData
, int len
)
96 wxDELETEA(m_privData
);
98 if (m_privDataLen
> 0)
100 m_privData
= new char[m_privDataLen
];
101 memcpy( m_privData
, privData
, m_privDataLen
);
105 wxPrintData::~wxPrintData()
107 m_nativeData
->m_ref
--;
108 if (m_nativeData
->m_ref
== 0)
112 delete [] m_privData
;
115 void wxPrintData::ConvertToNative()
117 m_nativeData
->TransferFrom( *this ) ;
120 void wxPrintData::ConvertFromNative()
122 m_nativeData
->TransferTo( *this ) ;
125 wxPrintData
& wxPrintData::operator=(const wxPrintData
& data
)
130 m_printNoCopies
= data
.m_printNoCopies
;
131 m_printCollate
= data
.m_printCollate
;
132 m_printOrientation
= data
.m_printOrientation
;
133 m_printOrientationReversed
= data
.m_printOrientationReversed
;
134 m_printerName
= data
.m_printerName
;
135 m_colour
= data
.m_colour
;
136 m_duplexMode
= data
.m_duplexMode
;
137 m_printQuality
= data
.m_printQuality
;
138 m_paperId
= data
.m_paperId
;
139 m_paperSize
= data
.m_paperSize
;
141 m_media
= data
.m_media
;
142 m_printMode
= data
.m_printMode
;
143 m_filename
= data
.m_filename
;
145 // UnRef old m_nativeData
148 m_nativeData
->m_ref
--;
149 if (m_nativeData
->m_ref
== 0)
153 m_nativeData
= data
.GetNativeData();
154 m_nativeData
->m_ref
++;
156 wxDELETEA(m_privData
);
157 m_privDataLen
= data
.GetPrivDataLen();
158 if (m_privDataLen
> 0)
160 m_privData
= new char[m_privDataLen
];
161 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
167 // Is this data OK for showing the print dialog?
168 bool wxPrintData::IsOk() const
170 m_nativeData
->TransferFrom( *this );
172 return m_nativeData
->IsOk();
175 // ----------------------------------------------------------------------------
177 // ----------------------------------------------------------------------------
179 wxPrintDialogData::wxPrintDialogData()
186 m_printAllPages
= false;
187 m_printCollate
= false;
188 m_printToFile
= false;
189 m_printSelection
= false;
190 m_printEnableSelection
= false;
191 m_printEnablePageNumbers
= true;
193 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
194 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
196 m_printEnableHelp
= false;
199 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
202 (*this) = dialogData
;
205 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
210 m_printMaxPage
= 9999;
212 // On Mac the Print dialog always defaults to "All Pages"
214 m_printAllPages
= true;
216 m_printAllPages
= false;
218 m_printCollate
= false;
219 m_printToFile
= false;
220 m_printSelection
= false;
221 m_printEnableSelection
= false;
222 m_printEnablePageNumbers
= true;
223 m_printEnablePrintToFile
= true;
224 m_printEnableHelp
= false;
225 m_printData
= printData
;
228 wxPrintDialogData::~wxPrintDialogData()
232 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
234 m_printFromPage
= data
.m_printFromPage
;
235 m_printToPage
= data
.m_printToPage
;
236 m_printMinPage
= data
.m_printMinPage
;
237 m_printMaxPage
= data
.m_printMaxPage
;
238 m_printNoCopies
= data
.m_printNoCopies
;
239 m_printAllPages
= data
.m_printAllPages
;
240 m_printCollate
= data
.m_printCollate
;
241 m_printToFile
= data
.m_printToFile
;
242 m_printSelection
= data
.m_printSelection
;
243 m_printEnableSelection
= data
.m_printEnableSelection
;
244 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
245 m_printEnableHelp
= data
.m_printEnableHelp
;
246 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
247 m_printData
= data
.m_printData
;
250 void wxPrintDialogData::operator=(const wxPrintData
& data
)
255 // ----------------------------------------------------------------------------
256 // wxPageSetupDialogData
257 // ----------------------------------------------------------------------------
259 wxPageSetupDialogData::wxPageSetupDialogData()
261 m_paperSize
= wxSize(0,0);
263 CalculatePaperSizeFromId();
266 m_minMarginBottomRight
=
268 m_marginBottomRight
= wxPoint(0,0);
271 m_defaultMinMargins
= false;
272 m_enableMargins
= true;
273 m_enableOrientation
= true;
274 m_enablePaper
= true;
275 m_enablePrinter
= true;
276 m_enableHelp
= false;
277 m_getDefaultInfo
= false;
280 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
283 (*this) = dialogData
;
286 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
288 m_paperSize
= wxSize(0,0);
290 m_minMarginBottomRight
=
292 m_marginBottomRight
= wxPoint(0,0);
295 m_defaultMinMargins
= false;
296 m_enableMargins
= true;
297 m_enableOrientation
= true;
298 m_enablePaper
= true;
299 m_enablePrinter
= true;
300 m_enableHelp
= false;
301 m_getDefaultInfo
= false;
303 m_printData
= printData
;
305 // The wxPrintData paper size overrides these values, unless the size cannot
307 CalculatePaperSizeFromId();
310 wxPageSetupDialogData::~wxPageSetupDialogData()
314 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
316 m_paperSize
= data
.m_paperSize
;
317 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
318 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
319 m_marginTopLeft
= data
.m_marginTopLeft
;
320 m_marginBottomRight
= data
.m_marginBottomRight
;
321 m_defaultMinMargins
= data
.m_defaultMinMargins
;
322 m_enableMargins
= data
.m_enableMargins
;
323 m_enableOrientation
= data
.m_enableOrientation
;
324 m_enablePaper
= data
.m_enablePaper
;
325 m_enablePrinter
= data
.m_enablePrinter
;
326 m_getDefaultInfo
= data
.m_getDefaultInfo
;
327 m_enableHelp
= data
.m_enableHelp
;
329 m_printData
= data
.m_printData
;
334 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
337 CalculatePaperSizeFromId();
342 // If a corresponding paper type is found in the paper database, will set the m_printData
343 // paper size id member as well.
344 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
348 CalculateIdFromPaperSize();
351 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
352 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
354 m_printData
.SetPaperId(id
);
356 CalculatePaperSizeFromId();
359 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
361 m_printData
= printData
;
362 CalculatePaperSizeFromId();
365 // Use paper size defined in this object to set the wxPrintData
367 void wxPageSetupDialogData::CalculateIdFromPaperSize()
369 wxASSERT_MSG( (wxThePrintPaperDatabase
!= NULL
),
370 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
372 wxSize sz
= GetPaperSize();
374 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
375 if (id
!= wxPAPER_NONE
)
377 m_printData
.SetPaperId(id
);
381 // Use paper id in wxPrintData to set this object's paper size
382 void wxPageSetupDialogData::CalculatePaperSizeFromId()
384 wxASSERT_MSG( (wxThePrintPaperDatabase
!= NULL
),
385 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
387 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
389 if (sz
!= wxSize(0, 0))
391 // sz is in 10ths of a mm, while paper size is in mm
392 m_paperSize
.x
= sz
.x
/ 10;
393 m_paperSize
.y
= sz
.y
/ 10;
397 #endif // wxUSE_PRINTING_ARCHITECTURE