]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
Fix ribbon documentation warnings.
[wxWidgets.git] / src / common / cmndata.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
e4db172a 2// Name: src/common/cmndata.cpp
c801d85f
KB
3// Purpose: Common GDI data
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
55d99c7a 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
8826f46f
VZ
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
c801d85f
KB
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
8826f46f 23 #pragma hdrstop
c801d85f
KB
24#endif
25
081d8d96
PC
26#if wxUSE_PRINTING_ARCHITECTURE
27
e4db172a
WS
28#include "wx/cmndata.h"
29
c801d85f 30#ifndef WX_PRECOMP
57bd4c60
WS
31 #if defined(__WXMSW__)
32 #include "wx/msw/wrapcdlg.h"
33 #endif // MSW
8826f46f
VZ
34 #include <stdio.h>
35 #include "wx/string.h"
36 #include "wx/utils.h"
37 #include "wx/app.h"
e4db172a 38 #include "wx/log.h"
dd05139a 39 #include "wx/gdicmn.h"
c801d85f
KB
40#endif
41
8850cbd3
RR
42#include "wx/prntbase.h"
43#include "wx/printdlg.h"
57bd4c60 44#include "wx/paper.h"
179e085f 45
746d7582 46
57bd4c60
WS
47IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
48IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
49IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject)
50
8826f46f
VZ
51// ============================================================================
52// implementation
53// ============================================================================
54
55// ----------------------------------------------------------------------------
8826f46f
VZ
56// Print data
57// ----------------------------------------------------------------------------
c801d85f 58
8bbe427f 59wxPrintData::wxPrintData()
c801d85f 60{
60090256 61 m_bin = wxPRINTBIN_DEFAULT;
781609f2 62 m_media = wxPRINTMEDIA_DEFAULT;
6038ec8e 63 m_printMode = wxPRINT_MODE_PRINTER;
7bcb11d3 64 m_printOrientation = wxPORTRAIT;
c7c6e54b 65 m_printOrientationReversed = false;
7bcb11d3 66 m_printNoCopies = 1;
c9d59ee7 67 m_printCollate = false;
8826f46f 68
7bcb11d3 69 // New, 24/3/99
b494c48b 70 m_printerName = wxEmptyString;
c9d59ee7 71 m_colour = true;
7bcb11d3
JS
72 m_duplexMode = wxDUPLEX_SIMPLEX;
73 m_printQuality = wxPRINT_QUALITY_HIGH;
d5eaa19f
VZ
74
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;
7bcb11d3 79
aa96f01c
RR
80 m_privData = NULL;
81 m_privDataLen = 0;
660296aa 82
8850cbd3 83 m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData();
7bcb11d3
JS
84}
85
86wxPrintData::wxPrintData(const wxPrintData& printData)
5e472c1f 87 : wxObject()
7bcb11d3 88{
7b8a9da3 89 m_nativeData = NULL;
7cc52cd8 90 m_privData = NULL;
7bcb11d3 91 (*this) = printData;
c801d85f
KB
92}
93
aa96f01c
RR
94void wxPrintData::SetPrivData( char *privData, int len )
95{
5276b0a5 96 wxDELETEA(m_privData);
aa96f01c
RR
97 m_privDataLen = len;
98 if (m_privDataLen > 0)
99 {
100 m_privData = new char[m_privDataLen];
101 memcpy( m_privData, privData, m_privDataLen );
102 }
103}
104
8bbe427f 105wxPrintData::~wxPrintData()
c801d85f 106{
8850cbd3 107 m_nativeData->m_ref--;
4055ed82 108 if (m_nativeData->m_ref == 0)
8850cbd3 109 delete m_nativeData;
660296aa 110
aa96f01c
RR
111 if (m_privData)
112 delete [] m_privData;
c801d85f
KB
113}
114
51abe921
SC
115void wxPrintData::ConvertToNative()
116{
53fa663a 117 m_nativeData->TransferFrom( *this ) ;
51abe921
SC
118}
119
120void wxPrintData::ConvertFromNative()
121{
53fa663a 122 m_nativeData->TransferTo( *this ) ;
53fa663a 123}
51abe921 124
83666e99 125wxPrintData& wxPrintData::operator=(const wxPrintData& data)
7bcb11d3 126{
83666e99
VZ
127 if ( &data == this )
128 return *this;
129
7bcb11d3
JS
130 m_printNoCopies = data.m_printNoCopies;
131 m_printCollate = data.m_printCollate;
132 m_printOrientation = data.m_printOrientation;
c7c6e54b 133 m_printOrientationReversed = data.m_printOrientationReversed;
7bcb11d3
JS
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;
60090256 140 m_bin = data.m_bin;
781609f2 141 m_media = data.m_media;
6038ec8e 142 m_printMode = data.m_printMode;
4055ed82 143 m_filename = data.m_filename;
aac85509 144
4055ed82 145 // UnRef old m_nativeData
7b8a9da3
RD
146 if (m_nativeData)
147 {
148 m_nativeData->m_ref--;
4055ed82 149 if (m_nativeData->m_ref == 0)
7b8a9da3
RD
150 delete m_nativeData;
151 }
aac85509 152 // Set Ref new one
8850cbd3
RR
153 m_nativeData = data.GetNativeData();
154 m_nativeData->m_ref++;
4055ed82 155
5276b0a5 156 wxDELETEA(m_privData);
aa96f01c
RR
157 m_privDataLen = data.GetPrivDataLen();
158 if (m_privDataLen > 0)
159 {
160 m_privData = new char[m_privDataLen];
161 memcpy( m_privData, data.GetPrivData(), m_privDataLen );
162 }
83666e99
VZ
163
164 return *this;
7bcb11d3
JS
165}
166
58cf0491 167// Is this data OK for showing the print dialog?
b7cacb43 168bool wxPrintData::IsOk() const
58cf0491 169{
fd64de59 170 m_nativeData->TransferFrom( *this );
8850cbd3 171
a1b806b9 172 return m_nativeData->IsOk();
58cf0491 173}
8826f46f
VZ
174
175// ----------------------------------------------------------------------------
176// Print dialog data
177// ----------------------------------------------------------------------------
7bcb11d3
JS
178
179wxPrintDialogData::wxPrintDialogData()
180{
7bcb11d3
JS
181 m_printFromPage = 0;
182 m_printToPage = 0;
183 m_printMinPage = 0;
184 m_printMaxPage = 0;
185 m_printNoCopies = 1;
c9d59ee7
WS
186 m_printAllPages = false;
187 m_printCollate = false;
188 m_printToFile = false;
189 m_printSelection = false;
190 m_printEnableSelection = false;
191 m_printEnablePageNumbers = true;
4055ed82 192
9f1316dc
RR
193 wxPrintFactory* factory = wxPrintFactory::GetFactory();
194 m_printEnablePrintToFile = ! factory->HasOwnPrintToFile();
4055ed82 195
c9d59ee7 196 m_printEnableHelp = false;
7bcb11d3
JS
197}
198
199wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
5e472c1f 200 : wxObject()
7bcb11d3
JS
201{
202 (*this) = dialogData;
203}
204
205wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
206{
d2b354f9 207 m_printFromPage = 1;
7bcb11d3 208 m_printToPage = 0;
d2b354f9
JS
209 m_printMinPage = 1;
210 m_printMaxPage = 9999;
7bcb11d3 211 m_printNoCopies = 1;
dc0cea5e
RR
212 // On Mac the Print dialog always defaults to "All Pages"
213#ifdef __WXMAC__
214 m_printAllPages = true;
215#else
c9d59ee7 216 m_printAllPages = false;
dc0cea5e 217#endif
c9d59ee7
WS
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;
7bcb11d3
JS
225 m_printData = printData;
226}
227
228wxPrintDialogData::~wxPrintDialogData()
229{
7bcb11d3
JS
230}
231
7bcb11d3 232void wxPrintDialogData::operator=(const wxPrintDialogData& data)
c801d85f 233{
7bcb11d3
JS
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;
5360828d 242 m_printSelection = data.m_printSelection;
7bcb11d3
JS
243 m_printEnableSelection = data.m_printEnableSelection;
244 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
245 m_printEnableHelp = data.m_printEnableHelp;
246 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
7bcb11d3
JS
247 m_printData = data.m_printData;
248}
249
250void wxPrintDialogData::operator=(const wxPrintData& data)
251{
252 m_printData = data;
c801d85f
KB
253}
254
8826f46f
VZ
255// ----------------------------------------------------------------------------
256// wxPageSetupDialogData
257// ----------------------------------------------------------------------------
c801d85f 258
7bcb11d3 259wxPageSetupDialogData::wxPageSetupDialogData()
c801d85f 260{
c47addef 261 m_paperSize = wxSize(0,0);
7bcb11d3
JS
262
263 CalculatePaperSizeFromId();
264
2997ca30
WS
265 m_minMarginTopLeft =
266 m_minMarginBottomRight =
267 m_marginTopLeft =
c47addef 268 m_marginBottomRight = wxPoint(0,0);
7bcb11d3
JS
269
270 // Flags
c9d59ee7
WS
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;
7bcb11d3 278}
c801d85f 279
7bcb11d3 280wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
5e472c1f 281 : wxObject()
7bcb11d3
JS
282{
283 (*this) = dialogData;
284}
285
286wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
287{
c47addef 288 m_paperSize = wxSize(0,0);
2997ca30
WS
289 m_minMarginTopLeft =
290 m_minMarginBottomRight =
291 m_marginTopLeft =
c47addef 292 m_marginBottomRight = wxPoint(0,0);
7bcb11d3
JS
293
294 // Flags
c9d59ee7
WS
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;
7bcb11d3
JS
302
303 m_printData = printData;
304
305 // The wxPrintData paper size overrides these values, unless the size cannot
306 // be found.
307 CalculatePaperSizeFromId();
c801d85f
KB
308}
309
7bcb11d3 310wxPageSetupDialogData::~wxPageSetupDialogData()
c801d85f 311{
c801d85f
KB
312}
313
5e472c1f 314wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
c801d85f 315{
7bcb11d3
JS
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;
d0ee33f5 326 m_getDefaultInfo = data.m_getDefaultInfo;
7bcb11d3
JS
327 m_enableHelp = data.m_enableHelp;
328
329 m_printData = data.m_printData;
5e472c1f
GD
330
331 return *this;
7bcb11d3 332}
c801d85f 333
5e472c1f 334wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
7bcb11d3
JS
335{
336 m_printData = data;
24c5243d 337 CalculatePaperSizeFromId();
5e472c1f
GD
338
339 return *this;
c801d85f
KB
340}
341
7bcb11d3
JS
342// If a corresponding paper type is found in the paper database, will set the m_printData
343// paper size id member as well.
344void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
345{
346 m_paperSize = sz;
c801d85f 347
7bcb11d3
JS
348 CalculateIdFromPaperSize();
349}
c801d85f 350
7bcb11d3
JS
351// Sets the wxPrintData id, plus the paper width/height if found in the paper database.
352void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
353{
354 m_printData.SetPaperId(id);
355
356 CalculatePaperSizeFromId();
c801d85f
KB
357}
358
24c5243d
RD
359void wxPageSetupDialogData::SetPrintData(const wxPrintData& printData)
360{
361 m_printData = printData;
b494c48b 362 CalculatePaperSizeFromId();
24c5243d
RD
363}
364
7bcb11d3
JS
365// Use paper size defined in this object to set the wxPrintData
366// paper id
367void wxPageSetupDialogData::CalculateIdFromPaperSize()
c801d85f 368{
d3b9f782 369 wxASSERT_MSG( (wxThePrintPaperDatabase != NULL),
fbdcff4a 370 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
c801d85f 371
7bcb11d3
JS
372 wxSize sz = GetPaperSize();
373
374 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
375 if (id != wxPAPER_NONE)
c801d85f 376 {
7bcb11d3 377 m_printData.SetPaperId(id);
c801d85f
KB
378 }
379}
8826f46f 380
7bcb11d3
JS
381// Use paper id in wxPrintData to set this object's paper size
382void wxPageSetupDialogData::CalculatePaperSizeFromId()
383{
d3b9f782 384 wxASSERT_MSG( (wxThePrintPaperDatabase != NULL),
fbdcff4a 385 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
7bcb11d3
JS
386
387 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
c801d85f 388
331dbb61
JS
389 if (sz != wxSize(0, 0))
390 {
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;
394 }
7bcb11d3 395}
8826f46f 396
88ac883a 397#endif // wxUSE_PRINTING_ARCHITECTURE