[wxMac 2.8x] wxWindow::DoGetBestSize bug still not solved

H H at h.com
Sun Apr 15 07:53:49 PDT 2007


In article <AJPNhB.A.aGF.CBWIGB at brage.sunsite.dk>,
 vadim at wxwindows.org (Vadim Zeitlin) wrote:

> On Sat, 14 Apr 2007 23:21:17 +0200 H <H at h.com> wrote:
> 
> H> no, the problem is in wxWindowBase::DoGetBestSize() during 
> H> initialization. When this method is called the scrollbars already exist 
> H> but are ignored due to
> H> 
> H> #ifdef __WXMAC__
> H>               && wxHasRealChildren(this)
> H> #endif
> H> 
> H> So, the next "else"-branch is used:
> H> 
> H>     else // ! has children

The window has children but only scrollbars. As these are no "real" 
children the else-clause is reached.
> H>     {
> ...
> H>         wxSize size = GetMinSize();

size contains afterwards (-1, -1)
> H>         if ( !size.IsFullySpecified() )
> H>         {
> H>             size.SetDefaults(GetSize());

GetSize() returns (0, 0). Probably you do not expect it but that is what 
is returned. The window is constructed with a default size of (0, 0).
> H>             wxConstCast(this, wxWindowBase)->SetMinSize(size);
> H>         }
> H> 
> H>         // return as-is, unadjusted by the client size difference.
> H>         return size;

As size contains (0, 0) - as the window is basically not initialized 
correctly for the operation system it has got the size (0, 0) on the 
screen. Therefore, (0, 0) is the return result.
> H>     }
> H> 
> H> But as written in the comments the size is returned as it is (see 
> H> above). Namely, wxSize(0, 0). THERE IS NO ADJUSTMENT!
> 
>  Wait, but GetSize(), unlike GetClientSize(), should already account for
> the scrollbars. Or do you mean that there is a min size set for this
> window? I agree that we should add scrollbars (i.e. the difference between
> size and client size) in this case. But when the min size is not set (as is
> the case here AFAICS) we already should have the correct size. Am I still
> missing something?
> 
>  Thanks,
> VZ

Yes, you are still missing something (see my comments in the source code 
above).
When the real window size is (0, 0) and there are children (in this case 
scrollbars) you might get a negative client size.
As DoGetBestSize is often used to initialize windows correctly this 
method should return a size making sure that the children's sizes are 
taken into consideration.
Or you should modify "GetClientSize()".

I would already have fixed the problem if somebody can tell me which 
functions should have which values. I do not know which values these 
functions should return:

 - GetSize() // probably at all times the real size of the window
 - GetClientSize() // what happens if the children's sizes are larger 
than the window's size? At the moment we get sometimes negative values 
under these conditions.
 - DoGetBestSize // which size is best? With or without scrollbars - 
especially if only scrollbars are present?
 - Get/SetMinSize() // What is the minimum size - again especially under 
the condition of existing/visible scrollbars?
 - SetDefaults() // with or without scrollbars? Does a default size of 
(0, 0) makes sense at all? At the moment (0, 0) is returned which does 
not make sense for me at all as this results in a non-visible window as 
a default state.

At the moment I am using these functions hoping that they return 
something useful but this is not always the case.

Hartwig






More information about the wx-users mailing list