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