X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4427f297a61887e0161fdf7a40b545620d19061c..2028c33ab5a39a12bd410ac953731a56ad6377ba:/src/richtext/richtextctrl.cpp diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 622a4ef502..be2bc269ee 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -289,6 +289,17 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va wxAcceleratorTable accel(6, entries); SetAcceleratorTable(accel); + m_contextMenu = new wxMenu; + m_contextMenu->Append(wxID_UNDO, _("&Undo")); + m_contextMenu->Append(wxID_REDO, _("&Redo")); + m_contextMenu->AppendSeparator(); + m_contextMenu->Append(wxID_CUT, _("Cu&t")); + m_contextMenu->Append(wxID_COPY, _("&Copy")); + m_contextMenu->Append(wxID_PASTE, _("&Paste")); + m_contextMenu->Append(wxID_CLEAR, _("&Delete")); + m_contextMenu->AppendSeparator(); + m_contextMenu->Append(wxID_SELECTALL, _("Select &All")); + return true; } @@ -952,7 +963,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) } } - if (!processed) + if (!processed && newPos < (GetLastPosition()-1)) GetBuffer().DeleteRangeWithUndo(wxRichTextRange(newPos+1, newPos+1), this); } @@ -1068,7 +1079,15 @@ bool wxRichTextCtrl::DeleteSelectedContent(long* newPos) if (HasSelection()) { long pos = m_selectionRange.GetStart(); - GetBuffer().DeleteRangeWithUndo(m_selectionRange, this); + wxRichTextRange range = m_selectionRange; + + // SelectAll causes more to be selected than doing it interactively, + // and causes a new paragraph to be inserted. So for multiline buffers, + // don't delete the final position. + if (range.GetEnd() == GetLastPosition() && GetNumberOfLines() > 0) + range.SetEnd(range.GetEnd()-1); + + GetBuffer().DeleteRangeWithUndo(range, this); m_selectionRange.SetRange(-2, -2); if (newPos) @@ -2048,7 +2067,7 @@ void wxRichTextCtrl::SetupScrollbars(bool atTop) return; // Don't set scrollbars if there were none before, and there will be none now. - if (oldPPUY != 0 && (oldVirtualSizeY < clientSize.y) && (unitsY*pixelsPerUnit < clientSize.y)) + if (oldPPUY != 0 && (oldVirtualSizeY*oldPPUY < clientSize.y) && (unitsY*pixelsPerUnit < clientSize.y)) return; // Move to previous scroll position if @@ -2163,8 +2182,7 @@ wxRichTextRange wxRichTextCtrl::AddImage(const wxImage& image) void wxRichTextCtrl::SelectAll() { - SetSelection(0, GetLastPosition()+1); - m_selectionAnchor = -1; + SetSelection(-1, -1); } /// Select none @@ -2504,6 +2522,13 @@ bool wxRichTextCtrl::CanDeleteSelection() const // Accessors // ---------------------------------------------------------------------------- +void wxRichTextCtrl::SetContextMenu(wxMenu* menu) +{ + if (m_contextMenu && m_contextMenu != menu) + delete m_contextMenu; + m_contextMenu = menu; +} + void wxRichTextCtrl::SetEditable(bool editable) { m_editable = editable; @@ -2572,10 +2597,10 @@ void wxRichTextCtrl::SetSelection(long from, long to) else { wxRichTextRange oldSelection = m_selectionRange; - m_selectionAnchor = from; + m_selectionAnchor = from-1; m_selectionRange.SetRange(from, to-1); - if (from > -2) - m_caretPosition = from-1; + + m_caretPosition = wxMax(-1, to-2); RefreshForSelectionChange(oldSelection, m_selectionRange); PositionCaret(); @@ -2787,7 +2812,8 @@ void wxRichTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) void wxRichTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event)) { - SelectAll(); + if (GetLastPosition() > 0) + SelectAll(); } void wxRichTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) @@ -2803,20 +2829,8 @@ void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent& event) return; } - if (!m_contextMenu) - { - m_contextMenu = new wxMenu; - m_contextMenu->Append(wxID_UNDO, _("&Undo")); - m_contextMenu->Append(wxID_REDO, _("&Redo")); - m_contextMenu->AppendSeparator(); - m_contextMenu->Append(wxID_CUT, _("Cu&t")); - m_contextMenu->Append(wxID_COPY, _("&Copy")); - m_contextMenu->Append(wxID_PASTE, _("&Paste")); - m_contextMenu->Append(wxID_CLEAR, _("&Delete")); - m_contextMenu->AppendSeparator(); - m_contextMenu->Append(wxID_SELECTALL, _("Select &All")); - } - PopupMenu(m_contextMenu); + if (m_contextMenu) + PopupMenu(m_contextMenu); return; } @@ -3338,13 +3352,7 @@ wxRichTextRange wxRichTextCtrl::GetSelectionRange() const void wxRichTextCtrl::SetSelectionRange(const wxRichTextRange& range) { - wxRichTextRange range1(range); - if (range1 != wxRichTextRange(-2,-2) && range1 != wxRichTextRange(-1,-1) ) - range1.SetEnd(range1.GetEnd() - 1); - - wxASSERT( range1.GetStart() > range1.GetEnd() ); - - SetInternalSelectionRange(range1); + SetSelection(range.GetStart(), range.GetEnd()); } /// Set list style