wxToolTip::Enable(false) does NOT work in ctor Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
aquawicket
Earned some good credits
Earned some good credits
Posts: 103
Joined: Sun Aug 05, 2007 5:49 am

wxToolTip::Enable(false) does NOT work in ctor

Post by aquawicket »

Ok, here's a little problem I've been dealing with all day. Quite an annoying little bugger.

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?
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol »

You can try using wxActivateEvent, then set a flag, so that the code only executes the first time the main window is activated

Regards.
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
aquawicket
Earned some good credits
Earned some good credits
Posts: 103
Joined: Sun Aug 05, 2007 5:49 am

Post by aquawicket »

I threw in a EVT_ACTIVATE(MyFrame::SetToolTip). The first time the event triggers, it's still too soon to use wxToolTip::Enable(false); Then the event won't trigger again until the User changes windows etc. Oh Well. :P

Maybe there's a way to hold an event and post it to the very end of the que. Not sure. Think I'll start digging into the wx/tooltip.cpp file to see what can be done.

I,m gonna give it a break for now and come back to this one later since the Idle Event is working for now. Thanks for the reply protocol.
Strati
Earned a small fee
Earned a small fee
Posts: 13
Joined: Sun Aug 03, 2008 11:44 am
Location: Sulzbach (Taunus), Germany

Post by Strati »

Hi, I am stuck at the same problem. However I observed the following:

A tooltip on a wxListBox responds perfectly and immediately to my toggling of wxToolTip::Enable(toolbar);

What is not responding are my toolbar buttons, their tooltips always show up, even with

Code: Select all

void HauptFrame::OnIdle( wxIdleEvent& event )
{
    wxToolTip::Enable(false);
}
My toolbars are of type wxToolBar inside an aui managed frame. Since I am using wxwidgets to not care about MSWindows details :) I am lost at debugging why the broadcast SendTooltipMessageToAll() does not have the desired result. :(
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol »

In addition to the proposed wxActivateEvent, I also use a wxTimer, start it during the first wxActivateEvent, then 5 secs (or whatever) after the event I do the "app started" code.

regards.
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
Strati
Earned a small fee
Earned a small fee
Posts: 13
Joined: Sun Aug 03, 2008 11:44 am
Location: Sulzbach (Taunus), Germany

Post by Strati »

Hi,
protocol wrote:In addition to the proposed wxActivateEvent, I also use a wxTimer, start it during the first wxActivateEvent, then 5 secs (or whatever) after the event I do the "app started" code.
I am sorry, I do not really get, why all this is needed. As far as I understand we have two issues here:

1) the tooltip state gets ignored during creation of the frame, leaving tooltips enabled.
2) the wxToolbar buttons (those you create with wxToolbar::AddTool()) ignores the tooltip state at all (always display tooltip). The wxToolbar itself can have a tooltip, this one responds perfectly. Also any control I put in a toolbar responds. But not the toolbar's own buttons.

1) I simply solved like this in CreateControls()

Code: Select all

...
GetAuiManager().Update();
wxToolTip::Enable(myTooltipState);
...
2) To me this looks like a bug related to wxToolbar.

Now I am not sure anymore if I have the same issues as aquawicket.

Regards, Michael
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol »

Strati wrote:I am sorry, I do not really get, why all this is needed.
To clarify, Strati, all the code I proposed was in relation to "just started app" code techniques; without using OnIdle. Better/different ways to detect when the application has fully started.
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
Post Reply