Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#15184 closed defect (fixed)

wxRichTextAction fix for when the command identifier is wxRICHTEXT_CHANGE_OBJECT

Reported by: dghart Owned by:
Priority: normal Milestone: 2.9.5
Component: wxRichText Version: stable-latest
Keywords: wxRichTextAction wxRICHTEXT_CHANGE_OBJECT Cc:
Blocked By: Blocking:
Patch: yes


There are several different cases in wxRichTextAction::Do and similar. One of these, wxRICHTEXT_CHANGE_OBJECT, is currently not called by any code findable by grep or google. Its purpose is to switch the current state of an object with its saved state. It does this by saving the 'address' of the object in m_objectAddress and storing an original-state clone in m_object.

There are two problems with the current implementation:

1) Storing the address with wxRichTextObjectAddress::Create requires that the passed object is contained in a paragraph inside a buffer, and so will only work for the 'real' object, not the clone. The only current way of storing the object is with wxRichTextAction::SetObject which both sets it and calls wxRichTextObjectAddress::Create, which clears any existing address before failing to find the clone.
The patch therefore adds a simple setter for m_object, StoreObject(). This makes it possible first to set the object's address, then later to store the clone.

2) When wxRichTextAction::Do is called to switch states, it correctly retrieves the current object. However it then tries to search for that inside m_buffer using the line:
wxRichTextObjectList::compatibility_iterator node = container->GetChildren().Find(obj);
which fails because (iiuc) wxRichTextBuffer stores only child paragraphs, not objects. The patch fixes this by using the object's parent paragraph instead.

The patch can be seen working, both in the standard situation and when the table is inside a cell of another table, in the patches to the richtext sample and unit-test which will be attached to (probably) #15185. A situation where it fails will be described in a separate report.

Attachments (1)

patch.diff download (3.0 KB) - added by dghart 5 years ago.

Download all attachments as: .zip

Change History (3)

Changed 5 years ago by dghart

comment:1 Changed 5 years ago by juliansmart

  • Resolution set to fixed
  • Status changed from new to closed

Thank you, applied.

comment:2 Changed 5 years ago by VZ

(In [73951]) Fix wxRichTextCtrl test compilation.

Work around broken pre-C++98 for loop scoping rules in VC6.

See #15184.

Note: See TracTickets for help on using tickets.