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