Began work on print dialogs. Now wxPrintDialog
[wxWidgets.git] / src / msw / printdlg.cpp
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$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "printdlg.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
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)
34
35 #ifndef WX_PRECOMP
36 #include "wx/app.h"
37 #endif
38
39 #include "wx/cmndata.h"
40 #include "wx/printdlg.h"
41 #include "wx/dcprint.h"
42
43 #include <stdlib.h>
44
45 #include "wx/msw/private.h"
46
47 #include <commdlg.h>
48
49 #ifndef __WIN32__
50 #include <print.h>
51 #endif
52
53 // ---------------------------------------------------------------------------
54 // wxPrintDialog
55 // ---------------------------------------------------------------------------
56
57 IMPLEMENT_CLASS(wxWindowsPrintDialog, wxPrintDialogBase)
58
59 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow *p, wxPrintDialogData* data)
60 {
61 Create(p, data);
62 }
63
64 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow *p, wxPrintData* data)
65 {
66 wxPrintDialogData data2;
67 if ( data )
68 data2 = *data;
69
70 Create(p, &data2);
71 }
72
73 bool wxWindowsPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
74 {
75 m_dialogParent = p;
76 m_printerDC = NULL;
77 m_destroyDC = true;
78
79 if ( data )
80 m_printDialogData = *data;
81
82 m_printDialogData.SetOwnerWindow(p);
83
84 return true;
85 }
86
87 wxWindowsPrintDialog::~wxWindowsPrintDialog()
88 {
89 if (m_destroyDC && m_printerDC)
90 delete m_printerDC;
91 }
92
93 int wxWindowsPrintDialog::ShowModal()
94 {
95 m_printDialogData.ConvertToNative();
96
97 PRINTDLG* p = (PRINTDLG *)m_printDialogData.GetNativeData() ;
98 if (m_dialogParent)
99 p->hwndOwner = (HWND) m_dialogParent->GetHWND();
100 else if (wxTheApp->GetTopWindow())
101 p->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
102 else
103 p->hwndOwner = 0;
104
105 bool ret = (PrintDlg( p ) != 0);
106
107 p->hwndOwner = 0;
108
109 if ( ret != false && ((PRINTDLG *)m_printDialogData.GetNativeData())->hDC)
110 {
111 wxPrinterDC *pdc = new wxPrinterDC((WXHDC) ((PRINTDLG *)m_printDialogData.GetNativeData())->hDC);
112 m_printerDC = pdc;
113 m_printDialogData.ConvertFromNative();
114 return wxID_OK;
115 }
116 else
117 {
118 return wxID_CANCEL;
119 }
120 }
121
122 wxDC *wxWindowsPrintDialog::GetPrintDC()
123 {
124 if (m_printerDC)
125 {
126 m_destroyDC = false;
127 return m_printerDC;
128 }
129 else
130 return (wxDC*) NULL;
131 }
132
133 // ---------------------------------------------------------------------------
134 // wxPageSetupDialog
135 // ---------------------------------------------------------------------------
136
137 IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog)
138
139 wxPageSetupDialog::wxPageSetupDialog()
140 {
141 m_dialogParent = NULL;
142 }
143
144 wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data)
145 {
146 Create(p, data);
147 }
148
149 bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data)
150 {
151 m_dialogParent = p;
152
153 if (data)
154 m_pageSetupData = (*data);
155
156 #if defined(__WIN95__)
157 m_pageSetupData.SetOwnerWindow(p);
158 #endif
159 return true;
160 }
161
162 wxPageSetupDialog::~wxPageSetupDialog()
163 {
164 }
165
166 int wxPageSetupDialog::ShowModal()
167 {
168 #ifdef __WIN95__
169 m_pageSetupData.ConvertToNative();
170 PAGESETUPDLG *p = (PAGESETUPDLG *)m_pageSetupData.GetNativeData();
171 if (m_dialogParent)
172 p->hwndOwner = (HWND) m_dialogParent->GetHWND();
173 else if (wxTheApp->GetTopWindow())
174 p->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
175 else
176 p->hwndOwner = 0;
177 BOOL retVal = PageSetupDlg( p ) ;
178 p->hwndOwner = 0;
179 if (retVal)
180 {
181 m_pageSetupData.ConvertFromNative();
182 return wxID_OK;
183 }
184 else
185 return wxID_CANCEL;
186 #else
187 wxGenericPageSetupDialog *genericPageSetupDialog = new wxGenericPageSetupDialog(GetParent(), & m_pageSetupData);
188 int ret = genericPageSetupDialog->ShowModal();
189 m_pageSetupData = genericPageSetupDialog->GetPageSetupData();
190 genericPageSetupDialog->Close(true);
191 return ret;
192 #endif
193 }
194
195 #endif
196 // wxUSE_PRINTING_ARCHITECTURE