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