1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtexttabspage.cpp
4 // Author: Julian Smart
6 // Created: 10/4/2006 8:03:20 AM
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/richtext/richtexttabspage.h"
17 * wxRichTextTabsPage type definition
20 IMPLEMENT_DYNAMIC_CLASS( wxRichTextTabsPage
, wxRichTextDialogPage
)
23 * wxRichTextTabsPage event table definition
26 BEGIN_EVENT_TABLE( wxRichTextTabsPage
, wxRichTextDialogPage
)
28 ////@begin wxRichTextTabsPage event table entries
29 EVT_LISTBOX( ID_RICHTEXTTABSPAGE_TABLIST
, wxRichTextTabsPage::OnTablistSelected
)
31 EVT_BUTTON( ID_RICHTEXTTABSPAGE_NEW_TAB
, wxRichTextTabsPage::OnNewTabClick
)
32 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_NEW_TAB
, wxRichTextTabsPage::OnNewTabUpdate
)
34 EVT_BUTTON( ID_RICHTEXTTABSPAGE_DELETE_TAB
, wxRichTextTabsPage::OnDeleteTabClick
)
35 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_DELETE_TAB
, wxRichTextTabsPage::OnDeleteTabUpdate
)
37 EVT_BUTTON( ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
, wxRichTextTabsPage::OnDeleteAllTabsClick
)
38 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
, wxRichTextTabsPage::OnDeleteAllTabsUpdate
)
40 ////@end wxRichTextTabsPage event table entries
44 IMPLEMENT_HELP_PROVISION(wxRichTextTabsPage
)
47 * wxRichTextTabsPage constructors
50 wxRichTextTabsPage::wxRichTextTabsPage( )
55 wxRichTextTabsPage::wxRichTextTabsPage( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
58 Create(parent
, id
, pos
, size
, style
);
65 void wxRichTextTabsPage::Init()
67 m_tabsPresent
= false;
69 ////@begin wxRichTextTabsPage member initialisation
72 ////@end wxRichTextTabsPage member initialisation
76 * wxRichTextTabsPage creator
79 bool wxRichTextTabsPage::Create( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
81 ////@begin wxRichTextTabsPage creation
82 wxRichTextDialogPage::Create( parent
, id
, pos
, size
, style
);
87 GetSizer()->SetSizeHints(this);
90 ////@end wxRichTextTabsPage creation
95 * Control creation for wxRichTextTabsPage
98 void wxRichTextTabsPage::CreateControls()
100 ////@begin wxRichTextTabsPage content construction
101 wxRichTextTabsPage
* itemRichTextDialogPage1
= this;
103 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
104 itemRichTextDialogPage1
->SetSizer(itemBoxSizer2
);
106 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
107 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
109 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
110 itemBoxSizer3
->Add(itemBoxSizer4
, 1, wxGROW
, 5);
112 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
113 itemBoxSizer4
->Add(itemBoxSizer5
, 0, wxGROW
, 5);
115 wxStaticText
* itemStaticText6
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Position (tenths of a mm):"), wxDefaultPosition
, wxDefaultSize
, 0 );
116 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
118 m_tabEditCtrl
= new wxTextCtrl( itemRichTextDialogPage1
, ID_RICHTEXTTABSPAGE_TABEDIT
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, 0 );
119 m_tabEditCtrl
->SetHelpText(_("The tab position."));
120 if (wxRichTextTabsPage::ShowToolTips())
121 m_tabEditCtrl
->SetToolTip(_("The tab position."));
122 itemBoxSizer5
->Add(m_tabEditCtrl
, 0, wxGROW
|wxALL
, 5);
124 wxArrayString m_tabListCtrlStrings
;
125 m_tabListCtrlStrings
.Add(_("The tab positions."));
126 m_tabListCtrl
= new wxListBox( itemRichTextDialogPage1
, ID_RICHTEXTTABSPAGE_TABLIST
, wxDefaultPosition
, wxSize(80, 200), m_tabListCtrlStrings
, wxLB_SINGLE
);
127 itemBoxSizer5
->Add(m_tabListCtrl
, 1, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
129 itemBoxSizer4
->Add(2, 1, 1, wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
, 5);
131 wxBoxSizer
* itemBoxSizer10
= new wxBoxSizer(wxVERTICAL
);
132 itemBoxSizer4
->Add(itemBoxSizer10
, 0, wxGROW
, 5);
134 wxStaticText
* itemStaticText11
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, 0 );
135 itemBoxSizer10
->Add(itemStaticText11
, 0, wxALIGN_CENTER_HORIZONTAL
|wxBOTTOM
, 5);
137 wxButton
* itemButton12
= new wxButton( itemRichTextDialogPage1
, ID_RICHTEXTTABSPAGE_NEW_TAB
, _("&New"), wxDefaultPosition
, wxDefaultSize
, 0 );
138 itemButton12
->SetHelpText(_("Click to create a new tab position."));
139 if (wxRichTextTabsPage::ShowToolTips())
140 itemButton12
->SetToolTip(_("Click to create a new tab position."));
141 itemBoxSizer10
->Add(itemButton12
, 0, wxGROW
|wxALL
, 5);
143 wxButton
* itemButton13
= new wxButton( itemRichTextDialogPage1
, ID_RICHTEXTTABSPAGE_DELETE_TAB
, _("&Delete"), wxDefaultPosition
, wxDefaultSize
, 0 );
144 itemButton13
->SetHelpText(_("Click to delete the selected tab position."));
145 if (wxRichTextTabsPage::ShowToolTips())
146 itemButton13
->SetToolTip(_("Click to delete the selected tab position."));
147 itemBoxSizer10
->Add(itemButton13
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
149 wxButton
* itemButton14
= new wxButton( itemRichTextDialogPage1
, ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
, _("Delete A&ll"), wxDefaultPosition
, wxDefaultSize
, 0 );
150 itemButton14
->SetHelpText(_("Click to delete all tab positions."));
151 if (wxRichTextTabsPage::ShowToolTips())
152 itemButton14
->SetToolTip(_("Click to delete all tab positions."));
153 itemBoxSizer10
->Add(itemButton14
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
155 ////@end wxRichTextTabsPage content construction
158 /// Transfer data from/to window
159 bool wxRichTextTabsPage::TransferDataFromWindow()
161 wxPanel::TransferDataFromWindow();
163 wxRichTextAttr
* attr
= GetAttributes();
169 for (i
= 0; i
< m_tabListCtrl
->GetCount(); i
++)
171 tabs
.Add(wxAtoi(m_tabListCtrl
->GetString(i
)));
178 bool wxRichTextTabsPage::TransferDataToWindow()
180 wxPanel::TransferDataToWindow();
182 wxRichTextAttr
* attr
= GetAttributes();
184 m_tabListCtrl
->Clear();
185 m_tabEditCtrl
->SetValue(wxEmptyString
);
189 m_tabsPresent
= true;
191 for (i
= 0; i
< attr
->GetTabs().GetCount(); i
++)
193 wxString
s(wxString::Format(wxT("%d"), attr
->GetTabs()[i
]));
194 m_tabListCtrl
->Append(s
);
201 static int wxTabSortFunc(int* a
, int* b
)
205 else if ((*b
) < (*a
))
211 /// Sorts the tab array
212 void wxRichTextTabsPage::SortTabs()
216 for (i
= 0; i
< m_tabListCtrl
->GetCount(); i
++)
218 tabs
.Add(wxAtoi(m_tabListCtrl
->GetString(i
)));
220 tabs
.Sort(& wxTabSortFunc
);
222 m_tabListCtrl
->Clear();
223 for (i
= 0; i
< tabs
.GetCount(); i
++)
225 wxString
s(wxString::Format(wxT("%d"), tabs
[i
]));
226 m_tabListCtrl
->Append(s
);
230 wxRichTextAttr
* wxRichTextTabsPage::GetAttributes()
232 return wxRichTextFormattingDialog::GetDialogAttributes(this);
236 * Should we show tooltips?
239 bool wxRichTextTabsPage::ShowToolTips()
241 return wxRichTextFormattingDialog::ShowToolTips();
245 * Get bitmap resources
248 wxBitmap
wxRichTextTabsPage::GetBitmapResource( const wxString
& name
)
251 ////@begin wxRichTextTabsPage bitmap retrieval
254 ////@end wxRichTextTabsPage bitmap retrieval
261 wxIcon
wxRichTextTabsPage::GetIconResource( const wxString
& name
)
264 ////@begin wxRichTextTabsPage icon retrieval
267 ////@end wxRichTextTabsPage icon retrieval
271 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
274 void wxRichTextTabsPage::OnNewTabClick( wxCommandEvent
& WXUNUSED(event
) )
276 wxString str
= m_tabEditCtrl
->GetValue();
277 if (!str
.empty() && str
.IsNumber())
279 wxString
s(wxString::Format(wxT("%d"), wxAtoi(str
)));
281 m_tabListCtrl
->Append(s
);
282 m_tabsPresent
= true;
289 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
292 void wxRichTextTabsPage::OnNewTabUpdate( wxUpdateUIEvent
& event
)
294 // This may be a bit expensive - consider updating New button when text
295 // changes in edit control
296 wxString str
= m_tabEditCtrl
->GetValue();
297 if (!str
.empty() && str
.IsNumber())
299 wxString
s(wxString::Format(wxT("%d"), wxAtoi(str
)));
300 event
.Enable(m_tabListCtrl
->FindString(s
) == wxNOT_FOUND
);
308 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
311 void wxRichTextTabsPage::OnDeleteTabClick( wxCommandEvent
& WXUNUSED(event
) )
313 if (m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0 && m_tabListCtrl
->GetSelection() != wxNOT_FOUND
)
315 m_tabListCtrl
->Delete(m_tabListCtrl
->GetSelection());
320 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
323 void wxRichTextTabsPage::OnDeleteTabUpdate( wxUpdateUIEvent
& event
)
325 event
.Enable( m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0 && m_tabListCtrl
->GetSelection() != wxNOT_FOUND
);
330 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
333 void wxRichTextTabsPage::OnDeleteAllTabsClick( wxCommandEvent
& WXUNUSED(event
) )
335 if (m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0)
337 m_tabListCtrl
->Clear();
338 m_tabEditCtrl
->SetValue(wxEmptyString
);
343 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
346 void wxRichTextTabsPage::OnDeleteAllTabsUpdate( wxUpdateUIEvent
& event
)
348 event
.Enable( m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0 );
353 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTTABSPAGE_TABLIST
356 void wxRichTextTabsPage::OnTablistSelected( wxCommandEvent
& WXUNUSED(event
) )
358 wxString str
= m_tabListCtrl
->GetStringSelection();
360 m_tabEditCtrl
->SetValue(str
);
363 #endif // wxUSE_RICHTEXT