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