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