Re: How to get the width of a container

Clemens Szyperski (szypersk@fit.qut.edu.au)
Thu, 2 Jan 1997 11:51:11 +1000 (EST)

Hi Roger,

> I am developing a new view (derived from Views.View) and this view should be
> able to adjust itself dynamically to the width of the surrounding container
> (eg. a form view).
> Does anyone know how I can get the acutal width of the embedding container?
>
> BTW: I tried to get the view via the context but I could only reach the
> embedding model (view->context->ThisModel()). Because the view is embedded
> in a container you get a Containers.Model. There, I tried to get the width
> with GetEmbeddingLimits(minW, maxW, minH, maxH) but maxW is much larger than
> the actual width of the embedding container.
> Any other idea?

The reason why the framework only returns the model and not the embedding
view is simple: there might be several of them, all of which may have
different sizes! (The reason is that a model can be displayed by many views
which may visualize the model's data in different ways, etc. This is a result
of using a recursive MVC approach.)

Since a view must have a defined size known to its (unique) embedding model,
it cannot adapt to the size of all possible embedding views. It might adapt
to the minimum or maximum of these, leading to the expected result in the
common case where there is only one container view. However, there is
currently no support in the framework for enumerating all existing containing
views of a view.

You may want to try something different: specify a large but fixed size for
your view, but adapt the actual display to the size of the frame that you get
in method Restore. This is not 100% what you asked for, but may do in your
case. (Note: the coordinates (l,t,r,b) you also get in Restore may be a
subregion of the frame in cases where only a partial restore is required.
Therefore, you would have to use the frame's (l,t,r,b) coordinates.)

Hope this helps,

- Clemens