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