1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "cmndata.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/string.h"
38 #include "wx/gdicmn.h"
39 #include "wx/cmndata.h"
41 #include "wx/prntbase.h"
42 #include "wx/printdlg.h"
45 #include "wx/fontdlg.h"
46 #endif // wxUSE_FONTDLG
48 #if wxUSE_PRINTING_ARCHITECTURE
50 #endif // wxUSE_PRINTING_ARCHITECTURE
52 #if defined(__WXMSW__) && !defined(__PALMOS__)
54 #include "wx/msw/private.h"
56 #ifndef __SMARTPHONE__ /* of WinCE */
60 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
67 #include "wx/mac/private/print.h"
70 #if wxUSE_PRINTING_ARCHITECTURE
71 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
72 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
73 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
74 #endif // wxUSE_PRINTING_ARCHITECTURE
76 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
77 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
80 #define DMPAPER_USER 256
83 // ============================================================================
85 // ============================================================================
87 // ----------------------------------------------------------------------------
89 // ----------------------------------------------------------------------------
91 wxColourData::wxColourData()
94 m_dataColour
.Set(0,0,0);
95 // m_custColours are wxNullColours initially
98 wxColourData::wxColourData(const wxColourData
& data
)
104 wxColourData::~wxColourData()
108 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
110 wxCHECK_RET( (i
>= 0 && i
< 16), _T("custom colour index out of range") );
112 m_custColours
[i
] = colour
;
115 wxColour
wxColourData::GetCustomColour(int i
)
117 wxCHECK_MSG( (i
>= 0 && i
< 16), wxColour(0,0,0),
118 _T("custom colour index out of range") );
120 return m_custColours
[i
];
123 void wxColourData::operator=(const wxColourData
& data
)
126 for (i
= 0; i
< 16; i
++)
127 m_custColours
[i
] = data
.m_custColours
[i
];
129 m_dataColour
= (wxColour
&)data
.m_dataColour
;
130 m_chooseFull
= data
.m_chooseFull
;
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 wxFontData::wxFontData()
139 // Intialize colour to black.
140 m_fontColour
= wxNullColour
;
143 m_allowSymbols
= true;
144 m_enableEffects
= true;
148 m_encoding
= wxFONTENCODING_SYSTEM
;
151 wxFontData::~wxFontData()
157 wxFontDialogBase::~wxFontDialogBase()
161 #endif // wxUSE_FONTDLG
163 #if wxUSE_PRINTING_ARCHITECTURE
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 wxPrintData::wxPrintData()
171 m_nativePrintData
= wxNativePrintData::Create() ;
173 m_bin
= wxPRINTBIN_DEFAULT
;
174 m_printMode
= wxPRINT_MODE_PRINTER
;
175 m_printOrientation
= wxPORTRAIT
;
177 m_printCollate
= false;
180 m_printerName
= wxT("");
182 m_duplexMode
= wxDUPLEX_SIMPLEX
;
183 m_printQuality
= wxPRINT_QUALITY_HIGH
;
184 m_paperId
= wxPAPER_A4
;
185 m_paperSize
= wxSize(210, 297);
187 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
190 wxPrintData::wxPrintData(const wxPrintData
& printData
)
196 wxPrintData::~wxPrintData()
198 m_nativeData
->m_ref
--;
199 if (m_nativeData
->m_ref
== 0)
203 delete m_nativePrintData
;
209 void wxPrintData::ConvertToNative()
211 m_nativePrintData
->TransferFrom( this ) ;
214 void wxPrintData::ConvertFromNative()
216 m_nativePrintData
->TransferTo( this ) ;
220 void wxPrintData::operator=(const wxPrintData
& data
)
222 m_printNoCopies
= data
.m_printNoCopies
;
223 m_printCollate
= data
.m_printCollate
;
224 m_printOrientation
= data
.m_printOrientation
;
225 m_printerName
= data
.m_printerName
;
226 m_colour
= data
.m_colour
;
227 m_duplexMode
= data
.m_duplexMode
;
228 m_printQuality
= data
.m_printQuality
;
229 m_paperId
= data
.m_paperId
;
230 m_paperSize
= data
.m_paperSize
;
232 m_printMode
= data
.m_printMode
;
234 m_nativeData
= data
.GetNativeData();
235 m_nativeData
->m_ref
++;
238 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
242 // Is this data OK for showing the print dialog?
243 bool wxPrintData::Ok() const
245 m_nativeData
->TransferFrom( *this );
247 return m_nativeData
->Ok();
250 // ----------------------------------------------------------------------------
252 // ----------------------------------------------------------------------------
254 wxPrintDialogData::wxPrintDialogData()
257 m_printDlgData
= NULL
;
264 m_printAllPages
= false;
265 m_printCollate
= false;
266 m_printToFile
= false;
267 m_printSelection
= false;
268 m_printEnableSelection
= false;
269 m_printEnablePageNumbers
= true;
270 m_printEnablePrintToFile
= true;
271 m_printEnableHelp
= false;
272 m_printSetupDialog
= false;
275 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
279 m_printDlgData
= NULL
;
281 (*this) = dialogData
;
284 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
287 m_printDlgData
= NULL
;
292 m_printMaxPage
= 9999;
294 m_printAllPages
= false;
295 m_printCollate
= false;
296 m_printToFile
= false;
297 m_printSelection
= false;
298 m_printEnableSelection
= false;
299 m_printEnablePageNumbers
= true;
300 m_printEnablePrintToFile
= true;
301 m_printEnableHelp
= false;
302 m_printSetupDialog
= false;
304 m_printData
= printData
;
307 wxPrintDialogData::~wxPrintDialogData()
310 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
311 if ( pd
&& pd
->hDevMode
)
312 GlobalFree(pd
->hDevMode
);
319 void wxPrintDialogData::ConvertToNative()
321 wxWindowsPrintNativeData
*data
=
322 (wxWindowsPrintNativeData
*) m_printData
.GetNativeData();
323 data
->TransferFrom( m_printData
);
325 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
330 memset( pd
, 0, sizeof(PRINTDLG
) );
331 m_printDlgData
= (void*) pd
;
333 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
335 pd
->lStructSize
= 66;
337 pd
->lStructSize
= sizeof(PRINTDLG
);
339 pd
->hwndOwner
= (HWND
)NULL
;
340 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
341 pd
->hDevNames
= NULL
; // Ditto
343 pd
->Flags
= PD_RETURNDEFAULT
;
347 // Pass the devmode data to the PRINTDLG structure, since it'll
348 // be needed when PrintDlg is called.
351 GlobalFree(pd
->hDevMode
);
354 // Pass the devnames data to the PRINTDLG structure, since it'll
355 // be needed when PrintDlg is called.
358 GlobalFree(pd
->hDevNames
);
361 pd
->hDevMode
= (HGLOBAL
)(DWORD
) data
->GetDevMode();
363 data
->SetDevMode( (void*) NULL
);
365 // Shouldn't assert; we should be able to test Ok-ness at a higher level
366 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
368 pd
->hDevNames
= (HGLOBAL
)(DWORD
) data
->GetDevNames();
370 data
->SetDevNames( (void*) NULL
);
372 pd
->hDC
= (HDC
) NULL
;
373 pd
->nFromPage
= (WORD
)m_printFromPage
;
374 pd
->nToPage
= (WORD
)m_printToPage
;
375 pd
->nMinPage
= (WORD
)m_printMinPage
;
376 pd
->nMaxPage
= (WORD
)m_printMaxPage
;
377 pd
->nCopies
= (WORD
)m_printNoCopies
;
379 pd
->Flags
= PD_RETURNDC
;
382 pd
->lStructSize
= 66;
384 pd
->lStructSize
= sizeof( PRINTDLG
);
387 pd
->hwndOwner
=(HWND
)NULL
;
388 // pd->hDevNames=(HANDLE)NULL;
389 pd
->hInstance
=(HINSTANCE
)NULL
;
390 pd
->lCustData
= (LPARAM
) NULL
;
391 pd
->lpfnPrintHook
= NULL
;
392 pd
->lpfnSetupHook
= NULL
;
393 pd
->lpPrintTemplateName
= NULL
;
394 pd
->lpSetupTemplateName
= NULL
;
395 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
396 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
398 if ( m_printAllPages
)
399 pd
->Flags
|= PD_ALLPAGES
;
400 if ( m_printSelection
)
401 pd
->Flags
|= PD_SELECTION
;
402 if ( m_printCollate
)
403 pd
->Flags
|= PD_COLLATE
;
405 pd
->Flags
|= PD_PRINTTOFILE
;
406 if ( !m_printEnablePrintToFile
)
407 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
408 if ( !m_printEnableSelection
)
409 pd
->Flags
|= PD_NOSELECTION
;
410 if ( !m_printEnablePageNumbers
)
411 pd
->Flags
|= PD_NOPAGENUMS
;
412 else if ( (!m_printAllPages
) && (!m_printSelection
) && (m_printFromPage
!= 0) && (m_printToPage
!= 0))
413 pd
->Flags
|= PD_PAGENUMS
;
414 if ( m_printEnableHelp
)
415 pd
->Flags
|= PD_SHOWHELP
;
416 if ( m_printSetupDialog
)
417 pd
->Flags
|= PD_PRINTSETUP
;
420 void wxPrintDialogData::ConvertFromNative()
422 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
426 wxWindowsPrintNativeData
*data
=
427 (wxWindowsPrintNativeData
*) m_printData
.GetNativeData();
429 // Pass the devmode data back to the wxPrintData structure where it really belongs.
432 if (data
->GetDevMode())
434 // Make sure we don't leak memory
435 GlobalFree( (HGLOBAL
)(DWORD
) data
->GetDevMode() );
437 data
->SetDevMode( (void*)(long) pd
->hDevMode
);
441 // Pass the devnames data back to the wxPrintData structure where it really belongs.
444 if (data
->GetDevNames())
446 // Make sure we don't leak memory
447 GlobalFree((HGLOBAL
)(DWORD
) data
->GetDevNames());
449 data
->SetDevNames((void*)(long) pd
->hDevNames
);
450 pd
->hDevNames
= NULL
;
453 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
454 // into wxWidgets form.
455 data
->TransferTo( m_printData
);
457 m_printFromPage
= pd
->nFromPage
;
458 m_printToPage
= pd
->nToPage
;
459 m_printMinPage
= pd
->nMinPage
;
460 m_printMaxPage
= pd
->nMaxPage
;
461 m_printNoCopies
= pd
->nCopies
;
463 m_printAllPages
= (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
));
464 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
465 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
466 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
467 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
468 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
469 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
470 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
471 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
473 /* port is obsolete in WIN32
477 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
479 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
480 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
481 GlobalUnlock(pd->hDevNames);
483 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
489 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
491 if ( m_printDlgData
== NULL
)
494 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
496 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
497 pd
->hwndOwner
=(HWND
) win
->GetHWND();
504 void wxPrintDialogData::ConvertToNative()
506 m_printData
.ConvertToNative();
507 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
510 void wxPrintDialogData::ConvertFromNative()
512 m_printData
.ConvertFromNative();
513 m_printData
.m_nativePrintData
->TransferTo( this ) ;
519 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
521 m_printFromPage
= data
.m_printFromPage
;
522 m_printToPage
= data
.m_printToPage
;
523 m_printMinPage
= data
.m_printMinPage
;
524 m_printMaxPage
= data
.m_printMaxPage
;
525 m_printNoCopies
= data
.m_printNoCopies
;
526 m_printAllPages
= data
.m_printAllPages
;
527 m_printCollate
= data
.m_printCollate
;
528 m_printToFile
= data
.m_printToFile
;
529 m_printSelection
= data
.m_printSelection
;
530 m_printEnableSelection
= data
.m_printEnableSelection
;
531 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
532 m_printEnableHelp
= data
.m_printEnableHelp
;
533 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
534 m_printSetupDialog
= data
.m_printSetupDialog
;
536 m_printData
= data
.m_printData
;
539 void wxPrintDialogData::operator=(const wxPrintData
& data
)
544 // ----------------------------------------------------------------------------
545 // wxPageSetupDialogData
546 // ----------------------------------------------------------------------------
548 wxPageSetupDialogData::wxPageSetupDialogData()
550 #if defined(__WIN95__)
551 m_pageSetupData
= NULL
;
553 m_paperSize
= wxSize(0, 0);
555 CalculatePaperSizeFromId();
557 m_minMarginTopLeft
= wxPoint(0, 0);
558 m_minMarginBottomRight
= wxPoint(0, 0);
559 m_marginTopLeft
= wxPoint(0, 0);
560 m_marginBottomRight
= wxPoint(0, 0);
563 m_defaultMinMargins
= false;
564 m_enableMargins
= true;
565 m_enableOrientation
= true;
566 m_enablePaper
= true;
567 m_enablePrinter
= true;
568 m_enableHelp
= false;
569 m_getDefaultInfo
= false;
572 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
575 #if defined(__WIN95__)
576 m_pageSetupData
= NULL
;
578 (*this) = dialogData
;
581 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
583 #if defined(__WIN95__)
584 m_pageSetupData
= NULL
;
586 m_paperSize
= wxSize(0, 0);
587 m_minMarginTopLeft
= wxPoint(0, 0);
588 m_minMarginBottomRight
= wxPoint(0, 0);
589 m_marginTopLeft
= wxPoint(0, 0);
590 m_marginBottomRight
= wxPoint(0, 0);
593 m_defaultMinMargins
= false;
594 m_enableMargins
= true;
595 m_enableOrientation
= true;
596 m_enablePaper
= true;
597 m_enablePrinter
= true;
598 m_enableHelp
= false;
599 m_getDefaultInfo
= false;
601 m_printData
= printData
;
603 // The wxPrintData paper size overrides these values, unless the size cannot
605 CalculatePaperSizeFromId();
608 wxPageSetupDialogData::~wxPageSetupDialogData()
610 #if defined(__WIN95__) && defined(__WXMSW__)
611 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
612 if ( pd
&& pd
->hDevMode
)
613 GlobalFree(pd
->hDevMode
);
614 if ( pd
&& pd
->hDevNames
)
615 GlobalFree(pd
->hDevNames
);
621 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
623 m_paperSize
= data
.m_paperSize
;
624 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
625 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
626 m_marginTopLeft
= data
.m_marginTopLeft
;
627 m_marginBottomRight
= data
.m_marginBottomRight
;
628 m_defaultMinMargins
= data
.m_defaultMinMargins
;
629 m_enableMargins
= data
.m_enableMargins
;
630 m_enableOrientation
= data
.m_enableOrientation
;
631 m_enablePaper
= data
.m_enablePaper
;
632 m_enablePrinter
= data
.m_enablePrinter
;
633 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
634 m_enableHelp
= data
.m_enableHelp
;
636 m_printData
= data
.m_printData
;
641 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
648 #if defined(__WIN95__)
649 void wxPageSetupDialogData::ConvertToNative()
651 wxWindowsPrintNativeData
*data
=
652 (wxWindowsPrintNativeData
*) m_printData
.GetNativeData();
653 data
->TransferFrom( m_printData
);
655 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
657 if ( m_pageSetupData
== NULL
)
659 pd
= new PAGESETUPDLG
;
661 pd
->hDevNames
= NULL
;
662 m_pageSetupData
= (void *)pd
;
665 // Pass the devmode data (created in m_printData.ConvertToNative)
666 // to the PRINTDLG structure, since it'll
667 // be needed when PrintDlg is called.
671 GlobalFree(pd
->hDevMode
);
675 pd
->hDevMode
= (HGLOBAL
) data
->GetDevMode();
677 data
->SetDevMode( (void*) NULL
);
679 // Shouldn't assert; we should be able to test Ok-ness at a higher level
680 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
682 // Pass the devnames data (created in m_printData.ConvertToNative)
683 // to the PRINTDLG structure, since it'll
684 // be needed when PrintDlg is called.
688 GlobalFree(pd
->hDevNames
);
689 pd
->hDevNames
= NULL
;
692 pd
->hDevNames
= (HGLOBAL
) data
->GetDevNames();
694 data
->SetDevNames((void*) NULL
);
696 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
698 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
700 if ( m_defaultMinMargins
)
701 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
702 if ( !m_enableMargins
)
703 pd
->Flags
|= PSD_DISABLEMARGINS
;
704 if ( !m_enableOrientation
)
705 pd
->Flags
|= PSD_DISABLEORIENTATION
;
706 if ( !m_enablePaper
)
707 pd
->Flags
|= PSD_DISABLEPAPER
;
708 if ( !m_enablePrinter
)
709 pd
->Flags
|= PSD_DISABLEPRINTER
;
710 if ( m_getDefaultInfo
)
711 pd
->Flags
|= PSD_RETURNDEFAULT
;
713 pd
->Flags
|= PSD_SHOWHELP
;
715 // We want the units to be in hundredths of a millimetre
716 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
718 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
719 pd
->hwndOwner
=(HWND
)NULL
;
720 // pd->hDevNames=(HWND)NULL;
721 pd
->hInstance
=(HINSTANCE
)NULL
;
722 // PAGESETUPDLG is in hundreds of a mm
723 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
724 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
726 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
727 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
728 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
729 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
731 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
732 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
733 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
734 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
737 pd
->lpfnPageSetupHook
= NULL
;
738 pd
->lpfnPagePaintHook
= NULL
;
739 pd
->hPageSetupTemplate
= NULL
;
740 pd
->lpPageSetupTemplateName
= NULL
;
745 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
746 memset(devMode, 0, sizeof(DEVMODE));
747 devMode->dmSize = sizeof(DEVMODE);
748 devMode->dmOrientation = m_orientation;
749 devMode->dmFields = DM_ORIENTATION;
750 GlobalUnlock(pd->hDevMode);
755 void wxPageSetupDialogData::ConvertFromNative()
757 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
761 wxWindowsPrintNativeData
*data
=
762 (wxWindowsPrintNativeData
*) m_printData
.GetNativeData();
764 // Pass the devmode data back to the wxPrintData structure where it really belongs.
767 if (data
->GetDevMode())
769 // Make sure we don't leak memory
770 GlobalFree((HGLOBAL
) data
->GetDevMode());
772 data
->SetDevMode( (void*) pd
->hDevMode
);
776 data
->TransferTo( m_printData
);
778 // Pass the devnames data back to the wxPrintData structure where it really belongs.
781 if (data
->GetDevNames())
783 // Make sure we don't leak memory
784 GlobalFree((HGLOBAL
) data
->GetDevNames());
786 data
->SetDevNames((void*) pd
->hDevNames
);
787 pd
->hDevNames
= NULL
;
790 data
->TransferTo( m_printData
);
792 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
794 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
795 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
796 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
797 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
798 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
799 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
800 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
802 // PAGESETUPDLG is in hundreds of a mm
803 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
804 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
806 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
807 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
808 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
809 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
811 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100;
812 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100;
813 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100;
814 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100;
817 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
819 if ( m_pageSetupData
== NULL
)
822 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
824 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
825 pd
->hwndOwner
=(HWND
) win
->GetHWND();
831 void wxPageSetupDialogData::ConvertToNative()
833 m_printData
.ConvertToNative();
834 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
837 void wxPageSetupDialogData::ConvertFromNative()
839 m_printData
.ConvertFromNative ();
840 m_paperSize
= m_printData
.GetPaperSize() ;
841 CalculateIdFromPaperSize();
842 m_printData
.m_nativePrintData
->TransferTo( this ) ;
843 // adjust minimal values
845 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
846 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
848 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
849 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
851 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
852 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
854 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
855 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
860 // If a corresponding paper type is found in the paper database, will set the m_printData
861 // paper size id member as well.
862 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
866 CalculateIdFromPaperSize();
869 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
870 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
872 m_printData
.SetPaperId(id
);
874 CalculatePaperSizeFromId();
877 // Use paper size defined in this object to set the wxPrintData
879 void wxPageSetupDialogData::CalculateIdFromPaperSize()
881 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
882 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
884 wxSize sz
= GetPaperSize();
886 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
887 if (id
!= wxPAPER_NONE
)
889 m_printData
.SetPaperId(id
);
893 // Use paper id in wxPrintData to set this object's paper size
894 void wxPageSetupDialogData::CalculatePaperSizeFromId()
896 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
897 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
899 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
901 // sz is in 10ths of a mm, while paper size is in mm
902 m_paperSize
.x
= sz
.x
/ 10;
903 m_paperSize
.y
= sz
.y
/ 10;
906 #endif // wxUSE_PRINTING_ARCHITECTURE