]>
Commit | Line | Data |
---|---|---|
dadd4f55 | 1 | ///////////////////////////////////////////////////////////////////////////// |
41a85215 WS |
2 | // Name: src/richtext/richtextstyledlg.cpp |
3 | // Purpose: | |
dadd4f55 | 4 | // Author: Julian Smart |
41a85215 | 5 | // Modified by: |
dadd4f55 | 6 | // Created: 10/5/2006 12:05:31 PM |
dadd4f55 | 7 | // Copyright: (c) Julian Smart |
41a85215 | 8 | // Licence: wxWindows licence |
dadd4f55 JS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | // For compilers that support precompilation, includes "wx/wx.h". | |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
5c6e84b6 JS |
18 | #if wxUSE_RICHTEXT |
19 | ||
dadd4f55 JS |
20 | #ifndef WX_PRECOMP |
21 | #include "wx/wx.h" | |
22 | #endif | |
23 | ||
dadd4f55 JS |
24 | #include "wx/richtext/richtextstyledlg.h" |
25 | #include "wx/richtext/richtextformatdlg.h" | |
26 | ||
dadd4f55 JS |
27 | /*! |
28 | * wxRichTextStyleOrganiserDialog type definition | |
29 | */ | |
30 | ||
31 | bool wxRichTextStyleOrganiserDialog::sm_showToolTips = false; | |
32 | ||
33 | IMPLEMENT_DYNAMIC_CLASS( wxRichTextStyleOrganiserDialog, wxDialog ) | |
34 | ||
35 | /*! | |
36 | * wxRichTextStyleOrganiserDialog event table definition | |
37 | */ | |
38 | ||
39 | BEGIN_EVENT_TABLE( wxRichTextStyleOrganiserDialog, wxDialog ) | |
40 | ||
41 | EVT_LISTBOX(wxID_ANY, wxRichTextStyleOrganiserDialog::OnListSelection) | |
42 | ||
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 ) | |
dadd4f55 JS |
46 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA, wxRichTextStyleOrganiserDialog::OnNewParaClick ) |
47 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA, wxRichTextStyleOrganiserDialog::OnNewParaUpdate ) | |
dadd4f55 JS |
48 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST, wxRichTextStyleOrganiserDialog::OnNewListClick ) |
49 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST, wxRichTextStyleOrganiserDialog::OnNewListUpdate ) | |
cd720353 JS |
50 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX, wxRichTextStyleOrganiserDialog::OnNewBoxClick ) |
51 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX, wxRichTextStyleOrganiserDialog::OnNewBoxUpdate ) | |
dadd4f55 JS |
52 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY, wxRichTextStyleOrganiserDialog::OnApplyClick ) |
53 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY, wxRichTextStyleOrganiserDialog::OnApplyUpdate ) | |
dadd4f55 JS |
54 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME, wxRichTextStyleOrganiserDialog::OnRenameClick ) |
55 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME, wxRichTextStyleOrganiserDialog::OnRenameUpdate ) | |
dadd4f55 JS |
56 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT, wxRichTextStyleOrganiserDialog::OnEditClick ) |
57 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT, wxRichTextStyleOrganiserDialog::OnEditUpdate ) | |
dadd4f55 JS |
58 | EVT_BUTTON( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE, wxRichTextStyleOrganiserDialog::OnDeleteClick ) |
59 | EVT_UPDATE_UI( ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE, wxRichTextStyleOrganiserDialog::OnDeleteUpdate ) | |
3bb084c4 | 60 | EVT_BUTTON( wxID_HELP, wxRichTextStyleOrganiserDialog::OnHelpClick ) |
dadd4f55 JS |
61 | ////@end wxRichTextStyleOrganiserDialog event table entries |
62 | ||
63 | END_EVENT_TABLE() | |
64 | ||
603f702b JS |
65 | IMPLEMENT_HELP_PROVISION(wxRichTextStyleOrganiserDialog) |
66 | ||
dadd4f55 JS |
67 | /*! |
68 | * wxRichTextStyleOrganiserDialog constructors | |
69 | */ | |
70 | ||
71 | wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( ) | |
72 | { | |
73 | Init(); | |
74 | } | |
75 | ||
76 | wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( int flags, wxRichTextStyleSheet* sheet, wxRichTextCtrl* ctrl, wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) | |
77 | { | |
78 | Init(); | |
79 | Create(flags, sheet, ctrl, parent, id, caption, pos, size, style); | |
80 | } | |
81 | ||
82 | /*! | |
83 | * Member initialisation for wxSymbolPickerDialog | |
84 | */ | |
85 | ||
86 | void wxRichTextStyleOrganiserDialog::Init() | |
87 | { | |
88 | m_richTextStyleSheet = NULL; | |
89 | m_richTextCtrl = NULL; | |
bcedac44 | 90 | m_dontUpdate = false; |
dadd4f55 JS |
91 | m_flags = 0; |
92 | m_restartNumbering = true; | |
41a85215 | 93 | |
dadd4f55 JS |
94 | ////@begin wxRichTextStyleOrganiserDialog member initialisation |
95 | m_innerSizer = NULL; | |
96 | m_buttonSizerParent = NULL; | |
97 | m_stylesListBox = NULL; | |
98 | m_previewCtrl = NULL; | |
99 | m_buttonSizer = NULL; | |
100 | m_newCharacter = NULL; | |
101 | m_newParagraph = NULL; | |
102 | m_newList = NULL; | |
cd720353 | 103 | m_newBox = NULL; |
dadd4f55 JS |
104 | m_applyStyle = NULL; |
105 | m_renameStyle = NULL; | |
106 | m_editStyle = NULL; | |
107 | m_deleteStyle = NULL; | |
108 | m_closeButton = NULL; | |
109 | m_bottomButtonSizer = NULL; | |
110 | m_restartNumberingCtrl = NULL; | |
603f702b | 111 | m_stdButtonSizer = NULL; |
dadd4f55 JS |
112 | m_okButton = NULL; |
113 | m_cancelButton = NULL; | |
114 | ////@end wxRichTextStyleOrganiserDialog member initialisation | |
115 | } | |
116 | ||
117 | /*! | |
118 | * wxRichTextStyleOrganiserDialog creator | |
119 | */ | |
120 | ||
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 ) | |
122 | { | |
123 | m_richTextStyleSheet = sheet; | |
124 | m_richTextCtrl = ctrl; | |
125 | m_flags = flags; | |
41a85215 | 126 | |
dadd4f55 | 127 | ////@begin wxRichTextStyleOrganiserDialog creation |
ce04fea5 | 128 | SetExtraStyle(wxWS_EX_BLOCK_EVENTS|wxDIALOG_EX_CONTEXTHELP); |
dadd4f55 JS |
129 | wxDialog::Create( parent, id, caption, pos, size, style ); |
130 | ||
131 | CreateControls(); | |
132 | if (GetSizer()) | |
133 | { | |
134 | GetSizer()->SetSizeHints(this); | |
135 | } | |
136 | Centre(); | |
137 | ////@end wxRichTextStyleOrganiserDialog creation | |
138 | return true; | |
139 | } | |
140 | ||
141 | /*! | |
142 | * Control creation for wxRichTextStyleOrganiserDialog | |
143 | */ | |
144 | ||
145 | void wxRichTextStyleOrganiserDialog::CreateControls() | |
41a85215 | 146 | { |
2fb1532a JS |
147 | #ifdef __WXMAC__ |
148 | SetWindowVariant(wxWINDOW_VARIANT_SMALL); | |
149 | #endif | |
150 | ||
dadd4f55 JS |
151 | bool hideTypeSelector = false; |
152 | wxRichTextStyleListBox::wxRichTextStyleType typesToShow = wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL; | |
41a85215 | 153 | |
dadd4f55 JS |
154 | if ((m_flags & wxRICHTEXT_ORGANISER_SHOW_CHARACTER) != 0) |
155 | { | |
156 | typesToShow = wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER; | |
157 | hideTypeSelector = true; | |
158 | } | |
159 | else if ((m_flags & wxRICHTEXT_ORGANISER_SHOW_PARAGRAPH) != 0) | |
160 | { | |
161 | typesToShow = wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH; | |
162 | hideTypeSelector = true; | |
163 | } | |
cd720353 JS |
164 | else if ((m_flags & wxRICHTEXT_ORGANISER_SHOW_BOX) != 0) |
165 | { | |
166 | typesToShow = wxRichTextStyleListBox::wxRICHTEXT_STYLE_BOX; | |
167 | hideTypeSelector = true; | |
168 | } | |
dadd4f55 JS |
169 | else if ((m_flags & wxRICHTEXT_ORGANISER_SHOW_LIST) != 0) |
170 | { | |
171 | typesToShow = wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST; | |
172 | hideTypeSelector = true; | |
173 | } | |
174 | else | |
175 | { | |
176 | // wxRICHTEXT_ORGANISER_SHOW_ALL is implied if the other styles aren't included | |
177 | } | |
41a85215 | 178 | |
dadd4f55 JS |
179 | long listCtrlStyle = 0; |
180 | if (hideTypeSelector) | |
181 | listCtrlStyle = wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR; | |
41a85215 | 182 | |
dadd4f55 JS |
183 | ////@begin wxRichTextStyleOrganiserDialog content construction |
184 | wxRichTextStyleOrganiserDialog* itemDialog1 = this; | |
185 | ||
186 | wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); | |
187 | itemDialog1->SetSizer(itemBoxSizer2); | |
188 | ||
189 | m_innerSizer = new wxBoxSizer(wxVERTICAL); | |
190 | itemBoxSizer2->Add(m_innerSizer, 1, wxGROW|wxALL, 5); | |
191 | ||
192 | m_buttonSizerParent = new wxBoxSizer(wxHORIZONTAL); | |
193 | m_innerSizer->Add(m_buttonSizerParent, 1, wxGROW, 5); | |
194 | ||
195 | wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL); | |
196 | m_buttonSizerParent->Add(itemBoxSizer5, 1, wxGROW, 5); | |
197 | ||
198 | wxStaticText* itemStaticText6 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Styles:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 199 | itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
dadd4f55 | 200 | |
2fce6547 | 201 | m_stylesListBox = new wxRichTextStyleListCtrl( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_STYLES, wxDefaultPosition, wxSize(280, 260), listCtrlStyle ); |
dadd4f55 | 202 | m_stylesListBox->SetHelpText(_("The available styles.")); |
ce04fea5 | 203 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
204 | m_stylesListBox->SetToolTip(_("The available styles.")); |
205 | itemBoxSizer5->Add(m_stylesListBox, 1, wxGROW|wxALL, 5); | |
206 | ||
207 | wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxVERTICAL); | |
208 | m_buttonSizerParent->Add(itemBoxSizer8, 0, wxGROW, 5); | |
209 | ||
ce04fea5 JS |
210 | wxStaticText* itemStaticText9 = new wxStaticText( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE, _(" "), wxDefaultPosition, wxDefaultSize, 0 ); |
211 | itemBoxSizer8->Add(itemStaticText9, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5); | |
dadd4f55 | 212 | |
cd720353 | 213 | m_previewCtrl = new wxRichTextCtrl( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_PREVIEW, wxEmptyString, wxDefaultPosition, wxSize(250, 200), wxBORDER_THEME|wxVSCROLL|wxTE_READONLY ); |
dadd4f55 | 214 | m_previewCtrl->SetHelpText(_("The style preview.")); |
ce04fea5 | 215 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
216 | m_previewCtrl->SetToolTip(_("The style preview.")); |
217 | itemBoxSizer8->Add(m_previewCtrl, 1, wxGROW|wxALL, 5); | |
218 | ||
219 | m_buttonSizer = new wxBoxSizer(wxVERTICAL); | |
220 | m_buttonSizerParent->Add(m_buttonSizer, 0, wxGROW, 5); | |
221 | ||
222 | wxStaticText* itemStaticText12 = new wxStaticText( itemDialog1, wxID_STATIC, _(" "), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 223 | m_buttonSizer->Add(itemStaticText12, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
dadd4f55 JS |
224 | |
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.")); | |
ce04fea5 | 227 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
228 | m_newCharacter->SetToolTip(_("Click to create a new character style.")); |
229 | m_buttonSizer->Add(m_newCharacter, 0, wxGROW|wxALL, 5); | |
230 | ||
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.")); | |
ce04fea5 | 233 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
234 | m_newParagraph->SetToolTip(_("Click to create a new paragraph style.")); |
235 | m_buttonSizer->Add(m_newParagraph, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); | |
236 | ||
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.")); | |
ce04fea5 | 239 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
240 | m_newList->SetToolTip(_("Click to create a new list style.")); |
241 | m_buttonSizer->Add(m_newList, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); | |
242 | ||
cd720353 JS |
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); | |
248 | ||
dadd4f55 JS |
249 | m_buttonSizer->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); |
250 | ||
251 | m_applyStyle = new wxButton( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY, _("&Apply Style"), wxDefaultPosition, wxDefaultSize, 0 ); | |
252 | m_applyStyle->SetHelpText(_("Click to apply the selected style.")); | |
ce04fea5 | 253 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
254 | m_applyStyle->SetToolTip(_("Click to apply the selected style.")); |
255 | m_buttonSizer->Add(m_applyStyle, 0, wxGROW|wxALL, 5); | |
256 | ||
257 | m_renameStyle = new wxButton( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME, _("&Rename Style..."), wxDefaultPosition, wxDefaultSize, 0 ); | |
258 | m_renameStyle->SetHelpText(_("Click to rename the selected style.")); | |
ce04fea5 | 259 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
260 | m_renameStyle->SetToolTip(_("Click to rename the selected style.")); |
261 | m_buttonSizer->Add(m_renameStyle, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); | |
262 | ||
263 | m_editStyle = new wxButton( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT, _("&Edit Style..."), wxDefaultPosition, wxDefaultSize, 0 ); | |
264 | m_editStyle->SetHelpText(_("Click to edit the selected style.")); | |
ce04fea5 | 265 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
266 | m_editStyle->SetToolTip(_("Click to edit the selected style.")); |
267 | m_buttonSizer->Add(m_editStyle, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); | |
268 | ||
269 | m_deleteStyle = new wxButton( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE, _("&Delete Style..."), wxDefaultPosition, wxDefaultSize, 0 ); | |
270 | m_deleteStyle->SetHelpText(_("Click to delete the selected style.")); | |
ce04fea5 | 271 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
272 | m_deleteStyle->SetToolTip(_("Click to delete the selected style.")); |
273 | m_buttonSizer->Add(m_deleteStyle, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); | |
274 | ||
275 | m_buttonSizer->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); | |
276 | ||
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.")); | |
ce04fea5 | 280 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
281 | m_closeButton->SetToolTip(_("Click to close this window.")); |
282 | m_buttonSizer->Add(m_closeButton, 0, wxGROW|wxALL, 5); | |
283 | ||
284 | m_bottomButtonSizer = new wxBoxSizer(wxHORIZONTAL); | |
285 | m_innerSizer->Add(m_bottomButtonSizer, 0, wxGROW, 5); | |
286 | ||
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.")); | |
ce04fea5 | 290 | if (wxRichTextStyleOrganiserDialog::ShowToolTips()) |
dadd4f55 JS |
291 | m_restartNumberingCtrl->SetToolTip(_("Check to restart numbering.")); |
292 | m_bottomButtonSizer->Add(m_restartNumberingCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
293 | ||
603f702b | 294 | m_stdButtonSizer = new wxStdDialogButtonSizer; |
dadd4f55 | 295 | |
603f702b | 296 | m_bottomButtonSizer->Add(m_stdButtonSizer, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
dadd4f55 | 297 | m_okButton = new wxButton( itemDialog1, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 ); |
603f702b | 298 | m_stdButtonSizer->AddButton(m_okButton); |
dadd4f55 JS |
299 | |
300 | m_cancelButton = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); | |
603f702b JS |
301 | m_stdButtonSizer->AddButton(m_cancelButton); |
302 | ||
cd720353 JS |
303 | wxButton* itemButton29 = new wxButton( itemDialog1, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, 0 ); |
304 | m_stdButtonSizer->AddButton(itemButton29); | |
603f702b JS |
305 | |
306 | m_stdButtonSizer->Realize(); | |
dadd4f55 JS |
307 | |
308 | ////@end wxRichTextStyleOrganiserDialog content construction | |
309 | ||
603f702b JS |
310 | if (GetHelpId() == -1) |
311 | { | |
312 | wxWindow* button = FindWindowById(wxID_HELP); | |
313 | if (button) | |
314 | m_stdButtonSizer->Show(button, false); | |
315 | } | |
316 | ||
dadd4f55 JS |
317 | if ((m_flags & wxRICHTEXT_ORGANISER_CREATE_STYLES) == 0) |
318 | { | |
319 | m_buttonSizer->Show(m_newCharacter, false); | |
320 | m_buttonSizer->Show(m_newParagraph, false); | |
321 | m_buttonSizer->Show(m_newList, false); | |
cd720353 | 322 | m_buttonSizer->Show(m_newBox, false); |
dadd4f55 JS |
323 | } |
324 | if ((m_flags & wxRICHTEXT_ORGANISER_DELETE_STYLES) == 0) | |
325 | { | |
326 | m_buttonSizer->Show(m_deleteStyle, false); | |
327 | } | |
328 | if ((m_flags & wxRICHTEXT_ORGANISER_APPLY_STYLES) == 0) | |
329 | { | |
330 | m_buttonSizer->Show(m_applyStyle, false); | |
331 | } | |
332 | if ((m_flags & wxRICHTEXT_ORGANISER_EDIT_STYLES) == 0) | |
333 | { | |
334 | m_buttonSizer->Show(m_editStyle, false); | |
335 | } | |
336 | if ((m_flags & wxRICHTEXT_ORGANISER_RENAME_STYLES) == 0) | |
337 | { | |
338 | m_buttonSizer->Show(m_renameStyle, false); | |
339 | } | |
340 | if ((m_flags & wxRICHTEXT_ORGANISER_RENUMBER) == 0) | |
341 | { | |
342 | m_bottomButtonSizer->Show(m_restartNumberingCtrl, false); | |
343 | } | |
344 | ||
345 | if ((m_flags & wxRICHTEXT_ORGANISER_OK_CANCEL) == 0) | |
346 | { | |
603f702b JS |
347 | m_stdButtonSizer->Show(m_okButton, false); |
348 | m_stdButtonSizer->Show(m_cancelButton, false); | |
dadd4f55 JS |
349 | } |
350 | else | |
351 | { | |
352 | m_buttonSizer->Show(m_closeButton, false); | |
353 | } | |
354 | ||
355 | // No buttons in the vertical group are shown, so hide the whole sizer | |
356 | if ((m_flags & wxRICHTEXT_ORGANISER_ORGANISE) == 0) | |
357 | { | |
358 | m_buttonSizerParent->Show(m_buttonSizer, false); | |
359 | } | |
41a85215 | 360 | |
dadd4f55 JS |
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) | |
363 | { | |
364 | m_innerSizer->Show(m_bottomButtonSizer, false); | |
365 | } | |
41a85215 | 366 | |
dadd4f55 JS |
367 | if (hideTypeSelector) |
368 | { | |
369 | m_stylesListBox->GetStyleListBox()->SetStyleType(typesToShow); | |
370 | } | |
41a85215 | 371 | |
dadd4f55 JS |
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) | |
377 | { | |
378 | m_stylesListBox->GetStyleListBox()->SetSelection(0); | |
379 | ShowPreview(); | |
380 | } | |
381 | } | |
382 | ||
383 | /*! | |
384 | * Should we show tooltips? | |
385 | */ | |
386 | ||
387 | /// Get selected style name or definition | |
388 | wxString wxRichTextStyleOrganiserDialog::GetSelectedStyle() const | |
389 | { | |
390 | wxRichTextStyleDefinition* def = GetSelectedStyleDefinition(); | |
391 | if (def) | |
392 | return def->GetName(); | |
393 | else | |
394 | return wxEmptyString; | |
395 | } | |
396 | ||
397 | wxRichTextStyleDefinition* wxRichTextStyleOrganiserDialog::GetSelectedStyleDefinition() const | |
398 | { | |
399 | int sel = m_stylesListBox->GetStyleListBox()->GetSelection(); | |
400 | return m_stylesListBox->GetStyleListBox()->GetStyle(sel); | |
401 | } | |
402 | ||
403 | ||
404 | /// Transfer data from/to window | |
405 | bool wxRichTextStyleOrganiserDialog::TransferDataFromWindow() | |
406 | { | |
407 | if (!wxDialog::TransferDataFromWindow()) | |
408 | return false; | |
41a85215 | 409 | |
dadd4f55 | 410 | m_restartNumbering = m_restartNumberingCtrl->GetValue(); |
41a85215 | 411 | |
dadd4f55 JS |
412 | return true; |
413 | } | |
414 | ||
415 | bool wxRichTextStyleOrganiserDialog::TransferDataToWindow() | |
416 | { | |
417 | if (!wxDialog::TransferDataToWindow()) | |
418 | return false; | |
41a85215 | 419 | |
dadd4f55 | 420 | m_restartNumberingCtrl->SetValue(m_restartNumbering); |
41a85215 | 421 | |
dadd4f55 JS |
422 | return true; |
423 | } | |
424 | ||
425 | /// Show preview for given or selected preview | |
426 | void wxRichTextStyleOrganiserDialog::ShowPreview(int sel) | |
427 | { | |
428 | static const wxChar* s_para1 = wxT("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \ | |
c268eb32 | 429 | Nullam ante sapien, vestibulum nonummy, pulvinar sed, luctus ut, lacus.\n"); |
dadd4f55 | 430 | |
c268eb32 | 431 | static const wxChar* s_para2List = wxT("Duis pharetra consequat dui. Nullam vitae justo id mauris lobortis interdum.\n"); |
dadd4f55 JS |
432 | |
433 | static const wxChar* s_para2 = wxT("Duis pharetra consequat dui. Cum sociis natoque penatibus \ | |
c268eb32 | 434 | et magnis dis parturient montes, nascetur ridiculus mus. Nullam vitae justo id mauris lobortis interdum.\n"); |
dadd4f55 | 435 | |
c268eb32 | 436 | static const wxChar* s_para3 = wxT("Integer convallis dolor at augue \ |
dadd4f55 JS |
437 | iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n"); |
438 | ||
439 | if (sel == -1) | |
440 | { | |
441 | sel = m_stylesListBox->GetStyleListBox()->GetSelection(); | |
442 | if (sel == -1) | |
41a85215 | 443 | return; |
dadd4f55 JS |
444 | } |
445 | ||
446 | wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); | |
dadd4f55 | 447 | wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition); |
cd720353 | 448 | wxRichTextBoxStyleDefinition* boxDef = wxDynamicCast(def, wxRichTextBoxStyleDefinition); |
336d8ae9 | 449 | |
ce04fea5 JS |
450 | wxStaticText* labelCtrl = (wxStaticText*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE); |
451 | if (labelCtrl) | |
452 | labelCtrl->SetLabel(def->GetName() + wxT(":")); | |
453 | ||
24777478 | 454 | wxRichTextAttr attr(def->GetStyleMergedWithBase(GetStyleSheet())); |
dadd4f55 JS |
455 | |
456 | wxFont font(m_previewCtrl->GetFont()); | |
457 | font.SetPointSize(9); | |
458 | m_previewCtrl->SetFont(font); | |
459 | ||
24777478 | 460 | wxRichTextAttr normalParaAttr; |
dadd4f55 JS |
461 | normalParaAttr.SetFont(font); |
462 | normalParaAttr.SetTextColour(wxColour(wxT("LIGHT GREY"))); | |
463 | ||
464 | m_previewCtrl->Freeze(); | |
41a85215 | 465 | m_previewCtrl->Clear(); |
dadd4f55 JS |
466 | |
467 | m_previewCtrl->BeginStyle(normalParaAttr); | |
468 | m_previewCtrl->WriteText(s_para1); | |
469 | m_previewCtrl->EndStyle(); | |
41a85215 | 470 | |
dadd4f55 JS |
471 | if (listDef) |
472 | { | |
cd720353 | 473 | m_previewCtrl->BeginStyle(attr); |
d2d0adc7 | 474 | long listStart = m_previewCtrl->GetInsertionPoint() + 1; |
dadd4f55 JS |
475 | int i; |
476 | for (i = 0; i < 10; i++) | |
477 | { | |
24777478 | 478 | wxRichTextAttr levelAttr = * listDef->GetLevelAttributes(i); |
dadd4f55 JS |
479 | levelAttr.SetBulletNumber(1); |
480 | m_previewCtrl->BeginStyle(levelAttr); | |
c268eb32 | 481 | m_previewCtrl->WriteText(wxString::Format(wxT("List level %d. "), i+1) + s_para2List); |
dadd4f55 JS |
482 | m_previewCtrl->EndStyle(); |
483 | } | |
d2d0adc7 JS |
484 | long listEnd = m_previewCtrl->GetInsertionPoint(); |
485 | m_previewCtrl->NumberList(wxRichTextRange(listStart, listEnd), listDef); | |
cd720353 JS |
486 | m_previewCtrl->EndStyle(); |
487 | } | |
488 | else if (boxDef) | |
489 | { | |
490 | wxRichTextAttr cellParaAttr; | |
491 | cellParaAttr.SetFont(font); | |
492 | cellParaAttr.SetTextColour(*wxBLACK); | |
493 | ||
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()); | |
dadd4f55 JS |
504 | } |
505 | else | |
506 | { | |
cd720353 | 507 | m_previewCtrl->BeginStyle(attr); |
c268eb32 | 508 | m_previewCtrl->WriteText(s_para2); |
cd720353 | 509 | m_previewCtrl->EndStyle(); |
dadd4f55 | 510 | } |
41a85215 | 511 | |
dadd4f55 JS |
512 | m_previewCtrl->BeginStyle(normalParaAttr); |
513 | m_previewCtrl->WriteText(s_para3); | |
514 | m_previewCtrl->EndStyle(); | |
515 | ||
516 | m_previewCtrl->Thaw(); | |
517 | } | |
41a85215 | 518 | |
dadd4f55 JS |
519 | /// Clears the preview |
520 | void wxRichTextStyleOrganiserDialog::ClearPreview() | |
521 | { | |
5bbdfd5b | 522 | m_previewCtrl->Clear(); |
ce04fea5 JS |
523 | wxStaticText* labelCtrl = (wxStaticText*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE); |
524 | if (labelCtrl) | |
525 | labelCtrl->SetLabel(wxEmptyString); | |
dadd4f55 JS |
526 | } |
527 | ||
528 | bool wxRichTextStyleOrganiserDialog::ApplyStyle(wxRichTextCtrl* ctrl) | |
529 | { | |
530 | int sel = m_stylesListBox->GetStyleListBox()->GetSelection(); | |
531 | if (sel == -1) | |
532 | return false; | |
533 | if (!ctrl) | |
534 | ctrl = GetRichTextCtrl(); | |
535 | if (!ctrl) | |
536 | return false; | |
41a85215 WS |
537 | |
538 | wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); | |
dadd4f55 JS |
539 | wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition); |
540 | ||
b9433288 | 541 | if (listDef && m_restartNumberingCtrl->GetValue() && ctrl->HasSelection()) |
dadd4f55 JS |
542 | { |
543 | wxRichTextRange range = ctrl->GetSelectionRange(); | |
544 | return ctrl->SetListStyle(range, listDef, wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_RENUMBER); | |
545 | } | |
546 | else | |
547 | { | |
548 | return ctrl->ApplyStyle(def); | |
549 | } | |
550 | } | |
551 | ||
552 | /*! | |
553 | * Get bitmap resources | |
554 | */ | |
555 | ||
556 | wxBitmap wxRichTextStyleOrganiserDialog::GetBitmapResource( const wxString& name ) | |
557 | { | |
558 | // Bitmap retrieval | |
559 | ////@begin wxRichTextStyleOrganiserDialog bitmap retrieval | |
560 | wxUnusedVar(name); | |
561 | return wxNullBitmap; | |
562 | ////@end wxRichTextStyleOrganiserDialog bitmap retrieval | |
563 | } | |
564 | ||
565 | /*! | |
566 | * Get icon resources | |
567 | */ | |
568 | ||
569 | wxIcon wxRichTextStyleOrganiserDialog::GetIconResource( const wxString& name ) | |
570 | { | |
571 | // Icon retrieval | |
572 | ////@begin wxRichTextStyleOrganiserDialog icon retrieval | |
573 | wxUnusedVar(name); | |
574 | return wxNullIcon; | |
575 | ////@end wxRichTextStyleOrganiserDialog icon retrieval | |
576 | } | |
577 | ||
578 | /*! | |
ce7fe42e | 579 | * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY |
dadd4f55 JS |
580 | */ |
581 | ||
582 | void wxRichTextStyleOrganiserDialog::OnApplyClick( wxCommandEvent& WXUNUSED(event) ) | |
583 | { | |
584 | ApplyStyle(); | |
585 | } | |
586 | ||
587 | /*! | |
588 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY | |
589 | */ | |
590 | ||
591 | void wxRichTextStyleOrganiserDialog::OnApplyUpdate( wxUpdateUIEvent& event ) | |
592 | { | |
593 | event.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_APPLY_STYLES) != 0) && m_stylesListBox->GetStyleListBox()->GetSelection() != wxNOT_FOUND); | |
594 | } | |
595 | ||
596 | ||
597 | /*! | |
ce7fe42e | 598 | * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR |
dadd4f55 JS |
599 | */ |
600 | ||
601 | void wxRichTextStyleOrganiserDialog::OnNewCharClick( wxCommandEvent& WXUNUSED(event) ) | |
602 | { | |
603 | wxString styleName = wxGetTextFromUser(_("Enter a character style name"), _("New Style")); | |
604 | if (!styleName.IsEmpty()) | |
605 | { | |
606 | if (GetStyleSheet()->FindCharacterStyle(styleName)) | |
607 | { | |
608 | wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); | |
609 | return; | |
610 | } | |
41a85215 | 611 | |
dadd4f55 | 612 | wxRichTextCharacterStyleDefinition* style = new wxRichTextCharacterStyleDefinition(styleName); |
41a85215 | 613 | |
dadd4f55 JS |
614 | int pages = wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_STYLE_EDITOR; |
615 | wxRichTextFormattingDialog formatDlg; | |
616 | formatDlg.SetStyleDefinition(*style, GetStyleSheet()); | |
617 | formatDlg.Create(pages, this); | |
618 | ||
619 | if (formatDlg.ShowModal() == wxID_OK) | |
620 | { | |
621 | wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextCharacterStyleDefinition); | |
41a85215 | 622 | |
dadd4f55 | 623 | (*((wxRichTextCharacterStyleDefinition* ) style)) = (*charDef); |
41a85215 | 624 | |
dadd4f55 JS |
625 | GetStyleSheet()->AddCharacterStyle(style); |
626 | ||
627 | m_stylesListBox->UpdateStyles(); | |
628 | ShowPreview(); | |
629 | } | |
630 | else | |
631 | delete style; | |
41a85215 | 632 | } |
dadd4f55 JS |
633 | } |
634 | ||
635 | /*! | |
636 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR | |
637 | */ | |
638 | ||
639 | void wxRichTextStyleOrganiserDialog::OnNewCharUpdate( wxUpdateUIEvent& event ) | |
640 | { | |
641 | event.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES) != 0); | |
642 | } | |
643 | ||
644 | ||
645 | /*! | |
ce7fe42e | 646 | * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA |
dadd4f55 JS |
647 | */ |
648 | ||
649 | void wxRichTextStyleOrganiserDialog::OnNewParaClick( wxCommandEvent& WXUNUSED(event) ) | |
650 | { | |
651 | wxString styleName = wxGetTextFromUser(_("Enter a paragraph style name"), _("New Style")); | |
652 | if (!styleName.IsEmpty()) | |
653 | { | |
654 | if (GetStyleSheet()->FindParagraphStyle(styleName)) | |
655 | { | |
656 | wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); | |
657 | return; | |
658 | } | |
41a85215 | 659 | |
dadd4f55 | 660 | wxRichTextParagraphStyleDefinition* style = new wxRichTextParagraphStyleDefinition(styleName); |
41a85215 | 661 | |
dadd4f55 JS |
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); | |
666 | ||
667 | if (formatDlg.ShowModal() == wxID_OK) | |
668 | { | |
669 | wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextParagraphStyleDefinition); | |
41a85215 | 670 | |
dadd4f55 | 671 | (*((wxRichTextParagraphStyleDefinition* ) style)) = (*paraDef); |
41a85215 | 672 | |
dadd4f55 JS |
673 | GetStyleSheet()->AddParagraphStyle(style); |
674 | ||
675 | m_stylesListBox->UpdateStyles(); | |
676 | ShowPreview(); | |
677 | } | |
678 | else | |
679 | delete style; | |
41a85215 | 680 | } |
dadd4f55 JS |
681 | } |
682 | ||
683 | /*! | |
684 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA | |
685 | */ | |
686 | ||
687 | void wxRichTextStyleOrganiserDialog::OnNewParaUpdate( wxUpdateUIEvent& event ) | |
688 | { | |
689 | event.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES) != 0); | |
690 | } | |
691 | ||
692 | ||
693 | /*! | |
ce7fe42e | 694 | * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT |
dadd4f55 JS |
695 | */ |
696 | ||
697 | void wxRichTextStyleOrganiserDialog::OnEditClick( wxCommandEvent& WXUNUSED(event) ) | |
698 | { | |
699 | int sel = m_stylesListBox->GetStyleListBox()->GetSelection(); | |
700 | if (sel != wxNOT_FOUND) | |
701 | { | |
702 | wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); | |
41a85215 | 703 | |
dadd4f55 | 704 | int pages = wxRICHTEXT_FORMAT_STYLE_EDITOR; |
41a85215 | 705 | |
345c78ca | 706 | if (wxDynamicCast(def, wxRichTextCharacterStyleDefinition)) |
dadd4f55 JS |
707 | { |
708 | pages |= wxRICHTEXT_FORMAT_FONT; | |
709 | } | |
345c78ca | 710 | else if (wxDynamicCast(def, wxRichTextListStyleDefinition)) |
dadd4f55 JS |
711 | { |
712 | pages |= wxRICHTEXT_FORMAT_LIST_STYLE|wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_INDENTS_SPACING; | |
713 | } | |
345c78ca | 714 | else if (wxDynamicCast(def, wxRichTextParagraphStyleDefinition)) |
dadd4f55 JS |
715 | { |
716 | pages |= wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_INDENTS_SPACING|wxRICHTEXT_FORMAT_TABS|wxRICHTEXT_FORMAT_BULLETS; | |
717 | } | |
345c78ca | 718 | else if (wxDynamicCast(def, wxRichTextBoxStyleDefinition)) |
cd720353 JS |
719 | { |
720 | pages |= wxRICHTEXT_FORMAT_MARGINS|wxRICHTEXT_FORMAT_SIZE|wxRICHTEXT_FORMAT_BORDERS|wxRICHTEXT_FORMAT_BACKGROUND; | |
721 | } | |
41a85215 | 722 | |
dadd4f55 JS |
723 | wxRichTextFormattingDialog formatDlg; |
724 | formatDlg.SetStyleDefinition(*def, GetStyleSheet()); | |
725 | formatDlg.Create(pages, this); | |
726 | ||
727 | if (formatDlg.ShowModal() == wxID_OK) | |
728 | { | |
729 | wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextParagraphStyleDefinition); | |
730 | wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextCharacterStyleDefinition); | |
731 | wxRichTextListStyleDefinition* listDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextListStyleDefinition); | |
cd720353 | 732 | wxRichTextBoxStyleDefinition* boxDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextBoxStyleDefinition); |
41a85215 | 733 | |
dadd4f55 JS |
734 | if (listDef) |
735 | { | |
736 | (*((wxRichTextListStyleDefinition* ) def)) = (*listDef); | |
737 | } | |
738 | else if (paraDef) | |
739 | { | |
740 | (*((wxRichTextParagraphStyleDefinition* ) def)) = (*paraDef); | |
741 | } | |
cd720353 JS |
742 | else if (boxDef) |
743 | { | |
744 | (*((wxRichTextBoxStyleDefinition* ) def)) = (*boxDef); | |
745 | } | |
dadd4f55 JS |
746 | else |
747 | { | |
748 | (*((wxRichTextCharacterStyleDefinition* ) def)) = (*charDef); | |
749 | } | |
750 | ||
751 | m_stylesListBox->UpdateStyles(); | |
e5cda2df | 752 | m_stylesListBox->GetStyleListBox()->SetSelection(sel); |
dadd4f55 JS |
753 | ShowPreview(); |
754 | } | |
755 | } | |
756 | } | |
757 | ||
758 | /*! | |
759 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT | |
760 | */ | |
761 | ||
762 | void wxRichTextStyleOrganiserDialog::OnEditUpdate( wxUpdateUIEvent& event ) | |
763 | { | |
764 | event.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_EDIT_STYLES) != 0) && m_stylesListBox->GetStyleListBox()->GetSelection() != wxNOT_FOUND); | |
765 | } | |
766 | ||
767 | ||
768 | /*! | |
ce7fe42e | 769 | * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE |
dadd4f55 JS |
770 | */ |
771 | ||
772 | void wxRichTextStyleOrganiserDialog::OnDeleteClick( wxCommandEvent& WXUNUSED(event) ) | |
773 | { | |
774 | int sel = m_stylesListBox->GetStyleListBox()->GetSelection(); | |
775 | if (sel != wxNOT_FOUND) | |
776 | { | |
777 | wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); | |
778 | wxString name(def->GetName()); | |
ad43a43f | 779 | if (wxYES == wxMessageBox(wxString::Format(_("Delete style %s?"), name), _("Delete Style"), wxYES_NO|wxICON_QUESTION, this)) |
dadd4f55 JS |
780 | { |
781 | m_stylesListBox->GetStyleListBox()->SetItemCount(0); | |
41a85215 | 782 | |
345c78ca | 783 | if (wxDynamicCast(def, wxRichTextListStyleDefinition)) |
dadd4f55 | 784 | GetStyleSheet()->RemoveListStyle((wxRichTextListStyleDefinition*) def, true); |
345c78ca | 785 | else if (wxDynamicCast(def, wxRichTextParagraphStyleDefinition)) |
dadd4f55 | 786 | GetStyleSheet()->RemoveParagraphStyle((wxRichTextParagraphStyleDefinition*) def, true); |
345c78ca | 787 | else if (wxDynamicCast(def, wxRichTextCharacterStyleDefinition)) |
dadd4f55 | 788 | GetStyleSheet()->RemoveCharacterStyle((wxRichTextCharacterStyleDefinition*) def, true); |
345c78ca | 789 | else if (wxDynamicCast(def, wxRichTextBoxStyleDefinition)) |
cd720353 | 790 | GetStyleSheet()->RemoveBoxStyle((wxRichTextBoxStyleDefinition*) def, true); |
41a85215 | 791 | |
dadd4f55 JS |
792 | m_stylesListBox->UpdateStyles(); |
793 | ||
794 | if (m_stylesListBox->GetStyleListBox()->GetSelection() != -1) | |
795 | ShowPreview(); | |
796 | else | |
797 | ClearPreview(); | |
798 | } | |
799 | } | |
800 | } | |
801 | ||
802 | /*! | |
803 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_DELETE | |
804 | */ | |
805 | ||
806 | void wxRichTextStyleOrganiserDialog::OnDeleteUpdate( wxUpdateUIEvent& event ) | |
807 | { | |
808 | event.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_DELETE_STYLES) != 0) && m_stylesListBox->GetStyleListBox()->GetSelection() != wxNOT_FOUND); | |
809 | } | |
810 | ||
811 | /*! | |
ce7fe42e | 812 | * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST |
dadd4f55 JS |
813 | */ |
814 | ||
815 | void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent& WXUNUSED(event) ) | |
816 | { | |
817 | wxString styleName = wxGetTextFromUser(_("Enter a list style name"), _("New Style")); | |
818 | if (!styleName.IsEmpty()) | |
819 | { | |
820 | if (GetStyleSheet()->FindListStyle(styleName)) | |
821 | { | |
822 | wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); | |
823 | return; | |
824 | } | |
41a85215 | 825 | |
dadd4f55 | 826 | wxRichTextListStyleDefinition* style = new wxRichTextListStyleDefinition(styleName); |
41a85215 | 827 | |
dadd4f55 JS |
828 | // Initialize the style to make it easier to edit |
829 | int i; | |
830 | for (i = 0; i < 10; i++) | |
831 | { | |
832 | wxString bulletSymbol; | |
833 | if (i == 0) | |
834 | bulletSymbol = wxT("*"); | |
835 | else if (i == 1) | |
836 | bulletSymbol = wxT("-"); | |
837 | else if (i == 2) | |
838 | bulletSymbol = wxT("*"); | |
839 | else if (i == 3) | |
840 | bulletSymbol = wxT("-"); | |
841 | else | |
842 | bulletSymbol = wxT("*"); | |
843 | ||
844 | style->SetAttributes(i, (i+1)*60, 60, wxTEXT_ATTR_BULLET_STYLE_SYMBOL, bulletSymbol); | |
845 | } | |
41a85215 | 846 | |
dadd4f55 JS |
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); | |
851 | ||
852 | if (formatDlg.ShowModal() == wxID_OK) | |
853 | { | |
854 | wxRichTextListStyleDefinition* listDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextListStyleDefinition); | |
41a85215 | 855 | |
dadd4f55 | 856 | (*((wxRichTextListStyleDefinition* ) style)) = (*listDef); |
41a85215 | 857 | |
dadd4f55 JS |
858 | GetStyleSheet()->AddListStyle(style); |
859 | ||
860 | m_stylesListBox->UpdateStyles(); | |
861 | ShowPreview(); | |
862 | } | |
863 | else | |
864 | delete style; | |
41a85215 | 865 | } |
dadd4f55 JS |
866 | } |
867 | ||
868 | /*! | |
869 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST | |
870 | */ | |
871 | ||
872 | void wxRichTextStyleOrganiserDialog::OnNewListUpdate( wxUpdateUIEvent& event ) | |
873 | { | |
874 | event.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES) != 0); | |
875 | } | |
876 | ||
877 | /*! | |
ce7fe42e | 878 | * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME |
dadd4f55 JS |
879 | */ |
880 | ||
881 | void wxRichTextStyleOrganiserDialog::OnRenameClick( wxCommandEvent& WXUNUSED(event) ) | |
882 | { | |
5bbdfd5b JS |
883 | int sel = m_stylesListBox->GetStyleListBox()->GetSelection(); |
884 | if (sel == -1) | |
885 | return; | |
886 | wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); | |
887 | if (!def) | |
888 | return; | |
889 | ||
890 | wxString styleName = wxGetTextFromUser(_("Enter a new style name"), _("New Style"), def->GetName()); | |
891 | if (!styleName.IsEmpty()) | |
892 | { | |
893 | if (styleName == def->GetName()) | |
894 | return; | |
895 | ||
cd720353 | 896 | if (GetStyleSheet()->FindParagraphStyle(styleName) || GetStyleSheet()->FindCharacterStyle(styleName) || GetStyleSheet()->FindListStyle(styleName) || GetStyleSheet()->FindBoxStyle(styleName)) |
5bbdfd5b JS |
897 | { |
898 | wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); | |
899 | return; | |
900 | } | |
901 | ||
902 | def->SetName(styleName); | |
903 | m_stylesListBox->UpdateStyles(); | |
904 | } | |
dadd4f55 JS |
905 | } |
906 | ||
907 | /*! | |
908 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME | |
909 | */ | |
910 | ||
911 | void wxRichTextStyleOrganiserDialog::OnRenameUpdate( wxUpdateUIEvent& event ) | |
912 | { | |
913 | event.Enable(((GetFlags() & wxRICHTEXT_ORGANISER_RENAME_STYLES) != 0) && m_stylesListBox->GetStyleListBox()->GetSelection() != wxNOT_FOUND); | |
914 | } | |
915 | ||
916 | /// List selection | |
917 | void wxRichTextStyleOrganiserDialog::OnListSelection(wxCommandEvent& event) | |
918 | { | |
919 | if (event.GetEventObject() == m_stylesListBox->GetStyleListBox()) | |
920 | ShowPreview(); | |
921 | else | |
922 | event.Skip(); | |
923 | } | |
5c6e84b6 | 924 | |
cd720353 | 925 | /*! |
ce7fe42e | 926 | * wxEVT_BUTTON event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX |
cd720353 JS |
927 | */ |
928 | ||
929 | void wxRichTextStyleOrganiserDialog::OnNewBoxClick( wxCommandEvent& WXUNUSED(event) ) | |
930 | { | |
931 | wxString styleName = wxGetTextFromUser(_("Enter a box style name"), _("New Style")); | |
932 | if (!styleName.IsEmpty()) | |
933 | { | |
934 | if (GetStyleSheet()->FindBoxStyle(styleName)) | |
935 | { | |
936 | wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); | |
937 | return; | |
938 | } | |
939 | ||
940 | wxRichTextBoxStyleDefinition* style = new wxRichTextBoxStyleDefinition(styleName); | |
941 | ||
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); | |
946 | ||
947 | if (formatDlg.ShowModal() == wxID_OK) | |
948 | { | |
949 | wxRichTextBoxStyleDefinition* boxDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextBoxStyleDefinition); | |
950 | ||
951 | (*((wxRichTextBoxStyleDefinition* ) style)) = (*boxDef); | |
952 | ||
953 | GetStyleSheet()->AddBoxStyle(style); | |
954 | ||
955 | m_stylesListBox->UpdateStyles(); | |
956 | ShowPreview(); | |
957 | } | |
958 | else | |
959 | delete style; | |
960 | } | |
961 | } | |
962 | ||
963 | /*! | |
964 | * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_BOX | |
965 | */ | |
966 | ||
967 | void wxRichTextStyleOrganiserDialog::OnNewBoxUpdate( wxUpdateUIEvent& event ) | |
968 | { | |
969 | event.Enable((GetFlags() & wxRICHTEXT_ORGANISER_CREATE_STYLES) != 0); | |
970 | } | |
971 | ||
3bb084c4 | 972 | /*! |
ce7fe42e | 973 | * wxEVT_BUTTON event handler for wxID_HELP |
3bb084c4 JS |
974 | */ |
975 | ||
976 | void wxRichTextStyleOrganiserDialog::OnHelpClick( wxCommandEvent& WXUNUSED(event) ) | |
977 | { | |
978 | if ((GetHelpId() != -1) && GetUICustomization()) | |
979 | ShowHelp(this); | |
980 | } | |
981 | ||
5c6e84b6 JS |
982 | #endif |
983 | // wxUSE_RICHTEXT |