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