]>
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"
29 #include "wx/gdicmn.h"
30 #include "wx/cmndata.h"
41 #if !USE_SHARED_LIBRARY
42 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
43 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupData
, wxObject
)
44 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
45 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
52 wxColourData::wxColourData(void)
55 for (i
= 0; i
< 16; i
++)
56 custColours
[i
].Set(255, 255, 255);
59 dataColour
.Set(0,0,0);
62 wxColourData::~wxColourData(void)
66 void wxColourData::SetCustomColour(int i
, wxColour
& colour
)
71 custColours
[i
] = colour
;
74 wxColour
wxColourData::GetCustomColour(int i
)
77 return wxColour(0,0,0);
79 return custColours
[i
];
82 void wxColourData::operator=(const wxColourData
& data
)
85 for (i
= 0; i
< 16; i
++)
86 custColours
[i
] = data
.custColours
[i
];
88 dataColour
= (wxColour
&)data
.dataColour
;
89 chooseFull
= data
.chooseFull
;
96 wxFontData::wxFontData(void)
98 // Intialize colour to black.
99 fontColour
.Set(0, 0, 0);
103 enableEffects
= TRUE
;
108 wxFontData::~wxFontData(void)
112 void wxFontData::operator=(const wxFontData
& data
)
114 fontColour
= data
.fontColour
;
115 showHelp
= data
.showHelp
;
116 allowSymbols
= data
.allowSymbols
;
117 enableEffects
= data
.enableEffects
;
118 initialFont
= data
.initialFont
;
119 chosenFont
= data
.chosenFont
;
120 minSize
= data
.minSize
;
121 maxSize
= data
.maxSize
;
128 wxPrintData::wxPrintData(void)
133 printOrientation
= wxPORTRAIT
;
139 printAllPages
= FALSE
;
140 printCollate
= FALSE
;
142 printEnableSelection
= FALSE
;
143 printEnablePageNumbers
= TRUE
;
144 printEnablePrintToFile
= TRUE
;
145 printEnableHelp
= FALSE
;
146 printSetupDialog
= FALSE
;
149 wxPrintData::~wxPrintData(void)
152 PRINTDLG
*pd
= (PRINTDLG
*)printData
;
153 if ( pd
&& pd
->hDevMode
)
154 GlobalFree(pd
->hDevMode
);
161 void wxPrintData::ConvertToNative(void)
163 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
167 printData
= (void*) pd
;
169 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
170 // pd->lStructSize = sizeof(PRINTDLG);
171 pd
->lStructSize
= 66 ;
172 pd
->hwndOwner
= (HWND
)NULL
;
173 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
174 pd
->hDevNames
= NULL
; // Ditto
176 // Why had I put this #ifdef in?? Seems fine to me.
178 pd
->Flags
= PD_RETURNDEFAULT
;
181 // Fill out the DEVMODE structure
182 // so we can use it as input in the 'real' PrintDlg
186 GlobalFree(pd
->hDevMode
);
188 GlobalFree(pd
->hDevNames
);
190 pd
->hDevNames
= NULL
;
195 GlobalFree(pd
->hDevNames
);
196 pd
->hDevNames
= NULL
;
203 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
204 devMode
->dmOrientation
= printOrientation
;
205 devMode
->dmFields
= DM_ORIENTATION
;
206 GlobalUnlock(pd
->hDevMode
);
208 pd
->hDC
= (HDC
) NULL
;
209 pd
->nFromPage
= (UINT
)printFromPage
;
210 pd
->nToPage
= (UINT
)printToPage
;
211 pd
->nMinPage
= (UINT
)printMinPage
;
212 pd
->nMaxPage
= (UINT
)printMaxPage
;
213 pd
->nCopies
= (UINT
)printNoCopies
;
215 pd
->Flags
= PD_RETURNDC
;
216 // pd->lStructSize = sizeof( PRINTDLG );
217 pd
->lStructSize
= 66 ;
218 pd
->hwndOwner
=(HWND
)NULL
;
219 pd
->hDevNames
=(HANDLE
)NULL
;
220 pd
->hInstance
=(HINSTANCE
)NULL
;
221 pd
->lCustData
= (LPARAM
) NULL
;
222 pd
->lpfnPrintHook
= NULL
;
223 pd
->lpfnSetupHook
= NULL
;
224 pd
->lpPrintTemplateName
= NULL
;
225 pd
->lpSetupTemplateName
= NULL
;
226 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
227 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
230 pd
->Flags
|= PD_ALLPAGES
;
232 pd
->Flags
|= PD_COLLATE
;
234 pd
->Flags
|= PD_PRINTTOFILE
;
235 if ( !printEnablePrintToFile
)
236 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
237 if ( !printEnableSelection
)
238 pd
->Flags
|= PD_NOSELECTION
;
239 if ( !printEnablePageNumbers
)
240 pd
->Flags
|= PD_NOPAGENUMS
;
241 if ( printEnableHelp
)
242 pd
->Flags
|= PD_SHOWHELP
;
243 if ( printSetupDialog
)
244 pd
->Flags
|= PD_PRINTSETUP
;
247 void wxPrintData::ConvertFromNative(void)
249 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
255 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
256 printOrientation
= devMode
->dmOrientation
;
257 GlobalUnlock(pd
->hDevMode
);
259 printFromPage
= pd
->nFromPage
;
260 printToPage
= pd
->nToPage
;
261 printMinPage
= pd
->nMinPage
;
262 printMaxPage
= pd
->nMaxPage
;
263 printNoCopies
= pd
->nCopies
;
265 printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
266 printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
267 printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
268 printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
269 printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
270 printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
271 printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
272 printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
275 void wxPrintData::SetOwnerWindow(wxWindow
* win
)
277 if ( printData
== NULL
)
280 if ( printData
!= NULL
&& win
!= NULL
)
282 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
283 pd
->hwndOwner
=(HWND
) win
->GetHWND();
288 void wxPrintData::operator=(const wxPrintData
& data
)
290 printFromPage
= data
.printFromPage
;
291 printToPage
= data
.printToPage
;
292 printMinPage
= data
.printMinPage
;
293 printMaxPage
= data
.printMaxPage
;
294 printNoCopies
= data
.printNoCopies
;
295 printAllPages
= data
.printAllPages
;
296 printCollate
= data
.printCollate
;
297 printToFile
= data
.printToFile
;
298 printEnableSelection
= data
.printEnableSelection
;
299 printEnablePageNumbers
= data
.printEnablePageNumbers
;
300 printEnableHelp
= data
.printEnableHelp
;
301 printEnablePrintToFile
= data
.printEnablePrintToFile
;
302 printSetupDialog
= data
.printSetupDialog
;
303 printOrientation
= data
.printOrientation
;
310 wxPageSetupData::wxPageSetupData(void)
312 #if defined(__WIN95__)
313 m_pageSetupData
= NULL
;
315 m_paperSize
= wxPoint(0, 0);
316 m_minMarginTopLeft
= wxPoint(0, 0);
317 m_minMarginBottomRight
= wxPoint(0, 0);
318 m_marginTopLeft
= wxPoint(0, 0);
319 m_marginBottomRight
= wxPoint(0, 0);
320 m_orientation
= wxPORTRAIT
;
323 m_defaultMinMargins
= FALSE
;
324 m_enableMargins
= TRUE
;
325 m_enableOrientation
= TRUE
;
326 m_enablePaper
= TRUE
;
327 m_enablePrinter
= TRUE
;
328 m_enableHelp
= FALSE
;
329 m_getDefaultInfo
= FALSE
;
332 wxPageSetupData::~wxPageSetupData(void)
334 #if defined(__WIN95__)
335 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
336 if ( pd
&& pd
->hDevMode
)
337 GlobalFree(pd
->hDevMode
);
343 void wxPageSetupData::operator=(const wxPageSetupData
& data
)
345 m_paperSize
= data
.m_paperSize
;
346 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
347 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
348 m_marginTopLeft
= data
.m_marginTopLeft
;
349 m_marginBottomRight
= data
.m_marginBottomRight
;
350 m_orientation
= data
.m_orientation
;
352 m_defaultMinMargins
= data
.m_defaultMinMargins
;
353 m_enableMargins
= data
.m_enableMargins
;
354 m_enableOrientation
= data
.m_enableOrientation
;
355 m_enablePaper
= data
.m_enablePaper
;
356 m_enablePrinter
= data
.m_enablePrinter
;
357 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
358 m_enableHelp
= data
.m_enableHelp
;
361 #if defined(__WIN95__)
362 void wxPageSetupData::ConvertToNative(void)
364 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
365 if ( m_pageSetupData
== NULL
)
367 pd
= new PAGESETUPDLG
;
368 pd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(DEVMODE
));
369 m_pageSetupData
= (void *)pd
;
372 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
374 if ( m_defaultMinMargins
)
375 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
376 if ( !m_enableMargins
)
377 pd
->Flags
|= PSD_DISABLEMARGINS
;
378 if ( !m_enableOrientation
)
379 pd
->Flags
|= PSD_DISABLEORIENTATION
;
380 if ( !m_enablePaper
)
381 pd
->Flags
|= PSD_DISABLEPAPER
;
382 if ( !m_enablePrinter
)
383 pd
->Flags
|= PSD_DISABLEPRINTER
;
384 if ( m_getDefaultInfo
)
385 pd
->Flags
|= PSD_RETURNDEFAULT
;
387 pd
->Flags
|= PSD_SHOWHELP
;
389 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
390 pd
->hwndOwner
=(HWND
)NULL
;
391 pd
->hDevNames
=(HWND
)NULL
;
392 pd
->hInstance
=(HINSTANCE
)NULL
;
394 pd
->ptPaperSize
.x
= m_paperSize
.x
;
395 pd
->ptPaperSize
.y
= m_paperSize
.y
;
397 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
;
398 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
;
399 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
;
400 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
;
402 pd
->rtMargin
.left
= m_marginTopLeft
.x
;
403 pd
->rtMargin
.top
= m_marginTopLeft
.y
;
404 pd
->rtMargin
.right
= m_marginBottomRight
.x
;
405 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
;
408 pd
->lpfnPageSetupHook
= NULL
;
409 pd
->lpfnPagePaintHook
= NULL
;
410 pd
->hPageSetupTemplate
= NULL
;
411 pd
->lpPageSetupTemplateName
= NULL
;
415 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
416 memset(devMode
, 0, sizeof(DEVMODE
));
417 devMode
->dmSize
= sizeof(DEVMODE
);
418 devMode
->dmOrientation
= m_orientation
;
419 devMode
->dmFields
= DM_ORIENTATION
;
420 GlobalUnlock(pd
->hDevMode
);
424 void wxPageSetupData::ConvertFromNative(void)
426 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
430 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
432 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
433 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
434 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
435 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
436 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
437 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
438 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
440 m_paperSize
.x
= pd
->ptPaperSize
.x
;
441 m_paperSize
.y
= pd
->ptPaperSize
.y
;
443 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
;
444 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
;
445 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
;
446 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
;
448 m_marginTopLeft
.x
= pd
->rtMargin
.left
;
449 m_marginTopLeft
.y
= pd
->rtMargin
.top
;
450 m_marginBottomRight
.x
= pd
->rtMargin
.right
;
451 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
;
455 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
456 m_orientation
= devMode
->dmOrientation
;
457 GlobalUnlock(pd
->hDevMode
);
461 void wxPageSetupData::SetOwnerWindow(wxWindow
* win
)
463 if ( m_pageSetupData
== NULL
)
466 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
468 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
469 pd
->hwndOwner
=(HWND
) win
->GetHWND();