]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
6d50343d | 2 | // Name: src/msw/printdlg.cpp |
2bda0e17 KB |
3 | // Purpose: wxPrintDialog, wxPageSetupDialog |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
103aec29 VZ |
12 | // =========================================================================== |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | // For compilers that support precompilation, includes "wx.h". |
2bda0e17 KB |
21 | #include "wx/wxprec.h" |
22 | ||
a3b46648 | 23 | #ifdef __BORLANDC__ |
103aec29 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
12bdd77c JS |
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) | |
f6bcfd97 BP |
30 | |
31 | #ifndef WX_PRECOMP | |
57bd4c60 | 32 | #include "wx/msw/wrapcdlg.h" |
f6bcfd97 | 33 | #include "wx/app.h" |
6d50343d | 34 | #include "wx/dcprint.h" |
ce5d92e1 | 35 | #include "wx/cmndata.h" |
f6bcfd97 BP |
36 | #endif |
37 | ||
2bda0e17 | 38 | #include "wx/printdlg.h" |
08680429 | 39 | #include "wx/msw/printdlg.h" |
888dde65 | 40 | #include "wx/msw/dcprint.h" |
8850cbd3 | 41 | #include "wx/paper.h" |
643e9cf9 | 42 | #include "wx/testing.h" |
2bda0e17 | 43 | |
2bda0e17 | 44 | #include <stdlib.h> |
42e69d6b | 45 | |
7da33e04 JS |
46 | // smart pointer like class using OpenPrinter and ClosePrinter |
47 | class WinPrinter | |
48 | { | |
49 | public: | |
50 | // default ctor | |
51 | WinPrinter() | |
52 | { | |
53 | m_hPrinter = (HANDLE)NULL; | |
54 | } | |
55 | ||
56 | WinPrinter( const wxString& printerName ) | |
57 | { | |
58 | Open( printerName ); | |
59 | } | |
60 | ||
61 | ~WinPrinter() | |
62 | { | |
63 | Close(); | |
64 | } | |
65 | ||
66 | BOOL Open( const wxString& printerName, LPPRINTER_DEFAULTS pDefault=(LPPRINTER_DEFAULTS)NULL ) | |
67 | { | |
68 | Close(); | |
017dc06b | 69 | return OpenPrinter( wxMSW_CONV_LPTSTR(printerName), &m_hPrinter, pDefault ); |
7da33e04 JS |
70 | } |
71 | ||
72 | BOOL Close() | |
73 | { | |
74 | BOOL result = TRUE; | |
75 | if( m_hPrinter ) | |
76 | { | |
77 | result = ClosePrinter( m_hPrinter ); | |
78 | m_hPrinter = (HANDLE)NULL; | |
79 | } | |
80 | return result; | |
81 | } | |
82 | ||
83 | operator HANDLE() { return m_hPrinter; } | |
84 | operator bool() { return m_hPrinter != (HANDLE)NULL; } | |
85 | ||
86 | private: | |
87 | HANDLE m_hPrinter; | |
88 | ||
89 | wxDECLARE_NO_COPY_CLASS(WinPrinter); | |
90 | }; | |
91 | ||
92 | ||
8850cbd3 RR |
93 | //---------------------------------------------------------------------------- |
94 | // wxWindowsPrintNativeData | |
95 | //---------------------------------------------------------------------------- | |
96 | ||
d021f94f VZ |
97 | #if wxDEBUG_LEVEL |
98 | ||
8850cbd3 RR |
99 | static wxString wxGetPrintDlgError() |
100 | { | |
101 | DWORD err = CommDlgExtendedError(); | |
102 | wxString msg = wxT("Unknown"); | |
103 | switch (err) | |
104 | { | |
105 | case CDERR_FINDRESFAILURE: msg = wxT("CDERR_FINDRESFAILURE"); break; | |
106 | case CDERR_INITIALIZATION: msg = wxT("CDERR_INITIALIZATION"); break; | |
107 | case CDERR_LOADRESFAILURE: msg = wxT("CDERR_LOADRESFAILURE"); break; | |
108 | case CDERR_LOADSTRFAILURE: msg = wxT("CDERR_LOADSTRFAILURE"); break; | |
109 | case CDERR_LOCKRESFAILURE: msg = wxT("CDERR_LOCKRESFAILURE"); break; | |
110 | case CDERR_MEMALLOCFAILURE: msg = wxT("CDERR_MEMALLOCFAILURE"); break; | |
111 | case CDERR_MEMLOCKFAILURE: msg = wxT("CDERR_MEMLOCKFAILURE"); break; | |
112 | case CDERR_NOHINSTANCE: msg = wxT("CDERR_NOHINSTANCE"); break; | |
113 | case CDERR_NOHOOK: msg = wxT("CDERR_NOHOOK"); break; | |
114 | case CDERR_NOTEMPLATE: msg = wxT("CDERR_NOTEMPLATE"); break; | |
115 | case CDERR_STRUCTSIZE: msg = wxT("CDERR_STRUCTSIZE"); break; | |
116 | case PDERR_RETDEFFAILURE: msg = wxT("PDERR_RETDEFFAILURE"); break; | |
117 | case PDERR_PRINTERNOTFOUND: msg = wxT("PDERR_PRINTERNOTFOUND"); break; | |
118 | case PDERR_PARSEFAILURE: msg = wxT("PDERR_PARSEFAILURE"); break; | |
119 | case PDERR_NODEVICES: msg = wxT("PDERR_NODEVICES"); break; | |
120 | case PDERR_NODEFAULTPRN: msg = wxT("PDERR_NODEFAULTPRN"); break; | |
121 | case PDERR_LOADDRVFAILURE: msg = wxT("PDERR_LOADDRVFAILURE"); break; | |
122 | case PDERR_INITFAILURE: msg = wxT("PDERR_INITFAILURE"); break; | |
123 | case PDERR_GETDEVMODEFAIL: msg = wxT("PDERR_GETDEVMODEFAIL"); break; | |
124 | case PDERR_DNDMMISMATCH: msg = wxT("PDERR_DNDMMISMATCH"); break; | |
125 | case PDERR_DEFAULTDIFFERENT: msg = wxT("PDERR_DEFAULTDIFFERENT"); break; | |
126 | case PDERR_CREATEICFAILURE: msg = wxT("PDERR_CREATEICFAILURE"); break; | |
127 | default: break; | |
128 | } | |
129 | return msg; | |
130 | } | |
8850cbd3 | 131 | |
d021f94f VZ |
132 | #endif // wxDEBUG_LEVEL |
133 | ||
134 | ||
bd84061d VZ |
135 | static HGLOBAL |
136 | wxCreateDevNames(const wxString& driverName, | |
137 | const wxString& printerName, | |
138 | const wxString& portName) | |
8850cbd3 RR |
139 | { |
140 | HGLOBAL hDev = NULL; | |
f31a4098 WS |
141 | // if (!driverName.empty() && !printerName.empty() && !portName.empty()) |
142 | if (driverName.empty() && printerName.empty() && portName.empty()) | |
8850cbd3 RR |
143 | { |
144 | } | |
145 | else | |
146 | { | |
147 | hDev = GlobalAlloc(GPTR, 4*sizeof(WORD)+ | |
6d50343d WS |
148 | ( driverName.length() + 1 + |
149 | printerName.length() + 1 + | |
150 | portName.length()+1 ) * sizeof(wxChar) ); | |
8850cbd3 RR |
151 | LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(hDev); |
152 | lpDev->wDriverOffset = sizeof(WORD) * 4 / sizeof(wxChar); | |
153 | wxStrcpy((wxChar*)lpDev + lpDev->wDriverOffset, driverName); | |
154 | ||
155 | lpDev->wDeviceOffset = (WORD)( lpDev->wDriverOffset + | |
6d50343d | 156 | driverName.length() + 1 ); |
8850cbd3 RR |
157 | wxStrcpy((wxChar*)lpDev + lpDev->wDeviceOffset, printerName); |
158 | ||
159 | lpDev->wOutputOffset = (WORD)( lpDev->wDeviceOffset + | |
6d50343d | 160 | printerName.length() + 1 ); |
8850cbd3 RR |
161 | wxStrcpy((wxChar*)lpDev + lpDev->wOutputOffset, portName); |
162 | ||
163 | lpDev->wDefault = 0; | |
164 | ||
165 | GlobalUnlock(hDev); | |
166 | } | |
167 | ||
168 | return hDev; | |
169 | } | |
170 | ||
171 | IMPLEMENT_CLASS(wxWindowsPrintNativeData, wxPrintNativeDataBase) | |
172 | ||
173 | wxWindowsPrintNativeData::wxWindowsPrintNativeData() | |
174 | { | |
dca0f651 VZ |
175 | m_devMode = NULL; |
176 | m_devNames = NULL; | |
3168b4c3 | 177 | m_customWindowsPaperId = 0; |
8850cbd3 RR |
178 | } |
179 | ||
180 | wxWindowsPrintNativeData::~wxWindowsPrintNativeData() | |
181 | { | |
dca0f651 | 182 | if ( m_devMode ) |
5c33522f | 183 | ::GlobalFree(static_cast<HGLOBAL>(m_devMode)); |
dca0f651 VZ |
184 | |
185 | if ( m_devNames ) | |
5c33522f | 186 | ::GlobalFree(static_cast<HGLOBAL>(m_devNames)); |
8850cbd3 RR |
187 | } |
188 | ||
b7cacb43 | 189 | bool wxWindowsPrintNativeData::IsOk() const |
8850cbd3 RR |
190 | { |
191 | return (m_devMode != NULL) ; | |
192 | } | |
193 | ||
fd64de59 | 194 | bool wxWindowsPrintNativeData::TransferTo( wxPrintData &data ) |
8850cbd3 | 195 | { |
6c797d8f RD |
196 | if ( !m_devMode ) |
197 | InitializeDevMode(); | |
198 | ||
dca0f651 | 199 | if ( !m_devMode ) |
8850cbd3 | 200 | return false; |
8850cbd3 | 201 | |
dca0f651 | 202 | GlobalPtrLock lockDevMode(m_devMode); |
8850cbd3 | 203 | |
5c33522f | 204 | LPDEVMODE devMode = static_cast<LPDEVMODE>(lockDevMode.Get()); |
8850cbd3 | 205 | |
dca0f651 VZ |
206 | //// Orientation |
207 | if (devMode->dmFields & DM_ORIENTATION) | |
af7e24c3 | 208 | data.SetOrientation( (wxPrintOrientation)devMode->dmOrientation ); |
8850cbd3 | 209 | |
dca0f651 VZ |
210 | //// Collation |
211 | if (devMode->dmFields & DM_COLLATE) | |
212 | { | |
213 | if (devMode->dmCollate == DMCOLLATE_TRUE) | |
214 | data.SetCollate( true ); | |
8850cbd3 | 215 | else |
dca0f651 VZ |
216 | data.SetCollate( false ); |
217 | } | |
218 | ||
219 | //// Number of copies | |
220 | if (devMode->dmFields & DM_COPIES) | |
221 | data.SetNoCopies( devMode->dmCopies ); | |
222 | ||
223 | //// Bin | |
224 | if (devMode->dmFields & DM_DEFAULTSOURCE) { | |
225 | switch (devMode->dmDefaultSource) { | |
226 | case DMBIN_ONLYONE : data.SetBin(wxPRINTBIN_ONLYONE ); break; | |
227 | case DMBIN_LOWER : data.SetBin(wxPRINTBIN_LOWER ); break; | |
228 | case DMBIN_MIDDLE : data.SetBin(wxPRINTBIN_MIDDLE ); break; | |
229 | case DMBIN_MANUAL : data.SetBin(wxPRINTBIN_MANUAL ); break; | |
230 | case DMBIN_ENVELOPE : data.SetBin(wxPRINTBIN_ENVELOPE ); break; | |
231 | case DMBIN_ENVMANUAL : data.SetBin(wxPRINTBIN_ENVMANUAL ); break; | |
232 | case DMBIN_AUTO : data.SetBin(wxPRINTBIN_AUTO ); break; | |
233 | case DMBIN_TRACTOR : data.SetBin(wxPRINTBIN_TRACTOR ); break; | |
234 | case DMBIN_SMALLFMT : data.SetBin(wxPRINTBIN_SMALLFMT ); break; | |
235 | case DMBIN_LARGEFMT : data.SetBin(wxPRINTBIN_LARGEFMT ); break; | |
236 | case DMBIN_LARGECAPACITY : data.SetBin(wxPRINTBIN_LARGECAPACITY ); break; | |
237 | case DMBIN_CASSETTE : data.SetBin(wxPRINTBIN_CASSETTE ); break; | |
238 | case DMBIN_FORMSOURCE : data.SetBin(wxPRINTBIN_FORMSOURCE ); break; | |
239 | default: | |
bd84061d | 240 | if (devMode->dmDefaultSource >= DMBIN_USER) |
dca0f651 | 241 | data.SetBin((wxPrintBin)((devMode->dmDefaultSource)-DMBIN_USER+(int)wxPRINTBIN_USER)); |
bd84061d | 242 | else |
dca0f651 | 243 | data.SetBin(wxPRINTBIN_DEFAULT); |
dca0f651 VZ |
244 | } |
245 | } else { | |
246 | data.SetBin(wxPRINTBIN_DEFAULT); | |
247 | } | |
248 | if (devMode->dmFields & DM_MEDIATYPE) | |
249 | { | |
250 | wxASSERT( (int)devMode->dmMediaType != wxPRINTMEDIA_DEFAULT ); | |
251 | data.SetMedia(devMode->dmMediaType); | |
252 | } | |
253 | //// Printer name | |
254 | if (devMode->dmDeviceName[0] != 0) | |
255 | // This syntax fixes a crash when using VS 7.1 | |
256 | data.SetPrinterName( wxString(devMode->dmDeviceName, CCHDEVICENAME) ); | |
257 | ||
258 | //// Colour | |
259 | if (devMode->dmFields & DM_COLOR) | |
260 | { | |
261 | if (devMode->dmColor == DMCOLOR_COLOR) | |
8850cbd3 | 262 | data.SetColour( true ); |
dca0f651 VZ |
263 | else |
264 | data.SetColour( false ); | |
265 | } | |
266 | else | |
267 | data.SetColour( true ); | |
8850cbd3 | 268 | |
dca0f651 | 269 | //// Paper size |
8850cbd3 | 270 | |
dca0f651 VZ |
271 | // We don't know size of user defined paper and some buggy drivers |
272 | // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since | |
273 | // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this | |
274 | // code wouldn't set m_paperSize correctly. | |
21c358b2 | 275 | |
dca0f651 VZ |
276 | bool foundPaperSize = false; |
277 | if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER)) | |
278 | { | |
279 | if (wxThePrintPaperDatabase) | |
8850cbd3 | 280 | { |
dca0f651 VZ |
281 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize); |
282 | if (paper) | |
8850cbd3 | 283 | { |
dca0f651 VZ |
284 | data.SetPaperId( paper->GetId() ); |
285 | data.SetPaperSize( wxSize(paper->GetWidth() / 10,paper->GetHeight() / 10) ); | |
3168b4c3 | 286 | m_customWindowsPaperId = 0; |
dca0f651 | 287 | foundPaperSize = true; |
8850cbd3 RR |
288 | } |
289 | } | |
dca0f651 VZ |
290 | else |
291 | { | |
292 | // Shouldn't really get here | |
293 | wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative.")); | |
294 | data.SetPaperId( wxPAPER_NONE ); | |
295 | data.SetPaperSize( wxSize(0,0) ); | |
296 | m_customWindowsPaperId = 0; | |
3168b4c3 | 297 | |
dca0f651 | 298 | return false; |
8850cbd3 | 299 | } |
dca0f651 | 300 | } |
8850cbd3 | 301 | |
dca0f651 VZ |
302 | if (!foundPaperSize) { |
303 | if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH)) | |
8850cbd3 | 304 | { |
dca0f651 VZ |
305 | // DEVMODE is in tenths of a millimeter |
306 | data.SetPaperSize( wxSize(devMode->dmPaperWidth / 10, devMode->dmPaperLength / 10) ); | |
307 | data.SetPaperId( wxPAPER_NONE ); | |
308 | m_customWindowsPaperId = devMode->dmPaperSize; | |
8850cbd3 RR |
309 | } |
310 | else | |
dca0f651 VZ |
311 | { |
312 | // Often will reach this for non-standard paper sizes (sizes which | |
313 | // wouldn't be in wxWidget's paper database). Setting | |
314 | // m_customWindowsPaperId to devMode->dmPaperSize should be enough | |
315 | // to get this paper size working. | |
316 | data.SetPaperSize( wxSize(0,0) ); | |
317 | data.SetPaperId( wxPAPER_NONE ); | |
318 | m_customWindowsPaperId = devMode->dmPaperSize; | |
319 | } | |
320 | } | |
8850cbd3 | 321 | |
dca0f651 VZ |
322 | //// Duplex |
323 | ||
324 | if (devMode->dmFields & DM_DUPLEX) | |
325 | { | |
326 | switch (devMode->dmDuplex) | |
327 | { | |
328 | case DMDUP_HORIZONTAL: data.SetDuplex( wxDUPLEX_HORIZONTAL ); break; | |
329 | case DMDUP_VERTICAL: data.SetDuplex( wxDUPLEX_VERTICAL ); break; | |
330 | default: | |
331 | case DMDUP_SIMPLEX: data.SetDuplex( wxDUPLEX_SIMPLEX ); break; | |
332 | } | |
333 | } | |
334 | else | |
335 | data.SetDuplex( wxDUPLEX_SIMPLEX ); | |
8850cbd3 | 336 | |
dca0f651 VZ |
337 | //// Quality |
338 | ||
339 | if (devMode->dmFields & DM_PRINTQUALITY) | |
340 | { | |
341 | switch (devMode->dmPrintQuality) | |
8850cbd3 | 342 | { |
dca0f651 VZ |
343 | case DMRES_MEDIUM: data.SetQuality( wxPRINT_QUALITY_MEDIUM ); break; |
344 | case DMRES_LOW: data.SetQuality( wxPRINT_QUALITY_LOW ); break; | |
345 | case DMRES_DRAFT: data.SetQuality( wxPRINT_QUALITY_DRAFT ); break; | |
346 | case DMRES_HIGH: data.SetQuality( wxPRINT_QUALITY_HIGH ); break; | |
347 | default: | |
8850cbd3 | 348 | { |
dca0f651 VZ |
349 | // TODO: if the printer fills in the resolution in DPI, how |
350 | // will the application know if it's high, low, draft etc.?? | |
351 | // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values."); | |
352 | data.SetQuality( devMode->dmPrintQuality ); | |
353 | break; | |
8850cbd3 | 354 | |
8850cbd3 RR |
355 | } |
356 | } | |
8850cbd3 | 357 | } |
dca0f651 VZ |
358 | else |
359 | data.SetQuality( wxPRINT_QUALITY_HIGH ); | |
360 | ||
361 | if (devMode->dmDriverExtra > 0) | |
362 | data.SetPrivData( (char *)devMode+devMode->dmSize, devMode->dmDriverExtra ); | |
363 | else | |
364 | data.SetPrivData( NULL, 0 ); | |
8850cbd3 | 365 | |
dca0f651 | 366 | if ( m_devNames ) |
8850cbd3 | 367 | { |
dca0f651 | 368 | GlobalPtrLock lockDevNames(m_devNames); |
5c33522f | 369 | LPDEVNAMES lpDevNames = static_cast<LPDEVNAMES>(lockDevNames.Get()); |
8850cbd3 | 370 | |
dca0f651 | 371 | // TODO: Unicode-ification |
8850cbd3 | 372 | |
dca0f651 VZ |
373 | // Get the port name |
374 | // port is obsolete in WIN32 | |
375 | // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset); | |
8850cbd3 | 376 | |
dca0f651 VZ |
377 | // Get the printer name |
378 | wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
8850cbd3 | 379 | |
dca0f651 VZ |
380 | // Not sure if we should check for this mismatch |
381 | // wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); | |
8850cbd3 | 382 | |
dca0f651 VZ |
383 | if (!printerName.empty()) |
384 | data.SetPrinterName( printerName ); | |
8850cbd3 | 385 | } |
f31a4098 | 386 | |
8850cbd3 RR |
387 | return true; |
388 | } | |
389 | ||
6c797d8f | 390 | void wxWindowsPrintNativeData::InitializeDevMode(const wxString& printerName, WinPrinter* printer) |
8850cbd3 | 391 | { |
6c797d8f RD |
392 | if (m_devMode) |
393 | return; | |
394 | ||
017dc06b | 395 | LPTSTR szPrinterName = wxMSW_CONV_LPTSTR(printerName); |
082e5b98 JS |
396 | |
397 | // From MSDN: How To Modify Printer Settings with the DocumentProperties() Function | |
398 | // The purpose of this is to fill the DEVMODE with privdata from printer driver. | |
070d6391 | 399 | // If we have a printer name and OpenPrinter successfully returns |
082e5b98 | 400 | // this replaces the PrintDlg function which creates the DEVMODE filled only with data from default printer. |
6c797d8f | 401 | if ( !m_devMode && !printerName.IsEmpty() ) |
082e5b98 JS |
402 | { |
403 | // Open printer | |
6c797d8f | 404 | if ( printer && printer->Open( printerName ) == TRUE ) |
082e5b98 JS |
405 | { |
406 | DWORD dwNeeded, dwRet; | |
407 | ||
408 | // Step 1: | |
409 | // Allocate a buffer of the correct size. | |
410 | dwNeeded = DocumentProperties( NULL, | |
b98b75cd | 411 | *printer, // Handle to our printer. |
082e5b98 JS |
412 | szPrinterName, // Name of the printer. |
413 | NULL, // Asking for size, so | |
414 | NULL, // these are not used. | |
415 | 0 ); // Zero returns buffer size. | |
416 | ||
417 | LPDEVMODE tempDevMode = static_cast<LPDEVMODE>( GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, dwNeeded ) ); | |
418 | ||
419 | // Step 2: | |
420 | // Get the default DevMode for the printer | |
421 | dwRet = DocumentProperties( NULL, | |
b98b75cd | 422 | *printer, |
082e5b98 JS |
423 | szPrinterName, |
424 | tempDevMode, // The address of the buffer to fill. | |
425 | NULL, // Not using the input buffer. | |
426 | DM_OUT_BUFFER ); // Have the output buffer filled. | |
427 | ||
428 | if ( dwRet != IDOK ) | |
429 | { | |
430 | // If failure, cleanup | |
431 | GlobalFree( tempDevMode ); | |
6c797d8f | 432 | printer->Close(); |
082e5b98 JS |
433 | } |
434 | else | |
435 | { | |
6c797d8f | 436 | m_devMode = tempDevMode; |
082e5b98 JS |
437 | tempDevMode = NULL; |
438 | } | |
439 | } | |
440 | } | |
441 | ||
dca0f651 | 442 | if ( !m_devMode ) |
8850cbd3 RR |
443 | { |
444 | // Use PRINTDLG as a way of creating a DEVMODE object | |
445 | PRINTDLG pd; | |
446 | ||
8850cbd3 RR |
447 | memset(&pd, 0, sizeof(PRINTDLG)); |
448 | #ifdef __WXWINCE__ | |
449 | pd.cbStruct = sizeof(PRINTDLG); | |
450 | #else | |
451 | pd.lStructSize = sizeof(PRINTDLG); | |
8850cbd3 RR |
452 | #endif |
453 | ||
bd84061d | 454 | pd.hwndOwner = NULL; |
8850cbd3 RR |
455 | pd.hDevMode = NULL; // Will be created by PrintDlg |
456 | pd.hDevNames = NULL; // Ditto | |
8850cbd3 RR |
457 | |
458 | pd.Flags = PD_RETURNDEFAULT; | |
459 | pd.nCopies = 1; | |
460 | ||
461 | // Fill out the DEVMODE structure | |
462 | // so we can use it as input in the 'real' PrintDlg | |
463 | if (!PrintDlg(&pd)) | |
464 | { | |
465 | if ( pd.hDevMode ) | |
466 | GlobalFree(pd.hDevMode); | |
467 | if ( pd.hDevNames ) | |
468 | GlobalFree(pd.hDevNames); | |
469 | pd.hDevMode = NULL; | |
470 | pd.hDevNames = NULL; | |
471 | ||
113f4def | 472 | #if wxDEBUG_LEVEL |
4b6a582b | 473 | wxLogDebug(wxT("Printing error: ") + wxGetPrintDlgError()); |
d021f94f | 474 | #endif // wxDEBUG_LEVEL |
8850cbd3 RR |
475 | } |
476 | else | |
477 | { | |
6c797d8f | 478 | m_devMode = pd.hDevMode; |
8850cbd3 RR |
479 | pd.hDevMode = NULL; |
480 | ||
481 | // We'll create a new DEVNAMEs structure below. | |
482 | if ( pd.hDevNames ) | |
483 | GlobalFree(pd.hDevNames); | |
484 | pd.hDevNames = NULL; | |
485 | ||
486 | // hDevNames = pd->hDevNames; | |
487 | // m_devNames = (void*)(long) hDevNames; | |
488 | // pd->hDevnames = NULL; | |
489 | ||
490 | } | |
491 | } | |
492 | ||
6c797d8f RD |
493 | } |
494 | ||
495 | bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data ) | |
496 | { | |
497 | WinPrinter printer; | |
017dc06b | 498 | LPTSTR szPrinterName = wxMSW_CONV_LPTSTR(data.GetPrinterName()); |
6c797d8f RD |
499 | |
500 | if (!m_devMode) | |
501 | InitializeDevMode(data.GetPrinterName(), &printer); | |
502 | ||
503 | HGLOBAL hDevMode = static_cast<HGLOBAL>(m_devMode); | |
504 | ||
8850cbd3 RR |
505 | if ( hDevMode ) |
506 | { | |
dca0f651 | 507 | GlobalPtrLock lockDevMode(hDevMode); |
5c33522f | 508 | DEVMODE * const devMode = static_cast<DEVMODE *>(lockDevMode.Get()); |
8850cbd3 RR |
509 | |
510 | //// Orientation | |
511 | devMode->dmOrientation = (short)data.GetOrientation(); | |
512 | ||
513 | //// Collation | |
514 | devMode->dmCollate = (data.GetCollate() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE); | |
515 | devMode->dmFields |= DM_COLLATE; | |
516 | ||
517 | //// Number of copies | |
518 | devMode->dmCopies = (short)data.GetNoCopies(); | |
519 | devMode->dmFields |= DM_COPIES; | |
520 | ||
521 | //// Printer name | |
522 | wxString name = data.GetPrinterName(); | |
f31a4098 | 523 | if (!name.empty()) |
8850cbd3 | 524 | { |
47af39fb VZ |
525 | // NB: the cast is needed in the ANSI build, strangely enough |
526 | // dmDeviceName is BYTE[] and not char[] there | |
e408bf52 | 527 | wxStrlcpy(reinterpret_cast<wxChar *>(devMode->dmDeviceName), |
017dc06b | 528 | name.t_str(), |
e408bf52 | 529 | WXSIZEOF(devMode->dmDeviceName)); |
8850cbd3 RR |
530 | } |
531 | ||
532 | //// Colour | |
533 | if (data.GetColour()) | |
534 | devMode->dmColor = DMCOLOR_COLOR; | |
535 | else | |
536 | devMode->dmColor = DMCOLOR_MONOCHROME; | |
537 | devMode->dmFields |= DM_COLOR; | |
538 | ||
539 | //// Paper size | |
d5eaa19f VZ |
540 | |
541 | // Paper id has priority over paper size. If id is specified, then size | |
542 | // is ignored (as it can be filled in even for standard paper sizes) | |
543 | ||
544 | wxPrintPaperType *paperType = NULL; | |
545 | ||
546 | const wxPaperSize paperId = data.GetPaperId(); | |
547 | if ( paperId != wxPAPER_NONE && wxThePrintPaperDatabase ) | |
8850cbd3 | 548 | { |
d5eaa19f | 549 | paperType = wxThePrintPaperDatabase->FindPaperType(paperId); |
8850cbd3 | 550 | } |
d5eaa19f VZ |
551 | |
552 | if ( paperType ) | |
8850cbd3 | 553 | { |
d5eaa19f VZ |
554 | devMode->dmPaperSize = (short)paperType->GetPlatformId(); |
555 | devMode->dmFields |= DM_PAPERSIZE; | |
556 | } | |
557 | else // custom (or no) paper size | |
558 | { | |
559 | const wxSize paperSize = data.GetPaperSize(); | |
560 | if ( paperSize != wxDefaultSize ) | |
8850cbd3 | 561 | { |
d5eaa19f VZ |
562 | // Fall back on specifying the paper size explicitly |
563 | if(m_customWindowsPaperId != 0) | |
564 | devMode->dmPaperSize = m_customWindowsPaperId; | |
21c358b2 | 565 | else |
21c358b2 | 566 | devMode->dmPaperSize = DMPAPER_USER; |
d5eaa19f VZ |
567 | devMode->dmPaperWidth = (short)(paperSize.x * 10); |
568 | devMode->dmPaperLength = (short)(paperSize.y * 10); | |
569 | devMode->dmFields |= DM_PAPERWIDTH; | |
570 | devMode->dmFields |= DM_PAPERLENGTH; | |
3c46da42 JS |
571 | |
572 | // A printer driver may or may not also want DM_PAPERSIZE to | |
573 | // be specified. Also, if the printer driver doesn't implement the DMPAPER_USER | |
574 | // size, then this won't work, and even if you found the correct id by | |
575 | // enumerating the driver's paper sizes, it probably won't change the actual size, | |
576 | // it'll just select that custom paper type with its own current setting. | |
577 | // For a discussion on this, see http://www.codeguru.com/forum/showthread.php?threadid=458617 | |
578 | // Although m_customWindowsPaperId is intended to work around this, it's | |
579 | // unclear how it can help you set the custom paper size programmatically. | |
8850cbd3 | 580 | } |
d5eaa19f VZ |
581 | //else: neither paper type nor size specified, don't fill DEVMODE |
582 | // at all so that the system defaults are used | |
8850cbd3 RR |
583 | } |
584 | ||
585 | //// Duplex | |
586 | short duplex; | |
587 | switch (data.GetDuplex()) | |
588 | { | |
589 | case wxDUPLEX_HORIZONTAL: | |
590 | duplex = DMDUP_HORIZONTAL; | |
591 | break; | |
592 | case wxDUPLEX_VERTICAL: | |
593 | duplex = DMDUP_VERTICAL; | |
594 | break; | |
595 | default: | |
596 | // in fact case wxDUPLEX_SIMPLEX: | |
597 | duplex = DMDUP_SIMPLEX; | |
598 | break; | |
599 | } | |
600 | devMode->dmDuplex = duplex; | |
601 | devMode->dmFields |= DM_DUPLEX; | |
602 | ||
603 | //// Quality | |
604 | ||
605 | short quality; | |
606 | switch (data.GetQuality()) | |
607 | { | |
608 | case wxPRINT_QUALITY_MEDIUM: | |
609 | quality = DMRES_MEDIUM; | |
610 | break; | |
611 | case wxPRINT_QUALITY_LOW: | |
612 | quality = DMRES_LOW; | |
613 | break; | |
614 | case wxPRINT_QUALITY_DRAFT: | |
615 | quality = DMRES_DRAFT; | |
616 | break; | |
617 | case wxPRINT_QUALITY_HIGH: | |
618 | quality = DMRES_HIGH; | |
619 | break; | |
620 | default: | |
621 | quality = (short)data.GetQuality(); | |
082e5b98 JS |
622 | devMode->dmYResolution = quality; |
623 | devMode->dmFields |= DM_YRESOLUTION; | |
8850cbd3 RR |
624 | break; |
625 | } | |
626 | devMode->dmPrintQuality = quality; | |
627 | devMode->dmFields |= DM_PRINTQUALITY; | |
4e22a1f2 | 628 | |
aa96f01c RR |
629 | if (data.GetPrivDataLen() > 0) |
630 | { | |
631 | memcpy( (char *)devMode+devMode->dmSize, data.GetPrivData(), data.GetPrivDataLen() ); | |
4e22a1f2 | 632 | devMode->dmDriverExtra = (WXWORD)data.GetPrivDataLen(); |
aa96f01c | 633 | } |
8850cbd3 RR |
634 | |
635 | if (data.GetBin() != wxPRINTBIN_DEFAULT) | |
636 | { | |
637 | switch (data.GetBin()) | |
638 | { | |
639 | case wxPRINTBIN_ONLYONE: devMode->dmDefaultSource = DMBIN_ONLYONE; break; | |
640 | case wxPRINTBIN_LOWER: devMode->dmDefaultSource = DMBIN_LOWER; break; | |
641 | case wxPRINTBIN_MIDDLE: devMode->dmDefaultSource = DMBIN_MIDDLE; break; | |
642 | case wxPRINTBIN_MANUAL: devMode->dmDefaultSource = DMBIN_MANUAL; break; | |
643 | case wxPRINTBIN_ENVELOPE: devMode->dmDefaultSource = DMBIN_ENVELOPE; break; | |
644 | case wxPRINTBIN_ENVMANUAL: devMode->dmDefaultSource = DMBIN_ENVMANUAL; break; | |
645 | case wxPRINTBIN_AUTO: devMode->dmDefaultSource = DMBIN_AUTO; break; | |
646 | case wxPRINTBIN_TRACTOR: devMode->dmDefaultSource = DMBIN_TRACTOR; break; | |
647 | case wxPRINTBIN_SMALLFMT: devMode->dmDefaultSource = DMBIN_SMALLFMT; break; | |
648 | case wxPRINTBIN_LARGEFMT: devMode->dmDefaultSource = DMBIN_LARGEFMT; break; | |
649 | case wxPRINTBIN_LARGECAPACITY: devMode->dmDefaultSource = DMBIN_LARGECAPACITY; break; | |
650 | case wxPRINTBIN_CASSETTE: devMode->dmDefaultSource = DMBIN_CASSETTE; break; | |
651 | case wxPRINTBIN_FORMSOURCE: devMode->dmDefaultSource = DMBIN_FORMSOURCE; break; | |
652 | ||
653 | default: | |
fde05480 | 654 | devMode->dmDefaultSource = (short)(DMBIN_USER + data.GetBin() - wxPRINTBIN_USER); // 256 + data.GetBin() - 14 = 242 + data.GetBin() |
8850cbd3 RR |
655 | break; |
656 | } | |
657 | ||
658 | devMode->dmFields |= DM_DEFAULTSOURCE; | |
659 | } | |
781609f2 JS |
660 | if (data.GetMedia() != wxPRINTMEDIA_DEFAULT) |
661 | { | |
662 | devMode->dmMediaType = data.GetMedia(); | |
663 | devMode->dmFields |= DM_MEDIATYPE; | |
664 | } | |
082e5b98 JS |
665 | |
666 | if( printer ) | |
667 | { | |
668 | // Step 3: | |
669 | // Merge the new settings with the old. | |
670 | // This gives the driver an opportunity to update any private | |
671 | // portions of the DevMode structure. | |
672 | DocumentProperties( NULL, | |
673 | printer, | |
674 | szPrinterName, | |
675 | (LPDEVMODE)hDevMode, // Reuse our buffer for output. | |
676 | (LPDEVMODE)hDevMode, // Pass the driver our changes | |
677 | DM_IN_BUFFER | // Commands to Merge our changes and | |
678 | DM_OUT_BUFFER ); // write the result. | |
679 | } | |
8850cbd3 RR |
680 | } |
681 | ||
dca0f651 | 682 | if ( m_devNames ) |
8850cbd3 | 683 | { |
5c33522f | 684 | ::GlobalFree(static_cast<HGLOBAL>(m_devNames)); |
8850cbd3 RR |
685 | } |
686 | ||
687 | // TODO: I hope it's OK to pass some empty strings to DEVNAMES. | |
dca0f651 | 688 | m_devNames = wxCreateDevNames(wxEmptyString, data.GetPrinterName(), wxEmptyString); |
f31a4098 | 689 | |
8850cbd3 RR |
690 | return true; |
691 | } | |
f31a4098 | 692 | |
103aec29 VZ |
693 | // --------------------------------------------------------------------------- |
694 | // wxPrintDialog | |
695 | // --------------------------------------------------------------------------- | |
696 | ||
c061373d | 697 | IMPLEMENT_CLASS(wxWindowsPrintDialog, wxPrintDialogBase) |
2bda0e17 | 698 | |
c061373d | 699 | wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow *p, wxPrintDialogData* data) |
2bda0e17 | 700 | { |
7bcb11d3 | 701 | Create(p, data); |
2bda0e17 KB |
702 | } |
703 | ||
c061373d | 704 | wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow *p, wxPrintData* data) |
103aec29 VZ |
705 | { |
706 | wxPrintDialogData data2; | |
707 | if ( data ) | |
708 | data2 = *data; | |
709 | ||
710 | Create(p, &data2); | |
711 | } | |
712 | ||
c061373d | 713 | bool wxWindowsPrintDialog::Create(wxWindow *p, wxPrintDialogData* data) |
2bda0e17 | 714 | { |
7bcb11d3 JS |
715 | m_dialogParent = p; |
716 | m_printerDC = NULL; | |
078cf5cb | 717 | m_destroyDC = true; |
7bcb11d3 | 718 | |
93c2f401 RR |
719 | // MSW handle |
720 | m_printDlg = NULL; | |
f31a4098 | 721 | |
7bcb11d3 JS |
722 | if ( data ) |
723 | m_printDialogData = *data; | |
103aec29 | 724 | |
078cf5cb | 725 | return true; |
2bda0e17 KB |
726 | } |
727 | ||
c061373d | 728 | wxWindowsPrintDialog::~wxWindowsPrintDialog() |
2bda0e17 | 729 | { |
93c2f401 RR |
730 | PRINTDLG *pd = (PRINTDLG *) m_printDlg; |
731 | if (pd && pd->hDevMode) | |
732 | GlobalFree(pd->hDevMode); | |
733 | if ( pd ) | |
734 | delete pd; | |
735 | ||
7bcb11d3 JS |
736 | if (m_destroyDC && m_printerDC) |
737 | delete m_printerDC; | |
2bda0e17 KB |
738 | } |
739 | ||
c061373d | 740 | int wxWindowsPrintDialog::ShowModal() |
2bda0e17 | 741 | { |
643e9cf9 VS |
742 | WX_TESTING_SHOW_MODAL_HOOK(); |
743 | ||
93c2f401 | 744 | ConvertToNative( m_printDialogData ); |
103aec29 | 745 | |
93c2f401 | 746 | PRINTDLG *pd = (PRINTDLG*) m_printDlg; |
f31a4098 | 747 | |
f6bcfd97 | 748 | if (m_dialogParent) |
93c2f401 | 749 | pd->hwndOwner = (HWND) m_dialogParent->GetHWND(); |
f6bcfd97 | 750 | else if (wxTheApp->GetTopWindow()) |
93c2f401 | 751 | pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND(); |
f6bcfd97 | 752 | else |
93c2f401 | 753 | pd->hwndOwner = 0; |
f6bcfd97 | 754 | |
93c2f401 | 755 | bool ret = (PrintDlg( pd ) != 0); |
f6bcfd97 | 756 | |
93c2f401 | 757 | pd->hwndOwner = 0; |
f6bcfd97 | 758 | |
d0ee33f5 | 759 | if ( ret && (pd->hDC) ) |
7bcb11d3 | 760 | { |
888dde65 | 761 | wxPrinterDC *pdc = new wxPrinterDCFromHDC( (WXHDC) pd->hDC ); |
7bcb11d3 | 762 | m_printerDC = pdc; |
93c2f401 | 763 | ConvertFromNative( m_printDialogData ); |
7bcb11d3 JS |
764 | return wxID_OK; |
765 | } | |
766 | else | |
767 | { | |
7bcb11d3 JS |
768 | return wxID_CANCEL; |
769 | } | |
2bda0e17 KB |
770 | } |
771 | ||
c061373d | 772 | wxDC *wxWindowsPrintDialog::GetPrintDC() |
2bda0e17 | 773 | { |
7bcb11d3 JS |
774 | if (m_printerDC) |
775 | { | |
078cf5cb | 776 | m_destroyDC = false; |
7bcb11d3 JS |
777 | return m_printerDC; |
778 | } | |
779 | else | |
bd84061d | 780 | return NULL; |
2bda0e17 KB |
781 | } |
782 | ||
93c2f401 RR |
783 | bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data ) |
784 | { | |
785 | wxWindowsPrintNativeData *native_data = | |
786 | (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); | |
787 | data.GetPrintData().ConvertToNative(); | |
f31a4098 | 788 | |
93c2f401 RR |
789 | PRINTDLG *pd = (PRINTDLG*) m_printDlg; |
790 | ||
791 | // Shouldn't have been defined anywhere | |
792 | if (pd) | |
793 | return false; | |
f31a4098 | 794 | |
93c2f401 RR |
795 | pd = new PRINTDLG; |
796 | memset( pd, 0, sizeof(PRINTDLG) ); | |
797 | m_printDlg = (void*) pd; | |
798 | ||
93c2f401 | 799 | pd->lStructSize = sizeof(PRINTDLG); |
bd84061d | 800 | pd->hwndOwner = NULL; |
93c2f401 RR |
801 | pd->hDevMode = NULL; // Will be created by PrintDlg |
802 | pd->hDevNames = NULL; // Ditto | |
803 | ||
804 | pd->Flags = PD_RETURNDEFAULT; | |
805 | pd->nCopies = 1; | |
f31a4098 | 806 | |
93c2f401 RR |
807 | // Pass the devmode data to the PRINTDLG structure, since it'll |
808 | // be needed when PrintDlg is called. | |
809 | if (pd->hDevMode) | |
810 | GlobalFree(pd->hDevMode); | |
811 | ||
812 | // Pass the devnames data to the PRINTDLG structure, since it'll | |
813 | // be needed when PrintDlg is called. | |
814 | if (pd->hDevNames) | |
815 | GlobalFree(pd->hDevNames); | |
816 | ||
5c33522f | 817 | pd->hDevMode = static_cast<HGLOBAL>(native_data->GetDevMode()); |
dca0f651 | 818 | native_data->SetDevMode(NULL); |
93c2f401 RR |
819 | |
820 | // Shouldn't assert; we should be able to test Ok-ness at a higher level | |
821 | //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
822 | ||
5c33522f | 823 | pd->hDevNames = static_cast<HGLOBAL>(native_data->GetDevNames()); |
dca0f651 | 824 | native_data->SetDevNames(NULL); |
93c2f401 RR |
825 | |
826 | ||
bd84061d | 827 | pd->hDC = NULL; |
93c2f401 RR |
828 | pd->nFromPage = (WORD)data.GetFromPage(); |
829 | pd->nToPage = (WORD)data.GetToPage(); | |
830 | pd->nMinPage = (WORD)data.GetMinPage(); | |
831 | pd->nMaxPage = (WORD)data.GetMaxPage(); | |
832 | pd->nCopies = (WORD)data.GetNoCopies(); | |
833 | ||
834 | pd->Flags = PD_RETURNDC; | |
93c2f401 | 835 | pd->lStructSize = sizeof( PRINTDLG ); |
93c2f401 | 836 | |
bd84061d VZ |
837 | pd->hwndOwner = NULL; |
838 | pd->hInstance = NULL; | |
312242ea | 839 | pd->lCustData = 0; |
93c2f401 RR |
840 | pd->lpfnPrintHook = NULL; |
841 | pd->lpfnSetupHook = NULL; | |
842 | pd->lpPrintTemplateName = NULL; | |
843 | pd->lpSetupTemplateName = NULL; | |
bd84061d VZ |
844 | pd->hPrintTemplate = NULL; |
845 | pd->hSetupTemplate = NULL; | |
93c2f401 RR |
846 | |
847 | if ( data.GetAllPages() ) | |
848 | pd->Flags |= PD_ALLPAGES; | |
849 | if ( data.GetSelection() ) | |
850 | pd->Flags |= PD_SELECTION; | |
851 | if ( data.GetCollate() ) | |
852 | pd->Flags |= PD_COLLATE; | |
853 | if ( data.GetPrintToFile() ) | |
854 | pd->Flags |= PD_PRINTTOFILE; | |
855 | if ( !data.GetEnablePrintToFile() ) | |
856 | pd->Flags |= PD_DISABLEPRINTTOFILE; | |
857 | if ( !data.GetEnableSelection() ) | |
858 | pd->Flags |= PD_NOSELECTION; | |
859 | if ( !data.GetEnablePageNumbers() ) | |
860 | pd->Flags |= PD_NOPAGENUMS; | |
861 | else if ( (!data.GetAllPages()) && (!data.GetSelection()) && (data.GetFromPage() != 0) && (data.GetToPage() != 0)) | |
862 | pd->Flags |= PD_PAGENUMS; | |
863 | if ( data.GetEnableHelp() ) | |
864 | pd->Flags |= PD_SHOWHELP; | |
f31a4098 | 865 | |
93c2f401 RR |
866 | return true; |
867 | } | |
868 | ||
869 | bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData &data ) | |
870 | { | |
871 | PRINTDLG *pd = (PRINTDLG*) m_printDlg; | |
872 | if ( pd == NULL ) | |
873 | return false; | |
874 | ||
875 | wxWindowsPrintNativeData *native_data = | |
876 | (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); | |
f31a4098 | 877 | |
93c2f401 RR |
878 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
879 | if (pd->hDevMode) | |
880 | { | |
881 | if (native_data->GetDevMode()) | |
882 | { | |
5c33522f | 883 | ::GlobalFree(static_cast<HGLOBAL>(native_data->GetDevMode())); |
93c2f401 | 884 | } |
dca0f651 | 885 | native_data->SetDevMode(pd->hDevMode); |
93c2f401 RR |
886 | pd->hDevMode = NULL; |
887 | } | |
888 | ||
889 | // Pass the devnames data back to the wxPrintData structure where it really belongs. | |
890 | if (pd->hDevNames) | |
891 | { | |
892 | if (native_data->GetDevNames()) | |
893 | { | |
5c33522f | 894 | ::GlobalFree(static_cast<HGLOBAL>(native_data->GetDevNames())); |
93c2f401 | 895 | } |
dca0f651 | 896 | native_data->SetDevNames(pd->hDevNames); |
93c2f401 RR |
897 | pd->hDevNames = NULL; |
898 | } | |
899 | ||
900 | // Now convert the DEVMODE object, passed down from the PRINTDLG object, | |
901 | // into wxWidgets form. | |
902 | native_data->TransferTo( data.GetPrintData() ); | |
903 | ||
904 | data.SetFromPage( pd->nFromPage ); | |
905 | data.SetToPage( pd->nToPage ); | |
906 | data.SetMinPage( pd->nMinPage ); | |
907 | data.SetMaxPage( pd->nMaxPage ); | |
908 | data.SetNoCopies( pd->nCopies ); | |
909 | ||
910 | data.SetAllPages( (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION)) ); | |
911 | data.SetSelection( ((pd->Flags & PD_SELECTION) == PD_SELECTION) ); | |
912 | data.SetCollate( ((pd->Flags & PD_COLLATE) == PD_COLLATE) ); | |
913 | data.SetPrintToFile( ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE) ); | |
914 | data.EnablePrintToFile( ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE) ); | |
915 | data.EnableSelection( ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION) ); | |
916 | data.EnablePageNumbers( ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS) ); | |
917 | data.EnableHelp( ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP) ); | |
c1dc9f83 | 918 | |
93c2f401 RR |
919 | return true; |
920 | } | |
921 | ||
103aec29 | 922 | // --------------------------------------------------------------------------- |
08680429 | 923 | // wxWidnowsPageSetupDialog |
103aec29 | 924 | // --------------------------------------------------------------------------- |
2bda0e17 | 925 | |
08680429 | 926 | IMPLEMENT_CLASS(wxWindowsPageSetupDialog, wxPageSetupDialogBase) |
c061373d | 927 | |
08680429 | 928 | wxWindowsPageSetupDialog::wxWindowsPageSetupDialog() |
2bda0e17 | 929 | { |
7bcb11d3 | 930 | m_dialogParent = NULL; |
b45dfd0a | 931 | m_pageDlg = NULL; |
2bda0e17 KB |
932 | } |
933 | ||
08680429 | 934 | wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow *p, wxPageSetupDialogData *data) |
2bda0e17 | 935 | { |
7bcb11d3 | 936 | Create(p, data); |
2bda0e17 KB |
937 | } |
938 | ||
08680429 | 939 | bool wxWindowsPageSetupDialog::Create(wxWindow *p, wxPageSetupDialogData *data) |
2bda0e17 | 940 | { |
7bcb11d3 | 941 | m_dialogParent = p; |
b45dfd0a | 942 | m_pageDlg = NULL; |
103aec29 | 943 | |
7bcb11d3 JS |
944 | if (data) |
945 | m_pageSetupData = (*data); | |
103aec29 | 946 | |
078cf5cb | 947 | return true; |
2bda0e17 KB |
948 | } |
949 | ||
08680429 | 950 | wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog() |
2bda0e17 | 951 | { |
b45dfd0a RR |
952 | PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageDlg; |
953 | if ( pd && pd->hDevMode ) | |
954 | GlobalFree(pd->hDevMode); | |
955 | if ( pd && pd->hDevNames ) | |
956 | GlobalFree(pd->hDevNames); | |
957 | if ( pd ) | |
958 | delete pd; | |
2bda0e17 KB |
959 | } |
960 | ||
08680429 | 961 | int wxWindowsPageSetupDialog::ShowModal() |
2bda0e17 | 962 | { |
643e9cf9 VS |
963 | WX_TESTING_SHOW_MODAL_HOOK(); |
964 | ||
b45dfd0a | 965 | ConvertToNative( m_pageSetupData ); |
f31a4098 | 966 | |
b45dfd0a | 967 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageDlg; |
f6bcfd97 | 968 | if (m_dialogParent) |
b45dfd0a | 969 | pd->hwndOwner = (HWND) m_dialogParent->GetHWND(); |
f6bcfd97 | 970 | else if (wxTheApp->GetTopWindow()) |
b45dfd0a | 971 | pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND(); |
f6bcfd97 | 972 | else |
b45dfd0a RR |
973 | pd->hwndOwner = 0; |
974 | BOOL retVal = PageSetupDlg( pd ) ; | |
975 | pd->hwndOwner = 0; | |
f6bcfd97 | 976 | if (retVal) |
2bda0e17 | 977 | { |
b45dfd0a | 978 | ConvertFromNative( m_pageSetupData ); |
7bcb11d3 | 979 | return wxID_OK; |
2bda0e17 KB |
980 | } |
981 | else | |
7bcb11d3 | 982 | return wxID_CANCEL; |
b45dfd0a RR |
983 | } |
984 | ||
08680429 | 985 | bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData &data ) |
b45dfd0a RR |
986 | { |
987 | wxWindowsPrintNativeData *native_data = | |
988 | (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); | |
989 | data.GetPrintData().ConvertToNative(); | |
990 | ||
991 | PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageDlg; | |
992 | ||
993 | // Shouldn't have been defined anywhere | |
994 | if (pd) | |
995 | return false; | |
f31a4098 | 996 | |
b45dfd0a | 997 | pd = new PAGESETUPDLG; |
b45dfd0a RR |
998 | m_pageDlg = (void *)pd; |
999 | ||
fd76344e VZ |
1000 | // We must not set hDevMode and hDevNames when using PSD_RETURNDEFAULT, |
1001 | // otherwise the call to PageSetupDlg() would fail. | |
1002 | if ( data.GetDefaultInfo() ) | |
b45dfd0a | 1003 | { |
b45dfd0a | 1004 | pd->hDevMode = NULL; |
fd76344e | 1005 | pd->hDevNames = NULL; |
b45dfd0a | 1006 | } |
fd76344e VZ |
1007 | else |
1008 | { | |
1009 | // Pass the devmode data (created in m_printData.ConvertToNative) | |
1010 | // to the PRINTDLG structure, since it'll | |
1011 | // be needed when PrintDlg is called. | |
b45dfd0a | 1012 | |
fd76344e VZ |
1013 | pd->hDevMode = (HGLOBAL) native_data->GetDevMode(); |
1014 | native_data->SetDevMode(NULL); | |
b45dfd0a | 1015 | |
fd76344e VZ |
1016 | // Shouldn't assert; we should be able to test Ok-ness at a higher level |
1017 | //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
b45dfd0a | 1018 | |
fd76344e VZ |
1019 | // Pass the devnames data (created in m_printData.ConvertToNative) |
1020 | // to the PRINTDLG structure, since it'll | |
1021 | // be needed when PrintDlg is called. | |
b45dfd0a | 1022 | |
fd76344e VZ |
1023 | pd->hDevNames = (HGLOBAL) native_data->GetDevNames(); |
1024 | native_data->SetDevNames(NULL); | |
1025 | } | |
b45dfd0a RR |
1026 | |
1027 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; | |
1028 | ||
1029 | if ( data.GetDefaultMinMargins() ) | |
1030 | pd->Flags |= PSD_DEFAULTMINMARGINS; | |
1031 | if ( !data.GetEnableMargins() ) | |
1032 | pd->Flags |= PSD_DISABLEMARGINS; | |
1033 | if ( !data.GetEnableOrientation() ) | |
1034 | pd->Flags |= PSD_DISABLEORIENTATION; | |
1035 | if ( !data.GetEnablePaper() ) | |
1036 | pd->Flags |= PSD_DISABLEPAPER; | |
1037 | if ( !data.GetEnablePrinter() ) | |
1038 | pd->Flags |= PSD_DISABLEPRINTER; | |
1039 | if ( data.GetDefaultInfo() ) | |
1040 | pd->Flags |= PSD_RETURNDEFAULT; | |
1041 | if ( data.GetEnableHelp() ) | |
1042 | pd->Flags |= PSD_SHOWHELP; | |
1043 | ||
1044 | // We want the units to be in hundredths of a millimetre | |
1045 | pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS; | |
1046 | ||
1047 | pd->lStructSize = sizeof( PAGESETUPDLG ); | |
bd84061d VZ |
1048 | pd->hwndOwner = NULL; |
1049 | pd->hInstance = NULL; | |
b45dfd0a RR |
1050 | // PAGESETUPDLG is in hundreds of a mm |
1051 | pd->ptPaperSize.x = data.GetPaperSize().x * 100; | |
1052 | pd->ptPaperSize.y = data.GetPaperSize().y * 100; | |
1053 | ||
1054 | pd->rtMinMargin.left = data.GetMinMarginTopLeft().x * 100; | |
1055 | pd->rtMinMargin.top = data.GetMinMarginTopLeft().y * 100; | |
1056 | pd->rtMinMargin.right = data.GetMinMarginBottomRight().x * 100; | |
1057 | pd->rtMinMargin.bottom = data.GetMinMarginBottomRight().y * 100; | |
1058 | ||
1059 | pd->rtMargin.left = data.GetMarginTopLeft().x * 100; | |
1060 | pd->rtMargin.top = data.GetMarginTopLeft().y * 100; | |
1061 | pd->rtMargin.right = data.GetMarginBottomRight().x * 100; | |
1062 | pd->rtMargin.bottom = data.GetMarginBottomRight().y * 100; | |
1063 | ||
1064 | pd->lCustData = 0; | |
1065 | pd->lpfnPageSetupHook = NULL; | |
1066 | pd->lpfnPagePaintHook = NULL; | |
1067 | pd->hPageSetupTemplate = NULL; | |
1068 | pd->lpPageSetupTemplateName = NULL; | |
1069 | ||
b45dfd0a RR |
1070 | return true; |
1071 | } | |
1072 | ||
08680429 | 1073 | bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData &data ) |
b45dfd0a RR |
1074 | { |
1075 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageDlg; | |
1076 | if ( !pd ) | |
1077 | return false; | |
1078 | ||
1079 | wxWindowsPrintNativeData *native_data = | |
1080 | (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); | |
f31a4098 | 1081 | |
b45dfd0a RR |
1082 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
1083 | if (pd->hDevMode) | |
1084 | { | |
1085 | if (native_data->GetDevMode()) | |
1086 | { | |
1087 | // Make sure we don't leak memory | |
1088 | GlobalFree((HGLOBAL) native_data->GetDevMode()); | |
1089 | } | |
1090 | native_data->SetDevMode( (void*) pd->hDevMode ); | |
1091 | pd->hDevMode = NULL; | |
1092 | } | |
f31a4098 | 1093 | |
b45dfd0a RR |
1094 | // Isn't this superfluous? It's called again below. |
1095 | // data.GetPrintData().ConvertFromNative(); | |
1096 | ||
1097 | // Pass the devnames data back to the wxPrintData structure where it really belongs. | |
1098 | if (pd->hDevNames) | |
1099 | { | |
1100 | if (native_data->GetDevNames()) | |
1101 | { | |
1102 | // Make sure we don't leak memory | |
1103 | GlobalFree((HGLOBAL) native_data->GetDevNames()); | |
1104 | } | |
1105 | native_data->SetDevNames((void*) pd->hDevNames); | |
1106 | pd->hDevNames = NULL; | |
1107 | } | |
1108 | ||
1109 | data.GetPrintData().ConvertFromNative(); | |
1110 | ||
1111 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; | |
1112 | ||
1113 | data.SetDefaultMinMargins( ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS) ); | |
1114 | data.EnableMargins( ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS) ); | |
1115 | data.EnableOrientation( ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION) ); | |
1116 | data.EnablePaper( ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER) ); | |
1117 | data.EnablePrinter( ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER) ); | |
1118 | data.SetDefaultInfo( ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT) ); | |
1119 | data.EnableHelp( ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP) ); | |
1120 | ||
1121 | // PAGESETUPDLG is in hundreds of a mm | |
fa4f4c58 RR |
1122 | if (data.GetPrintData().GetOrientation() == wxLANDSCAPE) |
1123 | data.SetPaperSize( wxSize(pd->ptPaperSize.y / 100, pd->ptPaperSize.x / 100) ); | |
1124 | else | |
1125 | data.SetPaperSize( wxSize(pd->ptPaperSize.x / 100, pd->ptPaperSize.y / 100) ); | |
b45dfd0a RR |
1126 | |
1127 | data.SetMinMarginTopLeft( wxPoint(pd->rtMinMargin.left / 100, pd->rtMinMargin.top / 100) ); | |
1128 | data.SetMinMarginBottomRight( wxPoint(pd->rtMinMargin.right / 100, pd->rtMinMargin.bottom / 100) ); | |
1129 | ||
1130 | data.SetMarginTopLeft( wxPoint(pd->rtMargin.left / 100, pd->rtMargin.top / 100) ); | |
1131 | data.SetMarginBottomRight( wxPoint(pd->rtMargin.right / 100, pd->rtMargin.bottom / 100) ); | |
f31a4098 | 1132 | |
b45dfd0a | 1133 | return true; |
2bda0e17 KB |
1134 | } |
1135 | ||
f6bcfd97 BP |
1136 | #endif |
1137 | // wxUSE_PRINTING_ARCHITECTURE |