]>
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()
56 for (i
= 0; i
< 16; i
++)
57 custColours
[i
].Set(255, 255, 255);
60 dataColour
.Set(0,0,0);
63 wxColourData::~wxColourData()
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()
99 // Intialize colour to black.
100 fontColour
.Set(0, 0, 0);
104 enableEffects
= TRUE
;
109 wxFontData::~wxFontData()
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()
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()
153 PRINTDLG
*pd
= (PRINTDLG
*)printData
;
154 if ( pd
&& pd
->hDevMode
)
155 GlobalFree(pd
->hDevMode
);
162 void wxPrintData::ConvertToNative()
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 pd
->Flags
= PD_RETURNDEFAULT
;
180 // Fill out the DEVMODE structure
181 // so we can use it as input in the 'real' PrintDlg
185 GlobalFree(pd
->hDevMode
);
187 GlobalFree(pd
->hDevNames
);
189 pd
->hDevNames
= NULL
;
194 GlobalFree(pd
->hDevNames
);
195 pd
->hDevNames
= NULL
;
201 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
202 devMode
->dmOrientation
= printOrientation
;
203 devMode
->dmFields
= DM_ORIENTATION
;
204 GlobalUnlock(pd
->hDevMode
);
206 pd
->hDC
= (HDC
) NULL
;
207 pd
->nFromPage
= (UINT
)printFromPage
;
208 pd
->nToPage
= (UINT
)printToPage
;
209 pd
->nMinPage
= (UINT
)printMinPage
;
210 pd
->nMaxPage
= (UINT
)printMaxPage
;
211 pd
->nCopies
= (UINT
)printNoCopies
;
213 pd
->Flags
= PD_RETURNDC
;
214 // pd->lStructSize = sizeof( PRINTDLG );
215 pd
->lStructSize
= 66 ;
216 pd
->hwndOwner
=(HWND
)NULL
;
217 pd
->hDevNames
=(HANDLE
)NULL
;
218 pd
->hInstance
=(HINSTANCE
)NULL
;
219 pd
->lCustData
= (LPARAM
) NULL
;
220 pd
->lpfnPrintHook
= NULL
;
221 pd
->lpfnSetupHook
= NULL
;
222 pd
->lpPrintTemplateName
= NULL
;
223 pd
->lpSetupTemplateName
= NULL
;
224 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
225 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
228 pd
->Flags
|= PD_ALLPAGES
;
230 pd
->Flags
|= PD_COLLATE
;
232 pd
->Flags
|= PD_PRINTTOFILE
;
233 if ( !printEnablePrintToFile
)
234 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
235 if ( !printEnableSelection
)
236 pd
->Flags
|= PD_NOSELECTION
;
237 if ( !printEnablePageNumbers
)
238 pd
->Flags
|= PD_NOPAGENUMS
;
239 if ( printEnableHelp
)
240 pd
->Flags
|= PD_SHOWHELP
;
241 if ( printSetupDialog
)
242 pd
->Flags
|= PD_PRINTSETUP
;
245 void wxPrintData::ConvertFromNative()
247 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
253 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
254 printOrientation
= devMode
->dmOrientation
;
255 GlobalUnlock(pd
->hDevMode
);
257 printFromPage
= pd
->nFromPage
;
258 printToPage
= pd
->nToPage
;
259 printMinPage
= pd
->nMinPage
;
260 printMaxPage
= pd
->nMaxPage
;
261 printNoCopies
= pd
->nCopies
;
263 printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
264 printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
265 printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
266 printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
267 printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
268 printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
269 printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
270 printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
273 void wxPrintData::SetOwnerWindow(wxWindow
* win
)
275 if ( printData
== NULL
)
278 if ( printData
!= NULL
&& win
!= NULL
)
280 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
281 pd
->hwndOwner
=(HWND
) win
->GetHWND();
286 void wxPrintData::operator=(const wxPrintData
& data
)
288 printFromPage
= data
.printFromPage
;
289 printToPage
= data
.printToPage
;
290 printMinPage
= data
.printMinPage
;
291 printMaxPage
= data
.printMaxPage
;
292 printNoCopies
= data
.printNoCopies
;
293 printAllPages
= data
.printAllPages
;
294 printCollate
= data
.printCollate
;
295 printToFile
= data
.printToFile
;
296 printEnableSelection
= data
.printEnableSelection
;
297 printEnablePageNumbers
= data
.printEnablePageNumbers
;
298 printEnableHelp
= data
.printEnableHelp
;
299 printEnablePrintToFile
= data
.printEnablePrintToFile
;
300 printSetupDialog
= data
.printSetupDialog
;
301 printOrientation
= data
.printOrientation
;
308 wxPageSetupData::wxPageSetupData()
310 #if defined(__WIN95__)
311 m_pageSetupData
= NULL
;
313 m_paperSize
= wxPoint(0, 0);
314 m_minMarginTopLeft
= wxPoint(0, 0);
315 m_minMarginBottomRight
= wxPoint(0, 0);
316 m_marginTopLeft
= wxPoint(0, 0);
317 m_marginBottomRight
= wxPoint(0, 0);
318 m_orientation
= wxPORTRAIT
;
321 m_defaultMinMargins
= FALSE
;
322 m_enableMargins
= TRUE
;
323 m_enableOrientation
= TRUE
;
324 m_enablePaper
= TRUE
;
325 m_enablePrinter
= TRUE
;
326 m_enableHelp
= FALSE
;
327 m_getDefaultInfo
= FALSE
;
330 wxPageSetupData::~wxPageSetupData()
332 #if defined(__WIN95__) && defined(__WXMSW__)
333 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
334 if ( pd
&& pd
->hDevMode
)
335 GlobalFree(pd
->hDevMode
);
341 void wxPageSetupData::operator=(const wxPageSetupData
& data
)
343 m_paperSize
= data
.m_paperSize
;
344 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
345 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
346 m_marginTopLeft
= data
.m_marginTopLeft
;
347 m_marginBottomRight
= data
.m_marginBottomRight
;
348 m_orientation
= data
.m_orientation
;
350 m_defaultMinMargins
= data
.m_defaultMinMargins
;
351 m_enableMargins
= data
.m_enableMargins
;
352 m_enableOrientation
= data
.m_enableOrientation
;
353 m_enablePaper
= data
.m_enablePaper
;
354 m_enablePrinter
= data
.m_enablePrinter
;
355 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
356 m_enableHelp
= data
.m_enableHelp
;
359 #if defined(__WXMSW__) && defined(__WIN95__)
360 void wxPageSetupData::ConvertToNative()
362 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
363 if ( m_pageSetupData
== NULL
)
365 pd
= new PAGESETUPDLG
;
366 pd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(DEVMODE
));
367 m_pageSetupData
= (void *)pd
;
370 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
372 if ( m_defaultMinMargins
)
373 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
374 if ( !m_enableMargins
)
375 pd
->Flags
|= PSD_DISABLEMARGINS
;
376 if ( !m_enableOrientation
)
377 pd
->Flags
|= PSD_DISABLEORIENTATION
;
378 if ( !m_enablePaper
)
379 pd
->Flags
|= PSD_DISABLEPAPER
;
380 if ( !m_enablePrinter
)
381 pd
->Flags
|= PSD_DISABLEPRINTER
;
382 if ( m_getDefaultInfo
)
383 pd
->Flags
|= PSD_RETURNDEFAULT
;
385 pd
->Flags
|= PSD_SHOWHELP
;
387 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
388 pd
->hwndOwner
=(HWND
)NULL
;
389 pd
->hDevNames
=(HWND
)NULL
;
390 pd
->hInstance
=(HINSTANCE
)NULL
;
392 pd
->ptPaperSize
.x
= m_paperSize
.x
;
393 pd
->ptPaperSize
.y
= m_paperSize
.y
;
395 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
;
396 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
;
397 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
;
398 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
;
400 pd
->rtMargin
.left
= m_marginTopLeft
.x
;
401 pd
->rtMargin
.top
= m_marginTopLeft
.y
;
402 pd
->rtMargin
.right
= m_marginBottomRight
.x
;
403 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
;
406 pd
->lpfnPageSetupHook
= NULL
;
407 pd
->lpfnPagePaintHook
= NULL
;
408 pd
->hPageSetupTemplate
= NULL
;
409 pd
->lpPageSetupTemplateName
= NULL
;
413 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
414 memset(devMode
, 0, sizeof(DEVMODE
));
415 devMode
->dmSize
= sizeof(DEVMODE
);
416 devMode
->dmOrientation
= m_orientation
;
417 devMode
->dmFields
= DM_ORIENTATION
;
418 GlobalUnlock(pd
->hDevMode
);
422 void wxPageSetupData::ConvertFromNative()
424 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
428 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
430 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
431 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
432 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
433 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
434 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
435 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
436 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
438 m_paperSize
.x
= pd
->ptPaperSize
.x
;
439 m_paperSize
.y
= pd
->ptPaperSize
.y
;
441 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
;
442 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
;
443 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
;
444 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
;
446 m_marginTopLeft
.x
= pd
->rtMargin
.left
;
447 m_marginTopLeft
.y
= pd
->rtMargin
.top
;
448 m_marginBottomRight
.x
= pd
->rtMargin
.right
;
449 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
;
453 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
454 m_orientation
= devMode
->dmOrientation
;
455 GlobalUnlock(pd
->hDevMode
);
459 void wxPageSetupData::SetOwnerWindow(wxWindow
* win
)
461 if ( m_pageSetupData
== NULL
)
464 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
466 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
467 pd
->hwndOwner
=(HWND
) win
->GetHWND();