/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/printdlg.cpp
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/printdlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (9 years, 11 months ago) by william
File size: 35907 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/printdlg.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id: printdlg.cpp 46089 2007-05-17 10:54:31Z RR $
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 // Don't use the Windows print dialog if we're in wxUniv mode and using
28 // the PostScript architecture
29 #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXUNIVERSAL__) || !wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
30
31 #ifndef WX_PRECOMP
32 #include "wx/msw/wrapcdlg.h"
33 #include "wx/app.h"
34 #include "wx/dcprint.h"
35 #include "wx/cmndata.h"
36 #endif
37
38 #include "wx/printdlg.h"
39 #include "wx/msw/printdlg.h"
40 #include "wx/paper.h"
41 #include "wx/msgdlg.h"
42
43 #include <stdlib.h>
44
45 #ifndef __WIN32__
46 #include <print.h>
47 #endif
48
49 //----------------------------------------------------------------------------
50 // wxWindowsPrintNativeData
51 //----------------------------------------------------------------------------
52
53 #ifdef __WXDEBUG__
54 static wxString wxGetPrintDlgError()
55 {
56 DWORD err = CommDlgExtendedError();
57 wxString msg = wxT("Unknown");
58 switch (err)
59 {
60 case CDERR_FINDRESFAILURE: msg = wxT("CDERR_FINDRESFAILURE"); break;
61 case CDERR_INITIALIZATION: msg = wxT("CDERR_INITIALIZATION"); break;
62 case CDERR_LOADRESFAILURE: msg = wxT("CDERR_LOADRESFAILURE"); break;
63 case CDERR_LOADSTRFAILURE: msg = wxT("CDERR_LOADSTRFAILURE"); break;
64 case CDERR_LOCKRESFAILURE: msg = wxT("CDERR_LOCKRESFAILURE"); break;
65 case CDERR_MEMALLOCFAILURE: msg = wxT("CDERR_MEMALLOCFAILURE"); break;
66 case CDERR_MEMLOCKFAILURE: msg = wxT("CDERR_MEMLOCKFAILURE"); break;
67 case CDERR_NOHINSTANCE: msg = wxT("CDERR_NOHINSTANCE"); break;
68 case CDERR_NOHOOK: msg = wxT("CDERR_NOHOOK"); break;
69 case CDERR_NOTEMPLATE: msg = wxT("CDERR_NOTEMPLATE"); break;
70 case CDERR_STRUCTSIZE: msg = wxT("CDERR_STRUCTSIZE"); break;
71 case PDERR_RETDEFFAILURE: msg = wxT("PDERR_RETDEFFAILURE"); break;
72 case PDERR_PRINTERNOTFOUND: msg = wxT("PDERR_PRINTERNOTFOUND"); break;
73 case PDERR_PARSEFAILURE: msg = wxT("PDERR_PARSEFAILURE"); break;
74 case PDERR_NODEVICES: msg = wxT("PDERR_NODEVICES"); break;
75 case PDERR_NODEFAULTPRN: msg = wxT("PDERR_NODEFAULTPRN"); break;
76 case PDERR_LOADDRVFAILURE: msg = wxT("PDERR_LOADDRVFAILURE"); break;
77 case PDERR_INITFAILURE: msg = wxT("PDERR_INITFAILURE"); break;
78 case PDERR_GETDEVMODEFAIL: msg = wxT("PDERR_GETDEVMODEFAIL"); break;
79 case PDERR_DNDMMISMATCH: msg = wxT("PDERR_DNDMMISMATCH"); break;
80 case PDERR_DEFAULTDIFFERENT: msg = wxT("PDERR_DEFAULTDIFFERENT"); break;
81 case PDERR_CREATEICFAILURE: msg = wxT("PDERR_CREATEICFAILURE"); break;
82 default: break;
83 }
84 return msg;
85 }
86 #endif
87
88 static HGLOBAL wxCreateDevNames(const wxString& driverName, const wxString& printerName, const wxString& portName)
89 {
90 HGLOBAL hDev = NULL;
91 // if (!driverName.empty() && !printerName.empty() && !portName.empty())
92 if (driverName.empty() && printerName.empty() && portName.empty())
93 {
94 }
95 else
96 {
97 hDev = GlobalAlloc(GPTR, 4*sizeof(WORD)+
98 ( driverName.length() + 1 +
99 printerName.length() + 1 +
100 portName.length()+1 ) * sizeof(wxChar) );
101 LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(hDev);
102 lpDev->wDriverOffset = sizeof(WORD) * 4 / sizeof(wxChar);
103 wxStrcpy((wxChar*)lpDev + lpDev->wDriverOffset, driverName);
104
105 lpDev->wDeviceOffset = (WORD)( lpDev->wDriverOffset +
106 driverName.length() + 1 );
107 wxStrcpy((wxChar*)lpDev + lpDev->wDeviceOffset, printerName);
108
109 lpDev->wOutputOffset = (WORD)( lpDev->wDeviceOffset +
110 printerName.length() + 1 );
111 wxStrcpy((wxChar*)lpDev + lpDev->wOutputOffset, portName);
112
113 lpDev->wDefault = 0;
114
115 GlobalUnlock(hDev);
116 }
117
118 return hDev;
119 }
120
121 IMPLEMENT_CLASS(wxWindowsPrintNativeData, wxPrintNativeDataBase)
122
123 wxWindowsPrintNativeData::wxWindowsPrintNativeData()
124 {
125 m_devMode = (void*) NULL;
126 m_devNames = (void*) NULL;
127 m_customWindowsPaperId = 0;
128 }
129
130 wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
131 {
132 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
133 if ( hDevMode )
134 GlobalFree(hDevMode);
135 HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
136 if ( hDevNames )
137 GlobalFree(hDevNames);
138 }
139
140 bool wxWindowsPrintNativeData::IsOk() const
141 {
142 return (m_devMode != NULL) ;
143 }
144
145 bool wxWindowsPrintNativeData::TransferTo( wxPrintData &data )
146 {
147 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
148 HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
149
150 if (!hDevMode)
151 {
152 return false;
153 }
154 else
155 {
156 LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode);
157
158 //// Orientation
159 if (devMode->dmFields & DM_ORIENTATION)
160 data.SetOrientation( devMode->dmOrientation );
161
162 //// Collation
163 if (devMode->dmFields & DM_COLLATE)
164 {
165 if (devMode->dmCollate == DMCOLLATE_TRUE)
166 data.SetCollate( true );
167 else
168 data.SetCollate( false );
169 }
170
171 //// Number of copies
172 if (devMode->dmFields & DM_COPIES)
173 data.SetNoCopies( devMode->dmCopies );
174
175 //// Bin
176 if (devMode->dmFields & DM_DEFAULTSOURCE) {
177 switch (devMode->dmDefaultSource) {
178 case DMBIN_ONLYONE : data.SetBin(wxPRINTBIN_ONLYONE ); break;
179 case DMBIN_LOWER : data.SetBin(wxPRINTBIN_LOWER ); break;
180 case DMBIN_MIDDLE : data.SetBin(wxPRINTBIN_MIDDLE ); break;
181 case DMBIN_MANUAL : data.SetBin(wxPRINTBIN_MANUAL ); break;
182 case DMBIN_ENVELOPE : data.SetBin(wxPRINTBIN_ENVELOPE ); break;
183 case DMBIN_ENVMANUAL : data.SetBin(wxPRINTBIN_ENVMANUAL ); break;
184 case DMBIN_AUTO : data.SetBin(wxPRINTBIN_AUTO ); break;
185 case DMBIN_TRACTOR : data.SetBin(wxPRINTBIN_TRACTOR ); break;
186 case DMBIN_SMALLFMT : data.SetBin(wxPRINTBIN_SMALLFMT ); break;
187 case DMBIN_LARGEFMT : data.SetBin(wxPRINTBIN_LARGEFMT ); break;
188 case DMBIN_LARGECAPACITY : data.SetBin(wxPRINTBIN_LARGECAPACITY ); break;
189 case DMBIN_CASSETTE : data.SetBin(wxPRINTBIN_CASSETTE ); break;
190 case DMBIN_FORMSOURCE : data.SetBin(wxPRINTBIN_FORMSOURCE ); break;
191 default:
192 if (devMode->dmDefaultSource>=DMBIN_USER) {
193 data.SetBin((wxPrintBin)((devMode->dmDefaultSource)-DMBIN_USER+(int)wxPRINTBIN_USER));
194 } else {
195 data.SetBin(wxPRINTBIN_DEFAULT);
196 }
197 break;
198 }
199 } else {
200 data.SetBin(wxPRINTBIN_DEFAULT);
201 }
202 if (devMode->dmFields & DM_MEDIATYPE)
203 {
204 wxASSERT( (int)devMode->dmMediaType != wxPRINTMEDIA_DEFAULT );
205 data.SetMedia(devMode->dmMediaType);
206 }
207 //// Printer name
208 if (devMode->dmDeviceName[0] != 0)
209 // This syntax fixes a crash when using VS 7.1
210 data.SetPrinterName( wxString(devMode->dmDeviceName, CCHDEVICENAME) );
211
212 //// Colour
213 if (devMode->dmFields & DM_COLOR)
214 {
215 if (devMode->dmColor == DMCOLOR_COLOR)
216 data.SetColour( true );
217 else
218 data.SetColour( false );
219 }
220 else
221 data.SetColour( true );
222
223 //// Paper size
224 // We don't know size of user defined paper and some buggy drivers
225 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
226 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
227 // code wouldn't set m_paperSize correctly.
228
229 bool foundPaperSize = false;
230 if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER))
231 {
232 if (wxThePrintPaperDatabase)
233 {
234 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
235 if (paper)
236 {
237 data.SetPaperId( paper->GetId() );
238 data.SetPaperSize( wxSize(paper->GetWidth() / 10,paper->GetHeight() / 10) );
239 m_customWindowsPaperId = 0;
240 foundPaperSize = true;
241 }
242 }
243 else
244 {
245 // Shouldn't really get here
246 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
247 data.SetPaperId( wxPAPER_NONE );
248 data.SetPaperSize( wxSize(0,0) );
249 m_customWindowsPaperId = 0;
250
251 GlobalUnlock(hDevMode);
252 return false;
253 }
254 }
255
256 if (!foundPaperSize)
257 {
258 if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
259 {
260 // DEVMODE is in tenths of a millimeter
261 data.SetPaperSize( wxSize(devMode->dmPaperWidth / 10, devMode->dmPaperLength / 10) );
262 data.SetPaperId( wxPAPER_NONE );
263 m_customWindowsPaperId = devMode->dmPaperSize;
264 }
265 else
266 {
267 // Often will reach this for non-standard paper sizes (sizes which
268 // wouldn't be in wxWidget's paper database). Setting
269 // m_customWindowsPaperId to devMode->dmPaperSize should be enough
270 // to get this paper size working.
271 data.SetPaperSize( wxSize(0,0) );
272 data.SetPaperId( wxPAPER_NONE );
273 m_customWindowsPaperId = devMode->dmPaperSize;
274 }
275 }
276
277 //// Duplex
278
279 if (devMode->dmFields & DM_DUPLEX)
280 {
281 switch (devMode->dmDuplex)
282 {
283 case DMDUP_HORIZONTAL: data.SetDuplex( wxDUPLEX_HORIZONTAL ); break;
284 case DMDUP_VERTICAL: data.SetDuplex( wxDUPLEX_VERTICAL ); break;
285 default:
286 case DMDUP_SIMPLEX: data.SetDuplex( wxDUPLEX_SIMPLEX ); break;
287 }
288 }
289 else
290 data.SetDuplex( wxDUPLEX_SIMPLEX );
291
292 //// Quality
293
294 if (devMode->dmFields & DM_PRINTQUALITY)
295 {
296 switch (devMode->dmPrintQuality)
297 {
298 case DMRES_MEDIUM: data.SetQuality( wxPRINT_QUALITY_MEDIUM ); break;
299 case DMRES_LOW: data.SetQuality( wxPRINT_QUALITY_LOW ); break;
300 case DMRES_DRAFT: data.SetQuality( wxPRINT_QUALITY_DRAFT ); break;
301 case DMRES_HIGH: data.SetQuality( wxPRINT_QUALITY_HIGH ); break;
302 default:
303 {
304 // TODO: if the printer fills in the resolution in DPI, how
305 // will the application know if it's high, low, draft etc.??
306 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
307 data.SetQuality( devMode->dmPrintQuality );
308 break;
309
310 }
311 }
312 }
313 else
314 data.SetQuality( wxPRINT_QUALITY_HIGH );
315
316 if (devMode->dmDriverExtra > 0)
317 data.SetPrivData( (char *)devMode+devMode->dmSize, devMode->dmDriverExtra );
318 else
319 data.SetPrivData( NULL, 0 );
320
321 GlobalUnlock(hDevMode);
322 }
323
324 if (hDevNames)
325 {
326 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames);
327 if (lpDevNames)
328 {
329 // TODO: Unicode-ification
330
331 // Get the port name
332 // port is obsolete in WIN32
333 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
334
335 // Get the printer name
336 wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset;
337
338 // Not sure if we should check for this mismatch
339 // wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
340
341 if (!printerName.empty())
342 data.SetPrinterName( printerName );
343
344 GlobalUnlock(hDevNames);
345 }
346 }
347
348 return true;
349 }
350
351 bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
352 {
353 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
354 HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
355 if (!hDevMode)
356 {
357 // Use PRINTDLG as a way of creating a DEVMODE object
358 PRINTDLG pd;
359
360 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
361 #ifdef __GNUWIN32__
362 memset(&pd, 0, 66);
363 pd.lStructSize = 66;
364 #else
365 memset(&pd, 0, sizeof(PRINTDLG));
366 #ifdef __WXWINCE__
367 pd.cbStruct = sizeof(PRINTDLG);
368 #else
369 pd.lStructSize = sizeof(PRINTDLG);
370 #endif
371 #endif
372
373 pd.hwndOwner = (HWND)NULL;
374 pd.hDevMode = NULL; // Will be created by PrintDlg
375 pd.hDevNames = NULL; // Ditto
376 //pd.hInstance = (HINSTANCE) wxGetInstance();
377
378 pd.Flags = PD_RETURNDEFAULT;
379 pd.nCopies = 1;
380
381 // Fill out the DEVMODE structure
382 // so we can use it as input in the 'real' PrintDlg
383 if (!PrintDlg(&pd))
384 {
385 if ( pd.hDevMode )
386 GlobalFree(pd.hDevMode);
387 if ( pd.hDevNames )
388 GlobalFree(pd.hDevNames);
389 pd.hDevMode = NULL;
390 pd.hDevNames = NULL;
391
392 #if defined(__WXDEBUG__) && defined(__WIN32__)
393 wxString str(wxT("Printing error: "));
394 str += wxGetPrintDlgError();
395 wxLogDebug(str);
396 #endif
397 }
398 else
399 {
400 hDevMode = pd.hDevMode;
401 m_devMode = (void*)(long) hDevMode;
402 pd.hDevMode = NULL;
403
404 // We'll create a new DEVNAMEs structure below.
405 if ( pd.hDevNames )
406 GlobalFree(pd.hDevNames);
407 pd.hDevNames = NULL;
408
409 // hDevNames = pd->hDevNames;
410 // m_devNames = (void*)(long) hDevNames;
411 // pd->hDevnames = NULL;
412
413 }
414 }
415
416 if ( hDevMode )
417 {
418 LPDEVMODE devMode = (LPDEVMODE) GlobalLock(hDevMode);
419
420 //// Orientation
421 devMode->dmOrientation = (short)data.GetOrientation();
422
423 //// Collation
424 devMode->dmCollate = (data.GetCollate() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
425 devMode->dmFields |= DM_COLLATE;
426
427 //// Number of copies
428 devMode->dmCopies = (short)data.GetNoCopies();
429 devMode->dmFields |= DM_COPIES;
430
431 //// Printer name
432 wxString name = data.GetPrinterName();
433 if (!name.empty())
434 {
435 //int len = wxMin(31, m_printerName.Len());
436 wxStrncpy((wxChar*)devMode->dmDeviceName,name.c_str(),31);
437 devMode->dmDeviceName[31] = wxT('\0');
438 }
439
440 //// Colour
441 if (data.GetColour())
442 devMode->dmColor = DMCOLOR_COLOR;
443 else
444 devMode->dmColor = DMCOLOR_MONOCHROME;
445 devMode->dmFields |= DM_COLOR;
446
447 //// Paper size
448
449 // Paper id has priority over paper size. If id is specified, then size
450 // is ignored (as it can be filled in even for standard paper sizes)
451
452 wxPrintPaperType *paperType = NULL;
453
454 const wxPaperSize paperId = data.GetPaperId();
455 if ( paperId != wxPAPER_NONE && wxThePrintPaperDatabase )
456 {
457 paperType = wxThePrintPaperDatabase->FindPaperType(paperId);
458 }
459
460 if ( paperType )
461 {
462 devMode->dmPaperSize = (short)paperType->GetPlatformId();
463 devMode->dmFields |= DM_PAPERSIZE;
464 }
465 else // custom (or no) paper size
466 {
467 const wxSize paperSize = data.GetPaperSize();
468 if ( paperSize != wxDefaultSize )
469 {
470 // Fall back on specifying the paper size explicitly
471 if(m_customWindowsPaperId != 0)
472 devMode->dmPaperSize = m_customWindowsPaperId;
473 else
474 devMode->dmPaperSize = DMPAPER_USER;
475 devMode->dmPaperWidth = (short)(paperSize.x * 10);
476 devMode->dmPaperLength = (short)(paperSize.y * 10);
477 devMode->dmFields |= DM_PAPERWIDTH;
478 devMode->dmFields |= DM_PAPERLENGTH;
479 }
480 //else: neither paper type nor size specified, don't fill DEVMODE
481 // at all so that the system defaults are used
482 }
483
484 //// Duplex
485 short duplex;
486 switch (data.GetDuplex())
487 {
488 case wxDUPLEX_HORIZONTAL:
489 duplex = DMDUP_HORIZONTAL;
490 break;
491 case wxDUPLEX_VERTICAL:
492 duplex = DMDUP_VERTICAL;
493 break;
494 default:
495 // in fact case wxDUPLEX_SIMPLEX:
496 duplex = DMDUP_SIMPLEX;
497 break;
498 }
499 devMode->dmDuplex = duplex;
500 devMode->dmFields |= DM_DUPLEX;
501
502 //// Quality
503
504 short quality;
505 switch (data.GetQuality())
506 {
507 case wxPRINT_QUALITY_MEDIUM:
508 quality = DMRES_MEDIUM;
509 break;
510 case wxPRINT_QUALITY_LOW:
511 quality = DMRES_LOW;
512 break;
513 case wxPRINT_QUALITY_DRAFT:
514 quality = DMRES_DRAFT;
515 break;
516 case wxPRINT_QUALITY_HIGH:
517 quality = DMRES_HIGH;
518 break;
519 default:
520 quality = (short)data.GetQuality();
521 break;
522 }
523 devMode->dmPrintQuality = quality;
524 devMode->dmFields |= DM_PRINTQUALITY;
525
526 if (data.GetPrivDataLen() > 0)
527 {
528 memcpy( (char *)devMode+devMode->dmSize, data.GetPrivData(), data.GetPrivDataLen() );
529 devMode->dmDriverExtra = (WXWORD)data.GetPrivDataLen();
530 }
531
532 if (data.GetBin() != wxPRINTBIN_DEFAULT)
533 {
534 switch (data.GetBin())
535 {
536 case wxPRINTBIN_ONLYONE: devMode->dmDefaultSource = DMBIN_ONLYONE; break;
537 case wxPRINTBIN_LOWER: devMode->dmDefaultSource = DMBIN_LOWER; break;
538 case wxPRINTBIN_MIDDLE: devMode->dmDefaultSource = DMBIN_MIDDLE; break;
539 case wxPRINTBIN_MANUAL: devMode->dmDefaultSource = DMBIN_MANUAL; break;
540 case wxPRINTBIN_ENVELOPE: devMode->dmDefaultSource = DMBIN_ENVELOPE; break;
541 case wxPRINTBIN_ENVMANUAL: devMode->dmDefaultSource = DMBIN_ENVMANUAL; break;
542 case wxPRINTBIN_AUTO: devMode->dmDefaultSource = DMBIN_AUTO; break;
543 case wxPRINTBIN_TRACTOR: devMode->dmDefaultSource = DMBIN_TRACTOR; break;
544 case wxPRINTBIN_SMALLFMT: devMode->dmDefaultSource = DMBIN_SMALLFMT; break;
545 case wxPRINTBIN_LARGEFMT: devMode->dmDefaultSource = DMBIN_LARGEFMT; break;
546 case wxPRINTBIN_LARGECAPACITY: devMode->dmDefaultSource = DMBIN_LARGECAPACITY; break;
547 case wxPRINTBIN_CASSETTE: devMode->dmDefaultSource = DMBIN_CASSETTE; break;
548 case wxPRINTBIN_FORMSOURCE: devMode->dmDefaultSource = DMBIN_FORMSOURCE; break;
549
550 default:
551 devMode->dmDefaultSource = (short)(DMBIN_USER + data.GetBin() - wxPRINTBIN_USER); // 256 + data.GetBin() - 14 = 242 + data.GetBin()
552 break;
553 }
554
555 devMode->dmFields |= DM_DEFAULTSOURCE;
556 }
557 if (data.GetMedia() != wxPRINTMEDIA_DEFAULT)
558 {
559 devMode->dmMediaType = data.GetMedia();
560 devMode->dmFields |= DM_MEDIATYPE;
561 }
562 GlobalUnlock(hDevMode);
563 }
564
565 if ( hDevNames )
566 {
567 GlobalFree(hDevNames);
568 }
569
570 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
571 m_devNames = (void*) (long) wxCreateDevNames(wxEmptyString, data.GetPrinterName(), wxEmptyString);
572
573 return true;
574 }
575
576 // ---------------------------------------------------------------------------
577 // wxPrintDialog
578 // ---------------------------------------------------------------------------
579
580 IMPLEMENT_CLASS(wxWindowsPrintDialog, wxPrintDialogBase)
581
582 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow *p, wxPrintDialogData* data)
583 {
584 Create(p, data);
585 }
586
587 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow *p, wxPrintData* data)
588 {
589 wxPrintDialogData data2;
590 if ( data )
591 data2 = *data;
592
593 Create(p, &data2);
594 }
595
596 bool wxWindowsPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
597 {
598 m_dialogParent = p;
599 m_printerDC = NULL;
600 m_destroyDC = true;
601
602 // MSW handle
603 m_printDlg = NULL;
604
605 if ( data )
606 m_printDialogData = *data;
607
608 return true;
609 }
610
611 wxWindowsPrintDialog::~wxWindowsPrintDialog()
612 {
613 PRINTDLG *pd = (PRINTDLG *) m_printDlg;
614 if (pd && pd->hDevMode)
615 GlobalFree(pd->hDevMode);
616 if ( pd )
617 delete pd;
618
619 if (m_destroyDC && m_printerDC)
620 delete m_printerDC;
621 }
622
623 int wxWindowsPrintDialog::ShowModal()
624 {
625 ConvertToNative( m_printDialogData );
626
627 PRINTDLG *pd = (PRINTDLG*) m_printDlg;
628
629 if (m_dialogParent)
630 pd->hwndOwner = (HWND) m_dialogParent->GetHWND();
631 else if (wxTheApp->GetTopWindow())
632 pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
633 else
634 pd->hwndOwner = 0;
635
636 bool ret = (PrintDlg( pd ) != 0);
637
638 pd->hwndOwner = 0;
639
640 if ( ret && (pd->hDC) )
641 {
642 wxPrinterDC *pdc = new wxPrinterDC( (WXHDC) pd->hDC );
643 m_printerDC = pdc;
644 ConvertFromNative( m_printDialogData );
645 return wxID_OK;
646 }
647 else
648 {
649 return wxID_CANCEL;
650 }
651 }
652
653 wxDC *wxWindowsPrintDialog::GetPrintDC()
654 {
655 if (m_printerDC)
656 {
657 m_destroyDC = false;
658 return m_printerDC;
659 }
660 else
661 return (wxPrinterDC*) NULL;
662 }
663
664 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data )
665 {
666 wxWindowsPrintNativeData *native_data =
667 (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData();
668 data.GetPrintData().ConvertToNative();
669
670 PRINTDLG *pd = (PRINTDLG*) m_printDlg;
671
672 // Shouldn't have been defined anywhere
673 if (pd)
674 return false;
675
676 pd = new PRINTDLG;
677 memset( pd, 0, sizeof(PRINTDLG) );
678 m_printDlg = (void*) pd;
679
680 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
681 #ifdef __GNUWIN32__
682 pd->lStructSize = 66;
683 #else
684 pd->lStructSize = sizeof(PRINTDLG);
685 #endif
686 pd->hwndOwner = (HWND)NULL;
687 pd->hDevMode = NULL; // Will be created by PrintDlg
688 pd->hDevNames = NULL; // Ditto
689
690 pd->Flags = PD_RETURNDEFAULT;
691 pd->nCopies = 1;
692
693 // Pass the devmode data to the PRINTDLG structure, since it'll
694 // be needed when PrintDlg is called.
695 if (pd->hDevMode)
696 GlobalFree(pd->hDevMode);
697
698 // Pass the devnames data to the PRINTDLG structure, since it'll
699 // be needed when PrintDlg is called.
700 if (pd->hDevNames)
701 GlobalFree(pd->hDevNames);
702
703 pd->hDevMode = (HGLOBAL)(DWORD) native_data->GetDevMode();
704 native_data->SetDevMode( (void*) NULL);
705
706 // Shouldn't assert; we should be able to test Ok-ness at a higher level
707 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
708
709 pd->hDevNames = (HGLOBAL)(DWORD) native_data->GetDevNames();
710 native_data->SetDevNames( (void*) NULL);
711
712
713 pd->hDC = (HDC) NULL;
714 pd->nFromPage = (WORD)data.GetFromPage();
715 pd->nToPage = (WORD)data.GetToPage();
716 pd->nMinPage = (WORD)data.GetMinPage();
717 pd->nMaxPage = (WORD)data.GetMaxPage();
718 pd->nCopies = (WORD)data.GetNoCopies();
719
720 pd->Flags = PD_RETURNDC;
721
722 #ifdef __GNUWIN32__
723 pd->lStructSize = 66;
724 #else
725 pd->lStructSize = sizeof( PRINTDLG );
726 #endif
727
728 pd->hwndOwner=(HWND)NULL;
729 // pd->hDevNames=(HANDLE)NULL;
730 pd->hInstance=(HINSTANCE)NULL;
731 pd->lCustData = (LPARAM) NULL;
732 pd->lpfnPrintHook = NULL;
733 pd->lpfnSetupHook = NULL;
734 pd->lpPrintTemplateName = NULL;
735 pd->lpSetupTemplateName = NULL;
736 pd->hPrintTemplate = (HGLOBAL) NULL;
737 pd->hSetupTemplate = (HGLOBAL) NULL;
738
739 if ( data.GetAllPages() )
740 pd->Flags |= PD_ALLPAGES;
741 if ( data.GetSelection() )
742 pd->Flags |= PD_SELECTION;
743 if ( data.GetCollate() )
744 pd->Flags |= PD_COLLATE;
745 if ( data.GetPrintToFile() )
746 pd->Flags |= PD_PRINTTOFILE;
747 if ( !data.GetEnablePrintToFile() )
748 pd->Flags |= PD_DISABLEPRINTTOFILE;
749 if ( !data.GetEnableSelection() )
750 pd->Flags |= PD_NOSELECTION;
751 if ( !data.GetEnablePageNumbers() )
752 pd->Flags |= PD_NOPAGENUMS;
753 else if ( (!data.GetAllPages()) && (!data.GetSelection()) && (data.GetFromPage() != 0) && (data.GetToPage() != 0))
754 pd->Flags |= PD_PAGENUMS;
755 if ( data.GetEnableHelp() )
756 pd->Flags |= PD_SHOWHELP;
757 #if WXWIN_COMPATIBILITY_2_4
758 if ( data.GetSetupDialog() )
759 pd->Flags |= PD_PRINTSETUP;
760 #endif
761
762 return true;
763 }
764
765 bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData &data )
766 {
767 PRINTDLG *pd = (PRINTDLG*) m_printDlg;
768 if ( pd == NULL )
769 return false;
770
771 wxWindowsPrintNativeData *native_data =
772 (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData();
773
774 // Pass the devmode data back to the wxPrintData structure where it really belongs.
775 if (pd->hDevMode)
776 {
777 if (native_data->GetDevMode())
778 {
779 // Make sure we don't leak memory
780 GlobalFree( (HGLOBAL)(DWORD) native_data->GetDevMode() );
781 }
782 native_data->SetDevMode( (void*)(long) pd->hDevMode );
783 pd->hDevMode = NULL;
784 }
785
786 // Pass the devnames data back to the wxPrintData structure where it really belongs.
787 if (pd->hDevNames)
788 {
789 if (native_data->GetDevNames())
790 {
791 // Make sure we don't leak memory
792 GlobalFree((HGLOBAL)(DWORD) native_data->GetDevNames());
793 }
794 native_data->SetDevNames((void*)(long) pd->hDevNames);
795 pd->hDevNames = NULL;
796 }
797
798 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
799 // into wxWidgets form.
800 native_data->TransferTo( data.GetPrintData() );
801
802 data.SetFromPage( pd->nFromPage );
803 data.SetToPage( pd->nToPage );
804 data.SetMinPage( pd->nMinPage );
805 data.SetMaxPage( pd->nMaxPage );
806 data.SetNoCopies( pd->nCopies );
807
808 data.SetAllPages( (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION)) );
809 data.SetSelection( ((pd->Flags & PD_SELECTION) == PD_SELECTION) );
810 data.SetCollate( ((pd->Flags & PD_COLLATE) == PD_COLLATE) );
811 data.SetPrintToFile( ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE) );
812 data.EnablePrintToFile( ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE) );
813 data.EnableSelection( ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION) );
814 data.EnablePageNumbers( ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS) );
815 data.EnableHelp( ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP) );
816 #if WXWIN_COMPATIBILITY_2_4
817 data.SetSetupDialog( ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP) );
818 #endif
819
820 return true;
821 }
822
823 // ---------------------------------------------------------------------------
824 // wxWidnowsPageSetupDialog
825 // ---------------------------------------------------------------------------
826
827 IMPLEMENT_CLASS(wxWindowsPageSetupDialog, wxPageSetupDialogBase)
828
829 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog()
830 {
831 m_dialogParent = NULL;
832 m_pageDlg = NULL;
833 }
834
835 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow *p, wxPageSetupDialogData *data)
836 {
837 Create(p, data);
838 }
839
840 bool wxWindowsPageSetupDialog::Create(wxWindow *p, wxPageSetupDialogData *data)
841 {
842 m_dialogParent = p;
843 m_pageDlg = NULL;
844
845 if (data)
846 m_pageSetupData = (*data);
847
848 return true;
849 }
850
851 wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog()
852 {
853 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageDlg;
854 if ( pd && pd->hDevMode )
855 GlobalFree(pd->hDevMode);
856 if ( pd && pd->hDevNames )
857 GlobalFree(pd->hDevNames);
858 if ( pd )
859 delete pd;
860 }
861
862 int wxWindowsPageSetupDialog::ShowModal()
863 {
864 ConvertToNative( m_pageSetupData );
865
866 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageDlg;
867 if (m_dialogParent)
868 pd->hwndOwner = (HWND) m_dialogParent->GetHWND();
869 else if (wxTheApp->GetTopWindow())
870 pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
871 else
872 pd->hwndOwner = 0;
873
874 BOOL retVal = PageSetupDlg( pd ) ;
875 pd->hwndOwner = 0;
876
877 if (retVal)
878 {
879 ConvertFromNative( m_pageSetupData );
880
881 return wxID_OK;
882 }
883
884 return wxID_CANCEL;
885 }
886
887 bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData &data )
888 {
889 wxWindowsPrintNativeData *native_data =
890 (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData();
891 data.GetPrintData().ConvertToNative();
892
893 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageDlg;
894
895 // Shouldn't have been defined anywhere
896 if (pd)
897 return false;
898
899 pd = new PAGESETUPDLG;
900 pd->hDevMode = NULL;
901 pd->hDevNames = NULL;
902 m_pageDlg = (void *)pd;
903
904 // Pass the devmode data (created in m_printData.ConvertToNative)
905 // to the PRINTDLG structure, since it'll
906 // be needed when PrintDlg is called.
907
908 if (pd->hDevMode)
909 {
910 GlobalFree(pd->hDevMode);
911 pd->hDevMode = NULL;
912 }
913 pd->hDevMode = (HGLOBAL) native_data->GetDevMode();
914 native_data->SetDevMode( (void*) NULL );
915
916 // Shouldn't assert; we should be able to test Ok-ness at a higher level
917 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
918
919 // Pass the devnames data (created in m_printData.ConvertToNative)
920 // to the PRINTDLG structure, since it'll
921 // be needed when PrintDlg is called.
922
923 if (pd->hDevNames)
924 {
925 GlobalFree(pd->hDevNames);
926 pd->hDevNames = NULL;
927 }
928 pd->hDevNames = (HGLOBAL) native_data->GetDevNames();
929 native_data->SetDevNames((void*) NULL);
930
931 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
932
933 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
934
935 if ( data.GetDefaultMinMargins() )
936 pd->Flags |= PSD_DEFAULTMINMARGINS;
937 if ( !data.GetEnableMargins() )
938 pd->Flags |= PSD_DISABLEMARGINS;
939 if ( !data.GetEnableOrientation() )
940 pd->Flags |= PSD_DISABLEORIENTATION;
941 if ( !data.GetEnablePaper() )
942 pd->Flags |= PSD_DISABLEPAPER;
943 if ( !data.GetEnablePrinter() )
944 pd->Flags |= PSD_DISABLEPRINTER;
945 if ( data.GetDefaultInfo() )
946 pd->Flags |= PSD_RETURNDEFAULT;
947 if ( data.GetEnableHelp() )
948 pd->Flags |= PSD_SHOWHELP;
949
950 // We want the units to be in hundredths of a millimetre
951 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
952
953 pd->lStructSize = sizeof( PAGESETUPDLG );
954 pd->hwndOwner=(HWND)NULL;
955 // pd->hDevNames=(HWND)NULL;
956 pd->hInstance=(HINSTANCE)NULL;
957 // PAGESETUPDLG is in hundreds of a mm
958 pd->ptPaperSize.x = data.GetPaperSize().x * 100;
959 pd->ptPaperSize.y = data.GetPaperSize().y * 100;
960
961 pd->rtMinMargin.left = data.GetMinMarginTopLeft().x * 100;
962 pd->rtMinMargin.top = data.GetMinMarginTopLeft().y * 100;
963 pd->rtMinMargin.right = data.GetMinMarginBottomRight().x * 100;
964 pd->rtMinMargin.bottom = data.GetMinMarginBottomRight().y * 100;
965
966 pd->rtMargin.left = data.GetMarginTopLeft().x * 100;
967 pd->rtMargin.top = data.GetMarginTopLeft().y * 100;
968 pd->rtMargin.right = data.GetMarginBottomRight().x * 100;
969 pd->rtMargin.bottom = data.GetMarginBottomRight().y * 100;
970
971 pd->lCustData = 0;
972 pd->lpfnPageSetupHook = NULL;
973 pd->lpfnPagePaintHook = NULL;
974 pd->hPageSetupTemplate = NULL;
975 pd->lpPageSetupTemplateName = NULL;
976
977 /*
978 if ( pd->hDevMode )
979 {
980 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
981 memset(devMode, 0, sizeof(DEVMODE));
982 devMode->dmSize = sizeof(DEVMODE);
983 devMode->dmOrientation = m_orientation;
984 devMode->dmFields = DM_ORIENTATION;
985 GlobalUnlock(pd->hDevMode);
986 }
987 */
988 return true;
989 }
990
991 bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData &data )
992 {
993 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageDlg;
994 if ( !pd )
995 return false;
996
997 wxWindowsPrintNativeData *native_data =
998 (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData();
999
1000 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1001 if (pd->hDevMode)
1002 {
1003 if (native_data->GetDevMode())
1004 {
1005 // Make sure we don't leak memory
1006 GlobalFree((HGLOBAL) native_data->GetDevMode());
1007 }
1008 native_data->SetDevMode( (void*) pd->hDevMode );
1009 pd->hDevMode = NULL;
1010 }
1011
1012 // Isn't this superfluous? It's called again below.
1013 // data.GetPrintData().ConvertFromNative();
1014
1015 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1016 if (pd->hDevNames)
1017 {
1018 if (native_data->GetDevNames())
1019 {
1020 // Make sure we don't leak memory
1021 GlobalFree((HGLOBAL) native_data->GetDevNames());
1022 }
1023 native_data->SetDevNames((void*) pd->hDevNames);
1024 pd->hDevNames = NULL;
1025 }
1026
1027 data.GetPrintData().ConvertFromNative();
1028
1029 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
1030
1031 data.SetDefaultMinMargins( ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS) );
1032 data.EnableMargins( ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS) );
1033 data.EnableOrientation( ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION) );
1034 data.EnablePaper( ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER) );
1035 data.EnablePrinter( ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER) );
1036 data.SetDefaultInfo( ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT) );
1037 data.EnableHelp( ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP) );
1038
1039 // PAGESETUPDLG is in hundreds of a mm
1040 if (data.GetPrintData().GetOrientation() == wxLANDSCAPE)
1041 data.SetPaperSize( wxSize(pd->ptPaperSize.y / 100, pd->ptPaperSize.x / 100) );
1042 else
1043 data.SetPaperSize( wxSize(pd->ptPaperSize.x / 100, pd->ptPaperSize.y / 100) );
1044
1045 data.SetMinMarginTopLeft( wxPoint(pd->rtMinMargin.left / 100, pd->rtMinMargin.top / 100) );
1046 data.SetMinMarginBottomRight( wxPoint(pd->rtMinMargin.right / 100, pd->rtMinMargin.bottom / 100) );
1047
1048 data.SetMarginTopLeft( wxPoint(pd->rtMargin.left / 100, pd->rtMargin.top / 100) );
1049 data.SetMarginBottomRight( wxPoint(pd->rtMargin.right / 100, pd->rtMargin.bottom / 100) );
1050
1051 return true;
1052 }
1053
1054 #endif
1055 // wxUSE_PRINTING_ARCHITECTURE

  ViewVC Help
Powered by ViewVC 1.1.22