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