#pragma hdrstop
#endif
+#if wxUSE_RICHTEXT
+
+#include "wx/richtext/richtextctrl.h"
+
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
-#include "wx/image.h"
-
-#if wxUSE_RICHTEXT
-
#include "wx/textfile.h"
#include "wx/ffile.h"
#include "wx/settings.h"
#include "wx/filename.h"
#include "wx/dcbuffer.h"
-
-#include "wx/richtext/richtextctrl.h"
#include "wx/arrimpl.cpp"
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED)
}
/// Call Thaw to refresh
-void wxRichTextCtrl::Thaw(bool refresh)
+void wxRichTextCtrl::Thaw()
{
m_freezeCount --;
- if (m_freezeCount == 0 && refresh)
+ if (m_freezeCount == 0)
{
SetupScrollbars();
- Refresh();
+ Refresh(false);
}
}
if (m_freezeCount == 0)
{
SetupScrollbars();
- Refresh();
+ Refresh(false);
}
SendUpdateEvent();
}
{
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())
GetBuffer().SetDirty(false);
SetupScrollbars();
}
-
+
GetBuffer().Draw(dc, GetBuffer().GetRange(), GetSelectionRange(), drawingArea, 0 /* descent */, 0 /* flags */);
}
PositionCaret();
if (!IsFrozen())
- Refresh();
+ Refresh(false);
}
void wxRichTextCtrl::OnKillFocus(wxFocusEvent& WXUNUSED(event))
SetCaret(NULL);
if (!IsFrozen())
- Refresh();
+ Refresh(false);
}
/// Left-click
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
}
}
}
event.GetKeyCode() == WXK_NEXT ||
event.GetKeyCode() == WXK_END)
{
- Navigate(event.GetKeyCode(), flags);
+ KeyboardNavigate(event.GetKeyCode(), flags);
}
else if (event.GetKeyCode() == WXK_RETURN)
{
EndBatchUndo();
SetDefaultStyleToCursorStyle();
+
+ ScrollIntoView(m_caretPosition, WXK_RIGHT);
}
else if (event.GetKeyCode() == WXK_BACK)
{
SetDefaultStyleToCursorStyle();
}
+ ScrollIntoView(m_caretPosition, WXK_LEFT);
}
else if (event.GetKeyCode() == WXK_DELETE)
{
EndBatchUndo();
SetDefaultStyleToCursorStyle();
+ ScrollIntoView(m_caretPosition, WXK_RIGHT);
}
#if 0
else
*/
-bool wxRichTextCtrl::Navigate(int keyCode, int flags)
+bool wxRichTextCtrl::KeyboardNavigate(int keyCode, int flags)
{
bool success = false;
- Freeze();
if (keyCode == WXK_RIGHT)
{
SetDefaultStyleToCursorStyle();
}
- Thaw(false);
-
return success;
}
startX = 0;
startY = startY * ppuY;
- int sx, sy;
+ int sx = 0, sy = 0;
GetVirtualSize(& sx, & sy);
sx = 0;
if (ppuY != 0)
startX = 0;
startY = startY * ppuY;
- int sx, sy;
+ int sx = 0, sy = 0;
GetVirtualSize(& sx, & sy);
sx = 0;
if (ppuY != 0)
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
return true;
}
else
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
return true;
}
else
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
return true;
}
- else
- return false;
+
+ return false;
}
/// Move to the end of the paragraph
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
return true;
}
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
return true;
}
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
return true;
}
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
return true;
}
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
return true;
}
else
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
return true;
}
else
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
return true;
}
}
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
return true;
}
SetDefaultStyleToCursorStyle();
if (extendSel)
- Refresh();
+ Refresh(false);
return true;
}
m_fullLayoutRequired = true;
m_fullLayoutTime = wxGetLocalTimeMillis();
m_fullLayoutSavedPosition = GetFirstVisiblePosition();
- Layout(true /* onlyVisibleRect */);
+ LayoutContent(true /* onlyVisibleRect */);
}
else
GetBuffer().Invalidate(wxRICHTEXT_ALL);
m_fullLayoutTime = 0;
GetBuffer().Invalidate(wxRICHTEXT_ALL);
ShowPosition(m_fullLayoutSavedPosition);
- Refresh();
+ Refresh(false);
}
event.Skip();
}
DiscardEdits();
SetInsertionPoint(0);
- Layout();
+ LayoutContent();
PositionCaret();
SetupScrollbars(true);
- Refresh();
+ Refresh(false);
SendUpdateEvent();
if (success)
}
// 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
((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;
}
// ----------------------------------------------------------------------------
wxImage image2 = image;
if (imageBlock.MakeImageBlock(image2, bitmapType))
return WriteImage(imageBlock);
- else
- return false;
+
+ return false;
}
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)
wxImage image = bitmap.ConvertToImage();
if (image.Ok() && imageBlock.MakeImageBlock(image, bitmapType))
return WriteImage(imageBlock);
- else
- return false;
}
+
return false;
}
GetBuffer().CopyToClipboard(range);
DeleteSelectedContent();
- Layout();
- Refresh();
+ LayoutContent();
+ Refresh(false);
}
}
{
m_selectionAnchor = from;
m_selectionRange.SetRange(from, to);
- Refresh();
+ Refresh(false);
PositionCaret();
}
from, // New caret position
this);
- Layout();
+ LayoutContent();
if (!IsFrozen())
- Refresh();
+ Refresh(false);
}
bool wxRichTextCtrl::IsModified() const
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
bool wxRichTextCtrl::MoveCaret(long pos, bool showAtLineStart)
{
if (GetBuffer().GetDirty())
- Layout();
+ LayoutContent();
if (pos <= GetBuffer().GetRange().GetEnd())
{
/// Layout the buffer: which we must do before certain operations, such as
/// setting the caret position.
-bool wxRichTextCtrl::Layout(bool onlyVisibleRect)
+bool wxRichTextCtrl::LayoutContent(bool onlyVisibleRect)
{
if (GetBuffer().GetDirty() || 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();
}
SetDefaultStyle(attr);
return true;
}
- else
- return false;
+
+ return false;
}
/// Returns the first visible position in the current view