1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/printdlg.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 // Don't use the Windows print dialog if we're in wxUniv mode and using
28 // the PostScript architecture
29 #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXUNIVERSAL__) || !wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
32 #include "wx/msw/wrapcdlg.h"
34 #include "wx/dcprint.h"
35 #include "wx/cmndata.h"
38 #include "wx/printdlg.h"
39 #include "wx/msw/printdlg.h"
40 #include "wx/msw/dcprint.h"
45 //----------------------------------------------------------------------------
46 // wxWindowsPrintNativeData
47 //----------------------------------------------------------------------------
49 static wxString
wxGetPrintDlgError()
51 DWORD err
= CommDlgExtendedError();
52 wxString msg
= wxT("Unknown");
55 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
56 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
57 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
58 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
59 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
60 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
61 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
62 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
63 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
64 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
65 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
66 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
67 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
68 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
69 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
70 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
71 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
72 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
73 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
74 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
75 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
76 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
83 wxCreateDevNames(const wxString
& driverName
,
84 const wxString
& printerName
,
85 const wxString
& portName
)
88 // if (!driverName.empty() && !printerName.empty() && !portName.empty())
89 if (driverName
.empty() && printerName
.empty() && portName
.empty())
94 hDev
= GlobalAlloc(GPTR
, 4*sizeof(WORD
)+
95 ( driverName
.length() + 1 +
96 printerName
.length() + 1 +
97 portName
.length()+1 ) * sizeof(wxChar
) );
98 LPDEVNAMES lpDev
= (LPDEVNAMES
)GlobalLock(hDev
);
99 lpDev
->wDriverOffset
= sizeof(WORD
) * 4 / sizeof(wxChar
);
100 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDriverOffset
, driverName
);
102 lpDev
->wDeviceOffset
= (WORD
)( lpDev
->wDriverOffset
+
103 driverName
.length() + 1 );
104 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDeviceOffset
, printerName
);
106 lpDev
->wOutputOffset
= (WORD
)( lpDev
->wDeviceOffset
+
107 printerName
.length() + 1 );
108 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wOutputOffset
, portName
);
118 IMPLEMENT_CLASS(wxWindowsPrintNativeData
, wxPrintNativeDataBase
)
120 wxWindowsPrintNativeData::wxWindowsPrintNativeData()
124 m_customWindowsPaperId
= 0;
127 wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
130 ::GlobalFree(static_cast<HGLOBAL
>(m_devMode
));
133 ::GlobalFree(static_cast<HGLOBAL
>(m_devNames
));
136 bool wxWindowsPrintNativeData::IsOk() const
138 return (m_devMode
!= NULL
) ;
141 bool wxWindowsPrintNativeData::TransferTo( wxPrintData
&data
)
146 GlobalPtrLock
lockDevMode(m_devMode
);
148 LPDEVMODE devMode
= static_cast<LPDEVMODE
>(lockDevMode
.Get());
151 if (devMode
->dmFields
& DM_ORIENTATION
)
152 data
.SetOrientation( devMode
->dmOrientation
);
155 if (devMode
->dmFields
& DM_COLLATE
)
157 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
158 data
.SetCollate( true );
160 data
.SetCollate( false );
163 //// Number of copies
164 if (devMode
->dmFields
& DM_COPIES
)
165 data
.SetNoCopies( devMode
->dmCopies
);
168 if (devMode
->dmFields
& DM_DEFAULTSOURCE
) {
169 switch (devMode
->dmDefaultSource
) {
170 case DMBIN_ONLYONE
: data
.SetBin(wxPRINTBIN_ONLYONE
); break;
171 case DMBIN_LOWER
: data
.SetBin(wxPRINTBIN_LOWER
); break;
172 case DMBIN_MIDDLE
: data
.SetBin(wxPRINTBIN_MIDDLE
); break;
173 case DMBIN_MANUAL
: data
.SetBin(wxPRINTBIN_MANUAL
); break;
174 case DMBIN_ENVELOPE
: data
.SetBin(wxPRINTBIN_ENVELOPE
); break;
175 case DMBIN_ENVMANUAL
: data
.SetBin(wxPRINTBIN_ENVMANUAL
); break;
176 case DMBIN_AUTO
: data
.SetBin(wxPRINTBIN_AUTO
); break;
177 case DMBIN_TRACTOR
: data
.SetBin(wxPRINTBIN_TRACTOR
); break;
178 case DMBIN_SMALLFMT
: data
.SetBin(wxPRINTBIN_SMALLFMT
); break;
179 case DMBIN_LARGEFMT
: data
.SetBin(wxPRINTBIN_LARGEFMT
); break;
180 case DMBIN_LARGECAPACITY
: data
.SetBin(wxPRINTBIN_LARGECAPACITY
); break;
181 case DMBIN_CASSETTE
: data
.SetBin(wxPRINTBIN_CASSETTE
); break;
182 case DMBIN_FORMSOURCE
: data
.SetBin(wxPRINTBIN_FORMSOURCE
); break;
184 if (devMode
->dmDefaultSource
>= DMBIN_USER
)
185 data
.SetBin((wxPrintBin
)((devMode
->dmDefaultSource
)-DMBIN_USER
+(int)wxPRINTBIN_USER
));
187 data
.SetBin(wxPRINTBIN_DEFAULT
);
190 data
.SetBin(wxPRINTBIN_DEFAULT
);
192 if (devMode
->dmFields
& DM_MEDIATYPE
)
194 wxASSERT( (int)devMode
->dmMediaType
!= wxPRINTMEDIA_DEFAULT
);
195 data
.SetMedia(devMode
->dmMediaType
);
198 if (devMode
->dmDeviceName
[0] != 0)
199 // This syntax fixes a crash when using VS 7.1
200 data
.SetPrinterName( wxString(devMode
->dmDeviceName
, CCHDEVICENAME
) );
203 if (devMode
->dmFields
& DM_COLOR
)
205 if (devMode
->dmColor
== DMCOLOR_COLOR
)
206 data
.SetColour( true );
208 data
.SetColour( false );
211 data
.SetColour( true );
215 // We don't know size of user defined paper and some buggy drivers
216 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
217 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
218 // code wouldn't set m_paperSize correctly.
220 bool foundPaperSize
= false;
221 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
223 if (wxThePrintPaperDatabase
)
225 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
228 data
.SetPaperId( paper
->GetId() );
229 data
.SetPaperSize( wxSize(paper
->GetWidth() / 10,paper
->GetHeight() / 10) );
230 m_customWindowsPaperId
= 0;
231 foundPaperSize
= true;
236 // Shouldn't really get here
237 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
238 data
.SetPaperId( wxPAPER_NONE
);
239 data
.SetPaperSize( wxSize(0,0) );
240 m_customWindowsPaperId
= 0;
246 if (!foundPaperSize
) {
247 if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
249 // DEVMODE is in tenths of a millimeter
250 data
.SetPaperSize( wxSize(devMode
->dmPaperWidth
/ 10, devMode
->dmPaperLength
/ 10) );
251 data
.SetPaperId( wxPAPER_NONE
);
252 m_customWindowsPaperId
= devMode
->dmPaperSize
;
256 // Often will reach this for non-standard paper sizes (sizes which
257 // wouldn't be in wxWidget's paper database). Setting
258 // m_customWindowsPaperId to devMode->dmPaperSize should be enough
259 // to get this paper size working.
260 data
.SetPaperSize( wxSize(0,0) );
261 data
.SetPaperId( wxPAPER_NONE
);
262 m_customWindowsPaperId
= devMode
->dmPaperSize
;
268 if (devMode
->dmFields
& DM_DUPLEX
)
270 switch (devMode
->dmDuplex
)
272 case DMDUP_HORIZONTAL
: data
.SetDuplex( wxDUPLEX_HORIZONTAL
); break;
273 case DMDUP_VERTICAL
: data
.SetDuplex( wxDUPLEX_VERTICAL
); break;
275 case DMDUP_SIMPLEX
: data
.SetDuplex( wxDUPLEX_SIMPLEX
); break;
279 data
.SetDuplex( wxDUPLEX_SIMPLEX
);
283 if (devMode
->dmFields
& DM_PRINTQUALITY
)
285 switch (devMode
->dmPrintQuality
)
287 case DMRES_MEDIUM
: data
.SetQuality( wxPRINT_QUALITY_MEDIUM
); break;
288 case DMRES_LOW
: data
.SetQuality( wxPRINT_QUALITY_LOW
); break;
289 case DMRES_DRAFT
: data
.SetQuality( wxPRINT_QUALITY_DRAFT
); break;
290 case DMRES_HIGH
: data
.SetQuality( wxPRINT_QUALITY_HIGH
); break;
293 // TODO: if the printer fills in the resolution in DPI, how
294 // will the application know if it's high, low, draft etc.??
295 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
296 data
.SetQuality( devMode
->dmPrintQuality
);
303 data
.SetQuality( wxPRINT_QUALITY_HIGH
);
305 if (devMode
->dmDriverExtra
> 0)
306 data
.SetPrivData( (char *)devMode
+devMode
->dmSize
, devMode
->dmDriverExtra
);
308 data
.SetPrivData( NULL
, 0 );
312 GlobalPtrLock
lockDevNames(m_devNames
);
313 LPDEVNAMES lpDevNames
= static_cast<LPDEVNAMES
>(lockDevNames
.Get());
315 // TODO: Unicode-ification
318 // port is obsolete in WIN32
319 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
321 // Get the printer name
322 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
324 // Not sure if we should check for this mismatch
325 // wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
327 if (!printerName
.empty())
328 data
.SetPrinterName( printerName
);
334 bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData
&data
)
336 HGLOBAL hDevMode
= static_cast<HGLOBAL
>(m_devMode
);
339 // Use PRINTDLG as a way of creating a DEVMODE object
342 memset(&pd
, 0, sizeof(PRINTDLG
));
344 pd
.cbStruct
= sizeof(PRINTDLG
);
346 pd
.lStructSize
= sizeof(PRINTDLG
);
350 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
351 pd
.hDevNames
= NULL
; // Ditto
353 pd
.Flags
= PD_RETURNDEFAULT
;
356 // Fill out the DEVMODE structure
357 // so we can use it as input in the 'real' PrintDlg
361 GlobalFree(pd
.hDevMode
);
363 GlobalFree(pd
.hDevNames
);
367 wxLogDebug(wxT("Printing error: ") + wxGetPrintDlgError());
371 hDevMode
= pd
.hDevMode
;
372 m_devMode
= hDevMode
;
375 // We'll create a new DEVNAMEs structure below.
377 GlobalFree(pd
.hDevNames
);
380 // hDevNames = pd->hDevNames;
381 // m_devNames = (void*)(long) hDevNames;
382 // pd->hDevnames = NULL;
389 GlobalPtrLock
lockDevMode(hDevMode
);
390 DEVMODE
* const devMode
= static_cast<DEVMODE
*>(lockDevMode
.Get());
393 devMode
->dmOrientation
= (short)data
.GetOrientation();
396 devMode
->dmCollate
= (data
.GetCollate() ? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
397 devMode
->dmFields
|= DM_COLLATE
;
399 //// Number of copies
400 devMode
->dmCopies
= (short)data
.GetNoCopies();
401 devMode
->dmFields
|= DM_COPIES
;
404 wxString name
= data
.GetPrinterName();
407 // NB: the cast is needed in the ANSI build, strangely enough
408 // dmDeviceName is BYTE[] and not char[] there
409 wxStrlcpy(reinterpret_cast<wxChar
*>(devMode
->dmDeviceName
),
411 WXSIZEOF(devMode
->dmDeviceName
));
415 if (data
.GetColour())
416 devMode
->dmColor
= DMCOLOR_COLOR
;
418 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
419 devMode
->dmFields
|= DM_COLOR
;
423 // Paper id has priority over paper size. If id is specified, then size
424 // is ignored (as it can be filled in even for standard paper sizes)
426 wxPrintPaperType
*paperType
= NULL
;
428 const wxPaperSize paperId
= data
.GetPaperId();
429 if ( paperId
!= wxPAPER_NONE
&& wxThePrintPaperDatabase
)
431 paperType
= wxThePrintPaperDatabase
->FindPaperType(paperId
);
436 devMode
->dmPaperSize
= (short)paperType
->GetPlatformId();
437 devMode
->dmFields
|= DM_PAPERSIZE
;
439 else // custom (or no) paper size
441 const wxSize paperSize
= data
.GetPaperSize();
442 if ( paperSize
!= wxDefaultSize
)
444 // Fall back on specifying the paper size explicitly
445 if(m_customWindowsPaperId
!= 0)
446 devMode
->dmPaperSize
= m_customWindowsPaperId
;
448 devMode
->dmPaperSize
= DMPAPER_USER
;
449 devMode
->dmPaperWidth
= (short)(paperSize
.x
* 10);
450 devMode
->dmPaperLength
= (short)(paperSize
.y
* 10);
451 devMode
->dmFields
|= DM_PAPERWIDTH
;
452 devMode
->dmFields
|= DM_PAPERLENGTH
;
454 //else: neither paper type nor size specified, don't fill DEVMODE
455 // at all so that the system defaults are used
460 switch (data
.GetDuplex())
462 case wxDUPLEX_HORIZONTAL
:
463 duplex
= DMDUP_HORIZONTAL
;
465 case wxDUPLEX_VERTICAL
:
466 duplex
= DMDUP_VERTICAL
;
469 // in fact case wxDUPLEX_SIMPLEX:
470 duplex
= DMDUP_SIMPLEX
;
473 devMode
->dmDuplex
= duplex
;
474 devMode
->dmFields
|= DM_DUPLEX
;
479 switch (data
.GetQuality())
481 case wxPRINT_QUALITY_MEDIUM
:
482 quality
= DMRES_MEDIUM
;
484 case wxPRINT_QUALITY_LOW
:
487 case wxPRINT_QUALITY_DRAFT
:
488 quality
= DMRES_DRAFT
;
490 case wxPRINT_QUALITY_HIGH
:
491 quality
= DMRES_HIGH
;
494 quality
= (short)data
.GetQuality();
497 devMode
->dmPrintQuality
= quality
;
498 devMode
->dmFields
|= DM_PRINTQUALITY
;
500 if (data
.GetPrivDataLen() > 0)
502 memcpy( (char *)devMode
+devMode
->dmSize
, data
.GetPrivData(), data
.GetPrivDataLen() );
503 devMode
->dmDriverExtra
= (WXWORD
)data
.GetPrivDataLen();
506 if (data
.GetBin() != wxPRINTBIN_DEFAULT
)
508 switch (data
.GetBin())
510 case wxPRINTBIN_ONLYONE
: devMode
->dmDefaultSource
= DMBIN_ONLYONE
; break;
511 case wxPRINTBIN_LOWER
: devMode
->dmDefaultSource
= DMBIN_LOWER
; break;
512 case wxPRINTBIN_MIDDLE
: devMode
->dmDefaultSource
= DMBIN_MIDDLE
; break;
513 case wxPRINTBIN_MANUAL
: devMode
->dmDefaultSource
= DMBIN_MANUAL
; break;
514 case wxPRINTBIN_ENVELOPE
: devMode
->dmDefaultSource
= DMBIN_ENVELOPE
; break;
515 case wxPRINTBIN_ENVMANUAL
: devMode
->dmDefaultSource
= DMBIN_ENVMANUAL
; break;
516 case wxPRINTBIN_AUTO
: devMode
->dmDefaultSource
= DMBIN_AUTO
; break;
517 case wxPRINTBIN_TRACTOR
: devMode
->dmDefaultSource
= DMBIN_TRACTOR
; break;
518 case wxPRINTBIN_SMALLFMT
: devMode
->dmDefaultSource
= DMBIN_SMALLFMT
; break;
519 case wxPRINTBIN_LARGEFMT
: devMode
->dmDefaultSource
= DMBIN_LARGEFMT
; break;
520 case wxPRINTBIN_LARGECAPACITY
: devMode
->dmDefaultSource
= DMBIN_LARGECAPACITY
; break;
521 case wxPRINTBIN_CASSETTE
: devMode
->dmDefaultSource
= DMBIN_CASSETTE
; break;
522 case wxPRINTBIN_FORMSOURCE
: devMode
->dmDefaultSource
= DMBIN_FORMSOURCE
; break;
525 devMode
->dmDefaultSource
= (short)(DMBIN_USER
+ data
.GetBin() - wxPRINTBIN_USER
); // 256 + data.GetBin() - 14 = 242 + data.GetBin()
529 devMode
->dmFields
|= DM_DEFAULTSOURCE
;
531 if (data
.GetMedia() != wxPRINTMEDIA_DEFAULT
)
533 devMode
->dmMediaType
= data
.GetMedia();
534 devMode
->dmFields
|= DM_MEDIATYPE
;
540 ::GlobalFree(static_cast<HGLOBAL
>(m_devNames
));
543 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
544 m_devNames
= wxCreateDevNames(wxEmptyString
, data
.GetPrinterName(), wxEmptyString
);
549 // ---------------------------------------------------------------------------
551 // ---------------------------------------------------------------------------
553 IMPLEMENT_CLASS(wxWindowsPrintDialog
, wxPrintDialogBase
)
555 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
560 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintData
* data
)
562 wxPrintDialogData data2
;
569 bool wxWindowsPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
579 m_printDialogData
= *data
;
584 wxWindowsPrintDialog::~wxWindowsPrintDialog()
586 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
587 if (pd
&& pd
->hDevMode
)
588 GlobalFree(pd
->hDevMode
);
592 if (m_destroyDC
&& m_printerDC
)
596 int wxWindowsPrintDialog::ShowModal()
598 ConvertToNative( m_printDialogData
);
600 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
603 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
604 else if (wxTheApp
->GetTopWindow())
605 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
609 bool ret
= (PrintDlg( pd
) != 0);
613 if ( ret
&& (pd
->hDC
) )
615 wxPrinterDC
*pdc
= new wxPrinterDCFromHDC( (WXHDC
) pd
->hDC
);
617 ConvertFromNative( m_printDialogData
);
626 wxDC
*wxWindowsPrintDialog::GetPrintDC()
637 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData
&data
)
639 wxWindowsPrintNativeData
*native_data
=
640 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
641 data
.GetPrintData().ConvertToNative();
643 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
645 // Shouldn't have been defined anywhere
650 memset( pd
, 0, sizeof(PRINTDLG
) );
651 m_printDlg
= (void*) pd
;
653 pd
->lStructSize
= sizeof(PRINTDLG
);
654 pd
->hwndOwner
= NULL
;
655 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
656 pd
->hDevNames
= NULL
; // Ditto
658 pd
->Flags
= PD_RETURNDEFAULT
;
661 // Pass the devmode data to the PRINTDLG structure, since it'll
662 // be needed when PrintDlg is called.
664 GlobalFree(pd
->hDevMode
);
666 // Pass the devnames data to the PRINTDLG structure, since it'll
667 // be needed when PrintDlg is called.
669 GlobalFree(pd
->hDevNames
);
671 pd
->hDevMode
= static_cast<HGLOBAL
>(native_data
->GetDevMode());
672 native_data
->SetDevMode(NULL
);
674 // Shouldn't assert; we should be able to test Ok-ness at a higher level
675 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
677 pd
->hDevNames
= static_cast<HGLOBAL
>(native_data
->GetDevNames());
678 native_data
->SetDevNames(NULL
);
682 pd
->nFromPage
= (WORD
)data
.GetFromPage();
683 pd
->nToPage
= (WORD
)data
.GetToPage();
684 pd
->nMinPage
= (WORD
)data
.GetMinPage();
685 pd
->nMaxPage
= (WORD
)data
.GetMaxPage();
686 pd
->nCopies
= (WORD
)data
.GetNoCopies();
688 pd
->Flags
= PD_RETURNDC
;
689 pd
->lStructSize
= sizeof( PRINTDLG
);
691 pd
->hwndOwner
= NULL
;
692 pd
->hInstance
= NULL
;
694 pd
->lpfnPrintHook
= NULL
;
695 pd
->lpfnSetupHook
= NULL
;
696 pd
->lpPrintTemplateName
= NULL
;
697 pd
->lpSetupTemplateName
= NULL
;
698 pd
->hPrintTemplate
= NULL
;
699 pd
->hSetupTemplate
= NULL
;
701 if ( data
.GetAllPages() )
702 pd
->Flags
|= PD_ALLPAGES
;
703 if ( data
.GetSelection() )
704 pd
->Flags
|= PD_SELECTION
;
705 if ( data
.GetCollate() )
706 pd
->Flags
|= PD_COLLATE
;
707 if ( data
.GetPrintToFile() )
708 pd
->Flags
|= PD_PRINTTOFILE
;
709 if ( !data
.GetEnablePrintToFile() )
710 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
711 if ( !data
.GetEnableSelection() )
712 pd
->Flags
|= PD_NOSELECTION
;
713 if ( !data
.GetEnablePageNumbers() )
714 pd
->Flags
|= PD_NOPAGENUMS
;
715 else if ( (!data
.GetAllPages()) && (!data
.GetSelection()) && (data
.GetFromPage() != 0) && (data
.GetToPage() != 0))
716 pd
->Flags
|= PD_PAGENUMS
;
717 if ( data
.GetEnableHelp() )
718 pd
->Flags
|= PD_SHOWHELP
;
723 bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData
&data
)
725 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
729 wxWindowsPrintNativeData
*native_data
=
730 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
732 // Pass the devmode data back to the wxPrintData structure where it really belongs.
735 if (native_data
->GetDevMode())
737 ::GlobalFree(static_cast<HGLOBAL
>(native_data
->GetDevMode()));
739 native_data
->SetDevMode(pd
->hDevMode
);
743 // Pass the devnames data back to the wxPrintData structure where it really belongs.
746 if (native_data
->GetDevNames())
748 ::GlobalFree(static_cast<HGLOBAL
>(native_data
->GetDevNames()));
750 native_data
->SetDevNames(pd
->hDevNames
);
751 pd
->hDevNames
= NULL
;
754 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
755 // into wxWidgets form.
756 native_data
->TransferTo( data
.GetPrintData() );
758 data
.SetFromPage( pd
->nFromPage
);
759 data
.SetToPage( pd
->nToPage
);
760 data
.SetMinPage( pd
->nMinPage
);
761 data
.SetMaxPage( pd
->nMaxPage
);
762 data
.SetNoCopies( pd
->nCopies
);
764 data
.SetAllPages( (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
)) );
765 data
.SetSelection( ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
) );
766 data
.SetCollate( ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
) );
767 data
.SetPrintToFile( ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
) );
768 data
.EnablePrintToFile( ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
) );
769 data
.EnableSelection( ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
) );
770 data
.EnablePageNumbers( ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
) );
771 data
.EnableHelp( ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
) );
776 // ---------------------------------------------------------------------------
777 // wxWidnowsPageSetupDialog
778 // ---------------------------------------------------------------------------
780 IMPLEMENT_CLASS(wxWindowsPageSetupDialog
, wxPageSetupDialogBase
)
782 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog()
784 m_dialogParent
= NULL
;
788 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow
*p
, wxPageSetupDialogData
*data
)
793 bool wxWindowsPageSetupDialog::Create(wxWindow
*p
, wxPageSetupDialogData
*data
)
799 m_pageSetupData
= (*data
);
804 wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog()
806 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageDlg
;
807 if ( pd
&& pd
->hDevMode
)
808 GlobalFree(pd
->hDevMode
);
809 if ( pd
&& pd
->hDevNames
)
810 GlobalFree(pd
->hDevNames
);
815 int wxWindowsPageSetupDialog::ShowModal()
817 ConvertToNative( m_pageSetupData
);
819 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
821 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
822 else if (wxTheApp
->GetTopWindow())
823 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
826 BOOL retVal
= PageSetupDlg( pd
) ;
830 ConvertFromNative( m_pageSetupData
);
837 bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData
&data
)
839 wxWindowsPrintNativeData
*native_data
=
840 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
841 data
.GetPrintData().ConvertToNative();
843 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
845 // Shouldn't have been defined anywhere
849 pd
= new PAGESETUPDLG
;
851 pd
->hDevNames
= NULL
;
852 m_pageDlg
= (void *)pd
;
854 // Pass the devmode data (created in m_printData.ConvertToNative)
855 // to the PRINTDLG structure, since it'll
856 // be needed when PrintDlg is called.
860 GlobalFree(pd
->hDevMode
);
863 pd
->hDevMode
= (HGLOBAL
) native_data
->GetDevMode();
864 native_data
->SetDevMode(NULL
);
866 // Shouldn't assert; we should be able to test Ok-ness at a higher level
867 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
869 // Pass the devnames data (created in m_printData.ConvertToNative)
870 // to the PRINTDLG structure, since it'll
871 // be needed when PrintDlg is called.
875 GlobalFree(pd
->hDevNames
);
876 pd
->hDevNames
= NULL
;
878 pd
->hDevNames
= (HGLOBAL
) native_data
->GetDevNames();
879 native_data
->SetDevNames(NULL
);
881 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
883 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
885 if ( data
.GetDefaultMinMargins() )
886 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
887 if ( !data
.GetEnableMargins() )
888 pd
->Flags
|= PSD_DISABLEMARGINS
;
889 if ( !data
.GetEnableOrientation() )
890 pd
->Flags
|= PSD_DISABLEORIENTATION
;
891 if ( !data
.GetEnablePaper() )
892 pd
->Flags
|= PSD_DISABLEPAPER
;
893 if ( !data
.GetEnablePrinter() )
894 pd
->Flags
|= PSD_DISABLEPRINTER
;
895 if ( data
.GetDefaultInfo() )
896 pd
->Flags
|= PSD_RETURNDEFAULT
;
897 if ( data
.GetEnableHelp() )
898 pd
->Flags
|= PSD_SHOWHELP
;
900 // We want the units to be in hundredths of a millimetre
901 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
903 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
904 pd
->hwndOwner
= NULL
;
905 pd
->hInstance
= NULL
;
906 // PAGESETUPDLG is in hundreds of a mm
907 pd
->ptPaperSize
.x
= data
.GetPaperSize().x
* 100;
908 pd
->ptPaperSize
.y
= data
.GetPaperSize().y
* 100;
910 pd
->rtMinMargin
.left
= data
.GetMinMarginTopLeft().x
* 100;
911 pd
->rtMinMargin
.top
= data
.GetMinMarginTopLeft().y
* 100;
912 pd
->rtMinMargin
.right
= data
.GetMinMarginBottomRight().x
* 100;
913 pd
->rtMinMargin
.bottom
= data
.GetMinMarginBottomRight().y
* 100;
915 pd
->rtMargin
.left
= data
.GetMarginTopLeft().x
* 100;
916 pd
->rtMargin
.top
= data
.GetMarginTopLeft().y
* 100;
917 pd
->rtMargin
.right
= data
.GetMarginBottomRight().x
* 100;
918 pd
->rtMargin
.bottom
= data
.GetMarginBottomRight().y
* 100;
921 pd
->lpfnPageSetupHook
= NULL
;
922 pd
->lpfnPagePaintHook
= NULL
;
923 pd
->hPageSetupTemplate
= NULL
;
924 pd
->lpPageSetupTemplateName
= NULL
;
929 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
930 memset(devMode, 0, sizeof(DEVMODE));
931 devMode->dmSize = sizeof(DEVMODE);
932 devMode->dmOrientation = m_orientation;
933 devMode->dmFields = DM_ORIENTATION;
934 GlobalUnlock(pd->hDevMode);
940 bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData
&data
)
942 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
946 wxWindowsPrintNativeData
*native_data
=
947 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
949 // Pass the devmode data back to the wxPrintData structure where it really belongs.
952 if (native_data
->GetDevMode())
954 // Make sure we don't leak memory
955 GlobalFree((HGLOBAL
) native_data
->GetDevMode());
957 native_data
->SetDevMode( (void*) pd
->hDevMode
);
961 // Isn't this superfluous? It's called again below.
962 // data.GetPrintData().ConvertFromNative();
964 // Pass the devnames data back to the wxPrintData structure where it really belongs.
967 if (native_data
->GetDevNames())
969 // Make sure we don't leak memory
970 GlobalFree((HGLOBAL
) native_data
->GetDevNames());
972 native_data
->SetDevNames((void*) pd
->hDevNames
);
973 pd
->hDevNames
= NULL
;
976 data
.GetPrintData().ConvertFromNative();
978 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
980 data
.SetDefaultMinMargins( ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
) );
981 data
.EnableMargins( ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
) );
982 data
.EnableOrientation( ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
) );
983 data
.EnablePaper( ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
) );
984 data
.EnablePrinter( ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
) );
985 data
.SetDefaultInfo( ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
) );
986 data
.EnableHelp( ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
) );
988 // PAGESETUPDLG is in hundreds of a mm
989 if (data
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
990 data
.SetPaperSize( wxSize(pd
->ptPaperSize
.y
/ 100, pd
->ptPaperSize
.x
/ 100) );
992 data
.SetPaperSize( wxSize(pd
->ptPaperSize
.x
/ 100, pd
->ptPaperSize
.y
/ 100) );
994 data
.SetMinMarginTopLeft( wxPoint(pd
->rtMinMargin
.left
/ 100, pd
->rtMinMargin
.top
/ 100) );
995 data
.SetMinMarginBottomRight( wxPoint(pd
->rtMinMargin
.right
/ 100, pd
->rtMinMargin
.bottom
/ 100) );
997 data
.SetMarginTopLeft( wxPoint(pd
->rtMargin
.left
/ 100, pd
->rtMargin
.top
/ 100) );
998 data
.SetMarginBottomRight( wxPoint(pd
->rtMargin
.right
/ 100, pd
->rtMargin
.bottom
/ 100) );
1004 // wxUSE_PRINTING_ARCHITECTURE