]> git.saurik.com Git - wxWidgets.git/blob - src/common/cmndata.cpp
a37373c110b08f53f22777343aebc58894d6cac4
[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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "cmndata.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include <stdio.h>
33 #include "wx/string.h"
34 #include "wx/utils.h"
35 #include "wx/app.h"
36 #endif
37
38 #include "wx/gdicmn.h"
39 #include "wx/cmndata.h"
40 #include "wx/log.h"
41 #include "wx/prntbase.h"
42 #include "wx/printdlg.h"
43
44 #if wxUSE_FONTDLG
45 #include "wx/fontdlg.h"
46 #endif // wxUSE_FONTDLG
47
48 #if wxUSE_PRINTING_ARCHITECTURE
49 #include "wx/paper.h"
50 #endif // wxUSE_PRINTING_ARCHITECTURE
51
52 #if defined(__WXMSW__) && !defined(__PALMOS__)
53 #include <windowsx.h>
54 #include "wx/msw/private.h"
55
56 #ifndef __SMARTPHONE__ /* of WinCE */
57 #include <commdlg.h>
58 #endif
59
60 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
61 #include <windowsx.h>
62 #include <commdlg.h>
63 #endif
64 #endif // MSW
65
66 #ifdef __WXMAC__
67 #include "wx/mac/private/print.h"
68 #endif
69
70 #if wxUSE_PRINTING_ARCHITECTURE
71 IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
72 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
73 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject)
74 #endif // wxUSE_PRINTING_ARCHITECTURE
75
76 IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
77 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
78
79 #ifndef DMPAPER_USER
80 #define DMPAPER_USER 256
81 #endif
82
83 // ============================================================================
84 // implementation
85 // ============================================================================
86
87 // ----------------------------------------------------------------------------
88 // wxColourData
89 // ----------------------------------------------------------------------------
90
91 wxColourData::wxColourData()
92 {
93 m_chooseFull = false;
94 m_dataColour.Set(0,0,0);
95 // m_custColours are wxNullColours initially
96 }
97
98 wxColourData::wxColourData(const wxColourData& data)
99 : wxObject()
100 {
101 (*this) = data;
102 }
103
104 wxColourData::~wxColourData()
105 {
106 }
107
108 void wxColourData::SetCustomColour(int i, const wxColour& colour)
109 {
110 wxCHECK_RET( (i >= 0 && i < 16), _T("custom colour index out of range") );
111
112 m_custColours[i] = colour;
113 }
114
115 wxColour wxColourData::GetCustomColour(int i)
116 {
117 wxCHECK_MSG( (i >= 0 && i < 16), wxColour(0,0,0),
118 _T("custom colour index out of range") );
119
120 return m_custColours[i];
121 }
122
123 void wxColourData::operator=(const wxColourData& data)
124 {
125 int i;
126 for (i = 0; i < 16; i++)
127 m_custColours[i] = data.m_custColours[i];
128
129 m_dataColour = (wxColour&)data.m_dataColour;
130 m_chooseFull = data.m_chooseFull;
131 }
132
133 // ----------------------------------------------------------------------------
134 // Font data
135 // ----------------------------------------------------------------------------
136
137 wxFontData::wxFontData()
138 {
139 // Intialize colour to black.
140 m_fontColour = wxNullColour;
141
142 m_showHelp = false;
143 m_allowSymbols = true;
144 m_enableEffects = true;
145 m_minSize = 0;
146 m_maxSize = 0;
147
148 m_encoding = wxFONTENCODING_SYSTEM;
149 }
150
151 wxFontData::~wxFontData()
152 {
153 }
154
155 #if wxUSE_FONTDLG
156
157 wxFontDialogBase::~wxFontDialogBase()
158 {
159 }
160
161 #endif // wxUSE_FONTDLG
162
163 #if wxUSE_PRINTING_ARCHITECTURE
164 // ----------------------------------------------------------------------------
165 // Print data
166 // ----------------------------------------------------------------------------
167
168 wxPrintData::wxPrintData()
169 {
170 #ifdef __WXMAC__
171 m_nativePrintData = wxNativePrintData::Create() ;
172 #endif
173 m_bin = wxPRINTBIN_DEFAULT;
174 m_printMode = wxPRINT_MODE_PRINTER;
175 m_printOrientation = wxPORTRAIT;
176 m_printNoCopies = 1;
177 m_printCollate = false;
178
179 // New, 24/3/99
180 m_printerName = wxT("");
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 m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData();
188 }
189
190 wxPrintData::wxPrintData(const wxPrintData& printData)
191 : wxObject()
192 {
193 (*this) = printData;
194 }
195
196 wxPrintData::~wxPrintData()
197 {
198 m_nativeData->m_ref--;
199 if (m_nativeData->m_ref == 0)
200 delete m_nativeData;
201
202 #ifdef __WXMAC__
203 delete m_nativePrintData ;
204 #endif
205 }
206
207
208 #ifdef __WXMAC__
209 void wxPrintData::ConvertToNative()
210 {
211 m_nativePrintData->TransferFrom( this ) ;
212 }
213
214 void wxPrintData::ConvertFromNative()
215 {
216 m_nativePrintData->TransferTo( this ) ;
217 }
218 #endif
219
220 void wxPrintData::operator=(const wxPrintData& data)
221 {
222 m_printNoCopies = data.m_printNoCopies;
223 m_printCollate = data.m_printCollate;
224 m_printOrientation = data.m_printOrientation;
225 m_printerName = data.m_printerName;
226 m_colour = data.m_colour;
227 m_duplexMode = data.m_duplexMode;
228 m_printQuality = data.m_printQuality;
229 m_paperId = data.m_paperId;
230 m_paperSize = data.m_paperSize;
231 m_bin = data.m_bin;
232 m_printMode = data.m_printMode;
233 m_filename = data.m_filename;
234
235 m_nativeData = data.GetNativeData();
236 m_nativeData->m_ref++;
237
238 #ifdef __WXMAC__
239 m_nativePrintData->CopyFrom( data.m_nativePrintData ) ;
240 #endif
241 }
242
243 // Is this data OK for showing the print dialog?
244 bool wxPrintData::Ok() const
245 {
246 m_nativeData->TransferFrom( *this );
247
248 return m_nativeData->Ok();
249 }
250
251 // ----------------------------------------------------------------------------
252 // Print dialog data
253 // ----------------------------------------------------------------------------
254
255 wxPrintDialogData::wxPrintDialogData()
256 {
257 #ifdef __WXMSW__
258 m_printDlgData = NULL;
259 #endif
260 m_printFromPage = 0;
261 m_printToPage = 0;
262 m_printMinPage = 0;
263 m_printMaxPage = 0;
264 m_printNoCopies = 1;
265 m_printAllPages = false;
266 m_printCollate = false;
267 m_printToFile = false;
268 m_printSelection = false;
269 m_printEnableSelection = false;
270 m_printEnablePageNumbers = true;
271
272 wxPrintFactory* factory = wxPrintFactory::GetFactory();
273 m_printEnablePrintToFile = ! factory->HasOwnPrintToFile();
274
275 m_printEnableHelp = false;
276 m_printSetupDialog = false;
277 }
278
279 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
280 : wxObject()
281 {
282 #ifdef __WXMSW__
283 m_printDlgData = NULL;
284 #endif
285 (*this) = dialogData;
286 }
287
288 wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
289 {
290 #ifdef __WXMSW__
291 m_printDlgData = NULL;
292 #endif
293 m_printFromPage = 1;
294 m_printToPage = 0;
295 m_printMinPage = 1;
296 m_printMaxPage = 9999;
297 m_printNoCopies = 1;
298 m_printAllPages = false;
299 m_printCollate = false;
300 m_printToFile = false;
301 m_printSelection = false;
302 m_printEnableSelection = false;
303 m_printEnablePageNumbers = true;
304 m_printEnablePrintToFile = true;
305 m_printEnableHelp = false;
306 m_printSetupDialog = false;
307
308 m_printData = printData;
309 }
310
311 wxPrintDialogData::~wxPrintDialogData()
312 {
313 #ifdef __WXMSW__
314 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
315 if ( pd && pd->hDevMode )
316 GlobalFree(pd->hDevMode);
317 if ( pd )
318 delete pd;
319 #endif
320 }
321
322 #ifdef __WXMSW__
323 void wxPrintDialogData::ConvertToNative()
324 {
325 wxWindowsPrintNativeData *data =
326 (wxWindowsPrintNativeData *) m_printData.GetNativeData();
327 data->TransferFrom( m_printData );
328
329 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
330
331 if (!pd)
332 {
333 pd = new PRINTDLG;
334 memset( pd, 0, sizeof(PRINTDLG) );
335 m_printDlgData = (void*) pd;
336
337 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
338 #ifdef __GNUWIN32__
339 pd->lStructSize = 66;
340 #else
341 pd->lStructSize = sizeof(PRINTDLG);
342 #endif
343 pd->hwndOwner = (HWND)NULL;
344 pd->hDevMode = NULL; // Will be created by PrintDlg
345 pd->hDevNames = NULL; // Ditto
346
347 pd->Flags = PD_RETURNDEFAULT;
348 pd->nCopies = 1;
349 }
350
351 // Pass the devmode data to the PRINTDLG structure, since it'll
352 // be needed when PrintDlg is called.
353 if (pd->hDevMode)
354 {
355 GlobalFree(pd->hDevMode);
356 }
357
358 // Pass the devnames data to the PRINTDLG structure, since it'll
359 // be needed when PrintDlg is called.
360 if (pd->hDevNames)
361 {
362 GlobalFree(pd->hDevNames);
363 }
364
365 pd->hDevMode = (HGLOBAL)(DWORD) data->GetDevMode();
366
367 data->SetDevMode( (void*) NULL);
368
369 // Shouldn't assert; we should be able to test Ok-ness at a higher level
370 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
371
372 pd->hDevNames = (HGLOBAL)(DWORD) data->GetDevNames();
373
374 data->SetDevNames( (void*) NULL);
375
376 pd->hDC = (HDC) NULL;
377 pd->nFromPage = (WORD)m_printFromPage;
378 pd->nToPage = (WORD)m_printToPage;
379 pd->nMinPage = (WORD)m_printMinPage;
380 pd->nMaxPage = (WORD)m_printMaxPage;
381 pd->nCopies = (WORD)m_printNoCopies;
382
383 pd->Flags = PD_RETURNDC;
384
385 #ifdef __GNUWIN32__
386 pd->lStructSize = 66;
387 #else
388 pd->lStructSize = sizeof( PRINTDLG );
389 #endif
390
391 pd->hwndOwner=(HWND)NULL;
392 // pd->hDevNames=(HANDLE)NULL;
393 pd->hInstance=(HINSTANCE)NULL;
394 pd->lCustData = (LPARAM) NULL;
395 pd->lpfnPrintHook = NULL;
396 pd->lpfnSetupHook = NULL;
397 pd->lpPrintTemplateName = NULL;
398 pd->lpSetupTemplateName = NULL;
399 pd->hPrintTemplate = (HGLOBAL) NULL;
400 pd->hSetupTemplate = (HGLOBAL) NULL;
401
402 if ( m_printAllPages )
403 pd->Flags |= PD_ALLPAGES;
404 if ( m_printSelection )
405 pd->Flags |= PD_SELECTION;
406 if ( m_printCollate )
407 pd->Flags |= PD_COLLATE;
408 if ( m_printToFile )
409 pd->Flags |= PD_PRINTTOFILE;
410 if ( !m_printEnablePrintToFile )
411 pd->Flags |= PD_DISABLEPRINTTOFILE;
412 if ( !m_printEnableSelection )
413 pd->Flags |= PD_NOSELECTION;
414 if ( !m_printEnablePageNumbers )
415 pd->Flags |= PD_NOPAGENUMS;
416 else if ( (!m_printAllPages) && (!m_printSelection) && (m_printFromPage != 0) && (m_printToPage != 0))
417 pd->Flags |= PD_PAGENUMS;
418 if ( m_printEnableHelp )
419 pd->Flags |= PD_SHOWHELP;
420 if ( m_printSetupDialog )
421 pd->Flags |= PD_PRINTSETUP;
422 }
423
424 void wxPrintDialogData::ConvertFromNative()
425 {
426 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
427 if ( pd == NULL )
428 return;
429
430 wxWindowsPrintNativeData *data =
431 (wxWindowsPrintNativeData *) m_printData.GetNativeData();
432
433 // Pass the devmode data back to the wxPrintData structure where it really belongs.
434 if (pd->hDevMode)
435 {
436 if (data->GetDevMode())
437 {
438 // Make sure we don't leak memory
439 GlobalFree( (HGLOBAL)(DWORD) data->GetDevMode() );
440 }
441 data->SetDevMode( (void*)(long) pd->hDevMode );
442 pd->hDevMode = NULL;
443 }
444
445 // Pass the devnames data back to the wxPrintData structure where it really belongs.
446 if (pd->hDevNames)
447 {
448 if (data->GetDevNames())
449 {
450 // Make sure we don't leak memory
451 GlobalFree((HGLOBAL)(DWORD) data->GetDevNames());
452 }
453 data->SetDevNames((void*)(long) pd->hDevNames);
454 pd->hDevNames = NULL;
455 }
456
457 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
458 // into wxWidgets form.
459 data->TransferTo( m_printData );
460
461 m_printFromPage = pd->nFromPage;
462 m_printToPage = pd->nToPage;
463 m_printMinPage = pd->nMinPage;
464 m_printMaxPage = pd->nMaxPage;
465 m_printNoCopies = pd->nCopies;
466
467 m_printAllPages = (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION));
468 m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION);
469 m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
470 m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
471 m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE);
472 m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION);
473 m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS);
474 m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP);
475 m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP);
476
477 /* port is obsolete in WIN32
478 // Get the port name
479 if (pd->hDevNames)
480 {
481 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
482 if (lpDevNames) {
483 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
484 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
485 GlobalUnlock(pd->hDevNames);
486
487 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
488 }
489 }
490 */
491 }
492
493 void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
494 {
495 if ( m_printDlgData == NULL )
496 ConvertToNative();
497
498 if ( m_printDlgData != NULL && win != NULL)
499 {
500 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
501 pd->hwndOwner=(HWND) win->GetHWND();
502 }
503 }
504 #endif // MSW
505
506 #ifdef __WXMAC__
507
508 void wxPrintDialogData::ConvertToNative()
509 {
510 m_printData.ConvertToNative();
511 m_printData.m_nativePrintData->TransferFrom( this ) ;
512 }
513
514 void wxPrintDialogData::ConvertFromNative()
515 {
516 m_printData.ConvertFromNative();
517 m_printData.m_nativePrintData->TransferTo( this ) ;
518 }
519
520 #endif
521
522
523 void wxPrintDialogData::operator=(const wxPrintDialogData& data)
524 {
525 m_printFromPage = data.m_printFromPage;
526 m_printToPage = data.m_printToPage;
527 m_printMinPage = data.m_printMinPage;
528 m_printMaxPage = data.m_printMaxPage;
529 m_printNoCopies = data.m_printNoCopies;
530 m_printAllPages = data.m_printAllPages;
531 m_printCollate = data.m_printCollate;
532 m_printToFile = data.m_printToFile;
533 m_printSelection = data.m_printSelection;
534 m_printEnableSelection = data.m_printEnableSelection;
535 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
536 m_printEnableHelp = data.m_printEnableHelp;
537 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
538 m_printSetupDialog = data.m_printSetupDialog;
539
540 m_printData = data.m_printData;
541 }
542
543 void wxPrintDialogData::operator=(const wxPrintData& data)
544 {
545 m_printData = data;
546 }
547
548 // ----------------------------------------------------------------------------
549 // wxPageSetupDialogData
550 // ----------------------------------------------------------------------------
551
552 wxPageSetupDialogData::wxPageSetupDialogData()
553 {
554 #if defined(__WIN95__)
555 m_pageSetupData = NULL;
556 #endif
557 m_paperSize = wxSize(0, 0);
558
559 CalculatePaperSizeFromId();
560
561 m_minMarginTopLeft = wxPoint(0, 0);
562 m_minMarginBottomRight = wxPoint(0, 0);
563 m_marginTopLeft = wxPoint(0, 0);
564 m_marginBottomRight = wxPoint(0, 0);
565
566 // Flags
567 m_defaultMinMargins = false;
568 m_enableMargins = true;
569 m_enableOrientation = true;
570 m_enablePaper = true;
571 m_enablePrinter = true;
572 m_enableHelp = false;
573 m_getDefaultInfo = false;
574 }
575
576 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
577 : wxObject()
578 {
579 #if defined(__WIN95__)
580 m_pageSetupData = NULL;
581 #endif
582 (*this) = dialogData;
583 }
584
585 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
586 {
587 #if defined(__WIN95__)
588 m_pageSetupData = NULL;
589 #endif
590 m_paperSize = wxSize(0, 0);
591 m_minMarginTopLeft = wxPoint(0, 0);
592 m_minMarginBottomRight = wxPoint(0, 0);
593 m_marginTopLeft = wxPoint(0, 0);
594 m_marginBottomRight = wxPoint(0, 0);
595
596 // Flags
597 m_defaultMinMargins = false;
598 m_enableMargins = true;
599 m_enableOrientation = true;
600 m_enablePaper = true;
601 m_enablePrinter = true;
602 m_enableHelp = false;
603 m_getDefaultInfo = false;
604
605 m_printData = printData;
606
607 // The wxPrintData paper size overrides these values, unless the size cannot
608 // be found.
609 CalculatePaperSizeFromId();
610 }
611
612 wxPageSetupDialogData::~wxPageSetupDialogData()
613 {
614 #if defined(__WIN95__) && defined(__WXMSW__)
615 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
616 if ( pd && pd->hDevMode )
617 GlobalFree(pd->hDevMode);
618 if ( pd && pd->hDevNames )
619 GlobalFree(pd->hDevNames);
620 if ( pd )
621 delete pd;
622 #endif
623 }
624
625 wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
626 {
627 m_paperSize = data.m_paperSize;
628 m_minMarginTopLeft = data.m_minMarginTopLeft;
629 m_minMarginBottomRight = data.m_minMarginBottomRight;
630 m_marginTopLeft = data.m_marginTopLeft;
631 m_marginBottomRight = data.m_marginBottomRight;
632 m_defaultMinMargins = data.m_defaultMinMargins;
633 m_enableMargins = data.m_enableMargins;
634 m_enableOrientation = data.m_enableOrientation;
635 m_enablePaper = data.m_enablePaper;
636 m_enablePrinter = data.m_enablePrinter;
637 m_getDefaultInfo = data.m_getDefaultInfo;;
638 m_enableHelp = data.m_enableHelp;
639
640 m_printData = data.m_printData;
641
642 return *this;
643 }
644
645 wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
646 {
647 m_printData = data;
648
649 return *this;
650 }
651
652 #if defined(__WIN95__)
653 void wxPageSetupDialogData::ConvertToNative()
654 {
655 wxWindowsPrintNativeData *data =
656 (wxWindowsPrintNativeData *) m_printData.GetNativeData();
657 data->TransferFrom( m_printData );
658
659 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
660
661 if ( m_pageSetupData == NULL )
662 {
663 pd = new PAGESETUPDLG;
664 pd->hDevMode = NULL;
665 pd->hDevNames = NULL;
666 m_pageSetupData = (void *)pd;
667 }
668
669 // Pass the devmode data (created in m_printData.ConvertToNative)
670 // to the PRINTDLG structure, since it'll
671 // be needed when PrintDlg is called.
672
673 if (pd->hDevMode)
674 {
675 GlobalFree(pd->hDevMode);
676 pd->hDevMode = NULL;
677 }
678
679 pd->hDevMode = (HGLOBAL) data->GetDevMode();
680
681 data->SetDevMode( (void*) NULL );
682
683 // Shouldn't assert; we should be able to test Ok-ness at a higher level
684 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
685
686 // Pass the devnames data (created in m_printData.ConvertToNative)
687 // to the PRINTDLG structure, since it'll
688 // be needed when PrintDlg is called.
689
690 if (pd->hDevNames)
691 {
692 GlobalFree(pd->hDevNames);
693 pd->hDevNames = NULL;
694 }
695
696 pd->hDevNames = (HGLOBAL) data->GetDevNames();
697
698 data->SetDevNames((void*) NULL);
699
700 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
701
702 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
703
704 if ( m_defaultMinMargins )
705 pd->Flags |= PSD_DEFAULTMINMARGINS;
706 if ( !m_enableMargins )
707 pd->Flags |= PSD_DISABLEMARGINS;
708 if ( !m_enableOrientation )
709 pd->Flags |= PSD_DISABLEORIENTATION;
710 if ( !m_enablePaper )
711 pd->Flags |= PSD_DISABLEPAPER;
712 if ( !m_enablePrinter )
713 pd->Flags |= PSD_DISABLEPRINTER;
714 if ( m_getDefaultInfo )
715 pd->Flags |= PSD_RETURNDEFAULT;
716 if ( m_enableHelp )
717 pd->Flags |= PSD_SHOWHELP;
718
719 // We want the units to be in hundredths of a millimetre
720 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
721
722 pd->lStructSize = sizeof( PAGESETUPDLG );
723 pd->hwndOwner=(HWND)NULL;
724 // pd->hDevNames=(HWND)NULL;
725 pd->hInstance=(HINSTANCE)NULL;
726 // PAGESETUPDLG is in hundreds of a mm
727 pd->ptPaperSize.x = m_paperSize.x * 100;
728 pd->ptPaperSize.y = m_paperSize.y * 100;
729
730 pd->rtMinMargin.left = m_minMarginTopLeft.x * 100;
731 pd->rtMinMargin.top = m_minMarginTopLeft.y * 100;
732 pd->rtMinMargin.right = m_minMarginBottomRight.x * 100;
733 pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100;
734
735 pd->rtMargin.left = m_marginTopLeft.x * 100;
736 pd->rtMargin.top = m_marginTopLeft.y * 100;
737 pd->rtMargin.right = m_marginBottomRight.x * 100;
738 pd->rtMargin.bottom = m_marginBottomRight.y * 100;
739
740 pd->lCustData = 0;
741 pd->lpfnPageSetupHook = NULL;
742 pd->lpfnPagePaintHook = NULL;
743 pd->hPageSetupTemplate = NULL;
744 pd->lpPageSetupTemplateName = NULL;
745
746 /*
747 if ( pd->hDevMode )
748 {
749 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
750 memset(devMode, 0, sizeof(DEVMODE));
751 devMode->dmSize = sizeof(DEVMODE);
752 devMode->dmOrientation = m_orientation;
753 devMode->dmFields = DM_ORIENTATION;
754 GlobalUnlock(pd->hDevMode);
755 }
756 */
757 }
758
759 void wxPageSetupDialogData::ConvertFromNative()
760 {
761 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData;
762 if ( !pd )
763 return;
764
765 wxWindowsPrintNativeData *data =
766 (wxWindowsPrintNativeData *) m_printData.GetNativeData();
767
768 // Pass the devmode data back to the wxPrintData structure where it really belongs.
769 if (pd->hDevMode)
770 {
771 if (data->GetDevMode())
772 {
773 // Make sure we don't leak memory
774 GlobalFree((HGLOBAL) data->GetDevMode());
775 }
776 data->SetDevMode( (void*) pd->hDevMode );
777 pd->hDevMode = NULL;
778 }
779
780 data->TransferTo( m_printData );
781
782 // Pass the devnames data back to the wxPrintData structure where it really belongs.
783 if (pd->hDevNames)
784 {
785 if (data->GetDevNames())
786 {
787 // Make sure we don't leak memory
788 GlobalFree((HGLOBAL) data->GetDevNames());
789 }
790 data->SetDevNames((void*) pd->hDevNames);
791 pd->hDevNames = NULL;
792 }
793
794 data->TransferTo( m_printData );
795
796 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
797
798 m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS);
799 m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS);
800 m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION);
801 m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER);
802 m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER);
803 m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT);
804 m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP);
805
806 // PAGESETUPDLG is in hundreds of a mm
807 m_paperSize.x = pd->ptPaperSize.x / 100;
808 m_paperSize.y = pd->ptPaperSize.y / 100;
809
810 m_minMarginTopLeft.x = pd->rtMinMargin.left / 100;
811 m_minMarginTopLeft.y = pd->rtMinMargin.top / 100;
812 m_minMarginBottomRight.x = pd->rtMinMargin.right / 100;
813 m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100;
814
815 m_marginTopLeft.x = pd->rtMargin.left / 100;
816 m_marginTopLeft.y = pd->rtMargin.top / 100;
817 m_marginBottomRight.x = pd->rtMargin.right / 100;
818 m_marginBottomRight.y = pd->rtMargin.bottom / 100;
819 }
820
821 void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
822 {
823 if ( m_pageSetupData == NULL )
824 ConvertToNative();
825
826 if ( m_pageSetupData != NULL && win != NULL)
827 {
828 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData;
829 pd->hwndOwner=(HWND) win->GetHWND();
830 }
831 }
832 #endif // Win95
833
834 #ifdef __WXMAC__
835 void wxPageSetupDialogData::ConvertToNative()
836 {
837 m_printData.ConvertToNative();
838 m_printData.m_nativePrintData->TransferFrom( this ) ;
839 }
840
841 void wxPageSetupDialogData::ConvertFromNative()
842 {
843 m_printData.ConvertFromNative ();
844 m_paperSize = m_printData.GetPaperSize() ;
845 CalculateIdFromPaperSize();
846 m_printData.m_nativePrintData->TransferTo( this ) ;
847 // adjust minimal values
848
849 if ( m_marginTopLeft.x < m_minMarginTopLeft.x )
850 m_marginTopLeft.x = m_minMarginTopLeft.x;
851
852 if ( m_marginBottomRight.x < m_minMarginBottomRight.x )
853 m_marginBottomRight.x = m_minMarginBottomRight.x;
854
855 if ( m_marginTopLeft.y < m_minMarginTopLeft.y )
856 m_marginTopLeft.y = m_minMarginTopLeft.y;
857
858 if ( m_marginBottomRight.y < m_minMarginBottomRight.y )
859 m_marginBottomRight.y = m_minMarginBottomRight.y;
860 }
861 #endif
862
863
864 // If a corresponding paper type is found in the paper database, will set the m_printData
865 // paper size id member as well.
866 void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
867 {
868 m_paperSize = sz;
869
870 CalculateIdFromPaperSize();
871 }
872
873 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
874 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
875 {
876 m_printData.SetPaperId(id);
877
878 CalculatePaperSizeFromId();
879 }
880
881 // Use paper size defined in this object to set the wxPrintData
882 // paper id
883 void wxPageSetupDialogData::CalculateIdFromPaperSize()
884 {
885 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
886 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
887
888 wxSize sz = GetPaperSize();
889
890 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
891 if (id != wxPAPER_NONE)
892 {
893 m_printData.SetPaperId(id);
894 }
895 }
896
897 // Use paper id in wxPrintData to set this object's paper size
898 void wxPageSetupDialogData::CalculatePaperSizeFromId()
899 {
900 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
901 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
902
903 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
904
905 // sz is in 10ths of a mm, while paper size is in mm
906 m_paperSize.x = sz.x / 10;
907 m_paperSize.y = sz.y / 10;
908 }
909
910 #endif // wxUSE_PRINTING_ARCHITECTURE