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/wrapcdlg.h"
53 //----------------------------------------------------------------------------
54 // wxWindowsPrintNativeData
55 //----------------------------------------------------------------------------
58 static wxString
wxGetPrintDlgError()
60 DWORD err
= CommDlgExtendedError();
61 wxString msg
= wxT("Unknown");
64 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
65 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
66 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
67 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
68 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
69 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
70 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
71 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
72 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
73 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
74 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
75 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
76 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
77 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
78 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
79 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
80 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
81 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
82 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
83 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
84 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
85 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
92 static HGLOBAL
wxCreateDevNames(const wxString
& driverName
, const wxString
& printerName
, const wxString
& portName
)
95 // if (!driverName.empty() && !printerName.empty() && !portName.empty())
96 if (driverName
.empty() && printerName
.empty() && portName
.empty())
101 hDev
= GlobalAlloc(GPTR
, 4*sizeof(WORD
)+
102 ( driverName
.Length() + 1 +
103 printerName
.Length() + 1 +
104 portName
.Length()+1 ) * sizeof(wxChar
) );
105 LPDEVNAMES lpDev
= (LPDEVNAMES
)GlobalLock(hDev
);
106 lpDev
->wDriverOffset
= sizeof(WORD
) * 4 / sizeof(wxChar
);
107 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDriverOffset
, driverName
);
109 lpDev
->wDeviceOffset
= (WORD
)( lpDev
->wDriverOffset
+
110 driverName
.Length() + 1 );
111 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDeviceOffset
, printerName
);
113 lpDev
->wOutputOffset
= (WORD
)( lpDev
->wDeviceOffset
+
114 printerName
.Length() + 1 );
115 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wOutputOffset
, portName
);
125 IMPLEMENT_CLASS(wxWindowsPrintNativeData
, wxPrintNativeDataBase
)
127 wxWindowsPrintNativeData::wxWindowsPrintNativeData()
129 m_devMode
= (void*) NULL
;
130 m_devNames
= (void*) NULL
;
133 wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
135 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
137 GlobalFree(hDevMode
);
138 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
140 GlobalFree(hDevNames
);
143 bool wxWindowsPrintNativeData::Ok() const
145 return (m_devMode
!= NULL
) ;
148 bool wxWindowsPrintNativeData::TransferTo( wxPrintData
&data
)
150 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
151 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
158 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
161 if (devMode
->dmFields
& DM_ORIENTATION
)
162 data
.SetOrientation( devMode
->dmOrientation
);
165 if (devMode
->dmFields
& DM_COLLATE
)
167 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
168 data
.SetCollate( true );
170 data
.SetCollate( false );
173 //// Number of copies
174 if (devMode
->dmFields
& DM_COPIES
)
175 data
.SetNoCopies( devMode
->dmCopies
);
177 if (devMode
->dmFields
& DM_DEFAULTSOURCE
)
178 data
.SetBin( (wxPrintBin
)devMode
->dmDefaultSource
);
181 if (devMode
->dmDeviceName
[0] != 0)
182 data
.SetPrinterName( devMode
->dmDeviceName
);
185 if (devMode
->dmFields
& DM_COLOR
)
187 if (devMode
->dmColor
== DMCOLOR_COLOR
)
188 data
.SetColour( true );
190 data
.SetColour( false );
193 data
.SetColour( true );
197 // We don't know size of user defined paper and some buggy drivers
198 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
199 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
200 // code wouldn't set m_paperSize correctly.
201 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
203 if (wxThePrintPaperDatabase
)
205 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
208 data
.SetPaperId( paper
->GetId() );
209 data
.SetPaperSize( wxSize(paper
->GetWidth() / 10,paper
->GetHeight() / 10) );
213 // Shouldn't really get here
214 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
215 data
.SetPaperId( wxPAPER_NONE
);
216 data
.SetPaperSize( wxSize(0,0) );
221 // Shouldn't really get here
222 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
223 data
.SetPaperId( wxPAPER_NONE
);
224 data
.SetPaperSize( wxSize(0,0) );
227 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
229 // DEVMODE is in tenths of a milimeter
230 data
.SetPaperId( wxPAPER_NONE
);
231 data
.SetPaperSize( wxSize(devMode
->dmPaperWidth
/ 10, devMode
->dmPaperLength
/ 10) );
235 // Shouldn't really get here
236 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
237 data
.SetPaperId( wxPAPER_NONE
);
238 data
.SetPaperSize( wxSize(0,0) );
243 if (devMode
->dmFields
& DM_DUPLEX
)
245 switch (devMode
->dmDuplex
)
247 case DMDUP_HORIZONTAL
: data
.SetDuplex( wxDUPLEX_HORIZONTAL
); break;
248 case DMDUP_VERTICAL
: data
.SetDuplex( wxDUPLEX_VERTICAL
); break;
250 case DMDUP_SIMPLEX
: data
.SetDuplex( wxDUPLEX_SIMPLEX
); break;
254 data
.SetDuplex( wxDUPLEX_SIMPLEX
);
258 if (devMode
->dmFields
& DM_PRINTQUALITY
)
260 switch (devMode
->dmPrintQuality
)
262 case DMRES_MEDIUM
: data
.SetQuality( wxPRINT_QUALITY_MEDIUM
); break;
263 case DMRES_LOW
: data
.SetQuality( wxPRINT_QUALITY_LOW
); break;
264 case DMRES_DRAFT
: data
.SetQuality( wxPRINT_QUALITY_DRAFT
); break;
265 case DMRES_HIGH
: data
.SetQuality( wxPRINT_QUALITY_HIGH
); break;
268 // TODO: if the printer fills in the resolution in DPI, how
269 // will the application know if it's high, low, draft etc.??
270 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
271 data
.SetQuality( devMode
->dmPrintQuality
);
278 data
.SetQuality( wxPRINT_QUALITY_HIGH
);
280 if (devMode
->dmDriverExtra
> 0)
281 data
.SetPrivData( (char *)devMode
+devMode
->dmSize
, devMode
->dmDriverExtra
);
283 data
.SetPrivData( NULL
, 0 );
285 GlobalUnlock(hDevMode
);
290 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
293 // TODO: Unicode-ification
296 // port is obsolete in WIN32
297 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
299 // Get the printer name
300 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
302 // Not sure if we should check for this mismatch
303 // wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
305 if (!printerName
.empty())
306 data
.SetPrinterName( printerName
);
308 GlobalUnlock(hDevNames
);
315 bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData
&data
)
317 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
318 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
321 // Use PRINTDLG as a way of creating a DEVMODE object
324 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
329 memset(&pd
, 0, sizeof(PRINTDLG
));
331 pd
.cbStruct
= sizeof(PRINTDLG
);
333 pd
.lStructSize
= sizeof(PRINTDLG
);
337 pd
.hwndOwner
= (HWND
)NULL
;
338 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
339 pd
.hDevNames
= NULL
; // Ditto
340 //pd.hInstance = (HINSTANCE) wxGetInstance();
342 pd
.Flags
= PD_RETURNDEFAULT
;
345 // Fill out the DEVMODE structure
346 // so we can use it as input in the 'real' PrintDlg
350 GlobalFree(pd
.hDevMode
);
352 GlobalFree(pd
.hDevNames
);
356 #if defined(__WXDEBUG__) && defined(__WIN32__)
357 wxString
str(wxT("Printing error: "));
358 str
+= wxGetPrintDlgError();
364 hDevMode
= pd
.hDevMode
;
365 m_devMode
= (void*)(long) hDevMode
;
368 // We'll create a new DEVNAMEs structure below.
370 GlobalFree(pd
.hDevNames
);
373 // hDevNames = pd->hDevNames;
374 // m_devNames = (void*)(long) hDevNames;
375 // pd->hDevnames = NULL;
382 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
385 devMode
->dmOrientation
= (short)data
.GetOrientation();
388 devMode
->dmCollate
= (data
.GetCollate() ? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
389 devMode
->dmFields
|= DM_COLLATE
;
391 //// Number of copies
392 devMode
->dmCopies
= (short)data
.GetNoCopies();
393 devMode
->dmFields
|= DM_COPIES
;
396 wxString name
= data
.GetPrinterName();
399 //int len = wxMin(31, m_printerName.Len());
400 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,name
.c_str(),31);
401 devMode
->dmDeviceName
[31] = wxT('\0');
405 if (data
.GetColour())
406 devMode
->dmColor
= DMCOLOR_COLOR
;
408 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
409 devMode
->dmFields
|= DM_COLOR
;
412 if (data
.GetPaperId() == wxPAPER_NONE
)
414 // DEVMODE is in tenths of a milimeter
415 devMode
->dmPaperWidth
= (short)(data
.GetPaperSize().x
* 10);
416 devMode
->dmPaperLength
= (short)(data
.GetPaperSize().y
* 10);
417 devMode
->dmPaperSize
= DMPAPER_USER
;
418 devMode
->dmFields
|= DM_PAPERWIDTH
;
419 devMode
->dmFields
|= DM_PAPERLENGTH
;
423 if (wxThePrintPaperDatabase
)
425 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType( data
.GetPaperId() );
428 devMode
->dmPaperSize
= (short)paper
->GetPlatformId();
429 devMode
->dmFields
|= DM_PAPERSIZE
;
436 switch (data
.GetDuplex())
438 case wxDUPLEX_HORIZONTAL
:
439 duplex
= DMDUP_HORIZONTAL
;
441 case wxDUPLEX_VERTICAL
:
442 duplex
= DMDUP_VERTICAL
;
445 // in fact case wxDUPLEX_SIMPLEX:
446 duplex
= DMDUP_SIMPLEX
;
449 devMode
->dmDuplex
= duplex
;
450 devMode
->dmFields
|= DM_DUPLEX
;
455 switch (data
.GetQuality())
457 case wxPRINT_QUALITY_MEDIUM
:
458 quality
= DMRES_MEDIUM
;
460 case wxPRINT_QUALITY_LOW
:
463 case wxPRINT_QUALITY_DRAFT
:
464 quality
= DMRES_DRAFT
;
466 case wxPRINT_QUALITY_HIGH
:
467 quality
= DMRES_HIGH
;
470 quality
= (short)data
.GetQuality();
473 devMode
->dmPrintQuality
= quality
;
474 devMode
->dmFields
|= DM_PRINTQUALITY
;
476 if (data
.GetPrivDataLen() > 0)
478 memcpy( (char *)devMode
+devMode
->dmSize
, data
.GetPrivData(), data
.GetPrivDataLen() );
479 devMode
->dmDriverExtra
= (WXWORD
)data
.GetPrivDataLen();
482 if (data
.GetBin() != wxPRINTBIN_DEFAULT
)
484 switch (data
.GetBin())
486 case wxPRINTBIN_ONLYONE
: devMode
->dmDefaultSource
= DMBIN_ONLYONE
; break;
487 case wxPRINTBIN_LOWER
: devMode
->dmDefaultSource
= DMBIN_LOWER
; break;
488 case wxPRINTBIN_MIDDLE
: devMode
->dmDefaultSource
= DMBIN_MIDDLE
; break;
489 case wxPRINTBIN_MANUAL
: devMode
->dmDefaultSource
= DMBIN_MANUAL
; break;
490 case wxPRINTBIN_ENVELOPE
: devMode
->dmDefaultSource
= DMBIN_ENVELOPE
; break;
491 case wxPRINTBIN_ENVMANUAL
: devMode
->dmDefaultSource
= DMBIN_ENVMANUAL
; break;
492 case wxPRINTBIN_AUTO
: devMode
->dmDefaultSource
= DMBIN_AUTO
; break;
493 case wxPRINTBIN_TRACTOR
: devMode
->dmDefaultSource
= DMBIN_TRACTOR
; break;
494 case wxPRINTBIN_SMALLFMT
: devMode
->dmDefaultSource
= DMBIN_SMALLFMT
; break;
495 case wxPRINTBIN_LARGEFMT
: devMode
->dmDefaultSource
= DMBIN_LARGEFMT
; break;
496 case wxPRINTBIN_LARGECAPACITY
: devMode
->dmDefaultSource
= DMBIN_LARGECAPACITY
; break;
497 case wxPRINTBIN_CASSETTE
: devMode
->dmDefaultSource
= DMBIN_CASSETTE
; break;
498 case wxPRINTBIN_FORMSOURCE
: devMode
->dmDefaultSource
= DMBIN_FORMSOURCE
; break;
501 devMode
->dmDefaultSource
= (short)(DMBIN_USER
+ data
.GetBin() - wxPRINTBIN_USER
);
505 devMode
->dmFields
|= DM_DEFAULTSOURCE
;
508 GlobalUnlock(hDevMode
);
513 GlobalFree(hDevNames
);
516 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
517 m_devNames
= (void*) (long) wxCreateDevNames(wxEmptyString
, data
.GetPrinterName(), wxEmptyString
);
522 // ---------------------------------------------------------------------------
524 // ---------------------------------------------------------------------------
526 IMPLEMENT_CLASS(wxWindowsPrintDialog
, wxPrintDialogBase
)
528 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
533 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintData
* data
)
535 wxPrintDialogData data2
;
542 bool wxWindowsPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
552 m_printDialogData
= *data
;
557 wxWindowsPrintDialog::~wxWindowsPrintDialog()
559 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
560 if (pd
&& pd
->hDevMode
)
561 GlobalFree(pd
->hDevMode
);
565 if (m_destroyDC
&& m_printerDC
)
569 int wxWindowsPrintDialog::ShowModal()
571 ConvertToNative( m_printDialogData
);
573 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
576 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
577 else if (wxTheApp
->GetTopWindow())
578 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
582 bool ret
= (PrintDlg( pd
) != 0);
586 if ( ret
!= false && (pd
->hDC
) )
588 wxPrinterDC
*pdc
= new wxPrinterDC( (WXHDC
) pd
->hDC
);
590 ConvertFromNative( m_printDialogData
);
599 wxDC
*wxWindowsPrintDialog::GetPrintDC()
610 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData
&data
)
612 wxWindowsPrintNativeData
*native_data
=
613 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
614 data
.GetPrintData().ConvertToNative();
616 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
618 // Shouldn't have been defined anywhere
623 memset( pd
, 0, sizeof(PRINTDLG
) );
624 m_printDlg
= (void*) pd
;
626 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
628 pd
->lStructSize
= 66;
630 pd
->lStructSize
= sizeof(PRINTDLG
);
632 pd
->hwndOwner
= (HWND
)NULL
;
633 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
634 pd
->hDevNames
= NULL
; // Ditto
636 pd
->Flags
= PD_RETURNDEFAULT
;
639 // Pass the devmode data to the PRINTDLG structure, since it'll
640 // be needed when PrintDlg is called.
642 GlobalFree(pd
->hDevMode
);
644 // Pass the devnames data to the PRINTDLG structure, since it'll
645 // be needed when PrintDlg is called.
647 GlobalFree(pd
->hDevNames
);
649 pd
->hDevMode
= (HGLOBAL
)(DWORD
) native_data
->GetDevMode();
650 native_data
->SetDevMode( (void*) NULL
);
652 // Shouldn't assert; we should be able to test Ok-ness at a higher level
653 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
655 pd
->hDevNames
= (HGLOBAL
)(DWORD
) native_data
->GetDevNames();
656 native_data
->SetDevNames( (void*) NULL
);
659 pd
->hDC
= (HDC
) NULL
;
660 pd
->nFromPage
= (WORD
)data
.GetFromPage();
661 pd
->nToPage
= (WORD
)data
.GetToPage();
662 pd
->nMinPage
= (WORD
)data
.GetMinPage();
663 pd
->nMaxPage
= (WORD
)data
.GetMaxPage();
664 pd
->nCopies
= (WORD
)data
.GetNoCopies();
666 pd
->Flags
= PD_RETURNDC
;
669 pd
->lStructSize
= 66;
671 pd
->lStructSize
= sizeof( PRINTDLG
);
674 pd
->hwndOwner
=(HWND
)NULL
;
675 // pd->hDevNames=(HANDLE)NULL;
676 pd
->hInstance
=(HINSTANCE
)NULL
;
677 pd
->lCustData
= (LPARAM
) NULL
;
678 pd
->lpfnPrintHook
= NULL
;
679 pd
->lpfnSetupHook
= NULL
;
680 pd
->lpPrintTemplateName
= NULL
;
681 pd
->lpSetupTemplateName
= NULL
;
682 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
683 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
685 if ( data
.GetAllPages() )
686 pd
->Flags
|= PD_ALLPAGES
;
687 if ( data
.GetSelection() )
688 pd
->Flags
|= PD_SELECTION
;
689 if ( data
.GetCollate() )
690 pd
->Flags
|= PD_COLLATE
;
691 if ( data
.GetPrintToFile() )
692 pd
->Flags
|= PD_PRINTTOFILE
;
693 if ( !data
.GetEnablePrintToFile() )
694 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
695 if ( !data
.GetEnableSelection() )
696 pd
->Flags
|= PD_NOSELECTION
;
697 if ( !data
.GetEnablePageNumbers() )
698 pd
->Flags
|= PD_NOPAGENUMS
;
699 else if ( (!data
.GetAllPages()) && (!data
.GetSelection()) && (data
.GetFromPage() != 0) && (data
.GetToPage() != 0))
700 pd
->Flags
|= PD_PAGENUMS
;
701 if ( data
.GetEnableHelp() )
702 pd
->Flags
|= PD_SHOWHELP
;
703 #if WXWIN_COMPATIBILITY_2_4
704 if ( data
.GetSetupDialog() )
705 pd
->Flags
|= PD_PRINTSETUP
;
711 bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData
&data
)
713 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
717 wxWindowsPrintNativeData
*native_data
=
718 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
720 // Pass the devmode data back to the wxPrintData structure where it really belongs.
723 if (native_data
->GetDevMode())
725 // Make sure we don't leak memory
726 GlobalFree( (HGLOBAL
)(DWORD
) native_data
->GetDevMode() );
728 native_data
->SetDevMode( (void*)(long) pd
->hDevMode
);
732 // Pass the devnames data back to the wxPrintData structure where it really belongs.
735 if (native_data
->GetDevNames())
737 // Make sure we don't leak memory
738 GlobalFree((HGLOBAL
)(DWORD
) native_data
->GetDevNames());
740 native_data
->SetDevNames((void*)(long) pd
->hDevNames
);
741 pd
->hDevNames
= NULL
;
744 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
745 // into wxWidgets form.
746 native_data
->TransferTo( data
.GetPrintData() );
748 data
.SetFromPage( pd
->nFromPage
);
749 data
.SetToPage( pd
->nToPage
);
750 data
.SetMinPage( pd
->nMinPage
);
751 data
.SetMaxPage( pd
->nMaxPage
);
752 data
.SetNoCopies( pd
->nCopies
);
754 data
.SetAllPages( (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
)) );
755 data
.SetSelection( ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
) );
756 data
.SetCollate( ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
) );
757 data
.SetPrintToFile( ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
) );
758 data
.EnablePrintToFile( ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
) );
759 data
.EnableSelection( ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
) );
760 data
.EnablePageNumbers( ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
) );
761 data
.EnableHelp( ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
) );
762 #if WXWIN_COMPATIBILITY_2_4
763 data
.SetSetupDialog( ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
) );
768 // ---------------------------------------------------------------------------
769 // wxWidnowsPageSetupDialog
770 // ---------------------------------------------------------------------------
772 IMPLEMENT_CLASS(wxWindowsPageSetupDialog
, wxPageSetupDialogBase
)
774 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog()
776 m_dialogParent
= NULL
;
780 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow
*p
, wxPageSetupDialogData
*data
)
785 bool wxWindowsPageSetupDialog::Create(wxWindow
*p
, wxPageSetupDialogData
*data
)
791 m_pageSetupData
= (*data
);
796 wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog()
798 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageDlg
;
799 if ( pd
&& pd
->hDevMode
)
800 GlobalFree(pd
->hDevMode
);
801 if ( pd
&& pd
->hDevNames
)
802 GlobalFree(pd
->hDevNames
);
807 int wxWindowsPageSetupDialog::ShowModal()
809 ConvertToNative( m_pageSetupData
);
811 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
813 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
814 else if (wxTheApp
->GetTopWindow())
815 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
818 BOOL retVal
= PageSetupDlg( pd
) ;
822 ConvertFromNative( m_pageSetupData
);
829 bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData
&data
)
831 wxWindowsPrintNativeData
*native_data
=
832 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
833 data
.GetPrintData().ConvertToNative();
835 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
837 // Shouldn't have been defined anywhere
841 pd
= new PAGESETUPDLG
;
843 pd
->hDevNames
= NULL
;
844 m_pageDlg
= (void *)pd
;
846 // Pass the devmode data (created in m_printData.ConvertToNative)
847 // to the PRINTDLG structure, since it'll
848 // be needed when PrintDlg is called.
852 GlobalFree(pd
->hDevMode
);
855 pd
->hDevMode
= (HGLOBAL
) native_data
->GetDevMode();
856 native_data
->SetDevMode( (void*) NULL
);
858 // Shouldn't assert; we should be able to test Ok-ness at a higher level
859 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
861 // Pass the devnames data (created in m_printData.ConvertToNative)
862 // to the PRINTDLG structure, since it'll
863 // be needed when PrintDlg is called.
867 GlobalFree(pd
->hDevNames
);
868 pd
->hDevNames
= NULL
;
870 pd
->hDevNames
= (HGLOBAL
) native_data
->GetDevNames();
871 native_data
->SetDevNames((void*) NULL
);
873 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
875 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
877 if ( data
.GetDefaultMinMargins() )
878 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
879 if ( !data
.GetEnableMargins() )
880 pd
->Flags
|= PSD_DISABLEMARGINS
;
881 if ( !data
.GetEnableOrientation() )
882 pd
->Flags
|= PSD_DISABLEORIENTATION
;
883 if ( !data
.GetEnablePaper() )
884 pd
->Flags
|= PSD_DISABLEPAPER
;
885 if ( !data
.GetEnablePrinter() )
886 pd
->Flags
|= PSD_DISABLEPRINTER
;
887 if ( data
.GetDefaultInfo() )
888 pd
->Flags
|= PSD_RETURNDEFAULT
;
889 if ( data
.GetEnableHelp() )
890 pd
->Flags
|= PSD_SHOWHELP
;
892 // We want the units to be in hundredths of a millimetre
893 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
895 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
896 pd
->hwndOwner
=(HWND
)NULL
;
897 // pd->hDevNames=(HWND)NULL;
898 pd
->hInstance
=(HINSTANCE
)NULL
;
899 // PAGESETUPDLG is in hundreds of a mm
900 pd
->ptPaperSize
.x
= data
.GetPaperSize().x
* 100;
901 pd
->ptPaperSize
.y
= data
.GetPaperSize().y
* 100;
903 pd
->rtMinMargin
.left
= data
.GetMinMarginTopLeft().x
* 100;
904 pd
->rtMinMargin
.top
= data
.GetMinMarginTopLeft().y
* 100;
905 pd
->rtMinMargin
.right
= data
.GetMinMarginBottomRight().x
* 100;
906 pd
->rtMinMargin
.bottom
= data
.GetMinMarginBottomRight().y
* 100;
908 pd
->rtMargin
.left
= data
.GetMarginTopLeft().x
* 100;
909 pd
->rtMargin
.top
= data
.GetMarginTopLeft().y
* 100;
910 pd
->rtMargin
.right
= data
.GetMarginBottomRight().x
* 100;
911 pd
->rtMargin
.bottom
= data
.GetMarginBottomRight().y
* 100;
914 pd
->lpfnPageSetupHook
= NULL
;
915 pd
->lpfnPagePaintHook
= NULL
;
916 pd
->hPageSetupTemplate
= NULL
;
917 pd
->lpPageSetupTemplateName
= NULL
;
922 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
923 memset(devMode, 0, sizeof(DEVMODE));
924 devMode->dmSize = sizeof(DEVMODE);
925 devMode->dmOrientation = m_orientation;
926 devMode->dmFields = DM_ORIENTATION;
927 GlobalUnlock(pd->hDevMode);
933 bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData
&data
)
935 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
939 wxWindowsPrintNativeData
*native_data
=
940 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
942 // Pass the devmode data back to the wxPrintData structure where it really belongs.
945 if (native_data
->GetDevMode())
947 // Make sure we don't leak memory
948 GlobalFree((HGLOBAL
) native_data
->GetDevMode());
950 native_data
->SetDevMode( (void*) pd
->hDevMode
);
954 // Isn't this superfluous? It's called again below.
955 // data.GetPrintData().ConvertFromNative();
957 // Pass the devnames data back to the wxPrintData structure where it really belongs.
960 if (native_data
->GetDevNames())
962 // Make sure we don't leak memory
963 GlobalFree((HGLOBAL
) native_data
->GetDevNames());
965 native_data
->SetDevNames((void*) pd
->hDevNames
);
966 pd
->hDevNames
= NULL
;
969 data
.GetPrintData().ConvertFromNative();
971 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
973 data
.SetDefaultMinMargins( ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
) );
974 data
.EnableMargins( ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
) );
975 data
.EnableOrientation( ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
) );
976 data
.EnablePaper( ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
) );
977 data
.EnablePrinter( ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
) );
978 data
.SetDefaultInfo( ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
) );
979 data
.EnableHelp( ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
) );
981 // PAGESETUPDLG is in hundreds of a mm
982 data
.SetPaperSize( wxSize(pd
->ptPaperSize
.x
/ 100, pd
->ptPaperSize
.y
/ 100) );
984 data
.SetMinMarginTopLeft( wxPoint(pd
->rtMinMargin
.left
/ 100, pd
->rtMinMargin
.top
/ 100) );
985 data
.SetMinMarginBottomRight( wxPoint(pd
->rtMinMargin
.right
/ 100, pd
->rtMinMargin
.bottom
/ 100) );
987 data
.SetMarginTopLeft( wxPoint(pd
->rtMargin
.left
/ 100, pd
->rtMargin
.top
/ 100) );
988 data
.SetMarginBottomRight( wxPoint(pd
->rtMargin
.right
/ 100, pd
->rtMargin
.bottom
/ 100) );
994 // wxUSE_PRINTING_ARCHITECTURE