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