[wx-dev] [wxMac] wxButton and wxBU_EXACTFIT

Stefan Csomor csomor at advancedconcepts.ch
Fri Sep 21 12:35:24 PDT 2007


Hi Julian
> I was wondering why wxButton didn't respond to wxBU_EXACTFIT and 
> noticed that in wxButton::Create, 'bounds' is set to (-1, -1, -1, -1) 
> by wxGetBoundsForControl for a default button size. Then, we have the 
> line:
>
>            bounds.bottom = bounds.top + 20 ;
>
> but the right, top and left of the bounds are not set So they are left 
> at with -1 values before being passed to CreatePushButtonControl, 
> which doesn't seem quite right. However this may be OK and a red 
> herring...
it does not really matter that much, all controls are correctly resized 
on the MacPostControlCreate by asking for the best size, which involves 
in many cases asking the native controls for its best size

> Then, in wxButton::DoGetBestSize, we have
>
>    wxSize sz = GetDefaultSize() ;
>
> (getting a size of 70 x 20) and then
>
>    Rect    bestsize = { 0 , 0 , 0 , 0 } ;
>    m_peer->GetBestRect( &bestsize ) ;
>
> which returns (-1, -1, 19, 69) because presumably the -1 has been 
> added to the default 20 and 70 height and width.
a mac rect is top,left,bottom,right so the size is still ok
> Then the code which should take into account wxBU_EXACTFIT:
>
>    int wBtn;
>    if ( EmptyRect( &bestsize ) )
>    {
>       //  !!! This is never executed AFAICT becase the rect is never 
> empty (?)
>        wBtn = m_label.length() * charspace + 12 ;
>    }
>    else
>    {
>        wBtn = bestsize.right - bestsize.left ;
>        sz.y = bestsize.bottom - bestsize.top ;
>    }
>
> so wBtn is never set to the actual length of the text...
>
>    if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT))
>        sz.x = wBtn;
>
> ...and therefore wxBU_EXACTFIT has no effect.
>
> We could probably do this:
>
>    int wBtn;
>    if ( EmptyRect( &bestsize )  || ( GetWindowStyle() & wxBU_EXACTFIT))
>    {
>        wBtn = m_label.length() * charspace + 12 ;
>    }
>
> Do you think that would solve it?
it would solve that problem, yes, I just hope that wxBU_EXACTFIT isn't 
used to many times, otherwise we will get that ugly layout with small 
push buttons for small text, which gives every mac user shivers ... due 
to that bug, these cases didn't show up until we fixed it ... ;-)

I'll have to come up with a better estimate first, things like '<<' 
aren't getting enough space

Thanks,

Stefan







More information about the wx-dev mailing list