]> git.saurik.com Git - wxWidgets.git/blame - src/msw/printdlg.cpp
added some missing mac headers
[wxWidgets.git] / src / msw / printdlg.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: printdlg.cpp
3// Purpose: wxPrintDialog, wxPageSetupDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
103aec29
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
103aec29 21 #pragma implementation "printdlg.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
2bda0e17
KB
25#include "wx/wxprec.h"
26
a3b46648 27#ifdef __BORLANDC__
103aec29 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
12bdd77c
JS
31// Don't use the Windows print dialog if we're in wxUniv mode and using
32// the PostScript architecture
33#if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXUNIVERSAL__) || !wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
f6bcfd97
BP
34
35#ifndef WX_PRECOMP
36 #include "wx/app.h"
37#endif
38
2bda0e17
KB
39#include "wx/printdlg.h"
40#include "wx/dcprint.h"
41
2bda0e17 42#include <stdlib.h>
42e69d6b
VZ
43
44#include "wx/msw/private.h"
45
2bda0e17
KB
46#include <commdlg.h>
47
48#ifndef __WIN32__
103aec29 49 #include <print.h>
2bda0e17
KB
50#endif
51
103aec29
VZ
52// ---------------------------------------------------------------------------
53// wxWin macros
54// ---------------------------------------------------------------------------
55
103aec29
VZ
56 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog)
57 IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog)
2bda0e17 58
103aec29
VZ
59// ===========================================================================
60// implementation
61// ===========================================================================
62
63// ---------------------------------------------------------------------------
64// wxPrintDialog
65// ---------------------------------------------------------------------------
66
67wxPrintDialog::wxPrintDialog()
2bda0e17 68{
7bcb11d3
JS
69 m_dialogParent = NULL;
70 m_printerDC = NULL;
078cf5cb 71 m_destroyDC = true;
2bda0e17
KB
72}
73
103aec29 74wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data)
2bda0e17 75{
7bcb11d3 76 Create(p, data);
2bda0e17
KB
77}
78
103aec29
VZ
79wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data)
80{
81 wxPrintDialogData data2;
82 if ( data )
83 data2 = *data;
84
85 Create(p, &data2);
86}
87
7bcb11d3 88bool wxPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
2bda0e17 89{
7bcb11d3
JS
90 m_dialogParent = p;
91 m_printerDC = NULL;
078cf5cb 92 m_destroyDC = true;
7bcb11d3
JS
93
94 if ( data )
95 m_printDialogData = *data;
103aec29 96
7bcb11d3 97 m_printDialogData.SetOwnerWindow(p);
2bda0e17 98
078cf5cb 99 return true;
2bda0e17
KB
100}
101
103aec29 102wxPrintDialog::~wxPrintDialog()
2bda0e17 103{
7bcb11d3
JS
104 if (m_destroyDC && m_printerDC)
105 delete m_printerDC;
2bda0e17
KB
106}
107
103aec29 108int wxPrintDialog::ShowModal()
2bda0e17 109{
7bcb11d3 110 m_printDialogData.ConvertToNative();
103aec29 111
f6bcfd97
BP
112 PRINTDLG* p = (PRINTDLG *)m_printDialogData.GetNativeData() ;
113 if (m_dialogParent)
114 p->hwndOwner = (HWND) m_dialogParent->GetHWND();
115 else if (wxTheApp->GetTopWindow())
116 p->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
117 else
118 p->hwndOwner = 0;
119
120 bool ret = (PrintDlg( p ) != 0);
121
122 p->hwndOwner = 0;
123
078cf5cb 124 if ( ret != false && ((PRINTDLG *)m_printDialogData.GetNativeData())->hDC)
7bcb11d3
JS
125 {
126 wxPrinterDC *pdc = new wxPrinterDC((WXHDC) ((PRINTDLG *)m_printDialogData.GetNativeData())->hDC);
127 m_printerDC = pdc;
128 m_printDialogData.ConvertFromNative();
129 return wxID_OK;
130 }
131 else
132 {
7bcb11d3
JS
133 return wxID_CANCEL;
134 }
2bda0e17
KB
135}
136
103aec29 137wxDC *wxPrintDialog::GetPrintDC()
2bda0e17 138{
7bcb11d3
JS
139 if (m_printerDC)
140 {
078cf5cb 141 m_destroyDC = false;
7bcb11d3
JS
142 return m_printerDC;
143 }
144 else
145 return (wxDC*) NULL;
2bda0e17
KB
146}
147
103aec29
VZ
148// ---------------------------------------------------------------------------
149// wxPageSetupDialog
150// ---------------------------------------------------------------------------
2bda0e17 151
103aec29 152wxPageSetupDialog::wxPageSetupDialog()
2bda0e17 153{
7bcb11d3 154 m_dialogParent = NULL;
2bda0e17
KB
155}
156
103aec29 157wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data)
2bda0e17 158{
7bcb11d3 159 Create(p, data);
2bda0e17
KB
160}
161
162bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data)
163{
7bcb11d3 164 m_dialogParent = p;
103aec29 165
7bcb11d3
JS
166 if (data)
167 m_pageSetupData = (*data);
103aec29 168
2bda0e17 169#if defined(__WIN95__)
7bcb11d3 170 m_pageSetupData.SetOwnerWindow(p);
2bda0e17 171#endif
078cf5cb 172 return true;
2bda0e17
KB
173}
174
103aec29 175wxPageSetupDialog::~wxPageSetupDialog()
2bda0e17
KB
176{
177}
178
103aec29 179int wxPageSetupDialog::ShowModal()
2bda0e17
KB
180{
181#ifdef __WIN95__
182 m_pageSetupData.ConvertToNative();
f6bcfd97
BP
183 PAGESETUPDLG *p = (PAGESETUPDLG *)m_pageSetupData.GetNativeData();
184 if (m_dialogParent)
185 p->hwndOwner = (HWND) m_dialogParent->GetHWND();
186 else if (wxTheApp->GetTopWindow())
187 p->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
188 else
189 p->hwndOwner = 0;
190 BOOL retVal = PageSetupDlg( p ) ;
191 p->hwndOwner = 0;
192 if (retVal)
2bda0e17 193 {
7bcb11d3
JS
194 m_pageSetupData.ConvertFromNative();
195 return wxID_OK;
2bda0e17
KB
196 }
197 else
7bcb11d3 198 return wxID_CANCEL;
2bda0e17
KB
199#else
200 wxGenericPageSetupDialog *genericPageSetupDialog = new wxGenericPageSetupDialog(GetParent(), & m_pageSetupData);
201 int ret = genericPageSetupDialog->ShowModal();
202 m_pageSetupData = genericPageSetupDialog->GetPageSetupData();
078cf5cb 203 genericPageSetupDialog->Close(true);
2bda0e17
KB
204 return ret;
205#endif
206}
207
f6bcfd97
BP
208#endif
209 // wxUSE_PRINTING_ARCHITECTURE