I'm using wxPython to develop a form which has been constructed using XRC. On this form there are a couple of RichTextControls which are attached using AttachUnknownControl(). The form displays correctly, but when I attempt to retrieve the (client) position of the RichtText controls I always get back (0,0).
The XRC controls not created using AttachUnknownControl() do report their correct client position.
Has anyone had the same experience? How can I get the correct client position for the RichText controls?
P.S.: why doesn't XRC have support for RichText controls?
XRC control client position is always (0,0)
XRC control client position is always (0,0)
Soon to be world famous
Re: XRC control client position is always (0,0)
Hi,
(I've no idea about the wxPython/AttachUnknownControl aspects of this question.)
Regards,
David
(I've no idea about the wxPython/AttachUnknownControl aspects of this question.)
Doesn't it? The wx3.0.5 source contains src/xrc/xh_richtext.cpp. In fact, so does wx2.8.12.P.S.: why doesn't XRC have support for RichText controls?
Regards,
David
Re: XRC control client position is always (0,0)
Looking at the implementation of AttachUnknownControl (src\xrc\xmlres.cpp):
and the code of Reparent() (src\common\wincmn.cpp)
Why is it reparenting to the "container"?
Code: Select all
bool wxXmlResource::AttachUnknownControl(const wxString& name,
wxWindow *control, wxWindow *parent)
{
if (parent == NULL)
parent = control->GetParent();
wxWindow *container = parent->FindWindow(name + wxT("_container"));
if (!container)
{
wxLogError("Cannot find container for unknown control '%s'.", name);
return false;
}
return control->Reparent(container);
}
Code: Select all
bool wxWindowBase::Reparent(wxWindowBase *newParent)
{
wxWindow *oldParent = GetParent();
if ( newParent == oldParent )
{
// nothing done
return false;
}
const bool oldEnabledState = IsEnabled();
// unlink this window from the existing parent.
if ( oldParent )
{
oldParent->RemoveChild(this);
}
else
{
wxTopLevelWindows.DeleteObject((wxWindow *)this);
}
// add it to the new one
if ( newParent )
{
newParent->AddChild(this);
}
else
{
wxTopLevelWindows.Append((wxWindow *)this);
}
// We need to notify window (and its subwindows) if by changing the parent
// we also change our enabled/disabled status.
const bool newEnabledState = IsEnabled();
if ( newEnabledState != oldEnabledState )
{
NotifyWindowOnEnableChange(newEnabledState);
}
return true;
}
Soon to be world famous
Re: XRC control client position is always (0,0)
I'm starting to understand the problem. When the XRC system sees an object of type "unknown" with name <name> it creates a panel with the name <name>_container and puts that in as a sort of placeholder.
When you call AttachUnknownControl() your control is actually added to the <name>_container wxPanel and the client position you get back is actually the position relative to the <name>_container, which is (0,0).
Now the question seems to be: how do I get the client position of my control relative to the parent of the <name>_container wxPanel?
When you call AttachUnknownControl() your control is actually added to the <name>_container wxPanel and the client position you get back is actually the position relative to the <name>_container, which is (0,0).
Now the question seems to be: how do I get the client position of my control relative to the parent of the <name>_container wxPanel?
Soon to be world famous
Re: XRC control client position is always (0,0)
To answer my own question:Now the question seems to be: how do I get the client position of my control relative to the parent of the <name>_container wxPanel?
controlA = control I want the client coordinates of relative to WindowB
pos = controlA.GetScreenPosition()
clientPos = WindowB.ScreenToClient(pos)
clientPos is the client position of ControlA as if it had WindowB as its parent.
Soon to be world famous
Re: XRC control client position is always (0,0)
Thanks David.
I created an issue with the wxFormBuilder team: https://github.com/wxFormBuilder/wxForm ... issues/618
Soon to be world famous