]> git.saurik.com Git - wxWidgets.git/blobdiff - src/richtext/richtextctrl.cpp
fixed typo in XRC error message
[wxWidgets.git] / src / richtext / richtextctrl.cpp
index b3395fe20bf21373931d7166bf10519c07fc4c3a..7e9cde82e9d7ba3811e041b6a9293fea34e28057 100644 (file)
@@ -136,6 +136,7 @@ BEGIN_EVENT_TABLE( wxRichTextCtrl, wxControl )
     EVT_MIDDLE_DOWN(wxRichTextCtrl::OnMiddleClick)
     EVT_LEFT_DCLICK(wxRichTextCtrl::OnLeftDClick)
     EVT_CHAR(wxRichTextCtrl::OnChar)
+    EVT_KEY_DOWN(wxRichTextCtrl::OnChar)
     EVT_SIZE(wxRichTextCtrl::OnSize)
     EVT_SET_FOCUS(wxRichTextCtrl::OnSetFocus)
     EVT_KILL_FOCUS(wxRichTextCtrl::OnKillFocus)
@@ -216,8 +217,6 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va
     attributes.SetLineSpacing(10);
     attributes.SetParagraphSpacingAfter(10);
     attributes.SetParagraphSpacingBefore(0);
-    attributes.SetTextEffects(0);
-    attributes.SetTextEffectFlags(wxTEXT_ATTR_EFFECT_STRIKETHROUGH|wxTEXT_ATTR_EFFECT_CAPITALS);
 
     SetBasicStyle(attributes);
 
@@ -458,6 +457,7 @@ void wxRichTextCtrl::OnLeftClick(wxMouseEvent& event)
         long oldCaretPos = m_caretPosition;
 
         MoveCaret(position, caretAtLineStart);
+        SetDefaultStyleToCursorStyle();
 
         if (event.ShiftDown())
         {
@@ -596,6 +596,7 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event)
             ExtendSelection(m_caretPosition, position, wxRICHTEXT_SHIFT_DOWN);
 
             MoveCaret(position, caretAtLineStart);
+            SetDefaultStyleToCursorStyle();
         }
     }
 }
@@ -654,6 +655,65 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
     if (event.AltDown())
         flags |= wxRICHTEXT_ALT_DOWN;
 
+    if (event.GetEventType() == wxEVT_KEY_DOWN)
+    {
+        // Must process this before translation, otherwise it's translated into a WXK_DELETE event.
+        if (event.CmdDown() && event.GetKeyCode() == WXK_BACK)
+        {
+            BeginBatchUndo(_("Delete Text"));
+
+            long newPos = m_caretPosition;
+
+            DeleteSelectedContent(& newPos);
+
+            // Submit range in character positions, which are greater than caret positions,
+            // so subtract 1 for deleted character and add 1 for conversion to character position.
+            if (newPos > -1)
+            {
+                bool processed = false;
+                if (event.CmdDown())
+                {
+                    long pos = wxRichTextCtrl::FindNextWordPosition(-1);
+                    if (pos != -1 && (pos < newPos))
+                    {
+                        GetBuffer().DeleteRangeWithUndo(wxRichTextRange(pos+1, newPos), this);
+                        processed = true;
+                    }
+                }
+
+                if (!processed)
+                    GetBuffer().DeleteRangeWithUndo(wxRichTextRange(newPos, newPos), this);
+            }
+
+            EndBatchUndo();
+
+            if (GetLastPosition() == -1)
+            {
+                GetBuffer().Reset();
+
+                m_caretPosition = -1;
+                PositionCaret();
+                SetDefaultStyleToCursorStyle();
+            }
+
+            ScrollIntoView(m_caretPosition, WXK_LEFT);
+
+            wxRichTextEvent cmdEvent(
+                wxEVT_COMMAND_RICHTEXT_DELETE,
+                GetId());
+            cmdEvent.SetEventObject(this);
+            cmdEvent.SetFlags(flags);
+            cmdEvent.SetPosition(m_caretPosition+1);
+            GetEventHandler()->ProcessEvent(cmdEvent);
+
+            Update();
+        }
+        else
+            event.Skip();
+
+        return;
+    }
+
     if (event.GetKeyCode() == WXK_LEFT ||
         event.GetKeyCode() == WXK_RIGHT ||
         event.GetKeyCode() == WXK_UP ||
@@ -686,7 +746,6 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
 
     if (event.GetKeyCode() == WXK_RETURN)
     {
-        SetDefaultStyleToCursorStyle();
         BeginBatchUndo(_("Insert Text"));
 
         long newPos = m_caretPosition;
@@ -698,11 +757,14 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
             wxString text;
             text = wxRichTextLineBreakChar;
             GetBuffer().InsertTextWithUndo(newPos+1, text, this);
+            m_caretAtLineStart = true;
+            PositionCaret();
         }
         else
             GetBuffer().InsertNewlineWithUndo(newPos+1, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE|wxRICHTEXT_INSERT_INTERACTIVE);
 
         EndBatchUndo();
+        SetDefaultStyleToCursorStyle();
 
         ScrollIntoView(m_caretPosition, WXK_RIGHT);
 
@@ -727,26 +789,28 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
     {
         BeginBatchUndo(_("Delete Text"));
 
+        long newPos = m_caretPosition;
+
+        DeleteSelectedContent(& newPos);
+
         // Submit range in character positions, which are greater than caret positions,
         // so subtract 1 for deleted character and add 1 for conversion to character position.
-        if (m_caretPosition > -1 && !HasSelection())
+        if (newPos > -1)
         {
             bool processed = false;
             if (event.CmdDown())
             {
                 long pos = wxRichTextCtrl::FindNextWordPosition(-1);
-                if (pos != -1 && (pos < m_caretPosition))
+                if (pos != -1 && (pos < newPos))
                 {
-                    GetBuffer().DeleteRangeWithUndo(wxRichTextRange(pos+1, m_caretPosition), this);
+                    GetBuffer().DeleteRangeWithUndo(wxRichTextRange(pos+1, newPos), this);
                     processed = true;
                 }
             }
 
             if (!processed)
-                GetBuffer().DeleteRangeWithUndo(wxRichTextRange(m_caretPosition, m_caretPosition), this);
+                GetBuffer().DeleteRangeWithUndo(wxRichTextRange(newPos, newPos), this);
         }
-        else
-            DeleteSelectedContent();
 
         EndBatchUndo();
 
@@ -756,6 +820,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
 
             m_caretPosition = -1;
             PositionCaret();
+            SetDefaultStyleToCursorStyle();
         }
 
         ScrollIntoView(m_caretPosition, WXK_LEFT);
@@ -774,13 +839,27 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
     {
         BeginBatchUndo(_("Delete Text"));
 
+        long newPos = m_caretPosition;
+
+        DeleteSelectedContent(& newPos);
+
         // Submit range in character positions, which are greater than caret positions,
-        if (m_caretPosition < GetBuffer().GetRange().GetEnd()+1 && !HasSelection())
+        if (newPos < GetBuffer().GetRange().GetEnd()+1)
         {
-            GetBuffer().DeleteRangeWithUndo(wxRichTextRange(m_caretPosition+1, m_caretPosition+1), this);
+            bool processed = false;
+            if (event.CmdDown())
+            {
+                long pos = wxRichTextCtrl::FindNextWordPosition(1);
+                if (pos != -1 && (pos > newPos))
+                {
+                    GetBuffer().DeleteRangeWithUndo(wxRichTextRange(newPos+1, pos), this);
+                    processed = true;
+                }
+            }
+
+            if (!processed)
+                GetBuffer().DeleteRangeWithUndo(wxRichTextRange(newPos+1, newPos+1), this);
         }
-        else
-            DeleteSelectedContent();
 
         EndBatchUndo();
 
@@ -790,6 +869,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
 
             m_caretPosition = -1;
             PositionCaret();
+            SetDefaultStyleToCursorStyle();
         }
 
         wxRichTextEvent cmdEvent(
@@ -951,7 +1031,6 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
                     }
                 }
 
-                SetDefaultStyleToCursorStyle();
                 BeginBatchUndo(_("Insert Text"));
 
                 long newPos = m_caretPosition;
@@ -966,6 +1045,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
 
                 EndBatchUndo();
 
+                SetDefaultStyleToCursorStyle();
                 ScrollIntoView(m_caretPosition, WXK_RIGHT);
 
                 GetEventHandler()->ProcessEvent(cmdEvent);
@@ -1082,6 +1162,7 @@ bool wxRichTextCtrl::KeyboardNavigate(int keyCode, int flags)
     if (success)
     {
         ScrollIntoView(m_caretPosition, keyCode);
+        SetDefaultStyleToCursorStyle();
     }
 
     return success;
@@ -1092,6 +1173,9 @@ bool wxRichTextCtrl::ExtendSelection(long oldPos, long newPos, int flags)
 {
     if (flags & wxRICHTEXT_SHIFT_DOWN)
     {
+        if (oldPos == newPos)
+            return false;
+
         wxRichTextRange oldSelection = m_selectionRange;
 
         // If not currently selecting, start selecting
@@ -1110,6 +1194,8 @@ bool wxRichTextCtrl::ExtendSelection(long oldPos, long newPos, int flags)
             // the end.
             if (newPos > m_selectionAnchor)
                 m_selectionRange.SetRange(m_selectionAnchor+1, newPos);
+            else if (newPos == m_selectionAnchor)
+                m_selectionRange = wxRichTextRange(-2, -2);
             else
                 m_selectionRange.SetRange(newPos+1, m_selectionAnchor);
         }
@@ -1303,11 +1389,13 @@ void wxRichTextCtrl::MoveCaretForward(long oldPosition)
                     m_caretPosition = oldPosition;
                     m_caretAtLineStart = true;
                 }
+                SetDefaultStyleToCursorStyle();
                 return;
             }
         }
     }
     m_caretPosition ++;
+    SetDefaultStyleToCursorStyle();
 }
 
 /// Move caret one visual step backward: this may mean setting a flag
@@ -1351,11 +1439,13 @@ void wxRichTextCtrl::MoveCaretBack(long oldPosition)
                     // to the previous character position.
                     m_caretPosition = oldPosition - 1;
                 }
+                SetDefaultStyleToCursorStyle();
                 return;
             }
         }
     }
     m_caretPosition --;
+    SetDefaultStyleToCursorStyle();
 }
 
 /// Move right
@@ -1383,6 +1473,7 @@ bool wxRichTextCtrl::MoveRight(int noPositions, int flags)
             SetCaretPosition(newPos);
 
         PositionCaret();
+        SetDefaultStyleToCursorStyle();
 
         return true;
     }
@@ -1409,6 +1500,7 @@ bool wxRichTextCtrl::MoveLeft(int noPositions, int flags)
             SetCaretPosition(newPos);
 
         PositionCaret();
+        SetDefaultStyleToCursorStyle();
 
         return true;
     }
@@ -1497,6 +1589,7 @@ bool wxRichTextCtrl::MoveDown(int noLines, int flags)
 
         SetCaretPosition(newPos, caretLineStart);
         PositionCaret();
+        SetDefaultStyleToCursorStyle();
 
         return true;
     }
@@ -1517,6 +1610,7 @@ bool wxRichTextCtrl::MoveToParagraphEnd(int flags)
 
         SetCaretPosition(newPos);
         PositionCaret();
+        SetDefaultStyleToCursorStyle();
 
         return true;
     }
@@ -1537,6 +1631,7 @@ bool wxRichTextCtrl::MoveToParagraphStart(int flags)
 
         SetCaretPosition(newPos);
         PositionCaret();
+        SetDefaultStyleToCursorStyle();
 
         return true;
     }
@@ -1559,6 +1654,7 @@ bool wxRichTextCtrl::MoveToLineEnd(int flags)
 
         SetCaretPosition(newPos);
         PositionCaret();
+        SetDefaultStyleToCursorStyle();
 
         return true;
     }
@@ -1583,6 +1679,7 @@ bool wxRichTextCtrl::MoveToLineStart(int flags)
 
         SetCaretPosition(newPos, para->GetRange().GetStart() != lineRange.GetStart());
         PositionCaret();
+        SetDefaultStyleToCursorStyle();
 
         return true;
     }
@@ -1601,6 +1698,7 @@ bool wxRichTextCtrl::MoveHome(int flags)
 
         SetCaretPosition(-1);
         PositionCaret();
+        SetDefaultStyleToCursorStyle();
 
         return true;
     }
@@ -1621,6 +1719,7 @@ bool wxRichTextCtrl::MoveEnd(int flags)
 
         SetCaretPosition(endPos);
         PositionCaret();
+        SetDefaultStyleToCursorStyle();
 
         return true;
     }
@@ -1659,6 +1758,7 @@ bool wxRichTextCtrl::PageDown(int noPages, int flags)
 
                 SetCaretPosition(pos, para->GetRange().GetStart() != lineRange.GetStart());
                 PositionCaret();
+                SetDefaultStyleToCursorStyle();
 
                 return true;
             }
@@ -1775,6 +1875,7 @@ bool wxRichTextCtrl::WordLeft(int WXUNUSED(n), int flags)
 
         SetCaretPosition(pos, para->GetRange().GetStart() != pos);
         PositionCaret();
+        SetDefaultStyleToCursorStyle();
 
         return true;
     }
@@ -1796,6 +1897,7 @@ bool wxRichTextCtrl::WordRight(int WXUNUSED(n), int flags)
 
         SetCaretPosition(pos, para->GetRange().GetStart() != pos);
         PositionCaret();
+        SetDefaultStyleToCursorStyle();
 
         return true;
     }
@@ -1969,7 +2071,7 @@ bool wxRichTextCtrl::RecreateBuffer(const wxSize& size)
 
 bool wxRichTextCtrl::DoLoadFile(const wxString& filename, int fileType)
 {
-    bool success = GetBuffer().LoadFile(filename, fileType);
+    bool success = GetBuffer().LoadFile(filename, (wxRichTextFileType)fileType);
     if (success)
         m_filename = filename;
 
@@ -1993,7 +2095,7 @@ bool wxRichTextCtrl::DoLoadFile(const wxString& filename, int fileType)
 
 bool wxRichTextCtrl::DoSaveFile(const wxString& filename, int fileType)
 {
-    if (GetBuffer().SaveFile(filename, fileType))
+    if (GetBuffer().SaveFile(filename, (wxRichTextFileType)fileType))
     {
         m_filename = filename;
 
@@ -2104,6 +2206,7 @@ bool wxRichTextCtrl::SelectWord(long position)
     if (positionStart >= 0)
     {
         MoveCaret(positionStart-1, true);
+        SetDefaultStyleToCursorStyle();
     }
 
     return true;
@@ -2221,7 +2324,6 @@ void wxRichTextCtrl::DoWriteText(const wxString& value, int flags)
 {
     wxString valueUnix = wxTextFile::Translate(value, wxTextFileType_Unix);
 
-    SetDefaultStyleToCursorStyle();
     GetBuffer().InsertTextWithUndo(m_caretPosition+1, valueUnix, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE);
 
     if ( flags & SetValue_SendEvent )
@@ -2236,7 +2338,7 @@ void wxRichTextCtrl::AppendText(const wxString& text)
 }
 
 /// Write an image at the current insertion point
-bool wxRichTextCtrl::WriteImage(const wxImage& image, int bitmapType)
+bool wxRichTextCtrl::WriteImage(const wxImage& image, wxBitmapType bitmapType)
 {
     wxRichTextImageBlock imageBlock;
 
@@ -2247,7 +2349,7 @@ bool wxRichTextCtrl::WriteImage(const wxImage& image, int bitmapType)
     return false;
 }
 
-bool wxRichTextCtrl::WriteImage(const wxString& filename, int bitmapType)
+bool wxRichTextCtrl::WriteImage(const wxString& filename, wxBitmapType bitmapType)
 {
     wxRichTextImageBlock imageBlock;
 
@@ -2263,7 +2365,7 @@ bool wxRichTextCtrl::WriteImage(const wxRichTextImageBlock& imageBlock)
     return GetBuffer().InsertImageWithUndo(m_caretPosition+1, imageBlock, this);
 }
 
-bool wxRichTextCtrl::WriteImage(const wxBitmap& bitmap, int bitmapType)
+bool wxRichTextCtrl::WriteImage(const wxBitmap& bitmap, wxBitmapType bitmapType)
 {
     if (bitmap.Ok())
     {
@@ -2280,7 +2382,7 @@ bool wxRichTextCtrl::WriteImage(const wxBitmap& bitmap, int bitmapType)
 /// Insert a newline (actually paragraph) at the current insertion point.
 bool wxRichTextCtrl::Newline()
 {
-    return GetBuffer().InsertNewlineWithUndo(m_caretPosition+1, this);
+    return GetBuffer().InsertNewlineWithUndo(m_caretPosition+1, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE);
 }
 
 /// Insert a line break at the current insertion point.
@@ -2321,7 +2423,6 @@ void wxRichTextCtrl::Paste()
 {
     if (CanPaste())
     {
-        SetDefaultStyleToCursorStyle();
         BeginBatchUndo(_("Paste"));
 
         long newPos = m_caretPosition;