1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "cmndata.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/string.h"
30 #include "wx/gdicmn.h"
31 #include "wx/cmndata.h"
35 #if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT
36 #include "wx/generic/dcpsg.h"
42 #if !defined(__WIN32__)
47 #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__)
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
)
66 wxColourData::wxColourData()
69 for (i
= 0; i
< 16; i
++)
70 custColours
[i
].Set(255, 255, 255);
73 dataColour
.Set(0,0,0);
76 wxColourData::wxColourData(const wxColourData
& data
)
81 wxColourData::~wxColourData()
85 void wxColourData::SetCustomColour(int i
, wxColour
& colour
)
90 custColours
[i
] = colour
;
93 wxColour
wxColourData::GetCustomColour(int i
)
96 return wxColour(0,0,0);
98 return custColours
[i
];
101 void wxColourData::operator=(const wxColourData
& data
)
104 for (i
= 0; i
< 16; i
++)
105 custColours
[i
] = data
.custColours
[i
];
107 dataColour
= (wxColour
&)data
.dataColour
;
108 chooseFull
= data
.chooseFull
;
115 wxFontData::wxFontData()
117 // Intialize colour to black.
118 fontColour
.Set(0, 0, 0);
122 enableEffects
= TRUE
;
127 wxFontData::wxFontData(const wxFontData
& data
)
132 wxFontData::~wxFontData()
136 void wxFontData::operator=(const wxFontData
& data
)
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
;
152 wxPrintData::wxPrintData()
157 m_printOrientation
= wxPORTRAIT
;
159 m_printCollate
= FALSE
;
164 m_duplexMode
= wxDUPLEX_SIMPLEX
;
165 m_printQuality
= wxPRINT_QUALITY_HIGH
;
166 m_paperId
= wxPAPER_A4
;
167 m_paperSize
= wxSize(210, 297);
169 // PostScript-specific data
170 m_printerCommand
= "";
171 m_previewCommand
= "";
172 m_printerOptions
= "";
175 m_printerScaleX
= 1.0;
176 m_printerScaleY
= 1.0;
177 m_printerTranslateX
= 0;
178 m_printerTranslateY
= 0;
179 m_printMode
= wxPRINT_MODE_FILE
;
182 wxPrintData::wxPrintData(const wxPrintData
& printData
)
187 wxPrintData::~wxPrintData()
190 HGLOBAL hDevMode
= (HGLOBAL
) hDevMode
;
192 GlobalFree(hDevMode
);
194 PRINTDLG *pd = (PRINTDLG *) m_printData;
195 if ( pd && pd->hDevMode )
196 GlobalFree(pd->hDevMode);
205 void wxPrintData::ConvertToNative()
207 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
210 // Use PRINTDLG as a way of creating a DEVMODE object
211 PRINTDLG
*pd
= new PRINTDLG
;
213 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
215 pd
->lStructSize
= 66 ;
216 memset(pd
, 0, sizeof(PRINTDLG
));
218 pd
->lStructSize
= sizeof(PRINTDLG
);
219 memset(pd
, 0, sizeof(PRINTDLG
));
222 pd
->hwndOwner
= (HWND
)NULL
;
223 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
224 pd
->hDevNames
= NULL
; // Ditto
226 pd
->Flags
= PD_RETURNDEFAULT
;
229 // Fill out the DEVMODE structure
230 // so we can use it as input in the 'real' PrintDlg
234 GlobalFree(pd
->hDevMode
);
236 GlobalFree(pd
->hDevNames
);
238 pd
->hDevNames
= NULL
;
243 GlobalFree(pd
->hDevNames
);
244 pd
->hDevNames
= NULL
;
246 hDevMode
= pd
->hDevMode
;
247 m_devMode
= (void*) hDevMode
;
256 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
260 devMode
->dmOrientation
= m_printOrientation
;
261 devMode
->dmFields
= DM_ORIENTATION
;
265 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
266 devMode
->dmFields
|= DM_COLLATE
;
268 //// Number of copies
270 devMode
->dmCopies
= m_printNoCopies
;
271 devMode
->dmFields
|= DM_COPIES
;
275 if (m_printerName
!= "")
277 // TODO: make this Unicode compatible
278 int len
= wxMin(31, m_printerName
.Len());
280 for (i
= 0; i
< len
; i
++)
281 devMode
->dmDeviceName
[i
] = m_printerName
.GetChar(i
);
282 devMode
->dmDeviceName
[i
] = 0;
288 devMode
->dmColor
= DMCOLOR_COLOR
;
290 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
292 devMode
->dmFields
|= DM_COLOR
;
296 if (m_paperId
== wxPAPER_NONE
)
298 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
299 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
300 devMode
->dmFields
|= DM_PAPERWIDTH
;
301 devMode
->dmFields
|= DM_PAPERLENGTH
;
305 if (wxThePrintPaperDatabase
)
307 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
310 devMode
->dmPaperSize
= paper
->GetPlatformId();
311 devMode
->dmFields
|= DM_PAPERSIZE
;
319 switch (m_duplexMode
)
321 case wxDUPLEX_HORIZONTAL
: {
322 duplex
= DMDUP_HORIZONTAL
; break;
324 case wxDUPLEX_VERTICAL
: {
325 duplex
= DMDUP_VERTICAL
; break;
328 case wxDUPLEX_SIMPLEX
: {
329 duplex
= DMDUP_SIMPLEX
; break;
332 devMode
->dmDuplex
= duplex
;
333 devMode
->dmFields
|= DM_DUPLEX
;
338 switch (m_printQuality
)
340 case wxPRINT_QUALITY_MEDIUM
: {
341 quality
= DMRES_MEDIUM
; break;
343 case wxPRINT_QUALITY_LOW
: {
344 quality
= DMRES_LOW
; break;
346 case wxPRINT_QUALITY_DRAFT
: {
347 quality
= DMRES_DRAFT
; break;
349 case wxPRINT_QUALITY_HIGH
: {
350 quality
= DMRES_HIGH
; break;
353 quality
= m_printQuality
; break;
356 devMode
->dmPrintQuality
= quality
;
357 devMode
->dmFields
|= DM_PRINTQUALITY
;
359 GlobalUnlock(hDevMode
);
363 void wxPrintData::ConvertFromNative()
365 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
372 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
376 if (devMode
->dmFields
& DM_ORIENTATION
)
377 m_printOrientation
= devMode
->dmOrientation
;
381 if (devMode
->dmFields
& DM_COLLATE
)
383 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
384 m_printCollate
= TRUE
;
386 m_printCollate
= FALSE
;
389 //// Number of copies
391 if (devMode
->dmFields
& DM_COPIES
)
393 m_printNoCopies
= devMode
->dmCopies
;
398 if (devMode
->dmDeviceName
[0] != 0)
400 // TODO: make this Unicode compatible
403 while (devMode
->dmDeviceName
[i
] != 0)
405 buf
[i
] = devMode
->dmDeviceName
[i
];
415 if (devMode
->dmFields
& DM_COLOR
)
417 if (devMode
->dmColor
== DMCOLOR_COLOR
)
427 if (devMode
->dmFields
& DM_PAPERSIZE
)
429 if (wxThePrintPaperDatabase
)
431 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
434 m_paperId
= paper
->GetId();
435 m_paperSize
.x
= paper
->GetWidth() / 10 ;
436 m_paperSize
.y
= paper
->GetHeight() / 10 ;
440 // Shouldn't really get here
441 wxFAIL_MSG("Couldn't find paper size in paper database.");
443 m_paperId
= wxPAPER_NONE
;
450 // Shouldn't really get here
451 wxFAIL_MSG("Paper database wasn't initialized in wxPrintData::ConvertFromNative.");
453 m_paperId
= wxPAPER_NONE
;
458 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
460 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
461 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
462 m_paperId
= wxPAPER_NONE
;
466 // Shouldn't really get here
467 wxFAIL_MSG("Couldn't find paper size from DEVMODE.");
471 m_paperId
= wxPAPER_NONE
;
477 if (devMode
->dmFields
& DM_DUPLEX
)
479 switch (devMode
->dmDuplex
)
481 case DMDUP_HORIZONTAL
: {
482 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
484 case DMDUP_VERTICAL
: {
485 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
488 case DMDUP_SIMPLEX
: {
489 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
494 m_duplexMode
= wxDUPLEX_SIMPLEX
;
498 if (devMode
->dmFields
& DM_PRINTQUALITY
)
500 switch (devMode
->dmPrintQuality
)
503 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
506 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
509 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
512 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
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;
525 m_printQuality
= wxPRINT_QUALITY_HIGH
;
527 GlobalUnlock(hDevMode
);
533 void wxPrintData::operator=(const wxPrintData
& data
)
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
;
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
;
559 #if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT
560 void wxPrintData::operator=(const wxPrintSetupData
& setupData
)
562 SetPrinterCommand(setupData
.GetPrinterCommand());
563 SetPreviewCommand(setupData
.GetPrintPreviewCommand());
564 SetPrinterOptions(setupData
.GetPrinterOptions());
567 setupData
.GetPrinterTranslation(& xt
, & yt
);
568 SetPrinterTranslation(xt
, yt
);
571 setupData
.GetPrinterScaling(& xs
, & ys
);
572 SetPrinterScaling(xs
, ys
);
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());
589 wxPrintDialogData::wxPrintDialogData()
592 m_printDlgData
= NULL
;
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
;
609 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
611 (*this) = dialogData
;
614 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
617 m_printDlgData
= NULL
;
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
;
633 m_printData
= printData
;
636 wxPrintDialogData::~wxPrintDialogData()
639 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
640 if ( pd
&& pd
->hDevMode
)
641 GlobalFree(pd
->hDevMode
);
648 void wxPrintDialogData::ConvertToNative()
650 m_printData
.ConvertToNative();
652 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
657 m_printDlgData
= (void*) pd
;
659 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
661 pd
->lStructSize
= 66 ;
664 pd
->lStructSize
= sizeof(PRINTDLG
);
665 pd
->hwndOwner
= (HWND
)NULL
;
666 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
667 pd
->hDevNames
= NULL
; // Ditto
669 pd
->Flags
= PD_RETURNDEFAULT
;
673 // Pass the devmode data to the PRINTDLG structure, since it'll
674 // be needed when PrintDlg is called.
677 GlobalFree(pd
->hDevMode
);
680 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
682 m_printData
.SetNativeData((void*) NULL
);
684 wxASSERT_MSG( (pd
->hDevMode
), "hDevMode must be non-NULL in ConvertToNative!");
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
;
693 pd
->Flags
= PD_RETURNDC
;
696 pd
->lStructSize
= 66 ;
698 pd
->lStructSize
= sizeof( PRINTDLG
);
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
;
712 if ( m_printAllPages
)
713 pd
->Flags
|= PD_ALLPAGES
;
714 if ( m_printCollate
)
715 pd
->Flags
|= PD_COLLATE
;
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
;
730 void wxPrintDialogData::ConvertFromNative()
732 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
736 // Pass the devmode data back to the wxPrintData structure where it really belongs.
739 if (m_printData
.GetNativeData())
741 // Make sure we don't leak memory
742 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
744 m_printData
.SetNativeData((void*) pd
->hDevMode
);
748 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
749 // into wxWindows form.
750 m_printData
.ConvertFromNative();
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
;
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
);
767 /* port is obsolete in WIN32
771 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
773 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
774 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
775 GlobalUnlock(pd->hDevNames);
777 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
783 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
785 if ( m_printDlgData
== NULL
)
788 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
790 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
791 pd
->hwndOwner
=(HWND
) win
->GetHWND();
796 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
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
;
812 m_printData
= data
.m_printData
;
815 void wxPrintDialogData::operator=(const wxPrintData
& data
)
821 * wxPageSetupDialogData
824 wxPageSetupDialogData::wxPageSetupDialogData()
826 #if defined(__WIN95__)
827 m_pageSetupData
= NULL
;
829 m_paperSize
= wxSize(0, 0);
831 CalculatePaperSizeFromId();
833 m_minMarginTopLeft
= wxPoint(0, 0);
834 m_minMarginBottomRight
= wxPoint(0, 0);
835 m_marginTopLeft
= wxPoint(0, 0);
836 m_marginBottomRight
= wxPoint(0, 0);
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
;
848 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
850 (*this) = dialogData
;
853 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
855 #if defined(__WIN95__)
856 m_pageSetupData
= NULL
;
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);
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
;
873 m_printData
= printData
;
875 // The wxPrintData paper size overrides these values, unless the size cannot
877 CalculatePaperSizeFromId();
880 wxPageSetupDialogData::~wxPageSetupDialogData()
882 #if defined(__WIN95__) && defined(__WXMSW__)
883 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
884 if ( pd
&& pd
->hDevMode
)
885 GlobalFree(pd
->hDevMode
);
891 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
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
;
906 m_printData
= data
.m_printData
;
909 void wxPageSetupDialogData::operator=(const wxPrintData
& data
)
914 #if defined(__WXMSW__) && defined(__WIN95__)
915 void wxPageSetupDialogData::ConvertToNative()
917 m_printData
.ConvertToNative();
919 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
921 if ( m_pageSetupData
== NULL
)
923 pd
= new PAGESETUPDLG
;
925 m_pageSetupData
= (void *)pd
;
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.
934 GlobalFree(pd
->hDevMode
);
939 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
941 m_printData
.SetNativeData((void*) NULL
);
943 wxASSERT_MSG( (pd
->hDevMode
), "hDevMode must be non-NULL in ConvertToNative!");
945 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
947 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
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
;
962 pd
->Flags
|= PSD_SHOWHELP
;
964 // We want the units to be in hundredths of a millimetre
965 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
967 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
968 pd
->hwndOwner
=(HWND
)NULL
;
969 pd
->hDevNames
=(HWND
)NULL
;
970 pd
->hInstance
=(HINSTANCE
)NULL
;
972 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
973 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
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;
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;
986 pd
->lpfnPageSetupHook
= NULL
;
987 pd
->lpfnPagePaintHook
= NULL
;
988 pd
->hPageSetupTemplate
= NULL
;
989 pd
->lpPageSetupTemplateName
= NULL
;
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);
1004 void wxPageSetupDialogData::ConvertFromNative()
1006 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1010 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1013 if (m_printData
.GetNativeData())
1015 // Make sure we don't leak memory
1016 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1018 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1019 pd
->hDevMode
= NULL
;
1022 m_printData
.ConvertFromNative();
1024 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
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
);
1034 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1035 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
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;
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 ;
1048 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1050 if ( m_pageSetupData
== NULL
)
1053 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1055 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1056 pd
->hwndOwner
=(HWND
) win
->GetHWND();
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
)
1067 CalculateIdFromPaperSize();
1070 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1071 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1073 m_printData
.SetPaperId(id
);
1075 CalculatePaperSizeFromId();
1078 // Use paper size defined in this object to set the wxPrintData
1080 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1082 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
), "wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects." );
1084 wxSize sz
= GetPaperSize();
1086 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1087 if (id
!= wxPAPER_NONE
)
1089 m_printData
.SetPaperId(id
);
1093 // Use paper id in wxPrintData to set this object's paper size
1094 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1096 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
), "wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects." );
1098 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
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;