Preventing the wxScrollbar getting the focus.

Luca Cappa luca.cappa at sequoia.it
Mon Jan 28 09:22:18 PST 2008


Hello,

I am using MSW2.8.7, and in my GUI I have a wxScrollbar which gets the  
keyboard focus and I would like to avoid the scrollbar from getting the  
focus.

I know that I could subclass the wxScrollbar class and override the  
wxWindow::AcceptsFocus and the wxWindow::AcceptsFocusFromKeyboard which  
should return false, but I would like to accomplish this by simply
pushing an event handler (and also because i am using a XRC editor and I  
do not want to deal with custom controls classes for this simple case).

I tried with the following event handler, but it requires that the  
scrollbar is created with the greater (or lowest) identifier number, so  
that it is the first or the last in the tab trasversal order, because if  
it is in the middle of this list then it wont allow the focus to  
passthrough the scrollbar (since it just put the focus back from where it  
came).

Any better solution or any advice is welcome.

Luca


struct NoFocusEventHandler : public wxEvtHandler
{
   DECLARE_DYNAMIC_CLASS (NoFocusEventHandler)

   void NoFocusEventHandler::onFocus (wxFocusEvent& pEvent);

   DECLARE_EVENT_TABLE()
};

IMPLEMENT_DYNAMIC_CLASS( NoFocusEventHandler, wxEvtHandler)
BEGIN_EVENT_TABLE (NoFocusEventHandler, wxEvtHandler)
   EVT_KILL_FOCUS (NoFocusEventHandler::onFocus)
   EVT_SET_FOCUS (NoFocusEventHandler::onFocus)
END_EVENT_TABLE ()

void NoFocusEventHandler::onFocus (wxFocusEvent& pEvent)
{
   pEvent.Skip (false);
   if (pEvent.GetEventType () == wxEVT_KILL_FOCUS)
   {
   }//if
   else if (pEvent.GetEventType () == wxEVT_SET_FOCUS)
   {
     if (wxWindow *lLostFocus = pEvent.GetWindow ())
       lLostFocus->SetFocus ();
   }//else if
}




More information about the wx-users mailing list