/////////////////////////////////////////////////////////////////////////////
-// Name: src/richtext/richeditctrl.cpp
+// Name: src/richtext/richtextctrl.cpp
// Purpose: A rich edit control
// Author: Julian Smart
// Modified by:
validator, name))
return false;
- if (!GetFont().Ok())
+ if (!GetFont().IsOk())
{
SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
}
attributes.SetLineSpacing(10);
attributes.SetParagraphSpacingAfter(10);
attributes.SetParagraphSpacingBefore(0);
-
+
SetBasicStyle(attributes);
int margin = 5;
int flags = 0;
if ((GetExtraStyle() & wxRICHTEXT_EX_NO_GUIDELINES) == 0)
flags |= wxRICHTEXT_DRAW_GUIDELINES;
-
+
GetBuffer().Draw(dc, GetBuffer().GetOwnRange(), GetSelection(), drawingArea, 0 /* descent */, flags);
dc.DestroyClippingRegion();
MoveCaret(position, caretAtLineStart);
SetDefaultStyleToCursorStyle();
-
+
return true;
}
{
SetFocusObject(container, false /* don't set caret position yet */);
}
-
+
m_dragStart = event.GetLogicalPosition(dc);
m_dragging = true;
CaptureMouse();
wxPoint logicalPt = event.GetLogicalPosition(dc);
wxRichTextObject* hitObj = NULL;
wxRichTextObject* contextObj = NULL;
-
+
int flags = 0;
-
+
// If we're dragging, let's only consider positions at this level; otherwise
// selecting a range is not going to work.
wxRichTextParagraphLayoutBox* container = & GetBuffer();
container = GetFocusObject();
}
int hit = container->HitTest(dc, logicalPt, position, & hitObj, & contextObj, flags);
-
+
// See if we need to change the cursor
{
event.Skip();
return;
}
-
+
if (m_dragging)
{
wxRichTextParagraphLayoutBox* commonAncestor = NULL;
// is the common ancestor.
commonAncestor = wxDynamicCast(firstContainer->GetParent(), wxRichTextParagraphLayoutBox);
}
-
+
if (commonAncestor && commonAncestor->HandlesChildSelections())
{
wxRichTextObject* p = hitObj2;
if (otherContainer->AcceptsFocus())
SetFocusObject(otherContainer, false /* don't set caret and clear selection */);
- MoveCaret(-1, false);
+ MoveCaret(-1, false);
SetDefaultStyleToCursorStyle();
}
}
void wxRichTextCtrl::OnRightClick(wxMouseEvent& event)
{
SetFocus();
-
+
wxClientDC dc(this);
PrepareDC(dc);
dc.SetFont(GetFont());
SetDefaultStyleToCursorStyle();
ScrollIntoView(m_caretPosition, WXK_RIGHT);
+ cmdEvent.SetPosition(m_caretPosition);
GetEventHandler()->ProcessEvent(cmdEvent);
Update();
return false;
wxRichTextSelection oldSelection = m_selection;
-
+
m_selection.SetContainer(GetFocusObject());
-
+
wxRichTextRange oldRange;
if (m_selection.IsValid())
oldRange = m_selection.GetRange();
else
newRange.SetRange(newPos+1, m_selectionAnchor);
}
-
+
m_selection.SetRange(newRange);
RefreshForSelectionChange(oldSelection, m_selection);
bool scrolled = false;
wxSize clientSize = GetClientSize();
-
+
int leftMargin, rightMargin, topMargin, bottomMargin;
{
wxSize clientSize = GetClientSize();
clientSize.y -= GetBuffer().GetBottomMargin();
- return (rect.GetBottom() > (startY + GetBuffer().GetTopMargin())) && (rect.GetTop() < (startY + clientSize.y));
+ return (rect.GetTop() >= (startY + GetBuffer().GetTopMargin())) && (rect.GetBottom() <= (startY + clientSize.y));
}
void wxRichTextCtrl::SetCaretPosition(long position, bool showAtLineStart)
long lineNumber = GetFocusObject()->GetVisibleLineNumber(m_caretPosition, true, m_caretAtLineStart);
wxPoint pt = GetCaret()->GetPosition();
- long newLine = lineNumber + noLines;
+ long newLine = lineNumber + noLines;
bool notInThisObject = false;
if (lineNumber != -1)
notInThisObject = true;
}
}
-
+
wxRichTextParagraphLayoutBox* container = GetFocusObject();
- int hitTestFlags = wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS;
+ int hitTestFlags = wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS|wxRICHTEXT_HITTEST_NO_FLOATING_OBJECTS;
if (notInThisObject)
{
// If we know we're navigating out of the current object,
// try to find an object anywhere in the buffer at the new position (up or down a bit)
container = & GetBuffer();
- hitTestFlags = 0;
-
+ hitTestFlags &= ~wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS;
+
if (noLines > 0) // going down
{
pt.y = GetFocusObject()->GetPosition().y + GetFocusObject()->GetCachedSize().y + 2;
wxRichTextObject* contextObj = NULL;
int hitTest = container->HitTest(dc, pt, newPos, & hitObj, & contextObj, hitTestFlags);
- if (hitTest != wxRICHTEXT_HITTEST_NONE && hitObj)
+ if (hitObj &&
+ ((hitTest & wxRICHTEXT_HITTEST_NONE) == 0) &&
+ (! (hitObj == (& m_buffer) && ((hitTest & wxRICHTEXT_HITTEST_OUTSIDE) != 0))) // outside the buffer counts as 'do nothing'
+ )
{
if (notInThisObject)
{
if (actualContainer && actualContainer != GetFocusObject() && actualContainer->AcceptsFocus())
{
SetFocusObject(actualContainer, false /* don't set caret position yet */);
-
+
container = actualContainer;
}
}
-
+
bool caretLineStart = true;
long caretPosition = FindCaretPositionForCharacterPosition(newPos, hitTest, container, caretLineStart);
long newSelEnd = caretPosition;
event.Skip();
}
+// Force any pending layout due to large buffer
+void wxRichTextCtrl::ForceDelayedLayout()
+{
+ if (m_fullLayoutRequired)
+ {
+ m_fullLayoutRequired = false;
+ m_fullLayoutTime = 0;
+ GetBuffer().Invalidate(wxRICHTEXT_ALL);
+ ShowPosition(m_fullLayoutSavedPosition);
+ Refresh(false);
+ Update();
+ }
+}
/// Idle-time processing
void wxRichTextCtrl::OnIdle(wxIdleEvent& event)
void wxRichTextCtrl::PaintBackground(wxDC& dc)
{
wxColour backgroundColour = GetBackgroundColour();
- if (!backgroundColour.Ok())
+ if (!backgroundColour.IsOk())
backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
// Clear the background
if (sz.x < 1 || sz.y < 1)
return false;
- if (!m_bufferBitmap.Ok() || m_bufferBitmap.GetWidth() < sz.x || m_bufferBitmap.GetHeight() < sz.y)
+ if (!m_bufferBitmap.IsOk() || m_bufferBitmap.GetWidth() < sz.x || m_bufferBitmap.GetHeight() < sz.y)
m_bufferBitmap = wxBitmap(sz.x, sz.y);
- return m_bufferBitmap.Ok();
+ return m_bufferBitmap.IsOk();
}
#endif
wxRichTextRange wxRichTextCtrl::AddParagraph(const wxString& text)
{
wxRichTextRange range = GetFocusObject()->AddParagraph(text);
+ GetBuffer().Invalidate();
LayoutContent();
return range;
}
wxRichTextRange wxRichTextCtrl::AddImage(const wxImage& image)
{
wxRichTextRange range = GetFocusObject()->AddImage(image);
+ GetBuffer().Invalidate();
LayoutContent();
return range;
}
bool wxRichTextCtrl::WriteImage(const wxBitmap& bitmap, wxBitmapType bitmapType, const wxRichTextAttr& textAttr)
{
- if (bitmap.Ok())
+ if (bitmap.IsOk())
{
wxRichTextImageBlock imageBlock;
wxImage image = bitmap.ConvertToImage();
- if (image.Ok() && imageBlock.MakeImageBlock(image, bitmapType))
+ if (image.IsOk() && imageBlock.MakeImageBlock(image, bitmapType))
return WriteImage(imageBlock, textAttr);
}
wxRichTextTable* table = new wxRichTextTable;
table->SetAttributes(tableAttr);
table->SetParent(& GetBuffer()); // set parent temporarily for AddParagraph to use correct style
-
+
table->CreateTable(rows, cols);
table->SetParent(NULL);
bool wxRichTextCtrl::CanUndo() const
{
- return GetCommandProcessor()->CanUndo();
+ return GetCommandProcessor()->CanUndo() && IsEditable();
}
bool wxRichTextCtrl::CanRedo() const
{
- return GetCommandProcessor()->CanRedo();
+ return GetCommandProcessor()->CanRedo() && IsEditable();
}
// ----------------------------------------------------------------------------
wxRichTextObject* hitObj = NULL;
wxRichTextObject* contextObj = NULL;
int hit = GetFocusObject()->HitTest(dc, logicalPt, position, & hitObj, & contextObj);
-
+
m_contextMenuPropertiesInfo.Clear();
-
+
if (hit == wxRICHTEXT_HITTEST_ON || hit == wxRICHTEXT_HITTEST_BEFORE || hit == wxRICHTEXT_HITTEST_AFTER)
{
wxRichTextParagraphLayoutBox* actualContainer = wxDynamicCast(contextObj, wxRichTextParagraphLayoutBox);
SetFocusObject(actualContainer, false /* don't set caret position yet */);
SetCaretPositionAfterClick(actualContainer, position, hit);
}
-
+
m_contextMenuPropertiesInfo.AddItems(actualContainer, hitObj);
}
else
wxPoint pt;
int height = 0;
-
+
if (!container)
container = GetFocusObject();
Refresh(false);
return true;
}
-
+
wxRichTextRange oldRange, newRange;
if (oldSelection.IsValid())
oldRange = oldSelection.GetRange();
newRange = newSelection.GetRange();
else
newRange = wxRICHTEXT_NO_SELECTION;
-
+
// Calculate the refresh rectangle - just the affected lines
long firstPos, lastPos;
if (oldRange.GetStart() == -2 && newRange.GetStart() != -2)
GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetRight().SetValue(pt.x, wxTEXT_ATTR_UNITS_PIXELS);
GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetTop().SetValue(pt.y, wxTEXT_ATTR_UNITS_PIXELS);
GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetBottom().SetValue(pt.y, wxTEXT_ATTR_UNITS_PIXELS);
-
+
return true;
}
bool changingContainer = (m_focusObject != obj);
m_focusObject = obj;
-
+
if (!obj)
m_focusObject = & m_buffer;
m_selectionState = wxRichTextCtrlSelectionState_Normal;
long pos = -1;
-
+
m_caretAtLineStart = false;
MoveCaret(pos, m_caretAtLineStart);
SetDefaultStyleToCursorStyle();
if (GetCount() == 0)
{
menu->SetLabel(startCmd, _("&Properties"));
-
+
// Delete the others if necessary
int i;
for (i = startCmd+1; i < startCmd+3; i++)
break;
}
}
-
+
if (pos != -1)
{
int insertBefore = pos+1;
}
insertBefore ++;
}
-
+
// Delete any old items still left on the menu
for (i = startCmd + GetCount(); i < startCmd+3; i++)
{