]>
Commit | Line | Data |
---|---|---|
2646f485 | 1 | ///////////////////////////////////////////////////////////////////////////// |
8e3f3880 | 2 | // Name: src/mac/classic/printdlg.cpp |
2646f485 SC |
3 | // Purpose: wxPrintDialog, wxPageSetupDialog |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
8e3f3880 | 9 | // Licence: wxWindows licence |
2646f485 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8e3f3880 WS |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
246c5004 WS |
15 | #include "wx/printdlg.h" |
16 | ||
8e3f3880 WS |
17 | #ifndef WX_PRECOMP |
18 | #include "wx/object.h" | |
6d50343d | 19 | #include "wx/dcprint.h" |
246c5004 | 20 | #include "wx/msgdlg.h" |
8e3f3880 WS |
21 | #endif |
22 | ||
2646f485 SC |
23 | #include "wx/mac/private/print.h" |
24 | ||
25 | // Use generic page setup dialog: use your own native one if one exists. | |
26 | ||
2646f485 SC |
27 | IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog) |
28 | IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog) | |
2646f485 SC |
29 | |
30 | wxPrintDialog::wxPrintDialog() | |
31 | { | |
32 | m_dialogParent = NULL; | |
33 | m_printerDC = NULL; | |
8e3f3880 | 34 | m_destroyDC = true; |
2646f485 SC |
35 | } |
36 | ||
37 | wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data) | |
38 | { | |
39 | Create(p, data); | |
40 | } | |
41 | ||
42 | wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data) | |
43 | { | |
44 | wxPrintDialogData data2; | |
45 | if ( data ) | |
46 | data2 = *data; | |
8e3f3880 | 47 | |
2646f485 SC |
48 | Create(p, &data2); |
49 | } | |
50 | ||
51 | bool wxPrintDialog::Create(wxWindow *p, wxPrintDialogData* data) | |
52 | { | |
53 | m_dialogParent = p; | |
54 | m_printerDC = NULL; | |
8e3f3880 WS |
55 | m_destroyDC = true; |
56 | ||
2646f485 SC |
57 | if ( data ) |
58 | m_printDialogData = *data; | |
8e3f3880 WS |
59 | |
60 | return true; | |
2646f485 SC |
61 | } |
62 | ||
63 | wxPrintDialog::~wxPrintDialog() | |
64 | { | |
65 | if (m_destroyDC && m_printerDC) { | |
66 | delete m_printerDC; | |
67 | m_printerDC = NULL; | |
68 | } | |
69 | } | |
70 | ||
71 | int wxPrintDialog::ShowModal() | |
72 | { | |
73 | m_printDialogData.ConvertToNative() ; | |
74 | int result = m_printDialogData.GetPrintData().m_nativePrintData->ShowPrintDialog() ; | |
75 | if ( result == wxID_OK ) | |
76 | m_printDialogData.ConvertFromNative() ; | |
8e3f3880 | 77 | |
2646f485 SC |
78 | return result ; |
79 | } | |
80 | ||
81 | wxDC *wxPrintDialog::GetPrintDC() | |
82 | { | |
83 | return new wxPrinterDC( m_printDialogData.GetPrintData() ) ; | |
84 | } | |
85 | ||
86 | /* | |
87 | * wxPageSetupDialog | |
88 | */ | |
89 | ||
90 | wxPageSetupDialog::wxPageSetupDialog(): | |
91 | wxDialog() | |
92 | { | |
93 | m_dialogParent = NULL; | |
94 | } | |
95 | ||
96 | wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data): | |
97 | wxDialog() | |
98 | { | |
99 | Create(p, data); | |
100 | } | |
101 | ||
102 | bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data) | |
103 | { | |
104 | m_dialogParent = p; | |
8e3f3880 | 105 | |
2646f485 SC |
106 | if (data) |
107 | m_pageSetupData = (*data); | |
8e3f3880 WS |
108 | |
109 | return true; | |
2646f485 SC |
110 | } |
111 | ||
112 | wxPageSetupDialog::~wxPageSetupDialog() | |
113 | { | |
114 | } | |
115 | ||
116 | int wxPageSetupDialog::ShowModal() | |
117 | { | |
118 | m_pageSetupData.ConvertToNative() ; | |
119 | int result = m_pageSetupData.GetPrintData().m_nativePrintData->ShowPageSetupDialog() ; | |
120 | if (result == wxID_OK ) | |
121 | m_pageSetupData.ConvertFromNative() ; | |
8e3f3880 | 122 | |
2646f485 SC |
123 | return result ; |
124 | } | |
f415cab9 JS |
125 | |
126 | ||
127 | IMPLEMENT_CLASS(wxMacPageMarginsDialog, wxDialog) | |
128 | ||
129 | wxMacPageMarginsDialog::wxMacPageMarginsDialog(wxFrame *parent, wxPageSetupData *data) : | |
130 | wxDialog(parent, wxID_ANY, wxString(wxT("Page Margins"))), | |
131 | m_pageSetupDialogData(data) | |
132 | { | |
133 | GetMinMargins(); | |
134 | wxBoxSizer *colSizer = new wxBoxSizer(wxVERTICAL); | |
135 | wxFlexGridSizer *gridSizer = new wxFlexGridSizer(4, 5, 5); | |
136 | colSizer->Add(gridSizer, wxSizerFlags().Border(wxALL, 5)); | |
137 | gridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Left (mm):")), wxSizerFlags().Right()); | |
138 | gridSizer->Add(m_LeftMargin = new wxTextCtrl(this, wxID_ANY), wxSizerFlags().Left()); | |
139 | gridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Top (mm):")), wxSizerFlags().Right()); | |
140 | gridSizer->Add(m_TopMargin = new wxTextCtrl(this, wxID_ANY), wxSizerFlags().Left()); | |
141 | gridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Right (mm):")), wxSizerFlags().Right()); | |
142 | gridSizer->Add(m_RightMargin = new wxTextCtrl(this, wxID_ANY), wxSizerFlags().Left()); | |
143 | gridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Bottom (mm):")), wxSizerFlags().Right()); | |
144 | gridSizer->Add(m_BottomMargin = new wxTextCtrl(this, wxID_ANY), wxSizerFlags().Left()); | |
145 | colSizer->Add(new wxStaticLine(this), wxSizerFlags().Expand().Border(wxTOP|wxBOTTOM, 5)); | |
146 | colSizer->Add(CreateButtonSizer(wxOK | wxCANCEL), wxSizerFlags().Expand().Border(wxALL, 5)); | |
147 | TransferToWindow(); | |
148 | SetSizerAndFit(colSizer); | |
149 | Center(wxBOTH); | |
150 | } | |
151 | ||
152 | bool wxMacPageMarginsDialog::TransferToWindow() | |
153 | { | |
154 | wxASSERT(m_pageSetupDialogData); | |
155 | wxPoint topLeft = m_pageSetupDialogData->GetMarginTopLeft(); | |
156 | wxPoint bottomRight = m_pageSetupDialogData->GetMarginBottomRight(); | |
157 | wxPoint minTopLeft = m_pageSetupDialogData->GetMinMarginTopLeft(); | |
158 | wxPoint minBottomRight = m_pageSetupDialogData->GetMinMarginBottomRight(); | |
159 | m_LeftMargin->SetValue(wxString::Format(wxT("%d"), wxMax(topLeft.x, minTopLeft.x))); | |
160 | m_LeftMargin->SetSelection(-1, -1); | |
161 | m_TopMargin->SetValue(wxString::Format(wxT("%d"), wxMax(topLeft.y, minTopLeft.y))); | |
162 | m_TopMargin->SetSelection(-1, -1); | |
163 | m_RightMargin->SetValue(wxString::Format(wxT("%d"), wxMax(bottomRight.x, minBottomRight.x))); | |
164 | m_RightMargin->SetSelection(-1, -1); | |
165 | m_BottomMargin->SetValue(wxString::Format(wxT("%d"), wxMax(bottomRight.y, minBottomRight.y))); | |
166 | m_BottomMargin->SetSelection(-1, -1); | |
167 | m_LeftMargin->SetFocus(); | |
168 | return true; | |
169 | } | |
170 | ||
171 | bool wxMacPageMarginsDialog::TransferDataFromWindow() | |
172 | { | |
173 | wxPoint topLeft, bottomRight; | |
174 | if (!CheckValue(m_LeftMargin, &topLeft.x, m_MinMarginTopLeft.x, wxT("left margin"))) return false; | |
175 | if (!CheckValue(m_TopMargin, &topLeft.y, m_MinMarginTopLeft.y, wxT("top margin"))) return false; | |
176 | if (!CheckValue(m_RightMargin, &bottomRight.x, m_MinMarginBottomRight.x, wxT("right margin"))) return false; | |
177 | if (!CheckValue(m_BottomMargin, &bottomRight.y, m_MinMarginBottomRight.y, wxT("bottom margin"))) return false; | |
178 | m_pageSetupDialogData->SetMarginTopLeft(topLeft); | |
179 | m_pageSetupDialogData->SetMarginBottomRight(bottomRight); | |
180 | return true; | |
181 | } | |
182 | ||
183 | bool wxMacPageMarginsDialog::CheckValue(wxTextCtrl* textCtrl, int *value, int minValue, const wxString& name) | |
184 | { | |
185 | long lvalue; | |
186 | if (!textCtrl->GetValue().ToLong(&lvalue)) | |
187 | { | |
188 | wxMessageBox(wxString::Format(wxT("Sorry, \"%s\" is not a valid numerical value for the %s"), textCtrl->GetValue().c_str(), name.c_str()), wxT("Page Margin Error")); | |
189 | return false; | |
190 | } | |
191 | if (lvalue < minValue) | |
192 | { | |
193 | wxMessageBox(wxString::Format(wxT("Sorry, \"%s\" is not a valid value for the %s, which must be >= %d"), textCtrl->GetValue().c_str(), name.c_str(), minValue), wxT("Page Margin Error")); | |
194 | textCtrl->SetValue(wxString::Format(wxT("%d"), minValue)); | |
195 | textCtrl->SetSelection(-1, -1); | |
196 | textCtrl->SetFocus(); | |
197 | return false; | |
198 | } | |
199 | *value = int(lvalue); | |
200 | return true; | |
201 | } | |
202 | ||
203 | void wxMacPageMarginsDialog::GetMinMargins() | |
204 | { | |
205 | m_MinMarginTopLeft = m_pageSetupDialogData->GetMinMarginTopLeft(); | |
206 | m_MinMarginBottomRight = m_pageSetupDialogData->GetMinMarginBottomRight(); | |
207 | } |