]>
git.saurik.com Git - wxWidgets.git/blob - src/common/cmndata.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "cmndata.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/string.h"
30 #include "wx/gdicmn.h"
31 #include "wx/cmndata.h"
36 #if !defined(__WIN32__)
41 #if defined(__WATCOMC__)
47 #if !USE_SHARED_LIBRARY
48 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
49 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupData
, wxObject
)
50 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
51 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
58 wxColourData::wxColourData()
61 for (i
= 0; i
< 16; i
++)
62 custColours
[i
].Set(255, 255, 255);
65 dataColour
.Set(0,0,0);
68 wxColourData::~wxColourData()
72 void wxColourData::SetCustomColour(int i
, wxColour
& colour
)
77 custColours
[i
] = colour
;
80 wxColour
wxColourData::GetCustomColour(int i
)
83 return wxColour(0,0,0);
85 return custColours
[i
];
88 void wxColourData::operator=(const wxColourData
& data
)
91 for (i
= 0; i
< 16; i
++)
92 custColours
[i
] = data
.custColours
[i
];
94 dataColour
= (wxColour
&)data
.dataColour
;
95 chooseFull
= data
.chooseFull
;
102 wxFontData::wxFontData()
104 // Intialize colour to black.
105 fontColour
.Set(0, 0, 0);
109 enableEffects
= TRUE
;
114 wxFontData::~wxFontData()
118 void wxFontData::operator=(const wxFontData
& data
)
120 fontColour
= data
.fontColour
;
121 showHelp
= data
.showHelp
;
122 allowSymbols
= data
.allowSymbols
;
123 enableEffects
= data
.enableEffects
;
124 initialFont
= data
.initialFont
;
125 chosenFont
= data
.chosenFont
;
126 minSize
= data
.minSize
;
127 maxSize
= data
.maxSize
;
134 wxPrintData::wxPrintData()
139 printOrientation
= wxPORTRAIT
;
145 printAllPages
= FALSE
;
146 printCollate
= FALSE
;
148 printEnableSelection
= FALSE
;
149 printEnablePageNumbers
= TRUE
;
150 printEnablePrintToFile
= TRUE
;
151 printEnableHelp
= FALSE
;
152 printSetupDialog
= FALSE
;
155 wxPrintData::~wxPrintData()
158 PRINTDLG
*pd
= (PRINTDLG
*)printData
;
159 if ( pd
&& pd
->hDevMode
)
160 GlobalFree(pd
->hDevMode
);
167 void wxPrintData::ConvertToNative()
169 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
173 printData
= (void*) pd
;
175 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
176 // pd->lStructSize = sizeof(PRINTDLG);
177 pd
->lStructSize
= 66 ;
178 pd
->hwndOwner
= (HWND
)NULL
;
179 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
180 pd
->hDevNames
= NULL
; // Ditto
182 pd
->Flags
= PD_RETURNDEFAULT
;
185 // Fill out the DEVMODE structure
186 // so we can use it as input in the 'real' PrintDlg
190 GlobalFree(pd
->hDevMode
);
192 GlobalFree(pd
->hDevNames
);
194 pd
->hDevNames
= NULL
;
199 GlobalFree(pd
->hDevNames
);
200 pd
->hDevNames
= NULL
;
206 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
207 devMode
->dmOrientation
= printOrientation
;
208 devMode
->dmFields
= DM_ORIENTATION
;
209 GlobalUnlock(pd
->hDevMode
);
211 pd
->hDC
= (HDC
) NULL
;
212 pd
->nFromPage
= (UINT
)printFromPage
;
213 pd
->nToPage
= (UINT
)printToPage
;
214 pd
->nMinPage
= (UINT
)printMinPage
;
215 pd
->nMaxPage
= (UINT
)printMaxPage
;
216 pd
->nCopies
= (UINT
)printNoCopies
;
218 pd
->Flags
= PD_RETURNDC
;
219 // pd->lStructSize = sizeof( PRINTDLG );
220 pd
->lStructSize
= 66 ;
221 pd
->hwndOwner
=(HWND
)NULL
;
222 pd
->hDevNames
=(HANDLE
)NULL
;
223 pd
->hInstance
=(HINSTANCE
)NULL
;
224 pd
->lCustData
= (LPARAM
) NULL
;
225 pd
->lpfnPrintHook
= NULL
;
226 pd
->lpfnSetupHook
= NULL
;
227 pd
->lpPrintTemplateName
= NULL
;
228 pd
->lpSetupTemplateName
= NULL
;
229 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
230 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
233 pd
->Flags
|= PD_ALLPAGES
;
235 pd
->Flags
|= PD_COLLATE
;
237 pd
->Flags
|= PD_PRINTTOFILE
;
238 if ( !printEnablePrintToFile
)
239 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
240 if ( !printEnableSelection
)
241 pd
->Flags
|= PD_NOSELECTION
;
242 if ( !printEnablePageNumbers
)
243 pd
->Flags
|= PD_NOPAGENUMS
;
244 if ( printEnableHelp
)
245 pd
->Flags
|= PD_SHOWHELP
;
246 if ( printSetupDialog
)
247 pd
->Flags
|= PD_PRINTSETUP
;
250 void wxPrintData::ConvertFromNative()
252 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
258 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
259 printOrientation
= devMode
->dmOrientation
;
260 GlobalUnlock(pd
->hDevMode
);
262 printFromPage
= pd
->nFromPage
;
263 printToPage
= pd
->nToPage
;
264 printMinPage
= pd
->nMinPage
;
265 printMaxPage
= pd
->nMaxPage
;
266 printNoCopies
= pd
->nCopies
;
268 printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
269 printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
270 printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
271 printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
272 printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
273 printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
274 printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
275 printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
278 void wxPrintData::SetOwnerWindow(wxWindow
* win
)
280 if ( printData
== NULL
)
283 if ( printData
!= NULL
&& win
!= NULL
)
285 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
286 pd
->hwndOwner
=(HWND
) win
->GetHWND();
291 void wxPrintData::operator=(const wxPrintData
& data
)
293 printFromPage
= data
.printFromPage
;
294 printToPage
= data
.printToPage
;
295 printMinPage
= data
.printMinPage
;
296 printMaxPage
= data
.printMaxPage
;
297 printNoCopies
= data
.printNoCopies
;
298 printAllPages
= data
.printAllPages
;
299 printCollate
= data
.printCollate
;
300 printToFile
= data
.printToFile
;
301 printEnableSelection
= data
.printEnableSelection
;
302 printEnablePageNumbers
= data
.printEnablePageNumbers
;
303 printEnableHelp
= data
.printEnableHelp
;
304 printEnablePrintToFile
= data
.printEnablePrintToFile
;
305 printSetupDialog
= data
.printSetupDialog
;
306 printOrientation
= data
.printOrientation
;
313 wxPageSetupData::wxPageSetupData()
315 #if defined(__WIN95__)
316 m_pageSetupData
= NULL
;
318 m_paperSize
= wxPoint(0, 0);
319 m_minMarginTopLeft
= wxPoint(0, 0);
320 m_minMarginBottomRight
= wxPoint(0, 0);
321 m_marginTopLeft
= wxPoint(0, 0);
322 m_marginBottomRight
= wxPoint(0, 0);
323 m_orientation
= wxPORTRAIT
;
326 m_defaultMinMargins
= FALSE
;
327 m_enableMargins
= TRUE
;
328 m_enableOrientation
= TRUE
;
329 m_enablePaper
= TRUE
;
330 m_enablePrinter
= TRUE
;
331 m_enableHelp
= FALSE
;
332 m_getDefaultInfo
= FALSE
;
335 wxPageSetupData::~wxPageSetupData()
337 #if defined(__WIN95__) && defined(__WXMSW__)
338 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
339 if ( pd
&& pd
->hDevMode
)
340 GlobalFree(pd
->hDevMode
);
346 void wxPageSetupData::operator=(const wxPageSetupData
& data
)
348 m_paperSize
= data
.m_paperSize
;
349 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
350 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
351 m_marginTopLeft
= data
.m_marginTopLeft
;
352 m_marginBottomRight
= data
.m_marginBottomRight
;
353 m_orientation
= data
.m_orientation
;
355 m_defaultMinMargins
= data
.m_defaultMinMargins
;
356 m_enableMargins
= data
.m_enableMargins
;
357 m_enableOrientation
= data
.m_enableOrientation
;
358 m_enablePaper
= data
.m_enablePaper
;
359 m_enablePrinter
= data
.m_enablePrinter
;
360 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
361 m_enableHelp
= data
.m_enableHelp
;
364 #if defined(__WXMSW__) && defined(__WIN95__)
365 void wxPageSetupData::ConvertToNative()
367 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
368 if ( m_pageSetupData
== NULL
)
370 pd
= new PAGESETUPDLG
;
371 pd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(DEVMODE
));
372 m_pageSetupData
= (void *)pd
;
375 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
377 if ( m_defaultMinMargins
)
378 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
379 if ( !m_enableMargins
)
380 pd
->Flags
|= PSD_DISABLEMARGINS
;
381 if ( !m_enableOrientation
)
382 pd
->Flags
|= PSD_DISABLEORIENTATION
;
383 if ( !m_enablePaper
)
384 pd
->Flags
|= PSD_DISABLEPAPER
;
385 if ( !m_enablePrinter
)
386 pd
->Flags
|= PSD_DISABLEPRINTER
;
387 if ( m_getDefaultInfo
)
388 pd
->Flags
|= PSD_RETURNDEFAULT
;
390 pd
->Flags
|= PSD_SHOWHELP
;
392 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
393 pd
->hwndOwner
=(HWND
)NULL
;
394 pd
->hDevNames
=(HWND
)NULL
;
395 pd
->hInstance
=(HINSTANCE
)NULL
;
397 pd
->ptPaperSize
.x
= m_paperSize
.x
;
398 pd
->ptPaperSize
.y
= m_paperSize
.y
;
400 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
;
401 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
;
402 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
;
403 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
;
405 pd
->rtMargin
.left
= m_marginTopLeft
.x
;
406 pd
->rtMargin
.top
= m_marginTopLeft
.y
;
407 pd
->rtMargin
.right
= m_marginBottomRight
.x
;
408 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
;
411 pd
->lpfnPageSetupHook
= NULL
;
412 pd
->lpfnPagePaintHook
= NULL
;
413 pd
->hPageSetupTemplate
= NULL
;
414 pd
->lpPageSetupTemplateName
= NULL
;
418 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
419 memset(devMode
, 0, sizeof(DEVMODE
));
420 devMode
->dmSize
= sizeof(DEVMODE
);
421 devMode
->dmOrientation
= m_orientation
;
422 devMode
->dmFields
= DM_ORIENTATION
;
423 GlobalUnlock(pd
->hDevMode
);
427 void wxPageSetupData::ConvertFromNative()
429 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
433 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
435 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
436 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
437 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
438 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
439 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
440 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
441 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
443 m_paperSize
.x
= pd
->ptPaperSize
.x
;
444 m_paperSize
.y
= pd
->ptPaperSize
.y
;
446 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
;
447 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
;
448 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
;
449 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
;
451 m_marginTopLeft
.x
= pd
->rtMargin
.left
;
452 m_marginTopLeft
.y
= pd
->rtMargin
.top
;
453 m_marginBottomRight
.x
= pd
->rtMargin
.right
;
454 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
;
458 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
459 m_orientation
= devMode
->dmOrientation
;
460 GlobalUnlock(pd
->hDevMode
);
464 void wxPageSetupData::SetOwnerWindow(wxWindow
* win
)
466 if ( m_pageSetupData
== NULL
)
469 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
471 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
472 pd
->hwndOwner
=(HWND
) win
->GetHWND();