]>
Commit | Line | Data |
---|---|---|
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/tokenzr.h" | |
42 | #include "wx/prntbase.h" | |
43 | #include "wx/printdlg.h" | |
44 | ||
45 | #if wxUSE_FONTDLG | |
46 | #include "wx/fontdlg.h" | |
47 | #endif // wxUSE_FONTDLG | |
48 | ||
49 | #if wxUSE_PRINTING_ARCHITECTURE | |
50 | ||
51 | #include "wx/paper.h" | |
52 | ||
53 | ||
54 | IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject) | |
55 | IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject) | |
56 | IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject) | |
57 | ||
58 | #endif // wxUSE_PRINTING_ARCHITECTURE | |
59 | ||
60 | IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject) | |
61 | IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject) | |
62 | ||
63 | // ============================================================================ | |
64 | // implementation | |
65 | // ============================================================================ | |
66 | ||
67 | // ---------------------------------------------------------------------------- | |
68 | // wxColourData | |
69 | // ---------------------------------------------------------------------------- | |
70 | ||
71 | wxColourData::wxColourData() | |
72 | { | |
73 | m_chooseFull = false; | |
74 | m_dataColour.Set(0,0,0); | |
75 | // m_custColours are wxNullColours initially | |
76 | } | |
77 | ||
78 | wxColourData::wxColourData(const wxColourData& data) | |
79 | : wxObject() | |
80 | { | |
81 | (*this) = data; | |
82 | } | |
83 | ||
84 | wxColourData::~wxColourData() | |
85 | { | |
86 | } | |
87 | ||
88 | void wxColourData::SetCustomColour(int i, const wxColour& colour) | |
89 | { | |
90 | wxCHECK_RET( i >= 0 && i < NUM_CUSTOM, _T("custom colour index out of range") ); | |
91 | ||
92 | m_custColours[i] = colour; | |
93 | } | |
94 | ||
95 | wxColour wxColourData::GetCustomColour(int i) const | |
96 | { | |
97 | wxCHECK_MSG( i >= 0 && i < NUM_CUSTOM, wxColour(0,0,0), | |
98 | _T("custom colour index out of range") ); | |
99 | ||
100 | return m_custColours[i]; | |
101 | } | |
102 | ||
103 | wxColourData& wxColourData::operator=(const wxColourData& data) | |
104 | { | |
105 | for ( int i = 0; i < NUM_CUSTOM; i++) | |
106 | m_custColours[i] = data.m_custColours[i]; | |
107 | ||
108 | m_dataColour = data.m_dataColour; | |
109 | m_chooseFull = data.m_chooseFull; | |
110 | ||
111 | return *this; | |
112 | } | |
113 | ||
114 | // ---------------------------------------------------------------------------- | |
115 | // [de]serialization | |
116 | // ---------------------------------------------------------------------------- | |
117 | ||
118 | // separator used between different fields | |
119 | static const char wxCOL_DATA_SEP = ','; | |
120 | ||
121 | wxString wxColourData::ToString() const | |
122 | { | |
123 | wxString str(m_chooseFull ? '1' : '0'); | |
124 | ||
125 | for ( int i = 0; i < NUM_CUSTOM; i++ ) | |
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 | ||
137 | bool wxColourData::FromString(const wxString& str) | |
138 | { | |
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++) | |
144 | { | |
145 | token = tokenizer.GetNextToken(); | |
146 | if (token.empty()) | |
147 | m_custColours[i] = wxNullColour; | |
148 | else | |
149 | success = m_custColours[i].Set(token); | |
150 | } | |
151 | return success; | |
152 | } | |
153 | ||
154 | // ---------------------------------------------------------------------------- | |
155 | // Font data | |
156 | // ---------------------------------------------------------------------------- | |
157 | ||
158 | wxFontData::wxFontData() | |
159 | { | |
160 | // Intialize colour to black. | |
161 | m_fontColour = wxNullColour; | |
162 | ||
163 | m_showHelp = false; | |
164 | m_allowSymbols = true; | |
165 | m_enableEffects = true; | |
166 | m_minSize = 0; | |
167 | m_maxSize = 0; | |
168 | ||
169 | m_encoding = wxFONTENCODING_SYSTEM; | |
170 | } | |
171 | ||
172 | wxFontData::~wxFontData() | |
173 | { | |
174 | } | |
175 | ||
176 | #if wxUSE_FONTDLG | |
177 | ||
178 | wxFontDialogBase::~wxFontDialogBase() | |
179 | { | |
180 | } | |
181 | ||
182 | #endif // wxUSE_FONTDLG | |
183 | ||
184 | #if wxUSE_PRINTING_ARCHITECTURE | |
185 | // ---------------------------------------------------------------------------- | |
186 | // Print data | |
187 | // ---------------------------------------------------------------------------- | |
188 | ||
189 | wxPrintData::wxPrintData() | |
190 | { | |
191 | m_bin = wxPRINTBIN_DEFAULT; | |
192 | m_media = wxPRINTMEDIA_DEFAULT; | |
193 | m_printMode = wxPRINT_MODE_PRINTER; | |
194 | m_printOrientation = wxPORTRAIT; | |
195 | m_printOrientationReversed = false; | |
196 | m_printNoCopies = 1; | |
197 | m_printCollate = false; | |
198 | ||
199 | // New, 24/3/99 | |
200 | m_printerName = wxEmptyString; | |
201 | m_colour = true; | |
202 | m_duplexMode = wxDUPLEX_SIMPLEX; | |
203 | m_printQuality = wxPRINT_QUALITY_HIGH; | |
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; | |
209 | ||
210 | m_privData = NULL; | |
211 | m_privDataLen = 0; | |
212 | ||
213 | m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData(); | |
214 | } | |
215 | ||
216 | wxPrintData::wxPrintData(const wxPrintData& printData) | |
217 | : wxObject() | |
218 | { | |
219 | m_nativeData = NULL; | |
220 | m_privData = NULL; | |
221 | (*this) = printData; | |
222 | } | |
223 | ||
224 | void 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 | ||
239 | wxPrintData::~wxPrintData() | |
240 | { | |
241 | m_nativeData->m_ref--; | |
242 | if (m_nativeData->m_ref == 0) | |
243 | delete m_nativeData; | |
244 | ||
245 | if (m_privData) | |
246 | delete [] m_privData; | |
247 | } | |
248 | ||
249 | void wxPrintData::ConvertToNative() | |
250 | { | |
251 | m_nativeData->TransferFrom( *this ) ; | |
252 | } | |
253 | ||
254 | void wxPrintData::ConvertFromNative() | |
255 | { | |
256 | m_nativeData->TransferTo( *this ) ; | |
257 | } | |
258 | ||
259 | wxPrintData& wxPrintData::operator=(const wxPrintData& data) | |
260 | { | |
261 | if ( &data == this ) | |
262 | return *this; | |
263 | ||
264 | m_printNoCopies = data.m_printNoCopies; | |
265 | m_printCollate = data.m_printCollate; | |
266 | m_printOrientation = data.m_printOrientation; | |
267 | m_printOrientationReversed = data.m_printOrientationReversed; | |
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; | |
274 | m_bin = data.m_bin; | |
275 | m_media = data.m_media; | |
276 | m_printMode = data.m_printMode; | |
277 | m_filename = data.m_filename; | |
278 | ||
279 | // UnRef old m_nativeData | |
280 | if (m_nativeData) | |
281 | { | |
282 | m_nativeData->m_ref--; | |
283 | if (m_nativeData->m_ref == 0) | |
284 | delete m_nativeData; | |
285 | } | |
286 | // Set Ref new one | |
287 | m_nativeData = data.GetNativeData(); | |
288 | m_nativeData->m_ref++; | |
289 | ||
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 | } | |
301 | ||
302 | return *this; | |
303 | } | |
304 | ||
305 | // Is this data OK for showing the print dialog? | |
306 | bool wxPrintData::IsOk() const | |
307 | { | |
308 | m_nativeData->TransferFrom( *this ); | |
309 | ||
310 | return m_nativeData->Ok(); | |
311 | } | |
312 | ||
313 | // ---------------------------------------------------------------------------- | |
314 | // Print dialog data | |
315 | // ---------------------------------------------------------------------------- | |
316 | ||
317 | wxPrintDialogData::wxPrintDialogData() | |
318 | { | |
319 | m_printFromPage = 0; | |
320 | m_printToPage = 0; | |
321 | m_printMinPage = 0; | |
322 | m_printMaxPage = 0; | |
323 | m_printNoCopies = 1; | |
324 | m_printAllPages = false; | |
325 | m_printCollate = false; | |
326 | m_printToFile = false; | |
327 | m_printSelection = false; | |
328 | m_printEnableSelection = false; | |
329 | m_printEnablePageNumbers = true; | |
330 | ||
331 | wxPrintFactory* factory = wxPrintFactory::GetFactory(); | |
332 | m_printEnablePrintToFile = ! factory->HasOwnPrintToFile(); | |
333 | ||
334 | m_printEnableHelp = false; | |
335 | } | |
336 | ||
337 | wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData) | |
338 | : wxObject() | |
339 | { | |
340 | (*this) = dialogData; | |
341 | } | |
342 | ||
343 | wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData) | |
344 | { | |
345 | m_printFromPage = 1; | |
346 | m_printToPage = 0; | |
347 | m_printMinPage = 1; | |
348 | m_printMaxPage = 9999; | |
349 | m_printNoCopies = 1; | |
350 | // On Mac the Print dialog always defaults to "All Pages" | |
351 | #ifdef __WXMAC__ | |
352 | m_printAllPages = true; | |
353 | #else | |
354 | m_printAllPages = false; | |
355 | #endif | |
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; | |
363 | m_printData = printData; | |
364 | } | |
365 | ||
366 | wxPrintDialogData::~wxPrintDialogData() | |
367 | { | |
368 | } | |
369 | ||
370 | void wxPrintDialogData::operator=(const wxPrintDialogData& data) | |
371 | { | |
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; | |
380 | m_printSelection = data.m_printSelection; | |
381 | m_printEnableSelection = data.m_printEnableSelection; | |
382 | m_printEnablePageNumbers = data.m_printEnablePageNumbers; | |
383 | m_printEnableHelp = data.m_printEnableHelp; | |
384 | m_printEnablePrintToFile = data.m_printEnablePrintToFile; | |
385 | m_printData = data.m_printData; | |
386 | } | |
387 | ||
388 | void wxPrintDialogData::operator=(const wxPrintData& data) | |
389 | { | |
390 | m_printData = data; | |
391 | } | |
392 | ||
393 | // ---------------------------------------------------------------------------- | |
394 | // wxPageSetupDialogData | |
395 | // ---------------------------------------------------------------------------- | |
396 | ||
397 | wxPageSetupDialogData::wxPageSetupDialogData() | |
398 | { | |
399 | m_paperSize = wxSize(0,0); | |
400 | ||
401 | CalculatePaperSizeFromId(); | |
402 | ||
403 | m_minMarginTopLeft = | |
404 | m_minMarginBottomRight = | |
405 | m_marginTopLeft = | |
406 | m_marginBottomRight = wxPoint(0,0); | |
407 | ||
408 | // Flags | |
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; | |
416 | } | |
417 | ||
418 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData) | |
419 | : wxObject() | |
420 | { | |
421 | (*this) = dialogData; | |
422 | } | |
423 | ||
424 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData) | |
425 | { | |
426 | m_paperSize = wxSize(0,0); | |
427 | m_minMarginTopLeft = | |
428 | m_minMarginBottomRight = | |
429 | m_marginTopLeft = | |
430 | m_marginBottomRight = wxPoint(0,0); | |
431 | ||
432 | // Flags | |
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; | |
440 | ||
441 | m_printData = printData; | |
442 | ||
443 | // The wxPrintData paper size overrides these values, unless the size cannot | |
444 | // be found. | |
445 | CalculatePaperSizeFromId(); | |
446 | } | |
447 | ||
448 | wxPageSetupDialogData::~wxPageSetupDialogData() | |
449 | { | |
450 | } | |
451 | ||
452 | wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data) | |
453 | { | |
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; | |
464 | m_getDefaultInfo = data.m_getDefaultInfo; | |
465 | m_enableHelp = data.m_enableHelp; | |
466 | ||
467 | m_printData = data.m_printData; | |
468 | ||
469 | return *this; | |
470 | } | |
471 | ||
472 | wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data) | |
473 | { | |
474 | m_printData = data; | |
475 | CalculatePaperSizeFromId(); | |
476 | ||
477 | return *this; | |
478 | } | |
479 | ||
480 | // If a corresponding paper type is found in the paper database, will set the m_printData | |
481 | // paper size id member as well. | |
482 | void wxPageSetupDialogData::SetPaperSize(const wxSize& sz) | |
483 | { | |
484 | m_paperSize = sz; | |
485 | ||
486 | CalculateIdFromPaperSize(); | |
487 | } | |
488 | ||
489 | // Sets the wxPrintData id, plus the paper width/height if found in the paper database. | |
490 | void wxPageSetupDialogData::SetPaperSize(wxPaperSize id) | |
491 | { | |
492 | m_printData.SetPaperId(id); | |
493 | ||
494 | CalculatePaperSizeFromId(); | |
495 | } | |
496 | ||
497 | void wxPageSetupDialogData::SetPrintData(const wxPrintData& printData) | |
498 | { | |
499 | m_printData = printData; | |
500 | CalculatePaperSizeFromId(); | |
501 | } | |
502 | ||
503 | // Use paper size defined in this object to set the wxPrintData | |
504 | // paper id | |
505 | void wxPageSetupDialogData::CalculateIdFromPaperSize() | |
506 | { | |
507 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), | |
508 | wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") ); | |
509 | ||
510 | wxSize sz = GetPaperSize(); | |
511 | ||
512 | wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10)); | |
513 | if (id != wxPAPER_NONE) | |
514 | { | |
515 | m_printData.SetPaperId(id); | |
516 | } | |
517 | } | |
518 | ||
519 | // Use paper id in wxPrintData to set this object's paper size | |
520 | void wxPageSetupDialogData::CalculatePaperSizeFromId() | |
521 | { | |
522 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), | |
523 | wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") ); | |
524 | ||
525 | wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId()); | |
526 | ||
527 | // sz is in 10ths of a mm, while paper size is in mm | |
528 | m_paperSize.x = sz.x / 10; | |
529 | m_paperSize.y = sz.y / 10; | |
530 | } | |
531 | ||
532 | #endif // wxUSE_PRINTING_ARCHITECTURE |