]> git.saurik.com Git - wxWidgets.git/blob - src/common/cmndata.cpp
Silence warning about truncation since the comment says it ok
[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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include <stdio.h>
29 #include "wx/string.h"
30 #include "wx/utils.h"
31 #include "wx/app.h"
32 #endif
33
34 #include "wx/gdicmn.h"
35 #include "wx/cmndata.h"
36 #include "wx/log.h"
37 #include "wx/prntbase.h"
38 #include "wx/printdlg.h"
39
40 #if wxUSE_FONTDLG
41 #include "wx/fontdlg.h"
42 #endif // wxUSE_FONTDLG
43
44 #if wxUSE_PRINTING_ARCHITECTURE
45 #include "wx/paper.h"
46 #endif // wxUSE_PRINTING_ARCHITECTURE
47
48 #if defined(__WXMSW__)
49 #include "wx/msw/wrapcdlg.h"
50 #endif // MSW
51
52 #if wxUSE_PRINTING_ARCHITECTURE
53
54 #if defined(__WXMAC__)
55 #include "wx/mac/private/print.h"
56 #endif
57
58 IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
59 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
60 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject)
61 #endif // wxUSE_PRINTING_ARCHITECTURE
62
63 IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
64 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
65
66 // ============================================================================
67 // implementation
68 // ============================================================================
69
70 // ----------------------------------------------------------------------------
71 // wxColourData
72 // ----------------------------------------------------------------------------
73
74 wxColourData::wxColourData()
75 {
76 m_chooseFull = false;
77 m_dataColour.Set(0,0,0);
78 // m_custColours are wxNullColours initially
79 }
80
81 wxColourData::wxColourData(const wxColourData& data)
82 : wxObject()
83 {
84 (*this) = data;
85 }
86
87 wxColourData::~wxColourData()
88 {
89 }
90
91 void wxColourData::SetCustomColour(int i, const wxColour& colour)
92 {
93 wxCHECK_RET( (i >= 0 && i < 16), _T("custom colour index out of range") );
94
95 m_custColours[i] = colour;
96 }
97
98 wxColour wxColourData::GetCustomColour(int i)
99 {
100 wxCHECK_MSG( (i >= 0 && i < 16), wxColour(0,0,0),
101 _T("custom colour index out of range") );
102
103 return m_custColours[i];
104 }
105
106 void wxColourData::operator=(const wxColourData& data)
107 {
108 int i;
109 for (i = 0; i < 16; i++)
110 m_custColours[i] = data.m_custColours[i];
111
112 m_dataColour = (wxColour&)data.m_dataColour;
113 m_chooseFull = data.m_chooseFull;
114 }
115
116 // ----------------------------------------------------------------------------
117 // Font data
118 // ----------------------------------------------------------------------------
119
120 wxFontData::wxFontData()
121 {
122 // Intialize colour to black.
123 m_fontColour = wxNullColour;
124
125 m_showHelp = false;
126 m_allowSymbols = true;
127 m_enableEffects = true;
128 m_minSize = 0;
129 m_maxSize = 0;
130
131 m_encoding = wxFONTENCODING_SYSTEM;
132 }
133
134 wxFontData::~wxFontData()
135 {
136 }
137
138 #if wxUSE_FONTDLG
139
140 wxFontDialogBase::~wxFontDialogBase()
141 {
142 }
143
144 #endif // wxUSE_FONTDLG
145
146 #if wxUSE_PRINTING_ARCHITECTURE
147 // ----------------------------------------------------------------------------
148 // Print data
149 // ----------------------------------------------------------------------------
150
151 wxPrintData::wxPrintData()
152 {
153 m_bin = wxPRINTBIN_DEFAULT;
154 m_printMode = wxPRINT_MODE_PRINTER;
155 m_printOrientation = wxPORTRAIT;
156 m_printNoCopies = 1;
157 m_printCollate = false;
158
159 // New, 24/3/99
160 m_printerName = wxEmptyString;
161 m_colour = true;
162 m_duplexMode = wxDUPLEX_SIMPLEX;
163 m_printQuality = wxPRINT_QUALITY_HIGH;
164 m_paperId = wxPAPER_A4;
165 m_paperSize = wxSize(210, 297);
166
167 m_privData = NULL;
168 m_privDataLen = 0;
169
170 m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData();
171 }
172
173 wxPrintData::wxPrintData(const wxPrintData& printData)
174 : wxObject()
175 {
176 m_nativeData = NULL;
177 m_privData = NULL;
178 (*this) = printData;
179 }
180
181 void wxPrintData::SetPrivData( char *privData, int len )
182 {
183 if (m_privData)
184 {
185 delete [] m_privData;
186 m_privData = NULL;
187 }
188 m_privDataLen = len;
189 if (m_privDataLen > 0)
190 {
191 m_privData = new char[m_privDataLen];
192 memcpy( m_privData, privData, m_privDataLen );
193 }
194 }
195
196 wxPrintData::~wxPrintData()
197 {
198 m_nativeData->m_ref--;
199 if (m_nativeData->m_ref == 0)
200 delete m_nativeData;
201
202 if (m_privData)
203 delete [] m_privData;
204 }
205
206 void wxPrintData::ConvertToNative()
207 {
208 m_nativeData->TransferFrom( *this ) ;
209 }
210
211 void wxPrintData::ConvertFromNative()
212 {
213 m_nativeData->TransferTo( *this ) ;
214 }
215
216 void wxPrintData::operator=(const wxPrintData& data)
217 {
218 m_printNoCopies = data.m_printNoCopies;
219 m_printCollate = data.m_printCollate;
220 m_printOrientation = data.m_printOrientation;
221 m_printerName = data.m_printerName;
222 m_colour = data.m_colour;
223 m_duplexMode = data.m_duplexMode;
224 m_printQuality = data.m_printQuality;
225 m_paperId = data.m_paperId;
226 m_paperSize = data.m_paperSize;
227 m_bin = data.m_bin;
228 m_printMode = data.m_printMode;
229 m_filename = data.m_filename;
230
231 // UnRef old m_nativeData
232 if (m_nativeData)
233 {
234 m_nativeData->m_ref--;
235 if (m_nativeData->m_ref == 0)
236 delete m_nativeData;
237 }
238 // Set Ref new one
239 m_nativeData = data.GetNativeData();
240 m_nativeData->m_ref++;
241
242 if (m_privData)
243 {
244 delete [] m_privData;
245 m_privData = NULL;
246 }
247 m_privDataLen = data.GetPrivDataLen();
248 if (m_privDataLen > 0)
249 {
250 m_privData = new char[m_privDataLen];
251 memcpy( m_privData, data.GetPrivData(), m_privDataLen );
252 }
253 }
254
255 // Is this data OK for showing the print dialog?
256 bool wxPrintData::Ok() const
257 {
258 m_nativeData->TransferFrom( *this );
259
260 return m_nativeData->Ok();
261 }
262
263 // What should happen here? wxPostScriptPrintNativeData is not
264 // defined unless all this is true on MSW.
265 #if WXWIN_COMPATIBILITY_2_4 && wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
266
267 #include "wx/generic/prntdlgg.h"
268
269 #if wxUSE_POSTSCRIPT
270 #define WXUNUSED_WITHOUT_PS(name) name
271 #else
272 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
273 #endif
274
275 wxString wxPrintData::GetPrinterCommand() const
276 {
277 #if wxUSE_POSTSCRIPT
278 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
279 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPrinterCommand();
280 #endif
281 return wxEmptyString;
282 }
283
284 wxString wxPrintData::GetPrinterOptions() const
285 {
286 #if wxUSE_POSTSCRIPT
287 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
288 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPrinterOptions();
289 #endif
290 return wxEmptyString;
291 }
292
293 wxString wxPrintData::GetPreviewCommand() const
294 {
295 #if wxUSE_POSTSCRIPT
296 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
297 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPreviewCommand();
298 #endif
299 return wxEmptyString;
300 }
301
302 wxString wxPrintData::GetFontMetricPath() const
303 {
304 #if wxUSE_POSTSCRIPT
305 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
306 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetFontMetricPath();
307 #endif
308 return wxEmptyString;
309 }
310
311 double wxPrintData::GetPrinterScaleX() const
312 {
313 #if wxUSE_POSTSCRIPT
314 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
315 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPrinterScaleX();
316 #endif
317 return 1.0;
318 }
319
320 double wxPrintData::GetPrinterScaleY() const
321 {
322 #if wxUSE_POSTSCRIPT
323 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
324 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPrinterScaleY();
325 #endif
326 return 1.0;
327 }
328
329 long wxPrintData::GetPrinterTranslateX() const
330 {
331 #if wxUSE_POSTSCRIPT
332 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
333 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPrinterTranslateX();
334 #endif
335 return 0;
336 }
337
338 long wxPrintData::GetPrinterTranslateY() const
339 {
340 #if wxUSE_POSTSCRIPT
341 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
342 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPrinterTranslateY();
343 #endif
344 return 0;
345 }
346
347 void wxPrintData::SetPrinterCommand(const wxString& WXUNUSED_WITHOUT_PS(command))
348 {
349 #if wxUSE_POSTSCRIPT
350 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
351 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterCommand( command );
352 #endif
353 }
354
355 void wxPrintData::SetPrinterOptions(const wxString& WXUNUSED_WITHOUT_PS(options))
356 {
357 #if wxUSE_POSTSCRIPT
358 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
359 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterOptions( options );
360 #endif
361 }
362
363 void wxPrintData::SetPreviewCommand(const wxString& WXUNUSED_WITHOUT_PS(command))
364 {
365 #if wxUSE_POSTSCRIPT
366 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
367 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPreviewCommand( command );
368 #endif
369 }
370
371 void wxPrintData::SetFontMetricPath(const wxString& WXUNUSED_WITHOUT_PS(path))
372 {
373 #if wxUSE_POSTSCRIPT
374 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
375 ((wxPostScriptPrintNativeData*)m_nativeData)->SetFontMetricPath( path );
376 #endif
377 }
378
379 void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x))
380 {
381 #if wxUSE_POSTSCRIPT
382 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
383 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterScaleX( x );
384 #endif
385 }
386
387 void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y))
388 {
389 #if wxUSE_POSTSCRIPT
390 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
391 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterScaleY( y );
392 #endif
393 }
394
395 void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x), double WXUNUSED_WITHOUT_PS(y))
396 {
397 #if wxUSE_POSTSCRIPT
398 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
399 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterScaling( x, y );
400 #endif
401 }
402
403 void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x))
404 {
405 #if wxUSE_POSTSCRIPT
406 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
407 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterTranslateX( x );
408 #endif
409 }
410
411 void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y))
412 {
413 #if wxUSE_POSTSCRIPT
414 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
415 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterTranslateY( y );
416 #endif
417 }
418
419 void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x), long WXUNUSED_WITHOUT_PS(y))
420 {
421 #if wxUSE_POSTSCRIPT
422 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
423 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterTranslation( x, y );
424 #endif
425 }
426 #endif
427
428 // ----------------------------------------------------------------------------
429 // Print dialog data
430 // ----------------------------------------------------------------------------
431
432 wxPrintDialogData::wxPrintDialogData()
433 {
434 m_printFromPage = 0;
435 m_printToPage = 0;
436 m_printMinPage = 0;
437 m_printMaxPage = 0;
438 m_printNoCopies = 1;
439 m_printAllPages = false;
440 m_printCollate = false;
441 m_printToFile = false;
442 m_printSelection = false;
443 m_printEnableSelection = false;
444 m_printEnablePageNumbers = true;
445
446 wxPrintFactory* factory = wxPrintFactory::GetFactory();
447 m_printEnablePrintToFile = ! factory->HasOwnPrintToFile();
448
449 m_printEnableHelp = false;
450 #if WXWIN_COMPATIBILITY_2_4
451 m_printSetupDialog = false;
452 #endif
453 }
454
455 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
456 : wxObject()
457 {
458 (*this) = dialogData;
459 }
460
461 wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
462 {
463 m_printFromPage = 1;
464 m_printToPage = 0;
465 m_printMinPage = 1;
466 m_printMaxPage = 9999;
467 m_printNoCopies = 1;
468 m_printAllPages = false;
469 m_printCollate = false;
470 m_printToFile = false;
471 m_printSelection = false;
472 m_printEnableSelection = false;
473 m_printEnablePageNumbers = true;
474 m_printEnablePrintToFile = true;
475 m_printEnableHelp = false;
476 #if WXWIN_COMPATIBILITY_2_4
477 m_printSetupDialog = false;
478 #endif
479 m_printData = printData;
480 }
481
482 wxPrintDialogData::~wxPrintDialogData()
483 {
484 }
485
486 void wxPrintDialogData::operator=(const wxPrintDialogData& data)
487 {
488 m_printFromPage = data.m_printFromPage;
489 m_printToPage = data.m_printToPage;
490 m_printMinPage = data.m_printMinPage;
491 m_printMaxPage = data.m_printMaxPage;
492 m_printNoCopies = data.m_printNoCopies;
493 m_printAllPages = data.m_printAllPages;
494 m_printCollate = data.m_printCollate;
495 m_printToFile = data.m_printToFile;
496 m_printSelection = data.m_printSelection;
497 m_printEnableSelection = data.m_printEnableSelection;
498 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
499 m_printEnableHelp = data.m_printEnableHelp;
500 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
501 #if WXWIN_COMPATIBILITY_2_4
502 m_printSetupDialog = data.m_printSetupDialog;
503 #endif
504 m_printData = data.m_printData;
505 }
506
507 void wxPrintDialogData::operator=(const wxPrintData& data)
508 {
509 m_printData = data;
510 }
511
512 // ----------------------------------------------------------------------------
513 // wxPageSetupDialogData
514 // ----------------------------------------------------------------------------
515
516 wxPageSetupDialogData::wxPageSetupDialogData()
517 {
518 m_paperSize = wxSize(0,0);
519
520 CalculatePaperSizeFromId();
521
522 m_minMarginTopLeft =
523 m_minMarginBottomRight =
524 m_marginTopLeft =
525 m_marginBottomRight = wxPoint(0,0);
526
527 // Flags
528 m_defaultMinMargins = false;
529 m_enableMargins = true;
530 m_enableOrientation = true;
531 m_enablePaper = true;
532 m_enablePrinter = true;
533 m_enableHelp = false;
534 m_getDefaultInfo = false;
535 }
536
537 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
538 : wxObject()
539 {
540 (*this) = dialogData;
541 }
542
543 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
544 {
545 m_paperSize = wxSize(0,0);
546 m_minMarginTopLeft =
547 m_minMarginBottomRight =
548 m_marginTopLeft =
549 m_marginBottomRight = wxPoint(0,0);
550
551 // Flags
552 m_defaultMinMargins = false;
553 m_enableMargins = true;
554 m_enableOrientation = true;
555 m_enablePaper = true;
556 m_enablePrinter = true;
557 m_enableHelp = false;
558 m_getDefaultInfo = false;
559
560 m_printData = printData;
561
562 // The wxPrintData paper size overrides these values, unless the size cannot
563 // be found.
564 CalculatePaperSizeFromId();
565 }
566
567 wxPageSetupDialogData::~wxPageSetupDialogData()
568 {
569 }
570
571 wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
572 {
573 m_paperSize = data.m_paperSize;
574 m_minMarginTopLeft = data.m_minMarginTopLeft;
575 m_minMarginBottomRight = data.m_minMarginBottomRight;
576 m_marginTopLeft = data.m_marginTopLeft;
577 m_marginBottomRight = data.m_marginBottomRight;
578 m_defaultMinMargins = data.m_defaultMinMargins;
579 m_enableMargins = data.m_enableMargins;
580 m_enableOrientation = data.m_enableOrientation;
581 m_enablePaper = data.m_enablePaper;
582 m_enablePrinter = data.m_enablePrinter;
583 m_getDefaultInfo = data.m_getDefaultInfo;
584 m_enableHelp = data.m_enableHelp;
585
586 m_printData = data.m_printData;
587
588 return *this;
589 }
590
591 wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
592 {
593 m_printData = data;
594 CalculatePaperSizeFromId();
595
596 return *this;
597 }
598
599 // If a corresponding paper type is found in the paper database, will set the m_printData
600 // paper size id member as well.
601 void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
602 {
603 m_paperSize = sz;
604
605 CalculateIdFromPaperSize();
606 }
607
608 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
609 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
610 {
611 m_printData.SetPaperId(id);
612
613 CalculatePaperSizeFromId();
614 }
615
616 void wxPageSetupDialogData::SetPrintData(const wxPrintData& printData)
617 {
618 m_printData = printData;
619 CalculatePaperSizeFromId();
620 }
621
622 // Use paper size defined in this object to set the wxPrintData
623 // paper id
624 void wxPageSetupDialogData::CalculateIdFromPaperSize()
625 {
626 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
627 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
628
629 wxSize sz = GetPaperSize();
630
631 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
632 if (id != wxPAPER_NONE)
633 {
634 m_printData.SetPaperId(id);
635 }
636 }
637
638 // Use paper id in wxPrintData to set this object's paper size
639 void wxPageSetupDialogData::CalculatePaperSizeFromId()
640 {
641 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
642 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
643
644 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
645
646 // sz is in 10ths of a mm, while paper size is in mm
647 m_paperSize.x = sz.x / 10;
648 m_paperSize.y = sz.y / 10;
649 }
650
651 #endif // wxUSE_PRINTING_ARCHITECTURE