WideStudio Logo
WideStudio
Programming Guide
WideStudio Index
Table of contents


The sample of the event procedures for WSCvifield



Executing some event procedures by return key

You can execute the specified procedures in the event procedure. Here, the following sample shows executing the procedure which name is "InputFixed".

use mpfc;
# A sample of WSEV_KEY_HOOK trigger.
sub cbop {
  my ($object) = @_;
  # (A)Get the pressed key.
  $key = mpfc::WSGIappKeyboard()->getKey();

  # (B)If the key is return..
  if ($key == $mpfc::WSK_Return){
    # Execute the procedure which name is "InputFixed".
    $object->execProcedure("InputFixed");
  }
  return;
}
1;

This procedure sometimes is used to execute some procedure on the end of key input.

Clearing the last input string on starting of next input

Here, you create a procedure which clears the last input string on starting of the next. the procedure clears the string the first key input since the input field instance is focused or clicked by the mouse pointer. The clear process is as follows:

use mpfc;
# To contain the last focused input field.
$focus_if = 0;

# sub-procedure with WSEV_FOCUS_CH
sub _focus_ch_ {
  my ($object) = @_;
  # (A) Examine whether the instance is focused.
  if ($focus_if != 0 &&
      $focus_if->getInstanceName() != $object->getInstanceName() &&
      $object->getFocus() != &mpfc::False ){

    # (B)It need to clear the string!
    # Set the clear flag True.
    $object->setVariantData("CLEAR TIMING",1);
    # (C)store that the last focused one is.
    $focus_if = $object;
  }
  return;
}
#A sub-procedure with WSEV_MOUSE_PRESS
sub _btn_press_ {
  my ($object) = @_;
  # (D) if clicked by the mouse pointer,
  # it needs to clear the string!
  # Set the clear flag True.
  $object->setVariantData("CLEAR TIMING",1);
  $object->setProperty("cursorPos",0);
  # (E)store that the last focused one is.
  $focus_if = $object;
  return;
}
# A sub-procedure with WSEV_MOUSE_PRESS
sub _key_hook_ {
  my ($object) = @_;
  # (F) See the clear flag to clear the last input string.
  $fl = $object->getVariantData("CLEAR TIMING");
  if ($fl->getLong() == 1){
    $key = mpfc::WSGIappKeyboard()->getKey();
    # (G)Clear the string,if the key is not cursor key.
    if ($key != $mpfc::WSK_Tab &&
        $key != $mpfc::WSK_Up &&
        $key != $mpfc::WSK_Down &&
        $key != $mpfc::WSK_Left &&
        $key != $mpfc::WSK_Right ){
      # (H)Clear...
      $object->setProperty("labelString","");
    }else{
      return;
    }
  }
  # (I)Set the clear flag False.
  $object->setVariantData("CLEAR TIMING",0);
  return;
}

# The main-procedure.
# Set the input field instance with WSEV_INITIALIZE trigger.
sub ifdclr {
  my ($object) = @_;
  # Setup the sub-procedure(1) with WSEV_FOCUS_CH
  $object->addProcedure("ac1","_focus_ch_",$mpfc::WSEV_FOCUS_CH);

  # Setup the sub-procedure(2) with WSEV_MOUSE_PRESS
  $object->addProcedure("ac2","_btn_press_",$mpfc::WSEV_MOUSE_PRESS);

  # Setup the sub-procedure(3) with WSEV_KEY_PRESS
  $object->addProcedure("ac3","_key_hook_",$mpfc::WSEV_KEY_HOOK);
}
1;

In the focus_ch event procedure, To examine the instance is focused afresh, It uses the static variable which is stored the last focused instance.


Document Release 3.80 for WideStudio ver 3.80, Jan 2005


WideStudio documents index | Table of contents

Copyright(C) WideStudio Development Team, 1999-2005 Last modified: Jan 05, 2005