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