]> git.saurik.com Git - wxWidgets.git/blob - src/richtext/richtexttabspage.cpp
GetStyleMergedWithBase no longer hangs if there's a loop implied by based-on styles.
[wxWidgets.git] / src / richtext / richtexttabspage.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtexttabspage.cpp
3 // Purpose:
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 10/4/2006 8:03:20 AM
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if wxUSE_RICHTEXT
13
14 #include "wx/richtext/richtexttabspage.h"
15
16 /*!
17 * wxRichTextTabsPage type definition
18 */
19
20 IMPLEMENT_DYNAMIC_CLASS( wxRichTextTabsPage, wxPanel )
21
22 /*!
23 * wxRichTextTabsPage event table definition
24 */
25
26 BEGIN_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
42 END_EVENT_TABLE()
43
44 /*!
45 * wxRichTextTabsPage constructors
46 */
47
48 wxRichTextTabsPage::wxRichTextTabsPage( )
49 {
50 Init();
51 }
52
53 wxRichTextTabsPage::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 */
62
63 void 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
77 bool 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
96 void 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, 5);
115
116 m_tabEditCtrl = new wxTextCtrl( itemPanel1, ID_RICHTEXTTABSPAGE_TABEDIT, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
117 m_tabEditCtrl->SetHelpText(_("The tab position."));
118 if (wxRichTextTabsPage::ShowToolTips())
119 m_tabEditCtrl->SetToolTip(_("The tab position."));
120 itemBoxSizer5->Add(m_tabEditCtrl, 0, wxGROW|wxALL, 5);
121
122 wxArrayString m_tabListCtrlStrings;
123 m_tabListCtrlStrings.Add(_("The tab positions."));
124 m_tabListCtrl = new wxListBox( itemPanel1, ID_RICHTEXTTABSPAGE_TABLIST, wxDefaultPosition, wxSize(80, 200), 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, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
133 itemBoxSizer10->Add(itemStaticText11, 0, wxALIGN_CENTER_HORIZONTAL|wxBOTTOM, 5);
134
135 wxButton* itemButton12 = new wxButton( itemPanel1, ID_RICHTEXTTABSPAGE_NEW_TAB, _("&New"), wxDefaultPosition, wxDefaultSize, 0 );
136 itemButton12->SetHelpText(_("Click to create a new tab position."));
137 if (wxRichTextTabsPage::ShowToolTips())
138 itemButton12->SetToolTip(_("Click to create a new tab position."));
139 itemBoxSizer10->Add(itemButton12, 0, wxGROW|wxALL, 5);
140
141 wxButton* itemButton13 = new wxButton( itemPanel1, ID_RICHTEXTTABSPAGE_DELETE_TAB, _("&Delete"), wxDefaultPosition, wxDefaultSize, 0 );
142 itemButton13->SetHelpText(_("Click to delete the selected tab position."));
143 if (wxRichTextTabsPage::ShowToolTips())
144 itemButton13->SetToolTip(_("Click to delete the selected tab position."));
145 itemBoxSizer10->Add(itemButton13, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
146
147 wxButton* itemButton14 = new wxButton( itemPanel1, ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS, _("Delete A&ll"), wxDefaultPosition, wxDefaultSize, 0 );
148 itemButton14->SetHelpText(_("Click to delete all tab positions."));
149 if (wxRichTextTabsPage::ShowToolTips())
150 itemButton14->SetToolTip(_("Click to delete all tab positions."));
151 itemBoxSizer10->Add(itemButton14, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
152
153 ////@end wxRichTextTabsPage content construction
154 }
155
156 /// Transfer data from/to window
157 bool wxRichTextTabsPage::TransferDataFromWindow()
158 {
159 wxPanel::TransferDataFromWindow();
160
161 wxTextAttr* attr = GetAttributes();
162
163 if (m_tabsPresent)
164 {
165 wxArrayInt tabs;
166 size_t i;
167 for (i = 0; i < m_tabListCtrl->GetCount(); i++)
168 {
169 tabs.Add(wxAtoi(m_tabListCtrl->GetString(i)));
170 }
171 attr->SetTabs(tabs);
172 }
173 return true;
174 }
175
176 bool wxRichTextTabsPage::TransferDataToWindow()
177 {
178 wxPanel::TransferDataToWindow();
179
180 wxTextAttr* attr = GetAttributes();
181
182 m_tabListCtrl->Clear();
183 m_tabEditCtrl->SetValue(wxEmptyString);
184
185 if (attr->HasTabs())
186 {
187 m_tabsPresent = true;
188 size_t i;
189 for (i = 0; i < attr->GetTabs().GetCount(); i++)
190 {
191 wxString s(wxString::Format(wxT("%d"), attr->GetTabs()[i]));
192 m_tabListCtrl->Append(s);
193 }
194 }
195
196 return true;
197 }
198
199 static int wxTabSortFunc(int* a, int* b)
200 {
201 if ((*a) < (*b))
202 return -1;
203 else if ((*b) < (*a))
204 return 1;
205 else
206 return 0;
207 }
208
209 /// Sorts the tab array
210 void wxRichTextTabsPage::SortTabs()
211 {
212 wxArrayInt tabs;
213 size_t i;
214 for (i = 0; i < m_tabListCtrl->GetCount(); i++)
215 {
216 tabs.Add(wxAtoi(m_tabListCtrl->GetString(i)));
217 }
218 tabs.Sort(& wxTabSortFunc);
219
220 m_tabListCtrl->Clear();
221 for (i = 0; i < tabs.GetCount(); i++)
222 {
223 wxString s(wxString::Format(wxT("%d"), tabs[i]));
224 m_tabListCtrl->Append(s);
225 }
226 }
227
228 wxTextAttr* wxRichTextTabsPage::GetAttributes()
229 {
230 return wxRichTextFormattingDialog::GetDialogAttributes(this);
231 }
232
233 /*!
234 * Should we show tooltips?
235 */
236
237 bool wxRichTextTabsPage::ShowToolTips()
238 {
239 return wxRichTextFormattingDialog::ShowToolTips();
240 }
241
242 /*!
243 * Get bitmap resources
244 */
245
246 wxBitmap wxRichTextTabsPage::GetBitmapResource( const wxString& name )
247 {
248 // Bitmap retrieval
249 ////@begin wxRichTextTabsPage bitmap retrieval
250 wxUnusedVar(name);
251 return wxNullBitmap;
252 ////@end wxRichTextTabsPage bitmap retrieval
253 }
254
255 /*!
256 * Get icon resources
257 */
258
259 wxIcon wxRichTextTabsPage::GetIconResource( const wxString& name )
260 {
261 // Icon retrieval
262 ////@begin wxRichTextTabsPage icon retrieval
263 wxUnusedVar(name);
264 return wxNullIcon;
265 ////@end wxRichTextTabsPage icon retrieval
266 }
267
268 /*!
269 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
270 */
271
272 void wxRichTextTabsPage::OnNewTabClick( wxCommandEvent& WXUNUSED(event) )
273 {
274 wxString str = m_tabEditCtrl->GetValue();
275 if (!str.empty() && str.IsNumber())
276 {
277 wxString s(wxString::Format(wxT("%d"), wxAtoi(str)));
278
279 m_tabListCtrl->Append(s);
280 m_tabsPresent = true;
281
282 SortTabs();
283 }
284 }
285
286 /*!
287 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
288 */
289
290 void wxRichTextTabsPage::OnNewTabUpdate( wxUpdateUIEvent& event )
291 {
292 // This may be a bit expensive - consider updating New button when text
293 // changes in edit control
294 wxString str = m_tabEditCtrl->GetValue();
295 if (!str.empty() && str.IsNumber())
296 {
297 wxString s(wxString::Format(wxT("%d"), wxAtoi(str)));
298 event.Enable(m_tabListCtrl->FindString(s) == wxNOT_FOUND);
299 }
300 else
301 event.Enable(false);
302 }
303
304
305 /*!
306 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
307 */
308
309 void wxRichTextTabsPage::OnDeleteTabClick( wxCommandEvent& WXUNUSED(event) )
310 {
311 if (m_tabsPresent && m_tabListCtrl->GetCount() > 0 && m_tabListCtrl->GetSelection() != wxNOT_FOUND)
312 {
313 m_tabListCtrl->Delete(m_tabListCtrl->GetSelection());
314 }
315 }
316
317 /*!
318 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
319 */
320
321 void wxRichTextTabsPage::OnDeleteTabUpdate( wxUpdateUIEvent& event )
322 {
323 event.Enable( m_tabsPresent && m_tabListCtrl->GetCount() > 0 && m_tabListCtrl->GetSelection() != wxNOT_FOUND );
324 }
325
326
327 /*!
328 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
329 */
330
331 void wxRichTextTabsPage::OnDeleteAllTabsClick( wxCommandEvent& WXUNUSED(event) )
332 {
333 if (m_tabsPresent && m_tabListCtrl->GetCount() > 0)
334 {
335 m_tabListCtrl->Clear();
336 m_tabEditCtrl->SetValue(wxEmptyString);
337 }
338 }
339
340 /*!
341 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
342 */
343
344 void wxRichTextTabsPage::OnDeleteAllTabsUpdate( wxUpdateUIEvent& event )
345 {
346 event.Enable( m_tabsPresent && m_tabListCtrl->GetCount() > 0 );
347 }
348
349
350 /*!
351 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTTABSPAGE_TABLIST
352 */
353
354 void wxRichTextTabsPage::OnTablistSelected( wxCommandEvent& WXUNUSED(event) )
355 {
356 wxString str = m_tabListCtrl->GetStringSelection();
357 if (!str.empty())
358 m_tabEditCtrl->SetValue(str);
359 }
360
361 #endif // wxUSE_RICHTEXT