1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPrintDialog, wxPageSetupDialog
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 "printdlg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 // Don't use the Windows print dialog if we're in wxUniv mode and using
32 // the PostScript architecture
33 #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXUNIVERSAL__) || !wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
39 #include "wx/cmndata.h"
40 #include "wx/printdlg.h"
41 #include "wx/msw/printdlg.h"
42 #include "wx/dcprint.h"
47 #include "wx/msw/private.h"
55 //----------------------------------------------------------------------------
56 // wxWindowsPrintNativeData
57 //----------------------------------------------------------------------------
60 static wxString
wxGetPrintDlgError()
62 DWORD err
= CommDlgExtendedError();
63 wxString msg
= wxT("Unknown");
66 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
67 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
68 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
69 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
70 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
71 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
72 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
73 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
74 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
75 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
76 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
77 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
78 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
79 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
80 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
81 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
82 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
83 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
84 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
85 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
86 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
87 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
94 static HGLOBAL
wxCreateDevNames(const wxString
& driverName
, const wxString
& printerName
, const wxString
& portName
)
97 // if (!driverName.IsEmpty() && !printerName.IsEmpty() && !portName.IsEmpty())
98 if (driverName
.IsEmpty() && printerName
.IsEmpty() && portName
.IsEmpty())
103 hDev
= GlobalAlloc(GPTR
, 4*sizeof(WORD
)+
104 ( driverName
.Length() + 1 +
105 printerName
.Length() + 1 +
106 portName
.Length()+1 ) * sizeof(wxChar
) );
107 LPDEVNAMES lpDev
= (LPDEVNAMES
)GlobalLock(hDev
);
108 lpDev
->wDriverOffset
= sizeof(WORD
) * 4 / sizeof(wxChar
);
109 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDriverOffset
, driverName
);
111 lpDev
->wDeviceOffset
= (WORD
)( lpDev
->wDriverOffset
+
112 driverName
.Length() + 1 );
113 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDeviceOffset
, printerName
);
115 lpDev
->wOutputOffset
= (WORD
)( lpDev
->wDeviceOffset
+
116 printerName
.Length() + 1 );
117 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wOutputOffset
, portName
);
127 IMPLEMENT_CLASS(wxWindowsPrintNativeData
, wxPrintNativeDataBase
)
129 wxWindowsPrintNativeData::wxWindowsPrintNativeData()
131 m_devMode
= (void*) NULL
;
132 m_devNames
= (void*) NULL
;
135 wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
137 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
139 GlobalFree(hDevMode
);
140 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
142 GlobalFree(hDevNames
);
145 bool wxWindowsPrintNativeData::Ok() const
147 return (m_devMode
!= NULL
) ;
150 bool wxWindowsPrintNativeData::TransferTo( wxPrintData
&data
)
152 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
153 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
160 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
163 if (devMode
->dmFields
& DM_ORIENTATION
)
164 data
.SetOrientation( devMode
->dmOrientation
);
167 if (devMode
->dmFields
& DM_COLLATE
)
169 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
170 data
.SetCollate( true );
172 data
.SetCollate( false );
175 //// Number of copies
176 if (devMode
->dmFields
& DM_COPIES
)
177 data
.SetNoCopies( devMode
->dmCopies
);
179 if (devMode
->dmFields
& DM_DEFAULTSOURCE
)
180 data
.SetBin( (wxPrintBin
)devMode
->dmDefaultSource
);
183 if (devMode
->dmDeviceName
[0] != 0)
184 data
.SetPrinterName( devMode
->dmDeviceName
);
187 if (devMode
->dmFields
& DM_COLOR
)
189 if (devMode
->dmColor
== DMCOLOR_COLOR
)
190 data
.SetColour( true );
192 data
.SetColour( false );
195 data
.SetColour( true );
199 // We don't know size of user defined paper and some buggy drivers
200 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
201 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
202 // code wouldn't set m_paperSize correctly.
203 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
205 if (wxThePrintPaperDatabase
)
207 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
210 data
.SetPaperId( paper
->GetId() );
211 data
.SetPaperSize( wxSize(paper
->GetWidth() / 10,paper
->GetHeight() / 10) );
215 // Shouldn't really get here
216 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
217 data
.SetPaperId( wxPAPER_NONE
);
218 data
.SetPaperSize( wxSize(0,0) );
223 // Shouldn't really get here
224 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
225 data
.SetPaperId( wxPAPER_NONE
);
226 data
.SetPaperSize( wxSize(0,0) );
229 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
231 // DEVMODE is in tenths of a milimeter
232 data
.SetPaperId( wxPAPER_NONE
);
233 data
.SetPaperSize( wxSize(devMode
->dmPaperWidth
/ 10, devMode
->dmPaperLength
/ 10) );
237 // Shouldn't really get here
238 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
239 data
.SetPaperId( wxPAPER_NONE
);
240 data
.SetPaperSize( wxSize(0,0) );
245 if (devMode
->dmFields
& DM_DUPLEX
)
247 switch (devMode
->dmDuplex
)
249 case DMDUP_HORIZONTAL
: data
.SetDuplex( wxDUPLEX_HORIZONTAL
); break;
250 case DMDUP_VERTICAL
: data
.SetDuplex( wxDUPLEX_VERTICAL
); break;
252 case DMDUP_SIMPLEX
: data
.SetDuplex( wxDUPLEX_SIMPLEX
); break;
256 data
.SetDuplex( wxDUPLEX_SIMPLEX
);
260 if (devMode
->dmFields
& DM_PRINTQUALITY
)
262 switch (devMode
->dmPrintQuality
)
264 case DMRES_MEDIUM
: data
.SetQuality( wxPRINT_QUALITY_MEDIUM
); break;
265 case DMRES_LOW
: data
.SetQuality( wxPRINT_QUALITY_LOW
); break;
266 case DMRES_DRAFT
: data
.SetQuality( wxPRINT_QUALITY_DRAFT
); break;
267 case DMRES_HIGH
: data
.SetQuality( wxPRINT_QUALITY_HIGH
); break;
270 // TODO: if the printer fills in the resolution in DPI, how
271 // will the application know if it's high, low, draft etc.??
272 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
273 data
.SetQuality( devMode
->dmPrintQuality
);
280 data
.SetQuality( wxPRINT_QUALITY_HIGH
);
282 GlobalUnlock(hDevMode
);
287 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
290 // TODO: Unicode-ification
293 // port is obsolete in WIN32
294 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
296 // Get the printer name
297 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
299 // Not sure if we should check for this mismatch
300 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
302 if (printerName
!= wxT(""))
303 data
.SetPrinterName( printerName
);
305 GlobalUnlock(hDevNames
);
312 bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData
&data
)
314 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
315 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
318 // Use PRINTDLG as a way of creating a DEVMODE object
321 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
326 memset(&pd
, 0, sizeof(PRINTDLG
));
328 pd
.cbStruct
= sizeof(PRINTDLG
);
330 pd
.lStructSize
= sizeof(PRINTDLG
);
334 pd
.hwndOwner
= (HWND
)NULL
;
335 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
336 pd
.hDevNames
= NULL
; // Ditto
337 //pd.hInstance = (HINSTANCE) wxGetInstance();
339 pd
.Flags
= PD_RETURNDEFAULT
;
342 // Fill out the DEVMODE structure
343 // so we can use it as input in the 'real' PrintDlg
347 GlobalFree(pd
.hDevMode
);
349 GlobalFree(pd
.hDevNames
);
353 #if defined(__WXDEBUG__) && defined(__WIN32__)
354 wxString
str(wxT("Printing error: "));
355 str
+= wxGetPrintDlgError();
361 hDevMode
= pd
.hDevMode
;
362 m_devMode
= (void*)(long) hDevMode
;
365 // We'll create a new DEVNAMEs structure below.
367 GlobalFree(pd
.hDevNames
);
370 // hDevNames = pd->hDevNames;
371 // m_devNames = (void*)(long) hDevNames;
372 // pd->hDevnames = NULL;
379 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
382 devMode
->dmOrientation
= (short)data
.GetOrientation();
385 devMode
->dmCollate
= (data
.GetCollate() ? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
386 devMode
->dmFields
|= DM_COLLATE
;
388 //// Number of copies
389 devMode
->dmCopies
= (short)data
.GetNoCopies();
390 devMode
->dmFields
|= DM_COPIES
;
393 wxString name
= data
.GetPrinterName();
396 //int len = wxMin(31, m_printerName.Len());
397 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,name
.c_str(),31);
398 devMode
->dmDeviceName
[31] = wxT('\0');
402 if (data
.GetColour())
403 devMode
->dmColor
= DMCOLOR_COLOR
;
405 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
406 devMode
->dmFields
|= DM_COLOR
;
409 if (data
.GetPaperId() == wxPAPER_NONE
)
411 // DEVMODE is in tenths of a milimeter
412 devMode
->dmPaperWidth
= (short)(data
.GetPaperSize().x
* 10);
413 devMode
->dmPaperLength
= (short)(data
.GetPaperSize().y
* 10);
414 devMode
->dmPaperSize
= DMPAPER_USER
;
415 devMode
->dmFields
|= DM_PAPERWIDTH
;
416 devMode
->dmFields
|= DM_PAPERLENGTH
;
420 if (wxThePrintPaperDatabase
)
422 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType( data
.GetPaperId() );
425 devMode
->dmPaperSize
= (short)paper
->GetPlatformId();
426 devMode
->dmFields
|= DM_PAPERSIZE
;
433 switch (data
.GetDuplex())
435 case wxDUPLEX_HORIZONTAL
:
436 duplex
= DMDUP_HORIZONTAL
;
438 case wxDUPLEX_VERTICAL
:
439 duplex
= DMDUP_VERTICAL
;
442 // in fact case wxDUPLEX_SIMPLEX:
443 duplex
= DMDUP_SIMPLEX
;
446 devMode
->dmDuplex
= duplex
;
447 devMode
->dmFields
|= DM_DUPLEX
;
452 switch (data
.GetQuality())
454 case wxPRINT_QUALITY_MEDIUM
:
455 quality
= DMRES_MEDIUM
;
457 case wxPRINT_QUALITY_LOW
:
460 case wxPRINT_QUALITY_DRAFT
:
461 quality
= DMRES_DRAFT
;
463 case wxPRINT_QUALITY_HIGH
:
464 quality
= DMRES_HIGH
;
467 quality
= (short)data
.GetQuality();
470 devMode
->dmPrintQuality
= quality
;
471 devMode
->dmFields
|= DM_PRINTQUALITY
;
473 if (data
.GetBin() != wxPRINTBIN_DEFAULT
)
475 switch (data
.GetBin())
477 case wxPRINTBIN_ONLYONE
: devMode
->dmDefaultSource
= DMBIN_ONLYONE
; break;
478 case wxPRINTBIN_LOWER
: devMode
->dmDefaultSource
= DMBIN_LOWER
; break;
479 case wxPRINTBIN_MIDDLE
: devMode
->dmDefaultSource
= DMBIN_MIDDLE
; break;
480 case wxPRINTBIN_MANUAL
: devMode
->dmDefaultSource
= DMBIN_MANUAL
; break;
481 case wxPRINTBIN_ENVELOPE
: devMode
->dmDefaultSource
= DMBIN_ENVELOPE
; break;
482 case wxPRINTBIN_ENVMANUAL
: devMode
->dmDefaultSource
= DMBIN_ENVMANUAL
; break;
483 case wxPRINTBIN_AUTO
: devMode
->dmDefaultSource
= DMBIN_AUTO
; break;
484 case wxPRINTBIN_TRACTOR
: devMode
->dmDefaultSource
= DMBIN_TRACTOR
; break;
485 case wxPRINTBIN_SMALLFMT
: devMode
->dmDefaultSource
= DMBIN_SMALLFMT
; break;
486 case wxPRINTBIN_LARGEFMT
: devMode
->dmDefaultSource
= DMBIN_LARGEFMT
; break;
487 case wxPRINTBIN_LARGECAPACITY
: devMode
->dmDefaultSource
= DMBIN_LARGECAPACITY
; break;
488 case wxPRINTBIN_CASSETTE
: devMode
->dmDefaultSource
= DMBIN_CASSETTE
; break;
489 case wxPRINTBIN_FORMSOURCE
: devMode
->dmDefaultSource
= DMBIN_FORMSOURCE
; break;
492 devMode
->dmDefaultSource
= (short)(DMBIN_USER
+ data
.GetBin() - wxPRINTBIN_USER
);
496 devMode
->dmFields
|= DM_DEFAULTSOURCE
;
499 GlobalUnlock(hDevMode
);
504 GlobalFree(hDevNames
);
507 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
508 m_devNames
= (void*) (long) wxCreateDevNames(wxT(""), data
.GetPrinterName(), wxT(""));
513 // ---------------------------------------------------------------------------
515 // ---------------------------------------------------------------------------
517 IMPLEMENT_CLASS(wxWindowsPrintDialog
, wxPrintDialogBase
)
519 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
524 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintData
* data
)
526 wxPrintDialogData data2
;
533 bool wxWindowsPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
543 m_printDialogData
= *data
;
548 wxWindowsPrintDialog::~wxWindowsPrintDialog()
550 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
551 if (pd
&& pd
->hDevMode
)
552 GlobalFree(pd
->hDevMode
);
556 if (m_destroyDC
&& m_printerDC
)
560 int wxWindowsPrintDialog::ShowModal()
562 ConvertToNative( m_printDialogData
);
564 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
567 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
568 else if (wxTheApp
->GetTopWindow())
569 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
573 bool ret
= (PrintDlg( pd
) != 0);
577 if ( ret
!= false && (pd
->hDC
) )
579 wxPrinterDC
*pdc
= new wxPrinterDC( (WXHDC
) pd
->hDC
);
581 ConvertFromNative( m_printDialogData
);
590 wxDC
*wxWindowsPrintDialog::GetPrintDC()
601 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData
&data
)
603 wxWindowsPrintNativeData
*native_data
=
604 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
605 data
.GetPrintData().ConvertToNative();
607 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
609 // Shouldn't have been defined anywhere
614 memset( pd
, 0, sizeof(PRINTDLG
) );
615 m_printDlg
= (void*) pd
;
617 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
619 pd
->lStructSize
= 66;
621 pd
->lStructSize
= sizeof(PRINTDLG
);
623 pd
->hwndOwner
= (HWND
)NULL
;
624 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
625 pd
->hDevNames
= NULL
; // Ditto
627 pd
->Flags
= PD_RETURNDEFAULT
;
630 // Pass the devmode data to the PRINTDLG structure, since it'll
631 // be needed when PrintDlg is called.
633 GlobalFree(pd
->hDevMode
);
635 // Pass the devnames data to the PRINTDLG structure, since it'll
636 // be needed when PrintDlg is called.
638 GlobalFree(pd
->hDevNames
);
640 pd
->hDevMode
= (HGLOBAL
)(DWORD
) native_data
->GetDevMode();
641 native_data
->SetDevMode( (void*) NULL
);
643 // Shouldn't assert; we should be able to test Ok-ness at a higher level
644 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
646 pd
->hDevNames
= (HGLOBAL
)(DWORD
) native_data
->GetDevNames();
647 native_data
->SetDevNames( (void*) NULL
);
650 pd
->hDC
= (HDC
) NULL
;
651 pd
->nFromPage
= (WORD
)data
.GetFromPage();
652 pd
->nToPage
= (WORD
)data
.GetToPage();
653 pd
->nMinPage
= (WORD
)data
.GetMinPage();
654 pd
->nMaxPage
= (WORD
)data
.GetMaxPage();
655 pd
->nCopies
= (WORD
)data
.GetNoCopies();
657 pd
->Flags
= PD_RETURNDC
;
660 pd
->lStructSize
= 66;
662 pd
->lStructSize
= sizeof( PRINTDLG
);
665 pd
->hwndOwner
=(HWND
)NULL
;
666 // pd->hDevNames=(HANDLE)NULL;
667 pd
->hInstance
=(HINSTANCE
)NULL
;
668 pd
->lCustData
= (LPARAM
) NULL
;
669 pd
->lpfnPrintHook
= NULL
;
670 pd
->lpfnSetupHook
= NULL
;
671 pd
->lpPrintTemplateName
= NULL
;
672 pd
->lpSetupTemplateName
= NULL
;
673 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
674 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
676 if ( data
.GetAllPages() )
677 pd
->Flags
|= PD_ALLPAGES
;
678 if ( data
.GetSelection() )
679 pd
->Flags
|= PD_SELECTION
;
680 if ( data
.GetCollate() )
681 pd
->Flags
|= PD_COLLATE
;
682 if ( data
.GetPrintToFile() )
683 pd
->Flags
|= PD_PRINTTOFILE
;
684 if ( !data
.GetEnablePrintToFile() )
685 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
686 if ( !data
.GetEnableSelection() )
687 pd
->Flags
|= PD_NOSELECTION
;
688 if ( !data
.GetEnablePageNumbers() )
689 pd
->Flags
|= PD_NOPAGENUMS
;
690 else if ( (!data
.GetAllPages()) && (!data
.GetSelection()) && (data
.GetFromPage() != 0) && (data
.GetToPage() != 0))
691 pd
->Flags
|= PD_PAGENUMS
;
692 if ( data
.GetEnableHelp() )
693 pd
->Flags
|= PD_SHOWHELP
;
694 #if WXWIN_COMPATIBILITY_2_4
695 if ( data
.GetSetupDialog() )
696 pd
->Flags
|= PD_PRINTSETUP
;
702 bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData
&data
)
704 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
708 wxWindowsPrintNativeData
*native_data
=
709 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
711 // Pass the devmode data back to the wxPrintData structure where it really belongs.
714 if (native_data
->GetDevMode())
716 // Make sure we don't leak memory
717 GlobalFree( (HGLOBAL
)(DWORD
) native_data
->GetDevMode() );
719 native_data
->SetDevMode( (void*)(long) pd
->hDevMode
);
723 // Pass the devnames data back to the wxPrintData structure where it really belongs.
726 if (native_data
->GetDevNames())
728 // Make sure we don't leak memory
729 GlobalFree((HGLOBAL
)(DWORD
) native_data
->GetDevNames());
731 native_data
->SetDevNames((void*)(long) pd
->hDevNames
);
732 pd
->hDevNames
= NULL
;
735 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
736 // into wxWidgets form.
737 native_data
->TransferTo( data
.GetPrintData() );
739 data
.SetFromPage( pd
->nFromPage
);
740 data
.SetToPage( pd
->nToPage
);
741 data
.SetMinPage( pd
->nMinPage
);
742 data
.SetMaxPage( pd
->nMaxPage
);
743 data
.SetNoCopies( pd
->nCopies
);
745 data
.SetAllPages( (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
)) );
746 data
.SetSelection( ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
) );
747 data
.SetCollate( ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
) );
748 data
.SetPrintToFile( ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
) );
749 data
.EnablePrintToFile( ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
) );
750 data
.EnableSelection( ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
) );
751 data
.EnablePageNumbers( ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
) );
752 data
.EnableHelp( ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
) );
753 #if WXWIN_COMPATIBILITY_2_4
754 data
.SetSetupDialog( ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
) );
759 // ---------------------------------------------------------------------------
760 // wxWidnowsPageSetupDialog
761 // ---------------------------------------------------------------------------
763 IMPLEMENT_CLASS(wxWindowsPageSetupDialog
, wxPageSetupDialogBase
)
765 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog()
767 m_dialogParent
= NULL
;
771 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow
*p
, wxPageSetupDialogData
*data
)
776 bool wxWindowsPageSetupDialog::Create(wxWindow
*p
, wxPageSetupDialogData
*data
)
782 m_pageSetupData
= (*data
);
787 wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog()
789 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageDlg
;
790 if ( pd
&& pd
->hDevMode
)
791 GlobalFree(pd
->hDevMode
);
792 if ( pd
&& pd
->hDevNames
)
793 GlobalFree(pd
->hDevNames
);
798 int wxWindowsPageSetupDialog::ShowModal()
800 ConvertToNative( m_pageSetupData
);
802 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
804 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
805 else if (wxTheApp
->GetTopWindow())
806 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
809 BOOL retVal
= PageSetupDlg( pd
) ;
813 ConvertFromNative( m_pageSetupData
);
820 bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData
&data
)
822 wxWindowsPrintNativeData
*native_data
=
823 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
824 data
.GetPrintData().ConvertToNative();
826 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
828 // Shouldn't have been defined anywhere
832 pd
= new PAGESETUPDLG
;
834 pd
->hDevNames
= NULL
;
835 m_pageDlg
= (void *)pd
;
837 // Pass the devmode data (created in m_printData.ConvertToNative)
838 // to the PRINTDLG structure, since it'll
839 // be needed when PrintDlg is called.
843 GlobalFree(pd
->hDevMode
);
846 pd
->hDevMode
= (HGLOBAL
) native_data
->GetDevMode();
847 native_data
->SetDevMode( (void*) NULL
);
849 // Shouldn't assert; we should be able to test Ok-ness at a higher level
850 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
852 // Pass the devnames data (created in m_printData.ConvertToNative)
853 // to the PRINTDLG structure, since it'll
854 // be needed when PrintDlg is called.
858 GlobalFree(pd
->hDevNames
);
859 pd
->hDevNames
= NULL
;
861 pd
->hDevNames
= (HGLOBAL
) native_data
->GetDevNames();
862 native_data
->SetDevNames((void*) NULL
);
864 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
866 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
868 if ( data
.GetDefaultMinMargins() )
869 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
870 if ( !data
.GetEnableMargins() )
871 pd
->Flags
|= PSD_DISABLEMARGINS
;
872 if ( !data
.GetEnableOrientation() )
873 pd
->Flags
|= PSD_DISABLEORIENTATION
;
874 if ( !data
.GetEnablePaper() )
875 pd
->Flags
|= PSD_DISABLEPAPER
;
876 if ( !data
.GetEnablePrinter() )
877 pd
->Flags
|= PSD_DISABLEPRINTER
;
878 if ( data
.GetDefaultInfo() )
879 pd
->Flags
|= PSD_RETURNDEFAULT
;
880 if ( data
.GetEnableHelp() )
881 pd
->Flags
|= PSD_SHOWHELP
;
883 // We want the units to be in hundredths of a millimetre
884 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
886 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
887 pd
->hwndOwner
=(HWND
)NULL
;
888 // pd->hDevNames=(HWND)NULL;
889 pd
->hInstance
=(HINSTANCE
)NULL
;
890 // PAGESETUPDLG is in hundreds of a mm
891 pd
->ptPaperSize
.x
= data
.GetPaperSize().x
* 100;
892 pd
->ptPaperSize
.y
= data
.GetPaperSize().y
* 100;
894 pd
->rtMinMargin
.left
= data
.GetMinMarginTopLeft().x
* 100;
895 pd
->rtMinMargin
.top
= data
.GetMinMarginTopLeft().y
* 100;
896 pd
->rtMinMargin
.right
= data
.GetMinMarginBottomRight().x
* 100;
897 pd
->rtMinMargin
.bottom
= data
.GetMinMarginBottomRight().y
* 100;
899 pd
->rtMargin
.left
= data
.GetMarginTopLeft().x
* 100;
900 pd
->rtMargin
.top
= data
.GetMarginTopLeft().y
* 100;
901 pd
->rtMargin
.right
= data
.GetMarginBottomRight().x
* 100;
902 pd
->rtMargin
.bottom
= data
.GetMarginBottomRight().y
* 100;
905 pd
->lpfnPageSetupHook
= NULL
;
906 pd
->lpfnPagePaintHook
= NULL
;
907 pd
->hPageSetupTemplate
= NULL
;
908 pd
->lpPageSetupTemplateName
= NULL
;
913 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
914 memset(devMode, 0, sizeof(DEVMODE));
915 devMode->dmSize = sizeof(DEVMODE);
916 devMode->dmOrientation = m_orientation;
917 devMode->dmFields = DM_ORIENTATION;
918 GlobalUnlock(pd->hDevMode);
924 bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData
&data
)
926 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
930 wxWindowsPrintNativeData
*native_data
=
931 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
933 // Pass the devmode data back to the wxPrintData structure where it really belongs.
936 if (native_data
->GetDevMode())
938 // Make sure we don't leak memory
939 GlobalFree((HGLOBAL
) native_data
->GetDevMode());
941 native_data
->SetDevMode( (void*) pd
->hDevMode
);
945 // Isn't this superfluous? It's called again below.
946 // data.GetPrintData().ConvertFromNative();
948 // Pass the devnames data back to the wxPrintData structure where it really belongs.
951 if (native_data
->GetDevNames())
953 // Make sure we don't leak memory
954 GlobalFree((HGLOBAL
) native_data
->GetDevNames());
956 native_data
->SetDevNames((void*) pd
->hDevNames
);
957 pd
->hDevNames
= NULL
;
960 data
.GetPrintData().ConvertFromNative();
962 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
964 data
.SetDefaultMinMargins( ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
) );
965 data
.EnableMargins( ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
) );
966 data
.EnableOrientation( ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
) );
967 data
.EnablePaper( ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
) );
968 data
.EnablePrinter( ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
) );
969 data
.SetDefaultInfo( ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
) );
970 data
.EnableHelp( ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
) );
972 // PAGESETUPDLG is in hundreds of a mm
973 data
.SetPaperSize( wxSize(pd
->ptPaperSize
.x
/ 100, pd
->ptPaperSize
.y
/ 100) );
975 data
.SetMinMarginTopLeft( wxPoint(pd
->rtMinMargin
.left
/ 100, pd
->rtMinMargin
.top
/ 100) );
976 data
.SetMinMarginBottomRight( wxPoint(pd
->rtMinMargin
.right
/ 100, pd
->rtMinMargin
.bottom
/ 100) );
978 data
.SetMarginTopLeft( wxPoint(pd
->rtMargin
.left
/ 100, pd
->rtMargin
.top
/ 100) );
979 data
.SetMarginBottomRight( wxPoint(pd
->rtMargin
.right
/ 100, pd
->rtMargin
.bottom
/ 100) );
985 // wxUSE_PRINTING_ARCHITECTURE