WideStudio Programming Guide

| 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.

>     # Set this to a label instance with WSEV_MOUSE_PRESS(MOUSE-PRESS trigger)
>     use mpfc;

>     sub cbop {
>       my ($object) = @_;
>       # Which the mouse button is pressed?
>       # btn1 -> fire. btn2 or the other -> return.
>       if ((mpfc::WSGIappMouse()->getMouseStatus() & $mpfc::WS_MOUSE_BTN1) == 0){
>         return;
>       }
>       # (A)Get the value of the property: "userValue"
>       $value = $object->getProperty("userValue");
>       # (B)Count it up.
>       $val = $value->getLong() + 1;
>       # (C)Display the value.
>       $object->setProperty("labelString",$val);
>       # (D)Store the counted value into the property:
>       #                         "userValue" for the next time.
>       $object->setProperty("userValue",$val);
>       return;
>     }
>     1;

> 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.
> - (0): It distinguishes whether the mouse btn 1 is pressed. Please refer to it for your implementation.
> - (A): It uses the property: "userValue" to contain the userValue of the counter. The default userValue of the property is 0, and it can be used freely by user. The procedure uses it because it wants to store each counter userValue of each label instance. the counter userValue becomes a singleton when the procedure uses the static variable for the counter, even if used by many label instances.
> - (B): It increases the counter.
> - (C): It stores into the property: "labelString" to display it.
> - (D): It stores into the property: "userValue" for the next time.
> 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/getVariantData() to get/store data instead of the property: "userValue".

>     # Set this to a label instance with WSEV_MOUSE_PRESS
>     #                                 (MOUSE-PRESS trigger)
>     use mpfc;

>     sub cbop {
>       my ($object) = @_;
>       #(A) Get the value with getUserData()
>       $value = $object->getVariantData("STATUS");
>       #(B) it makes the instance selected  if value is 0,
>       #                             and unselected if 1.
>       if ($value->getLong() == 0){
>         #(C)Store the backcolor(which is string type) into "userString"
>         $color = $object->getProperty("backColor");
>         $object->setProperty("userString",$color);
>         #(D)Set the backcolor to the selected color.
>         $object->setProperty("backColor","slategray4");
>         #(E)Store the state with setUserData().
>         $object->setVariantData("STATUS",1);
>       }else{
>         #(F)Get the original backcolor from "userString".
>         $color =  $object->getProperty("userString");
>         #(G)Store it to "backColor" to display with the original color.
>         $object->setProperty("backColor",$color);
>         #(H)Store the state with setUserData().
>         $object->setVariantData("STATUS",0);
>       }
>     }
>     1;

> 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.
> - (A): It uses the method: setVariantData() to contain the selected value of the state. The default value of the method is 0, and it can be used freely by user. The procedure uses it because it wants to store each status of each instance.
>   You can specify a name of value to store with setVariantData(), and can get the value by the specified name with set/getVariantData.
> - (B): It distinguishes the state.
> - (C): It stores the original back-color to the property: userString.
> - (D): It makes the instance selected.
> - (E): It stores the state with setUserData() again.
> - (F): It gets the original back-color from "userString".
> - (G): It stores the original back-color to "backColor".
> - (H): It stores the state with setUserData() again.

> ### 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.

>     use mpfc;
>     #a sub-procedure with WSEV_MOUSE_IN trigger
>     sub subop1 {
>         my ($object) = @_;
>         #(A)(A)Store the original back-color to "userString"
>         $color = $object->getProperty("backColor");
>         $object->setProperty("userString",$color);
>         #(B)highlight the instance.
>         $object->setProperty("backColor","slategray4");
>         return;
>     }

>     #a sub-procedure with WSEV_MOUSE_OUT trigger
>     sub subop2 {
>         my ($object) = @_;
>         #(C)Get the original back-color from "userString"
>         $color = $object->getProperty("userString");
>         #(D)Store the original back color.
>         $object->setProperty("backColor",$color);
>     }

>     #a main-procedure with WSEV_INITIALIZE trigger
>     sub cbop {
>        my ($object) = @_;
>        #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
>        $object->addProcedure("Highlight1","subop1",$mpfc::WSEV_MOUSE_IN);
>        #(F)Setup a sub-procedure:WSEV_MOUSE_OUT.
>        #ProcedureName="Highlight2" Trigger=WSEV_MOUSE_OUT Function=subop2
>        $object->addProcedure("Highlight2","subop2",$mpfc::WSEV_MOUSE_OUT);
>     }
>     1;

> 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.

>     user mpfc;

>     # An event procedure with WSEV_MOUSE_PRESS trigger
>     sub cbop {
>       my ($object) = @_;
>       #(A)Use the value of "userValue" as "instance identifier"
>       $val = $object->getProperty("userValue");
>       #(B)Make the instance selected: WS_SHADOW_IN state.
>       $object->setProperty("shadowType",$mpfc::WS_SHADOW_IN);
>       #(C)Get the last selected instance which is memorized
>       $parent = $object->getParent();
>       $target = $parent->getVariantData("SelectedItem");
>       #(D)Make it not selected: WS_SHADOW_OUT state.
>       $target_obj = $target->getInstancePtr();
>       if (mpfc::WSGIappObjectList()->existInstance($target_obj) != $mpfc::False){
>         $target_obj->setProperty("shadowType",$mpfc::WS_SHADOW_OUT);
>       }
>       if (mpfc::WSGIappObjectList()->existInstance($target_obj) != $mpfc::False &&
>           $target_obj->getInstanceName() == $object->getInstanceName()){
>         #(E)When clicking the selected instance twice,
>         #    clear the selected state.
>         $parent->setVariantData("GroupValue",0);
>         $parent->setVariantData("SelectedItem",0);
>       }else{
>         #(F)The other,store the selected instance to the parent instance.
>         $parent->setVariantData("GroupValue",val);      # ID
>         $parent->setVariantData("SelectedItem",$object);  # WSCbaseinstance
>       }
>     }
>     1;

> 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.
> - (A): Gets the instance identifier from the property: "userValue".
> - (B): Makes the instance selected with WS_SHADOW_IN.
> - (C): Gets the last instance which is selected from the parent instance.
> - (D): Makes the last one not selected.
> - (E): Makes the instance not selected if it is selected twice and clears the value which is memorized in the parent instance.
> - (F): Stores the new selected instance to the parent instance.

Document Release 3.70 for WideStudio ver 3.70, Feb 2004

WideStudio documents index | Table of contents

Copyright(C) T. Hirabayashi, 2000-2004 | Last modified: Feb 25, 2004