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