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