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
)
47 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, wxRichTextStyleOrganiserDialog::OnNewParaClick
)
48 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, wxRichTextStyleOrganiserDialog::OnNewParaUpdate
)
49 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, wxRichTextStyleOrganiserDialog::OnNewListClick
)
50 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, wxRichTextStyleOrganiserDialog::OnNewListUpdate
)
51 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
, wxRichTextStyleOrganiserDialog::OnNewBoxClick
)
52 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
, wxRichTextStyleOrganiserDialog::OnNewBoxUpdate
)
53 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, wxRichTextStyleOrganiserDialog::OnApplyClick
)
54 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, wxRichTextStyleOrganiserDialog::OnApplyUpdate
)
55 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, wxRichTextStyleOrganiserDialog::OnRenameClick
)
56 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, wxRichTextStyleOrganiserDialog::OnRenameUpdate
)
57 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, wxRichTextStyleOrganiserDialog::OnEditClick
)
58 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, wxRichTextStyleOrganiserDialog::OnEditUpdate
)
59 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, wxRichTextStyleOrganiserDialog::OnDeleteClick
)
60 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, wxRichTextStyleOrganiserDialog::OnDeleteUpdate
)
61 EVT_BUTTON( wxID_HELP
, wxRichTextStyleOrganiserDialog::OnHelpClick
)
62 ////@end wxRichTextStyleOrganiserDialog event table entries
66 IMPLEMENT_HELP_PROVISION(wxRichTextStyleOrganiserDialog
)
69 * wxRichTextStyleOrganiserDialog constructors
72 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( )
77 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
80 Create(flags
, sheet
, ctrl
, parent
, id
, caption
, pos
, size
, style
);
84 * Member initialisation for wxSymbolPickerDialog
87 void wxRichTextStyleOrganiserDialog::Init()
89 m_richTextStyleSheet
= NULL
;
90 m_richTextCtrl
= NULL
;
93 m_restartNumbering
= true;
95 ////@begin wxRichTextStyleOrganiserDialog member initialisation
97 m_buttonSizerParent
= NULL
;
98 m_stylesListBox
= NULL
;
100 m_buttonSizer
= NULL
;
101 m_newCharacter
= NULL
;
102 m_newParagraph
= NULL
;
106 m_renameStyle
= NULL
;
108 m_deleteStyle
= NULL
;
109 m_closeButton
= NULL
;
110 m_bottomButtonSizer
= NULL
;
111 m_restartNumberingCtrl
= NULL
;
112 m_stdButtonSizer
= NULL
;
114 m_cancelButton
= NULL
;
115 ////@end wxRichTextStyleOrganiserDialog member initialisation
119 * wxRichTextStyleOrganiserDialog creator
122 bool wxRichTextStyleOrganiserDialog::Create( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
124 m_richTextStyleSheet
= sheet
;
125 m_richTextCtrl
= ctrl
;
128 ////@begin wxRichTextStyleOrganiserDialog creation
129 SetExtraStyle(wxWS_EX_BLOCK_EVENTS
|wxDIALOG_EX_CONTEXTHELP
);
130 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
135 GetSizer()->SetSizeHints(this);
138 ////@end wxRichTextStyleOrganiserDialog creation
143 * Control creation for wxRichTextStyleOrganiserDialog
146 void wxRichTextStyleOrganiserDialog::CreateControls()
149 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
152 bool hideTypeSelector
= false;
153 wxRichTextStyleListBox::wxRichTextStyleType typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL
;
155 if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_CHARACTER
) != 0)
157 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
;
158 hideTypeSelector
= true;
160 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_PARAGRAPH
) != 0)
162 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH
;
163 hideTypeSelector
= true;
165 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_BOX
) != 0)
167 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_BOX
;
168 hideTypeSelector
= true;
170 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_LIST
) != 0)
172 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST
;
173 hideTypeSelector
= true;
177 // wxRICHTEXT_ORGANISER_SHOW_ALL is implied if the other styles aren't included
180 long listCtrlStyle
= 0;
181 if (hideTypeSelector
)
182 listCtrlStyle
= wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR
;
184 ////@begin wxRichTextStyleOrganiserDialog content construction
185 wxRichTextStyleOrganiserDialog
* itemDialog1
= this;
187 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
188 itemDialog1
->SetSizer(itemBoxSizer2
);
190 m_innerSizer
= new wxBoxSizer(wxVERTICAL
);
191 itemBoxSizer2
->Add(m_innerSizer
, 1, wxGROW
|wxALL
, 5);
193 m_buttonSizerParent
= new wxBoxSizer(wxHORIZONTAL
);
194 m_innerSizer
->Add(m_buttonSizerParent
, 1, wxGROW
, 5);
196 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
197 m_buttonSizerParent
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
199 wxStaticText
* itemStaticText6
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Styles:"), wxDefaultPosition
, wxDefaultSize
, 0 );
200 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
202 m_stylesListBox
= new wxRichTextStyleListCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_STYLES
, wxDefaultPosition
, wxSize(280, 260), listCtrlStyle
);
203 m_stylesListBox
->SetHelpText(_("The available styles."));
204 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
205 m_stylesListBox
->SetToolTip(_("The available styles."));
206 itemBoxSizer5
->Add(m_stylesListBox
, 1, wxGROW
|wxALL
, 5);
208 wxBoxSizer
* itemBoxSizer8
= new wxBoxSizer(wxVERTICAL
);
209 m_buttonSizerParent
->Add(itemBoxSizer8
, 0, wxGROW
, 5);
211 wxStaticText
* itemStaticText9
= new wxStaticText( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
212 itemBoxSizer8
->Add(itemStaticText9
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
214 m_previewCtrl
= new wxRichTextCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_PREVIEW
, wxEmptyString
, wxDefaultPosition
, wxSize(250, 200), wxBORDER_THEME
|wxVSCROLL
|wxTE_READONLY
);
215 m_previewCtrl
->SetHelpText(_("The style preview."));
216 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
217 m_previewCtrl
->SetToolTip(_("The style preview."));
218 itemBoxSizer8
->Add(m_previewCtrl
, 1, wxGROW
|wxALL
, 5);
220 m_buttonSizer
= new wxBoxSizer(wxVERTICAL
);
221 m_buttonSizerParent
->Add(m_buttonSizer
, 0, wxGROW
, 5);
223 wxStaticText
* itemStaticText12
= new wxStaticText( itemDialog1
, wxID_STATIC
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
224 m_buttonSizer
->Add(itemStaticText12
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
226 m_newCharacter
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
, _("New &Character Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
227 m_newCharacter
->SetHelpText(_("Click to create a new character style."));
228 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
229 m_newCharacter
->SetToolTip(_("Click to create a new character style."));
230 m_buttonSizer
->Add(m_newCharacter
, 0, wxGROW
|wxALL
, 5);
232 m_newParagraph
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, _("New &Paragraph Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
233 m_newParagraph
->SetHelpText(_("Click to create a new paragraph style."));
234 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
235 m_newParagraph
->SetToolTip(_("Click to create a new paragraph style."));
236 m_buttonSizer
->Add(m_newParagraph
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
238 m_newList
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, _("New &List Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
239 m_newList
->SetHelpText(_("Click to create a new list style."));
240 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
241 m_newList
->SetToolTip(_("Click to create a new list style."));
242 m_buttonSizer
->Add(m_newList
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
244 m_newBox
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
, _("New &Box Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
245 m_newBox
->SetHelpText(_("Click to create a new box style."));
246 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
247 m_newBox
->SetToolTip(_("Click to create a new box style."));
248 m_buttonSizer
->Add(m_newBox
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
250 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
252 m_applyStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, _("&Apply Style"), wxDefaultPosition
, wxDefaultSize
, 0 );
253 m_applyStyle
->SetHelpText(_("Click to apply the selected style."));
254 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
255 m_applyStyle
->SetToolTip(_("Click to apply the selected style."));
256 m_buttonSizer
->Add(m_applyStyle
, 0, wxGROW
|wxALL
, 5);
258 m_renameStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, _("&Rename Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
259 m_renameStyle
->SetHelpText(_("Click to rename the selected style."));
260 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
261 m_renameStyle
->SetToolTip(_("Click to rename the selected style."));
262 m_buttonSizer
->Add(m_renameStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
264 m_editStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, _("&Edit Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
265 m_editStyle
->SetHelpText(_("Click to edit the selected style."));
266 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
267 m_editStyle
->SetToolTip(_("Click to edit the selected style."));
268 m_buttonSizer
->Add(m_editStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
270 m_deleteStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, _("&Delete Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
271 m_deleteStyle
->SetHelpText(_("Click to delete the selected style."));
272 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
273 m_deleteStyle
->SetToolTip(_("Click to delete the selected style."));
274 m_buttonSizer
->Add(m_deleteStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
276 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
278 m_closeButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
279 m_closeButton
->SetDefault();
280 m_closeButton
->SetHelpText(_("Click to close this window."));
281 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
282 m_closeButton
->SetToolTip(_("Click to close this window."));
283 m_buttonSizer
->Add(m_closeButton
, 0, wxGROW
|wxALL
, 5);
285 m_bottomButtonSizer
= new wxBoxSizer(wxHORIZONTAL
);
286 m_innerSizer
->Add(m_bottomButtonSizer
, 0, wxGROW
, 5);
288 m_restartNumberingCtrl
= new wxCheckBox( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RESTART_NUMBERING
, _("&Restart numbering"), wxDefaultPosition
, wxDefaultSize
, 0 );
289 m_restartNumberingCtrl
->SetValue(false);
290 m_restartNumberingCtrl
->SetHelpText(_("Check to restart numbering."));
291 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
292 m_restartNumberingCtrl
->SetToolTip(_("Check to restart numbering."));
293 m_bottomButtonSizer
->Add(m_restartNumberingCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
295 m_stdButtonSizer
= new wxStdDialogButtonSizer
;
297 m_bottomButtonSizer
->Add(m_stdButtonSizer
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
298 m_okButton
= new wxButton( itemDialog1
, wxID_OK
, _("OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
299 m_stdButtonSizer
->AddButton(m_okButton
);
301 m_cancelButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
302 m_stdButtonSizer
->AddButton(m_cancelButton
);
304 wxButton
* itemButton29
= new wxButton( itemDialog1
, wxID_HELP
, _("&Help"), wxDefaultPosition
, wxDefaultSize
, 0 );
305 m_stdButtonSizer
->AddButton(itemButton29
);
307 m_stdButtonSizer
->Realize();
309 ////@end wxRichTextStyleOrganiserDialog content construction
311 if (GetHelpId() == -1)
313 wxWindow
* button
= FindWindowById(wxID_HELP
);
315 m_stdButtonSizer
->Show(button
, false);
318 if ((m_flags
& wxRICHTEXT_ORGANISER_CREATE_STYLES
) == 0)
320 m_buttonSizer
->Show(m_newCharacter
, false);
321 m_buttonSizer
->Show(m_newParagraph
, false);
322 m_buttonSizer
->Show(m_newList
, false);
323 m_buttonSizer
->Show(m_newBox
, false);
325 if ((m_flags
& wxRICHTEXT_ORGANISER_DELETE_STYLES
) == 0)
327 m_buttonSizer
->Show(m_deleteStyle
, false);
329 if ((m_flags
& wxRICHTEXT_ORGANISER_APPLY_STYLES
) == 0)
331 m_buttonSizer
->Show(m_applyStyle
, false);
333 if ((m_flags
& wxRICHTEXT_ORGANISER_EDIT_STYLES
) == 0)
335 m_buttonSizer
->Show(m_editStyle
, false);
337 if ((m_flags
& wxRICHTEXT_ORGANISER_RENAME_STYLES
) == 0)
339 m_buttonSizer
->Show(m_renameStyle
, false);
341 if ((m_flags
& wxRICHTEXT_ORGANISER_RENUMBER
) == 0)
343 m_bottomButtonSizer
->Show(m_restartNumberingCtrl
, false);
346 if ((m_flags
& wxRICHTEXT_ORGANISER_OK_CANCEL
) == 0)
348 m_stdButtonSizer
->Show(m_okButton
, false);
349 m_stdButtonSizer
->Show(m_cancelButton
, false);
353 m_buttonSizer
->Show(m_closeButton
, false);
356 // No buttons in the vertical group are shown, so hide the whole sizer
357 if ((m_flags
& wxRICHTEXT_ORGANISER_ORGANISE
) == 0)
359 m_buttonSizerParent
->Show(m_buttonSizer
, false);
362 // No buttons in the horizontal group are shown, so hide the whole sizer
363 if ((m_flags
& (wxRICHTEXT_ORGANISER_OK_CANCEL
|wxRICHTEXT_ORGANISER_RENUMBER
)) == 0)
365 m_innerSizer
->Show(m_bottomButtonSizer
, false);
368 if (hideTypeSelector
)
370 m_stylesListBox
->GetStyleListBox()->SetStyleType(typesToShow
);
373 m_stylesListBox
->SetStyleSheet(m_richTextStyleSheet
);
374 m_stylesListBox
->SetRichTextCtrl(m_richTextCtrl
);
375 m_stylesListBox
->UpdateStyles();
376 m_stylesListBox
->GetStyleListBox()->SetAutoSetSelection(false); // stop idle-time auto selection
377 if (m_stylesListBox
->GetStyleListBox()->GetItemCount() > 0)
379 m_stylesListBox
->GetStyleListBox()->SetSelection(0);
385 * Should we show tooltips?
388 /// Get selected style name or definition
389 wxString
wxRichTextStyleOrganiserDialog::GetSelectedStyle() const
391 wxRichTextStyleDefinition
* def
= GetSelectedStyleDefinition();
393 return def
->GetName();
395 return wxEmptyString
;
398 wxRichTextStyleDefinition
* wxRichTextStyleOrganiserDialog::GetSelectedStyleDefinition() const
400 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
401 return m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
405 /// Transfer data from/to window
406 bool wxRichTextStyleOrganiserDialog::TransferDataFromWindow()
408 if (!wxDialog::TransferDataFromWindow())
411 m_restartNumbering
= m_restartNumberingCtrl
->GetValue();
416 bool wxRichTextStyleOrganiserDialog::TransferDataToWindow()
418 if (!wxDialog::TransferDataToWindow())
421 m_restartNumberingCtrl
->SetValue(m_restartNumbering
);
426 /// Show preview for given or selected preview
427 void wxRichTextStyleOrganiserDialog::ShowPreview(int sel
)
429 static const wxChar
* s_para1
= wxT("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
430 Nullam ante sapien, vestibulum nonummy, pulvinar sed, luctus ut, lacus.\n");
432 static const wxChar
* s_para2List
= wxT("Duis pharetra consequat dui. Nullam vitae justo id mauris lobortis interdum.\n");
434 static const wxChar
* s_para2
= wxT("Duis pharetra consequat dui. Cum sociis natoque penatibus \
435 et magnis dis parturient montes, nascetur ridiculus mus. Nullam vitae justo id mauris lobortis interdum.\n");
437 static const wxChar
* s_para3
= wxT("Integer convallis dolor at augue \
438 iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n");
442 sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
447 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
448 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
449 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(def
, wxRichTextBoxStyleDefinition
);
451 wxStaticText
* labelCtrl
= (wxStaticText
*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
);
453 labelCtrl
->SetLabel(def
->GetName() + wxT(":"));
455 wxRichTextAttr
attr(def
->GetStyleMergedWithBase(GetStyleSheet()));
457 wxFont
font(m_previewCtrl
->GetFont());
458 font
.SetPointSize(9);
459 m_previewCtrl
->SetFont(font
);
461 wxRichTextAttr normalParaAttr
;
462 normalParaAttr
.SetFont(font
);
463 normalParaAttr
.SetTextColour(wxColour(wxT("LIGHT GREY")));
465 m_previewCtrl
->Freeze();
466 m_previewCtrl
->Clear();
468 m_previewCtrl
->BeginStyle(normalParaAttr
);
469 m_previewCtrl
->WriteText(s_para1
);
470 m_previewCtrl
->EndStyle();
474 m_previewCtrl
->BeginStyle(attr
);
475 long listStart
= m_previewCtrl
->GetInsertionPoint() + 1;
477 for (i
= 0; i
< 10; i
++)
479 wxRichTextAttr levelAttr
= * listDef
->GetLevelAttributes(i
);
480 levelAttr
.SetBulletNumber(1);
481 m_previewCtrl
->BeginStyle(levelAttr
);
482 m_previewCtrl
->WriteText(wxString::Format(wxT("List level %d. "), i
+1) + s_para2List
);
483 m_previewCtrl
->EndStyle();
485 long listEnd
= m_previewCtrl
->GetInsertionPoint();
486 m_previewCtrl
->NumberList(wxRichTextRange(listStart
, listEnd
), listDef
);
487 m_previewCtrl
->EndStyle();
491 wxRichTextAttr cellParaAttr
;
492 cellParaAttr
.SetFont(font
);
493 cellParaAttr
.SetTextColour(*wxBLACK
);
495 wxRichTextBox
* textBox
= m_previewCtrl
->WriteTextBox(attr
);
496 m_previewCtrl
->SetFocusObject(textBox
);
497 m_previewCtrl
->BeginStyle(cellParaAttr
);
498 wxString
text(s_para2
);
499 text
.Replace(wxT("\n"), wxEmptyString
);
500 m_previewCtrl
->WriteText(text
);
501 m_previewCtrl
->EndStyle();
502 m_previewCtrl
->SetFocusObject(NULL
); // Set the focus back to the main buffer
503 m_previewCtrl
->SetInsertionPointEnd();
504 m_previewCtrl
->SetDefaultStyle(wxRichTextAttr());
508 m_previewCtrl
->BeginStyle(attr
);
509 m_previewCtrl
->WriteText(s_para2
);
510 m_previewCtrl
->EndStyle();
513 m_previewCtrl
->BeginStyle(normalParaAttr
);
514 m_previewCtrl
->WriteText(s_para3
);
515 m_previewCtrl
->EndStyle();
517 m_previewCtrl
->Thaw();
520 /// Clears the preview
521 void wxRichTextStyleOrganiserDialog::ClearPreview()
523 m_previewCtrl
->Clear();
524 wxStaticText
* labelCtrl
= (wxStaticText
*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
);
526 labelCtrl
->SetLabel(wxEmptyString
);
529 bool wxRichTextStyleOrganiserDialog::ApplyStyle(wxRichTextCtrl
* ctrl
)
531 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
535 ctrl
= GetRichTextCtrl();
539 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
540 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
542 if (listDef
&& m_restartNumberingCtrl
->GetValue() && ctrl
->HasSelection())
544 wxRichTextRange range
= ctrl
->GetSelectionRange();
545 return ctrl
->SetListStyle(range
, listDef
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_RENUMBER
);
549 return ctrl
->ApplyStyle(def
);
554 * Get bitmap resources
557 wxBitmap
wxRichTextStyleOrganiserDialog::GetBitmapResource( const wxString
& name
)
560 ////@begin wxRichTextStyleOrganiserDialog bitmap retrieval
563 ////@end wxRichTextStyleOrganiserDialog bitmap retrieval
570 wxIcon
wxRichTextStyleOrganiserDialog::GetIconResource( const wxString
& name
)
573 ////@begin wxRichTextStyleOrganiserDialog icon retrieval
576 ////@end wxRichTextStyleOrganiserDialog icon retrieval
580 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
583 void wxRichTextStyleOrganiserDialog::OnApplyClick( wxCommandEvent
& WXUNUSED(event
) )
589 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
592 void wxRichTextStyleOrganiserDialog::OnApplyUpdate( wxUpdateUIEvent
& event
)
594 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_APPLY_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
599 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
602 void wxRichTextStyleOrganiserDialog::OnNewCharClick( wxCommandEvent
& WXUNUSED(event
) )
604 wxString styleName
= wxGetTextFromUser(_("Enter a character style name"), _("New Style"));
605 if (!styleName
.IsEmpty())
607 if (GetStyleSheet()->FindCharacterStyle(styleName
))
609 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
613 wxRichTextCharacterStyleDefinition
* style
= new wxRichTextCharacterStyleDefinition(styleName
);
615 int pages
= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_STYLE_EDITOR
;
616 wxRichTextFormattingDialog formatDlg
;
617 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
618 formatDlg
.Create(pages
, this);
620 if (formatDlg
.ShowModal() == wxID_OK
)
622 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
624 (*((wxRichTextCharacterStyleDefinition
* ) style
)) = (*charDef
);
626 GetStyleSheet()->AddCharacterStyle(style
);
628 m_stylesListBox
->UpdateStyles();
637 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
640 void wxRichTextStyleOrganiserDialog::OnNewCharUpdate( wxUpdateUIEvent
& event
)
642 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
647 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
650 void wxRichTextStyleOrganiserDialog::OnNewParaClick( wxCommandEvent
& WXUNUSED(event
) )
652 wxString styleName
= wxGetTextFromUser(_("Enter a paragraph style name"), _("New Style"));
653 if (!styleName
.IsEmpty())
655 if (GetStyleSheet()->FindParagraphStyle(styleName
))
657 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
661 wxRichTextParagraphStyleDefinition
* style
= new wxRichTextParagraphStyleDefinition(styleName
);
663 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
664 wxRichTextFormattingDialog formatDlg
;
665 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
666 formatDlg
.Create(pages
, this);
668 if (formatDlg
.ShowModal() == wxID_OK
)
670 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
672 (*((wxRichTextParagraphStyleDefinition
* ) style
)) = (*paraDef
);
674 GetStyleSheet()->AddParagraphStyle(style
);
676 m_stylesListBox
->UpdateStyles();
685 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
688 void wxRichTextStyleOrganiserDialog::OnNewParaUpdate( wxUpdateUIEvent
& event
)
690 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
695 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
698 void wxRichTextStyleOrganiserDialog::OnEditClick( wxCommandEvent
& WXUNUSED(event
) )
700 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
701 if (sel
!= wxNOT_FOUND
)
703 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
705 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
;
707 if (wxDynamicCast(def
, wxRichTextCharacterStyleDefinition
))
709 pages
|= wxRICHTEXT_FORMAT_FONT
;
711 else if (wxDynamicCast(def
, wxRichTextListStyleDefinition
))
713 pages
|= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
715 else if (wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
))
717 pages
|= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
719 else if (wxDynamicCast(def
, wxRichTextBoxStyleDefinition
))
721 pages
|= wxRICHTEXT_FORMAT_MARGINS
|wxRICHTEXT_FORMAT_SIZE
|wxRICHTEXT_FORMAT_BORDERS
|wxRICHTEXT_FORMAT_BACKGROUND
;
724 wxRichTextFormattingDialog formatDlg
;
725 formatDlg
.SetStyleDefinition(*def
, GetStyleSheet());
726 formatDlg
.Create(pages
, this);
728 if (formatDlg
.ShowModal() == wxID_OK
)
730 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
731 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
732 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
733 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextBoxStyleDefinition
);
737 (*((wxRichTextListStyleDefinition
* ) def
)) = (*listDef
);
741 (*((wxRichTextParagraphStyleDefinition
* ) def
)) = (*paraDef
);
745 (*((wxRichTextBoxStyleDefinition
* ) def
)) = (*boxDef
);
749 (*((wxRichTextCharacterStyleDefinition
* ) def
)) = (*charDef
);
752 m_stylesListBox
->UpdateStyles();
753 m_stylesListBox
->GetStyleListBox()->SetSelection(sel
);
760 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
763 void wxRichTextStyleOrganiserDialog::OnEditUpdate( wxUpdateUIEvent
& event
)
765 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_EDIT_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
770 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
773 void wxRichTextStyleOrganiserDialog::OnDeleteClick( wxCommandEvent
& WXUNUSED(event
) )
775 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
776 if (sel
!= wxNOT_FOUND
)
778 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
779 wxString
name(def
->GetName());
780 if (wxYES
== wxMessageBox(wxString::Format(_("Delete style %s?"), name
), _("Delete Style"), wxYES_NO
|wxICON_QUESTION
, this))
782 m_stylesListBox
->GetStyleListBox()->SetItemCount(0);
784 if (wxDynamicCast(def
, wxRichTextListStyleDefinition
))
785 GetStyleSheet()->RemoveListStyle((wxRichTextListStyleDefinition
*) def
, true);
786 else if (wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
))
787 GetStyleSheet()->RemoveParagraphStyle((wxRichTextParagraphStyleDefinition
*) def
, true);
788 else if (wxDynamicCast(def
, wxRichTextCharacterStyleDefinition
))
789 GetStyleSheet()->RemoveCharacterStyle((wxRichTextCharacterStyleDefinition
*) def
, true);
790 else if (wxDynamicCast(def
, wxRichTextBoxStyleDefinition
))
791 GetStyleSheet()->RemoveBoxStyle((wxRichTextBoxStyleDefinition
*) def
, true);
793 m_stylesListBox
->UpdateStyles();
795 if (m_stylesListBox
->GetStyleListBox()->GetSelection() != -1)
804 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
807 void wxRichTextStyleOrganiserDialog::OnDeleteUpdate( wxUpdateUIEvent
& event
)
809 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_DELETE_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
813 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
816 void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent
& WXUNUSED(event
) )
818 wxString styleName
= wxGetTextFromUser(_("Enter a list style name"), _("New Style"));
819 if (!styleName
.IsEmpty())
821 if (GetStyleSheet()->FindListStyle(styleName
))
823 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
827 wxRichTextListStyleDefinition
* style
= new wxRichTextListStyleDefinition(styleName
);
829 // Initialize the style to make it easier to edit
831 for (i
= 0; i
< 10; i
++)
833 wxString bulletSymbol
;
835 bulletSymbol
= wxT("*");
837 bulletSymbol
= wxT("-");
839 bulletSymbol
= wxT("*");
841 bulletSymbol
= wxT("-");
843 bulletSymbol
= wxT("*");
845 style
->SetAttributes(i
, (i
+1)*60, 60, wxTEXT_ATTR_BULLET_STYLE_SYMBOL
, bulletSymbol
);
848 int pages
= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
849 wxRichTextFormattingDialog formatDlg
;
850 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
851 formatDlg
.Create(pages
, this);
853 if (formatDlg
.ShowModal() == wxID_OK
)
855 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
857 (*((wxRichTextListStyleDefinition
* ) style
)) = (*listDef
);
859 GetStyleSheet()->AddListStyle(style
);
861 m_stylesListBox
->UpdateStyles();
870 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
873 void wxRichTextStyleOrganiserDialog::OnNewListUpdate( wxUpdateUIEvent
& event
)
875 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
879 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
882 void wxRichTextStyleOrganiserDialog::OnRenameClick( wxCommandEvent
& WXUNUSED(event
) )
884 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
887 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
891 wxString styleName
= wxGetTextFromUser(_("Enter a new style name"), _("New Style"), def
->GetName());
892 if (!styleName
.IsEmpty())
894 if (styleName
== def
->GetName())
897 if (GetStyleSheet()->FindParagraphStyle(styleName
) || GetStyleSheet()->FindCharacterStyle(styleName
) || GetStyleSheet()->FindListStyle(styleName
) || GetStyleSheet()->FindBoxStyle(styleName
))
899 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
903 def
->SetName(styleName
);
904 m_stylesListBox
->UpdateStyles();
909 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
912 void wxRichTextStyleOrganiserDialog::OnRenameUpdate( wxUpdateUIEvent
& event
)
914 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_RENAME_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
918 void wxRichTextStyleOrganiserDialog::OnListSelection(wxCommandEvent
& event
)
920 if (event
.GetEventObject() == m_stylesListBox
->GetStyleListBox())
927 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
930 void wxRichTextStyleOrganiserDialog::OnNewBoxClick( wxCommandEvent
& WXUNUSED(event
) )
932 wxString styleName
= wxGetTextFromUser(_("Enter a box style name"), _("New Style"));
933 if (!styleName
.IsEmpty())
935 if (GetStyleSheet()->FindBoxStyle(styleName
))
937 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
941 wxRichTextBoxStyleDefinition
* style
= new wxRichTextBoxStyleDefinition(styleName
);
943 int pages
= wxRICHTEXT_FORMAT_MARGINS
|wxRICHTEXT_FORMAT_SIZE
|wxRICHTEXT_FORMAT_BORDERS
|wxRICHTEXT_FORMAT_BACKGROUND
;
944 wxRichTextFormattingDialog formatDlg
;
945 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
946 formatDlg
.Create(pages
, this);
948 if (formatDlg
.ShowModal() == wxID_OK
)
950 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextBoxStyleDefinition
);
952 (*((wxRichTextBoxStyleDefinition
* ) style
)) = (*boxDef
);
954 GetStyleSheet()->AddBoxStyle(style
);
956 m_stylesListBox
->UpdateStyles();
965 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
968 void wxRichTextStyleOrganiserDialog::OnNewBoxUpdate( wxUpdateUIEvent
& event
)
970 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
974 * wxEVT_BUTTON event handler for wxID_HELP
977 void wxRichTextStyleOrganiserDialog::OnHelpClick( wxCommandEvent
& WXUNUSED(event
) )
979 if ((GetHelpId() != -1) && GetUICustomization())