1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextstylepage.cpp
4 // Author: Julian Smart
6 // Created: 10/5/2006 11:34:55 AM
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/richtext/richtextstylepage.h"
16 * wxRichTextStylePage type definition
19 IMPLEMENT_DYNAMIC_CLASS( wxRichTextStylePage
, wxRichTextDialogPage
)
22 * wxRichTextStylePage event table definition
25 BEGIN_EVENT_TABLE( wxRichTextStylePage
, wxRichTextDialogPage
)
27 ////@begin wxRichTextStylePage event table entries
28 EVT_UPDATE_UI( ID_RICHTEXTSTYLEPAGE_NEXT_STYLE
, wxRichTextStylePage::OnNextStyleUpdate
)
30 ////@end wxRichTextStylePage event table entries
34 IMPLEMENT_HELP_PROVISION(wxRichTextStylePage
)
37 * wxRichTextStylePage constructors
40 wxRichTextStylePage::wxRichTextStylePage( )
45 wxRichTextStylePage::wxRichTextStylePage( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
48 Create(parent
, id
, pos
, size
, style
);
55 void wxRichTextStylePage::Init()
57 ////@begin wxRichTextStylePage member initialisation
61 ////@end wxRichTextStylePage member initialisation
65 * wxRichTextStylePage creator
68 bool wxRichTextStylePage::Create( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
70 ////@begin wxRichTextStylePage creation
71 wxRichTextDialogPage::Create( parent
, id
, pos
, size
, style
);
76 GetSizer()->SetSizeHints(this);
79 ////@end wxRichTextStylePage creation
84 * Control creation for wxRichTextStylePage
87 void wxRichTextStylePage::CreateControls()
89 ////@begin wxRichTextStylePage content construction
90 wxRichTextStylePage
* itemRichTextDialogPage1
= this;
92 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
93 itemRichTextDialogPage1
->SetSizer(itemBoxSizer2
);
95 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
96 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
98 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
99 itemBoxSizer3
->Add(itemBoxSizer4
, 0, wxGROW
, 5);
101 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
102 itemBoxSizer4
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
104 wxStaticText
* itemStaticText6
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
105 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
107 m_styleName
= new wxTextCtrl( itemRichTextDialogPage1
, ID_RICHTEXTSTYLEPAGE_STYLE_NAME
, wxEmptyString
, wxDefaultPosition
, wxSize(300, -1), wxTE_READONLY
);
108 m_styleName
->SetHelpText(_("The style name."));
109 if (wxRichTextStylePage::ShowToolTips())
110 m_styleName
->SetToolTip(_("The style name."));
111 itemBoxSizer5
->Add(m_styleName
, 0, wxGROW
|wxALL
, 5);
113 wxStaticText
* itemStaticText8
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Based on:"), wxDefaultPosition
, wxDefaultSize
, 0 );
114 itemBoxSizer5
->Add(itemStaticText8
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
116 wxArrayString m_basedOnStrings
;
117 m_basedOn
= new wxComboBox( itemRichTextDialogPage1
, ID_RICHTEXTSTYLEPAGE_BASED_ON
, wxEmptyString
, wxDefaultPosition
, wxSize(300, -1), m_basedOnStrings
, wxCB_DROPDOWN
);
118 m_basedOn
->SetHelpText(_("The style on which this style is based."));
119 if (wxRichTextStylePage::ShowToolTips())
120 m_basedOn
->SetToolTip(_("The style on which this style is based."));
121 itemBoxSizer5
->Add(m_basedOn
, 0, wxGROW
|wxALL
, 5);
123 wxStaticText
* itemStaticText10
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Next style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
124 itemBoxSizer5
->Add(itemStaticText10
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
126 wxArrayString m_nextStyleStrings
;
127 m_nextStyle
= new wxComboBox( itemRichTextDialogPage1
, ID_RICHTEXTSTYLEPAGE_NEXT_STYLE
, wxEmptyString
, wxDefaultPosition
, wxSize(300, -1), m_nextStyleStrings
, wxCB_DROPDOWN
);
128 m_nextStyle
->SetHelpText(_("The default style for the next paragraph."));
129 if (wxRichTextStylePage::ShowToolTips())
130 m_nextStyle
->SetToolTip(_("The default style for the next paragraph."));
131 itemBoxSizer5
->Add(m_nextStyle
, 0, wxGROW
|wxALL
, 5);
133 itemBoxSizer3
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
135 ////@end wxRichTextStylePage content construction
138 /// Transfer data from/to window
139 bool wxRichTextStylePage::TransferDataFromWindow()
141 wxPanel::TransferDataFromWindow();
143 wxRichTextStyleDefinition
* def
= wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
146 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
);
148 paraDef
->SetNextStyle(m_nextStyle
->GetValue());
150 def
->SetName(m_styleName
->GetValue());
151 def
->SetBaseStyle(m_basedOn
->GetValue());
157 bool wxRichTextStylePage::TransferDataToWindow()
159 wxPanel::TransferDataToWindow();
161 wxRichTextStyleDefinition
* def
= wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
165 m_nextStyle
->Freeze();
167 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
);
168 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
169 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(def
, wxRichTextCharacterStyleDefinition
);
170 wxRichTextStyleSheet
* sheet
= wxRichTextFormattingDialog::GetDialog(this)->GetStyleSheet();
171 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(def
, wxRichTextBoxStyleDefinition
);
173 m_styleName
->SetValue(def
->GetName());
177 if (m_nextStyle
->GetCount() == 0)
182 for (i
= 0; i
< sheet
->GetListStyleCount(); i
++)
184 wxRichTextListStyleDefinition
* p
= wxDynamicCast(sheet
->GetListStyle(i
), wxRichTextListStyleDefinition
);
186 m_nextStyle
->Append(p
->GetName());
190 m_nextStyle
->SetValue(listDef
->GetNextStyle());
194 if (m_nextStyle
->GetCount() == 0)
199 for (i
= 0; i
< sheet
->GetParagraphStyleCount(); i
++)
201 wxRichTextParagraphStyleDefinition
* p
= wxDynamicCast(sheet
->GetParagraphStyle(i
), wxRichTextParagraphStyleDefinition
);
203 m_nextStyle
->Append(p
->GetName());
207 m_nextStyle
->SetValue(paraDef
->GetNextStyle());
210 if (m_basedOn
->GetCount() == 0)
217 for (i
= 0; i
< sheet
->GetListStyleCount(); i
++)
219 wxRichTextListStyleDefinition
* p
= wxDynamicCast(sheet
->GetListStyle(i
), wxRichTextListStyleDefinition
);
221 m_basedOn
->Append(p
->GetName());
227 for (i
= 0; i
< sheet
->GetParagraphStyleCount(); i
++)
229 wxRichTextParagraphStyleDefinition
* p
= wxDynamicCast(sheet
->GetParagraphStyle(i
), wxRichTextParagraphStyleDefinition
);
231 m_basedOn
->Append(p
->GetName());
237 for (i
= 0; i
< sheet
->GetBoxStyleCount(); i
++)
239 wxRichTextBoxStyleDefinition
* p
= wxDynamicCast(sheet
->GetBoxStyle(i
), wxRichTextBoxStyleDefinition
);
241 m_basedOn
->Append(p
->GetName());
247 for (i
= 0; i
< sheet
->GetCharacterStyleCount(); i
++)
249 wxRichTextCharacterStyleDefinition
* p
= wxDynamicCast(sheet
->GetCharacterStyle(i
), wxRichTextCharacterStyleDefinition
);
251 m_basedOn
->Append(p
->GetName());
257 m_basedOn
->SetValue(def
->GetBaseStyle());
266 wxRichTextAttr
* wxRichTextStylePage::GetAttributes()
268 return wxRichTextFormattingDialog::GetDialogAttributes(this);
272 * Should we show tooltips?
275 bool wxRichTextStylePage::ShowToolTips()
277 return wxRichTextFormattingDialog::ShowToolTips();
281 * Get bitmap resources
284 wxBitmap
wxRichTextStylePage::GetBitmapResource( const wxString
& name
)
287 ////@begin wxRichTextStylePage bitmap retrieval
290 ////@end wxRichTextStylePage bitmap retrieval
297 wxIcon
wxRichTextStylePage::GetIconResource( const wxString
& name
)
300 ////@begin wxRichTextStylePage icon retrieval
303 ////@end wxRichTextStylePage icon retrieval
306 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEPAGE_NEXT_STYLE
309 void wxRichTextStylePage::OnNextStyleUpdate( wxUpdateUIEvent
& event
)
311 wxRichTextStyleDefinition
* def
= wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
312 event
.Enable(wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
) != NULL
);
315 #endif // wxUSE_RICHTEXT