![]() |
The sample of the event procedures for WSCvlabelMaking the WSCvlabel instance click-ableIn 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.#include "WSDmouse.h" //Set this to a label instance with WSEV_MOUSE_PRESS(MOUSE-PRESS trigger) void cbop(WSCbase* object){ //(0) Which the mouse button is pressed? // btn1 -> fire. btn2 or the other -> return. if ( (WSGIappMouse()->getMouseStatus() & WS_MOUSE_BTN1) == 0){ return; } //(A)Get the value of the property: WSNuserValue long value = object->getProperty(WSNuserValue); //(B)Count it up. value++; //(C)Display the value. object->setProperty(WSNlabelString,value); //(D)Store the counted value into the property: WSNuserValue for the next time. object->setProperty(WSNuserValue,value); }At first, this event procedure uses the property: WSNlabelString 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_RESS trigger. It will be executed by clinking of the mouse pointer.
Making the WSCvlabel instance select-ableHere, 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 backcolor of it. This time, the procedure uses the method: set/getUserData() to get/store data instead of the property: WSNuserValue.//Set this to a label instance with WSEV_MOUSE_PRESS(MOUSE-PRESS trigger) void cbop(WSCbase* object){ //(A) Get the value with getUserData() long value = object->getProperty("STATUS"); //(B) it makes the instance selected if value is 0, and unselected if 1. if (value == 0){ //(C) Store the backcolor(which is string type) into WSNuserString WSCvariant color = object->getProperty(WSNbackColor); object->setProperty(WSNuserString,color); //(D)Set the backcolor to the selected color. object->setProperty(WSNbackColor,"slategray4"); //(E)Store the state with setUserData(). value = 1; object->setUserData("STATUS",(void*)value); }else{ //(F)Get the original backcolor from WSNuserString. WSCvariant color = object->getProperty(WSNuserString); //(G)Store it to WSNbackColor to display with the original color. object->setProperty(WSNbackColor,color); //(H)Store the state with setUserData(). value = 0; object->setUserData("STATUS",(void*)value); } }The kind of class like WSCvbtn,WSCvlabel which has the property: WSNbackColor, can be used with WSEV_MOUSE_RESS trigger. It will be executed by clinking of the mouse pointer.
Making the WSCvlabel instance highlight-ableHere, you will create a procedure with WSEV_MOUSE_IN/OUT to make the instace hightlighted. 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. //a sub-procedure with WSEV_MOUSE_IN trigger void subop1(WSCbase* object){ //(A)Store the original backcolor to WSNuserString WSCvariant color = object->getProperty(WSNbackColor); object->setProperty(WSNuserString,color); //(B)highlight the instance. object->setProperty(WSNbackColor,"slategray4"); } //a sub-procedure with WSEV_MOUSE_OUT trigger void subop1(WSCbase* object){ //(C)Get the original backcolor from WSNuserString WSCvariant color = object->getProperty(WSNuserString); //(D)Store the original back color. object->setProperty(WSNbackColor,color); } //a main-procedure with WSEV_INITIALIZE trigger void cbop(WSCbase* 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 WSCprocedure* ac1 = new WSCprocedure("Highlight1",WSEV_MOUSE_IN); ac1->setFunction(subop1,"subop1"); object->addProcedure(ac1); //(F) Setup a sub-procedure:WSEV_MOUSE_OUT. //ProcedureName="Highlight2" Trigger=WSEV_MOUSE_OUT Function=subop2 WSCprocedure* ac2 = new WSCprocedure("Highlight2",WSEV_MOUSE_OUT); ac2->setFunction(subop2,"subop2"); object->addProcedure(ac2); }The subop1() is executed by WSEV_MOUSE_IN fired, and makes the instance backcolor highlight(A)(B). The subop2() is executed by WSEV_MOUSE_OUT fired, and makes the instance backcolor 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 instancesHere, 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_SHAODW_IN to the property:WSNshadowType and memolise which instance is selected by storing it to its parent instance.//An event procedure with WSEV_MOUSE_PRESS trigger void cbop(WSCbase* object){ //(A)Use the value of WSNuserValue as "instance identifier" long val = object->getProperty(WSNuserValue); //(B)Make the instance selected: WS_SHADOW_IN state. object->setProperty(WSNshadowType,WS_SHADOW_IN); //(C)Get the last selected instance which is memorized with setUserData() of the parent instance. WSCbase* parent = object->getParent(); WSCbase* target = (WSCbase*)parent->getUserData("SelectedItem"); //(D)Make it not selected: WS_SHADOW_OUT state. if (target != NULL){ target->setProperty(WSNshadowType,WS_SHADOW_OUT); } if (target == object){ //(E)When clicking the selected instance twice, // clear the selected state. parent->setUserData("GroupValue",(void*)0); parent->setUserData("SelectedItem",(void*)0); }else{ //(E)The other,store the selected instance to the parent instance. parent->setUserData("GroupValue",(void*)val); //Instance identifier parent->setUserData("SelectedItem",(void*)object); //selected instance } }The label instances needs each instance identifier to recognise which instance is selected, then we decide to use the property: WSNuserValue as the instance identifier which has unique value.
Document Release 1.3 For Use with Wide Studio Release 1.3, Summer 2001
|