]>
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 |
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 | ||
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 | */ | |
5778b3c8 | 53 | |
97ff49b3 JS |
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() | |
5778b3c8 | 87 | { |
97ff49b3 JS |
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 ); | |
69ce77e2 | 104 | itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
97ff49b3 | 105 | |
9a83f860 | 106 | m_styleName = new wxTextCtrl( itemPanel1, ID_RICHTEXTSTYLEPAGE_STYLE_NAME, wxT(""), wxDefaultPosition, wxSize(300, -1), wxTE_READONLY ); |
dadd4f55 | 107 | m_styleName->SetHelpText(_("The style name.")); |
c187b472 | 108 | if (wxRichTextStylePage::ShowToolTips()) |
dadd4f55 | 109 | m_styleName->SetToolTip(_("The style name.")); |
97ff49b3 JS |
110 | itemBoxSizer5->Add(m_styleName, 0, wxGROW|wxALL, 5); |
111 | ||
112 | wxStaticText* itemStaticText8 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Based on:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 113 | itemBoxSizer5->Add(itemStaticText8, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
97ff49b3 | 114 | |
c187b472 | 115 | wxArrayString m_basedOnStrings; |
9a83f860 | 116 | m_basedOn = new wxComboBox( itemPanel1, ID_RICHTEXTSTYLEPAGE_BASED_ON, wxT(""), wxDefaultPosition, wxDefaultSize, m_basedOnStrings, wxCB_DROPDOWN ); |
dadd4f55 | 117 | m_basedOn->SetHelpText(_("The style on which this style is based.")); |
c187b472 | 118 | if (wxRichTextStylePage::ShowToolTips()) |
dadd4f55 | 119 | m_basedOn->SetToolTip(_("The style on which this style is based.")); |
97ff49b3 JS |
120 | itemBoxSizer5->Add(m_basedOn, 0, wxGROW|wxALL, 5); |
121 | ||
122 | wxStaticText* itemStaticText10 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Next style:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 123 | itemBoxSizer5->Add(itemStaticText10, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); |
97ff49b3 | 124 | |
c187b472 | 125 | wxArrayString m_nextStyleStrings; |
9a83f860 | 126 | m_nextStyle = new wxComboBox( itemPanel1, ID_RICHTEXTSTYLEPAGE_NEXT_STYLE, wxT(""), wxDefaultPosition, wxDefaultSize, m_nextStyleStrings, wxCB_DROPDOWN ); |
dadd4f55 | 127 | m_nextStyle->SetHelpText(_("The default style for the next paragraph.")); |
c187b472 | 128 | if (wxRichTextStylePage::ShowToolTips()) |
dadd4f55 | 129 | m_nextStyle->SetToolTip(_("The default style for the next paragraph.")); |
97ff49b3 JS |
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); | |
dadd4f55 JS |
143 | if (def) |
144 | { | |
145 | wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition); | |
146 | if (paraDef) | |
147 | paraDef->SetNextStyle(m_nextStyle->GetValue()); | |
41a85215 | 148 | |
dadd4f55 JS |
149 | def->SetName(m_styleName->GetValue()); |
150 | def->SetBaseStyle(m_basedOn->GetValue()); | |
151 | } | |
97ff49b3 JS |
152 | |
153 | return true; | |
154 | } | |
155 | ||
156 | bool wxRichTextStylePage::TransferDataToWindow() | |
157 | { | |
158 | wxPanel::TransferDataToWindow(); | |
159 | ||
160 | wxRichTextStyleDefinition* def = wxRichTextFormattingDialog::GetDialogStyleDefinition(this); | |
dadd4f55 | 161 | if (def) |
97ff49b3 | 162 | { |
dadd4f55 JS |
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(); | |
41a85215 | 167 | |
dadd4f55 | 168 | m_styleName->SetValue(def->GetName()); |
41a85215 | 169 | |
dadd4f55 | 170 | if (listDef) |
97ff49b3 | 171 | { |
dadd4f55 | 172 | if (m_nextStyle->GetCount() == 0) |
97ff49b3 | 173 | { |
dadd4f55 | 174 | if (sheet) |
97ff49b3 | 175 | { |
dadd4f55 JS |
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 | } | |
97ff49b3 JS |
183 | } |
184 | } | |
dadd4f55 | 185 | m_nextStyle->SetValue(listDef->GetNextStyle()); |
97ff49b3 | 186 | } |
dadd4f55 | 187 | else if (paraDef) |
97ff49b3 | 188 | { |
dadd4f55 | 189 | if (m_nextStyle->GetCount() == 0) |
97ff49b3 | 190 | { |
dadd4f55 | 191 | if (sheet) |
97ff49b3 | 192 | { |
dadd4f55 JS |
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 | } | |
97ff49b3 JS |
200 | } |
201 | } | |
dadd4f55 JS |
202 | m_nextStyle->SetValue(paraDef->GetNextStyle()); |
203 | } | |
41a85215 | 204 | |
dadd4f55 JS |
205 | if (m_basedOn->GetCount() == 0) |
206 | { | |
207 | if (sheet) | |
97ff49b3 | 208 | { |
dadd4f55 JS |
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) | |
97ff49b3 | 220 | { |
dadd4f55 JS |
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 | } | |
97ff49b3 JS |
238 | } |
239 | } | |
240 | } | |
41a85215 | 241 | |
dadd4f55 | 242 | m_basedOn->SetValue(def->GetBaseStyle()); |
97ff49b3 | 243 | } |
5778b3c8 | 244 | |
97ff49b3 JS |
245 | return true; |
246 | } | |
247 | ||
44cc96a8 | 248 | wxTextAttr* wxRichTextStylePage::GetAttributes() |
97ff49b3 JS |
249 | { |
250 | return wxRichTextFormattingDialog::GetDialogAttributes(this); | |
251 | } | |
252 | ||
253 | /*! | |
254 | * Should we show tooltips? | |
255 | */ | |
256 | ||
257 | bool wxRichTextStylePage::ShowToolTips() | |
258 | { | |
dadd4f55 | 259 | return wxRichTextFormattingDialog::ShowToolTips(); |
97ff49b3 JS |
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 | } | |
b68603d5 WS |
296 | |
297 | #endif // wxUSE_RICHTEXT |