EVT_KILL_FOCUS(wxRichTextCtrl::OnKillFocus)
EVT_MOUSE_CAPTURE_LOST(wxRichTextCtrl::OnCaptureLost)
EVT_CONTEXT_MENU(wxRichTextCtrl::OnContextMenu)
+ EVT_SYS_COLOUR_CHANGED(wxRichTextCtrl::OnSysColourChanged)
EVT_MENU(wxID_UNDO, wxRichTextCtrl::OnUndo)
EVT_UPDATE_UI(wxID_UNDO, wxRichTextCtrl::OnUpdateUndo)
bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style,
const wxValidator& validator, const wxString& name)
{
- if (!wxTextCtrlBase::Create(parent, id, pos, size,
- style|wxFULL_REPAINT_ON_RESIZE,
- validator, name))
+ if (!wxControl::Create(parent, id, pos, size,
+ style|wxFULL_REPAINT_ON_RESIZE,
+ validator, name))
return false;
if (!GetFont().Ok())
SetEditable(false);
// The base attributes must all have default values
- wxTextAttrEx attributes;
+ wxTextAttr attributes;
attributes.SetFont(GetFont());
- attributes.SetTextColour(*wxBLACK);
+ attributes.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
attributes.SetAlignment(wxTEXT_ALIGNMENT_LEFT);
attributes.SetLineSpacing(10);
attributes.SetParagraphSpacingAfter(10);
// The default attributes will be merged with base attributes, so
// can be empty to begin with
- wxTextAttrEx defaultAttributes;
+ wxTextAttr defaultAttributes;
SetDefaultStyle(defaultAttributes);
- SetBackgroundColour(*wxWHITE);
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
// Tell the sizers to use the given or best size
/// Member initialisation
void wxRichTextCtrl::Init()
{
- m_freezeCount = 0;
m_contextMenu = NULL;
m_caret = NULL;
m_caretPosition = -1;
m_caretPositionForDefaultStyle = -2;
}
-/// Call Freeze to prevent refresh
-void wxRichTextCtrl::Freeze()
+void wxRichTextCtrl::DoThaw()
{
- m_freezeCount ++;
-}
-
-/// Call Thaw to refresh
-void wxRichTextCtrl::Thaw()
-{
- m_freezeCount --;
-
- if (m_freezeCount == 0)
- {
+ if (GetBuffer().GetDirty())
+ LayoutContent();
+ else
SetupScrollbars();
- Refresh(false);
- }
+ Refresh(false);
}
/// Clear all text
m_caretAtLineStart = false;
m_selectionRange.SetRange(-2, -2);
- SetScrollbars(0, 0, 0, 0, 0, 0);
-
- if (m_freezeCount == 0)
+ if (!IsFrozen())
{
- SetupScrollbars();
+ LayoutContent();
Refresh(false);
}
- SendTextUpdatedEvent();
+
+ wxTextCtrl::SendTextUpdatedEvent(this);
}
/// Painting
#else
wxPaintDC dc(this);
#endif
- PrepareDC(dc);
- if (m_freezeCount > 0)
+ if (IsFrozen())
return;
+ PrepareDC(dc);
+
dc.SetFont(GetFont());
// Paint the background
if (!GetEventHandler()->ProcessEvent(cmdEvent))
{
- wxTextAttrEx attr;
+ wxTextAttr attr;
if (GetStyle(position, attr))
{
if (attr.HasFlag(wxTEXT_ATTR_URL))
if (!urlTarget.IsEmpty())
{
wxMouseEvent mouseEvent(event);
-
+
long startPos = 0, endPos = 0;
wxRichTextObject* obj = GetBuffer().GetLeafObjectAtPosition(position);
if (obj)
startPos = obj->GetRange().GetStart();
endPos = obj->GetRange().GetEnd();
}
-
+
wxTextUrlEvent urlEvent(GetId(), mouseEvent, startPos, endPos);
InitCommandEvent(urlEvent);
-
+
urlEvent.SetString(urlTarget);
-
+
GetEventHandler()->ProcessEvent(urlEvent);
}
}
{
if (hit != wxRICHTEXT_HITTEST_NONE && !(hit & wxRICHTEXT_HITTEST_OUTSIDE))
{
- wxTextAttrEx attr;
+ wxTextAttr attr;
if (GetStyle(position, attr))
{
if (attr.HasFlag(wxTEXT_ATTR_URL))
}
/// Right-click
-void wxRichTextCtrl::OnRightClick(wxMouseEvent& WXUNUSED(event))
+void wxRichTextCtrl::OnRightClick(wxMouseEvent& event)
{
SetFocus();
GetId());
cmdEvent.SetEventObject(this);
cmdEvent.SetPosition(m_caretPosition+1);
-
- GetEventHandler()->ProcessEvent(cmdEvent);
+
+ if (!GetEventHandler()->ProcessEvent(cmdEvent))
+ event.Skip();
}
/// Left-double-click
GetId());
cmdEvent.SetEventObject(this);
cmdEvent.SetPosition(m_caretPosition+1);
-
+
if (!GetEventHandler()->ProcessEvent(cmdEvent))
{
SelectWord(GetCaretPosition()+1);
GetId());
cmdEvent.SetEventObject(this);
cmdEvent.SetPosition(m_caretPosition+1);
-
+
if (!GetEventHandler()->ProcessEvent(cmdEvent))
event.Skip();
}
// Going down
if (keyCode == WXK_DOWN || keyCode == WXK_NUMPAD_DOWN ||
- keyCode == WXK_RIGHT || keyCode == WXK_NUMPAD_DOWN ||
+ keyCode == WXK_RIGHT || keyCode == WXK_NUMPAD_RIGHT ||
keyCode == WXK_END || keyCode == WXK_NUMPAD_END ||
keyCode == WXK_PAGEDOWN || keyCode == WXK_NUMPAD_PAGEDOWN)
{
startX = 0;
startY = startY * ppuY;
- int sx = 0, sy = 0;
- GetVirtualSize(& sx, & sy);
- sx = 0;
- if (ppuY != 0)
- sy = sy/ppuY;
-
wxRect rect = line->GetRect();
-
wxSize clientSize = GetClientSize();
- return !(((rect.y + rect.height) > (clientSize.y + startY)) || rect.y < startY);
+ return (rect.GetBottom() > startY) && (rect.GetTop() < (startY + clientSize.y));
}
void wxRichTextCtrl::SetCaretPosition(long position, bool showAtLineStart)
/// Set up scrollbars, e.g. after a resize
void wxRichTextCtrl::SetupScrollbars(bool atTop)
{
- if (m_freezeCount)
+ if (IsFrozen())
return;
if (GetBuffer().IsEmpty())
PositionCaret();
SetupScrollbars(true);
Refresh(false);
- SendTextUpdatedEvent();
+ wxTextCtrl::SendTextUpdatedEvent(this);
if (success)
return true;
return wxTE_HT_BEFORE;
else if ((hit & wxRICHTEXT_HITTEST_AFTER) && (hit & wxRICHTEXT_HITTEST_OUTSIDE))
return wxTE_HT_BEYOND;
- else if (hit & wxRICHTEXT_HITTEST_BEFORE|wxRICHTEXT_HITTEST_AFTER)
+ else if (hit & (wxRICHTEXT_HITTEST_BEFORE|wxRICHTEXT_HITTEST_AFTER))
return wxTE_HT_ON_TEXT;
return wxTE_HT_UNKNOWN;
{
Clear();
- // if the text is long enough, it's faster to just set it instead of first
- // comparing it with the old one (chances are that it will be different
- // anyhow, this comparison is there to avoid flicker for small single-line
- // edit controls mostly)
- if ( (value.length() > 0x400) || (value != GetValue()) )
+ if (!value.IsEmpty())
{
+ // Remove empty paragraph
+ GetBuffer().Clear();
DoWriteText(value);
// for compatibility, don't move the cursor when doing SetValue()
SetInsertionPoint(0);
}
- else // same text
+ else
{
- if ( flags & SetValue_SendEvent )
- {
- // still send an event for consistency
- SendTextUpdatedEvent();
- }
+ // still send an event for consistency
+ if (flags & SetValue_SendEvent)
+ wxTextCtrl::SendTextUpdatedEvent(this);
}
-
- // we should reset the modified flag even if the value didn't really change
-
- // mark the control as being not dirty - we changed its text, not the
- // user
DiscardEdits();
}
GetBuffer().InsertTextWithUndo(m_caretPosition+1, valueUnix, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE);
if ( flags & SetValue_SendEvent )
- SendTextUpdatedEvent();
+ wxTextCtrl::SendTextUpdatedEvent(this);
}
void wxRichTextCtrl::AppendText(const wxString& text)
SelectNone();
m_caretPosition = pos - 1;
+
+ PositionCaret();
}
void wxRichTextCtrl::SetInsertionPointEnd()
event.Enable(GetLastPosition() > 0);
}
-void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent& WXUNUSED(event))
+void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent& event)
{
+ if (event.GetEventObject() != this)
+ {
+ event.Skip();
+ return;
+ }
+
if (!m_contextMenu)
{
m_contextMenu = new wxMenu;
return;
}
-bool wxRichTextCtrl::SetStyle(long start, long end, const wxTextAttrEx& style)
-{
- return GetBuffer().SetStyle(wxRichTextRange(start, end-1), style);
-}
-
bool wxRichTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
{
- return GetBuffer().SetStyle(wxRichTextRange(start, end-1), wxTextAttrEx(style));
+ return GetBuffer().SetStyle(wxRichTextRange(start, end-1), wxTextAttr(style));
}
-bool wxRichTextCtrl::SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style)
+bool wxRichTextCtrl::SetStyle(const wxRichTextRange& range, const wxTextAttr& style)
{
return GetBuffer().SetStyle(range.ToInternal(), style);
}
// extended style setting operation with flags including:
// wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY.
// see richtextbuffer.h for more details.
-bool wxRichTextCtrl::SetStyleEx(long start, long end, const wxTextAttrEx& style, int flags)
-{
- return GetBuffer().SetStyle(wxRichTextRange(start, end-1), style, flags);
-}
-bool wxRichTextCtrl::SetStyleEx(const wxRichTextRange& range, const wxTextAttrEx& style, int flags)
+bool wxRichTextCtrl::SetStyleEx(const wxRichTextRange& range, const wxTextAttr& style, int flags)
{
return GetBuffer().SetStyle(range.ToInternal(), style, flags);
}
-bool wxRichTextCtrl::SetStyleEx(const wxRichTextRange& range, const wxRichTextAttr& style, int flags)
-{
- return GetBuffer().SetStyle(range.ToInternal(), style, flags);
-}
-
-bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttrEx& style)
-{
- return GetBuffer().SetDefaultStyle(style);
-}
-
bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttr& style)
{
- return GetBuffer().SetDefaultStyle(wxTextAttrEx(style));
-}
-
-const wxTextAttrEx& wxRichTextCtrl::GetDefaultStyleEx() const
-{
- return GetBuffer().GetDefaultStyle();
+ return GetBuffer().SetDefaultStyle(wxTextAttr(style));
}
const wxTextAttr& wxRichTextCtrl::GetDefaultStyle() const
}
bool wxRichTextCtrl::GetStyle(long position, wxTextAttr& style)
-{
- wxTextAttrEx attr(style);
- if (GetBuffer().GetStyle(position, attr))
- {
- style = attr;
- return true;
- }
- else
- return false;
-}
-
-bool wxRichTextCtrl::GetStyle(long position, wxTextAttrEx& style)
-{
- return GetBuffer().GetStyle(position, style);
-}
-
-bool wxRichTextCtrl::GetStyle(long position, wxRichTextAttr& style)
{
return GetBuffer().GetStyle(position, style);
}
// get the common set of styles for the range
-bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style)
-{
- wxTextAttrEx styleEx;
- if (GetBuffer().GetStyleForRange(range.ToInternal(), styleEx))
- {
- style = styleEx;
- return true;
- }
- else
- return false;
-}
-
-bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style)
+bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange& range, wxTextAttr& style)
{
return GetBuffer().GetStyleForRange(range.ToInternal(), style);
}
/// Get the content (uncombined) attributes for this position.
-
bool wxRichTextCtrl::GetUncombinedStyle(long position, wxTextAttr& style)
-{
- wxTextAttrEx attr(style);
- if (GetBuffer().GetUncombinedStyle(position, attr))
- {
- style = attr;
- return true;
- }
- else
- return false;
-}
-
-bool wxRichTextCtrl::GetUncombinedStyle(long position, wxTextAttrEx& style)
-{
- return GetBuffer().GetUncombinedStyle(position, style);
-}
-
-bool wxRichTextCtrl::GetUncombinedStyle(long position, wxRichTextAttr& style)
{
return GetBuffer().GetUncombinedStyle(position, style);
}
{
wxControl::SetFont(font);
- wxTextAttrEx attr = GetBuffer().GetAttributes();
+ wxTextAttr attr = GetBuffer().GetAttributes();
attr.SetFont(font);
GetBuffer().SetBasicStyle(attr);
wxRect caretRect;
if (GetCaretPositionForIndex(GetCaretPosition(), caretRect))
{
- wxPoint originalPt = caretRect.GetPosition();
- wxPoint pt = GetPhysicalPoint(originalPt);
- if (GetCaret()->GetPosition() != pt)
+ wxPoint newPt = caretRect.GetPosition();
+ wxSize newSz = caretRect.GetSize();
+ wxPoint pt = GetPhysicalPoint(newPt);
+ if (GetCaret()->GetPosition() != pt || GetCaret()->GetSize() != newSz)
{
GetCaret()->Move(pt);
- GetCaret()->SetSize(caretRect.GetSize());
+ GetCaret()->SetSize(newSz);
}
}
}
{
if (HasSelection())
{
- wxRichTextAttr attr;
+ wxTextAttr attr;
wxRichTextRange range = GetSelectionRange();
attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT);
attr.SetFontWeight(wxBOLD);
{
// If no selection, then we need to combine current style with default style
// to see what the effect would be if we started typing.
- wxRichTextAttr attr;
+ wxTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT);
long pos = GetAdjustedCaretPosition(GetCaretPosition());
if (HasSelection())
{
wxRichTextRange range = GetSelectionRange();
- wxRichTextAttr attr;
+ wxTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_ITALIC);
attr.SetFontStyle(wxITALIC);
{
// If no selection, then we need to combine current style with default style
// to see what the effect would be if we started typing.
- wxRichTextAttr attr;
+ wxTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_ITALIC);
long pos = GetAdjustedCaretPosition(GetCaretPosition());
if (HasSelection())
{
wxRichTextRange range = GetSelectionRange();
- wxRichTextAttr attr;
+ wxTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE);
attr.SetFontUnderlined(true);
{
// If no selection, then we need to combine current style with default style
// to see what the effect would be if we started typing.
- wxRichTextAttr attr;
+ wxTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE);
long pos = GetAdjustedCaretPosition(GetCaretPosition());
/// Apply bold to the selection
bool wxRichTextCtrl::ApplyBoldToSelection()
{
- wxRichTextAttr attr;
+ wxTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT);
attr.SetFontWeight(IsSelectionBold() ? wxNORMAL : wxBOLD);
/// Apply italic to the selection
bool wxRichTextCtrl::ApplyItalicToSelection()
{
- wxRichTextAttr attr;
+ wxTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_ITALIC);
attr.SetFontStyle(IsSelectionItalics() ? wxNORMAL : wxITALIC);
/// Apply underline to the selection
bool wxRichTextCtrl::ApplyUnderlineToSelection()
{
- wxRichTextAttr attr;
+ wxTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE);
attr.SetFontUnderlined(!IsSelectionUnderlined());
else
range = wxRichTextRange(GetCaretPosition()+1, GetCaretPosition()+2);
- wxRichTextAttr attr;
+ wxTextAttr attr;
attr.SetAlignment(alignment);
return HasParagraphAttributes(range, attr);
/// Apply alignment to the selection
bool wxRichTextCtrl::ApplyAlignmentToSelection(wxTextAttrAlignment alignment)
{
- wxRichTextAttr attr;
+ wxTextAttr attr;
attr.SetAlignment(alignment);
if (HasSelection())
return SetStyle(GetSelectionRange(), attr);
{
// Flags are defined within each definition, so only certain
// attributes are applied.
- wxRichTextAttr attr(GetStyleSheet() ? def->GetStyleMergedWithBase(GetStyleSheet()) : def->GetStyle());
+ wxTextAttr attr(GetStyleSheet() ? def->GetStyleMergedWithBase(GetStyleSheet()) : def->GetStyle());
int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE;
/// Sets the default style to the style under the cursor
bool wxRichTextCtrl::SetDefaultStyleToCursorStyle()
{
- wxTextAttrEx attr;
+ wxTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_CHARACTER);
// If at the start of a paragraph, use the next position.
sm_availableFontNames.Clear();
}
+void wxRichTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
+{
+ //wxLogDebug(wxT("wxRichTextCtrl::OnSysColourChanged"));
+
+ wxTextAttrEx basicStyle = GetBasicStyle();
+ basicStyle.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
+ SetBasicStyle(basicStyle);
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
+
+ Refresh();
+}
+
#endif
// wxUSE_RICHTEXT