Fix for incorrect programmatic formatting (default style set immediately if not using Thaw/Freeze)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66705 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2011-01-18 13:34:10 +00:00
parent 07d4142fc4
commit 4fe83b93a5
2 changed files with 40 additions and 34 deletions

View File

@@ -9765,7 +9765,11 @@ void wxRichTextAction::UpdateAppearance(long caretPosition, bool sendUpdateEvent
m_ctrl->Refresh(false); m_ctrl->Refresh(false);
m_ctrl->PositionCaret(); m_ctrl->PositionCaret();
m_ctrl->SetDefaultStyleToCursorStyle();
// This causes styles to persist when doing programmatic
// content creation except when Freeze/Thaw is used, so
// disable this and check for the consequences.
// m_ctrl->SetDefaultStyleToCursorStyle();
if (sendUpdateEvent) if (sendUpdateEvent)
wxTextCtrl::SendTextUpdatedEvent(m_ctrl); wxTextCtrl::SendTextUpdatedEvent(m_ctrl);

View File

@@ -249,7 +249,7 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va
attributes.SetLineSpacing(10); attributes.SetLineSpacing(10);
attributes.SetParagraphSpacingAfter(10); attributes.SetParagraphSpacingAfter(10);
attributes.SetParagraphSpacingBefore(0); attributes.SetParagraphSpacingBefore(0);
SetBasicStyle(attributes); SetBasicStyle(attributes);
int margin = 5; int margin = 5;
@@ -436,7 +436,7 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
int flags = 0; int flags = 0;
if ((GetExtraStyle() & wxRICHTEXT_EX_NO_GUIDELINES) == 0) if ((GetExtraStyle() & wxRICHTEXT_EX_NO_GUIDELINES) == 0)
flags |= wxRICHTEXT_DRAW_GUIDELINES; flags |= wxRICHTEXT_DRAW_GUIDELINES;
GetBuffer().Draw(dc, GetBuffer().GetOwnRange(), GetSelection(), drawingArea, 0 /* descent */, flags); GetBuffer().Draw(dc, GetBuffer().GetOwnRange(), GetSelection(), drawingArea, 0 /* descent */, flags);
dc.DestroyClippingRegion(); dc.DestroyClippingRegion();
@@ -525,7 +525,7 @@ bool wxRichTextCtrl::SetCaretPositionAfterClick(wxRichTextParagraphLayoutBox* co
MoveCaret(position, caretAtLineStart); MoveCaret(position, caretAtLineStart);
SetDefaultStyleToCursorStyle(); SetDefaultStyleToCursorStyle();
return true; return true;
} }
@@ -552,7 +552,7 @@ void wxRichTextCtrl::OnLeftClick(wxMouseEvent& event)
{ {
SetFocusObject(container, false /* don't set caret position yet */); SetFocusObject(container, false /* don't set caret position yet */);
} }
m_dragStart = event.GetLogicalPosition(dc); m_dragStart = event.GetLogicalPosition(dc);
m_dragging = true; m_dragging = true;
CaptureMouse(); CaptureMouse();
@@ -652,9 +652,9 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event)
wxPoint logicalPt = event.GetLogicalPosition(dc); wxPoint logicalPt = event.GetLogicalPosition(dc);
wxRichTextObject* hitObj = NULL; wxRichTextObject* hitObj = NULL;
wxRichTextObject* contextObj = NULL; wxRichTextObject* contextObj = NULL;
int flags = 0; int flags = 0;
// If we're dragging, let's only consider positions at this level; otherwise // If we're dragging, let's only consider positions at this level; otherwise
// selecting a range is not going to work. // selecting a range is not going to work.
wxRichTextParagraphLayoutBox* container = & GetBuffer(); wxRichTextParagraphLayoutBox* container = & GetBuffer();
@@ -664,7 +664,7 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event)
container = GetFocusObject(); container = GetFocusObject();
} }
int hit = container->HitTest(dc, logicalPt, position, & hitObj, & contextObj, flags); int hit = container->HitTest(dc, logicalPt, position, & hitObj, & contextObj, flags);
// See if we need to change the cursor // See if we need to change the cursor
{ {
@@ -693,7 +693,7 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event)
event.Skip(); event.Skip();
return; return;
} }
if (m_dragging) if (m_dragging)
{ {
wxRichTextParagraphLayoutBox* commonAncestor = NULL; wxRichTextParagraphLayoutBox* commonAncestor = NULL;
@@ -719,7 +719,7 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event)
// is the common ancestor. // is the common ancestor.
commonAncestor = wxDynamicCast(firstContainer->GetParent(), wxRichTextParagraphLayoutBox); commonAncestor = wxDynamicCast(firstContainer->GetParent(), wxRichTextParagraphLayoutBox);
} }
if (commonAncestor && commonAncestor->HandlesChildSelections()) if (commonAncestor && commonAncestor->HandlesChildSelections())
{ {
wxRichTextObject* p = hitObj2; wxRichTextObject* p = hitObj2;
@@ -761,7 +761,7 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event)
if (otherContainer->AcceptsFocus()) if (otherContainer->AcceptsFocus())
SetFocusObject(otherContainer, false /* don't set caret and clear selection */); SetFocusObject(otherContainer, false /* don't set caret and clear selection */);
MoveCaret(-1, false); MoveCaret(-1, false);
SetDefaultStyleToCursorStyle(); SetDefaultStyleToCursorStyle();
} }
} }
@@ -778,7 +778,7 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event)
void wxRichTextCtrl::OnRightClick(wxMouseEvent& event) void wxRichTextCtrl::OnRightClick(wxMouseEvent& event)
{ {
SetFocus(); SetFocus();
wxClientDC dc(this); wxClientDC dc(this);
PrepareDC(dc); PrepareDC(dc);
dc.SetFont(GetFont()); dc.SetFont(GetFont());
@@ -1359,9 +1359,9 @@ bool wxRichTextCtrl::ExtendSelection(long oldPos, long newPos, int flags)
return false; return false;
wxRichTextSelection oldSelection = m_selection; wxRichTextSelection oldSelection = m_selection;
m_selection.SetContainer(GetFocusObject()); m_selection.SetContainer(GetFocusObject());
wxRichTextRange oldRange; wxRichTextRange oldRange;
if (m_selection.IsValid()) if (m_selection.IsValid())
oldRange = m_selection.GetRange(); oldRange = m_selection.GetRange();
@@ -1390,7 +1390,7 @@ bool wxRichTextCtrl::ExtendSelection(long oldPos, long newPos, int flags)
else else
newRange.SetRange(newPos+1, m_selectionAnchor); newRange.SetRange(newPos+1, m_selectionAnchor);
} }
m_selection.SetRange(newRange); m_selection.SetRange(newRange);
RefreshForSelectionChange(oldSelection, m_selection); RefreshForSelectionChange(oldSelection, m_selection);
@@ -1434,7 +1434,7 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode)
bool scrolled = false; bool scrolled = false;
wxSize clientSize = GetClientSize(); wxSize clientSize = GetClientSize();
int leftMargin, rightMargin, topMargin, bottomMargin; int leftMargin, rightMargin, topMargin, bottomMargin;
{ {
@@ -1780,7 +1780,7 @@ bool wxRichTextCtrl::MoveDown(int noLines, int flags)
long lineNumber = GetFocusObject()->GetVisibleLineNumber(m_caretPosition, true, m_caretAtLineStart); long lineNumber = GetFocusObject()->GetVisibleLineNumber(m_caretPosition, true, m_caretAtLineStart);
wxPoint pt = GetCaret()->GetPosition(); wxPoint pt = GetCaret()->GetPosition();
long newLine = lineNumber + noLines; long newLine = lineNumber + noLines;
bool notInThisObject = false; bool notInThisObject = false;
if (lineNumber != -1) if (lineNumber != -1)
@@ -1797,7 +1797,7 @@ bool wxRichTextCtrl::MoveDown(int noLines, int flags)
notInThisObject = true; notInThisObject = true;
} }
} }
wxRichTextParagraphLayoutBox* container = GetFocusObject(); wxRichTextParagraphLayoutBox* container = GetFocusObject();
int hitTestFlags = wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS; int hitTestFlags = wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS;
@@ -1807,7 +1807,7 @@ bool wxRichTextCtrl::MoveDown(int noLines, int flags)
// try to find an object anywhere in the buffer at the new position (up or down a bit) // try to find an object anywhere in the buffer at the new position (up or down a bit)
container = & GetBuffer(); container = & GetBuffer();
hitTestFlags = 0; hitTestFlags = 0;
if (noLines > 0) // going down if (noLines > 0) // going down
{ {
pt.y = GetFocusObject()->GetPosition().y + GetFocusObject()->GetCachedSize().y + 2; pt.y = GetFocusObject()->GetPosition().y + GetFocusObject()->GetCachedSize().y + 2;
@@ -1843,11 +1843,11 @@ bool wxRichTextCtrl::MoveDown(int noLines, int flags)
if (actualContainer && actualContainer != GetFocusObject() && actualContainer->AcceptsFocus()) if (actualContainer && actualContainer != GetFocusObject() && actualContainer->AcceptsFocus())
{ {
SetFocusObject(actualContainer, false /* don't set caret position yet */); SetFocusObject(actualContainer, false /* don't set caret position yet */);
container = actualContainer; container = actualContainer;
} }
} }
bool caretLineStart = true; bool caretLineStart = true;
long caretPosition = FindCaretPositionForCharacterPosition(newPos, hitTest, container, caretLineStart); long caretPosition = FindCaretPositionForCharacterPosition(newPos, hitTest, container, caretLineStart);
long newSelEnd = caretPosition; long newSelEnd = caretPosition;
@@ -2391,6 +2391,7 @@ bool wxRichTextCtrl::DoSaveFile(const wxString& filename, int fileType)
wxRichTextRange wxRichTextCtrl::AddParagraph(const wxString& text) wxRichTextRange wxRichTextCtrl::AddParagraph(const wxString& text)
{ {
wxRichTextRange range = GetFocusObject()->AddParagraph(text); wxRichTextRange range = GetFocusObject()->AddParagraph(text);
GetBuffer().Invalidate();
LayoutContent(); LayoutContent();
return range; return range;
} }
@@ -2399,6 +2400,7 @@ wxRichTextRange wxRichTextCtrl::AddParagraph(const wxString& text)
wxRichTextRange wxRichTextCtrl::AddImage(const wxImage& image) wxRichTextRange wxRichTextCtrl::AddImage(const wxImage& image)
{ {
wxRichTextRange range = GetFocusObject()->AddImage(image); wxRichTextRange range = GetFocusObject()->AddImage(image);
GetBuffer().Invalidate();
LayoutContent(); LayoutContent();
return range; return range;
} }
@@ -2684,7 +2686,7 @@ wxRichTextTable* wxRichTextCtrl::WriteTable(int rows, int cols, const wxRichText
wxRichTextTable* table = new wxRichTextTable; wxRichTextTable* table = new wxRichTextTable;
table->SetAttributes(tableAttr); table->SetAttributes(tableAttr);
table->SetParent(& GetBuffer()); // set parent temporarily for AddParagraph to use correct style table->SetParent(& GetBuffer()); // set parent temporarily for AddParagraph to use correct style
table->CreateTable(rows, cols); table->CreateTable(rows, cols);
table->SetParent(NULL); table->SetParent(NULL);
@@ -3153,9 +3155,9 @@ void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent& event)
wxRichTextObject* hitObj = NULL; wxRichTextObject* hitObj = NULL;
wxRichTextObject* contextObj = NULL; wxRichTextObject* contextObj = NULL;
int hit = GetFocusObject()->HitTest(dc, logicalPt, position, & hitObj, & contextObj); int hit = GetFocusObject()->HitTest(dc, logicalPt, position, & hitObj, & contextObj);
m_contextMenuPropertiesInfo.Clear(); m_contextMenuPropertiesInfo.Clear();
if (hit == wxRICHTEXT_HITTEST_ON || hit == wxRICHTEXT_HITTEST_BEFORE || hit == wxRICHTEXT_HITTEST_AFTER) if (hit == wxRICHTEXT_HITTEST_ON || hit == wxRICHTEXT_HITTEST_BEFORE || hit == wxRICHTEXT_HITTEST_AFTER)
{ {
wxRichTextParagraphLayoutBox* actualContainer = wxDynamicCast(contextObj, wxRichTextParagraphLayoutBox); wxRichTextParagraphLayoutBox* actualContainer = wxDynamicCast(contextObj, wxRichTextParagraphLayoutBox);
@@ -3166,7 +3168,7 @@ void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent& event)
SetFocusObject(actualContainer, false /* don't set caret position yet */); SetFocusObject(actualContainer, false /* don't set caret position yet */);
SetCaretPositionAfterClick(actualContainer, position, hit); SetCaretPositionAfterClick(actualContainer, position, hit);
} }
m_contextMenuPropertiesInfo.AddItems(actualContainer, hitObj); m_contextMenuPropertiesInfo.AddItems(actualContainer, hitObj);
} }
else else
@@ -3376,7 +3378,7 @@ bool wxRichTextCtrl::GetCaretPositionForIndex(long position, wxRect& rect, wxRic
wxPoint pt; wxPoint pt;
int height = 0; int height = 0;
if (!container) if (!container)
container = GetFocusObject(); container = GetFocusObject();
@@ -3890,7 +3892,7 @@ bool wxRichTextCtrl::RefreshForSelectionChange(const wxRichTextSelection& oldSel
Refresh(false); Refresh(false);
return true; return true;
} }
wxRichTextRange oldRange, newRange; wxRichTextRange oldRange, newRange;
if (oldSelection.IsValid()) if (oldSelection.IsValid())
oldRange = oldSelection.GetRange(); oldRange = oldSelection.GetRange();
@@ -3900,7 +3902,7 @@ bool wxRichTextCtrl::RefreshForSelectionChange(const wxRichTextSelection& oldSel
newRange = newSelection.GetRange(); newRange = newSelection.GetRange();
else else
newRange = wxRICHTEXT_NO_SELECTION; newRange = wxRICHTEXT_NO_SELECTION;
// Calculate the refresh rectangle - just the affected lines // Calculate the refresh rectangle - just the affected lines
long firstPos, lastPos; long firstPos, lastPos;
if (oldRange.GetStart() == -2 && newRange.GetStart() != -2) if (oldRange.GetStart() == -2 && newRange.GetStart() != -2)
@@ -3953,7 +3955,7 @@ bool wxRichTextCtrl::DoSetMargins(const wxPoint& pt)
GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetRight().SetValue(pt.x, wxTEXT_ATTR_UNITS_PIXELS); 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().GetTop().SetValue(pt.y, wxTEXT_ATTR_UNITS_PIXELS);
GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetBottom().SetValue(pt.y, wxTEXT_ATTR_UNITS_PIXELS); GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetBottom().SetValue(pt.y, wxTEXT_ATTR_UNITS_PIXELS);
return true; return true;
} }
@@ -3972,7 +3974,7 @@ bool wxRichTextCtrl::SetFocusObject(wxRichTextParagraphLayoutBox* obj, bool setC
bool changingContainer = (m_focusObject != obj); bool changingContainer = (m_focusObject != obj);
m_focusObject = obj; m_focusObject = obj;
if (!obj) if (!obj)
m_focusObject = & m_buffer; m_focusObject = & m_buffer;
@@ -3984,7 +3986,7 @@ bool wxRichTextCtrl::SetFocusObject(wxRichTextParagraphLayoutBox* obj, bool setC
m_selectionState = wxRichTextCtrlSelectionState_Normal; m_selectionState = wxRichTextCtrlSelectionState_Normal;
long pos = -1; long pos = -1;
m_caretAtLineStart = false; m_caretAtLineStart = false;
MoveCaret(pos, m_caretAtLineStart); MoveCaret(pos, m_caretAtLineStart);
SetDefaultStyleToCursorStyle(); SetDefaultStyleToCursorStyle();
@@ -4168,7 +4170,7 @@ int wxRichTextContextMenuPropertiesInfo::AddMenuItems(wxMenu* menu, int startCmd
if (GetCount() == 0) if (GetCount() == 0)
{ {
menu->SetLabel(startCmd, _("&Properties")); menu->SetLabel(startCmd, _("&Properties"));
// Delete the others if necessary // Delete the others if necessary
int i; int i;
for (i = startCmd+1; i < startCmd+3; i++) for (i = startCmd+1; i < startCmd+3; i++)
@@ -4193,7 +4195,7 @@ int wxRichTextContextMenuPropertiesInfo::AddMenuItems(wxMenu* menu, int startCmd
break; break;
} }
} }
if (pos != -1) if (pos != -1)
{ {
int insertBefore = pos+1; int insertBefore = pos+1;
@@ -4212,7 +4214,7 @@ int wxRichTextContextMenuPropertiesInfo::AddMenuItems(wxMenu* menu, int startCmd
} }
insertBefore ++; insertBefore ++;
} }
// Delete any old items still left on the menu // Delete any old items still left on the menu
for (i = startCmd + GetCount(); i < startCmd+3; i++) for (i = startCmd + GetCount(); i < startCmd+3; i++)
{ {