X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e637208a3210dfae3ee044cc5b7179fd76082769..ccb5db57cdb1766eefb7023dda50ede9f0d01f78:/src/richtext/richtextstyles.cpp diff --git a/src/richtext/richtextstyles.cpp b/src/richtext/richtextstyles.cpp index 183daea53a..e0bad0c3ad 100644 --- a/src/richtext/richtextstyles.cpp +++ b/src/richtext/richtextstyles.cpp @@ -13,7 +13,7 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ - #pragma hdrstop + #pragma hdrstop #endif #if wxUSE_RICHTEXT @@ -21,8 +21,7 @@ #include "wx/richtext/richtextstyles.h" #ifndef WX_PRECOMP - #include "wx/dcclient.h" - #include "wx/module.h" + #include "wx/wx.h" #endif #include "wx/filename.h" @@ -35,6 +34,38 @@ IMPLEMENT_CLASS(wxRichTextStyleDefinition, wxObject) IMPLEMENT_CLASS(wxRichTextCharacterStyleDefinition, wxRichTextStyleDefinition) IMPLEMENT_CLASS(wxRichTextParagraphStyleDefinition, wxRichTextStyleDefinition) +/*! + * A definition + */ + +void wxRichTextStyleDefinition::Copy(const wxRichTextStyleDefinition& def) +{ + m_name = def.m_name; + m_baseStyle = def.m_baseStyle; + m_style = def.m_style; +} + +bool wxRichTextStyleDefinition::Eq(const wxRichTextStyleDefinition& def) const +{ + return (m_name == def.m_name && m_baseStyle == def.m_baseStyle && m_style == def.m_style); +} + +/*! + * Paragraph style definition + */ + +void wxRichTextParagraphStyleDefinition::Copy(const wxRichTextParagraphStyleDefinition& def) +{ + wxRichTextStyleDefinition::Copy(def); + + m_nextStyle = def.m_nextStyle; +} + +bool wxRichTextParagraphStyleDefinition::operator ==(const wxRichTextParagraphStyleDefinition& def) const +{ + return (Eq(def) && m_nextStyle == def.m_nextStyle); +} + /*! * The style manager */ @@ -89,6 +120,48 @@ void wxRichTextStyleSheet::DeleteStyles() WX_CLEAR_LIST(wxList, m_paragraphStyleDefinitions); } +/// Add a definition to the character style list +bool wxRichTextStyleSheet::AddCharacterStyle(wxRichTextCharacterStyleDefinition* def) +{ + def->GetStyle().SetCharacterStyleName(def->GetName()); + return AddStyle(m_characterStyleDefinitions, def); +} + +/// Add a definition to the paragraph style list +bool wxRichTextStyleSheet::AddParagraphStyle(wxRichTextParagraphStyleDefinition* def) +{ + def->GetStyle().SetParagraphStyleName(def->GetName()); + return AddStyle(m_paragraphStyleDefinitions, def); +} + +/// Copy +void wxRichTextStyleSheet::Copy(const wxRichTextStyleSheet& sheet) +{ + DeleteStyles(); + + wxList::compatibility_iterator node; + + for (node = sheet.m_characterStyleDefinitions.GetFirst(); node; node = node->GetNext()) + { + wxRichTextCharacterStyleDefinition* def = (wxRichTextCharacterStyleDefinition*) node->GetData(); + AddCharacterStyle(new wxRichTextCharacterStyleDefinition(*def)); + } + + for (node = sheet.m_paragraphStyleDefinitions.GetFirst(); node; node = node->GetNext()) + { + wxRichTextParagraphStyleDefinition* def = (wxRichTextParagraphStyleDefinition*) node->GetData(); + AddParagraphStyle(new wxRichTextParagraphStyleDefinition(*def)); + } +} + +/// Equality +bool wxRichTextStyleSheet::operator==(const wxRichTextStyleSheet& WXUNUSED(sheet)) const +{ + // TODO + return false; +} + + #if wxUSE_HTML /*! * wxRichTextStyleListBox class declaration @@ -307,8 +380,8 @@ void wxRichTextStyleListBox::OnLeftDown(wxMouseEvent& event) wxVListBox::OnLeftDown(event); int item = HitTest(event.GetPosition()); - if (item != wxNOT_FOUND) - DoSelection(item); + if (item != wxNOT_FOUND && GetApplyOnSelection()) + ApplyStyle(item); } /// Auto-select from style under caret in idle time @@ -316,8 +389,10 @@ void wxRichTextStyleListBox::OnIdle(wxIdleEvent& event) { if (CanAutoSetSelection() && GetRichTextCtrl()) { - wxRichTextParagraph* para = GetRichTextCtrl()->GetBuffer().GetParagraphAtPosition(GetRichTextCtrl()->GetCaretPosition()); - wxRichTextObject* obj = GetRichTextCtrl()->GetBuffer().GetLeafObjectAtPosition(GetRichTextCtrl()->GetCaretPosition()); + int adjustedCaretPos = GetRichTextCtrl()->GetAdjustedCaretPosition(GetRichTextCtrl()->GetCaretPosition()); + + wxRichTextParagraph* para = GetRichTextCtrl()->GetBuffer().GetParagraphAtPosition(adjustedCaretPos); + wxRichTextObject* obj = GetRichTextCtrl()->GetBuffer().GetLeafObjectAtPosition(adjustedCaretPos); wxString styleName; @@ -354,7 +429,7 @@ void wxRichTextStyleListBox::OnIdle(wxIdleEvent& event) } /// Do selection -void wxRichTextStyleListBox::DoSelection(int item) +void wxRichTextStyleListBox::ApplyStyle(int item) { if ( item != wxNOT_FOUND ) { @@ -433,11 +508,11 @@ void wxRichTextStyleComboPopup::OnMouseClick(wxMouseEvent& WXUNUSED(event)) m_value = m_itemHere; // Ordering is important, so we don't dismiss this popup accidentally - // by setting the focus elsewhere e.g. in DoSelection + // by setting the focus elsewhere e.g. in ApplyStyle Dismiss(); if (m_itemHere >= 0) - wxRichTextStyleListBox::DoSelection(m_itemHere); + wxRichTextStyleListBox::ApplyStyle(m_itemHere); } /*! @@ -483,8 +558,10 @@ void wxRichTextStyleComboCtrl::OnIdle(wxIdleEvent& event) { if (GetRichTextCtrl() && !IsPopupShown()) { - wxRichTextParagraph* para = GetRichTextCtrl()->GetBuffer().GetParagraphAtPosition(GetRichTextCtrl()->GetCaretPosition()); - wxRichTextObject* obj = GetRichTextCtrl()->GetBuffer().GetLeafObjectAtPosition(GetRichTextCtrl()->GetCaretPosition()); + int adjustedCaretPos = GetRichTextCtrl()->GetAdjustedCaretPosition(GetRichTextCtrl()->GetCaretPosition()); + + wxRichTextParagraph* para = GetRichTextCtrl()->GetBuffer().GetParagraphAtPosition(adjustedCaretPos); + wxRichTextObject* obj = GetRichTextCtrl()->GetBuffer().GetLeafObjectAtPosition(adjustedCaretPos); wxString styleName;