]>
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 | #ifndef __WIN16__ | |
394 | devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE); | |
395 | devMode->dmFields |= DM_COLLATE; | |
396 | #endif | |
397 | ||
398 | //// Number of copies | |
399 | ||
400 | devMode->dmCopies = m_printNoCopies; | |
401 | devMode->dmFields |= DM_COPIES; | |
402 | ||
403 | //// Printer name | |
404 | ||
405 | if (m_printerName != wxT("")) | |
406 | { | |
407 | //int len = wxMin(31, m_printerName.Len()); | |
408 | wxStrncpy((wxChar*)devMode->dmDeviceName,m_printerName.c_str(),31); | |
409 | devMode->dmDeviceName[31] = wxT('\0'); | |
410 | } | |
411 | ||
412 | //// Colour | |
413 | ||
414 | if (m_colour) | |
415 | devMode->dmColor = DMCOLOR_COLOR; | |
416 | else | |
417 | devMode->dmColor = DMCOLOR_MONOCHROME; | |
418 | ||
419 | devMode->dmFields |= DM_COLOR; | |
420 | ||
421 | //// Paper size | |
422 | ||
423 | if (m_paperId == wxPAPER_NONE) | |
424 | { | |
425 | // DEVMODE is in tenths of a milimeter | |
426 | devMode->dmPaperWidth = m_paperSize.x * 10; | |
427 | devMode->dmPaperLength = m_paperSize.y * 10; | |
428 | devMode->dmPaperSize = DMPAPER_USER; | |
429 | devMode->dmFields |= DM_PAPERWIDTH; | |
430 | devMode->dmFields |= DM_PAPERLENGTH; | |
431 | } | |
432 | else | |
433 | { | |
434 | if (wxThePrintPaperDatabase) | |
435 | { | |
436 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId); | |
437 | if (paper) | |
438 | { | |
439 | devMode->dmPaperSize = paper->GetPlatformId(); | |
440 | devMode->dmFields |= DM_PAPERSIZE; | |
441 | } | |
442 | } | |
443 | } | |
444 | ||
445 | //// Duplex | |
446 | ||
447 | int duplex; | |
448 | switch (m_duplexMode) | |
449 | { | |
450 | case wxDUPLEX_HORIZONTAL: { | |
451 | duplex = DMDUP_HORIZONTAL; break; | |
452 | } | |
453 | case wxDUPLEX_VERTICAL: { | |
454 | duplex = DMDUP_VERTICAL; break; | |
455 | } | |
456 | default: | |
457 | case wxDUPLEX_SIMPLEX: { | |
458 | duplex = DMDUP_SIMPLEX; break; | |
459 | } | |
460 | } | |
461 | devMode->dmDuplex = duplex; | |
462 | devMode->dmFields |= DM_DUPLEX; | |
463 | ||
464 | //// Quality | |
465 | ||
466 | int quality; | |
467 | switch (m_printQuality) | |
468 | { | |
469 | case wxPRINT_QUALITY_MEDIUM: { | |
470 | quality = DMRES_MEDIUM; break; | |
471 | } | |
472 | case wxPRINT_QUALITY_LOW: { | |
473 | quality = DMRES_LOW; break; | |
474 | } | |
475 | case wxPRINT_QUALITY_DRAFT: { | |
476 | quality = DMRES_DRAFT; break; | |
477 | } | |
478 | case wxPRINT_QUALITY_HIGH: { | |
479 | quality = DMRES_HIGH; break; | |
480 | } | |
481 | default: { | |
482 | quality = m_printQuality; break; | |
483 | } | |
484 | } | |
485 | devMode->dmPrintQuality = quality; | |
486 | devMode->dmFields |= DM_PRINTQUALITY; | |
487 | ||
488 | GlobalUnlock(hDevMode); | |
489 | } | |
490 | ||
491 | if ( hDevNames ) | |
492 | { | |
493 | GlobalFree(hDevNames); | |
494 | } | |
495 | ||
496 | // TODO: I hope it's OK to pass some empty strings to DEVNAMES. | |
497 | m_devNames = (void*) (long) wxCreateDevNames(wxT(""), m_printerName, wxT("")); | |
498 | } | |
499 | ||
500 | void wxPrintData::ConvertFromNative() | |
501 | { | |
502 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; | |
503 | HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames; | |
504 | ||
505 | if (!hDevMode) | |
506 | return; | |
507 | ||
508 | if ( hDevMode ) | |
509 | { | |
510 | LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode); | |
511 | ||
512 | //// Orientation | |
513 | ||
514 | if (devMode->dmFields & DM_ORIENTATION) | |
515 | m_printOrientation = devMode->dmOrientation; | |
516 | ||
517 | //// Collation | |
518 | ||
519 | #ifndef __WIN16__ | |
520 | if (devMode->dmFields & DM_COLLATE) | |
521 | { | |
522 | if (devMode->dmCollate == DMCOLLATE_TRUE) | |
523 | m_printCollate = TRUE; | |
524 | else | |
525 | m_printCollate = FALSE; | |
526 | } | |
527 | #endif | |
528 | ||
529 | //// Number of copies | |
530 | ||
531 | if (devMode->dmFields & DM_COPIES) | |
532 | { | |
533 | m_printNoCopies = devMode->dmCopies; | |
534 | } | |
535 | ||
536 | //// Printer name | |
537 | ||
538 | if (devMode->dmDeviceName[0] != 0) | |
539 | { | |
540 | m_printerName = devMode->dmDeviceName; | |
541 | } | |
542 | ||
543 | //// Colour | |
544 | ||
545 | if (devMode->dmFields & DM_COLOR) | |
546 | { | |
547 | if (devMode->dmColor == DMCOLOR_COLOR) | |
548 | m_colour = TRUE; | |
549 | else | |
550 | m_colour = FALSE; | |
551 | } | |
552 | else | |
553 | m_colour = TRUE; | |
554 | ||
555 | //// Paper size | |
556 | ||
557 | // We don't know size of user defined paper and some buggy drivers | |
558 | // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since | |
559 | // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this | |
560 | // code wouldn't set m_paperSize correctly. | |
561 | if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER)) | |
562 | { | |
563 | if (wxThePrintPaperDatabase) | |
564 | { | |
565 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize); | |
566 | if (paper) | |
567 | { | |
568 | m_paperId = paper->GetId(); | |
569 | m_paperSize.x = paper->GetWidth() / 10; | |
570 | m_paperSize.y = paper->GetHeight() / 10; | |
571 | } | |
572 | else | |
573 | { | |
574 | // Shouldn't really get here | |
575 | wxFAIL_MSG(wxT("Couldn't find paper size in paper database.")); | |
576 | ||
577 | m_paperId = wxPAPER_NONE; | |
578 | m_paperSize.x = 0; | |
579 | m_paperSize.y = 0; | |
580 | } | |
581 | } | |
582 | else | |
583 | { | |
584 | // Shouldn't really get here | |
585 | wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative.")); | |
586 | ||
587 | m_paperId = wxPAPER_NONE; | |
588 | m_paperSize.x = 0; | |
589 | m_paperSize.y = 0; | |
590 | } | |
591 | } | |
592 | else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH)) | |
593 | { | |
594 | // DEVMODE is in tenths of a milimeter | |
595 | m_paperSize.x = devMode->dmPaperWidth / 10; | |
596 | m_paperSize.y = devMode->dmPaperLength / 10; | |
597 | m_paperId = wxPAPER_NONE; | |
598 | } | |
599 | else | |
600 | { | |
601 | // Shouldn't really get here | |
602 | wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE.")); | |
603 | ||
604 | m_paperSize.x = 0; | |
605 | m_paperSize.y = 0; | |
606 | m_paperId = wxPAPER_NONE; | |
607 | } | |
608 | ||
609 | //// Duplex | |
610 | ||
611 | if (devMode->dmFields & DM_DUPLEX) | |
612 | { | |
613 | switch (devMode->dmDuplex) | |
614 | { | |
615 | case DMDUP_HORIZONTAL: { | |
616 | m_duplexMode = wxDUPLEX_HORIZONTAL; break; | |
617 | } | |
618 | case DMDUP_VERTICAL: { | |
619 | m_duplexMode = wxDUPLEX_VERTICAL; break; | |
620 | } | |
621 | default: | |
622 | case DMDUP_SIMPLEX: { | |
623 | m_duplexMode = wxDUPLEX_SIMPLEX; break; | |
624 | } | |
625 | } | |
626 | } | |
627 | else | |
628 | m_duplexMode = wxDUPLEX_SIMPLEX; | |
629 | ||
630 | //// Quality | |
631 | ||
632 | if (devMode->dmFields & DM_PRINTQUALITY) | |
633 | { | |
634 | switch (devMode->dmPrintQuality) | |
635 | { | |
636 | case DMRES_MEDIUM: { | |
637 | m_printQuality = wxPRINT_QUALITY_MEDIUM; break; | |
638 | } | |
639 | case DMRES_LOW: { | |
640 | m_printQuality = wxPRINT_QUALITY_LOW; break; | |
641 | } | |
642 | case DMRES_DRAFT: { | |
643 | m_printQuality = wxPRINT_QUALITY_DRAFT; break; | |
644 | } | |
645 | case DMRES_HIGH: { | |
646 | m_printQuality = wxPRINT_QUALITY_HIGH; break; | |
647 | } | |
648 | default: | |
649 | { | |
650 | // TODO: if the printer fills in the resolution in DPI, how | |
651 | // will the application know if it's high, low, draft etc.?? | |
652 | // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values."); | |
653 | m_printQuality = devMode->dmPrintQuality; break; | |
654 | ||
655 | } | |
656 | } | |
657 | } | |
658 | else | |
659 | m_printQuality = wxPRINT_QUALITY_HIGH; | |
660 | ||
661 | GlobalUnlock(hDevMode); | |
662 | } | |
663 | ||
664 | if (hDevNames) | |
665 | { | |
666 | LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames); | |
667 | if (lpDevNames) | |
668 | { | |
669 | // TODO: Unicode-ification | |
670 | ||
671 | // Get the port name | |
672 | // port is obsolete in WIN32 | |
673 | // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset); | |
674 | ||
675 | // Get the printer name | |
676 | wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
677 | ||
678 | // Not sure if we should check for this mismatch | |
679 | // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); | |
680 | ||
681 | if (printerName != wxT("")) | |
682 | m_printerName = printerName; | |
683 | ||
684 | GlobalUnlock(hDevNames); | |
685 | } | |
686 | } | |
687 | } | |
688 | ||
689 | #endif | |
690 | ||
691 | #ifdef __WXMAC__ | |
692 | ||
693 | void wxPrintData::ConvertToNative() | |
694 | { | |
695 | m_nativePrintData->TransferFrom( this ) ; | |
696 | } | |
697 | ||
698 | void wxPrintData::ConvertFromNative() | |
699 | { | |
700 | m_nativePrintData->TransferTo( this ) ; | |
701 | } | |
702 | ||
703 | #endif | |
704 | ||
705 | void wxPrintData::operator=(const wxPrintData& data) | |
706 | { | |
707 | #ifdef __WXMAC__ | |
708 | m_nativePrintData->CopyFrom( data.m_nativePrintData ) ; | |
709 | #endif | |
710 | m_printNoCopies = data.m_printNoCopies; | |
711 | m_printCollate = data.m_printCollate; | |
712 | m_printOrientation = data.m_printOrientation; | |
713 | m_printerName = data.m_printerName; | |
714 | m_colour = data.m_colour; | |
715 | m_duplexMode = data.m_duplexMode; | |
716 | m_printQuality = data.m_printQuality; | |
717 | m_paperId = data.m_paperId; | |
718 | m_paperSize = data.m_paperSize; | |
719 | #ifdef wxUSE_STREAMS | |
720 | m_outputstream = data.m_outputstream; | |
721 | #endif | |
722 | ||
723 | // PostScript-specific data | |
724 | m_printerCommand = data.m_printerCommand; | |
725 | m_previewCommand = data.m_previewCommand; | |
726 | m_printerOptions = data.m_printerOptions; | |
727 | m_filename = data.m_filename; | |
728 | m_afmPath = data.m_afmPath; | |
729 | m_printerScaleX = data.m_printerScaleX; | |
730 | m_printerScaleY = data.m_printerScaleY; | |
731 | m_printerTranslateX = data.m_printerTranslateX; | |
732 | m_printerTranslateY = data.m_printerTranslateY; | |
733 | m_printMode = data.m_printMode; | |
734 | } | |
735 | ||
736 | // Is this data OK for showing the print dialog? | |
737 | bool wxPrintData::Ok() const | |
738 | { | |
739 | #ifdef __WXMSW__ | |
740 | ((wxPrintData*)this)->ConvertToNative(); | |
741 | return (m_devMode != NULL) ; | |
742 | #else | |
743 | return TRUE; | |
744 | #endif | |
745 | } | |
746 | ||
747 | // ---------------------------------------------------------------------------- | |
748 | // Print dialog data | |
749 | // ---------------------------------------------------------------------------- | |
750 | ||
751 | wxPrintDialogData::wxPrintDialogData() | |
752 | { | |
753 | #ifdef __WXMSW__ | |
754 | m_printDlgData = NULL; | |
755 | #endif | |
756 | m_printFromPage = 0; | |
757 | m_printToPage = 0; | |
758 | m_printMinPage = 0; | |
759 | m_printMaxPage = 0; | |
760 | m_printNoCopies = 1; | |
761 | m_printAllPages = FALSE; | |
762 | m_printCollate = FALSE; | |
763 | m_printToFile = FALSE; | |
764 | m_printSelection = FALSE; | |
765 | m_printEnableSelection = FALSE; | |
766 | m_printEnablePageNumbers = TRUE; | |
767 | m_printEnablePrintToFile = TRUE; | |
768 | m_printEnableHelp = FALSE; | |
769 | m_printSetupDialog = FALSE; | |
770 | } | |
771 | ||
772 | wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData) | |
773 | : wxObject() | |
774 | { | |
775 | #ifdef __WXMSW__ | |
776 | m_printDlgData = NULL; | |
777 | #endif | |
778 | (*this) = dialogData; | |
779 | } | |
780 | ||
781 | wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData) | |
782 | { | |
783 | #ifdef __WXMSW__ | |
784 | m_printDlgData = NULL; | |
785 | #endif | |
786 | m_printFromPage = 1; | |
787 | m_printToPage = 0; | |
788 | m_printMinPage = 1; | |
789 | m_printMaxPage = 9999; | |
790 | m_printNoCopies = 1; | |
791 | m_printAllPages = FALSE; | |
792 | m_printCollate = FALSE; | |
793 | m_printToFile = FALSE; | |
794 | m_printSelection = FALSE; | |
795 | m_printEnableSelection = FALSE; | |
796 | m_printEnablePageNumbers = TRUE; | |
797 | m_printEnablePrintToFile = TRUE; | |
798 | m_printEnableHelp = FALSE; | |
799 | m_printSetupDialog = FALSE; | |
800 | ||
801 | m_printData = printData; | |
802 | } | |
803 | ||
804 | wxPrintDialogData::~wxPrintDialogData() | |
805 | { | |
806 | #ifdef __WXMSW__ | |
807 | PRINTDLG *pd = (PRINTDLG *) m_printDlgData; | |
808 | if ( pd && pd->hDevMode ) | |
809 | GlobalFree(pd->hDevMode); | |
810 | if ( pd ) | |
811 | delete pd; | |
812 | #endif | |
813 | } | |
814 | ||
815 | #ifdef __WXMSW__ | |
816 | void wxPrintDialogData::ConvertToNative() | |
817 | { | |
818 | m_printData.ConvertToNative(); | |
819 | ||
820 | PRINTDLG *pd = (PRINTDLG*) m_printDlgData; | |
821 | ||
822 | if (!pd) | |
823 | { | |
824 | pd = new PRINTDLG; | |
825 | memset( pd, 0, sizeof(PRINTDLG) ); | |
826 | m_printDlgData = (void*) pd; | |
827 | ||
828 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. | |
829 | #ifdef __GNUWIN32__ | |
830 | pd->lStructSize = 66; | |
831 | #else | |
832 | pd->lStructSize = sizeof(PRINTDLG); | |
833 | #endif | |
834 | pd->hwndOwner = (HWND)NULL; | |
835 | pd->hDevMode = NULL; // Will be created by PrintDlg | |
836 | pd->hDevNames = NULL; // Ditto | |
837 | ||
838 | pd->Flags = PD_RETURNDEFAULT; | |
839 | pd->nCopies = 1; | |
840 | } | |
841 | ||
842 | // Pass the devmode data to the PRINTDLG structure, since it'll | |
843 | // be needed when PrintDlg is called. | |
844 | if (pd->hDevMode) | |
845 | { | |
846 | GlobalFree(pd->hDevMode); | |
847 | } | |
848 | ||
849 | // Pass the devnames data to the PRINTDLG structure, since it'll | |
850 | // be needed when PrintDlg is called. | |
851 | if (pd->hDevNames) | |
852 | { | |
853 | GlobalFree(pd->hDevNames); | |
854 | } | |
855 | ||
856 | pd->hDevMode = (HGLOBAL)(DWORD) m_printData.GetNativeData(); | |
857 | ||
858 | m_printData.SetNativeData((void*) NULL); | |
859 | ||
860 | // Shouldn't assert; we should be able to test Ok-ness at a higher level | |
861 | //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
862 | ||
863 | pd->hDevNames = (HGLOBAL)(DWORD) m_printData.GetNativeDataDevNames(); | |
864 | ||
865 | m_printData.SetNativeDataDevNames((void*) NULL); | |
866 | ||
867 | pd->hDC = (HDC) NULL; | |
868 | pd->nFromPage = (WORD)m_printFromPage; | |
869 | pd->nToPage = (WORD)m_printToPage; | |
870 | pd->nMinPage = (WORD)m_printMinPage; | |
871 | pd->nMaxPage = (WORD)m_printMaxPage; | |
872 | pd->nCopies = (WORD)m_printNoCopies; | |
873 | ||
874 | pd->Flags = PD_RETURNDC; | |
875 | ||
876 | #ifdef __GNUWIN32__ | |
877 | pd->lStructSize = 66; | |
878 | #else | |
879 | pd->lStructSize = sizeof( PRINTDLG ); | |
880 | #endif | |
881 | ||
882 | pd->hwndOwner=(HWND)NULL; | |
883 | // pd->hDevNames=(HANDLE)NULL; | |
884 | pd->hInstance=(HINSTANCE)NULL; | |
885 | pd->lCustData = (LPARAM) NULL; | |
886 | pd->lpfnPrintHook = NULL; | |
887 | pd->lpfnSetupHook = NULL; | |
888 | pd->lpPrintTemplateName = NULL; | |
889 | pd->lpSetupTemplateName = NULL; | |
890 | pd->hPrintTemplate = (HGLOBAL) NULL; | |
891 | pd->hSetupTemplate = (HGLOBAL) NULL; | |
892 | ||
893 | if ( m_printAllPages ) | |
894 | pd->Flags |= PD_ALLPAGES; | |
895 | if ( m_printSelection ) | |
896 | pd->Flags |= PD_SELECTION; | |
897 | if ( m_printCollate ) | |
898 | pd->Flags |= PD_COLLATE; | |
899 | if ( m_printToFile ) | |
900 | pd->Flags |= PD_PRINTTOFILE; | |
901 | if ( !m_printEnablePrintToFile ) | |
902 | pd->Flags |= PD_DISABLEPRINTTOFILE; | |
903 | if ( !m_printEnableSelection ) | |
904 | pd->Flags |= PD_NOSELECTION; | |
905 | if ( !m_printEnablePageNumbers ) | |
906 | pd->Flags |= PD_NOPAGENUMS; | |
907 | else if ( (!m_printAllPages) && (!m_printSelection) && (m_printFromPage != 0) && (m_printToPage != 0)) | |
908 | pd->Flags |= PD_PAGENUMS; | |
909 | if ( m_printEnableHelp ) | |
910 | pd->Flags |= PD_SHOWHELP; | |
911 | if ( m_printSetupDialog ) | |
912 | pd->Flags |= PD_PRINTSETUP; | |
913 | } | |
914 | ||
915 | void wxPrintDialogData::ConvertFromNative() | |
916 | { | |
917 | PRINTDLG *pd = (PRINTDLG*) m_printDlgData; | |
918 | if ( pd == NULL ) | |
919 | return; | |
920 | ||
921 | // Pass the devmode data back to the wxPrintData structure where it really belongs. | |
922 | if (pd->hDevMode) | |
923 | { | |
924 | if (m_printData.GetNativeData()) | |
925 | { | |
926 | // Make sure we don't leak memory | |
927 | GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeData()); | |
928 | } | |
929 | m_printData.SetNativeData((void*)(long) pd->hDevMode); | |
930 | pd->hDevMode = NULL; | |
931 | } | |
932 | ||
933 | // Pass the devnames data back to the wxPrintData structure where it really belongs. | |
934 | if (pd->hDevNames) | |
935 | { | |
936 | if (m_printData.GetNativeDataDevNames()) | |
937 | { | |
938 | // Make sure we don't leak memory | |
939 | GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeDataDevNames()); | |
940 | } | |
941 | m_printData.SetNativeDataDevNames((void*)(long) pd->hDevNames); | |
942 | pd->hDevNames = NULL; | |
943 | } | |
944 | ||
945 | // Now convert the DEVMODE object, passed down from the PRINTDLG object, | |
946 | // into wxWindows form. | |
947 | m_printData.ConvertFromNative(); | |
948 | ||
949 | m_printFromPage = pd->nFromPage; | |
950 | m_printToPage = pd->nToPage; | |
951 | m_printMinPage = pd->nMinPage; | |
952 | m_printMaxPage = pd->nMaxPage; | |
953 | m_printNoCopies = pd->nCopies; | |
954 | ||
955 | m_printAllPages = (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION)); | |
956 | m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION); | |
957 | m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE); | |
958 | m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE); | |
959 | m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE); | |
960 | m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION); | |
961 | m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS); | |
962 | m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP); | |
963 | m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP); | |
964 | ||
965 | /* port is obsolete in WIN32 | |
966 | // Get the port name | |
967 | if (pd->hDevNames) | |
968 | { | |
969 | LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames); | |
970 | if (lpDevNames) { | |
971 | m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset); | |
972 | wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
973 | GlobalUnlock(pd->hDevNames); | |
974 | ||
975 | // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); | |
976 | } | |
977 | } | |
978 | */ | |
979 | } | |
980 | ||
981 | void wxPrintDialogData::SetOwnerWindow(wxWindow* win) | |
982 | { | |
983 | if ( m_printDlgData == NULL ) | |
984 | ConvertToNative(); | |
985 | ||
986 | if ( m_printDlgData != NULL && win != NULL) | |
987 | { | |
988 | PRINTDLG *pd = (PRINTDLG *) m_printDlgData; | |
989 | pd->hwndOwner=(HWND) win->GetHWND(); | |
990 | } | |
991 | } | |
992 | #endif // MSW | |
993 | ||
994 | #ifdef __WXMAC__ | |
995 | ||
996 | void wxPrintDialogData::ConvertToNative() | |
997 | { | |
998 | m_printData.ConvertToNative(); | |
999 | m_printData.m_nativePrintData->TransferFrom( this ) ; | |
1000 | } | |
1001 | ||
1002 | void wxPrintDialogData::ConvertFromNative() | |
1003 | { | |
1004 | m_printData.ConvertFromNative(); | |
1005 | m_printData.m_nativePrintData->TransferTo( this ) ; | |
1006 | } | |
1007 | ||
1008 | #endif | |
1009 | ||
1010 | ||
1011 | void wxPrintDialogData::operator=(const wxPrintDialogData& data) | |
1012 | { | |
1013 | m_printFromPage = data.m_printFromPage; | |
1014 | m_printToPage = data.m_printToPage; | |
1015 | m_printMinPage = data.m_printMinPage; | |
1016 | m_printMaxPage = data.m_printMaxPage; | |
1017 | m_printNoCopies = data.m_printNoCopies; | |
1018 | m_printAllPages = data.m_printAllPages; | |
1019 | m_printCollate = data.m_printCollate; | |
1020 | m_printToFile = data.m_printToFile; | |
1021 | m_printSelection = data.m_printSelection; | |
1022 | m_printEnableSelection = data.m_printEnableSelection; | |
1023 | m_printEnablePageNumbers = data.m_printEnablePageNumbers; | |
1024 | m_printEnableHelp = data.m_printEnableHelp; | |
1025 | m_printEnablePrintToFile = data.m_printEnablePrintToFile; | |
1026 | m_printSetupDialog = data.m_printSetupDialog; | |
1027 | ||
1028 | m_printData = data.m_printData; | |
1029 | } | |
1030 | ||
1031 | void wxPrintDialogData::operator=(const wxPrintData& data) | |
1032 | { | |
1033 | m_printData = data; | |
1034 | } | |
1035 | ||
1036 | // ---------------------------------------------------------------------------- | |
1037 | // wxPageSetupDialogData | |
1038 | // ---------------------------------------------------------------------------- | |
1039 | ||
1040 | wxPageSetupDialogData::wxPageSetupDialogData() | |
1041 | { | |
1042 | #if defined(__WIN95__) | |
1043 | m_pageSetupData = NULL; | |
1044 | #endif | |
1045 | m_paperSize = wxSize(0, 0); | |
1046 | ||
1047 | CalculatePaperSizeFromId(); | |
1048 | ||
1049 | m_minMarginTopLeft = wxPoint(0, 0); | |
1050 | m_minMarginBottomRight = wxPoint(0, 0); | |
1051 | m_marginTopLeft = wxPoint(0, 0); | |
1052 | m_marginBottomRight = wxPoint(0, 0); | |
1053 | ||
1054 | // Flags | |
1055 | m_defaultMinMargins = FALSE; | |
1056 | m_enableMargins = TRUE; | |
1057 | m_enableOrientation = TRUE; | |
1058 | m_enablePaper = TRUE; | |
1059 | m_enablePrinter = TRUE; | |
1060 | m_enableHelp = FALSE; | |
1061 | m_getDefaultInfo = FALSE; | |
1062 | } | |
1063 | ||
1064 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData) | |
1065 | : wxObject() | |
1066 | { | |
1067 | #if defined(__WIN95__) | |
1068 | m_pageSetupData = NULL; | |
1069 | #endif | |
1070 | (*this) = dialogData; | |
1071 | } | |
1072 | ||
1073 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData) | |
1074 | { | |
1075 | #if defined(__WIN95__) | |
1076 | m_pageSetupData = NULL; | |
1077 | #endif | |
1078 | m_paperSize = wxSize(0, 0); | |
1079 | m_minMarginTopLeft = wxPoint(0, 0); | |
1080 | m_minMarginBottomRight = wxPoint(0, 0); | |
1081 | m_marginTopLeft = wxPoint(0, 0); | |
1082 | m_marginBottomRight = wxPoint(0, 0); | |
1083 | ||
1084 | // Flags | |
1085 | m_defaultMinMargins = FALSE; | |
1086 | m_enableMargins = TRUE; | |
1087 | m_enableOrientation = TRUE; | |
1088 | m_enablePaper = TRUE; | |
1089 | m_enablePrinter = TRUE; | |
1090 | m_enableHelp = FALSE; | |
1091 | m_getDefaultInfo = FALSE; | |
1092 | ||
1093 | m_printData = printData; | |
1094 | ||
1095 | // The wxPrintData paper size overrides these values, unless the size cannot | |
1096 | // be found. | |
1097 | CalculatePaperSizeFromId(); | |
1098 | } | |
1099 | ||
1100 | wxPageSetupDialogData::~wxPageSetupDialogData() | |
1101 | { | |
1102 | #if defined(__WIN95__) && defined(__WXMSW__) | |
1103 | PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData; | |
1104 | if ( pd && pd->hDevMode ) | |
1105 | GlobalFree(pd->hDevMode); | |
1106 | if ( pd && pd->hDevNames ) | |
1107 | GlobalFree(pd->hDevNames); | |
1108 | if ( pd ) | |
1109 | delete pd; | |
1110 | #endif | |
1111 | } | |
1112 | ||
1113 | wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data) | |
1114 | { | |
1115 | m_paperSize = data.m_paperSize; | |
1116 | m_minMarginTopLeft = data.m_minMarginTopLeft; | |
1117 | m_minMarginBottomRight = data.m_minMarginBottomRight; | |
1118 | m_marginTopLeft = data.m_marginTopLeft; | |
1119 | m_marginBottomRight = data.m_marginBottomRight; | |
1120 | m_defaultMinMargins = data.m_defaultMinMargins; | |
1121 | m_enableMargins = data.m_enableMargins; | |
1122 | m_enableOrientation = data.m_enableOrientation; | |
1123 | m_enablePaper = data.m_enablePaper; | |
1124 | m_enablePrinter = data.m_enablePrinter; | |
1125 | m_getDefaultInfo = data.m_getDefaultInfo;; | |
1126 | m_enableHelp = data.m_enableHelp; | |
1127 | ||
1128 | m_printData = data.m_printData; | |
1129 | ||
1130 | return *this; | |
1131 | } | |
1132 | ||
1133 | wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data) | |
1134 | { | |
1135 | m_printData = data; | |
1136 | ||
1137 | return *this; | |
1138 | } | |
1139 | ||
1140 | #if defined(__WIN95__) | |
1141 | void wxPageSetupDialogData::ConvertToNative() | |
1142 | { | |
1143 | m_printData.ConvertToNative(); | |
1144 | ||
1145 | PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData; | |
1146 | ||
1147 | if ( m_pageSetupData == NULL ) | |
1148 | { | |
1149 | pd = new PAGESETUPDLG; | |
1150 | pd->hDevMode = NULL; | |
1151 | pd->hDevNames = NULL; | |
1152 | m_pageSetupData = (void *)pd; | |
1153 | } | |
1154 | ||
1155 | // Pass the devmode data (created in m_printData.ConvertToNative) | |
1156 | // to the PRINTDLG structure, since it'll | |
1157 | // be needed when PrintDlg is called. | |
1158 | ||
1159 | if (pd->hDevMode) | |
1160 | { | |
1161 | GlobalFree(pd->hDevMode); | |
1162 | pd->hDevMode = NULL; | |
1163 | } | |
1164 | ||
1165 | pd->hDevMode = (HGLOBAL) m_printData.GetNativeData(); | |
1166 | ||
1167 | m_printData.SetNativeData((void*) NULL); | |
1168 | ||
1169 | // Shouldn't assert; we should be able to test Ok-ness at a higher level | |
1170 | //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
1171 | ||
1172 | // Pass the devnames data (created in m_printData.ConvertToNative) | |
1173 | // to the PRINTDLG structure, since it'll | |
1174 | // be needed when PrintDlg is called. | |
1175 | ||
1176 | if (pd->hDevNames) | |
1177 | { | |
1178 | GlobalFree(pd->hDevNames); | |
1179 | pd->hDevNames = NULL; | |
1180 | } | |
1181 | ||
1182 | pd->hDevNames = (HGLOBAL) m_printData.GetNativeDataDevNames(); | |
1183 | ||
1184 | m_printData.SetNativeDataDevNames((void*) NULL); | |
1185 | ||
1186 | // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE)); | |
1187 | ||
1188 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; | |
1189 | ||
1190 | if ( m_defaultMinMargins ) | |
1191 | pd->Flags |= PSD_DEFAULTMINMARGINS; | |
1192 | if ( !m_enableMargins ) | |
1193 | pd->Flags |= PSD_DISABLEMARGINS; | |
1194 | if ( !m_enableOrientation ) | |
1195 | pd->Flags |= PSD_DISABLEORIENTATION; | |
1196 | if ( !m_enablePaper ) | |
1197 | pd->Flags |= PSD_DISABLEPAPER; | |
1198 | if ( !m_enablePrinter ) | |
1199 | pd->Flags |= PSD_DISABLEPRINTER; | |
1200 | if ( m_getDefaultInfo ) | |
1201 | pd->Flags |= PSD_RETURNDEFAULT; | |
1202 | if ( m_enableHelp ) | |
1203 | pd->Flags |= PSD_SHOWHELP; | |
1204 | ||
1205 | // We want the units to be in hundredths of a millimetre | |
1206 | pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS; | |
1207 | ||
1208 | pd->lStructSize = sizeof( PAGESETUPDLG ); | |
1209 | pd->hwndOwner=(HWND)NULL; | |
1210 | // pd->hDevNames=(HWND)NULL; | |
1211 | pd->hInstance=(HINSTANCE)NULL; | |
1212 | // PAGESETUPDLG is in hundreds of a mm | |
1213 | pd->ptPaperSize.x = m_paperSize.x * 100; | |
1214 | pd->ptPaperSize.y = m_paperSize.y * 100; | |
1215 | ||
1216 | pd->rtMinMargin.left = m_minMarginTopLeft.x * 100; | |
1217 | pd->rtMinMargin.top = m_minMarginTopLeft.y * 100; | |
1218 | pd->rtMinMargin.right = m_minMarginBottomRight.x * 100; | |
1219 | pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100; | |
1220 | ||
1221 | pd->rtMargin.left = m_marginTopLeft.x * 100; | |
1222 | pd->rtMargin.top = m_marginTopLeft.y * 100; | |
1223 | pd->rtMargin.right = m_marginBottomRight.x * 100; | |
1224 | pd->rtMargin.bottom = m_marginBottomRight.y * 100; | |
1225 | ||
1226 | pd->lCustData = 0; | |
1227 | pd->lpfnPageSetupHook = NULL; | |
1228 | pd->lpfnPagePaintHook = NULL; | |
1229 | pd->hPageSetupTemplate = NULL; | |
1230 | pd->lpPageSetupTemplateName = NULL; | |
1231 | ||
1232 | /* | |
1233 | if ( pd->hDevMode ) | |
1234 | { | |
1235 | DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); | |
1236 | memset(devMode, 0, sizeof(DEVMODE)); | |
1237 | devMode->dmSize = sizeof(DEVMODE); | |
1238 | devMode->dmOrientation = m_orientation; | |
1239 | devMode->dmFields = DM_ORIENTATION; | |
1240 | GlobalUnlock(pd->hDevMode); | |
1241 | } | |
1242 | */ | |
1243 | } | |
1244 | ||
1245 | void wxPageSetupDialogData::ConvertFromNative() | |
1246 | { | |
1247 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData; | |
1248 | if ( !pd ) | |
1249 | return; | |
1250 | ||
1251 | // Pass the devmode data back to the wxPrintData structure where it really belongs. | |
1252 | if (pd->hDevMode) | |
1253 | { | |
1254 | if (m_printData.GetNativeData()) | |
1255 | { | |
1256 | // Make sure we don't leak memory | |
1257 | GlobalFree((HGLOBAL) m_printData.GetNativeData()); | |
1258 | } | |
1259 | m_printData.SetNativeData((void*) pd->hDevMode); | |
1260 | pd->hDevMode = NULL; | |
1261 | } | |
1262 | ||
1263 | m_printData.ConvertFromNative(); | |
1264 | ||
1265 | // Pass the devnames data back to the wxPrintData structure where it really belongs. | |
1266 | if (pd->hDevNames) | |
1267 | { | |
1268 | if (m_printData.GetNativeDataDevNames()) | |
1269 | { | |
1270 | // Make sure we don't leak memory | |
1271 | GlobalFree((HGLOBAL) m_printData.GetNativeDataDevNames()); | |
1272 | } | |
1273 | m_printData.SetNativeDataDevNames((void*) pd->hDevNames); | |
1274 | pd->hDevNames = NULL; | |
1275 | } | |
1276 | ||
1277 | m_printData.ConvertFromNative(); | |
1278 | ||
1279 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; | |
1280 | ||
1281 | m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS); | |
1282 | m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS); | |
1283 | m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION); | |
1284 | m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER); | |
1285 | m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER); | |
1286 | m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT); | |
1287 | m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP); | |
1288 | ||
1289 | // PAGESETUPDLG is in hundreds of a mm | |
1290 | m_paperSize.x = pd->ptPaperSize.x / 100; | |
1291 | m_paperSize.y = pd->ptPaperSize.y / 100; | |
1292 | ||
1293 | m_minMarginTopLeft.x = pd->rtMinMargin.left / 100; | |
1294 | m_minMarginTopLeft.y = pd->rtMinMargin.top / 100; | |
1295 | m_minMarginBottomRight.x = pd->rtMinMargin.right / 100; | |
1296 | m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100; | |
1297 | ||
1298 | m_marginTopLeft.x = pd->rtMargin.left / 100; | |
1299 | m_marginTopLeft.y = pd->rtMargin.top / 100; | |
1300 | m_marginBottomRight.x = pd->rtMargin.right / 100; | |
1301 | m_marginBottomRight.y = pd->rtMargin.bottom / 100; | |
1302 | } | |
1303 | ||
1304 | void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win) | |
1305 | { | |
1306 | if ( m_pageSetupData == NULL ) | |
1307 | ConvertToNative(); | |
1308 | ||
1309 | if ( m_pageSetupData != NULL && win != NULL) | |
1310 | { | |
1311 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData; | |
1312 | pd->hwndOwner=(HWND) win->GetHWND(); | |
1313 | } | |
1314 | } | |
1315 | #endif // Win95 | |
1316 | ||
1317 | #ifdef __WXMAC__ | |
1318 | void wxPageSetupDialogData::ConvertToNative() | |
1319 | { | |
1320 | m_printData.ConvertToNative(); | |
1321 | m_printData.m_nativePrintData->TransferFrom( this ) ; | |
1322 | } | |
1323 | ||
1324 | void wxPageSetupDialogData::ConvertFromNative() | |
1325 | { | |
1326 | m_printData.ConvertFromNative (); | |
1327 | m_paperSize = m_printData.GetPaperSize() ; | |
1328 | CalculateIdFromPaperSize(); | |
1329 | m_printData.m_nativePrintData->TransferTo( this ) ; | |
1330 | // adjust minimal values | |
1331 | ||
1332 | if ( m_marginTopLeft.x < m_minMarginTopLeft.x ) | |
1333 | m_marginTopLeft.x = m_minMarginTopLeft.x; | |
1334 | ||
1335 | if ( m_marginBottomRight.x < m_minMarginBottomRight.x ) | |
1336 | m_marginBottomRight.x = m_minMarginBottomRight.x; | |
1337 | ||
1338 | if ( m_marginTopLeft.y < m_minMarginTopLeft.y ) | |
1339 | m_marginTopLeft.y = m_minMarginTopLeft.y; | |
1340 | ||
1341 | if ( m_marginBottomRight.y < m_minMarginBottomRight.y ) | |
1342 | m_marginBottomRight.y = m_minMarginBottomRight.y; | |
1343 | } | |
1344 | #endif | |
1345 | ||
1346 | ||
1347 | // If a corresponding paper type is found in the paper database, will set the m_printData | |
1348 | // paper size id member as well. | |
1349 | void wxPageSetupDialogData::SetPaperSize(const wxSize& sz) | |
1350 | { | |
1351 | m_paperSize = sz; | |
1352 | ||
1353 | CalculateIdFromPaperSize(); | |
1354 | } | |
1355 | ||
1356 | // Sets the wxPrintData id, plus the paper width/height if found in the paper database. | |
1357 | void wxPageSetupDialogData::SetPaperSize(wxPaperSize id) | |
1358 | { | |
1359 | m_printData.SetPaperId(id); | |
1360 | ||
1361 | CalculatePaperSizeFromId(); | |
1362 | } | |
1363 | ||
1364 | // Use paper size defined in this object to set the wxPrintData | |
1365 | // paper id | |
1366 | void wxPageSetupDialogData::CalculateIdFromPaperSize() | |
1367 | { | |
1368 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), | |
1369 | wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") ); | |
1370 | ||
1371 | wxSize sz = GetPaperSize(); | |
1372 | ||
1373 | wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10)); | |
1374 | if (id != wxPAPER_NONE) | |
1375 | { | |
1376 | m_printData.SetPaperId(id); | |
1377 | } | |
1378 | } | |
1379 | ||
1380 | // Use paper id in wxPrintData to set this object's paper size | |
1381 | void wxPageSetupDialogData::CalculatePaperSizeFromId() | |
1382 | { | |
1383 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), | |
1384 | wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") ); | |
1385 | ||
1386 | wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId()); | |
1387 | ||
1388 | // sz is in 10ths of a mm, while paper size is in mm | |
1389 | m_paperSize.x = sz.x / 10; | |
1390 | m_paperSize.y = sz.y / 10; | |
1391 | } | |
1392 | ||
1393 | #endif // wxUSE_PRINTING_ARCHITECTURE |