Connect Event Methods

The following methods connect dialog control events to methods the programmer defines in the parent dialog class.

ConnectKeyPress

>>-aDialogControl~ConnectKeyPress(--msgToRaise--,--keys--+-----------+--)----><
                                                         +-,-filter--+

The ConnectKeyPress method connects a key down event, when the control has the keyboard focus, with a programmer defined method in the parent dialog of the control. The underlying Windows dialog must exist before this method can be invoked.

Note: This method is only available on systems running Windows XP or later. On earlier versions of Windows, the method will fail and return -4.

The arguments, return values, and behavior of this method are the same as those for the ConnectKeyPress method of the BaseDialog. However, the method of the BaseDialog connects any key down event when the dialog is the active window and this method of the DialogControl only connects the key down events when the specific control has the focus. See the ConnectKeyPress method of the BaseDialog for a detailed description of the arguments, return values, and behavior.

Arguments:

The arguments are:

msgToRaise

The method to be invoked for the key down event.

keys

The key, or list of keys, whose key down event will invoke the method specified by msgToRaise.

filter

An optional filter to be applied to the key down event.

Return value:

The return values are:

0

Success.

1

The underlying mechanism in the Windows API failed.

-1

A problem with one of the arguments.

-2

An (internal) problem with the dialog window.

-3

An (internal) problem with the dialog administration.

-4

This method is not supported by this version of Windows. Windows XP or later is required.

-5

Memory allocation error in the underlying Windows API.

-6

The maximum number of connections has been reached.

-7

The msgToRaise method is already connected to a key down event for this dialog control.

Event Method Arguments

The ooDialog method connected to the key press event will receive the following five arguments in the order listed:

keyCode

The numeric code of the key pressed.

shift

True if a shift key was down at the time of the event and false if the shift key was not down.

control

True if a control key was down at the time of the key press, false if it was not.

alt

True if an alt key was down at the time of the key press, false if it was not.

extraInfo

This argument is a string containing keywords. It supplies extra information about the keyboard state at the time of a key press event. The string will contain some combination of these keywords

numOn

Num Lock was on at the time of the key press event.

numOff

Num Lock was off.

capsOn

Caps Lock was on at the time of the key press event.

capsOff

Caps Lock was off.

scrollOn

Scroll Lock was on at the time of the key press event.

scrollOff

Scroll Lock was off.

lShift

The left shift key was down at the time of the key press event.

rShift

The right shift key was down.

lControl

The left control key was down at the time of the key press event.

rControl

The right control key was down.

lAlt

The left alt key was down at the time of the key press event.

rAlt

The right alt key was down.

Example:

The following example could be from an application that supplies extended editing abilities for a multi-line edit control. When the edit control has the focus the user can use Alt-D to delete the current word, Ctrl-D to delete the current line, and Shift-Alt-D delete the current paragraph:


::method initDialog
  expose editControl

  editControl = self~getEditControl(IDC_EDTIT)
  ...

  -- Capture the D key press when either the Alt or Control keys are
  -- also pressed.
  editControl~connectKeyPress(onDPress, self~vCode('D'), "ALT CONTROL")
  ...

::method onDPress
  expose editControl
  use arg key, shift, control, alt, info

  -- Determine which of the key press combinations this is and take
  -- appropriate action if it is a combination we are interested in.

  isAltD = \ shift & \ control & alt
  isCtrlD = \ shift & control & \ alt
  isShiftAltD = shift & \ control & alt

  if isAltD then self~deleteWord(editControl)
  if isCtrlD the self~deleteLine(editControl)
  if isShiftAltD then self~deleteParagraph(editControl)

ConnectFKeyPress

>>-aDialogControl~ConnectFKeyPress(--msgToRaise--)-------------><


The ConnectFKeyPress method is a convenience method that connects all F key down events, when the control has the keyboard focus, with a programmer defined method in the parent dialog of the control. (This is for the standard function keys, F2 through F24.) The underlying Windows dialog must exist before this method can be invoked.

Note: This method is only available on systems running Windows XP or later. On earlier versions of Windows, the method will fail and return -4.

The arguments, return values, and behavior of this method are the same as those for the ConnectFKeyPress method of the BaseDialog. However, the method of the BaseDialog class connects any F key down event when the dialog is the active window and this method of the DialogControl class only connects the F key down events when the specific control has the focus. See the ConnectFKeyPress method of the BaseDialog for a more detailed description of the arguments, return values, and behavior.

Arguments:

The required argument is:

msgToRaise

The method to be invoked for the key down event.

Return value:

The return values are:

0

Success.

1

The underlying mechanism in the Windows API failed.

-1

A problem with one of the arguments.

-2

An (internal) problem with the dialog window.

-3

An (internal) problem with the dialog administration.

-4

This method is not supported by this version of Windows. Windows XP or later is required.

-5

Memory allocation error in the underlying Windows API.

-6

The maximum number of connections has been reached.

-7

The msgToRaise method is already connected to a key down event for this dialog control.

Event Method Arguments

The ooDialog method connected to the F key down event receives five arguments. This arguments are described in detail in the ConnectKeyPress method of the DialogControl.

Example:

The following example connects the F key down events for an edit control. The application determines which F key was pressed and takes appropriate action. For this application, the F3 key is the search key.

 

::method initDialog
  expose editControl searchToken

  editControl = self~getEditControl(IDC_EDIT)
  editControl~connectFKeyPress(onFKey)
  ...
  lastSearchToken = ""
  ...

::method onFKey
  expose editControl searchToken
  use arg key

  select
    when self~keyName(key) == 'F2' then do
      ...
    end
    when self~keyName(key) == 'F3' then do
      description = "What word would you like to search for?"
      searchToken = inputBox(description, "Search", searchToken)

      if searchToken <> "" then
        self~findAndHighlight(searchToken, editControl)
    end
    when self~keyName(key) == 'F4' then do
      ...
    end
    ...
  end
  ...

DisconnectKeyPress

>>-aDialogControl~DisconnectKeyPress(--+--------------+--)-----><
                                       +--methodName--+

The DisconnectKeyPress method disconnects a previously connected method with a key down event. If no method name is specified than all key down event connections are removed. Otherwise, only the key down events connected to the specific method are removed.

Note: This method is only available on systems running Windows XP or later. On earlier versions of Windows, the method will fail and return -4.

The arguments, return values, and behavior of this method are the same as those for the DisonnectKeyPress method of the BaseDialog. However, this method only works for connections made using the DialogControl's ConnectKeyPress method. It can not work with a connection made though the BaseDialog's method. See the DisconnectKeyPress method of the BaseDialog for a more detailed description of the behavior of this method.

Arguments:

The single optional argument is:

methodName

If methodName is specified, only the key down events connected to that method are disconnected. If the argument is omitted, then all key down events for the dialog control will be disconnected.

Return value:

The return values are:

0

Success.

1

The underlying mechanism in the Windows API that captures the key down events failed to disconnect.

-1

The specified methodName is not connected to any key down events for this control.

-2

The underlying mechanism in the Windows API that captures the key down events was never installed.

-4

This method is not supported by this version of Windows. Windows XP or later is required.

Example:

The following example could come from a dialog where the user can enable or disable the user of hot keys when she is working within an edit control. When the user presses the disable hot keys button, the dialog disables the hot keys for the edit control by removing the key press connections.


::method defineDialog

  ...
  self~addButton(IDC_PB_DISABLE, 60, 135, 65, 15, "Disable Hot Keys", onDisable)
  ...

method onDisable
  editControl = self~getEditControl(IDC_EDIT)
  editControl~disconnectKeyPress

HasKeyPressConnection

>>-aDialogControl~HasKeyPressConnection(--+--------------+--)-----><
                                          +--methodName--+

This method is used to query if a connection to a key down event already exists.

Note: This method is only available on systems running Windows XP or later. On earlier versions of Windows, the method will fail and return -4.

The arguments, return values, and behavior of this method are the same as those for the HasKeyPressConnection method of the BaseDialog. However, this method only works for connections made using the DialogControl's ConnectKeyPress method. It can not work with a connection made though the BaseDialog's method. The HasKeyPressConnection method of the BaseDialog may provide some additional insight into the behavior of this method.

Arguments:

The single optional argument is:

methodName

When this argument is not used, HasKeyPressConnection queries if any key down event for the dialog control is connected to a method. When methodName is specified, the query checks for a connection to the specified method.

Return value:

The returned value is always true or false.

true

A connection exists.

false

No connection exists.

Example:

The following example is from an application where the user can enable the use of hot keys when an edit control has the focus, or not. The reset push button is used in the application to reset the state of the dialog. One of the things done when the state is reset to check or uncheck a check box that shows whether hot keys are currently enabled or not.


::method defineDialog

  ...
  self~addCheckBox(IDC_CHECK_FKEYSENABlED, , 30, 60, , , "Hot Keys Enabled")
  ...
  self~addButton(IDC_PB_RESET, 60, 135, 45, 15, "Reset", onReset)
  ...

::method onReset

  ...
  editControl = self~getEditControl(IDC_EDIT)

  if editControl~hasKeyPressConnection then
    self~getCheckControl(IDC_CHECK_FKEYSENABlED)~check
  else
    self~getCheckControl(IDC_CHECK_FKEYSENABlED)~uncheck
  ...