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