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