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