]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
Fix tracking rectangles in 64-bit build by remembering the tag as the 64-bit integer...
[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)
5cd0202b 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{
559843f0 92 wxCHECK_RET( i >= 0 && i < NUM_CUSTOM, _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{
559843f0 99 wxCHECK_MSG( i >= 0 && i < NUM_CUSTOM, wxColour(0,0,0),
393c836c 100 _T("custom colour index out of range") );
8826f46f 101
ae500232 102 return m_custColours[i];
c801d85f
KB
103}
104
5cd0202b 105wxColourData& wxColourData::operator=(const wxColourData& data)
c801d85f 106{
559843f0 107 for ( int i = 0; i < NUM_CUSTOM; i++)
ae500232 108 m_custColours[i] = data.m_custColours[i];
8826f46f 109
e6ef9ea4 110 m_dataColour = data.m_dataColour;
ae500232 111 m_chooseFull = data.m_chooseFull;
5cd0202b
VZ
112
113 return *this;
c801d85f
KB
114}
115
e6ef9ea4
VZ
116// ----------------------------------------------------------------------------
117// [de]serialization
118// ----------------------------------------------------------------------------
119
120// separator used between different fields
121static const char wxCOL_DATA_SEP = ',';
122
123wxString wxColourData::ToString() const
124{
125 wxString str(m_chooseFull ? '1' : '0');
126
559843f0 127 for ( int i = 0; i < NUM_CUSTOM; i++ )
e6ef9ea4
VZ
128 {
129 str += wxCOL_DATA_SEP;
130
131 const wxColour& clr = m_custColours[i];
132 if ( clr.IsOk() )
133 str += clr.GetAsString(wxC2S_HTML_SYNTAX);
134 }
135
136 return str;
137}
138
139bool wxColourData::FromString(const wxString& str)
140{
141 wxString token;
142 int n = -1; // index of the field, -1 corresponds to m_chooseFull
143 for ( wxString::const_iterator i = str.begin(); i != str.end(); ++i )
144 {
145 if ( *i == wxCOL_DATA_SEP )
146 {
147 if ( n == -1 )
148 {
149 if ( token == '0' )
150 m_chooseFull = false;
151 else if ( token == '1' )
152 m_chooseFull = true;
153 else // only '0' and '1' are used in ToString()
154 return false;
155 }
156 else // custom colour
157 {
158 if ( n == WXSIZEOF(m_custColours) )
159 return false; // too many custom colours
160
161 // empty strings are used by ToString() for colours not used
162 if ( token.empty() )
163 m_custColours[n] = wxNullColour;
164 else if ( !m_custColours[n].Set(token) )
165 return false; // invalid colour string
166 }
167
168 token.clear();
169 n++;
170 }
171 else // continuation of the current field
172 {
173 token += *i;
174 }
175 }
176
177 return true;
178}
179
8826f46f
VZ
180// ----------------------------------------------------------------------------
181// Font data
182// ----------------------------------------------------------------------------
c801d85f 183
8bbe427f 184wxFontData::wxFontData()
c801d85f 185{
7bcb11d3 186 // Intialize colour to black.
ae500232 187 m_fontColour = wxNullColour;
8826f46f 188
c9d59ee7
WS
189 m_showHelp = false;
190 m_allowSymbols = true;
191 m_enableEffects = true;
ae500232
JS
192 m_minSize = 0;
193 m_maxSize = 0;
c801d85f 194
7beba2fc 195 m_encoding = wxFONTENCODING_SYSTEM;
c801d85f
KB
196}
197
8bbe427f 198wxFontData::~wxFontData()
c801d85f
KB
199{
200}
201
dbc65e27
VZ
202#if wxUSE_FONTDLG
203
204wxFontDialogBase::~wxFontDialogBase()
205{
206}
207
208#endif // wxUSE_FONTDLG
209
88ac883a 210#if wxUSE_PRINTING_ARCHITECTURE
8826f46f
VZ
211// ----------------------------------------------------------------------------
212// Print data
213// ----------------------------------------------------------------------------
c801d85f 214
8bbe427f 215wxPrintData::wxPrintData()
c801d85f 216{
60090256 217 m_bin = wxPRINTBIN_DEFAULT;
781609f2 218 m_media = wxPRINTMEDIA_DEFAULT;
6038ec8e 219 m_printMode = wxPRINT_MODE_PRINTER;
7bcb11d3 220 m_printOrientation = wxPORTRAIT;
c7c6e54b 221 m_printOrientationReversed = false;
7bcb11d3 222 m_printNoCopies = 1;
c9d59ee7 223 m_printCollate = false;
8826f46f 224
7bcb11d3 225 // New, 24/3/99
b494c48b 226 m_printerName = wxEmptyString;
c9d59ee7 227 m_colour = true;
7bcb11d3
JS
228 m_duplexMode = wxDUPLEX_SIMPLEX;
229 m_printQuality = wxPRINT_QUALITY_HIGH;
d5eaa19f
VZ
230
231 // we intentionally don't initialize paper id and size at all, like this
232 // the default system settings will be used for them
233 m_paperId = wxPAPER_NONE;
234 m_paperSize = wxDefaultSize;
7bcb11d3 235
aa96f01c
RR
236 m_privData = NULL;
237 m_privDataLen = 0;
660296aa 238
8850cbd3 239 m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData();
7bcb11d3
JS
240}
241
242wxPrintData::wxPrintData(const wxPrintData& printData)
5e472c1f 243 : wxObject()
7bcb11d3 244{
7b8a9da3 245 m_nativeData = NULL;
7cc52cd8 246 m_privData = NULL;
7bcb11d3 247 (*this) = printData;
c801d85f
KB
248}
249
aa96f01c
RR
250void wxPrintData::SetPrivData( char *privData, int len )
251{
252 if (m_privData)
253 {
254 delete [] m_privData;
255 m_privData = NULL;
256 }
257 m_privDataLen = len;
258 if (m_privDataLen > 0)
259 {
260 m_privData = new char[m_privDataLen];
261 memcpy( m_privData, privData, m_privDataLen );
262 }
263}
264
8bbe427f 265wxPrintData::~wxPrintData()
c801d85f 266{
8850cbd3 267 m_nativeData->m_ref--;
4055ed82 268 if (m_nativeData->m_ref == 0)
8850cbd3 269 delete m_nativeData;
660296aa 270
aa96f01c
RR
271 if (m_privData)
272 delete [] m_privData;
c801d85f
KB
273}
274
51abe921
SC
275void wxPrintData::ConvertToNative()
276{
53fa663a 277 m_nativeData->TransferFrom( *this ) ;
51abe921
SC
278}
279
280void wxPrintData::ConvertFromNative()
281{
53fa663a 282 m_nativeData->TransferTo( *this ) ;
53fa663a 283}
51abe921 284
7bcb11d3
JS
285void wxPrintData::operator=(const wxPrintData& data)
286{
287 m_printNoCopies = data.m_printNoCopies;
288 m_printCollate = data.m_printCollate;
289 m_printOrientation = data.m_printOrientation;
c7c6e54b 290 m_printOrientationReversed = data.m_printOrientationReversed;
7bcb11d3
JS
291 m_printerName = data.m_printerName;
292 m_colour = data.m_colour;
293 m_duplexMode = data.m_duplexMode;
294 m_printQuality = data.m_printQuality;
295 m_paperId = data.m_paperId;
296 m_paperSize = data.m_paperSize;
60090256 297 m_bin = data.m_bin;
781609f2 298 m_media = data.m_media;
6038ec8e 299 m_printMode = data.m_printMode;
4055ed82 300 m_filename = data.m_filename;
aac85509 301
4055ed82 302 // UnRef old m_nativeData
7b8a9da3
RD
303 if (m_nativeData)
304 {
305 m_nativeData->m_ref--;
4055ed82 306 if (m_nativeData->m_ref == 0)
7b8a9da3
RD
307 delete m_nativeData;
308 }
aac85509 309 // Set Ref new one
8850cbd3
RR
310 m_nativeData = data.GetNativeData();
311 m_nativeData->m_ref++;
4055ed82 312
aa96f01c
RR
313 if (m_privData)
314 {
315 delete [] m_privData;
316 m_privData = NULL;
317 }
318 m_privDataLen = data.GetPrivDataLen();
319 if (m_privDataLen > 0)
320 {
321 m_privData = new char[m_privDataLen];
322 memcpy( m_privData, data.GetPrivData(), m_privDataLen );
323 }
7bcb11d3
JS
324}
325
58cf0491 326// Is this data OK for showing the print dialog?
b7cacb43 327bool wxPrintData::IsOk() const
58cf0491 328{
fd64de59 329 m_nativeData->TransferFrom( *this );
8850cbd3
RR
330
331 return m_nativeData->Ok();
58cf0491 332}
8826f46f
VZ
333
334// ----------------------------------------------------------------------------
335// Print dialog data
336// ----------------------------------------------------------------------------
7bcb11d3
JS
337
338wxPrintDialogData::wxPrintDialogData()
339{
7bcb11d3
JS
340 m_printFromPage = 0;
341 m_printToPage = 0;
342 m_printMinPage = 0;
343 m_printMaxPage = 0;
344 m_printNoCopies = 1;
c9d59ee7
WS
345 m_printAllPages = false;
346 m_printCollate = false;
347 m_printToFile = false;
348 m_printSelection = false;
349 m_printEnableSelection = false;
350 m_printEnablePageNumbers = true;
4055ed82 351
9f1316dc
RR
352 wxPrintFactory* factory = wxPrintFactory::GetFactory();
353 m_printEnablePrintToFile = ! factory->HasOwnPrintToFile();
4055ed82 354
c9d59ee7 355 m_printEnableHelp = false;
7bcb11d3
JS
356}
357
358wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
5e472c1f 359 : wxObject()
7bcb11d3
JS
360{
361 (*this) = dialogData;
362}
363
364wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
365{
d2b354f9 366 m_printFromPage = 1;
7bcb11d3 367 m_printToPage = 0;
d2b354f9
JS
368 m_printMinPage = 1;
369 m_printMaxPage = 9999;
7bcb11d3 370 m_printNoCopies = 1;
c9d59ee7
WS
371 m_printAllPages = false;
372 m_printCollate = false;
373 m_printToFile = false;
374 m_printSelection = false;
375 m_printEnableSelection = false;
376 m_printEnablePageNumbers = true;
377 m_printEnablePrintToFile = true;
378 m_printEnableHelp = false;
7bcb11d3
JS
379 m_printData = printData;
380}
381
382wxPrintDialogData::~wxPrintDialogData()
383{
7bcb11d3
JS
384}
385
7bcb11d3 386void wxPrintDialogData::operator=(const wxPrintDialogData& data)
c801d85f 387{
7bcb11d3
JS
388 m_printFromPage = data.m_printFromPage;
389 m_printToPage = data.m_printToPage;
390 m_printMinPage = data.m_printMinPage;
391 m_printMaxPage = data.m_printMaxPage;
392 m_printNoCopies = data.m_printNoCopies;
393 m_printAllPages = data.m_printAllPages;
394 m_printCollate = data.m_printCollate;
395 m_printToFile = data.m_printToFile;
5360828d 396 m_printSelection = data.m_printSelection;
7bcb11d3
JS
397 m_printEnableSelection = data.m_printEnableSelection;
398 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
399 m_printEnableHelp = data.m_printEnableHelp;
400 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
7bcb11d3
JS
401 m_printData = data.m_printData;
402}
403
404void wxPrintDialogData::operator=(const wxPrintData& data)
405{
406 m_printData = data;
c801d85f
KB
407}
408
8826f46f
VZ
409// ----------------------------------------------------------------------------
410// wxPageSetupDialogData
411// ----------------------------------------------------------------------------
c801d85f 412
7bcb11d3 413wxPageSetupDialogData::wxPageSetupDialogData()
c801d85f 414{
c47addef 415 m_paperSize = wxSize(0,0);
7bcb11d3
JS
416
417 CalculatePaperSizeFromId();
418
2997ca30
WS
419 m_minMarginTopLeft =
420 m_minMarginBottomRight =
421 m_marginTopLeft =
c47addef 422 m_marginBottomRight = wxPoint(0,0);
7bcb11d3
JS
423
424 // Flags
c9d59ee7
WS
425 m_defaultMinMargins = false;
426 m_enableMargins = true;
427 m_enableOrientation = true;
428 m_enablePaper = true;
429 m_enablePrinter = true;
430 m_enableHelp = false;
431 m_getDefaultInfo = false;
7bcb11d3 432}
c801d85f 433
7bcb11d3 434wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
5e472c1f 435 : wxObject()
7bcb11d3
JS
436{
437 (*this) = dialogData;
438}
439
440wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
441{
c47addef 442 m_paperSize = wxSize(0,0);
2997ca30
WS
443 m_minMarginTopLeft =
444 m_minMarginBottomRight =
445 m_marginTopLeft =
c47addef 446 m_marginBottomRight = wxPoint(0,0);
7bcb11d3
JS
447
448 // Flags
c9d59ee7
WS
449 m_defaultMinMargins = false;
450 m_enableMargins = true;
451 m_enableOrientation = true;
452 m_enablePaper = true;
453 m_enablePrinter = true;
454 m_enableHelp = false;
455 m_getDefaultInfo = false;
7bcb11d3
JS
456
457 m_printData = printData;
458
459 // The wxPrintData paper size overrides these values, unless the size cannot
460 // be found.
461 CalculatePaperSizeFromId();
c801d85f
KB
462}
463
7bcb11d3 464wxPageSetupDialogData::~wxPageSetupDialogData()
c801d85f 465{
c801d85f
KB
466}
467
5e472c1f 468wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
c801d85f 469{
7bcb11d3
JS
470 m_paperSize = data.m_paperSize;
471 m_minMarginTopLeft = data.m_minMarginTopLeft;
472 m_minMarginBottomRight = data.m_minMarginBottomRight;
473 m_marginTopLeft = data.m_marginTopLeft;
474 m_marginBottomRight = data.m_marginBottomRight;
475 m_defaultMinMargins = data.m_defaultMinMargins;
476 m_enableMargins = data.m_enableMargins;
477 m_enableOrientation = data.m_enableOrientation;
478 m_enablePaper = data.m_enablePaper;
479 m_enablePrinter = data.m_enablePrinter;
d0ee33f5 480 m_getDefaultInfo = data.m_getDefaultInfo;
7bcb11d3
JS
481 m_enableHelp = data.m_enableHelp;
482
483 m_printData = data.m_printData;
5e472c1f
GD
484
485 return *this;
7bcb11d3 486}
c801d85f 487
5e472c1f 488wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
7bcb11d3
JS
489{
490 m_printData = data;
24c5243d 491 CalculatePaperSizeFromId();
5e472c1f
GD
492
493 return *this;
c801d85f
KB
494}
495
7bcb11d3
JS
496// If a corresponding paper type is found in the paper database, will set the m_printData
497// paper size id member as well.
498void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
499{
500 m_paperSize = sz;
c801d85f 501
7bcb11d3
JS
502 CalculateIdFromPaperSize();
503}
c801d85f 504
7bcb11d3
JS
505// Sets the wxPrintData id, plus the paper width/height if found in the paper database.
506void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
507{
508 m_printData.SetPaperId(id);
509
510 CalculatePaperSizeFromId();
c801d85f
KB
511}
512
24c5243d
RD
513void wxPageSetupDialogData::SetPrintData(const wxPrintData& printData)
514{
515 m_printData = printData;
b494c48b 516 CalculatePaperSizeFromId();
24c5243d
RD
517}
518
7bcb11d3
JS
519// Use paper size defined in this object to set the wxPrintData
520// paper id
521void wxPageSetupDialogData::CalculateIdFromPaperSize()
c801d85f 522{
8826f46f 523 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 524 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
c801d85f 525
7bcb11d3
JS
526 wxSize sz = GetPaperSize();
527
528 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
529 if (id != wxPAPER_NONE)
c801d85f 530 {
7bcb11d3 531 m_printData.SetPaperId(id);
c801d85f
KB
532 }
533}
8826f46f 534
7bcb11d3
JS
535// Use paper id in wxPrintData to set this object's paper size
536void wxPageSetupDialogData::CalculatePaperSizeFromId()
537{
8826f46f 538 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 539 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
7bcb11d3
JS
540
541 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
c801d85f 542
01cf2f95
VZ
543 // sz is in 10ths of a mm, while paper size is in mm
544 m_paperSize.x = sz.x / 10;
545 m_paperSize.y = sz.y / 10;
7bcb11d3 546}
8826f46f 547
88ac883a 548#endif // wxUSE_PRINTING_ARCHITECTURE