WideStudio Logo
WideStudio
Programming Guide
WideStudio Index
Table of contents


The sample of the event procedures for WSCvlabel



Making the WSCvlabel instance click-able

In the sample of the event procedures, It is a most basic procedure that makes the label instance to react to the mouse pointer. Here, you will create a procedure to make it counting up clicking of the mouse pointer.

(*----------------------------------------------------------*)
(*Function for the event procedure                          *)
(*----------------------------------------------------------*)
open Swig
open Mwt
open Mwtlib
(* Set this to a label instance with WSEV_MOUSE_PRESS      *)
(*                                 (MOUSE-PRESS trigger)   *)
let cbop obj =
  (* (0) Which the mouse button is pressed?     *)
  (* btn1 -> fire. btn2 or the other -> return. *)
   let status = _WSGIappMouse '() -> getMouseStatus() in
     if ( (get_int status) land (get_int _WS_MOUSE_BTN1) ) <> 0 then
       (* (A)Get the value of the property: userValue *)
       let value = obj -> getProperty ( "userValue" ) in begin
       (* (B)Count it up. *)
         let value2 = (get_int value) +1 in
         (* (C)Display the value. *)
         obj -> setProperty ( "labelString", (make_int value2));
         (* (D) Store the counted value into the property: *)
         (*     userValue for the next time. *)
         obj -> setProperty ( "userValue", (make_int value2));
       end;
  ()
let _ = Callback.register "cbop" cbop

At first, this event procedure uses the property: "labelString" to display the number which is counted up. So, The kind of class like WSCvbtn,WSCvlabel which has it, can be used with WSEV_MOUSE_PRESS trigger. It will be executed by clicking of the mouse pointer. If by WSEV_MOUSE_IN trigger is used, it count the number of entering and exiting of the mouse pointer.



Making the WSCvlabel instance select-able

Here, you will create a procedure to make the label instance select-able by clicking of the mouse pointer. To display the instance is selected, the procedure changes the back-color of it. This time, the procedure uses the method: set/getUserData() to get/store data instead of the property: "userValue".

(* Set this to a label instance with WSEV_MOUSE_PRESS *)
(*                              (MOUSE-PRESS trigger) *)
let cbop obj =
  (* (A) getVariantData() Get the value with *)
  let value = obj -> getVariantData ( "STATUS" ) in begin
    (* (B) it makes the instance selected  if value is 0, *)
    (*                               and unselected if 1. *)
    if get_int (value -> getInt()) = 0 then begin
      (* (C)Store the backcolor(which is string type) into userString *)
      let color = obj -> getProperty ( "backColor" ) in
      obj -> setProperty ( "userString", (color -> "getCharPtr"()));
      (* (D)Set the backcolor to the selected color. *)
      obj -> setProperty("backColor","slateray4");
      (* (E)Store the state with setValiantData(). *)
      obj -> setVariantData ("STATUS",1);
    end else begin
      (* (F)Get the original backcolor from userString. *)
      let color = obj -> getProperty ( "userString" ) in
      (* (G)Store it to backColor to display with the original color. *)
      obj -> setProperty ( "backColor", (color -> "getCharPtr"()));
      (* (H)Store the state with setValiantData(). *)
      obj -> setVariantData ( "STATUS", 0);
    end;
  end;
  ()
let _ = Callback.register "cbop" cbop

The kind of class like WSCvbtn,WSCvlabel which has the property: "backColor", can be used with WSEV_MOUSE_PRESS trigger. It will be executed by clicking of the mouse pointer.





Making the WSCvlabel instance highlight-able

Here, you will create a procedure with WSEV_MOUSE_IN/OUT to make the instance highlighted. Coming into the area,the instance is highlighted,and Going out of the area, it is returned normal.

An important matter is that you create a procedure which prepares a sub-procedure with WSEV_MOUSE_IN and another with WSEV_MOUSE_OUT. In other words,that procedure with WSEV_INITIALIZE is executed, it adds two sub-procedures to the instance which trigger is WSEV_MOUSE_IN and WSEV_MOUSE_OUT to make the instance highlight-able. One procedure can prepares many procedures. Then you can go with a procedure even if many procedures are needed.

(*----------------------------------------------------------*)
(*Function for the event procedure                          *)
(*----------------------------------------------------------*)
open Swig
open Mwt
open Mwtlib
(* a sub-procedure with WSEV_MOUSE_IN trigger *)
let subop1 obj =
  (* (A)Store the original back-color to userString *)
  let color = obj -> getProperty ( "backColor" ) in
  obj -> setProperty ( "userString", (color -> "getCharPtr"()) );
  (* (B)highlight the instance. *)
  obj -> setProperty ( "backColor", "slategray4");
  ()
let _ = Callback.register "subop1" subop1

(* a sub-procedure with WSEV_MOUSE_OUT trigger *)
let subop2 obj =
  (* (C)Get the original back-color from userString *)
  let color = obj -> getProperty ( "userString" ) in
  (* (D)Store the original back color. *)
  obj -> setProperty ( "backColor", (color -> "getCharPtr"()) );
  ()
let _ = Callback.register "subop2" subop2

(* a main-procedure with WSEV_INITIALIZE trigger *)
let cbop obj =
  (* If executed,it add the sub-procedures to the instance.            *)
  (* (E) Setup a sub-procedure:WSEV_MOUSE_IN.                          *)
  (* ProcedureName="Highlight1" Trigger=WSEV_MOUSE_IN Function=subop1  *)
  obj -> addProcedure("Highlight1","subop1",_WSEV_MOUSE_IN);

  (* (F) Setup a sub-procedure:WSEV_MOUSE_OUT.                         *)
  (* ProcedureName="Highlight2" Trigger=WSEV_MOUSE_OUT Function=subop2 *)
  obj -> addProcedure("Highlight2","subop2",_WSEV_MOUSE_OUT);
  ()
let _ = Callback.register "cbop" cbop

The subop1() is executed by WSEV_MOUSE_IN fired, and makes the instance back-color highlight(A)(B). The subop2() is executed by WSEV_MOUSE_OUT fired, and makes the instance back-color original one(C)(D). The main procedure is executed by WSEV_INITIALIZE only once to setup the sub-procedures (E)(F).

Making a group of selectable WSCvlabel instances

Here, you create a event procedure to make a group of the mouse-selectable label instances on the same parent. the procedure make the instance selected by storing WS_SHADOW_IN to the property:"shadowType" and memorize which instance is selected by storing it to its parent instance.

(* An event procedure with WSEV_MOUSE_PRESS trigger *)
let cbop obj =
  (* (A)Use the value of userValue as "instance identifier" *)
  let value = obj -> "getProperty" ( "userValue" ) in
  (* (B)Make the instance selected: WS_SHADOW_IN state.     *)
  obj -> setProperty ( "shadowType", _WS_SHADOW_IN );
  (* (C)Get the last selected instance which is memorized   *)
  (*    with setUserData() of the parent instance.          *)
  let parent = obj -> getParent () in
  let targetn = parent -> getVariantData ("SelectedItem") in
  let target = parent -> getChildInstance ((targetn -> "getCharPtr"())) in
  (* (D)Make it not selected: WS_SHADOW_OUT state.          *)
  if (get_bool (_WSGIappObjectList '() -> existInstance( target ))) then
    ignore(target -> setProperty ( "shadowType", _WS_SHADOW_OUT ));
  if (get_bool (_WSGIappObjectList '() -> existInstance( target ))) &&
     (get_string (target -> getInstanceName()) = get_string (obj -> getInstanceName()) ) then begin
    (* (E)When clicking the selected instance twice,        *)
    (*    clear the selected state.                         *)
    parent -> setVariantData ( "GroupValue",0);
    parent -> setVariantData ( "SelectedItem","");
  end else begin
    (* (F)The other,store the selected instance to the parent instance. *)
    parent -> setVariantData ( "GroupValue", 0);
    parent -> setVariantData ( "GroupValue", (value -> "getInt"()));
    parent -> setVariantData ( "SelectedItem", (obj -> "getInstanceName"()));
  end;

  ()
let _ = Callback.register "cbop" cbop

The label instances needs each instance identifier to recognize which instance is selected, then we decide to use the property: "userValue" as the instance identifier which has unique value.




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