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