X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b01ca8b6a9b2828aa7fe6399d8920951c24661ce..cc57f388d769cba09debd611d1e5e5f6d28aee41:/src/richtext/richtextctrl.cpp diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index e4ec1418d0..b414fa7bb5 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: richtext/richeditctrl.cpp +// Name: src/richtext/richeditctrl.cpp // Purpose: A rich edit control // Author: Julian Smart // Modified by: @@ -13,7 +13,7 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ - #pragma hdrstop + #pragma hdrstop #endif #if wxUSE_RICHTEXT @@ -21,12 +21,12 @@ #include "wx/richtext/richtextctrl.h" #ifndef WX_PRECOMP - #include "wx/wx.h" + #include "wx/wx.h" + #include "wx/settings.h" #endif #include "wx/textfile.h" #include "wx/ffile.h" -#include "wx/settings.h" #include "wx/filename.h" #include "wx/dcbuffer.h" #include "wx/arrimpl.cpp" @@ -222,19 +222,19 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) { wxBufferedPaintDC dc(this, m_bufferBitmap); //wxLogDebug(wxT("OnPaint")); - + PrepareDC(dc); - + if (m_freezeCount > 0) return; - + dc.SetFont(GetFont()); - + // Paint the background PaintBackground(dc); - + wxRegion dirtyRegion = GetUpdateRegion(); - + wxRect drawingArea(GetLogicalPoint(wxPoint(0, 0)), GetClientSize()); wxRect availableSpace(GetClientSize()); if (GetBuffer().GetDirty()) @@ -243,7 +243,7 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) GetBuffer().SetDirty(false); SetupScrollbars(); } - + GetBuffer().Draw(dc, GetBuffer().GetRange(), GetSelectionRange(), drawingArea, 0 /* descent */, 0 /* flags */); } @@ -429,13 +429,21 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) event.GetKeyCode() == WXK_HOME || event.GetKeyCode() == WXK_PAGEUP || event.GetKeyCode() == WXK_PAGEDOWN || - event.GetKeyCode() == WXK_PRIOR || - event.GetKeyCode() == WXK_NEXT || event.GetKeyCode() == WXK_END) { KeyboardNavigate(event.GetKeyCode(), flags); + return; } - else if (event.GetKeyCode() == WXK_RETURN) + + // all the other keys modify the controls contents which shouldn't be + // possible if we're read-only + if ( !IsEditable() ) + { + event.Skip(); + return; + } + + if (event.GetKeyCode() == WXK_RETURN) { BeginBatchUndo(_("Insert Text")); @@ -454,6 +462,8 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) EndBatchUndo(); SetDefaultStyleToCursorStyle(); + + ScrollIntoView(m_caretPosition, WXK_RIGHT); } else if (event.GetKeyCode() == WXK_BACK) { @@ -483,6 +493,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) SetDefaultStyleToCursorStyle(); } + ScrollIntoView(m_caretPosition, WXK_LEFT); } else if (event.GetKeyCode() == WXK_DELETE) { @@ -524,11 +535,8 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) EndBatchUndo(); SetDefaultStyleToCursorStyle(); + ScrollIntoView(m_caretPosition, WXK_RIGHT); } -#if 0 - else - event.Skip(); -#endif } /// Delete content if there is a selection, e.g. when pressing a key. @@ -614,11 +622,11 @@ bool wxRichTextCtrl::KeyboardNavigate(int keyCode, int flags) else success = MoveDown(1, flags); } - else if (keyCode == WXK_PAGEUP || keyCode == WXK_PRIOR) + else if (keyCode == WXK_PAGEUP) { success = PageUp(1, flags); } - else if (keyCode == WXK_PAGEDOWN || keyCode == WXK_NEXT) + else if (keyCode == WXK_PAGEDOWN) { success = PageDown(1, flags); } @@ -699,7 +707,7 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) startX = 0; startY = startY * ppuY; - int sx, sy; + int sx = 0, sy = 0; GetVirtualSize(& sx, & sy); sx = 0; if (ppuY != 0) @@ -712,7 +720,7 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) wxSize clientSize = GetClientSize(); // Going down - if (keyCode == WXK_DOWN || keyCode == WXK_RIGHT || keyCode == WXK_END || keyCode == WXK_NEXT || keyCode == WXK_PAGEDOWN) + if (keyCode == WXK_DOWN || keyCode == WXK_RIGHT || keyCode == WXK_END || keyCode == WXK_PAGEDOWN) { if ((rect.y + rect.height) > (clientSize.y + startY)) { @@ -742,7 +750,7 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode) } } // Going up - else if (keyCode == WXK_UP || keyCode == WXK_LEFT || keyCode == WXK_HOME || keyCode == WXK_PRIOR || keyCode == WXK_PAGEUP) + else if (keyCode == WXK_UP || keyCode == WXK_LEFT || keyCode == WXK_HOME || keyCode == WXK_PAGEUP ) { if (rect.y < startY) { @@ -792,7 +800,7 @@ bool wxRichTextCtrl::IsPositionVisible(long pos) const startX = 0; startY = startY * ppuY; - int sx, sy; + int sx = 0, sy = 0; GetVirtualSize(& sx, & sy); sx = 0; if (ppuY != 0) @@ -1057,8 +1065,8 @@ bool wxRichTextCtrl::MoveDown(int noLines, int flags) Refresh(false); return true; } - else - return false; + + return false; } /// Move to the end of the paragraph @@ -1577,17 +1585,20 @@ wxString wxRichTextCtrl::GetStringSelection() const } // do the window-specific processing after processing the update event +#if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE void wxRichTextCtrl::DoUpdateWindowUI(wxUpdateUIEvent& event) { - if ( event.GetSetEnabled() ) - Enable(event.GetEnabled()); + // call inherited + wxWindowBase::DoUpdateWindowUI(event); + // update text if ( event.GetSetText() ) { if ( event.GetText() != GetValue() ) SetValue(event.GetText()); } } +#endif // !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE // ---------------------------------------------------------------------------- // hit testing @@ -1618,14 +1629,20 @@ wxRichTextCtrl::HitTest(const wxPoint& pt, ((wxRichTextCtrl*)this)->PrepareDC(dc); int hit = ((wxRichTextCtrl*)this)->GetBuffer().HitTest(dc, pt, *pos); - if (hit == wxRICHTEXT_HITTEST_BEFORE) - return wxTE_HT_BEFORE; - else if (hit == wxRICHTEXT_HITTEST_AFTER) - return wxTE_HT_BEYOND; - else if (hit == wxRICHTEXT_HITTEST_ON) - return wxTE_HT_ON_TEXT; - else - return wxTE_HT_UNKNOWN; + + switch ( hit ) + { + case wxRICHTEXT_HITTEST_BEFORE: + return wxTE_HT_BEFORE; + + case wxRICHTEXT_HITTEST_AFTER: + return wxTE_HT_BEYOND; + + case wxRICHTEXT_HITTEST_ON: + return wxTE_HT_ON_TEXT; + } + + return wxTE_HT_UNKNOWN; } // ---------------------------------------------------------------------------- @@ -1695,8 +1712,8 @@ bool wxRichTextCtrl::WriteImage(const wxImage& image, int bitmapType) wxImage image2 = image; if (imageBlock.MakeImageBlock(image2, bitmapType)) return WriteImage(imageBlock); - else - return false; + + return false; } bool wxRichTextCtrl::WriteImage(const wxString& filename, int bitmapType) @@ -1706,8 +1723,8 @@ bool wxRichTextCtrl::WriteImage(const wxString& filename, int bitmapType) wxImage image; if (imageBlock.MakeImageBlock(filename, bitmapType, image, false)) return WriteImage(imageBlock); - else - return false; + + return false; } bool wxRichTextCtrl::WriteImage(const wxRichTextImageBlock& imageBlock) @@ -1724,9 +1741,8 @@ bool wxRichTextCtrl::WriteImage(const wxBitmap& bitmap, int bitmapType) wxImage image = bitmap.ConvertToImage(); if (image.Ok() && imageBlock.MakeImageBlock(image, bitmapType)) return WriteImage(imageBlock); - else - return false; } + return false; } @@ -2254,8 +2270,8 @@ bool wxRichTextCtrl::GetCaretPositionForIndex(long position, wxRect& rect) rect = wxRect(pt, wxSize(wxRICHTEXT_DEFAULT_CARET_WIDTH, height)); return true; } - else - return false; + + return false; } /// Gets the line for the visible caret position. If the caret is @@ -2316,17 +2332,17 @@ bool wxRichTextCtrl::LayoutContent(bool onlyVisibleRect) flags |= wxRICHTEXT_LAYOUT_SPECIFIED_RECT; availableSpace.SetPosition(GetLogicalPoint(wxPoint(0, 0))); } - + wxClientDC dc(this); dc.SetFont(GetFont()); - + PrepareDC(dc); - + GetBuffer().Defragment(); GetBuffer().UpdateRanges(); // If items were deleted, ranges need recalculation GetBuffer().Layout(dc, availableSpace, flags); GetBuffer().SetDirty(false); - + if (!IsFrozen()) SetupScrollbars(); } @@ -2505,8 +2521,8 @@ bool wxRichTextCtrl::SetDefaultStyleToCursorStyle() SetDefaultStyle(attr); return true; } - else - return false; + + return false; } /// Returns the first visible position in the current view @@ -2521,4 +2537,3 @@ long wxRichTextCtrl::GetFirstVisiblePosition() const #endif // wxUSE_RICHTEXT -