]> git.saurik.com Git - wxWidgets.git/blob - src/common/cmndata.cpp
Mem leaks in connection with print factory code.
[wxWidgets.git] / src / common / cmndata.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "cmndata.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include <stdio.h>
33 #include "wx/string.h"
34 #include "wx/utils.h"
35 #include "wx/app.h"
36 #endif
37
38 #include "wx/gdicmn.h"
39 #include "wx/cmndata.h"
40 #include "wx/log.h"
41 #include "wx/prntbase.h"
42 #include "wx/printdlg.h"
43
44 #if wxUSE_FONTDLG
45 #include "wx/fontdlg.h"
46 #endif // wxUSE_FONTDLG
47
48 #if wxUSE_PRINTING_ARCHITECTURE
49 #include "wx/paper.h"
50 #endif // wxUSE_PRINTING_ARCHITECTURE
51
52 #if defined(__WXMSW__) && !defined(__PALMOS__)
53 #include <windowsx.h>
54 #include "wx/msw/private.h"
55
56 #ifndef __SMARTPHONE__ /* of WinCE */
57 #include <commdlg.h>
58 #endif
59
60 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
61 #include <windowsx.h>
62 #include <commdlg.h>
63 #endif
64 #endif // MSW
65
66 #ifdef __WXMAC__
67 #include "wx/mac/private/print.h"
68 #endif
69
70 #if wxUSE_PRINTING_ARCHITECTURE
71 IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
72 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
73 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject)
74 #endif // wxUSE_PRINTING_ARCHITECTURE
75
76 IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
77 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
78
79 #ifndef DMPAPER_USER
80 #define DMPAPER_USER 256
81 #endif
82
83 // ============================================================================
84 // implementation
85 // ============================================================================
86
87 // ----------------------------------------------------------------------------
88 // wxColourData
89 // ----------------------------------------------------------------------------
90
91 wxColourData::wxColourData()
92 {
93 m_chooseFull = false;
94 m_dataColour.Set(0,0,0);
95 // m_custColours are wxNullColours initially
96 }
97
98 wxColourData::wxColourData(const wxColourData& data)
99 : wxObject()
100 {
101 (*this) = data;
102 }
103
104 wxColourData::~wxColourData()
105 {
106 }
107
108 void wxColourData::SetCustomColour(int i, const wxColour& colour)
109 {
110 wxCHECK_RET( (i >= 0 && i < 16), _T("custom colour index out of range") );
111
112 m_custColours[i] = colour;
113 }
114
115 wxColour wxColourData::GetCustomColour(int i)
116 {
117 wxCHECK_MSG( (i >= 0 && i < 16), wxColour(0,0,0),
118 _T("custom colour index out of range") );
119
120 return m_custColours[i];
121 }
122
123 void wxColourData::operator=(const wxColourData& data)
124 {
125 int i;
126 for (i = 0; i < 16; i++)
127 m_custColours[i] = data.m_custColours[i];
128
129 m_dataColour = (wxColour&)data.m_dataColour;
130 m_chooseFull = data.m_chooseFull;
131 }
132
133 // ----------------------------------------------------------------------------
134 // Font data
135 // ----------------------------------------------------------------------------
136
137 wxFontData::wxFontData()
138 {
139 // Intialize colour to black.
140 m_fontColour = wxNullColour;
141
142 m_showHelp = false;
143 m_allowSymbols = true;
144 m_enableEffects = true;
145 m_minSize = 0;
146 m_maxSize = 0;
147
148 m_encoding = wxFONTENCODING_SYSTEM;
149 }
150
151 wxFontData::~wxFontData()
152 {
153 }
154
155 #if wxUSE_FONTDLG
156
157 wxFontDialogBase::~wxFontDialogBase()
158 {
159 }
160
161 #endif // wxUSE_FONTDLG
162
163 #if wxUSE_PRINTING_ARCHITECTURE
164 // ----------------------------------------------------------------------------
165 // Print data
166 // ----------------------------------------------------------------------------
167
168 wxPrintData::wxPrintData()
169 {
170 #ifdef __WXMAC__
171 m_nativePrintData = wxNativePrintData::Create() ;
172 #endif
173 m_bin = wxPRINTBIN_DEFAULT;
174 m_printMode = wxPRINT_MODE_PRINTER;
175 m_printOrientation = wxPORTRAIT;
176 m_printNoCopies = 1;
177 m_printCollate = false;
178
179 // New, 24/3/99
180 m_printerName = wxT("");
181 m_colour = true;
182 m_duplexMode = wxDUPLEX_SIMPLEX;
183 m_printQuality = wxPRINT_QUALITY_HIGH;
184 m_paperId = wxPAPER_A4;
185 m_paperSize = wxSize(210, 297);
186
187 m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData();
188 }
189
190 wxPrintData::wxPrintData(const wxPrintData& printData)
191 : wxObject()
192 {
193 (*this) = printData;
194 }
195
196 wxPrintData::~wxPrintData()
197 {
198 m_nativeData->m_ref--;
199 if (m_nativeData->m_ref == 0)
200 delete m_nativeData;
201
202 #ifdef __WXMAC__
203 delete m_nativePrintData ;
204 #endif
205 }
206
207
208 void wxPrintData::ConvertToNative()
209 {
210 #ifdef __WXMAC__
211 m_nativePrintData->TransferFrom( this ) ;
212 #else
213 m_nativeData->TransferFrom( *this ) ;
214 #endif
215 }
216
217 void wxPrintData::ConvertFromNative()
218 {
219 #ifdef __WXMAC__
220 m_nativePrintData->TransferTo( this ) ;
221 #else
222 m_nativeData->TransferTo( *this ) ;
223 #endif
224 }
225
226 void wxPrintData::operator=(const wxPrintData& data)
227 {
228 m_printNoCopies = data.m_printNoCopies;
229 m_printCollate = data.m_printCollate;
230 m_printOrientation = data.m_printOrientation;
231 m_printerName = data.m_printerName;
232 m_colour = data.m_colour;
233 m_duplexMode = data.m_duplexMode;
234 m_printQuality = data.m_printQuality;
235 m_paperId = data.m_paperId;
236 m_paperSize = data.m_paperSize;
237 m_bin = data.m_bin;
238 m_printMode = data.m_printMode;
239 m_filename = data.m_filename;
240
241 // UnRef old m_nativeData
242 m_nativeData->m_ref--;
243 if (m_nativeData->m_ref == 0)
244 delete m_nativeData;
245 // Set Ref new one
246 m_nativeData = data.GetNativeData();
247 m_nativeData->m_ref++;
248
249 #ifdef __WXMAC__
250 m_nativePrintData->CopyFrom( data.m_nativePrintData ) ;
251 #endif
252 }
253
254 // Is this data OK for showing the print dialog?
255 bool wxPrintData::Ok() const
256 {
257 m_nativeData->TransferFrom( *this );
258
259 return m_nativeData->Ok();
260 }
261
262 // ----------------------------------------------------------------------------
263 // Print dialog data
264 // ----------------------------------------------------------------------------
265
266 wxPrintDialogData::wxPrintDialogData()
267 {
268 m_printFromPage = 0;
269 m_printToPage = 0;
270 m_printMinPage = 0;
271 m_printMaxPage = 0;
272 m_printNoCopies = 1;
273 m_printAllPages = false;
274 m_printCollate = false;
275 m_printToFile = false;
276 m_printSelection = false;
277 m_printEnableSelection = false;
278 m_printEnablePageNumbers = true;
279
280 wxPrintFactory* factory = wxPrintFactory::GetFactory();
281 m_printEnablePrintToFile = ! factory->HasOwnPrintToFile();
282
283 m_printEnableHelp = false;
284 #if WXWIN_COMPATIBILITY_2_4
285 m_printSetupDialog = false;
286 #endif
287 }
288
289 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
290 : wxObject()
291 {
292 (*this) = dialogData;
293 }
294
295 wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
296 {
297 m_printFromPage = 1;
298 m_printToPage = 0;
299 m_printMinPage = 1;
300 m_printMaxPage = 9999;
301 m_printNoCopies = 1;
302 m_printAllPages = false;
303 m_printCollate = false;
304 m_printToFile = false;
305 m_printSelection = false;
306 m_printEnableSelection = false;
307 m_printEnablePageNumbers = true;
308 m_printEnablePrintToFile = true;
309 m_printEnableHelp = false;
310 #if WXWIN_COMPATIBILITY_2_4
311 m_printSetupDialog = false;
312 #endif
313 m_printData = printData;
314 }
315
316 wxPrintDialogData::~wxPrintDialogData()
317 {
318 }
319
320 #ifdef __WXMAC__
321
322 void wxPrintDialogData::ConvertToNative()
323 {
324 m_printData.ConvertToNative();
325 m_printData.m_nativePrintData->TransferFrom( this ) ;
326 }
327
328 void wxPrintDialogData::ConvertFromNative()
329 {
330 m_printData.ConvertFromNative();
331 m_printData.m_nativePrintData->TransferTo( this ) ;
332 }
333
334 #endif
335
336
337 void wxPrintDialogData::operator=(const wxPrintDialogData& data)
338 {
339 m_printFromPage = data.m_printFromPage;
340 m_printToPage = data.m_printToPage;
341 m_printMinPage = data.m_printMinPage;
342 m_printMaxPage = data.m_printMaxPage;
343 m_printNoCopies = data.m_printNoCopies;
344 m_printAllPages = data.m_printAllPages;
345 m_printCollate = data.m_printCollate;
346 m_printToFile = data.m_printToFile;
347 m_printSelection = data.m_printSelection;
348 m_printEnableSelection = data.m_printEnableSelection;
349 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
350 m_printEnableHelp = data.m_printEnableHelp;
351 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
352 #if WXWIN_COMPATIBILITY_2_4
353 m_printSetupDialog = data.m_printSetupDialog;
354 #endif
355 m_printData = data.m_printData;
356 }
357
358 void wxPrintDialogData::operator=(const wxPrintData& data)
359 {
360 m_printData = data;
361 }
362
363 // ----------------------------------------------------------------------------
364 // wxPageSetupDialogData
365 // ----------------------------------------------------------------------------
366
367 wxPageSetupDialogData::wxPageSetupDialogData()
368 {
369 m_paperSize = wxSize(0, 0);
370
371 CalculatePaperSizeFromId();
372
373 m_minMarginTopLeft = wxPoint(0, 0);
374 m_minMarginBottomRight = wxPoint(0, 0);
375 m_marginTopLeft = wxPoint(0, 0);
376 m_marginBottomRight = wxPoint(0, 0);
377
378 // Flags
379 m_defaultMinMargins = false;
380 m_enableMargins = true;
381 m_enableOrientation = true;
382 m_enablePaper = true;
383 m_enablePrinter = true;
384 m_enableHelp = false;
385 m_getDefaultInfo = false;
386 }
387
388 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
389 : wxObject()
390 {
391 (*this) = dialogData;
392 }
393
394 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
395 {
396 m_paperSize = wxSize(0, 0);
397 m_minMarginTopLeft = wxPoint(0, 0);
398 m_minMarginBottomRight = wxPoint(0, 0);
399 m_marginTopLeft = wxPoint(0, 0);
400 m_marginBottomRight = wxPoint(0, 0);
401
402 // Flags
403 m_defaultMinMargins = false;
404 m_enableMargins = true;
405 m_enableOrientation = true;
406 m_enablePaper = true;
407 m_enablePrinter = true;
408 m_enableHelp = false;
409 m_getDefaultInfo = false;
410
411 m_printData = printData;
412
413 // The wxPrintData paper size overrides these values, unless the size cannot
414 // be found.
415 CalculatePaperSizeFromId();
416 }
417
418 wxPageSetupDialogData::~wxPageSetupDialogData()
419 {
420 }
421
422 wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
423 {
424 m_paperSize = data.m_paperSize;
425 m_minMarginTopLeft = data.m_minMarginTopLeft;
426 m_minMarginBottomRight = data.m_minMarginBottomRight;
427 m_marginTopLeft = data.m_marginTopLeft;
428 m_marginBottomRight = data.m_marginBottomRight;
429 m_defaultMinMargins = data.m_defaultMinMargins;
430 m_enableMargins = data.m_enableMargins;
431 m_enableOrientation = data.m_enableOrientation;
432 m_enablePaper = data.m_enablePaper;
433 m_enablePrinter = data.m_enablePrinter;
434 m_getDefaultInfo = data.m_getDefaultInfo;;
435 m_enableHelp = data.m_enableHelp;
436
437 m_printData = data.m_printData;
438
439 return *this;
440 }
441
442 wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
443 {
444 m_printData = data;
445
446 return *this;
447 }
448
449 #ifdef __WXMAC__
450 void wxPageSetupDialogData::ConvertToNative()
451 {
452 m_printData.ConvertToNative();
453 m_printData.m_nativePrintData->TransferFrom( this ) ;
454 }
455
456 void wxPageSetupDialogData::ConvertFromNative()
457 {
458 m_printData.ConvertFromNative ();
459 m_paperSize = m_printData.GetPaperSize() ;
460 CalculateIdFromPaperSize();
461 m_printData.m_nativePrintData->TransferTo( this ) ;
462 // adjust minimal values
463
464 if ( m_marginTopLeft.x < m_minMarginTopLeft.x )
465 m_marginTopLeft.x = m_minMarginTopLeft.x;
466
467 if ( m_marginBottomRight.x < m_minMarginBottomRight.x )
468 m_marginBottomRight.x = m_minMarginBottomRight.x;
469
470 if ( m_marginTopLeft.y < m_minMarginTopLeft.y )
471 m_marginTopLeft.y = m_minMarginTopLeft.y;
472
473 if ( m_marginBottomRight.y < m_minMarginBottomRight.y )
474 m_marginBottomRight.y = m_minMarginBottomRight.y;
475 }
476 #endif
477
478
479 // If a corresponding paper type is found in the paper database, will set the m_printData
480 // paper size id member as well.
481 void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
482 {
483 m_paperSize = sz;
484
485 CalculateIdFromPaperSize();
486 }
487
488 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
489 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
490 {
491 m_printData.SetPaperId(id);
492
493 CalculatePaperSizeFromId();
494 }
495
496 // Use paper size defined in this object to set the wxPrintData
497 // paper id
498 void wxPageSetupDialogData::CalculateIdFromPaperSize()
499 {
500 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
501 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
502
503 wxSize sz = GetPaperSize();
504
505 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
506 if (id != wxPAPER_NONE)
507 {
508 m_printData.SetPaperId(id);
509 }
510 }
511
512 // Use paper id in wxPrintData to set this object's paper size
513 void wxPageSetupDialogData::CalculatePaperSizeFromId()
514 {
515 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
516 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
517
518 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
519
520 // sz is in 10ths of a mm, while paper size is in mm
521 m_paperSize.x = sz.x / 10;
522 m_paperSize.y = sz.y / 10;
523 }
524
525 #endif // wxUSE_PRINTING_ARCHITECTURE