]> git.saurik.com Git - wxWidgets.git/blob - src/msw/printdlg.cpp
wxMenuBarBase for MSW (untested)
[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 #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 #if !USE_SHARED_LIBRARY
54 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog)
55 IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog)
56 #endif
57
58 // ===========================================================================
59 // implementation
60 // ===========================================================================
61
62 // ---------------------------------------------------------------------------
63 // wxPrintDialog
64 // ---------------------------------------------------------------------------
65
66 wxPrintDialog::wxPrintDialog()
67 {
68 m_dialogParent = NULL;
69 m_printerDC = NULL;
70 m_destroyDC = TRUE;
71 }
72
73 wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data)
74 {
75 Create(p, data);
76 }
77
78 wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data)
79 {
80 wxPrintDialogData data2;
81 if ( data )
82 data2 = *data;
83
84 Create(p, &data2);
85 }
86
87 bool wxPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
88 {
89 m_dialogParent = p;
90 m_printerDC = NULL;
91 m_destroyDC = TRUE;
92
93 if ( data )
94 m_printDialogData = *data;
95
96 m_printDialogData.SetOwnerWindow(p);
97
98 return TRUE;
99 }
100
101 wxPrintDialog::~wxPrintDialog()
102 {
103 if (m_destroyDC && m_printerDC)
104 delete m_printerDC;
105 }
106
107 int wxPrintDialog::ShowModal()
108 {
109 m_printDialogData.ConvertToNative();
110
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 {
121 return wxID_CANCEL;
122 }
123 }
124
125 wxDC *wxPrintDialog::GetPrintDC()
126 {
127 if (m_printerDC)
128 {
129 m_destroyDC = FALSE;
130 return m_printerDC;
131 }
132 else
133 return (wxDC*) NULL;
134 }
135
136 // ---------------------------------------------------------------------------
137 // wxPageSetupDialog
138 // ---------------------------------------------------------------------------
139
140 wxPageSetupDialog::wxPageSetupDialog()
141 {
142 m_dialogParent = NULL;
143 }
144
145 wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data)
146 {
147 Create(p, data);
148 }
149
150 bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data)
151 {
152 m_dialogParent = p;
153
154 if (data)
155 m_pageSetupData = (*data);
156
157 #if defined(__WIN95__)
158 m_pageSetupData.SetOwnerWindow(p);
159 #endif
160 return TRUE;
161 }
162
163 wxPageSetupDialog::~wxPageSetupDialog()
164 {
165 }
166
167 int wxPageSetupDialog::ShowModal()
168 {
169 #ifdef __WIN95__
170 m_pageSetupData.ConvertToNative();
171 if (PageSetupDlg( (PAGESETUPDLG *)m_pageSetupData.GetNativeData() ))
172 {
173 m_pageSetupData.ConvertFromNative();
174 return wxID_OK;
175 }
176 else
177 return wxID_CANCEL;
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