1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextstyledlg.cpp
4 // Author: Julian Smart
6 // Created: 10/5/2006 12:05:31 PM
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
25 #include "wx/richtext/richtextstyledlg.h"
26 #include "wx/richtext/richtextformatdlg.h"
29 * wxRichTextStyleOrganiserDialog type definition
32 bool wxRichTextStyleOrganiserDialog::sm_showToolTips
= false;
34 IMPLEMENT_DYNAMIC_CLASS( wxRichTextStyleOrganiserDialog
, wxDialog
)
37 * wxRichTextStyleOrganiserDialog event table definition
40 BEGIN_EVENT_TABLE( wxRichTextStyleOrganiserDialog
, wxDialog
)
42 EVT_LISTBOX(wxID_ANY
, wxRichTextStyleOrganiserDialog::OnListSelection
)
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
)
48 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, wxRichTextStyleOrganiserDialog::OnNewParaClick
)
49 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, wxRichTextStyleOrganiserDialog::OnNewParaUpdate
)
51 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, wxRichTextStyleOrganiserDialog::OnNewListClick
)
52 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, wxRichTextStyleOrganiserDialog::OnNewListUpdate
)
54 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, wxRichTextStyleOrganiserDialog::OnApplyClick
)
55 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, wxRichTextStyleOrganiserDialog::OnApplyUpdate
)
57 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, wxRichTextStyleOrganiserDialog::OnRenameClick
)
58 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, wxRichTextStyleOrganiserDialog::OnRenameUpdate
)
60 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, wxRichTextStyleOrganiserDialog::OnEditClick
)
61 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, wxRichTextStyleOrganiserDialog::OnEditUpdate
)
63 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, wxRichTextStyleOrganiserDialog::OnDeleteClick
)
64 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, wxRichTextStyleOrganiserDialog::OnDeleteUpdate
)
66 ////@end wxRichTextStyleOrganiserDialog event table entries
71 * wxRichTextStyleOrganiserDialog constructors
74 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( )
79 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
82 Create(flags
, sheet
, ctrl
, parent
, id
, caption
, pos
, size
, style
);
86 * Member initialisation for wxSymbolPickerDialog
89 void wxRichTextStyleOrganiserDialog::Init()
91 m_richTextStyleSheet
= NULL
;
92 m_richTextCtrl
= NULL
;
95 m_restartNumbering
= true;
97 ////@begin wxRichTextStyleOrganiserDialog member initialisation
99 m_buttonSizerParent
= NULL
;
100 m_stylesListBox
= NULL
;
101 m_previewCtrl
= NULL
;
102 m_buttonSizer
= NULL
;
103 m_newCharacter
= NULL
;
104 m_newParagraph
= NULL
;
107 m_renameStyle
= NULL
;
109 m_deleteStyle
= NULL
;
110 m_closeButton
= NULL
;
111 m_bottomButtonSizer
= NULL
;
112 m_restartNumberingCtrl
= NULL
;
114 m_cancelButton
= NULL
;
115 ////@end wxRichTextStyleOrganiserDialog member initialisation
119 * wxRichTextStyleOrganiserDialog creator
122 bool wxRichTextStyleOrganiserDialog::Create( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
124 m_richTextStyleSheet
= sheet
;
125 m_richTextCtrl
= ctrl
;
128 ////@begin wxRichTextStyleOrganiserDialog creation
129 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
|wxDIALOG_EX_CONTEXTHELP
);
130 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
135 GetSizer()->SetSizeHints(this);
138 ////@end wxRichTextStyleOrganiserDialog creation
143 * Control creation for wxRichTextStyleOrganiserDialog
146 void wxRichTextStyleOrganiserDialog::CreateControls()
148 bool hideTypeSelector
= false;
149 wxRichTextStyleListBox::wxRichTextStyleType typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL
;
151 if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_CHARACTER
) != 0)
153 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
;
154 hideTypeSelector
= true;
156 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_PARAGRAPH
) != 0)
158 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH
;
159 hideTypeSelector
= true;
161 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_LIST
) != 0)
163 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST
;
164 hideTypeSelector
= true;
168 // wxRICHTEXT_ORGANISER_SHOW_ALL is implied if the other styles aren't included
171 long listCtrlStyle
= 0;
172 if (hideTypeSelector
)
173 listCtrlStyle
= wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR
;
175 ////@begin wxRichTextStyleOrganiserDialog content construction
176 wxRichTextStyleOrganiserDialog
* itemDialog1
= this;
178 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
179 itemDialog1
->SetSizer(itemBoxSizer2
);
181 m_innerSizer
= new wxBoxSizer(wxVERTICAL
);
182 itemBoxSizer2
->Add(m_innerSizer
, 1, wxGROW
|wxALL
, 5);
184 m_buttonSizerParent
= new wxBoxSizer(wxHORIZONTAL
);
185 m_innerSizer
->Add(m_buttonSizerParent
, 1, wxGROW
, 5);
187 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
188 m_buttonSizerParent
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
190 wxStaticText
* itemStaticText6
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Styles:"), wxDefaultPosition
, wxDefaultSize
, 0 );
191 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
193 m_stylesListBox
= new wxRichTextStyleListCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_STYLES
, wxDefaultPosition
, wxSize(200, 350), wxSIMPLE_BORDER
|listCtrlStyle
);
194 m_stylesListBox
->SetHelpText(_("The available styles."));
196 m_stylesListBox
->SetToolTip(_("The available styles."));
197 itemBoxSizer5
->Add(m_stylesListBox
, 1, wxGROW
|wxALL
, 5);
199 wxBoxSizer
* itemBoxSizer8
= new wxBoxSizer(wxVERTICAL
);
200 m_buttonSizerParent
->Add(itemBoxSizer8
, 0, wxGROW
, 5);
202 wxStaticText
* itemStaticText9
= new wxStaticText( itemDialog1
, wxID_STATIC
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
203 itemBoxSizer8
->Add(itemStaticText9
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
205 m_previewCtrl
= new wxRichTextCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_PREVIEW
, wxEmptyString
, wxDefaultPosition
, wxSize(310, 200), wxSIMPLE_BORDER
|wxTE_READONLY
);
206 m_previewCtrl
->SetHelpText(_("The style preview."));
208 m_previewCtrl
->SetToolTip(_("The style preview."));
209 itemBoxSizer8
->Add(m_previewCtrl
, 1, wxGROW
|wxALL
, 5);
211 m_buttonSizer
= new wxBoxSizer(wxVERTICAL
);
212 m_buttonSizerParent
->Add(m_buttonSizer
, 0, wxGROW
, 5);
214 wxStaticText
* itemStaticText12
= new wxStaticText( itemDialog1
, wxID_STATIC
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
215 m_buttonSizer
->Add(itemStaticText12
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
217 m_newCharacter
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
, _("New &Character Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
218 m_newCharacter
->SetHelpText(_("Click to create a new character style."));
220 m_newCharacter
->SetToolTip(_("Click to create a new character style."));
221 m_buttonSizer
->Add(m_newCharacter
, 0, wxGROW
|wxALL
, 5);
223 m_newParagraph
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, _("New &Paragraph Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
224 m_newParagraph
->SetHelpText(_("Click to create a new paragraph style."));
226 m_newParagraph
->SetToolTip(_("Click to create a new paragraph style."));
227 m_buttonSizer
->Add(m_newParagraph
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
229 m_newList
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, _("New &List Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
230 m_newList
->SetHelpText(_("Click to create a new list style."));
232 m_newList
->SetToolTip(_("Click to create a new list style."));
233 m_buttonSizer
->Add(m_newList
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
235 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
237 m_applyStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, _("&Apply Style"), wxDefaultPosition
, wxDefaultSize
, 0 );
238 m_applyStyle
->SetHelpText(_("Click to apply the selected style."));
240 m_applyStyle
->SetToolTip(_("Click to apply the selected style."));
241 m_buttonSizer
->Add(m_applyStyle
, 0, wxGROW
|wxALL
, 5);
243 m_renameStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, _("&Rename Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
244 m_renameStyle
->SetHelpText(_("Click to rename the selected style."));
246 m_renameStyle
->SetToolTip(_("Click to rename the selected style."));
247 m_buttonSizer
->Add(m_renameStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
249 m_editStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, _("&Edit Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
250 m_editStyle
->SetHelpText(_("Click to edit the selected style."));
252 m_editStyle
->SetToolTip(_("Click to edit the selected style."));
253 m_buttonSizer
->Add(m_editStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
255 m_deleteStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, _("&Delete Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
256 m_deleteStyle
->SetHelpText(_("Click to delete the selected style."));
258 m_deleteStyle
->SetToolTip(_("Click to delete the selected style."));
259 m_buttonSizer
->Add(m_deleteStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
261 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
263 m_closeButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
264 m_closeButton
->SetDefault();
265 m_closeButton
->SetHelpText(_("Click to close this window."));
267 m_closeButton
->SetToolTip(_("Click to close this window."));
268 m_buttonSizer
->Add(m_closeButton
, 0, wxGROW
|wxALL
, 5);
270 m_bottomButtonSizer
= new wxBoxSizer(wxHORIZONTAL
);
271 m_innerSizer
->Add(m_bottomButtonSizer
, 0, wxGROW
, 5);
273 m_restartNumberingCtrl
= new wxCheckBox( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RESTART_NUMBERING
, _("&Restart numbering"), wxDefaultPosition
, wxDefaultSize
, 0 );
274 m_restartNumberingCtrl
->SetValue(false);
275 m_restartNumberingCtrl
->SetHelpText(_("Check to restart numbering."));
277 m_restartNumberingCtrl
->SetToolTip(_("Check to restart numbering."));
278 m_bottomButtonSizer
->Add(m_restartNumberingCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
280 m_bottomButtonSizer
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
282 m_okButton
= new wxButton( itemDialog1
, wxID_OK
, _("OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
283 m_okButton
->SetDefault();
284 m_okButton
->SetHelpText(_("Click to confirm your selection."));
286 m_okButton
->SetToolTip(_("Click to confirm your selection."));
287 m_bottomButtonSizer
->Add(m_okButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
289 m_cancelButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
290 m_cancelButton
->SetHelpText(_("Click to cancel this window."));
292 m_cancelButton
->SetToolTip(_("Click to cancel this window."));
293 m_bottomButtonSizer
->Add(m_cancelButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
295 ////@end wxRichTextStyleOrganiserDialog content construction
297 if ((m_flags
& wxRICHTEXT_ORGANISER_CREATE_STYLES
) == 0)
299 m_buttonSizer
->Show(m_newCharacter
, false);
300 m_buttonSizer
->Show(m_newParagraph
, false);
301 m_buttonSizer
->Show(m_newList
, false);
303 if ((m_flags
& wxRICHTEXT_ORGANISER_DELETE_STYLES
) == 0)
305 m_buttonSizer
->Show(m_deleteStyle
, false);
307 if ((m_flags
& wxRICHTEXT_ORGANISER_APPLY_STYLES
) == 0)
309 m_buttonSizer
->Show(m_applyStyle
, false);
311 if ((m_flags
& wxRICHTEXT_ORGANISER_EDIT_STYLES
) == 0)
313 m_buttonSizer
->Show(m_editStyle
, false);
315 if ((m_flags
& wxRICHTEXT_ORGANISER_RENAME_STYLES
) == 0)
317 m_buttonSizer
->Show(m_renameStyle
, false);
319 if ((m_flags
& wxRICHTEXT_ORGANISER_RENUMBER
) == 0)
321 m_bottomButtonSizer
->Show(m_restartNumberingCtrl
, false);
324 if ((m_flags
& wxRICHTEXT_ORGANISER_OK_CANCEL
) == 0)
326 m_bottomButtonSizer
->Show(m_okButton
, false);
327 m_bottomButtonSizer
->Show(m_cancelButton
, false);
331 m_buttonSizer
->Show(m_closeButton
, false);
334 // No buttons in the vertical group are shown, so hide the whole sizer
335 if ((m_flags
& wxRICHTEXT_ORGANISER_ORGANISE
) == 0)
337 m_buttonSizerParent
->Show(m_buttonSizer
, false);
340 // No buttons in the horizontal group are shown, so hide the whole sizer
341 if ((m_flags
& (wxRICHTEXT_ORGANISER_OK_CANCEL
|wxRICHTEXT_ORGANISER_RENUMBER
)) == 0)
343 m_innerSizer
->Show(m_bottomButtonSizer
, false);
346 if (hideTypeSelector
)
348 m_stylesListBox
->GetStyleListBox()->SetStyleType(typesToShow
);
351 m_stylesListBox
->SetStyleSheet(m_richTextStyleSheet
);
352 m_stylesListBox
->SetRichTextCtrl(m_richTextCtrl
);
353 m_stylesListBox
->UpdateStyles();
354 m_stylesListBox
->GetStyleListBox()->SetAutoSetSelection(false); // stop idle-time auto selection
355 if (m_stylesListBox
->GetStyleListBox()->GetItemCount() > 0)
357 m_stylesListBox
->GetStyleListBox()->SetSelection(0);
363 * Should we show tooltips?
366 /// Get selected style name or definition
367 wxString
wxRichTextStyleOrganiserDialog::GetSelectedStyle() const
369 wxRichTextStyleDefinition
* def
= GetSelectedStyleDefinition();
371 return def
->GetName();
373 return wxEmptyString
;
376 wxRichTextStyleDefinition
* wxRichTextStyleOrganiserDialog::GetSelectedStyleDefinition() const
378 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
379 return m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
383 /// Transfer data from/to window
384 bool wxRichTextStyleOrganiserDialog::TransferDataFromWindow()
386 if (!wxDialog::TransferDataFromWindow())
389 m_restartNumbering
= m_restartNumberingCtrl
->GetValue();
394 bool wxRichTextStyleOrganiserDialog::TransferDataToWindow()
396 if (!wxDialog::TransferDataToWindow())
399 m_restartNumberingCtrl
->SetValue(m_restartNumbering
);
404 /// Show preview for given or selected preview
405 void wxRichTextStyleOrganiserDialog::ShowPreview(int sel
)
407 static const wxChar
* s_para1
= wxT("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
408 Nullam ante sapien, vestibulum nonummy, pulvinar sed, luctus ut, lacus.");
410 static const wxChar
* s_para2List
= wxT("Duis pharetra consequat dui. Nullam vitae justo id mauris lobortis interdum.");
412 static const wxChar
* s_para2
= wxT("Duis pharetra consequat dui. Cum sociis natoque penatibus \
413 et magnis dis parturient montes, nascetur ridiculus mus. Nullam vitae justo id mauris lobortis interdum.");
415 static const wxChar
* s_para3
= wxT("\nInteger convallis dolor at augue \
416 iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n");
420 sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
425 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
427 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
428 //wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
429 //wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition);
431 wxTextAttrEx
attr(def
->GetStyle());
433 attr
.SetFlags(attr
.GetFlags() &
434 (wxTEXT_ATTR_ALIGNMENT
|wxTEXT_ATTR_LEFT_INDENT
|wxTEXT_ATTR_RIGHT_INDENT
|wxTEXT_ATTR_PARA_SPACING_BEFORE
|wxTEXT_ATTR_PARA_SPACING_AFTER
|
435 wxTEXT_ATTR_LINE_SPACING
|
436 wxTEXT_ATTR_BULLET_STYLE
|wxTEXT_ATTR_BULLET_NUMBER
|wxTEXT_ATTR_BULLET_SYMBOL
));
439 wxFont
font(m_previewCtrl
->GetFont());
440 font
.SetPointSize(9);
441 m_previewCtrl
->SetFont(font
);
443 wxTextAttrEx normalParaAttr
;
444 normalParaAttr
.SetFont(font
);
445 normalParaAttr
.SetTextColour(wxColour(wxT("LIGHT GREY")));
447 m_previewCtrl
->Freeze();
448 m_previewCtrl
->Clear();
450 m_previewCtrl
->BeginStyle(normalParaAttr
);
451 m_previewCtrl
->WriteText(s_para1
);
452 m_previewCtrl
->EndStyle();
454 m_previewCtrl
->BeginStyle(attr
);
458 long listStart
= m_previewCtrl
->GetInsertionPoint() + 1;
460 for (i
= 0; i
< 10; i
++)
462 wxTextAttrEx levelAttr
= * listDef
->GetLevelAttributes(i
);
463 levelAttr
.SetBulletNumber(1);
464 m_previewCtrl
->BeginStyle(levelAttr
);
465 m_previewCtrl
->WriteText(wxString::Format(wxT("\nList level %d. "), i
+1) + s_para2List
);
466 m_previewCtrl
->EndStyle();
468 long listEnd
= m_previewCtrl
->GetInsertionPoint();
469 m_previewCtrl
->NumberList(wxRichTextRange(listStart
, listEnd
), listDef
);
473 m_previewCtrl
->WriteText(wxString(wxT("\n")) + s_para2
);
476 m_previewCtrl
->EndStyle();
478 m_previewCtrl
->BeginStyle(normalParaAttr
);
479 m_previewCtrl
->WriteText(s_para3
);
480 m_previewCtrl
->EndStyle();
482 m_previewCtrl
->Thaw();
485 /// Clears the preview
486 void wxRichTextStyleOrganiserDialog::ClearPreview()
488 m_previewCtrl
->Clear();
491 bool wxRichTextStyleOrganiserDialog::ApplyStyle(wxRichTextCtrl
* ctrl
)
493 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
497 ctrl
= GetRichTextCtrl();
500 if (!ctrl
->HasSelection())
504 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
505 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
507 if (listDef
&& m_restartNumberingCtrl
->GetValue())
509 wxRichTextRange range
= ctrl
->GetSelectionRange();
510 return ctrl
->SetListStyle(range
, listDef
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_RENUMBER
);
514 return ctrl
->ApplyStyle(def
);
519 * Get bitmap resources
522 wxBitmap
wxRichTextStyleOrganiserDialog::GetBitmapResource( const wxString
& name
)
525 ////@begin wxRichTextStyleOrganiserDialog bitmap retrieval
528 ////@end wxRichTextStyleOrganiserDialog bitmap retrieval
535 wxIcon
wxRichTextStyleOrganiserDialog::GetIconResource( const wxString
& name
)
538 ////@begin wxRichTextStyleOrganiserDialog icon retrieval
541 ////@end wxRichTextStyleOrganiserDialog icon retrieval
545 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
548 void wxRichTextStyleOrganiserDialog::OnApplyClick( wxCommandEvent
& WXUNUSED(event
) )
554 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
557 void wxRichTextStyleOrganiserDialog::OnApplyUpdate( wxUpdateUIEvent
& event
)
559 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_APPLY_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
564 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
567 void wxRichTextStyleOrganiserDialog::OnNewCharClick( wxCommandEvent
& WXUNUSED(event
) )
569 wxString styleName
= wxGetTextFromUser(_("Enter a character style name"), _("New Style"));
570 if (!styleName
.IsEmpty())
572 if (GetStyleSheet()->FindCharacterStyle(styleName
))
574 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
578 wxRichTextCharacterStyleDefinition
* style
= new wxRichTextCharacterStyleDefinition(styleName
);
580 int pages
= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_STYLE_EDITOR
;
581 wxRichTextFormattingDialog formatDlg
;
582 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
583 formatDlg
.Create(pages
, this);
585 if (formatDlg
.ShowModal() == wxID_OK
)
587 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
589 (*((wxRichTextCharacterStyleDefinition
* ) style
)) = (*charDef
);
591 GetStyleSheet()->AddCharacterStyle(style
);
593 m_stylesListBox
->UpdateStyles();
602 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
605 void wxRichTextStyleOrganiserDialog::OnNewCharUpdate( wxUpdateUIEvent
& event
)
607 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
612 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
615 void wxRichTextStyleOrganiserDialog::OnNewParaClick( wxCommandEvent
& WXUNUSED(event
) )
617 wxString styleName
= wxGetTextFromUser(_("Enter a paragraph style name"), _("New Style"));
618 if (!styleName
.IsEmpty())
620 if (GetStyleSheet()->FindParagraphStyle(styleName
))
622 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
626 wxRichTextParagraphStyleDefinition
* style
= new wxRichTextParagraphStyleDefinition(styleName
);
628 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
629 wxRichTextFormattingDialog formatDlg
;
630 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
631 formatDlg
.Create(pages
, this);
633 if (formatDlg
.ShowModal() == wxID_OK
)
635 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
637 (*((wxRichTextParagraphStyleDefinition
* ) style
)) = (*paraDef
);
639 GetStyleSheet()->AddParagraphStyle(style
);
641 m_stylesListBox
->UpdateStyles();
650 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
653 void wxRichTextStyleOrganiserDialog::OnNewParaUpdate( wxUpdateUIEvent
& event
)
655 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
660 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
663 void wxRichTextStyleOrganiserDialog::OnEditClick( wxCommandEvent
& WXUNUSED(event
) )
665 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
666 if (sel
!= wxNOT_FOUND
)
668 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
670 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
;
672 if (def
->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition
)))
674 pages
|= wxRICHTEXT_FORMAT_FONT
;
676 else if (def
->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition
)))
678 pages
|= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
680 else if (def
->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition
)))
682 pages
|= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
685 wxRichTextFormattingDialog formatDlg
;
686 formatDlg
.SetStyleDefinition(*def
, GetStyleSheet());
687 formatDlg
.Create(pages
, this);
689 if (formatDlg
.ShowModal() == wxID_OK
)
691 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
692 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
693 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
697 (*((wxRichTextListStyleDefinition
* ) def
)) = (*listDef
);
701 (*((wxRichTextParagraphStyleDefinition
* ) def
)) = (*paraDef
);
705 (*((wxRichTextCharacterStyleDefinition
* ) def
)) = (*charDef
);
708 m_stylesListBox
->UpdateStyles();
715 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
718 void wxRichTextStyleOrganiserDialog::OnEditUpdate( wxUpdateUIEvent
& event
)
720 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_EDIT_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
725 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
728 void wxRichTextStyleOrganiserDialog::OnDeleteClick( wxCommandEvent
& WXUNUSED(event
) )
730 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
731 if (sel
!= wxNOT_FOUND
)
733 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
734 wxString
name(def
->GetName());
735 if (wxYES
== wxMessageBox(wxString::Format(_("Delete style %s?"), (const wxChar
*) name
), _("Delete Style"), wxYES_NO
|wxICON_QUESTION
, this))
737 m_stylesListBox
->GetStyleListBox()->SetItemCount(0);
739 if (def
->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition
)))
740 GetStyleSheet()->RemoveListStyle((wxRichTextListStyleDefinition
*) def
, true);
741 else if (def
->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition
)))
742 GetStyleSheet()->RemoveParagraphStyle((wxRichTextParagraphStyleDefinition
*) def
, true);
743 else if (def
->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition
)))
744 GetStyleSheet()->RemoveCharacterStyle((wxRichTextCharacterStyleDefinition
*) def
, true);
746 m_stylesListBox
->UpdateStyles();
748 if (m_stylesListBox
->GetStyleListBox()->GetSelection() != -1)
757 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
760 void wxRichTextStyleOrganiserDialog::OnDeleteUpdate( wxUpdateUIEvent
& event
)
762 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_DELETE_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
766 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
769 void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent
& WXUNUSED(event
) )
771 wxString styleName
= wxGetTextFromUser(_("Enter a list style name"), _("New Style"));
772 if (!styleName
.IsEmpty())
774 if (GetStyleSheet()->FindListStyle(styleName
))
776 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
780 wxRichTextListStyleDefinition
* style
= new wxRichTextListStyleDefinition(styleName
);
782 // Initialize the style to make it easier to edit
784 for (i
= 0; i
< 10; i
++)
786 wxString bulletSymbol
;
788 bulletSymbol
= wxT("*");
790 bulletSymbol
= wxT("-");
792 bulletSymbol
= wxT("*");
794 bulletSymbol
= wxT("-");
796 bulletSymbol
= wxT("*");
798 style
->SetAttributes(i
, (i
+1)*60, 60, wxTEXT_ATTR_BULLET_STYLE_SYMBOL
, bulletSymbol
);
801 int pages
= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
802 wxRichTextFormattingDialog formatDlg
;
803 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
804 formatDlg
.Create(pages
, this);
806 if (formatDlg
.ShowModal() == wxID_OK
)
808 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
810 (*((wxRichTextListStyleDefinition
* ) style
)) = (*listDef
);
812 GetStyleSheet()->AddListStyle(style
);
814 m_stylesListBox
->UpdateStyles();
823 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
826 void wxRichTextStyleOrganiserDialog::OnNewListUpdate( wxUpdateUIEvent
& event
)
828 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
832 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
835 void wxRichTextStyleOrganiserDialog::OnRenameClick( wxCommandEvent
& WXUNUSED(event
) )
837 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
840 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
844 wxString styleName
= wxGetTextFromUser(_("Enter a new style name"), _("New Style"), def
->GetName());
845 if (!styleName
.IsEmpty())
847 if (styleName
== def
->GetName())
850 if (GetStyleSheet()->FindParagraphStyle(styleName
) || GetStyleSheet()->FindCharacterStyle(styleName
) || GetStyleSheet()->FindListStyle(styleName
))
852 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
856 def
->SetName(styleName
);
857 m_stylesListBox
->UpdateStyles();
862 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
865 void wxRichTextStyleOrganiserDialog::OnRenameUpdate( wxUpdateUIEvent
& event
)
867 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_RENAME_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
871 void wxRichTextStyleOrganiserDialog::OnListSelection(wxCommandEvent
& event
)
873 if (event
.GetEventObject() == m_stylesListBox
->GetStyleListBox())