1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtextstyledlg.cpp
4 // Author: Julian Smart
6 // Created: 10/5/2006 12:05:31 PM
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
26 #include "wx/richtext/richtextstyledlg.h"
27 #include "wx/richtext/richtextformatdlg.h"
33 * wxRichTextStyleOrganiserDialog type definition
36 bool wxRichTextStyleOrganiserDialog::sm_showToolTips
= false;
38 IMPLEMENT_DYNAMIC_CLASS( wxRichTextStyleOrganiserDialog
, wxDialog
)
41 * wxRichTextStyleOrganiserDialog event table definition
44 BEGIN_EVENT_TABLE( wxRichTextStyleOrganiserDialog
, wxDialog
)
46 EVT_LISTBOX(wxID_ANY
, wxRichTextStyleOrganiserDialog::OnListSelection
)
48 ////@begin wxRichTextStyleOrganiserDialog event table entries
49 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
, wxRichTextStyleOrganiserDialog::OnNewCharClick
)
50 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
, wxRichTextStyleOrganiserDialog::OnNewCharUpdate
)
52 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, wxRichTextStyleOrganiserDialog::OnNewParaClick
)
53 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, wxRichTextStyleOrganiserDialog::OnNewParaUpdate
)
55 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, wxRichTextStyleOrganiserDialog::OnNewListClick
)
56 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, wxRichTextStyleOrganiserDialog::OnNewListUpdate
)
58 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, wxRichTextStyleOrganiserDialog::OnApplyClick
)
59 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, wxRichTextStyleOrganiserDialog::OnApplyUpdate
)
61 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, wxRichTextStyleOrganiserDialog::OnRenameClick
)
62 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, wxRichTextStyleOrganiserDialog::OnRenameUpdate
)
64 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, wxRichTextStyleOrganiserDialog::OnEditClick
)
65 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, wxRichTextStyleOrganiserDialog::OnEditUpdate
)
67 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, wxRichTextStyleOrganiserDialog::OnDeleteClick
)
68 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, wxRichTextStyleOrganiserDialog::OnDeleteUpdate
)
70 ////@end wxRichTextStyleOrganiserDialog event table entries
75 * wxRichTextStyleOrganiserDialog constructors
78 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( )
83 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
86 Create(flags
, sheet
, ctrl
, parent
, id
, caption
, pos
, size
, style
);
90 * Member initialisation for wxSymbolPickerDialog
93 void wxRichTextStyleOrganiserDialog::Init()
95 m_richTextStyleSheet
= NULL
;
96 m_richTextCtrl
= NULL
;
99 m_restartNumbering
= true;
101 ////@begin wxRichTextStyleOrganiserDialog member initialisation
103 m_buttonSizerParent
= NULL
;
104 m_stylesListBox
= NULL
;
105 m_previewCtrl
= NULL
;
106 m_buttonSizer
= NULL
;
107 m_newCharacter
= NULL
;
108 m_newParagraph
= NULL
;
111 m_renameStyle
= NULL
;
113 m_deleteStyle
= NULL
;
114 m_closeButton
= NULL
;
115 m_bottomButtonSizer
= NULL
;
116 m_restartNumberingCtrl
= NULL
;
118 m_cancelButton
= NULL
;
119 ////@end wxRichTextStyleOrganiserDialog member initialisation
123 * wxRichTextStyleOrganiserDialog creator
126 bool wxRichTextStyleOrganiserDialog::Create( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
128 m_richTextStyleSheet
= sheet
;
129 m_richTextCtrl
= ctrl
;
132 ////@begin wxRichTextStyleOrganiserDialog creation
133 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
|wxDIALOG_EX_CONTEXTHELP
);
134 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
139 GetSizer()->SetSizeHints(this);
142 ////@end wxRichTextStyleOrganiserDialog creation
147 * Control creation for wxRichTextStyleOrganiserDialog
150 void wxRichTextStyleOrganiserDialog::CreateControls()
152 bool hideTypeSelector
= false;
153 wxRichTextStyleListBox::wxRichTextStyleType typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL
;
155 if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_CHARACTER
) != 0)
157 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
;
158 hideTypeSelector
= true;
160 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_PARAGRAPH
) != 0)
162 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH
;
163 hideTypeSelector
= true;
165 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_LIST
) != 0)
167 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST
;
168 hideTypeSelector
= true;
172 // wxRICHTEXT_ORGANISER_SHOW_ALL is implied if the other styles aren't included
175 long listCtrlStyle
= 0;
176 if (hideTypeSelector
)
177 listCtrlStyle
= wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR
;
179 ////@begin wxRichTextStyleOrganiserDialog content construction
180 wxRichTextStyleOrganiserDialog
* itemDialog1
= this;
182 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
183 itemDialog1
->SetSizer(itemBoxSizer2
);
185 m_innerSizer
= new wxBoxSizer(wxVERTICAL
);
186 itemBoxSizer2
->Add(m_innerSizer
, 1, wxGROW
|wxALL
, 5);
188 m_buttonSizerParent
= new wxBoxSizer(wxHORIZONTAL
);
189 m_innerSizer
->Add(m_buttonSizerParent
, 1, wxGROW
, 5);
191 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
192 m_buttonSizerParent
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
194 wxStaticText
* itemStaticText6
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Styles:"), wxDefaultPosition
, wxDefaultSize
, 0 );
195 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
197 m_stylesListBox
= new wxRichTextStyleListCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_STYLES
, wxDefaultPosition
, wxSize(200, 350), wxSIMPLE_BORDER
|listCtrlStyle
);
198 m_stylesListBox
->SetHelpText(_("The available styles."));
200 m_stylesListBox
->SetToolTip(_("The available styles."));
201 itemBoxSizer5
->Add(m_stylesListBox
, 1, wxGROW
|wxALL
, 5);
203 wxBoxSizer
* itemBoxSizer8
= new wxBoxSizer(wxVERTICAL
);
204 m_buttonSizerParent
->Add(itemBoxSizer8
, 0, wxGROW
, 5);
206 wxStaticText
* itemStaticText9
= new wxStaticText( itemDialog1
, wxID_STATIC
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
207 itemBoxSizer8
->Add(itemStaticText9
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
209 m_previewCtrl
= new wxRichTextCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_PREVIEW
, wxEmptyString
, wxDefaultPosition
, wxSize(310, 200), wxSIMPLE_BORDER
|wxTE_READONLY
);
210 m_previewCtrl
->SetHelpText(_("The style preview."));
212 m_previewCtrl
->SetToolTip(_("The style preview."));
213 itemBoxSizer8
->Add(m_previewCtrl
, 1, wxGROW
|wxALL
, 5);
215 m_buttonSizer
= new wxBoxSizer(wxVERTICAL
);
216 m_buttonSizerParent
->Add(m_buttonSizer
, 0, wxGROW
, 5);
218 wxStaticText
* itemStaticText12
= new wxStaticText( itemDialog1
, wxID_STATIC
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
219 m_buttonSizer
->Add(itemStaticText12
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
221 m_newCharacter
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
, _("New &Character Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
222 m_newCharacter
->SetHelpText(_("Click to create a new character style."));
224 m_newCharacter
->SetToolTip(_("Click to create a new character style."));
225 m_buttonSizer
->Add(m_newCharacter
, 0, wxGROW
|wxALL
, 5);
227 m_newParagraph
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, _("New &Paragraph Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
228 m_newParagraph
->SetHelpText(_("Click to create a new paragraph style."));
230 m_newParagraph
->SetToolTip(_("Click to create a new paragraph style."));
231 m_buttonSizer
->Add(m_newParagraph
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
233 m_newList
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, _("New &List Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
234 m_newList
->SetHelpText(_("Click to create a new list style."));
236 m_newList
->SetToolTip(_("Click to create a new list style."));
237 m_buttonSizer
->Add(m_newList
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
239 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
241 m_applyStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, _("&Apply Style"), wxDefaultPosition
, wxDefaultSize
, 0 );
242 m_applyStyle
->SetHelpText(_("Click to apply the selected style."));
244 m_applyStyle
->SetToolTip(_("Click to apply the selected style."));
245 m_buttonSizer
->Add(m_applyStyle
, 0, wxGROW
|wxALL
, 5);
247 m_renameStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, _("&Rename Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
248 m_renameStyle
->SetHelpText(_("Click to rename the selected style."));
250 m_renameStyle
->SetToolTip(_("Click to rename the selected style."));
251 m_buttonSizer
->Add(m_renameStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
253 m_editStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, _("&Edit Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
254 m_editStyle
->SetHelpText(_("Click to edit the selected style."));
256 m_editStyle
->SetToolTip(_("Click to edit the selected style."));
257 m_buttonSizer
->Add(m_editStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
259 m_deleteStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, _("&Delete Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
260 m_deleteStyle
->SetHelpText(_("Click to delete the selected style."));
262 m_deleteStyle
->SetToolTip(_("Click to delete the selected style."));
263 m_buttonSizer
->Add(m_deleteStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
265 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
267 m_closeButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
268 m_closeButton
->SetDefault();
269 m_closeButton
->SetHelpText(_("Click to close this window."));
271 m_closeButton
->SetToolTip(_("Click to close this window."));
272 m_buttonSizer
->Add(m_closeButton
, 0, wxGROW
|wxALL
, 5);
274 m_bottomButtonSizer
= new wxBoxSizer(wxHORIZONTAL
);
275 m_innerSizer
->Add(m_bottomButtonSizer
, 0, wxGROW
, 5);
277 m_restartNumberingCtrl
= new wxCheckBox( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RESTART_NUMBERING
, _("&Restart numbering"), wxDefaultPosition
, wxDefaultSize
, 0 );
278 m_restartNumberingCtrl
->SetValue(false);
279 m_restartNumberingCtrl
->SetHelpText(_("Check to restart numbering."));
281 m_restartNumberingCtrl
->SetToolTip(_("Check to restart numbering."));
282 m_bottomButtonSizer
->Add(m_restartNumberingCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
284 m_bottomButtonSizer
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
286 m_okButton
= new wxButton( itemDialog1
, wxID_OK
, _("OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
287 m_okButton
->SetDefault();
288 m_okButton
->SetHelpText(_("Click to confirm your selection."));
290 m_okButton
->SetToolTip(_("Click to confirm your selection."));
291 m_bottomButtonSizer
->Add(m_okButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
293 m_cancelButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
294 m_cancelButton
->SetHelpText(_("Click to cancel this window."));
296 m_cancelButton
->SetToolTip(_("Click to cancel this window."));
297 m_bottomButtonSizer
->Add(m_cancelButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
299 ////@end wxRichTextStyleOrganiserDialog content construction
301 if ((m_flags
& wxRICHTEXT_ORGANISER_CREATE_STYLES
) == 0)
303 m_buttonSizer
->Show(m_newCharacter
, false);
304 m_buttonSizer
->Show(m_newParagraph
, false);
305 m_buttonSizer
->Show(m_newList
, false);
307 if ((m_flags
& wxRICHTEXT_ORGANISER_DELETE_STYLES
) == 0)
309 m_buttonSizer
->Show(m_deleteStyle
, false);
311 if ((m_flags
& wxRICHTEXT_ORGANISER_APPLY_STYLES
) == 0)
313 m_buttonSizer
->Show(m_applyStyle
, false);
315 if ((m_flags
& wxRICHTEXT_ORGANISER_EDIT_STYLES
) == 0)
317 m_buttonSizer
->Show(m_editStyle
, false);
319 if ((m_flags
& wxRICHTEXT_ORGANISER_RENAME_STYLES
) == 0)
321 m_buttonSizer
->Show(m_renameStyle
, false);
323 if ((m_flags
& wxRICHTEXT_ORGANISER_RENUMBER
) == 0)
325 m_bottomButtonSizer
->Show(m_restartNumberingCtrl
, false);
328 if ((m_flags
& wxRICHTEXT_ORGANISER_OK_CANCEL
) == 0)
330 m_bottomButtonSizer
->Show(m_okButton
, false);
331 m_bottomButtonSizer
->Show(m_cancelButton
, false);
335 m_buttonSizer
->Show(m_closeButton
, false);
338 // No buttons in the vertical group are shown, so hide the whole sizer
339 if ((m_flags
& wxRICHTEXT_ORGANISER_ORGANISE
) == 0)
341 m_buttonSizerParent
->Show(m_buttonSizer
, false);
344 // No buttons in the horizontal group are shown, so hide the whole sizer
345 if ((m_flags
& (wxRICHTEXT_ORGANISER_OK_CANCEL
|wxRICHTEXT_ORGANISER_RENUMBER
)) == 0)
347 m_innerSizer
->Show(m_bottomButtonSizer
, false);
350 if (hideTypeSelector
)
352 m_stylesListBox
->GetStyleListBox()->SetStyleType(typesToShow
);
355 m_stylesListBox
->SetStyleSheet(m_richTextStyleSheet
);
356 m_stylesListBox
->SetRichTextCtrl(m_richTextCtrl
);
357 m_stylesListBox
->UpdateStyles();
358 m_stylesListBox
->GetStyleListBox()->SetAutoSetSelection(false); // stop idle-time auto selection
359 if (m_stylesListBox
->GetStyleListBox()->GetItemCount() > 0)
361 m_stylesListBox
->GetStyleListBox()->SetSelection(0);
367 * Should we show tooltips?
370 /// Get selected style name or definition
371 wxString
wxRichTextStyleOrganiserDialog::GetSelectedStyle() const
373 wxRichTextStyleDefinition
* def
= GetSelectedStyleDefinition();
375 return def
->GetName();
377 return wxEmptyString
;
380 wxRichTextStyleDefinition
* wxRichTextStyleOrganiserDialog::GetSelectedStyleDefinition() const
382 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
383 return m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
387 /// Transfer data from/to window
388 bool wxRichTextStyleOrganiserDialog::TransferDataFromWindow()
390 if (!wxDialog::TransferDataFromWindow())
393 m_restartNumbering
= m_restartNumberingCtrl
->GetValue();
398 bool wxRichTextStyleOrganiserDialog::TransferDataToWindow()
400 if (!wxDialog::TransferDataToWindow())
403 m_restartNumberingCtrl
->SetValue(m_restartNumbering
);
408 /// Show preview for given or selected preview
409 void wxRichTextStyleOrganiserDialog::ShowPreview(int sel
)
411 static const wxChar
* s_para1
= wxT("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
412 Nullam ante sapien, vestibulum nonummy, pulvinar sed, luctus ut, lacus.");
414 static const wxChar
* s_para2List
= wxT("Duis pharetra consequat dui. Nullam vitae justo id mauris lobortis interdum.");
416 static const wxChar
* s_para2
= wxT("Duis pharetra consequat dui. Cum sociis natoque penatibus \
417 et magnis dis parturient montes, nascetur ridiculus mus. Nullam vitae justo id mauris lobortis interdum.");
419 static const wxChar
* s_para3
= wxT("\nInteger convallis dolor at augue \
420 iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n");
424 sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
429 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
431 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
432 //wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
433 //wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition);
435 wxTextAttrEx
attr(def
->GetStyle());
437 attr
.SetFlags(attr
.GetFlags() &
438 (wxTEXT_ATTR_ALIGNMENT
|wxTEXT_ATTR_LEFT_INDENT
|wxTEXT_ATTR_RIGHT_INDENT
|wxTEXT_ATTR_PARA_SPACING_BEFORE
|wxTEXT_ATTR_PARA_SPACING_AFTER
|
439 wxTEXT_ATTR_LINE_SPACING
|
440 wxTEXT_ATTR_BULLET_STYLE
|wxTEXT_ATTR_BULLET_NUMBER
|wxTEXT_ATTR_BULLET_SYMBOL
));
443 wxFont
font(m_previewCtrl
->GetFont());
444 font
.SetPointSize(9);
445 m_previewCtrl
->SetFont(font
);
447 wxTextAttrEx normalParaAttr
;
448 normalParaAttr
.SetFont(font
);
449 normalParaAttr
.SetTextColour(wxColour(wxT("LIGHT GREY")));
451 m_previewCtrl
->Freeze();
452 m_previewCtrl
->Clear();
454 m_previewCtrl
->BeginStyle(normalParaAttr
);
455 m_previewCtrl
->WriteText(s_para1
);
456 m_previewCtrl
->EndStyle();
458 m_previewCtrl
->BeginStyle(attr
);
463 for (i
= 0; i
< 10; i
++)
465 wxTextAttrEx levelAttr
= * listDef
->GetLevelAttributes(i
);
466 levelAttr
.SetBulletNumber(1);
467 m_previewCtrl
->BeginStyle(levelAttr
);
468 m_previewCtrl
->WriteText(wxString::Format(wxT("\nList level %d. "), i
+1) + s_para2List
);
469 m_previewCtrl
->EndStyle();
474 m_previewCtrl
->WriteText(wxString(wxT("\n")) + s_para2
);
477 m_previewCtrl
->EndStyle();
479 m_previewCtrl
->BeginStyle(normalParaAttr
);
480 m_previewCtrl
->WriteText(s_para3
);
481 m_previewCtrl
->EndStyle();
483 m_previewCtrl
->Thaw();
486 /// Clears the preview
487 void wxRichTextStyleOrganiserDialog::ClearPreview()
489 m_richTextCtrl
->Clear();
492 bool wxRichTextStyleOrganiserDialog::ApplyStyle(wxRichTextCtrl
* ctrl
)
494 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
498 ctrl
= GetRichTextCtrl();
501 if (!ctrl
->HasSelection())
505 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
506 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
508 if (listDef
&& m_restartNumberingCtrl
->GetValue())
510 wxRichTextRange range
= ctrl
->GetSelectionRange();
511 return ctrl
->SetListStyle(range
, listDef
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_RENUMBER
);
515 return ctrl
->ApplyStyle(def
);
520 * Get bitmap resources
523 wxBitmap
wxRichTextStyleOrganiserDialog::GetBitmapResource( const wxString
& name
)
526 ////@begin wxRichTextStyleOrganiserDialog bitmap retrieval
529 ////@end wxRichTextStyleOrganiserDialog bitmap retrieval
536 wxIcon
wxRichTextStyleOrganiserDialog::GetIconResource( const wxString
& name
)
539 ////@begin wxRichTextStyleOrganiserDialog icon retrieval
542 ////@end wxRichTextStyleOrganiserDialog icon retrieval
546 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
549 void wxRichTextStyleOrganiserDialog::OnApplyClick( wxCommandEvent
& WXUNUSED(event
) )
555 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
558 void wxRichTextStyleOrganiserDialog::OnApplyUpdate( wxUpdateUIEvent
& event
)
560 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_APPLY_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
565 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
568 void wxRichTextStyleOrganiserDialog::OnNewCharClick( wxCommandEvent
& WXUNUSED(event
) )
570 wxString styleName
= wxGetTextFromUser(_("Enter a character style name"), _("New Style"));
571 if (!styleName
.IsEmpty())
573 if (GetStyleSheet()->FindCharacterStyle(styleName
))
575 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
579 wxRichTextCharacterStyleDefinition
* style
= new wxRichTextCharacterStyleDefinition(styleName
);
581 int pages
= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_STYLE_EDITOR
;
582 wxRichTextFormattingDialog formatDlg
;
583 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
584 formatDlg
.Create(pages
, this);
586 if (formatDlg
.ShowModal() == wxID_OK
)
588 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
590 (*((wxRichTextCharacterStyleDefinition
* ) style
)) = (*charDef
);
592 GetStyleSheet()->AddCharacterStyle(style
);
594 m_stylesListBox
->UpdateStyles();
603 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
606 void wxRichTextStyleOrganiserDialog::OnNewCharUpdate( wxUpdateUIEvent
& event
)
608 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
613 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
616 void wxRichTextStyleOrganiserDialog::OnNewParaClick( wxCommandEvent
& WXUNUSED(event
) )
618 wxString styleName
= wxGetTextFromUser(_("Enter a paragraph style name"), _("New Style"));
619 if (!styleName
.IsEmpty())
621 if (GetStyleSheet()->FindParagraphStyle(styleName
))
623 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
627 wxRichTextParagraphStyleDefinition
* style
= new wxRichTextParagraphStyleDefinition(styleName
);
629 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
630 wxRichTextFormattingDialog formatDlg
;
631 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
632 formatDlg
.Create(pages
, this);
634 if (formatDlg
.ShowModal() == wxID_OK
)
636 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
638 (*((wxRichTextParagraphStyleDefinition
* ) style
)) = (*paraDef
);
640 GetStyleSheet()->AddParagraphStyle(style
);
642 m_stylesListBox
->UpdateStyles();
651 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
654 void wxRichTextStyleOrganiserDialog::OnNewParaUpdate( wxUpdateUIEvent
& event
)
656 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
661 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
664 void wxRichTextStyleOrganiserDialog::OnEditClick( wxCommandEvent
& WXUNUSED(event
) )
666 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
667 if (sel
!= wxNOT_FOUND
)
669 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
671 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
;
673 if (def
->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition
)))
675 pages
|= wxRICHTEXT_FORMAT_FONT
;
677 else if (def
->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition
)))
679 pages
|= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
681 else if (def
->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition
)))
683 pages
|= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
686 wxRichTextFormattingDialog formatDlg
;
687 formatDlg
.SetStyleDefinition(*def
, GetStyleSheet());
688 formatDlg
.Create(pages
, this);
690 if (formatDlg
.ShowModal() == wxID_OK
)
692 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
693 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
694 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
698 (*((wxRichTextListStyleDefinition
* ) def
)) = (*listDef
);
702 (*((wxRichTextParagraphStyleDefinition
* ) def
)) = (*paraDef
);
706 (*((wxRichTextCharacterStyleDefinition
* ) def
)) = (*charDef
);
709 m_stylesListBox
->UpdateStyles();
716 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
719 void wxRichTextStyleOrganiserDialog::OnEditUpdate( wxUpdateUIEvent
& event
)
721 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_EDIT_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
726 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
729 void wxRichTextStyleOrganiserDialog::OnDeleteClick( wxCommandEvent
& WXUNUSED(event
) )
731 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
732 if (sel
!= wxNOT_FOUND
)
734 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
735 wxString
name(def
->GetName());
736 if (wxYES
== wxMessageBox(wxString::Format(_("Delete style %s?"), (const wxChar
*) name
), _("Delete Style"), wxYES_NO
|wxICON_QUESTION
, this))
738 m_stylesListBox
->GetStyleListBox()->SetItemCount(0);
740 if (def
->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition
)))
741 GetStyleSheet()->RemoveListStyle((wxRichTextListStyleDefinition
*) def
, true);
742 else if (def
->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition
)))
743 GetStyleSheet()->RemoveParagraphStyle((wxRichTextParagraphStyleDefinition
*) def
, true);
744 else if (def
->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition
)))
745 GetStyleSheet()->RemoveCharacterStyle((wxRichTextCharacterStyleDefinition
*) def
, true);
747 m_stylesListBox
->UpdateStyles();
749 if (m_stylesListBox
->GetStyleListBox()->GetSelection() != -1)
758 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
761 void wxRichTextStyleOrganiserDialog::OnDeleteUpdate( wxUpdateUIEvent
& event
)
763 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_DELETE_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
767 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
770 void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent
& WXUNUSED(event
) )
772 wxString styleName
= wxGetTextFromUser(_("Enter a list style name"), _("New Style"));
773 if (!styleName
.IsEmpty())
775 if (GetStyleSheet()->FindListStyle(styleName
))
777 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
781 wxRichTextListStyleDefinition
* style
= new wxRichTextListStyleDefinition(styleName
);
783 // Initialize the style to make it easier to edit
785 for (i
= 0; i
< 10; i
++)
787 wxString bulletSymbol
;
789 bulletSymbol
= wxT("*");
791 bulletSymbol
= wxT("-");
793 bulletSymbol
= wxT("*");
795 bulletSymbol
= wxT("-");
797 bulletSymbol
= wxT("*");
799 style
->SetAttributes(i
, (i
+1)*60, 60, wxTEXT_ATTR_BULLET_STYLE_SYMBOL
, bulletSymbol
);
802 int pages
= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
803 wxRichTextFormattingDialog formatDlg
;
804 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
805 formatDlg
.Create(pages
, this);
807 if (formatDlg
.ShowModal() == wxID_OK
)
809 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
811 (*((wxRichTextListStyleDefinition
* ) style
)) = (*listDef
);
813 GetStyleSheet()->AddListStyle(style
);
815 m_stylesListBox
->UpdateStyles();
824 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
827 void wxRichTextStyleOrganiserDialog::OnNewListUpdate( wxUpdateUIEvent
& event
)
829 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
833 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
836 void wxRichTextStyleOrganiserDialog::OnRenameClick( wxCommandEvent
& WXUNUSED(event
) )
841 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
844 void wxRichTextStyleOrganiserDialog::OnRenameUpdate( wxUpdateUIEvent
& event
)
846 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_RENAME_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
850 void wxRichTextStyleOrganiserDialog::OnListSelection(wxCommandEvent
& event
)
852 if (event
.GetEventObject() == m_stylesListBox
->GetStyleListBox())