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
70 IMPLEMENT_HELP_PROVISION(wxRichTextStyleOrganiserDialog
)
73 * wxRichTextStyleOrganiserDialog constructors
76 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( )
81 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
84 Create(flags
, sheet
, ctrl
, parent
, id
, caption
, pos
, size
, style
);
88 * Member initialisation for wxSymbolPickerDialog
91 void wxRichTextStyleOrganiserDialog::Init()
93 m_richTextStyleSheet
= NULL
;
94 m_richTextCtrl
= NULL
;
97 m_restartNumbering
= true;
99 ////@begin wxRichTextStyleOrganiserDialog member initialisation
101 m_buttonSizerParent
= NULL
;
102 m_stylesListBox
= NULL
;
103 m_previewCtrl
= NULL
;
104 m_buttonSizer
= NULL
;
105 m_newCharacter
= NULL
;
106 m_newParagraph
= NULL
;
109 m_renameStyle
= NULL
;
111 m_deleteStyle
= NULL
;
112 m_closeButton
= NULL
;
113 m_bottomButtonSizer
= NULL
;
114 m_restartNumberingCtrl
= NULL
;
115 m_stdButtonSizer
= NULL
;
117 m_cancelButton
= NULL
;
118 ////@end wxRichTextStyleOrganiserDialog member initialisation
122 * wxRichTextStyleOrganiserDialog creator
125 bool wxRichTextStyleOrganiserDialog::Create( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
127 m_richTextStyleSheet
= sheet
;
128 m_richTextCtrl
= ctrl
;
131 ////@begin wxRichTextStyleOrganiserDialog creation
132 SetExtraStyle(wxWS_EX_BLOCK_EVENTS
|wxDIALOG_EX_CONTEXTHELP
);
133 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
138 GetSizer()->SetSizeHints(this);
141 ////@end wxRichTextStyleOrganiserDialog creation
146 * Control creation for wxRichTextStyleOrganiserDialog
149 void wxRichTextStyleOrganiserDialog::CreateControls()
151 bool hideTypeSelector
= false;
152 wxRichTextStyleListBox::wxRichTextStyleType typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL
;
154 if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_CHARACTER
) != 0)
156 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
;
157 hideTypeSelector
= true;
159 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_PARAGRAPH
) != 0)
161 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH
;
162 hideTypeSelector
= true;
164 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_LIST
) != 0)
166 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST
;
167 hideTypeSelector
= true;
171 // wxRICHTEXT_ORGANISER_SHOW_ALL is implied if the other styles aren't included
174 long listCtrlStyle
= 0;
175 if (hideTypeSelector
)
176 listCtrlStyle
= wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR
;
178 ////@begin wxRichTextStyleOrganiserDialog content construction
179 wxRichTextStyleOrganiserDialog
* itemDialog1
= this;
181 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
182 itemDialog1
->SetSizer(itemBoxSizer2
);
184 m_innerSizer
= new wxBoxSizer(wxVERTICAL
);
185 itemBoxSizer2
->Add(m_innerSizer
, 1, wxGROW
|wxALL
, 5);
187 m_buttonSizerParent
= new wxBoxSizer(wxHORIZONTAL
);
188 m_innerSizer
->Add(m_buttonSizerParent
, 1, wxGROW
, 5);
190 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
191 m_buttonSizerParent
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
193 wxStaticText
* itemStaticText6
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Styles:"), wxDefaultPosition
, wxDefaultSize
, 0 );
194 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
196 m_stylesListBox
= new wxRichTextStyleListCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_STYLES
, wxDefaultPosition
, wxSize(280, 260), listCtrlStyle
);
197 m_stylesListBox
->SetHelpText(_("The available styles."));
198 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
199 m_stylesListBox
->SetToolTip(_("The available styles."));
200 itemBoxSizer5
->Add(m_stylesListBox
, 1, wxGROW
|wxALL
, 5);
202 wxBoxSizer
* itemBoxSizer8
= new wxBoxSizer(wxVERTICAL
);
203 m_buttonSizerParent
->Add(itemBoxSizer8
, 0, wxGROW
, 5);
205 wxStaticText
* itemStaticText9
= new wxStaticText( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
206 itemBoxSizer8
->Add(itemStaticText9
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
208 m_previewCtrl
= new wxRichTextCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_PREVIEW
, wxEmptyString
, wxDefaultPosition
, wxSize(250, 200), wxVSCROLL
|wxTE_READONLY
);
209 m_previewCtrl
->SetHelpText(_("The style preview."));
210 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
211 m_previewCtrl
->SetToolTip(_("The style preview."));
212 itemBoxSizer8
->Add(m_previewCtrl
, 1, wxGROW
|wxALL
, 5);
214 m_buttonSizer
= new wxBoxSizer(wxVERTICAL
);
215 m_buttonSizerParent
->Add(m_buttonSizer
, 0, wxGROW
, 5);
217 wxStaticText
* itemStaticText12
= new wxStaticText( itemDialog1
, wxID_STATIC
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
218 m_buttonSizer
->Add(itemStaticText12
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
220 m_newCharacter
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
, _("New &Character Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
221 m_newCharacter
->SetHelpText(_("Click to create a new character style."));
222 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
223 m_newCharacter
->SetToolTip(_("Click to create a new character style."));
224 m_buttonSizer
->Add(m_newCharacter
, 0, wxGROW
|wxALL
, 5);
226 m_newParagraph
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, _("New &Paragraph Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
227 m_newParagraph
->SetHelpText(_("Click to create a new paragraph style."));
228 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
229 m_newParagraph
->SetToolTip(_("Click to create a new paragraph style."));
230 m_buttonSizer
->Add(m_newParagraph
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
232 m_newList
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, _("New &List Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
233 m_newList
->SetHelpText(_("Click to create a new list style."));
234 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
235 m_newList
->SetToolTip(_("Click to create a new list style."));
236 m_buttonSizer
->Add(m_newList
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
238 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
240 m_applyStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, _("&Apply Style"), wxDefaultPosition
, wxDefaultSize
, 0 );
241 m_applyStyle
->SetHelpText(_("Click to apply the selected style."));
242 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
243 m_applyStyle
->SetToolTip(_("Click to apply the selected style."));
244 m_buttonSizer
->Add(m_applyStyle
, 0, wxGROW
|wxALL
, 5);
246 m_renameStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, _("&Rename Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
247 m_renameStyle
->SetHelpText(_("Click to rename the selected style."));
248 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
249 m_renameStyle
->SetToolTip(_("Click to rename the selected style."));
250 m_buttonSizer
->Add(m_renameStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
252 m_editStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, _("&Edit Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
253 m_editStyle
->SetHelpText(_("Click to edit the selected style."));
254 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
255 m_editStyle
->SetToolTip(_("Click to edit the selected style."));
256 m_buttonSizer
->Add(m_editStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
258 m_deleteStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, _("&Delete Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
259 m_deleteStyle
->SetHelpText(_("Click to delete the selected style."));
260 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
261 m_deleteStyle
->SetToolTip(_("Click to delete the selected style."));
262 m_buttonSizer
->Add(m_deleteStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
264 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
266 m_closeButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
267 m_closeButton
->SetDefault();
268 m_closeButton
->SetHelpText(_("Click to close this window."));
269 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
270 m_closeButton
->SetToolTip(_("Click to close this window."));
271 m_buttonSizer
->Add(m_closeButton
, 0, wxGROW
|wxALL
, 5);
273 m_bottomButtonSizer
= new wxBoxSizer(wxHORIZONTAL
);
274 m_innerSizer
->Add(m_bottomButtonSizer
, 0, wxGROW
, 5);
276 m_restartNumberingCtrl
= new wxCheckBox( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RESTART_NUMBERING
, _("&Restart numbering"), wxDefaultPosition
, wxDefaultSize
, 0 );
277 m_restartNumberingCtrl
->SetValue(false);
278 m_restartNumberingCtrl
->SetHelpText(_("Check to restart numbering."));
279 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
280 m_restartNumberingCtrl
->SetToolTip(_("Check to restart numbering."));
281 m_bottomButtonSizer
->Add(m_restartNumberingCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
283 m_stdButtonSizer
= new wxStdDialogButtonSizer
;
285 m_bottomButtonSizer
->Add(m_stdButtonSizer
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
286 m_okButton
= new wxButton( itemDialog1
, wxID_OK
, _("OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
287 m_stdButtonSizer
->AddButton(m_okButton
);
289 m_cancelButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
290 m_stdButtonSizer
->AddButton(m_cancelButton
);
292 wxButton
* itemButton28
= new wxButton( itemDialog1
, wxID_HELP
, _("&Help"), wxDefaultPosition
, wxDefaultSize
, 0 );
293 m_stdButtonSizer
->AddButton(itemButton28
);
295 m_stdButtonSizer
->Realize();
297 ////@end wxRichTextStyleOrganiserDialog content construction
299 if (GetHelpId() == -1)
301 wxWindow
* button
= FindWindowById(wxID_HELP
);
303 m_stdButtonSizer
->Show(button
, false);
306 if ((m_flags
& wxRICHTEXT_ORGANISER_CREATE_STYLES
) == 0)
308 m_buttonSizer
->Show(m_newCharacter
, false);
309 m_buttonSizer
->Show(m_newParagraph
, false);
310 m_buttonSizer
->Show(m_newList
, false);
312 if ((m_flags
& wxRICHTEXT_ORGANISER_DELETE_STYLES
) == 0)
314 m_buttonSizer
->Show(m_deleteStyle
, false);
316 if ((m_flags
& wxRICHTEXT_ORGANISER_APPLY_STYLES
) == 0)
318 m_buttonSizer
->Show(m_applyStyle
, false);
320 if ((m_flags
& wxRICHTEXT_ORGANISER_EDIT_STYLES
) == 0)
322 m_buttonSizer
->Show(m_editStyle
, false);
324 if ((m_flags
& wxRICHTEXT_ORGANISER_RENAME_STYLES
) == 0)
326 m_buttonSizer
->Show(m_renameStyle
, false);
328 if ((m_flags
& wxRICHTEXT_ORGANISER_RENUMBER
) == 0)
330 m_bottomButtonSizer
->Show(m_restartNumberingCtrl
, false);
333 if ((m_flags
& wxRICHTEXT_ORGANISER_OK_CANCEL
) == 0)
335 m_stdButtonSizer
->Show(m_okButton
, false);
336 m_stdButtonSizer
->Show(m_cancelButton
, false);
340 m_buttonSizer
->Show(m_closeButton
, false);
343 // No buttons in the vertical group are shown, so hide the whole sizer
344 if ((m_flags
& wxRICHTEXT_ORGANISER_ORGANISE
) == 0)
346 m_buttonSizerParent
->Show(m_buttonSizer
, false);
349 // No buttons in the horizontal group are shown, so hide the whole sizer
350 if ((m_flags
& (wxRICHTEXT_ORGANISER_OK_CANCEL
|wxRICHTEXT_ORGANISER_RENUMBER
)) == 0)
352 m_innerSizer
->Show(m_bottomButtonSizer
, false);
355 if (hideTypeSelector
)
357 m_stylesListBox
->GetStyleListBox()->SetStyleType(typesToShow
);
360 m_stylesListBox
->SetStyleSheet(m_richTextStyleSheet
);
361 m_stylesListBox
->SetRichTextCtrl(m_richTextCtrl
);
362 m_stylesListBox
->UpdateStyles();
363 m_stylesListBox
->GetStyleListBox()->SetAutoSetSelection(false); // stop idle-time auto selection
364 if (m_stylesListBox
->GetStyleListBox()->GetItemCount() > 0)
366 m_stylesListBox
->GetStyleListBox()->SetSelection(0);
372 * Should we show tooltips?
375 /// Get selected style name or definition
376 wxString
wxRichTextStyleOrganiserDialog::GetSelectedStyle() const
378 wxRichTextStyleDefinition
* def
= GetSelectedStyleDefinition();
380 return def
->GetName();
382 return wxEmptyString
;
385 wxRichTextStyleDefinition
* wxRichTextStyleOrganiserDialog::GetSelectedStyleDefinition() const
387 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
388 return m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
392 /// Transfer data from/to window
393 bool wxRichTextStyleOrganiserDialog::TransferDataFromWindow()
395 if (!wxDialog::TransferDataFromWindow())
398 m_restartNumbering
= m_restartNumberingCtrl
->GetValue();
403 bool wxRichTextStyleOrganiserDialog::TransferDataToWindow()
405 if (!wxDialog::TransferDataToWindow())
408 m_restartNumberingCtrl
->SetValue(m_restartNumbering
);
413 /// Show preview for given or selected preview
414 void wxRichTextStyleOrganiserDialog::ShowPreview(int sel
)
416 static const wxChar
* s_para1
= wxT("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
417 Nullam ante sapien, vestibulum nonummy, pulvinar sed, luctus ut, lacus.\n");
419 static const wxChar
* s_para2List
= wxT("Duis pharetra consequat dui. Nullam vitae justo id mauris lobortis interdum.\n");
421 static const wxChar
* s_para2
= wxT("Duis pharetra consequat dui. Cum sociis natoque penatibus \
422 et magnis dis parturient montes, nascetur ridiculus mus. Nullam vitae justo id mauris lobortis interdum.\n");
424 static const wxChar
* s_para3
= wxT("Integer convallis dolor at augue \
425 iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n");
429 sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
434 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
436 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
438 wxStaticText
* labelCtrl
= (wxStaticText
*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
);
440 labelCtrl
->SetLabel(def
->GetName() + wxT(":"));
442 wxRichTextAttr
attr(def
->GetStyleMergedWithBase(GetStyleSheet()));
444 wxFont
font(m_previewCtrl
->GetFont());
445 font
.SetPointSize(9);
446 m_previewCtrl
->SetFont(font
);
448 wxRichTextAttr normalParaAttr
;
449 normalParaAttr
.SetFont(font
);
450 normalParaAttr
.SetTextColour(wxColour(wxT("LIGHT GREY")));
452 m_previewCtrl
->Freeze();
453 m_previewCtrl
->Clear();
455 m_previewCtrl
->BeginStyle(normalParaAttr
);
456 m_previewCtrl
->WriteText(s_para1
);
457 m_previewCtrl
->EndStyle();
459 m_previewCtrl
->BeginStyle(attr
);
463 long listStart
= m_previewCtrl
->GetInsertionPoint() + 1;
465 for (i
= 0; i
< 10; i
++)
467 wxRichTextAttr levelAttr
= * listDef
->GetLevelAttributes(i
);
468 levelAttr
.SetBulletNumber(1);
469 m_previewCtrl
->BeginStyle(levelAttr
);
470 m_previewCtrl
->WriteText(wxString::Format(wxT("List level %d. "), i
+1) + s_para2List
);
471 m_previewCtrl
->EndStyle();
473 long listEnd
= m_previewCtrl
->GetInsertionPoint();
474 m_previewCtrl
->NumberList(wxRichTextRange(listStart
, listEnd
), listDef
);
478 m_previewCtrl
->WriteText(s_para2
);
481 m_previewCtrl
->EndStyle();
483 m_previewCtrl
->BeginStyle(normalParaAttr
);
484 m_previewCtrl
->WriteText(s_para3
);
485 m_previewCtrl
->EndStyle();
487 m_previewCtrl
->Thaw();
490 /// Clears the preview
491 void wxRichTextStyleOrganiserDialog::ClearPreview()
493 m_previewCtrl
->Clear();
494 wxStaticText
* labelCtrl
= (wxStaticText
*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
);
496 labelCtrl
->SetLabel(wxEmptyString
);
499 bool wxRichTextStyleOrganiserDialog::ApplyStyle(wxRichTextCtrl
* ctrl
)
501 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
505 ctrl
= GetRichTextCtrl();
508 if (!ctrl
->HasSelection())
512 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
513 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
515 if (listDef
&& m_restartNumberingCtrl
->GetValue())
517 wxRichTextRange range
= ctrl
->GetSelectionRange();
518 return ctrl
->SetListStyle(range
, listDef
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_RENUMBER
);
522 return ctrl
->ApplyStyle(def
);
527 * Get bitmap resources
530 wxBitmap
wxRichTextStyleOrganiserDialog::GetBitmapResource( const wxString
& name
)
533 ////@begin wxRichTextStyleOrganiserDialog bitmap retrieval
536 ////@end wxRichTextStyleOrganiserDialog bitmap retrieval
543 wxIcon
wxRichTextStyleOrganiserDialog::GetIconResource( const wxString
& name
)
546 ////@begin wxRichTextStyleOrganiserDialog icon retrieval
549 ////@end wxRichTextStyleOrganiserDialog icon retrieval
553 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
556 void wxRichTextStyleOrganiserDialog::OnApplyClick( wxCommandEvent
& WXUNUSED(event
) )
562 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
565 void wxRichTextStyleOrganiserDialog::OnApplyUpdate( wxUpdateUIEvent
& event
)
567 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_APPLY_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
572 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
575 void wxRichTextStyleOrganiserDialog::OnNewCharClick( wxCommandEvent
& WXUNUSED(event
) )
577 wxString styleName
= wxGetTextFromUser(_("Enter a character style name"), _("New Style"));
578 if (!styleName
.IsEmpty())
580 if (GetStyleSheet()->FindCharacterStyle(styleName
))
582 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
586 wxRichTextCharacterStyleDefinition
* style
= new wxRichTextCharacterStyleDefinition(styleName
);
588 int pages
= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_STYLE_EDITOR
;
589 wxRichTextFormattingDialog formatDlg
;
590 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
591 formatDlg
.Create(pages
, this);
593 if (formatDlg
.ShowModal() == wxID_OK
)
595 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
597 (*((wxRichTextCharacterStyleDefinition
* ) style
)) = (*charDef
);
599 GetStyleSheet()->AddCharacterStyle(style
);
601 m_stylesListBox
->UpdateStyles();
610 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
613 void wxRichTextStyleOrganiserDialog::OnNewCharUpdate( wxUpdateUIEvent
& event
)
615 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
620 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
623 void wxRichTextStyleOrganiserDialog::OnNewParaClick( wxCommandEvent
& WXUNUSED(event
) )
625 wxString styleName
= wxGetTextFromUser(_("Enter a paragraph style name"), _("New Style"));
626 if (!styleName
.IsEmpty())
628 if (GetStyleSheet()->FindParagraphStyle(styleName
))
630 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
634 wxRichTextParagraphStyleDefinition
* style
= new wxRichTextParagraphStyleDefinition(styleName
);
636 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
637 wxRichTextFormattingDialog formatDlg
;
638 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
639 formatDlg
.Create(pages
, this);
641 if (formatDlg
.ShowModal() == wxID_OK
)
643 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
645 (*((wxRichTextParagraphStyleDefinition
* ) style
)) = (*paraDef
);
647 GetStyleSheet()->AddParagraphStyle(style
);
649 m_stylesListBox
->UpdateStyles();
658 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
661 void wxRichTextStyleOrganiserDialog::OnNewParaUpdate( wxUpdateUIEvent
& event
)
663 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
668 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
671 void wxRichTextStyleOrganiserDialog::OnEditClick( wxCommandEvent
& WXUNUSED(event
) )
673 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
674 if (sel
!= wxNOT_FOUND
)
676 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
678 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
;
680 if (def
->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition
)))
682 pages
|= wxRICHTEXT_FORMAT_FONT
;
684 else if (def
->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition
)))
686 pages
|= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
688 else if (def
->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition
)))
690 pages
|= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
693 wxRichTextFormattingDialog formatDlg
;
694 formatDlg
.SetStyleDefinition(*def
, GetStyleSheet());
695 formatDlg
.Create(pages
, this);
697 if (formatDlg
.ShowModal() == wxID_OK
)
699 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
700 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
701 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
705 (*((wxRichTextListStyleDefinition
* ) def
)) = (*listDef
);
709 (*((wxRichTextParagraphStyleDefinition
* ) def
)) = (*paraDef
);
713 (*((wxRichTextCharacterStyleDefinition
* ) def
)) = (*charDef
);
716 m_stylesListBox
->UpdateStyles();
717 m_stylesListBox
->GetStyleListBox()->SetSelection(sel
);
724 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
727 void wxRichTextStyleOrganiserDialog::OnEditUpdate( wxUpdateUIEvent
& event
)
729 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_EDIT_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
734 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
737 void wxRichTextStyleOrganiserDialog::OnDeleteClick( wxCommandEvent
& WXUNUSED(event
) )
739 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
740 if (sel
!= wxNOT_FOUND
)
742 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
743 wxString
name(def
->GetName());
744 if (wxYES
== wxMessageBox(wxString::Format(_("Delete style %s?"), name
), _("Delete Style"), wxYES_NO
|wxICON_QUESTION
, this))
746 m_stylesListBox
->GetStyleListBox()->SetItemCount(0);
748 if (def
->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition
)))
749 GetStyleSheet()->RemoveListStyle((wxRichTextListStyleDefinition
*) def
, true);
750 else if (def
->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition
)))
751 GetStyleSheet()->RemoveParagraphStyle((wxRichTextParagraphStyleDefinition
*) def
, true);
752 else if (def
->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition
)))
753 GetStyleSheet()->RemoveCharacterStyle((wxRichTextCharacterStyleDefinition
*) def
, true);
755 m_stylesListBox
->UpdateStyles();
757 if (m_stylesListBox
->GetStyleListBox()->GetSelection() != -1)
766 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
769 void wxRichTextStyleOrganiserDialog::OnDeleteUpdate( wxUpdateUIEvent
& event
)
771 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_DELETE_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
775 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
778 void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent
& WXUNUSED(event
) )
780 wxString styleName
= wxGetTextFromUser(_("Enter a list style name"), _("New Style"));
781 if (!styleName
.IsEmpty())
783 if (GetStyleSheet()->FindListStyle(styleName
))
785 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
789 wxRichTextListStyleDefinition
* style
= new wxRichTextListStyleDefinition(styleName
);
791 // Initialize the style to make it easier to edit
793 for (i
= 0; i
< 10; i
++)
795 wxString bulletSymbol
;
797 bulletSymbol
= wxT("*");
799 bulletSymbol
= wxT("-");
801 bulletSymbol
= wxT("*");
803 bulletSymbol
= wxT("-");
805 bulletSymbol
= wxT("*");
807 style
->SetAttributes(i
, (i
+1)*60, 60, wxTEXT_ATTR_BULLET_STYLE_SYMBOL
, bulletSymbol
);
810 int pages
= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
811 wxRichTextFormattingDialog formatDlg
;
812 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
813 formatDlg
.Create(pages
, this);
815 if (formatDlg
.ShowModal() == wxID_OK
)
817 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
819 (*((wxRichTextListStyleDefinition
* ) style
)) = (*listDef
);
821 GetStyleSheet()->AddListStyle(style
);
823 m_stylesListBox
->UpdateStyles();
832 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
835 void wxRichTextStyleOrganiserDialog::OnNewListUpdate( wxUpdateUIEvent
& event
)
837 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
841 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
844 void wxRichTextStyleOrganiserDialog::OnRenameClick( wxCommandEvent
& WXUNUSED(event
) )
846 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
849 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
853 wxString styleName
= wxGetTextFromUser(_("Enter a new style name"), _("New Style"), def
->GetName());
854 if (!styleName
.IsEmpty())
856 if (styleName
== def
->GetName())
859 if (GetStyleSheet()->FindParagraphStyle(styleName
) || GetStyleSheet()->FindCharacterStyle(styleName
) || GetStyleSheet()->FindListStyle(styleName
))
861 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
865 def
->SetName(styleName
);
866 m_stylesListBox
->UpdateStyles();
871 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
874 void wxRichTextStyleOrganiserDialog::OnRenameUpdate( wxUpdateUIEvent
& event
)
876 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_RENAME_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
880 void wxRichTextStyleOrganiserDialog::OnListSelection(wxCommandEvent
& event
)
882 if (event
.GetEventObject() == m_stylesListBox
->GetStyleListBox())