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