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