X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a047aff270905b377a81657a90f92eb3297157d0..9d5507f7a2701395e1d5c121bd877bb9066ee6ea:/src/richtext/richtextctrl.cpp diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index b23a95f949..62acf0a2fa 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -76,6 +76,7 @@ BEGIN_EVENT_TABLE( wxRichTextCtrl, wxControl ) 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) @@ -129,17 +130,9 @@ wxRichTextCtrl::wxRichTextCtrl(wxWindow* parent, bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) { - // Try to make this only necessary in 2.8 -#if 0 -#ifdef __WXMSW__ - if ((style & wxBORDER_MASK) == wxDEFAULT) - style |= wxBORDER_THEME; -#endif -#endif - - 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()) @@ -157,9 +150,9 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va 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); @@ -171,10 +164,10 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va // 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 @@ -237,7 +230,10 @@ void wxRichTextCtrl::Thaw() if (m_freezeCount == 0) { - SetupScrollbars(); + if (GetBuffer().GetDirty()) + LayoutContent(); + else + SetupScrollbars(); Refresh(false); } } @@ -252,14 +248,13 @@ void wxRichTextCtrl::Clear() m_caretAtLineStart = false; m_selectionRange.SetRange(-2, -2); - SetScrollbars(0, 0, 0, 0, 0, 0); - if (m_freezeCount == 0) { - SetupScrollbars(); + LayoutContent(); Refresh(false); } - SendTextUpdatedEvent(); + + wxTextCtrl::SendTextUpdatedEvent(this); } /// Painting @@ -408,7 +403,7 @@ void wxRichTextCtrl::OnLeftUp(wxMouseEvent& event) if (!GetEventHandler()->ProcessEvent(cmdEvent)) { - wxTextAttrEx attr; + wxTextAttr attr; if (GetStyle(position, attr)) { if (attr.HasFlag(wxTEXT_ATTR_URL)) @@ -456,7 +451,7 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event) { if (hit != wxRICHTEXT_HITTEST_NONE && !(hit & wxRICHTEXT_HITTEST_OUTSIDE)) { - wxTextAttrEx attr; + wxTextAttr attr; if (GetStyle(position, attr)) { if (attr.HasFlag(wxTEXT_ATTR_URL)) @@ -512,7 +507,7 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event) } /// Right-click -void wxRichTextCtrl::OnRightClick(wxMouseEvent& WXUNUSED(event)) +void wxRichTextCtrl::OnRightClick(wxMouseEvent& event) { SetFocus(); @@ -522,7 +517,8 @@ void wxRichTextCtrl::OnRightClick(wxMouseEvent& WXUNUSED(event)) cmdEvent.SetEventObject(this); cmdEvent.SetPosition(m_caretPosition+1); - GetEventHandler()->ProcessEvent(cmdEvent); + if (!GetEventHandler()->ProcessEvent(cmdEvent)) + event.Skip(); } /// Left-double-click @@ -1148,17 +1144,10 @@ bool wxRichTextCtrl::IsPositionVisible(long pos) const 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) @@ -1886,7 +1875,7 @@ bool wxRichTextCtrl::DoLoadFile(const wxString& filename, int fileType) PositionCaret(); SetupScrollbars(true); Refresh(false); - SendTextUpdatedEvent(); + wxTextCtrl::SendTextUpdatedEvent(this); if (success) return true; @@ -2085,7 +2074,7 @@ void wxRichTextCtrl::DoSetValue(const wxString& value, int flags) { // still send an event for consistency if (flags & SetValue_SendEvent) - SendTextUpdatedEvent(); + wxTextCtrl::SendTextUpdatedEvent(this); } DiscardEdits(); } @@ -2102,7 +2091,7 @@ void wxRichTextCtrl::DoWriteText(const wxString& value, int flags) 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) @@ -2535,8 +2524,14 @@ void wxRichTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) 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; @@ -2554,17 +2549,12 @@ void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent& WXUNUSED(event)) 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); } @@ -2572,34 +2562,15 @@ bool wxRichTextCtrl::SetStyle(const wxRichTextRange& range, const wxRichTextAttr // 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 @@ -2608,65 +2579,18 @@ 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); } @@ -2676,7 +2600,7 @@ bool wxRichTextCtrl::SetFont(const wxFont& font) { wxControl::SetFont(font); - wxTextAttrEx attr = GetBuffer().GetAttributes(); + wxTextAttr attr = GetBuffer().GetAttributes(); attr.SetFont(font); GetBuffer().SetBasicStyle(attr); @@ -2715,12 +2639,13 @@ void wxRichTextCtrl::PositionCaret() 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); } } } @@ -2830,7 +2755,7 @@ bool wxRichTextCtrl::IsSelectionBold() { if (HasSelection()) { - wxRichTextAttr attr; + wxTextAttr attr; wxRichTextRange range = GetSelectionRange(); attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT); attr.SetFontWeight(wxBOLD); @@ -2841,7 +2766,7 @@ bool wxRichTextCtrl::IsSelectionBold() { // 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()); @@ -2861,7 +2786,7 @@ bool wxRichTextCtrl::IsSelectionItalics() if (HasSelection()) { wxRichTextRange range = GetSelectionRange(); - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_ITALIC); attr.SetFontStyle(wxITALIC); @@ -2871,7 +2796,7 @@ bool wxRichTextCtrl::IsSelectionItalics() { // 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()); @@ -2891,7 +2816,7 @@ bool wxRichTextCtrl::IsSelectionUnderlined() if (HasSelection()) { wxRichTextRange range = GetSelectionRange(); - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE); attr.SetFontUnderlined(true); @@ -2901,7 +2826,7 @@ bool wxRichTextCtrl::IsSelectionUnderlined() { // 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()); @@ -2918,7 +2843,7 @@ bool wxRichTextCtrl::IsSelectionUnderlined() /// Apply bold to the selection bool wxRichTextCtrl::ApplyBoldToSelection() { - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT); attr.SetFontWeight(IsSelectionBold() ? wxNORMAL : wxBOLD); @@ -2932,7 +2857,7 @@ bool wxRichTextCtrl::ApplyBoldToSelection() /// Apply italic to the selection bool wxRichTextCtrl::ApplyItalicToSelection() { - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_ITALIC); attr.SetFontStyle(IsSelectionItalics() ? wxNORMAL : wxITALIC); @@ -2946,7 +2871,7 @@ bool wxRichTextCtrl::ApplyItalicToSelection() /// Apply underline to the selection bool wxRichTextCtrl::ApplyUnderlineToSelection() { - wxRichTextAttr attr; + wxTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE); attr.SetFontUnderlined(!IsSelectionUnderlined()); @@ -2966,7 +2891,7 @@ bool wxRichTextCtrl::IsSelectionAligned(wxTextAttrAlignment alignment) else range = wxRichTextRange(GetCaretPosition()+1, GetCaretPosition()+2); - wxRichTextAttr attr; + wxTextAttr attr; attr.SetAlignment(alignment); return HasParagraphAttributes(range, attr); @@ -2975,7 +2900,7 @@ bool wxRichTextCtrl::IsSelectionAligned(wxTextAttrAlignment alignment) /// Apply alignment to the selection bool wxRichTextCtrl::ApplyAlignmentToSelection(wxTextAttrAlignment alignment) { - wxRichTextAttr attr; + wxTextAttr attr; attr.SetAlignment(alignment); if (HasSelection()) return SetStyle(GetSelectionRange(), attr); @@ -2993,7 +2918,7 @@ bool wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def) { // 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; @@ -3057,7 +2982,7 @@ bool wxRichTextCtrl::ApplyStyleSheet(wxRichTextStyleSheet* styleSheet) /// 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. @@ -3188,5 +3113,17 @@ void wxRichTextCtrl::ClearAvailableFontNames() 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