Author Topic: How to do Frame ptr be a member of app class when using wxSmith  (Read 5566 times)

Offline eranon

  • Almost regular
  • **
  • Posts: 180
How to do Frame ptr be a member of app class when using wxSmith
« on: September 04, 2012, 06:06:03 pm »
I would like to keep a reference to the main frame of my app. So, just adding this in testapp.h :
Code
TestFrame* m_pFrame;

And assignation in testapp.cpp, when the app class creates the main frame during its initialization. But wxSmith generates its own code like this :
Code
    //(*AppInitialize
    bool wxsOK = true;
    wxInitAllImageHandlers();
    if ( wxsOK )
    {
     TestFrame* Frame = new TestFrame(0);
     Frame->Show();
     SetTopWindow(Frame);
    }
    //*)
Then, how to do the most simple, from the point I can't modify the autogenerated wxSmith code block and Frame has no existence beyond the limited {} scope. Is there an option I didn't seen in wxSmith which could do Frame becomes a member of the app class ?
[Independent dev. - wxWidgets 3.0.0 under "Win 7 Pro 64-bit, C::B SVN 9435 & wxSmith, TDM64-GCC 4.7 & MSVC9" + "OS X 10.8, FSF GCC 4.7 & C::B SVN 8909"]

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: How to do Frame ptr be a member of app class when using wxSmith
« Reply #1 on: September 04, 2012, 07:51:20 pm »
Remove "//(*AppInitialize" and "//*)" and change the code however you like.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline eranon

  • Almost regular
  • **
  • Posts: 180
Re: How to do Frame ptr be a member of app class when using wxSmith
« Reply #2 on: September 04, 2012, 08:49:37 pm »
Oops :o And wxSmith will not regenerate its block of code ?
[Independent dev. - wxWidgets 3.0.0 under "Win 7 Pro 64-bit, C::B SVN 9435 & wxSmith, TDM64-GCC 4.7 & MSVC9" + "OS X 10.8, FSF GCC 4.7 & C::B SVN 8909"]

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: How to do Frame ptr be a member of app class when using wxSmith
« Reply #3 on: September 04, 2012, 09:04:27 pm »
Yes, because after you remove the wxsmith markers the code becomes yours.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: How to do Frame ptr be a member of app class when using wxSmith
« Reply #4 on: September 04, 2012, 09:09:20 pm »
What do you want to achieve ?

If you are inside the frame, it should know it's own address, if you are outside, you need the address to ask for the member variable.

The easiest way to get the address of the topmost window (frame, dialog or whatever) is wxTheApp->GetTopWindow() .

Offline eranon

  • Almost regular
  • **
  • Posts: 180
Re: How to do Frame ptr be a member of app class when using wxSmith
« Reply #5 on: September 10, 2012, 11:22:58 am »
Oops, solved since "long" time, jens. I didn't tagged any post as SOLVED because not any one matched exactly the solution I've adopted (I've just created a public method in app class which returns top level frame w/o relaying on any member). However, my main problem was orginally because of the wxSmith's block of code which doesn't store the pointer to the created frame as member... And I didn't liked the idea to remove the wxSmith tags (we never know the evolution of a tool by advance and he could need this code block a day or another ; better to not break natural working of tools chain in my mind).

--
EDIT : here is the fct ; also, I tag this post as SOLVED to close the thread ; it's not a self-congratulation, don't worry ;)
Code
MyFrame* MyApp::GetMainFrame()
{
    // Return a casted ptr to the toplevel frame of the app
    return (MyFrame*) GetTopWindow();
}

--
EDIT #2 : I should sleep during the night... I don't see any SOLVED button ; surely mixed with the wxWidgets forum in my mind ; oops, I said ;D
« Last Edit: September 10, 2012, 11:36:20 am by eanon »
[Independent dev. - wxWidgets 3.0.0 under "Win 7 Pro 64-bit, C::B SVN 9435 & wxSmith, TDM64-GCC 4.7 & MSVC9" + "OS X 10.8, FSF GCC 4.7 & C::B SVN 8909"]