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