A widget is a small size application designed to perform simple features.
Nexacro Platform does not provide a widget component. Instead, it facilitates a substitute way to develop a widget through the open method of the Application object. Developers can build a form that will act as a widget, and then execute the form with the open method.
This chapter will discuss how developers can create, execute and terminate a widget in Nexacro Platform.
Creating Widgets
To create a widget, the open method must be called in the process of running a Nexacro Platform application. When calling the method, you should set the widget property to "true" in the strOpenStyle argument.
nexacro.Application.open("NewWidget", "Base::WidgetMain1.xfdl", null, "", "showontaskbar=false showtitlebar=false showstatusbar=false widget=true", 0, 0, 678, 530, this);
The following is the syntax of the open method, which belongs to the Application object. See the help (i.e. Nexacro 14 Reference Guide) for the further details.
application.open(strName, strFormURL, objParentFrame, {objArgumentList}, strOpenStyle, nLeft, nTop[,nWidth, nHeight[, objOpener]])
Trimming Off Surroundings
Many times, widgets have other forms than a rectangle. In such cases, you can use the layered feature, which allows users to use only widget-inclusive areas out of entire form areas. You can apply this feature by setting the relevant property in Nexacro Platform.
In addition, you must make the background of a form transparent in order to utilize only a widget-inclusive area.
Set the layered property to "true" in the strOpenStyle argument when calling the open method in the main form, the one in which you intend to create a widget.
nexacro.Application.open("NewWidget", "Base:WidgetMain.xfdl", null, "", "showontaskbar=false showtitlebar=false showstatusbar=false layered=true widget=true", 0, 0, 678, 530, this);
Set the background of the parent frame as being transparent through the oninit event handler of the widget form (in the below sample code, the form is identified as
WidgetMain
).
this.WidgetMain_oninit = function(obj:Form, e:nexacro.InitEventInfo) { var parentFrame = this.parent; if (parentFrame.layered == true) { parentFrame.style.set_background("transparent"); } }
Developing Independent-type Widgets
You may have seen many widgets that perform as an independent starter of an application. However, widgets operated in Nexacro Platform cannot do so without additional manipulation because their forms must be created through the open method. This section will explain how to let Nexacro widgets seem to work as independent forms.
Create the main form (identified as
AppMain
in the below sample code) of an application and designate it as a starting form.Set the visible property of the main form to "false" through the oninit event handler.
Create a widget through the open method.
this.AppMain_oninit = function(obj:Form, e:nexacro.InitEventInfo) { application.mainframe.set_visible(false); nexacro.Application.open("NewWidget", "Base::WidgetMain.xfdl",null, "", " widget=true", 0, 0, 678, 530, this); }
You should be careful that terminating an independent widget developed with the above method does not lead to terminating its main form. To terminate the main form, therefore, you need to add a special process, which will be explained in the below Terminating Widgets section.
Controlling Widgets
Widgets in Nexacro Platform share the same methods and properties with child frames since they are created through the open method.
Obtaining Child Frames
The approaches to the child frame of a widget are divided into two according to the beginning points: the approach from the main form (which is a creator of a widget) and the approach from the widget form.
You should use the popupframes property to obtain the child frame from the main form. The popupframes property is used to obtain a collection of information on a modeless child frame created through the open method. Developers can access to the child frame of a widget by using the popupframes object and get_item method. The get_item method shares the same argument with the open method—which is an index or widget name.
var widgetFrame = nexacro.Application.popupframes.get_item("NewWidget");
You should use the parent object to obtain the child frame from the widget form.
var widgetFrame = this.parent;
Changing Position or Size of a Widget
To change the position or size of a widget, you should use the move method of the child frame after obtaining the child frame.
var widgetFrame = nexacro.Application.popupframes.get_item("NewWidget"); widgetFrame.move(100, 100); widgetFrame.move(100, 100, 200, 500);
Using Widget Properties
A widget' properties are the same as the ones owned by a child frame. Therefore, you should first obtain a child frame object and then access to its properties to use the properties of a widget.
var widgetFrame = nexacro.Application.popupframes.get_item(widgetId); if (widgetFrame && widgetFrame.openstatus == “normal”) { widgetFrame.set_openstatus("maximize"); }
Using Widget Methods
A widget' methods are the same as the ones owned by a child frame. Therefore, you should first obtain a child frame object and then access to its methods to use the methods of a widget.
var widgetFrame = nexacro.Application.popupframes.get_item(widgetId); if (widgetFrame) { widgetFrame.setFocus(); }
var widgetFrame = nexacro.Application.popupframes.get_item(widgetId); var widgetForm = widgetFrame.form; if (widgetForm) { var newButton = new Button("NewButton", "absolute", 10, 10, 110, 100, null, null); if (newButton) { newButton.set_text("NewButton"); widgetForm.addChild("NewButton", newButton); newButton.show(); } }
Device APIs for Widgets
setIconWidget(widgetId, strWidgetIconPath)
This method is used to set an icon displayed on the taskbar when the showontaskbar property of a widget is set to true.
Parameter | Type | Description |
---|---|---|
strWidgetId | String | Widget ID |
strWidgetIconPath | String | URL of an icon |
Sample:
nexacro.Application.setIconWidget("NewWidget", “URL(‘Img::Widget_Icon.png’)”); nexacro.Application.setIconWidget("NewWidget", “URL(‘http://localhost:8080/XP13/WidgetTest/Img/Widget_Icon.png’)”);
setTopmostWidget(strWidgetId, bWidgetTopmost)
This method is used to determine whether to show a widget on the top of the Z-order.
Parameter | Type | Description |
---|---|---|
strWidgetId | String | Widget ID |
bWidgetTopmost | Boolean | Whether to show a widget on the top of the Z-order |
Sample:
nexacro.Application.setTopmostWidget("NewWidget", true);
Terminating Widgets
Normally, access to the child frame object of a widget and then call the close method of the widget form for termination.
var widgetFrame = nexacro.Application.popupframes.get_item(widgetId); if (widgetFrame && widgetFrame.form) { widgetFrame.form.close(); }
However, terminating a source application should be accompanied if you want to end an independent-type widget. Accordingly, you need to call the exit method in the onclose event handler of the widget form (in the below sample code, the form is identified as WidgetMain)
this.WidgetMain_onclose = function(obj:Form, e:nexacro.CloseEventInfo) { if(!application.mainframe.visible) { application.exit(); } }