Ticket #15184 (closed defect: fixed)
wxRichTextAction fix for when the command identifier is wxRICHTEXT_CHANGE_OBJECT
|Reported by:||dghart||Owned by:|
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.