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