]> git.saurik.com Git - wxWidgets.git/blob - src/common/cmndata.cpp
use GetBestSize() and not GetSize() for AsIs() size constraints -- this makes much...
[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_printOrientation = wxPORTRAIT;
175 m_printNoCopies = 1;
176 m_printCollate = false;
177
178 // New, 24/3/99
179 m_printerName = wxT("");
180 m_colour = true;
181 m_duplexMode = wxDUPLEX_SIMPLEX;
182 m_printQuality = wxPRINT_QUALITY_HIGH;
183 m_paperId = wxPAPER_A4;
184 m_paperSize = wxSize(210, 297);
185
186 m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData();
187 }
188
189 wxPrintData::wxPrintData(const wxPrintData& printData)
190 : wxObject()
191 {
192 (*this) = printData;
193 }
194
195 wxPrintData::~wxPrintData()
196 {
197 m_nativeData->m_ref--;
198 if (m_nativeData->m_ref == 0)
199 delete m_nativeData;
200
201 #ifdef __WXMAC__
202 delete m_nativePrintData ;
203 #endif
204 }
205
206
207 #ifdef __WXMAC__
208 void wxPrintData::ConvertToNative()
209 {
210 m_nativePrintData->TransferFrom( this ) ;
211 }
212
213 void wxPrintData::ConvertFromNative()
214 {
215 m_nativePrintData->TransferTo( this ) ;
216 }
217 #endif
218
219 void wxPrintData::operator=(const wxPrintData& data)
220 {
221 m_printNoCopies = data.m_printNoCopies;
222 m_printCollate = data.m_printCollate;
223 m_printOrientation = data.m_printOrientation;
224 m_printerName = data.m_printerName;
225 m_colour = data.m_colour;
226 m_duplexMode = data.m_duplexMode;
227 m_printQuality = data.m_printQuality;
228 m_paperId = data.m_paperId;
229 m_paperSize = data.m_paperSize;
230 m_bin = data.m_bin;
231
232 m_nativeData = data.GetNativeData();
233 m_nativeData->m_ref++;
234
235 #ifdef __WXMAC__
236 m_nativePrintData->CopyFrom( data.m_nativePrintData ) ;
237 #endif
238 }
239
240 // Is this data OK for showing the print dialog?
241 bool wxPrintData::Ok() const
242 {
243 m_nativeData->TransferFrom( *this );
244
245 return m_nativeData->Ok();
246 }
247
248 // ----------------------------------------------------------------------------
249 // Print dialog data
250 // ----------------------------------------------------------------------------
251
252 wxPrintDialogData::wxPrintDialogData()
253 {
254 #ifdef __WXMSW__
255 m_printDlgData = NULL;
256 #endif
257 m_printFromPage = 0;
258 m_printToPage = 0;
259 m_printMinPage = 0;
260 m_printMaxPage = 0;
261 m_printNoCopies = 1;
262 m_printAllPages = false;
263 m_printCollate = false;
264 m_printToFile = false;
265 m_printSelection = false;
266 m_printEnableSelection = false;
267 m_printEnablePageNumbers = true;
268 m_printEnablePrintToFile = true;
269 m_printEnableHelp = false;
270 m_printSetupDialog = false;
271 }
272
273 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
274 : wxObject()
275 {
276 #ifdef __WXMSW__
277 m_printDlgData = NULL;
278 #endif
279 (*this) = dialogData;
280 }
281
282 wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
283 {
284 #ifdef __WXMSW__
285 m_printDlgData = NULL;
286 #endif
287 m_printFromPage = 1;
288 m_printToPage = 0;
289 m_printMinPage = 1;
290 m_printMaxPage = 9999;
291 m_printNoCopies = 1;
292 m_printAllPages = false;
293 m_printCollate = false;
294 m_printToFile = false;
295 m_printSelection = false;
296 m_printEnableSelection = false;
297 m_printEnablePageNumbers = true;
298 m_printEnablePrintToFile = true;
299 m_printEnableHelp = false;
300 m_printSetupDialog = false;
301
302 m_printData = printData;
303 }
304
305 wxPrintDialogData::~wxPrintDialogData()
306 {
307 #ifdef __WXMSW__
308 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
309 if ( pd && pd->hDevMode )
310 GlobalFree(pd->hDevMode);
311 if ( pd )
312 delete pd;
313 #endif
314 }
315
316 #ifdef __WXMSW__
317 void wxPrintDialogData::ConvertToNative()
318 {
319 wxWindowsPrintNativeData *data =
320 (wxWindowsPrintNativeData *) m_printData.GetNativeData();
321 data->TransferFrom( m_printData );
322
323 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
324
325 if (!pd)
326 {
327 pd = new PRINTDLG;
328 memset( pd, 0, sizeof(PRINTDLG) );
329 m_printDlgData = (void*) pd;
330
331 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
332 #ifdef __GNUWIN32__
333 pd->lStructSize = 66;
334 #else
335 pd->lStructSize = sizeof(PRINTDLG);
336 #endif
337 pd->hwndOwner = (HWND)NULL;
338 pd->hDevMode = NULL; // Will be created by PrintDlg
339 pd->hDevNames = NULL; // Ditto
340
341 pd->Flags = PD_RETURNDEFAULT;
342 pd->nCopies = 1;
343 }
344
345 // Pass the devmode data to the PRINTDLG structure, since it'll
346 // be needed when PrintDlg is called.
347 if (pd->hDevMode)
348 {
349 GlobalFree(pd->hDevMode);
350 }
351
352 // Pass the devnames data to the PRINTDLG structure, since it'll
353 // be needed when PrintDlg is called.
354 if (pd->hDevNames)
355 {
356 GlobalFree(pd->hDevNames);
357 }
358
359 pd->hDevMode = (HGLOBAL)(DWORD) data->GetDevMode();
360
361 data->SetDevMode( (void*) NULL);
362
363 // Shouldn't assert; we should be able to test Ok-ness at a higher level
364 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
365
366 pd->hDevNames = (HGLOBAL)(DWORD) data->GetDevNames();
367
368 data->SetDevNames( (void*) NULL);
369
370 pd->hDC = (HDC) NULL;
371 pd->nFromPage = (WORD)m_printFromPage;
372 pd->nToPage = (WORD)m_printToPage;
373 pd->nMinPage = (WORD)m_printMinPage;
374 pd->nMaxPage = (WORD)m_printMaxPage;
375 pd->nCopies = (WORD)m_printNoCopies;
376
377 pd->Flags = PD_RETURNDC;
378
379 #ifdef __GNUWIN32__
380 pd->lStructSize = 66;
381 #else
382 pd->lStructSize = sizeof( PRINTDLG );
383 #endif
384
385 pd->hwndOwner=(HWND)NULL;
386 // pd->hDevNames=(HANDLE)NULL;
387 pd->hInstance=(HINSTANCE)NULL;
388 pd->lCustData = (LPARAM) NULL;
389 pd->lpfnPrintHook = NULL;
390 pd->lpfnSetupHook = NULL;
391 pd->lpPrintTemplateName = NULL;
392 pd->lpSetupTemplateName = NULL;
393 pd->hPrintTemplate = (HGLOBAL) NULL;
394 pd->hSetupTemplate = (HGLOBAL) NULL;
395
396 if ( m_printAllPages )
397 pd->Flags |= PD_ALLPAGES;
398 if ( m_printSelection )
399 pd->Flags |= PD_SELECTION;
400 if ( m_printCollate )
401 pd->Flags |= PD_COLLATE;
402 if ( m_printToFile )
403 pd->Flags |= PD_PRINTTOFILE;
404 if ( !m_printEnablePrintToFile )
405 pd->Flags |= PD_DISABLEPRINTTOFILE;
406 if ( !m_printEnableSelection )
407 pd->Flags |= PD_NOSELECTION;
408 if ( !m_printEnablePageNumbers )
409 pd->Flags |= PD_NOPAGENUMS;
410 else if ( (!m_printAllPages) && (!m_printSelection) && (m_printFromPage != 0) && (m_printToPage != 0))
411 pd->Flags |= PD_PAGENUMS;
412 if ( m_printEnableHelp )
413 pd->Flags |= PD_SHOWHELP;
414 if ( m_printSetupDialog )
415 pd->Flags |= PD_PRINTSETUP;
416 }
417
418 void wxPrintDialogData::ConvertFromNative()
419 {
420 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
421 if ( pd == NULL )
422 return;
423
424 wxWindowsPrintNativeData *data =
425 (wxWindowsPrintNativeData *) m_printData.GetNativeData();
426
427 // Pass the devmode data back to the wxPrintData structure where it really belongs.
428 if (pd->hDevMode)
429 {
430 if (data->GetDevMode())
431 {
432 // Make sure we don't leak memory
433 GlobalFree( (HGLOBAL)(DWORD) data->GetDevMode() );
434 }
435 data->SetDevMode( (void*)(long) pd->hDevMode );
436 pd->hDevMode = NULL;
437 }
438
439 // Pass the devnames data back to the wxPrintData structure where it really belongs.
440 if (pd->hDevNames)
441 {
442 if (data->GetDevNames())
443 {
444 // Make sure we don't leak memory
445 GlobalFree((HGLOBAL)(DWORD) data->GetDevNames());
446 }
447 data->SetDevNames((void*)(long) pd->hDevNames);
448 pd->hDevNames = NULL;
449 }
450
451 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
452 // into wxWidgets form.
453 data->TransferTo( m_printData );
454
455 m_printFromPage = pd->nFromPage;
456 m_printToPage = pd->nToPage;
457 m_printMinPage = pd->nMinPage;
458 m_printMaxPage = pd->nMaxPage;
459 m_printNoCopies = pd->nCopies;
460
461 m_printAllPages = (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION));
462 m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION);
463 m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
464 m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
465 m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE);
466 m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION);
467 m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS);
468 m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP);
469 m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP);
470
471 /* port is obsolete in WIN32
472 // Get the port name
473 if (pd->hDevNames)
474 {
475 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
476 if (lpDevNames) {
477 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
478 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
479 GlobalUnlock(pd->hDevNames);
480
481 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
482 }
483 }
484 */
485 }
486
487 void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
488 {
489 if ( m_printDlgData == NULL )
490 ConvertToNative();
491
492 if ( m_printDlgData != NULL && win != NULL)
493 {
494 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
495 pd->hwndOwner=(HWND) win->GetHWND();
496 }
497 }
498 #endif // MSW
499
500 #ifdef __WXMAC__
501
502 void wxPrintDialogData::ConvertToNative()
503 {
504 m_printData.ConvertToNative();
505 m_printData.m_nativePrintData->TransferFrom( this ) ;
506 }
507
508 void wxPrintDialogData::ConvertFromNative()
509 {
510 m_printData.ConvertFromNative();
511 m_printData.m_nativePrintData->TransferTo( this ) ;
512 }
513
514 #endif
515
516
517 void wxPrintDialogData::operator=(const wxPrintDialogData& data)
518 {
519 m_printFromPage = data.m_printFromPage;
520 m_printToPage = data.m_printToPage;
521 m_printMinPage = data.m_printMinPage;
522 m_printMaxPage = data.m_printMaxPage;
523 m_printNoCopies = data.m_printNoCopies;
524 m_printAllPages = data.m_printAllPages;
525 m_printCollate = data.m_printCollate;
526 m_printToFile = data.m_printToFile;
527 m_printSelection = data.m_printSelection;
528 m_printEnableSelection = data.m_printEnableSelection;
529 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
530 m_printEnableHelp = data.m_printEnableHelp;
531 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
532 m_printSetupDialog = data.m_printSetupDialog;
533
534 m_printData = data.m_printData;
535 }
536
537 void wxPrintDialogData::operator=(const wxPrintData& data)
538 {
539 m_printData = data;
540 }
541
542 // ----------------------------------------------------------------------------
543 // wxPageSetupDialogData
544 // ----------------------------------------------------------------------------
545
546 wxPageSetupDialogData::wxPageSetupDialogData()
547 {
548 #if defined(__WIN95__)
549 m_pageSetupData = NULL;
550 #endif
551 m_paperSize = wxSize(0, 0);
552
553 CalculatePaperSizeFromId();
554
555 m_minMarginTopLeft = wxPoint(0, 0);
556 m_minMarginBottomRight = wxPoint(0, 0);
557 m_marginTopLeft = wxPoint(0, 0);
558 m_marginBottomRight = wxPoint(0, 0);
559
560 // Flags
561 m_defaultMinMargins = false;
562 m_enableMargins = true;
563 m_enableOrientation = true;
564 m_enablePaper = true;
565 m_enablePrinter = true;
566 m_enableHelp = false;
567 m_getDefaultInfo = false;
568 }
569
570 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
571 : wxObject()
572 {
573 #if defined(__WIN95__)
574 m_pageSetupData = NULL;
575 #endif
576 (*this) = dialogData;
577 }
578
579 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
580 {
581 #if defined(__WIN95__)
582 m_pageSetupData = NULL;
583 #endif
584 m_paperSize = wxSize(0, 0);
585 m_minMarginTopLeft = wxPoint(0, 0);
586 m_minMarginBottomRight = wxPoint(0, 0);
587 m_marginTopLeft = wxPoint(0, 0);
588 m_marginBottomRight = wxPoint(0, 0);
589
590 // Flags
591 m_defaultMinMargins = false;
592 m_enableMargins = true;
593 m_enableOrientation = true;
594 m_enablePaper = true;
595 m_enablePrinter = true;
596 m_enableHelp = false;
597 m_getDefaultInfo = false;
598
599 m_printData = printData;
600
601 // The wxPrintData paper size overrides these values, unless the size cannot
602 // be found.
603 CalculatePaperSizeFromId();
604 }
605
606 wxPageSetupDialogData::~wxPageSetupDialogData()
607 {
608 #if defined(__WIN95__) && defined(__WXMSW__)
609 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
610 if ( pd && pd->hDevMode )
611 GlobalFree(pd->hDevMode);
612 if ( pd && pd->hDevNames )
613 GlobalFree(pd->hDevNames);
614 if ( pd )
615 delete pd;
616 #endif
617 }
618
619 wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
620 {
621 m_paperSize = data.m_paperSize;
622 m_minMarginTopLeft = data.m_minMarginTopLeft;
623 m_minMarginBottomRight = data.m_minMarginBottomRight;
624 m_marginTopLeft = data.m_marginTopLeft;
625 m_marginBottomRight = data.m_marginBottomRight;
626 m_defaultMinMargins = data.m_defaultMinMargins;
627 m_enableMargins = data.m_enableMargins;
628 m_enableOrientation = data.m_enableOrientation;
629 m_enablePaper = data.m_enablePaper;
630 m_enablePrinter = data.m_enablePrinter;
631 m_getDefaultInfo = data.m_getDefaultInfo;;
632 m_enableHelp = data.m_enableHelp;
633
634 m_printData = data.m_printData;
635
636 return *this;
637 }
638
639 wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
640 {
641 m_printData = data;
642
643 return *this;
644 }
645
646 #if defined(__WIN95__)
647 void wxPageSetupDialogData::ConvertToNative()
648 {
649 wxWindowsPrintNativeData *data =
650 (wxWindowsPrintNativeData *) m_printData.GetNativeData();
651 data->TransferFrom( m_printData );
652
653 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
654
655 if ( m_pageSetupData == NULL )
656 {
657 pd = new PAGESETUPDLG;
658 pd->hDevMode = NULL;
659 pd->hDevNames = NULL;
660 m_pageSetupData = (void *)pd;
661 }
662
663 // Pass the devmode data (created in m_printData.ConvertToNative)
664 // to the PRINTDLG structure, since it'll
665 // be needed when PrintDlg is called.
666
667 if (pd->hDevMode)
668 {
669 GlobalFree(pd->hDevMode);
670 pd->hDevMode = NULL;
671 }
672
673 pd->hDevMode = (HGLOBAL) data->GetDevMode();
674
675 data->SetDevMode( (void*) NULL );
676
677 // Shouldn't assert; we should be able to test Ok-ness at a higher level
678 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
679
680 // Pass the devnames data (created in m_printData.ConvertToNative)
681 // to the PRINTDLG structure, since it'll
682 // be needed when PrintDlg is called.
683
684 if (pd->hDevNames)
685 {
686 GlobalFree(pd->hDevNames);
687 pd->hDevNames = NULL;
688 }
689
690 pd->hDevNames = (HGLOBAL) data->GetDevNames();
691
692 data->SetDevNames((void*) NULL);
693
694 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
695
696 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
697
698 if ( m_defaultMinMargins )
699 pd->Flags |= PSD_DEFAULTMINMARGINS;
700 if ( !m_enableMargins )
701 pd->Flags |= PSD_DISABLEMARGINS;
702 if ( !m_enableOrientation )
703 pd->Flags |= PSD_DISABLEORIENTATION;
704 if ( !m_enablePaper )
705 pd->Flags |= PSD_DISABLEPAPER;
706 if ( !m_enablePrinter )
707 pd->Flags |= PSD_DISABLEPRINTER;
708 if ( m_getDefaultInfo )
709 pd->Flags |= PSD_RETURNDEFAULT;
710 if ( m_enableHelp )
711 pd->Flags |= PSD_SHOWHELP;
712
713 // We want the units to be in hundredths of a millimetre
714 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
715
716 pd->lStructSize = sizeof( PAGESETUPDLG );
717 pd->hwndOwner=(HWND)NULL;
718 // pd->hDevNames=(HWND)NULL;
719 pd->hInstance=(HINSTANCE)NULL;
720 // PAGESETUPDLG is in hundreds of a mm
721 pd->ptPaperSize.x = m_paperSize.x * 100;
722 pd->ptPaperSize.y = m_paperSize.y * 100;
723
724 pd->rtMinMargin.left = m_minMarginTopLeft.x * 100;
725 pd->rtMinMargin.top = m_minMarginTopLeft.y * 100;
726 pd->rtMinMargin.right = m_minMarginBottomRight.x * 100;
727 pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100;
728
729 pd->rtMargin.left = m_marginTopLeft.x * 100;
730 pd->rtMargin.top = m_marginTopLeft.y * 100;
731 pd->rtMargin.right = m_marginBottomRight.x * 100;
732 pd->rtMargin.bottom = m_marginBottomRight.y * 100;
733
734 pd->lCustData = 0;
735 pd->lpfnPageSetupHook = NULL;
736 pd->lpfnPagePaintHook = NULL;
737 pd->hPageSetupTemplate = NULL;
738 pd->lpPageSetupTemplateName = NULL;
739
740 /*
741 if ( pd->hDevMode )
742 {
743 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
744 memset(devMode, 0, sizeof(DEVMODE));
745 devMode->dmSize = sizeof(DEVMODE);
746 devMode->dmOrientation = m_orientation;
747 devMode->dmFields = DM_ORIENTATION;
748 GlobalUnlock(pd->hDevMode);
749 }
750 */
751 }
752
753 void wxPageSetupDialogData::ConvertFromNative()
754 {
755 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData;
756 if ( !pd )
757 return;
758
759 wxWindowsPrintNativeData *data =
760 (wxWindowsPrintNativeData *) m_printData.GetNativeData();
761
762 // Pass the devmode data back to the wxPrintData structure where it really belongs.
763 if (pd->hDevMode)
764 {
765 if (data->GetDevMode())
766 {
767 // Make sure we don't leak memory
768 GlobalFree((HGLOBAL) data->GetDevMode());
769 }
770 data->SetDevMode( (void*) pd->hDevMode );
771 pd->hDevMode = NULL;
772 }
773
774 data->TransferTo( m_printData );
775
776 // Pass the devnames data back to the wxPrintData structure where it really belongs.
777 if (pd->hDevNames)
778 {
779 if (data->GetDevNames())
780 {
781 // Make sure we don't leak memory
782 GlobalFree((HGLOBAL) data->GetDevNames());
783 }
784 data->SetDevNames((void*) pd->hDevNames);
785 pd->hDevNames = NULL;
786 }
787
788 data->TransferTo( m_printData );
789
790 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
791
792 m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS);
793 m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS);
794 m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION);
795 m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER);
796 m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER);
797 m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT);
798 m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP);
799
800 // PAGESETUPDLG is in hundreds of a mm
801 m_paperSize.x = pd->ptPaperSize.x / 100;
802 m_paperSize.y = pd->ptPaperSize.y / 100;
803
804 m_minMarginTopLeft.x = pd->rtMinMargin.left / 100;
805 m_minMarginTopLeft.y = pd->rtMinMargin.top / 100;
806 m_minMarginBottomRight.x = pd->rtMinMargin.right / 100;
807 m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100;
808
809 m_marginTopLeft.x = pd->rtMargin.left / 100;
810 m_marginTopLeft.y = pd->rtMargin.top / 100;
811 m_marginBottomRight.x = pd->rtMargin.right / 100;
812 m_marginBottomRight.y = pd->rtMargin.bottom / 100;
813 }
814
815 void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
816 {
817 if ( m_pageSetupData == NULL )
818 ConvertToNative();
819
820 if ( m_pageSetupData != NULL && win != NULL)
821 {
822 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData;
823 pd->hwndOwner=(HWND) win->GetHWND();
824 }
825 }
826 #endif // Win95
827
828 #ifdef __WXMAC__
829 void wxPageSetupDialogData::ConvertToNative()
830 {
831 m_printData.ConvertToNative();
832 m_printData.m_nativePrintData->TransferFrom( this ) ;
833 }
834
835 void wxPageSetupDialogData::ConvertFromNative()
836 {
837 m_printData.ConvertFromNative ();
838 m_paperSize = m_printData.GetPaperSize() ;
839 CalculateIdFromPaperSize();
840 m_printData.m_nativePrintData->TransferTo( this ) ;
841 // adjust minimal values
842
843 if ( m_marginTopLeft.x < m_minMarginTopLeft.x )
844 m_marginTopLeft.x = m_minMarginTopLeft.x;
845
846 if ( m_marginBottomRight.x < m_minMarginBottomRight.x )
847 m_marginBottomRight.x = m_minMarginBottomRight.x;
848
849 if ( m_marginTopLeft.y < m_minMarginTopLeft.y )
850 m_marginTopLeft.y = m_minMarginTopLeft.y;
851
852 if ( m_marginBottomRight.y < m_minMarginBottomRight.y )
853 m_marginBottomRight.y = m_minMarginBottomRight.y;
854 }
855 #endif
856
857
858 // If a corresponding paper type is found in the paper database, will set the m_printData
859 // paper size id member as well.
860 void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
861 {
862 m_paperSize = sz;
863
864 CalculateIdFromPaperSize();
865 }
866
867 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
868 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
869 {
870 m_printData.SetPaperId(id);
871
872 CalculatePaperSizeFromId();
873 }
874
875 // Use paper size defined in this object to set the wxPrintData
876 // paper id
877 void wxPageSetupDialogData::CalculateIdFromPaperSize()
878 {
879 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
880 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
881
882 wxSize sz = GetPaperSize();
883
884 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
885 if (id != wxPAPER_NONE)
886 {
887 m_printData.SetPaperId(id);
888 }
889 }
890
891 // Use paper id in wxPrintData to set this object's paper size
892 void wxPageSetupDialogData::CalculatePaperSizeFromId()
893 {
894 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
895 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
896
897 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
898
899 // sz is in 10ths of a mm, while paper size is in mm
900 m_paperSize.x = sz.x / 10;
901 m_paperSize.y = sz.y / 10;
902 }
903
904 #endif // wxUSE_PRINTING_ARCHITECTURE