Sha256: 2b7bd9b79b01a39d80d739abf2e1c9aef5252a9ce828d1718c9be6affc7e574b

Contents?: true

Size: 1.93 KB

Versions: 54

Compression:

Stored size: 1.93 KB

Contents

module Fox
  # Module to include in FXDialogBox to provide an easy nonmodal version
  # of execute.
  module FTNonModal

    def initialize(*args)
      super if defined?(super)
      FXMAPFUNC(SEL_COMMAND, FXDialogBox::ID_CANCEL, :onCmdCancel)
      FXMAPFUNC(SEL_COMMAND, FXDialogBox::ID_ACCEPT, :onCmdAccept)
    end

    #
    # Creates and shows the dialog, and registers the associated block to be
    # called when the dialog is closed. The block is passed a boolean argument
    # which is true if and only if the dialog was accepted.
    #
    # For example:
    #
    #   dialogBox.execute_modal do |accepted|
    #     if accepted
    #       puts "Dialog accepted"
    #     else
    #       puts "Dialog cancelled"
    #    end
    #
    def execute_modal(placement = PLACEMENT_CURSOR, &block)
      @__FTNonModal_block = block
      execute(placement)
    end
 
    #
    # Creates and shows the dialog, and registers the associated block to be
    # called when the dialog is closed. The block is passed a boolean argument
    # which is true if and only if the dialog was accepted.
    #
    # For example:
    #
    #   dialogBox.execute_nonmodal do |accepted|
    #     if accepted
    #       puts "Dialog accepted"
    #     else
    #       puts "Dialog cancelled"
    #    end
    #
    def execute_nonmodal(placement = PLACEMENT_CURSOR, &block)
      @__FTNonModal_block = block
      create
      show placement
    end

    def onCmdCancel(*args) # :nodoc:
      on_nonmodal_close(false)
    end

    def onCmdAccept(*args) # :nodoc:
      on_nonmodal_close(true)
    end

    # Called when dialog is closed, with _accepted_ equal to +true+ if and
    # only if the user accepted the dialog.
    def on_nonmodal_close(accepted)
      @__FTNonModal_block[accepted]

      ##return 0 -- why isn't this enough to close window?
      ## oh well, let's imitate FXTopWindow:
      getApp().stopModal(self, accepted ? 1 : 0)
      hide()
    end
  end
end

Version data entries

54 entries across 54 versions & 2 rubygems

Version Path
fxruby-1.6.22.pre2-x86-mingw32 lib/fox16/execute_nonmodal.rb
fxruby-1.6.22.pre2 lib/fox16/execute_nonmodal.rb
fxrubi-1.6.22.pre1-x86-mingw32 lib/fox16/execute_nonmodal.rb
fxrubi-1.6.22.pre1 lib/fox16/execute_nonmodal.rb
fxruby-1.6.20-x86-mingw32 lib/fox16/execute_nonmodal.rb
fxruby-1.6.20-x86-linux lib/fox16/execute_nonmodal.rb
fxruby-1.6.20 lib/fox16/execute_nonmodal.rb
fxruby-1.6.20-universal-darwin-10 lib/fox16/execute_nonmodal.rb
fxruby-1.6.19-x86-mingw32 lib/fox16/execute_nonmodal.rb
fxruby-1.6.14-mswin32 lib/fox16/execute_nonmodal.rb
fxruby-1.6.13-mswin32 lib/fox16/execute_nonmodal.rb
fxruby-1.2.3 lib/fox12/execute_nonmodal.rb
fxruby-1.2.4 lib/fox12/execute_nonmodal.rb
fxruby-1.2.5 lib/fox12/execute_nonmodal.rb
fxruby-1.4.0 lib/fox14/execute_nonmodal.rb
fxruby-1.2.6 lib/fox12/execute_nonmodal.rb
fxruby-1.4.1 lib/fox14/execute_nonmodal.rb
fxruby-1.4.2 lib/fox14/execute_nonmodal.rb
fxruby-1.4.3 lib/fox14/execute_nonmodal.rb
fxruby-1.4.4 lib/fox14/execute_nonmodal.rb