]> git.saurik.com Git - wxWidgets.git/blob - src/common/cmndata.cpp
don't use negative sizes for row/column labels subwindows to avoid GTK warnings ...
[wxWidgets.git] / src / common / cmndata.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/cmndata.cpp
3 // Purpose: Common GDI data
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/cmndata.h"
28
29 #ifndef WX_PRECOMP
30 #if defined(__WXMSW__)
31 #include "wx/msw/wrapcdlg.h"
32 #endif // MSW
33 #include <stdio.h>
34 #include "wx/string.h"
35 #include "wx/utils.h"
36 #include "wx/app.h"
37 #include "wx/log.h"
38 #include "wx/gdicmn.h"
39 #endif
40
41 #include "wx/prntbase.h"
42 #include "wx/printdlg.h"
43
44 #if wxUSE_FONTDLG
45 #include "wx/fontdlg.h"
46 #endif // wxUSE_FONTDLG
47
48 #if wxUSE_PRINTING_ARCHITECTURE
49
50 #include "wx/paper.h"
51
52 #if defined(__WXMAC__)
53 #include "wx/mac/private/print.h"
54 #endif
55
56 IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
57 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
58 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject)
59
60 #endif // wxUSE_PRINTING_ARCHITECTURE
61
62 IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
63 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
64
65 // ============================================================================
66 // implementation
67 // ============================================================================
68
69 // ----------------------------------------------------------------------------
70 // wxColourData
71 // ----------------------------------------------------------------------------
72
73 wxColourData::wxColourData()
74 {
75 m_chooseFull = false;
76 m_dataColour.Set(0,0,0);
77 // m_custColours are wxNullColours initially
78 }
79
80 wxColourData::wxColourData(const wxColourData& data)
81 : wxObject()
82 {
83 (*this) = data;
84 }
85
86 wxColourData::~wxColourData()
87 {
88 }
89
90 void wxColourData::SetCustomColour(int i, const wxColour& colour)
91 {
92 wxCHECK_RET( i >= 0 && i < NUM_CUSTOM, _T("custom colour index out of range") );
93
94 m_custColours[i] = colour;
95 }
96
97 wxColour wxColourData::GetCustomColour(int i)
98 {
99 wxCHECK_MSG( i >= 0 && i < NUM_CUSTOM, wxColour(0,0,0),
100 _T("custom colour index out of range") );
101
102 return m_custColours[i];
103 }
104
105 wxColourData& wxColourData::operator=(const wxColourData& data)
106 {
107 for ( int i = 0; i < NUM_CUSTOM; i++)
108 m_custColours[i] = data.m_custColours[i];
109
110 m_dataColour = data.m_dataColour;
111 m_chooseFull = data.m_chooseFull;
112
113 return *this;
114 }
115
116 // ----------------------------------------------------------------------------
117 // [de]serialization
118 // ----------------------------------------------------------------------------
119
120 // separator used between different fields
121 static const char wxCOL_DATA_SEP = ',';
122
123 wxString wxColourData::ToString() const
124 {
125 wxString str(m_chooseFull ? '1' : '0');
126
127 for ( int i = 0; i < NUM_CUSTOM; i++ )
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
139 bool 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
180 // ----------------------------------------------------------------------------
181 // Font data
182 // ----------------------------------------------------------------------------
183
184 wxFontData::wxFontData()
185 {
186 // Intialize colour to black.
187 m_fontColour = wxNullColour;
188
189 m_showHelp = false;
190 m_allowSymbols = true;
191 m_enableEffects = true;
192 m_minSize = 0;
193 m_maxSize = 0;
194
195 m_encoding = wxFONTENCODING_SYSTEM;
196 }
197
198 wxFontData::~wxFontData()
199 {
200 }
201
202 #if wxUSE_FONTDLG
203
204 wxFontDialogBase::~wxFontDialogBase()
205 {
206 }
207
208 #endif // wxUSE_FONTDLG
209
210 #if wxUSE_PRINTING_ARCHITECTURE
211 // ----------------------------------------------------------------------------
212 // Print data
213 // ----------------------------------------------------------------------------
214
215 wxPrintData::wxPrintData()
216 {
217 m_bin = wxPRINTBIN_DEFAULT;
218 m_media = wxPRINTMEDIA_DEFAULT;
219 m_printMode = wxPRINT_MODE_PRINTER;
220 m_printOrientation = wxPORTRAIT;
221 m_printOrientationReversed = false;
222 m_printNoCopies = 1;
223 m_printCollate = false;
224
225 // New, 24/3/99
226 m_printerName = wxEmptyString;
227 m_colour = true;
228 m_duplexMode = wxDUPLEX_SIMPLEX;
229 m_printQuality = wxPRINT_QUALITY_HIGH;
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;
235
236 m_privData = NULL;
237 m_privDataLen = 0;
238
239 m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData();
240 }
241
242 wxPrintData::wxPrintData(const wxPrintData& printData)
243 : wxObject()
244 {
245 m_nativeData = NULL;
246 m_privData = NULL;
247 (*this) = printData;
248 }
249
250 void 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
265 wxPrintData::~wxPrintData()
266 {
267 m_nativeData->m_ref--;
268 if (m_nativeData->m_ref == 0)
269 delete m_nativeData;
270
271 if (m_privData)
272 delete [] m_privData;
273 }
274
275 void wxPrintData::ConvertToNative()
276 {
277 m_nativeData->TransferFrom( *this ) ;
278 }
279
280 void wxPrintData::ConvertFromNative()
281 {
282 m_nativeData->TransferTo( *this ) ;
283 }
284
285 void wxPrintData::operator=(const wxPrintData& data)
286 {
287 m_printNoCopies = data.m_printNoCopies;
288 m_printCollate = data.m_printCollate;
289 m_printOrientation = data.m_printOrientation;
290 m_printOrientationReversed = data.m_printOrientationReversed;
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;
297 m_bin = data.m_bin;
298 m_media = data.m_media;
299 m_printMode = data.m_printMode;
300 m_filename = data.m_filename;
301
302 // UnRef old m_nativeData
303 if (m_nativeData)
304 {
305 m_nativeData->m_ref--;
306 if (m_nativeData->m_ref == 0)
307 delete m_nativeData;
308 }
309 // Set Ref new one
310 m_nativeData = data.GetNativeData();
311 m_nativeData->m_ref++;
312
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 }
324 }
325
326 // Is this data OK for showing the print dialog?
327 bool wxPrintData::IsOk() const
328 {
329 m_nativeData->TransferFrom( *this );
330
331 return m_nativeData->Ok();
332 }
333
334 // ----------------------------------------------------------------------------
335 // Print dialog data
336 // ----------------------------------------------------------------------------
337
338 wxPrintDialogData::wxPrintDialogData()
339 {
340 m_printFromPage = 0;
341 m_printToPage = 0;
342 m_printMinPage = 0;
343 m_printMaxPage = 0;
344 m_printNoCopies = 1;
345 m_printAllPages = false;
346 m_printCollate = false;
347 m_printToFile = false;
348 m_printSelection = false;
349 m_printEnableSelection = false;
350 m_printEnablePageNumbers = true;
351
352 wxPrintFactory* factory = wxPrintFactory::GetFactory();
353 m_printEnablePrintToFile = ! factory->HasOwnPrintToFile();
354
355 m_printEnableHelp = false;
356 }
357
358 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
359 : wxObject()
360 {
361 (*this) = dialogData;
362 }
363
364 wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
365 {
366 m_printFromPage = 1;
367 m_printToPage = 0;
368 m_printMinPage = 1;
369 m_printMaxPage = 9999;
370 m_printNoCopies = 1;
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;
379 m_printData = printData;
380 }
381
382 wxPrintDialogData::~wxPrintDialogData()
383 {
384 }
385
386 void wxPrintDialogData::operator=(const wxPrintDialogData& data)
387 {
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;
396 m_printSelection = data.m_printSelection;
397 m_printEnableSelection = data.m_printEnableSelection;
398 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
399 m_printEnableHelp = data.m_printEnableHelp;
400 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
401 m_printData = data.m_printData;
402 }
403
404 void wxPrintDialogData::operator=(const wxPrintData& data)
405 {
406 m_printData = data;
407 }
408
409 // ----------------------------------------------------------------------------
410 // wxPageSetupDialogData
411 // ----------------------------------------------------------------------------
412
413 wxPageSetupDialogData::wxPageSetupDialogData()
414 {
415 m_paperSize = wxSize(0,0);
416
417 CalculatePaperSizeFromId();
418
419 m_minMarginTopLeft =
420 m_minMarginBottomRight =
421 m_marginTopLeft =
422 m_marginBottomRight = wxPoint(0,0);
423
424 // Flags
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;
432 }
433
434 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
435 : wxObject()
436 {
437 (*this) = dialogData;
438 }
439
440 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
441 {
442 m_paperSize = wxSize(0,0);
443 m_minMarginTopLeft =
444 m_minMarginBottomRight =
445 m_marginTopLeft =
446 m_marginBottomRight = wxPoint(0,0);
447
448 // Flags
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;
456
457 m_printData = printData;
458
459 // The wxPrintData paper size overrides these values, unless the size cannot
460 // be found.
461 CalculatePaperSizeFromId();
462 }
463
464 wxPageSetupDialogData::~wxPageSetupDialogData()
465 {
466 }
467
468 wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
469 {
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;
480 m_getDefaultInfo = data.m_getDefaultInfo;
481 m_enableHelp = data.m_enableHelp;
482
483 m_printData = data.m_printData;
484
485 return *this;
486 }
487
488 wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
489 {
490 m_printData = data;
491 CalculatePaperSizeFromId();
492
493 return *this;
494 }
495
496 // If a corresponding paper type is found in the paper database, will set the m_printData
497 // paper size id member as well.
498 void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
499 {
500 m_paperSize = sz;
501
502 CalculateIdFromPaperSize();
503 }
504
505 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
506 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
507 {
508 m_printData.SetPaperId(id);
509
510 CalculatePaperSizeFromId();
511 }
512
513 void wxPageSetupDialogData::SetPrintData(const wxPrintData& printData)
514 {
515 m_printData = printData;
516 CalculatePaperSizeFromId();
517 }
518
519 // Use paper size defined in this object to set the wxPrintData
520 // paper id
521 void wxPageSetupDialogData::CalculateIdFromPaperSize()
522 {
523 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
524 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
525
526 wxSize sz = GetPaperSize();
527
528 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
529 if (id != wxPAPER_NONE)
530 {
531 m_printData.SetPaperId(id);
532 }
533 }
534
535 // Use paper id in wxPrintData to set this object's paper size
536 void wxPageSetupDialogData::CalculatePaperSizeFromId()
537 {
538 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
539 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
540
541 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
542
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;
546 }
547
548 #endif // wxUSE_PRINTING_ARCHITECTURE