1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextstyledlg.cpp
4 // Author: Julian Smart
6 // Created: 10/5/2006 12:05:31 PM
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
24 #include "wx/richtext/richtextstyledlg.h"
25 #include "wx/richtext/richtextformatdlg.h"
28 * wxRichTextStyleOrganiserDialog type definition
31 bool wxRichTextStyleOrganiserDialog::sm_showToolTips
= false;
33 IMPLEMENT_DYNAMIC_CLASS( wxRichTextStyleOrganiserDialog
, wxDialog
)
36 * wxRichTextStyleOrganiserDialog event table definition
39 BEGIN_EVENT_TABLE( wxRichTextStyleOrganiserDialog
, wxDialog
)
41 EVT_LISTBOX(wxID_ANY
, wxRichTextStyleOrganiserDialog::OnListSelection
)
43 ////@begin wxRichTextStyleOrganiserDialog event table entries
44 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
, wxRichTextStyleOrganiserDialog::OnNewCharClick
)
45 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
, wxRichTextStyleOrganiserDialog::OnNewCharUpdate
)
46 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, wxRichTextStyleOrganiserDialog::OnNewParaClick
)
47 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, wxRichTextStyleOrganiserDialog::OnNewParaUpdate
)
48 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, wxRichTextStyleOrganiserDialog::OnNewListClick
)
49 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, wxRichTextStyleOrganiserDialog::OnNewListUpdate
)
50 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
, wxRichTextStyleOrganiserDialog::OnNewBoxClick
)
51 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
, wxRichTextStyleOrganiserDialog::OnNewBoxUpdate
)
52 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, wxRichTextStyleOrganiserDialog::OnApplyClick
)
53 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, wxRichTextStyleOrganiserDialog::OnApplyUpdate
)
54 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, wxRichTextStyleOrganiserDialog::OnRenameClick
)
55 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, wxRichTextStyleOrganiserDialog::OnRenameUpdate
)
56 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, wxRichTextStyleOrganiserDialog::OnEditClick
)
57 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, wxRichTextStyleOrganiserDialog::OnEditUpdate
)
58 EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, wxRichTextStyleOrganiserDialog::OnDeleteClick
)
59 EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, wxRichTextStyleOrganiserDialog::OnDeleteUpdate
)
60 EVT_BUTTON( wxID_HELP
, wxRichTextStyleOrganiserDialog::OnHelpClick
)
61 ////@end wxRichTextStyleOrganiserDialog event table entries
65 IMPLEMENT_HELP_PROVISION(wxRichTextStyleOrganiserDialog
)
68 * wxRichTextStyleOrganiserDialog constructors
71 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( )
76 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
79 Create(flags
, sheet
, ctrl
, parent
, id
, caption
, pos
, size
, style
);
83 * Member initialisation for wxSymbolPickerDialog
86 void wxRichTextStyleOrganiserDialog::Init()
88 m_richTextStyleSheet
= NULL
;
89 m_richTextCtrl
= NULL
;
92 m_restartNumbering
= true;
94 ////@begin wxRichTextStyleOrganiserDialog member initialisation
96 m_buttonSizerParent
= NULL
;
97 m_stylesListBox
= NULL
;
100 m_newCharacter
= NULL
;
101 m_newParagraph
= NULL
;
105 m_renameStyle
= NULL
;
107 m_deleteStyle
= NULL
;
108 m_closeButton
= NULL
;
109 m_bottomButtonSizer
= NULL
;
110 m_restartNumberingCtrl
= NULL
;
111 m_stdButtonSizer
= NULL
;
113 m_cancelButton
= NULL
;
114 ////@end wxRichTextStyleOrganiserDialog member initialisation
118 * wxRichTextStyleOrganiserDialog creator
121 bool wxRichTextStyleOrganiserDialog::Create( int flags
, wxRichTextStyleSheet
* sheet
, wxRichTextCtrl
* ctrl
, wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
123 m_richTextStyleSheet
= sheet
;
124 m_richTextCtrl
= ctrl
;
127 ////@begin wxRichTextStyleOrganiserDialog creation
128 SetExtraStyle(wxWS_EX_BLOCK_EVENTS
|wxDIALOG_EX_CONTEXTHELP
);
129 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
134 GetSizer()->SetSizeHints(this);
137 ////@end wxRichTextStyleOrganiserDialog creation
142 * Control creation for wxRichTextStyleOrganiserDialog
145 void wxRichTextStyleOrganiserDialog::CreateControls()
148 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
151 bool hideTypeSelector
= false;
152 wxRichTextStyleListBox::wxRichTextStyleType typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL
;
154 if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_CHARACTER
) != 0)
156 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
;
157 hideTypeSelector
= true;
159 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_PARAGRAPH
) != 0)
161 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH
;
162 hideTypeSelector
= true;
164 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_BOX
) != 0)
166 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_BOX
;
167 hideTypeSelector
= true;
169 else if ((m_flags
& wxRICHTEXT_ORGANISER_SHOW_LIST
) != 0)
171 typesToShow
= wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST
;
172 hideTypeSelector
= true;
176 // wxRICHTEXT_ORGANISER_SHOW_ALL is implied if the other styles aren't included
179 long listCtrlStyle
= 0;
180 if (hideTypeSelector
)
181 listCtrlStyle
= wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR
;
183 ////@begin wxRichTextStyleOrganiserDialog content construction
184 wxRichTextStyleOrganiserDialog
* itemDialog1
= this;
186 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
187 itemDialog1
->SetSizer(itemBoxSizer2
);
189 m_innerSizer
= new wxBoxSizer(wxVERTICAL
);
190 itemBoxSizer2
->Add(m_innerSizer
, 1, wxGROW
|wxALL
, 5);
192 m_buttonSizerParent
= new wxBoxSizer(wxHORIZONTAL
);
193 m_innerSizer
->Add(m_buttonSizerParent
, 1, wxGROW
, 5);
195 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
196 m_buttonSizerParent
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
198 wxStaticText
* itemStaticText6
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Styles:"), wxDefaultPosition
, wxDefaultSize
, 0 );
199 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
201 m_stylesListBox
= new wxRichTextStyleListCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_STYLES
, wxDefaultPosition
, wxSize(280, 260), listCtrlStyle
);
202 m_stylesListBox
->SetHelpText(_("The available styles."));
203 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
204 m_stylesListBox
->SetToolTip(_("The available styles."));
205 itemBoxSizer5
->Add(m_stylesListBox
, 1, wxGROW
|wxALL
, 5);
207 wxBoxSizer
* itemBoxSizer8
= new wxBoxSizer(wxVERTICAL
);
208 m_buttonSizerParent
->Add(itemBoxSizer8
, 0, wxGROW
, 5);
210 wxStaticText
* itemStaticText9
= new wxStaticText( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
211 itemBoxSizer8
->Add(itemStaticText9
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
213 m_previewCtrl
= new wxRichTextCtrl( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_PREVIEW
, wxEmptyString
, wxDefaultPosition
, wxSize(250, 200), wxBORDER_THEME
|wxVSCROLL
|wxTE_READONLY
);
214 m_previewCtrl
->SetHelpText(_("The style preview."));
215 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
216 m_previewCtrl
->SetToolTip(_("The style preview."));
217 itemBoxSizer8
->Add(m_previewCtrl
, 1, wxGROW
|wxALL
, 5);
219 m_buttonSizer
= new wxBoxSizer(wxVERTICAL
);
220 m_buttonSizerParent
->Add(m_buttonSizer
, 0, wxGROW
, 5);
222 wxStaticText
* itemStaticText12
= new wxStaticText( itemDialog1
, wxID_STATIC
, _(" "), wxDefaultPosition
, wxDefaultSize
, 0 );
223 m_buttonSizer
->Add(itemStaticText12
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
225 m_newCharacter
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
, _("New &Character Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
226 m_newCharacter
->SetHelpText(_("Click to create a new character style."));
227 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
228 m_newCharacter
->SetToolTip(_("Click to create a new character style."));
229 m_buttonSizer
->Add(m_newCharacter
, 0, wxGROW
|wxALL
, 5);
231 m_newParagraph
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
, _("New &Paragraph Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
232 m_newParagraph
->SetHelpText(_("Click to create a new paragraph style."));
233 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
234 m_newParagraph
->SetToolTip(_("Click to create a new paragraph style."));
235 m_buttonSizer
->Add(m_newParagraph
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
237 m_newList
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
, _("New &List Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
238 m_newList
->SetHelpText(_("Click to create a new list style."));
239 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
240 m_newList
->SetToolTip(_("Click to create a new list style."));
241 m_buttonSizer
->Add(m_newList
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
243 m_newBox
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
, _("New &Box Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
244 m_newBox
->SetHelpText(_("Click to create a new box style."));
245 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
246 m_newBox
->SetToolTip(_("Click to create a new box style."));
247 m_buttonSizer
->Add(m_newBox
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
249 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
251 m_applyStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
, _("&Apply Style"), wxDefaultPosition
, wxDefaultSize
, 0 );
252 m_applyStyle
->SetHelpText(_("Click to apply the selected style."));
253 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
254 m_applyStyle
->SetToolTip(_("Click to apply the selected style."));
255 m_buttonSizer
->Add(m_applyStyle
, 0, wxGROW
|wxALL
, 5);
257 m_renameStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
, _("&Rename Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
258 m_renameStyle
->SetHelpText(_("Click to rename the selected style."));
259 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
260 m_renameStyle
->SetToolTip(_("Click to rename the selected style."));
261 m_buttonSizer
->Add(m_renameStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
263 m_editStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
, _("&Edit Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
264 m_editStyle
->SetHelpText(_("Click to edit the selected style."));
265 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
266 m_editStyle
->SetToolTip(_("Click to edit the selected style."));
267 m_buttonSizer
->Add(m_editStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
269 m_deleteStyle
= new wxButton( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
, _("&Delete Style..."), wxDefaultPosition
, wxDefaultSize
, 0 );
270 m_deleteStyle
->SetHelpText(_("Click to delete the selected style."));
271 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
272 m_deleteStyle
->SetToolTip(_("Click to delete the selected style."));
273 m_buttonSizer
->Add(m_deleteStyle
, 0, wxGROW
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5);
275 m_buttonSizer
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
277 m_closeButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
278 m_closeButton
->SetDefault();
279 m_closeButton
->SetHelpText(_("Click to close this window."));
280 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
281 m_closeButton
->SetToolTip(_("Click to close this window."));
282 m_buttonSizer
->Add(m_closeButton
, 0, wxGROW
|wxALL
, 5);
284 m_bottomButtonSizer
= new wxBoxSizer(wxHORIZONTAL
);
285 m_innerSizer
->Add(m_bottomButtonSizer
, 0, wxGROW
, 5);
287 m_restartNumberingCtrl
= new wxCheckBox( itemDialog1
, ID_RICHTEXTSTYLEORGANISERDIALOG_RESTART_NUMBERING
, _("&Restart numbering"), wxDefaultPosition
, wxDefaultSize
, 0 );
288 m_restartNumberingCtrl
->SetValue(false);
289 m_restartNumberingCtrl
->SetHelpText(_("Check to restart numbering."));
290 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
291 m_restartNumberingCtrl
->SetToolTip(_("Check to restart numbering."));
292 m_bottomButtonSizer
->Add(m_restartNumberingCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
294 m_stdButtonSizer
= new wxStdDialogButtonSizer
;
296 m_bottomButtonSizer
->Add(m_stdButtonSizer
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
297 m_okButton
= new wxButton( itemDialog1
, wxID_OK
, _("OK"), wxDefaultPosition
, wxDefaultSize
, 0 );
298 m_stdButtonSizer
->AddButton(m_okButton
);
300 m_cancelButton
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
301 m_stdButtonSizer
->AddButton(m_cancelButton
);
303 wxButton
* itemButton29
= new wxButton( itemDialog1
, wxID_HELP
, _("&Help"), wxDefaultPosition
, wxDefaultSize
, 0 );
304 m_stdButtonSizer
->AddButton(itemButton29
);
306 m_stdButtonSizer
->Realize();
308 ////@end wxRichTextStyleOrganiserDialog content construction
310 if (GetHelpId() == -1)
312 wxWindow
* button
= FindWindowById(wxID_HELP
);
314 m_stdButtonSizer
->Show(button
, false);
317 if ((m_flags
& wxRICHTEXT_ORGANISER_CREATE_STYLES
) == 0)
319 m_buttonSizer
->Show(m_newCharacter
, false);
320 m_buttonSizer
->Show(m_newParagraph
, false);
321 m_buttonSizer
->Show(m_newList
, false);
322 m_buttonSizer
->Show(m_newBox
, false);
324 if ((m_flags
& wxRICHTEXT_ORGANISER_DELETE_STYLES
) == 0)
326 m_buttonSizer
->Show(m_deleteStyle
, false);
328 if ((m_flags
& wxRICHTEXT_ORGANISER_APPLY_STYLES
) == 0)
330 m_buttonSizer
->Show(m_applyStyle
, false);
332 if ((m_flags
& wxRICHTEXT_ORGANISER_EDIT_STYLES
) == 0)
334 m_buttonSizer
->Show(m_editStyle
, false);
336 if ((m_flags
& wxRICHTEXT_ORGANISER_RENAME_STYLES
) == 0)
338 m_buttonSizer
->Show(m_renameStyle
, false);
340 if ((m_flags
& wxRICHTEXT_ORGANISER_RENUMBER
) == 0)
342 m_bottomButtonSizer
->Show(m_restartNumberingCtrl
, false);
345 if ((m_flags
& wxRICHTEXT_ORGANISER_OK_CANCEL
) == 0)
347 m_stdButtonSizer
->Show(m_okButton
, false);
348 m_stdButtonSizer
->Show(m_cancelButton
, false);
352 m_buttonSizer
->Show(m_closeButton
, false);
355 // No buttons in the vertical group are shown, so hide the whole sizer
356 if ((m_flags
& wxRICHTEXT_ORGANISER_ORGANISE
) == 0)
358 m_buttonSizerParent
->Show(m_buttonSizer
, false);
361 // No buttons in the horizontal group are shown, so hide the whole sizer
362 if ((m_flags
& (wxRICHTEXT_ORGANISER_OK_CANCEL
|wxRICHTEXT_ORGANISER_RENUMBER
)) == 0)
364 m_innerSizer
->Show(m_bottomButtonSizer
, false);
367 if (hideTypeSelector
)
369 m_stylesListBox
->GetStyleListBox()->SetStyleType(typesToShow
);
372 m_stylesListBox
->SetStyleSheet(m_richTextStyleSheet
);
373 m_stylesListBox
->SetRichTextCtrl(m_richTextCtrl
);
374 m_stylesListBox
->UpdateStyles();
375 m_stylesListBox
->GetStyleListBox()->SetAutoSetSelection(false); // stop idle-time auto selection
376 if (m_stylesListBox
->GetStyleListBox()->GetItemCount() > 0)
378 m_stylesListBox
->GetStyleListBox()->SetSelection(0);
384 * Should we show tooltips?
387 /// Get selected style name or definition
388 wxString
wxRichTextStyleOrganiserDialog::GetSelectedStyle() const
390 wxRichTextStyleDefinition
* def
= GetSelectedStyleDefinition();
392 return def
->GetName();
394 return wxEmptyString
;
397 wxRichTextStyleDefinition
* wxRichTextStyleOrganiserDialog::GetSelectedStyleDefinition() const
399 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
400 return m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
404 /// Transfer data from/to window
405 bool wxRichTextStyleOrganiserDialog::TransferDataFromWindow()
407 if (!wxDialog::TransferDataFromWindow())
410 m_restartNumbering
= m_restartNumberingCtrl
->GetValue();
415 bool wxRichTextStyleOrganiserDialog::TransferDataToWindow()
417 if (!wxDialog::TransferDataToWindow())
420 m_restartNumberingCtrl
->SetValue(m_restartNumbering
);
425 /// Show preview for given or selected preview
426 void wxRichTextStyleOrganiserDialog::ShowPreview(int sel
)
428 static const wxChar
* s_para1
= wxT("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
429 Nullam ante sapien, vestibulum nonummy, pulvinar sed, luctus ut, lacus.\n");
431 static const wxChar
* s_para2List
= wxT("Duis pharetra consequat dui. Nullam vitae justo id mauris lobortis interdum.\n");
433 static const wxChar
* s_para2
= wxT("Duis pharetra consequat dui. Cum sociis natoque penatibus \
434 et magnis dis parturient montes, nascetur ridiculus mus. Nullam vitae justo id mauris lobortis interdum.\n");
436 static const wxChar
* s_para3
= wxT("Integer convallis dolor at augue \
437 iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n");
441 sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
446 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
447 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
448 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(def
, wxRichTextBoxStyleDefinition
);
450 wxStaticText
* labelCtrl
= (wxStaticText
*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
);
452 labelCtrl
->SetLabel(def
->GetName() + wxT(":"));
454 wxRichTextAttr
attr(def
->GetStyleMergedWithBase(GetStyleSheet()));
456 wxFont
font(m_previewCtrl
->GetFont());
457 font
.SetPointSize(9);
458 m_previewCtrl
->SetFont(font
);
460 wxRichTextAttr normalParaAttr
;
461 normalParaAttr
.SetFont(font
);
462 normalParaAttr
.SetTextColour(wxColour(wxT("LIGHT GREY")));
464 m_previewCtrl
->Freeze();
465 m_previewCtrl
->Clear();
467 m_previewCtrl
->BeginStyle(normalParaAttr
);
468 m_previewCtrl
->WriteText(s_para1
);
469 m_previewCtrl
->EndStyle();
473 m_previewCtrl
->BeginStyle(attr
);
474 long listStart
= m_previewCtrl
->GetInsertionPoint() + 1;
476 for (i
= 0; i
< 10; i
++)
478 wxRichTextAttr levelAttr
= * listDef
->GetLevelAttributes(i
);
479 levelAttr
.SetBulletNumber(1);
480 m_previewCtrl
->BeginStyle(levelAttr
);
481 m_previewCtrl
->WriteText(wxString::Format(wxT("List level %d. "), i
+1) + s_para2List
);
482 m_previewCtrl
->EndStyle();
484 long listEnd
= m_previewCtrl
->GetInsertionPoint();
485 m_previewCtrl
->NumberList(wxRichTextRange(listStart
, listEnd
), listDef
);
486 m_previewCtrl
->EndStyle();
490 wxRichTextAttr cellParaAttr
;
491 cellParaAttr
.SetFont(font
);
492 cellParaAttr
.SetTextColour(*wxBLACK
);
494 wxRichTextBox
* textBox
= m_previewCtrl
->WriteTextBox(attr
);
495 m_previewCtrl
->SetFocusObject(textBox
);
496 m_previewCtrl
->BeginStyle(cellParaAttr
);
497 wxString
text(s_para2
);
498 text
.Replace(wxT("\n"), wxEmptyString
);
499 m_previewCtrl
->WriteText(text
);
500 m_previewCtrl
->EndStyle();
501 m_previewCtrl
->SetFocusObject(NULL
); // Set the focus back to the main buffer
502 m_previewCtrl
->SetInsertionPointEnd();
503 m_previewCtrl
->SetDefaultStyle(wxRichTextAttr());
507 m_previewCtrl
->BeginStyle(attr
);
508 m_previewCtrl
->WriteText(s_para2
);
509 m_previewCtrl
->EndStyle();
512 m_previewCtrl
->BeginStyle(normalParaAttr
);
513 m_previewCtrl
->WriteText(s_para3
);
514 m_previewCtrl
->EndStyle();
516 m_previewCtrl
->Thaw();
519 /// Clears the preview
520 void wxRichTextStyleOrganiserDialog::ClearPreview()
522 m_previewCtrl
->Clear();
523 wxStaticText
* labelCtrl
= (wxStaticText
*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE
);
525 labelCtrl
->SetLabel(wxEmptyString
);
528 bool wxRichTextStyleOrganiserDialog::ApplyStyle(wxRichTextCtrl
* ctrl
)
530 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
534 ctrl
= GetRichTextCtrl();
538 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
539 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
541 if (listDef
&& m_restartNumberingCtrl
->GetValue() && ctrl
->HasSelection())
543 wxRichTextRange range
= ctrl
->GetSelectionRange();
544 return ctrl
->SetListStyle(range
, listDef
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_RENUMBER
);
548 return ctrl
->ApplyStyle(def
);
553 * Get bitmap resources
556 wxBitmap
wxRichTextStyleOrganiserDialog::GetBitmapResource( const wxString
& name
)
559 ////@begin wxRichTextStyleOrganiserDialog bitmap retrieval
562 ////@end wxRichTextStyleOrganiserDialog bitmap retrieval
569 wxIcon
wxRichTextStyleOrganiserDialog::GetIconResource( const wxString
& name
)
572 ////@begin wxRichTextStyleOrganiserDialog icon retrieval
575 ////@end wxRichTextStyleOrganiserDialog icon retrieval
579 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
582 void wxRichTextStyleOrganiserDialog::OnApplyClick( wxCommandEvent
& WXUNUSED(event
) )
588 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
591 void wxRichTextStyleOrganiserDialog::OnApplyUpdate( wxUpdateUIEvent
& event
)
593 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_APPLY_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
598 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
601 void wxRichTextStyleOrganiserDialog::OnNewCharClick( wxCommandEvent
& WXUNUSED(event
) )
603 wxString styleName
= wxGetTextFromUser(_("Enter a character style name"), _("New Style"));
604 if (!styleName
.IsEmpty())
606 if (GetStyleSheet()->FindCharacterStyle(styleName
))
608 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
612 wxRichTextCharacterStyleDefinition
* style
= new wxRichTextCharacterStyleDefinition(styleName
);
614 int pages
= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_STYLE_EDITOR
;
615 wxRichTextFormattingDialog formatDlg
;
616 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
617 formatDlg
.Create(pages
, this);
619 if (formatDlg
.ShowModal() == wxID_OK
)
621 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
623 (*((wxRichTextCharacterStyleDefinition
* ) style
)) = (*charDef
);
625 GetStyleSheet()->AddCharacterStyle(style
);
627 m_stylesListBox
->UpdateStyles();
636 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
639 void wxRichTextStyleOrganiserDialog::OnNewCharUpdate( wxUpdateUIEvent
& event
)
641 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
646 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
649 void wxRichTextStyleOrganiserDialog::OnNewParaClick( wxCommandEvent
& WXUNUSED(event
) )
651 wxString styleName
= wxGetTextFromUser(_("Enter a paragraph style name"), _("New Style"));
652 if (!styleName
.IsEmpty())
654 if (GetStyleSheet()->FindParagraphStyle(styleName
))
656 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
660 wxRichTextParagraphStyleDefinition
* style
= new wxRichTextParagraphStyleDefinition(styleName
);
662 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
663 wxRichTextFormattingDialog formatDlg
;
664 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
665 formatDlg
.Create(pages
, this);
667 if (formatDlg
.ShowModal() == wxID_OK
)
669 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
671 (*((wxRichTextParagraphStyleDefinition
* ) style
)) = (*paraDef
);
673 GetStyleSheet()->AddParagraphStyle(style
);
675 m_stylesListBox
->UpdateStyles();
684 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
687 void wxRichTextStyleOrganiserDialog::OnNewParaUpdate( wxUpdateUIEvent
& event
)
689 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
694 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
697 void wxRichTextStyleOrganiserDialog::OnEditClick( wxCommandEvent
& WXUNUSED(event
) )
699 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
700 if (sel
!= wxNOT_FOUND
)
702 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
704 int pages
= wxRICHTEXT_FORMAT_STYLE_EDITOR
;
706 if (wxDynamicCast(def
, wxRichTextCharacterStyleDefinition
))
708 pages
|= wxRICHTEXT_FORMAT_FONT
;
710 else if (wxDynamicCast(def
, wxRichTextListStyleDefinition
))
712 pages
|= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
714 else if (wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
))
716 pages
|= wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
|wxRICHTEXT_FORMAT_TABS
|wxRICHTEXT_FORMAT_BULLETS
;
718 else if (wxDynamicCast(def
, wxRichTextBoxStyleDefinition
))
720 pages
|= wxRICHTEXT_FORMAT_MARGINS
|wxRICHTEXT_FORMAT_SIZE
|wxRICHTEXT_FORMAT_BORDERS
|wxRICHTEXT_FORMAT_BACKGROUND
;
723 wxRichTextFormattingDialog formatDlg
;
724 formatDlg
.SetStyleDefinition(*def
, GetStyleSheet());
725 formatDlg
.Create(pages
, this);
727 if (formatDlg
.ShowModal() == wxID_OK
)
729 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextParagraphStyleDefinition
);
730 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextCharacterStyleDefinition
);
731 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
732 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextBoxStyleDefinition
);
736 (*((wxRichTextListStyleDefinition
* ) def
)) = (*listDef
);
740 (*((wxRichTextParagraphStyleDefinition
* ) def
)) = (*paraDef
);
744 (*((wxRichTextBoxStyleDefinition
* ) def
)) = (*boxDef
);
748 (*((wxRichTextCharacterStyleDefinition
* ) def
)) = (*charDef
);
751 m_stylesListBox
->UpdateStyles();
752 m_stylesListBox
->GetStyleListBox()->SetSelection(sel
);
759 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
762 void wxRichTextStyleOrganiserDialog::OnEditUpdate( wxUpdateUIEvent
& event
)
764 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_EDIT_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
769 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
772 void wxRichTextStyleOrganiserDialog::OnDeleteClick( wxCommandEvent
& WXUNUSED(event
) )
774 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
775 if (sel
!= wxNOT_FOUND
)
777 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
778 wxString
name(def
->GetName());
779 if (wxYES
== wxMessageBox(wxString::Format(_("Delete style %s?"), name
), _("Delete Style"), wxYES_NO
|wxICON_QUESTION
, this))
781 m_stylesListBox
->GetStyleListBox()->SetItemCount(0);
783 if (wxDynamicCast(def
, wxRichTextListStyleDefinition
))
784 GetStyleSheet()->RemoveListStyle((wxRichTextListStyleDefinition
*) def
, true);
785 else if (wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
))
786 GetStyleSheet()->RemoveParagraphStyle((wxRichTextParagraphStyleDefinition
*) def
, true);
787 else if (wxDynamicCast(def
, wxRichTextCharacterStyleDefinition
))
788 GetStyleSheet()->RemoveCharacterStyle((wxRichTextCharacterStyleDefinition
*) def
, true);
789 else if (wxDynamicCast(def
, wxRichTextBoxStyleDefinition
))
790 GetStyleSheet()->RemoveBoxStyle((wxRichTextBoxStyleDefinition
*) def
, true);
792 m_stylesListBox
->UpdateStyles();
794 if (m_stylesListBox
->GetStyleListBox()->GetSelection() != -1)
803 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE
806 void wxRichTextStyleOrganiserDialog::OnDeleteUpdate( wxUpdateUIEvent
& event
)
808 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_DELETE_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
812 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
815 void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent
& WXUNUSED(event
) )
817 wxString styleName
= wxGetTextFromUser(_("Enter a list style name"), _("New Style"));
818 if (!styleName
.IsEmpty())
820 if (GetStyleSheet()->FindListStyle(styleName
))
822 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
826 wxRichTextListStyleDefinition
* style
= new wxRichTextListStyleDefinition(styleName
);
828 // Initialize the style to make it easier to edit
830 for (i
= 0; i
< 10; i
++)
832 wxString bulletSymbol
;
834 bulletSymbol
= wxT("*");
836 bulletSymbol
= wxT("-");
838 bulletSymbol
= wxT("*");
840 bulletSymbol
= wxT("-");
842 bulletSymbol
= wxT("*");
844 style
->SetAttributes(i
, (i
+1)*60, 60, wxTEXT_ATTR_BULLET_STYLE_SYMBOL
, bulletSymbol
);
847 int pages
= wxRICHTEXT_FORMAT_LIST_STYLE
|wxRICHTEXT_FORMAT_STYLE_EDITOR
|wxRICHTEXT_FORMAT_FONT
|wxRICHTEXT_FORMAT_INDENTS_SPACING
;
848 wxRichTextFormattingDialog formatDlg
;
849 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
850 formatDlg
.Create(pages
, this);
852 if (formatDlg
.ShowModal() == wxID_OK
)
854 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextListStyleDefinition
);
856 (*((wxRichTextListStyleDefinition
* ) style
)) = (*listDef
);
858 GetStyleSheet()->AddListStyle(style
);
860 m_stylesListBox
->UpdateStyles();
869 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
872 void wxRichTextStyleOrganiserDialog::OnNewListUpdate( wxUpdateUIEvent
& event
)
874 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
878 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
881 void wxRichTextStyleOrganiserDialog::OnRenameClick( wxCommandEvent
& WXUNUSED(event
) )
883 int sel
= m_stylesListBox
->GetStyleListBox()->GetSelection();
886 wxRichTextStyleDefinition
* def
= m_stylesListBox
->GetStyleListBox()->GetStyle(sel
);
890 wxString styleName
= wxGetTextFromUser(_("Enter a new style name"), _("New Style"), def
->GetName());
891 if (!styleName
.IsEmpty())
893 if (styleName
== def
->GetName())
896 if (GetStyleSheet()->FindParagraphStyle(styleName
) || GetStyleSheet()->FindCharacterStyle(styleName
) || GetStyleSheet()->FindListStyle(styleName
) || GetStyleSheet()->FindBoxStyle(styleName
))
898 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
902 def
->SetName(styleName
);
903 m_stylesListBox
->UpdateStyles();
908 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
911 void wxRichTextStyleOrganiserDialog::OnRenameUpdate( wxUpdateUIEvent
& event
)
913 event
.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_RENAME_STYLES
) != 0) && m_stylesListBox
->GetStyleListBox()->GetSelection() != wxNOT_FOUND
);
917 void wxRichTextStyleOrganiserDialog::OnListSelection(wxCommandEvent
& event
)
919 if (event
.GetEventObject() == m_stylesListBox
->GetStyleListBox())
926 * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
929 void wxRichTextStyleOrganiserDialog::OnNewBoxClick( wxCommandEvent
& WXUNUSED(event
) )
931 wxString styleName
= wxGetTextFromUser(_("Enter a box style name"), _("New Style"));
932 if (!styleName
.IsEmpty())
934 if (GetStyleSheet()->FindBoxStyle(styleName
))
936 wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION
|wxOK
, this);
940 wxRichTextBoxStyleDefinition
* style
= new wxRichTextBoxStyleDefinition(styleName
);
942 int pages
= wxRICHTEXT_FORMAT_MARGINS
|wxRICHTEXT_FORMAT_SIZE
|wxRICHTEXT_FORMAT_BORDERS
|wxRICHTEXT_FORMAT_BACKGROUND
;
943 wxRichTextFormattingDialog formatDlg
;
944 formatDlg
.SetStyleDefinition(*style
, GetStyleSheet());
945 formatDlg
.Create(pages
, this);
947 if (formatDlg
.ShowModal() == wxID_OK
)
949 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(formatDlg
.GetStyleDefinition(), wxRichTextBoxStyleDefinition
);
951 (*((wxRichTextBoxStyleDefinition
* ) style
)) = (*boxDef
);
953 GetStyleSheet()->AddBoxStyle(style
);
955 m_stylesListBox
->UpdateStyles();
964 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX
967 void wxRichTextStyleOrganiserDialog::OnNewBoxUpdate( wxUpdateUIEvent
& event
)
969 event
.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES
) != 0);
973 * wxEVT_BUTTON event handler for wxID_HELP
976 void wxRichTextStyleOrganiserDialog::OnHelpClick( wxCommandEvent
& WXUNUSED(event
) )
978 if ((GetHelpId() != -1) && GetUICustomization())