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_NEW_BOX
, wxRichTextStyleOrganiserDialog::OnNewBoxClick
)
55 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
, wxRichTextStyleOrganiserDialog::OnNewBoxUpdate
)
57 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, wxRichTextStyleOrganiserDialog::OnApplyClick
)
58 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, wxRichTextStyleOrganiserDialog::OnApplyUpdate
)
60 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, wxRichTextStyleOrganiserDialog::OnRenameClick
)
61 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, wxRichTextStyleOrganiserDialog::OnRenameUpdate
)
63 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, wxRichTextStyleOrganiserDialog::OnEditClick
)
64 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, wxRichTextStyleOrganiserDialog::OnEditUpdate
)
66 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, wxRichTextStyleOrganiserDialog::OnDeleteClick
)
67 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, wxRichTextStyleOrganiserDialog::OnDeleteUpdate
)
69 ////@end wxRichTextStyleOrganiserDialog event table entries
73 IMPLEMENT_HELP_PROVISION(wxRichTextStyleOrganiserDialog
)
76 * wxRichTextStyleOrganiserDialog constructors
79 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( )
84 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
87 Create(flags
, sheet
, ctrl
, parent
, id
, caption
, pos
, size
, style
);
91 * Member initialisation for wxSymbolPickerDialog
94 void wxRichTextStyleOrganiserDialog::Init()
96 m_richTextStyleSheet
= NULL
;
97 m_richTextCtrl
= NULL
;
100 m_restartNumbering
= true;
102 ////@begin wxRichTextStyleOrganiserDialog member initialisation
104 m_buttonSizerParent
= NULL
;
105 m_stylesListBox
= NULL
;
106 m_previewCtrl
= NULL
;
107 m_buttonSizer
= NULL
;
108 m_newCharacter
= NULL
;
109 m_newParagraph
= NULL
;
113 m_renameStyle
= NULL
;
115 m_deleteStyle
= NULL
;
116 m_closeButton
= NULL
;
117 m_bottomButtonSizer
= NULL
;
118 m_restartNumberingCtrl
= NULL
;
119 m_stdButtonSizer
= NULL
;
121 m_cancelButton
= NULL
;
122 ////@end wxRichTextStyleOrganiserDialog member initialisation
126 * wxRichTextStyleOrganiserDialog creator
129 bool wxRichTextStyleOrganiserDialog::Create( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
131 m_richTextStyleSheet
= sheet
;
132 m_richTextCtrl
= ctrl
;
135 ////@begin wxRichTextStyleOrganiserDialog creation
136 SetExtraStyle(wxWS_EX_BLOCK_EVENTS
|wxDIALOG_EX_CONTEXTHELP
);
137 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
142 GetSizer()->SetSizeHints(this);
145 ////@end wxRichTextStyleOrganiserDialog creation
150 * Control creation for wxRichTextStyleOrganiserDialog
153 void wxRichTextStyleOrganiserDialog::CreateControls()
155 bool hideTypeSelector
= false;
156 wxRichTextStyleListBox::wxRichTextStyleType typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL
;
158 if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_CHARACTER
) != 0)
160 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
;
161 hideTypeSelector
= true;
163 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_PARAGRAPH
) != 0)
165 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH
;
166 hideTypeSelector
= true;
168 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_BOX
) != 0)
170 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_BOX
;
171 hideTypeSelector
= true;
173 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_LIST
) != 0)
175 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST
;
176 hideTypeSelector
= true;
180 // wxRICHTEXT_ORGANISER_SHOW_ALL is implied if the other styles aren't included
183 long listCtrlStyle
= 0;
184 if (hideTypeSelector
)
185 listCtrlStyle
= wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR
;
187 ////@begin wxRichTextStyleOrganiserDialog content construction
188 wxRichTextStyleOrganiserDialog
* itemDialog1
= this;
190 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
191 itemDialog1
->SetSizer(itemBoxSizer2
);
193 m_innerSizer
= new wxBoxSizer(wxVERTICAL
);
194 itemBoxSizer2
->Add(m_innerSizer
, 1, wxGROW
|wxALL
, 5);
196 m_buttonSizerParent
= new wxBoxSizer(wxHORIZONTAL
);
197 m_innerSizer
->Add(m_buttonSizerParent
, 1, wxGROW
, 5);
199 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
200 m_buttonSizerParent
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
202 wxStaticText
* itemStaticText6
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Styles:"), wxDefaultPosition
, wxDefaultSize
, 0 );
203 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
205 m_stylesListBox
= new wxRichTextStyleListCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_STYLES
, wxDefaultPosition
, wxSize(280, 260), listCtrlStyle
);
206 m_stylesListBox
->SetHelpText(_("The available styles."));
207 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
208 m_stylesListBox
->SetToolTip(_("The available styles."));
209 itemBoxSizer5
->Add(m_stylesListBox
, 1, wxGROW
|wxALL
, 5);
211 wxBoxSizer
* itemBoxSizer8
= new wxBoxSizer(wxVERTICAL
);
212 m_buttonSizerParent
->Add(itemBoxSizer8
, 0, wxGROW
, 5);
214 wxStaticText
* itemStaticText9
= new wxStaticText( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
215 itemBoxSizer8
->Add(itemStaticText9
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
217 m_previewCtrl
= new wxRichTextCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_PREVIEW
, wxEmptyString
, wxDefaultPosition
, wxSize(250, 200), wxBORDER_THEME
|wxVSCROLL
|wxTE_READONLY
);
218 m_previewCtrl
->SetHelpText(_("The style preview."));
219 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
220 m_previewCtrl
->SetToolTip(_("The style preview."));
221 itemBoxSizer8
->Add(m_previewCtrl
, 1, wxGROW
|wxALL
, 5);
223 m_buttonSizer
= new wxBoxSizer(wxVERTICAL
);
224 m_buttonSizerParent
->Add(m_buttonSizer
, 0, wxGROW
, 5);
226 wxStaticText
* itemStaticText12
= new wxStaticText( itemDialog1
, wxID_STATIC
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
227 m_buttonSizer
->Add(itemStaticText12
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
229 m_newCharacter
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
, _("New &Character Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
230 m_newCharacter
->SetHelpText(_("Click to create a new character style."));
231 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
232 m_newCharacter
->SetToolTip(_("Click to create a new character style."));
233 m_buttonSizer
->Add(m_newCharacter
, 0, wxGROW
|wxALL
, 5);
235 m_newParagraph
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, _("New &Paragraph Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
236 m_newParagraph
->SetHelpText(_("Click to create a new paragraph style."));
237 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
238 m_newParagraph
->SetToolTip(_("Click to create a new paragraph style."));
239 m_buttonSizer
->Add(m_newParagraph
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
241 m_newList
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, _("New &List Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
242 m_newList
->SetHelpText(_("Click to create a new list style."));
243 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
244 m_newList
->SetToolTip(_("Click to create a new list style."));
245 m_buttonSizer
->Add(m_newList
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
247 m_newBox
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
, _("New &Box Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
248 m_newBox
->SetHelpText(_("Click to create a new box style."));
249 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
250 m_newBox
->SetToolTip(_("Click to create a new box style."));
251 m_buttonSizer
->Add(m_newBox
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
253 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
255 m_applyStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, _("&Apply Style"), wxDefaultPosition
, wxDefaultSize
, 0 );
256 m_applyStyle
->SetHelpText(_("Click to apply the selected style."));
257 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
258 m_applyStyle
->SetToolTip(_("Click to apply the selected style."));
259 m_buttonSizer
->Add(m_applyStyle
, 0, wxGROW
|wxALL
, 5);
261 m_renameStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, _("&Rename Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
262 m_renameStyle
->SetHelpText(_("Click to rename the selected style."));
263 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
264 m_renameStyle
->SetToolTip(_("Click to rename the selected style."));
265 m_buttonSizer
->Add(m_renameStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
267 m_editStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, _("&Edit Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
268 m_editStyle
->SetHelpText(_("Click to edit the selected style."));
269 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
270 m_editStyle
->SetToolTip(_("Click to edit the selected style."));
271 m_buttonSizer
->Add(m_editStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
273 m_deleteStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, _("&Delete Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
274 m_deleteStyle
->SetHelpText(_("Click to delete the selected style."));
275 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
276 m_deleteStyle
->SetToolTip(_("Click to delete the selected style."));
277 m_buttonSizer
->Add(m_deleteStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
279 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
281 m_closeButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
282 m_closeButton
->SetDefault();
283 m_closeButton
->SetHelpText(_("Click to close this window."));
284 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
285 m_closeButton
->SetToolTip(_("Click to close this window."));
286 m_buttonSizer
->Add(m_closeButton
, 0, wxGROW
|wxALL
, 5);
288 m_bottomButtonSizer
= new wxBoxSizer(wxHORIZONTAL
);
289 m_innerSizer
->Add(m_bottomButtonSizer
, 0, wxGROW
, 5);
291 m_restartNumberingCtrl
= new wxCheckBox( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RESTART_NUMBERING
, _("&Restart numbering"), wxDefaultPosition
, wxDefaultSize
, 0 );
292 m_restartNumberingCtrl
->SetValue(false);
293 m_restartNumberingCtrl
->SetHelpText(_("Check to restart numbering."));
294 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
295 m_restartNumberingCtrl
->SetToolTip(_("Check to restart numbering."));
296 m_bottomButtonSizer
->Add(m_restartNumberingCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
298 m_stdButtonSizer
= new wxStdDialogButtonSizer
;
300 m_bottomButtonSizer
->Add(m_stdButtonSizer
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
301 m_okButton
= new wxButton( itemDialog1
, wxID_OK
, _("OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
302 m_stdButtonSizer
->AddButton(m_okButton
);
304 m_cancelButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
305 m_stdButtonSizer
->AddButton(m_cancelButton
);
307 wxButton
* itemButton29
= new wxButton( itemDialog1
, wxID_HELP
, _("&Help"), wxDefaultPosition
, wxDefaultSize
, 0 );
308 m_stdButtonSizer
->AddButton(itemButton29
);
310 m_stdButtonSizer
->Realize();
312 ////@end wxRichTextStyleOrganiserDialog content construction
314 if (GetHelpId() == -1)
316 wxWindow
* button
= FindWindowById(wxID_HELP
);
318 m_stdButtonSizer
->Show(button
, false);
321 if ((m_flags
& wxRICHTEXT_ORGANISER_CREATE_STYLES
) == 0)
323 m_buttonSizer
->Show(m_newCharacter
, false);
324 m_buttonSizer
->Show(m_newParagraph
, false);
325 m_buttonSizer
->Show(m_newList
, false);
326 m_buttonSizer
->Show(m_newBox
, false);
328 if ((m_flags
& wxRICHTEXT_ORGANISER_DELETE_STYLES
) == 0)
330 m_buttonSizer
->Show(m_deleteStyle
, false);
332 if ((m_flags
& wxRICHTEXT_ORGANISER_APPLY_STYLES
) == 0)
334 m_buttonSizer
->Show(m_applyStyle
, false);
336 if ((m_flags
& wxRICHTEXT_ORGANISER_EDIT_STYLES
) == 0)
338 m_buttonSizer
->Show(m_editStyle
, false);
340 if ((m_flags
& wxRICHTEXT_ORGANISER_RENAME_STYLES
) == 0)
342 m_buttonSizer
->Show(m_renameStyle
, false);
344 if ((m_flags
& wxRICHTEXT_ORGANISER_RENUMBER
) == 0)
346 m_bottomButtonSizer
->Show(m_restartNumberingCtrl
, false);
349 if ((m_flags
& wxRICHTEXT_ORGANISER_OK_CANCEL
) == 0)
351 m_stdButtonSizer
->Show(m_okButton
, false);
352 m_stdButtonSizer
->Show(m_cancelButton
, false);
356 m_buttonSizer
->Show(m_closeButton
, false);
359 // No buttons in the vertical group are shown, so hide the whole sizer
360 if ((m_flags
& wxRICHTEXT_ORGANISER_ORGANISE
) == 0)
362 m_buttonSizerParent
->Show(m_buttonSizer
, false);
365 // No buttons in the horizontal group are shown, so hide the whole sizer
366 if ((m_flags
& (wxRICHTEXT_ORGANISER_OK_CANCEL
|wxRICHTEXT_ORGANISER_RENUMBER
)) == 0)
368 m_innerSizer
->Show(m_bottomButtonSizer
, false);
371 if (hideTypeSelector
)
373 m_stylesListBox
->GetStyleListBox()->SetStyleType(typesToShow
);
376 m_stylesListBox
->SetStyleSheet(m_richTextStyleSheet
);
377 m_stylesListBox
->SetRichTextCtrl(m_richTextCtrl
);
378 m_stylesListBox
->UpdateStyles();
379 m_stylesListBox
->GetStyleListBox()->SetAutoSetSelection(false); // stop idle-time auto selection
380 if (m_stylesListBox
->GetStyleListBox()->GetItemCount() > 0)
382 m_stylesListBox
->GetStyleListBox()->SetSelection(0);
388 * Should we show tooltips?
391 /// Get selected style name or definition
392 wxString
wxRichTextStyleOrganiserDialog::GetSelectedStyle() const
394 wxRichTextStyleDefinition
* def
= GetSelectedStyleDefinition();
396 return def
->GetName();
398 return wxEmptyString
;
401 wxRichTextStyleDefinition
* wxRichTextStyleOrganiserDialog::GetSelectedStyleDefinition() const
403 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
404 return m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
408 /// Transfer data from/to window
409 bool wxRichTextStyleOrganiserDialog::TransferDataFromWindow()
411 if (!wxDialog::TransferDataFromWindow())
414 m_restartNumbering
= m_restartNumberingCtrl
->GetValue();
419 bool wxRichTextStyleOrganiserDialog::TransferDataToWindow()
421 if (!wxDialog::TransferDataToWindow())
424 m_restartNumberingCtrl
->SetValue(m_restartNumbering
);
429 /// Show preview for given or selected preview
430 void wxRichTextStyleOrganiserDialog::ShowPreview(int sel
)
432 static const wxChar
* s_para1
= wxT("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
433 Nullam ante sapien, vestibulum nonummy, pulvinar sed, luctus ut, lacus.\n");
435 static const wxChar
* s_para2List
= wxT("Duis pharetra consequat dui. Nullam vitae justo id mauris lobortis interdum.\n");
437 static const wxChar
* s_para2
= wxT("Duis pharetra consequat dui. Cum sociis natoque penatibus \
438 et magnis dis parturient montes, nascetur ridiculus mus. Nullam vitae justo id mauris lobortis interdum.\n");
440 static const wxChar
* s_para3
= wxT("Integer convallis dolor at augue \
441 iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n");
445 sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
450 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
451 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
452 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(def
, wxRichTextBoxStyleDefinition
);
454 wxStaticText
* labelCtrl
= (wxStaticText
*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
);
456 labelCtrl
->SetLabel(def
->GetName() + wxT(":"));
458 wxRichTextAttr
attr(def
->GetStyleMergedWithBase(GetStyleSheet()));
460 wxFont
font(m_previewCtrl
->GetFont());
461 font
.SetPointSize(9);
462 m_previewCtrl
->SetFont(font
);
464 wxRichTextAttr normalParaAttr
;
465 normalParaAttr
.SetFont(font
);
466 normalParaAttr
.SetTextColour(wxColour(wxT("LIGHT GREY")));
468 m_previewCtrl
->Freeze();
469 m_previewCtrl
->Clear();
471 m_previewCtrl
->BeginStyle(normalParaAttr
);
472 m_previewCtrl
->WriteText(s_para1
);
473 m_previewCtrl
->EndStyle();
477 m_previewCtrl
->BeginStyle(attr
);
478 long listStart
= m_previewCtrl
->GetInsertionPoint() + 1;
480 for (i
= 0; i
< 10; i
++)
482 wxRichTextAttr levelAttr
= * listDef
->GetLevelAttributes(i
);
483 levelAttr
.SetBulletNumber(1);
484 m_previewCtrl
->BeginStyle(levelAttr
);
485 m_previewCtrl
->WriteText(wxString::Format(wxT("List level %d. "), i
+1) + s_para2List
);
486 m_previewCtrl
->EndStyle();
488 long listEnd
= m_previewCtrl
->GetInsertionPoint();
489 m_previewCtrl
->NumberList(wxRichTextRange(listStart
, listEnd
), listDef
);
490 m_previewCtrl
->EndStyle();
494 wxRichTextAttr cellParaAttr
;
495 cellParaAttr
.SetFont(font
);
496 cellParaAttr
.SetTextColour(*wxBLACK
);
498 wxRichTextBox
* textBox
= m_previewCtrl
->WriteTextBox(attr
);
499 m_previewCtrl
->SetFocusObject(textBox
);
500 m_previewCtrl
->BeginStyle(cellParaAttr
);
501 wxString
text(s_para2
);
502 text
.Replace(wxT("\n"), wxEmptyString
);
503 m_previewCtrl
->WriteText(text
);
504 m_previewCtrl
->EndStyle();
505 m_previewCtrl
->SetFocusObject(NULL
); // Set the focus back to the main buffer
506 m_previewCtrl
->SetInsertionPointEnd();
507 m_previewCtrl
->SetDefaultStyle(wxRichTextAttr());
511 m_previewCtrl
->BeginStyle(attr
);
512 m_previewCtrl
->WriteText(s_para2
);
513 m_previewCtrl
->EndStyle();
516 m_previewCtrl
->BeginStyle(normalParaAttr
);
517 m_previewCtrl
->WriteText(s_para3
);
518 m_previewCtrl
->EndStyle();
520 m_previewCtrl
->Thaw();
523 /// Clears the preview
524 void wxRichTextStyleOrganiserDialog::ClearPreview()
526 m_previewCtrl
->Clear();
527 wxStaticText
* labelCtrl
= (wxStaticText
*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
);
529 labelCtrl
->SetLabel(wxEmptyString
);
532 bool wxRichTextStyleOrganiserDialog::ApplyStyle(wxRichTextCtrl
* ctrl
)
534 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
538 ctrl
= GetRichTextCtrl();
542 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
543 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
545 if (listDef
&& m_restartNumberingCtrl
->GetValue() && ctrl
->HasSelection())
547 wxRichTextRange range
= ctrl
->GetSelectionRange();
548 return ctrl
->SetListStyle(range
, listDef
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_RENUMBER
);
552 return ctrl
->ApplyStyle(def
);
557 * Get bitmap resources
560 wxBitmap
wxRichTextStyleOrganiserDialog::GetBitmapResource( const wxString
& name
)
563 ////@begin wxRichTextStyleOrganiserDialog bitmap retrieval
566 ////@end wxRichTextStyleOrganiserDialog bitmap retrieval
573 wxIcon
wxRichTextStyleOrganiserDialog::GetIconResource( const wxString
& name
)
576 ////@begin wxRichTextStyleOrganiserDialog icon retrieval
579 ////@end wxRichTextStyleOrganiserDialog icon retrieval
583 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
586 void wxRichTextStyleOrganiserDialog::OnApplyClick( wxCommandEvent
& WXUNUSED(event
) )
592 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
595 void wxRichTextStyleOrganiserDialog::OnApplyUpdate( wxUpdateUIEvent
& event
)
597 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_APPLY_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
602 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
605 void wxRichTextStyleOrganiserDialog::OnNewCharClick( wxCommandEvent
& WXUNUSED(event
) )
607 wxString styleName
= wxGetTextFromUser(_("Enter a character style name"), _("New Style"));
608 if (!styleName
.IsEmpty())
610 if (GetStyleSheet()->FindCharacterStyle(styleName
))
612 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
616 wxRichTextCharacterStyleDefinition
* style
= new wxRichTextCharacterStyleDefinition(styleName
);
618 int pages
= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_STYLE_EDITOR
;
619 wxRichTextFormattingDialog formatDlg
;
620 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
621 formatDlg
.Create(pages
, this);
623 if (formatDlg
.ShowModal() == wxID_OK
)
625 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
627 (*((wxRichTextCharacterStyleDefinition
* ) style
)) = (*charDef
);
629 GetStyleSheet()->AddCharacterStyle(style
);
631 m_stylesListBox
->UpdateStyles();
640 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
643 void wxRichTextStyleOrganiserDialog::OnNewCharUpdate( wxUpdateUIEvent
& event
)
645 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
650 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
653 void wxRichTextStyleOrganiserDialog::OnNewParaClick( wxCommandEvent
& WXUNUSED(event
) )
655 wxString styleName
= wxGetTextFromUser(_("Enter a paragraph style name"), _("New Style"));
656 if (!styleName
.IsEmpty())
658 if (GetStyleSheet()->FindParagraphStyle(styleName
))
660 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
664 wxRichTextParagraphStyleDefinition
* style
= new wxRichTextParagraphStyleDefinition(styleName
);
666 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
667 wxRichTextFormattingDialog formatDlg
;
668 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
669 formatDlg
.Create(pages
, this);
671 if (formatDlg
.ShowModal() == wxID_OK
)
673 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
675 (*((wxRichTextParagraphStyleDefinition
* ) style
)) = (*paraDef
);
677 GetStyleSheet()->AddParagraphStyle(style
);
679 m_stylesListBox
->UpdateStyles();
688 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
691 void wxRichTextStyleOrganiserDialog::OnNewParaUpdate( wxUpdateUIEvent
& event
)
693 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
698 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
701 void wxRichTextStyleOrganiserDialog::OnEditClick( wxCommandEvent
& WXUNUSED(event
) )
703 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
704 if (sel
!= wxNOT_FOUND
)
706 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
708 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
;
710 if (def
->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition
)))
712 pages
|= wxRICHTEXT_FORMAT_FONT
;
714 else if (def
->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition
)))
716 pages
|= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
718 else if (def
->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition
)))
720 pages
|= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
722 else if (def
->IsKindOf(CLASSINFO(wxRichTextBoxStyleDefinition
)))
724 pages
|= wxRICHTEXT_FORMAT_MARGINS
|wxRICHTEXT_FORMAT_SIZE
|wxRICHTEXT_FORMAT_BORDERS
|wxRICHTEXT_FORMAT_BACKGROUND
;
727 wxRichTextFormattingDialog formatDlg
;
728 formatDlg
.SetStyleDefinition(*def
, GetStyleSheet());
729 formatDlg
.Create(pages
, this);
731 if (formatDlg
.ShowModal() == wxID_OK
)
733 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
734 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
735 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
736 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextBoxStyleDefinition
);
740 (*((wxRichTextListStyleDefinition
* ) def
)) = (*listDef
);
744 (*((wxRichTextParagraphStyleDefinition
* ) def
)) = (*paraDef
);
748 (*((wxRichTextBoxStyleDefinition
* ) def
)) = (*boxDef
);
752 (*((wxRichTextCharacterStyleDefinition
* ) def
)) = (*charDef
);
755 m_stylesListBox
->UpdateStyles();
756 m_stylesListBox
->GetStyleListBox()->SetSelection(sel
);
763 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
766 void wxRichTextStyleOrganiserDialog::OnEditUpdate( wxUpdateUIEvent
& event
)
768 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_EDIT_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
773 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
776 void wxRichTextStyleOrganiserDialog::OnDeleteClick( wxCommandEvent
& WXUNUSED(event
) )
778 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
779 if (sel
!= wxNOT_FOUND
)
781 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
782 wxString
name(def
->GetName());
783 if (wxYES
== wxMessageBox(wxString::Format(_("Delete style %s?"), name
), _("Delete Style"), wxYES_NO
|wxICON_QUESTION
, this))
785 m_stylesListBox
->GetStyleListBox()->SetItemCount(0);
787 if (def
->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition
)))
788 GetStyleSheet()->RemoveListStyle((wxRichTextListStyleDefinition
*) def
, true);
789 else if (def
->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition
)))
790 GetStyleSheet()->RemoveParagraphStyle((wxRichTextParagraphStyleDefinition
*) def
, true);
791 else if (def
->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition
)))
792 GetStyleSheet()->RemoveCharacterStyle((wxRichTextCharacterStyleDefinition
*) def
, true);
793 else if (def
->IsKindOf(CLASSINFO(wxRichTextBoxStyleDefinition
)))
794 GetStyleSheet()->RemoveBoxStyle((wxRichTextBoxStyleDefinition
*) def
, true);
796 m_stylesListBox
->UpdateStyles();
798 if (m_stylesListBox
->GetStyleListBox()->GetSelection() != -1)
807 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
810 void wxRichTextStyleOrganiserDialog::OnDeleteUpdate( wxUpdateUIEvent
& event
)
812 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_DELETE_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
816 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
819 void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent
& WXUNUSED(event
) )
821 wxString styleName
= wxGetTextFromUser(_("Enter a list style name"), _("New Style"));
822 if (!styleName
.IsEmpty())
824 if (GetStyleSheet()->FindListStyle(styleName
))
826 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
830 wxRichTextListStyleDefinition
* style
= new wxRichTextListStyleDefinition(styleName
);
832 // Initialize the style to make it easier to edit
834 for (i
= 0; i
< 10; i
++)
836 wxString bulletSymbol
;
838 bulletSymbol
= wxT("*");
840 bulletSymbol
= wxT("-");
842 bulletSymbol
= wxT("*");
844 bulletSymbol
= wxT("-");
846 bulletSymbol
= wxT("*");
848 style
->SetAttributes(i
, (i
+1)*60, 60, wxTEXT_ATTR_BULLET_STYLE_SYMBOL
, bulletSymbol
);
851 int pages
= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
852 wxRichTextFormattingDialog formatDlg
;
853 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
854 formatDlg
.Create(pages
, this);
856 if (formatDlg
.ShowModal() == wxID_OK
)
858 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
860 (*((wxRichTextListStyleDefinition
* ) style
)) = (*listDef
);
862 GetStyleSheet()->AddListStyle(style
);
864 m_stylesListBox
->UpdateStyles();
873 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
876 void wxRichTextStyleOrganiserDialog::OnNewListUpdate( wxUpdateUIEvent
& event
)
878 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
882 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
885 void wxRichTextStyleOrganiserDialog::OnRenameClick( wxCommandEvent
& WXUNUSED(event
) )
887 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
890 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
894 wxString styleName
= wxGetTextFromUser(_("Enter a new style name"), _("New Style"), def
->GetName());
895 if (!styleName
.IsEmpty())
897 if (styleName
== def
->GetName())
900 if (GetStyleSheet()->FindParagraphStyle(styleName
) || GetStyleSheet()->FindCharacterStyle(styleName
) || GetStyleSheet()->FindListStyle(styleName
) || GetStyleSheet()->FindBoxStyle(styleName
))
902 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
906 def
->SetName(styleName
);
907 m_stylesListBox
->UpdateStyles();
912 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
915 void wxRichTextStyleOrganiserDialog::OnRenameUpdate( wxUpdateUIEvent
& event
)
917 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_RENAME_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
921 void wxRichTextStyleOrganiserDialog::OnListSelection(wxCommandEvent
& event
)
923 if (event
.GetEventObject() == m_stylesListBox
->GetStyleListBox())
930 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
933 void wxRichTextStyleOrganiserDialog::OnNewBoxClick( wxCommandEvent
& WXUNUSED(event
) )
935 wxString styleName
= wxGetTextFromUser(_("Enter a box style name"), _("New Style"));
936 if (!styleName
.IsEmpty())
938 if (GetStyleSheet()->FindBoxStyle(styleName
))
940 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
944 wxRichTextBoxStyleDefinition
* style
= new wxRichTextBoxStyleDefinition(styleName
);
946 int pages
= wxRICHTEXT_FORMAT_MARGINS
|wxRICHTEXT_FORMAT_SIZE
|wxRICHTEXT_FORMAT_BORDERS
|wxRICHTEXT_FORMAT_BACKGROUND
;
947 wxRichTextFormattingDialog formatDlg
;
948 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
949 formatDlg
.Create(pages
, this);
951 if (formatDlg
.ShowModal() == wxID_OK
)
953 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextBoxStyleDefinition
);
955 (*((wxRichTextBoxStyleDefinition
* ) style
)) = (*boxDef
);
957 GetStyleSheet()->AddBoxStyle(style
);
959 m_stylesListBox
->UpdateStyles();
968 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
971 void wxRichTextStyleOrganiserDialog::OnNewBoxUpdate( wxUpdateUIEvent
& event
)
973 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);