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()
156 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
159 bool hideTypeSelector
= false;
160 wxRichTextStyleListBox::wxRichTextStyleType typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL
;
162 if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_CHARACTER
) != 0)
164 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
;
165 hideTypeSelector
= true;
167 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_PARAGRAPH
) != 0)
169 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH
;
170 hideTypeSelector
= true;
172 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_BOX
) != 0)
174 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_BOX
;
175 hideTypeSelector
= true;
177 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_LIST
) != 0)
179 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST
;
180 hideTypeSelector
= true;
184 // wxRICHTEXT_ORGANISER_SHOW_ALL is implied if the other styles aren't included
187 long listCtrlStyle
= 0;
188 if (hideTypeSelector
)
189 listCtrlStyle
= wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR
;
191 ////@begin wxRichTextStyleOrganiserDialog content construction
192 wxRichTextStyleOrganiserDialog
* itemDialog1
= this;
194 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
195 itemDialog1
->SetSizer(itemBoxSizer2
);
197 m_innerSizer
= new wxBoxSizer(wxVERTICAL
);
198 itemBoxSizer2
->Add(m_innerSizer
, 1, wxGROW
|wxALL
, 5);
200 m_buttonSizerParent
= new wxBoxSizer(wxHORIZONTAL
);
201 m_innerSizer
->Add(m_buttonSizerParent
, 1, wxGROW
, 5);
203 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
204 m_buttonSizerParent
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
206 wxStaticText
* itemStaticText6
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Styles:"), wxDefaultPosition
, wxDefaultSize
, 0 );
207 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
209 m_stylesListBox
= new wxRichTextStyleListCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_STYLES
, wxDefaultPosition
, wxSize(280, 260), listCtrlStyle
);
210 m_stylesListBox
->SetHelpText(_("The available styles."));
211 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
212 m_stylesListBox
->SetToolTip(_("The available styles."));
213 itemBoxSizer5
->Add(m_stylesListBox
, 1, wxGROW
|wxALL
, 5);
215 wxBoxSizer
* itemBoxSizer8
= new wxBoxSizer(wxVERTICAL
);
216 m_buttonSizerParent
->Add(itemBoxSizer8
, 0, wxGROW
, 5);
218 wxStaticText
* itemStaticText9
= new wxStaticText( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
219 itemBoxSizer8
->Add(itemStaticText9
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
221 m_previewCtrl
= new wxRichTextCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_PREVIEW
, wxEmptyString
, wxDefaultPosition
, wxSize(250, 200), wxBORDER_THEME
|wxVSCROLL
|wxTE_READONLY
);
222 m_previewCtrl
->SetHelpText(_("The style preview."));
223 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
224 m_previewCtrl
->SetToolTip(_("The style preview."));
225 itemBoxSizer8
->Add(m_previewCtrl
, 1, wxGROW
|wxALL
, 5);
227 m_buttonSizer
= new wxBoxSizer(wxVERTICAL
);
228 m_buttonSizerParent
->Add(m_buttonSizer
, 0, wxGROW
, 5);
230 wxStaticText
* itemStaticText12
= new wxStaticText( itemDialog1
, wxID_STATIC
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
231 m_buttonSizer
->Add(itemStaticText12
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
233 m_newCharacter
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
, _("New &Character Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
234 m_newCharacter
->SetHelpText(_("Click to create a new character style."));
235 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
236 m_newCharacter
->SetToolTip(_("Click to create a new character style."));
237 m_buttonSizer
->Add(m_newCharacter
, 0, wxGROW
|wxALL
, 5);
239 m_newParagraph
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, _("New &Paragraph Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
240 m_newParagraph
->SetHelpText(_("Click to create a new paragraph style."));
241 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
242 m_newParagraph
->SetToolTip(_("Click to create a new paragraph style."));
243 m_buttonSizer
->Add(m_newParagraph
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
245 m_newList
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, _("New &List Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
246 m_newList
->SetHelpText(_("Click to create a new list style."));
247 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
248 m_newList
->SetToolTip(_("Click to create a new list style."));
249 m_buttonSizer
->Add(m_newList
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
251 m_newBox
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
, _("New &Box Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
252 m_newBox
->SetHelpText(_("Click to create a new box style."));
253 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
254 m_newBox
->SetToolTip(_("Click to create a new box style."));
255 m_buttonSizer
->Add(m_newBox
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
257 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
259 m_applyStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, _("&Apply Style"), wxDefaultPosition
, wxDefaultSize
, 0 );
260 m_applyStyle
->SetHelpText(_("Click to apply the selected style."));
261 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
262 m_applyStyle
->SetToolTip(_("Click to apply the selected style."));
263 m_buttonSizer
->Add(m_applyStyle
, 0, wxGROW
|wxALL
, 5);
265 m_renameStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, _("&Rename Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
266 m_renameStyle
->SetHelpText(_("Click to rename the selected style."));
267 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
268 m_renameStyle
->SetToolTip(_("Click to rename the selected style."));
269 m_buttonSizer
->Add(m_renameStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
271 m_editStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, _("&Edit Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
272 m_editStyle
->SetHelpText(_("Click to edit the selected style."));
273 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
274 m_editStyle
->SetToolTip(_("Click to edit the selected style."));
275 m_buttonSizer
->Add(m_editStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
277 m_deleteStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, _("&Delete Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
278 m_deleteStyle
->SetHelpText(_("Click to delete the selected style."));
279 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
280 m_deleteStyle
->SetToolTip(_("Click to delete the selected style."));
281 m_buttonSizer
->Add(m_deleteStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
283 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
285 m_closeButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
286 m_closeButton
->SetDefault();
287 m_closeButton
->SetHelpText(_("Click to close this window."));
288 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
289 m_closeButton
->SetToolTip(_("Click to close this window."));
290 m_buttonSizer
->Add(m_closeButton
, 0, wxGROW
|wxALL
, 5);
292 m_bottomButtonSizer
= new wxBoxSizer(wxHORIZONTAL
);
293 m_innerSizer
->Add(m_bottomButtonSizer
, 0, wxGROW
, 5);
295 m_restartNumberingCtrl
= new wxCheckBox( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RESTART_NUMBERING
, _("&Restart numbering"), wxDefaultPosition
, wxDefaultSize
, 0 );
296 m_restartNumberingCtrl
->SetValue(false);
297 m_restartNumberingCtrl
->SetHelpText(_("Check to restart numbering."));
298 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
299 m_restartNumberingCtrl
->SetToolTip(_("Check to restart numbering."));
300 m_bottomButtonSizer
->Add(m_restartNumberingCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
302 m_stdButtonSizer
= new wxStdDialogButtonSizer
;
304 m_bottomButtonSizer
->Add(m_stdButtonSizer
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
305 m_okButton
= new wxButton( itemDialog1
, wxID_OK
, _("OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
306 m_stdButtonSizer
->AddButton(m_okButton
);
308 m_cancelButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
309 m_stdButtonSizer
->AddButton(m_cancelButton
);
311 wxButton
* itemButton29
= new wxButton( itemDialog1
, wxID_HELP
, _("&Help"), wxDefaultPosition
, wxDefaultSize
, 0 );
312 m_stdButtonSizer
->AddButton(itemButton29
);
314 m_stdButtonSizer
->Realize();
316 ////@end wxRichTextStyleOrganiserDialog content construction
318 if (GetHelpId() == -1)
320 wxWindow
* button
= FindWindowById(wxID_HELP
);
322 m_stdButtonSizer
->Show(button
, false);
325 if ((m_flags
& wxRICHTEXT_ORGANISER_CREATE_STYLES
) == 0)
327 m_buttonSizer
->Show(m_newCharacter
, false);
328 m_buttonSizer
->Show(m_newParagraph
, false);
329 m_buttonSizer
->Show(m_newList
, false);
330 m_buttonSizer
->Show(m_newBox
, false);
332 if ((m_flags
& wxRICHTEXT_ORGANISER_DELETE_STYLES
) == 0)
334 m_buttonSizer
->Show(m_deleteStyle
, false);
336 if ((m_flags
& wxRICHTEXT_ORGANISER_APPLY_STYLES
) == 0)
338 m_buttonSizer
->Show(m_applyStyle
, false);
340 if ((m_flags
& wxRICHTEXT_ORGANISER_EDIT_STYLES
) == 0)
342 m_buttonSizer
->Show(m_editStyle
, false);
344 if ((m_flags
& wxRICHTEXT_ORGANISER_RENAME_STYLES
) == 0)
346 m_buttonSizer
->Show(m_renameStyle
, false);
348 if ((m_flags
& wxRICHTEXT_ORGANISER_RENUMBER
) == 0)
350 m_bottomButtonSizer
->Show(m_restartNumberingCtrl
, false);
353 if ((m_flags
& wxRICHTEXT_ORGANISER_OK_CANCEL
) == 0)
355 m_stdButtonSizer
->Show(m_okButton
, false);
356 m_stdButtonSizer
->Show(m_cancelButton
, false);
360 m_buttonSizer
->Show(m_closeButton
, false);
363 // No buttons in the vertical group are shown, so hide the whole sizer
364 if ((m_flags
& wxRICHTEXT_ORGANISER_ORGANISE
) == 0)
366 m_buttonSizerParent
->Show(m_buttonSizer
, false);
369 // No buttons in the horizontal group are shown, so hide the whole sizer
370 if ((m_flags
& (wxRICHTEXT_ORGANISER_OK_CANCEL
|wxRICHTEXT_ORGANISER_RENUMBER
)) == 0)
372 m_innerSizer
->Show(m_bottomButtonSizer
, false);
375 if (hideTypeSelector
)
377 m_stylesListBox
->GetStyleListBox()->SetStyleType(typesToShow
);
380 m_stylesListBox
->SetStyleSheet(m_richTextStyleSheet
);
381 m_stylesListBox
->SetRichTextCtrl(m_richTextCtrl
);
382 m_stylesListBox
->UpdateStyles();
383 m_stylesListBox
->GetStyleListBox()->SetAutoSetSelection(false); // stop idle-time auto selection
384 if (m_stylesListBox
->GetStyleListBox()->GetItemCount() > 0)
386 m_stylesListBox
->GetStyleListBox()->SetSelection(0);
392 * Should we show tooltips?
395 /// Get selected style name or definition
396 wxString
wxRichTextStyleOrganiserDialog::GetSelectedStyle() const
398 wxRichTextStyleDefinition
* def
= GetSelectedStyleDefinition();
400 return def
->GetName();
402 return wxEmptyString
;
405 wxRichTextStyleDefinition
* wxRichTextStyleOrganiserDialog::GetSelectedStyleDefinition() const
407 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
408 return m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
412 /// Transfer data from/to window
413 bool wxRichTextStyleOrganiserDialog::TransferDataFromWindow()
415 if (!wxDialog::TransferDataFromWindow())
418 m_restartNumbering
= m_restartNumberingCtrl
->GetValue();
423 bool wxRichTextStyleOrganiserDialog::TransferDataToWindow()
425 if (!wxDialog::TransferDataToWindow())
428 m_restartNumberingCtrl
->SetValue(m_restartNumbering
);
433 /// Show preview for given or selected preview
434 void wxRichTextStyleOrganiserDialog::ShowPreview(int sel
)
436 static const wxChar
* s_para1
= wxT("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
437 Nullam ante sapien, vestibulum nonummy, pulvinar sed, luctus ut, lacus.\n");
439 static const wxChar
* s_para2List
= wxT("Duis pharetra consequat dui. Nullam vitae justo id mauris lobortis interdum.\n");
441 static const wxChar
* s_para2
= wxT("Duis pharetra consequat dui. Cum sociis natoque penatibus \
442 et magnis dis parturient montes, nascetur ridiculus mus. Nullam vitae justo id mauris lobortis interdum.\n");
444 static const wxChar
* s_para3
= wxT("Integer convallis dolor at augue \
445 iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n");
449 sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
454 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
455 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
456 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(def
, wxRichTextBoxStyleDefinition
);
458 wxStaticText
* labelCtrl
= (wxStaticText
*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
);
460 labelCtrl
->SetLabel(def
->GetName() + wxT(":"));
462 wxRichTextAttr
attr(def
->GetStyleMergedWithBase(GetStyleSheet()));
464 wxFont
font(m_previewCtrl
->GetFont());
465 font
.SetPointSize(9);
466 m_previewCtrl
->SetFont(font
);
468 wxRichTextAttr normalParaAttr
;
469 normalParaAttr
.SetFont(font
);
470 normalParaAttr
.SetTextColour(wxColour(wxT("LIGHT GREY")));
472 m_previewCtrl
->Freeze();
473 m_previewCtrl
->Clear();
475 m_previewCtrl
->BeginStyle(normalParaAttr
);
476 m_previewCtrl
->WriteText(s_para1
);
477 m_previewCtrl
->EndStyle();
481 m_previewCtrl
->BeginStyle(attr
);
482 long listStart
= m_previewCtrl
->GetInsertionPoint() + 1;
484 for (i
= 0; i
< 10; i
++)
486 wxRichTextAttr levelAttr
= * listDef
->GetLevelAttributes(i
);
487 levelAttr
.SetBulletNumber(1);
488 m_previewCtrl
->BeginStyle(levelAttr
);
489 m_previewCtrl
->WriteText(wxString::Format(wxT("List level %d. "), i
+1) + s_para2List
);
490 m_previewCtrl
->EndStyle();
492 long listEnd
= m_previewCtrl
->GetInsertionPoint();
493 m_previewCtrl
->NumberList(wxRichTextRange(listStart
, listEnd
), listDef
);
494 m_previewCtrl
->EndStyle();
498 wxRichTextAttr cellParaAttr
;
499 cellParaAttr
.SetFont(font
);
500 cellParaAttr
.SetTextColour(*wxBLACK
);
502 wxRichTextBox
* textBox
= m_previewCtrl
->WriteTextBox(attr
);
503 m_previewCtrl
->SetFocusObject(textBox
);
504 m_previewCtrl
->BeginStyle(cellParaAttr
);
505 wxString
text(s_para2
);
506 text
.Replace(wxT("\n"), wxEmptyString
);
507 m_previewCtrl
->WriteText(text
);
508 m_previewCtrl
->EndStyle();
509 m_previewCtrl
->SetFocusObject(NULL
); // Set the focus back to the main buffer
510 m_previewCtrl
->SetInsertionPointEnd();
511 m_previewCtrl
->SetDefaultStyle(wxRichTextAttr());
515 m_previewCtrl
->BeginStyle(attr
);
516 m_previewCtrl
->WriteText(s_para2
);
517 m_previewCtrl
->EndStyle();
520 m_previewCtrl
->BeginStyle(normalParaAttr
);
521 m_previewCtrl
->WriteText(s_para3
);
522 m_previewCtrl
->EndStyle();
524 m_previewCtrl
->Thaw();
527 /// Clears the preview
528 void wxRichTextStyleOrganiserDialog::ClearPreview()
530 m_previewCtrl
->Clear();
531 wxStaticText
* labelCtrl
= (wxStaticText
*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
);
533 labelCtrl
->SetLabel(wxEmptyString
);
536 bool wxRichTextStyleOrganiserDialog::ApplyStyle(wxRichTextCtrl
* ctrl
)
538 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
542 ctrl
= GetRichTextCtrl();
546 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
547 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
549 if (listDef
&& m_restartNumberingCtrl
->GetValue() && ctrl
->HasSelection())
551 wxRichTextRange range
= ctrl
->GetSelectionRange();
552 return ctrl
->SetListStyle(range
, listDef
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_RENUMBER
);
556 return ctrl
->ApplyStyle(def
);
561 * Get bitmap resources
564 wxBitmap
wxRichTextStyleOrganiserDialog::GetBitmapResource( const wxString
& name
)
567 ////@begin wxRichTextStyleOrganiserDialog bitmap retrieval
570 ////@end wxRichTextStyleOrganiserDialog bitmap retrieval
577 wxIcon
wxRichTextStyleOrganiserDialog::GetIconResource( const wxString
& name
)
580 ////@begin wxRichTextStyleOrganiserDialog icon retrieval
583 ////@end wxRichTextStyleOrganiserDialog icon retrieval
587 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
590 void wxRichTextStyleOrganiserDialog::OnApplyClick( wxCommandEvent
& WXUNUSED(event
) )
596 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
599 void wxRichTextStyleOrganiserDialog::OnApplyUpdate( wxUpdateUIEvent
& event
)
601 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_APPLY_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
606 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
609 void wxRichTextStyleOrganiserDialog::OnNewCharClick( wxCommandEvent
& WXUNUSED(event
) )
611 wxString styleName
= wxGetTextFromUser(_("Enter a character style name"), _("New Style"));
612 if (!styleName
.IsEmpty())
614 if (GetStyleSheet()->FindCharacterStyle(styleName
))
616 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
620 wxRichTextCharacterStyleDefinition
* style
= new wxRichTextCharacterStyleDefinition(styleName
);
622 int pages
= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_STYLE_EDITOR
;
623 wxRichTextFormattingDialog formatDlg
;
624 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
625 formatDlg
.Create(pages
, this);
627 if (formatDlg
.ShowModal() == wxID_OK
)
629 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
631 (*((wxRichTextCharacterStyleDefinition
* ) style
)) = (*charDef
);
633 GetStyleSheet()->AddCharacterStyle(style
);
635 m_stylesListBox
->UpdateStyles();
644 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
647 void wxRichTextStyleOrganiserDialog::OnNewCharUpdate( wxUpdateUIEvent
& event
)
649 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
654 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
657 void wxRichTextStyleOrganiserDialog::OnNewParaClick( wxCommandEvent
& WXUNUSED(event
) )
659 wxString styleName
= wxGetTextFromUser(_("Enter a paragraph style name"), _("New Style"));
660 if (!styleName
.IsEmpty())
662 if (GetStyleSheet()->FindParagraphStyle(styleName
))
664 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
668 wxRichTextParagraphStyleDefinition
* style
= new wxRichTextParagraphStyleDefinition(styleName
);
670 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
671 wxRichTextFormattingDialog formatDlg
;
672 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
673 formatDlg
.Create(pages
, this);
675 if (formatDlg
.ShowModal() == wxID_OK
)
677 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
679 (*((wxRichTextParagraphStyleDefinition
* ) style
)) = (*paraDef
);
681 GetStyleSheet()->AddParagraphStyle(style
);
683 m_stylesListBox
->UpdateStyles();
692 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
695 void wxRichTextStyleOrganiserDialog::OnNewParaUpdate( wxUpdateUIEvent
& event
)
697 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
702 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
705 void wxRichTextStyleOrganiserDialog::OnEditClick( wxCommandEvent
& WXUNUSED(event
) )
707 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
708 if (sel
!= wxNOT_FOUND
)
710 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
712 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
;
714 if (wxDynamicCast(def
, wxRichTextCharacterStyleDefinition
))
716 pages
|= wxRICHTEXT_FORMAT_FONT
;
718 else if (wxDynamicCast(def
, wxRichTextListStyleDefinition
))
720 pages
|= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
722 else if (wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
))
724 pages
|= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
726 else if (wxDynamicCast(def
, wxRichTextBoxStyleDefinition
))
728 pages
|= wxRICHTEXT_FORMAT_MARGINS
|wxRICHTEXT_FORMAT_SIZE
|wxRICHTEXT_FORMAT_BORDERS
|wxRICHTEXT_FORMAT_BACKGROUND
;
731 wxRichTextFormattingDialog formatDlg
;
732 formatDlg
.SetStyleDefinition(*def
, GetStyleSheet());
733 formatDlg
.Create(pages
, this);
735 if (formatDlg
.ShowModal() == wxID_OK
)
737 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
738 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
739 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
740 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextBoxStyleDefinition
);
744 (*((wxRichTextListStyleDefinition
* ) def
)) = (*listDef
);
748 (*((wxRichTextParagraphStyleDefinition
* ) def
)) = (*paraDef
);
752 (*((wxRichTextBoxStyleDefinition
* ) def
)) = (*boxDef
);
756 (*((wxRichTextCharacterStyleDefinition
* ) def
)) = (*charDef
);
759 m_stylesListBox
->UpdateStyles();
760 m_stylesListBox
->GetStyleListBox()->SetSelection(sel
);
767 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
770 void wxRichTextStyleOrganiserDialog::OnEditUpdate( wxUpdateUIEvent
& event
)
772 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_EDIT_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
777 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
780 void wxRichTextStyleOrganiserDialog::OnDeleteClick( wxCommandEvent
& WXUNUSED(event
) )
782 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
783 if (sel
!= wxNOT_FOUND
)
785 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
786 wxString
name(def
->GetName());
787 if (wxYES
== wxMessageBox(wxString::Format(_("Delete style %s?"), name
), _("Delete Style"), wxYES_NO
|wxICON_QUESTION
, this))
789 m_stylesListBox
->GetStyleListBox()->SetItemCount(0);
791 if (wxDynamicCast(def
, wxRichTextListStyleDefinition
))
792 GetStyleSheet()->RemoveListStyle((wxRichTextListStyleDefinition
*) def
, true);
793 else if (wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
))
794 GetStyleSheet()->RemoveParagraphStyle((wxRichTextParagraphStyleDefinition
*) def
, true);
795 else if (wxDynamicCast(def
, wxRichTextCharacterStyleDefinition
))
796 GetStyleSheet()->RemoveCharacterStyle((wxRichTextCharacterStyleDefinition
*) def
, true);
797 else if (wxDynamicCast(def
, wxRichTextBoxStyleDefinition
))
798 GetStyleSheet()->RemoveBoxStyle((wxRichTextBoxStyleDefinition
*) def
, true);
800 m_stylesListBox
->UpdateStyles();
802 if (m_stylesListBox
->GetStyleListBox()->GetSelection() != -1)
811 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
814 void wxRichTextStyleOrganiserDialog::OnDeleteUpdate( wxUpdateUIEvent
& event
)
816 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_DELETE_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
820 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
823 void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent
& WXUNUSED(event
) )
825 wxString styleName
= wxGetTextFromUser(_("Enter a list style name"), _("New Style"));
826 if (!styleName
.IsEmpty())
828 if (GetStyleSheet()->FindListStyle(styleName
))
830 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
834 wxRichTextListStyleDefinition
* style
= new wxRichTextListStyleDefinition(styleName
);
836 // Initialize the style to make it easier to edit
838 for (i
= 0; i
< 10; i
++)
840 wxString bulletSymbol
;
842 bulletSymbol
= wxT("*");
844 bulletSymbol
= wxT("-");
846 bulletSymbol
= wxT("*");
848 bulletSymbol
= wxT("-");
850 bulletSymbol
= wxT("*");
852 style
->SetAttributes(i
, (i
+1)*60, 60, wxTEXT_ATTR_BULLET_STYLE_SYMBOL
, bulletSymbol
);
855 int pages
= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
856 wxRichTextFormattingDialog formatDlg
;
857 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
858 formatDlg
.Create(pages
, this);
860 if (formatDlg
.ShowModal() == wxID_OK
)
862 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
864 (*((wxRichTextListStyleDefinition
* ) style
)) = (*listDef
);
866 GetStyleSheet()->AddListStyle(style
);
868 m_stylesListBox
->UpdateStyles();
877 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
880 void wxRichTextStyleOrganiserDialog::OnNewListUpdate( wxUpdateUIEvent
& event
)
882 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
886 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
889 void wxRichTextStyleOrganiserDialog::OnRenameClick( wxCommandEvent
& WXUNUSED(event
) )
891 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
894 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
898 wxString styleName
= wxGetTextFromUser(_("Enter a new style name"), _("New Style"), def
->GetName());
899 if (!styleName
.IsEmpty())
901 if (styleName
== def
->GetName())
904 if (GetStyleSheet()->FindParagraphStyle(styleName
) || GetStyleSheet()->FindCharacterStyle(styleName
) || GetStyleSheet()->FindListStyle(styleName
) || GetStyleSheet()->FindBoxStyle(styleName
))
906 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
910 def
->SetName(styleName
);
911 m_stylesListBox
->UpdateStyles();
916 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
919 void wxRichTextStyleOrganiserDialog::OnRenameUpdate( wxUpdateUIEvent
& event
)
921 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_RENAME_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
925 void wxRichTextStyleOrganiserDialog::OnListSelection(wxCommandEvent
& event
)
927 if (event
.GetEventObject() == m_stylesListBox
->GetStyleListBox())
934 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
937 void wxRichTextStyleOrganiserDialog::OnNewBoxClick( wxCommandEvent
& WXUNUSED(event
) )
939 wxString styleName
= wxGetTextFromUser(_("Enter a box style name"), _("New Style"));
940 if (!styleName
.IsEmpty())
942 if (GetStyleSheet()->FindBoxStyle(styleName
))
944 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
948 wxRichTextBoxStyleDefinition
* style
= new wxRichTextBoxStyleDefinition(styleName
);
950 int pages
= wxRICHTEXT_FORMAT_MARGINS
|wxRICHTEXT_FORMAT_SIZE
|wxRICHTEXT_FORMAT_BORDERS
|wxRICHTEXT_FORMAT_BACKGROUND
;
951 wxRichTextFormattingDialog formatDlg
;
952 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
953 formatDlg
.Create(pages
, this);
955 if (formatDlg
.ShowModal() == wxID_OK
)
957 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextBoxStyleDefinition
);
959 (*((wxRichTextBoxStyleDefinition
* ) style
)) = (*boxDef
);
961 GetStyleSheet()->AddBoxStyle(style
);
963 m_stylesListBox
->UpdateStyles();
972 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
975 void wxRichTextStyleOrganiserDialog::OnNewBoxUpdate( wxUpdateUIEvent
& event
)
977 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);