1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtexttabspage.cpp
4 // Author: Julian Smart
6 // Created: 10/4/2006 8:03:20 AM
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/richtext/richtexttabspage.h"
16 * wxRichTextTabsPage type definition
19 IMPLEMENT_DYNAMIC_CLASS( wxRichTextTabsPage
, wxRichTextDialogPage
)
22 * wxRichTextTabsPage event table definition
25 BEGIN_EVENT_TABLE( wxRichTextTabsPage
, wxRichTextDialogPage
)
27 ////@begin wxRichTextTabsPage event table entries
28 EVT_LISTBOX( ID_RICHTEXTTABSPAGE_TABLIST
, wxRichTextTabsPage::OnTablistSelected
)
30 EVT_BUTTON( ID_RICHTEXTTABSPAGE_NEW_TAB
, wxRichTextTabsPage::OnNewTabClick
)
31 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_NEW_TAB
, wxRichTextTabsPage::OnNewTabUpdate
)
33 EVT_BUTTON( ID_RICHTEXTTABSPAGE_DELETE_TAB
, wxRichTextTabsPage::OnDeleteTabClick
)
34 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_DELETE_TAB
, wxRichTextTabsPage::OnDeleteTabUpdate
)
36 EVT_BUTTON( ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
, wxRichTextTabsPage::OnDeleteAllTabsClick
)
37 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
, wxRichTextTabsPage::OnDeleteAllTabsUpdate
)
39 ////@end wxRichTextTabsPage event table entries
43 IMPLEMENT_HELP_PROVISION(wxRichTextTabsPage
)
46 * wxRichTextTabsPage constructors
49 wxRichTextTabsPage::wxRichTextTabsPage( )
54 wxRichTextTabsPage::wxRichTextTabsPage( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
57 Create(parent
, id
, pos
, size
, style
);
64 void wxRichTextTabsPage::Init()
66 m_tabsPresent
= false;
68 ////@begin wxRichTextTabsPage member initialisation
71 ////@end wxRichTextTabsPage member initialisation
75 * wxRichTextTabsPage creator
78 bool wxRichTextTabsPage::Create( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
80 ////@begin wxRichTextTabsPage creation
81 wxRichTextDialogPage::Create( parent
, id
, pos
, size
, style
);
86 GetSizer()->SetSizeHints(this);
89 ////@end wxRichTextTabsPage creation
94 * Control creation for wxRichTextTabsPage
97 void wxRichTextTabsPage::CreateControls()
99 ////@begin wxRichTextTabsPage content construction
100 wxRichTextTabsPage
* itemRichTextDialogPage1
= this;
102 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
103 itemRichTextDialogPage1
->SetSizer(itemBoxSizer2
);
105 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
106 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
108 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
109 itemBoxSizer3
->Add(itemBoxSizer4
, 1, wxGROW
, 5);
111 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
112 itemBoxSizer4
->Add(itemBoxSizer5
, 0, wxGROW
, 5);
114 wxStaticText
* itemStaticText6
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Position (tenths of a mm):"), wxDefaultPosition
, wxDefaultSize
, 0 );
115 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
117 m_tabEditCtrl
= new wxTextCtrl( itemRichTextDialogPage1
, ID_RICHTEXTTABSPAGE_TABEDIT
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, 0 );
118 m_tabEditCtrl
->SetHelpText(_("The tab position."));
119 if (wxRichTextTabsPage::ShowToolTips())
120 m_tabEditCtrl
->SetToolTip(_("The tab position."));
121 itemBoxSizer5
->Add(m_tabEditCtrl
, 0, wxGROW
|wxALL
, 5);
123 wxArrayString m_tabListCtrlStrings
;
124 m_tabListCtrlStrings
.Add(_("The tab positions."));
125 m_tabListCtrl
= new wxListBox( itemRichTextDialogPage1
, ID_RICHTEXTTABSPAGE_TABLIST
, wxDefaultPosition
, wxSize(80, 200), m_tabListCtrlStrings
, wxLB_SINGLE
);
126 itemBoxSizer5
->Add(m_tabListCtrl
, 1, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
128 itemBoxSizer4
->Add(2, 1, 1, wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
, 5);
130 wxBoxSizer
* itemBoxSizer10
= new wxBoxSizer(wxVERTICAL
);
131 itemBoxSizer4
->Add(itemBoxSizer10
, 0, wxGROW
, 5);
133 wxStaticText
* itemStaticText11
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, 0 );
134 itemBoxSizer10
->Add(itemStaticText11
, 0, wxALIGN_CENTER_HORIZONTAL
|wxBOTTOM
, 5);
136 wxButton
* itemButton12
= new wxButton( itemRichTextDialogPage1
, ID_RICHTEXTTABSPAGE_NEW_TAB
, _("&New"), wxDefaultPosition
, wxDefaultSize
, 0 );
137 itemButton12
->SetHelpText(_("Click to create a new tab position."));
138 if (wxRichTextTabsPage::ShowToolTips())
139 itemButton12
->SetToolTip(_("Click to create a new tab position."));
140 itemBoxSizer10
->Add(itemButton12
, 0, wxGROW
|wxALL
, 5);
142 wxButton
* itemButton13
= new wxButton( itemRichTextDialogPage1
, ID_RICHTEXTTABSPAGE_DELETE_TAB
, _("&Delete"), wxDefaultPosition
, wxDefaultSize
, 0 );
143 itemButton13
->SetHelpText(_("Click to delete the selected tab position."));
144 if (wxRichTextTabsPage::ShowToolTips())
145 itemButton13
->SetToolTip(_("Click to delete the selected tab position."));
146 itemBoxSizer10
->Add(itemButton13
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
148 wxButton
* itemButton14
= new wxButton( itemRichTextDialogPage1
, ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
, _("Delete A&ll"), wxDefaultPosition
, wxDefaultSize
, 0 );
149 itemButton14
->SetHelpText(_("Click to delete all tab positions."));
150 if (wxRichTextTabsPage::ShowToolTips())
151 itemButton14
->SetToolTip(_("Click to delete all tab positions."));
152 itemBoxSizer10
->Add(itemButton14
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
154 ////@end wxRichTextTabsPage content construction
157 /// Transfer data from/to window
158 bool wxRichTextTabsPage::TransferDataFromWindow()
160 wxPanel::TransferDataFromWindow();
162 wxRichTextAttr
* attr
= GetAttributes();
168 for (i
= 0; i
< m_tabListCtrl
->GetCount(); i
++)
170 tabs
.Add(wxAtoi(m_tabListCtrl
->GetString(i
)));
177 bool wxRichTextTabsPage::TransferDataToWindow()
179 wxPanel::TransferDataToWindow();
181 wxRichTextAttr
* attr
= GetAttributes();
183 m_tabListCtrl
->Clear();
184 m_tabEditCtrl
->SetValue(wxEmptyString
);
188 m_tabsPresent
= true;
190 for (i
= 0; i
< attr
->GetTabs().GetCount(); i
++)
192 wxString
s(wxString::Format(wxT("%d"), attr
->GetTabs()[i
]));
193 m_tabListCtrl
->Append(s
);
200 static int wxTabSortFunc(int* a
, int* b
)
204 else if ((*b
) < (*a
))
210 /// Sorts the tab array
211 void wxRichTextTabsPage::SortTabs()
215 for (i
= 0; i
< m_tabListCtrl
->GetCount(); i
++)
217 tabs
.Add(wxAtoi(m_tabListCtrl
->GetString(i
)));
219 tabs
.Sort(& wxTabSortFunc
);
221 m_tabListCtrl
->Clear();
222 for (i
= 0; i
< tabs
.GetCount(); i
++)
224 wxString
s(wxString::Format(wxT("%d"), tabs
[i
]));
225 m_tabListCtrl
->Append(s
);
229 wxRichTextAttr
* wxRichTextTabsPage::GetAttributes()
231 return wxRichTextFormattingDialog::GetDialogAttributes(this);
235 * Should we show tooltips?
238 bool wxRichTextTabsPage::ShowToolTips()
240 return wxRichTextFormattingDialog::ShowToolTips();
244 * Get bitmap resources
247 wxBitmap
wxRichTextTabsPage::GetBitmapResource( const wxString
& name
)
250 ////@begin wxRichTextTabsPage bitmap retrieval
253 ////@end wxRichTextTabsPage bitmap retrieval
260 wxIcon
wxRichTextTabsPage::GetIconResource( const wxString
& name
)
263 ////@begin wxRichTextTabsPage icon retrieval
266 ////@end wxRichTextTabsPage icon retrieval
270 * wxEVT_BUTTON event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
273 void wxRichTextTabsPage::OnNewTabClick( wxCommandEvent
& WXUNUSED(event
) )
275 wxString str
= m_tabEditCtrl
->GetValue();
276 if (!str
.empty() && str
.IsNumber())
278 wxString
s(wxString::Format(wxT("%d"), wxAtoi(str
)));
280 m_tabListCtrl
->Append(s
);
281 m_tabsPresent
= true;
288 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
291 void wxRichTextTabsPage::OnNewTabUpdate( wxUpdateUIEvent
& event
)
293 // This may be a bit expensive - consider updating New button when text
294 // changes in edit control
295 wxString str
= m_tabEditCtrl
->GetValue();
296 if (!str
.empty() && str
.IsNumber())
298 wxString
s(wxString::Format(wxT("%d"), wxAtoi(str
)));
299 event
.Enable(m_tabListCtrl
->FindString(s
) == wxNOT_FOUND
);
307 * wxEVT_BUTTON event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
310 void wxRichTextTabsPage::OnDeleteTabClick( wxCommandEvent
& WXUNUSED(event
) )
312 if (m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0 && m_tabListCtrl
->GetSelection() != wxNOT_FOUND
)
314 m_tabListCtrl
->Delete(m_tabListCtrl
->GetSelection());
319 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
322 void wxRichTextTabsPage::OnDeleteTabUpdate( wxUpdateUIEvent
& event
)
324 event
.Enable( m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0 && m_tabListCtrl
->GetSelection() != wxNOT_FOUND
);
329 * wxEVT_BUTTON event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
332 void wxRichTextTabsPage::OnDeleteAllTabsClick( wxCommandEvent
& WXUNUSED(event
) )
334 if (m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0)
336 m_tabListCtrl
->Clear();
337 m_tabEditCtrl
->SetValue(wxEmptyString
);
342 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
345 void wxRichTextTabsPage::OnDeleteAllTabsUpdate( wxUpdateUIEvent
& event
)
347 event
.Enable( m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0 );
352 * wxEVT_LISTBOX event handler for ID_RICHTEXTTABSPAGE_TABLIST
355 void wxRichTextTabsPage::OnTablistSelected( wxCommandEvent
& WXUNUSED(event
) )
357 wxString str
= m_tabListCtrl
->GetStringSelection();
359 m_tabEditCtrl
->SetValue(str
);
362 #endif // wxUSE_RICHTEXT