]> git.saurik.com Git - wxWidgets.git/blob - src/msw/printdlg.cpp
added missing -univ package control files.
[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 and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #ifdef __GNUG__
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 #if wxUSE_PRINTING_ARCHITECTURE
32
33 #ifndef WX_PRECOMP
34 #include "wx/app.h"
35 #endif
36
37 #include "wx/printdlg.h"
38 #include "wx/dcprint.h"
39
40 // Have to emulate page setup dialog for Win16
41 #if !defined(__WIN95__)
42 #include "wx/generic/prntdlgg.h"
43 #endif
44
45 #include <stdlib.h>
46
47 #include "wx/msw/private.h"
48
49 #include <commdlg.h>
50
51 #ifndef __WIN32__
52 #include <print.h>
53 #endif
54
55 // ---------------------------------------------------------------------------
56 // wxWin macros
57 // ---------------------------------------------------------------------------
58
59 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog)
60 IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog)
61
62 // ===========================================================================
63 // implementation
64 // ===========================================================================
65
66 // ---------------------------------------------------------------------------
67 // wxPrintDialog
68 // ---------------------------------------------------------------------------
69
70 wxPrintDialog::wxPrintDialog()
71 {
72 m_dialogParent = NULL;
73 m_printerDC = NULL;
74 m_destroyDC = TRUE;
75 }
76
77 wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data)
78 {
79 Create(p, data);
80 }
81
82 wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data)
83 {
84 wxPrintDialogData data2;
85 if ( data )
86 data2 = *data;
87
88 Create(p, &data2);
89 }
90
91 bool wxPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
92 {
93 m_dialogParent = p;
94 m_printerDC = NULL;
95 m_destroyDC = TRUE;
96
97 if ( data )
98 m_printDialogData = *data;
99
100 m_printDialogData.SetOwnerWindow(p);
101
102 return TRUE;
103 }
104
105 wxPrintDialog::~wxPrintDialog()
106 {
107 if (m_destroyDC && m_printerDC)
108 delete m_printerDC;
109 }
110
111 int wxPrintDialog::ShowModal()
112 {
113 m_printDialogData.ConvertToNative();
114
115 PRINTDLG* p = (PRINTDLG *)m_printDialogData.GetNativeData() ;
116 if (m_dialogParent)
117 p->hwndOwner = (HWND) m_dialogParent->GetHWND();
118 else if (wxTheApp->GetTopWindow())
119 p->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
120 else
121 p->hwndOwner = 0;
122
123 bool ret = (PrintDlg( p ) != 0);
124
125 p->hwndOwner = 0;
126
127 if ( ret != FALSE && ((PRINTDLG *)m_printDialogData.GetNativeData())->hDC)
128 {
129 wxPrinterDC *pdc = new wxPrinterDC((WXHDC) ((PRINTDLG *)m_printDialogData.GetNativeData())->hDC);
130 m_printerDC = pdc;
131 m_printDialogData.ConvertFromNative();
132 return wxID_OK;
133 }
134 else
135 {
136 return wxID_CANCEL;
137 }
138 }
139
140 wxDC *wxPrintDialog::GetPrintDC()
141 {
142 if (m_printerDC)
143 {
144 m_destroyDC = FALSE;
145 return m_printerDC;
146 }
147 else
148 return (wxDC*) NULL;
149 }
150
151 // ---------------------------------------------------------------------------
152 // wxPageSetupDialog
153 // ---------------------------------------------------------------------------
154
155 wxPageSetupDialog::wxPageSetupDialog()
156 {
157 m_dialogParent = NULL;
158 }
159
160 wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data)
161 {
162 Create(p, data);
163 }
164
165 bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data)
166 {
167 m_dialogParent = p;
168
169 if (data)
170 m_pageSetupData = (*data);
171
172 #if defined(__WIN95__)
173 m_pageSetupData.SetOwnerWindow(p);
174 #endif
175 return TRUE;
176 }
177
178 wxPageSetupDialog::~wxPageSetupDialog()
179 {
180 }
181
182 int wxPageSetupDialog::ShowModal()
183 {
184 #ifdef __WIN95__
185 m_pageSetupData.ConvertToNative();
186 PAGESETUPDLG *p = (PAGESETUPDLG *)m_pageSetupData.GetNativeData();
187 if (m_dialogParent)
188 p->hwndOwner = (HWND) m_dialogParent->GetHWND();
189 else if (wxTheApp->GetTopWindow())
190 p->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
191 else
192 p->hwndOwner = 0;
193 BOOL retVal = PageSetupDlg( p ) ;
194 p->hwndOwner = 0;
195 if (retVal)
196 {
197 m_pageSetupData.ConvertFromNative();
198 return wxID_OK;
199 }
200 else
201 return wxID_CANCEL;
202 #else
203 wxGenericPageSetupDialog *genericPageSetupDialog = new wxGenericPageSetupDialog(GetParent(), & m_pageSetupData);
204 int ret = genericPageSetupDialog->ShowModal();
205 m_pageSetupData = genericPageSetupDialog->GetPageSetupData();
206 genericPageSetupDialog->Close(TRUE);
207 return ret;
208 #endif
209 }
210
211 #endif
212 // wxUSE_PRINTING_ARCHITECTURE