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