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