]> git.saurik.com Git - wxWidgets.git/blame - src/richtext/richtexttabspage.cpp
warning fixes/minor cleanup
[wxWidgets.git] / src / richtext / richtexttabspage.cpp
CommitLineData
97ff49b3
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: richtexttabspage.cpp
3// Purpose:
4// Author: Julian Smart
5// Modified by:
6// Created: 10/4/2006 8:03:20 AM
7// RCS-ID:
8// Copyright: (c) Julian Smart
9// Licence:
10/////////////////////////////////////////////////////////////////////////////
11
12////@begin includes
13////@end includes
14
15#include "../../include/wx/richtext/richtexttabspage.h"
16
17////@begin XPM images
18////@end XPM images
19
20/*!
21 * wxRichTextTabsPage type definition
22 */
23
24IMPLEMENT_DYNAMIC_CLASS( wxRichTextTabsPage, wxPanel )
25
26/*!
27 * wxRichTextTabsPage event table definition
28 */
29
30BEGIN_EVENT_TABLE( wxRichTextTabsPage, wxPanel )
31
32////@begin wxRichTextTabsPage event table entries
33 EVT_LISTBOX( ID_RICHTEXTTABSPAGE_TABLIST, wxRichTextTabsPage::OnTablistSelected )
34
35 EVT_BUTTON( ID_RICHTEXTTABSPAGE_NEW_TAB, wxRichTextTabsPage::OnNewTabClick )
36 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_NEW_TAB, wxRichTextTabsPage::OnNewTabUpdate )
37
38 EVT_BUTTON( ID_RICHTEXTTABSPAGE_DELETE_TAB, wxRichTextTabsPage::OnDeleteTabClick )
39 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_DELETE_TAB, wxRichTextTabsPage::OnDeleteTabUpdate )
40
41 EVT_BUTTON( ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS, wxRichTextTabsPage::OnDeleteAllTabsClick )
42 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS, wxRichTextTabsPage::OnDeleteAllTabsUpdate )
43
44////@end wxRichTextTabsPage event table entries
45
46END_EVENT_TABLE()
47
48/*!
49 * wxRichTextTabsPage constructors
50 */
51
52wxRichTextTabsPage::wxRichTextTabsPage( )
53{
54 Init();
55}
56
57wxRichTextTabsPage::wxRichTextTabsPage( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
58{
59 Init();
60 Create(parent, id, pos, size, style);
61}
62
63/*!
64 * Initialise members
65 */
66
67void wxRichTextTabsPage::Init()
68{
69 m_tabsPresent = false;
70
71////@begin wxRichTextTabsPage member initialisation
72 m_tabEditCtrl = NULL;
73 m_tabListCtrl = NULL;
74////@end wxRichTextTabsPage member initialisation
75}
76
77/*!
78 * wxRichTextTabsPage creator
79 */
80
81bool wxRichTextTabsPage::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
82{
83////@begin wxRichTextTabsPage creation
84 wxPanel::Create( parent, id, pos, size, style );
85
86 CreateControls();
87 if (GetSizer())
88 {
89 GetSizer()->SetSizeHints(this);
90 }
91 Centre();
92////@end wxRichTextTabsPage creation
93 return true;
94}
95
96/*!
97 * Control creation for wxRichTextTabsPage
98 */
99
100void wxRichTextTabsPage::CreateControls()
101{
102////@begin wxRichTextTabsPage content construction
103 wxRichTextTabsPage* itemPanel1 = this;
104
105 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
106 itemPanel1->SetSizer(itemBoxSizer2);
107
108 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
109 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
110
111 wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
112 itemBoxSizer3->Add(itemBoxSizer4, 1, wxGROW, 5);
113
114 wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
115 itemBoxSizer4->Add(itemBoxSizer5, 0, wxGROW, 5);
116
117 wxStaticText* itemStaticText6 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Position (tenths of a mm):"), wxDefaultPosition, wxDefaultSize, 0 );
118 itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
119
120 m_tabEditCtrl = new wxTextCtrl( itemPanel1, ID_RICHTEXTTABSPAGE_TABEDIT, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
121 itemBoxSizer5->Add(m_tabEditCtrl, 0, wxGROW|wxALL, 5);
122
123 wxString* m_tabListCtrlStrings = NULL;
124 m_tabListCtrl = new wxListBox( itemPanel1, ID_RICHTEXTTABSPAGE_TABLIST, wxDefaultPosition, wxSize(80, 200), 0, m_tabListCtrlStrings, wxLB_SINGLE );
125 itemBoxSizer5->Add(m_tabListCtrl, 1, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
126
127 itemBoxSizer4->Add(2, 1, 1, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5);
128
129 wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxVERTICAL);
130 itemBoxSizer4->Add(itemBoxSizer10, 0, wxGROW, 5);
131
132 wxStaticText* itemStaticText11 = new wxStaticText( itemPanel1, wxID_STATIC, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
133 itemBoxSizer10->Add(itemStaticText11, 0, wxALIGN_CENTER_HORIZONTAL|wxBOTTOM|wxADJUST_MINSIZE, 5);
134
135 wxButton* itemButton12 = new wxButton( itemPanel1, ID_RICHTEXTTABSPAGE_NEW_TAB, _("&New"), wxDefaultPosition, wxDefaultSize, 0 );
136 itemBoxSizer10->Add(itemButton12, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
137
138 wxButton* itemButton13 = new wxButton( itemPanel1, ID_RICHTEXTTABSPAGE_DELETE_TAB, _("&Delete"), wxDefaultPosition, wxDefaultSize, 0 );
139 itemBoxSizer10->Add(itemButton13, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT|wxBOTTOM, 5);
140
141 wxButton* itemButton14 = new wxButton( itemPanel1, ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS, _("Delete A&ll"), wxDefaultPosition, wxDefaultSize, 0 );
142 itemBoxSizer10->Add(itemButton14, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT|wxBOTTOM, 5);
143
144////@end wxRichTextTabsPage content construction
145}
146
147/// Transfer data from/to window
148bool wxRichTextTabsPage::TransferDataFromWindow()
149{
150 wxPanel::TransferDataFromWindow();
151
152 wxTextAttrEx* attr = GetAttributes();
153
154 if (m_tabsPresent)
155 {
156 wxArrayInt tabs;
157 size_t i;
158 for (i = 0; i < m_tabListCtrl->GetCount(); i++)
159 {
160 tabs.Add(wxAtoi(m_tabListCtrl->GetString(i)));
161 }
162 attr->SetTabs(tabs);
163 }
164 return true;
165}
166
167bool wxRichTextTabsPage::TransferDataToWindow()
168{
169 wxPanel::TransferDataToWindow();
170
171 wxTextAttrEx* attr = GetAttributes();
172
173 m_tabListCtrl->Clear();
174 m_tabEditCtrl->SetValue(wxEmptyString);
175
176 if (attr->HasTabs())
177 {
178 m_tabsPresent = true;
179 size_t i;
180 for (i = 0; i < attr->GetTabs().GetCount(); i++)
181 {
182 wxString s(wxString::Format(wxT("%d"), attr->GetTabs()[i]));
183 m_tabListCtrl->Append(s);
184 }
185 }
186
187 return true;
188}
189
190static int wxTabSortFunc(int* a, int* b)
191{
192 if ((*a) < (*b))
193 return -1;
194 else if ((*b) < (*a))
195 return 1;
196 else
197 return 0;
198}
199
200/// Sorts the tab array
201void wxRichTextTabsPage::SortTabs()
202{
203 wxArrayInt tabs;
204 size_t i;
205 for (i = 0; i < m_tabListCtrl->GetCount(); i++)
206 {
207 tabs.Add(wxAtoi(m_tabListCtrl->GetString(i)));
208 }
209 tabs.Sort(& wxTabSortFunc);
210
211 m_tabListCtrl->Clear();
212 for (i = 0; i < tabs.GetCount(); i++)
213 {
214 wxString s(wxString::Format(wxT("%d"), tabs[i]));
215 m_tabListCtrl->Append(s);
216 }
217}
218
219wxTextAttrEx* wxRichTextTabsPage::GetAttributes()
220{
221 return wxRichTextFormattingDialog::GetDialogAttributes(this);
222}
223
224/*!
225 * Should we show tooltips?
226 */
227
228bool wxRichTextTabsPage::ShowToolTips()
229{
230 return true;
231}
232
233/*!
234 * Get bitmap resources
235 */
236
237wxBitmap wxRichTextTabsPage::GetBitmapResource( const wxString& name )
238{
239 // Bitmap retrieval
240////@begin wxRichTextTabsPage bitmap retrieval
241 wxUnusedVar(name);
242 return wxNullBitmap;
243////@end wxRichTextTabsPage bitmap retrieval
244}
245
246/*!
247 * Get icon resources
248 */
249
250wxIcon wxRichTextTabsPage::GetIconResource( const wxString& name )
251{
252 // Icon retrieval
253////@begin wxRichTextTabsPage icon retrieval
254 wxUnusedVar(name);
255 return wxNullIcon;
256////@end wxRichTextTabsPage icon retrieval
257}
258
259/*!
260 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
261 */
262
263void wxRichTextTabsPage::OnNewTabClick( wxCommandEvent& WXUNUSED(event) )
264{
265 wxString str = m_tabEditCtrl->GetValue();
266 if (!str.IsEmpty() && str.IsNumber())
267 {
268 wxString s(wxString::Format(wxT("%d"), wxAtoi(str)));
269
270 m_tabListCtrl->Append(s);
271 m_tabsPresent = true;
272
273 SortTabs();
274 }
275}
276
277/*!
278 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
279 */
280
281void wxRichTextTabsPage::OnNewTabUpdate( wxUpdateUIEvent& event )
282{
283 // This may be a bit expensive - consider updating New button when text
284 // changes in edit control
285 wxString str = m_tabEditCtrl->GetValue();
286 if (!str.IsEmpty() && str.IsNumber())
287 {
288 wxString s(wxString::Format(wxT("%d"), wxAtoi(str)));
289 event.Enable(m_tabListCtrl->FindString(s) == wxNOT_FOUND);
290 }
291 else
292 event.Enable(false);
293}
294
295
296/*!
297 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
298 */
299
300void wxRichTextTabsPage::OnDeleteTabClick( wxCommandEvent& WXUNUSED(event) )
301{
302 if (m_tabsPresent && m_tabListCtrl->GetCount() > 0 && m_tabListCtrl->GetSelection() != wxNOT_FOUND)
303 {
304 m_tabListCtrl->Delete(m_tabListCtrl->GetSelection());
305 }
306}
307
308/*!
309 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
310 */
311
312void wxRichTextTabsPage::OnDeleteTabUpdate( wxUpdateUIEvent& event )
313{
314 event.Enable( m_tabsPresent && m_tabListCtrl->GetCount() > 0 && m_tabListCtrl->GetSelection() != wxNOT_FOUND );
315}
316
317
318/*!
319 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
320 */
321
322void wxRichTextTabsPage::OnDeleteAllTabsClick( wxCommandEvent& WXUNUSED(event) )
323{
324 if (m_tabsPresent && m_tabListCtrl->GetCount() > 0)
325 {
326 m_tabListCtrl->Clear();
327 m_tabEditCtrl->SetValue(wxEmptyString);
328 }
329}
330
331/*!
332 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
333 */
334
335void wxRichTextTabsPage::OnDeleteAllTabsUpdate( wxUpdateUIEvent& event )
336{
337 event.Enable( m_tabsPresent && m_tabListCtrl->GetCount() > 0 );
338}
339
340
341/*!
342 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTTABSPAGE_TABLIST
343 */
344
345void wxRichTextTabsPage::OnTablistSelected( wxCommandEvent& WXUNUSED(event) )
346{
347 wxString str = m_tabListCtrl->GetStringSelection();
348 if (!str.IsEmpty())
349 m_tabEditCtrl->SetValue(str);
350}