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