]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
fixed bug in GetMimeType under win
[wxWidgets.git] / src / common / cmndata.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: cmndata.cpp
3// Purpose: Common GDI data
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
8bbe427f 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "cmndata.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include <stdio.h>
34138703 25#include "wx/string.h"
c801d85f
KB
26#include "wx/utils.h"
27#include "wx/app.h"
28#endif
29
30#include "wx/gdicmn.h"
31#include "wx/cmndata.h"
32
2049ba38 33#ifdef __WXMSW__
c801d85f
KB
34#include <windows.h>
35
7be1f0d9 36#if !defined(__WIN32__)
c801d85f
KB
37#include <print.h>
38#include <commdlg.h>
39#endif
7be1f0d9 40
a3ef5bf5 41#if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__)
2432b92d 42#include <windowsx.h>
7be1f0d9
JS
43#include <commdlg.h>
44#endif
45
c801d85f
KB
46#endif
47
48#if !USE_SHARED_LIBRARY
49IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
50IMPLEMENT_DYNAMIC_CLASS(wxPageSetupData, wxObject)
51IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
52IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
53#endif
54
55/*
56 * wxColourData
57 */
58
8bbe427f 59wxColourData::wxColourData()
c801d85f
KB
60{
61 int i;
62 for (i = 0; i < 16; i++)
63 custColours[i].Set(255, 255, 255);
64
65 chooseFull = FALSE;
66 dataColour.Set(0,0,0);
8bbe427f 67}
c801d85f 68
8bbe427f 69wxColourData::~wxColourData()
c801d85f
KB
70{
71}
72
73void wxColourData::SetCustomColour(int i, wxColour& colour)
74{
75 if (i > 15 || i < 0)
76 return;
77
78 custColours[i] = colour;
79}
80
81wxColour wxColourData::GetCustomColour(int i)
82{
83 if (i > 15 || i < 0)
84 return wxColour(0,0,0);
85
86 return custColours[i];
87}
88
89void wxColourData::operator=(const wxColourData& data)
90{
91 int i;
92 for (i = 0; i < 16; i++)
93 custColours[i] = data.custColours[i];
94
95 dataColour = (wxColour&)data.dataColour;
96 chooseFull = data.chooseFull;
97}
98
99/*
100 * Font data
101 */
102
8bbe427f 103wxFontData::wxFontData()
c801d85f
KB
104{
105 // Intialize colour to black.
106 fontColour.Set(0, 0, 0);
107
108 showHelp = FALSE;
109 allowSymbols = TRUE;
110 enableEffects = TRUE;
111 minSize = 0;
112 maxSize = 0;
113}
114
8bbe427f 115wxFontData::~wxFontData()
c801d85f
KB
116{
117}
118
119void wxFontData::operator=(const wxFontData& data)
120{
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;
129}
130
131/*
132 * Print data
133 */
134
8bbe427f 135wxPrintData::wxPrintData()
c801d85f 136{
2049ba38 137#ifdef __WXMSW__
c801d85f
KB
138 printData = NULL;
139#endif
140 printOrientation = wxPORTRAIT;
141 printFromPage = 0;
142 printToPage = 0;
143 printMinPage = 0;
144 printMaxPage = 0;
145 printNoCopies = 1;
146 printAllPages = FALSE;
147 printCollate = FALSE;
148 printToFile = FALSE;
149 printEnableSelection = FALSE;
150 printEnablePageNumbers = TRUE;
151 printEnablePrintToFile = TRUE;
152 printEnableHelp = FALSE;
153 printSetupDialog = FALSE;
154}
155
8bbe427f 156wxPrintData::~wxPrintData()
c801d85f 157{
2049ba38 158#ifdef __WXMSW__
c801d85f
KB
159 PRINTDLG *pd = (PRINTDLG *)printData;
160 if ( pd && pd->hDevMode )
161 GlobalFree(pd->hDevMode);
162 if ( pd )
163 delete pd;
164#endif
165}
166
2049ba38 167#ifdef __WXMSW__
8bbe427f 168void wxPrintData::ConvertToNative()
c801d85f
KB
169{
170 PRINTDLG *pd = (PRINTDLG*) printData;
171 if ( pd == NULL )
172 {
173 pd = new PRINTDLG;
174 printData = (void*) pd;
175
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
182
c801d85f
KB
183 pd->Flags = PD_RETURNDEFAULT;
184 pd->nCopies = 1;
185
186 // Fill out the DEVMODE structure
187 // so we can use it as input in the 'real' PrintDlg
188 if (!PrintDlg(pd))
189 {
190 if ( pd->hDevMode )
191 GlobalFree(pd->hDevMode);
192 if ( pd->hDevNames )
193 GlobalFree(pd->hDevNames);
194 pd->hDevMode = NULL;
195 pd->hDevNames = NULL;
196 }
197 else
198 {
199 if ( pd->hDevNames )
200 GlobalFree(pd->hDevNames);
201 pd->hDevNames = NULL;
202 }
c801d85f
KB
203 }
204
205 if ( pd->hDevMode )
206 {
207 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
208 devMode->dmOrientation = printOrientation;
209 devMode->dmFields = DM_ORIENTATION;
210 GlobalUnlock(pd->hDevMode);
211 }
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;
218
219 pd->Flags = PD_RETURNDC ;
220// pd->lStructSize = sizeof( PRINTDLG );
221 pd->lStructSize = 66 ;
8b9518ee 222 pd->hwndOwner=(HWND)NULL;
c801d85f
KB
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;
232
233 if ( printAllPages )
234 pd->Flags |= PD_ALLPAGES;
235 if ( printCollate )
236 pd->Flags |= PD_COLLATE;
237 if ( printToFile )
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;
249}
250
8bbe427f 251void wxPrintData::ConvertFromNative()
c801d85f
KB
252{
253 PRINTDLG *pd = (PRINTDLG*) printData;
254 if ( pd == NULL )
255 return;
256
257 if ( pd->hDevMode )
258 {
259 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
260 printOrientation = devMode->dmOrientation;
261 GlobalUnlock(pd->hDevMode);
262 }
263 printFromPage = pd->nFromPage ;
264 printToPage = pd->nToPage ;
265 printMinPage = pd->nMinPage ;
266 printMaxPage = pd->nMaxPage ;
267 printNoCopies = pd->nCopies ;
268
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);
277}
278
279void wxPrintData::SetOwnerWindow(wxWindow* win)
280{
281 if ( printData == NULL )
282 ConvertToNative();
283
284 if ( printData != NULL && win != NULL)
285 {
286 PRINTDLG *pd = (PRINTDLG *) printData ;
287 pd->hwndOwner=(HWND) win->GetHWND();
288 }
289}
290#endif
291
292void wxPrintData::operator=(const wxPrintData& data)
293{
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;
308}
309
310/*
311 * wxPageSetupData
312 */
313
8bbe427f 314wxPageSetupData::wxPageSetupData()
c801d85f
KB
315{
316#if defined(__WIN95__)
317 m_pageSetupData = NULL;
318#endif
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;
325
326 // Flags
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;
334}
335
8bbe427f 336wxPageSetupData::~wxPageSetupData()
c801d85f 337{
34138703 338#if defined(__WIN95__) && defined(__WXMSW__)
c801d85f
KB
339 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
340 if ( pd && pd->hDevMode )
341 GlobalFree(pd->hDevMode);
342 if ( pd )
343 delete pd;
344#endif
345}
346
347void wxPageSetupData::operator=(const wxPageSetupData& data)
348{
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;
355
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;
363}
364
34138703 365#if defined(__WXMSW__) && defined(__WIN95__)
8bbe427f 366void wxPageSetupData::ConvertToNative()
c801d85f
KB
367{
368 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
369 if ( m_pageSetupData == NULL )
370 {
371 pd = new PAGESETUPDLG;
372 pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
373 m_pageSetupData = (void *)pd;
374 }
8bbe427f 375
c801d85f
KB
376 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
377
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;
390 if ( m_enableHelp )
391 pd->Flags |= PSD_SHOWHELP;
392
393 pd->lStructSize = sizeof( PAGESETUPDLG );
c4e7c2aa 394 pd->hwndOwner=(HWND)NULL;
c801d85f
KB
395 pd->hDevNames=(HWND)NULL;
396 pd->hInstance=(HINSTANCE)NULL;
397
398 pd->ptPaperSize.x = m_paperSize.x;
399 pd->ptPaperSize.y = m_paperSize.y;
400
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;
405
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;
410
411 pd->lCustData = 0;
412 pd->lpfnPageSetupHook = NULL;
413 pd->lpfnPagePaintHook = NULL;
414 pd->hPageSetupTemplate = NULL;
415 pd->lpPageSetupTemplateName = NULL;
416
417 if ( pd->hDevMode )
418 {
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);
425 }
426}
427
8bbe427f 428void wxPageSetupData::ConvertFromNative()
c801d85f
KB
429{
430 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
431 if ( !pd )
432 return;
433
434 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
435
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);
443
444 m_paperSize.x = pd->ptPaperSize.x ;
445 m_paperSize.y = pd->ptPaperSize.y ;
446
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 ;
451
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 ;
456
457 if ( pd->hDevMode )
458 {
459 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
460 m_orientation = devMode->dmOrientation ;
461 GlobalUnlock(pd->hDevMode);
462 }
463}
464
465void wxPageSetupData::SetOwnerWindow(wxWindow* win)
466{
467 if ( m_pageSetupData == NULL )
468 ConvertToNative();
469
470 if ( m_pageSetupData != NULL && win != NULL)
471 {
472 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
473 pd->hwndOwner=(HWND) win->GetHWND();
474 }
475}
476#endif
477