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