wxStaticBoxSizer & wxStaticBox Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
raananb
Super wx Problem Solver
Super wx Problem Solver
Posts: 488
Joined: Fri Oct 27, 2006 4:35 pm
Location: Paris, France
Contact:

wxStaticBoxSizer & wxStaticBox

Post by raananb »

The following code will apply a given font to all children of a given sizer, except when the child is a wxStaticBoxSizer.

When a child is a wxStaticBoxSizer, GetStaticBox() should be called since the font applies to the static box and not to the sizer.

How can I check that a given sizer is a wxStaticBoxSizer ?

Code: Select all

void SetFontAllSizer(wxSizer* sp, const wxFont& font)
{
    wxSizerItem* current;

    wxSizerItemList& children = sp->GetChildren();

    for (wxSizerItemList::Node *node = children.GetFirst(); node; node = node->GetNext())
    {
        current = node->GetData();
    
        if (current->IsWindow())
        {
            current->GetWindow()->SetFont(font);
        }
        else if (current->IsSizer())
        {
            SetFontAllSizer(current->GetSizer(),font);
        }
    }
}
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxStaticBoxSizer & wxStaticBox

Post by doublemax »

Code: Select all

wxSizer *sbs = new wxStaticBoxSizer(wxVERTICAL, panel, "header");
wxLogMessage("sbs is a : wxSizer => %s", sbs->IsKindOf(wxCLASSINFO(wxSizer)) ? "yes" : "no" );
wxLogMessage("sbs is a : wxGridSizer => %s", sbs->IsKindOf(wxCLASSINFO(wxGridSizer)) ? "yes" : "no" );
wxLogMessage("sbs is a : wxStaticBoxSizer => %s", sbs->IsKindOf(wxCLASSINFO(wxStaticBoxSizer)) ? "yes" : "no" );
Use the source, Luke!
raananb
Super wx Problem Solver
Super wx Problem Solver
Posts: 488
Joined: Fri Oct 27, 2006 4:35 pm
Location: Paris, France
Contact:

Re: wxStaticBoxSizer & wxStaticBox

Post by raananb »

Thanks for the information.

The modified code below will set the font of all children of a sizer, including static box sizers, on Windows & Linux, but not on OSX.

Code: Select all

void SetFontAllSizer(wxSizer* sp, const wxFont& font)
{
    wxSizerItem* current;

    wxSizerItemList& children = sp->GetChildren();

    for (wxSizerItemList::Node *node = children.GetFirst(); node; node = node->GetNext())
    {
        current = node->GetData();
    
        if (current->IsWindow())
        {
            current->GetWindow()->SetFont(font); 
        }
        else if (current->IsSizer())
        {
            if (current->GetSizer()->IsKindOf(wxCLASSINFO(wxStaticBoxSizer)))
            {
                wxStaticBoxSizer* sb = (wxStaticBoxSizer*) current->GetSizer(); 
                sb->GetStaticBox()->SetFont(font);
            }
        
            SetFontAllSizer(current->GetSizer(),font);
        }
    }
}
Post Reply