Author Topic: wxSmith - wxGLCanvas - patch  (Read 6310 times)

Offline seb_seb0

  • Almost regular
  • **
  • Posts: 166
wxSmith - wxGLCanvas - patch
« on: March 12, 2010, 11:37:29 pm »
Hello,

I ran into a problem while using wxSmith + wxGLCanvas (in"advanced" group of widgets).
The constructor code provided by wxSmith is not wxWidgets 2.9.0 compatible (order of parameters are different)

Here is the patch (against SVN 6181)

file <CODE::BLOCKS DIR>\src\plugins\contrib\wxSmith\wxwidgets\defitems\wxsglcanvas.cpp
replace line 211.
- (old line)
Code
Codef(_T("%C(%W, %I, %P, %S, %T, %N, %v);\n"),aname.wx_str());

+ (new line)
Code
Codef(_T("%C(%W, %I, %v, %P, %S, %T, %N);\n"),aname.wx_str());

notice the change of the %v parameter.

This is all ! Now it works for me !

Best regards,

Seb

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: wxSmith - wxGLCanvas - patch
« Reply #1 on: March 13, 2010, 08:46:32 am »
you say for wx 2.9, can I conclude the old version of that line should reamin as it is for wx 2.8 ?
So actually we need then an #ifdef construct ?

Offline seb_seb0

  • Almost regular
  • **
  • Posts: 166
Re: wxSmith - wxGLCanvas - patch
« Reply #2 on: March 13, 2010, 12:01:34 pm »
Yes, there are differences between constructors.

wxWidgets 2.8.10:
Code
void wxGLCanvas(wxWindow* parent, 
                        wxWindowID id = -1,     
                        const wxPoint& pos = wxDefaultPosition,
                        const wxSize& size = wxDefaultSize,
                        long style=0,
                        const wxString& name="GLCanvas",
                        int* attribList = 0,
                        const wxPalette& palette = wxNullPalette)

wxWidgets 2.9:
Code
wxGLCanvas (wxWindow *parent, 
                   wxWindowID id=wxID_ANY,
                   const int *attribList=NULL,
                   const wxPoint &pos=wxDefaultPosition,
                   const wxSize &size=wxDefaultSize,
                   long style=0,
                   const wxString &name="GLCanvas",
                   const wxPalette &palette=wxNullPalette)

The attribList parameter shifts from last to third position between the 2 wxWidgets versions - and it gives a compiler mistakes.

It is true that the patch will break the 2.8.10 constructor (not a so good solution).
Therefore I propose the following change:

ORIGINAL CODE:
Code
            #if wxCHECK_VERSION(2, 9, 0)
            Codef(_T("%C(%W, %I, %P, %S, %T, %N, %v);\n"),aname.wx_str());
            #else
            Codef(_T("%C(%W, %I, %P, %S, %T, %N, %v);\n"),aname.c_str());
            #endif

NEW CODE:
           
Code
#if wxCHECK_VERSION(2, 9, 0)
            Codef(_T("#if wxCHECK_VERSION(2, 9, 0)\n"),aname.wx_str());
            Codef(_T("%C(%W, %I, %v, %P, %S, %T, %N);\n"),aname.wx_str());
            Codef(_T("#else\n"),aname.wx_str());
            Codef(_T("%C(%W, %I, %P, %S, %T, %N, %v);\n"),aname.wx_str());
            Codef(_T("#endif\n"),aname.wx_str());
            #else
            Codef(_T("#if wxCHECK_VERSION(2, 9, 0)\n"),aname.c_str());
            Codef(_T("%C(%W, %I, %v, %P, %S, %T, %N);\n"),aname.c_str());
            Codef(_T("#else\n"),aname.c_str());
            Codef(_T("%C(%W, %I, %P, %S, %T, %N, %v);\n"),aname.c_str());
            Codef(_T("#endif\n"),aname.c_str());
            #endif

That will put a wxCHECK_VERSION directive in the user code - therefore wxSmith will adapt itself directly to the user choice.
I have tested it this morning - here is the result code generated by wxSmith:

Code
         int GLCanvasAttributes_1[] = {
WX_GL_RGBA,
WX_GL_DOUBLEBUFFER,
WX_GL_DEPTH_SIZE,      16,
WX_GL_STENCIL_SIZE,    0,
0, 0 };
#if wxCHECK_VERSION(2, 9, 0)
GLCanvas1 = new wxGLCanvas(this, ID_GLCANVAS1, GLCanvasAttributes_1, wxDefaultPosition, wxSize(60,180), 0, _T("ID_GLCANVAS1"));
#else
GLCanvas1 = new wxGLCanvas(this, ID_GLCANVAS1, wxDefaultPosition, wxSize(60,180), 0, _T("ID_GLCANVAS1"), GLCanvasAttributes_1);
#endif

and it compiles perfectly well on my computer.
I attach also a patch (done against trunk this morning):



[attachment deleted by admin]

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: wxSmith - wxGLCanvas - patch
« Reply #3 on: March 13, 2010, 04:15:07 pm »

The patch looks good, but you can get rid of those "aname.wx_str*()" and "aname.c_str()"  where they are not needed:

NEW CODE:
            #if wxCHECK_VERSION(2, 9, 0)
            Codef(_T("#if wxCHECK_VERSION(2, 9, 0)\n"),aname.wx_str());
            Codef(_T("%C(%W, %I, %v, %P, %S, %T, %N);\n"),aname.wx_str());
            Codef(_T("#else\n"),aname.wx_str());
            Codef(_T("%C(%W, %I, %P, %S, %T, %N, %v);\n"),aname.wx_str());
            Codef(_T("#endif\n"),aname.wx_str());
            #else
            Codef(_T("#if wxCHECK_VERSION(2, 9, 0)\n"),aname.c_str());
            Codef(_T("%C(%W, %I, %v, %P, %S, %T, %N);\n"),aname.c_str());
            Codef(_T("#else\n"),aname.c_str());
            Codef(_T("%C(%W, %I, %P, %S, %T, %N, %v);\n"),aname.c_str());
            Codef(_T("#endif\n"),aname.c_str());
            #endif


That "aname" value is only needed where you have a "%v" somewhere in the print format.

Ringo