Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: eranon on September 04, 2012, 06:06:03 pm

Title: How to do Frame ptr be a member of app class when using wxSmith
Post by: eranon 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 ?
Title: Re: How to do Frame ptr be a member of app class when using wxSmith
Post by: oBFusCATed on September 04, 2012, 07:51:20 pm
Remove "//(*AppInitialize" and "//*)" and change the code however you like.
Title: Re: How to do Frame ptr be a member of app class when using wxSmith
Post by: eranon on September 04, 2012, 08:49:37 pm
Oops :o And wxSmith will not regenerate its block of code ?
Title: Re: How to do Frame ptr be a member of app class when using wxSmith
Post by: oBFusCATed on September 04, 2012, 09:04:27 pm
Yes, because after you remove the wxsmith markers the code becomes yours.
Title: Re: How to do Frame ptr be a member of app class when using wxSmith
Post by: Jenna 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() .
Title: Re: How to do Frame ptr be a member of app class when using wxSmith
Post by: eranon 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