1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtexttabspage.cpp
4 // Author: Julian Smart
6 // Created: 10/4/2006 8:03:20 AM
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
15 #include "../../include/wx/richtext/richtexttabspage.h"
21 * wxRichTextTabsPage type definition
24 IMPLEMENT_DYNAMIC_CLASS( wxRichTextTabsPage
, wxPanel
)
27 * wxRichTextTabsPage event table definition
30 BEGIN_EVENT_TABLE( wxRichTextTabsPage
, wxPanel
)
32 ////@begin wxRichTextTabsPage event table entries
33 EVT_LISTBOX( ID_RICHTEXTTABSPAGE_TABLIST
, wxRichTextTabsPage::OnTablistSelected
)
35 EVT_BUTTON( ID_RICHTEXTTABSPAGE_NEW_TAB
, wxRichTextTabsPage::OnNewTabClick
)
36 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_NEW_TAB
, wxRichTextTabsPage::OnNewTabUpdate
)
38 EVT_BUTTON( ID_RICHTEXTTABSPAGE_DELETE_TAB
, wxRichTextTabsPage::OnDeleteTabClick
)
39 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_DELETE_TAB
, wxRichTextTabsPage::OnDeleteTabUpdate
)
41 EVT_BUTTON( ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
, wxRichTextTabsPage::OnDeleteAllTabsClick
)
42 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
, wxRichTextTabsPage::OnDeleteAllTabsUpdate
)
44 ////@end wxRichTextTabsPage event table entries
49 * wxRichTextTabsPage constructors
52 wxRichTextTabsPage::wxRichTextTabsPage( )
57 wxRichTextTabsPage::wxRichTextTabsPage( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
60 Create(parent
, id
, pos
, size
, style
);
67 void wxRichTextTabsPage::Init()
69 m_tabsPresent
= false;
71 ////@begin wxRichTextTabsPage member initialisation
74 ////@end wxRichTextTabsPage member initialisation
78 * wxRichTextTabsPage creator
81 bool wxRichTextTabsPage::Create( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
83 ////@begin wxRichTextTabsPage creation
84 wxPanel::Create( parent
, id
, pos
, size
, style
);
89 GetSizer()->SetSizeHints(this);
92 ////@end wxRichTextTabsPage creation
97 * Control creation for wxRichTextTabsPage
100 void wxRichTextTabsPage::CreateControls()
102 ////@begin wxRichTextTabsPage content construction
103 wxRichTextTabsPage
* itemPanel1
= this;
105 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
106 itemPanel1
->SetSizer(itemBoxSizer2
);
108 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
109 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
111 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
112 itemBoxSizer3
->Add(itemBoxSizer4
, 1, wxGROW
, 5);
114 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
115 itemBoxSizer4
->Add(itemBoxSizer5
, 0, wxGROW
, 5);
117 wxStaticText
* itemStaticText6
= new wxStaticText( itemPanel1
, wxID_STATIC
, _("&Position (tenths of a mm):"), wxDefaultPosition
, wxDefaultSize
, 0 );
118 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
120 m_tabEditCtrl
= new wxTextCtrl( itemPanel1
, ID_RICHTEXTTABSPAGE_TABEDIT
, _T(""), wxDefaultPosition
, wxDefaultSize
, 0 );
121 itemBoxSizer5
->Add(m_tabEditCtrl
, 0, wxGROW
|wxALL
, 5);
123 wxString
* m_tabListCtrlStrings
= NULL
;
124 m_tabListCtrl
= new wxListBox( itemPanel1
, ID_RICHTEXTTABSPAGE_TABLIST
, wxDefaultPosition
, wxSize(80, 200), 0, m_tabListCtrlStrings
, wxLB_SINGLE
);
125 itemBoxSizer5
->Add(m_tabListCtrl
, 1, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
127 itemBoxSizer4
->Add(2, 1, 1, wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
, 5);
129 wxBoxSizer
* itemBoxSizer10
= new wxBoxSizer(wxVERTICAL
);
130 itemBoxSizer4
->Add(itemBoxSizer10
, 0, wxGROW
, 5);
132 wxStaticText
* itemStaticText11
= new wxStaticText( itemPanel1
, wxID_STATIC
, _T(""), wxDefaultPosition
, wxDefaultSize
, 0 );
133 itemBoxSizer10
->Add(itemStaticText11
, 0, wxALIGN_CENTER_HORIZONTAL
|wxBOTTOM
|wxADJUST_MINSIZE
, 5);
135 wxButton
* itemButton12
= new wxButton( itemPanel1
, ID_RICHTEXTTABSPAGE_NEW_TAB
, _("&New"), wxDefaultPosition
, wxDefaultSize
, 0 );
136 itemBoxSizer10
->Add(itemButton12
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
138 wxButton
* itemButton13
= new wxButton( itemPanel1
, ID_RICHTEXTTABSPAGE_DELETE_TAB
, _("&Delete"), wxDefaultPosition
, wxDefaultSize
, 0 );
139 itemBoxSizer10
->Add(itemButton13
, 0, wxALIGN_CENTER_HORIZONTAL
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
141 wxButton
* itemButton14
= new wxButton( itemPanel1
, ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
, _("Delete A&ll"), wxDefaultPosition
, wxDefaultSize
, 0 );
142 itemBoxSizer10
->Add(itemButton14
, 0, wxALIGN_CENTER_HORIZONTAL
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
144 ////@end wxRichTextTabsPage content construction
147 /// Transfer data from/to window
148 bool wxRichTextTabsPage::TransferDataFromWindow()
150 wxPanel::TransferDataFromWindow();
152 wxTextAttrEx
* attr
= GetAttributes();
158 for (i
= 0; i
< m_tabListCtrl
->GetCount(); i
++)
160 tabs
.Add(wxAtoi(m_tabListCtrl
->GetString(i
)));
167 bool wxRichTextTabsPage::TransferDataToWindow()
169 wxPanel::TransferDataToWindow();
171 wxTextAttrEx
* attr
= GetAttributes();
173 m_tabListCtrl
->Clear();
174 m_tabEditCtrl
->SetValue(wxEmptyString
);
178 m_tabsPresent
= true;
180 for (i
= 0; i
< attr
->GetTabs().GetCount(); i
++)
182 wxString
s(wxString::Format(wxT("%d"), attr
->GetTabs()[i
]));
183 m_tabListCtrl
->Append(s
);
190 static int wxTabSortFunc(int* a
, int* b
)
194 else if ((*b
) < (*a
))
200 /// Sorts the tab array
201 void wxRichTextTabsPage::SortTabs()
205 for (i
= 0; i
< m_tabListCtrl
->GetCount(); i
++)
207 tabs
.Add(wxAtoi(m_tabListCtrl
->GetString(i
)));
209 tabs
.Sort(& wxTabSortFunc
);
211 m_tabListCtrl
->Clear();
212 for (i
= 0; i
< tabs
.GetCount(); i
++)
214 wxString
s(wxString::Format(wxT("%d"), tabs
[i
]));
215 m_tabListCtrl
->Append(s
);
219 wxTextAttrEx
* wxRichTextTabsPage::GetAttributes()
221 return wxRichTextFormattingDialog::GetDialogAttributes(this);
225 * Should we show tooltips?
228 bool wxRichTextTabsPage::ShowToolTips()
234 * Get bitmap resources
237 wxBitmap
wxRichTextTabsPage::GetBitmapResource( const wxString
& name
)
240 ////@begin wxRichTextTabsPage bitmap retrieval
243 ////@end wxRichTextTabsPage bitmap retrieval
250 wxIcon
wxRichTextTabsPage::GetIconResource( const wxString
& name
)
253 ////@begin wxRichTextTabsPage icon retrieval
256 ////@end wxRichTextTabsPage icon retrieval
260 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
263 void wxRichTextTabsPage::OnNewTabClick( wxCommandEvent
& WXUNUSED(event
) )
265 wxString str
= m_tabEditCtrl
->GetValue();
266 if (!str
.IsEmpty() && str
.IsNumber())
268 wxString
s(wxString::Format(wxT("%d"), wxAtoi(str
)));
270 m_tabListCtrl
->Append(s
);
271 m_tabsPresent
= true;
278 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
281 void wxRichTextTabsPage::OnNewTabUpdate( wxUpdateUIEvent
& event
)
283 // This may be a bit expensive - consider updating New button when text
284 // changes in edit control
285 wxString str
= m_tabEditCtrl
->GetValue();
286 if (!str
.IsEmpty() && str
.IsNumber())
288 wxString
s(wxString::Format(wxT("%d"), wxAtoi(str
)));
289 event
.Enable(m_tabListCtrl
->FindString(s
) == wxNOT_FOUND
);
297 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
300 void wxRichTextTabsPage::OnDeleteTabClick( wxCommandEvent
& WXUNUSED(event
) )
302 if (m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0 && m_tabListCtrl
->GetSelection() != wxNOT_FOUND
)
304 m_tabListCtrl
->Delete(m_tabListCtrl
->GetSelection());
309 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
312 void wxRichTextTabsPage::OnDeleteTabUpdate( wxUpdateUIEvent
& event
)
314 event
.Enable( m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0 && m_tabListCtrl
->GetSelection() != wxNOT_FOUND
);
319 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
322 void wxRichTextTabsPage::OnDeleteAllTabsClick( wxCommandEvent
& WXUNUSED(event
) )
324 if (m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0)
326 m_tabListCtrl
->Clear();
327 m_tabEditCtrl
->SetValue(wxEmptyString
);
332 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
335 void wxRichTextTabsPage::OnDeleteAllTabsUpdate( wxUpdateUIEvent
& event
)
337 event
.Enable( m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0 );
342 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTTABSPAGE_TABLIST
345 void wxRichTextTabsPage::OnTablistSelected( wxCommandEvent
& WXUNUSED(event
) )
347 wxString str
= m_tabListCtrl
->GetStringSelection();
349 m_tabEditCtrl
->SetValue(str
);