Author Topic: Bug fix for wxSmith, when set default size in frame  (Read 8128 times)

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Bug fix for wxSmith, when set default size in frame
« on: March 29, 2010, 01:44:51 pm »
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!"));
}

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!"));
}

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"));
+                    }
                 }
             }
 

[attachment deleted by admin]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: Bug fix for wxSmith, when set default size in frame
« Reply #1 on: March 29, 2010, 02:09:28 pm »
Can anyone confirm this, interesting for the release.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Bug fix for wxSmith, when set default size in frame
« Reply #2 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);
    [...]

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 ?

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: Bug fix for wxSmith, when set default size in frame
« Reply #3 on: March 29, 2010, 04:20:15 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);
    [...]

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 ?

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);
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);
It's work well.
« Last Edit: March 29, 2010, 04:28:36 pm by Loaden »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Bug fix for wxSmith, when set default size in frame
« Reply #4 on: March 29, 2010, 04:37:54 pm »
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 .