[Haskell-beginners] Overwriting wxFrame::ProcessEvent in wxHaskell

Nathan Hüsken nathan.huesken at posteo.de
Wed Sep 4 10:48:10 CEST 2013


Hey,

In C++ wxWidgets code, I discovered (by looking at the richtext example) 
that when I overwritte the ProcessEvent function of my main frame, a few 
wonderful effects occur:

* Cut/Copy/Paste/Undo/Redo menu entries work out of the box for 
wxTextCtrl and other simply by creating menu items with the correct id.
* The menu items are also updated to be enabled or disabled correctly.

I want that in wxHaskell to! But I do not know if and how I can 
overwrite the ProcessEvent function of wxFrame in wxHaskell ... anyone 
knows if there is a way?
There is windowPushEventHandler, which might be what I want. But it 
takes "EvtHandler a" as argument, and I do not know how to write an 
EvtHandler with my own event handling function ...

Regards,
Nathan

For completeness, the C++ version of what I want (taken from richedit.cpp):

bool MainFrame::ProcessEvent(wxEvent& event)
{
     if (event.IsCommandEvent() && 
!event.IsKindOf(CLASSINFO(wxChildFocusEvent)))
     {
         // Problem: we can get infinite recursion because the events
         // climb back up to this frame, and repeat.
         // Assume that command events don't cause another command event
         // to be called, so we can rely on inCommand not being overwritten

         static int s_eventType = 0;
         static wxWindowID s_id = 0;

         if (s_id != event.GetId() && s_eventType != event.GetEventType())
         {
             s_eventType = event.GetEventType();
             s_id = event.GetId();

             wxWindow* focusWin = wxFindFocusDescendant(this);
             if (focusWin && 
focusWin->GetEventHandler()->ProcessEvent(event))
             {
                 //s_command = NULL;
                 s_eventType = 0;
                 s_id = 0;
                 return true;
             }

             s_eventType = 0;
             s_id = 0;
         }
         else
         {
             return false;
         }
     }

     return wxFrame::ProcessEvent(event);
}





More information about the Beginners mailing list