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