Let's say I have an option in my preferences menu to turn on and off tooltips. Preference get saved to a file on program exit and preferences get loaded for the file on program startup as usual. If our preferences say, "No Tooltips" when we start up, it's a pain getting wxToolTip::Enable(false) to have any effect until WAY after the ctor of the wxFrame.
Here's a few examples of the issue. We will keep saving and loading preferences out of this to keep things easy, and just try to turn tooltips off on program start.
EXAMPLE 1 - try after the frame ctor
Code: Select all
bool MyApp::OnInit()
{
if ( !wxApp::OnInit() ) return false;
Myframe frame = new MyFrame(0L, wxT("app"), 0);
SetTopWindow(frame);
frame->Show();
frame->Refresh();
wxToolTip::enable(false); //DOES NOT WORK
return true;
}
EXAMPLE 2 - try to make an event and post it after the ctor
Code: Select all
if ( !wxApp::OnInit() ) return false;
Myframe frame = new MyFrame(0L, wxT("app"), 0);
SetTopWindow(frame);
frame->Show();
frame->Refresh();
frame->AfterInit();
return true;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, MyFrame::OnSetToolTip)
END_EVENT_TABLE()
MyFrame::AfterInit(){
wxCommandEvent MyEvent( wxEVT_COMMAND_BUTTON_CLICKED ); wxPostEvent(this, MyEvent);
}
MyFrame::OnSetToolTip(){
//this event fires ok.
wxToolTip::Enable(false); //DOES NOT WORK
}
EXAMPLE 3 - use OnIdle event and and try a bunch.. this one works.
Code: Select all
if ( !wxApp::OnInit() ) return false;
Myframe frame = new MyFrame(0L, wxT("app"), 0);
SetTopWindow(frame);
frame->Show();
frame->Refresh();
return true;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_IDLE(MyFrame::OnIdle)
END_EVENT_TABLE()
MyFrame::MyFrame()
{
idleMarker = 0;
SetExtraStyle(wxWS_EX_PROCESS_IDLE);
}
void MyFrame::OnIdle(wxIdleEvent &event)
{
wxToolTip::Enable(false); //let's just beat the crap out of it for the first 500 idles.
//After around 82 idles. . . IT WORKS!!!!
if(idleMarker > 500){
SetExtraStyle(0); //Stop processing Idle
}
idleMarker++;
}
As you can see.. I've got to go to some extremes to get wxToolTip::Enable(false) to work on startup. During runtime, it works fine. It's just during startup. And no.. my actual OnIdle() function is not that ugly. . . it's just an example of where wxTooTip::Enable(false) actually takes effect.
Surley there must be a more correct way of accomplishing this. Any Ideas?