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
;
208 void wxPrintData::ConvertToNative()
211 m_nativePrintData
->TransferFrom( this ) ;
213 m_nativeData
->TransferFrom( *this ) ;
217 void wxPrintData::ConvertFromNative()
220 m_nativePrintData
->TransferTo( this ) ;
222 m_nativeData
->TransferTo( *this ) ;
226 void wxPrintData::operator=(const wxPrintData
& data
)
228 m_printNoCopies
= data
.m_printNoCopies
;
229 m_printCollate
= data
.m_printCollate
;
230 m_printOrientation
= data
.m_printOrientation
;
231 m_printerName
= data
.m_printerName
;
232 m_colour
= data
.m_colour
;
233 m_duplexMode
= data
.m_duplexMode
;
234 m_printQuality
= data
.m_printQuality
;
235 m_paperId
= data
.m_paperId
;
236 m_paperSize
= data
.m_paperSize
;
238 m_printMode
= data
.m_printMode
;
239 m_filename
= data
.m_filename
;
241 m_nativeData
= data
.GetNativeData();
242 m_nativeData
->m_ref
++;
245 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
249 // Is this data OK for showing the print dialog?
250 bool wxPrintData::Ok() const
252 m_nativeData
->TransferFrom( *this );
254 return m_nativeData
->Ok();
257 // ----------------------------------------------------------------------------
259 // ----------------------------------------------------------------------------
261 wxPrintDialogData::wxPrintDialogData()
264 m_printDlgData
= NULL
;
271 m_printAllPages
= false;
272 m_printCollate
= false;
273 m_printToFile
= false;
274 m_printSelection
= false;
275 m_printEnableSelection
= false;
276 m_printEnablePageNumbers
= true;
278 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
279 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
281 m_printEnableHelp
= false;
282 m_printSetupDialog
= false;
285 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
289 m_printDlgData
= NULL
;
291 (*this) = dialogData
;
294 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
297 m_printDlgData
= NULL
;
302 m_printMaxPage
= 9999;
304 m_printAllPages
= false;
305 m_printCollate
= false;
306 m_printToFile
= false;
307 m_printSelection
= false;
308 m_printEnableSelection
= false;
309 m_printEnablePageNumbers
= true;
310 m_printEnablePrintToFile
= true;
311 m_printEnableHelp
= false;
312 m_printSetupDialog
= false;
314 m_printData
= printData
;
317 wxPrintDialogData::~wxPrintDialogData()
320 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
321 if ( pd
&& pd
->hDevMode
)
322 GlobalFree(pd
->hDevMode
);
329 void wxPrintDialogData::ConvertToNative()
331 wxWindowsPrintNativeData
*data
=
332 (wxWindowsPrintNativeData
*) m_printData
.GetNativeData();
333 data
->TransferFrom( m_printData
);
335 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
340 memset( pd
, 0, sizeof(PRINTDLG
) );
341 m_printDlgData
= (void*) pd
;
343 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
345 pd
->lStructSize
= 66;
347 pd
->lStructSize
= sizeof(PRINTDLG
);
349 pd
->hwndOwner
= (HWND
)NULL
;
350 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
351 pd
->hDevNames
= NULL
; // Ditto
353 pd
->Flags
= PD_RETURNDEFAULT
;
357 // Pass the devmode data to the PRINTDLG structure, since it'll
358 // be needed when PrintDlg is called.
361 GlobalFree(pd
->hDevMode
);
364 // Pass the devnames data to the PRINTDLG structure, since it'll
365 // be needed when PrintDlg is called.
368 GlobalFree(pd
->hDevNames
);
371 pd
->hDevMode
= (HGLOBAL
)(DWORD
) data
->GetDevMode();
373 data
->SetDevMode( (void*) NULL
);
375 // Shouldn't assert; we should be able to test Ok-ness at a higher level
376 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
378 pd
->hDevNames
= (HGLOBAL
)(DWORD
) data
->GetDevNames();
380 data
->SetDevNames( (void*) NULL
);
382 pd
->hDC
= (HDC
) NULL
;
383 pd
->nFromPage
= (WORD
)m_printFromPage
;
384 pd
->nToPage
= (WORD
)m_printToPage
;
385 pd
->nMinPage
= (WORD
)m_printMinPage
;
386 pd
->nMaxPage
= (WORD
)m_printMaxPage
;
387 pd
->nCopies
= (WORD
)m_printNoCopies
;
389 pd
->Flags
= PD_RETURNDC
;
392 pd
->lStructSize
= 66;
394 pd
->lStructSize
= sizeof( PRINTDLG
);
397 pd
->hwndOwner
=(HWND
)NULL
;
398 // pd->hDevNames=(HANDLE)NULL;
399 pd
->hInstance
=(HINSTANCE
)NULL
;
400 pd
->lCustData
= (LPARAM
) NULL
;
401 pd
->lpfnPrintHook
= NULL
;
402 pd
->lpfnSetupHook
= NULL
;
403 pd
->lpPrintTemplateName
= NULL
;
404 pd
->lpSetupTemplateName
= NULL
;
405 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
406 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
408 if ( m_printAllPages
)
409 pd
->Flags
|= PD_ALLPAGES
;
410 if ( m_printSelection
)
411 pd
->Flags
|= PD_SELECTION
;
412 if ( m_printCollate
)
413 pd
->Flags
|= PD_COLLATE
;
415 pd
->Flags
|= PD_PRINTTOFILE
;
416 if ( !m_printEnablePrintToFile
)
417 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
418 if ( !m_printEnableSelection
)
419 pd
->Flags
|= PD_NOSELECTION
;
420 if ( !m_printEnablePageNumbers
)
421 pd
->Flags
|= PD_NOPAGENUMS
;
422 else if ( (!m_printAllPages
) && (!m_printSelection
) && (m_printFromPage
!= 0) && (m_printToPage
!= 0))
423 pd
->Flags
|= PD_PAGENUMS
;
424 if ( m_printEnableHelp
)
425 pd
->Flags
|= PD_SHOWHELP
;
426 if ( m_printSetupDialog
)
427 pd
->Flags
|= PD_PRINTSETUP
;
430 void wxPrintDialogData::ConvertFromNative()
432 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
436 wxWindowsPrintNativeData
*data
=
437 (wxWindowsPrintNativeData
*) m_printData
.GetNativeData();
439 // Pass the devmode data back to the wxPrintData structure where it really belongs.
442 if (data
->GetDevMode())
444 // Make sure we don't leak memory
445 GlobalFree( (HGLOBAL
)(DWORD
) data
->GetDevMode() );
447 data
->SetDevMode( (void*)(long) pd
->hDevMode
);
451 // Pass the devnames data back to the wxPrintData structure where it really belongs.
454 if (data
->GetDevNames())
456 // Make sure we don't leak memory
457 GlobalFree((HGLOBAL
)(DWORD
) data
->GetDevNames());
459 data
->SetDevNames((void*)(long) pd
->hDevNames
);
460 pd
->hDevNames
= NULL
;
463 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
464 // into wxWidgets form.
465 data
->TransferTo( m_printData
);
467 m_printFromPage
= pd
->nFromPage
;
468 m_printToPage
= pd
->nToPage
;
469 m_printMinPage
= pd
->nMinPage
;
470 m_printMaxPage
= pd
->nMaxPage
;
471 m_printNoCopies
= pd
->nCopies
;
473 m_printAllPages
= (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
));
474 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
475 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
476 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
477 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
478 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
479 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
480 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
481 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
483 /* port is obsolete in WIN32
487 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
489 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
490 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
491 GlobalUnlock(pd->hDevNames);
493 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
499 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
501 if ( m_printDlgData
== NULL
)
504 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
506 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
507 pd
->hwndOwner
=(HWND
) win
->GetHWND();
514 void wxPrintDialogData::ConvertToNative()
516 m_printData
.ConvertToNative();
517 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
520 void wxPrintDialogData::ConvertFromNative()
522 m_printData
.ConvertFromNative();
523 m_printData
.m_nativePrintData
->TransferTo( this ) ;
529 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
531 m_printFromPage
= data
.m_printFromPage
;
532 m_printToPage
= data
.m_printToPage
;
533 m_printMinPage
= data
.m_printMinPage
;
534 m_printMaxPage
= data
.m_printMaxPage
;
535 m_printNoCopies
= data
.m_printNoCopies
;
536 m_printAllPages
= data
.m_printAllPages
;
537 m_printCollate
= data
.m_printCollate
;
538 m_printToFile
= data
.m_printToFile
;
539 m_printSelection
= data
.m_printSelection
;
540 m_printEnableSelection
= data
.m_printEnableSelection
;
541 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
542 m_printEnableHelp
= data
.m_printEnableHelp
;
543 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
544 m_printSetupDialog
= data
.m_printSetupDialog
;
546 m_printData
= data
.m_printData
;
549 void wxPrintDialogData::operator=(const wxPrintData
& data
)
554 // ----------------------------------------------------------------------------
555 // wxPageSetupDialogData
556 // ----------------------------------------------------------------------------
558 wxPageSetupDialogData::wxPageSetupDialogData()
560 #if defined(__WIN95__)
561 m_pageSetupData
= NULL
;
563 m_paperSize
= wxSize(0, 0);
565 CalculatePaperSizeFromId();
567 m_minMarginTopLeft
= wxPoint(0, 0);
568 m_minMarginBottomRight
= wxPoint(0, 0);
569 m_marginTopLeft
= wxPoint(0, 0);
570 m_marginBottomRight
= wxPoint(0, 0);
573 m_defaultMinMargins
= false;
574 m_enableMargins
= true;
575 m_enableOrientation
= true;
576 m_enablePaper
= true;
577 m_enablePrinter
= true;
578 m_enableHelp
= false;
579 m_getDefaultInfo
= false;
582 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
585 #if defined(__WIN95__)
586 m_pageSetupData
= NULL
;
588 (*this) = dialogData
;
591 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
593 #if defined(__WIN95__)
594 m_pageSetupData
= NULL
;
596 m_paperSize
= wxSize(0, 0);
597 m_minMarginTopLeft
= wxPoint(0, 0);
598 m_minMarginBottomRight
= wxPoint(0, 0);
599 m_marginTopLeft
= wxPoint(0, 0);
600 m_marginBottomRight
= wxPoint(0, 0);
603 m_defaultMinMargins
= false;
604 m_enableMargins
= true;
605 m_enableOrientation
= true;
606 m_enablePaper
= true;
607 m_enablePrinter
= true;
608 m_enableHelp
= false;
609 m_getDefaultInfo
= false;
611 m_printData
= printData
;
613 // The wxPrintData paper size overrides these values, unless the size cannot
615 CalculatePaperSizeFromId();
618 wxPageSetupDialogData::~wxPageSetupDialogData()
620 #if defined(__WIN95__) && defined(__WXMSW__)
621 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
622 if ( pd
&& pd
->hDevMode
)
623 GlobalFree(pd
->hDevMode
);
624 if ( pd
&& pd
->hDevNames
)
625 GlobalFree(pd
->hDevNames
);
631 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
633 m_paperSize
= data
.m_paperSize
;
634 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
635 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
636 m_marginTopLeft
= data
.m_marginTopLeft
;
637 m_marginBottomRight
= data
.m_marginBottomRight
;
638 m_defaultMinMargins
= data
.m_defaultMinMargins
;
639 m_enableMargins
= data
.m_enableMargins
;
640 m_enableOrientation
= data
.m_enableOrientation
;
641 m_enablePaper
= data
.m_enablePaper
;
642 m_enablePrinter
= data
.m_enablePrinter
;
643 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
644 m_enableHelp
= data
.m_enableHelp
;
646 m_printData
= data
.m_printData
;
651 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
658 #if defined(__WIN95__)
659 void wxPageSetupDialogData::ConvertToNative()
661 wxWindowsPrintNativeData
*data
=
662 (wxWindowsPrintNativeData
*) m_printData
.GetNativeData();
663 data
->TransferFrom( m_printData
);
665 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
667 if ( m_pageSetupData
== NULL
)
669 pd
= new PAGESETUPDLG
;
671 pd
->hDevNames
= NULL
;
672 m_pageSetupData
= (void *)pd
;
675 // Pass the devmode data (created in m_printData.ConvertToNative)
676 // to the PRINTDLG structure, since it'll
677 // be needed when PrintDlg is called.
681 GlobalFree(pd
->hDevMode
);
685 pd
->hDevMode
= (HGLOBAL
) data
->GetDevMode();
687 data
->SetDevMode( (void*) NULL
);
689 // Shouldn't assert; we should be able to test Ok-ness at a higher level
690 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
692 // Pass the devnames data (created in m_printData.ConvertToNative)
693 // to the PRINTDLG structure, since it'll
694 // be needed when PrintDlg is called.
698 GlobalFree(pd
->hDevNames
);
699 pd
->hDevNames
= NULL
;
702 pd
->hDevNames
= (HGLOBAL
) data
->GetDevNames();
704 data
->SetDevNames((void*) NULL
);
706 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
708 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
710 if ( m_defaultMinMargins
)
711 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
712 if ( !m_enableMargins
)
713 pd
->Flags
|= PSD_DISABLEMARGINS
;
714 if ( !m_enableOrientation
)
715 pd
->Flags
|= PSD_DISABLEORIENTATION
;
716 if ( !m_enablePaper
)
717 pd
->Flags
|= PSD_DISABLEPAPER
;
718 if ( !m_enablePrinter
)
719 pd
->Flags
|= PSD_DISABLEPRINTER
;
720 if ( m_getDefaultInfo
)
721 pd
->Flags
|= PSD_RETURNDEFAULT
;
723 pd
->Flags
|= PSD_SHOWHELP
;
725 // We want the units to be in hundredths of a millimetre
726 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
728 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
729 pd
->hwndOwner
=(HWND
)NULL
;
730 // pd->hDevNames=(HWND)NULL;
731 pd
->hInstance
=(HINSTANCE
)NULL
;
732 // PAGESETUPDLG is in hundreds of a mm
733 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
734 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
736 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
737 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
738 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
739 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
741 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
742 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
743 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
744 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
747 pd
->lpfnPageSetupHook
= NULL
;
748 pd
->lpfnPagePaintHook
= NULL
;
749 pd
->hPageSetupTemplate
= NULL
;
750 pd
->lpPageSetupTemplateName
= NULL
;
755 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
756 memset(devMode, 0, sizeof(DEVMODE));
757 devMode->dmSize = sizeof(DEVMODE);
758 devMode->dmOrientation = m_orientation;
759 devMode->dmFields = DM_ORIENTATION;
760 GlobalUnlock(pd->hDevMode);
765 void wxPageSetupDialogData::ConvertFromNative()
767 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
771 wxWindowsPrintNativeData
*data
=
772 (wxWindowsPrintNativeData
*) m_printData
.GetNativeData();
774 // Pass the devmode data back to the wxPrintData structure where it really belongs.
777 if (data
->GetDevMode())
779 // Make sure we don't leak memory
780 GlobalFree((HGLOBAL
) data
->GetDevMode());
782 data
->SetDevMode( (void*) pd
->hDevMode
);
786 data
->TransferTo( m_printData
);
788 // Pass the devnames data back to the wxPrintData structure where it really belongs.
791 if (data
->GetDevNames())
793 // Make sure we don't leak memory
794 GlobalFree((HGLOBAL
) data
->GetDevNames());
796 data
->SetDevNames((void*) pd
->hDevNames
);
797 pd
->hDevNames
= NULL
;
800 data
->TransferTo( m_printData
);
802 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
804 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
805 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
806 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
807 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
808 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
809 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
810 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
812 // PAGESETUPDLG is in hundreds of a mm
813 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
814 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
816 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
817 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
818 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
819 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
821 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100;
822 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100;
823 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100;
824 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100;
827 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
829 if ( m_pageSetupData
== NULL
)
832 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
834 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
835 pd
->hwndOwner
=(HWND
) win
->GetHWND();
841 void wxPageSetupDialogData::ConvertToNative()
843 m_printData
.ConvertToNative();
844 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
847 void wxPageSetupDialogData::ConvertFromNative()
849 m_printData
.ConvertFromNative ();
850 m_paperSize
= m_printData
.GetPaperSize() ;
851 CalculateIdFromPaperSize();
852 m_printData
.m_nativePrintData
->TransferTo( this ) ;
853 // adjust minimal values
855 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
856 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
858 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
859 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
861 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
862 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
864 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
865 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
870 // If a corresponding paper type is found in the paper database, will set the m_printData
871 // paper size id member as well.
872 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
876 CalculateIdFromPaperSize();
879 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
880 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
882 m_printData
.SetPaperId(id
);
884 CalculatePaperSizeFromId();
887 // Use paper size defined in this object to set the wxPrintData
889 void wxPageSetupDialogData::CalculateIdFromPaperSize()
891 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
892 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
894 wxSize sz
= GetPaperSize();
896 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
897 if (id
!= wxPAPER_NONE
)
899 m_printData
.SetPaperId(id
);
903 // Use paper id in wxPrintData to set this object's paper size
904 void wxPageSetupDialogData::CalculatePaperSizeFromId()
906 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
907 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
909 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
911 // sz is in 10ths of a mm, while paper size is in mm
912 m_paperSize
.x
= sz
.x
/ 10;
913 m_paperSize
.y
= sz
.y
/ 10;
916 #endif // wxUSE_PRINTING_ARCHITECTURE