]> git.saurik.com Git - wxWidgets.git/blob - src/richtext/richtextstyledlg.cpp
Overhaul IE zoom functions to support both text and optical zoom.
[wxWidgets.git] / src / richtext / richtextstyledlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextstyledlg.cpp
3 // Purpose:
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 10/5/2006 12:05:31 PM
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
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
19 #if wxUSE_RICHTEXT
20
21 #ifndef WX_PRECOMP
22 #include "wx/wx.h"
23 #endif
24
25 #include "wx/richtext/richtextstyledlg.h"
26 #include "wx/richtext/richtextformatdlg.h"
27
28 /*!
29 * wxRichTextStyleOrganiserDialog type definition
30 */
31
32 bool wxRichTextStyleOrganiserDialog::sm_showToolTips = false;
33
34 IMPLEMENT_DYNAMIC_CLASS( wxRichTextStyleOrganiserDialog, wxDialog )
35
36 /*!
37 * wxRichTextStyleOrganiserDialog event table definition
38 */
39
40 BEGIN_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
68 END_EVENT_TABLE()
69
70 IMPLEMENT_HELP_PROVISION(wxRichTextStyleOrganiserDialog)
71
72 /*!
73 * wxRichTextStyleOrganiserDialog constructors
74 */
75
76 wxRichTextStyleOrganiserDialog::wxRichTextStyleOrganiserDialog( )
77 {
78 Init();
79 }
80
81 wxRichTextStyleOrganiserDialog::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
91 void wxRichTextStyleOrganiserDialog::Init()
92 {
93 m_richTextStyleSheet = NULL;
94 m_richTextCtrl = NULL;
95 m_dontUpdate = false;
96 m_flags = 0;
97 m_restartNumbering = true;
98
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;
115 m_stdButtonSizer = NULL;
116 m_okButton = NULL;
117 m_cancelButton = NULL;
118 ////@end wxRichTextStyleOrganiserDialog member initialisation
119 }
120
121 /*!
122 * wxRichTextStyleOrganiserDialog creator
123 */
124
125 bool 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;
130
131 ////@begin wxRichTextStyleOrganiserDialog creation
132 SetExtraStyle(wxWS_EX_BLOCK_EVENTS|wxDIALOG_EX_CONTEXTHELP);
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
149 void wxRichTextStyleOrganiserDialog::CreateControls()
150 {
151 bool hideTypeSelector = false;
152 wxRichTextStyleListBox::wxRichTextStyleType typesToShow = wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL;
153
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 }
173
174 long listCtrlStyle = 0;
175 if (hideTypeSelector)
176 listCtrlStyle = wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR;
177
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 );
194 itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
195
196 m_stylesListBox = new wxRichTextStyleListCtrl( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_STYLES, wxDefaultPosition, wxSize(280, 260), listCtrlStyle );
197 m_stylesListBox->SetHelpText(_("The available styles."));
198 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
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
205 wxStaticText* itemStaticText9 = new wxStaticText( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE, _(" "), wxDefaultPosition, wxDefaultSize, 0 );
206 itemBoxSizer8->Add(itemStaticText9, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
207
208 m_previewCtrl = new wxRichTextCtrl( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_PREVIEW, wxEmptyString, wxDefaultPosition, wxSize(250, 200), wxVSCROLL|wxTE_READONLY );
209 m_previewCtrl->SetHelpText(_("The style preview."));
210 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
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 );
218 m_buttonSizer->Add(itemStaticText12, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
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."));
222 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
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."));
228 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
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."));
234 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
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."));
242 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
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."));
248 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
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."));
254 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
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."));
260 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
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."));
269 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
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."));
279 if (wxRichTextStyleOrganiserDialog::ShowToolTips())
280 m_restartNumberingCtrl->SetToolTip(_("Check to restart numbering."));
281 m_bottomButtonSizer->Add(m_restartNumberingCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
282
283 m_stdButtonSizer = new wxStdDialogButtonSizer;
284
285 m_bottomButtonSizer->Add(m_stdButtonSizer, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
286 m_okButton = new wxButton( itemDialog1, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
287 m_stdButtonSizer->AddButton(m_okButton);
288
289 m_cancelButton = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
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();
296
297 ////@end wxRichTextStyleOrganiserDialog content construction
298
299 if (GetHelpId() == -1)
300 {
301 wxWindow* button = FindWindowById(wxID_HELP);
302 if (button)
303 m_stdButtonSizer->Show(button, false);
304 }
305
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 {
335 m_stdButtonSizer->Show(m_okButton, false);
336 m_stdButtonSizer->Show(m_cancelButton, false);
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 }
348
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 }
354
355 if (hideTypeSelector)
356 {
357 m_stylesListBox->GetStyleListBox()->SetStyleType(typesToShow);
358 }
359
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
376 wxString wxRichTextStyleOrganiserDialog::GetSelectedStyle() const
377 {
378 wxRichTextStyleDefinition* def = GetSelectedStyleDefinition();
379 if (def)
380 return def->GetName();
381 else
382 return wxEmptyString;
383 }
384
385 wxRichTextStyleDefinition* 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
393 bool wxRichTextStyleOrganiserDialog::TransferDataFromWindow()
394 {
395 if (!wxDialog::TransferDataFromWindow())
396 return false;
397
398 m_restartNumbering = m_restartNumberingCtrl->GetValue();
399
400 return true;
401 }
402
403 bool wxRichTextStyleOrganiserDialog::TransferDataToWindow()
404 {
405 if (!wxDialog::TransferDataToWindow())
406 return false;
407
408 m_restartNumberingCtrl->SetValue(m_restartNumbering);
409
410 return true;
411 }
412
413 /// Show preview for given or selected preview
414 void wxRichTextStyleOrganiserDialog::ShowPreview(int sel)
415 {
416 static const wxChar* s_para1 = wxT("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
417 Nullam ante sapien, vestibulum nonummy, pulvinar sed, luctus ut, lacus.\n");
418
419 static const wxChar* s_para2List = wxT("Duis pharetra consequat dui. Nullam vitae justo id mauris lobortis interdum.\n");
420
421 static const wxChar* s_para2 = wxT("Duis pharetra consequat dui. Cum sociis natoque penatibus \
422 et magnis dis parturient montes, nascetur ridiculus mus. Nullam vitae justo id mauris lobortis interdum.\n");
423
424 static const wxChar* s_para3 = wxT("Integer convallis dolor at augue \
425 iaculis 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)
431 return;
432 }
433
434 wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel);
435
436 wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition);
437
438 wxStaticText* labelCtrl = (wxStaticText*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE);
439 if (labelCtrl)
440 labelCtrl->SetLabel(def->GetName() + wxT(":"));
441
442 wxRichTextAttr attr(def->GetStyleMergedWithBase(GetStyleSheet()));
443
444 wxFont font(m_previewCtrl->GetFont());
445 font.SetPointSize(9);
446 m_previewCtrl->SetFont(font);
447
448 wxRichTextAttr normalParaAttr;
449 normalParaAttr.SetFont(font);
450 normalParaAttr.SetTextColour(wxColour(wxT("LIGHT GREY")));
451
452 m_previewCtrl->Freeze();
453 m_previewCtrl->Clear();
454
455 m_previewCtrl->BeginStyle(normalParaAttr);
456 m_previewCtrl->WriteText(s_para1);
457 m_previewCtrl->EndStyle();
458
459 m_previewCtrl->BeginStyle(attr);
460
461 if (listDef)
462 {
463 long listStart = m_previewCtrl->GetInsertionPoint() + 1;
464 int i;
465 for (i = 0; i < 10; i++)
466 {
467 wxRichTextAttr levelAttr = * listDef->GetLevelAttributes(i);
468 levelAttr.SetBulletNumber(1);
469 m_previewCtrl->BeginStyle(levelAttr);
470 m_previewCtrl->WriteText(wxString::Format(wxT("List level %d. "), i+1) + s_para2List);
471 m_previewCtrl->EndStyle();
472 }
473 long listEnd = m_previewCtrl->GetInsertionPoint();
474 m_previewCtrl->NumberList(wxRichTextRange(listStart, listEnd), listDef);
475 }
476 else
477 {
478 m_previewCtrl->WriteText(s_para2);
479 }
480
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 }
489
490 /// Clears the preview
491 void wxRichTextStyleOrganiserDialog::ClearPreview()
492 {
493 m_previewCtrl->Clear();
494 wxStaticText* labelCtrl = (wxStaticText*) FindWindow(ID_RICHTEXTSTYLEORGANISERDIALOG_CURRENT_STYLE);
495 if (labelCtrl)
496 labelCtrl->SetLabel(wxEmptyString);
497 }
498
499 bool 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;
510
511
512 wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel);
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
530 wxBitmap 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
543 wxIcon 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
556 void wxRichTextStyleOrganiserDialog::OnApplyClick( wxCommandEvent& WXUNUSED(event) )
557 {
558 ApplyStyle();
559 }
560
561 /*!
562 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_APPLY
563 */
564
565 void 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
575 void 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 }
585
586 wxRichTextCharacterStyleDefinition* style = new wxRichTextCharacterStyleDefinition(styleName);
587
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);
596
597 (*((wxRichTextCharacterStyleDefinition* ) style)) = (*charDef);
598
599 GetStyleSheet()->AddCharacterStyle(style);
600
601 m_stylesListBox->UpdateStyles();
602 ShowPreview();
603 }
604 else
605 delete style;
606 }
607 }
608
609 /*!
610 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR
611 */
612
613 void 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
623 void 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 }
633
634 wxRichTextParagraphStyleDefinition* style = new wxRichTextParagraphStyleDefinition(styleName);
635
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);
644
645 (*((wxRichTextParagraphStyleDefinition* ) style)) = (*paraDef);
646
647 GetStyleSheet()->AddParagraphStyle(style);
648
649 m_stylesListBox->UpdateStyles();
650 ShowPreview();
651 }
652 else
653 delete style;
654 }
655 }
656
657 /*!
658 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_PARA
659 */
660
661 void 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
671 void 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);
677
678 int pages = wxRICHTEXT_FORMAT_STYLE_EDITOR;
679
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 }
692
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);
702
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();
717 m_stylesListBox->GetStyleListBox()->SetSelection(sel);
718 ShowPreview();
719 }
720 }
721 }
722
723 /*!
724 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_EDIT
725 */
726
727 void 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
737 void 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());
744 if (wxYES == wxMessageBox(wxString::Format(_("Delete style %s?"), name), _("Delete Style"), wxYES_NO|wxICON_QUESTION, this))
745 {
746 m_stylesListBox->GetStyleListBox()->SetItemCount(0);
747
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);
754
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
769 void 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
778 void 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 }
788
789 wxRichTextListStyleDefinition* style = new wxRichTextListStyleDefinition(styleName);
790
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 }
809
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);
818
819 (*((wxRichTextListStyleDefinition* ) style)) = (*listDef);
820
821 GetStyleSheet()->AddListStyle(style);
822
823 m_stylesListBox->UpdateStyles();
824 ShowPreview();
825 }
826 else
827 delete style;
828 }
829 }
830
831 /*!
832 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_LIST
833 */
834
835 void 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
844 void wxRichTextStyleOrganiserDialog::OnRenameClick( wxCommandEvent& WXUNUSED(event) )
845 {
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 }
868 }
869
870 /*!
871 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEORGANISERDIALOG_RENAME
872 */
873
874 void 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
880 void wxRichTextStyleOrganiserDialog::OnListSelection(wxCommandEvent& event)
881 {
882 if (event.GetEventObject() == m_stylesListBox->GetStyleListBox())
883 ShowPreview();
884 else
885 event.Skip();
886 }
887
888 #endif
889 // wxUSE_RICHTEXT
890