]> git.saurik.com Git - wxWidgets.git/blame - src/osx/printdlg_osx.cpp
Add ClearSelection for msw ie and gtk webkit, with a stub for osx webkit. Document...
[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
b5b208a1 7// RCS-ID: $Id$
e158da36
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
33IMPLEMENT_DYNAMIC_CLASS(wxMacPrintDialog, wxPrintDialogBase)
34
35wxMacPrintDialog::wxMacPrintDialog()
36{
37 m_dialogParent = NULL;
38 m_printerDC = NULL;
39 m_destroyDC = true;
40}
41
42wxMacPrintDialog::wxMacPrintDialog( wxWindow *p, wxPrintDialogData *data )
43{
44 Create( p, data );
45}
46
47wxMacPrintDialog::wxMacPrintDialog( wxWindow *p, wxPrintData *data )
48{
49 wxPrintDialogData data2;
50 if (data != NULL)
51 data2 = *data;
52
53 Create( p, &data2 );
54}
55
56bool 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
68wxMacPrintDialog::~wxMacPrintDialog()
69{
5276b0a5 70 if (m_destroyDC)
e158da36 71 {
5276b0a5 72 wxDELETE(m_printerDC);
e158da36
SC
73 }
74}
75
76wxDC *wxMacPrintDialog::GetPrintDC()
77{
78 return new wxPrinterDC( m_printDialogData.GetPrintData() );
79}
80
81IMPLEMENT_CLASS(wxMacPageSetupDialog, wxPageSetupDialogBase)
82
83wxMacPageSetupDialog::wxMacPageSetupDialog( wxWindow *p, wxPageSetupData *data )
84 : wxPageSetupDialogBase()
85{
86 Create( p, data );
87}
88
89bool wxMacPageSetupDialog::Create( wxWindow *p, wxPageSetupData *data )
90{
91 m_dialogParent = p;
92
93 if (data != NULL)
94 m_pageSetupData = (*data);
95
96 return true;
97}
98
99wxMacPageSetupDialog::~wxMacPageSetupDialog()
100{
101}
102
103wxPageSetupData& wxMacPageSetupDialog::GetPageSetupDialogData()
104{
105 return m_pageSetupData;
106}
107
108IMPLEMENT_CLASS(wxMacPageMarginsDialog, wxDialog)
109
110wxMacPageMarginsDialog::wxMacPageMarginsDialog(wxFrame *parent, wxPageSetupData *data) :
111 wxDialog(parent, wxID_ANY, wxString(wxT("Page Margins"))),
112 m_pageSetupDialogData(data)
113 {
114 GetMinMargins();
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));
128 TransferToWindow();
129 SetSizerAndFit(colSizer);
130 Center(wxBOTH);
131 }
132
133bool wxMacPageMarginsDialog::TransferToWindow()
134 {
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();
149 return true;
150 }
03647350 151
e158da36
SC
152bool wxMacPageMarginsDialog::TransferDataFromWindow()
153 {
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);
161 return true;
162 }
03647350 163
e158da36
SC
164bool wxMacPageMarginsDialog::CheckValue(wxTextCtrl* textCtrl, int *value, int minValue, const wxString& name)
165 {
166 long lvalue;
167 if (!textCtrl->GetValue().ToLong(&lvalue))
168 {
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"));
170 return false;
171 }
172 if (lvalue < minValue)
173 {
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();
178 return false;
179 }
180 *value = int(lvalue);
181 return true;
182 }
183
184void wxMacPageMarginsDialog::GetMinMargins()
185 {
186 m_MinMarginTopLeft = m_pageSetupDialogData->GetMinMarginTopLeft();
187 m_MinMarginBottomRight = m_pageSetupDialogData->GetMinMarginBottomRight();
188 }
189
190#endif