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