Implementing a custom widget involves several steps.
Define a subclass of the selected implementation object class.
Define a subclass of the selected public class. It is not necessary to subclass both the public and the implementation object class, but this is the typical use case.
Creating each custom widget requires obtaining a factory from an existing container, then:
Use the
factory's get_container_impl
() method.
This returns an
x::w::container_impl
that refers the parent container widget's implementation object.
The custom implementation object class's parent class is
x::w::child_elementObj
whose constructor
takes the parent container widget's implementation object as
a parameter.
The custom subclass's constructor typically takes the parent container
widget reference as the first parameter
to its constructor, and the subclass's
constructor typically passes it to its parent class together with
any other parameters.
The custom public object class gets constructed with the custom implementation object class as its parameter. This typically gets forwarded to the public class's parent class. The implementation subclass is typically a subclass of the public object's implementation class. The public parent class's constructor's first parameter is usually its implementation object. Because of this, the custom public object subclass's constructor simply forwards its implementation class to the public object's parent class's constructor.
The constructed public object gets passed to the factory's
created_internally
() method. This method
places the new widget into its container.
Just creating the implementation object and the public object
is not the entire story. The story doesn't end until the
factory's
created_internally
() gets called.