]>
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"
42 #if !USE_SHARED_LIBRARY
43 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
44 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupData
, wxObject
)
45 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
46 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
53 wxColourData::wxColourData(void)
56 for (i
= 0; i
< 16; i
++)
57 custColours
[i
].Set(255, 255, 255);
60 dataColour
.Set(0,0,0);
63 wxColourData::~wxColourData(void)
67 void wxColourData::SetCustomColour(int i
, wxColour
& colour
)
72 custColours
[i
] = colour
;
75 wxColour
wxColourData::GetCustomColour(int i
)
78 return wxColour(0,0,0);
80 return custColours
[i
];
83 void wxColourData::operator=(const wxColourData
& data
)
86 for (i
= 0; i
< 16; i
++)
87 custColours
[i
] = data
.custColours
[i
];
89 dataColour
= (wxColour
&)data
.dataColour
;
90 chooseFull
= data
.chooseFull
;
97 wxFontData::wxFontData(void)
99 // Intialize colour to black.
100 fontColour
.Set(0, 0, 0);
104 enableEffects
= TRUE
;
109 wxFontData::~wxFontData(void)
113 void wxFontData::operator=(const wxFontData
& data
)
115 fontColour
= data
.fontColour
;
116 showHelp
= data
.showHelp
;
117 allowSymbols
= data
.allowSymbols
;
118 enableEffects
= data
.enableEffects
;
119 initialFont
= data
.initialFont
;
120 chosenFont
= data
.chosenFont
;
121 minSize
= data
.minSize
;
122 maxSize
= data
.maxSize
;
129 wxPrintData::wxPrintData(void)
134 printOrientation
= wxPORTRAIT
;
140 printAllPages
= FALSE
;
141 printCollate
= FALSE
;
143 printEnableSelection
= FALSE
;
144 printEnablePageNumbers
= TRUE
;
145 printEnablePrintToFile
= TRUE
;
146 printEnableHelp
= FALSE
;
147 printSetupDialog
= FALSE
;
150 wxPrintData::~wxPrintData(void)
153 PRINTDLG
*pd
= (PRINTDLG
*)printData
;
154 if ( pd
&& pd
->hDevMode
)
155 GlobalFree(pd
->hDevMode
);
162 void wxPrintData::ConvertToNative(void)
164 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
168 printData
= (void*) pd
;
170 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
171 // pd->lStructSize = sizeof(PRINTDLG);
172 pd
->lStructSize
= 66 ;
173 pd
->hwndOwner
= (HWND
)NULL
;
174 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
175 pd
->hDevNames
= NULL
; // Ditto
177 // Why had I put this #ifdef in?? Seems fine to me.
179 pd
->Flags
= PD_RETURNDEFAULT
;
182 // Fill out the DEVMODE structure
183 // so we can use it as input in the 'real' PrintDlg
187 GlobalFree(pd
->hDevMode
);
189 GlobalFree(pd
->hDevNames
);
191 pd
->hDevNames
= NULL
;
196 GlobalFree(pd
->hDevNames
);
197 pd
->hDevNames
= NULL
;
204 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
205 devMode
->dmOrientation
= printOrientation
;
206 devMode
->dmFields
= DM_ORIENTATION
;
207 GlobalUnlock(pd
->hDevMode
);
209 pd
->hDC
= (HDC
) NULL
;
210 pd
->nFromPage
= (UINT
)printFromPage
;
211 pd
->nToPage
= (UINT
)printToPage
;
212 pd
->nMinPage
= (UINT
)printMinPage
;
213 pd
->nMaxPage
= (UINT
)printMaxPage
;
214 pd
->nCopies
= (UINT
)printNoCopies
;
216 pd
->Flags
= PD_RETURNDC
;
217 // pd->lStructSize = sizeof( PRINTDLG );
218 pd
->lStructSize
= 66 ;
219 pd
->hwndOwner
=(HWND
)NULL
;
220 pd
->hDevNames
=(HANDLE
)NULL
;
221 pd
->hInstance
=(HINSTANCE
)NULL
;
222 pd
->lCustData
= (LPARAM
) NULL
;
223 pd
->lpfnPrintHook
= NULL
;
224 pd
->lpfnSetupHook
= NULL
;
225 pd
->lpPrintTemplateName
= NULL
;
226 pd
->lpSetupTemplateName
= NULL
;
227 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
228 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
231 pd
->Flags
|= PD_ALLPAGES
;
233 pd
->Flags
|= PD_COLLATE
;
235 pd
->Flags
|= PD_PRINTTOFILE
;
236 if ( !printEnablePrintToFile
)
237 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
238 if ( !printEnableSelection
)
239 pd
->Flags
|= PD_NOSELECTION
;
240 if ( !printEnablePageNumbers
)
241 pd
->Flags
|= PD_NOPAGENUMS
;
242 if ( printEnableHelp
)
243 pd
->Flags
|= PD_SHOWHELP
;
244 if ( printSetupDialog
)
245 pd
->Flags
|= PD_PRINTSETUP
;
248 void wxPrintData::ConvertFromNative(void)
250 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
256 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
257 printOrientation
= devMode
->dmOrientation
;
258 GlobalUnlock(pd
->hDevMode
);
260 printFromPage
= pd
->nFromPage
;
261 printToPage
= pd
->nToPage
;
262 printMinPage
= pd
->nMinPage
;
263 printMaxPage
= pd
->nMaxPage
;
264 printNoCopies
= pd
->nCopies
;
266 printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
267 printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
268 printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
269 printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
270 printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
271 printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
272 printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
273 printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
276 void wxPrintData::SetOwnerWindow(wxWindow
* win
)
278 if ( printData
== NULL
)
281 if ( printData
!= NULL
&& win
!= NULL
)
283 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
284 pd
->hwndOwner
=(HWND
) win
->GetHWND();
289 void wxPrintData::operator=(const wxPrintData
& data
)
291 printFromPage
= data
.printFromPage
;
292 printToPage
= data
.printToPage
;
293 printMinPage
= data
.printMinPage
;
294 printMaxPage
= data
.printMaxPage
;
295 printNoCopies
= data
.printNoCopies
;
296 printAllPages
= data
.printAllPages
;
297 printCollate
= data
.printCollate
;
298 printToFile
= data
.printToFile
;
299 printEnableSelection
= data
.printEnableSelection
;
300 printEnablePageNumbers
= data
.printEnablePageNumbers
;
301 printEnableHelp
= data
.printEnableHelp
;
302 printEnablePrintToFile
= data
.printEnablePrintToFile
;
303 printSetupDialog
= data
.printSetupDialog
;
304 printOrientation
= data
.printOrientation
;
311 wxPageSetupData::wxPageSetupData(void)
313 #if defined(__WIN95__)
314 m_pageSetupData
= NULL
;
316 m_paperSize
= wxPoint(0, 0);
317 m_minMarginTopLeft
= wxPoint(0, 0);
318 m_minMarginBottomRight
= wxPoint(0, 0);
319 m_marginTopLeft
= wxPoint(0, 0);
320 m_marginBottomRight
= wxPoint(0, 0);
321 m_orientation
= wxPORTRAIT
;
324 m_defaultMinMargins
= FALSE
;
325 m_enableMargins
= TRUE
;
326 m_enableOrientation
= TRUE
;
327 m_enablePaper
= TRUE
;
328 m_enablePrinter
= TRUE
;
329 m_enableHelp
= FALSE
;
330 m_getDefaultInfo
= FALSE
;
333 wxPageSetupData::~wxPageSetupData(void)
335 #if defined(__WIN95__) && defined(__WXMSW__)
336 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
337 if ( pd
&& pd
->hDevMode
)
338 GlobalFree(pd
->hDevMode
);
344 void wxPageSetupData::operator=(const wxPageSetupData
& data
)
346 m_paperSize
= data
.m_paperSize
;
347 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
348 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
349 m_marginTopLeft
= data
.m_marginTopLeft
;
350 m_marginBottomRight
= data
.m_marginBottomRight
;
351 m_orientation
= data
.m_orientation
;
353 m_defaultMinMargins
= data
.m_defaultMinMargins
;
354 m_enableMargins
= data
.m_enableMargins
;
355 m_enableOrientation
= data
.m_enableOrientation
;
356 m_enablePaper
= data
.m_enablePaper
;
357 m_enablePrinter
= data
.m_enablePrinter
;
358 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
359 m_enableHelp
= data
.m_enableHelp
;
362 #if defined(__WXMSW__) && defined(__WIN95__)
363 void wxPageSetupData::ConvertToNative(void)
365 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
366 if ( m_pageSetupData
== NULL
)
368 pd
= new PAGESETUPDLG
;
369 pd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(DEVMODE
));
370 m_pageSetupData
= (void *)pd
;
373 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
375 if ( m_defaultMinMargins
)
376 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
377 if ( !m_enableMargins
)
378 pd
->Flags
|= PSD_DISABLEMARGINS
;
379 if ( !m_enableOrientation
)
380 pd
->Flags
|= PSD_DISABLEORIENTATION
;
381 if ( !m_enablePaper
)
382 pd
->Flags
|= PSD_DISABLEPAPER
;
383 if ( !m_enablePrinter
)
384 pd
->Flags
|= PSD_DISABLEPRINTER
;
385 if ( m_getDefaultInfo
)
386 pd
->Flags
|= PSD_RETURNDEFAULT
;
388 pd
->Flags
|= PSD_SHOWHELP
;
390 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
391 pd
->hwndOwner
=(HWND
)NULL
;
392 pd
->hDevNames
=(HWND
)NULL
;
393 pd
->hInstance
=(HINSTANCE
)NULL
;
395 pd
->ptPaperSize
.x
= m_paperSize
.x
;
396 pd
->ptPaperSize
.y
= m_paperSize
.y
;
398 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
;
399 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
;
400 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
;
401 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
;
403 pd
->rtMargin
.left
= m_marginTopLeft
.x
;
404 pd
->rtMargin
.top
= m_marginTopLeft
.y
;
405 pd
->rtMargin
.right
= m_marginBottomRight
.x
;
406 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
;
409 pd
->lpfnPageSetupHook
= NULL
;
410 pd
->lpfnPagePaintHook
= NULL
;
411 pd
->hPageSetupTemplate
= NULL
;
412 pd
->lpPageSetupTemplateName
= NULL
;
416 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
417 memset(devMode
, 0, sizeof(DEVMODE
));
418 devMode
->dmSize
= sizeof(DEVMODE
);
419 devMode
->dmOrientation
= m_orientation
;
420 devMode
->dmFields
= DM_ORIENTATION
;
421 GlobalUnlock(pd
->hDevMode
);
425 void wxPageSetupData::ConvertFromNative(void)
427 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
431 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
433 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
434 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
435 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
436 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
437 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
438 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
439 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
441 m_paperSize
.x
= pd
->ptPaperSize
.x
;
442 m_paperSize
.y
= pd
->ptPaperSize
.y
;
444 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
;
445 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
;
446 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
;
447 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
;
449 m_marginTopLeft
.x
= pd
->rtMargin
.left
;
450 m_marginTopLeft
.y
= pd
->rtMargin
.top
;
451 m_marginBottomRight
.x
= pd
->rtMargin
.right
;
452 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
;
456 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
457 m_orientation
= devMode
->dmOrientation
;
458 GlobalUnlock(pd
->hDevMode
);
462 void wxPageSetupData::SetOwnerWindow(wxWindow
* win
)
464 if ( m_pageSetupData
== NULL
)
467 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
469 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
470 pd
->hwndOwner
=(HWND
) win
->GetHWND();