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