Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development

Bug fix for wxSmith, when set default size in frame

(1/1)

Loaden:
In SVN 6197, when set wxSizer in frame ( NOT default size) , wxSmith automatically generated code is:

--- Quote ---Frame::Frame() : m_logCnt(0), m_dlgFind(NULL)
{
    //(*Initialize(Frame)
...

    Create(0, wxID_ANY, _("Parser Testing"), wxDefaultPosition, wxSize(800,550), wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR));
    sizer = new wxBoxSizer(wxHORIZONTAL);
...
   sizer->Fit(this);
    sizer->SetSizeHints(this);
    Center();
...
    //*)

    m_statuBar->SetStatusText(_("Ready!"));
}
--- End quote ---

BUT the code shoud be:

--- Quote ---Frame::Frame() : m_logCnt(0), m_dlgFind(NULL)
{
    //(*Initialize(Frame)
...

    Create(0, wxID_ANY, _("Parser Testing"), wxDefaultPosition, wxSize(800,550), wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR));
    sizer = new wxBoxSizer(wxHORIZONTAL);
...
   SetSizer(sizer);
    Layout();
    Center();
...
    //*)

    m_statuBar->SetStatusText(_("Ready!"));
}
--- End quote ---

This patch fix it, welcome to test.  :lol:


--- Code: ---Index: src/plugins/contrib/wxSmith/wxwidgets/wxscontainer.cpp

===================================================================

--- src/plugins/contrib/wxSmith/wxwidgets/wxscontainer.cpp (revision 6197)

+++ src/plugins/contrib/wxSmith/wxwidgets/wxscontainer.cpp (working copy)

@@ -209,21 +209,32 @@

                 wxsItem* Child = GetChild(i);
                 if ( Child->GetType() == wxsTSizer )
                 {
-                    wxString ChildAccessPrefix = Child->GetAccessPrefix(GetLanguage());
                     if ( GetBaseProps()->m_Size.IsDefault )
                     {
+                        wxString ChildAccessPrefix = Child->GetAccessPrefix(GetLanguage());
                         #if wxCHECK_VERSION(2, 9, 0)
                         Codef(_T("%sFit(%O);\n"),ChildAccessPrefix.wx_str());
                         #else
                         Codef(_T("%sFit(%O);\n"),ChildAccessPrefix.c_str());
                         #endif
+
+                        #if wxCHECK_VERSION(2, 9, 0)
+                        Codef(_T("%sSetSizeHints(%O);\n"),ChildAccessPrefix.wx_str());
+                        #else
+                        Codef(_T("%sSetSizeHints(%O);\n"),ChildAccessPrefix.c_str());
+                        #endif
                     }
+                    else
+                    {
+                        wxString ChildVarName = Child->GetVarName();
+                        #if wxCHECK_VERSION(2, 9, 0)
+                        Codef(_T("SetSizer(%s);\n"), ChildVarName.wx_str());
+                        #else
+                        Codef(_T("SetSizer(%s);\n"), ChildVarName.c_str());
+                        #endif
 
-                    #if wxCHECK_VERSION(2, 9, 0)
-                    Codef(_T("%sSetSizeHints(%O);\n"),ChildAccessPrefix.wx_str());
-                    #else
-                    Codef(_T("%sSetSizeHints(%O);\n"),ChildAccessPrefix.c_str());
-                    #endif
+                        Codef(_T("Layout();\n"));
+                    }
                 }
             }
 

--- End code ---

[attachment deleted by admin]

killerbot:
Can anyone confirm this, interesting for the release.

Jenna:
This is a snippet if I create a simple test project with a frame containing a boxsizer and syet the frames size to a fixed size:

--- Quote ---    [...]   
    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    SetClientSize(wxSize(450,150));
    BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
    SetSizer(BoxSizer1);
    [...]
    BoxSizer1->SetSizeHints(this);
    [...]

--- End quote ---

And I don't see what is wrong.
It works and it does more or less exactly what the wxWidgets docu suggests to do with a (box)sizer (according to the sizer overview.
Maybe I am wrong, but I don't know why it should be done the other way.

Loaden:
could you please explain what is wrong doing it this way and/or point me to the part of the wxWidgets documentation that describes why it should be done this way ?

Loaden:

--- Quote from: jens on March 29, 2010, 03:25:44 pm ---This is a snippet if I create a simple test project with a frame containing a boxsizer and syet the frames size to a fixed size:

--- Quote ---    [...]    
    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    SetClientSize(wxSize(450,150));
    BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
    SetSizer(BoxSizer1);
    [...]
    BoxSizer1->SetSizeHints(this);
    [...]

--- End quote ---

And I don't see what is wrong.
It works and it does more or less exactly what the wxWidgets docu suggests to do with a (box)sizer (according to the sizer overview.
Maybe I am wrong, but I don't know why it should be done the other way.

Loaden:
could you please explain what is wrong doing it this way and/or point me to the part of the wxWidgets documentation that describes why it should be done this way ?

--- End quote ---

Because wxFormBuilder is handled this way.
I compared the code before we find the reason.


--- Quote ---    Create(0, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
    SetClientSize(wxSize(450,150));
    wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
    wxTextCtrl* logCtrl = new wxTextCtrl(this, wxNewId(), wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxHSCROLL | wxTE_RICH2, wxDefaultValidator, _T("ID_LOGMAIN"));
    sizer->Add(logCtrl, 1, wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
    SetSizer(sizer);
    sizer->SetSizeHints(this);
--- End quote ---
NOTICE: The logCtrl use wxDefaultSize, but NOT wxSize(x, y).

If Changed to:

--- Quote ---    Create(0, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
    SetClientSize(wxSize(450,150));
    wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
    wxTextCtrl* logCtrl = new wxTextCtrl(this, wxNewId(), wxEmptyString, wxDefaultPosition, wxSize(800, 600), wxTE_MULTILINE | wxTE_READONLY | wxHSCROLL | wxTE_RICH2, wxDefaultValidator, _T("ID_LOGMAIN"));
    sizer->Add(logCtrl, 1, wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
    SetSizer(sizer);
    sizer->SetSizeHints(this);
--- End quote ---
It's work well.

Jenna:
You did not mention the textcontrol before.

I don't think we should change the wxSmith-code in this point, because it might break other (existing) layouts, that rely on the actual behaviour and I don't think it's a bug.

Maybe it could be made configurable to force the use of Layout instead of SetSizeHints .

Navigation

[0] Message Index

Go to full version