]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: printdlg.cpp | |
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 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
103aec29 | 21 | #pragma implementation "printdlg.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
2bda0e17 KB |
25 | #include "wx/wxprec.h" |
26 | ||
a3b46648 | 27 | #ifdef __BORLANDC__ |
103aec29 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
12bdd77c JS |
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) | |
f6bcfd97 BP |
34 | |
35 | #ifndef WX_PRECOMP | |
36 | #include "wx/app.h" | |
37 | #endif | |
38 | ||
c061373d | 39 | #include "wx/cmndata.h" |
2bda0e17 | 40 | #include "wx/printdlg.h" |
08680429 | 41 | #include "wx/msw/printdlg.h" |
2bda0e17 | 42 | #include "wx/dcprint.h" |
8850cbd3 | 43 | #include "wx/paper.h" |
2bda0e17 | 44 | |
2bda0e17 | 45 | #include <stdlib.h> |
42e69d6b | 46 | |
660296aa | 47 | #include "wx/msw/wrapcdlg.h" |
2bda0e17 KB |
48 | |
49 | #ifndef __WIN32__ | |
103aec29 | 50 | #include <print.h> |
2bda0e17 KB |
51 | #endif |
52 | ||
8850cbd3 RR |
53 | //---------------------------------------------------------------------------- |
54 | // wxWindowsPrintNativeData | |
55 | //---------------------------------------------------------------------------- | |
56 | ||
57 | #ifdef __WXDEBUG__ | |
58 | static wxString wxGetPrintDlgError() | |
59 | { | |
60 | DWORD err = CommDlgExtendedError(); | |
61 | wxString msg = wxT("Unknown"); | |
62 | switch (err) | |
63 | { | |
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; | |
86 | default: break; | |
87 | } | |
88 | return msg; | |
89 | } | |
90 | #endif | |
91 | ||
92 | static HGLOBAL wxCreateDevNames(const wxString& driverName, const wxString& printerName, const wxString& portName) | |
93 | { | |
94 | HGLOBAL hDev = NULL; | |
f31a4098 WS |
95 | // if (!driverName.empty() && !printerName.empty() && !portName.empty()) |
96 | if (driverName.empty() && printerName.empty() && portName.empty()) | |
8850cbd3 RR |
97 | { |
98 | } | |
99 | else | |
100 | { | |
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); | |
108 | ||
109 | lpDev->wDeviceOffset = (WORD)( lpDev->wDriverOffset + | |
110 | driverName.Length() + 1 ); | |
111 | wxStrcpy((wxChar*)lpDev + lpDev->wDeviceOffset, printerName); | |
112 | ||
113 | lpDev->wOutputOffset = (WORD)( lpDev->wDeviceOffset + | |
114 | printerName.Length() + 1 ); | |
115 | wxStrcpy((wxChar*)lpDev + lpDev->wOutputOffset, portName); | |
116 | ||
117 | lpDev->wDefault = 0; | |
118 | ||
119 | GlobalUnlock(hDev); | |
120 | } | |
121 | ||
122 | return hDev; | |
123 | } | |
124 | ||
125 | IMPLEMENT_CLASS(wxWindowsPrintNativeData, wxPrintNativeDataBase) | |
126 | ||
127 | wxWindowsPrintNativeData::wxWindowsPrintNativeData() | |
128 | { | |
129 | m_devMode = (void*) NULL; | |
130 | m_devNames = (void*) NULL; | |
3168b4c3 | 131 | m_customWindowsPaperId = 0; |
8850cbd3 RR |
132 | } |
133 | ||
134 | wxWindowsPrintNativeData::~wxWindowsPrintNativeData() | |
135 | { | |
136 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; | |
137 | if ( hDevMode ) | |
138 | GlobalFree(hDevMode); | |
139 | HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames; | |
140 | if ( hDevNames ) | |
141 | GlobalFree(hDevNames); | |
142 | } | |
143 | ||
144 | bool wxWindowsPrintNativeData::Ok() const | |
145 | { | |
146 | return (m_devMode != NULL) ; | |
147 | } | |
148 | ||
fd64de59 | 149 | bool wxWindowsPrintNativeData::TransferTo( wxPrintData &data ) |
8850cbd3 RR |
150 | { |
151 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; | |
152 | HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames; | |
153 | ||
154 | if (!hDevMode) | |
155 | return false; | |
156 | ||
157 | if ( hDevMode ) | |
158 | { | |
159 | LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode); | |
160 | ||
161 | //// Orientation | |
162 | if (devMode->dmFields & DM_ORIENTATION) | |
163 | data.SetOrientation( devMode->dmOrientation ); | |
164 | ||
165 | //// Collation | |
166 | if (devMode->dmFields & DM_COLLATE) | |
167 | { | |
168 | if (devMode->dmCollate == DMCOLLATE_TRUE) | |
169 | data.SetCollate( true ); | |
170 | else | |
171 | data.SetCollate( false ); | |
172 | } | |
173 | ||
174 | //// Number of copies | |
175 | if (devMode->dmFields & DM_COPIES) | |
176 | data.SetNoCopies( devMode->dmCopies ); | |
177 | ||
178 | if (devMode->dmFields & DM_DEFAULTSOURCE) | |
179 | data.SetBin( (wxPrintBin)devMode->dmDefaultSource ); | |
180 | ||
181 | //// Printer name | |
182 | if (devMode->dmDeviceName[0] != 0) | |
183 | data.SetPrinterName( devMode->dmDeviceName ); | |
184 | ||
185 | //// Colour | |
186 | if (devMode->dmFields & DM_COLOR) | |
187 | { | |
188 | if (devMode->dmColor == DMCOLOR_COLOR) | |
189 | data.SetColour( true ); | |
190 | else | |
191 | data.SetColour( false ); | |
192 | } | |
193 | else | |
194 | data.SetColour( true ); | |
195 | ||
196 | //// Paper size | |
197 | ||
198 | // We don't know size of user defined paper and some buggy drivers | |
199 | // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since | |
200 | // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this | |
201 | // code wouldn't set m_paperSize correctly. | |
21c358b2 JS |
202 | |
203 | bool foundPaperSize = false; | |
8850cbd3 RR |
204 | if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER)) |
205 | { | |
206 | if (wxThePrintPaperDatabase) | |
207 | { | |
208 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize); | |
209 | if (paper) | |
210 | { | |
211 | data.SetPaperId( paper->GetId() ); | |
212 | data.SetPaperSize( wxSize(paper->GetWidth() / 10,paper->GetHeight() / 10) ); | |
3168b4c3 | 213 | m_customWindowsPaperId = 0; |
21c358b2 | 214 | foundPaperSize = true; |
8850cbd3 RR |
215 | } |
216 | } | |
217 | else | |
218 | { | |
219 | // Shouldn't really get here | |
220 | wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative.")); | |
221 | data.SetPaperId( wxPAPER_NONE ); | |
c47addef | 222 | data.SetPaperSize( wxSize(0,0) ); |
3168b4c3 | 223 | m_customWindowsPaperId = 0; |
21c358b2 JS |
224 | |
225 | GlobalUnlock(hDevMode); | |
226 | return false; | |
8850cbd3 RR |
227 | } |
228 | } | |
3168b4c3 | 229 | |
21c358b2 | 230 | if (!foundPaperSize && (devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH)) |
8850cbd3 RR |
231 | { |
232 | // DEVMODE is in tenths of a milimeter | |
8850cbd3 | 233 | data.SetPaperSize( wxSize(devMode->dmPaperWidth / 10, devMode->dmPaperLength / 10) ); |
3168b4c3 JS |
234 | data.SetPaperId( wxPAPER_NONE ); |
235 | m_customWindowsPaperId = devMode->dmPaperSize; | |
8850cbd3 RR |
236 | } |
237 | else | |
238 | { | |
3168b4c3 JS |
239 | // Often will reach this for non-standard paper sizes (sizes which |
240 | // wouldn't be in wxWidget's paper database). Setting | |
241 | // m_customWindowsPaperId to devMode->dmPaperSize should be enough | |
242 | // to get this paper size working. | |
c47addef | 243 | data.SetPaperSize( wxSize(0,0) ); |
3168b4c3 JS |
244 | data.SetPaperId( wxPAPER_NONE ); |
245 | m_customWindowsPaperId = devMode->dmPaperSize; | |
8850cbd3 RR |
246 | } |
247 | ||
248 | //// Duplex | |
249 | ||
250 | if (devMode->dmFields & DM_DUPLEX) | |
251 | { | |
252 | switch (devMode->dmDuplex) | |
253 | { | |
254 | case DMDUP_HORIZONTAL: data.SetDuplex( wxDUPLEX_HORIZONTAL ); break; | |
255 | case DMDUP_VERTICAL: data.SetDuplex( wxDUPLEX_VERTICAL ); break; | |
f31a4098 | 256 | default: |
8850cbd3 RR |
257 | case DMDUP_SIMPLEX: data.SetDuplex( wxDUPLEX_SIMPLEX ); break; |
258 | } | |
259 | } | |
260 | else | |
261 | data.SetDuplex( wxDUPLEX_SIMPLEX ); | |
262 | ||
263 | //// Quality | |
264 | ||
265 | if (devMode->dmFields & DM_PRINTQUALITY) | |
266 | { | |
267 | switch (devMode->dmPrintQuality) | |
268 | { | |
269 | case DMRES_MEDIUM: data.SetQuality( wxPRINT_QUALITY_MEDIUM ); break; | |
270 | case DMRES_LOW: data.SetQuality( wxPRINT_QUALITY_LOW ); break; | |
271 | case DMRES_DRAFT: data.SetQuality( wxPRINT_QUALITY_DRAFT ); break; | |
272 | case DMRES_HIGH: data.SetQuality( wxPRINT_QUALITY_HIGH ); break; | |
273 | default: | |
274 | { | |
275 | // TODO: if the printer fills in the resolution in DPI, how | |
276 | // will the application know if it's high, low, draft etc.?? | |
277 | // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values."); | |
278 | data.SetQuality( devMode->dmPrintQuality ); | |
279 | break; | |
280 | ||
281 | } | |
282 | } | |
283 | } | |
284 | else | |
285 | data.SetQuality( wxPRINT_QUALITY_HIGH ); | |
286 | ||
aa96f01c RR |
287 | if (devMode->dmDriverExtra > 0) |
288 | data.SetPrivData( (char *)devMode+devMode->dmSize, devMode->dmDriverExtra ); | |
289 | else | |
290 | data.SetPrivData( NULL, 0 ); | |
291 | ||
8850cbd3 RR |
292 | GlobalUnlock(hDevMode); |
293 | } | |
294 | ||
295 | if (hDevNames) | |
296 | { | |
297 | LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames); | |
298 | if (lpDevNames) | |
299 | { | |
300 | // TODO: Unicode-ification | |
301 | ||
302 | // Get the port name | |
303 | // port is obsolete in WIN32 | |
304 | // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset); | |
305 | ||
306 | // Get the printer name | |
307 | wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
308 | ||
309 | // Not sure if we should check for this mismatch | |
660296aa | 310 | // wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); |
8850cbd3 | 311 | |
f31a4098 | 312 | if (!printerName.empty()) |
8850cbd3 RR |
313 | data.SetPrinterName( printerName ); |
314 | ||
315 | GlobalUnlock(hDevNames); | |
316 | } | |
317 | } | |
f31a4098 | 318 | |
8850cbd3 RR |
319 | return true; |
320 | } | |
321 | ||
fd64de59 | 322 | bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data ) |
8850cbd3 RR |
323 | { |
324 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; | |
325 | HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames; | |
326 | if (!hDevMode) | |
327 | { | |
328 | // Use PRINTDLG as a way of creating a DEVMODE object | |
329 | PRINTDLG pd; | |
330 | ||
331 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. | |
332 | #ifdef __GNUWIN32__ | |
333 | memset(&pd, 0, 66); | |
334 | pd.lStructSize = 66; | |
335 | #else | |
336 | memset(&pd, 0, sizeof(PRINTDLG)); | |
337 | #ifdef __WXWINCE__ | |
338 | pd.cbStruct = sizeof(PRINTDLG); | |
339 | #else | |
340 | pd.lStructSize = sizeof(PRINTDLG); | |
341 | #endif | |
342 | #endif | |
343 | ||
344 | pd.hwndOwner = (HWND)NULL; | |
345 | pd.hDevMode = NULL; // Will be created by PrintDlg | |
346 | pd.hDevNames = NULL; // Ditto | |
347 | //pd.hInstance = (HINSTANCE) wxGetInstance(); | |
348 | ||
349 | pd.Flags = PD_RETURNDEFAULT; | |
350 | pd.nCopies = 1; | |
351 | ||
352 | // Fill out the DEVMODE structure | |
353 | // so we can use it as input in the 'real' PrintDlg | |
354 | if (!PrintDlg(&pd)) | |
355 | { | |
356 | if ( pd.hDevMode ) | |
357 | GlobalFree(pd.hDevMode); | |
358 | if ( pd.hDevNames ) | |
359 | GlobalFree(pd.hDevNames); | |
360 | pd.hDevMode = NULL; | |
361 | pd.hDevNames = NULL; | |
362 | ||
363 | #if defined(__WXDEBUG__) && defined(__WIN32__) | |
364 | wxString str(wxT("Printing error: ")); | |
365 | str += wxGetPrintDlgError(); | |
366 | wxLogDebug(str); | |
367 | #endif | |
368 | } | |
369 | else | |
370 | { | |
371 | hDevMode = pd.hDevMode; | |
372 | m_devMode = (void*)(long) hDevMode; | |
373 | pd.hDevMode = NULL; | |
374 | ||
375 | // We'll create a new DEVNAMEs structure below. | |
376 | if ( pd.hDevNames ) | |
377 | GlobalFree(pd.hDevNames); | |
378 | pd.hDevNames = NULL; | |
379 | ||
380 | // hDevNames = pd->hDevNames; | |
381 | // m_devNames = (void*)(long) hDevNames; | |
382 | // pd->hDevnames = NULL; | |
383 | ||
384 | } | |
385 | } | |
386 | ||
387 | if ( hDevMode ) | |
388 | { | |
389 | LPDEVMODE devMode = (LPDEVMODE) GlobalLock(hDevMode); | |
390 | ||
391 | //// Orientation | |
392 | devMode->dmOrientation = (short)data.GetOrientation(); | |
393 | ||
394 | //// Collation | |
395 | devMode->dmCollate = (data.GetCollate() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE); | |
396 | devMode->dmFields |= DM_COLLATE; | |
397 | ||
398 | //// Number of copies | |
399 | devMode->dmCopies = (short)data.GetNoCopies(); | |
400 | devMode->dmFields |= DM_COPIES; | |
401 | ||
402 | //// Printer name | |
403 | wxString name = data.GetPrinterName(); | |
f31a4098 | 404 | if (!name.empty()) |
8850cbd3 RR |
405 | { |
406 | //int len = wxMin(31, m_printerName.Len()); | |
407 | wxStrncpy((wxChar*)devMode->dmDeviceName,name.c_str(),31); | |
408 | devMode->dmDeviceName[31] = wxT('\0'); | |
409 | } | |
410 | ||
411 | //// Colour | |
412 | if (data.GetColour()) | |
413 | devMode->dmColor = DMCOLOR_COLOR; | |
414 | else | |
415 | devMode->dmColor = DMCOLOR_MONOCHROME; | |
416 | devMode->dmFields |= DM_COLOR; | |
417 | ||
418 | //// Paper size | |
419 | if (data.GetPaperId() == wxPAPER_NONE) | |
420 | { | |
421 | // DEVMODE is in tenths of a milimeter | |
422 | devMode->dmPaperWidth = (short)(data.GetPaperSize().x * 10); | |
423 | devMode->dmPaperLength = (short)(data.GetPaperSize().y * 10); | |
3168b4c3 JS |
424 | if(m_customWindowsPaperId != 0) |
425 | devMode->dmPaperSize = m_customWindowsPaperId; | |
426 | else | |
427 | devMode->dmPaperSize = DMPAPER_USER; | |
8850cbd3 RR |
428 | devMode->dmFields |= DM_PAPERWIDTH; |
429 | devMode->dmFields |= DM_PAPERLENGTH; | |
430 | } | |
431 | else | |
432 | { | |
433 | if (wxThePrintPaperDatabase) | |
434 | { | |
435 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType( data.GetPaperId() ); | |
436 | if (paper) | |
437 | { | |
438 | devMode->dmPaperSize = (short)paper->GetPlatformId(); | |
439 | devMode->dmFields |= DM_PAPERSIZE; | |
440 | } | |
21c358b2 JS |
441 | else |
442 | { | |
443 | // Fall back on specifying the paper size explicitly | |
444 | devMode->dmPaperWidth = (short)(data.GetPaperSize().x * 10); | |
445 | devMode->dmPaperLength = (short)(data.GetPaperSize().y * 10); | |
446 | devMode->dmPaperSize = DMPAPER_USER; | |
447 | devMode->dmFields |= DM_PAPERWIDTH; | |
448 | devMode->dmFields |= DM_PAPERLENGTH; | |
449 | } | |
8850cbd3 RR |
450 | } |
451 | } | |
452 | ||
453 | //// Duplex | |
454 | short duplex; | |
455 | switch (data.GetDuplex()) | |
456 | { | |
457 | case wxDUPLEX_HORIZONTAL: | |
458 | duplex = DMDUP_HORIZONTAL; | |
459 | break; | |
460 | case wxDUPLEX_VERTICAL: | |
461 | duplex = DMDUP_VERTICAL; | |
462 | break; | |
463 | default: | |
464 | // in fact case wxDUPLEX_SIMPLEX: | |
465 | duplex = DMDUP_SIMPLEX; | |
466 | break; | |
467 | } | |
468 | devMode->dmDuplex = duplex; | |
469 | devMode->dmFields |= DM_DUPLEX; | |
470 | ||
471 | //// Quality | |
472 | ||
473 | short quality; | |
474 | switch (data.GetQuality()) | |
475 | { | |
476 | case wxPRINT_QUALITY_MEDIUM: | |
477 | quality = DMRES_MEDIUM; | |
478 | break; | |
479 | case wxPRINT_QUALITY_LOW: | |
480 | quality = DMRES_LOW; | |
481 | break; | |
482 | case wxPRINT_QUALITY_DRAFT: | |
483 | quality = DMRES_DRAFT; | |
484 | break; | |
485 | case wxPRINT_QUALITY_HIGH: | |
486 | quality = DMRES_HIGH; | |
487 | break; | |
488 | default: | |
489 | quality = (short)data.GetQuality(); | |
490 | break; | |
491 | } | |
492 | devMode->dmPrintQuality = quality; | |
493 | devMode->dmFields |= DM_PRINTQUALITY; | |
4e22a1f2 | 494 | |
aa96f01c RR |
495 | if (data.GetPrivDataLen() > 0) |
496 | { | |
497 | memcpy( (char *)devMode+devMode->dmSize, data.GetPrivData(), data.GetPrivDataLen() ); | |
4e22a1f2 | 498 | devMode->dmDriverExtra = (WXWORD)data.GetPrivDataLen(); |
aa96f01c | 499 | } |
8850cbd3 RR |
500 | |
501 | if (data.GetBin() != wxPRINTBIN_DEFAULT) | |
502 | { | |
503 | switch (data.GetBin()) | |
504 | { | |
505 | case wxPRINTBIN_ONLYONE: devMode->dmDefaultSource = DMBIN_ONLYONE; break; | |
506 | case wxPRINTBIN_LOWER: devMode->dmDefaultSource = DMBIN_LOWER; break; | |
507 | case wxPRINTBIN_MIDDLE: devMode->dmDefaultSource = DMBIN_MIDDLE; break; | |
508 | case wxPRINTBIN_MANUAL: devMode->dmDefaultSource = DMBIN_MANUAL; break; | |
509 | case wxPRINTBIN_ENVELOPE: devMode->dmDefaultSource = DMBIN_ENVELOPE; break; | |
510 | case wxPRINTBIN_ENVMANUAL: devMode->dmDefaultSource = DMBIN_ENVMANUAL; break; | |
511 | case wxPRINTBIN_AUTO: devMode->dmDefaultSource = DMBIN_AUTO; break; | |
512 | case wxPRINTBIN_TRACTOR: devMode->dmDefaultSource = DMBIN_TRACTOR; break; | |
513 | case wxPRINTBIN_SMALLFMT: devMode->dmDefaultSource = DMBIN_SMALLFMT; break; | |
514 | case wxPRINTBIN_LARGEFMT: devMode->dmDefaultSource = DMBIN_LARGEFMT; break; | |
515 | case wxPRINTBIN_LARGECAPACITY: devMode->dmDefaultSource = DMBIN_LARGECAPACITY; break; | |
516 | case wxPRINTBIN_CASSETTE: devMode->dmDefaultSource = DMBIN_CASSETTE; break; | |
517 | case wxPRINTBIN_FORMSOURCE: devMode->dmDefaultSource = DMBIN_FORMSOURCE; break; | |
518 | ||
519 | default: | |
520 | devMode->dmDefaultSource = (short)(DMBIN_USER + data.GetBin() - wxPRINTBIN_USER); | |
521 | break; | |
522 | } | |
523 | ||
524 | devMode->dmFields |= DM_DEFAULTSOURCE; | |
525 | } | |
526 | ||
527 | GlobalUnlock(hDevMode); | |
528 | } | |
529 | ||
530 | if ( hDevNames ) | |
531 | { | |
532 | GlobalFree(hDevNames); | |
533 | } | |
534 | ||
535 | // TODO: I hope it's OK to pass some empty strings to DEVNAMES. | |
f31a4098 WS |
536 | m_devNames = (void*) (long) wxCreateDevNames(wxEmptyString, data.GetPrinterName(), wxEmptyString); |
537 | ||
8850cbd3 RR |
538 | return true; |
539 | } | |
f31a4098 | 540 | |
103aec29 VZ |
541 | // --------------------------------------------------------------------------- |
542 | // wxPrintDialog | |
543 | // --------------------------------------------------------------------------- | |
544 | ||
c061373d | 545 | IMPLEMENT_CLASS(wxWindowsPrintDialog, wxPrintDialogBase) |
2bda0e17 | 546 | |
c061373d | 547 | wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow *p, wxPrintDialogData* data) |
2bda0e17 | 548 | { |
7bcb11d3 | 549 | Create(p, data); |
2bda0e17 KB |
550 | } |
551 | ||
c061373d | 552 | wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow *p, wxPrintData* data) |
103aec29 VZ |
553 | { |
554 | wxPrintDialogData data2; | |
555 | if ( data ) | |
556 | data2 = *data; | |
557 | ||
558 | Create(p, &data2); | |
559 | } | |
560 | ||
c061373d | 561 | bool wxWindowsPrintDialog::Create(wxWindow *p, wxPrintDialogData* data) |
2bda0e17 | 562 | { |
7bcb11d3 JS |
563 | m_dialogParent = p; |
564 | m_printerDC = NULL; | |
078cf5cb | 565 | m_destroyDC = true; |
7bcb11d3 | 566 | |
93c2f401 RR |
567 | // MSW handle |
568 | m_printDlg = NULL; | |
f31a4098 | 569 | |
7bcb11d3 JS |
570 | if ( data ) |
571 | m_printDialogData = *data; | |
103aec29 | 572 | |
078cf5cb | 573 | return true; |
2bda0e17 KB |
574 | } |
575 | ||
c061373d | 576 | wxWindowsPrintDialog::~wxWindowsPrintDialog() |
2bda0e17 | 577 | { |
93c2f401 RR |
578 | PRINTDLG *pd = (PRINTDLG *) m_printDlg; |
579 | if (pd && pd->hDevMode) | |
580 | GlobalFree(pd->hDevMode); | |
581 | if ( pd ) | |
582 | delete pd; | |
583 | ||
7bcb11d3 JS |
584 | if (m_destroyDC && m_printerDC) |
585 | delete m_printerDC; | |
2bda0e17 KB |
586 | } |
587 | ||
c061373d | 588 | int wxWindowsPrintDialog::ShowModal() |
2bda0e17 | 589 | { |
93c2f401 | 590 | ConvertToNative( m_printDialogData ); |
103aec29 | 591 | |
93c2f401 | 592 | PRINTDLG *pd = (PRINTDLG*) m_printDlg; |
f31a4098 | 593 | |
f6bcfd97 | 594 | if (m_dialogParent) |
93c2f401 | 595 | pd->hwndOwner = (HWND) m_dialogParent->GetHWND(); |
f6bcfd97 | 596 | else if (wxTheApp->GetTopWindow()) |
93c2f401 | 597 | pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND(); |
f6bcfd97 | 598 | else |
93c2f401 | 599 | pd->hwndOwner = 0; |
f6bcfd97 | 600 | |
93c2f401 | 601 | bool ret = (PrintDlg( pd ) != 0); |
f6bcfd97 | 602 | |
93c2f401 | 603 | pd->hwndOwner = 0; |
f6bcfd97 | 604 | |
93c2f401 | 605 | if ( ret != false && (pd->hDC) ) |
7bcb11d3 | 606 | { |
93c2f401 | 607 | wxPrinterDC *pdc = new wxPrinterDC( (WXHDC) pd->hDC ); |
7bcb11d3 | 608 | m_printerDC = pdc; |
93c2f401 | 609 | ConvertFromNative( m_printDialogData ); |
7bcb11d3 JS |
610 | return wxID_OK; |
611 | } | |
612 | else | |
613 | { | |
7bcb11d3 JS |
614 | return wxID_CANCEL; |
615 | } | |
2bda0e17 KB |
616 | } |
617 | ||
c061373d | 618 | wxDC *wxWindowsPrintDialog::GetPrintDC() |
2bda0e17 | 619 | { |
7bcb11d3 JS |
620 | if (m_printerDC) |
621 | { | |
078cf5cb | 622 | m_destroyDC = false; |
7bcb11d3 JS |
623 | return m_printerDC; |
624 | } | |
625 | else | |
626 | return (wxDC*) NULL; | |
2bda0e17 KB |
627 | } |
628 | ||
93c2f401 RR |
629 | bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data ) |
630 | { | |
631 | wxWindowsPrintNativeData *native_data = | |
632 | (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); | |
633 | data.GetPrintData().ConvertToNative(); | |
f31a4098 | 634 | |
93c2f401 RR |
635 | PRINTDLG *pd = (PRINTDLG*) m_printDlg; |
636 | ||
637 | // Shouldn't have been defined anywhere | |
638 | if (pd) | |
639 | return false; | |
f31a4098 | 640 | |
93c2f401 RR |
641 | pd = new PRINTDLG; |
642 | memset( pd, 0, sizeof(PRINTDLG) ); | |
643 | m_printDlg = (void*) pd; | |
644 | ||
645 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. | |
646 | #ifdef __GNUWIN32__ | |
647 | pd->lStructSize = 66; | |
648 | #else | |
649 | pd->lStructSize = sizeof(PRINTDLG); | |
650 | #endif | |
651 | pd->hwndOwner = (HWND)NULL; | |
652 | pd->hDevMode = NULL; // Will be created by PrintDlg | |
653 | pd->hDevNames = NULL; // Ditto | |
654 | ||
655 | pd->Flags = PD_RETURNDEFAULT; | |
656 | pd->nCopies = 1; | |
f31a4098 | 657 | |
93c2f401 RR |
658 | // Pass the devmode data to the PRINTDLG structure, since it'll |
659 | // be needed when PrintDlg is called. | |
660 | if (pd->hDevMode) | |
661 | GlobalFree(pd->hDevMode); | |
662 | ||
663 | // Pass the devnames data to the PRINTDLG structure, since it'll | |
664 | // be needed when PrintDlg is called. | |
665 | if (pd->hDevNames) | |
666 | GlobalFree(pd->hDevNames); | |
667 | ||
668 | pd->hDevMode = (HGLOBAL)(DWORD) native_data->GetDevMode(); | |
669 | native_data->SetDevMode( (void*) NULL); | |
670 | ||
671 | // Shouldn't assert; we should be able to test Ok-ness at a higher level | |
672 | //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
673 | ||
674 | pd->hDevNames = (HGLOBAL)(DWORD) native_data->GetDevNames(); | |
675 | native_data->SetDevNames( (void*) NULL); | |
676 | ||
677 | ||
678 | pd->hDC = (HDC) NULL; | |
679 | pd->nFromPage = (WORD)data.GetFromPage(); | |
680 | pd->nToPage = (WORD)data.GetToPage(); | |
681 | pd->nMinPage = (WORD)data.GetMinPage(); | |
682 | pd->nMaxPage = (WORD)data.GetMaxPage(); | |
683 | pd->nCopies = (WORD)data.GetNoCopies(); | |
684 | ||
685 | pd->Flags = PD_RETURNDC; | |
686 | ||
687 | #ifdef __GNUWIN32__ | |
688 | pd->lStructSize = 66; | |
689 | #else | |
690 | pd->lStructSize = sizeof( PRINTDLG ); | |
691 | #endif | |
692 | ||
693 | pd->hwndOwner=(HWND)NULL; | |
694 | // pd->hDevNames=(HANDLE)NULL; | |
695 | pd->hInstance=(HINSTANCE)NULL; | |
696 | pd->lCustData = (LPARAM) NULL; | |
697 | pd->lpfnPrintHook = NULL; | |
698 | pd->lpfnSetupHook = NULL; | |
699 | pd->lpPrintTemplateName = NULL; | |
700 | pd->lpSetupTemplateName = NULL; | |
701 | pd->hPrintTemplate = (HGLOBAL) NULL; | |
702 | pd->hSetupTemplate = (HGLOBAL) NULL; | |
703 | ||
704 | if ( data.GetAllPages() ) | |
705 | pd->Flags |= PD_ALLPAGES; | |
706 | if ( data.GetSelection() ) | |
707 | pd->Flags |= PD_SELECTION; | |
708 | if ( data.GetCollate() ) | |
709 | pd->Flags |= PD_COLLATE; | |
710 | if ( data.GetPrintToFile() ) | |
711 | pd->Flags |= PD_PRINTTOFILE; | |
712 | if ( !data.GetEnablePrintToFile() ) | |
713 | pd->Flags |= PD_DISABLEPRINTTOFILE; | |
714 | if ( !data.GetEnableSelection() ) | |
715 | pd->Flags |= PD_NOSELECTION; | |
716 | if ( !data.GetEnablePageNumbers() ) | |
717 | pd->Flags |= PD_NOPAGENUMS; | |
718 | else if ( (!data.GetAllPages()) && (!data.GetSelection()) && (data.GetFromPage() != 0) && (data.GetToPage() != 0)) | |
719 | pd->Flags |= PD_PAGENUMS; | |
720 | if ( data.GetEnableHelp() ) | |
721 | pd->Flags |= PD_SHOWHELP; | |
b45dfd0a | 722 | #if WXWIN_COMPATIBILITY_2_4 |
93c2f401 RR |
723 | if ( data.GetSetupDialog() ) |
724 | pd->Flags |= PD_PRINTSETUP; | |
b45dfd0a | 725 | #endif |
f31a4098 | 726 | |
93c2f401 RR |
727 | return true; |
728 | } | |
729 | ||
730 | bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData &data ) | |
731 | { | |
732 | PRINTDLG *pd = (PRINTDLG*) m_printDlg; | |
733 | if ( pd == NULL ) | |
734 | return false; | |
735 | ||
736 | wxWindowsPrintNativeData *native_data = | |
737 | (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); | |
f31a4098 | 738 | |
93c2f401 RR |
739 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
740 | if (pd->hDevMode) | |
741 | { | |
742 | if (native_data->GetDevMode()) | |
743 | { | |
744 | // Make sure we don't leak memory | |
745 | GlobalFree( (HGLOBAL)(DWORD) native_data->GetDevMode() ); | |
746 | } | |
747 | native_data->SetDevMode( (void*)(long) pd->hDevMode ); | |
748 | pd->hDevMode = NULL; | |
749 | } | |
750 | ||
751 | // Pass the devnames data back to the wxPrintData structure where it really belongs. | |
752 | if (pd->hDevNames) | |
753 | { | |
754 | if (native_data->GetDevNames()) | |
755 | { | |
756 | // Make sure we don't leak memory | |
757 | GlobalFree((HGLOBAL)(DWORD) native_data->GetDevNames()); | |
758 | } | |
759 | native_data->SetDevNames((void*)(long) pd->hDevNames); | |
760 | pd->hDevNames = NULL; | |
761 | } | |
762 | ||
763 | // Now convert the DEVMODE object, passed down from the PRINTDLG object, | |
764 | // into wxWidgets form. | |
765 | native_data->TransferTo( data.GetPrintData() ); | |
766 | ||
767 | data.SetFromPage( pd->nFromPage ); | |
768 | data.SetToPage( pd->nToPage ); | |
769 | data.SetMinPage( pd->nMinPage ); | |
770 | data.SetMaxPage( pd->nMaxPage ); | |
771 | data.SetNoCopies( pd->nCopies ); | |
772 | ||
773 | data.SetAllPages( (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION)) ); | |
774 | data.SetSelection( ((pd->Flags & PD_SELECTION) == PD_SELECTION) ); | |
775 | data.SetCollate( ((pd->Flags & PD_COLLATE) == PD_COLLATE) ); | |
776 | data.SetPrintToFile( ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE) ); | |
777 | data.EnablePrintToFile( ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE) ); | |
778 | data.EnableSelection( ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION) ); | |
779 | data.EnablePageNumbers( ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS) ); | |
780 | data.EnableHelp( ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP) ); | |
b45dfd0a | 781 | #if WXWIN_COMPATIBILITY_2_4 |
93c2f401 | 782 | data.SetSetupDialog( ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP) ); |
f31a4098 | 783 | #endif |
93c2f401 RR |
784 | return true; |
785 | } | |
786 | ||
103aec29 | 787 | // --------------------------------------------------------------------------- |
08680429 | 788 | // wxWidnowsPageSetupDialog |
103aec29 | 789 | // --------------------------------------------------------------------------- |
2bda0e17 | 790 | |
08680429 | 791 | IMPLEMENT_CLASS(wxWindowsPageSetupDialog, wxPageSetupDialogBase) |
c061373d | 792 | |
08680429 | 793 | wxWindowsPageSetupDialog::wxWindowsPageSetupDialog() |
2bda0e17 | 794 | { |
7bcb11d3 | 795 | m_dialogParent = NULL; |
b45dfd0a | 796 | m_pageDlg = NULL; |
2bda0e17 KB |
797 | } |
798 | ||
08680429 | 799 | wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow *p, wxPageSetupDialogData *data) |
2bda0e17 | 800 | { |
7bcb11d3 | 801 | Create(p, data); |
2bda0e17 KB |
802 | } |
803 | ||
08680429 | 804 | bool wxWindowsPageSetupDialog::Create(wxWindow *p, wxPageSetupDialogData *data) |
2bda0e17 | 805 | { |
7bcb11d3 | 806 | m_dialogParent = p; |
b45dfd0a | 807 | m_pageDlg = NULL; |
103aec29 | 808 | |
7bcb11d3 JS |
809 | if (data) |
810 | m_pageSetupData = (*data); | |
103aec29 | 811 | |
078cf5cb | 812 | return true; |
2bda0e17 KB |
813 | } |
814 | ||
08680429 | 815 | wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog() |
2bda0e17 | 816 | { |
b45dfd0a RR |
817 | PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageDlg; |
818 | if ( pd && pd->hDevMode ) | |
819 | GlobalFree(pd->hDevMode); | |
820 | if ( pd && pd->hDevNames ) | |
821 | GlobalFree(pd->hDevNames); | |
822 | if ( pd ) | |
823 | delete pd; | |
2bda0e17 KB |
824 | } |
825 | ||
08680429 | 826 | int wxWindowsPageSetupDialog::ShowModal() |
2bda0e17 | 827 | { |
b45dfd0a | 828 | ConvertToNative( m_pageSetupData ); |
f31a4098 | 829 | |
b45dfd0a | 830 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageDlg; |
f6bcfd97 | 831 | if (m_dialogParent) |
b45dfd0a | 832 | pd->hwndOwner = (HWND) m_dialogParent->GetHWND(); |
f6bcfd97 | 833 | else if (wxTheApp->GetTopWindow()) |
b45dfd0a | 834 | pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND(); |
f6bcfd97 | 835 | else |
b45dfd0a RR |
836 | pd->hwndOwner = 0; |
837 | BOOL retVal = PageSetupDlg( pd ) ; | |
838 | pd->hwndOwner = 0; | |
f6bcfd97 | 839 | if (retVal) |
2bda0e17 | 840 | { |
b45dfd0a | 841 | ConvertFromNative( m_pageSetupData ); |
7bcb11d3 | 842 | return wxID_OK; |
2bda0e17 KB |
843 | } |
844 | else | |
7bcb11d3 | 845 | return wxID_CANCEL; |
b45dfd0a RR |
846 | } |
847 | ||
08680429 | 848 | bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData &data ) |
b45dfd0a RR |
849 | { |
850 | wxWindowsPrintNativeData *native_data = | |
851 | (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); | |
852 | data.GetPrintData().ConvertToNative(); | |
853 | ||
854 | PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageDlg; | |
855 | ||
856 | // Shouldn't have been defined anywhere | |
857 | if (pd) | |
858 | return false; | |
f31a4098 | 859 | |
b45dfd0a RR |
860 | pd = new PAGESETUPDLG; |
861 | pd->hDevMode = NULL; | |
862 | pd->hDevNames = NULL; | |
863 | m_pageDlg = (void *)pd; | |
864 | ||
865 | // Pass the devmode data (created in m_printData.ConvertToNative) | |
866 | // to the PRINTDLG structure, since it'll | |
867 | // be needed when PrintDlg is called. | |
868 | ||
869 | if (pd->hDevMode) | |
870 | { | |
871 | GlobalFree(pd->hDevMode); | |
872 | pd->hDevMode = NULL; | |
873 | } | |
874 | pd->hDevMode = (HGLOBAL) native_data->GetDevMode(); | |
875 | native_data->SetDevMode( (void*) NULL ); | |
876 | ||
877 | // Shouldn't assert; we should be able to test Ok-ness at a higher level | |
878 | //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
879 | ||
880 | // Pass the devnames data (created in m_printData.ConvertToNative) | |
881 | // to the PRINTDLG structure, since it'll | |
882 | // be needed when PrintDlg is called. | |
883 | ||
884 | if (pd->hDevNames) | |
885 | { | |
886 | GlobalFree(pd->hDevNames); | |
887 | pd->hDevNames = NULL; | |
888 | } | |
889 | pd->hDevNames = (HGLOBAL) native_data->GetDevNames(); | |
890 | native_data->SetDevNames((void*) NULL); | |
891 | ||
892 | // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE)); | |
893 | ||
894 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; | |
895 | ||
896 | if ( data.GetDefaultMinMargins() ) | |
897 | pd->Flags |= PSD_DEFAULTMINMARGINS; | |
898 | if ( !data.GetEnableMargins() ) | |
899 | pd->Flags |= PSD_DISABLEMARGINS; | |
900 | if ( !data.GetEnableOrientation() ) | |
901 | pd->Flags |= PSD_DISABLEORIENTATION; | |
902 | if ( !data.GetEnablePaper() ) | |
903 | pd->Flags |= PSD_DISABLEPAPER; | |
904 | if ( !data.GetEnablePrinter() ) | |
905 | pd->Flags |= PSD_DISABLEPRINTER; | |
906 | if ( data.GetDefaultInfo() ) | |
907 | pd->Flags |= PSD_RETURNDEFAULT; | |
908 | if ( data.GetEnableHelp() ) | |
909 | pd->Flags |= PSD_SHOWHELP; | |
910 | ||
911 | // We want the units to be in hundredths of a millimetre | |
912 | pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS; | |
913 | ||
914 | pd->lStructSize = sizeof( PAGESETUPDLG ); | |
915 | pd->hwndOwner=(HWND)NULL; | |
916 | // pd->hDevNames=(HWND)NULL; | |
917 | pd->hInstance=(HINSTANCE)NULL; | |
918 | // PAGESETUPDLG is in hundreds of a mm | |
919 | pd->ptPaperSize.x = data.GetPaperSize().x * 100; | |
920 | pd->ptPaperSize.y = data.GetPaperSize().y * 100; | |
921 | ||
922 | pd->rtMinMargin.left = data.GetMinMarginTopLeft().x * 100; | |
923 | pd->rtMinMargin.top = data.GetMinMarginTopLeft().y * 100; | |
924 | pd->rtMinMargin.right = data.GetMinMarginBottomRight().x * 100; | |
925 | pd->rtMinMargin.bottom = data.GetMinMarginBottomRight().y * 100; | |
926 | ||
927 | pd->rtMargin.left = data.GetMarginTopLeft().x * 100; | |
928 | pd->rtMargin.top = data.GetMarginTopLeft().y * 100; | |
929 | pd->rtMargin.right = data.GetMarginBottomRight().x * 100; | |
930 | pd->rtMargin.bottom = data.GetMarginBottomRight().y * 100; | |
931 | ||
932 | pd->lCustData = 0; | |
933 | pd->lpfnPageSetupHook = NULL; | |
934 | pd->lpfnPagePaintHook = NULL; | |
935 | pd->hPageSetupTemplate = NULL; | |
936 | pd->lpPageSetupTemplateName = NULL; | |
937 | ||
938 | /* | |
939 | if ( pd->hDevMode ) | |
940 | { | |
941 | DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); | |
942 | memset(devMode, 0, sizeof(DEVMODE)); | |
943 | devMode->dmSize = sizeof(DEVMODE); | |
944 | devMode->dmOrientation = m_orientation; | |
945 | devMode->dmFields = DM_ORIENTATION; | |
946 | GlobalUnlock(pd->hDevMode); | |
947 | } | |
948 | */ | |
949 | return true; | |
950 | } | |
951 | ||
08680429 | 952 | bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData &data ) |
b45dfd0a RR |
953 | { |
954 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageDlg; | |
955 | if ( !pd ) | |
956 | return false; | |
957 | ||
958 | wxWindowsPrintNativeData *native_data = | |
959 | (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); | |
f31a4098 | 960 | |
b45dfd0a RR |
961 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
962 | if (pd->hDevMode) | |
963 | { | |
964 | if (native_data->GetDevMode()) | |
965 | { | |
966 | // Make sure we don't leak memory | |
967 | GlobalFree((HGLOBAL) native_data->GetDevMode()); | |
968 | } | |
969 | native_data->SetDevMode( (void*) pd->hDevMode ); | |
970 | pd->hDevMode = NULL; | |
971 | } | |
f31a4098 | 972 | |
b45dfd0a RR |
973 | // Isn't this superfluous? It's called again below. |
974 | // data.GetPrintData().ConvertFromNative(); | |
975 | ||
976 | // Pass the devnames data back to the wxPrintData structure where it really belongs. | |
977 | if (pd->hDevNames) | |
978 | { | |
979 | if (native_data->GetDevNames()) | |
980 | { | |
981 | // Make sure we don't leak memory | |
982 | GlobalFree((HGLOBAL) native_data->GetDevNames()); | |
983 | } | |
984 | native_data->SetDevNames((void*) pd->hDevNames); | |
985 | pd->hDevNames = NULL; | |
986 | } | |
987 | ||
988 | data.GetPrintData().ConvertFromNative(); | |
989 | ||
990 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; | |
991 | ||
992 | data.SetDefaultMinMargins( ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS) ); | |
993 | data.EnableMargins( ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS) ); | |
994 | data.EnableOrientation( ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION) ); | |
995 | data.EnablePaper( ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER) ); | |
996 | data.EnablePrinter( ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER) ); | |
997 | data.SetDefaultInfo( ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT) ); | |
998 | data.EnableHelp( ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP) ); | |
999 | ||
1000 | // PAGESETUPDLG is in hundreds of a mm | |
1001 | data.SetPaperSize( wxSize(pd->ptPaperSize.x / 100, pd->ptPaperSize.y / 100) ); | |
1002 | ||
1003 | data.SetMinMarginTopLeft( wxPoint(pd->rtMinMargin.left / 100, pd->rtMinMargin.top / 100) ); | |
1004 | data.SetMinMarginBottomRight( wxPoint(pd->rtMinMargin.right / 100, pd->rtMinMargin.bottom / 100) ); | |
1005 | ||
1006 | data.SetMarginTopLeft( wxPoint(pd->rtMargin.left / 100, pd->rtMargin.top / 100) ); | |
1007 | data.SetMarginBottomRight( wxPoint(pd->rtMargin.right / 100, pd->rtMargin.bottom / 100) ); | |
f31a4098 | 1008 | |
b45dfd0a | 1009 | return true; |
2bda0e17 KB |
1010 | } |
1011 | ||
f6bcfd97 BP |
1012 | #endif |
1013 | // wxUSE_PRINTING_ARCHITECTURE |