Class: Wx::CloseEvent

Inherits:
Event show all
Defined in:
lib/wx/doc/gen/events.rb

Overview

This event class contains information about window and session close events.

The handler function for EVT_CLOSE is called when the user has tried to close a a frame or dialog box using the window manager (X) or system menu (Windows). It can also be invoked by the application itself programmatically, for example by calling the Window#close function. You should check whether the application is forcing the deletion of the window using #can_veto. If this is false, you must destroy the window using Window#destroy. If the return value is true, it is up to you whether you respond by destroying the window. If you don’t destroy the window, you should call #veto to let the calling code know that you did not destroy the window. This allows the Window#close function to return true or false depending on whether the close instruction was honoured or not. Example of a CloseEvent handler:

def on_close(event)
    if event.can_veto? && @file_not_saved
      if Wx.message_box("The file has not been saved... continue closing?",
                        "Please confirm",
                        Wx::ICON_QUESTION | Wx::YES_NO) != Wx::YES)
        event.veto
        return
      end
    end
  
    destroy  # you may also do:  event.skip
             # since the default event handler does call #destroy too
  end

See also samples/dialogs for a full example of interrupting closing an application when there are e.g. unsaved files. The EVT_END_SESSION event is slightly different as it is sent by the system when the user session is ending (e.g. because of log out or shutdown) and so all windows are being forcefully closed. At least under MSW, after the handler for this event is executed the program is simply killed by the system. Because of this, the default handler for this event provided by wxWidgets calls all the usual cleanup code (including App#on_exit) so that it could still be executed and exit()s the process itself, without waiting for being killed. If this behaviour is for some reason undesirable, make sure that you define a handler for this event in your App-derived class and do not call event.Skip() in it (but be aware that the system will still kill your application).

Events using this class

The following event-handler methods redirect the events to member method or handler blocks for CloseEvent events. Event handler methods:

Category: Events

Instance Method Summary collapse

Methods inherited from Event

#clone, #get_event_category, #get_event_object, #get_event_type, #get_id, #get_skipped, #get_timestamp, #is_command_event, #resume_propagation, #set_event_object, #set_event_type, #set_id, #set_timestamp, #should_propagate, #skip, #stop_propagation

Methods inherited from Object

#clone, #dup, #is_same_as, #un_share

Constructor Details

#initialize(commandEventType = Wx::EVT_NULL, id = 0) ⇒ Wx::CloseEvent

Constructor.

Parameters:

  • commandEventType (Wx::GenericCollapsiblePane::EventType) (defaults to: Wx::EVT_NULL)
  • id (Integer) (defaults to: 0)


1780
# File 'lib/wx/doc/gen/events.rb', line 1780

def initialize(commandEventType=Wx::EVT_NULL, id=0) end

Instance Method Details

#can_vetoBoolean Also known as: can_veto?

Returns true if you can veto a system shutdown or a window close event.

Vetoing a window close event is not possible if the calling code wishes to force the application to exit, and so this function must be called to check this.

Returns:

  • (Boolean)


1786
# File 'lib/wx/doc/gen/events.rb', line 1786

def can_veto; end

#get_logging_offBoolean Also known as: logging_off

Returns true if the user is just logging off or false if the system is shutting down.

This method can only be called for end session and query end session events, it doesn’t make sense for close window event.

Returns:

  • (Boolean)


1793
# File 'lib/wx/doc/gen/events.rb', line 1793

def get_logging_off; end

#get_vetoBoolean

Returns whether the Veto flag was set.

Returns:

  • (Boolean)


1817
# File 'lib/wx/doc/gen/events.rb', line 1817

def get_veto; end

#set_can_veto(canVeto) ⇒ void Also known as: can_veto=

This method returns an undefined value.

Sets the ‘can veto’ flag.

Parameters:

  • canVeto (Boolean)


1799
# File 'lib/wx/doc/gen/events.rb', line 1799

def set_can_veto(canVeto) end

#set_logging_off(loggingOff) ⇒ void Also known as: logging_off=

This method returns an undefined value.

Sets the ‘logging off’ flag.

Parameters:

  • loggingOff (Boolean)


1805
# File 'lib/wx/doc/gen/events.rb', line 1805

def set_logging_off(loggingOff) end

#veto(veto = true) ⇒ void

This method returns an undefined value.

Call this from your event handler to veto a system shutdown or to signal to the calling application that a window close did not happen.

You can only veto a shutdown if #can_veto returns true.

Parameters:

  • veto (Boolean) (defaults to: true)


1813
# File 'lib/wx/doc/gen/events.rb', line 1813

def veto(veto=true) end