]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: cmndata.cpp | |
3 | // Purpose: Common GDI data | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
8bbe427f | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8826f46f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
c801d85f | 20 | #ifdef __GNUG__ |
8826f46f | 21 | #pragma implementation "cmndata.h" |
c801d85f KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
8826f46f | 28 | #pragma hdrstop |
c801d85f KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
8826f46f VZ |
32 | #include <stdio.h> |
33 | #include "wx/string.h" | |
34 | #include "wx/utils.h" | |
35 | #include "wx/app.h" | |
c801d85f KB |
36 | #endif |
37 | ||
38 | #include "wx/gdicmn.h" | |
39 | #include "wx/cmndata.h" | |
6776a0b2 | 40 | #include "wx/log.h" |
8826f46f | 41 | |
7bcb11d3 JS |
42 | // For compatibility |
43 | #if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT | |
8826f46f | 44 | #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1 |
7bcb11d3 | 45 | #endif |
c801d85f | 46 | |
88ac883a VZ |
47 | #if wxUSE_PRINTING_ARCHITECTURE |
48 | #include "wx/paper.h" | |
49 | ||
50 | #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA | |
51 | #include "wx/generic/dcpsg.h" | |
52 | #endif | |
53 | #endif // wxUSE_PRINTING_ARCHITECTURE | |
7be1f0d9 | 54 | |
8826f46f VZ |
55 | #ifdef __WXMSW__ |
56 | #include <windows.h> | |
3096bd2f | 57 | #include "wx/msw/private.h" |
7be1f0d9 | 58 | |
8826f46f VZ |
59 | #if !defined(__WIN32__) |
60 | #include <print.h> | |
61 | #include <commdlg.h> | |
62 | #endif // Win16 | |
63 | ||
c455ab93 RR |
64 | #ifdef __WXWINE__ |
65 | #include <cderr.h> | |
66 | #include <commdlg.h> | |
67 | #endif | |
68 | ||
8826f46f VZ |
69 | #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__) |
70 | #include <windowsx.h> | |
71 | #include <commdlg.h> | |
72 | #endif | |
73 | #endif // MSW | |
c801d85f KB |
74 | |
75 | #if !USE_SHARED_LIBRARY | |
88ac883a VZ |
76 | #if wxUSE_PRINTING_ARCHITECTURE |
77 | IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject) | |
78 | IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject) | |
79 | IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject) | |
80 | #endif // wxUSE_PRINTING_ARCHITECTURE | |
8826f46f VZ |
81 | IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject) |
82 | IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject) | |
c801d85f KB |
83 | #endif |
84 | ||
8826f46f VZ |
85 | // ============================================================================ |
86 | // implementation | |
87 | // ============================================================================ | |
88 | ||
89 | // ---------------------------------------------------------------------------- | |
90 | // wxColourData | |
91 | // ---------------------------------------------------------------------------- | |
c801d85f | 92 | |
8bbe427f | 93 | wxColourData::wxColourData() |
c801d85f | 94 | { |
7bcb11d3 JS |
95 | int i; |
96 | for (i = 0; i < 16; i++) | |
97 | custColours[i].Set(255, 255, 255); | |
8826f46f | 98 | |
7bcb11d3 JS |
99 | chooseFull = FALSE; |
100 | dataColour.Set(0,0,0); | |
101 | } | |
c801d85f | 102 | |
7bcb11d3 JS |
103 | wxColourData::wxColourData(const wxColourData& data) |
104 | { | |
105 | (*this) = data; | |
8bbe427f | 106 | } |
c801d85f | 107 | |
8bbe427f | 108 | wxColourData::~wxColourData() |
c801d85f KB |
109 | { |
110 | } | |
111 | ||
112 | void wxColourData::SetCustomColour(int i, wxColour& colour) | |
113 | { | |
7bcb11d3 JS |
114 | if (i > 15 || i < 0) |
115 | return; | |
8826f46f | 116 | |
7bcb11d3 | 117 | custColours[i] = colour; |
c801d85f KB |
118 | } |
119 | ||
120 | wxColour wxColourData::GetCustomColour(int i) | |
121 | { | |
7bcb11d3 JS |
122 | if (i > 15 || i < 0) |
123 | return wxColour(0,0,0); | |
8826f46f | 124 | |
7bcb11d3 | 125 | return custColours[i]; |
c801d85f KB |
126 | } |
127 | ||
128 | void wxColourData::operator=(const wxColourData& data) | |
129 | { | |
7bcb11d3 JS |
130 | int i; |
131 | for (i = 0; i < 16; i++) | |
132 | custColours[i] = data.custColours[i]; | |
8826f46f | 133 | |
7bcb11d3 JS |
134 | dataColour = (wxColour&)data.dataColour; |
135 | chooseFull = data.chooseFull; | |
c801d85f KB |
136 | } |
137 | ||
8826f46f VZ |
138 | // ---------------------------------------------------------------------------- |
139 | // Font data | |
140 | // ---------------------------------------------------------------------------- | |
c801d85f | 141 | |
8bbe427f | 142 | wxFontData::wxFontData() |
c801d85f | 143 | { |
7bcb11d3 JS |
144 | // Intialize colour to black. |
145 | fontColour.Set(0, 0, 0); | |
8826f46f | 146 | |
7bcb11d3 JS |
147 | showHelp = FALSE; |
148 | allowSymbols = TRUE; | |
149 | enableEffects = TRUE; | |
150 | minSize = 0; | |
151 | maxSize = 0; | |
c801d85f | 152 | |
7beba2fc | 153 | m_encoding = wxFONTENCODING_SYSTEM; |
c801d85f KB |
154 | } |
155 | ||
8bbe427f | 156 | wxFontData::~wxFontData() |
c801d85f KB |
157 | { |
158 | } | |
159 | ||
88ac883a | 160 | #if wxUSE_PRINTING_ARCHITECTURE |
8826f46f VZ |
161 | // ---------------------------------------------------------------------------- |
162 | // Print data | |
163 | // ---------------------------------------------------------------------------- | |
c801d85f | 164 | |
8bbe427f | 165 | wxPrintData::wxPrintData() |
c801d85f | 166 | { |
2049ba38 | 167 | #ifdef __WXMSW__ |
7bcb11d3 | 168 | m_devMode = NULL; |
c801d85f | 169 | #endif |
7bcb11d3 JS |
170 | m_printOrientation = wxPORTRAIT; |
171 | m_printNoCopies = 1; | |
172 | m_printCollate = FALSE; | |
8826f46f | 173 | |
7bcb11d3 JS |
174 | // New, 24/3/99 |
175 | m_printerName = ""; | |
176 | m_colour = TRUE; | |
177 | m_duplexMode = wxDUPLEX_SIMPLEX; | |
178 | m_printQuality = wxPRINT_QUALITY_HIGH; | |
179 | m_paperId = wxPAPER_A4; | |
180 | m_paperSize = wxSize(210, 297); | |
181 | ||
182 | // PostScript-specific data | |
183 | m_printerCommand = ""; | |
184 | m_previewCommand = ""; | |
185 | m_printerOptions = ""; | |
186 | m_filename = ""; | |
187 | m_afmPath = ""; | |
188 | m_printerScaleX = 1.0; | |
189 | m_printerScaleY = 1.0; | |
190 | m_printerTranslateX = 0; | |
191 | m_printerTranslateY = 0; | |
192 | m_printMode = wxPRINT_MODE_FILE; | |
193 | } | |
194 | ||
195 | wxPrintData::wxPrintData(const wxPrintData& printData) | |
196 | { | |
58abfef6 JS |
197 | #ifdef __WXMSW__ |
198 | m_devMode = NULL; | |
199 | #endif | |
200 | ||
7bcb11d3 | 201 | (*this) = printData; |
c801d85f KB |
202 | } |
203 | ||
8bbe427f | 204 | wxPrintData::~wxPrintData() |
c801d85f | 205 | { |
2049ba38 | 206 | #ifdef __WXMSW__ |
48c12cb1 | 207 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; |
7bcb11d3 JS |
208 | if (hDevMode ) |
209 | GlobalFree(hDevMode); | |
c801d85f KB |
210 | #endif |
211 | } | |
212 | ||
25889d3c | 213 | #if defined(__WXMSW__) // && defined(__WIN32__) |
7bcb11d3 | 214 | |
25889d3c | 215 | #ifdef __WIN32__ |
6aa55ce7 JS |
216 | static wxString wxGetPrintDlgError() |
217 | { | |
218 | DWORD err = CommDlgExtendedError(); | |
223d09f6 | 219 | wxString msg = wxT("Unknown"); |
6aa55ce7 JS |
220 | switch (err) |
221 | { | |
223d09f6 KB |
222 | case CDERR_FINDRESFAILURE: msg = wxT("CDERR_FINDRESFAILURE"); break; |
223 | case CDERR_INITIALIZATION: msg = wxT("CDERR_INITIALIZATION"); break; | |
224 | case CDERR_LOADRESFAILURE: msg = wxT("CDERR_LOADRESFAILURE"); break; | |
225 | case CDERR_LOADSTRFAILURE: msg = wxT("CDERR_LOADSTRFAILURE"); break; | |
226 | case CDERR_LOCKRESFAILURE: msg = wxT("CDERR_LOCKRESFAILURE"); break; | |
227 | case CDERR_MEMALLOCFAILURE: msg = wxT("CDERR_MEMALLOCFAILURE"); break; | |
228 | case CDERR_MEMLOCKFAILURE: msg = wxT("CDERR_MEMLOCKFAILURE"); break; | |
229 | case CDERR_NOHINSTANCE: msg = wxT("CDERR_NOHINSTANCE"); break; | |
230 | case CDERR_NOHOOK: msg = wxT("CDERR_NOHOOK"); break; | |
231 | case CDERR_NOTEMPLATE: msg = wxT("CDERR_NOTEMPLATE"); break; | |
232 | case CDERR_STRUCTSIZE: msg = wxT("CDERR_STRUCTSIZE"); break; | |
233 | case PDERR_RETDEFFAILURE: msg = wxT("PDERR_RETDEFFAILURE"); break; | |
234 | case PDERR_PRINTERNOTFOUND: msg = wxT("PDERR_PRINTERNOTFOUND"); break; | |
235 | case PDERR_PARSEFAILURE: msg = wxT("PDERR_PARSEFAILURE"); break; | |
236 | case PDERR_NODEVICES: msg = wxT("PDERR_NODEVICES"); break; | |
237 | case PDERR_NODEFAULTPRN: msg = wxT("PDERR_NODEFAULTPRN"); break; | |
238 | case PDERR_LOADDRVFAILURE: msg = wxT("PDERR_LOADDRVFAILURE"); break; | |
239 | case PDERR_INITFAILURE: msg = wxT("PDERR_INITFAILURE"); break; | |
240 | case PDERR_GETDEVMODEFAIL: msg = wxT("PDERR_GETDEVMODEFAIL"); break; | |
241 | case PDERR_DNDMMISMATCH: msg = wxT("PDERR_DNDMMISMATCH"); break; | |
242 | case PDERR_DEFAULTDIFFERENT: msg = wxT("PDERR_DEFAULTDIFFERENT"); break; | |
243 | case PDERR_CREATEICFAILURE: msg = wxT("PDERR_CREATEICFAILURE"); break; | |
6aa55ce7 JS |
244 | default: break; |
245 | } | |
246 | return msg; | |
247 | } | |
25889d3c | 248 | #endif |
6aa55ce7 | 249 | |
8bbe427f | 250 | void wxPrintData::ConvertToNative() |
c801d85f | 251 | { |
48c12cb1 | 252 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; |
7bcb11d3 | 253 | if (!hDevMode) |
c801d85f | 254 | { |
7bcb11d3 JS |
255 | // Use PRINTDLG as a way of creating a DEVMODE object |
256 | PRINTDLG *pd = new PRINTDLG; | |
8826f46f | 257 | |
c801d85f | 258 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. |
7bcb11d3 | 259 | #ifdef __GNUWIN32__ |
6aa55ce7 | 260 | memset(pd, 0, 66); |
c801d85f | 261 | pd->lStructSize = 66 ; |
7bcb11d3 | 262 | #else |
7bcb11d3 | 263 | memset(pd, 0, sizeof(PRINTDLG)); |
6aa55ce7 | 264 | pd->lStructSize = sizeof(PRINTDLG); |
7bcb11d3 JS |
265 | #endif |
266 | ||
c801d85f KB |
267 | pd->hwndOwner = (HWND)NULL; |
268 | pd->hDevMode = NULL; // Will be created by PrintDlg | |
269 | pd->hDevNames = NULL; // Ditto | |
6aa55ce7 | 270 | pd->hInstance = (HINSTANCE) wxGetInstance(); |
8826f46f | 271 | |
c801d85f KB |
272 | pd->Flags = PD_RETURNDEFAULT; |
273 | pd->nCopies = 1; | |
8826f46f | 274 | |
c801d85f KB |
275 | // Fill out the DEVMODE structure |
276 | // so we can use it as input in the 'real' PrintDlg | |
277 | if (!PrintDlg(pd)) | |
278 | { | |
279 | if ( pd->hDevMode ) | |
280 | GlobalFree(pd->hDevMode); | |
281 | if ( pd->hDevNames ) | |
282 | GlobalFree(pd->hDevNames); | |
283 | pd->hDevMode = NULL; | |
284 | pd->hDevNames = NULL; | |
58a33cb4 JS |
285 | |
286 | #if defined(__WXDEBUG__) && defined(__WIN32__) | |
223d09f6 | 287 | wxString str(wxT("Printing error: ")); |
6aa55ce7 JS |
288 | str += wxGetPrintDlgError(); |
289 | wxLogDebug(str); | |
290 | #endif | |
c801d85f KB |
291 | } |
292 | else | |
293 | { | |
294 | if ( pd->hDevNames ) | |
295 | GlobalFree(pd->hDevNames); | |
296 | pd->hDevNames = NULL; | |
7bcb11d3 JS |
297 | |
298 | hDevMode = pd->hDevMode; | |
aeb50f86 | 299 | m_devMode = (void*)(long) hDevMode; |
7bcb11d3 | 300 | pd->hDevMode = NULL; |
c801d85f | 301 | } |
c801d85f | 302 | |
7bcb11d3 JS |
303 | delete pd; |
304 | } | |
8826f46f | 305 | |
7bcb11d3 | 306 | if ( hDevMode ) |
c801d85f | 307 | { |
7bcb11d3 | 308 | DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode); |
8826f46f | 309 | |
7bcb11d3 | 310 | //// Orientation |
8826f46f | 311 | |
c455ab93 | 312 | #ifndef __WXWINE__ |
7bcb11d3 | 313 | devMode->dmOrientation = m_printOrientation; |
c455ab93 | 314 | #endif |
c801d85f | 315 | devMode->dmFields = DM_ORIENTATION; |
8826f46f | 316 | |
7bcb11d3 | 317 | //// Collation |
8826f46f | 318 | |
25889d3c | 319 | #ifndef __WIN16__ |
7bcb11d3 JS |
320 | devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE); |
321 | devMode->dmFields |= DM_COLLATE; | |
25889d3c | 322 | #endif |
8826f46f | 323 | |
7bcb11d3 | 324 | //// Number of copies |
8826f46f | 325 | |
7bcb11d3 JS |
326 | devMode->dmCopies = m_printNoCopies; |
327 | devMode->dmFields |= DM_COPIES; | |
8826f46f | 328 | |
7bcb11d3 | 329 | //// Printer name |
8826f46f | 330 | |
223d09f6 | 331 | if (m_printerName != wxT("")) |
7bcb11d3 JS |
332 | { |
333 | // TODO: make this Unicode compatible | |
334 | int len = wxMin(31, m_printerName.Len()); | |
335 | int i; | |
336 | for (i = 0; i < len; i++) | |
337 | devMode->dmDeviceName[i] = m_printerName.GetChar(i); | |
338 | devMode->dmDeviceName[i] = 0; | |
339 | } | |
8826f46f | 340 | |
7bcb11d3 | 341 | //// Colour |
8826f46f | 342 | |
7bcb11d3 JS |
343 | if (m_colour) |
344 | devMode->dmColor = DMCOLOR_COLOR; | |
345 | else | |
346 | devMode->dmColor = DMCOLOR_MONOCHROME; | |
8826f46f | 347 | |
7bcb11d3 | 348 | devMode->dmFields |= DM_COLOR; |
8826f46f | 349 | |
c455ab93 | 350 | #ifndef __WXWINE__ |
7bcb11d3 | 351 | //// Paper size |
8826f46f | 352 | |
7bcb11d3 JS |
353 | if (m_paperId == wxPAPER_NONE) |
354 | { | |
355 | devMode->dmPaperWidth = m_paperSize.x * 10; | |
356 | devMode->dmPaperLength = m_paperSize.y * 10; | |
357 | devMode->dmFields |= DM_PAPERWIDTH; | |
358 | devMode->dmFields |= DM_PAPERLENGTH; | |
359 | } | |
360 | else | |
361 | { | |
362 | if (wxThePrintPaperDatabase) | |
363 | { | |
364 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId); | |
365 | if (paper) | |
366 | { | |
367 | devMode->dmPaperSize = paper->GetPlatformId(); | |
368 | devMode->dmFields |= DM_PAPERSIZE; | |
369 | } | |
370 | } | |
371 | } | |
c455ab93 | 372 | #endif |
8826f46f | 373 | |
7bcb11d3 | 374 | //// Duplex |
8826f46f | 375 | |
7bcb11d3 JS |
376 | int duplex; |
377 | switch (m_duplexMode) | |
378 | { | |
379 | case wxDUPLEX_HORIZONTAL: { | |
380 | duplex = DMDUP_HORIZONTAL; break; | |
381 | } | |
382 | case wxDUPLEX_VERTICAL: { | |
383 | duplex = DMDUP_VERTICAL; break; | |
384 | } | |
385 | default: | |
386 | case wxDUPLEX_SIMPLEX: { | |
387 | duplex = DMDUP_SIMPLEX; break; | |
388 | } | |
389 | } | |
390 | devMode->dmDuplex = duplex; | |
391 | devMode->dmFields |= DM_DUPLEX; | |
8826f46f | 392 | |
7bcb11d3 | 393 | //// Quality |
8826f46f | 394 | |
7bcb11d3 JS |
395 | int quality; |
396 | switch (m_printQuality) | |
397 | { | |
398 | case wxPRINT_QUALITY_MEDIUM: { | |
399 | quality = DMRES_MEDIUM; break; | |
400 | } | |
401 | case wxPRINT_QUALITY_LOW: { | |
402 | quality = DMRES_LOW; break; | |
403 | } | |
404 | case wxPRINT_QUALITY_DRAFT: { | |
405 | quality = DMRES_DRAFT; break; | |
406 | } | |
407 | case wxPRINT_QUALITY_HIGH: { | |
408 | quality = DMRES_HIGH; break; | |
409 | } | |
410 | default: { | |
411 | quality = m_printQuality; break; | |
412 | } | |
413 | } | |
414 | devMode->dmPrintQuality = quality; | |
415 | devMode->dmFields |= DM_PRINTQUALITY; | |
8826f46f | 416 | |
7bcb11d3 | 417 | GlobalUnlock(hDevMode); |
c801d85f | 418 | } |
7bcb11d3 JS |
419 | } |
420 | ||
421 | void wxPrintData::ConvertFromNative() | |
422 | { | |
48c12cb1 | 423 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; |
7bcb11d3 JS |
424 | |
425 | if (!hDevMode) | |
426 | return; | |
427 | ||
428 | if ( hDevMode ) | |
429 | { | |
430 | DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode); | |
8826f46f | 431 | |
c455ab93 | 432 | #ifndef __WXWINE__ |
7bcb11d3 | 433 | //// Orientation |
8826f46f | 434 | |
7bcb11d3 JS |
435 | if (devMode->dmFields & DM_ORIENTATION) |
436 | m_printOrientation = devMode->dmOrientation; | |
c455ab93 | 437 | #endif |
8826f46f | 438 | |
7bcb11d3 | 439 | //// Collation |
8826f46f | 440 | |
25889d3c | 441 | #ifndef __WIN16__ |
7bcb11d3 JS |
442 | if (devMode->dmFields & DM_COLLATE) |
443 | { | |
444 | if (devMode->dmCollate == DMCOLLATE_TRUE) | |
445 | m_printCollate = TRUE; | |
446 | else | |
447 | m_printCollate = FALSE; | |
448 | } | |
25889d3c | 449 | #endif |
8826f46f | 450 | |
7bcb11d3 | 451 | //// Number of copies |
8826f46f | 452 | |
7bcb11d3 JS |
453 | if (devMode->dmFields & DM_COPIES) |
454 | { | |
455 | m_printNoCopies = devMode->dmCopies; | |
456 | } | |
8826f46f | 457 | |
7bcb11d3 | 458 | //// Printer name |
8826f46f | 459 | |
7bcb11d3 JS |
460 | if (devMode->dmDeviceName[0] != 0) |
461 | { | |
462 | // TODO: make this Unicode compatible | |
463 | char buf[32]; | |
464 | int i = 0; | |
465 | while (devMode->dmDeviceName[i] != 0) | |
466 | { | |
467 | buf[i] = devMode->dmDeviceName[i]; | |
468 | i ++; | |
469 | } | |
470 | buf[i] = 0; | |
8826f46f | 471 | |
7bcb11d3 JS |
472 | m_printerName = buf; |
473 | } | |
8826f46f | 474 | |
7bcb11d3 | 475 | //// Colour |
8826f46f | 476 | |
7bcb11d3 JS |
477 | if (devMode->dmFields & DM_COLOR) |
478 | { | |
479 | if (devMode->dmColor == DMCOLOR_COLOR) | |
480 | m_colour = TRUE; | |
481 | else | |
482 | m_colour = FALSE; | |
483 | } | |
484 | else | |
485 | m_colour = TRUE; | |
8826f46f | 486 | |
c455ab93 | 487 | #ifndef __WXWINE__ |
7bcb11d3 | 488 | //// Paper size |
8826f46f | 489 | |
7bcb11d3 JS |
490 | if (devMode->dmFields & DM_PAPERSIZE) |
491 | { | |
492 | if (wxThePrintPaperDatabase) | |
493 | { | |
494 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize); | |
495 | if (paper) | |
496 | { | |
497 | m_paperId = paper->GetId(); | |
498 | m_paperSize.x = paper->GetWidth() / 10 ; | |
499 | m_paperSize.y = paper->GetHeight() / 10 ; | |
500 | } | |
501 | else | |
502 | { | |
503 | // Shouldn't really get here | |
223d09f6 | 504 | wxFAIL_MSG(wxT("Couldn't find paper size in paper database.")); |
8826f46f | 505 | |
7bcb11d3 JS |
506 | m_paperId = wxPAPER_NONE; |
507 | m_paperSize.x = 0; | |
508 | m_paperSize.y = 0; | |
509 | } | |
510 | } | |
511 | else | |
512 | { | |
513 | // Shouldn't really get here | |
223d09f6 | 514 | wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative.")); |
8826f46f | 515 | |
7bcb11d3 JS |
516 | m_paperId = wxPAPER_NONE; |
517 | m_paperSize.x = 0; | |
518 | m_paperSize.y = 0; | |
519 | } | |
520 | } | |
521 | else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH)) | |
522 | { | |
523 | m_paperSize.x = devMode->dmPaperWidth / 10; | |
524 | m_paperSize.y = devMode->dmPaperLength / 10; | |
525 | m_paperId = wxPAPER_NONE; | |
526 | } | |
527 | else | |
528 | { | |
529 | // Shouldn't really get here | |
223d09f6 | 530 | wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE.")); |
8826f46f | 531 | |
7bcb11d3 JS |
532 | m_paperSize.x = 0; |
533 | m_paperSize.y = 0; | |
534 | m_paperId = wxPAPER_NONE; | |
535 | } | |
c455ab93 | 536 | #endif |
8826f46f | 537 | |
7bcb11d3 | 538 | //// Duplex |
8826f46f | 539 | |
7bcb11d3 JS |
540 | if (devMode->dmFields & DM_DUPLEX) |
541 | { | |
542 | switch (devMode->dmDuplex) | |
543 | { | |
544 | case DMDUP_HORIZONTAL: { | |
545 | m_duplexMode = wxDUPLEX_HORIZONTAL; break; | |
546 | } | |
547 | case DMDUP_VERTICAL: { | |
548 | m_duplexMode = wxDUPLEX_VERTICAL; break; | |
549 | } | |
550 | default: | |
551 | case DMDUP_SIMPLEX: { | |
552 | m_duplexMode = wxDUPLEX_SIMPLEX; break; | |
553 | } | |
554 | } | |
555 | } | |
556 | else | |
557 | m_duplexMode = wxDUPLEX_SIMPLEX; | |
8826f46f | 558 | |
7bcb11d3 | 559 | //// Quality |
8826f46f | 560 | |
7bcb11d3 JS |
561 | if (devMode->dmFields & DM_PRINTQUALITY) |
562 | { | |
563 | switch (devMode->dmPrintQuality) | |
564 | { | |
565 | case DMRES_MEDIUM: { | |
566 | m_printQuality = wxPRINT_QUALITY_MEDIUM; break; | |
567 | } | |
568 | case DMRES_LOW: { | |
569 | m_printQuality = wxPRINT_QUALITY_LOW; break; | |
570 | } | |
571 | case DMRES_DRAFT: { | |
572 | m_printQuality = wxPRINT_QUALITY_DRAFT; break; | |
573 | } | |
574 | case DMRES_HIGH: { | |
575 | m_printQuality = wxPRINT_QUALITY_HIGH; break; | |
576 | } | |
577 | default: | |
578 | { | |
579 | // TODO: if the printer fills in the resolution in DPI, how | |
580 | // will the application know if it's high, low, draft etc.?? | |
581 | // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values."); | |
582 | m_printQuality = devMode->dmPrintQuality; break; | |
8826f46f | 583 | |
7bcb11d3 JS |
584 | } |
585 | } | |
586 | } | |
587 | else | |
588 | m_printQuality = wxPRINT_QUALITY_HIGH; | |
8826f46f | 589 | |
7bcb11d3 JS |
590 | GlobalUnlock(hDevMode); |
591 | } | |
592 | } | |
c801d85f | 593 | |
7bcb11d3 JS |
594 | #endif |
595 | ||
596 | void wxPrintData::operator=(const wxPrintData& data) | |
597 | { | |
598 | m_printNoCopies = data.m_printNoCopies; | |
599 | m_printCollate = data.m_printCollate; | |
600 | m_printOrientation = data.m_printOrientation; | |
601 | m_printerName = data.m_printerName; | |
602 | m_colour = data.m_colour; | |
603 | m_duplexMode = data.m_duplexMode; | |
604 | m_printQuality = data.m_printQuality; | |
605 | m_paperId = data.m_paperId; | |
606 | m_paperSize = data.m_paperSize; | |
607 | ||
608 | // PostScript-specific data | |
609 | m_printerCommand = data.m_printerCommand; | |
610 | m_previewCommand = data.m_previewCommand; | |
611 | m_printerOptions = data.m_printerOptions; | |
612 | m_filename = data.m_filename; | |
613 | m_afmPath = data.m_afmPath; | |
614 | m_printerScaleX = data.m_printerScaleX; | |
615 | m_printerScaleY = data.m_printerScaleY; | |
616 | m_printerTranslateX = data.m_printerTranslateX; | |
617 | m_printerTranslateY = data.m_printerTranslateY; | |
618 | m_printMode = data.m_printMode; | |
619 | } | |
620 | ||
621 | // For compatibility | |
8826f46f | 622 | #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA |
7bcb11d3 JS |
623 | void wxPrintData::operator=(const wxPrintSetupData& setupData) |
624 | { | |
625 | SetPrinterCommand(setupData.GetPrinterCommand()); | |
626 | SetPreviewCommand(setupData.GetPrintPreviewCommand()); | |
627 | SetPrinterOptions(setupData.GetPrinterOptions()); | |
628 | ||
629 | long xt, yt; | |
630 | setupData.GetPrinterTranslation(& xt, & yt); | |
631 | SetPrinterTranslation(xt, yt); | |
632 | ||
633 | double xs, ys; | |
634 | setupData.GetPrinterScaling(& xs, & ys); | |
635 | SetPrinterScaling(xs, ys); | |
636 | ||
637 | SetOrientation(setupData.GetPrinterOrientation()); | |
638 | SetPrintMode((wxPrintMode) setupData.GetPrinterMode()); | |
639 | SetFontMetricPath(setupData.GetAFMPath()); | |
640 | if (setupData.GetPaperName() != "") | |
641 | SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(setupData.GetPaperName())); | |
642 | SetColour(setupData.GetColour()); | |
643 | SetFilename(setupData.GetPrinterFile()); | |
644 | } | |
8826f46f | 645 | #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA |
7bcb11d3 | 646 | |
8826f46f VZ |
647 | |
648 | // ---------------------------------------------------------------------------- | |
649 | // Print dialog data | |
650 | // ---------------------------------------------------------------------------- | |
7bcb11d3 JS |
651 | |
652 | wxPrintDialogData::wxPrintDialogData() | |
653 | { | |
654 | #ifdef __WXMSW__ | |
655 | m_printDlgData = NULL; | |
656 | #endif | |
657 | m_printFromPage = 0; | |
658 | m_printToPage = 0; | |
659 | m_printMinPage = 0; | |
660 | m_printMaxPage = 0; | |
661 | m_printNoCopies = 1; | |
662 | m_printAllPages = FALSE; | |
663 | m_printCollate = FALSE; | |
664 | m_printToFile = FALSE; | |
5360828d | 665 | m_printSelection = FALSE; |
7bcb11d3 JS |
666 | m_printEnableSelection = FALSE; |
667 | m_printEnablePageNumbers = TRUE; | |
668 | m_printEnablePrintToFile = TRUE; | |
669 | m_printEnableHelp = FALSE; | |
670 | m_printSetupDialog = FALSE; | |
671 | } | |
672 | ||
673 | wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData) | |
674 | { | |
675 | (*this) = dialogData; | |
676 | } | |
677 | ||
678 | wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData) | |
679 | { | |
680 | #ifdef __WXMSW__ | |
681 | m_printDlgData = NULL; | |
682 | #endif | |
683 | m_printFromPage = 0; | |
684 | m_printToPage = 0; | |
685 | m_printMinPage = 0; | |
686 | m_printMaxPage = 0; | |
687 | m_printNoCopies = 1; | |
688 | m_printAllPages = FALSE; | |
689 | m_printCollate = FALSE; | |
690 | m_printToFile = FALSE; | |
5360828d | 691 | m_printSelection = FALSE; |
7bcb11d3 JS |
692 | m_printEnableSelection = FALSE; |
693 | m_printEnablePageNumbers = TRUE; | |
694 | m_printEnablePrintToFile = TRUE; | |
695 | m_printEnableHelp = FALSE; | |
696 | m_printSetupDialog = FALSE; | |
697 | ||
698 | m_printData = printData; | |
699 | } | |
700 | ||
701 | wxPrintDialogData::~wxPrintDialogData() | |
702 | { | |
703 | #ifdef __WXMSW__ | |
704 | PRINTDLG *pd = (PRINTDLG *) m_printDlgData; | |
705 | if ( pd && pd->hDevMode ) | |
706 | GlobalFree(pd->hDevMode); | |
707 | if ( pd ) | |
708 | delete pd; | |
709 | #endif | |
710 | } | |
711 | ||
712 | #ifdef __WXMSW__ | |
713 | void wxPrintDialogData::ConvertToNative() | |
714 | { | |
715 | m_printData.ConvertToNative(); | |
716 | ||
717 | PRINTDLG *pd = (PRINTDLG*) m_printDlgData; | |
718 | ||
719 | if (!pd) | |
720 | { | |
721 | pd = new PRINTDLG; | |
722 | m_printDlgData = (void*) pd; | |
723 | ||
724 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. | |
725 | #ifdef __GNUWIN32__ | |
726 | pd->lStructSize = 66 ; | |
727 | #else | |
7bcb11d3 | 728 | pd->lStructSize = sizeof(PRINTDLG); |
25889d3c | 729 | #endif |
7bcb11d3 JS |
730 | pd->hwndOwner = (HWND)NULL; |
731 | pd->hDevMode = NULL; // Will be created by PrintDlg | |
732 | pd->hDevNames = NULL; // Ditto | |
733 | ||
734 | pd->Flags = PD_RETURNDEFAULT; | |
735 | pd->nCopies = 1; | |
736 | } | |
737 | ||
738 | // Pass the devmode data to the PRINTDLG structure, since it'll | |
739 | // be needed when PrintDlg is called. | |
740 | if (pd->hDevMode) | |
741 | { | |
742 | GlobalFree(pd->hDevMode); | |
743 | } | |
744 | ||
48c12cb1 | 745 | pd->hDevMode = (HGLOBAL)(DWORD) m_printData.GetNativeData(); |
7bcb11d3 JS |
746 | |
747 | m_printData.SetNativeData((void*) NULL); | |
748 | ||
223d09f6 | 749 | wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); |
7bcb11d3 JS |
750 | |
751 | pd->hDC = (HDC) NULL; | |
752 | pd->nFromPage = (UINT)m_printFromPage; | |
753 | pd->nToPage = (UINT)m_printToPage; | |
754 | pd->nMinPage = (UINT)m_printMinPage; | |
755 | pd->nMaxPage = (UINT)m_printMaxPage; | |
756 | pd->nCopies = (UINT)m_printNoCopies; | |
8826f46f | 757 | |
c801d85f | 758 | pd->Flags = PD_RETURNDC ; |
7bcb11d3 JS |
759 | |
760 | #ifdef __GNUWIN32__ | |
c801d85f | 761 | pd->lStructSize = 66 ; |
7bcb11d3 JS |
762 | #else |
763 | pd->lStructSize = sizeof( PRINTDLG ); | |
764 | #endif | |
765 | ||
8b9518ee | 766 | pd->hwndOwner=(HWND)NULL; |
c801d85f KB |
767 | pd->hDevNames=(HANDLE)NULL; |
768 | pd->hInstance=(HINSTANCE)NULL; | |
769 | pd->lCustData = (LPARAM) NULL; | |
770 | pd->lpfnPrintHook = NULL; | |
771 | pd->lpfnSetupHook = NULL; | |
772 | pd->lpPrintTemplateName = NULL; | |
773 | pd->lpSetupTemplateName = NULL; | |
774 | pd->hPrintTemplate = (HGLOBAL) NULL; | |
775 | pd->hSetupTemplate = (HGLOBAL) NULL; | |
8826f46f | 776 | |
7bcb11d3 | 777 | if ( m_printAllPages ) |
c801d85f | 778 | pd->Flags |= PD_ALLPAGES; |
5360828d JS |
779 | if ( m_printAllPages ) |
780 | pd->Flags |= PD_SELECTION; | |
7bcb11d3 | 781 | if ( m_printCollate ) |
c801d85f | 782 | pd->Flags |= PD_COLLATE; |
7bcb11d3 | 783 | if ( m_printToFile ) |
c801d85f | 784 | pd->Flags |= PD_PRINTTOFILE; |
7bcb11d3 | 785 | if ( !m_printEnablePrintToFile ) |
c801d85f | 786 | pd->Flags |= PD_DISABLEPRINTTOFILE; |
7bcb11d3 JS |
787 | if ( !m_printEnableSelection ) |
788 | pd->Flags |= PD_NOSELECTION; | |
789 | if ( !m_printEnablePageNumbers ) | |
790 | pd->Flags |= PD_NOPAGENUMS; | |
791 | if ( m_printEnableHelp ) | |
792 | pd->Flags |= PD_SHOWHELP; | |
793 | if ( m_printSetupDialog ) | |
794 | pd->Flags |= PD_PRINTSETUP; | |
c801d85f KB |
795 | } |
796 | ||
7bcb11d3 | 797 | void wxPrintDialogData::ConvertFromNative() |
c801d85f | 798 | { |
7bcb11d3 | 799 | PRINTDLG *pd = (PRINTDLG*) m_printDlgData; |
c801d85f KB |
800 | if ( pd == NULL ) |
801 | return; | |
802 | ||
7bcb11d3 JS |
803 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
804 | if (pd->hDevMode) | |
c801d85f | 805 | { |
7bcb11d3 JS |
806 | if (m_printData.GetNativeData()) |
807 | { | |
808 | // Make sure we don't leak memory | |
48c12cb1 | 809 | GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeData()); |
7bcb11d3 | 810 | } |
aeb50f86 | 811 | m_printData.SetNativeData((void*)(long) pd->hDevMode); |
7bcb11d3 | 812 | pd->hDevMode = NULL; |
c801d85f | 813 | } |
c801d85f | 814 | |
7bcb11d3 JS |
815 | // Now convert the DEVMODE object, passed down from the PRINTDLG object, |
816 | // into wxWindows form. | |
817 | m_printData.ConvertFromNative(); | |
818 | ||
819 | m_printFromPage = pd->nFromPage ; | |
820 | m_printToPage = pd->nToPage ; | |
821 | m_printMinPage = pd->nMinPage ; | |
822 | m_printMaxPage = pd->nMaxPage ; | |
823 | m_printNoCopies = pd->nCopies ; | |
8826f46f | 824 | |
7bcb11d3 | 825 | m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES); |
5360828d | 826 | m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION); |
7bcb11d3 JS |
827 | m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE); |
828 | m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE); | |
829 | m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE); | |
830 | m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION); | |
831 | m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS); | |
832 | m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP); | |
833 | m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP); | |
834 | ||
835 | /* port is obsolete in WIN32 | |
836 | // Get the port name | |
837 | if (pd->hDevNames) | |
838 | { | |
839 | LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames); | |
840 | if (lpDevNames) { | |
841 | m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset); | |
842 | wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
843 | GlobalUnlock(pd->hDevNames); | |
8826f46f | 844 | |
7bcb11d3 JS |
845 | // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); |
846 | } | |
847 | } | |
848 | */ | |
c801d85f KB |
849 | } |
850 | ||
7bcb11d3 | 851 | void wxPrintDialogData::SetOwnerWindow(wxWindow* win) |
c801d85f | 852 | { |
7bcb11d3 | 853 | if ( m_printDlgData == NULL ) |
c801d85f | 854 | ConvertToNative(); |
8826f46f | 855 | |
7bcb11d3 | 856 | if ( m_printDlgData != NULL && win != NULL) |
c801d85f | 857 | { |
7bcb11d3 JS |
858 | PRINTDLG *pd = (PRINTDLG *) m_printDlgData ; |
859 | pd->hwndOwner=(HWND) win->GetHWND(); | |
c801d85f KB |
860 | } |
861 | } | |
8826f46f | 862 | #endif // MSW |
c801d85f | 863 | |
7bcb11d3 | 864 | void wxPrintDialogData::operator=(const wxPrintDialogData& data) |
c801d85f | 865 | { |
7bcb11d3 JS |
866 | m_printFromPage = data.m_printFromPage; |
867 | m_printToPage = data.m_printToPage; | |
868 | m_printMinPage = data.m_printMinPage; | |
869 | m_printMaxPage = data.m_printMaxPage; | |
870 | m_printNoCopies = data.m_printNoCopies; | |
871 | m_printAllPages = data.m_printAllPages; | |
872 | m_printCollate = data.m_printCollate; | |
873 | m_printToFile = data.m_printToFile; | |
5360828d | 874 | m_printSelection = data.m_printSelection; |
7bcb11d3 JS |
875 | m_printEnableSelection = data.m_printEnableSelection; |
876 | m_printEnablePageNumbers = data.m_printEnablePageNumbers; | |
877 | m_printEnableHelp = data.m_printEnableHelp; | |
878 | m_printEnablePrintToFile = data.m_printEnablePrintToFile; | |
879 | m_printSetupDialog = data.m_printSetupDialog; | |
880 | ||
881 | m_printData = data.m_printData; | |
882 | } | |
883 | ||
884 | void wxPrintDialogData::operator=(const wxPrintData& data) | |
885 | { | |
886 | m_printData = data; | |
c801d85f KB |
887 | } |
888 | ||
8826f46f VZ |
889 | // ---------------------------------------------------------------------------- |
890 | // wxPageSetupDialogData | |
891 | // ---------------------------------------------------------------------------- | |
c801d85f | 892 | |
7bcb11d3 | 893 | wxPageSetupDialogData::wxPageSetupDialogData() |
c801d85f KB |
894 | { |
895 | #if defined(__WIN95__) | |
7bcb11d3 | 896 | m_pageSetupData = NULL; |
c801d85f | 897 | #endif |
7bcb11d3 JS |
898 | m_paperSize = wxSize(0, 0); |
899 | ||
900 | CalculatePaperSizeFromId(); | |
901 | ||
902 | m_minMarginTopLeft = wxPoint(0, 0); | |
903 | m_minMarginBottomRight = wxPoint(0, 0); | |
904 | m_marginTopLeft = wxPoint(0, 0); | |
905 | m_marginBottomRight = wxPoint(0, 0); | |
906 | ||
907 | // Flags | |
908 | m_defaultMinMargins = FALSE; | |
909 | m_enableMargins = TRUE; | |
910 | m_enableOrientation = TRUE; | |
911 | m_enablePaper = TRUE; | |
912 | m_enablePrinter = TRUE; | |
913 | m_enableHelp = FALSE; | |
914 | m_getDefaultInfo = FALSE; | |
915 | } | |
c801d85f | 916 | |
7bcb11d3 JS |
917 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData) |
918 | { | |
919 | (*this) = dialogData; | |
920 | } | |
921 | ||
922 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData) | |
923 | { | |
924 | #if defined(__WIN95__) | |
925 | m_pageSetupData = NULL; | |
926 | #endif | |
927 | m_paperSize = wxSize(0, 0); | |
928 | m_minMarginTopLeft = wxPoint(0, 0); | |
929 | m_minMarginBottomRight = wxPoint(0, 0); | |
930 | m_marginTopLeft = wxPoint(0, 0); | |
931 | m_marginBottomRight = wxPoint(0, 0); | |
932 | ||
933 | // Flags | |
934 | m_defaultMinMargins = FALSE; | |
935 | m_enableMargins = TRUE; | |
936 | m_enableOrientation = TRUE; | |
937 | m_enablePaper = TRUE; | |
938 | m_enablePrinter = TRUE; | |
939 | m_enableHelp = FALSE; | |
940 | m_getDefaultInfo = FALSE; | |
941 | ||
942 | m_printData = printData; | |
943 | ||
944 | // The wxPrintData paper size overrides these values, unless the size cannot | |
945 | // be found. | |
946 | CalculatePaperSizeFromId(); | |
c801d85f KB |
947 | } |
948 | ||
7bcb11d3 | 949 | wxPageSetupDialogData::~wxPageSetupDialogData() |
c801d85f | 950 | { |
34138703 | 951 | #if defined(__WIN95__) && defined(__WXMSW__) |
c801d85f KB |
952 | PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData; |
953 | if ( pd && pd->hDevMode ) | |
954 | GlobalFree(pd->hDevMode); | |
955 | if ( pd ) | |
956 | delete pd; | |
957 | #endif | |
958 | } | |
959 | ||
7bcb11d3 | 960 | void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data) |
c801d85f | 961 | { |
7bcb11d3 JS |
962 | m_paperSize = data.m_paperSize; |
963 | m_minMarginTopLeft = data.m_minMarginTopLeft; | |
964 | m_minMarginBottomRight = data.m_minMarginBottomRight; | |
965 | m_marginTopLeft = data.m_marginTopLeft; | |
966 | m_marginBottomRight = data.m_marginBottomRight; | |
967 | m_defaultMinMargins = data.m_defaultMinMargins; | |
968 | m_enableMargins = data.m_enableMargins; | |
969 | m_enableOrientation = data.m_enableOrientation; | |
970 | m_enablePaper = data.m_enablePaper; | |
971 | m_enablePrinter = data.m_enablePrinter; | |
972 | m_getDefaultInfo = data.m_getDefaultInfo;; | |
973 | m_enableHelp = data.m_enableHelp; | |
974 | ||
975 | m_printData = data.m_printData; | |
976 | } | |
c801d85f | 977 | |
7bcb11d3 JS |
978 | void wxPageSetupDialogData::operator=(const wxPrintData& data) |
979 | { | |
980 | m_printData = data; | |
c801d85f KB |
981 | } |
982 | ||
8826f46f | 983 | #if defined(__WIN95__) |
7bcb11d3 | 984 | void wxPageSetupDialogData::ConvertToNative() |
c801d85f | 985 | { |
7bcb11d3 JS |
986 | m_printData.ConvertToNative(); |
987 | ||
c801d85f | 988 | PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData; |
7bcb11d3 | 989 | |
c801d85f KB |
990 | if ( m_pageSetupData == NULL ) |
991 | { | |
7bcb11d3 JS |
992 | pd = new PAGESETUPDLG; |
993 | pd->hDevMode = NULL; | |
994 | m_pageSetupData = (void *)pd; | |
c801d85f | 995 | } |
8bbe427f | 996 | |
7bcb11d3 JS |
997 | // Pass the devmode data (created in m_printData.ConvertToNative) |
998 | // to the PRINTDLG structure, since it'll | |
999 | // be needed when PrintDlg is called. | |
1000 | ||
1001 | if (pd->hDevMode) | |
1002 | { | |
1003 | GlobalFree(pd->hDevMode); | |
1004 | pd->hDevMode = NULL; | |
1005 | } | |
1006 | ||
7bcb11d3 JS |
1007 | pd->hDevMode = (HGLOBAL) m_printData.GetNativeData(); |
1008 | ||
1009 | m_printData.SetNativeData((void*) NULL); | |
1010 | ||
223d09f6 | 1011 | wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); |
7bcb11d3 JS |
1012 | |
1013 | // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE)); | |
c801d85f | 1014 | |
7bcb11d3 | 1015 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; |
8826f46f | 1016 | |
c801d85f KB |
1017 | if ( m_defaultMinMargins ) |
1018 | pd->Flags |= PSD_DEFAULTMINMARGINS; | |
1019 | if ( !m_enableMargins ) | |
1020 | pd->Flags |= PSD_DISABLEMARGINS; | |
1021 | if ( !m_enableOrientation ) | |
1022 | pd->Flags |= PSD_DISABLEORIENTATION; | |
1023 | if ( !m_enablePaper ) | |
1024 | pd->Flags |= PSD_DISABLEPAPER; | |
1025 | if ( !m_enablePrinter ) | |
1026 | pd->Flags |= PSD_DISABLEPRINTER; | |
1027 | if ( m_getDefaultInfo ) | |
1028 | pd->Flags |= PSD_RETURNDEFAULT; | |
1029 | if ( m_enableHelp ) | |
1030 | pd->Flags |= PSD_SHOWHELP; | |
1031 | ||
7bcb11d3 JS |
1032 | // We want the units to be in hundredths of a millimetre |
1033 | pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS; | |
1034 | ||
c801d85f | 1035 | pd->lStructSize = sizeof( PAGESETUPDLG ); |
c4e7c2aa | 1036 | pd->hwndOwner=(HWND)NULL; |
c801d85f KB |
1037 | pd->hDevNames=(HWND)NULL; |
1038 | pd->hInstance=(HINSTANCE)NULL; | |
8826f46f | 1039 | |
7bcb11d3 JS |
1040 | pd->ptPaperSize.x = m_paperSize.x * 100; |
1041 | pd->ptPaperSize.y = m_paperSize.y * 100; | |
8826f46f | 1042 | |
7bcb11d3 JS |
1043 | pd->rtMinMargin.left = m_minMarginTopLeft.x * 100; |
1044 | pd->rtMinMargin.top = m_minMarginTopLeft.y * 100; | |
1045 | pd->rtMinMargin.right = m_minMarginBottomRight.x * 100; | |
1046 | pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100; | |
8826f46f | 1047 | |
7bcb11d3 JS |
1048 | pd->rtMargin.left = m_marginTopLeft.x * 100; |
1049 | pd->rtMargin.top = m_marginTopLeft.y * 100; | |
1050 | pd->rtMargin.right = m_marginBottomRight.x * 100; | |
1051 | pd->rtMargin.bottom = m_marginBottomRight.y * 100; | |
8826f46f | 1052 | |
c801d85f KB |
1053 | pd->lCustData = 0; |
1054 | pd->lpfnPageSetupHook = NULL; | |
1055 | pd->lpfnPagePaintHook = NULL; | |
1056 | pd->hPageSetupTemplate = NULL; | |
1057 | pd->lpPageSetupTemplateName = NULL; | |
1058 | ||
8826f46f | 1059 | /* |
c801d85f KB |
1060 | if ( pd->hDevMode ) |
1061 | { | |
1062 | DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); | |
1063 | memset(devMode, 0, sizeof(DEVMODE)); | |
1064 | devMode->dmSize = sizeof(DEVMODE); | |
1065 | devMode->dmOrientation = m_orientation; | |
1066 | devMode->dmFields = DM_ORIENTATION; | |
1067 | GlobalUnlock(pd->hDevMode); | |
1068 | } | |
7bcb11d3 | 1069 | */ |
c801d85f KB |
1070 | } |
1071 | ||
7bcb11d3 | 1072 | void wxPageSetupDialogData::ConvertFromNative() |
c801d85f KB |
1073 | { |
1074 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ; | |
1075 | if ( !pd ) | |
1076 | return; | |
8826f46f | 1077 | |
7bcb11d3 JS |
1078 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
1079 | if (pd->hDevMode) | |
1080 | { | |
1081 | if (m_printData.GetNativeData()) | |
1082 | { | |
1083 | // Make sure we don't leak memory | |
1084 | GlobalFree((HGLOBAL) m_printData.GetNativeData()); | |
1085 | } | |
1086 | m_printData.SetNativeData((void*) pd->hDevMode); | |
1087 | pd->hDevMode = NULL; | |
1088 | } | |
c801d85f | 1089 | |
7bcb11d3 | 1090 | m_printData.ConvertFromNative(); |
c801d85f | 1091 | |
7bcb11d3 | 1092 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; |
8826f46f | 1093 | |
c801d85f KB |
1094 | m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS); |
1095 | m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS); | |
1096 | m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION); | |
1097 | m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER); | |
1098 | m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER); | |
1099 | m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT); | |
1100 | m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP); | |
8826f46f | 1101 | |
7bcb11d3 JS |
1102 | m_paperSize.x = pd->ptPaperSize.x / 100; |
1103 | m_paperSize.y = pd->ptPaperSize.y / 100; | |
8826f46f | 1104 | |
7bcb11d3 JS |
1105 | m_minMarginTopLeft.x = pd->rtMinMargin.left / 100; |
1106 | m_minMarginTopLeft.y = pd->rtMinMargin.top / 100; | |
1107 | m_minMarginBottomRight.x = pd->rtMinMargin.right / 100; | |
1108 | m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100; | |
8826f46f | 1109 | |
7bcb11d3 JS |
1110 | m_marginTopLeft.x = pd->rtMargin.left / 100 ; |
1111 | m_marginTopLeft.y = pd->rtMargin.top / 100 ; | |
1112 | m_marginBottomRight.x = pd->rtMargin.right / 100 ; | |
1113 | m_marginBottomRight.y = pd->rtMargin.bottom / 100 ; | |
1114 | } | |
c801d85f | 1115 | |
7bcb11d3 JS |
1116 | void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win) |
1117 | { | |
1118 | if ( m_pageSetupData == NULL ) | |
1119 | ConvertToNative(); | |
8826f46f | 1120 | |
7bcb11d3 JS |
1121 | if ( m_pageSetupData != NULL && win != NULL) |
1122 | { | |
1123 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ; | |
1124 | pd->hwndOwner=(HWND) win->GetHWND(); | |
1125 | } | |
1126 | } | |
8826f46f | 1127 | #endif // Win95 |
c801d85f | 1128 | |
7bcb11d3 JS |
1129 | // If a corresponding paper type is found in the paper database, will set the m_printData |
1130 | // paper size id member as well. | |
1131 | void wxPageSetupDialogData::SetPaperSize(const wxSize& sz) | |
1132 | { | |
1133 | m_paperSize = sz; | |
c801d85f | 1134 | |
7bcb11d3 JS |
1135 | CalculateIdFromPaperSize(); |
1136 | } | |
c801d85f | 1137 | |
7bcb11d3 JS |
1138 | // Sets the wxPrintData id, plus the paper width/height if found in the paper database. |
1139 | void wxPageSetupDialogData::SetPaperSize(wxPaperSize id) | |
1140 | { | |
1141 | m_printData.SetPaperId(id); | |
1142 | ||
1143 | CalculatePaperSizeFromId(); | |
c801d85f KB |
1144 | } |
1145 | ||
7bcb11d3 JS |
1146 | // Use paper size defined in this object to set the wxPrintData |
1147 | // paper id | |
1148 | void wxPageSetupDialogData::CalculateIdFromPaperSize() | |
c801d85f | 1149 | { |
8826f46f | 1150 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), |
223d09f6 | 1151 | wxT("wxThePrintPaperDatabase should not be NULL. " |
60df2e7d | 1152 | "Do not create global print dialog data objects.") ); |
c801d85f | 1153 | |
7bcb11d3 JS |
1154 | wxSize sz = GetPaperSize(); |
1155 | ||
1156 | wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10)); | |
1157 | if (id != wxPAPER_NONE) | |
c801d85f | 1158 | { |
7bcb11d3 | 1159 | m_printData.SetPaperId(id); |
c801d85f KB |
1160 | } |
1161 | } | |
8826f46f | 1162 | |
7bcb11d3 JS |
1163 | // Use paper id in wxPrintData to set this object's paper size |
1164 | void wxPageSetupDialogData::CalculatePaperSizeFromId() | |
1165 | { | |
8826f46f | 1166 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), |
223d09f6 | 1167 | wxT("wxThePrintPaperDatabase should not be NULL. " |
60df2e7d | 1168 | "Do not create global print dialog data objects.") ); |
7bcb11d3 JS |
1169 | |
1170 | wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId()); | |
c801d85f | 1171 | |
7bcb11d3 JS |
1172 | if (sz.x != 0) |
1173 | { | |
1174 | // sz is in 10ths of a mm, so multiply by 10. | |
1175 | m_paperSize.x = sz.x * 10; | |
1176 | m_paperSize.y = sz.y * 10; | |
1177 | } | |
1178 | } | |
8826f46f | 1179 | |
88ac883a | 1180 | #endif // wxUSE_PRINTING_ARCHITECTURE |