]> git.saurik.com Git - wxWidgets.git/blob - src/richtext/richtexttabspage.cpp
Compilation fir for VC6 after r73124.
[wxWidgets.git] / src / richtext / richtexttabspage.cpp
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 #if wxUSE_RICHTEXT
13
14 #include "wx/richtext/richtexttabspage.h"
15
16 /*!
17 * wxRichTextTabsPage type definition
18 */
19
20 IMPLEMENT_DYNAMIC_CLASS( wxRichTextTabsPage, wxRichTextDialogPage )
21
22 /*!
23 * wxRichTextTabsPage event table definition
24 */
25
26 BEGIN_EVENT_TABLE( wxRichTextTabsPage, wxRichTextDialogPage )
27
28 ////@begin wxRichTextTabsPage event table entries
29 EVT_LISTBOX( ID_RICHTEXTTABSPAGE_TABLIST, wxRichTextTabsPage::OnTablistSelected )
30
31 EVT_BUTTON( ID_RICHTEXTTABSPAGE_NEW_TAB, wxRichTextTabsPage::OnNewTabClick )
32 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_NEW_TAB, wxRichTextTabsPage::OnNewTabUpdate )
33
34 EVT_BUTTON( ID_RICHTEXTTABSPAGE_DELETE_TAB, wxRichTextTabsPage::OnDeleteTabClick )
35 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_DELETE_TAB, wxRichTextTabsPage::OnDeleteTabUpdate )
36
37 EVT_BUTTON( ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS, wxRichTextTabsPage::OnDeleteAllTabsClick )
38 EVT_UPDATE_UI( ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS, wxRichTextTabsPage::OnDeleteAllTabsUpdate )
39
40 ////@end wxRichTextTabsPage event table entries
41
42 END_EVENT_TABLE()
43
44 IMPLEMENT_HELP_PROVISION(wxRichTextTabsPage)
45
46 /*!
47 * wxRichTextTabsPage constructors
48 */
49
50 wxRichTextTabsPage::wxRichTextTabsPage( )
51 {
52 Init();
53 }
54
55 wxRichTextTabsPage::wxRichTextTabsPage( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
56 {
57 Init();
58 Create(parent, id, pos, size, style);
59 }
60
61 /*!
62 * Initialise members
63 */
64
65 void wxRichTextTabsPage::Init()
66 {
67 m_tabsPresent = false;
68
69 ////@begin wxRichTextTabsPage member initialisation
70 m_tabEditCtrl = NULL;
71 m_tabListCtrl = NULL;
72 ////@end wxRichTextTabsPage member initialisation
73 }
74
75 /*!
76 * wxRichTextTabsPage creator
77 */
78
79 bool wxRichTextTabsPage::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
80 {
81 ////@begin wxRichTextTabsPage creation
82 wxRichTextDialogPage::Create( parent, id, pos, size, style );
83
84 CreateControls();
85 if (GetSizer())
86 {
87 GetSizer()->SetSizeHints(this);
88 }
89 Centre();
90 ////@end wxRichTextTabsPage creation
91 return true;
92 }
93
94 /*!
95 * Control creation for wxRichTextTabsPage
96 */
97
98 void wxRichTextTabsPage::CreateControls()
99 {
100 ////@begin wxRichTextTabsPage content construction
101 wxRichTextTabsPage* itemRichTextDialogPage1 = this;
102
103 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
104 itemRichTextDialogPage1->SetSizer(itemBoxSizer2);
105
106 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
107 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
108
109 wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
110 itemBoxSizer3->Add(itemBoxSizer4, 1, wxGROW, 5);
111
112 wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
113 itemBoxSizer4->Add(itemBoxSizer5, 0, wxGROW, 5);
114
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);
117
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);
123
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);
128
129 itemBoxSizer4->Add(2, 1, 1, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5);
130
131 wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxVERTICAL);
132 itemBoxSizer4->Add(itemBoxSizer10, 0, wxGROW, 5);
133
134 wxStaticText* itemStaticText11 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
135 itemBoxSizer10->Add(itemStaticText11, 0, wxALIGN_CENTER_HORIZONTAL|wxBOTTOM, 5);
136
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);
142
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);
148
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);
154
155 ////@end wxRichTextTabsPage content construction
156 }
157
158 /// Transfer data from/to window
159 bool wxRichTextTabsPage::TransferDataFromWindow()
160 {
161 wxPanel::TransferDataFromWindow();
162
163 wxRichTextAttr* attr = GetAttributes();
164
165 if (m_tabsPresent)
166 {
167 wxArrayInt tabs;
168 size_t i;
169 for (i = 0; i < m_tabListCtrl->GetCount(); i++)
170 {
171 tabs.Add(wxAtoi(m_tabListCtrl->GetString(i)));
172 }
173 attr->SetTabs(tabs);
174 }
175 return true;
176 }
177
178 bool wxRichTextTabsPage::TransferDataToWindow()
179 {
180 wxPanel::TransferDataToWindow();
181
182 wxRichTextAttr* attr = GetAttributes();
183
184 m_tabListCtrl->Clear();
185 m_tabEditCtrl->SetValue(wxEmptyString);
186
187 if (attr->HasTabs())
188 {
189 m_tabsPresent = true;
190 size_t i;
191 for (i = 0; i < attr->GetTabs().GetCount(); i++)
192 {
193 wxString s(wxString::Format(wxT("%d"), attr->GetTabs()[i]));
194 m_tabListCtrl->Append(s);
195 }
196 }
197
198 return true;
199 }
200
201 static int wxTabSortFunc(int* a, int* b)
202 {
203 if ((*a) < (*b))
204 return -1;
205 else if ((*b) < (*a))
206 return 1;
207 else
208 return 0;
209 }
210
211 /// Sorts the tab array
212 void wxRichTextTabsPage::SortTabs()
213 {
214 wxArrayInt tabs;
215 size_t i;
216 for (i = 0; i < m_tabListCtrl->GetCount(); i++)
217 {
218 tabs.Add(wxAtoi(m_tabListCtrl->GetString(i)));
219 }
220 tabs.Sort(& wxTabSortFunc);
221
222 m_tabListCtrl->Clear();
223 for (i = 0; i < tabs.GetCount(); i++)
224 {
225 wxString s(wxString::Format(wxT("%d"), tabs[i]));
226 m_tabListCtrl->Append(s);
227 }
228 }
229
230 wxRichTextAttr* wxRichTextTabsPage::GetAttributes()
231 {
232 return wxRichTextFormattingDialog::GetDialogAttributes(this);
233 }
234
235 /*!
236 * Should we show tooltips?
237 */
238
239 bool wxRichTextTabsPage::ShowToolTips()
240 {
241 return wxRichTextFormattingDialog::ShowToolTips();
242 }
243
244 /*!
245 * Get bitmap resources
246 */
247
248 wxBitmap wxRichTextTabsPage::GetBitmapResource( const wxString& name )
249 {
250 // Bitmap retrieval
251 ////@begin wxRichTextTabsPage bitmap retrieval
252 wxUnusedVar(name);
253 return wxNullBitmap;
254 ////@end wxRichTextTabsPage bitmap retrieval
255 }
256
257 /*!
258 * Get icon resources
259 */
260
261 wxIcon wxRichTextTabsPage::GetIconResource( const wxString& name )
262 {
263 // Icon retrieval
264 ////@begin wxRichTextTabsPage icon retrieval
265 wxUnusedVar(name);
266 return wxNullIcon;
267 ////@end wxRichTextTabsPage icon retrieval
268 }
269
270 /*!
271 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
272 */
273
274 void wxRichTextTabsPage::OnNewTabClick( wxCommandEvent& WXUNUSED(event) )
275 {
276 wxString str = m_tabEditCtrl->GetValue();
277 if (!str.empty() && str.IsNumber())
278 {
279 wxString s(wxString::Format(wxT("%d"), wxAtoi(str)));
280
281 m_tabListCtrl->Append(s);
282 m_tabsPresent = true;
283
284 SortTabs();
285 }
286 }
287
288 /*!
289 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_NEW_TAB
290 */
291
292 void wxRichTextTabsPage::OnNewTabUpdate( wxUpdateUIEvent& event )
293 {
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())
298 {
299 wxString s(wxString::Format(wxT("%d"), wxAtoi(str)));
300 event.Enable(m_tabListCtrl->FindString(s) == wxNOT_FOUND);
301 }
302 else
303 event.Enable(false);
304 }
305
306
307 /*!
308 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
309 */
310
311 void wxRichTextTabsPage::OnDeleteTabClick( wxCommandEvent& WXUNUSED(event) )
312 {
313 if (m_tabsPresent && m_tabListCtrl->GetCount() > 0 && m_tabListCtrl->GetSelection() != wxNOT_FOUND)
314 {
315 m_tabListCtrl->Delete(m_tabListCtrl->GetSelection());
316 }
317 }
318
319 /*!
320 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_TAB
321 */
322
323 void wxRichTextTabsPage::OnDeleteTabUpdate( wxUpdateUIEvent& event )
324 {
325 event.Enable( m_tabsPresent && m_tabListCtrl->GetCount() > 0 && m_tabListCtrl->GetSelection() != wxNOT_FOUND );
326 }
327
328
329 /*!
330 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
331 */
332
333 void wxRichTextTabsPage::OnDeleteAllTabsClick( wxCommandEvent& WXUNUSED(event) )
334 {
335 if (m_tabsPresent && m_tabListCtrl->GetCount() > 0)
336 {
337 m_tabListCtrl->Clear();
338 m_tabEditCtrl->SetValue(wxEmptyString);
339 }
340 }
341
342 /*!
343 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTTABSPAGE_DELETE_ALL_TABS
344 */
345
346 void wxRichTextTabsPage::OnDeleteAllTabsUpdate( wxUpdateUIEvent& event )
347 {
348 event.Enable( m_tabsPresent && m_tabListCtrl->GetCount() > 0 );
349 }
350
351
352 /*!
353 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_RICHTEXTTABSPAGE_TABLIST
354 */
355
356 void wxRichTextTabsPage::OnTablistSelected( wxCommandEvent& WXUNUSED(event) )
357 {
358 wxString str = m_tabListCtrl->GetStringSelection();
359 if (!str.empty())
360 m_tabEditCtrl->SetValue(str);
361 }
362
363 #endif // wxUSE_RICHTEXT