1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/cmndata.cpp
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_PRINTING_ARCHITECTURE
29 #include "wx/cmndata.h"
32 #if defined(__WXMSW__)
33 #include "wx/msw/wrapcdlg.h"
36 #include "wx/string.h"
40 #include "wx/gdicmn.h"
43 #include "wx/prntbase.h"
44 #include "wx/printdlg.h"
48 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
49 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
50 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
52 // ============================================================================
54 // ============================================================================
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 wxPrintData::wxPrintData()
62 m_bin
= wxPRINTBIN_DEFAULT
;
63 m_media
= wxPRINTMEDIA_DEFAULT
;
64 m_printMode
= wxPRINT_MODE_PRINTER
;
65 m_printOrientation
= wxPORTRAIT
;
66 m_printOrientationReversed
= false;
68 m_printCollate
= false;
71 m_printerName
= wxEmptyString
;
73 m_duplexMode
= wxDUPLEX_SIMPLEX
;
74 m_printQuality
= wxPRINT_QUALITY_HIGH
;
76 // we intentionally don't initialize paper id and size at all, like this
77 // the default system settings will be used for them
78 m_paperId
= wxPAPER_NONE
;
79 m_paperSize
= wxDefaultSize
;
84 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
87 wxPrintData::wxPrintData(const wxPrintData
& printData
)
95 void wxPrintData::SetPrivData( char *privData
, int len
)
97 wxDELETEA(m_privData
);
99 if (m_privDataLen
> 0)
101 m_privData
= new char[m_privDataLen
];
102 memcpy( m_privData
, privData
, m_privDataLen
);
106 wxPrintData::~wxPrintData()
108 m_nativeData
->m_ref
--;
109 if (m_nativeData
->m_ref
== 0)
113 delete [] m_privData
;
116 void wxPrintData::ConvertToNative()
118 m_nativeData
->TransferFrom( *this ) ;
121 void wxPrintData::ConvertFromNative()
123 m_nativeData
->TransferTo( *this ) ;
126 wxPrintData
& wxPrintData::operator=(const wxPrintData
& data
)
131 m_printNoCopies
= data
.m_printNoCopies
;
132 m_printCollate
= data
.m_printCollate
;
133 m_printOrientation
= data
.m_printOrientation
;
134 m_printOrientationReversed
= data
.m_printOrientationReversed
;
135 m_printerName
= data
.m_printerName
;
136 m_colour
= data
.m_colour
;
137 m_duplexMode
= data
.m_duplexMode
;
138 m_printQuality
= data
.m_printQuality
;
139 m_paperId
= data
.m_paperId
;
140 m_paperSize
= data
.m_paperSize
;
142 m_media
= data
.m_media
;
143 m_printMode
= data
.m_printMode
;
144 m_filename
= data
.m_filename
;
146 // UnRef old m_nativeData
149 m_nativeData
->m_ref
--;
150 if (m_nativeData
->m_ref
== 0)
154 m_nativeData
= data
.GetNativeData();
155 m_nativeData
->m_ref
++;
157 wxDELETEA(m_privData
);
158 m_privDataLen
= data
.GetPrivDataLen();
159 if (m_privDataLen
> 0)
161 m_privData
= new char[m_privDataLen
];
162 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
168 // Is this data OK for showing the print dialog?
169 bool wxPrintData::IsOk() const
171 m_nativeData
->TransferFrom( *this );
173 return m_nativeData
->Ok();
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 wxPrintDialogData::wxPrintDialogData()
187 m_printAllPages
= false;
188 m_printCollate
= false;
189 m_printToFile
= false;
190 m_printSelection
= false;
191 m_printEnableSelection
= false;
192 m_printEnablePageNumbers
= true;
194 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
195 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
197 m_printEnableHelp
= false;
200 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
203 (*this) = dialogData
;
206 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
211 m_printMaxPage
= 9999;
213 // On Mac the Print dialog always defaults to "All Pages"
215 m_printAllPages
= true;
217 m_printAllPages
= false;
219 m_printCollate
= false;
220 m_printToFile
= false;
221 m_printSelection
= false;
222 m_printEnableSelection
= false;
223 m_printEnablePageNumbers
= true;
224 m_printEnablePrintToFile
= true;
225 m_printEnableHelp
= false;
226 m_printData
= printData
;
229 wxPrintDialogData::~wxPrintDialogData()
233 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
235 m_printFromPage
= data
.m_printFromPage
;
236 m_printToPage
= data
.m_printToPage
;
237 m_printMinPage
= data
.m_printMinPage
;
238 m_printMaxPage
= data
.m_printMaxPage
;
239 m_printNoCopies
= data
.m_printNoCopies
;
240 m_printAllPages
= data
.m_printAllPages
;
241 m_printCollate
= data
.m_printCollate
;
242 m_printToFile
= data
.m_printToFile
;
243 m_printSelection
= data
.m_printSelection
;
244 m_printEnableSelection
= data
.m_printEnableSelection
;
245 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
246 m_printEnableHelp
= data
.m_printEnableHelp
;
247 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
248 m_printData
= data
.m_printData
;
251 void wxPrintDialogData::operator=(const wxPrintData
& data
)
256 // ----------------------------------------------------------------------------
257 // wxPageSetupDialogData
258 // ----------------------------------------------------------------------------
260 wxPageSetupDialogData::wxPageSetupDialogData()
262 m_paperSize
= wxSize(0,0);
264 CalculatePaperSizeFromId();
267 m_minMarginBottomRight
=
269 m_marginBottomRight
= wxPoint(0,0);
272 m_defaultMinMargins
= false;
273 m_enableMargins
= true;
274 m_enableOrientation
= true;
275 m_enablePaper
= true;
276 m_enablePrinter
= true;
277 m_enableHelp
= false;
278 m_getDefaultInfo
= false;
281 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
284 (*this) = dialogData
;
287 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
289 m_paperSize
= wxSize(0,0);
291 m_minMarginBottomRight
=
293 m_marginBottomRight
= wxPoint(0,0);
296 m_defaultMinMargins
= false;
297 m_enableMargins
= true;
298 m_enableOrientation
= true;
299 m_enablePaper
= true;
300 m_enablePrinter
= true;
301 m_enableHelp
= false;
302 m_getDefaultInfo
= false;
304 m_printData
= printData
;
306 // The wxPrintData paper size overrides these values, unless the size cannot
308 CalculatePaperSizeFromId();
311 wxPageSetupDialogData::~wxPageSetupDialogData()
315 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
317 m_paperSize
= data
.m_paperSize
;
318 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
319 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
320 m_marginTopLeft
= data
.m_marginTopLeft
;
321 m_marginBottomRight
= data
.m_marginBottomRight
;
322 m_defaultMinMargins
= data
.m_defaultMinMargins
;
323 m_enableMargins
= data
.m_enableMargins
;
324 m_enableOrientation
= data
.m_enableOrientation
;
325 m_enablePaper
= data
.m_enablePaper
;
326 m_enablePrinter
= data
.m_enablePrinter
;
327 m_getDefaultInfo
= data
.m_getDefaultInfo
;
328 m_enableHelp
= data
.m_enableHelp
;
330 m_printData
= data
.m_printData
;
335 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
338 CalculatePaperSizeFromId();
343 // If a corresponding paper type is found in the paper database, will set the m_printData
344 // paper size id member as well.
345 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
349 CalculateIdFromPaperSize();
352 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
353 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
355 m_printData
.SetPaperId(id
);
357 CalculatePaperSizeFromId();
360 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
362 m_printData
= printData
;
363 CalculatePaperSizeFromId();
366 // Use paper size defined in this object to set the wxPrintData
368 void wxPageSetupDialogData::CalculateIdFromPaperSize()
370 wxASSERT_MSG( (wxThePrintPaperDatabase
!= NULL
),
371 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
373 wxSize sz
= GetPaperSize();
375 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
376 if (id
!= wxPAPER_NONE
)
378 m_printData
.SetPaperId(id
);
382 // Use paper id in wxPrintData to set this object's paper size
383 void wxPageSetupDialogData::CalculatePaperSizeFromId()
385 wxASSERT_MSG( (wxThePrintPaperDatabase
!= NULL
),
386 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
388 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
390 if (sz
!= wxSize(0, 0))
392 // sz is in 10ths of a mm, while paper size is in mm
393 m_paperSize
.x
= sz
.x
/ 10;
394 m_paperSize
.y
= sz
.y
/ 10;
398 #endif // wxUSE_PRINTING_ARCHITECTURE