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