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