]>
Commit | Line | Data |
---|---|---|
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 |
97ff49b3 | 7 | // Copyright: (c) Julian Smart |
b68603d5 | 8 | // Licence: wxWindows licence |
97ff49b3 JS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
b68603d5 WS |
11 | #if wxUSE_RICHTEXT |
12 | ||
13 | #include "wx/richtext/richtextstylepage.h" | |
14 | ||
97ff49b3 JS |
15 | /*! |
16 | * wxRichTextStylePage type definition | |
17 | */ | |
18 | ||
603f702b | 19 | IMPLEMENT_DYNAMIC_CLASS( wxRichTextStylePage, wxRichTextDialogPage ) |
97ff49b3 JS |
20 | |
21 | /*! | |
22 | * wxRichTextStylePage event table definition | |
23 | */ | |
24 | ||
603f702b | 25 | BEGIN_EVENT_TABLE( wxRichTextStylePage, wxRichTextDialogPage ) |
97ff49b3 JS |
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 | ||
603f702b JS |
34 | IMPLEMENT_HELP_PROVISION(wxRichTextStylePage) |
35 | ||
97ff49b3 JS |
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 | */ | |
5778b3c8 | 54 | |
97ff49b3 JS |
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 | |
603f702b | 71 | wxRichTextDialogPage::Create( parent, id, pos, size, style ); |
97ff49b3 JS |
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() | |
5778b3c8 | 88 | { |
97ff49b3 | 89 | ////@begin wxRichTextStylePage content construction |
603f702b | 90 | wxRichTextStylePage* itemRichTextDialogPage1 = this; |
97ff49b3 JS |
91 | |
92 | wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); | |
603f702b | 93 | itemRichTextDialogPage1->SetSizer(itemBoxSizer2); |
97ff49b3 JS |
94 | |
95 | wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL); | |
96 | itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5); | |
97 | ||
98 | wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL); | |
603f702b | 99 | itemBoxSizer3->Add(itemBoxSizer4, 0, wxGROW, 5); |
97ff49b3 JS |
100 | |
101 | wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL); | |
603f702b | 102 | itemBoxSizer4->Add(itemBoxSizer5, 1, wxGROW, 5); |
97ff49b3 | 103 | |
603f702b | 104 | wxStaticText* itemStaticText6 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Style:"), wxDefaultPosition, wxDefaultSize, 0 ); |
69ce77e2 | 105 | itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
97ff49b3 | 106 | |
603f702b | 107 | m_styleName = new wxTextCtrl( itemRichTextDialogPage1, ID_RICHTEXTSTYLEPAGE_STYLE_NAME, wxEmptyString, wxDefaultPosition, wxSize(300, -1), wxTE_READONLY ); |
dadd4f55 | 108 | m_styleName->SetHelpText(_("The style name.")); |
c187b472 | 109 | if (wxRichTextStylePage::ShowToolTips()) |
dadd4f55 | 110 | m_styleName->SetToolTip(_("The style name.")); |
97ff49b3 JS |
111 | itemBoxSizer5->Add(m_styleName, 0, wxGROW|wxALL, 5); |
112 | ||
603f702b | 113 | wxStaticText* itemStaticText8 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Based on:"), wxDefaultPosition, wxDefaultSize, 0 ); |
69ce77e2 | 114 | itemBoxSizer5->Add(itemStaticText8, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
97ff49b3 | 115 | |
c187b472 | 116 | wxArrayString m_basedOnStrings; |
603f702b | 117 | m_basedOn = new wxComboBox( itemRichTextDialogPage1, ID_RICHTEXTSTYLEPAGE_BASED_ON, wxEmptyString, wxDefaultPosition, wxSize(300, -1), m_basedOnStrings, wxCB_DROPDOWN ); |
dadd4f55 | 118 | m_basedOn->SetHelpText(_("The style on which this style is based.")); |
c187b472 | 119 | if (wxRichTextStylePage::ShowToolTips()) |
dadd4f55 | 120 | m_basedOn->SetToolTip(_("The style on which this style is based.")); |
97ff49b3 JS |
121 | itemBoxSizer5->Add(m_basedOn, 0, wxGROW|wxALL, 5); |
122 | ||
603f702b | 123 | wxStaticText* itemStaticText10 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("&Next style:"), wxDefaultPosition, wxDefaultSize, 0 ); |
69ce77e2 | 124 | itemBoxSizer5->Add(itemStaticText10, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
97ff49b3 | 125 | |
c187b472 | 126 | wxArrayString m_nextStyleStrings; |
603f702b | 127 | m_nextStyle = new wxComboBox( itemRichTextDialogPage1, ID_RICHTEXTSTYLEPAGE_NEXT_STYLE, wxEmptyString, wxDefaultPosition, wxSize(300, -1), m_nextStyleStrings, wxCB_DROPDOWN ); |
dadd4f55 | 128 | m_nextStyle->SetHelpText(_("The default style for the next paragraph.")); |
c187b472 | 129 | if (wxRichTextStylePage::ShowToolTips()) |
dadd4f55 | 130 | m_nextStyle->SetToolTip(_("The default style for the next paragraph.")); |
97ff49b3 JS |
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); | |
dadd4f55 JS |
144 | if (def) |
145 | { | |
146 | wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition); | |
147 | if (paraDef) | |
148 | paraDef->SetNextStyle(m_nextStyle->GetValue()); | |
41a85215 | 149 | |
dadd4f55 JS |
150 | def->SetName(m_styleName->GetValue()); |
151 | def->SetBaseStyle(m_basedOn->GetValue()); | |
152 | } | |
97ff49b3 JS |
153 | |
154 | return true; | |
155 | } | |
156 | ||
157 | bool wxRichTextStylePage::TransferDataToWindow() | |
158 | { | |
159 | wxPanel::TransferDataToWindow(); | |
5a376169 | 160 | |
97ff49b3 | 161 | wxRichTextStyleDefinition* def = wxRichTextFormattingDialog::GetDialogStyleDefinition(this); |
dadd4f55 | 162 | if (def) |
97ff49b3 | 163 | { |
603f702b JS |
164 | m_basedOn->Freeze(); |
165 | m_nextStyle->Freeze(); | |
166 | ||
dadd4f55 JS |
167 | wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition); |
168 | wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition); | |
603f702b | 169 | wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition); |
dadd4f55 | 170 | wxRichTextStyleSheet* sheet = wxRichTextFormattingDialog::GetDialog(this)->GetStyleSheet(); |
603f702b | 171 | wxRichTextBoxStyleDefinition* boxDef = wxDynamicCast(def, wxRichTextBoxStyleDefinition); |
41a85215 | 172 | |
dadd4f55 | 173 | m_styleName->SetValue(def->GetName()); |
41a85215 | 174 | |
dadd4f55 | 175 | if (listDef) |
97ff49b3 | 176 | { |
dadd4f55 | 177 | if (m_nextStyle->GetCount() == 0) |
97ff49b3 | 178 | { |
dadd4f55 | 179 | if (sheet) |
97ff49b3 | 180 | { |
dadd4f55 JS |
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 | } | |
97ff49b3 JS |
188 | } |
189 | } | |
dadd4f55 | 190 | m_nextStyle->SetValue(listDef->GetNextStyle()); |
97ff49b3 | 191 | } |
dadd4f55 | 192 | else if (paraDef) |
97ff49b3 | 193 | { |
dadd4f55 | 194 | if (m_nextStyle->GetCount() == 0) |
97ff49b3 | 195 | { |
dadd4f55 | 196 | if (sheet) |
97ff49b3 | 197 | { |
dadd4f55 JS |
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 | } | |
97ff49b3 JS |
205 | } |
206 | } | |
dadd4f55 JS |
207 | m_nextStyle->SetValue(paraDef->GetNextStyle()); |
208 | } | |
41a85215 | 209 | |
dadd4f55 JS |
210 | if (m_basedOn->GetCount() == 0) |
211 | { | |
212 | if (sheet) | |
97ff49b3 | 213 | { |
dadd4f55 JS |
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) | |
97ff49b3 | 225 | { |
dadd4f55 JS |
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 | } | |
603f702b JS |
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) | |
dadd4f55 JS |
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 | } | |
97ff49b3 JS |
253 | } |
254 | } | |
255 | } | |
41a85215 | 256 | |
dadd4f55 | 257 | m_basedOn->SetValue(def->GetBaseStyle()); |
603f702b JS |
258 | |
259 | m_nextStyle->Thaw(); | |
260 | m_basedOn->Thaw(); | |
97ff49b3 | 261 | } |
5778b3c8 | 262 | |
97ff49b3 JS |
263 | return true; |
264 | } | |
265 | ||
24777478 | 266 | wxRichTextAttr* wxRichTextStylePage::GetAttributes() |
97ff49b3 JS |
267 | { |
268 | return wxRichTextFormattingDialog::GetDialogAttributes(this); | |
269 | } | |
270 | ||
271 | /*! | |
272 | * Should we show tooltips? | |
273 | */ | |
274 | ||
275 | bool wxRichTextStylePage::ShowToolTips() | |
276 | { | |
dadd4f55 | 277 | return wxRichTextFormattingDialog::ShowToolTips(); |
97ff49b3 JS |
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); | |
568fb7e9 | 312 | event.Enable(wxDynamicCast(def, wxRichTextParagraphStyleDefinition) != NULL); |
97ff49b3 | 313 | } |
b68603d5 WS |
314 | |
315 | #endif // wxUSE_RICHTEXT |