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
, wxPanel
)
23 * wxRichTextTabsPage event table definition
26 BEGIN_EVENT_TABLE( wxRichTextTabsPage
, wxPanel
)
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
45 * wxRichTextTabsPage constructors
48 wxRichTextTabsPage::wxRichTextTabsPage( )
53 wxRichTextTabsPage::wxRichTextTabsPage( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
56 Create(parent
, id
, pos
, size
, style
);
63 void wxRichTextTabsPage::Init()
65 m_tabsPresent
= false;
67 ////@begin wxRichTextTabsPage member initialisation
70 ////@end wxRichTextTabsPage member initialisation
74 * wxRichTextTabsPage creator
77 bool wxRichTextTabsPage::Create( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
79 ////@begin wxRichTextTabsPage creation
80 wxPanel::Create( parent
, id
, pos
, size
, style
);
85 GetSizer()->SetSizeHints(this);
88 ////@end wxRichTextTabsPage creation
93 * Control creation for wxRichTextTabsPage
96 void wxRichTextTabsPage::CreateControls()
98 ////@begin wxRichTextTabsPage content construction
99 wxRichTextTabsPage
* itemPanel1
= this;
101 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
102 itemPanel1
->SetSizer(itemBoxSizer2
);
104 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
105 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
107 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
108 itemBoxSizer3
->Add(itemBoxSizer4
, 1, wxGROW
, 5);
110 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
111 itemBoxSizer4
->Add(itemBoxSizer5
, 0, wxGROW
, 5);
113 wxStaticText
* itemStaticText6
= new wxStaticText( itemPanel1
, wxID_STATIC
, _("&Position (tenths of a mm):"), wxDefaultPosition
, wxDefaultSize
, 0 );
114 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
116 m_tabEditCtrl
= new wxTextCtrl( itemPanel1
,
117 ID_RICHTEXTTABSPAGE_TABEDIT
,
122 itemBoxSizer5
->Add(m_tabEditCtrl
, 0, wxGROW
|wxALL
, 5);
124 wxString
* m_tabListCtrlStrings
= NULL
;
125 m_tabListCtrl
= new wxListBox( itemPanel1
, ID_RICHTEXTTABSPAGE_TABLIST
, wxDefaultPosition
, wxSize(80, 200), 0, 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( itemPanel1
,
139 itemBoxSizer10
->Add(itemStaticText11
, 0, wxALIGN_CENTER_HORIZONTAL
|wxBOTTOM
|wxADJUST_MINSIZE
, 5);
141 wxButton
* itemButton12
= new wxButton( itemPanel1
, ID_RICHTEXTTABSPAGE_NEW_TAB
, _("&New"), wxDefaultPosition
, wxDefaultSize
, 0 );
142 itemBoxSizer10
->Add(itemButton12
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
144 wxButton
* itemButton13
= new wxButton( itemPanel1
, ID_RICHTEXTTABSPAGE_DELETE_TAB
, _("&Delete"), wxDefaultPosition
, wxDefaultSize
, 0 );
145 itemBoxSizer10
->Add(itemButton13
, 0, wxALIGN_CENTER_HORIZONTAL
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
147 wxButton
* itemButton14
= new wxButton( itemPanel1
, ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
, _("Delete A&ll"), wxDefaultPosition
, wxDefaultSize
, 0 );
148 itemBoxSizer10
->Add(itemButton14
, 0, wxALIGN_CENTER_HORIZONTAL
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
150 ////@end wxRichTextTabsPage content construction
153 /// Transfer data from/to window
154 bool wxRichTextTabsPage::TransferDataFromWindow()
156 wxPanel::TransferDataFromWindow();
158 wxTextAttrEx
* attr
= GetAttributes();
164 for (i
= 0; i
< m_tabListCtrl
->GetCount(); i
++)
166 tabs
.Add(wxAtoi(m_tabListCtrl
->GetString(i
)));
173 bool wxRichTextTabsPage::TransferDataToWindow()
175 wxPanel::TransferDataToWindow();
177 wxTextAttrEx
* attr
= GetAttributes();
179 m_tabListCtrl
->Clear();
180 m_tabEditCtrl
->SetValue(wxEmptyString
);
184 m_tabsPresent
= true;
186 for (i
= 0; i
< attr
->GetTabs().GetCount(); i
++)
188 wxString
s(wxString::Format(wxT("%d"), attr
->GetTabs()[i
]));
189 m_tabListCtrl
->Append(s
);
196 static int wxTabSortFunc(int* a
, int* b
)
200 else if ((*b
) < (*a
))
206 /// Sorts the tab array
207 void wxRichTextTabsPage::SortTabs()
211 for (i
= 0; i
< m_tabListCtrl
->GetCount(); i
++)
213 tabs
.Add(wxAtoi(m_tabListCtrl
->GetString(i
)));
215 tabs
.Sort(& wxTabSortFunc
);
217 m_tabListCtrl
->Clear();
218 for (i
= 0; i
< tabs
.GetCount(); i
++)
220 wxString
s(wxString::Format(wxT("%d"), tabs
[i
]));
221 m_tabListCtrl
->Append(s
);
225 wxTextAttrEx
* wxRichTextTabsPage::GetAttributes()
227 return wxRichTextFormattingDialog::GetDialogAttributes(this);
231 * Should we show tooltips?
234 bool wxRichTextTabsPage::ShowToolTips()
240 * Get bitmap resources
243 wxBitmap
wxRichTextTabsPage::GetBitmapResource( const wxString
& name
)
246 ////@begin wxRichTextTabsPage bitmap retrieval
249 ////@end wxRichTextTabsPage bitmap retrieval
256 wxIcon
wxRichTextTabsPage::GetIconResource( const wxString
& name
)
259 ////@begin wxRichTextTabsPage icon retrieval
262 ////@end wxRichTextTabsPage icon retrieval
266 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
269 void wxRichTextTabsPage::OnNewTabClick( wxCommandEvent
& WXUNUSED(event
) )
271 wxString str
= m_tabEditCtrl
->GetValue();
272 if (!str
.empty() && str
.IsNumber())
274 wxString
s(wxString::Format(wxT("%d"), wxAtoi(str
)));
276 m_tabListCtrl
->Append(s
);
277 m_tabsPresent
= true;
284 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
287 void wxRichTextTabsPage::OnNewTabUpdate( wxUpdateUIEvent
& event
)
289 // This may be a bit expensive - consider updating New button when text
290 // changes in edit control
291 wxString str
= m_tabEditCtrl
->GetValue();
292 if (!str
.empty() && str
.IsNumber())
294 wxString
s(wxString::Format(wxT("%d"), wxAtoi(str
)));
295 event
.Enable(m_tabListCtrl
->FindString(s
) == wxNOT_FOUND
);
303 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
306 void wxRichTextTabsPage::OnDeleteTabClick( wxCommandEvent
& WXUNUSED(event
) )
308 if (m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0 && m_tabListCtrl
->GetSelection() != wxNOT_FOUND
)
310 m_tabListCtrl
->Delete(m_tabListCtrl
->GetSelection());
315 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
318 void wxRichTextTabsPage::OnDeleteTabUpdate( wxUpdateUIEvent
& event
)
320 event
.Enable( m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0 && m_tabListCtrl
->GetSelection() != wxNOT_FOUND
);
325 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
328 void wxRichTextTabsPage::OnDeleteAllTabsClick( wxCommandEvent
& WXUNUSED(event
) )
330 if (m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0)
332 m_tabListCtrl
->Clear();
333 m_tabEditCtrl
->SetValue(wxEmptyString
);
338 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
341 void wxRichTextTabsPage::OnDeleteAllTabsUpdate( wxUpdateUIEvent
& event
)
343 event
.Enable( m_tabsPresent
&& m_tabListCtrl
->GetCount() > 0 );
348 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTTABSPAGE_TABLIST
351 void wxRichTextTabsPage::OnTablistSelected( wxCommandEvent
& WXUNUSED(event
) )
353 wxString str
= m_tabListCtrl
->GetStringSelection();
355 m_tabEditCtrl
->SetValue(str
);
358 #endif // wxUSE_RICHTEXT