]>
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__) || defined(__SC__)
48 #if !USE_SHARED_LIBRARY
49 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
50 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupData
, wxObject
)
51 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
52 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
59 wxColourData::wxColourData()
62 for (i
= 0; i
< 16; i
++)
63 custColours
[i
].Set(255, 255, 255);
66 dataColour
.Set(0,0,0);
69 wxColourData::~wxColourData()
73 void wxColourData::SetCustomColour(int i
, wxColour
& colour
)
78 custColours
[i
] = colour
;
81 wxColour
wxColourData::GetCustomColour(int i
)
84 return wxColour(0,0,0);
86 return custColours
[i
];
89 void wxColourData::operator=(const wxColourData
& data
)
92 for (i
= 0; i
< 16; i
++)
93 custColours
[i
] = data
.custColours
[i
];
95 dataColour
= (wxColour
&)data
.dataColour
;
96 chooseFull
= data
.chooseFull
;
103 wxFontData::wxFontData()
105 // Intialize colour to black.
106 fontColour
.Set(0, 0, 0);
110 enableEffects
= TRUE
;
115 wxFontData::~wxFontData()
119 void wxFontData::operator=(const wxFontData
& data
)
121 fontColour
= data
.fontColour
;
122 showHelp
= data
.showHelp
;
123 allowSymbols
= data
.allowSymbols
;
124 enableEffects
= data
.enableEffects
;
125 initialFont
= data
.initialFont
;
126 chosenFont
= data
.chosenFont
;
127 minSize
= data
.minSize
;
128 maxSize
= data
.maxSize
;
135 wxPrintData::wxPrintData()
140 printOrientation
= wxPORTRAIT
;
146 printAllPages
= FALSE
;
147 printCollate
= FALSE
;
149 printEnableSelection
= FALSE
;
150 printEnablePageNumbers
= TRUE
;
151 printEnablePrintToFile
= TRUE
;
152 printEnableHelp
= FALSE
;
153 printSetupDialog
= FALSE
;
156 wxPrintData::~wxPrintData()
159 PRINTDLG
*pd
= (PRINTDLG
*)printData
;
160 if ( pd
&& pd
->hDevMode
)
161 GlobalFree(pd
->hDevMode
);
168 void wxPrintData::ConvertToNative()
170 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
174 printData
= (void*) pd
;
176 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
177 // pd->lStructSize = sizeof(PRINTDLG);
178 pd
->lStructSize
= 66 ;
179 pd
->hwndOwner
= (HWND
)NULL
;
180 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
181 pd
->hDevNames
= NULL
; // Ditto
183 pd
->Flags
= PD_RETURNDEFAULT
;
186 // Fill out the DEVMODE structure
187 // so we can use it as input in the 'real' PrintDlg
191 GlobalFree(pd
->hDevMode
);
193 GlobalFree(pd
->hDevNames
);
195 pd
->hDevNames
= NULL
;
200 GlobalFree(pd
->hDevNames
);
201 pd
->hDevNames
= NULL
;
207 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
208 devMode
->dmOrientation
= printOrientation
;
209 devMode
->dmFields
= DM_ORIENTATION
;
210 GlobalUnlock(pd
->hDevMode
);
212 pd
->hDC
= (HDC
) NULL
;
213 pd
->nFromPage
= (UINT
)printFromPage
;
214 pd
->nToPage
= (UINT
)printToPage
;
215 pd
->nMinPage
= (UINT
)printMinPage
;
216 pd
->nMaxPage
= (UINT
)printMaxPage
;
217 pd
->nCopies
= (UINT
)printNoCopies
;
219 pd
->Flags
= PD_RETURNDC
;
220 // pd->lStructSize = sizeof( PRINTDLG );
221 pd
->lStructSize
= 66 ;
222 pd
->hwndOwner
=(HWND
)NULL
;
223 pd
->hDevNames
=(HANDLE
)NULL
;
224 pd
->hInstance
=(HINSTANCE
)NULL
;
225 pd
->lCustData
= (LPARAM
) NULL
;
226 pd
->lpfnPrintHook
= NULL
;
227 pd
->lpfnSetupHook
= NULL
;
228 pd
->lpPrintTemplateName
= NULL
;
229 pd
->lpSetupTemplateName
= NULL
;
230 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
231 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
234 pd
->Flags
|= PD_ALLPAGES
;
236 pd
->Flags
|= PD_COLLATE
;
238 pd
->Flags
|= PD_PRINTTOFILE
;
239 if ( !printEnablePrintToFile
)
240 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
241 if ( !printEnableSelection
)
242 pd
->Flags
|= PD_NOSELECTION
;
243 if ( !printEnablePageNumbers
)
244 pd
->Flags
|= PD_NOPAGENUMS
;
245 if ( printEnableHelp
)
246 pd
->Flags
|= PD_SHOWHELP
;
247 if ( printSetupDialog
)
248 pd
->Flags
|= PD_PRINTSETUP
;
251 void wxPrintData::ConvertFromNative()
253 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
259 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
260 printOrientation
= devMode
->dmOrientation
;
261 GlobalUnlock(pd
->hDevMode
);
263 printFromPage
= pd
->nFromPage
;
264 printToPage
= pd
->nToPage
;
265 printMinPage
= pd
->nMinPage
;
266 printMaxPage
= pd
->nMaxPage
;
267 printNoCopies
= pd
->nCopies
;
269 printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
270 printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
271 printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
272 printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
273 printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
274 printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
275 printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
276 printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
279 void wxPrintData::SetOwnerWindow(wxWindow
* win
)
281 if ( printData
== NULL
)
284 if ( printData
!= NULL
&& win
!= NULL
)
286 PRINTDLG
*pd
= (PRINTDLG
*) printData
;
287 pd
->hwndOwner
=(HWND
) win
->GetHWND();
292 void wxPrintData::operator=(const wxPrintData
& data
)
294 printFromPage
= data
.printFromPage
;
295 printToPage
= data
.printToPage
;
296 printMinPage
= data
.printMinPage
;
297 printMaxPage
= data
.printMaxPage
;
298 printNoCopies
= data
.printNoCopies
;
299 printAllPages
= data
.printAllPages
;
300 printCollate
= data
.printCollate
;
301 printToFile
= data
.printToFile
;
302 printEnableSelection
= data
.printEnableSelection
;
303 printEnablePageNumbers
= data
.printEnablePageNumbers
;
304 printEnableHelp
= data
.printEnableHelp
;
305 printEnablePrintToFile
= data
.printEnablePrintToFile
;
306 printSetupDialog
= data
.printSetupDialog
;
307 printOrientation
= data
.printOrientation
;
314 wxPageSetupData::wxPageSetupData()
316 #if defined(__WIN95__)
317 m_pageSetupData
= NULL
;
319 m_paperSize
= wxPoint(0, 0);
320 m_minMarginTopLeft
= wxPoint(0, 0);
321 m_minMarginBottomRight
= wxPoint(0, 0);
322 m_marginTopLeft
= wxPoint(0, 0);
323 m_marginBottomRight
= wxPoint(0, 0);
324 m_orientation
= wxPORTRAIT
;
327 m_defaultMinMargins
= FALSE
;
328 m_enableMargins
= TRUE
;
329 m_enableOrientation
= TRUE
;
330 m_enablePaper
= TRUE
;
331 m_enablePrinter
= TRUE
;
332 m_enableHelp
= FALSE
;
333 m_getDefaultInfo
= FALSE
;
336 wxPageSetupData::~wxPageSetupData()
338 #if defined(__WIN95__) && defined(__WXMSW__)
339 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
340 if ( pd
&& pd
->hDevMode
)
341 GlobalFree(pd
->hDevMode
);
347 void wxPageSetupData::operator=(const wxPageSetupData
& data
)
349 m_paperSize
= data
.m_paperSize
;
350 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
351 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
352 m_marginTopLeft
= data
.m_marginTopLeft
;
353 m_marginBottomRight
= data
.m_marginBottomRight
;
354 m_orientation
= data
.m_orientation
;
356 m_defaultMinMargins
= data
.m_defaultMinMargins
;
357 m_enableMargins
= data
.m_enableMargins
;
358 m_enableOrientation
= data
.m_enableOrientation
;
359 m_enablePaper
= data
.m_enablePaper
;
360 m_enablePrinter
= data
.m_enablePrinter
;
361 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
362 m_enableHelp
= data
.m_enableHelp
;
365 #if defined(__WXMSW__) && defined(__WIN95__)
366 void wxPageSetupData::ConvertToNative()
368 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
369 if ( m_pageSetupData
== NULL
)
371 pd
= new PAGESETUPDLG
;
372 pd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(DEVMODE
));
373 m_pageSetupData
= (void *)pd
;
376 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
378 if ( m_defaultMinMargins
)
379 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
380 if ( !m_enableMargins
)
381 pd
->Flags
|= PSD_DISABLEMARGINS
;
382 if ( !m_enableOrientation
)
383 pd
->Flags
|= PSD_DISABLEORIENTATION
;
384 if ( !m_enablePaper
)
385 pd
->Flags
|= PSD_DISABLEPAPER
;
386 if ( !m_enablePrinter
)
387 pd
->Flags
|= PSD_DISABLEPRINTER
;
388 if ( m_getDefaultInfo
)
389 pd
->Flags
|= PSD_RETURNDEFAULT
;
391 pd
->Flags
|= PSD_SHOWHELP
;
393 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
394 pd
->hwndOwner
=(HWND
)NULL
;
395 pd
->hDevNames
=(HWND
)NULL
;
396 pd
->hInstance
=(HINSTANCE
)NULL
;
398 pd
->ptPaperSize
.x
= m_paperSize
.x
;
399 pd
->ptPaperSize
.y
= m_paperSize
.y
;
401 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
;
402 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
;
403 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
;
404 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
;
406 pd
->rtMargin
.left
= m_marginTopLeft
.x
;
407 pd
->rtMargin
.top
= m_marginTopLeft
.y
;
408 pd
->rtMargin
.right
= m_marginBottomRight
.x
;
409 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
;
412 pd
->lpfnPageSetupHook
= NULL
;
413 pd
->lpfnPagePaintHook
= NULL
;
414 pd
->hPageSetupTemplate
= NULL
;
415 pd
->lpPageSetupTemplateName
= NULL
;
419 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
420 memset(devMode
, 0, sizeof(DEVMODE
));
421 devMode
->dmSize
= sizeof(DEVMODE
);
422 devMode
->dmOrientation
= m_orientation
;
423 devMode
->dmFields
= DM_ORIENTATION
;
424 GlobalUnlock(pd
->hDevMode
);
428 void wxPageSetupData::ConvertFromNative()
430 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
434 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
436 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
437 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
438 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
439 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
440 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
441 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
442 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
444 m_paperSize
.x
= pd
->ptPaperSize
.x
;
445 m_paperSize
.y
= pd
->ptPaperSize
.y
;
447 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
;
448 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
;
449 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
;
450 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
;
452 m_marginTopLeft
.x
= pd
->rtMargin
.left
;
453 m_marginTopLeft
.y
= pd
->rtMargin
.top
;
454 m_marginBottomRight
.x
= pd
->rtMargin
.right
;
455 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
;
459 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(pd
->hDevMode
);
460 m_orientation
= devMode
->dmOrientation
;
461 GlobalUnlock(pd
->hDevMode
);
465 void wxPageSetupData::SetOwnerWindow(wxWindow
* win
)
467 if ( m_pageSetupData
== NULL
)
470 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
472 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
473 pd
->hwndOwner
=(HWND
) win
->GetHWND();