]> git.saurik.com Git - wxWidgets.git/commitdiff
Further fixes, for selected text display and new paragraph insertion
authorJulian Smart <julian@anthemion.co.uk>
Wed, 13 Feb 2008 14:24:49 +0000 (14:24 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Wed, 13 Feb 2008 14:24:49 +0000 (14:24 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51753 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/richtext/richtextbuffer.h
src/richtext/richtextbuffer.cpp
src/richtext/richtextctrl.cpp

index 6752005ad78a9612245bbd02817704bad275c7ef..9692e8a9f2a35578dababb88348b32b872e5115e 100644 (file)
@@ -195,6 +195,7 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer;
 
 #define wxRICHTEXT_INSERT_NONE                              0x00
 #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE     0x01
+#define wxRICHTEXT_INSERT_INTERACTIVE                       0x02
 
 /*!
  * wxRichTextFontTable
index 9a96b42105532bb88c76685e8dd820d6194d6979..4ee7357eeabfc39461f33b800e191da4f167e1f9 100644 (file)
@@ -1159,13 +1159,10 @@ bool wxRichTextParagraphLayoutBox::InsertFragment(long position, wxRichTextParag
 
             while (objectNode)
             {
-                if (!objectNode->GetData()->IsEmpty())
-                {
-                    wxRichTextObject* newObj = objectNode->GetData()->Clone();
+                wxRichTextObject* newObj = objectNode->GetData()->Clone();
 
-                    // Append
-                    para->AppendChild(newObj);
-                }
+                // Append
+                para->AppendChild(newObj);
 
                 objectNode = objectNode->GetNext();
             }
@@ -1212,7 +1209,8 @@ bool wxRichTextParagraphLayoutBox::InsertFragment(long position, wxRichTextParag
             // 4. Add back the remaining content.
             if (finalPara)
             {
-                finalPara->MoveFromList(savedObjects);
+                if (nextObject)
+                    finalPara->MoveFromList(savedObjects);
 
                 // Ensure there's at least one object
                 if (finalPara->GetChildCount() == 0)
@@ -4272,11 +4270,11 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR
     wxString str = m_text;
     wxString toRemove = wxRichTextLineBreakChar;
     str.Replace(toRemove, wxT(" "));
+    if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS))
+        str.MakeUpper();
 
     long len = range.GetLength();
     wxString stringChunk = str.Mid(range.GetStart() - offset, (size_t) len);
-    if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS))
-        stringChunk.MakeUpper();
 
     int charHeight = dc.GetCharHeight();
 
@@ -4903,17 +4901,45 @@ bool wxRichTextBuffer::InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int
     action->GetNewParagraphs().AppendChild(newPara);
     action->GetNewParagraphs().UpdateRanges();
     action->GetNewParagraphs().SetPartialParagraph(false);
+    wxRichTextParagraph* para = GetParagraphAtPosition(pos, false);
+    long pos1 = pos;
+
+    if (flags & wxRICHTEXT_INSERT_INTERACTIVE)
+    {
+        if (para && para->GetRange().GetEnd() == pos)
+            pos1 ++;
+    }
+
     action->SetPosition(pos);
 
     if (p)
         newPara->SetAttributes(*p);
 
+    // Use the default character style
     // Use the default character style
     if (!GetDefaultStyle().IsDefault() && newPara->GetChildren().GetFirst())
-        newPara->GetChildren().GetFirst()->GetData()->SetAttributes(GetDefaultStyle());
+    {
+        // Check whether the default style merely reflects the paragraph/basic style,
+        // in which case don't apply it.
+        wxTextAttrEx defaultStyle(GetDefaultStyle());
+        wxTextAttrEx toApply;
+        if (para)
+        {
+            wxRichTextAttr combinedAttr = para->GetCombinedAttributes();
+            wxTextAttrEx newAttr;
+            // This filters out attributes that are accounted for by the current
+            // paragraph/basic style
+            wxRichTextApplyStyle(toApply, defaultStyle, & combinedAttr);
+        }
+        else
+            toApply = defaultStyle;
+
+        if (!toApply.IsDefault())
+            newPara->GetChildren().GetFirst()->GetData()->SetAttributes(toApply);
+    }
 
     // Set the range we'll need to delete in Undo
-    action->SetRange(wxRichTextRange(pos, pos));
+    action->SetRange(wxRichTextRange(pos1, pos1));
 
     SubmitAction(action);
 
@@ -6129,7 +6155,7 @@ bool wxRichTextAction::Do()
                 wxPoint firstVisiblePt = m_ctrl->GetFirstVisiblePoint();
                 int lastY = firstVisiblePt.y + clientSize.y;
 
-                wxRichTextParagraph* para = m_buffer->GetParagraphAtPosition(GetPosition());
+                wxRichTextParagraph* para = m_buffer->GetParagraphAtPosition(GetRange().GetStart());
                 wxRichTextObjectList::compatibility_iterator node = m_buffer->GetChildren().Find(para);
                 while (node)
                 {
@@ -6162,9 +6188,9 @@ bool wxRichTextAction::Do()
             }
 #endif
 
-            m_buffer->InsertFragment(GetPosition(), m_newParagraphs);
+            m_buffer->InsertFragment(GetRange().GetStart(), m_newParagraphs);
             m_buffer->UpdateRanges();
-            m_buffer->Invalidate(GetRange());
+            m_buffer->Invalidate(wxRichTextRange(GetRange().GetStart()-1, GetRange().GetEnd()));
 
             long newCaretPosition = GetPosition() + m_newParagraphs.GetRange().GetLength();
 
index 252cfe22afc281c70f3c4f6b636791f3abecb948..25f71a853dd7a9f03692c6235b7f5d22cb9f84b8 100644 (file)
@@ -596,7 +596,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
             GetBuffer().InsertTextWithUndo(newPos+1, text, this);
         }
         else
-            GetBuffer().InsertNewlineWithUndo(newPos+1, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE);
+            GetBuffer().InsertNewlineWithUndo(newPos+1, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE|wxRICHTEXT_INSERT_INTERACTIVE);
 
         EndBatchUndo();
         SetDefaultStyleToCursorStyle();