]> git.saurik.com Git - wxWidgets.git/blob - src/common/cmndata.cpp
wxAtof implementation independent of (the rest of) wxNEED_WX_STDLIB_H
[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 and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
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
41 #include "wx/paper.h"
42
43 // For compatibility
44 #if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT
45 #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1
46 #endif
47
48 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
49 #include "wx/generic/dcpsg.h"
50 #endif
51
52 #ifdef __WXMSW__
53 #include <windows.h>
54 #include <wx/msw/private.h>
55
56 #if !defined(__WIN32__)
57 #include <print.h>
58 #include <commdlg.h>
59 #endif // Win16
60
61 #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__)
62 #include <windowsx.h>
63 #include <commdlg.h>
64 #endif
65 #endif // MSW
66
67 #if !USE_SHARED_LIBRARY
68 IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
69 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
70 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject)
71 IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
72 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
73 #endif
74
75 // ============================================================================
76 // implementation
77 // ============================================================================
78
79 // ----------------------------------------------------------------------------
80 // wxColourData
81 // ----------------------------------------------------------------------------
82
83 wxColourData::wxColourData()
84 {
85 int i;
86 for (i = 0; i < 16; i++)
87 custColours[i].Set(255, 255, 255);
88
89 chooseFull = FALSE;
90 dataColour.Set(0,0,0);
91 }
92
93 wxColourData::wxColourData(const wxColourData& data)
94 {
95 (*this) = data;
96 }
97
98 wxColourData::~wxColourData()
99 {
100 }
101
102 void wxColourData::SetCustomColour(int i, wxColour& colour)
103 {
104 if (i > 15 || i < 0)
105 return;
106
107 custColours[i] = colour;
108 }
109
110 wxColour wxColourData::GetCustomColour(int i)
111 {
112 if (i > 15 || i < 0)
113 return wxColour(0,0,0);
114
115 return custColours[i];
116 }
117
118 void wxColourData::operator=(const wxColourData& data)
119 {
120 int i;
121 for (i = 0; i < 16; i++)
122 custColours[i] = data.custColours[i];
123
124 dataColour = (wxColour&)data.dataColour;
125 chooseFull = data.chooseFull;
126 }
127
128 // ----------------------------------------------------------------------------
129 // Font data
130 // ----------------------------------------------------------------------------
131
132 wxFontData::wxFontData()
133 {
134 // Intialize colour to black.
135 fontColour.Set(0, 0, 0);
136
137 showHelp = FALSE;
138 allowSymbols = TRUE;
139 enableEffects = TRUE;
140 minSize = 0;
141 maxSize = 0;
142 }
143
144 wxFontData::wxFontData(const wxFontData& data)
145 {
146 (*this) = data;
147 }
148
149 wxFontData::~wxFontData()
150 {
151 }
152
153 void wxFontData::operator=(const wxFontData& data)
154 {
155 fontColour = data.fontColour;
156 showHelp = data.showHelp;
157 allowSymbols = data.allowSymbols;
158 enableEffects = data.enableEffects;
159 initialFont = data.initialFont;
160 chosenFont = data.chosenFont;
161 minSize = data.minSize;
162 maxSize = data.maxSize;
163 }
164
165 // ----------------------------------------------------------------------------
166 // Print data
167 // ----------------------------------------------------------------------------
168
169 wxPrintData::wxPrintData()
170 {
171 #ifdef __WXMSW__
172 m_devMode = NULL;
173 #endif
174 m_printOrientation = wxPORTRAIT;
175 m_printNoCopies = 1;
176 m_printCollate = FALSE;
177
178 // New, 24/3/99
179 m_printerName = "";
180 m_colour = TRUE;
181 m_duplexMode = wxDUPLEX_SIMPLEX;
182 m_printQuality = wxPRINT_QUALITY_HIGH;
183 m_paperId = wxPAPER_A4;
184 m_paperSize = wxSize(210, 297);
185
186 // PostScript-specific data
187 m_printerCommand = "";
188 m_previewCommand = "";
189 m_printerOptions = "";
190 m_filename = "";
191 m_afmPath = "";
192 m_printerScaleX = 1.0;
193 m_printerScaleY = 1.0;
194 m_printerTranslateX = 0;
195 m_printerTranslateY = 0;
196 m_printMode = wxPRINT_MODE_FILE;
197 }
198
199 wxPrintData::wxPrintData(const wxPrintData& printData)
200 {
201 #ifdef __WXMSW__
202 m_devMode = NULL;
203 #endif
204
205 (*this) = printData;
206 }
207
208 wxPrintData::~wxPrintData()
209 {
210 #ifdef __WXMSW__
211 HGLOBAL hDevMode = (HGLOBAL) m_devMode;
212 if (hDevMode )
213 GlobalFree(hDevMode);
214 #endif
215 }
216
217 #if defined(__WXMSW__) && defined(__WIN32__)
218
219 static wxString wxGetPrintDlgError()
220 {
221 DWORD err = CommDlgExtendedError();
222 wxString msg = "Unknown";
223 switch (err)
224 {
225 case CDERR_FINDRESFAILURE: msg = "CDERR_FINDRESFAILURE"; break;
226 case CDERR_INITIALIZATION: msg = "CDERR_INITIALIZATION"; break;
227 case CDERR_LOADRESFAILURE: msg = "CDERR_LOADRESFAILURE"; break;
228 case CDERR_LOADSTRFAILURE: msg = "CDERR_LOADSTRFAILURE"; break;
229 case CDERR_LOCKRESFAILURE: msg = "CDERR_LOCKRESFAILURE"; break;
230 case CDERR_MEMALLOCFAILURE: msg = "CDERR_MEMALLOCFAILURE"; break;
231 case CDERR_MEMLOCKFAILURE: msg = "CDERR_MEMLOCKFAILURE"; break;
232 case CDERR_NOHINSTANCE: msg = "CDERR_NOHINSTANCE"; break;
233 case CDERR_NOHOOK: msg = "CDERR_NOHOOK"; break;
234 case CDERR_NOTEMPLATE: msg = "CDERR_NOTEMPLATE"; break;
235 case CDERR_STRUCTSIZE: msg = "CDERR_STRUCTSIZE"; break;
236 case PDERR_RETDEFFAILURE: msg = "PDERR_RETDEFFAILURE"; break;
237 case PDERR_PRINTERNOTFOUND: msg = "PDERR_PRINTERNOTFOUND"; break;
238 case PDERR_PARSEFAILURE: msg = "PDERR_PARSEFAILURE"; break;
239 case PDERR_NODEVICES: msg = "PDERR_NODEVICES"; break;
240 case PDERR_NODEFAULTPRN: msg = "PDERR_NODEFAULTPRN"; break;
241 case PDERR_LOADDRVFAILURE: msg = "PDERR_LOADDRVFAILURE"; break;
242 case PDERR_INITFAILURE: msg = "PDERR_INITFAILURE"; break;
243 case PDERR_GETDEVMODEFAIL: msg = "PDERR_GETDEVMODEFAIL"; break;
244 case PDERR_DNDMMISMATCH: msg = "PDERR_DNDMMISMATCH"; break;
245 case PDERR_DEFAULTDIFFERENT: msg = "PDERR_DEFAULTDIFFERENT"; break;
246 case PDERR_CREATEICFAILURE: msg = "PDERR_CREATEICFAILURE"; break;
247 default: break;
248 }
249 return msg;
250 }
251
252
253
254 void wxPrintData::ConvertToNative()
255 {
256 HGLOBAL hDevMode = (HGLOBAL) m_devMode;
257 if (!hDevMode)
258 {
259 // Use PRINTDLG as a way of creating a DEVMODE object
260 PRINTDLG *pd = new PRINTDLG;
261
262 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
263 #ifdef __GNUWIN32__
264 memset(pd, 0, 66);
265 pd->lStructSize = 66 ;
266 #else
267 memset(pd, 0, sizeof(PRINTDLG));
268 pd->lStructSize = sizeof(PRINTDLG);
269 #endif
270
271 pd->hwndOwner = (HWND)NULL;
272 pd->hDevMode = NULL; // Will be created by PrintDlg
273 pd->hDevNames = NULL; // Ditto
274 pd->hInstance = (HINSTANCE) wxGetInstance();
275
276 pd->Flags = PD_RETURNDEFAULT;
277 pd->nCopies = 1;
278
279 // Fill out the DEVMODE structure
280 // so we can use it as input in the 'real' PrintDlg
281 if (!PrintDlg(pd))
282 {
283 if ( pd->hDevMode )
284 GlobalFree(pd->hDevMode);
285 if ( pd->hDevNames )
286 GlobalFree(pd->hDevNames);
287 pd->hDevMode = NULL;
288 pd->hDevNames = NULL;
289
290 #if defined(__WXDEBUG__) && defined(__WIN32__)
291 wxString str("Printing error: ");
292 str += wxGetPrintDlgError();
293 wxLogDebug(str);
294 #endif
295 }
296 else
297 {
298 if ( pd->hDevNames )
299 GlobalFree(pd->hDevNames);
300 pd->hDevNames = NULL;
301
302 hDevMode = pd->hDevMode;
303 m_devMode = (void*) hDevMode;
304 pd->hDevMode = NULL;
305 }
306
307 delete pd;
308 }
309
310 if ( hDevMode )
311 {
312 DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode);
313
314 //// Orientation
315
316 devMode->dmOrientation = m_printOrientation;
317 devMode->dmFields = DM_ORIENTATION;
318
319 //// Collation
320
321 devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
322 devMode->dmFields |= DM_COLLATE;
323
324 //// Number of copies
325
326 devMode->dmCopies = m_printNoCopies;
327 devMode->dmFields |= DM_COPIES;
328
329 //// Printer name
330
331 if (m_printerName != "")
332 {
333 // TODO: make this Unicode compatible
334 int len = wxMin(31, m_printerName.Len());
335 int i;
336 for (i = 0; i < len; i++)
337 devMode->dmDeviceName[i] = m_printerName.GetChar(i);
338 devMode->dmDeviceName[i] = 0;
339 }
340
341 //// Colour
342
343 if (m_colour)
344 devMode->dmColor = DMCOLOR_COLOR;
345 else
346 devMode->dmColor = DMCOLOR_MONOCHROME;
347
348 devMode->dmFields |= DM_COLOR;
349
350 //// Paper size
351
352 if (m_paperId == wxPAPER_NONE)
353 {
354 devMode->dmPaperWidth = m_paperSize.x * 10;
355 devMode->dmPaperLength = m_paperSize.y * 10;
356 devMode->dmFields |= DM_PAPERWIDTH;
357 devMode->dmFields |= DM_PAPERLENGTH;
358 }
359 else
360 {
361 if (wxThePrintPaperDatabase)
362 {
363 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId);
364 if (paper)
365 {
366 devMode->dmPaperSize = paper->GetPlatformId();
367 devMode->dmFields |= DM_PAPERSIZE;
368 }
369 }
370 }
371
372 //// Duplex
373
374 int duplex;
375 switch (m_duplexMode)
376 {
377 case wxDUPLEX_HORIZONTAL: {
378 duplex = DMDUP_HORIZONTAL; break;
379 }
380 case wxDUPLEX_VERTICAL: {
381 duplex = DMDUP_VERTICAL; break;
382 }
383 default:
384 case wxDUPLEX_SIMPLEX: {
385 duplex = DMDUP_SIMPLEX; break;
386 }
387 }
388 devMode->dmDuplex = duplex;
389 devMode->dmFields |= DM_DUPLEX;
390
391 //// Quality
392
393 int quality;
394 switch (m_printQuality)
395 {
396 case wxPRINT_QUALITY_MEDIUM: {
397 quality = DMRES_MEDIUM; break;
398 }
399 case wxPRINT_QUALITY_LOW: {
400 quality = DMRES_LOW; break;
401 }
402 case wxPRINT_QUALITY_DRAFT: {
403 quality = DMRES_DRAFT; break;
404 }
405 case wxPRINT_QUALITY_HIGH: {
406 quality = DMRES_HIGH; break;
407 }
408 default: {
409 quality = m_printQuality; break;
410 }
411 }
412 devMode->dmPrintQuality = quality;
413 devMode->dmFields |= DM_PRINTQUALITY;
414
415 GlobalUnlock(hDevMode);
416 }
417 }
418
419 void wxPrintData::ConvertFromNative()
420 {
421 HGLOBAL hDevMode = (HGLOBAL) m_devMode;
422
423 if (!hDevMode)
424 return;
425
426 if ( hDevMode )
427 {
428 DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode);
429
430 //// Orientation
431
432 if (devMode->dmFields & DM_ORIENTATION)
433 m_printOrientation = devMode->dmOrientation;
434
435 //// Collation
436
437 if (devMode->dmFields & DM_COLLATE)
438 {
439 if (devMode->dmCollate == DMCOLLATE_TRUE)
440 m_printCollate = TRUE;
441 else
442 m_printCollate = FALSE;
443 }
444
445 //// Number of copies
446
447 if (devMode->dmFields & DM_COPIES)
448 {
449 m_printNoCopies = devMode->dmCopies;
450 }
451
452 //// Printer name
453
454 if (devMode->dmDeviceName[0] != 0)
455 {
456 // TODO: make this Unicode compatible
457 char buf[32];
458 int i = 0;
459 while (devMode->dmDeviceName[i] != 0)
460 {
461 buf[i] = devMode->dmDeviceName[i];
462 i ++;
463 }
464 buf[i] = 0;
465
466 m_printerName = buf;
467 }
468
469 //// Colour
470
471 if (devMode->dmFields & DM_COLOR)
472 {
473 if (devMode->dmColor == DMCOLOR_COLOR)
474 m_colour = TRUE;
475 else
476 m_colour = FALSE;
477 }
478 else
479 m_colour = TRUE;
480
481 //// Paper size
482
483 if (devMode->dmFields & DM_PAPERSIZE)
484 {
485 if (wxThePrintPaperDatabase)
486 {
487 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
488 if (paper)
489 {
490 m_paperId = paper->GetId();
491 m_paperSize.x = paper->GetWidth() / 10 ;
492 m_paperSize.y = paper->GetHeight() / 10 ;
493 }
494 else
495 {
496 // Shouldn't really get here
497 wxFAIL_MSG("Couldn't find paper size in paper database.");
498
499 m_paperId = wxPAPER_NONE;
500 m_paperSize.x = 0;
501 m_paperSize.y = 0;
502 }
503 }
504 else
505 {
506 // Shouldn't really get here
507 wxFAIL_MSG("Paper database wasn't initialized in wxPrintData::ConvertFromNative.");
508
509 m_paperId = wxPAPER_NONE;
510 m_paperSize.x = 0;
511 m_paperSize.y = 0;
512 }
513 }
514 else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
515 {
516 m_paperSize.x = devMode->dmPaperWidth / 10;
517 m_paperSize.y = devMode->dmPaperLength / 10;
518 m_paperId = wxPAPER_NONE;
519 }
520 else
521 {
522 // Shouldn't really get here
523 wxFAIL_MSG("Couldn't find paper size from DEVMODE.");
524
525 m_paperSize.x = 0;
526 m_paperSize.y = 0;
527 m_paperId = wxPAPER_NONE;
528 }
529
530
531 //// Duplex
532
533 if (devMode->dmFields & DM_DUPLEX)
534 {
535 switch (devMode->dmDuplex)
536 {
537 case DMDUP_HORIZONTAL: {
538 m_duplexMode = wxDUPLEX_HORIZONTAL; break;
539 }
540 case DMDUP_VERTICAL: {
541 m_duplexMode = wxDUPLEX_VERTICAL; break;
542 }
543 default:
544 case DMDUP_SIMPLEX: {
545 m_duplexMode = wxDUPLEX_SIMPLEX; break;
546 }
547 }
548 }
549 else
550 m_duplexMode = wxDUPLEX_SIMPLEX;
551
552 //// Quality
553
554 if (devMode->dmFields & DM_PRINTQUALITY)
555 {
556 switch (devMode->dmPrintQuality)
557 {
558 case DMRES_MEDIUM: {
559 m_printQuality = wxPRINT_QUALITY_MEDIUM; break;
560 }
561 case DMRES_LOW: {
562 m_printQuality = wxPRINT_QUALITY_LOW; break;
563 }
564 case DMRES_DRAFT: {
565 m_printQuality = wxPRINT_QUALITY_DRAFT; break;
566 }
567 case DMRES_HIGH: {
568 m_printQuality = wxPRINT_QUALITY_HIGH; break;
569 }
570 default:
571 {
572 // TODO: if the printer fills in the resolution in DPI, how
573 // will the application know if it's high, low, draft etc.??
574 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
575 m_printQuality = devMode->dmPrintQuality; break;
576
577 }
578 }
579 }
580 else
581 m_printQuality = wxPRINT_QUALITY_HIGH;
582
583 GlobalUnlock(hDevMode);
584 }
585 }
586
587 #endif
588
589 void wxPrintData::operator=(const wxPrintData& data)
590 {
591 m_printNoCopies = data.m_printNoCopies;
592 m_printCollate = data.m_printCollate;
593 m_printOrientation = data.m_printOrientation;
594 m_printerName = data.m_printerName;
595 m_colour = data.m_colour;
596 m_duplexMode = data.m_duplexMode;
597 m_printQuality = data.m_printQuality;
598 m_paperId = data.m_paperId;
599 m_paperSize = data.m_paperSize;
600
601 // PostScript-specific data
602 m_printerCommand = data.m_printerCommand;
603 m_previewCommand = data.m_previewCommand;
604 m_printerOptions = data.m_printerOptions;
605 m_filename = data.m_filename;
606 m_afmPath = data.m_afmPath;
607 m_printerScaleX = data.m_printerScaleX;
608 m_printerScaleY = data.m_printerScaleY;
609 m_printerTranslateX = data.m_printerTranslateX;
610 m_printerTranslateY = data.m_printerTranslateY;
611 m_printMode = data.m_printMode;
612 }
613
614 // For compatibility
615 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
616 void wxPrintData::operator=(const wxPrintSetupData& setupData)
617 {
618 SetPrinterCommand(setupData.GetPrinterCommand());
619 SetPreviewCommand(setupData.GetPrintPreviewCommand());
620 SetPrinterOptions(setupData.GetPrinterOptions());
621
622 long xt, yt;
623 setupData.GetPrinterTranslation(& xt, & yt);
624 SetPrinterTranslation(xt, yt);
625
626 double xs, ys;
627 setupData.GetPrinterScaling(& xs, & ys);
628 SetPrinterScaling(xs, ys);
629
630 SetOrientation(setupData.GetPrinterOrientation());
631 SetPrintMode((wxPrintMode) setupData.GetPrinterMode());
632 SetFontMetricPath(setupData.GetAFMPath());
633 if (setupData.GetPaperName() != "")
634 SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(setupData.GetPaperName()));
635 SetColour(setupData.GetColour());
636 SetFilename(setupData.GetPrinterFile());
637 }
638 #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
639
640
641 // ----------------------------------------------------------------------------
642 // Print dialog data
643 // ----------------------------------------------------------------------------
644
645 wxPrintDialogData::wxPrintDialogData()
646 {
647 #ifdef __WXMSW__
648 m_printDlgData = NULL;
649 #endif
650 m_printFromPage = 0;
651 m_printToPage = 0;
652 m_printMinPage = 0;
653 m_printMaxPage = 0;
654 m_printNoCopies = 1;
655 m_printAllPages = FALSE;
656 m_printCollate = FALSE;
657 m_printToFile = FALSE;
658 m_printEnableSelection = FALSE;
659 m_printEnablePageNumbers = TRUE;
660 m_printEnablePrintToFile = TRUE;
661 m_printEnableHelp = FALSE;
662 m_printSetupDialog = FALSE;
663 }
664
665 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
666 {
667 (*this) = dialogData;
668 }
669
670 wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
671 {
672 #ifdef __WXMSW__
673 m_printDlgData = NULL;
674 #endif
675 m_printFromPage = 0;
676 m_printToPage = 0;
677 m_printMinPage = 0;
678 m_printMaxPage = 0;
679 m_printNoCopies = 1;
680 m_printAllPages = FALSE;
681 m_printCollate = FALSE;
682 m_printToFile = FALSE;
683 m_printEnableSelection = FALSE;
684 m_printEnablePageNumbers = TRUE;
685 m_printEnablePrintToFile = TRUE;
686 m_printEnableHelp = FALSE;
687 m_printSetupDialog = FALSE;
688
689 m_printData = printData;
690 }
691
692 wxPrintDialogData::~wxPrintDialogData()
693 {
694 #ifdef __WXMSW__
695 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
696 if ( pd && pd->hDevMode )
697 GlobalFree(pd->hDevMode);
698 if ( pd )
699 delete pd;
700 #endif
701 }
702
703 #ifdef __WXMSW__
704 void wxPrintDialogData::ConvertToNative()
705 {
706 m_printData.ConvertToNative();
707
708 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
709
710 if (!pd)
711 {
712 pd = new PRINTDLG;
713 m_printDlgData = (void*) pd;
714
715 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
716 #ifdef __GNUWIN32__
717 pd->lStructSize = 66 ;
718 #else
719 #endif
720 pd->lStructSize = sizeof(PRINTDLG);
721 pd->hwndOwner = (HWND)NULL;
722 pd->hDevMode = NULL; // Will be created by PrintDlg
723 pd->hDevNames = NULL; // Ditto
724
725 pd->Flags = PD_RETURNDEFAULT;
726 pd->nCopies = 1;
727 }
728
729 // Pass the devmode data to the PRINTDLG structure, since it'll
730 // be needed when PrintDlg is called.
731 if (pd->hDevMode)
732 {
733 GlobalFree(pd->hDevMode);
734 }
735
736 pd->hDevMode = (HGLOBAL) m_printData.GetNativeData();
737
738 m_printData.SetNativeData((void*) NULL);
739
740 wxASSERT_MSG( (pd->hDevMode), "hDevMode must be non-NULL in ConvertToNative!");
741
742 pd->hDC = (HDC) NULL;
743 pd->nFromPage = (UINT)m_printFromPage;
744 pd->nToPage = (UINT)m_printToPage;
745 pd->nMinPage = (UINT)m_printMinPage;
746 pd->nMaxPage = (UINT)m_printMaxPage;
747 pd->nCopies = (UINT)m_printNoCopies;
748
749 pd->Flags = PD_RETURNDC ;
750
751 #ifdef __GNUWIN32__
752 pd->lStructSize = 66 ;
753 #else
754 pd->lStructSize = sizeof( PRINTDLG );
755 #endif
756
757 pd->hwndOwner=(HWND)NULL;
758 pd->hDevNames=(HANDLE)NULL;
759 pd->hInstance=(HINSTANCE)NULL;
760 pd->lCustData = (LPARAM) NULL;
761 pd->lpfnPrintHook = NULL;
762 pd->lpfnSetupHook = NULL;
763 pd->lpPrintTemplateName = NULL;
764 pd->lpSetupTemplateName = NULL;
765 pd->hPrintTemplate = (HGLOBAL) NULL;
766 pd->hSetupTemplate = (HGLOBAL) NULL;
767
768 if ( m_printAllPages )
769 pd->Flags |= PD_ALLPAGES;
770 if ( m_printCollate )
771 pd->Flags |= PD_COLLATE;
772 if ( m_printToFile )
773 pd->Flags |= PD_PRINTTOFILE;
774 if ( !m_printEnablePrintToFile )
775 pd->Flags |= PD_DISABLEPRINTTOFILE;
776 if ( !m_printEnableSelection )
777 pd->Flags |= PD_NOSELECTION;
778 if ( !m_printEnablePageNumbers )
779 pd->Flags |= PD_NOPAGENUMS;
780 if ( m_printEnableHelp )
781 pd->Flags |= PD_SHOWHELP;
782 if ( m_printSetupDialog )
783 pd->Flags |= PD_PRINTSETUP;
784 }
785
786 void wxPrintDialogData::ConvertFromNative()
787 {
788 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
789 if ( pd == NULL )
790 return;
791
792 // Pass the devmode data back to the wxPrintData structure where it really belongs.
793 if (pd->hDevMode)
794 {
795 if (m_printData.GetNativeData())
796 {
797 // Make sure we don't leak memory
798 GlobalFree((HGLOBAL) m_printData.GetNativeData());
799 }
800 m_printData.SetNativeData((void*) pd->hDevMode);
801 pd->hDevMode = NULL;
802 }
803
804 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
805 // into wxWindows form.
806 m_printData.ConvertFromNative();
807
808 m_printFromPage = pd->nFromPage ;
809 m_printToPage = pd->nToPage ;
810 m_printMinPage = pd->nMinPage ;
811 m_printMaxPage = pd->nMaxPage ;
812 m_printNoCopies = pd->nCopies ;
813
814 m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES);
815 m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
816 m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
817 m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE);
818 m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION);
819 m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS);
820 m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP);
821 m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP);
822
823 /* port is obsolete in WIN32
824 // Get the port name
825 if (pd->hDevNames)
826 {
827 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
828 if (lpDevNames) {
829 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
830 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
831 GlobalUnlock(pd->hDevNames);
832
833 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
834 }
835 }
836 */
837 }
838
839 void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
840 {
841 if ( m_printDlgData == NULL )
842 ConvertToNative();
843
844 if ( m_printDlgData != NULL && win != NULL)
845 {
846 PRINTDLG *pd = (PRINTDLG *) m_printDlgData ;
847 pd->hwndOwner=(HWND) win->GetHWND();
848 }
849 }
850 #endif // MSW
851
852 void wxPrintDialogData::operator=(const wxPrintDialogData& data)
853 {
854 m_printFromPage = data.m_printFromPage;
855 m_printToPage = data.m_printToPage;
856 m_printMinPage = data.m_printMinPage;
857 m_printMaxPage = data.m_printMaxPage;
858 m_printNoCopies = data.m_printNoCopies;
859 m_printAllPages = data.m_printAllPages;
860 m_printCollate = data.m_printCollate;
861 m_printToFile = data.m_printToFile;
862 m_printEnableSelection = data.m_printEnableSelection;
863 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
864 m_printEnableHelp = data.m_printEnableHelp;
865 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
866 m_printSetupDialog = data.m_printSetupDialog;
867
868 m_printData = data.m_printData;
869 }
870
871 void wxPrintDialogData::operator=(const wxPrintData& data)
872 {
873 m_printData = data;
874 }
875
876 // ----------------------------------------------------------------------------
877 // wxPageSetupDialogData
878 // ----------------------------------------------------------------------------
879
880 wxPageSetupDialogData::wxPageSetupDialogData()
881 {
882 #if defined(__WIN95__)
883 m_pageSetupData = NULL;
884 #endif
885 m_paperSize = wxSize(0, 0);
886
887 CalculatePaperSizeFromId();
888
889 m_minMarginTopLeft = wxPoint(0, 0);
890 m_minMarginBottomRight = wxPoint(0, 0);
891 m_marginTopLeft = wxPoint(0, 0);
892 m_marginBottomRight = wxPoint(0, 0);
893
894 // Flags
895 m_defaultMinMargins = FALSE;
896 m_enableMargins = TRUE;
897 m_enableOrientation = TRUE;
898 m_enablePaper = TRUE;
899 m_enablePrinter = TRUE;
900 m_enableHelp = FALSE;
901 m_getDefaultInfo = FALSE;
902 }
903
904 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
905 {
906 (*this) = dialogData;
907 }
908
909 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
910 {
911 #if defined(__WIN95__)
912 m_pageSetupData = NULL;
913 #endif
914 m_paperSize = wxSize(0, 0);
915 m_minMarginTopLeft = wxPoint(0, 0);
916 m_minMarginBottomRight = wxPoint(0, 0);
917 m_marginTopLeft = wxPoint(0, 0);
918 m_marginBottomRight = wxPoint(0, 0);
919
920 // Flags
921 m_defaultMinMargins = FALSE;
922 m_enableMargins = TRUE;
923 m_enableOrientation = TRUE;
924 m_enablePaper = TRUE;
925 m_enablePrinter = TRUE;
926 m_enableHelp = FALSE;
927 m_getDefaultInfo = FALSE;
928
929 m_printData = printData;
930
931 // The wxPrintData paper size overrides these values, unless the size cannot
932 // be found.
933 CalculatePaperSizeFromId();
934 }
935
936 wxPageSetupDialogData::~wxPageSetupDialogData()
937 {
938 #if defined(__WIN95__) && defined(__WXMSW__)
939 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
940 if ( pd && pd->hDevMode )
941 GlobalFree(pd->hDevMode);
942 if ( pd )
943 delete pd;
944 #endif
945 }
946
947 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
948 {
949 m_paperSize = data.m_paperSize;
950 m_minMarginTopLeft = data.m_minMarginTopLeft;
951 m_minMarginBottomRight = data.m_minMarginBottomRight;
952 m_marginTopLeft = data.m_marginTopLeft;
953 m_marginBottomRight = data.m_marginBottomRight;
954 m_defaultMinMargins = data.m_defaultMinMargins;
955 m_enableMargins = data.m_enableMargins;
956 m_enableOrientation = data.m_enableOrientation;
957 m_enablePaper = data.m_enablePaper;
958 m_enablePrinter = data.m_enablePrinter;
959 m_getDefaultInfo = data.m_getDefaultInfo;;
960 m_enableHelp = data.m_enableHelp;
961
962 m_printData = data.m_printData;
963 }
964
965 void wxPageSetupDialogData::operator=(const wxPrintData& data)
966 {
967 m_printData = data;
968 }
969
970 #if defined(__WIN95__)
971 void wxPageSetupDialogData::ConvertToNative()
972 {
973 m_printData.ConvertToNative();
974
975 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
976
977 if ( m_pageSetupData == NULL )
978 {
979 pd = new PAGESETUPDLG;
980 pd->hDevMode = NULL;
981 m_pageSetupData = (void *)pd;
982 }
983
984 // Pass the devmode data (created in m_printData.ConvertToNative)
985 // to the PRINTDLG structure, since it'll
986 // be needed when PrintDlg is called.
987
988 if (pd->hDevMode)
989 {
990 GlobalFree(pd->hDevMode);
991 pd->hDevMode = NULL;
992 }
993
994
995 pd->hDevMode = (HGLOBAL) m_printData.GetNativeData();
996
997 m_printData.SetNativeData((void*) NULL);
998
999 wxASSERT_MSG( (pd->hDevMode), "hDevMode must be non-NULL in ConvertToNative!");
1000
1001 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1002
1003 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
1004
1005 if ( m_defaultMinMargins )
1006 pd->Flags |= PSD_DEFAULTMINMARGINS;
1007 if ( !m_enableMargins )
1008 pd->Flags |= PSD_DISABLEMARGINS;
1009 if ( !m_enableOrientation )
1010 pd->Flags |= PSD_DISABLEORIENTATION;
1011 if ( !m_enablePaper )
1012 pd->Flags |= PSD_DISABLEPAPER;
1013 if ( !m_enablePrinter )
1014 pd->Flags |= PSD_DISABLEPRINTER;
1015 if ( m_getDefaultInfo )
1016 pd->Flags |= PSD_RETURNDEFAULT;
1017 if ( m_enableHelp )
1018 pd->Flags |= PSD_SHOWHELP;
1019
1020 // We want the units to be in hundredths of a millimetre
1021 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1022
1023 pd->lStructSize = sizeof( PAGESETUPDLG );
1024 pd->hwndOwner=(HWND)NULL;
1025 pd->hDevNames=(HWND)NULL;
1026 pd->hInstance=(HINSTANCE)NULL;
1027
1028 pd->ptPaperSize.x = m_paperSize.x * 100;
1029 pd->ptPaperSize.y = m_paperSize.y * 100;
1030
1031 pd->rtMinMargin.left = m_minMarginTopLeft.x * 100;
1032 pd->rtMinMargin.top = m_minMarginTopLeft.y * 100;
1033 pd->rtMinMargin.right = m_minMarginBottomRight.x * 100;
1034 pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100;
1035
1036 pd->rtMargin.left = m_marginTopLeft.x * 100;
1037 pd->rtMargin.top = m_marginTopLeft.y * 100;
1038 pd->rtMargin.right = m_marginBottomRight.x * 100;
1039 pd->rtMargin.bottom = m_marginBottomRight.y * 100;
1040
1041 pd->lCustData = 0;
1042 pd->lpfnPageSetupHook = NULL;
1043 pd->lpfnPagePaintHook = NULL;
1044 pd->hPageSetupTemplate = NULL;
1045 pd->lpPageSetupTemplateName = NULL;
1046
1047 /*
1048 if ( pd->hDevMode )
1049 {
1050 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1051 memset(devMode, 0, sizeof(DEVMODE));
1052 devMode->dmSize = sizeof(DEVMODE);
1053 devMode->dmOrientation = m_orientation;
1054 devMode->dmFields = DM_ORIENTATION;
1055 GlobalUnlock(pd->hDevMode);
1056 }
1057 */
1058 }
1059
1060 void wxPageSetupDialogData::ConvertFromNative()
1061 {
1062 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1063 if ( !pd )
1064 return;
1065
1066 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1067 if (pd->hDevMode)
1068 {
1069 if (m_printData.GetNativeData())
1070 {
1071 // Make sure we don't leak memory
1072 GlobalFree((HGLOBAL) m_printData.GetNativeData());
1073 }
1074 m_printData.SetNativeData((void*) pd->hDevMode);
1075 pd->hDevMode = NULL;
1076 }
1077
1078 m_printData.ConvertFromNative();
1079
1080 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
1081
1082 m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS);
1083 m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS);
1084 m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION);
1085 m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER);
1086 m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER);
1087 m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT);
1088 m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP);
1089
1090 m_paperSize.x = pd->ptPaperSize.x / 100;
1091 m_paperSize.y = pd->ptPaperSize.y / 100;
1092
1093 m_minMarginTopLeft.x = pd->rtMinMargin.left / 100;
1094 m_minMarginTopLeft.y = pd->rtMinMargin.top / 100;
1095 m_minMarginBottomRight.x = pd->rtMinMargin.right / 100;
1096 m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100;
1097
1098 m_marginTopLeft.x = pd->rtMargin.left / 100 ;
1099 m_marginTopLeft.y = pd->rtMargin.top / 100 ;
1100 m_marginBottomRight.x = pd->rtMargin.right / 100 ;
1101 m_marginBottomRight.y = pd->rtMargin.bottom / 100 ;
1102 }
1103
1104 void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
1105 {
1106 if ( m_pageSetupData == NULL )
1107 ConvertToNative();
1108
1109 if ( m_pageSetupData != NULL && win != NULL)
1110 {
1111 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1112 pd->hwndOwner=(HWND) win->GetHWND();
1113 }
1114 }
1115 #endif // Win95
1116
1117 // If a corresponding paper type is found in the paper database, will set the m_printData
1118 // paper size id member as well.
1119 void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
1120 {
1121 m_paperSize = sz;
1122
1123 CalculateIdFromPaperSize();
1124 }
1125
1126 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1127 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
1128 {
1129 m_printData.SetPaperId(id);
1130
1131 CalculatePaperSizeFromId();
1132 }
1133
1134 // Use paper size defined in this object to set the wxPrintData
1135 // paper id
1136 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1137 {
1138 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
1139 _T("wxThePrintPaperDatabase should not be NULL. "
1140 "Do not create global print dialog data objects.") );
1141
1142 wxSize sz = GetPaperSize();
1143
1144 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
1145 if (id != wxPAPER_NONE)
1146 {
1147 m_printData.SetPaperId(id);
1148 }
1149 }
1150
1151 // Use paper id in wxPrintData to set this object's paper size
1152 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1153 {
1154 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
1155 _T("wxThePrintPaperDatabase should not be NULL. "
1156 "Do not create global print dialog data objects.") );
1157
1158 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
1159
1160 if (sz.x != 0)
1161 {
1162 // sz is in 10ths of a mm, so multiply by 10.
1163 m_paperSize.x = sz.x * 10;
1164 m_paperSize.y = sz.y * 10;
1165 }
1166 }
1167