]> git.saurik.com Git - wxWidgets.git/blame - src/richtext/richtextstylepage.cpp
Add missing WXK constants for the control keys
[wxWidgets.git] / src / richtext / richtextstylepage.cpp
CommitLineData
97ff49b3 1/////////////////////////////////////////////////////////////////////////////
b68603d5 2// Name: src/richtext/richtextstylepage.cpp
5778b3c8 3// Purpose:
97ff49b3 4// Author: Julian Smart
5778b3c8 5// Modified by:
97ff49b3 6// Created: 10/5/2006 11:34:55 AM
b68603d5 7// RCS-ID: $Id$
97ff49b3 8// Copyright: (c) Julian Smart
b68603d5 9// Licence: wxWindows licence
97ff49b3
JS
10/////////////////////////////////////////////////////////////////////////////
11
b68603d5
WS
12#if wxUSE_RICHTEXT
13
14#include "wx/richtext/richtextstylepage.h"
15
97ff49b3
JS
16/*!
17 * wxRichTextStylePage type definition
18 */
19
603f702b 20IMPLEMENT_DYNAMIC_CLASS( wxRichTextStylePage, wxRichTextDialogPage )
97ff49b3
JS
21
22/*!
23 * wxRichTextStylePage event table definition
24 */
25
603f702b 26BEGIN_EVENT_TABLE( wxRichTextStylePage, wxRichTextDialogPage )
97ff49b3
JS
27
28////@begin wxRichTextStylePage event table entries
29 EVT_UPDATE_UI( ID_RICHTEXTSTYLEPAGE_NEXT_STYLE, wxRichTextStylePage::OnNextStyleUpdate )
30
31////@end wxRichTextStylePage event table entries
32
33END_EVENT_TABLE()
34
603f702b
JS
35IMPLEMENT_HELP_PROVISION(wxRichTextStylePage)
36
97ff49b3
JS
37/*!
38 * wxRichTextStylePage constructors
39 */
40
41wxRichTextStylePage::wxRichTextStylePage( )
42{
43 Init();
44}
45
46wxRichTextStylePage::wxRichTextStylePage( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
47{
48 Init();
49 Create(parent, id, pos, size, style);
50}
51
52/*!
53 * Initialise members
54 */
5778b3c8 55
97ff49b3
JS
56void wxRichTextStylePage::Init()
57{
58////@begin wxRichTextStylePage member initialisation
59 m_styleName = NULL;
60 m_basedOn = NULL;
61 m_nextStyle = NULL;
62////@end wxRichTextStylePage member initialisation
63}
64
65/*!
66 * wxRichTextStylePage creator
67 */
68
69bool wxRichTextStylePage::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
70{
71////@begin wxRichTextStylePage creation
603f702b 72 wxRichTextDialogPage::Create( parent, id, pos, size, style );
97ff49b3
JS
73
74 CreateControls();
75 if (GetSizer())
76 {
77 GetSizer()->SetSizeHints(this);
78 }
79 Centre();
80////@end wxRichTextStylePage creation
81 return true;
82}
83
84/*!
85 * Control creation for wxRichTextStylePage
86 */
87
88void wxRichTextStylePage::CreateControls()
5778b3c8 89{
97ff49b3 90////@begin wxRichTextStylePage content construction
603f702b 91 wxRichTextStylePage* itemRichTextDialogPage1 = this;
97ff49b3
JS
92
93 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
603f702b 94 itemRichTextDialogPage1->SetSizer(itemBoxSizer2);
97ff49b3
JS
95
96 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
97 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
98
99 wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
603f702b 100 itemBoxSizer3->Add(itemBoxSizer4, 0, wxGROW, 5);
97ff49b3
JS
101
102 wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
603f702b 103 itemBoxSizer4->Add(itemBoxSizer5, 1, wxGROW, 5);
97ff49b3 104
603f702b 105 wxStaticText* itemStaticText6 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Style:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 106 itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3 107
603f702b 108 m_styleName = new wxTextCtrl( itemRichTextDialogPage1, ID_RICHTEXTSTYLEPAGE_STYLE_NAME, wxEmptyString, wxDefaultPosition, wxSize(300, -1), wxTE_READONLY );
dadd4f55 109 m_styleName->SetHelpText(_("The style name."));
c187b472 110 if (wxRichTextStylePage::ShowToolTips())
dadd4f55 111 m_styleName->SetToolTip(_("The style name."));
97ff49b3
JS
112 itemBoxSizer5->Add(m_styleName, 0, wxGROW|wxALL, 5);
113
603f702b 114 wxStaticText* itemStaticText8 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Based on:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 115 itemBoxSizer5->Add(itemStaticText8, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3 116
c187b472 117 wxArrayString m_basedOnStrings;
603f702b 118 m_basedOn = new wxComboBox( itemRichTextDialogPage1, ID_RICHTEXTSTYLEPAGE_BASED_ON, wxEmptyString, wxDefaultPosition, wxSize(300, -1), m_basedOnStrings, wxCB_DROPDOWN );
dadd4f55 119 m_basedOn->SetHelpText(_("The style on which this style is based."));
c187b472 120 if (wxRichTextStylePage::ShowToolTips())
dadd4f55 121 m_basedOn->SetToolTip(_("The style on which this style is based."));
97ff49b3
JS
122 itemBoxSizer5->Add(m_basedOn, 0, wxGROW|wxALL, 5);
123
603f702b 124 wxStaticText* itemStaticText10 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Next style:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 125 itemBoxSizer5->Add(itemStaticText10, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
97ff49b3 126
c187b472 127 wxArrayString m_nextStyleStrings;
603f702b 128 m_nextStyle = new wxComboBox( itemRichTextDialogPage1, ID_RICHTEXTSTYLEPAGE_NEXT_STYLE, wxEmptyString, wxDefaultPosition, wxSize(300, -1), m_nextStyleStrings, wxCB_DROPDOWN );
dadd4f55 129 m_nextStyle->SetHelpText(_("The default style for the next paragraph."));
c187b472 130 if (wxRichTextStylePage::ShowToolTips())
dadd4f55 131 m_nextStyle->SetToolTip(_("The default style for the next paragraph."));
97ff49b3
JS
132 itemBoxSizer5->Add(m_nextStyle, 0, wxGROW|wxALL, 5);
133
134 itemBoxSizer3->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
135
136////@end wxRichTextStylePage content construction
137}
138
139/// Transfer data from/to window
140bool wxRichTextStylePage::TransferDataFromWindow()
141{
142 wxPanel::TransferDataFromWindow();
143
144 wxRichTextStyleDefinition* def = wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
dadd4f55
JS
145 if (def)
146 {
147 wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
148 if (paraDef)
149 paraDef->SetNextStyle(m_nextStyle->GetValue());
41a85215 150
dadd4f55
JS
151 def->SetName(m_styleName->GetValue());
152 def->SetBaseStyle(m_basedOn->GetValue());
153 }
97ff49b3
JS
154
155 return true;
156}
157
158bool wxRichTextStylePage::TransferDataToWindow()
159{
160 wxPanel::TransferDataToWindow();
5a376169 161
97ff49b3 162 wxRichTextStyleDefinition* def = wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
dadd4f55 163 if (def)
97ff49b3 164 {
603f702b
JS
165 m_basedOn->Freeze();
166 m_nextStyle->Freeze();
167
dadd4f55
JS
168 wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
169 wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition);
603f702b 170 wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition);
dadd4f55 171 wxRichTextStyleSheet* sheet = wxRichTextFormattingDialog::GetDialog(this)->GetStyleSheet();
603f702b 172 wxRichTextBoxStyleDefinition* boxDef = wxDynamicCast(def, wxRichTextBoxStyleDefinition);
41a85215 173
dadd4f55 174 m_styleName->SetValue(def->GetName());
41a85215 175
dadd4f55 176 if (listDef)
97ff49b3 177 {
dadd4f55 178 if (m_nextStyle->GetCount() == 0)
97ff49b3 179 {
dadd4f55 180 if (sheet)
97ff49b3 181 {
dadd4f55
JS
182 size_t i;
183 for (i = 0; i < sheet->GetListStyleCount(); i++)
184 {
185 wxRichTextListStyleDefinition* p = wxDynamicCast(sheet->GetListStyle(i), wxRichTextListStyleDefinition);
186 if (p)
187 m_nextStyle->Append(p->GetName());
188 }
97ff49b3
JS
189 }
190 }
dadd4f55 191 m_nextStyle->SetValue(listDef->GetNextStyle());
97ff49b3 192 }
dadd4f55 193 else if (paraDef)
97ff49b3 194 {
dadd4f55 195 if (m_nextStyle->GetCount() == 0)
97ff49b3 196 {
dadd4f55 197 if (sheet)
97ff49b3 198 {
dadd4f55
JS
199 size_t i;
200 for (i = 0; i < sheet->GetParagraphStyleCount(); i++)
201 {
202 wxRichTextParagraphStyleDefinition* p = wxDynamicCast(sheet->GetParagraphStyle(i), wxRichTextParagraphStyleDefinition);
203 if (p)
204 m_nextStyle->Append(p->GetName());
205 }
97ff49b3
JS
206 }
207 }
dadd4f55
JS
208 m_nextStyle->SetValue(paraDef->GetNextStyle());
209 }
41a85215 210
dadd4f55
JS
211 if (m_basedOn->GetCount() == 0)
212 {
213 if (sheet)
97ff49b3 214 {
dadd4f55
JS
215 if (listDef)
216 {
217 size_t i;
218 for (i = 0; i < sheet->GetListStyleCount(); i++)
219 {
220 wxRichTextListStyleDefinition* p = wxDynamicCast(sheet->GetListStyle(i), wxRichTextListStyleDefinition);
221 if (p)
222 m_basedOn->Append(p->GetName());
223 }
224 }
225 else if (paraDef)
97ff49b3 226 {
dadd4f55
JS
227 size_t i;
228 for (i = 0; i < sheet->GetParagraphStyleCount(); i++)
229 {
230 wxRichTextParagraphStyleDefinition* p = wxDynamicCast(sheet->GetParagraphStyle(i), wxRichTextParagraphStyleDefinition);
231 if (p)
232 m_basedOn->Append(p->GetName());
233 }
234 }
603f702b
JS
235 else if (boxDef)
236 {
237 size_t i;
238 for (i = 0; i < sheet->GetBoxStyleCount(); i++)
239 {
240 wxRichTextBoxStyleDefinition* p = wxDynamicCast(sheet->GetBoxStyle(i), wxRichTextBoxStyleDefinition);
241 if (p)
242 m_basedOn->Append(p->GetName());
243 }
244 }
245 else if (charDef)
dadd4f55
JS
246 {
247 size_t i;
248 for (i = 0; i < sheet->GetCharacterStyleCount(); i++)
249 {
250 wxRichTextCharacterStyleDefinition* p = wxDynamicCast(sheet->GetCharacterStyle(i), wxRichTextCharacterStyleDefinition);
251 if (p)
252 m_basedOn->Append(p->GetName());
253 }
97ff49b3
JS
254 }
255 }
256 }
41a85215 257
dadd4f55 258 m_basedOn->SetValue(def->GetBaseStyle());
603f702b
JS
259
260 m_nextStyle->Thaw();
261 m_basedOn->Thaw();
97ff49b3 262 }
5778b3c8 263
97ff49b3
JS
264 return true;
265}
266
24777478 267wxRichTextAttr* wxRichTextStylePage::GetAttributes()
97ff49b3
JS
268{
269 return wxRichTextFormattingDialog::GetDialogAttributes(this);
270}
271
272/*!
273 * Should we show tooltips?
274 */
275
276bool wxRichTextStylePage::ShowToolTips()
277{
dadd4f55 278 return wxRichTextFormattingDialog::ShowToolTips();
97ff49b3
JS
279}
280
281/*!
282 * Get bitmap resources
283 */
284
285wxBitmap wxRichTextStylePage::GetBitmapResource( const wxString& name )
286{
287 // Bitmap retrieval
288////@begin wxRichTextStylePage bitmap retrieval
289 wxUnusedVar(name);
290 return wxNullBitmap;
291////@end wxRichTextStylePage bitmap retrieval
292}
293
294/*!
295 * Get icon resources
296 */
297
298wxIcon wxRichTextStylePage::GetIconResource( const wxString& name )
299{
300 // Icon retrieval
301////@begin wxRichTextStylePage icon retrieval
302 wxUnusedVar(name);
303 return wxNullIcon;
304////@end wxRichTextStylePage icon retrieval
305}
306/*!
307 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEPAGE_NEXT_STYLE
308 */
309
310void wxRichTextStylePage::OnNextStyleUpdate( wxUpdateUIEvent& event )
311{
312 wxRichTextStyleDefinition* def = wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
568fb7e9 313 event.Enable(wxDynamicCast(def, wxRichTextParagraphStyleDefinition) != NULL);
97ff49b3 314}
b68603d5
WS
315
316#endif // wxUSE_RICHTEXT