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