1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
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"
43 #include "wx/fontdlg.h"
44 #endif // wxUSE_FONTDLG
46 #if wxUSE_PRINTING_ARCHITECTURE
48 #endif // wxUSE_PRINTING_ARCHITECTURE
52 #include "wx/msw/private.h"
54 #if !defined(__WIN32__)
59 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
65 #if wxUSE_PRINTING_ARCHITECTURE
66 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
67 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
68 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
69 #endif // wxUSE_PRINTING_ARCHITECTURE
71 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
72 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
75 #include "wx/mac/uma.h"
77 #if defined(TARGET_CARBON) && !defined(__DARWIN__)
78 # if PM_USE_SESSION_APIS
81 # include <PMApplication.h>
87 #define mm2pt 2.83464566929
88 #define pt2mm 0.352777777778
92 #define DMPAPER_USER 256
95 // ============================================================================
97 // ============================================================================
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 wxColourData::wxColourData()
106 for (i
= 0; i
< 16; i
++)
107 custColours
[i
].Set(255, 255, 255);
110 dataColour
.Set(0,0,0);
113 wxColourData::wxColourData(const wxColourData
& data
)
119 wxColourData::~wxColourData()
123 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
128 custColours
[i
] = colour
;
131 wxColour
wxColourData::GetCustomColour(int i
)
134 return wxColour(0,0,0);
136 return custColours
[i
];
139 void wxColourData::operator=(const wxColourData
& data
)
142 for (i
= 0; i
< 16; i
++)
143 custColours
[i
] = data
.custColours
[i
];
145 dataColour
= (wxColour
&)data
.dataColour
;
146 chooseFull
= data
.chooseFull
;
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
153 wxFontData::wxFontData()
155 // Intialize colour to black.
156 fontColour
= wxNullColour
;
160 enableEffects
= TRUE
;
164 m_encoding
= wxFONTENCODING_SYSTEM
;
167 wxFontData::~wxFontData()
173 wxFontDialogBase::~wxFontDialogBase()
177 #endif // wxUSE_FONTDLG
179 #if wxUSE_PRINTING_ARCHITECTURE
180 // ----------------------------------------------------------------------------
182 // ----------------------------------------------------------------------------
184 wxPrintData::wxPrintData()
187 m_devMode
= (void*) NULL
;
188 m_devNames
= (void*) NULL
;
189 #elif defined( __WXMAC__ )
191 m_macPageFormat
= kPMNoPageFormat
;
192 m_macPrintSettings
= kPMNoPrintSettings
;
193 m_macPrintSession
= kPMNoReference
;
194 ValidateOrCreateNative() ;
196 m_macPrintSettings
= (THPrint
) NewHandleClear( sizeof( TPrint
) );
197 (**(THPrint
)m_macPrintSettings
).iPrVersion
= 0; // something invalid
199 (**(THPrint
)m_macPrintSettings
).prInfo
.iHRes
= 72;
200 (**(THPrint
)m_macPrintSettings
).prInfo
.iVRes
= 72;
201 Rect r1
= { 0, 0, 8*72 - 2 * 18, 11*72 - 2 * 36 };
202 (**(THPrint
)m_macPrintSettings
).prInfo
.rPage
= r1
;// must have its top left & (0,0)
204 Rect r2
= { -18, -36, 8*72 - 18, 11*72 - 36 };
205 (**(THPrint
)m_macPrintSettings
).rPaper
= r2
;
206 (**(THPrint
)m_macPrintSettings
).prStl
.iPageV
= 11 * 120 ; // 11 inches in 120th of an inch
207 (**(THPrint
)m_macPrintSettings
).prStl
.iPageH
= 8 * 120 ; // 8 inches in 120th of an inch
210 m_printOrientation
= wxPORTRAIT
;
212 m_printCollate
= FALSE
;
215 m_printerName
= wxT("");
217 m_duplexMode
= wxDUPLEX_SIMPLEX
;
218 m_printQuality
= wxPRINT_QUALITY_HIGH
;
219 m_paperId
= wxPAPER_A4
;
220 m_paperSize
= wxSize(210, 297);
222 // PostScript-specific data
223 m_previewCommand
= wxT("");
224 m_filename
= wxT("");
226 m_printerCommand
= wxT("print");
227 m_printerOptions
= wxT("/nonotify/queue=psqueue");
228 m_afmPath
= wxT("sys$ps_font_metrics:");
232 m_printerCommand
= wxT("print");
233 m_printerOptions
= wxT("");
234 m_afmPath
= wxT("c:\\windows\\system\\");
237 #if !defined(__VMS__) && !defined(__WXMSW__)
238 m_printerCommand
= wxT("lpr");
239 m_printerOptions
= wxT("");
243 m_printerScaleX
= 1.0;
244 m_printerScaleY
= 1.0;
245 m_printerTranslateX
= 0;
246 m_printerTranslateY
= 0;
247 m_printMode
= wxPRINT_MODE_FILE
;
250 wxPrintData::wxPrintData(const wxPrintData
& printData
)
254 m_devMode
= (void*) NULL
;
255 m_devNames
= (void*) NULL
;
256 #elif defined( __WXMAC__ )
258 m_macPageFormat
= kPMNoPageFormat
;
259 m_macPrintSettings
= kPMNoPrintSettings
;
260 m_macPrintSession
= kPMNoReference
;
262 m_macPrintSettings
= NULL
;
268 wxPrintData::~wxPrintData()
271 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
273 GlobalFree(hDevMode
);
274 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
276 GlobalFree(hDevNames
);
277 #elif defined(__WXMAC__)
279 if (m_macPageFormat
!= kPMNoPageFormat
)
281 #if PM_USE_SESSION_APIS
282 (void)PMRelease(m_macPageFormat
);
284 (void)PMDisposePageFormat(m_macPageFormat
);
286 m_macPageFormat
= kPMNoPageFormat
;
289 if (m_macPrintSettings
!= kPMNoPrintSettings
)
291 #if PM_USE_SESSION_APIS
292 (void)PMRelease(m_macPrintSettings
);
294 (void)PMDisposePrintSettings(m_macPrintSettings
);
296 m_macPrintSettings
= kPMNoPrintSettings
;
299 if ( m_macPrintSession
!= kPMNoReference
)
301 #if PM_USE_SESSION_APIS
302 (void)PMRelease(m_macPrintSession
);
304 (void)PMDisposePrintSession(m_macPrintSession
);
306 m_macPrintSession
= kPMNoReference
;
309 wxASSERT( m_macPrintSettings
);
310 // we should perhaps delete
315 #if defined(__WXMSW__) // && defined(__WIN32__)
317 #if defined(__WXDEBUG__) && defined(__WIN32__)
318 static wxString
wxGetPrintDlgError()
320 DWORD err
= CommDlgExtendedError();
321 wxString msg
= wxT("Unknown");
324 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
325 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
326 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
327 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
328 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
329 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
330 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
331 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
332 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
333 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
334 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
335 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
336 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
337 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
338 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
339 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
340 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
341 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
342 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
343 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
344 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
345 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
352 static HGLOBAL
wxCreateDevNames(const wxString
& driverName
, const wxString
& printerName
, const wxString
& portName
)
355 // if (!driverName.IsEmpty() && !printerName.IsEmpty() && !portName.IsEmpty())
356 if (driverName
.IsEmpty() && printerName
.IsEmpty() && portName
.IsEmpty())
361 hDev
= GlobalAlloc(GPTR
, 4*sizeof(WORD
)+
362 ( driverName
.Length() + 1 +
363 printerName
.Length() + 1 +
364 portName
.Length()+1 ) * sizeof(wxChar
) );
365 LPDEVNAMES lpDev
= (LPDEVNAMES
)GlobalLock(hDev
);
366 lpDev
->wDriverOffset
= sizeof(WORD
)*4;
367 wxStrcpy((wxChar
*)((char*)lpDev
+ lpDev
->wDriverOffset
), driverName
);
369 lpDev
->wDeviceOffset
= (WORD
)( lpDev
->wDriverOffset
+
370 sizeof(wxChar
) * ( driverName
.Length() + 1 ) );
371 wxStrcpy((wxChar
*)((char*)lpDev
+ lpDev
->wDeviceOffset
), printerName
);
373 lpDev
->wOutputOffset
= (WORD
)( lpDev
->wDeviceOffset
+
374 sizeof(wxChar
) * ( printerName
.Length() + 1 ) );
375 wxStrcpy((wxChar
*)((char*) lpDev
+ lpDev
->wOutputOffset
), portName
);
385 void wxPrintData::ConvertToNative()
387 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
388 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
391 // Use PRINTDLG as a way of creating a DEVMODE object
394 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
399 memset(&pd
, 0, sizeof(PRINTDLG
));
400 pd
.lStructSize
= sizeof(PRINTDLG
);
403 pd
.hwndOwner
= (HWND
)NULL
;
404 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
405 pd
.hDevNames
= NULL
; // Ditto
406 //pd.hInstance = (HINSTANCE) wxGetInstance();
408 pd
.Flags
= PD_RETURNDEFAULT
;
411 // Fill out the DEVMODE structure
412 // so we can use it as input in the 'real' PrintDlg
416 GlobalFree(pd
.hDevMode
);
418 GlobalFree(pd
.hDevNames
);
422 #if defined(__WXDEBUG__) && defined(__WIN32__)
423 wxString
str(wxT("Printing error: "));
424 str
+= wxGetPrintDlgError();
430 hDevMode
= pd
.hDevMode
;
431 m_devMode
= (void*)(long) hDevMode
;
434 // We'll create a new DEVNAMEs structure below.
436 GlobalFree(pd
.hDevNames
);
439 // hDevNames = pd->hDevNames;
440 // m_devNames = (void*)(long) hDevNames;
441 // pd->hDevnames = NULL;
448 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
452 devMode
->dmOrientation
= m_printOrientation
;
457 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
458 devMode
->dmFields
|= DM_COLLATE
;
461 //// Number of copies
463 devMode
->dmCopies
= m_printNoCopies
;
464 devMode
->dmFields
|= DM_COPIES
;
468 if (m_printerName
!= wxT(""))
470 //int len = wxMin(31, m_printerName.Len());
471 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,m_printerName
.c_str(),31);
472 devMode
->dmDeviceName
[31] = wxT('\0');
478 devMode
->dmColor
= DMCOLOR_COLOR
;
480 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
482 devMode
->dmFields
|= DM_COLOR
;
486 if (m_paperId
== wxPAPER_NONE
)
488 // DEVMODE is in tenths of a milimeter
489 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
490 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
491 devMode
->dmPaperSize
= DMPAPER_USER
;
492 devMode
->dmFields
|= DM_PAPERWIDTH
;
493 devMode
->dmFields
|= DM_PAPERLENGTH
;
497 if (wxThePrintPaperDatabase
)
499 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
502 devMode
->dmPaperSize
= paper
->GetPlatformId();
503 devMode
->dmFields
|= DM_PAPERSIZE
;
511 switch (m_duplexMode
)
513 case wxDUPLEX_HORIZONTAL
: {
514 duplex
= DMDUP_HORIZONTAL
; break;
516 case wxDUPLEX_VERTICAL
: {
517 duplex
= DMDUP_VERTICAL
; break;
520 case wxDUPLEX_SIMPLEX
: {
521 duplex
= DMDUP_SIMPLEX
; break;
524 devMode
->dmDuplex
= duplex
;
525 devMode
->dmFields
|= DM_DUPLEX
;
530 switch (m_printQuality
)
532 case wxPRINT_QUALITY_MEDIUM
: {
533 quality
= DMRES_MEDIUM
; break;
535 case wxPRINT_QUALITY_LOW
: {
536 quality
= DMRES_LOW
; break;
538 case wxPRINT_QUALITY_DRAFT
: {
539 quality
= DMRES_DRAFT
; break;
541 case wxPRINT_QUALITY_HIGH
: {
542 quality
= DMRES_HIGH
; break;
545 quality
= m_printQuality
; break;
548 devMode
->dmPrintQuality
= quality
;
549 devMode
->dmFields
|= DM_PRINTQUALITY
;
551 GlobalUnlock(hDevMode
);
556 GlobalFree(hDevNames
);
559 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
560 m_devNames
= (void*) (long) wxCreateDevNames(wxT(""), m_printerName
, wxT(""));
563 void wxPrintData::ConvertFromNative()
565 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
566 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
573 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
577 if (devMode
->dmFields
& DM_ORIENTATION
)
578 m_printOrientation
= devMode
->dmOrientation
;
583 if (devMode
->dmFields
& DM_COLLATE
)
585 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
586 m_printCollate
= TRUE
;
588 m_printCollate
= FALSE
;
592 //// Number of copies
594 if (devMode
->dmFields
& DM_COPIES
)
596 m_printNoCopies
= devMode
->dmCopies
;
601 if (devMode
->dmDeviceName
[0] != 0)
603 m_printerName
= devMode
->dmDeviceName
;
608 if (devMode
->dmFields
& DM_COLOR
)
610 if (devMode
->dmColor
== DMCOLOR_COLOR
)
620 // We don't know size of user defined paper and some buggy drivers
621 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
622 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
623 // code wouldn't set m_paperSize correctly.
624 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
626 if (wxThePrintPaperDatabase
)
628 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
631 m_paperId
= paper
->GetId();
632 m_paperSize
.x
= paper
->GetWidth() / 10;
633 m_paperSize
.y
= paper
->GetHeight() / 10;
637 // Shouldn't really get here
638 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
640 m_paperId
= wxPAPER_NONE
;
647 // Shouldn't really get here
648 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
650 m_paperId
= wxPAPER_NONE
;
655 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
657 // DEVMODE is in tenths of a milimeter
658 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
659 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
660 m_paperId
= wxPAPER_NONE
;
664 // Shouldn't really get here
665 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
669 m_paperId
= wxPAPER_NONE
;
674 if (devMode
->dmFields
& DM_DUPLEX
)
676 switch (devMode
->dmDuplex
)
678 case DMDUP_HORIZONTAL
: {
679 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
681 case DMDUP_VERTICAL
: {
682 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
685 case DMDUP_SIMPLEX
: {
686 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
691 m_duplexMode
= wxDUPLEX_SIMPLEX
;
695 if (devMode
->dmFields
& DM_PRINTQUALITY
)
697 switch (devMode
->dmPrintQuality
)
700 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
703 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
706 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
709 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
713 // TODO: if the printer fills in the resolution in DPI, how
714 // will the application know if it's high, low, draft etc.??
715 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
716 m_printQuality
= devMode
->dmPrintQuality
; break;
722 m_printQuality
= wxPRINT_QUALITY_HIGH
;
724 GlobalUnlock(hDevMode
);
729 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
732 // TODO: Unicode-ification
735 // port is obsolete in WIN32
736 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
738 // Get the printer name
739 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
741 // Not sure if we should check for this mismatch
742 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
744 if (printerName
!= wxT(""))
745 m_printerName
= printerName
;
747 GlobalUnlock(hDevNames
);
756 void wxPrintData::ConvertToNative()
758 ValidateOrCreateNative() ;
760 PMSetCopies( (PMPrintSettings
) m_macPrintSettings
, m_printNoCopies
, false ) ;
761 PMSetOrientation( (PMPageFormat
) m_macPageFormat
, ( m_printOrientation
== wxLANDSCAPE
) ?
762 kPMLandscape
: kPMPortrait
, false ) ;
763 // collate cannot be set
764 #if 0 // not yet tested
765 if ( m_printerName
.Length() > 0 )
766 PMSessionSetCurrentPrinter( (PMPrintSession
) m_macPrintSession
, wxMacCFStringHolder( m_printerName
) ) ;
769 PMGetColorMode( (PMPrintSettings
) m_macPrintSettings
, &color
) ;
772 if ( color
== kPMBlackAndWhite
)
773 PMSetColorMode( (PMPrintSettings
) m_macPrintSettings
, kPMColor
) ;
776 PMSetColorMode( (PMPrintSettings
) m_macPrintSettings
, kPMBlackAndWhite
) ;
778 // PMDuplexMode not yet accessible via API
779 // PMQualityMode not yet accessible via API
782 // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
783 (**(THPrint
)m_macPrintSettings
).prJob
.iCopies
= m_printNoCopies
;
784 (**(THPrint
)m_macPrintSettings
).rPaper
.left
= int( ((double) m_minMarginTopLeft
.x
)*mm2pt
);
785 (**(THPrint
)m_macPrintSettings
).rPaper
.top
= int( ((double) m_minMarginTopLeft
.y
)*mm2pt
);
787 (**(THPrint
)m_macPrintSettings
).rPaper
.right
= int( ((double) m_paperSize
.x
- m_minMarginTopLeft
.x
)*mm2pt
);
788 (**(THPrint
)m_macPrintSettings
).rPaper
.bottom
= int( ((double) m_paperSize
.y
- m_minMarginTopLeft
.y
)*mm2pt
);
790 (**(THPrint
)m_macPrintSettings
).prInfo
.rPage
.left
= 0;
791 (**(THPrint
)m_macPrintSettings
).prInfo
.rPage
.top
= 0;
792 (**(THPrint
)m_macPrintSettings
).prInfo
.rPage
.right
= int( ((double) m_paperSize
.x
- m_minMarginTopLeft
.x
- m_minMarginBottomRight
.x
)*mm2pt
);
793 (**(THPrint
)m_macPrintSettings
).prInfo
.rPage
.bottom
= int( ((double) m_paperSize
.y
- m_minMarginTopLeft
.y
- m_minMarginBottomRight
.y
)*mm2pt
);
797 void wxPrintData::ConvertFromNative()
800 OSStatus err
= noErr
;
803 err
= PMGetCopies( (PMPrintSettings
) m_macPrintSettings
, &copies
) ;
805 m_printNoCopies
= copies
;
807 PMOrientation orientation
;
808 err
= PMGetOrientation( (PMPageFormat
) m_macPageFormat
, &orientation
) ;
811 if ( orientation
== kPMPortrait
|| orientation
== kPMReversePortrait
)
812 m_printOrientation
= wxPORTRAIT
;
814 m_printOrientation
= wxLANDSCAPE
;
817 // collate cannot be set
820 wxMacCFStringHolder name
;
822 PMSessionGetCurrentPrinter( (PMPrintSession
) m_macPrintSession
,
824 m_printerName
= name
.AsString() ;
829 err
= PMGetColorMode( (PMPrintSettings
) m_macPrintSettings
, &color
) ;
831 m_colour
= !(color
== kPMBlackAndWhite
) ;
833 // PMDuplexMode not yet accessible via API
834 // PMQualityMode not yet accessible via API
837 err
= PMGetUnadjustedPaperRect((PMPageFormat
) m_macPageFormat
, &rPaper
);
840 m_paperSize
.x
= (int)(( rPaper
.right
- rPaper
.left
) * pt2mm
+ 0.5 );
841 m_paperSize
.y
= (int)(( rPaper
.bottom
- rPaper
.top
) * pt2mm
+ 0.5 );
844 m_printNoCopies
= (**(THPrint
)m_macPrintSettings
).prJob
.iCopies
;
847 m_paperSize
.x
= ((double) (**(THPrint
)m_macPrintSettings
).rPaper
.right
- (**(THPrint
)m_macPrintSettings
).rPaper
.left
) * pt2mm
;
848 m_paperSize
.y
= ((double) (**(THPrint
)m_macPrintSettings
).rPaper
.bottom
- (**(THPrint
)m_macPrintSettings
).rPaper
.top
) * pt2mm
;
852 void wxPrintData::ValidateOrCreateNative()
855 OSStatus err
= noErr
;
856 if ( m_macPrintSession
== kPMNoReference
)
858 err
= PMCreateSession( (PMPrintSession
*) &m_macPrintSession
) ;
860 // Set up a valid PageFormat object.
861 if ( m_macPageFormat
== kPMNoPageFormat
)
863 err
= PMCreatePageFormat((PMPageFormat
*) &m_macPageFormat
);
865 // Note that PMPageFormat is not session-specific, but calling
866 // PMSessionDefaultPageFormat assigns values specific to the printer
867 // associated with the current printing session.
868 if ((err
== noErr
) &&
869 ( m_macPageFormat
!= kPMNoPageFormat
))
871 err
= PMSessionDefaultPageFormat((PMPrintSession
) m_macPrintSession
,
872 (PMPageFormat
) m_macPageFormat
);
877 err
= PMSessionValidatePageFormat((PMPrintSession
) m_macPrintSession
,
878 (PMPageFormat
) m_macPageFormat
,
882 // Set up a valid PrintSettings object.
883 if ( m_macPrintSettings
== kPMNoPrintSettings
)
885 err
= PMCreatePrintSettings((PMPrintSettings
*) &m_macPrintSettings
);
887 // Note that PMPrintSettings is not session-specific, but calling
888 // PMSessionDefaultPrintSettings assigns values specific to the printer
889 // associated with the current printing session.
890 if ((err
== noErr
) &&
891 ( m_macPrintSettings
!= kPMNoPrintSettings
))
893 err
= PMSessionDefaultPrintSettings((PMPrintSession
) m_macPrintSession
,
894 (PMPrintSettings
) m_macPrintSettings
);
899 err
= PMSessionValidatePrintSettings((PMPrintSession
) m_macPrintSession
,
900 (PMPrintSettings
) m_macPrintSettings
,
909 void wxPrintData::operator=(const wxPrintData
& data
)
913 if ( m_macPrintSession
!= kPMNoPrintSettings
)
915 PMRelease( m_macPrintSession
) ;
916 m_macPrintSession
= kPMNoPrintSettings
;
918 if ( data
.m_macPrintSession
!= kPMNoPrintSettings
)
920 m_macPrintSession
= data
.m_macPrintSession
;
921 PMRetain( m_macPrintSession
) ;
924 if ( m_macPrintSettings
!= kPMNoPrintSettings
)
926 PMRelease( m_macPrintSettings
) ;
927 m_macPrintSettings
= kPMNoPrintSettings
;
929 if ( data
.m_macPrintSettings
!= kPMNoPrintSettings
)
931 m_macPrintSettings
= data
.m_macPrintSettings
;
932 PMRetain( m_macPrintSettings
) ;
935 if ( m_macPageFormat
!= kPMNoPageFormat
)
937 PMRelease( m_macPageFormat
) ;
938 m_macPageFormat
= kPMNoPageFormat
;
940 if ( data
.m_macPageFormat
!= kPMNoPageFormat
)
942 m_macPageFormat
= data
.m_macPageFormat
;
943 PMRetain( m_macPageFormat
) ;
946 m_macPrintSettings
= data
.m_macPrintSettings
;
947 HandToHand( (Handle
*) &m_macPrintSettings
);
950 m_printNoCopies
= data
.m_printNoCopies
;
951 m_printCollate
= data
.m_printCollate
;
952 m_printOrientation
= data
.m_printOrientation
;
953 m_printerName
= data
.m_printerName
;
954 m_colour
= data
.m_colour
;
955 m_duplexMode
= data
.m_duplexMode
;
956 m_printQuality
= data
.m_printQuality
;
957 m_paperId
= data
.m_paperId
;
958 m_paperSize
= data
.m_paperSize
;
960 // PostScript-specific data
961 m_printerCommand
= data
.m_printerCommand
;
962 m_previewCommand
= data
.m_previewCommand
;
963 m_printerOptions
= data
.m_printerOptions
;
964 m_filename
= data
.m_filename
;
965 m_afmPath
= data
.m_afmPath
;
966 m_printerScaleX
= data
.m_printerScaleX
;
967 m_printerScaleY
= data
.m_printerScaleY
;
968 m_printerTranslateX
= data
.m_printerTranslateX
;
969 m_printerTranslateY
= data
.m_printerTranslateY
;
970 m_printMode
= data
.m_printMode
;
973 // Is this data OK for showing the print dialog?
974 bool wxPrintData::Ok() const
977 ((wxPrintData
*)this)->ConvertToNative();
978 return (m_devMode
!= NULL
) ;
984 // ----------------------------------------------------------------------------
986 // ----------------------------------------------------------------------------
988 wxPrintDialogData::wxPrintDialogData()
991 m_printDlgData
= NULL
;
998 m_printAllPages
= FALSE
;
999 m_printCollate
= FALSE
;
1000 m_printToFile
= FALSE
;
1001 m_printSelection
= FALSE
;
1002 m_printEnableSelection
= FALSE
;
1003 m_printEnablePageNumbers
= TRUE
;
1004 m_printEnablePrintToFile
= TRUE
;
1005 m_printEnableHelp
= FALSE
;
1006 m_printSetupDialog
= FALSE
;
1009 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
1013 m_printDlgData
= NULL
;
1015 (*this) = dialogData
;
1018 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
1021 m_printDlgData
= NULL
;
1023 m_printFromPage
= 0;
1027 m_printNoCopies
= 1;
1028 m_printAllPages
= FALSE
;
1029 m_printCollate
= FALSE
;
1030 m_printToFile
= FALSE
;
1031 m_printSelection
= FALSE
;
1032 m_printEnableSelection
= FALSE
;
1033 m_printEnablePageNumbers
= TRUE
;
1034 m_printEnablePrintToFile
= TRUE
;
1035 m_printEnableHelp
= FALSE
;
1036 m_printSetupDialog
= FALSE
;
1038 m_printData
= printData
;
1041 wxPrintDialogData::~wxPrintDialogData()
1044 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
1045 if ( pd
&& pd
->hDevMode
)
1046 GlobalFree(pd
->hDevMode
);
1053 void wxPrintDialogData::ConvertToNative()
1055 m_printData
.ConvertToNative();
1057 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
1062 memset( pd
, 0, sizeof(PRINTDLG
) );
1063 m_printDlgData
= (void*) pd
;
1065 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
1067 pd
->lStructSize
= 66;
1069 pd
->lStructSize
= sizeof(PRINTDLG
);
1071 pd
->hwndOwner
= (HWND
)NULL
;
1072 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
1073 pd
->hDevNames
= NULL
; // Ditto
1075 pd
->Flags
= PD_RETURNDEFAULT
;
1079 // Pass the devmode data to the PRINTDLG structure, since it'll
1080 // be needed when PrintDlg is called.
1083 GlobalFree(pd
->hDevMode
);
1086 // Pass the devnames data to the PRINTDLG structure, since it'll
1087 // be needed when PrintDlg is called.
1090 GlobalFree(pd
->hDevNames
);
1093 pd
->hDevMode
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeData();
1095 m_printData
.SetNativeData((void*) NULL
);
1097 // Shouldn't assert; we should be able to test Ok-ness at a higher level
1098 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1100 pd
->hDevNames
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames();
1102 m_printData
.SetNativeDataDevNames((void*) NULL
);
1104 pd
->hDC
= (HDC
) NULL
;
1105 pd
->nFromPage
= (WORD
)m_printFromPage
;
1106 pd
->nToPage
= (WORD
)m_printToPage
;
1107 pd
->nMinPage
= (WORD
)m_printMinPage
;
1108 pd
->nMaxPage
= (WORD
)m_printMaxPage
;
1109 pd
->nCopies
= (WORD
)m_printNoCopies
;
1111 pd
->Flags
= PD_RETURNDC
;
1114 pd
->lStructSize
= 66;
1116 pd
->lStructSize
= sizeof( PRINTDLG
);
1119 pd
->hwndOwner
=(HWND
)NULL
;
1120 // pd->hDevNames=(HANDLE)NULL;
1121 pd
->hInstance
=(HINSTANCE
)NULL
;
1122 pd
->lCustData
= (LPARAM
) NULL
;
1123 pd
->lpfnPrintHook
= NULL
;
1124 pd
->lpfnSetupHook
= NULL
;
1125 pd
->lpPrintTemplateName
= NULL
;
1126 pd
->lpSetupTemplateName
= NULL
;
1127 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
1128 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
1130 if ( m_printAllPages
)
1131 pd
->Flags
|= PD_ALLPAGES
;
1132 if ( m_printSelection
)
1133 pd
->Flags
|= PD_SELECTION
;
1134 if ( m_printCollate
)
1135 pd
->Flags
|= PD_COLLATE
;
1136 if ( m_printToFile
)
1137 pd
->Flags
|= PD_PRINTTOFILE
;
1138 if ( !m_printEnablePrintToFile
)
1139 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
1140 if ( !m_printEnableSelection
)
1141 pd
->Flags
|= PD_NOSELECTION
;
1142 if ( !m_printEnablePageNumbers
)
1143 pd
->Flags
|= PD_NOPAGENUMS
;
1144 if ( m_printEnableHelp
)
1145 pd
->Flags
|= PD_SHOWHELP
;
1146 if ( m_printSetupDialog
)
1147 pd
->Flags
|= PD_PRINTSETUP
;
1150 void wxPrintDialogData::ConvertFromNative()
1152 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
1156 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1159 if (m_printData
.GetNativeData())
1161 // Make sure we don't leak memory
1162 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeData());
1164 m_printData
.SetNativeData((void*)(long) pd
->hDevMode
);
1165 pd
->hDevMode
= NULL
;
1168 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1171 if (m_printData
.GetNativeDataDevNames())
1173 // Make sure we don't leak memory
1174 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames());
1176 m_printData
.SetNativeDataDevNames((void*)(long) pd
->hDevNames
);
1177 pd
->hDevNames
= NULL
;
1180 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
1181 // into wxWindows form.
1182 m_printData
.ConvertFromNative();
1184 m_printFromPage
= pd
->nFromPage
;
1185 m_printToPage
= pd
->nToPage
;
1186 m_printMinPage
= pd
->nMinPage
;
1187 m_printMaxPage
= pd
->nMaxPage
;
1188 m_printNoCopies
= pd
->nCopies
;
1190 m_printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
1191 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
1192 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
1193 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
1194 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
1195 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
1196 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
1197 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
1198 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
1200 /* port is obsolete in WIN32
1201 // Get the port name
1204 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
1206 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
1207 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
1208 GlobalUnlock(pd->hDevNames);
1210 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
1216 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
1218 if ( m_printDlgData
== NULL
)
1221 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
1223 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
1224 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1231 void wxPrintDialogData::ConvertToNative()
1233 m_printData
.ConvertToNative();
1235 PMSetPageRange( (PMPrintSettings
) m_printData
.m_macPrintSettings
, m_printMinPage
, m_printMaxPage
) ;
1236 PMSetCopies( (PMPrintSettings
) m_printData
.m_macPrintSettings
, m_printNoCopies
, false ) ;
1237 PMSetFirstPage( (PMPrintSettings
) m_printData
.m_macPrintSettings
, m_printFromPage
, false ) ;
1238 PMSetLastPage( (PMPrintSettings
) m_printData
.m_macPrintSettings
, m_printToPage
, false ) ;
1240 (**(THPrint
)m_printData
.m_macPrintSettings
).prJob
.iFstPage
= m_printFromPage
;
1241 (**(THPrint
)m_printData
.m_macPrintSettings
).prJob
.iLstPage
= m_printToPage
;
1245 void wxPrintDialogData::ConvertFromNative()
1247 m_printData
.ConvertFromNative();
1249 UInt32 minPage
, maxPage
;
1250 PMGetPageRange( (PMPrintSettings
) m_printData
.m_macPrintSettings
, &minPage
, &maxPage
) ;
1251 m_printMinPage
= minPage
;
1252 m_printMaxPage
= maxPage
;
1254 PMGetCopies( (PMPrintSettings
) m_printData
.m_macPrintSettings
, &copies
) ;
1255 m_printNoCopies
= copies
;
1257 PMGetFirstPage((PMPrintSettings
) m_printData
.m_macPrintSettings
, &from
) ;
1258 PMGetLastPage((PMPrintSettings
) m_printData
.m_macPrintSettings
, &to
) ;
1259 m_printFromPage
= from
;
1260 m_printToPage
= to
;
1262 m_printFromPage
= (**(THPrint
)m_printData
.m_macPrintSettings
).prJob
.iFstPage
;
1263 m_printToPage
= (**(THPrint
)m_printData
.m_macPrintSettings
).prJob
.iLstPage
;
1270 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
1272 m_printFromPage
= data
.m_printFromPage
;
1273 m_printToPage
= data
.m_printToPage
;
1274 m_printMinPage
= data
.m_printMinPage
;
1275 m_printMaxPage
= data
.m_printMaxPage
;
1276 m_printNoCopies
= data
.m_printNoCopies
;
1277 m_printAllPages
= data
.m_printAllPages
;
1278 m_printCollate
= data
.m_printCollate
;
1279 m_printToFile
= data
.m_printToFile
;
1280 m_printSelection
= data
.m_printSelection
;
1281 m_printEnableSelection
= data
.m_printEnableSelection
;
1282 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
1283 m_printEnableHelp
= data
.m_printEnableHelp
;
1284 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
1285 m_printSetupDialog
= data
.m_printSetupDialog
;
1287 m_printData
= data
.m_printData
;
1290 void wxPrintDialogData::operator=(const wxPrintData
& data
)
1295 // ----------------------------------------------------------------------------
1296 // wxPageSetupDialogData
1297 // ----------------------------------------------------------------------------
1299 wxPageSetupDialogData::wxPageSetupDialogData()
1301 #if defined(__WIN95__)
1302 m_pageSetupData
= NULL
;
1304 m_paperSize
= wxSize(0, 0);
1306 CalculatePaperSizeFromId();
1308 m_minMarginTopLeft
= wxPoint(0, 0);
1309 m_minMarginBottomRight
= wxPoint(0, 0);
1310 m_marginTopLeft
= wxPoint(0, 0);
1311 m_marginBottomRight
= wxPoint(0, 0);
1314 m_defaultMinMargins
= FALSE
;
1315 m_enableMargins
= TRUE
;
1316 m_enableOrientation
= TRUE
;
1317 m_enablePaper
= TRUE
;
1318 m_enablePrinter
= TRUE
;
1319 m_enableHelp
= FALSE
;
1320 m_getDefaultInfo
= FALSE
;
1323 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
1326 #if defined(__WIN95__)
1327 m_pageSetupData
= NULL
;
1329 (*this) = dialogData
;
1332 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
1334 #if defined(__WIN95__)
1335 m_pageSetupData
= NULL
;
1337 m_paperSize
= wxSize(0, 0);
1338 m_minMarginTopLeft
= wxPoint(0, 0);
1339 m_minMarginBottomRight
= wxPoint(0, 0);
1340 m_marginTopLeft
= wxPoint(0, 0);
1341 m_marginBottomRight
= wxPoint(0, 0);
1344 m_defaultMinMargins
= FALSE
;
1345 m_enableMargins
= TRUE
;
1346 m_enableOrientation
= TRUE
;
1347 m_enablePaper
= TRUE
;
1348 m_enablePrinter
= TRUE
;
1349 m_enableHelp
= FALSE
;
1350 m_getDefaultInfo
= FALSE
;
1352 m_printData
= printData
;
1354 // The wxPrintData paper size overrides these values, unless the size cannot
1356 CalculatePaperSizeFromId();
1359 wxPageSetupDialogData::~wxPageSetupDialogData()
1361 #if defined(__WIN95__) && defined(__WXMSW__)
1362 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
1363 if ( pd
&& pd
->hDevMode
)
1364 GlobalFree(pd
->hDevMode
);
1365 if ( pd
&& pd
->hDevNames
)
1366 GlobalFree(pd
->hDevNames
);
1372 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
1374 m_paperSize
= data
.m_paperSize
;
1375 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
1376 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
1377 m_marginTopLeft
= data
.m_marginTopLeft
;
1378 m_marginBottomRight
= data
.m_marginBottomRight
;
1379 m_defaultMinMargins
= data
.m_defaultMinMargins
;
1380 m_enableMargins
= data
.m_enableMargins
;
1381 m_enableOrientation
= data
.m_enableOrientation
;
1382 m_enablePaper
= data
.m_enablePaper
;
1383 m_enablePrinter
= data
.m_enablePrinter
;
1384 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
1385 m_enableHelp
= data
.m_enableHelp
;
1387 m_printData
= data
.m_printData
;
1392 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
1399 #if defined(__WIN95__)
1400 void wxPageSetupDialogData::ConvertToNative()
1402 m_printData
.ConvertToNative();
1404 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1406 if ( m_pageSetupData
== NULL
)
1408 pd
= new PAGESETUPDLG
;
1409 pd
->hDevMode
= NULL
;
1410 pd
->hDevNames
= NULL
;
1411 m_pageSetupData
= (void *)pd
;
1414 // Pass the devmode data (created in m_printData.ConvertToNative)
1415 // to the PRINTDLG structure, since it'll
1416 // be needed when PrintDlg is called.
1420 GlobalFree(pd
->hDevMode
);
1421 pd
->hDevMode
= NULL
;
1424 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1426 m_printData
.SetNativeData((void*) NULL
);
1428 // Shouldn't assert; we should be able to test Ok-ness at a higher level
1429 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1431 // Pass the devnames data (created in m_printData.ConvertToNative)
1432 // to the PRINTDLG structure, since it'll
1433 // be needed when PrintDlg is called.
1437 GlobalFree(pd
->hDevNames
);
1438 pd
->hDevNames
= NULL
;
1441 pd
->hDevNames
= (HGLOBAL
) m_printData
.GetNativeDataDevNames();
1443 m_printData
.SetNativeDataDevNames((void*) NULL
);
1445 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1447 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1449 if ( m_defaultMinMargins
)
1450 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1451 if ( !m_enableMargins
)
1452 pd
->Flags
|= PSD_DISABLEMARGINS
;
1453 if ( !m_enableOrientation
)
1454 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1455 if ( !m_enablePaper
)
1456 pd
->Flags
|= PSD_DISABLEPAPER
;
1457 if ( !m_enablePrinter
)
1458 pd
->Flags
|= PSD_DISABLEPRINTER
;
1459 if ( m_getDefaultInfo
)
1460 pd
->Flags
|= PSD_RETURNDEFAULT
;
1462 pd
->Flags
|= PSD_SHOWHELP
;
1464 // We want the units to be in hundredths of a millimetre
1465 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1467 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1468 pd
->hwndOwner
=(HWND
)NULL
;
1469 // pd->hDevNames=(HWND)NULL;
1470 pd
->hInstance
=(HINSTANCE
)NULL
;
1471 // PAGESETUPDLG is in hundreds of a mm
1472 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1473 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1475 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1476 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1477 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1478 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1480 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1481 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1482 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1483 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1486 pd
->lpfnPageSetupHook
= NULL
;
1487 pd
->lpfnPagePaintHook
= NULL
;
1488 pd
->hPageSetupTemplate
= NULL
;
1489 pd
->lpPageSetupTemplateName
= NULL
;
1494 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1495 memset(devMode, 0, sizeof(DEVMODE));
1496 devMode->dmSize = sizeof(DEVMODE);
1497 devMode->dmOrientation = m_orientation;
1498 devMode->dmFields = DM_ORIENTATION;
1499 GlobalUnlock(pd->hDevMode);
1504 void wxPageSetupDialogData::ConvertFromNative()
1506 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1510 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1513 if (m_printData
.GetNativeData())
1515 // Make sure we don't leak memory
1516 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1518 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1519 pd
->hDevMode
= NULL
;
1522 m_printData
.ConvertFromNative();
1524 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1527 if (m_printData
.GetNativeDataDevNames())
1529 // Make sure we don't leak memory
1530 GlobalFree((HGLOBAL
) m_printData
.GetNativeDataDevNames());
1532 m_printData
.SetNativeDataDevNames((void*) pd
->hDevNames
);
1533 pd
->hDevNames
= NULL
;
1536 m_printData
.ConvertFromNative();
1538 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1540 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1541 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1542 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1543 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1544 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1545 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1546 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1548 // PAGESETUPDLG is in hundreds of a mm
1549 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1550 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1552 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1553 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1554 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1555 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1557 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100;
1558 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100;
1559 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100;
1560 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100;
1563 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1565 if ( m_pageSetupData
== NULL
)
1568 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1570 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1571 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1577 void wxPageSetupDialogData::ConvertToNative()
1579 m_printData
.ConvertToNative();
1580 // should we setup the page rect here ?
1581 // since MacOS sometimes has two same paper rects with different
1582 // page rects we could make it roundtrip safe perhaps
1588 void wxPageSetupDialogData::ConvertFromNative()
1590 m_printData
.ConvertFromNative ();
1591 m_paperSize
= m_printData
.GetPaperSize() ;
1592 CalculateIdFromPaperSize();
1595 OSStatus err
= PMGetUnadjustedPaperRect((PMPageFormat
) m_printData
.m_macPageFormat
, &rPaper
);
1599 err
= PMGetUnadjustedPageRect((PMPageFormat
) m_printData
.m_macPageFormat
, &rPage
) ;
1602 m_minMarginTopLeft
.x
= (int)(((double) rPage
.left
- rPaper
.left
) * pt2mm
);
1603 m_minMarginTopLeft
.y
= (int)(((double) rPage
.top
- rPaper
.top
) * pt2mm
);
1604 m_minMarginBottomRight
.x
= ((double) rPaper
.right
- rPage
.right
) * pt2mm
;
1605 m_minMarginBottomRight
.y
= ((double) rPaper
.bottom
- rPage
.bottom
) * pt2mm
;
1609 m_minMarginTopLeft
.x
= ((double) (**(THPrint
)m_macPrintSettings
).prInfo
.rPage
.left
)-(**(THPrint
)m_macPrintSettings
).rPaper
.left
) * pt2mm
;
1610 m_minMarginTopLeft
.y
= ((double) (**(THPrint
)m_macPrintSettings
).prInfo
.rPage
.top
)-(**(THPrint
)m_macPrintSettings
).rPaper
.top
) * pt2mm
;
1611 m_minMarginBottomRight
.x
= ((double) (**(THPrint
)m_macPrintSettings
).rPaper
.right
- (**(THPrint
)m_macPrintSettings
).prInfo
.rPage
.right
) * pt2mm
;
1612 m_minMarginBottomRight
.y
= ((double)(**(THPrint
)m_macPrintSettings
).rPaper
.bottom
- (**(THPrint
)m_macPrintSettings
).prInfo
.rPage
.bottom
) * pt2mm
;
1614 // adjust minimal values
1616 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
1617 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
1619 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
1620 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
1622 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
1623 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
1625 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
1626 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
1631 // If a corresponding paper type is found in the paper database, will set the m_printData
1632 // paper size id member as well.
1633 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1637 CalculateIdFromPaperSize();
1640 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1641 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1643 m_printData
.SetPaperId(id
);
1645 CalculatePaperSizeFromId();
1648 // Use paper size defined in this object to set the wxPrintData
1650 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1652 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1653 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1655 wxSize sz
= GetPaperSize();
1657 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1658 if (id
!= wxPAPER_NONE
)
1660 m_printData
.SetPaperId(id
);
1664 // Use paper id in wxPrintData to set this object's paper size
1665 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1667 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1668 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1670 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1672 // sz is in 10ths of a mm, while paper size is in mm
1673 m_paperSize
.x
= sz
.x
/ 10;
1674 m_paperSize
.y
= sz
.y
/ 10;
1677 #endif // wxUSE_PRINTING_ARCHITECTURE