Class: Fox::FXAccelTable

Inherits:
FXObject show all
Defined in:
rdoc-sources/FXAccelTable.rb,
lib/fox16/accel_table.rb

Overview

The accelerator table sends a message to a specific target object when the indicated key and modifier combination is pressed.

Instance Method Summary collapse

Methods inherited from FXObject

#bind, #handle, #load, #save, subclasses

Constructor Details

#initializeFXAccelTable

Construct empty accelerator table.


11
12
# File 'rdoc-sources/FXAccelTable.rb', line 11

def initialize # :yields: acceleratorTable
end

Instance Method Details

#addAccel(hotKey, *args) ⇒ Object

Add an accelerator to the table. The hotKey is a code returned by the Fox.fxparseAccel method.

There are several forms for addAccel; the original form (from FOX) takes either three or four arguments. For example, to associate the Ctrl+H keypress with sending the “hide” command to a window, you might use code like this:

hotKey = fxparseAccel("Ctrl+H")
accelTable.addAccel(hotKey, window, FXSEL(SEL_COMMAND, FXWindow::ID_HIDE))

If you instead want to trigger the command on the key release (instead of the key press), pass a zero for the third argument and pass the command as the fourth argument:

accelTable.addAccel(hotKey, window, 0, FXSEL(SEL_COMMAND, FXWindow::ID_HIDE))

You can even pass in two different messages, corresponding to the key press and key release events for the hot key, although this is less common.

accelTable.addAccel(hotKey, window,
  FXSEL(SEL_COMMAND, FXWindow::ID_HIDE),
  FXSEL(SEL_COMMAND, FXWindow::ID_SHOW))

The problem with this form is that you need to be familiar with the message types and identifiers that different widgets respond to, and this information isn't very well documented. A more straightforward way to use addAccel from Ruby code is to instead pass one or more callable objects in as the second and third arguments. For example:

accelTable.addAccel(hotKey, lambda { window.hide })

or to trigger the event on the key release event:

accelTable.addAccel(hotKey, nil, lambda { window.hide })

Or to handle both the key press and key release events:

accelTable.addAccel(hotKey, lambda { window.hide }, lambda { window.show })

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fox16/accel_table.rb', line 46

def addAccel(hotKey, *args)
  tgt, seldn, selup = nil, 0, 0
  if args.length > 0
    if args[0].respond_to? :call
      tgt = FXPseudoTarget.new
      seldn = Fox.FXSEL(SEL_KEYPRESS, 0)
      tgt.pconnect(SEL_KEYPRESS, args[0])
    else
      tgt = args[0]
    end
    if args.length > 1
      if args[1].respond_to? :call
        tgt = tgt || FXPseudoTarget.new
        selup = Fox.FXSEL(SEL_KEYRELEASE, 0)
        tgt.pconnect(SEL_KEYRELEASE, args[1])
      else
        seldn = args[1]
        selup = args[2] if args.length > 2
      end
    end
  end
  # FIXME: The target objects stored in the accelerator table are currently
  # private. Therefore FXRbAccelTable::markfunc() doesn't mark them as used.
  # As a workaround the objects are additionally stored in @targets Hash.
  @targets = {} unless instance_variable_defined?('@targets')
  @targets[hotKey] = tgt
  addAccelOrig(hotKey, tgt, seldn, selup)
end

#addAccelOrigObject

:nodoc:


3
# File 'lib/fox16/accel_table.rb', line 3

alias addAccelOrig addAccel

#hasAccel?(hotKey) ⇒ Boolean

Return true if accelerator specified. Here, hotKey is a code representing an accelerator key as returned by the Fox.fxparseAccel method. For example,

if accelTable.hasAccel?(fxparseAccel("Ctrl+S"))
  ...
end

Returns:

  • (Boolean)

28
# File 'rdoc-sources/FXAccelTable.rb', line 28

def hasAccel?(hotKey) ; end

#removeAccel(hotKey) ⇒ Object

Remove mapping for specified hot key. Here, hotKey is a code representing an accelerator key as returned by the Fox.fxparseAccel method. For example,

accelTable.removeAccel(fxparseAccel("Ctrl+S"))

17
# File 'rdoc-sources/FXAccelTable.rb', line 17

def removeAccel(hotKey) ; end

#removeAccelOrigObject

Remove mapping for specified hot key. Here, hotKey is a code representing an accelerator key as returned by the Fox.fxparseAccel method. For example,

accelTable.removeAccel(fxparseAccel("Ctrl+S"))

:nodoc:


75
# File 'lib/fox16/accel_table.rb', line 75

def removeAccel(hotKey) ; end

#targetOfAccel(hotKey) ⇒ Object

Return the target object of the given accelerator, or nil if the accelerator is not present in this accelerator table. Here, hotKey is a code representing an accelerator key as returned by the Fox.fxparseAccel method. For example,

doc = accelTable.targetofAccel(fxparseAccel("Ctrl+S"))

38
# File 'rdoc-sources/FXAccelTable.rb', line 38

def targetOfAccel(hotKey) ; end