]> git.saurik.com Git - wxWidgets.git/blobdiff - src/richtext/richtextctrl.cpp
Compilation with new dc code
[wxWidgets.git] / src / richtext / richtextctrl.cpp
index 37a98dcd6a713165dff5487817ee982662c20ea8..14b77e9b1d8b73883d1b14a646c2880b92961fde 100644 (file)
@@ -151,7 +151,7 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va
     // The base attributes must all have default values
     wxTextAttrEx attributes;
     attributes.SetFont(GetFont());
-    attributes.SetTextColour(*wxBLACK);
+    attributes.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
     attributes.SetAlignment(wxTEXT_ALIGNMENT_LEFT);
     attributes.SetLineSpacing(10);
     attributes.SetParagraphSpacingAfter(10);
@@ -166,7 +166,7 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va
     wxTextAttrEx defaultAttributes;
     SetDefaultStyle(defaultAttributes);
 
-    SetBackgroundColour(*wxWHITE);
+    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
     SetBackgroundStyle(wxBG_STYLE_CUSTOM);
 
     // Tell the sizers to use the given or best size
@@ -229,7 +229,10 @@ void wxRichTextCtrl::Thaw()
 
     if (m_freezeCount == 0)
     {
-        SetupScrollbars();
+        if (GetBuffer().GetDirty())
+            LayoutContent();
+        else
+            SetupScrollbars();
         Refresh(false);
     }
 }
@@ -244,11 +247,9 @@ void wxRichTextCtrl::Clear()
     m_caretAtLineStart = false;
     m_selectionRange.SetRange(-2, -2);
 
-    SetScrollbars(0, 0, 0, 0, 0, 0);
-
     if (m_freezeCount == 0)
     {
-        SetupScrollbars();
+        LayoutContent();
         Refresh(false);
     }
     SendTextUpdatedEvent();
@@ -409,7 +410,7 @@ void wxRichTextCtrl::OnLeftUp(wxMouseEvent& event)
                         if (!urlTarget.IsEmpty())
                         {
                             wxMouseEvent mouseEvent(event);
-                            
+
                             long startPos = 0, endPos = 0;
                             wxRichTextObject* obj = GetBuffer().GetLeafObjectAtPosition(position);
                             if (obj)
@@ -417,12 +418,12 @@ void wxRichTextCtrl::OnLeftUp(wxMouseEvent& event)
                                 startPos = obj->GetRange().GetStart();
                                 endPos = obj->GetRange().GetEnd();
                             }
-                            
+
                             wxTextUrlEvent urlEvent(GetId(), mouseEvent, startPos, endPos);
                             InitCommandEvent(urlEvent);
-                            
+
                             urlEvent.SetString(urlTarget);
-                            
+
                             GetEventHandler()->ProcessEvent(urlEvent);
                         }
                     }
@@ -513,7 +514,7 @@ void wxRichTextCtrl::OnRightClick(wxMouseEvent& WXUNUSED(event))
         GetId());
     cmdEvent.SetEventObject(this);
     cmdEvent.SetPosition(m_caretPosition+1);
-    
+
     GetEventHandler()->ProcessEvent(cmdEvent);
 }
 
@@ -525,7 +526,7 @@ void wxRichTextCtrl::OnLeftDClick(wxMouseEvent& WXUNUSED(event))
         GetId());
     cmdEvent.SetEventObject(this);
     cmdEvent.SetPosition(m_caretPosition+1);
-    
+
     if (!GetEventHandler()->ProcessEvent(cmdEvent))
     {
         SelectWord(GetCaretPosition()+1);
@@ -540,7 +541,7 @@ void wxRichTextCtrl::OnMiddleClick(wxMouseEvent& event)
         GetId());
     cmdEvent.SetEventObject(this);
     cmdEvent.SetPosition(m_caretPosition+1);
-    
+
     if (!GetEventHandler()->ProcessEvent(cmdEvent))
         event.Skip();
 }
@@ -1047,7 +1048,7 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode)
 
     // Going down
     if (keyCode == WXK_DOWN || keyCode == WXK_NUMPAD_DOWN ||
-        keyCode == WXK_RIGHT || keyCode == WXK_NUMPAD_DOWN ||
+        keyCode == WXK_RIGHT || keyCode == WXK_NUMPAD_RIGHT ||
         keyCode == WXK_END || keyCode == WXK_NUMPAD_END ||
         keyCode == WXK_PAGEDOWN || keyCode == WXK_NUMPAD_PAGEDOWN)
     {
@@ -2039,7 +2040,7 @@ wxRichTextCtrl::HitTest(const wxPoint& pt,
         return wxTE_HT_BEFORE;
     else if ((hit & wxRICHTEXT_HITTEST_AFTER) && (hit & wxRICHTEXT_HITTEST_OUTSIDE))
         return wxTE_HT_BEYOND;
-    else if (hit & wxRICHTEXT_HITTEST_BEFORE|wxRICHTEXT_HITTEST_AFTER)
+    else if (hit & (wxRICHTEXT_HITTEST_BEFORE|wxRICHTEXT_HITTEST_AFTER))
         return wxTE_HT_ON_TEXT;
 
     return wxTE_HT_UNKNOWN;
@@ -2064,30 +2065,21 @@ void wxRichTextCtrl::DoSetValue(const wxString& value, int flags)
 {
     Clear();
 
-    // if the text is long enough, it's faster to just set it instead of first
-    // comparing it with the old one (chances are that it will be different
-    // anyhow, this comparison is there to avoid flicker for small single-line
-    // edit controls mostly)
-    if ( (value.length() > 0x400) || (value != GetValue()) )
+    if (!value.IsEmpty())
     {
+        // Remove empty paragraph
+        GetBuffer().Clear();
         DoWriteText(value);
 
         // for compatibility, don't move the cursor when doing SetValue()
         SetInsertionPoint(0);
     }
-    else // same text
+    else
     {
-        if ( flags & SetValue_SendEvent )
-        {
-            // still send an event for consistency
+        // still send an event for consistency
+        if (flags & SetValue_SendEvent)
             SendTextUpdatedEvent();
-        }
     }
-
-    // we should reset the modified flag even if the value didn't really change
-
-    // mark the control as being not dirty - we changed its text, not the
-    // user
     DiscardEdits();
 }
 
@@ -2536,8 +2528,14 @@ void wxRichTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event)
     event.Enable(GetLastPosition() > 0);
 }
 
-void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent& WXUNUSED(event))
+void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent& event)
 {
+    if (event.GetEventObject() != this)
+    {
+        event.Skip();
+        return;
+    }
+
     if (!m_contextMenu)
     {
         m_contextMenu = new wxMenu;
@@ -2716,12 +2714,13 @@ void wxRichTextCtrl::PositionCaret()
     wxRect caretRect;
     if (GetCaretPositionForIndex(GetCaretPosition(), caretRect))
     {
-        wxPoint originalPt = caretRect.GetPosition();
-        wxPoint pt = GetPhysicalPoint(originalPt);
-        if (GetCaret()->GetPosition() != pt)
+        wxPoint newPt = caretRect.GetPosition();
+        wxSize newSz = caretRect.GetSize();
+        wxPoint pt = GetPhysicalPoint(newPt);
+        if (GetCaret()->GetPosition() != pt || GetCaret()->GetSize() != newSz)
         {
             GetCaret()->Move(pt);
-            GetCaret()->SetSize(caretRect.GetSize());
+            GetCaret()->SetSize(newSz);
         }
     }
 }