# :stopdoc: # This file is automatically generated by the WXRuby3 documentation # generator. Do not alter this file. # :startdoc: module Wx # A global event filter for pre-processing all the events generated in the program. # This is a very simple class which just provides {Wx::EventFilter#filter_event} virtual method to be called by {Wx::EvtHandler} before starting process of any event. Thus, inheriting from this class and overriding {Wx::EventFilter#filter_event} allows capturing and possibly handling or ignoring all the events happening in the program. Of course, having event filters adds additional overhead to every event processing and so should not be used lightly and your {Wx::EventFilter#filter_event} code should try to return as quickly as possible, especially for the events it is not interested in. # An example of using this class: # ```ruby # # This class allows determining the last time the user has worked with # # this application: # class LastActivityTimeDetector < Wx::EventFilter # def initialize # Wx::EvtHandler.add_filter(self) # # @last = Time.now # end # # def clear # Wx::EvtHandler.remove_filter(self) # end # # def filter_event(event) # # Update the last user activity # t = event.get_event_type # case t # when Wx::EVT_KEY_DOWN, # Wx::EVT_MOTION, # Wx::EVT_LEFT_DOWN, # Wx::EVT_RIGHT_DOWN, # Wx::EVT_MIDDLE_DOWN # @last = Time.now # end # # # Continue processing the event normally as well. # Event_Skip # end # # # This function could be called periodically from some timer to # # do something (e.g. hide sensitive data or log out from remote # # server) if the user has been inactive for some time period. # def is_inactive_for?(diff) # (Time.now - diff) > @last # end # # end # ``` # # Notice that {Wx::App} derives from {Wx::EventFilter} and is registered as an event filter during its creation so you may also override {Wx::EventFilter#filter_event} method in your {Wx::App}-derived class and, in fact, this is often the most convenient way to do it. However creating a new class deriving directly from {Wx::EventFilter} allows isolating the event filtering code in its own separate class and also having several independent filters, if necessary. # Category: {Wx::Events} # # # @note This class is untracked and should not be derived from nor instances extended! class EventFilter < ::Object # Process event as usual. # Event_Skip = -1 # Don't process the event normally at all. # Event_Ignore = 0 # Event was already handled, don't process it normally. # Event_Processed = 1 # Default constructor. # Constructor does not register this filter using {Wx::EvtHandler.add_filter}, it's your responsibility to do it when necessary. # Notice that the objects of this class can't be copied. # @return [Wx::EventFilter] def initialize; end # Override this method to implement event pre-processing. # This method allows filtering all the events processed by the program, so you should try to return quickly from it to avoid slowing down the program to a crawl. # Although the return type of this method is int, this is only due to backwards compatibility concerns and the actual return value must be one of the Event_XXX constants defined above: # # - Event_Skip to continue processing the event normally (this should be used in most cases). # - Event_Ignore to not process this event at all (this can be used to suppress some events). # - Event_Processed to not process this event normally but indicate that it was already processed by the event filter and so no default processing should take place either (this should only be used if the filter really did process the event). # @param event [Wx::Event] # @return [Integer] def filter_event(event) end end # EventFilter end