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