]> git.saurik.com Git - wxWidgets.git/blob - src/richtext/richtextstylepage.cpp
Fix last count value after ReadAll() and WriteAll().
[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, wxRichTextDialogPage )
21
22 /*!
23 * wxRichTextStylePage event table definition
24 */
25
26 BEGIN_EVENT_TABLE( wxRichTextStylePage, wxRichTextDialogPage )
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 IMPLEMENT_HELP_PROVISION(wxRichTextStylePage)
36
37 /*!
38 * wxRichTextStylePage constructors
39 */
40
41 wxRichTextStylePage::wxRichTextStylePage( )
42 {
43 Init();
44 }
45
46 wxRichTextStylePage::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 */
55
56 void 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
69 bool wxRichTextStylePage::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
70 {
71 ////@begin wxRichTextStylePage creation
72 wxRichTextDialogPage::Create( parent, id, pos, size, style );
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
88 void wxRichTextStylePage::CreateControls()
89 {
90 ////@begin wxRichTextStylePage content construction
91 wxRichTextStylePage* itemRichTextDialogPage1 = this;
92
93 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
94 itemRichTextDialogPage1->SetSizer(itemBoxSizer2);
95
96 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
97 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
98
99 wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
100 itemBoxSizer3->Add(itemBoxSizer4, 0, wxGROW, 5);
101
102 wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
103 itemBoxSizer4->Add(itemBoxSizer5, 1, wxGROW, 5);
104
105 wxStaticText* itemStaticText6 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Style:"), wxDefaultPosition, wxDefaultSize, 0 );
106 itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
107
108 m_styleName = new wxTextCtrl( itemRichTextDialogPage1, ID_RICHTEXTSTYLEPAGE_STYLE_NAME, wxEmptyString, wxDefaultPosition, wxSize(300, -1), wxTE_READONLY );
109 m_styleName->SetHelpText(_("The style name."));
110 if (wxRichTextStylePage::ShowToolTips())
111 m_styleName->SetToolTip(_("The style name."));
112 itemBoxSizer5->Add(m_styleName, 0, wxGROW|wxALL, 5);
113
114 wxStaticText* itemStaticText8 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Based on:"), wxDefaultPosition, wxDefaultSize, 0 );
115 itemBoxSizer5->Add(itemStaticText8, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
116
117 wxArrayString m_basedOnStrings;
118 m_basedOn = new wxComboBox( itemRichTextDialogPage1, ID_RICHTEXTSTYLEPAGE_BASED_ON, wxEmptyString, wxDefaultPosition, wxSize(300, -1), m_basedOnStrings, wxCB_DROPDOWN );
119 m_basedOn->SetHelpText(_("The style on which this style is based."));
120 if (wxRichTextStylePage::ShowToolTips())
121 m_basedOn->SetToolTip(_("The style on which this style is based."));
122 itemBoxSizer5->Add(m_basedOn, 0, wxGROW|wxALL, 5);
123
124 wxStaticText* itemStaticText10 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Next style:"), wxDefaultPosition, wxDefaultSize, 0 );
125 itemBoxSizer5->Add(itemStaticText10, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
126
127 wxArrayString m_nextStyleStrings;
128 m_nextStyle = new wxComboBox( itemRichTextDialogPage1, ID_RICHTEXTSTYLEPAGE_NEXT_STYLE, wxEmptyString, wxDefaultPosition, wxSize(300, -1), m_nextStyleStrings, wxCB_DROPDOWN );
129 m_nextStyle->SetHelpText(_("The default style for the next paragraph."));
130 if (wxRichTextStylePage::ShowToolTips())
131 m_nextStyle->SetToolTip(_("The default style for the next paragraph."));
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
140 bool wxRichTextStylePage::TransferDataFromWindow()
141 {
142 wxPanel::TransferDataFromWindow();
143
144 wxRichTextStyleDefinition* def = wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
145 if (def)
146 {
147 wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
148 if (paraDef)
149 paraDef->SetNextStyle(m_nextStyle->GetValue());
150
151 def->SetName(m_styleName->GetValue());
152 def->SetBaseStyle(m_basedOn->GetValue());
153 }
154
155 return true;
156 }
157
158 bool wxRichTextStylePage::TransferDataToWindow()
159 {
160 wxPanel::TransferDataToWindow();
161
162 wxRichTextStyleDefinition* def = wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
163 if (def)
164 {
165 m_basedOn->Freeze();
166 m_nextStyle->Freeze();
167
168 wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
169 wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition);
170 wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition);
171 wxRichTextStyleSheet* sheet = wxRichTextFormattingDialog::GetDialog(this)->GetStyleSheet();
172 wxRichTextBoxStyleDefinition* boxDef = wxDynamicCast(def, wxRichTextBoxStyleDefinition);
173
174 m_styleName->SetValue(def->GetName());
175
176 if (listDef)
177 {
178 if (m_nextStyle->GetCount() == 0)
179 {
180 if (sheet)
181 {
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 }
189 }
190 }
191 m_nextStyle->SetValue(listDef->GetNextStyle());
192 }
193 else if (paraDef)
194 {
195 if (m_nextStyle->GetCount() == 0)
196 {
197 if (sheet)
198 {
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 }
206 }
207 }
208 m_nextStyle->SetValue(paraDef->GetNextStyle());
209 }
210
211 if (m_basedOn->GetCount() == 0)
212 {
213 if (sheet)
214 {
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)
226 {
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 }
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)
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 }
254 }
255 }
256 }
257
258 m_basedOn->SetValue(def->GetBaseStyle());
259
260 m_nextStyle->Thaw();
261 m_basedOn->Thaw();
262 }
263
264 return true;
265 }
266
267 wxRichTextAttr* wxRichTextStylePage::GetAttributes()
268 {
269 return wxRichTextFormattingDialog::GetDialogAttributes(this);
270 }
271
272 /*!
273 * Should we show tooltips?
274 */
275
276 bool wxRichTextStylePage::ShowToolTips()
277 {
278 return wxRichTextFormattingDialog::ShowToolTips();
279 }
280
281 /*!
282 * Get bitmap resources
283 */
284
285 wxBitmap 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
298 wxIcon 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
310 void wxRichTextStylePage::OnNextStyleUpdate( wxUpdateUIEvent& event )
311 {
312 wxRichTextStyleDefinition* def = wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
313 event.Enable(wxDynamicCast(def, wxRichTextParagraphStyleDefinition) != NULL);
314 }
315
316 #endif // wxUSE_RICHTEXT