1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "cmndata.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/string.h"
38 #include "wx/gdicmn.h"
39 #include "wx/cmndata.h"
41 #include "wx/prntbase.h"
42 #include "wx/printdlg.h"
45 #include "wx/fontdlg.h"
46 #endif // wxUSE_FONTDLG
48 #if wxUSE_PRINTING_ARCHITECTURE
50 #endif // wxUSE_PRINTING_ARCHITECTURE
52 #if defined(__WXMSW__) && !defined(__PALMOS__)
54 #include "wx/msw/private.h"
56 #ifndef __SMARTPHONE__ /* of WinCE */
60 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
67 #include "wx/mac/private/print.h"
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
76 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
77 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
80 #define DMPAPER_USER 256
83 // ============================================================================
85 // ============================================================================
87 // ----------------------------------------------------------------------------
89 // ----------------------------------------------------------------------------
91 wxColourData::wxColourData()
94 m_dataColour
.Set(0,0,0);
95 // m_custColours are wxNullColours initially
98 wxColourData::wxColourData(const wxColourData
& data
)
104 wxColourData::~wxColourData()
108 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
110 wxCHECK_RET( (i
>= 0 && i
< 16), _T("custom colour index out of range") );
112 m_custColours
[i
] = colour
;
115 wxColour
wxColourData::GetCustomColour(int i
)
117 wxCHECK_MSG( (i
>= 0 && i
< 16), wxColour(0,0,0),
118 _T("custom colour index out of range") );
120 return m_custColours
[i
];
123 void wxColourData::operator=(const wxColourData
& data
)
126 for (i
= 0; i
< 16; i
++)
127 m_custColours
[i
] = data
.m_custColours
[i
];
129 m_dataColour
= (wxColour
&)data
.m_dataColour
;
130 m_chooseFull
= data
.m_chooseFull
;
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 wxFontData::wxFontData()
139 // Intialize colour to black.
140 m_fontColour
= wxNullColour
;
143 m_allowSymbols
= true;
144 m_enableEffects
= true;
148 m_encoding
= wxFONTENCODING_SYSTEM
;
151 wxFontData::~wxFontData()
157 wxFontDialogBase::~wxFontDialogBase()
161 #endif // wxUSE_FONTDLG
163 #if wxUSE_PRINTING_ARCHITECTURE
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 wxPrintData::wxPrintData()
171 m_nativePrintData
= wxNativePrintData::Create() ;
173 m_bin
= wxPRINTBIN_DEFAULT
;
174 m_printMode
= wxPRINT_MODE_PRINTER
;
175 m_printOrientation
= wxPORTRAIT
;
177 m_printCollate
= false;
180 m_printerName
= wxT("");
182 m_duplexMode
= wxDUPLEX_SIMPLEX
;
183 m_printQuality
= wxPRINT_QUALITY_HIGH
;
184 m_paperId
= wxPAPER_A4
;
185 m_paperSize
= wxSize(210, 297);
187 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
190 wxPrintData::wxPrintData(const wxPrintData
& printData
)
196 wxPrintData::~wxPrintData()
198 m_nativeData
->m_ref
--;
199 if (m_nativeData
->m_ref
== 0)
203 delete m_nativePrintData
;
208 void wxPrintData::ConvertToNative()
211 m_nativePrintData
->TransferFrom( this ) ;
213 m_nativeData
->TransferFrom( *this ) ;
217 void wxPrintData::ConvertFromNative()
220 m_nativePrintData
->TransferTo( this ) ;
222 m_nativeData
->TransferTo( *this ) ;
226 void wxPrintData::operator=(const wxPrintData
& data
)
228 m_printNoCopies
= data
.m_printNoCopies
;
229 m_printCollate
= data
.m_printCollate
;
230 m_printOrientation
= data
.m_printOrientation
;
231 m_printerName
= data
.m_printerName
;
232 m_colour
= data
.m_colour
;
233 m_duplexMode
= data
.m_duplexMode
;
234 m_printQuality
= data
.m_printQuality
;
235 m_paperId
= data
.m_paperId
;
236 m_paperSize
= data
.m_paperSize
;
238 m_printMode
= data
.m_printMode
;
239 m_filename
= data
.m_filename
;
241 m_nativeData
= data
.GetNativeData();
242 m_nativeData
->m_ref
++;
245 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
249 // Is this data OK for showing the print dialog?
250 bool wxPrintData::Ok() const
252 m_nativeData
->TransferFrom( *this );
254 return m_nativeData
->Ok();
257 // ----------------------------------------------------------------------------
259 // ----------------------------------------------------------------------------
261 wxPrintDialogData::wxPrintDialogData()
268 m_printAllPages
= false;
269 m_printCollate
= false;
270 m_printToFile
= false;
271 m_printSelection
= false;
272 m_printEnableSelection
= false;
273 m_printEnablePageNumbers
= true;
275 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
276 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
278 m_printEnableHelp
= false;
279 m_printSetupDialog
= false;
282 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
285 (*this) = dialogData
;
288 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
293 m_printMaxPage
= 9999;
295 m_printAllPages
= false;
296 m_printCollate
= false;
297 m_printToFile
= false;
298 m_printSelection
= false;
299 m_printEnableSelection
= false;
300 m_printEnablePageNumbers
= true;
301 m_printEnablePrintToFile
= true;
302 m_printEnableHelp
= false;
303 m_printSetupDialog
= false;
305 m_printData
= printData
;
308 wxPrintDialogData::~wxPrintDialogData()
314 void wxPrintDialogData::ConvertToNative()
316 m_printData
.ConvertToNative();
317 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
320 void wxPrintDialogData::ConvertFromNative()
322 m_printData
.ConvertFromNative();
323 m_printData
.m_nativePrintData
->TransferTo( this ) ;
329 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
331 m_printFromPage
= data
.m_printFromPage
;
332 m_printToPage
= data
.m_printToPage
;
333 m_printMinPage
= data
.m_printMinPage
;
334 m_printMaxPage
= data
.m_printMaxPage
;
335 m_printNoCopies
= data
.m_printNoCopies
;
336 m_printAllPages
= data
.m_printAllPages
;
337 m_printCollate
= data
.m_printCollate
;
338 m_printToFile
= data
.m_printToFile
;
339 m_printSelection
= data
.m_printSelection
;
340 m_printEnableSelection
= data
.m_printEnableSelection
;
341 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
342 m_printEnableHelp
= data
.m_printEnableHelp
;
343 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
344 m_printSetupDialog
= data
.m_printSetupDialog
;
346 m_printData
= data
.m_printData
;
349 void wxPrintDialogData::operator=(const wxPrintData
& data
)
354 // ----------------------------------------------------------------------------
355 // wxPageSetupDialogData
356 // ----------------------------------------------------------------------------
358 wxPageSetupDialogData::wxPageSetupDialogData()
360 #if defined(__WIN95__)
361 m_pageSetupData
= NULL
;
363 m_paperSize
= wxSize(0, 0);
365 CalculatePaperSizeFromId();
367 m_minMarginTopLeft
= wxPoint(0, 0);
368 m_minMarginBottomRight
= wxPoint(0, 0);
369 m_marginTopLeft
= wxPoint(0, 0);
370 m_marginBottomRight
= wxPoint(0, 0);
373 m_defaultMinMargins
= false;
374 m_enableMargins
= true;
375 m_enableOrientation
= true;
376 m_enablePaper
= true;
377 m_enablePrinter
= true;
378 m_enableHelp
= false;
379 m_getDefaultInfo
= false;
382 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
385 #if defined(__WIN95__)
386 m_pageSetupData
= NULL
;
388 (*this) = dialogData
;
391 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
393 #if defined(__WIN95__)
394 m_pageSetupData
= NULL
;
396 m_paperSize
= wxSize(0, 0);
397 m_minMarginTopLeft
= wxPoint(0, 0);
398 m_minMarginBottomRight
= wxPoint(0, 0);
399 m_marginTopLeft
= wxPoint(0, 0);
400 m_marginBottomRight
= wxPoint(0, 0);
403 m_defaultMinMargins
= false;
404 m_enableMargins
= true;
405 m_enableOrientation
= true;
406 m_enablePaper
= true;
407 m_enablePrinter
= true;
408 m_enableHelp
= false;
409 m_getDefaultInfo
= false;
411 m_printData
= printData
;
413 // The wxPrintData paper size overrides these values, unless the size cannot
415 CalculatePaperSizeFromId();
418 wxPageSetupDialogData::~wxPageSetupDialogData()
420 #if defined(__WIN95__) && defined(__WXMSW__)
421 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
422 if ( pd
&& pd
->hDevMode
)
423 GlobalFree(pd
->hDevMode
);
424 if ( pd
&& pd
->hDevNames
)
425 GlobalFree(pd
->hDevNames
);
431 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
433 m_paperSize
= data
.m_paperSize
;
434 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
435 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
436 m_marginTopLeft
= data
.m_marginTopLeft
;
437 m_marginBottomRight
= data
.m_marginBottomRight
;
438 m_defaultMinMargins
= data
.m_defaultMinMargins
;
439 m_enableMargins
= data
.m_enableMargins
;
440 m_enableOrientation
= data
.m_enableOrientation
;
441 m_enablePaper
= data
.m_enablePaper
;
442 m_enablePrinter
= data
.m_enablePrinter
;
443 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
444 m_enableHelp
= data
.m_enableHelp
;
446 m_printData
= data
.m_printData
;
451 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
458 #if defined(__WIN95__)
459 void wxPageSetupDialogData::ConvertToNative()
461 wxWindowsPrintNativeData
*data
=
462 (wxWindowsPrintNativeData
*) m_printData
.GetNativeData();
463 data
->TransferFrom( m_printData
);
465 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
467 if ( m_pageSetupData
== NULL
)
469 pd
= new PAGESETUPDLG
;
471 pd
->hDevNames
= NULL
;
472 m_pageSetupData
= (void *)pd
;
475 // Pass the devmode data (created in m_printData.ConvertToNative)
476 // to the PRINTDLG structure, since it'll
477 // be needed when PrintDlg is called.
481 GlobalFree(pd
->hDevMode
);
485 pd
->hDevMode
= (HGLOBAL
) data
->GetDevMode();
487 data
->SetDevMode( (void*) NULL
);
489 // Shouldn't assert; we should be able to test Ok-ness at a higher level
490 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
492 // Pass the devnames data (created in m_printData.ConvertToNative)
493 // to the PRINTDLG structure, since it'll
494 // be needed when PrintDlg is called.
498 GlobalFree(pd
->hDevNames
);
499 pd
->hDevNames
= NULL
;
502 pd
->hDevNames
= (HGLOBAL
) data
->GetDevNames();
504 data
->SetDevNames((void*) NULL
);
506 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
508 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
510 if ( m_defaultMinMargins
)
511 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
512 if ( !m_enableMargins
)
513 pd
->Flags
|= PSD_DISABLEMARGINS
;
514 if ( !m_enableOrientation
)
515 pd
->Flags
|= PSD_DISABLEORIENTATION
;
516 if ( !m_enablePaper
)
517 pd
->Flags
|= PSD_DISABLEPAPER
;
518 if ( !m_enablePrinter
)
519 pd
->Flags
|= PSD_DISABLEPRINTER
;
520 if ( m_getDefaultInfo
)
521 pd
->Flags
|= PSD_RETURNDEFAULT
;
523 pd
->Flags
|= PSD_SHOWHELP
;
525 // We want the units to be in hundredths of a millimetre
526 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
528 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
529 pd
->hwndOwner
=(HWND
)NULL
;
530 // pd->hDevNames=(HWND)NULL;
531 pd
->hInstance
=(HINSTANCE
)NULL
;
532 // PAGESETUPDLG is in hundreds of a mm
533 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
534 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
536 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
537 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
538 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
539 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
541 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
542 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
543 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
544 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
547 pd
->lpfnPageSetupHook
= NULL
;
548 pd
->lpfnPagePaintHook
= NULL
;
549 pd
->hPageSetupTemplate
= NULL
;
550 pd
->lpPageSetupTemplateName
= NULL
;
555 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
556 memset(devMode, 0, sizeof(DEVMODE));
557 devMode->dmSize = sizeof(DEVMODE);
558 devMode->dmOrientation = m_orientation;
559 devMode->dmFields = DM_ORIENTATION;
560 GlobalUnlock(pd->hDevMode);
565 void wxPageSetupDialogData::ConvertFromNative()
567 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
571 wxWindowsPrintNativeData
*data
=
572 (wxWindowsPrintNativeData
*) m_printData
.GetNativeData();
574 // Pass the devmode data back to the wxPrintData structure where it really belongs.
577 if (data
->GetDevMode())
579 // Make sure we don't leak memory
580 GlobalFree((HGLOBAL
) data
->GetDevMode());
582 data
->SetDevMode( (void*) pd
->hDevMode
);
586 data
->TransferTo( m_printData
);
588 // Pass the devnames data back to the wxPrintData structure where it really belongs.
591 if (data
->GetDevNames())
593 // Make sure we don't leak memory
594 GlobalFree((HGLOBAL
) data
->GetDevNames());
596 data
->SetDevNames((void*) pd
->hDevNames
);
597 pd
->hDevNames
= NULL
;
600 data
->TransferTo( m_printData
);
602 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
604 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
605 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
606 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
607 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
608 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
609 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
610 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
612 // PAGESETUPDLG is in hundreds of a mm
613 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
614 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
616 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
617 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
618 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
619 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
621 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100;
622 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100;
623 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100;
624 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100;
627 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
629 if ( m_pageSetupData
== NULL
)
632 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
634 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
635 pd
->hwndOwner
=(HWND
) win
->GetHWND();
641 void wxPageSetupDialogData::ConvertToNative()
643 m_printData
.ConvertToNative();
644 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
647 void wxPageSetupDialogData::ConvertFromNative()
649 m_printData
.ConvertFromNative ();
650 m_paperSize
= m_printData
.GetPaperSize() ;
651 CalculateIdFromPaperSize();
652 m_printData
.m_nativePrintData
->TransferTo( this ) ;
653 // adjust minimal values
655 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
656 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
658 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
659 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
661 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
662 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
664 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
665 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
670 // If a corresponding paper type is found in the paper database, will set the m_printData
671 // paper size id member as well.
672 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
676 CalculateIdFromPaperSize();
679 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
680 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
682 m_printData
.SetPaperId(id
);
684 CalculatePaperSizeFromId();
687 // Use paper size defined in this object to set the wxPrintData
689 void wxPageSetupDialogData::CalculateIdFromPaperSize()
691 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
692 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
694 wxSize sz
= GetPaperSize();
696 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
697 if (id
!= wxPAPER_NONE
)
699 m_printData
.SetPaperId(id
);
703 // Use paper id in wxPrintData to set this object's paper size
704 void wxPageSetupDialogData::CalculatePaperSizeFromId()
706 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
707 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
709 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
711 // sz is in 10ths of a mm, while paper size is in mm
712 m_paperSize
.x
= sz
.x
/ 10;
713 m_paperSize
.y
= sz
.y
/ 10;
716 #endif // wxUSE_PRINTING_ARCHITECTURE