]> git.saurik.com Git - wxWidgets.git/blob - src/common/cmndata.cpp
Makefile corrections after the setup.h changes.
[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__)) && 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 !USE_SHARED_LIBRARY
76 #if wxUSE_PRINTING_ARCHITECTURE
77 IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
78 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
79 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject)
80 #endif // wxUSE_PRINTING_ARCHITECTURE
81 IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
82 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
83 #endif
84
85 // ============================================================================
86 // implementation
87 // ============================================================================
88
89 // ----------------------------------------------------------------------------
90 // wxColourData
91 // ----------------------------------------------------------------------------
92
93 wxColourData::wxColourData()
94 {
95 int i;
96 for (i = 0; i < 16; i++)
97 custColours[i].Set(255, 255, 255);
98
99 chooseFull = FALSE;
100 dataColour.Set(0,0,0);
101 }
102
103 wxColourData::wxColourData(const wxColourData& data)
104 {
105 (*this) = data;
106 }
107
108 wxColourData::~wxColourData()
109 {
110 }
111
112 void wxColourData::SetCustomColour(int i, wxColour& colour)
113 {
114 if (i > 15 || i < 0)
115 return;
116
117 custColours[i] = colour;
118 }
119
120 wxColour wxColourData::GetCustomColour(int i)
121 {
122 if (i > 15 || i < 0)
123 return wxColour(0,0,0);
124
125 return custColours[i];
126 }
127
128 void wxColourData::operator=(const wxColourData& data)
129 {
130 int i;
131 for (i = 0; i < 16; i++)
132 custColours[i] = data.custColours[i];
133
134 dataColour = (wxColour&)data.dataColour;
135 chooseFull = data.chooseFull;
136 }
137
138 // ----------------------------------------------------------------------------
139 // Font data
140 // ----------------------------------------------------------------------------
141
142 wxFontData::wxFontData()
143 {
144 // Intialize colour to black.
145 fontColour.Set(0, 0, 0);
146
147 showHelp = FALSE;
148 allowSymbols = TRUE;
149 enableEffects = TRUE;
150 minSize = 0;
151 maxSize = 0;
152 }
153
154 wxFontData::wxFontData(const wxFontData& data)
155 {
156 (*this) = data;
157 }
158
159 wxFontData::~wxFontData()
160 {
161 }
162
163 void wxFontData::operator=(const wxFontData& data)
164 {
165 fontColour = data.fontColour;
166 showHelp = data.showHelp;
167 allowSymbols = data.allowSymbols;
168 enableEffects = data.enableEffects;
169 initialFont = data.initialFont;
170 chosenFont = data.chosenFont;
171 minSize = data.minSize;
172 maxSize = data.maxSize;
173 }
174
175 #if wxUSE_PRINTING_ARCHITECTURE
176 // ----------------------------------------------------------------------------
177 // Print data
178 // ----------------------------------------------------------------------------
179
180 wxPrintData::wxPrintData()
181 {
182 #ifdef __WXMSW__
183 m_devMode = NULL;
184 #endif
185 m_printOrientation = wxPORTRAIT;
186 m_printNoCopies = 1;
187 m_printCollate = FALSE;
188
189 // New, 24/3/99
190 m_printerName = "";
191 m_colour = TRUE;
192 m_duplexMode = wxDUPLEX_SIMPLEX;
193 m_printQuality = wxPRINT_QUALITY_HIGH;
194 m_paperId = wxPAPER_A4;
195 m_paperSize = wxSize(210, 297);
196
197 // PostScript-specific data
198 m_printerCommand = "";
199 m_previewCommand = "";
200 m_printerOptions = "";
201 m_filename = "";
202 m_afmPath = "";
203 m_printerScaleX = 1.0;
204 m_printerScaleY = 1.0;
205 m_printerTranslateX = 0;
206 m_printerTranslateY = 0;
207 m_printMode = wxPRINT_MODE_FILE;
208 }
209
210 wxPrintData::wxPrintData(const wxPrintData& printData)
211 {
212 #ifdef __WXMSW__
213 m_devMode = NULL;
214 #endif
215
216 (*this) = printData;
217 }
218
219 wxPrintData::~wxPrintData()
220 {
221 #ifdef __WXMSW__
222 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
223 if (hDevMode )
224 GlobalFree(hDevMode);
225 #endif
226 }
227
228 #if defined(__WXMSW__) // && defined(__WIN32__)
229
230 #ifdef __WIN32__
231 static wxString wxGetPrintDlgError()
232 {
233 DWORD err = CommDlgExtendedError();
234 wxString msg = wxT("Unknown");
235 switch (err)
236 {
237 case CDERR_FINDRESFAILURE: msg = wxT("CDERR_FINDRESFAILURE"); break;
238 case CDERR_INITIALIZATION: msg = wxT("CDERR_INITIALIZATION"); break;
239 case CDERR_LOADRESFAILURE: msg = wxT("CDERR_LOADRESFAILURE"); break;
240 case CDERR_LOADSTRFAILURE: msg = wxT("CDERR_LOADSTRFAILURE"); break;
241 case CDERR_LOCKRESFAILURE: msg = wxT("CDERR_LOCKRESFAILURE"); break;
242 case CDERR_MEMALLOCFAILURE: msg = wxT("CDERR_MEMALLOCFAILURE"); break;
243 case CDERR_MEMLOCKFAILURE: msg = wxT("CDERR_MEMLOCKFAILURE"); break;
244 case CDERR_NOHINSTANCE: msg = wxT("CDERR_NOHINSTANCE"); break;
245 case CDERR_NOHOOK: msg = wxT("CDERR_NOHOOK"); break;
246 case CDERR_NOTEMPLATE: msg = wxT("CDERR_NOTEMPLATE"); break;
247 case CDERR_STRUCTSIZE: msg = wxT("CDERR_STRUCTSIZE"); break;
248 case PDERR_RETDEFFAILURE: msg = wxT("PDERR_RETDEFFAILURE"); break;
249 case PDERR_PRINTERNOTFOUND: msg = wxT("PDERR_PRINTERNOTFOUND"); break;
250 case PDERR_PARSEFAILURE: msg = wxT("PDERR_PARSEFAILURE"); break;
251 case PDERR_NODEVICES: msg = wxT("PDERR_NODEVICES"); break;
252 case PDERR_NODEFAULTPRN: msg = wxT("PDERR_NODEFAULTPRN"); break;
253 case PDERR_LOADDRVFAILURE: msg = wxT("PDERR_LOADDRVFAILURE"); break;
254 case PDERR_INITFAILURE: msg = wxT("PDERR_INITFAILURE"); break;
255 case PDERR_GETDEVMODEFAIL: msg = wxT("PDERR_GETDEVMODEFAIL"); break;
256 case PDERR_DNDMMISMATCH: msg = wxT("PDERR_DNDMMISMATCH"); break;
257 case PDERR_DEFAULTDIFFERENT: msg = wxT("PDERR_DEFAULTDIFFERENT"); break;
258 case PDERR_CREATEICFAILURE: msg = wxT("PDERR_CREATEICFAILURE"); break;
259 default: break;
260 }
261 return msg;
262 }
263 #endif
264
265 void wxPrintData::ConvertToNative()
266 {
267 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
268 if (!hDevMode)
269 {
270 // Use PRINTDLG as a way of creating a DEVMODE object
271 PRINTDLG *pd = new PRINTDLG;
272
273 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
274 #ifdef __GNUWIN32__
275 memset(pd, 0, 66);
276 pd->lStructSize = 66 ;
277 #else
278 memset(pd, 0, sizeof(PRINTDLG));
279 pd->lStructSize = sizeof(PRINTDLG);
280 #endif
281
282 pd->hwndOwner = (HWND)NULL;
283 pd->hDevMode = NULL; // Will be created by PrintDlg
284 pd->hDevNames = NULL; // Ditto
285 pd->hInstance = (HINSTANCE) wxGetInstance();
286
287 pd->Flags = PD_RETURNDEFAULT;
288 pd->nCopies = 1;
289
290 // Fill out the DEVMODE structure
291 // so we can use it as input in the 'real' PrintDlg
292 if (!PrintDlg(pd))
293 {
294 if ( pd->hDevMode )
295 GlobalFree(pd->hDevMode);
296 if ( pd->hDevNames )
297 GlobalFree(pd->hDevNames);
298 pd->hDevMode = NULL;
299 pd->hDevNames = NULL;
300
301 #if defined(__WXDEBUG__) && defined(__WIN32__)
302 wxString str(wxT("Printing error: "));
303 str += wxGetPrintDlgError();
304 wxLogDebug(str);
305 #endif
306 }
307 else
308 {
309 if ( pd->hDevNames )
310 GlobalFree(pd->hDevNames);
311 pd->hDevNames = NULL;
312
313 hDevMode = pd->hDevMode;
314 m_devMode = (void*)(long) hDevMode;
315 pd->hDevMode = NULL;
316 }
317
318 delete pd;
319 }
320
321 if ( hDevMode )
322 {
323 DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode);
324
325 //// Orientation
326
327 #ifndef __WXWINE__
328 devMode->dmOrientation = m_printOrientation;
329 #endif
330 devMode->dmFields = DM_ORIENTATION;
331
332 //// Collation
333
334 #ifndef __WIN16__
335 devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
336 devMode->dmFields |= DM_COLLATE;
337 #endif
338
339 //// Number of copies
340
341 devMode->dmCopies = m_printNoCopies;
342 devMode->dmFields |= DM_COPIES;
343
344 //// Printer name
345
346 if (m_printerName != wxT(""))
347 {
348 // TODO: make this Unicode compatible
349 int len = wxMin(31, m_printerName.Len());
350 int i;
351 for (i = 0; i < len; i++)
352 devMode->dmDeviceName[i] = m_printerName.GetChar(i);
353 devMode->dmDeviceName[i] = 0;
354 }
355
356 //// Colour
357
358 if (m_colour)
359 devMode->dmColor = DMCOLOR_COLOR;
360 else
361 devMode->dmColor = DMCOLOR_MONOCHROME;
362
363 devMode->dmFields |= DM_COLOR;
364
365 #ifndef __WXWINE__
366 //// Paper size
367
368 if (m_paperId == wxPAPER_NONE)
369 {
370 devMode->dmPaperWidth = m_paperSize.x * 10;
371 devMode->dmPaperLength = m_paperSize.y * 10;
372 devMode->dmFields |= DM_PAPERWIDTH;
373 devMode->dmFields |= DM_PAPERLENGTH;
374 }
375 else
376 {
377 if (wxThePrintPaperDatabase)
378 {
379 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId);
380 if (paper)
381 {
382 devMode->dmPaperSize = paper->GetPlatformId();
383 devMode->dmFields |= DM_PAPERSIZE;
384 }
385 }
386 }
387 #endif
388
389 //// Duplex
390
391 int duplex;
392 switch (m_duplexMode)
393 {
394 case wxDUPLEX_HORIZONTAL: {
395 duplex = DMDUP_HORIZONTAL; break;
396 }
397 case wxDUPLEX_VERTICAL: {
398 duplex = DMDUP_VERTICAL; break;
399 }
400 default:
401 case wxDUPLEX_SIMPLEX: {
402 duplex = DMDUP_SIMPLEX; break;
403 }
404 }
405 devMode->dmDuplex = duplex;
406 devMode->dmFields |= DM_DUPLEX;
407
408 //// Quality
409
410 int quality;
411 switch (m_printQuality)
412 {
413 case wxPRINT_QUALITY_MEDIUM: {
414 quality = DMRES_MEDIUM; break;
415 }
416 case wxPRINT_QUALITY_LOW: {
417 quality = DMRES_LOW; break;
418 }
419 case wxPRINT_QUALITY_DRAFT: {
420 quality = DMRES_DRAFT; break;
421 }
422 case wxPRINT_QUALITY_HIGH: {
423 quality = DMRES_HIGH; break;
424 }
425 default: {
426 quality = m_printQuality; break;
427 }
428 }
429 devMode->dmPrintQuality = quality;
430 devMode->dmFields |= DM_PRINTQUALITY;
431
432 GlobalUnlock(hDevMode);
433 }
434 }
435
436 void wxPrintData::ConvertFromNative()
437 {
438 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
439
440 if (!hDevMode)
441 return;
442
443 if ( hDevMode )
444 {
445 DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode);
446
447 #ifndef __WXWINE__
448 //// Orientation
449
450 if (devMode->dmFields & DM_ORIENTATION)
451 m_printOrientation = devMode->dmOrientation;
452 #endif
453
454 //// Collation
455
456 #ifndef __WIN16__
457 if (devMode->dmFields & DM_COLLATE)
458 {
459 if (devMode->dmCollate == DMCOLLATE_TRUE)
460 m_printCollate = TRUE;
461 else
462 m_printCollate = FALSE;
463 }
464 #endif
465
466 //// Number of copies
467
468 if (devMode->dmFields & DM_COPIES)
469 {
470 m_printNoCopies = devMode->dmCopies;
471 }
472
473 //// Printer name
474
475 if (devMode->dmDeviceName[0] != 0)
476 {
477 // TODO: make this Unicode compatible
478 char buf[32];
479 int i = 0;
480 while (devMode->dmDeviceName[i] != 0)
481 {
482 buf[i] = devMode->dmDeviceName[i];
483 i ++;
484 }
485 buf[i] = 0;
486
487 m_printerName = buf;
488 }
489
490 //// Colour
491
492 if (devMode->dmFields & DM_COLOR)
493 {
494 if (devMode->dmColor == DMCOLOR_COLOR)
495 m_colour = TRUE;
496 else
497 m_colour = FALSE;
498 }
499 else
500 m_colour = TRUE;
501
502 #ifndef __WXWINE__
503 //// Paper size
504
505 if (devMode->dmFields & DM_PAPERSIZE)
506 {
507 if (wxThePrintPaperDatabase)
508 {
509 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
510 if (paper)
511 {
512 m_paperId = paper->GetId();
513 m_paperSize.x = paper->GetWidth() / 10 ;
514 m_paperSize.y = paper->GetHeight() / 10 ;
515 }
516 else
517 {
518 // Shouldn't really get here
519 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
520
521 m_paperId = wxPAPER_NONE;
522 m_paperSize.x = 0;
523 m_paperSize.y = 0;
524 }
525 }
526 else
527 {
528 // Shouldn't really get here
529 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
530
531 m_paperId = wxPAPER_NONE;
532 m_paperSize.x = 0;
533 m_paperSize.y = 0;
534 }
535 }
536 else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
537 {
538 m_paperSize.x = devMode->dmPaperWidth / 10;
539 m_paperSize.y = devMode->dmPaperLength / 10;
540 m_paperId = wxPAPER_NONE;
541 }
542 else
543 {
544 // Shouldn't really get here
545 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
546
547 m_paperSize.x = 0;
548 m_paperSize.y = 0;
549 m_paperId = wxPAPER_NONE;
550 }
551 #endif
552
553 //// Duplex
554
555 if (devMode->dmFields & DM_DUPLEX)
556 {
557 switch (devMode->dmDuplex)
558 {
559 case DMDUP_HORIZONTAL: {
560 m_duplexMode = wxDUPLEX_HORIZONTAL; break;
561 }
562 case DMDUP_VERTICAL: {
563 m_duplexMode = wxDUPLEX_VERTICAL; break;
564 }
565 default:
566 case DMDUP_SIMPLEX: {
567 m_duplexMode = wxDUPLEX_SIMPLEX; break;
568 }
569 }
570 }
571 else
572 m_duplexMode = wxDUPLEX_SIMPLEX;
573
574 //// Quality
575
576 if (devMode->dmFields & DM_PRINTQUALITY)
577 {
578 switch (devMode->dmPrintQuality)
579 {
580 case DMRES_MEDIUM: {
581 m_printQuality = wxPRINT_QUALITY_MEDIUM; break;
582 }
583 case DMRES_LOW: {
584 m_printQuality = wxPRINT_QUALITY_LOW; break;
585 }
586 case DMRES_DRAFT: {
587 m_printQuality = wxPRINT_QUALITY_DRAFT; break;
588 }
589 case DMRES_HIGH: {
590 m_printQuality = wxPRINT_QUALITY_HIGH; break;
591 }
592 default:
593 {
594 // TODO: if the printer fills in the resolution in DPI, how
595 // will the application know if it's high, low, draft etc.??
596 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
597 m_printQuality = devMode->dmPrintQuality; break;
598
599 }
600 }
601 }
602 else
603 m_printQuality = wxPRINT_QUALITY_HIGH;
604
605 GlobalUnlock(hDevMode);
606 }
607 }
608
609 #endif
610
611 void wxPrintData::operator=(const wxPrintData& data)
612 {
613 m_printNoCopies = data.m_printNoCopies;
614 m_printCollate = data.m_printCollate;
615 m_printOrientation = data.m_printOrientation;
616 m_printerName = data.m_printerName;
617 m_colour = data.m_colour;
618 m_duplexMode = data.m_duplexMode;
619 m_printQuality = data.m_printQuality;
620 m_paperId = data.m_paperId;
621 m_paperSize = data.m_paperSize;
622
623 // PostScript-specific data
624 m_printerCommand = data.m_printerCommand;
625 m_previewCommand = data.m_previewCommand;
626 m_printerOptions = data.m_printerOptions;
627 m_filename = data.m_filename;
628 m_afmPath = data.m_afmPath;
629 m_printerScaleX = data.m_printerScaleX;
630 m_printerScaleY = data.m_printerScaleY;
631 m_printerTranslateX = data.m_printerTranslateX;
632 m_printerTranslateY = data.m_printerTranslateY;
633 m_printMode = data.m_printMode;
634 }
635
636 // For compatibility
637 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
638 void wxPrintData::operator=(const wxPrintSetupData& setupData)
639 {
640 SetPrinterCommand(setupData.GetPrinterCommand());
641 SetPreviewCommand(setupData.GetPrintPreviewCommand());
642 SetPrinterOptions(setupData.GetPrinterOptions());
643
644 long xt, yt;
645 setupData.GetPrinterTranslation(& xt, & yt);
646 SetPrinterTranslation(xt, yt);
647
648 double xs, ys;
649 setupData.GetPrinterScaling(& xs, & ys);
650 SetPrinterScaling(xs, ys);
651
652 SetOrientation(setupData.GetPrinterOrientation());
653 SetPrintMode((wxPrintMode) setupData.GetPrinterMode());
654 SetFontMetricPath(setupData.GetAFMPath());
655 if (setupData.GetPaperName() != "")
656 SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(setupData.GetPaperName()));
657 SetColour(setupData.GetColour());
658 SetFilename(setupData.GetPrinterFile());
659 }
660 #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
661
662
663 // ----------------------------------------------------------------------------
664 // Print dialog data
665 // ----------------------------------------------------------------------------
666
667 wxPrintDialogData::wxPrintDialogData()
668 {
669 #ifdef __WXMSW__
670 m_printDlgData = NULL;
671 #endif
672 m_printFromPage = 0;
673 m_printToPage = 0;
674 m_printMinPage = 0;
675 m_printMaxPage = 0;
676 m_printNoCopies = 1;
677 m_printAllPages = FALSE;
678 m_printCollate = FALSE;
679 m_printToFile = FALSE;
680 m_printSelection = FALSE;
681 m_printEnableSelection = FALSE;
682 m_printEnablePageNumbers = TRUE;
683 m_printEnablePrintToFile = TRUE;
684 m_printEnableHelp = FALSE;
685 m_printSetupDialog = FALSE;
686 }
687
688 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
689 {
690 (*this) = dialogData;
691 }
692
693 wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
694 {
695 #ifdef __WXMSW__
696 m_printDlgData = NULL;
697 #endif
698 m_printFromPage = 0;
699 m_printToPage = 0;
700 m_printMinPage = 0;
701 m_printMaxPage = 0;
702 m_printNoCopies = 1;
703 m_printAllPages = FALSE;
704 m_printCollate = FALSE;
705 m_printToFile = FALSE;
706 m_printSelection = FALSE;
707 m_printEnableSelection = FALSE;
708 m_printEnablePageNumbers = TRUE;
709 m_printEnablePrintToFile = TRUE;
710 m_printEnableHelp = FALSE;
711 m_printSetupDialog = FALSE;
712
713 m_printData = printData;
714 }
715
716 wxPrintDialogData::~wxPrintDialogData()
717 {
718 #ifdef __WXMSW__
719 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
720 if ( pd && pd->hDevMode )
721 GlobalFree(pd->hDevMode);
722 if ( pd )
723 delete pd;
724 #endif
725 }
726
727 #ifdef __WXMSW__
728 void wxPrintDialogData::ConvertToNative()
729 {
730 m_printData.ConvertToNative();
731
732 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
733
734 if (!pd)
735 {
736 pd = new PRINTDLG;
737 m_printDlgData = (void*) pd;
738
739 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
740 #ifdef __GNUWIN32__
741 pd->lStructSize = 66 ;
742 #else
743 pd->lStructSize = sizeof(PRINTDLG);
744 #endif
745 pd->hwndOwner = (HWND)NULL;
746 pd->hDevMode = NULL; // Will be created by PrintDlg
747 pd->hDevNames = NULL; // Ditto
748
749 pd->Flags = PD_RETURNDEFAULT;
750 pd->nCopies = 1;
751 }
752
753 // Pass the devmode data to the PRINTDLG structure, since it'll
754 // be needed when PrintDlg is called.
755 if (pd->hDevMode)
756 {
757 GlobalFree(pd->hDevMode);
758 }
759
760 pd->hDevMode = (HGLOBAL)(DWORD) m_printData.GetNativeData();
761
762 m_printData.SetNativeData((void*) NULL);
763
764 wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
765
766 pd->hDC = (HDC) NULL;
767 pd->nFromPage = (UINT)m_printFromPage;
768 pd->nToPage = (UINT)m_printToPage;
769 pd->nMinPage = (UINT)m_printMinPage;
770 pd->nMaxPage = (UINT)m_printMaxPage;
771 pd->nCopies = (UINT)m_printNoCopies;
772
773 pd->Flags = PD_RETURNDC ;
774
775 #ifdef __GNUWIN32__
776 pd->lStructSize = 66 ;
777 #else
778 pd->lStructSize = sizeof( PRINTDLG );
779 #endif
780
781 pd->hwndOwner=(HWND)NULL;
782 pd->hDevNames=(HANDLE)NULL;
783 pd->hInstance=(HINSTANCE)NULL;
784 pd->lCustData = (LPARAM) NULL;
785 pd->lpfnPrintHook = NULL;
786 pd->lpfnSetupHook = NULL;
787 pd->lpPrintTemplateName = NULL;
788 pd->lpSetupTemplateName = NULL;
789 pd->hPrintTemplate = (HGLOBAL) NULL;
790 pd->hSetupTemplate = (HGLOBAL) NULL;
791
792 if ( m_printAllPages )
793 pd->Flags |= PD_ALLPAGES;
794 if ( m_printAllPages )
795 pd->Flags |= PD_SELECTION;
796 if ( m_printCollate )
797 pd->Flags |= PD_COLLATE;
798 if ( m_printToFile )
799 pd->Flags |= PD_PRINTTOFILE;
800 if ( !m_printEnablePrintToFile )
801 pd->Flags |= PD_DISABLEPRINTTOFILE;
802 if ( !m_printEnableSelection )
803 pd->Flags |= PD_NOSELECTION;
804 if ( !m_printEnablePageNumbers )
805 pd->Flags |= PD_NOPAGENUMS;
806 if ( m_printEnableHelp )
807 pd->Flags |= PD_SHOWHELP;
808 if ( m_printSetupDialog )
809 pd->Flags |= PD_PRINTSETUP;
810 }
811
812 void wxPrintDialogData::ConvertFromNative()
813 {
814 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
815 if ( pd == NULL )
816 return;
817
818 // Pass the devmode data back to the wxPrintData structure where it really belongs.
819 if (pd->hDevMode)
820 {
821 if (m_printData.GetNativeData())
822 {
823 // Make sure we don't leak memory
824 GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeData());
825 }
826 m_printData.SetNativeData((void*)(long) pd->hDevMode);
827 pd->hDevMode = NULL;
828 }
829
830 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
831 // into wxWindows form.
832 m_printData.ConvertFromNative();
833
834 m_printFromPage = pd->nFromPage ;
835 m_printToPage = pd->nToPage ;
836 m_printMinPage = pd->nMinPage ;
837 m_printMaxPage = pd->nMaxPage ;
838 m_printNoCopies = pd->nCopies ;
839
840 m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES);
841 m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION);
842 m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
843 m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
844 m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE);
845 m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION);
846 m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS);
847 m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP);
848 m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP);
849
850 /* port is obsolete in WIN32
851 // Get the port name
852 if (pd->hDevNames)
853 {
854 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
855 if (lpDevNames) {
856 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
857 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
858 GlobalUnlock(pd->hDevNames);
859
860 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
861 }
862 }
863 */
864 }
865
866 void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
867 {
868 if ( m_printDlgData == NULL )
869 ConvertToNative();
870
871 if ( m_printDlgData != NULL && win != NULL)
872 {
873 PRINTDLG *pd = (PRINTDLG *) m_printDlgData ;
874 pd->hwndOwner=(HWND) win->GetHWND();
875 }
876 }
877 #endif // MSW
878
879 void wxPrintDialogData::operator=(const wxPrintDialogData& data)
880 {
881 m_printFromPage = data.m_printFromPage;
882 m_printToPage = data.m_printToPage;
883 m_printMinPage = data.m_printMinPage;
884 m_printMaxPage = data.m_printMaxPage;
885 m_printNoCopies = data.m_printNoCopies;
886 m_printAllPages = data.m_printAllPages;
887 m_printCollate = data.m_printCollate;
888 m_printToFile = data.m_printToFile;
889 m_printSelection = data.m_printSelection;
890 m_printEnableSelection = data.m_printEnableSelection;
891 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
892 m_printEnableHelp = data.m_printEnableHelp;
893 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
894 m_printSetupDialog = data.m_printSetupDialog;
895
896 m_printData = data.m_printData;
897 }
898
899 void wxPrintDialogData::operator=(const wxPrintData& data)
900 {
901 m_printData = data;
902 }
903
904 // ----------------------------------------------------------------------------
905 // wxPageSetupDialogData
906 // ----------------------------------------------------------------------------
907
908 wxPageSetupDialogData::wxPageSetupDialogData()
909 {
910 #if defined(__WIN95__)
911 m_pageSetupData = NULL;
912 #endif
913 m_paperSize = wxSize(0, 0);
914
915 CalculatePaperSizeFromId();
916
917 m_minMarginTopLeft = wxPoint(0, 0);
918 m_minMarginBottomRight = wxPoint(0, 0);
919 m_marginTopLeft = wxPoint(0, 0);
920 m_marginBottomRight = wxPoint(0, 0);
921
922 // Flags
923 m_defaultMinMargins = FALSE;
924 m_enableMargins = TRUE;
925 m_enableOrientation = TRUE;
926 m_enablePaper = TRUE;
927 m_enablePrinter = TRUE;
928 m_enableHelp = FALSE;
929 m_getDefaultInfo = FALSE;
930 }
931
932 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
933 {
934 (*this) = dialogData;
935 }
936
937 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
938 {
939 #if defined(__WIN95__)
940 m_pageSetupData = NULL;
941 #endif
942 m_paperSize = wxSize(0, 0);
943 m_minMarginTopLeft = wxPoint(0, 0);
944 m_minMarginBottomRight = wxPoint(0, 0);
945 m_marginTopLeft = wxPoint(0, 0);
946 m_marginBottomRight = wxPoint(0, 0);
947
948 // Flags
949 m_defaultMinMargins = FALSE;
950 m_enableMargins = TRUE;
951 m_enableOrientation = TRUE;
952 m_enablePaper = TRUE;
953 m_enablePrinter = TRUE;
954 m_enableHelp = FALSE;
955 m_getDefaultInfo = FALSE;
956
957 m_printData = printData;
958
959 // The wxPrintData paper size overrides these values, unless the size cannot
960 // be found.
961 CalculatePaperSizeFromId();
962 }
963
964 wxPageSetupDialogData::~wxPageSetupDialogData()
965 {
966 #if defined(__WIN95__) && defined(__WXMSW__)
967 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
968 if ( pd && pd->hDevMode )
969 GlobalFree(pd->hDevMode);
970 if ( pd )
971 delete pd;
972 #endif
973 }
974
975 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
976 {
977 m_paperSize = data.m_paperSize;
978 m_minMarginTopLeft = data.m_minMarginTopLeft;
979 m_minMarginBottomRight = data.m_minMarginBottomRight;
980 m_marginTopLeft = data.m_marginTopLeft;
981 m_marginBottomRight = data.m_marginBottomRight;
982 m_defaultMinMargins = data.m_defaultMinMargins;
983 m_enableMargins = data.m_enableMargins;
984 m_enableOrientation = data.m_enableOrientation;
985 m_enablePaper = data.m_enablePaper;
986 m_enablePrinter = data.m_enablePrinter;
987 m_getDefaultInfo = data.m_getDefaultInfo;;
988 m_enableHelp = data.m_enableHelp;
989
990 m_printData = data.m_printData;
991 }
992
993 void wxPageSetupDialogData::operator=(const wxPrintData& data)
994 {
995 m_printData = data;
996 }
997
998 #if defined(__WIN95__)
999 void wxPageSetupDialogData::ConvertToNative()
1000 {
1001 m_printData.ConvertToNative();
1002
1003 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
1004
1005 if ( m_pageSetupData == NULL )
1006 {
1007 pd = new PAGESETUPDLG;
1008 pd->hDevMode = NULL;
1009 m_pageSetupData = (void *)pd;
1010 }
1011
1012 // Pass the devmode data (created in m_printData.ConvertToNative)
1013 // to the PRINTDLG structure, since it'll
1014 // be needed when PrintDlg is called.
1015
1016 if (pd->hDevMode)
1017 {
1018 GlobalFree(pd->hDevMode);
1019 pd->hDevMode = NULL;
1020 }
1021
1022 pd->hDevMode = (HGLOBAL) m_printData.GetNativeData();
1023
1024 m_printData.SetNativeData((void*) NULL);
1025
1026 wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1027
1028 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1029
1030 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
1031
1032 if ( m_defaultMinMargins )
1033 pd->Flags |= PSD_DEFAULTMINMARGINS;
1034 if ( !m_enableMargins )
1035 pd->Flags |= PSD_DISABLEMARGINS;
1036 if ( !m_enableOrientation )
1037 pd->Flags |= PSD_DISABLEORIENTATION;
1038 if ( !m_enablePaper )
1039 pd->Flags |= PSD_DISABLEPAPER;
1040 if ( !m_enablePrinter )
1041 pd->Flags |= PSD_DISABLEPRINTER;
1042 if ( m_getDefaultInfo )
1043 pd->Flags |= PSD_RETURNDEFAULT;
1044 if ( m_enableHelp )
1045 pd->Flags |= PSD_SHOWHELP;
1046
1047 // We want the units to be in hundredths of a millimetre
1048 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1049
1050 pd->lStructSize = sizeof( PAGESETUPDLG );
1051 pd->hwndOwner=(HWND)NULL;
1052 pd->hDevNames=(HWND)NULL;
1053 pd->hInstance=(HINSTANCE)NULL;
1054
1055 pd->ptPaperSize.x = m_paperSize.x * 100;
1056 pd->ptPaperSize.y = m_paperSize.y * 100;
1057
1058 pd->rtMinMargin.left = m_minMarginTopLeft.x * 100;
1059 pd->rtMinMargin.top = m_minMarginTopLeft.y * 100;
1060 pd->rtMinMargin.right = m_minMarginBottomRight.x * 100;
1061 pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100;
1062
1063 pd->rtMargin.left = m_marginTopLeft.x * 100;
1064 pd->rtMargin.top = m_marginTopLeft.y * 100;
1065 pd->rtMargin.right = m_marginBottomRight.x * 100;
1066 pd->rtMargin.bottom = m_marginBottomRight.y * 100;
1067
1068 pd->lCustData = 0;
1069 pd->lpfnPageSetupHook = NULL;
1070 pd->lpfnPagePaintHook = NULL;
1071 pd->hPageSetupTemplate = NULL;
1072 pd->lpPageSetupTemplateName = NULL;
1073
1074 /*
1075 if ( pd->hDevMode )
1076 {
1077 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1078 memset(devMode, 0, sizeof(DEVMODE));
1079 devMode->dmSize = sizeof(DEVMODE);
1080 devMode->dmOrientation = m_orientation;
1081 devMode->dmFields = DM_ORIENTATION;
1082 GlobalUnlock(pd->hDevMode);
1083 }
1084 */
1085 }
1086
1087 void wxPageSetupDialogData::ConvertFromNative()
1088 {
1089 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1090 if ( !pd )
1091 return;
1092
1093 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1094 if (pd->hDevMode)
1095 {
1096 if (m_printData.GetNativeData())
1097 {
1098 // Make sure we don't leak memory
1099 GlobalFree((HGLOBAL) m_printData.GetNativeData());
1100 }
1101 m_printData.SetNativeData((void*) pd->hDevMode);
1102 pd->hDevMode = NULL;
1103 }
1104
1105 m_printData.ConvertFromNative();
1106
1107 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
1108
1109 m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS);
1110 m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS);
1111 m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION);
1112 m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER);
1113 m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER);
1114 m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT);
1115 m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP);
1116
1117 m_paperSize.x = pd->ptPaperSize.x / 100;
1118 m_paperSize.y = pd->ptPaperSize.y / 100;
1119
1120 m_minMarginTopLeft.x = pd->rtMinMargin.left / 100;
1121 m_minMarginTopLeft.y = pd->rtMinMargin.top / 100;
1122 m_minMarginBottomRight.x = pd->rtMinMargin.right / 100;
1123 m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100;
1124
1125 m_marginTopLeft.x = pd->rtMargin.left / 100 ;
1126 m_marginTopLeft.y = pd->rtMargin.top / 100 ;
1127 m_marginBottomRight.x = pd->rtMargin.right / 100 ;
1128 m_marginBottomRight.y = pd->rtMargin.bottom / 100 ;
1129 }
1130
1131 void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
1132 {
1133 if ( m_pageSetupData == NULL )
1134 ConvertToNative();
1135
1136 if ( m_pageSetupData != NULL && win != NULL)
1137 {
1138 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1139 pd->hwndOwner=(HWND) win->GetHWND();
1140 }
1141 }
1142 #endif // Win95
1143
1144 // If a corresponding paper type is found in the paper database, will set the m_printData
1145 // paper size id member as well.
1146 void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
1147 {
1148 m_paperSize = sz;
1149
1150 CalculateIdFromPaperSize();
1151 }
1152
1153 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1154 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
1155 {
1156 m_printData.SetPaperId(id);
1157
1158 CalculatePaperSizeFromId();
1159 }
1160
1161 // Use paper size defined in this object to set the wxPrintData
1162 // paper id
1163 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1164 {
1165 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
1166 wxT("wxThePrintPaperDatabase should not be NULL. "
1167 "Do not create global print dialog data objects.") );
1168
1169 wxSize sz = GetPaperSize();
1170
1171 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
1172 if (id != wxPAPER_NONE)
1173 {
1174 m_printData.SetPaperId(id);
1175 }
1176 }
1177
1178 // Use paper id in wxPrintData to set this object's paper size
1179 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1180 {
1181 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
1182 wxT("wxThePrintPaperDatabase should not be NULL. "
1183 "Do not create global print dialog data objects.") );
1184
1185 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
1186
1187 if (sz.x != 0)
1188 {
1189 // sz is in 10ths of a mm, so multiply by 10.
1190 m_paperSize.x = sz.x * 10;
1191 m_paperSize.y = sz.y * 10;
1192 }
1193 }
1194
1195 #endif // wxUSE_PRINTING_ARCHITECTURE