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;
}
}
}
- if (!processed)
+ if (!processed && newPos < (GetLastPosition()-1))
GetBuffer().DeleteRangeWithUndo(wxRichTextRange(newPos+1, newPos+1), this);
}
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)
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
void wxRichTextCtrl::SelectAll()
{
- SetSelection(0, GetLastPosition()+1);
- m_selectionAnchor = -1;
+ SetSelection(-1, -1);
}
/// Select none
// 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;
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();
void wxRichTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event))
{
- SelectAll();
+ if (GetLastPosition() > 0)
+ SelectAll();
}
void wxRichTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& 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;
}
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