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