]>
Commit | Line | Data |
---|---|---|
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "cmndata.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include <stdio.h> | |
33 | #include "wx/string.h" | |
34 | #include "wx/utils.h" | |
35 | #include "wx/app.h" | |
36 | #endif | |
37 | ||
38 | #include "wx/gdicmn.h" | |
39 | #include "wx/cmndata.h" | |
40 | #include "wx/log.h" | |
41 | ||
42 | // For compatibility | |
43 | #if (defined(__WXMOTIF__) || defined(__WXGTK__) || defined(__WXPM__) || defined(__WXMAC__)) && wxUSE_POSTSCRIPT | |
44 | #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1 | |
45 | #endif | |
46 | ||
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 | |
54 | ||
55 | #ifdef __WXMSW__ | |
56 | #include <windows.h> | |
57 | #include "wx/msw/private.h" | |
58 | ||
59 | #if !defined(__WIN32__) | |
60 | #include <print.h> | |
61 | #include <commdlg.h> | |
62 | #endif // Win16 | |
63 | ||
64 | #ifdef __WXWINE__ | |
65 | #include <cderr.h> | |
66 | #include <commdlg.h> | |
67 | #endif | |
68 | ||
69 | #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__) | |
70 | #include <windowsx.h> | |
71 | #include <commdlg.h> | |
72 | #endif | |
73 | #endif // MSW | |
74 | ||
75 | #if wxUSE_PRINTING_ARCHITECTURE | |
76 | IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject) | |
77 | IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject) | |
78 | IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject) | |
79 | #endif // wxUSE_PRINTING_ARCHITECTURE | |
80 | ||
81 | IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject) | |
82 | IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject) | |
83 | ||
84 | #ifdef __WXMAC__ | |
85 | #define mm2pt 2.83464566929 | |
86 | #define pt2mm 0.352777777778 | |
87 | #endif // Mac | |
88 | ||
89 | #ifndef DMPAPER_USER | |
90 | #define DMPAPER_USER 256 | |
91 | #endif | |
92 | ||
93 | // ============================================================================ | |
94 | // implementation | |
95 | // ============================================================================ | |
96 | ||
97 | // ---------------------------------------------------------------------------- | |
98 | // wxColourData | |
99 | // ---------------------------------------------------------------------------- | |
100 | ||
101 | wxColourData::wxColourData() | |
102 | { | |
103 | int i; | |
104 | for (i = 0; i < 16; i++) | |
105 | custColours[i].Set(255, 255, 255); | |
106 | ||
107 | chooseFull = FALSE; | |
108 | dataColour.Set(0,0,0); | |
109 | } | |
110 | ||
111 | wxColourData::wxColourData(const wxColourData& data) | |
112 | { | |
113 | (*this) = data; | |
114 | } | |
115 | ||
116 | wxColourData::~wxColourData() | |
117 | { | |
118 | } | |
119 | ||
120 | void wxColourData::SetCustomColour(int i, wxColour& colour) | |
121 | { | |
122 | if (i > 15 || i < 0) | |
123 | return; | |
124 | ||
125 | custColours[i] = colour; | |
126 | } | |
127 | ||
128 | wxColour wxColourData::GetCustomColour(int i) | |
129 | { | |
130 | if (i > 15 || i < 0) | |
131 | return wxColour(0,0,0); | |
132 | ||
133 | return custColours[i]; | |
134 | } | |
135 | ||
136 | void wxColourData::operator=(const wxColourData& data) | |
137 | { | |
138 | int i; | |
139 | for (i = 0; i < 16; i++) | |
140 | custColours[i] = data.custColours[i]; | |
141 | ||
142 | dataColour = (wxColour&)data.dataColour; | |
143 | chooseFull = data.chooseFull; | |
144 | } | |
145 | ||
146 | // ---------------------------------------------------------------------------- | |
147 | // Font data | |
148 | // ---------------------------------------------------------------------------- | |
149 | ||
150 | wxFontData::wxFontData() | |
151 | { | |
152 | // Intialize colour to black. | |
153 | fontColour.Set(0, 0, 0); | |
154 | ||
155 | showHelp = FALSE; | |
156 | allowSymbols = TRUE; | |
157 | enableEffects = TRUE; | |
158 | minSize = 0; | |
159 | maxSize = 0; | |
160 | ||
161 | m_encoding = wxFONTENCODING_SYSTEM; | |
162 | } | |
163 | ||
164 | wxFontData::~wxFontData() | |
165 | { | |
166 | } | |
167 | ||
168 | #if wxUSE_PRINTING_ARCHITECTURE | |
169 | // ---------------------------------------------------------------------------- | |
170 | // Print data | |
171 | // ---------------------------------------------------------------------------- | |
172 | ||
173 | wxPrintData::wxPrintData() | |
174 | { | |
175 | #ifdef __WXMSW__ | |
176 | m_devMode = (void*) NULL; | |
177 | m_devNames = (void*) NULL; | |
178 | #elif defined( __WXMAC__ ) | |
179 | #if TARGET_CARBON | |
180 | m_macPageFormat = kPMNoPageFormat; | |
181 | m_macPrintSettings = kPMNoPrintSettings; | |
182 | #else | |
183 | m_macPrintInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ); | |
184 | (**m_macPrintInfo).iPrVersion = 0; // something invalid | |
185 | ||
186 | (**m_macPrintInfo).prInfo.iHRes = 72; | |
187 | (**m_macPrintInfo).prInfo.iVRes = 72; | |
188 | Rect r1 = { 0, 0, 8*72 - 2 * 18, 11*72 - 2 * 36 }; | |
189 | (**m_macPrintInfo).prInfo.rPage = r1;// must have its top left & (0,0) | |
190 | ||
191 | Rect r2 = { -18, -36, 8*72 - 18, 11*72 - 36 }; | |
192 | (**m_macPrintInfo).rPaper = r2; | |
193 | (**m_macPrintInfo).prStl.iPageV = 11 * 120 ; // 11 inches in 120th of an inch | |
194 | (**m_macPrintInfo).prStl.iPageH = 8 * 120 ; // 8 inches in 120th of an inch | |
195 | #endif | |
196 | #endif | |
197 | m_printOrientation = wxPORTRAIT; | |
198 | m_printNoCopies = 1; | |
199 | m_printCollate = FALSE; | |
200 | ||
201 | // New, 24/3/99 | |
202 | m_printerName = ""; | |
203 | m_colour = TRUE; | |
204 | m_duplexMode = wxDUPLEX_SIMPLEX; | |
205 | m_printQuality = wxPRINT_QUALITY_HIGH; | |
206 | m_paperId = wxPAPER_A4; | |
207 | m_paperSize = wxSize(210, 297); | |
208 | ||
209 | // PostScript-specific data | |
210 | m_printerCommand = ""; | |
211 | m_previewCommand = ""; | |
212 | m_printerOptions = ""; | |
213 | m_filename = ""; | |
214 | m_afmPath = ""; | |
215 | m_printerScaleX = 1.0; | |
216 | m_printerScaleY = 1.0; | |
217 | m_printerTranslateX = 0; | |
218 | m_printerTranslateY = 0; | |
219 | m_printMode = wxPRINT_MODE_FILE; | |
220 | } | |
221 | ||
222 | wxPrintData::wxPrintData(const wxPrintData& printData) | |
223 | { | |
224 | #ifdef __WXMSW__ | |
225 | m_devMode = (void*) NULL; | |
226 | m_devNames = (void*) NULL; | |
227 | #elif defined( __WXMAC__ ) | |
228 | #if TARGET_CARBON | |
229 | m_macPageFormat = kPMNoPageFormat; | |
230 | m_macPrintSettings = kPMNoPrintSettings; | |
231 | #else | |
232 | m_macPrintInfo = NULL; | |
233 | #endif | |
234 | #endif | |
235 | (*this) = printData; | |
236 | } | |
237 | ||
238 | wxPrintData::~wxPrintData() | |
239 | { | |
240 | #ifdef __WXMSW__ | |
241 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; | |
242 | if ( hDevMode ) | |
243 | GlobalFree(hDevMode); | |
244 | HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames; | |
245 | if ( hDevNames ) | |
246 | GlobalFree(hDevNames); | |
247 | #elif defined(__WXMAC__) | |
248 | #if TARGET_CARBON | |
249 | if (m_macPageFormat != kPMNoPageFormat) | |
250 | { | |
251 | #if PM_USE_SESSION_APIS | |
252 | (void)PMRelease(m_macPageFormat); | |
253 | #else | |
254 | (void)PMDisposePageFormat(m_macPageFormat); | |
255 | #endif | |
256 | m_macPageFormat = kPMNoPageFormat; | |
257 | } | |
258 | ||
259 | if (m_macPrintSettings != kPMNoPrintSettings) | |
260 | { | |
261 | #if PM_USE_SESSION_APIS | |
262 | (void)PMRelease(m_macPrintSettings); | |
263 | #else | |
264 | (void)PMDisposePrintSettings(m_macPrintSettings); | |
265 | #endif | |
266 | m_macPrintSettings = kPMNoPrintSettings; | |
267 | } | |
268 | #else | |
269 | wxASSERT( m_macPrintInfo ); | |
270 | // we should perhaps delete | |
271 | #endif | |
272 | #endif | |
273 | } | |
274 | ||
275 | #if defined(__WXMSW__) // && defined(__WIN32__) | |
276 | ||
277 | #if defined(__WXDEBUG__) && defined(__WIN32__) | |
278 | static wxString wxGetPrintDlgError() | |
279 | { | |
280 | DWORD err = CommDlgExtendedError(); | |
281 | wxString msg = wxT("Unknown"); | |
282 | switch (err) | |
283 | { | |
284 | case CDERR_FINDRESFAILURE: msg = wxT("CDERR_FINDRESFAILURE"); break; | |
285 | case CDERR_INITIALIZATION: msg = wxT("CDERR_INITIALIZATION"); break; | |
286 | case CDERR_LOADRESFAILURE: msg = wxT("CDERR_LOADRESFAILURE"); break; | |
287 | case CDERR_LOADSTRFAILURE: msg = wxT("CDERR_LOADSTRFAILURE"); break; | |
288 | case CDERR_LOCKRESFAILURE: msg = wxT("CDERR_LOCKRESFAILURE"); break; | |
289 | case CDERR_MEMALLOCFAILURE: msg = wxT("CDERR_MEMALLOCFAILURE"); break; | |
290 | case CDERR_MEMLOCKFAILURE: msg = wxT("CDERR_MEMLOCKFAILURE"); break; | |
291 | case CDERR_NOHINSTANCE: msg = wxT("CDERR_NOHINSTANCE"); break; | |
292 | case CDERR_NOHOOK: msg = wxT("CDERR_NOHOOK"); break; | |
293 | case CDERR_NOTEMPLATE: msg = wxT("CDERR_NOTEMPLATE"); break; | |
294 | case CDERR_STRUCTSIZE: msg = wxT("CDERR_STRUCTSIZE"); break; | |
295 | case PDERR_RETDEFFAILURE: msg = wxT("PDERR_RETDEFFAILURE"); break; | |
296 | case PDERR_PRINTERNOTFOUND: msg = wxT("PDERR_PRINTERNOTFOUND"); break; | |
297 | case PDERR_PARSEFAILURE: msg = wxT("PDERR_PARSEFAILURE"); break; | |
298 | case PDERR_NODEVICES: msg = wxT("PDERR_NODEVICES"); break; | |
299 | case PDERR_NODEFAULTPRN: msg = wxT("PDERR_NODEFAULTPRN"); break; | |
300 | case PDERR_LOADDRVFAILURE: msg = wxT("PDERR_LOADDRVFAILURE"); break; | |
301 | case PDERR_INITFAILURE: msg = wxT("PDERR_INITFAILURE"); break; | |
302 | case PDERR_GETDEVMODEFAIL: msg = wxT("PDERR_GETDEVMODEFAIL"); break; | |
303 | case PDERR_DNDMMISMATCH: msg = wxT("PDERR_DNDMMISMATCH"); break; | |
304 | case PDERR_DEFAULTDIFFERENT: msg = wxT("PDERR_DEFAULTDIFFERENT"); break; | |
305 | case PDERR_CREATEICFAILURE: msg = wxT("PDERR_CREATEICFAILURE"); break; | |
306 | default: break; | |
307 | } | |
308 | return msg; | |
309 | } | |
310 | #endif | |
311 | ||
312 | static HGLOBAL wxCreateDevNames(const wxString& driverName, const wxString& printerName, const wxString& portName) | |
313 | { | |
314 | HGLOBAL hDev = NULL; | |
315 | // if (!driverName.IsEmpty() && !printerName.IsEmpty() && !portName.IsEmpty()) | |
316 | if (driverName.IsEmpty() && printerName.IsEmpty() && portName.IsEmpty()) | |
317 | { | |
318 | } | |
319 | else | |
320 | { | |
321 | hDev = GlobalAlloc(GPTR, 4*sizeof(WORD)+ | |
322 | ( driverName.Length() + 1 + | |
323 | printerName.Length() + 1 + | |
324 | portName.Length()+1 ) * sizeof(wxChar) ); | |
325 | LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(hDev); | |
326 | lpDev->wDriverOffset = sizeof(WORD)*4; | |
327 | wxStrcpy((wxChar*)((char*)lpDev + lpDev->wDriverOffset ), driverName); | |
328 | ||
329 | lpDev->wDeviceOffset = (WORD)( lpDev->wDriverOffset + | |
330 | sizeof(wxChar) * ( driverName.Length() + 1 ) ); | |
331 | wxStrcpy((wxChar*)((char*)lpDev + lpDev->wDeviceOffset ), printerName); | |
332 | ||
333 | lpDev->wOutputOffset = (WORD)( lpDev->wDeviceOffset + | |
334 | sizeof(wxChar) * ( printerName.Length() + 1 ) ); | |
335 | wxStrcpy((wxChar*)((char*) lpDev + lpDev->wOutputOffset ), portName); | |
336 | ||
337 | lpDev->wDefault = 0; | |
338 | ||
339 | GlobalUnlock(hDev); | |
340 | } | |
341 | ||
342 | return hDev; | |
343 | } | |
344 | ||
345 | void wxPrintData::ConvertToNative() | |
346 | { | |
347 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; | |
348 | HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames; | |
349 | if (!hDevMode) | |
350 | { | |
351 | // Use PRINTDLG as a way of creating a DEVMODE object | |
352 | PRINTDLG pd; | |
353 | ||
354 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. | |
355 | #ifdef __GNUWIN32__ | |
356 | memset(&pd, 0, 66); | |
357 | pd.lStructSize = 66; | |
358 | #else | |
359 | memset(&pd, 0, sizeof(PRINTDLG)); | |
360 | pd.lStructSize = sizeof(PRINTDLG); | |
361 | #endif | |
362 | ||
363 | pd.hwndOwner = (HWND)NULL; | |
364 | pd.hDevMode = NULL; // Will be created by PrintDlg | |
365 | pd.hDevNames = NULL; // Ditto | |
366 | //pd.hInstance = (HINSTANCE) wxGetInstance(); | |
367 | ||
368 | pd.Flags = PD_RETURNDEFAULT; | |
369 | pd.nCopies = 1; | |
370 | ||
371 | // Fill out the DEVMODE structure | |
372 | // so we can use it as input in the 'real' PrintDlg | |
373 | if (!PrintDlg(&pd)) | |
374 | { | |
375 | if ( pd.hDevMode ) | |
376 | GlobalFree(pd.hDevMode); | |
377 | if ( pd.hDevNames ) | |
378 | GlobalFree(pd.hDevNames); | |
379 | pd.hDevMode = NULL; | |
380 | pd.hDevNames = NULL; | |
381 | ||
382 | #if defined(__WXDEBUG__) && defined(__WIN32__) | |
383 | wxString str(wxT("Printing error: ")); | |
384 | str += wxGetPrintDlgError(); | |
385 | wxLogDebug(str); | |
386 | #endif | |
387 | } | |
388 | else | |
389 | { | |
390 | hDevMode = pd.hDevMode; | |
391 | m_devMode = (void*)(long) hDevMode; | |
392 | pd.hDevMode = NULL; | |
393 | ||
394 | // We'll create a new DEVNAMEs structure below. | |
395 | if ( pd.hDevNames ) | |
396 | GlobalFree(pd.hDevNames); | |
397 | pd.hDevNames = NULL; | |
398 | ||
399 | // hDevNames = pd->hDevNames; | |
400 | // m_devNames = (void*)(long) hDevNames; | |
401 | // pd->hDevnames = NULL; | |
402 | ||
403 | } | |
404 | } | |
405 | ||
406 | if ( hDevMode ) | |
407 | { | |
408 | LPDEVMODE devMode = (LPDEVMODE) GlobalLock(hDevMode); | |
409 | ||
410 | //// Orientation | |
411 | ||
412 | #ifndef __WXWINE__ | |
413 | devMode->dmOrientation = m_printOrientation; | |
414 | #endif | |
415 | devMode->dmFields = DM_ORIENTATION; | |
416 | ||
417 | //// Collation | |
418 | ||
419 | #ifndef __WIN16__ | |
420 | devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE); | |
421 | devMode->dmFields |= DM_COLLATE; | |
422 | #endif | |
423 | ||
424 | //// Number of copies | |
425 | ||
426 | devMode->dmCopies = m_printNoCopies; | |
427 | devMode->dmFields |= DM_COPIES; | |
428 | ||
429 | //// Printer name | |
430 | ||
431 | if (m_printerName != wxT("")) | |
432 | { | |
433 | //int len = wxMin(31, m_printerName.Len()); | |
434 | wxStrncpy((wxChar*)devMode->dmDeviceName,m_printerName.c_str(),31); | |
435 | devMode->dmDeviceName[31] = wxT('\0'); | |
436 | } | |
437 | ||
438 | //// Colour | |
439 | ||
440 | if (m_colour) | |
441 | devMode->dmColor = DMCOLOR_COLOR; | |
442 | else | |
443 | devMode->dmColor = DMCOLOR_MONOCHROME; | |
444 | ||
445 | devMode->dmFields |= DM_COLOR; | |
446 | ||
447 | #ifndef __WXWINE__ | |
448 | //// Paper size | |
449 | ||
450 | if (m_paperId == wxPAPER_NONE) | |
451 | { | |
452 | // DEVMODE is in tenths of a milimeter | |
453 | devMode->dmPaperWidth = m_paperSize.x * 10; | |
454 | devMode->dmPaperLength = m_paperSize.y * 10; | |
455 | devMode->dmPaperSize = DMPAPER_USER; | |
456 | devMode->dmFields |= DM_PAPERWIDTH; | |
457 | devMode->dmFields |= DM_PAPERLENGTH; | |
458 | } | |
459 | else | |
460 | { | |
461 | if (wxThePrintPaperDatabase) | |
462 | { | |
463 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId); | |
464 | if (paper) | |
465 | { | |
466 | devMode->dmPaperSize = paper->GetPlatformId(); | |
467 | devMode->dmFields |= DM_PAPERSIZE; | |
468 | } | |
469 | } | |
470 | } | |
471 | #endif | |
472 | ||
473 | //// Duplex | |
474 | ||
475 | int duplex; | |
476 | switch (m_duplexMode) | |
477 | { | |
478 | case wxDUPLEX_HORIZONTAL: { | |
479 | duplex = DMDUP_HORIZONTAL; break; | |
480 | } | |
481 | case wxDUPLEX_VERTICAL: { | |
482 | duplex = DMDUP_VERTICAL; break; | |
483 | } | |
484 | default: | |
485 | case wxDUPLEX_SIMPLEX: { | |
486 | duplex = DMDUP_SIMPLEX; break; | |
487 | } | |
488 | } | |
489 | devMode->dmDuplex = duplex; | |
490 | devMode->dmFields |= DM_DUPLEX; | |
491 | ||
492 | //// Quality | |
493 | ||
494 | int quality; | |
495 | switch (m_printQuality) | |
496 | { | |
497 | case wxPRINT_QUALITY_MEDIUM: { | |
498 | quality = DMRES_MEDIUM; break; | |
499 | } | |
500 | case wxPRINT_QUALITY_LOW: { | |
501 | quality = DMRES_LOW; break; | |
502 | } | |
503 | case wxPRINT_QUALITY_DRAFT: { | |
504 | quality = DMRES_DRAFT; break; | |
505 | } | |
506 | case wxPRINT_QUALITY_HIGH: { | |
507 | quality = DMRES_HIGH; break; | |
508 | } | |
509 | default: { | |
510 | quality = m_printQuality; break; | |
511 | } | |
512 | } | |
513 | devMode->dmPrintQuality = quality; | |
514 | devMode->dmFields |= DM_PRINTQUALITY; | |
515 | ||
516 | GlobalUnlock(hDevMode); | |
517 | } | |
518 | ||
519 | if ( hDevNames ) | |
520 | { | |
521 | GlobalFree(hDevNames); | |
522 | } | |
523 | ||
524 | // TODO: I hope it's OK to pass some empty strings to DEVNAMES. | |
525 | m_devNames = (void*) (long) wxCreateDevNames(wxT(""), m_printerName, wxT("")); | |
526 | } | |
527 | ||
528 | void wxPrintData::ConvertFromNative() | |
529 | { | |
530 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; | |
531 | HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames; | |
532 | ||
533 | if (!hDevMode) | |
534 | return; | |
535 | ||
536 | if ( hDevMode ) | |
537 | { | |
538 | LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode); | |
539 | ||
540 | #ifndef __WXWINE__ | |
541 | //// Orientation | |
542 | ||
543 | if (devMode->dmFields & DM_ORIENTATION) | |
544 | m_printOrientation = devMode->dmOrientation; | |
545 | #endif | |
546 | ||
547 | //// Collation | |
548 | ||
549 | #ifndef __WIN16__ | |
550 | if (devMode->dmFields & DM_COLLATE) | |
551 | { | |
552 | if (devMode->dmCollate == DMCOLLATE_TRUE) | |
553 | m_printCollate = TRUE; | |
554 | else | |
555 | m_printCollate = FALSE; | |
556 | } | |
557 | #endif | |
558 | ||
559 | //// Number of copies | |
560 | ||
561 | if (devMode->dmFields & DM_COPIES) | |
562 | { | |
563 | m_printNoCopies = devMode->dmCopies; | |
564 | } | |
565 | ||
566 | //// Printer name | |
567 | ||
568 | if (devMode->dmDeviceName[0] != 0) | |
569 | { | |
570 | // TODO: make this Unicode compatible | |
571 | char buf[32]; | |
572 | int i = 0; | |
573 | while (devMode->dmDeviceName[i] != 0) | |
574 | { | |
575 | buf[i] = devMode->dmDeviceName[i]; | |
576 | i ++; | |
577 | } | |
578 | buf[i] = 0; | |
579 | ||
580 | m_printerName = buf; | |
581 | } | |
582 | ||
583 | //// Colour | |
584 | ||
585 | if (devMode->dmFields & DM_COLOR) | |
586 | { | |
587 | if (devMode->dmColor == DMCOLOR_COLOR) | |
588 | m_colour = TRUE; | |
589 | else | |
590 | m_colour = FALSE; | |
591 | } | |
592 | else | |
593 | m_colour = TRUE; | |
594 | ||
595 | #ifndef __WXWINE__ | |
596 | //// Paper size | |
597 | ||
598 | // We don't know size of user defined paper and some buggy drivers | |
599 | // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since | |
600 | // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this | |
601 | // code wouldn't set m_paperSize correctly. | |
602 | if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER)) | |
603 | { | |
604 | if (wxThePrintPaperDatabase) | |
605 | { | |
606 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize); | |
607 | if (paper) | |
608 | { | |
609 | m_paperId = paper->GetId(); | |
610 | m_paperSize.x = paper->GetWidth() / 10; | |
611 | m_paperSize.y = paper->GetHeight() / 10; | |
612 | } | |
613 | else | |
614 | { | |
615 | // Shouldn't really get here | |
616 | wxFAIL_MSG(wxT("Couldn't find paper size in paper database.")); | |
617 | ||
618 | m_paperId = wxPAPER_NONE; | |
619 | m_paperSize.x = 0; | |
620 | m_paperSize.y = 0; | |
621 | } | |
622 | } | |
623 | else | |
624 | { | |
625 | // Shouldn't really get here | |
626 | wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative.")); | |
627 | ||
628 | m_paperId = wxPAPER_NONE; | |
629 | m_paperSize.x = 0; | |
630 | m_paperSize.y = 0; | |
631 | } | |
632 | } | |
633 | else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH)) | |
634 | { | |
635 | // DEVMODE is in tenths of a milimeter | |
636 | m_paperSize.x = devMode->dmPaperWidth / 10; | |
637 | m_paperSize.y = devMode->dmPaperLength / 10; | |
638 | m_paperId = wxPAPER_NONE; | |
639 | } | |
640 | else | |
641 | { | |
642 | // Shouldn't really get here | |
643 | wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE.")); | |
644 | ||
645 | m_paperSize.x = 0; | |
646 | m_paperSize.y = 0; | |
647 | m_paperId = wxPAPER_NONE; | |
648 | } | |
649 | #endif | |
650 | ||
651 | //// Duplex | |
652 | ||
653 | if (devMode->dmFields & DM_DUPLEX) | |
654 | { | |
655 | switch (devMode->dmDuplex) | |
656 | { | |
657 | case DMDUP_HORIZONTAL: { | |
658 | m_duplexMode = wxDUPLEX_HORIZONTAL; break; | |
659 | } | |
660 | case DMDUP_VERTICAL: { | |
661 | m_duplexMode = wxDUPLEX_VERTICAL; break; | |
662 | } | |
663 | default: | |
664 | case DMDUP_SIMPLEX: { | |
665 | m_duplexMode = wxDUPLEX_SIMPLEX; break; | |
666 | } | |
667 | } | |
668 | } | |
669 | else | |
670 | m_duplexMode = wxDUPLEX_SIMPLEX; | |
671 | ||
672 | //// Quality | |
673 | ||
674 | if (devMode->dmFields & DM_PRINTQUALITY) | |
675 | { | |
676 | switch (devMode->dmPrintQuality) | |
677 | { | |
678 | case DMRES_MEDIUM: { | |
679 | m_printQuality = wxPRINT_QUALITY_MEDIUM; break; | |
680 | } | |
681 | case DMRES_LOW: { | |
682 | m_printQuality = wxPRINT_QUALITY_LOW; break; | |
683 | } | |
684 | case DMRES_DRAFT: { | |
685 | m_printQuality = wxPRINT_QUALITY_DRAFT; break; | |
686 | } | |
687 | case DMRES_HIGH: { | |
688 | m_printQuality = wxPRINT_QUALITY_HIGH; break; | |
689 | } | |
690 | default: | |
691 | { | |
692 | // TODO: if the printer fills in the resolution in DPI, how | |
693 | // will the application know if it's high, low, draft etc.?? | |
694 | // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values."); | |
695 | m_printQuality = devMode->dmPrintQuality; break; | |
696 | ||
697 | } | |
698 | } | |
699 | } | |
700 | else | |
701 | m_printQuality = wxPRINT_QUALITY_HIGH; | |
702 | ||
703 | GlobalUnlock(hDevMode); | |
704 | } | |
705 | ||
706 | if (hDevNames) | |
707 | { | |
708 | LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames); | |
709 | if (lpDevNames) | |
710 | { | |
711 | // TODO: Unicode-ification | |
712 | ||
713 | // Get the port name | |
714 | // port is obsolete in WIN32 | |
715 | // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset); | |
716 | ||
717 | // Get the printer name | |
718 | wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
719 | ||
720 | // Not sure if we should check for this mismatch | |
721 | // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); | |
722 | ||
723 | if (printerName != wxT("")) | |
724 | m_printerName = printerName; | |
725 | ||
726 | GlobalUnlock(hDevNames); | |
727 | } | |
728 | } | |
729 | } | |
730 | ||
731 | #endif | |
732 | ||
733 | #ifdef __WXMAC__ | |
734 | void wxPrintData::ConvertToNative() | |
735 | { | |
736 | #ifdef TARGET_CARBON | |
737 | #else | |
738 | (**m_macPrintInfo).prJob.iCopies = m_printNoCopies; | |
739 | #endif | |
740 | } | |
741 | ||
742 | void wxPrintData::ConvertFromNative() | |
743 | { | |
744 | #ifdef TARGET_CARBON | |
745 | #else | |
746 | m_printNoCopies = (**m_macPrintInfo).prJob.iCopies; | |
747 | #endif | |
748 | } | |
749 | #endif | |
750 | ||
751 | void wxPrintData::operator=(const wxPrintData& data) | |
752 | { | |
753 | #ifdef __WXMAC__ | |
754 | #ifdef TARGET_CARBON | |
755 | #else | |
756 | m_macPrintInfo = data.m_macPrintInfo; | |
757 | HandToHand( (Handle*) &m_macPrintInfo ); | |
758 | #endif | |
759 | #endif | |
760 | m_printNoCopies = data.m_printNoCopies; | |
761 | m_printCollate = data.m_printCollate; | |
762 | m_printOrientation = data.m_printOrientation; | |
763 | m_printerName = data.m_printerName; | |
764 | m_colour = data.m_colour; | |
765 | m_duplexMode = data.m_duplexMode; | |
766 | m_printQuality = data.m_printQuality; | |
767 | m_paperId = data.m_paperId; | |
768 | m_paperSize = data.m_paperSize; | |
769 | ||
770 | // PostScript-specific data | |
771 | m_printerCommand = data.m_printerCommand; | |
772 | m_previewCommand = data.m_previewCommand; | |
773 | m_printerOptions = data.m_printerOptions; | |
774 | m_filename = data.m_filename; | |
775 | m_afmPath = data.m_afmPath; | |
776 | m_printerScaleX = data.m_printerScaleX; | |
777 | m_printerScaleY = data.m_printerScaleY; | |
778 | m_printerTranslateX = data.m_printerTranslateX; | |
779 | m_printerTranslateY = data.m_printerTranslateY; | |
780 | m_printMode = data.m_printMode; | |
781 | } | |
782 | ||
783 | // For compatibility | |
784 | #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA | |
785 | void wxPrintData::operator=(const wxPrintSetupData& setupData) | |
786 | { | |
787 | SetPrinterCommand(setupData.GetPrinterCommand()); | |
788 | SetPreviewCommand(setupData.GetPrintPreviewCommand()); | |
789 | SetPrinterOptions(setupData.GetPrinterOptions()); | |
790 | ||
791 | long xt, yt; | |
792 | setupData.GetPrinterTranslation(& xt, & yt); | |
793 | SetPrinterTranslation(xt, yt); | |
794 | ||
795 | double xs, ys; | |
796 | setupData.GetPrinterScaling(& xs, & ys); | |
797 | SetPrinterScaling(xs, ys); | |
798 | ||
799 | SetOrientation(setupData.GetPrinterOrientation()); | |
800 | SetPrintMode((wxPrintMode) setupData.GetPrinterMode()); | |
801 | SetFontMetricPath(setupData.GetAFMPath()); | |
802 | if (setupData.GetPaperName() != "") | |
803 | SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(setupData.GetPaperName())); | |
804 | SetColour(setupData.GetColour()); | |
805 | SetFilename(setupData.GetPrinterFile()); | |
806 | } | |
807 | #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA | |
808 | ||
809 | ||
810 | // ---------------------------------------------------------------------------- | |
811 | // Print dialog data | |
812 | // ---------------------------------------------------------------------------- | |
813 | ||
814 | wxPrintDialogData::wxPrintDialogData() | |
815 | { | |
816 | #ifdef __WXMSW__ | |
817 | m_printDlgData = NULL; | |
818 | #endif | |
819 | m_printFromPage = 0; | |
820 | m_printToPage = 0; | |
821 | m_printMinPage = 0; | |
822 | m_printMaxPage = 0; | |
823 | m_printNoCopies = 1; | |
824 | m_printAllPages = FALSE; | |
825 | m_printCollate = FALSE; | |
826 | m_printToFile = FALSE; | |
827 | m_printSelection = FALSE; | |
828 | m_printEnableSelection = FALSE; | |
829 | m_printEnablePageNumbers = TRUE; | |
830 | m_printEnablePrintToFile = TRUE; | |
831 | m_printEnableHelp = FALSE; | |
832 | m_printSetupDialog = FALSE; | |
833 | } | |
834 | ||
835 | wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData) | |
836 | { | |
837 | #ifdef __WXMSW__ | |
838 | m_printDlgData = NULL; | |
839 | #endif | |
840 | (*this) = dialogData; | |
841 | } | |
842 | ||
843 | wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData) | |
844 | { | |
845 | #ifdef __WXMSW__ | |
846 | m_printDlgData = NULL; | |
847 | #endif | |
848 | m_printFromPage = 0; | |
849 | m_printToPage = 0; | |
850 | m_printMinPage = 0; | |
851 | m_printMaxPage = 0; | |
852 | m_printNoCopies = 1; | |
853 | m_printAllPages = FALSE; | |
854 | m_printCollate = FALSE; | |
855 | m_printToFile = FALSE; | |
856 | m_printSelection = FALSE; | |
857 | m_printEnableSelection = FALSE; | |
858 | m_printEnablePageNumbers = TRUE; | |
859 | m_printEnablePrintToFile = TRUE; | |
860 | m_printEnableHelp = FALSE; | |
861 | m_printSetupDialog = FALSE; | |
862 | ||
863 | m_printData = printData; | |
864 | } | |
865 | ||
866 | wxPrintDialogData::~wxPrintDialogData() | |
867 | { | |
868 | #ifdef __WXMSW__ | |
869 | PRINTDLG *pd = (PRINTDLG *) m_printDlgData; | |
870 | if ( pd && pd->hDevMode ) | |
871 | GlobalFree(pd->hDevMode); | |
872 | if ( pd ) | |
873 | delete pd; | |
874 | #endif | |
875 | } | |
876 | ||
877 | #ifdef __WXMSW__ | |
878 | void wxPrintDialogData::ConvertToNative() | |
879 | { | |
880 | m_printData.ConvertToNative(); | |
881 | ||
882 | PRINTDLG *pd = (PRINTDLG*) m_printDlgData; | |
883 | ||
884 | if (!pd) | |
885 | { | |
886 | pd = new PRINTDLG; | |
887 | memset( pd, 0, sizeof(PRINTDLG) ); | |
888 | m_printDlgData = (void*) pd; | |
889 | ||
890 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. | |
891 | #ifdef __GNUWIN32__ | |
892 | pd->lStructSize = 66; | |
893 | #else | |
894 | pd->lStructSize = sizeof(PRINTDLG); | |
895 | #endif | |
896 | pd->hwndOwner = (HWND)NULL; | |
897 | pd->hDevMode = NULL; // Will be created by PrintDlg | |
898 | pd->hDevNames = NULL; // Ditto | |
899 | ||
900 | pd->Flags = PD_RETURNDEFAULT; | |
901 | pd->nCopies = 1; | |
902 | } | |
903 | ||
904 | // Pass the devmode data to the PRINTDLG structure, since it'll | |
905 | // be needed when PrintDlg is called. | |
906 | if (pd->hDevMode) | |
907 | { | |
908 | GlobalFree(pd->hDevMode); | |
909 | } | |
910 | ||
911 | // Pass the devnames data to the PRINTDLG structure, since it'll | |
912 | // be needed when PrintDlg is called. | |
913 | if (pd->hDevNames) | |
914 | { | |
915 | GlobalFree(pd->hDevNames); | |
916 | } | |
917 | ||
918 | pd->hDevMode = (HGLOBAL)(DWORD) m_printData.GetNativeData(); | |
919 | ||
920 | m_printData.SetNativeData((void*) NULL); | |
921 | ||
922 | wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
923 | ||
924 | pd->hDevNames = (HGLOBAL)(DWORD) m_printData.GetNativeDataDevNames(); | |
925 | ||
926 | m_printData.SetNativeDataDevNames((void*) NULL); | |
927 | ||
928 | pd->hDC = (HDC) NULL; | |
929 | pd->nFromPage = (WORD)m_printFromPage; | |
930 | pd->nToPage = (WORD)m_printToPage; | |
931 | pd->nMinPage = (WORD)m_printMinPage; | |
932 | pd->nMaxPage = (WORD)m_printMaxPage; | |
933 | pd->nCopies = (WORD)m_printNoCopies; | |
934 | ||
935 | pd->Flags = PD_RETURNDC; | |
936 | ||
937 | #ifdef __GNUWIN32__ | |
938 | pd->lStructSize = 66; | |
939 | #else | |
940 | pd->lStructSize = sizeof( PRINTDLG ); | |
941 | #endif | |
942 | ||
943 | pd->hwndOwner=(HWND)NULL; | |
944 | // pd->hDevNames=(HANDLE)NULL; | |
945 | pd->hInstance=(HINSTANCE)NULL; | |
946 | pd->lCustData = (LPARAM) NULL; | |
947 | pd->lpfnPrintHook = NULL; | |
948 | pd->lpfnSetupHook = NULL; | |
949 | pd->lpPrintTemplateName = NULL; | |
950 | pd->lpSetupTemplateName = NULL; | |
951 | pd->hPrintTemplate = (HGLOBAL) NULL; | |
952 | pd->hSetupTemplate = (HGLOBAL) NULL; | |
953 | ||
954 | if ( m_printAllPages ) | |
955 | pd->Flags |= PD_ALLPAGES; | |
956 | if ( m_printSelection ) | |
957 | pd->Flags |= PD_SELECTION; | |
958 | if ( m_printCollate ) | |
959 | pd->Flags |= PD_COLLATE; | |
960 | if ( m_printToFile ) | |
961 | pd->Flags |= PD_PRINTTOFILE; | |
962 | if ( !m_printEnablePrintToFile ) | |
963 | pd->Flags |= PD_DISABLEPRINTTOFILE; | |
964 | if ( !m_printEnableSelection ) | |
965 | pd->Flags |= PD_NOSELECTION; | |
966 | if ( !m_printEnablePageNumbers ) | |
967 | pd->Flags |= PD_NOPAGENUMS; | |
968 | if ( m_printEnableHelp ) | |
969 | pd->Flags |= PD_SHOWHELP; | |
970 | if ( m_printSetupDialog ) | |
971 | pd->Flags |= PD_PRINTSETUP; | |
972 | } | |
973 | ||
974 | void wxPrintDialogData::ConvertFromNative() | |
975 | { | |
976 | PRINTDLG *pd = (PRINTDLG*) m_printDlgData; | |
977 | if ( pd == NULL ) | |
978 | return; | |
979 | ||
980 | // Pass the devmode data back to the wxPrintData structure where it really belongs. | |
981 | if (pd->hDevMode) | |
982 | { | |
983 | if (m_printData.GetNativeData()) | |
984 | { | |
985 | // Make sure we don't leak memory | |
986 | GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeData()); | |
987 | } | |
988 | m_printData.SetNativeData((void*)(long) pd->hDevMode); | |
989 | pd->hDevMode = NULL; | |
990 | } | |
991 | ||
992 | // Pass the devnames data back to the wxPrintData structure where it really belongs. | |
993 | if (pd->hDevNames) | |
994 | { | |
995 | if (m_printData.GetNativeDataDevNames()) | |
996 | { | |
997 | // Make sure we don't leak memory | |
998 | GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeDataDevNames()); | |
999 | } | |
1000 | m_printData.SetNativeDataDevNames((void*)(long) pd->hDevNames); | |
1001 | pd->hDevNames = NULL; | |
1002 | } | |
1003 | ||
1004 | // Now convert the DEVMODE object, passed down from the PRINTDLG object, | |
1005 | // into wxWindows form. | |
1006 | m_printData.ConvertFromNative(); | |
1007 | ||
1008 | m_printFromPage = pd->nFromPage; | |
1009 | m_printToPage = pd->nToPage; | |
1010 | m_printMinPage = pd->nMinPage; | |
1011 | m_printMaxPage = pd->nMaxPage; | |
1012 | m_printNoCopies = pd->nCopies; | |
1013 | ||
1014 | m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES); | |
1015 | m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION); | |
1016 | m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE); | |
1017 | m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE); | |
1018 | m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE); | |
1019 | m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION); | |
1020 | m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS); | |
1021 | m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP); | |
1022 | m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP); | |
1023 | ||
1024 | /* port is obsolete in WIN32 | |
1025 | // Get the port name | |
1026 | if (pd->hDevNames) | |
1027 | { | |
1028 | LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames); | |
1029 | if (lpDevNames) { | |
1030 | m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset); | |
1031 | wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
1032 | GlobalUnlock(pd->hDevNames); | |
1033 | ||
1034 | // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); | |
1035 | } | |
1036 | } | |
1037 | */ | |
1038 | } | |
1039 | ||
1040 | void wxPrintDialogData::SetOwnerWindow(wxWindow* win) | |
1041 | { | |
1042 | if ( m_printDlgData == NULL ) | |
1043 | ConvertToNative(); | |
1044 | ||
1045 | if ( m_printDlgData != NULL && win != NULL) | |
1046 | { | |
1047 | PRINTDLG *pd = (PRINTDLG *) m_printDlgData; | |
1048 | pd->hwndOwner=(HWND) win->GetHWND(); | |
1049 | } | |
1050 | } | |
1051 | #endif // MSW | |
1052 | ||
1053 | #ifdef __WXMAC__ | |
1054 | void wxPrintDialogData::ConvertToNative() | |
1055 | { | |
1056 | #ifdef TARGET_CARBON | |
1057 | #else | |
1058 | (**m_printData.m_macPrintInfo).prJob.iFstPage = m_printFromPage; | |
1059 | (**m_printData.m_macPrintInfo).prJob.iLstPage = m_printToPage; | |
1060 | m_printData.ConvertToNative(); | |
1061 | #endif | |
1062 | } | |
1063 | ||
1064 | void wxPrintDialogData::ConvertFromNative() | |
1065 | { | |
1066 | #ifdef TARGET_CARBON | |
1067 | #else | |
1068 | m_printData.ConvertFromNative(); | |
1069 | m_printFromPage = (**m_printData.m_macPrintInfo).prJob.iFstPage; | |
1070 | m_printToPage = (**m_printData.m_macPrintInfo).prJob.iLstPage; | |
1071 | #endif | |
1072 | } | |
1073 | #endif | |
1074 | ||
1075 | ||
1076 | void wxPrintDialogData::operator=(const wxPrintDialogData& data) | |
1077 | { | |
1078 | m_printFromPage = data.m_printFromPage; | |
1079 | m_printToPage = data.m_printToPage; | |
1080 | m_printMinPage = data.m_printMinPage; | |
1081 | m_printMaxPage = data.m_printMaxPage; | |
1082 | m_printNoCopies = data.m_printNoCopies; | |
1083 | m_printAllPages = data.m_printAllPages; | |
1084 | m_printCollate = data.m_printCollate; | |
1085 | m_printToFile = data.m_printToFile; | |
1086 | m_printSelection = data.m_printSelection; | |
1087 | m_printEnableSelection = data.m_printEnableSelection; | |
1088 | m_printEnablePageNumbers = data.m_printEnablePageNumbers; | |
1089 | m_printEnableHelp = data.m_printEnableHelp; | |
1090 | m_printEnablePrintToFile = data.m_printEnablePrintToFile; | |
1091 | m_printSetupDialog = data.m_printSetupDialog; | |
1092 | ||
1093 | m_printData = data.m_printData; | |
1094 | } | |
1095 | ||
1096 | void wxPrintDialogData::operator=(const wxPrintData& data) | |
1097 | { | |
1098 | m_printData = data; | |
1099 | } | |
1100 | ||
1101 | // ---------------------------------------------------------------------------- | |
1102 | // wxPageSetupDialogData | |
1103 | // ---------------------------------------------------------------------------- | |
1104 | ||
1105 | wxPageSetupDialogData::wxPageSetupDialogData() | |
1106 | { | |
1107 | #if defined(__WIN95__) | |
1108 | m_pageSetupData = NULL; | |
1109 | #endif | |
1110 | m_paperSize = wxSize(0, 0); | |
1111 | ||
1112 | CalculatePaperSizeFromId(); | |
1113 | ||
1114 | m_minMarginTopLeft = wxPoint(0, 0); | |
1115 | m_minMarginBottomRight = wxPoint(0, 0); | |
1116 | m_marginTopLeft = wxPoint(0, 0); | |
1117 | m_marginBottomRight = wxPoint(0, 0); | |
1118 | ||
1119 | // Flags | |
1120 | m_defaultMinMargins = FALSE; | |
1121 | m_enableMargins = TRUE; | |
1122 | m_enableOrientation = TRUE; | |
1123 | m_enablePaper = TRUE; | |
1124 | m_enablePrinter = TRUE; | |
1125 | m_enableHelp = FALSE; | |
1126 | m_getDefaultInfo = FALSE; | |
1127 | } | |
1128 | ||
1129 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData) | |
1130 | { | |
1131 | #if defined(__WIN95__) | |
1132 | m_pageSetupData = NULL; | |
1133 | #endif | |
1134 | (*this) = dialogData; | |
1135 | } | |
1136 | ||
1137 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData) | |
1138 | { | |
1139 | #if defined(__WIN95__) | |
1140 | m_pageSetupData = NULL; | |
1141 | #endif | |
1142 | m_paperSize = wxSize(0, 0); | |
1143 | m_minMarginTopLeft = wxPoint(0, 0); | |
1144 | m_minMarginBottomRight = wxPoint(0, 0); | |
1145 | m_marginTopLeft = wxPoint(0, 0); | |
1146 | m_marginBottomRight = wxPoint(0, 0); | |
1147 | ||
1148 | // Flags | |
1149 | m_defaultMinMargins = FALSE; | |
1150 | m_enableMargins = TRUE; | |
1151 | m_enableOrientation = TRUE; | |
1152 | m_enablePaper = TRUE; | |
1153 | m_enablePrinter = TRUE; | |
1154 | m_enableHelp = FALSE; | |
1155 | m_getDefaultInfo = FALSE; | |
1156 | ||
1157 | m_printData = printData; | |
1158 | ||
1159 | // The wxPrintData paper size overrides these values, unless the size cannot | |
1160 | // be found. | |
1161 | CalculatePaperSizeFromId(); | |
1162 | } | |
1163 | ||
1164 | wxPageSetupDialogData::~wxPageSetupDialogData() | |
1165 | { | |
1166 | #if defined(__WIN95__) && defined(__WXMSW__) | |
1167 | PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData; | |
1168 | if ( pd && pd->hDevMode ) | |
1169 | GlobalFree(pd->hDevMode); | |
1170 | if ( pd && pd->hDevNames ) | |
1171 | GlobalFree(pd->hDevNames); | |
1172 | if ( pd ) | |
1173 | delete pd; | |
1174 | #endif | |
1175 | } | |
1176 | ||
1177 | void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data) | |
1178 | { | |
1179 | m_paperSize = data.m_paperSize; | |
1180 | m_minMarginTopLeft = data.m_minMarginTopLeft; | |
1181 | m_minMarginBottomRight = data.m_minMarginBottomRight; | |
1182 | m_marginTopLeft = data.m_marginTopLeft; | |
1183 | m_marginBottomRight = data.m_marginBottomRight; | |
1184 | m_defaultMinMargins = data.m_defaultMinMargins; | |
1185 | m_enableMargins = data.m_enableMargins; | |
1186 | m_enableOrientation = data.m_enableOrientation; | |
1187 | m_enablePaper = data.m_enablePaper; | |
1188 | m_enablePrinter = data.m_enablePrinter; | |
1189 | m_getDefaultInfo = data.m_getDefaultInfo;; | |
1190 | m_enableHelp = data.m_enableHelp; | |
1191 | ||
1192 | m_printData = data.m_printData; | |
1193 | } | |
1194 | ||
1195 | void wxPageSetupDialogData::operator=(const wxPrintData& data) | |
1196 | { | |
1197 | m_printData = data; | |
1198 | } | |
1199 | ||
1200 | #if defined(__WIN95__) | |
1201 | void wxPageSetupDialogData::ConvertToNative() | |
1202 | { | |
1203 | m_printData.ConvertToNative(); | |
1204 | ||
1205 | PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData; | |
1206 | ||
1207 | if ( m_pageSetupData == NULL ) | |
1208 | { | |
1209 | pd = new PAGESETUPDLG; | |
1210 | pd->hDevMode = NULL; | |
1211 | pd->hDevNames = NULL; | |
1212 | m_pageSetupData = (void *)pd; | |
1213 | } | |
1214 | ||
1215 | // Pass the devmode data (created in m_printData.ConvertToNative) | |
1216 | // to the PRINTDLG structure, since it'll | |
1217 | // be needed when PrintDlg is called. | |
1218 | ||
1219 | if (pd->hDevMode) | |
1220 | { | |
1221 | GlobalFree(pd->hDevMode); | |
1222 | pd->hDevMode = NULL; | |
1223 | } | |
1224 | ||
1225 | pd->hDevMode = (HGLOBAL) m_printData.GetNativeData(); | |
1226 | ||
1227 | m_printData.SetNativeData((void*) NULL); | |
1228 | ||
1229 | wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
1230 | ||
1231 | // Pass the devnames data (created in m_printData.ConvertToNative) | |
1232 | // to the PRINTDLG structure, since it'll | |
1233 | // be needed when PrintDlg is called. | |
1234 | ||
1235 | if (pd->hDevNames) | |
1236 | { | |
1237 | GlobalFree(pd->hDevNames); | |
1238 | pd->hDevNames = NULL; | |
1239 | } | |
1240 | ||
1241 | pd->hDevNames = (HGLOBAL) m_printData.GetNativeDataDevNames(); | |
1242 | ||
1243 | m_printData.SetNativeDataDevNames((void*) NULL); | |
1244 | ||
1245 | // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE)); | |
1246 | ||
1247 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; | |
1248 | ||
1249 | if ( m_defaultMinMargins ) | |
1250 | pd->Flags |= PSD_DEFAULTMINMARGINS; | |
1251 | if ( !m_enableMargins ) | |
1252 | pd->Flags |= PSD_DISABLEMARGINS; | |
1253 | if ( !m_enableOrientation ) | |
1254 | pd->Flags |= PSD_DISABLEORIENTATION; | |
1255 | if ( !m_enablePaper ) | |
1256 | pd->Flags |= PSD_DISABLEPAPER; | |
1257 | if ( !m_enablePrinter ) | |
1258 | pd->Flags |= PSD_DISABLEPRINTER; | |
1259 | if ( m_getDefaultInfo ) | |
1260 | pd->Flags |= PSD_RETURNDEFAULT; | |
1261 | if ( m_enableHelp ) | |
1262 | pd->Flags |= PSD_SHOWHELP; | |
1263 | ||
1264 | // We want the units to be in hundredths of a millimetre | |
1265 | pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS; | |
1266 | ||
1267 | pd->lStructSize = sizeof( PAGESETUPDLG ); | |
1268 | pd->hwndOwner=(HWND)NULL; | |
1269 | // pd->hDevNames=(HWND)NULL; | |
1270 | pd->hInstance=(HINSTANCE)NULL; | |
1271 | // PAGESETUPDLG is in hundreds of a mm | |
1272 | pd->ptPaperSize.x = m_paperSize.x * 100; | |
1273 | pd->ptPaperSize.y = m_paperSize.y * 100; | |
1274 | ||
1275 | pd->rtMinMargin.left = m_minMarginTopLeft.x * 100; | |
1276 | pd->rtMinMargin.top = m_minMarginTopLeft.y * 100; | |
1277 | pd->rtMinMargin.right = m_minMarginBottomRight.x * 100; | |
1278 | pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100; | |
1279 | ||
1280 | pd->rtMargin.left = m_marginTopLeft.x * 100; | |
1281 | pd->rtMargin.top = m_marginTopLeft.y * 100; | |
1282 | pd->rtMargin.right = m_marginBottomRight.x * 100; | |
1283 | pd->rtMargin.bottom = m_marginBottomRight.y * 100; | |
1284 | ||
1285 | pd->lCustData = 0; | |
1286 | pd->lpfnPageSetupHook = NULL; | |
1287 | pd->lpfnPagePaintHook = NULL; | |
1288 | pd->hPageSetupTemplate = NULL; | |
1289 | pd->lpPageSetupTemplateName = NULL; | |
1290 | ||
1291 | /* | |
1292 | if ( pd->hDevMode ) | |
1293 | { | |
1294 | DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); | |
1295 | memset(devMode, 0, sizeof(DEVMODE)); | |
1296 | devMode->dmSize = sizeof(DEVMODE); | |
1297 | devMode->dmOrientation = m_orientation; | |
1298 | devMode->dmFields = DM_ORIENTATION; | |
1299 | GlobalUnlock(pd->hDevMode); | |
1300 | } | |
1301 | */ | |
1302 | } | |
1303 | ||
1304 | void wxPageSetupDialogData::ConvertFromNative() | |
1305 | { | |
1306 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData; | |
1307 | if ( !pd ) | |
1308 | return; | |
1309 | ||
1310 | // Pass the devmode data back to the wxPrintData structure where it really belongs. | |
1311 | if (pd->hDevMode) | |
1312 | { | |
1313 | if (m_printData.GetNativeData()) | |
1314 | { | |
1315 | // Make sure we don't leak memory | |
1316 | GlobalFree((HGLOBAL) m_printData.GetNativeData()); | |
1317 | } | |
1318 | m_printData.SetNativeData((void*) pd->hDevMode); | |
1319 | pd->hDevMode = NULL; | |
1320 | } | |
1321 | ||
1322 | m_printData.ConvertFromNative(); | |
1323 | ||
1324 | // Pass the devnames data back to the wxPrintData structure where it really belongs. | |
1325 | if (pd->hDevNames) | |
1326 | { | |
1327 | if (m_printData.GetNativeDataDevNames()) | |
1328 | { | |
1329 | // Make sure we don't leak memory | |
1330 | GlobalFree((HGLOBAL) m_printData.GetNativeDataDevNames()); | |
1331 | } | |
1332 | m_printData.SetNativeDataDevNames((void*) pd->hDevNames); | |
1333 | pd->hDevNames = NULL; | |
1334 | } | |
1335 | ||
1336 | m_printData.ConvertFromNative(); | |
1337 | ||
1338 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; | |
1339 | ||
1340 | m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS); | |
1341 | m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS); | |
1342 | m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION); | |
1343 | m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER); | |
1344 | m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER); | |
1345 | m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT); | |
1346 | m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP); | |
1347 | ||
1348 | // PAGESETUPDLG is in hundreds of a mm | |
1349 | m_paperSize.x = pd->ptPaperSize.x / 100; | |
1350 | m_paperSize.y = pd->ptPaperSize.y / 100; | |
1351 | ||
1352 | m_minMarginTopLeft.x = pd->rtMinMargin.left / 100; | |
1353 | m_minMarginTopLeft.y = pd->rtMinMargin.top / 100; | |
1354 | m_minMarginBottomRight.x = pd->rtMinMargin.right / 100; | |
1355 | m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100; | |
1356 | ||
1357 | m_marginTopLeft.x = pd->rtMargin.left / 100; | |
1358 | m_marginTopLeft.y = pd->rtMargin.top / 100; | |
1359 | m_marginBottomRight.x = pd->rtMargin.right / 100; | |
1360 | m_marginBottomRight.y = pd->rtMargin.bottom / 100; | |
1361 | } | |
1362 | ||
1363 | void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win) | |
1364 | { | |
1365 | if ( m_pageSetupData == NULL ) | |
1366 | ConvertToNative(); | |
1367 | ||
1368 | if ( m_pageSetupData != NULL && win != NULL) | |
1369 | { | |
1370 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData; | |
1371 | pd->hwndOwner=(HWND) win->GetHWND(); | |
1372 | } | |
1373 | } | |
1374 | #endif // Win95 | |
1375 | ||
1376 | #ifdef __WXMAC__ | |
1377 | void wxPageSetupDialogData::ConvertToNative() | |
1378 | { | |
1379 | m_printData.ConvertToNative(); | |
1380 | // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0 | |
1381 | #ifdef TARGET_CARBON | |
1382 | #else | |
1383 | (**m_printData.m_macPrintInfo).rPaper.left = int( ((double) m_minMarginTopLeft.x)*mm2pt ); | |
1384 | (**m_printData.m_macPrintInfo).rPaper.top = int( ((double) m_minMarginTopLeft.y)*mm2pt ); | |
1385 | ||
1386 | (**m_printData.m_macPrintInfo).rPaper.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x)*mm2pt ); | |
1387 | (**m_printData.m_macPrintInfo).rPaper.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y)*mm2pt ); | |
1388 | ||
1389 | (**m_printData.m_macPrintInfo).prInfo.rPage.left = 0; | |
1390 | (**m_printData.m_macPrintInfo).prInfo.rPage.top = 0; | |
1391 | (**m_printData.m_macPrintInfo).prInfo.rPage.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x - m_minMarginBottomRight.x)*mm2pt ); | |
1392 | (**m_printData.m_macPrintInfo).prInfo.rPage.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y - m_minMarginBottomRight.y)*mm2pt ); | |
1393 | #endif | |
1394 | } | |
1395 | ||
1396 | void wxPageSetupDialogData::ConvertFromNative() | |
1397 | { | |
1398 | m_printData.ConvertFromNative (); | |
1399 | ||
1400 | #ifdef TARGET_CARBON | |
1401 | #else | |
1402 | m_paperSize.x = ((double) (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ) * pt2mm; | |
1403 | m_paperSize.y = ((double) (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ) * pt2mm; | |
1404 | ||
1405 | m_minMarginTopLeft.x = ((double) -(**m_printData.m_macPrintInfo).rPaper.left ) * pt2mm; | |
1406 | m_minMarginTopLeft.y = ((double) -(**m_printData.m_macPrintInfo).rPaper.top ) * pt2mm; | |
1407 | ||
1408 | m_minMarginBottomRight.x = ((double) (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).prInfo.rPage.right ) * pt2mm; | |
1409 | m_minMarginBottomRight.y = ((double)(**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).prInfo.rPage.bottom ) * pt2mm; | |
1410 | #endif | |
1411 | // adjust minimal values | |
1412 | //TODO add custom fields in dialog for margins | |
1413 | ||
1414 | if ( m_marginTopLeft.x < m_minMarginTopLeft.x ) | |
1415 | m_marginTopLeft.x = m_minMarginTopLeft.x; | |
1416 | ||
1417 | if ( m_marginBottomRight.x < m_minMarginBottomRight.x ) | |
1418 | m_marginBottomRight.x = m_minMarginBottomRight.x; | |
1419 | ||
1420 | if ( m_marginTopLeft.y < m_minMarginTopLeft.y ) | |
1421 | m_marginTopLeft.y = m_minMarginTopLeft.y; | |
1422 | ||
1423 | if ( m_marginBottomRight.y < m_minMarginBottomRight.y ) | |
1424 | m_marginBottomRight.y = m_minMarginBottomRight.y; | |
1425 | } | |
1426 | #endif | |
1427 | ||
1428 | ||
1429 | // If a corresponding paper type is found in the paper database, will set the m_printData | |
1430 | // paper size id member as well. | |
1431 | void wxPageSetupDialogData::SetPaperSize(const wxSize& sz) | |
1432 | { | |
1433 | m_paperSize = sz; | |
1434 | ||
1435 | CalculateIdFromPaperSize(); | |
1436 | } | |
1437 | ||
1438 | // Sets the wxPrintData id, plus the paper width/height if found in the paper database. | |
1439 | void wxPageSetupDialogData::SetPaperSize(wxPaperSize id) | |
1440 | { | |
1441 | m_printData.SetPaperId(id); | |
1442 | ||
1443 | CalculatePaperSizeFromId(); | |
1444 | } | |
1445 | ||
1446 | // Use paper size defined in this object to set the wxPrintData | |
1447 | // paper id | |
1448 | void wxPageSetupDialogData::CalculateIdFromPaperSize() | |
1449 | { | |
1450 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), | |
1451 | wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") ); | |
1452 | ||
1453 | wxSize sz = GetPaperSize(); | |
1454 | ||
1455 | wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10)); | |
1456 | if (id != wxPAPER_NONE) | |
1457 | { | |
1458 | m_printData.SetPaperId(id); | |
1459 | } | |
1460 | } | |
1461 | ||
1462 | // Use paper id in wxPrintData to set this object's paper size | |
1463 | void wxPageSetupDialogData::CalculatePaperSizeFromId() | |
1464 | { | |
1465 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), | |
1466 | wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") ); | |
1467 | ||
1468 | wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId()); | |
1469 | ||
1470 | if (sz.x != 0) | |
1471 | { | |
1472 | // sz is in 10ths of a mm, so multiply by 10. | |
1473 | m_paperSize.x = sz.x * 10; | |
1474 | m_paperSize.y = sz.y * 10; | |
1475 | } | |
1476 | } | |
1477 | ||
1478 | #endif // wxUSE_PRINTING_ARCHITECTURE |