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