+BEGIN_EVENT_TABLE(wxRichTextStyleListCtrl, wxControl)
+ EVT_CHOICE(wxID_ANY, wxRichTextStyleListCtrl::OnChooseType)
+ EVT_SIZE(wxRichTextStyleListCtrl::OnSize)
+END_EVENT_TABLE()
+
+wxRichTextStyleListCtrl::wxRichTextStyleListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos,
+ const wxSize& size, long style)
+{
+ Init();
+ Create(parent, id, pos, size, style);
+}
+
+bool wxRichTextStyleListCtrl::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos,
+ const wxSize& size, long style)
+{
+ if ((style & wxBORDER_MASK) == wxBORDER_DEFAULT)
+ style |= wxBORDER_THEME;
+
+ wxControl::Create(parent, id, pos, size, style);
+
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
+ if (size != wxDefaultSize)
+ SetInitialSize(size);
+
+ bool showSelector = ((style & wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR) == 0);
+
+ wxBorder listBoxStyle;
+ if (showSelector)
+ listBoxStyle = wxBORDER_THEME;
+ else
+ listBoxStyle = wxBORDER_NONE;
+
+ m_styleListBox = new wxRichTextStyleListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, listBoxStyle);
+
+ wxBoxSizer* boxSizer = new wxBoxSizer(wxVERTICAL);
+
+ if (showSelector)
+ {
+ wxArrayString choices;
+ choices.Add(_("All styles"));
+ choices.Add(_("Paragraph styles"));
+ choices.Add(_("Character styles"));
+ choices.Add(_("List styles"));
+
+ m_styleChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices);
+
+ boxSizer->Add(m_styleListBox, 1, wxALL|wxEXPAND, 5);
+ boxSizer->Add(m_styleChoice, 0, wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, 5);
+ }
+ else
+ {
+ boxSizer->Add(m_styleListBox, 1, wxALL|wxEXPAND, 0);
+ }
+
+ SetSizer(boxSizer);
+ Layout();
+
+ m_dontUpdate = true;
+
+ if (m_styleChoice)
+ {
+ int i = StyleTypeToIndex(m_styleListBox->GetStyleType());
+ m_styleChoice->SetSelection(i);
+ }
+
+ m_dontUpdate = false;
+
+ return true;
+}
+
+wxRichTextStyleListCtrl::~wxRichTextStyleListCtrl()
+{
+
+}
+
+/// React to style type choice
+void wxRichTextStyleListCtrl::OnChooseType(wxCommandEvent& event)
+{
+ if (event.GetEventObject() != m_styleChoice)
+ event.Skip();
+ else
+ {
+ if (m_dontUpdate)
+ return;
+
+ wxRichTextStyleListBox::wxRichTextStyleType styleType = StyleIndexToType(event.GetSelection());
+ m_styleListBox->SetStyleType(styleType);
+ }
+}
+
+/// Lay out the controls
+void wxRichTextStyleListCtrl::OnSize(wxSizeEvent& WXUNUSED(event))
+{
+ if (GetAutoLayout())
+ Layout();
+}
+
+/// Get the choice index for style type
+int wxRichTextStyleListCtrl::StyleTypeToIndex(wxRichTextStyleListBox::wxRichTextStyleType styleType)
+{
+ if (styleType == wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL)
+ {
+ return 0;
+ }
+ else if (styleType == wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH)
+ {
+ return 1;
+ }
+ else if (styleType == wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER)
+ {
+ return 2;
+ }
+ else if (styleType == wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST)
+ {
+ return 3;
+ }
+ return 0;
+}
+
+/// Get the style type for choice index
+wxRichTextStyleListBox::wxRichTextStyleType wxRichTextStyleListCtrl::StyleIndexToType(int i)
+{
+ if (i == 1)
+ return wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH;
+ else if (i == 2)
+ return wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER;
+ else if (i == 3)
+ return wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST;
+
+ return wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL;
+}
+
+/// Associates the control with a style manager
+void wxRichTextStyleListCtrl::SetStyleSheet(wxRichTextStyleSheet* styleSheet)
+{
+ if (m_styleListBox)
+ m_styleListBox->SetStyleSheet(styleSheet);
+}
+
+wxRichTextStyleSheet* wxRichTextStyleListCtrl::GetStyleSheet() const
+{
+ if (m_styleListBox)
+ return m_styleListBox->GetStyleSheet();
+ else
+ return NULL;
+}
+
+/// Associates the control with a wxRichTextCtrl
+void wxRichTextStyleListCtrl::SetRichTextCtrl(wxRichTextCtrl* ctrl)
+{
+ if (m_styleListBox)
+ m_styleListBox->SetRichTextCtrl(ctrl);
+}
+
+wxRichTextCtrl* wxRichTextStyleListCtrl::GetRichTextCtrl() const
+{
+ if (m_styleListBox)
+ return m_styleListBox->GetRichTextCtrl();
+ else
+ return NULL;
+}
+
+/// Set/get the style type to display
+void wxRichTextStyleListCtrl::SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType)
+{
+ if ( !m_styleListBox )
+ return;
+
+ m_styleListBox->SetStyleType(styleType);
+
+ m_dontUpdate = true;
+
+ if (m_styleChoice)
+ {
+ int i = StyleTypeToIndex(m_styleListBox->GetStyleType());
+ m_styleChoice->SetSelection(i);
+ }
+
+ m_dontUpdate = false;
+}
+
+wxRichTextStyleListBox::wxRichTextStyleType wxRichTextStyleListCtrl::GetStyleType() const
+{
+ if (m_styleListBox)
+ return m_styleListBox->GetStyleType();
+ else
+ return wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL;
+}
+
+/// Updates the style list box
+void wxRichTextStyleListCtrl::UpdateStyles()
+{
+ if (m_styleListBox)
+ m_styleListBox->UpdateStyles();
+}
+
+#if wxUSE_COMBOCTRL
+
+/*!
+ * Style drop-down for a wxComboCtrl
+ */
+
+
+BEGIN_EVENT_TABLE(wxRichTextStyleComboPopup, wxRichTextStyleListBox)
+ EVT_MOTION(wxRichTextStyleComboPopup::OnMouseMove)
+ EVT_LEFT_DOWN(wxRichTextStyleComboPopup::OnMouseClick)
+END_EVENT_TABLE()
+
+bool wxRichTextStyleComboPopup::Create( wxWindow* parent )
+{
+ int borderStyle = GetDefaultBorder();
+ if (borderStyle == wxBORDER_SUNKEN)
+ borderStyle = wxBORDER_SIMPLE;
+
+ return wxRichTextStyleListBox::Create(parent, wxID_ANY,
+ wxPoint(0,0), wxDefaultSize,
+ borderStyle);
+}
+
+void wxRichTextStyleComboPopup::SetStringValue( const wxString& s )
+{
+ m_value = SetStyleSelection(s);
+}
+
+wxString wxRichTextStyleComboPopup::GetStringValue() const
+{
+ int sel = m_value;
+ if (sel > -1)
+ {
+ wxRichTextStyleDefinition* def = GetStyle(sel);
+ if (def)
+ return def->GetName();