]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
don't do anything before including the PCH header
[wxWidgets.git] / src / common / cmndata.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
e4db172a 2// Name: src/common/cmndata.cpp
c801d85f
KB
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
c801d85f
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
8826f46f 24 #pragma hdrstop
c801d85f
KB
25#endif
26
e4db172a
WS
27#include "wx/cmndata.h"
28
c801d85f 29#ifndef WX_PRECOMP
57bd4c60
WS
30 #if defined(__WXMSW__)
31 #include "wx/msw/wrapcdlg.h"
32 #endif // MSW
8826f46f
VZ
33 #include <stdio.h>
34 #include "wx/string.h"
35 #include "wx/utils.h"
36 #include "wx/app.h"
e4db172a 37 #include "wx/log.h"
dd05139a 38 #include "wx/gdicmn.h"
c801d85f
KB
39#endif
40
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 48#if wxUSE_PRINTING_ARCHITECTURE
c801d85f 49
57bd4c60 50#include "wx/paper.h"
179e085f
RN
51
52#if defined(__WXMAC__)
746d7582
SC
53 #include "wx/mac/private/print.h"
54#endif
55
57bd4c60
WS
56IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
57IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
58IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject)
59
60#endif // wxUSE_PRINTING_ARCHITECTURE
cd0b1709 61
57bd4c60
WS
62IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
63IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
c801d85f 64
8826f46f
VZ
65// ============================================================================
66// implementation
67// ============================================================================
68
69// ----------------------------------------------------------------------------
70// wxColourData
71// ----------------------------------------------------------------------------
c801d85f 72
8bbe427f 73wxColourData::wxColourData()
c801d85f 74{
393c836c 75 m_chooseFull = false;
ae500232 76 m_dataColour.Set(0,0,0);
393c836c 77 // m_custColours are wxNullColours initially
7bcb11d3 78}
c801d85f 79
7bcb11d3 80wxColourData::wxColourData(const wxColourData& data)
5e472c1f 81 : wxObject()
7bcb11d3
JS
82{
83 (*this) = data;
8bbe427f 84}
c801d85f 85
8bbe427f 86wxColourData::~wxColourData()
c801d85f
KB
87{
88}
89
cebf2fec 90void wxColourData::SetCustomColour(int i, const wxColour& colour)
c801d85f 91{
393c836c 92 wxCHECK_RET( (i >= 0 && i < 16), _T("custom colour index out of range") );
8826f46f 93
ae500232 94 m_custColours[i] = colour;
c801d85f
KB
95}
96
97wxColour wxColourData::GetCustomColour(int i)
98{
393c836c
VS
99 wxCHECK_MSG( (i >= 0 && i < 16), wxColour(0,0,0),
100 _T("custom colour index out of range") );
8826f46f 101
ae500232 102 return m_custColours[i];
c801d85f
KB
103}
104
105void wxColourData::operator=(const wxColourData& data)
106{
7bcb11d3
JS
107 int i;
108 for (i = 0; i < 16; i++)
ae500232 109 m_custColours[i] = data.m_custColours[i];
8826f46f 110
ae500232
JS
111 m_dataColour = (wxColour&)data.m_dataColour;
112 m_chooseFull = data.m_chooseFull;
c801d85f
KB
113}
114
8826f46f
VZ
115// ----------------------------------------------------------------------------
116// Font data
117// ----------------------------------------------------------------------------
c801d85f 118
8bbe427f 119wxFontData::wxFontData()
c801d85f 120{
7bcb11d3 121 // Intialize colour to black.
ae500232 122 m_fontColour = wxNullColour;
8826f46f 123
c9d59ee7
WS
124 m_showHelp = false;
125 m_allowSymbols = true;
126 m_enableEffects = true;
ae500232
JS
127 m_minSize = 0;
128 m_maxSize = 0;
c801d85f 129
7beba2fc 130 m_encoding = wxFONTENCODING_SYSTEM;
c801d85f
KB
131}
132
8bbe427f 133wxFontData::~wxFontData()
c801d85f
KB
134{
135}
136
dbc65e27
VZ
137#if wxUSE_FONTDLG
138
139wxFontDialogBase::~wxFontDialogBase()
140{
141}
142
143#endif // wxUSE_FONTDLG
144
88ac883a 145#if wxUSE_PRINTING_ARCHITECTURE
8826f46f
VZ
146// ----------------------------------------------------------------------------
147// Print data
148// ----------------------------------------------------------------------------
c801d85f 149
8bbe427f 150wxPrintData::wxPrintData()
c801d85f 151{
60090256 152 m_bin = wxPRINTBIN_DEFAULT;
781609f2 153 m_media = wxPRINTMEDIA_DEFAULT;
6038ec8e 154 m_printMode = wxPRINT_MODE_PRINTER;
7bcb11d3 155 m_printOrientation = wxPORTRAIT;
c7c6e54b 156 m_printOrientationReversed = false;
7bcb11d3 157 m_printNoCopies = 1;
c9d59ee7 158 m_printCollate = false;
8826f46f 159
7bcb11d3 160 // New, 24/3/99
b494c48b 161 m_printerName = wxEmptyString;
c9d59ee7 162 m_colour = true;
7bcb11d3
JS
163 m_duplexMode = wxDUPLEX_SIMPLEX;
164 m_printQuality = wxPRINT_QUALITY_HIGH;
d5eaa19f
VZ
165
166 // we intentionally don't initialize paper id and size at all, like this
167 // the default system settings will be used for them
168 m_paperId = wxPAPER_NONE;
169 m_paperSize = wxDefaultSize;
7bcb11d3 170
aa96f01c
RR
171 m_privData = NULL;
172 m_privDataLen = 0;
660296aa 173
8850cbd3 174 m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData();
7bcb11d3
JS
175}
176
177wxPrintData::wxPrintData(const wxPrintData& printData)
5e472c1f 178 : wxObject()
7bcb11d3 179{
7b8a9da3 180 m_nativeData = NULL;
7cc52cd8 181 m_privData = NULL;
7bcb11d3 182 (*this) = printData;
c801d85f
KB
183}
184
aa96f01c
RR
185void wxPrintData::SetPrivData( char *privData, int len )
186{
187 if (m_privData)
188 {
189 delete [] m_privData;
190 m_privData = NULL;
191 }
192 m_privDataLen = len;
193 if (m_privDataLen > 0)
194 {
195 m_privData = new char[m_privDataLen];
196 memcpy( m_privData, privData, m_privDataLen );
197 }
198}
199
8bbe427f 200wxPrintData::~wxPrintData()
c801d85f 201{
8850cbd3 202 m_nativeData->m_ref--;
4055ed82 203 if (m_nativeData->m_ref == 0)
8850cbd3 204 delete m_nativeData;
660296aa 205
aa96f01c
RR
206 if (m_privData)
207 delete [] m_privData;
c801d85f
KB
208}
209
51abe921
SC
210void wxPrintData::ConvertToNative()
211{
53fa663a 212 m_nativeData->TransferFrom( *this ) ;
51abe921
SC
213}
214
215void wxPrintData::ConvertFromNative()
216{
53fa663a 217 m_nativeData->TransferTo( *this ) ;
53fa663a 218}
51abe921 219
7bcb11d3
JS
220void wxPrintData::operator=(const wxPrintData& data)
221{
222 m_printNoCopies = data.m_printNoCopies;
223 m_printCollate = data.m_printCollate;
224 m_printOrientation = data.m_printOrientation;
c7c6e54b 225 m_printOrientationReversed = data.m_printOrientationReversed;
7bcb11d3
JS
226 m_printerName = data.m_printerName;
227 m_colour = data.m_colour;
228 m_duplexMode = data.m_duplexMode;
229 m_printQuality = data.m_printQuality;
230 m_paperId = data.m_paperId;
231 m_paperSize = data.m_paperSize;
60090256 232 m_bin = data.m_bin;
781609f2 233 m_media = data.m_media;
6038ec8e 234 m_printMode = data.m_printMode;
4055ed82 235 m_filename = data.m_filename;
aac85509 236
4055ed82 237 // UnRef old m_nativeData
7b8a9da3
RD
238 if (m_nativeData)
239 {
240 m_nativeData->m_ref--;
4055ed82 241 if (m_nativeData->m_ref == 0)
7b8a9da3
RD
242 delete m_nativeData;
243 }
aac85509 244 // Set Ref new one
8850cbd3
RR
245 m_nativeData = data.GetNativeData();
246 m_nativeData->m_ref++;
4055ed82 247
aa96f01c
RR
248 if (m_privData)
249 {
250 delete [] m_privData;
251 m_privData = NULL;
252 }
253 m_privDataLen = data.GetPrivDataLen();
254 if (m_privDataLen > 0)
255 {
256 m_privData = new char[m_privDataLen];
257 memcpy( m_privData, data.GetPrivData(), m_privDataLen );
258 }
7bcb11d3
JS
259}
260
58cf0491 261// Is this data OK for showing the print dialog?
b7cacb43 262bool wxPrintData::IsOk() const
58cf0491 263{
fd64de59 264 m_nativeData->TransferFrom( *this );
8850cbd3
RR
265
266 return m_nativeData->Ok();
58cf0491 267}
8826f46f
VZ
268
269// ----------------------------------------------------------------------------
270// Print dialog data
271// ----------------------------------------------------------------------------
7bcb11d3
JS
272
273wxPrintDialogData::wxPrintDialogData()
274{
7bcb11d3
JS
275 m_printFromPage = 0;
276 m_printToPage = 0;
277 m_printMinPage = 0;
278 m_printMaxPage = 0;
279 m_printNoCopies = 1;
c9d59ee7
WS
280 m_printAllPages = false;
281 m_printCollate = false;
282 m_printToFile = false;
283 m_printSelection = false;
284 m_printEnableSelection = false;
285 m_printEnablePageNumbers = true;
4055ed82 286
9f1316dc
RR
287 wxPrintFactory* factory = wxPrintFactory::GetFactory();
288 m_printEnablePrintToFile = ! factory->HasOwnPrintToFile();
4055ed82 289
c9d59ee7 290 m_printEnableHelp = false;
7bcb11d3
JS
291}
292
293wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
5e472c1f 294 : wxObject()
7bcb11d3
JS
295{
296 (*this) = dialogData;
297}
298
299wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
300{
d2b354f9 301 m_printFromPage = 1;
7bcb11d3 302 m_printToPage = 0;
d2b354f9
JS
303 m_printMinPage = 1;
304 m_printMaxPage = 9999;
7bcb11d3 305 m_printNoCopies = 1;
c9d59ee7
WS
306 m_printAllPages = false;
307 m_printCollate = false;
308 m_printToFile = false;
309 m_printSelection = false;
310 m_printEnableSelection = false;
311 m_printEnablePageNumbers = true;
312 m_printEnablePrintToFile = true;
313 m_printEnableHelp = false;
7bcb11d3
JS
314 m_printData = printData;
315}
316
317wxPrintDialogData::~wxPrintDialogData()
318{
7bcb11d3
JS
319}
320
7bcb11d3 321void wxPrintDialogData::operator=(const wxPrintDialogData& data)
c801d85f 322{
7bcb11d3
JS
323 m_printFromPage = data.m_printFromPage;
324 m_printToPage = data.m_printToPage;
325 m_printMinPage = data.m_printMinPage;
326 m_printMaxPage = data.m_printMaxPage;
327 m_printNoCopies = data.m_printNoCopies;
328 m_printAllPages = data.m_printAllPages;
329 m_printCollate = data.m_printCollate;
330 m_printToFile = data.m_printToFile;
5360828d 331 m_printSelection = data.m_printSelection;
7bcb11d3
JS
332 m_printEnableSelection = data.m_printEnableSelection;
333 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
334 m_printEnableHelp = data.m_printEnableHelp;
335 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
7bcb11d3
JS
336 m_printData = data.m_printData;
337}
338
339void wxPrintDialogData::operator=(const wxPrintData& data)
340{
341 m_printData = data;
c801d85f
KB
342}
343
8826f46f
VZ
344// ----------------------------------------------------------------------------
345// wxPageSetupDialogData
346// ----------------------------------------------------------------------------
c801d85f 347
7bcb11d3 348wxPageSetupDialogData::wxPageSetupDialogData()
c801d85f 349{
c47addef 350 m_paperSize = wxSize(0,0);
7bcb11d3
JS
351
352 CalculatePaperSizeFromId();
353
2997ca30
WS
354 m_minMarginTopLeft =
355 m_minMarginBottomRight =
356 m_marginTopLeft =
c47addef 357 m_marginBottomRight = wxPoint(0,0);
7bcb11d3
JS
358
359 // Flags
c9d59ee7
WS
360 m_defaultMinMargins = false;
361 m_enableMargins = true;
362 m_enableOrientation = true;
363 m_enablePaper = true;
364 m_enablePrinter = true;
365 m_enableHelp = false;
366 m_getDefaultInfo = false;
7bcb11d3 367}
c801d85f 368
7bcb11d3 369wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
5e472c1f 370 : wxObject()
7bcb11d3
JS
371{
372 (*this) = dialogData;
373}
374
375wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
376{
c47addef 377 m_paperSize = wxSize(0,0);
2997ca30
WS
378 m_minMarginTopLeft =
379 m_minMarginBottomRight =
380 m_marginTopLeft =
c47addef 381 m_marginBottomRight = wxPoint(0,0);
7bcb11d3
JS
382
383 // Flags
c9d59ee7
WS
384 m_defaultMinMargins = false;
385 m_enableMargins = true;
386 m_enableOrientation = true;
387 m_enablePaper = true;
388 m_enablePrinter = true;
389 m_enableHelp = false;
390 m_getDefaultInfo = false;
7bcb11d3
JS
391
392 m_printData = printData;
393
394 // The wxPrintData paper size overrides these values, unless the size cannot
395 // be found.
396 CalculatePaperSizeFromId();
c801d85f
KB
397}
398
7bcb11d3 399wxPageSetupDialogData::~wxPageSetupDialogData()
c801d85f 400{
c801d85f
KB
401}
402
5e472c1f 403wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
c801d85f 404{
7bcb11d3
JS
405 m_paperSize = data.m_paperSize;
406 m_minMarginTopLeft = data.m_minMarginTopLeft;
407 m_minMarginBottomRight = data.m_minMarginBottomRight;
408 m_marginTopLeft = data.m_marginTopLeft;
409 m_marginBottomRight = data.m_marginBottomRight;
410 m_defaultMinMargins = data.m_defaultMinMargins;
411 m_enableMargins = data.m_enableMargins;
412 m_enableOrientation = data.m_enableOrientation;
413 m_enablePaper = data.m_enablePaper;
414 m_enablePrinter = data.m_enablePrinter;
d0ee33f5 415 m_getDefaultInfo = data.m_getDefaultInfo;
7bcb11d3
JS
416 m_enableHelp = data.m_enableHelp;
417
418 m_printData = data.m_printData;
5e472c1f
GD
419
420 return *this;
7bcb11d3 421}
c801d85f 422
5e472c1f 423wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
7bcb11d3
JS
424{
425 m_printData = data;
24c5243d 426 CalculatePaperSizeFromId();
5e472c1f
GD
427
428 return *this;
c801d85f
KB
429}
430
7bcb11d3
JS
431// If a corresponding paper type is found in the paper database, will set the m_printData
432// paper size id member as well.
433void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
434{
435 m_paperSize = sz;
c801d85f 436
7bcb11d3
JS
437 CalculateIdFromPaperSize();
438}
c801d85f 439
7bcb11d3
JS
440// Sets the wxPrintData id, plus the paper width/height if found in the paper database.
441void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
442{
443 m_printData.SetPaperId(id);
444
445 CalculatePaperSizeFromId();
c801d85f
KB
446}
447
24c5243d
RD
448void wxPageSetupDialogData::SetPrintData(const wxPrintData& printData)
449{
450 m_printData = printData;
b494c48b 451 CalculatePaperSizeFromId();
24c5243d
RD
452}
453
7bcb11d3
JS
454// Use paper size defined in this object to set the wxPrintData
455// paper id
456void wxPageSetupDialogData::CalculateIdFromPaperSize()
c801d85f 457{
8826f46f 458 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 459 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
c801d85f 460
7bcb11d3
JS
461 wxSize sz = GetPaperSize();
462
463 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
464 if (id != wxPAPER_NONE)
c801d85f 465 {
7bcb11d3 466 m_printData.SetPaperId(id);
c801d85f
KB
467 }
468}
8826f46f 469
7bcb11d3
JS
470// Use paper id in wxPrintData to set this object's paper size
471void wxPageSetupDialogData::CalculatePaperSizeFromId()
472{
8826f46f 473 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 474 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
7bcb11d3
JS
475
476 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
c801d85f 477
01cf2f95
VZ
478 // sz is in 10ths of a mm, while paper size is in mm
479 m_paperSize.x = sz.x / 10;
480 m_paperSize.y = sz.y / 10;
7bcb11d3 481}
8826f46f 482
88ac883a 483#endif // wxUSE_PRINTING_ARCHITECTURE