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