]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
fixup
[wxWidgets.git] / src / common / cmndata.cpp
CommitLineData
c801d85f
KB
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$
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
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
8826f46f 21 #pragma implementation "cmndata.h"
c801d85f
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
8826f46f 28 #pragma hdrstop
c801d85f
KB
29#endif
30
31#ifndef WX_PRECOMP
8826f46f
VZ
32 #include <stdio.h>
33 #include "wx/string.h"
34 #include "wx/utils.h"
35 #include "wx/app.h"
c801d85f
KB
36#endif
37
38#include "wx/gdicmn.h"
39#include "wx/cmndata.h"
6776a0b2 40#include "wx/log.h"
8850cbd3
RR
41#include "wx/prntbase.h"
42#include "wx/printdlg.h"
8826f46f 43
dbc65e27
VZ
44#if wxUSE_FONTDLG
45 #include "wx/fontdlg.h"
46#endif // wxUSE_FONTDLG
47
88ac883a
VZ
48#if wxUSE_PRINTING_ARCHITECTURE
49 #include "wx/paper.h"
88ac883a 50#endif // wxUSE_PRINTING_ARCHITECTURE
7be1f0d9 51
ffecfa5a 52#if defined(__WXMSW__) && !defined(__PALMOS__)
1c193821 53 #include <windowsx.h>
3096bd2f 54 #include "wx/msw/private.h"
7be1f0d9 55
0c44ec97 56 #ifndef __SMARTPHONE__ /* of WinCE */
8826f46f 57 #include <commdlg.h>
1c193821 58 #endif
8826f46f 59
2bdf7154 60 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
8826f46f
VZ
61 #include <windowsx.h>
62 #include <commdlg.h>
63 #endif
64#endif // MSW
c801d85f 65
746d7582
SC
66#ifdef __WXMAC__
67 #include "wx/mac/private/print.h"
68#endif
69
88ac883a
VZ
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
cd0b1709 75
8826f46f
VZ
76 IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
77 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
c801d85f 78
83e72d5f
GT
79#ifndef DMPAPER_USER
80 #define DMPAPER_USER 256
81#endif
82
8826f46f
VZ
83// ============================================================================
84// implementation
85// ============================================================================
86
87// ----------------------------------------------------------------------------
88// wxColourData
89// ----------------------------------------------------------------------------
c801d85f 90
8bbe427f 91wxColourData::wxColourData()
c801d85f 92{
393c836c 93 m_chooseFull = false;
ae500232 94 m_dataColour.Set(0,0,0);
393c836c 95 // m_custColours are wxNullColours initially
7bcb11d3 96}
c801d85f 97
7bcb11d3 98wxColourData::wxColourData(const wxColourData& data)
5e472c1f 99 : wxObject()
7bcb11d3
JS
100{
101 (*this) = data;
8bbe427f 102}
c801d85f 103
8bbe427f 104wxColourData::~wxColourData()
c801d85f
KB
105{
106}
107
cebf2fec 108void wxColourData::SetCustomColour(int i, const wxColour& colour)
c801d85f 109{
393c836c 110 wxCHECK_RET( (i >= 0 && i < 16), _T("custom colour index out of range") );
8826f46f 111
ae500232 112 m_custColours[i] = colour;
c801d85f
KB
113}
114
115wxColour wxColourData::GetCustomColour(int i)
116{
393c836c
VS
117 wxCHECK_MSG( (i >= 0 && i < 16), wxColour(0,0,0),
118 _T("custom colour index out of range") );
8826f46f 119
ae500232 120 return m_custColours[i];
c801d85f
KB
121}
122
123void wxColourData::operator=(const wxColourData& data)
124{
7bcb11d3
JS
125 int i;
126 for (i = 0; i < 16; i++)
ae500232 127 m_custColours[i] = data.m_custColours[i];
8826f46f 128
ae500232
JS
129 m_dataColour = (wxColour&)data.m_dataColour;
130 m_chooseFull = data.m_chooseFull;
c801d85f
KB
131}
132
8826f46f
VZ
133// ----------------------------------------------------------------------------
134// Font data
135// ----------------------------------------------------------------------------
c801d85f 136
8bbe427f 137wxFontData::wxFontData()
c801d85f 138{
7bcb11d3 139 // Intialize colour to black.
ae500232 140 m_fontColour = wxNullColour;
8826f46f 141
c9d59ee7
WS
142 m_showHelp = false;
143 m_allowSymbols = true;
144 m_enableEffects = true;
ae500232
JS
145 m_minSize = 0;
146 m_maxSize = 0;
c801d85f 147
7beba2fc 148 m_encoding = wxFONTENCODING_SYSTEM;
c801d85f
KB
149}
150
8bbe427f 151wxFontData::~wxFontData()
c801d85f
KB
152{
153}
154
dbc65e27
VZ
155#if wxUSE_FONTDLG
156
157wxFontDialogBase::~wxFontDialogBase()
158{
159}
160
161#endif // wxUSE_FONTDLG
162
88ac883a 163#if wxUSE_PRINTING_ARCHITECTURE
8826f46f
VZ
164// ----------------------------------------------------------------------------
165// Print data
166// ----------------------------------------------------------------------------
c801d85f 167
8bbe427f 168wxPrintData::wxPrintData()
c801d85f 169{
8850cbd3 170#ifdef __WXMAC__
746d7582 171 m_nativePrintData = wxNativePrintData::Create() ;
c801d85f 172#endif
60090256 173 m_bin = wxPRINTBIN_DEFAULT;
6038ec8e 174 m_printMode = wxPRINT_MODE_PRINTER;
7bcb11d3
JS
175 m_printOrientation = wxPORTRAIT;
176 m_printNoCopies = 1;
c9d59ee7 177 m_printCollate = false;
8826f46f 178
7bcb11d3 179 // New, 24/3/99
2b5f62a0 180 m_printerName = wxT("");
c9d59ee7 181 m_colour = true;
7bcb11d3
JS
182 m_duplexMode = wxDUPLEX_SIMPLEX;
183 m_printQuality = wxPRINT_QUALITY_HIGH;
184 m_paperId = wxPAPER_A4;
185 m_paperSize = wxSize(210, 297);
186
8850cbd3 187 m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData();
7bcb11d3
JS
188}
189
190wxPrintData::wxPrintData(const wxPrintData& printData)
5e472c1f 191 : wxObject()
7bcb11d3
JS
192{
193 (*this) = printData;
c801d85f
KB
194}
195
8bbe427f 196wxPrintData::~wxPrintData()
c801d85f 197{
8850cbd3
RR
198 m_nativeData->m_ref--;
199 if (m_nativeData->m_ref == 0)
200 delete m_nativeData;
201
202#ifdef __WXMAC__
746d7582 203 delete m_nativePrintData ;
c801d85f
KB
204#endif
205}
206
7bcb11d3 207
51abe921
SC
208void wxPrintData::ConvertToNative()
209{
53fa663a 210#ifdef __WXMAC__
746d7582 211 m_nativePrintData->TransferFrom( this ) ;
53fa663a
RR
212#else
213 m_nativeData->TransferFrom( *this ) ;
214#endif
51abe921
SC
215}
216
217void wxPrintData::ConvertFromNative()
218{
53fa663a 219#ifdef __WXMAC__
746d7582 220 m_nativePrintData->TransferTo( this ) ;
53fa663a
RR
221#else
222 m_nativeData->TransferTo( *this ) ;
51abe921 223#endif
53fa663a 224}
51abe921 225
7bcb11d3
JS
226void 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;
60090256 237 m_bin = data.m_bin;
6038ec8e 238 m_printMode = data.m_printMode;
01b5396f 239 m_filename = data.m_filename;
aac85509
RR
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
8850cbd3
RR
246 m_nativeData = data.GetNativeData();
247 m_nativeData->m_ref++;
248
249#ifdef __WXMAC__
250 m_nativePrintData->CopyFrom( data.m_nativePrintData ) ;
244e5e34 251#endif
7bcb11d3
JS
252}
253
58cf0491
JS
254// Is this data OK for showing the print dialog?
255bool wxPrintData::Ok() const
256{
fd64de59 257 m_nativeData->TransferFrom( *this );
8850cbd3
RR
258
259 return m_nativeData->Ok();
58cf0491 260}
8826f46f
VZ
261
262// ----------------------------------------------------------------------------
263// Print dialog data
264// ----------------------------------------------------------------------------
7bcb11d3
JS
265
266wxPrintDialogData::wxPrintDialogData()
267{
7bcb11d3
JS
268 m_printFromPage = 0;
269 m_printToPage = 0;
270 m_printMinPage = 0;
271 m_printMaxPage = 0;
272 m_printNoCopies = 1;
c9d59ee7
WS
273 m_printAllPages = false;
274 m_printCollate = false;
275 m_printToFile = false;
276 m_printSelection = false;
277 m_printEnableSelection = false;
278 m_printEnablePageNumbers = true;
9f1316dc
RR
279
280 wxPrintFactory* factory = wxPrintFactory::GetFactory();
281 m_printEnablePrintToFile = ! factory->HasOwnPrintToFile();
282
c9d59ee7 283 m_printEnableHelp = false;
b45dfd0a 284#if WXWIN_COMPATIBILITY_2_4
c9d59ee7 285 m_printSetupDialog = false;
b45dfd0a 286#endif
7bcb11d3
JS
287}
288
289wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
5e472c1f 290 : wxObject()
7bcb11d3
JS
291{
292 (*this) = dialogData;
293}
294
295wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
296{
d2b354f9 297 m_printFromPage = 1;
7bcb11d3 298 m_printToPage = 0;
d2b354f9
JS
299 m_printMinPage = 1;
300 m_printMaxPage = 9999;
7bcb11d3 301 m_printNoCopies = 1;
c9d59ee7
WS
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;
b45dfd0a 310#if WXWIN_COMPATIBILITY_2_4
c9d59ee7 311 m_printSetupDialog = false;
b45dfd0a 312#endif
7bcb11d3
JS
313 m_printData = printData;
314}
315
316wxPrintDialogData::~wxPrintDialogData()
317{
7bcb11d3
JS
318}
319
51abe921 320#ifdef __WXMAC__
cfb00da4 321
51abe921
SC
322void wxPrintDialogData::ConvertToNative()
323{
cfb00da4 324 m_printData.ConvertToNative();
746d7582 325 m_printData.m_nativePrintData->TransferFrom( this ) ;
51abe921
SC
326}
327
328void wxPrintDialogData::ConvertFromNative()
329{
cfb00da4 330 m_printData.ConvertFromNative();
746d7582 331 m_printData.m_nativePrintData->TransferTo( this ) ;
51abe921 332}
cfb00da4 333
51abe921
SC
334#endif
335
336
7bcb11d3 337void wxPrintDialogData::operator=(const wxPrintDialogData& data)
c801d85f 338{
7bcb11d3
JS
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;
5360828d 347 m_printSelection = data.m_printSelection;
7bcb11d3
JS
348 m_printEnableSelection = data.m_printEnableSelection;
349 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
350 m_printEnableHelp = data.m_printEnableHelp;
351 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
b45dfd0a 352#if WXWIN_COMPATIBILITY_2_4
7bcb11d3 353 m_printSetupDialog = data.m_printSetupDialog;
b45dfd0a 354#endif
7bcb11d3
JS
355 m_printData = data.m_printData;
356}
357
358void wxPrintDialogData::operator=(const wxPrintData& data)
359{
360 m_printData = data;
c801d85f
KB
361}
362
8826f46f
VZ
363// ----------------------------------------------------------------------------
364// wxPageSetupDialogData
365// ----------------------------------------------------------------------------
c801d85f 366
7bcb11d3 367wxPageSetupDialogData::wxPageSetupDialogData()
c801d85f 368{
7bcb11d3
JS
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
c9d59ee7
WS
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;
7bcb11d3 386}
c801d85f 387
7bcb11d3 388wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
5e472c1f 389 : wxObject()
7bcb11d3
JS
390{
391 (*this) = dialogData;
392}
393
394wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
395{
7bcb11d3
JS
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
c9d59ee7
WS
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;
7bcb11d3
JS
410
411 m_printData = printData;
412
413 // The wxPrintData paper size overrides these values, unless the size cannot
414 // be found.
415 CalculatePaperSizeFromId();
c801d85f
KB
416}
417
7bcb11d3 418wxPageSetupDialogData::~wxPageSetupDialogData()
c801d85f 419{
c801d85f
KB
420}
421
5e472c1f 422wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
c801d85f 423{
7bcb11d3
JS
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;
5e472c1f
GD
438
439 return *this;
7bcb11d3 440}
c801d85f 441
5e472c1f 442wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
7bcb11d3
JS
443{
444 m_printData = data;
5e472c1f
GD
445
446 return *this;
c801d85f
KB
447}
448
51abe921 449#ifdef __WXMAC__
7c74e7fe 450void wxPageSetupDialogData::ConvertToNative()
51abe921 451{
161f4f73 452 m_printData.ConvertToNative();
746d7582 453 m_printData.m_nativePrintData->TransferFrom( this ) ;
51abe921
SC
454}
455
7c74e7fe 456void wxPageSetupDialogData::ConvertFromNative()
51abe921 457{
161f4f73 458 m_printData.ConvertFromNative ();
cfb00da4
SC
459 m_paperSize = m_printData.GetPaperSize() ;
460 CalculateIdFromPaperSize();
746d7582 461 m_printData.m_nativePrintData->TransferTo( this ) ;
161f4f73 462 // adjust minimal values
161f4f73
VZ
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;
51abe921
SC
475}
476#endif
477
478
7bcb11d3
JS
479// If a corresponding paper type is found in the paper database, will set the m_printData
480// paper size id member as well.
481void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
482{
483 m_paperSize = sz;
c801d85f 484
7bcb11d3
JS
485 CalculateIdFromPaperSize();
486}
c801d85f 487
7bcb11d3
JS
488// Sets the wxPrintData id, plus the paper width/height if found in the paper database.
489void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
490{
491 m_printData.SetPaperId(id);
492
493 CalculatePaperSizeFromId();
c801d85f
KB
494}
495
7bcb11d3
JS
496// Use paper size defined in this object to set the wxPrintData
497// paper id
498void wxPageSetupDialogData::CalculateIdFromPaperSize()
c801d85f 499{
8826f46f 500 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 501 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
c801d85f 502
7bcb11d3
JS
503 wxSize sz = GetPaperSize();
504
505 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
506 if (id != wxPAPER_NONE)
c801d85f 507 {
7bcb11d3 508 m_printData.SetPaperId(id);
c801d85f
KB
509 }
510}
8826f46f 511
7bcb11d3
JS
512// Use paper id in wxPrintData to set this object's paper size
513void wxPageSetupDialogData::CalculatePaperSizeFromId()
514{
8826f46f 515 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 516 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
7bcb11d3
JS
517
518 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
c801d85f 519
01cf2f95
VZ
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;
7bcb11d3 523}
8826f46f 524
88ac883a 525#endif // wxUSE_PRINTING_ARCHITECTURE