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