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