]> git.saurik.com Git - wxWidgets.git/blob - src/osx/printdlg_osx.cpp
move wxGridCellRenderer::Draw before other derived classes implementations (no real...
[wxWidgets.git] / src / osx / printdlg_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/printdlg_osx.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id: printdlg.cpp 58164 2009-01-17 08:46:00Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_PRINTING_ARCHITECTURE
15
16 #include "wx/printdlg.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/object.h"
20 #include "wx/dcprint.h"
21 #include "wx/msgdlg.h"
22 #include "wx/textctrl.h"
23 #include "wx/sizer.h"
24 #include "wx/stattext.h"
25 #endif
26
27 #include "wx/osx/printdlg.h"
28 #include "wx/osx/private/print.h"
29 #include "wx/osx/private.h"
30 #include "wx/statline.h"
31
32
33 IMPLEMENT_DYNAMIC_CLASS(wxMacPrintDialog, wxPrintDialogBase)
34
35 wxMacPrintDialog::wxMacPrintDialog()
36 {
37 m_dialogParent = NULL;
38 m_printerDC = NULL;
39 m_destroyDC = true;
40 }
41
42 wxMacPrintDialog::wxMacPrintDialog( wxWindow *p, wxPrintDialogData *data )
43 {
44 Create( p, data );
45 }
46
47 wxMacPrintDialog::wxMacPrintDialog( wxWindow *p, wxPrintData *data )
48 {
49 wxPrintDialogData data2;
50 if (data != NULL)
51 data2 = *data;
52
53 Create( p, &data2 );
54 }
55
56 bool wxMacPrintDialog::Create( wxWindow *p, wxPrintDialogData *data )
57 {
58 m_dialogParent = p;
59 m_printerDC = NULL;
60 m_destroyDC = true;
61
62 if (data != NULL)
63 m_printDialogData = *data;
64
65 return true;
66 }
67
68 wxMacPrintDialog::~wxMacPrintDialog()
69 {
70 if (m_destroyDC && m_printerDC)
71 {
72 delete m_printerDC;
73 m_printerDC = NULL;
74 }
75 }
76
77 wxDC *wxMacPrintDialog::GetPrintDC()
78 {
79 return new wxPrinterDC( m_printDialogData.GetPrintData() );
80 }
81
82 IMPLEMENT_CLASS(wxMacPageSetupDialog, wxPageSetupDialogBase)
83
84 wxMacPageSetupDialog::wxMacPageSetupDialog( wxWindow *p, wxPageSetupData *data )
85 : wxPageSetupDialogBase()
86 {
87 Create( p, data );
88 }
89
90 bool wxMacPageSetupDialog::Create( wxWindow *p, wxPageSetupData *data )
91 {
92 m_dialogParent = p;
93
94 if (data != NULL)
95 m_pageSetupData = (*data);
96
97 return true;
98 }
99
100 wxMacPageSetupDialog::~wxMacPageSetupDialog()
101 {
102 }
103
104 wxPageSetupData& wxMacPageSetupDialog::GetPageSetupDialogData()
105 {
106 return m_pageSetupData;
107 }
108
109 IMPLEMENT_CLASS(wxMacPageMarginsDialog, wxDialog)
110
111 wxMacPageMarginsDialog::wxMacPageMarginsDialog(wxFrame *parent, wxPageSetupData *data) :
112 wxDialog(parent, wxID_ANY, wxString(wxT("Page Margins"))),
113 m_pageSetupDialogData(data)
114 {
115 GetMinMargins();
116 wxBoxSizer *colSizer = new wxBoxSizer(wxVERTICAL);
117 wxFlexGridSizer *gridSizer = new wxFlexGridSizer(4, 5, 5);
118 colSizer->Add(gridSizer, wxSizerFlags().Border(wxALL, 5));
119 gridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Left (mm):")), wxSizerFlags().Right());
120 gridSizer->Add(m_LeftMargin = new wxTextCtrl(this, wxID_ANY), wxSizerFlags().Left());
121 gridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Top (mm):")), wxSizerFlags().Right());
122 gridSizer->Add(m_TopMargin = new wxTextCtrl(this, wxID_ANY), wxSizerFlags().Left());
123 gridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Right (mm):")), wxSizerFlags().Right());
124 gridSizer->Add(m_RightMargin = new wxTextCtrl(this, wxID_ANY), wxSizerFlags().Left());
125 gridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Bottom (mm):")), wxSizerFlags().Right());
126 gridSizer->Add(m_BottomMargin = new wxTextCtrl(this, wxID_ANY), wxSizerFlags().Left());
127 colSizer->Add(new wxStaticLine(this), wxSizerFlags().Expand().Border(wxTOP|wxBOTTOM, 5));
128 colSizer->Add(CreateButtonSizer(wxOK | wxCANCEL), wxSizerFlags().Expand().Border(wxALL, 5));
129 TransferToWindow();
130 SetSizerAndFit(colSizer);
131 Center(wxBOTH);
132 }
133
134 bool wxMacPageMarginsDialog::TransferToWindow()
135 {
136 wxASSERT(m_pageSetupDialogData);
137 wxPoint topLeft = m_pageSetupDialogData->GetMarginTopLeft();
138 wxPoint bottomRight = m_pageSetupDialogData->GetMarginBottomRight();
139 wxPoint minTopLeft = m_pageSetupDialogData->GetMinMarginTopLeft();
140 wxPoint minBottomRight = m_pageSetupDialogData->GetMinMarginBottomRight();
141 m_LeftMargin->SetValue(wxString::Format(wxT("%d"), wxMax(topLeft.x, minTopLeft.x)));
142 m_LeftMargin->SetSelection(-1, -1);
143 m_TopMargin->SetValue(wxString::Format(wxT("%d"), wxMax(topLeft.y, minTopLeft.y)));
144 m_TopMargin->SetSelection(-1, -1);
145 m_RightMargin->SetValue(wxString::Format(wxT("%d"), wxMax(bottomRight.x, minBottomRight.x)));
146 m_RightMargin->SetSelection(-1, -1);
147 m_BottomMargin->SetValue(wxString::Format(wxT("%d"), wxMax(bottomRight.y, minBottomRight.y)));
148 m_BottomMargin->SetSelection(-1, -1);
149 m_LeftMargin->SetFocus();
150 return true;
151 }
152
153 bool wxMacPageMarginsDialog::TransferDataFromWindow()
154 {
155 wxPoint topLeft, bottomRight;
156 if (!CheckValue(m_LeftMargin, &topLeft.x, m_MinMarginTopLeft.x, wxT("left margin"))) return false;
157 if (!CheckValue(m_TopMargin, &topLeft.y, m_MinMarginTopLeft.y, wxT("top margin"))) return false;
158 if (!CheckValue(m_RightMargin, &bottomRight.x, m_MinMarginBottomRight.x, wxT("right margin"))) return false;
159 if (!CheckValue(m_BottomMargin, &bottomRight.y, m_MinMarginBottomRight.y, wxT("bottom margin"))) return false;
160 m_pageSetupDialogData->SetMarginTopLeft(topLeft);
161 m_pageSetupDialogData->SetMarginBottomRight(bottomRight);
162 return true;
163 }
164
165 bool wxMacPageMarginsDialog::CheckValue(wxTextCtrl* textCtrl, int *value, int minValue, const wxString& name)
166 {
167 long lvalue;
168 if (!textCtrl->GetValue().ToLong(&lvalue))
169 {
170 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"));
171 return false;
172 }
173 if (lvalue < minValue)
174 {
175 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"));
176 textCtrl->SetValue(wxString::Format(wxT("%d"), minValue));
177 textCtrl->SetSelection(-1, -1);
178 textCtrl->SetFocus();
179 return false;
180 }
181 *value = int(lvalue);
182 return true;
183 }
184
185 void wxMacPageMarginsDialog::GetMinMargins()
186 {
187 m_MinMarginTopLeft = m_pageSetupDialogData->GetMinMarginTopLeft();
188 m_MinMarginBottomRight = m_pageSetupDialogData->GetMinMarginBottomRight();
189 }
190
191 #endif