]>
Commit | Line | Data |
---|---|---|
dadd4f55 | 1 | ///////////////////////////////////////////////////////////////////////////// |
41a85215 WS |
2 | // Name: src/richtext/richtextstyledlg.cpp |
3 | // Purpose: | |
dadd4f55 | 4 | // Author: Julian Smart |
41a85215 | 5 | // Modified by: |
dadd4f55 | 6 | // Created: 10/5/2006 12:05:31 PM |
41a85215 | 7 | // RCS-ID: $Id$ |
dadd4f55 | 8 | // Copyright: (c) Julian Smart |
41a85215 | 9 | // Licence: wxWindows licence |
dadd4f55 JS |
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 | ||
5c6e84b6 JS |
19 | #if wxUSE_RICHTEXT |
20 | ||
dadd4f55 JS |
21 | #ifndef WX_PRECOMP |
22 | #include "wx/wx.h" | |
23 | #endif | |
24 | ||
dadd4f55 JS |
25 | #include "wx/richtext/richtextstyledlg.h" |
26 | #include "wx/richtext/richtextformatdlg.h" | |
27 | ||
dadd4f55 JS |
28 | /*! |
29 | * wxRichTextStyleOrganiserDialog type definition | |
30 | */ | |
31 | ||
32 | bool wxRichTextStyleOrganiserDialog::sm_showToolTips = false; | |
33 | ||
34 | IMPLEMENT_DYNAMIC_CLASS( wxRichTextStyleOrganiserDialog, wxDialog ) | |
35 | ||
36 | /*! | |
37 | * wxRichTextStyleOrganiserDialog event table definition | |
38 | */ | |
39 | ||
40 | BEGIN_EVENT_TABLE( wxRichTextStyleOrganiserDialog, wxDialog ) | |
41 | ||
42 | EVT_LISTBOX(wxID_ANY, wxRichTextStyleOrganiserDialog::OnListSelection) | |
43 | ||
44 | ////@begin wxRichTextStyleOrganiserDialog event table entries | |
45 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR, wxRichTextStyleOrganiserDialog::OnNewCharClick ) | |
46 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR, wxRichTextStyleOrganiserDialog::OnNewCharUpdate ) | |
47 | ||
48 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA, wxRichTextStyleOrganiserDialog::OnNewParaClick ) | |
49 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA, wxRichTextStyleOrganiserDialog::OnNewParaUpdate ) | |
50 | ||
51 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST, wxRichTextStyleOrganiserDialog::OnNewListClick ) | |
52 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST, wxRichTextStyleOrganiserDialog::OnNewListUpdate ) | |
53 | ||
54 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY, wxRichTextStyleOrganiserDialog::OnApplyClick ) | |
55 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY, wxRichTextStyleOrganiserDialog::OnApplyUpdate ) | |
56 | ||
57 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME, wxRichTextStyleOrganiserDialog::OnRenameClick ) | |
58 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME, wxRichTextStyleOrganiserDialog::OnRenameUpdate ) | |
59 | ||
60 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT, wxRichTextStyleOrganiserDialog::OnEditClick ) | |
61 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT, wxRichTextStyleOrganiserDialog::OnEditUpdate ) | |
62 | ||
63 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE, wxRichTextStyleOrganiserDialog::OnDeleteClick ) | |
64 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE, wxRichTextStyleOrganiserDialog::OnDeleteUpdate ) | |
65 | ||
66 | ////@end wxRichTextStyleOrganiserDialog event table entries | |
67 | ||
68 | END_EVENT_TABLE() | |
69 | ||
70 | /*! | |
71 | * wxRichTextStyleOrganiserDialog constructors | |
72 | */ | |
73 | ||
74 | wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( ) | |
75 | { | |
76 | Init(); | |
77 | } | |
78 | ||
79 | wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( int flags, wxRichTextStyleSheet* sheet, wxRichTextCtrl* ctrl, wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) | |
80 | { | |
81 | Init(); | |
82 | Create(flags, sheet, ctrl, parent, id, caption, pos, size, style); | |
83 | } | |
84 | ||
85 | /*! | |
86 | * Member initialisation for wxSymbolPickerDialog | |
87 | */ | |
88 | ||
89 | void wxRichTextStyleOrganiserDialog::Init() | |
90 | { | |
91 | m_richTextStyleSheet = NULL; | |
92 | m_richTextCtrl = NULL; | |
bcedac44 | 93 | m_dontUpdate = false; |
dadd4f55 JS |
94 | m_flags = 0; |
95 | m_restartNumbering = true; | |
41a85215 | 96 | |
dadd4f55 JS |
97 | ////@begin wxRichTextStyleOrganiserDialog member initialisation |
98 | m_innerSizer = NULL; | |
99 | m_buttonSizerParent = NULL; | |
100 | m_stylesListBox = NULL; | |
101 | m_previewCtrl = NULL; | |
102 | m_buttonSizer = NULL; | |
103 | m_newCharacter = NULL; | |
104 | m_newParagraph = NULL; | |
105 | m_newList = NULL; | |
106 | m_applyStyle = NULL; | |
107 | m_renameStyle = NULL; | |
108 | m_editStyle = NULL; | |
109 | m_deleteStyle = NULL; | |
110 | m_closeButton = NULL; | |
111 | m_bottomButtonSizer = NULL; | |
112 | m_restartNumberingCtrl = NULL; | |
113 | m_okButton = NULL; | |
114 | m_cancelButton = NULL; | |
115 | ////@end wxRichTextStyleOrganiserDialog member initialisation | |
116 | } | |
117 | ||
118 | /*! | |
119 | * wxRichTextStyleOrganiserDialog creator | |
120 | */ | |
121 | ||
122 | bool wxRichTextStyleOrganiserDialog::Create( int flags, wxRichTextStyleSheet* sheet, wxRichTextCtrl* ctrl, wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) | |
123 | { | |
124 | m_richTextStyleSheet = sheet; | |
125 | m_richTextCtrl = ctrl; | |
126 | m_flags = flags; | |
41a85215 | 127 | |
dadd4f55 | 128 | ////@begin wxRichTextStyleOrganiserDialog creation |
ce04fea5 | 129 | SetExtraStyle(wxWS_EX_BLOCK_EVENTS|wxDIALOG_EX_CONTEXTHELP); |
dadd4f55 JS |
130 | wxDialog::Create( parent, id, caption, pos, size, style ); |
131 | ||
132 | CreateControls(); | |
133 | if (GetSizer()) | |
134 | { | |
135 | GetSizer()->SetSizeHints(this); | |
136 | } | |
137 | Centre(); | |
138 | ////@end wxRichTextStyleOrganiserDialog creation | |
139 | return true; | |
140 | } | |
141 | ||
142 | /*! | |
143 | * Control creation for wxRichTextStyleOrganiserDialog | |
144 | */ | |
145 | ||
146 | void wxRichTextStyleOrganiserDialog::CreateControls() | |
41a85215 | 147 | { |
dadd4f55 JS |
148 | bool hideTypeSelector = false; |
149 | wxRichTextStyleListBox::wxRichTextStyleType typesToShow = wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL; | |
41a85215 | 150 | |
dadd4f55 JS |
151 | if ((m_flags & wxRICHTEXT_ORGANISER_SHOW_CHARACTER) != 0) |
152 | { | |
153 | typesToShow = wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER; | |
154 | hideTypeSelector = true; | |
155 | } | |
156 | else if ((m_flags & wxRICHTEXT_ORGANISER_SHOW_PARAGRAPH) != 0) | |
157 | { | |
158 | typesToShow = wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH; | |
159 | hideTypeSelector = true; | |
160 | } | |
161 | else if ((m_flags & wxRICHTEXT_ORGANISER_SHOW_LIST) != 0) | |
162 | { | |
163 | typesToShow = wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST; | |
164 | hideTypeSelector = true; | |
165 | } | |
166 | else | |
167 | { | |
168 | // wxRICHTEXT_ORGANISER_SHOW_ALL is implied if the other styles aren't included | |
169 | } | |
41a85215 | 170 | |
dadd4f55 JS |
171 | long listCtrlStyle = 0; |
172 | if (hideTypeSelector) | |
173 | listCtrlStyle = wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR; | |
41a85215 | 174 | |
dadd4f55 JS |
175 | ////@begin wxRichTextStyleOrganiserDialog content construction |
176 | wxRichTextStyleOrganiserDialog* itemDialog1 = this; | |
177 | ||
178 | wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); | |
179 | itemDialog1->SetSizer(itemBoxSizer2); | |
180 | ||
181 | m_innerSizer = new wxBoxSizer(wxVERTICAL); | |
182 | itemBoxSizer2->Add(m_innerSizer, 1, wxGROW|wxALL, 5); | |
183 | ||
184 | m_buttonSizerParent = new wxBoxSizer(wxHORIZONTAL); | |
185 | m_innerSizer->Add(m_buttonSizerParent, 1, wxGROW, 5); | |
186 | ||
187 | wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL); | |
188 | m_buttonSizerParent->Add(itemBoxSizer5, 1, wxGROW, 5); | |
189 | ||
190 | wxStaticText* itemStaticText6 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Styles:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 191 | itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
dadd4f55 | 192 | |
2fce6547 | 193 | m_stylesListBox = new wxRichTextStyleListCtrl( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_STYLES, wxDefaultPosition, wxSize(280, 260), listCtrlStyle ); |
dadd4f55 | 194 | m_stylesListBox->SetHelpText(_("The available styles.")); |
ce04fea5 | 195 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
196 | m_stylesListBox->SetToolTip(_("The available styles.")); |
197 | itemBoxSizer5->Add(m_stylesListBox, 1, wxGROW|wxALL, 5); | |
198 | ||
199 | wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxVERTICAL); | |
200 | m_buttonSizerParent->Add(itemBoxSizer8, 0, wxGROW, 5); | |
201 | ||
ce04fea5 JS |
202 | wxStaticText* itemStaticText9 = new wxStaticText( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE, _(" "), wxDefaultPosition, wxDefaultSize, 0 ); |
203 | itemBoxSizer8->Add(itemStaticText9, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5); | |
dadd4f55 | 204 | |
2fce6547 | 205 | m_previewCtrl = new wxRichTextCtrl( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_PREVIEW, wxEmptyString, wxDefaultPosition, wxSize(250, 200), wxVSCROLL|wxTE_READONLY ); |
dadd4f55 | 206 | m_previewCtrl->SetHelpText(_("The style preview.")); |
ce04fea5 | 207 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
208 | m_previewCtrl->SetToolTip(_("The style preview.")); |
209 | itemBoxSizer8->Add(m_previewCtrl, 1, wxGROW|wxALL, 5); | |
210 | ||
211 | m_buttonSizer = new wxBoxSizer(wxVERTICAL); | |
212 | m_buttonSizerParent->Add(m_buttonSizer, 0, wxGROW, 5); | |
213 | ||
214 | wxStaticText* itemStaticText12 = new wxStaticText( itemDialog1, wxID_STATIC, _(" "), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 215 | m_buttonSizer->Add(itemStaticText12, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
dadd4f55 JS |
216 | |
217 | m_newCharacter = new wxButton( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR, _("New &Character Style..."), wxDefaultPosition, wxDefaultSize, 0 ); | |
218 | m_newCharacter->SetHelpText(_("Click to create a new character style.")); | |
ce04fea5 | 219 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
220 | m_newCharacter->SetToolTip(_("Click to create a new character style.")); |
221 | m_buttonSizer->Add(m_newCharacter, 0, wxGROW|wxALL, 5); | |
222 | ||
223 | m_newParagraph = new wxButton( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA, _("New &Paragraph Style..."), wxDefaultPosition, wxDefaultSize, 0 ); | |
224 | m_newParagraph->SetHelpText(_("Click to create a new paragraph style.")); | |
ce04fea5 | 225 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
226 | m_newParagraph->SetToolTip(_("Click to create a new paragraph style.")); |
227 | m_buttonSizer->Add(m_newParagraph, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); | |
228 | ||
229 | m_newList = new wxButton( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST, _("New &List Style..."), wxDefaultPosition, wxDefaultSize, 0 ); | |
230 | m_newList->SetHelpText(_("Click to create a new list style.")); | |
ce04fea5 | 231 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
232 | m_newList->SetToolTip(_("Click to create a new list style.")); |
233 | m_buttonSizer->Add(m_newList, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); | |
234 | ||
235 | m_buttonSizer->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); | |
236 | ||
237 | m_applyStyle = new wxButton( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY, _("&Apply Style"), wxDefaultPosition, wxDefaultSize, 0 ); | |
238 | m_applyStyle->SetHelpText(_("Click to apply the selected style.")); | |
ce04fea5 | 239 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
240 | m_applyStyle->SetToolTip(_("Click to apply the selected style.")); |
241 | m_buttonSizer->Add(m_applyStyle, 0, wxGROW|wxALL, 5); | |
242 | ||
243 | m_renameStyle = new wxButton( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME, _("&Rename Style..."), wxDefaultPosition, wxDefaultSize, 0 ); | |
244 | m_renameStyle->SetHelpText(_("Click to rename the selected style.")); | |
ce04fea5 | 245 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
246 | m_renameStyle->SetToolTip(_("Click to rename the selected style.")); |
247 | m_buttonSizer->Add(m_renameStyle, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); | |
248 | ||
249 | m_editStyle = new wxButton( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT, _("&Edit Style..."), wxDefaultPosition, wxDefaultSize, 0 ); | |
250 | m_editStyle->SetHelpText(_("Click to edit the selected style.")); | |
ce04fea5 | 251 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
252 | m_editStyle->SetToolTip(_("Click to edit the selected style.")); |
253 | m_buttonSizer->Add(m_editStyle, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); | |
254 | ||
255 | m_deleteStyle = new wxButton( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE, _("&Delete Style..."), wxDefaultPosition, wxDefaultSize, 0 ); | |
256 | m_deleteStyle->SetHelpText(_("Click to delete the selected style.")); | |
ce04fea5 | 257 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
258 | m_deleteStyle->SetToolTip(_("Click to delete the selected style.")); |
259 | m_buttonSizer->Add(m_deleteStyle, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); | |
260 | ||
261 | m_buttonSizer->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); | |
262 | ||
263 | m_closeButton = new wxButton( itemDialog1, wxID_CANCEL, _("Close"), wxDefaultPosition, wxDefaultSize, 0 ); | |
264 | m_closeButton->SetDefault(); | |
265 | m_closeButton->SetHelpText(_("Click to close this window.")); | |
ce04fea5 | 266 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
267 | m_closeButton->SetToolTip(_("Click to close this window.")); |
268 | m_buttonSizer->Add(m_closeButton, 0, wxGROW|wxALL, 5); | |
269 | ||
270 | m_bottomButtonSizer = new wxBoxSizer(wxHORIZONTAL); | |
271 | m_innerSizer->Add(m_bottomButtonSizer, 0, wxGROW, 5); | |
272 | ||
273 | m_restartNumberingCtrl = new wxCheckBox( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_RESTART_NUMBERING, _("&Restart numbering"), wxDefaultPosition, wxDefaultSize, 0 ); | |
274 | m_restartNumberingCtrl->SetValue(false); | |
275 | m_restartNumberingCtrl->SetHelpText(_("Check to restart numbering.")); | |
ce04fea5 | 276 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
277 | m_restartNumberingCtrl->SetToolTip(_("Check to restart numbering.")); |
278 | m_bottomButtonSizer->Add(m_restartNumberingCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
279 | ||
280 | m_bottomButtonSizer->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
281 | ||
282 | m_okButton = new wxButton( itemDialog1, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 ); | |
283 | m_okButton->SetDefault(); | |
284 | m_okButton->SetHelpText(_("Click to confirm your selection.")); | |
ce04fea5 | 285 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
286 | m_okButton->SetToolTip(_("Click to confirm your selection.")); |
287 | m_bottomButtonSizer->Add(m_okButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
288 | ||
289 | m_cancelButton = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); | |
290 | m_cancelButton->SetHelpText(_("Click to cancel this window.")); | |
ce04fea5 | 291 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
292 | m_cancelButton->SetToolTip(_("Click to cancel this window.")); |
293 | m_bottomButtonSizer->Add(m_cancelButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
294 | ||
295 | ////@end wxRichTextStyleOrganiserDialog content construction | |
296 | ||
297 | if ((m_flags & wxRICHTEXT_ORGANISER_CREATE_STYLES) == 0) | |
298 | { | |
299 | m_buttonSizer->Show(m_newCharacter, false); | |
300 | m_buttonSizer->Show(m_newParagraph, false); | |
301 | m_buttonSizer->Show(m_newList, false); | |
302 | } | |
303 | if ((m_flags & wxRICHTEXT_ORGANISER_DELETE_STYLES) == 0) | |
304 | { | |
305 | m_buttonSizer->Show(m_deleteStyle, false); | |
306 | } | |
307 | if ((m_flags & wxRICHTEXT_ORGANISER_APPLY_STYLES) == 0) | |
308 | { | |
309 | m_buttonSizer->Show(m_applyStyle, false); | |
310 | } | |
311 | if ((m_flags & wxRICHTEXT_ORGANISER_EDIT_STYLES) == 0) | |
312 | { | |
313 | m_buttonSizer->Show(m_editStyle, false); | |
314 | } | |
315 | if ((m_flags & wxRICHTEXT_ORGANISER_RENAME_STYLES) == 0) | |
316 | { | |
317 | m_buttonSizer->Show(m_renameStyle, false); | |
318 | } | |
319 | if ((m_flags & wxRICHTEXT_ORGANISER_RENUMBER) == 0) | |
320 | { | |
321 | m_bottomButtonSizer->Show(m_restartNumberingCtrl, false); | |
322 | } | |
323 | ||
324 | if ((m_flags & wxRICHTEXT_ORGANISER_OK_CANCEL) == 0) | |
325 | { | |
326 | m_bottomButtonSizer->Show(m_okButton, false); | |
327 | m_bottomButtonSizer->Show(m_cancelButton, false); | |
328 | } | |
329 | else | |
330 | { | |
331 | m_buttonSizer->Show(m_closeButton, false); | |
332 | } | |
333 | ||
334 | // No buttons in the vertical group are shown, so hide the whole sizer | |
335 | if ((m_flags & wxRICHTEXT_ORGANISER_ORGANISE) == 0) | |
336 | { | |
337 | m_buttonSizerParent->Show(m_buttonSizer, false); | |
338 | } | |
41a85215 | 339 | |
dadd4f55 JS |
340 | // No buttons in the horizontal group are shown, so hide the whole sizer |
341 | if ((m_flags & (wxRICHTEXT_ORGANISER_OK_CANCEL|wxRICHTEXT_ORGANISER_RENUMBER)) == 0) | |
342 | { | |
343 | m_innerSizer->Show(m_bottomButtonSizer, false); | |
344 | } | |
41a85215 | 345 | |
dadd4f55 JS |
346 | if (hideTypeSelector) |
347 | { | |
348 | m_stylesListBox->GetStyleListBox()->SetStyleType(typesToShow); | |
349 | } | |
41a85215 | 350 | |
dadd4f55 JS |
351 | m_stylesListBox->SetStyleSheet(m_richTextStyleSheet); |
352 | m_stylesListBox->SetRichTextCtrl(m_richTextCtrl); | |
353 | m_stylesListBox->UpdateStyles(); | |
354 | m_stylesListBox->GetStyleListBox()->SetAutoSetSelection(false); // stop idle-time auto selection | |
355 | if (m_stylesListBox->GetStyleListBox()->GetItemCount() > 0) | |
356 | { | |
357 | m_stylesListBox->GetStyleListBox()->SetSelection(0); | |
358 | ShowPreview(); | |
359 | } | |
360 | } | |
361 | ||
362 | /*! | |
363 | * Should we show tooltips? | |
364 | */ | |
365 | ||
366 | /// Get selected style name or definition | |
367 | wxString wxRichTextStyleOrganiserDialog::GetSelectedStyle() const | |
368 | { | |
369 | wxRichTextStyleDefinition* def = GetSelectedStyleDefinition(); | |
370 | if (def) | |
371 | return def->GetName(); | |
372 | else | |
373 | return wxEmptyString; | |
374 | } | |
375 | ||
376 | wxRichTextStyleDefinition* wxRichTextStyleOrganiserDialog::GetSelectedStyleDefinition() const | |
377 | { | |
378 | int sel = m_stylesListBox->GetStyleListBox()->GetSelection(); | |
379 | return m_stylesListBox->GetStyleListBox()->GetStyle(sel); | |
380 | } | |
381 | ||
382 | ||
383 | /// Transfer data from/to window | |
384 | bool wxRichTextStyleOrganiserDialog::TransferDataFromWindow() | |
385 | { | |
386 | if (!wxDialog::TransferDataFromWindow()) | |
387 | return false; | |
41a85215 | 388 | |
dadd4f55 | 389 | m_restartNumbering = m_restartNumberingCtrl->GetValue(); |
41a85215 | 390 | |
dadd4f55 JS |
391 | return true; |
392 | } | |
393 | ||
394 | bool wxRichTextStyleOrganiserDialog::TransferDataToWindow() | |
395 | { | |
396 | if (!wxDialog::TransferDataToWindow()) | |
397 | return false; | |
41a85215 | 398 | |
dadd4f55 | 399 | m_restartNumberingCtrl->SetValue(m_restartNumbering); |
41a85215 | 400 | |
dadd4f55 JS |
401 | return true; |
402 | } | |
403 | ||
404 | /// Show preview for given or selected preview | |
405 | void wxRichTextStyleOrganiserDialog::ShowPreview(int sel) | |
406 | { | |
407 | static const wxChar* s_para1 = wxT("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \ | |
c268eb32 | 408 | Nullam ante sapien, vestibulum nonummy, pulvinar sed, luctus ut, lacus.\n"); |
dadd4f55 | 409 | |
c268eb32 | 410 | static const wxChar* s_para2List = wxT("Duis pharetra consequat dui. Nullam vitae justo id mauris lobortis interdum.\n"); |
dadd4f55 JS |
411 | |
412 | static const wxChar* s_para2 = wxT("Duis pharetra consequat dui. Cum sociis natoque penatibus \ | |
c268eb32 | 413 | et magnis dis parturient montes, nascetur ridiculus mus. Nullam vitae justo id mauris lobortis interdum.\n"); |
dadd4f55 | 414 | |
c268eb32 | 415 | static const wxChar* s_para3 = wxT("Integer convallis dolor at augue \ |
dadd4f55 JS |
416 | iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n"); |
417 | ||
418 | if (sel == -1) | |
419 | { | |
420 | sel = m_stylesListBox->GetStyleListBox()->GetSelection(); | |
421 | if (sel == -1) | |
41a85215 | 422 | return; |
dadd4f55 JS |
423 | } |
424 | ||
425 | wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); | |
41a85215 | 426 | |
dadd4f55 | 427 | wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition); |
336d8ae9 | 428 | |
ce04fea5 JS |
429 | wxStaticText* labelCtrl = (wxStaticText*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE); |
430 | if (labelCtrl) | |
431 | labelCtrl->SetLabel(def->GetName() + wxT(":")); | |
432 | ||
24777478 | 433 | wxRichTextAttr attr(def->GetStyleMergedWithBase(GetStyleSheet())); |
dadd4f55 JS |
434 | |
435 | wxFont font(m_previewCtrl->GetFont()); | |
436 | font.SetPointSize(9); | |
437 | m_previewCtrl->SetFont(font); | |
438 | ||
24777478 | 439 | wxRichTextAttr normalParaAttr; |
dadd4f55 JS |
440 | normalParaAttr.SetFont(font); |
441 | normalParaAttr.SetTextColour(wxColour(wxT("LIGHT GREY"))); | |
442 | ||
443 | m_previewCtrl->Freeze(); | |
41a85215 | 444 | m_previewCtrl->Clear(); |
dadd4f55 JS |
445 | |
446 | m_previewCtrl->BeginStyle(normalParaAttr); | |
447 | m_previewCtrl->WriteText(s_para1); | |
448 | m_previewCtrl->EndStyle(); | |
41a85215 | 449 | |
dadd4f55 | 450 | m_previewCtrl->BeginStyle(attr); |
41a85215 | 451 | |
dadd4f55 JS |
452 | if (listDef) |
453 | { | |
d2d0adc7 | 454 | long listStart = m_previewCtrl->GetInsertionPoint() + 1; |
dadd4f55 JS |
455 | int i; |
456 | for (i = 0; i < 10; i++) | |
457 | { | |
24777478 | 458 | wxRichTextAttr levelAttr = * listDef->GetLevelAttributes(i); |
dadd4f55 JS |
459 | levelAttr.SetBulletNumber(1); |
460 | m_previewCtrl->BeginStyle(levelAttr); | |
c268eb32 | 461 | m_previewCtrl->WriteText(wxString::Format(wxT("List level %d. "), i+1) + s_para2List); |
dadd4f55 JS |
462 | m_previewCtrl->EndStyle(); |
463 | } | |
d2d0adc7 JS |
464 | long listEnd = m_previewCtrl->GetInsertionPoint(); |
465 | m_previewCtrl->NumberList(wxRichTextRange(listStart, listEnd), listDef); | |
dadd4f55 JS |
466 | } |
467 | else | |
468 | { | |
c268eb32 | 469 | m_previewCtrl->WriteText(s_para2); |
dadd4f55 | 470 | } |
41a85215 | 471 | |
dadd4f55 JS |
472 | m_previewCtrl->EndStyle(); |
473 | ||
474 | m_previewCtrl->BeginStyle(normalParaAttr); | |
475 | m_previewCtrl->WriteText(s_para3); | |
476 | m_previewCtrl->EndStyle(); | |
477 | ||
478 | m_previewCtrl->Thaw(); | |
479 | } | |
41a85215 | 480 | |
dadd4f55 JS |
481 | /// Clears the preview |
482 | void wxRichTextStyleOrganiserDialog::ClearPreview() | |
483 | { | |
5bbdfd5b | 484 | m_previewCtrl->Clear(); |
ce04fea5 JS |
485 | wxStaticText* labelCtrl = (wxStaticText*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE); |
486 | if (labelCtrl) | |
487 | labelCtrl->SetLabel(wxEmptyString); | |
dadd4f55 JS |
488 | } |
489 | ||
490 | bool wxRichTextStyleOrganiserDialog::ApplyStyle(wxRichTextCtrl* ctrl) | |
491 | { | |
492 | int sel = m_stylesListBox->GetStyleListBox()->GetSelection(); | |
493 | if (sel == -1) | |
494 | return false; | |
495 | if (!ctrl) | |
496 | ctrl = GetRichTextCtrl(); | |
497 | if (!ctrl) | |
498 | return false; | |
499 | if (!ctrl->HasSelection()) | |
500 | return false; | |
dadd4f55 | 501 | |
41a85215 WS |
502 | |
503 | wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); | |
dadd4f55 JS |
504 | wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition); |
505 | ||
506 | if (listDef && m_restartNumberingCtrl->GetValue()) | |
507 | { | |
508 | wxRichTextRange range = ctrl->GetSelectionRange(); | |
509 | return ctrl->SetListStyle(range, listDef, wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_RENUMBER); | |
510 | } | |
511 | else | |
512 | { | |
513 | return ctrl->ApplyStyle(def); | |
514 | } | |
515 | } | |
516 | ||
517 | /*! | |
518 | * Get bitmap resources | |
519 | */ | |
520 | ||
521 | wxBitmap wxRichTextStyleOrganiserDialog::GetBitmapResource( const wxString& name ) | |
522 | { | |
523 | // Bitmap retrieval | |
524 | ////@begin wxRichTextStyleOrganiserDialog bitmap retrieval | |
525 | wxUnusedVar(name); | |
526 | return wxNullBitmap; | |
527 | ////@end wxRichTextStyleOrganiserDialog bitmap retrieval | |
528 | } | |
529 | ||
530 | /*! | |
531 | * Get icon resources | |
532 | */ | |
533 | ||
534 | wxIcon wxRichTextStyleOrganiserDialog::GetIconResource( const wxString& name ) | |
535 | { | |
536 | // Icon retrieval | |
537 | ////@begin wxRichTextStyleOrganiserDialog icon retrieval | |
538 | wxUnusedVar(name); | |
539 | return wxNullIcon; | |
540 | ////@end wxRichTextStyleOrganiserDialog icon retrieval | |
541 | } | |
542 | ||
543 | /*! | |
544 | * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY | |
545 | */ | |
546 | ||
547 | void wxRichTextStyleOrganiserDialog::OnApplyClick( wxCommandEvent& WXUNUSED(event) ) | |
548 | { | |
549 | ApplyStyle(); | |
550 | } | |
551 | ||
552 | /*! | |
553 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY | |
554 | */ | |
555 | ||
556 | void wxRichTextStyleOrganiserDialog::OnApplyUpdate( wxUpdateUIEvent& event ) | |
557 | { | |
558 | event.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_APPLY_STYLES) != 0) && m_stylesListBox->GetStyleListBox()->GetSelection() != wxNOT_FOUND); | |
559 | } | |
560 | ||
561 | ||
562 | /*! | |
563 | * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR | |
564 | */ | |
565 | ||
566 | void wxRichTextStyleOrganiserDialog::OnNewCharClick( wxCommandEvent& WXUNUSED(event) ) | |
567 | { | |
568 | wxString styleName = wxGetTextFromUser(_("Enter a character style name"), _("New Style")); | |
569 | if (!styleName.IsEmpty()) | |
570 | { | |
571 | if (GetStyleSheet()->FindCharacterStyle(styleName)) | |
572 | { | |
573 | wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); | |
574 | return; | |
575 | } | |
41a85215 | 576 | |
dadd4f55 | 577 | wxRichTextCharacterStyleDefinition* style = new wxRichTextCharacterStyleDefinition(styleName); |
41a85215 | 578 | |
dadd4f55 JS |
579 | int pages = wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_STYLE_EDITOR; |
580 | wxRichTextFormattingDialog formatDlg; | |
581 | formatDlg.SetStyleDefinition(*style, GetStyleSheet()); | |
582 | formatDlg.Create(pages, this); | |
583 | ||
584 | if (formatDlg.ShowModal() == wxID_OK) | |
585 | { | |
586 | wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextCharacterStyleDefinition); | |
41a85215 | 587 | |
dadd4f55 | 588 | (*((wxRichTextCharacterStyleDefinition* ) style)) = (*charDef); |
41a85215 | 589 | |
dadd4f55 JS |
590 | GetStyleSheet()->AddCharacterStyle(style); |
591 | ||
592 | m_stylesListBox->UpdateStyles(); | |
593 | ShowPreview(); | |
594 | } | |
595 | else | |
596 | delete style; | |
41a85215 | 597 | } |
dadd4f55 JS |
598 | } |
599 | ||
600 | /*! | |
601 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR | |
602 | */ | |
603 | ||
604 | void wxRichTextStyleOrganiserDialog::OnNewCharUpdate( wxUpdateUIEvent& event ) | |
605 | { | |
606 | event.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES) != 0); | |
607 | } | |
608 | ||
609 | ||
610 | /*! | |
611 | * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA | |
612 | */ | |
613 | ||
614 | void wxRichTextStyleOrganiserDialog::OnNewParaClick( wxCommandEvent& WXUNUSED(event) ) | |
615 | { | |
616 | wxString styleName = wxGetTextFromUser(_("Enter a paragraph style name"), _("New Style")); | |
617 | if (!styleName.IsEmpty()) | |
618 | { | |
619 | if (GetStyleSheet()->FindParagraphStyle(styleName)) | |
620 | { | |
621 | wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); | |
622 | return; | |
623 | } | |
41a85215 | 624 | |
dadd4f55 | 625 | wxRichTextParagraphStyleDefinition* style = new wxRichTextParagraphStyleDefinition(styleName); |
41a85215 | 626 | |
dadd4f55 JS |
627 | int pages = wxRICHTEXT_FORMAT_STYLE_EDITOR|wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_INDENTS_SPACING|wxRICHTEXT_FORMAT_TABS|wxRICHTEXT_FORMAT_BULLETS; |
628 | wxRichTextFormattingDialog formatDlg; | |
629 | formatDlg.SetStyleDefinition(*style, GetStyleSheet()); | |
630 | formatDlg.Create(pages, this); | |
631 | ||
632 | if (formatDlg.ShowModal() == wxID_OK) | |
633 | { | |
634 | wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextParagraphStyleDefinition); | |
41a85215 | 635 | |
dadd4f55 | 636 | (*((wxRichTextParagraphStyleDefinition* ) style)) = (*paraDef); |
41a85215 | 637 | |
dadd4f55 JS |
638 | GetStyleSheet()->AddParagraphStyle(style); |
639 | ||
640 | m_stylesListBox->UpdateStyles(); | |
641 | ShowPreview(); | |
642 | } | |
643 | else | |
644 | delete style; | |
41a85215 | 645 | } |
dadd4f55 JS |
646 | } |
647 | ||
648 | /*! | |
649 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA | |
650 | */ | |
651 | ||
652 | void wxRichTextStyleOrganiserDialog::OnNewParaUpdate( wxUpdateUIEvent& event ) | |
653 | { | |
654 | event.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES) != 0); | |
655 | } | |
656 | ||
657 | ||
658 | /*! | |
659 | * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT | |
660 | */ | |
661 | ||
662 | void wxRichTextStyleOrganiserDialog::OnEditClick( wxCommandEvent& WXUNUSED(event) ) | |
663 | { | |
664 | int sel = m_stylesListBox->GetStyleListBox()->GetSelection(); | |
665 | if (sel != wxNOT_FOUND) | |
666 | { | |
667 | wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); | |
41a85215 | 668 | |
dadd4f55 | 669 | int pages = wxRICHTEXT_FORMAT_STYLE_EDITOR; |
41a85215 | 670 | |
dadd4f55 JS |
671 | if (def->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition))) |
672 | { | |
673 | pages |= wxRICHTEXT_FORMAT_FONT; | |
674 | } | |
675 | else if (def->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition))) | |
676 | { | |
677 | pages |= wxRICHTEXT_FORMAT_LIST_STYLE|wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_INDENTS_SPACING; | |
678 | } | |
679 | else if (def->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition))) | |
680 | { | |
681 | pages |= wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_INDENTS_SPACING|wxRICHTEXT_FORMAT_TABS|wxRICHTEXT_FORMAT_BULLETS; | |
682 | } | |
41a85215 | 683 | |
dadd4f55 JS |
684 | wxRichTextFormattingDialog formatDlg; |
685 | formatDlg.SetStyleDefinition(*def, GetStyleSheet()); | |
686 | formatDlg.Create(pages, this); | |
687 | ||
688 | if (formatDlg.ShowModal() == wxID_OK) | |
689 | { | |
690 | wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextParagraphStyleDefinition); | |
691 | wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextCharacterStyleDefinition); | |
692 | wxRichTextListStyleDefinition* listDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextListStyleDefinition); | |
41a85215 | 693 | |
dadd4f55 JS |
694 | if (listDef) |
695 | { | |
696 | (*((wxRichTextListStyleDefinition* ) def)) = (*listDef); | |
697 | } | |
698 | else if (paraDef) | |
699 | { | |
700 | (*((wxRichTextParagraphStyleDefinition* ) def)) = (*paraDef); | |
701 | } | |
702 | else | |
703 | { | |
704 | (*((wxRichTextCharacterStyleDefinition* ) def)) = (*charDef); | |
705 | } | |
706 | ||
707 | m_stylesListBox->UpdateStyles(); | |
e5cda2df | 708 | m_stylesListBox->GetStyleListBox()->SetSelection(sel); |
dadd4f55 JS |
709 | ShowPreview(); |
710 | } | |
711 | } | |
712 | } | |
713 | ||
714 | /*! | |
715 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT | |
716 | */ | |
717 | ||
718 | void wxRichTextStyleOrganiserDialog::OnEditUpdate( wxUpdateUIEvent& event ) | |
719 | { | |
720 | event.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_EDIT_STYLES) != 0) && m_stylesListBox->GetStyleListBox()->GetSelection() != wxNOT_FOUND); | |
721 | } | |
722 | ||
723 | ||
724 | /*! | |
725 | * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE | |
726 | */ | |
727 | ||
728 | void wxRichTextStyleOrganiserDialog::OnDeleteClick( wxCommandEvent& WXUNUSED(event) ) | |
729 | { | |
730 | int sel = m_stylesListBox->GetStyleListBox()->GetSelection(); | |
731 | if (sel != wxNOT_FOUND) | |
732 | { | |
733 | wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); | |
734 | wxString name(def->GetName()); | |
86501081 | 735 | if (wxYES == wxMessageBox(wxString::Format(_("Delete style %s?"), name), _("Delete Style"), wxYES_NO|wxICON_QUESTION, this)) |
dadd4f55 JS |
736 | { |
737 | m_stylesListBox->GetStyleListBox()->SetItemCount(0); | |
41a85215 | 738 | |
dadd4f55 JS |
739 | if (def->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition))) |
740 | GetStyleSheet()->RemoveListStyle((wxRichTextListStyleDefinition*) def, true); | |
741 | else if (def->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition))) | |
742 | GetStyleSheet()->RemoveParagraphStyle((wxRichTextParagraphStyleDefinition*) def, true); | |
743 | else if (def->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition))) | |
744 | GetStyleSheet()->RemoveCharacterStyle((wxRichTextCharacterStyleDefinition*) def, true); | |
41a85215 | 745 | |
dadd4f55 JS |
746 | m_stylesListBox->UpdateStyles(); |
747 | ||
748 | if (m_stylesListBox->GetStyleListBox()->GetSelection() != -1) | |
749 | ShowPreview(); | |
750 | else | |
751 | ClearPreview(); | |
752 | } | |
753 | } | |
754 | } | |
755 | ||
756 | /*! | |
757 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE | |
758 | */ | |
759 | ||
760 | void wxRichTextStyleOrganiserDialog::OnDeleteUpdate( wxUpdateUIEvent& event ) | |
761 | { | |
762 | event.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_DELETE_STYLES) != 0) && m_stylesListBox->GetStyleListBox()->GetSelection() != wxNOT_FOUND); | |
763 | } | |
764 | ||
765 | /*! | |
766 | * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST | |
767 | */ | |
768 | ||
769 | void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent& WXUNUSED(event) ) | |
770 | { | |
771 | wxString styleName = wxGetTextFromUser(_("Enter a list style name"), _("New Style")); | |
772 | if (!styleName.IsEmpty()) | |
773 | { | |
774 | if (GetStyleSheet()->FindListStyle(styleName)) | |
775 | { | |
776 | wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); | |
777 | return; | |
778 | } | |
41a85215 | 779 | |
dadd4f55 | 780 | wxRichTextListStyleDefinition* style = new wxRichTextListStyleDefinition(styleName); |
41a85215 | 781 | |
dadd4f55 JS |
782 | // Initialize the style to make it easier to edit |
783 | int i; | |
784 | for (i = 0; i < 10; i++) | |
785 | { | |
786 | wxString bulletSymbol; | |
787 | if (i == 0) | |
788 | bulletSymbol = wxT("*"); | |
789 | else if (i == 1) | |
790 | bulletSymbol = wxT("-"); | |
791 | else if (i == 2) | |
792 | bulletSymbol = wxT("*"); | |
793 | else if (i == 3) | |
794 | bulletSymbol = wxT("-"); | |
795 | else | |
796 | bulletSymbol = wxT("*"); | |
797 | ||
798 | style->SetAttributes(i, (i+1)*60, 60, wxTEXT_ATTR_BULLET_STYLE_SYMBOL, bulletSymbol); | |
799 | } | |
41a85215 | 800 | |
dadd4f55 JS |
801 | int pages = wxRICHTEXT_FORMAT_LIST_STYLE|wxRICHTEXT_FORMAT_STYLE_EDITOR|wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_INDENTS_SPACING; |
802 | wxRichTextFormattingDialog formatDlg; | |
803 | formatDlg.SetStyleDefinition(*style, GetStyleSheet()); | |
804 | formatDlg.Create(pages, this); | |
805 | ||
806 | if (formatDlg.ShowModal() == wxID_OK) | |
807 | { | |
808 | wxRichTextListStyleDefinition* listDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextListStyleDefinition); | |
41a85215 | 809 | |
dadd4f55 | 810 | (*((wxRichTextListStyleDefinition* ) style)) = (*listDef); |
41a85215 | 811 | |
dadd4f55 JS |
812 | GetStyleSheet()->AddListStyle(style); |
813 | ||
814 | m_stylesListBox->UpdateStyles(); | |
815 | ShowPreview(); | |
816 | } | |
817 | else | |
818 | delete style; | |
41a85215 | 819 | } |
dadd4f55 JS |
820 | } |
821 | ||
822 | /*! | |
823 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST | |
824 | */ | |
825 | ||
826 | void wxRichTextStyleOrganiserDialog::OnNewListUpdate( wxUpdateUIEvent& event ) | |
827 | { | |
828 | event.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES) != 0); | |
829 | } | |
830 | ||
831 | /*! | |
832 | * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME | |
833 | */ | |
834 | ||
835 | void wxRichTextStyleOrganiserDialog::OnRenameClick( wxCommandEvent& WXUNUSED(event) ) | |
836 | { | |
5bbdfd5b JS |
837 | int sel = m_stylesListBox->GetStyleListBox()->GetSelection(); |
838 | if (sel == -1) | |
839 | return; | |
840 | wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); | |
841 | if (!def) | |
842 | return; | |
843 | ||
844 | wxString styleName = wxGetTextFromUser(_("Enter a new style name"), _("New Style"), def->GetName()); | |
845 | if (!styleName.IsEmpty()) | |
846 | { | |
847 | if (styleName == def->GetName()) | |
848 | return; | |
849 | ||
850 | if (GetStyleSheet()->FindParagraphStyle(styleName) || GetStyleSheet()->FindCharacterStyle(styleName) || GetStyleSheet()->FindListStyle(styleName)) | |
851 | { | |
852 | wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); | |
853 | return; | |
854 | } | |
855 | ||
856 | def->SetName(styleName); | |
857 | m_stylesListBox->UpdateStyles(); | |
858 | } | |
dadd4f55 JS |
859 | } |
860 | ||
861 | /*! | |
862 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME | |
863 | */ | |
864 | ||
865 | void wxRichTextStyleOrganiserDialog::OnRenameUpdate( wxUpdateUIEvent& event ) | |
866 | { | |
867 | event.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_RENAME_STYLES) != 0) && m_stylesListBox->GetStyleListBox()->GetSelection() != wxNOT_FOUND); | |
868 | } | |
869 | ||
870 | /// List selection | |
871 | void wxRichTextStyleOrganiserDialog::OnListSelection(wxCommandEvent& event) | |
872 | { | |
873 | if (event.GetEventObject() == m_stylesListBox->GetStyleListBox()) | |
874 | ShowPreview(); | |
875 | else | |
876 | event.Skip(); | |
877 | } | |
5c6e84b6 JS |
878 | |
879 | #endif | |
880 | // wxUSE_RICHTEXT | |
44cc96a8 | 881 |