1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/printdlg_osx.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #if wxUSE_PRINTING_ARCHITECTURE
16 #include "wx/printdlg.h"
19 #include "wx/object.h"
20 #include "wx/dcprint.h"
21 #include "wx/msgdlg.h"
22 #include "wx/textctrl.h"
24 #include "wx/stattext.h"
27 #include "wx/osx/printdlg.h"
28 #include "wx/osx/private/print.h"
29 #include "wx/osx/private.h"
30 #include "wx/statline.h"
33 IMPLEMENT_DYNAMIC_CLASS(wxMacPrintDialog
, wxPrintDialogBase
)
35 wxMacPrintDialog::wxMacPrintDialog()
37 m_dialogParent
= NULL
;
42 wxMacPrintDialog::wxMacPrintDialog( wxWindow
*p
, wxPrintDialogData
*data
)
47 wxMacPrintDialog::wxMacPrintDialog( wxWindow
*p
, wxPrintData
*data
)
49 wxPrintDialogData data2
;
56 bool wxMacPrintDialog::Create( wxWindow
*p
, wxPrintDialogData
*data
)
63 m_printDialogData
= *data
;
68 wxMacPrintDialog::~wxMacPrintDialog()
72 wxDELETE(m_printerDC
);
76 wxDC
*wxMacPrintDialog::GetPrintDC()
78 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
81 IMPLEMENT_CLASS(wxMacPageSetupDialog
, wxPageSetupDialogBase
)
83 wxMacPageSetupDialog::wxMacPageSetupDialog( wxWindow
*p
, wxPageSetupData
*data
)
84 : wxPageSetupDialogBase()
89 bool wxMacPageSetupDialog::Create( wxWindow
*p
, wxPageSetupData
*data
)
94 m_pageSetupData
= (*data
);
99 wxMacPageSetupDialog::~wxMacPageSetupDialog()
103 wxPageSetupData
& wxMacPageSetupDialog::GetPageSetupDialogData()
105 return m_pageSetupData
;
108 IMPLEMENT_CLASS(wxMacPageMarginsDialog
, wxDialog
)
110 wxMacPageMarginsDialog::wxMacPageMarginsDialog(wxFrame
*parent
, wxPageSetupData
*data
) :
111 wxDialog(parent
, wxID_ANY
, wxString(wxT("Page Margins"))),
112 m_pageSetupDialogData(data
)
115 wxBoxSizer
*colSizer
= new wxBoxSizer(wxVERTICAL
);
116 wxFlexGridSizer
*gridSizer
= new wxFlexGridSizer(4, 5, 5);
117 colSizer
->Add(gridSizer
, wxSizerFlags().Border(wxALL
, 5));
118 gridSizer
->Add(new wxStaticText(this, wxID_ANY
, wxT("Left (mm):")), wxSizerFlags().Right());
119 gridSizer
->Add(m_LeftMargin
= new wxTextCtrl(this, wxID_ANY
), wxSizerFlags().Left());
120 gridSizer
->Add(new wxStaticText(this, wxID_ANY
, wxT("Top (mm):")), wxSizerFlags().Right());
121 gridSizer
->Add(m_TopMargin
= new wxTextCtrl(this, wxID_ANY
), wxSizerFlags().Left());
122 gridSizer
->Add(new wxStaticText(this, wxID_ANY
, wxT("Right (mm):")), wxSizerFlags().Right());
123 gridSizer
->Add(m_RightMargin
= new wxTextCtrl(this, wxID_ANY
), wxSizerFlags().Left());
124 gridSizer
->Add(new wxStaticText(this, wxID_ANY
, wxT("Bottom (mm):")), wxSizerFlags().Right());
125 gridSizer
->Add(m_BottomMargin
= new wxTextCtrl(this, wxID_ANY
), wxSizerFlags().Left());
126 colSizer
->Add(new wxStaticLine(this), wxSizerFlags().Expand().Border(wxTOP
|wxBOTTOM
, 5));
127 colSizer
->Add(CreateButtonSizer(wxOK
| wxCANCEL
), wxSizerFlags().Expand().Border(wxALL
, 5));
129 SetSizerAndFit(colSizer
);
133 bool wxMacPageMarginsDialog::TransferToWindow()
135 wxASSERT(m_pageSetupDialogData
);
136 wxPoint topLeft
= m_pageSetupDialogData
->GetMarginTopLeft();
137 wxPoint bottomRight
= m_pageSetupDialogData
->GetMarginBottomRight();
138 wxPoint minTopLeft
= m_pageSetupDialogData
->GetMinMarginTopLeft();
139 wxPoint minBottomRight
= m_pageSetupDialogData
->GetMinMarginBottomRight();
140 m_LeftMargin
->SetValue(wxString::Format(wxT("%d"), wxMax(topLeft
.x
, minTopLeft
.x
)));
141 m_LeftMargin
->SetSelection(-1, -1);
142 m_TopMargin
->SetValue(wxString::Format(wxT("%d"), wxMax(topLeft
.y
, minTopLeft
.y
)));
143 m_TopMargin
->SetSelection(-1, -1);
144 m_RightMargin
->SetValue(wxString::Format(wxT("%d"), wxMax(bottomRight
.x
, minBottomRight
.x
)));
145 m_RightMargin
->SetSelection(-1, -1);
146 m_BottomMargin
->SetValue(wxString::Format(wxT("%d"), wxMax(bottomRight
.y
, minBottomRight
.y
)));
147 m_BottomMargin
->SetSelection(-1, -1);
148 m_LeftMargin
->SetFocus();
152 bool wxMacPageMarginsDialog::TransferDataFromWindow()
154 wxPoint topLeft
, bottomRight
;
155 if (!CheckValue(m_LeftMargin
, &topLeft
.x
, m_MinMarginTopLeft
.x
, wxT("left margin"))) return false;
156 if (!CheckValue(m_TopMargin
, &topLeft
.y
, m_MinMarginTopLeft
.y
, wxT("top margin"))) return false;
157 if (!CheckValue(m_RightMargin
, &bottomRight
.x
, m_MinMarginBottomRight
.x
, wxT("right margin"))) return false;
158 if (!CheckValue(m_BottomMargin
, &bottomRight
.y
, m_MinMarginBottomRight
.y
, wxT("bottom margin"))) return false;
159 m_pageSetupDialogData
->SetMarginTopLeft(topLeft
);
160 m_pageSetupDialogData
->SetMarginBottomRight(bottomRight
);
164 bool wxMacPageMarginsDialog::CheckValue(wxTextCtrl
* textCtrl
, int *value
, int minValue
, const wxString
& name
)
167 if (!textCtrl
->GetValue().ToLong(&lvalue
))
169 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"));
172 if (lvalue
< minValue
)
174 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"));
175 textCtrl
->SetValue(wxString::Format(wxT("%d"), minValue
));
176 textCtrl
->SetSelection(-1, -1);
177 textCtrl
->SetFocus();
180 *value
= int(lvalue
);
184 void wxMacPageMarginsDialog::GetMinMargins()
186 m_MinMarginTopLeft
= m_pageSetupDialogData
->GetMinMarginTopLeft();
187 m_MinMarginBottomRight
= m_pageSetupDialogData
->GetMinMarginBottomRight();