]> git.saurik.com Git - wxWidgets.git/blob - src/richtext/richtextstylepage.cpp
Use widget->allocation instead of querying the
[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 #if wxUSE_RICHTEXT
13
14 #include "wx/richtext/richtextstylepage.h"
15
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 */
53
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()
87 {
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 );
104 itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
105
106 m_styleName = new wxTextCtrl( itemPanel1,
107 ID_RICHTEXTSTYLEPAGE_STYLE_NAME,
108 wxEmptyString,
109 wxDefaultPosition,
110 wxSize(300, wxDefaultCoord),
111 0 );
112 itemBoxSizer5->Add(m_styleName, 0, wxGROW|wxALL, 5);
113
114 wxStaticText* itemStaticText8 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Based on:"), wxDefaultPosition, wxDefaultSize, 0 );
115 itemBoxSizer5->Add(itemStaticText8, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
116
117 wxString* m_basedOnStrings = NULL;
118 m_basedOn = new wxComboBox( itemPanel1,
119 ID_RICHTEXTSTYLEPAGE_BASED_ON,
120 wxEmptyString,
121 wxDefaultPosition,
122 wxDefaultSize,
123 0,
124 m_basedOnStrings,
125 wxCB_DROPDOWN );
126 itemBoxSizer5->Add(m_basedOn, 0, wxGROW|wxALL, 5);
127
128 wxStaticText* itemStaticText10 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Next style:"), wxDefaultPosition, wxDefaultSize, 0 );
129 itemBoxSizer5->Add(itemStaticText10, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
130
131 wxString* m_nextStyleStrings = NULL;
132 m_nextStyle = new wxComboBox( itemPanel1,
133 ID_RICHTEXTSTYLEPAGE_NEXT_STYLE,
134 wxEmptyString,
135 wxDefaultPosition,
136 wxDefaultSize,
137 0,
138 m_nextStyleStrings,
139 wxCB_DROPDOWN );
140 itemBoxSizer5->Add(m_nextStyle, 0, wxGROW|wxALL, 5);
141
142 itemBoxSizer3->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
143
144 ////@end wxRichTextStylePage content construction
145 }
146
147 /// Transfer data from/to window
148 bool wxRichTextStylePage::TransferDataFromWindow()
149 {
150 wxPanel::TransferDataFromWindow();
151
152 wxRichTextStyleDefinition* def = wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
153 wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
154 if (paraDef)
155 paraDef->SetNextStyle(m_nextStyle->GetValue());
156
157 def->SetName(m_styleName->GetValue());
158 def->SetBaseStyle(m_basedOn->GetValue());
159
160 return true;
161 }
162
163 bool wxRichTextStylePage::TransferDataToWindow()
164 {
165 wxPanel::TransferDataToWindow();
166
167 wxRichTextStyleDefinition* def = wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
168 wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
169 wxRichTextStyleSheet* sheet = wxRichTextFormattingDialog::GetDialog(this)->GetStyleSheet();
170
171 m_styleName->SetValue(def->GetName());
172
173 if (paraDef)
174 {
175 if (m_nextStyle->GetCount() == 0)
176 {
177 if (sheet)
178 {
179 size_t i;
180 for (i = 0; i < sheet->GetParagraphStyleCount(); i++)
181 {
182 wxRichTextParagraphStyleDefinition* p = wxDynamicCast(sheet->GetParagraphStyle(i), wxRichTextParagraphStyleDefinition);
183 if (p)
184 m_nextStyle->Append(p->GetName());
185 }
186 }
187 }
188 m_nextStyle->SetValue(paraDef->GetNextStyle());
189 }
190
191 if (m_basedOn->GetCount() == 0)
192 {
193 if (sheet)
194 {
195 if (paraDef)
196 {
197 size_t i;
198 for (i = 0; i < sheet->GetParagraphStyleCount(); i++)
199 {
200 wxRichTextParagraphStyleDefinition* p = wxDynamicCast(sheet->GetParagraphStyle(i), wxRichTextParagraphStyleDefinition);
201 if (p)
202 m_basedOn->Append(p->GetName());
203 }
204 }
205 else
206 {
207 size_t i;
208 for (i = 0; i < sheet->GetCharacterStyleCount(); i++)
209 {
210 wxRichTextCharacterStyleDefinition* p = wxDynamicCast(sheet->GetCharacterStyle(i), wxRichTextCharacterStyleDefinition);
211 if (p)
212 m_basedOn->Append(p->GetName());
213 }
214 }
215 }
216 }
217
218 m_basedOn->SetValue(def->GetBaseStyle());
219
220 return true;
221 }
222
223 wxTextAttrEx* wxRichTextStylePage::GetAttributes()
224 {
225 return wxRichTextFormattingDialog::GetDialogAttributes(this);
226 }
227
228 /*!
229 * Should we show tooltips?
230 */
231
232 bool wxRichTextStylePage::ShowToolTips()
233 {
234 return true;
235 }
236
237 /*!
238 * Get bitmap resources
239 */
240
241 wxBitmap wxRichTextStylePage::GetBitmapResource( const wxString& name )
242 {
243 // Bitmap retrieval
244 ////@begin wxRichTextStylePage bitmap retrieval
245 wxUnusedVar(name);
246 return wxNullBitmap;
247 ////@end wxRichTextStylePage bitmap retrieval
248 }
249
250 /*!
251 * Get icon resources
252 */
253
254 wxIcon wxRichTextStylePage::GetIconResource( const wxString& name )
255 {
256 // Icon retrieval
257 ////@begin wxRichTextStylePage icon retrieval
258 wxUnusedVar(name);
259 return wxNullIcon;
260 ////@end wxRichTextStylePage icon retrieval
261 }
262 /*!
263 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEPAGE_NEXT_STYLE
264 */
265
266 void wxRichTextStylePage::OnNextStyleUpdate( wxUpdateUIEvent& event )
267 {
268 wxRichTextStyleDefinition* def = wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
269 event.Enable(def->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition)));
270 }
271
272 #endif // wxUSE_RICHTEXT