![]() | Programming Guide | WideStudio Index Table of contents |
范例事项过程及标签编辑
对用鼠标选择可能的标签要做
以下是事项过程中最基本的鼠标动作的范例。每次鼠标被单击时,在标签上就显示被点击数。# Set this to a label Instance with WSEV_MOUSE_PRESS use mpfc; sub cbop { my ($object) = @_; //(0) Which the mouse button is pressed? if ((mpfc::WSDmouse_getMouseStatus(mpfc::WSGIappMouse()) & $mpfc::WS_MOUSE_BTN1) == 0){ return; } //(A)Get the value of the property: userValue $value = mpfc::WSCbase_getProperty($object,"userValue"); //(B)Count it up. $val = mpfc::WSCvariant_getLong($value) + 1; //(C)Display the value. mpfc::WSCbase_setProperty($object,"labelString",$val); //(D)Store the counted value into the property: // userValue for the next time. mpfc::WSCbase_setProperty($object,"userValue",$val); return; } 1;首先,在这个事项过程,对WSCvbtn,WSCvlabel 等拥有labelString 属性的项目进行MOUSE-PRESS 触发器设定。每次鼠标键单击该项目时,该事项过程函数将被启动。 事项过程被启动后,以(0)进行鼠标键的判断。如果鼠标键为1以外,则按钮回车。请参照鼠标键判断的处理方法。
然后,(A)处取得userValue 的属性数字。 userValue 属性初始值为0,用户可自由指定初期值并进行保持。在这里,让项目记忆该数字是为了当多项项目被处理时,不发生各自的标签数字混乱。反过来,使用静态变量等制作的话,全部的标签可利用同一个计数器进行显示。
然后,(B)处追加点击数,并在(C)进行显示。在(D)中将显示的数字作为userValue的 属性数进行保存,预备下一个事项过程的启动。
如果触发器适用MOUSE-IN的话,应该可以显示鼠标出入回数。
制作可以鼠标选择的标签
以下,我们试着制作可以选择的标签。当标签被选择时,颜色将发生变化。这次,使用set/getUserData(函数)代替userValue 属性来保持选择状态。# Set this to a label Instance with WSEV_MOUSE_PRESS use mpfc; sub cbop { my ($object) = @_; #(A) Get the value with getUserData() $value = mpfc::WSCbase_getVariantData($object,"STATUS"); #(B) it makes the Instance selected if value is 0, if (mpfc::WSCvariant_getLong($value) == 0){ #(C)Store the backcolor(which is string type) into userString $color = mpfc::WSCbase_getProperty($object,"backColor"); mpfc::WSCbase_setProperty($object,"userString",$color); #(D)Set the backcolor to the selected color. mpfc::WSCbase_setProperty($object,"backColor","slategray4"); #(E)Store the state with setUserData(). mpfc::WSCbase_setVariantData($object,"STATUS",1); }else{ #(F)Get the original backcolor from userString. $color = mpfc::WSCbase_getProperty($object,"userString"); #(G)Store it to backColor to display with the original color. mpfc::WSCbase_setProperty($object,"backColor",$color); #(H)Store the state with setUserData(). mpfc::WSCbase_setVariantData($object,"STATUS",0); } } 1;在这个事项过程,对WSCvbtn,WSCvlabel 等具用labelString属性的项目,设定MOUSE-PRESS 触发器。
事项过程被启动时,在(A)处取得以setVariantData()函数记忆的数字。set/setVariantData()函数的初始值为0,用户可自由指定或保持其值。可使用喜欢的名称,用void*进行保持。
然后,在(B)处辨别该值,在(C)处将原来的颜色保存于属性 userString,以便下次显示原来颜色的使用。(D)处,显示所选择的颜色。(E)处,再次重新保持选择状态。
将颜色恢复到原来状态时,首先在(F)处取得保持的原来颜色,然后在(G)处显示该颜色。最后在(H)处再次保持选择状态。制作加亮鼠标标签
以下制作通过鼠标的进入及离开,显示加亮标签的事项过程。当鼠标进入项目上时,标签加亮,而当鼠标离开项目时,标签显示恢复。
这里重要的步骤是,设定鼠标进入时发生的触发器和鼠标出来时发生的触发器。
当事项过程被初始化启动时,可通过设定新事项过程的方法,实现一个事项过程中设定复数事项过程的处理。use mpfc; #a sub-procedure sub subop1 { my ($object) = @_; #(A)Store the original back-color $color = mpfc::WSCbase_getProperty($object,"backColor"); mpfc::WSCbase_setProperty($object,"userString",$color); #(B)highlight the Instance. mpfc::WSCbase_setProperty($object,"backColor","slategray4"); return; } sub subop2 { my ($object) = @_; #(C)Get the original back-color $color = mpfc::WSCbase_getProperty($object,"userString"); #(D)Store the original back color. mpfc::WSCbase_setProperty($object,"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 #ProcedureName="Highlight1" Trigger=WSEV_MOUSE_IN Function=subop1 mpfc::WSCbase_addProcedure($object,"HighlightOP1","subop1",$mpfc::WSEV_MOUSE_IN); #(F)Setup a sub-procedure #ProcedureName="Highlight2" Trigger=WSEV_MOUSE_OUT Function=subop2 mpfc::WSCbase_addProcedure($object,"HighlightOP2","subop2",$mpfc::WSEV_MOUSE_OUT); } 1;通过子项目EP1,将鼠标界内的触发器启动,把标签的背景显示颜色做为加亮颜色。子项目EP2,鼠标出界的触发器启动,把标签的背景显示颜色恢复为原来的颜色。事项过程的实体,被初始化触发器设定在项目中,并通过(E),(F)项目设定子项目EP1,2。以后,当鼠标点入时,设定在新程序中的子项目EP将被实行。制作可用鼠标选择的组化标签
对于同样区域上可配置的标签,可做成用鼠标选择可能的组化标签事项过程。在该选择状态里用鼠标选择标签,即可保持该区域中被选择的标签。user mpfc; # An event procedure with WSEV_MOUSE_PRESS trigger void cbop(WSCbase* object){ sub cbop { my ($object) = @_; #(A)Use the value of userValue as "Instance identifier" $val = mpfc::WSCbase_getProperty($object,"userValue"); #(B)Make the Instance selected mpfc::WSCbase_setProperty($object,"shadowType",$mpfc::WS_SHADOW_IN); #(C)Get the last selected Instance which is memorized $parent = mpfc::WSCbase_getParent($object); $target = mpfc::WSCbase_getVariantData($parent,"SelectedItem"); #(D)Make it not selected $target_obj = mpfc::WSCvariant_getInstancePtr($target); if (mpfc::WSCbaseList_existInstance(mpfc::WSGIappObjectList(),$target_obj) != $mpfc::False){ mpfc::WSCbase_setProperty($target_obj,"shadowType",$mpfc::WS_SHADOW_OUT); } if (mpfc::WSCbaseList_existInstance(mpfc::WSGIappObjectList(),$target_obj) != $mpfc::False && mpfc::WSCbase_getInstanceName($target_obj) == mpfc::WSCbase_getInstanceName($object)){ #(E)When clicking the selected Instance twice, # clear the selected state. mpfc::WSCbase_setVariantData($parent,"GroupValue",0); mpfc::WSCbase_setVariantData($parent,"SelectedItem",0); }else{ #(F)The other,store the selected Instance to the parent Instance. mpfc::WSCbase_setVariantData($parent,"GroupValue",val); # ID mpfc::WSCbase_setVariantData($parent,"SelectedItem",$object); # WSCbase Instance } } 1;对组化标签,各自需具有识别的ID,在此ID使用设定在userValue 属性上的设定值。
(A) 取得userValue 属性上设定的 ID 。
(B)为了表现可进入选择,显示选择状态。
(C)取得被选择的项目。任何项目均可以,不过,这个范例中,首先选择组化标签共有的母项目。
(D)将被选择项目的显示状态恢复到已选择状态。
(E)被选择的项目(target)和,已经被选择的项目(object)相等的情况,即选择2次时,选择状态被解除。母项目中所设定的值和项目将初期化。
(F)将被重新选择的项目和其值设定到母项目。
Copyright(C) T. Hirabayashi, 2000-2004 | Last modified: Feb 25, 2004 |