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
;
113 m_restartNumberingCtrl
= NULL
;
115 m_cancelButton
= NULL
;
116 ////@end wxRichTextStyleOrganiserDialog member initialisation
120 * wxRichTextStyleOrganiserDialog creator
123 bool wxRichTextStyleOrganiserDialog::Create( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
125 m_richTextStyleSheet
= sheet
;
126 m_richTextCtrl
= ctrl
;
129 ////@begin wxRichTextStyleOrganiserDialog creation
130 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS
|wxDIALOG_EX_CONTEXTHELP
);
131 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
136 GetSizer()->SetSizeHints(this);
139 ////@end wxRichTextStyleOrganiserDialog creation
144 * Control creation for wxRichTextStyleOrganiserDialog
147 void wxRichTextStyleOrganiserDialog::CreateControls()
149 bool hideTypeSelector
= false;
150 wxRichTextStyleListBox::wxRichTextStyleType typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL
;
152 if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_CHARACTER
) != 0)
154 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
;
155 hideTypeSelector
= true;
157 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_PARAGRAPH
) != 0)
159 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH
;
160 hideTypeSelector
= true;
162 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_LIST
) != 0)
164 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST
;
165 hideTypeSelector
= true;
169 // wxRICHTEXT_ORGANISER_SHOW_ALL is implied if the other styles aren't included
172 long listCtrlStyle
= 0;
173 if (hideTypeSelector
)
174 listCtrlStyle
= wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR
;
176 ////@begin wxRichTextStyleOrganiserDialog content construction
177 wxRichTextStyleOrganiserDialog
* itemDialog1
= this;
179 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
180 itemDialog1
->SetSizer(itemBoxSizer2
);
182 m_innerSizer
= new wxBoxSizer(wxVERTICAL
);
183 itemBoxSizer2
->Add(m_innerSizer
, 1, wxGROW
|wxALL
, 5);
185 m_buttonSizerParent
= new wxBoxSizer(wxHORIZONTAL
);
186 m_innerSizer
->Add(m_buttonSizerParent
, 1, wxGROW
, 5);
188 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
189 m_buttonSizerParent
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
191 wxStaticText
* itemStaticText6
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Styles:"), wxDefaultPosition
, wxDefaultSize
, 0 );
192 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
194 m_stylesListBox
= new wxRichTextStyleListCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_STYLES
, wxDefaultPosition
, wxSize(200, 350), wxSIMPLE_BORDER
|listCtrlStyle
);
195 m_stylesListBox
->SetHelpText(_("The available styles."));
197 m_stylesListBox
->SetToolTip(_("The available styles."));
198 itemBoxSizer5
->Add(m_stylesListBox
, 1, wxGROW
|wxALL
, 5);
200 wxBoxSizer
* itemBoxSizer8
= new wxBoxSizer(wxVERTICAL
);
201 m_buttonSizerParent
->Add(itemBoxSizer8
, 0, wxGROW
, 5);
203 wxStaticText
* itemStaticText9
= new wxStaticText( itemDialog1
, wxID_STATIC
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
204 itemBoxSizer8
->Add(itemStaticText9
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
206 m_previewCtrl
= new wxRichTextCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_PREVIEW
, wxEmptyString
, wxDefaultPosition
, wxSize(310, 200), wxSIMPLE_BORDER
|wxTE_READONLY
);
207 m_previewCtrl
->SetHelpText(_("The style preview."));
209 m_previewCtrl
->SetToolTip(_("The style preview."));
210 itemBoxSizer8
->Add(m_previewCtrl
, 1, wxGROW
|wxALL
, 5);
212 m_buttonSizer
= new wxBoxSizer(wxVERTICAL
);
213 m_buttonSizerParent
->Add(m_buttonSizer
, 0, wxGROW
, 5);
215 wxStaticText
* itemStaticText12
= new wxStaticText( itemDialog1
, wxID_STATIC
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
216 m_buttonSizer
->Add(itemStaticText12
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
218 m_newCharacter
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
, _("New &Character Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
219 m_newCharacter
->SetHelpText(_("Click to create a new character style."));
221 m_newCharacter
->SetToolTip(_("Click to create a new character style."));
222 m_buttonSizer
->Add(m_newCharacter
, 0, wxGROW
|wxALL
, 5);
224 m_newParagraph
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, _("New &Paragraph Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
225 m_newParagraph
->SetHelpText(_("Click to create a new paragraph style."));
227 m_newParagraph
->SetToolTip(_("Click to create a new paragraph style."));
228 m_buttonSizer
->Add(m_newParagraph
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
230 m_newList
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, _("New &List Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
231 m_newList
->SetHelpText(_("Click to create a new list style."));
233 m_newList
->SetToolTip(_("Click to create a new list style."));
234 m_buttonSizer
->Add(m_newList
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
236 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
238 m_applyStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, _("&Apply Style"), wxDefaultPosition
, wxDefaultSize
, 0 );
239 m_applyStyle
->SetHelpText(_("Click to apply the selected style."));
241 m_applyStyle
->SetToolTip(_("Click to apply the selected style."));
242 m_buttonSizer
->Add(m_applyStyle
, 0, wxGROW
|wxALL
, 5);
244 m_renameStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, _("&Rename Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
245 m_renameStyle
->SetHelpText(_("Click to rename the selected style."));
247 m_renameStyle
->SetToolTip(_("Click to rename the selected style."));
248 m_buttonSizer
->Add(m_renameStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
250 m_editStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, _("&Edit Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
251 m_editStyle
->SetHelpText(_("Click to edit the selected style."));
253 m_editStyle
->SetToolTip(_("Click to edit the selected style."));
254 m_buttonSizer
->Add(m_editStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
256 m_deleteStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, _("&Delete Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
257 m_deleteStyle
->SetHelpText(_("Click to delete the selected style."));
259 m_deleteStyle
->SetToolTip(_("Click to delete the selected style."));
260 m_buttonSizer
->Add(m_deleteStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
262 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
264 m_closeButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
265 m_closeButton
->SetDefault();
266 m_closeButton
->SetHelpText(_("Click to close this window."));
268 m_closeButton
->SetToolTip(_("Click to close this window."));
269 m_buttonSizer
->Add(m_closeButton
, 0, wxGROW
|wxALL
, 5);
271 m_bottomButtonSizer
= new wxBoxSizer(wxHORIZONTAL
);
272 m_innerSizer
->Add(m_bottomButtonSizer
, 0, wxGROW
, 5);
274 m_restartNumberingCtrl
= new wxCheckBox( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RESTART_NUMBERING
, _("&Restart numbering"), wxDefaultPosition
, wxDefaultSize
, 0 );
275 m_restartNumberingCtrl
->SetValue(false);
276 m_restartNumberingCtrl
->SetHelpText(_("Check to restart numbering."));
278 m_restartNumberingCtrl
->SetToolTip(_("Check to restart numbering."));
279 m_bottomButtonSizer
->Add(m_restartNumberingCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
281 m_bottomButtonSizer
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
283 m_okButton
= new wxButton( itemDialog1
, wxID_OK
, _("OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
284 m_okButton
->SetDefault();
285 m_okButton
->SetHelpText(_("Click to confirm your selection."));
287 m_okButton
->SetToolTip(_("Click to confirm your selection."));
288 m_bottomButtonSizer
->Add(m_okButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
290 m_cancelButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
291 m_cancelButton
->SetHelpText(_("Click to cancel this window."));
293 m_cancelButton
->SetToolTip(_("Click to cancel this window."));
294 m_bottomButtonSizer
->Add(m_cancelButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
296 ////@end wxRichTextStyleOrganiserDialog content construction
298 if ((m_flags
& wxRICHTEXT_ORGANISER_CREATE_STYLES
) == 0)
300 m_buttonSizer
->Show(m_newCharacter
, false);
301 m_buttonSizer
->Show(m_newParagraph
, false);
302 m_buttonSizer
->Show(m_newList
, false);
304 if ((m_flags
& wxRICHTEXT_ORGANISER_DELETE_STYLES
) == 0)
306 m_buttonSizer
->Show(m_deleteStyle
, false);
308 if ((m_flags
& wxRICHTEXT_ORGANISER_APPLY_STYLES
) == 0)
310 m_buttonSizer
->Show(m_applyStyle
, false);
312 if ((m_flags
& wxRICHTEXT_ORGANISER_EDIT_STYLES
) == 0)
314 m_buttonSizer
->Show(m_editStyle
, false);
316 if ((m_flags
& wxRICHTEXT_ORGANISER_RENAME_STYLES
) == 0)
318 m_buttonSizer
->Show(m_renameStyle
, false);
320 if ((m_flags
& wxRICHTEXT_ORGANISER_RENUMBER
) == 0)
322 m_bottomButtonSizer
->Show(m_restartNumberingCtrl
, false);
325 if ((m_flags
& wxRICHTEXT_ORGANISER_OK_CANCEL
) == 0)
327 m_bottomButtonSizer
->Show(m_okButton
, false);
328 m_bottomButtonSizer
->Show(m_cancelButton
, false);
332 m_buttonSizer
->Show(m_closeButton
, false);
335 // No buttons in the vertical group are shown, so hide the whole sizer
336 if ((m_flags
& wxRICHTEXT_ORGANISER_ORGANISE
) == 0)
338 m_buttonSizerParent
->Show(m_buttonSizer
, false);
341 // No buttons in the horizontal group are shown, so hide the whole sizer
342 if ((m_flags
& (wxRICHTEXT_ORGANISER_OK_CANCEL
|wxRICHTEXT_ORGANISER_RENUMBER
)) == 0)
344 m_innerSizer
->Show(m_bottomButtonSizer
, false);
347 if (hideTypeSelector
)
349 m_stylesListBox
->GetStyleListBox()->SetStyleType(typesToShow
);
352 m_stylesListBox
->SetStyleSheet(m_richTextStyleSheet
);
353 m_stylesListBox
->SetRichTextCtrl(m_richTextCtrl
);
354 m_stylesListBox
->UpdateStyles();
355 m_stylesListBox
->GetStyleListBox()->SetAutoSetSelection(false); // stop idle-time auto selection
356 if (m_stylesListBox
->GetStyleListBox()->GetItemCount() > 0)
358 m_stylesListBox
->GetStyleListBox()->SetSelection(0);
364 * Should we show tooltips?
367 /// Get selected style name or definition
368 wxString
wxRichTextStyleOrganiserDialog::GetSelectedStyle() const
370 wxRichTextStyleDefinition
* def
= GetSelectedStyleDefinition();
372 return def
->GetName();
374 return wxEmptyString
;
377 wxRichTextStyleDefinition
* wxRichTextStyleOrganiserDialog::GetSelectedStyleDefinition() const
379 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
380 return m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
384 /// Transfer data from/to window
385 bool wxRichTextStyleOrganiserDialog::TransferDataFromWindow()
387 if (!wxDialog::TransferDataFromWindow())
390 m_restartNumbering
= m_restartNumberingCtrl
->GetValue();
395 bool wxRichTextStyleOrganiserDialog::TransferDataToWindow()
397 if (!wxDialog::TransferDataToWindow())
400 m_restartNumberingCtrl
->SetValue(m_restartNumbering
);
405 /// Show preview for given or selected preview
406 void wxRichTextStyleOrganiserDialog::ShowPreview(int sel
)
408 static const wxChar
* s_para1
= wxT("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
409 Nullam ante sapien, vestibulum nonummy, pulvinar sed, luctus ut, lacus.");
411 static const wxChar
* s_para2List
= wxT("Duis pharetra consequat dui. Nullam vitae justo id mauris lobortis interdum.");
413 static const wxChar
* s_para2
= wxT("Duis pharetra consequat dui. Cum sociis natoque penatibus \
414 et magnis dis parturient montes, nascetur ridiculus mus. Nullam vitae justo id mauris lobortis interdum.");
416 static const wxChar
* s_para3
= wxT("\nInteger convallis dolor at augue \
417 iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n");
421 sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
426 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
428 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
429 //wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
430 //wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition);
432 wxTextAttrEx
attr(def
->GetStyle());
434 attr
.SetFlags(attr
.GetFlags() &
435 (wxTEXT_ATTR_ALIGNMENT
|wxTEXT_ATTR_LEFT_INDENT
|wxTEXT_ATTR_RIGHT_INDENT
|wxTEXT_ATTR_PARA_SPACING_BEFORE
|wxTEXT_ATTR_PARA_SPACING_AFTER
|
436 wxTEXT_ATTR_LINE_SPACING
|
437 wxTEXT_ATTR_BULLET_STYLE
|wxTEXT_ATTR_BULLET_NUMBER
|wxTEXT_ATTR_BULLET_SYMBOL
));
440 wxFont
font(m_previewCtrl
->GetFont());
441 font
.SetPointSize(9);
442 m_previewCtrl
->SetFont(font
);
444 wxTextAttrEx normalParaAttr
;
445 normalParaAttr
.SetFont(font
);
446 normalParaAttr
.SetTextColour(wxColour(wxT("LIGHT GREY")));
448 m_previewCtrl
->Freeze();
449 m_previewCtrl
->Clear();
451 m_previewCtrl
->BeginStyle(normalParaAttr
);
452 m_previewCtrl
->WriteText(s_para1
);
453 m_previewCtrl
->EndStyle();
455 m_previewCtrl
->BeginStyle(attr
);
459 long listStart
= m_previewCtrl
->GetInsertionPoint() + 1;
461 for (i
= 0; i
< 10; i
++)
463 wxTextAttrEx levelAttr
= * listDef
->GetLevelAttributes(i
);
464 levelAttr
.SetBulletNumber(1);
465 m_previewCtrl
->BeginStyle(levelAttr
);
466 m_previewCtrl
->WriteText(wxString::Format(wxT("\nList level %d. "), i
+1) + s_para2List
);
467 m_previewCtrl
->EndStyle();
469 long listEnd
= m_previewCtrl
->GetInsertionPoint();
470 m_previewCtrl
->NumberList(wxRichTextRange(listStart
, listEnd
), listDef
);
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())