20002016 Ericsson AB. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Built-In Objects gs_chapter8.xml
Overview

This section describes the built-in objects of the graphics interface. The following objects exist:

Window An ordinary window. Button A simple press button. Checkbutton A button with a check-mark indicator. Radiobutton A button with an indicator that has an only-one-selected-at-a-time property. Label Shows a text or bitmap. Frame A plain container object. It is used for logical and visual grouping of objects. Entry A one-line object for entering text. Listbox A list of text strings. Canvas A drawing area which contains light-weight objects such as rectangle, line, etc. Menu A collection of objects for constructing pull-down and pop-up menus. Grid An object for showing tables. A kind of multi-column listbox. Editor A multi-line text editor. Scale To select a value within a range.

Some objects can act as container objects. The following table describes these relationships:

Objects Valid Parents window window, gs buttons, canvas, editor, entry, frame, grid, label, listbox, menubar, scale frame, window arc, image, line, oval, polygon, rectangle, text canvas menubutton menubar, window, frame gridline grid menuitem menu menu menubutton, menuitem (with {itemtype, cascade}), window, frame (the last two are for pop-up menus) Relations Between Objects and Container Objects
Generic Options

Most objects have a common subset of options and will be referred to as generic options. They apply to most objects.

{Option,Value} Default Description beep <unspec> A beep will sound. Applies to all objects. {bg, Color} <unspec> Background color. Applies to objects which have a background color. {data, Term} [] Always delivered with the event in the data field. Applies to all objects. {default,Objecttype,{Key,Value}} <unspec> Applies to all container objects. Specifies the default value for an option for children of type Objecttype. {enable, Bool} true Objects can be enabled or disabled. A disabled object cannot be clicked on, and text cannot be entered. Applies to buttons, menuitem, entry, editor, scale. {font, Font} <unspec> Applies to all text related objects and the grid. {fg, Color} <unspec> Foreground color. Applies to objects which have a foreground color. flush <unspec> Ensures that front-end and back-end are synchronized. Applies to all objects. {setfocus, Bool} <unspec> Set or remove keyboard focus to this object. Applies to objects which can receive keyboard events. Generic Options

The following options apply to objects which can have a frame as parent. Coordinates are relative to the parent.

{Option,Value} Default Description {cursor, Cursor} parent The appearance of the mouse cursor. {height, Int} <unspec> The height in pixels. {pack_x, Column|{StartColumn,EndColumn}} <unspec> Packing position. See The Packer section. {pack_y, row|{Startrow,Endrow}} <unspec> Packing position. See The Packer section. {pack_xy, {Column,row}} <unspec> Packing position. See The Packer section. {width, Int} <unspec> The width in pixels. {x, Int} <unspec> The x coordinate within the parent objects frame in pixels. 0 is to the left. {y, Int} <unspec> The y coordinate in pixels. 0 is at the top. Generic Options (Frame as Parent)
Config-Only Description lower Lowers this object to the bottom in the visual hierarchy. raise Lowers this object in the visual hierarchy. Generic Config-Only Options

The following table lists generic Read-Only options:

Read-Only Return Description children [ObjectId1, ..., ObjectIdN] All children {choose_font,Font} Font Return the font that is actually used if a particular font is given. id ObjectId Return the object id for this object. Useful if the object is a named object. {font_wh,{Font,Text}} {Width,Height} Return the size of a text in a specified font. It returns the size of the font that is actually chosen by the back-end. type Atom The type of this object. parent ObjectId The parent of this object. Generic Read-Only Options
Generic Event Options

The table below lists all generic event options:

{Option,Value} Default {buttonpress, Bool} false {buttonrelease, Bool} false {enter, Bool} false {leave, Bool} false {keypress, Bool} false {motion, Bool} false Generic Event Options
Window

The basic object is the window object. It is the most common container object. All graphical applications use at least one (top-level) window.

Empty Window titled "A Window".

The following tables show all window specific options:

{Option,Value} Default Description {bg, Color} <unspec> {R,G,B} or a color name {configure,Bool} false Will generate a event when the window has been resized or moved. The field contains [Width,Height,X,Y|_] {destroy,Bool} true Will generate a event when the window is destroyed from the window manager. All GS applications should handle this event. {iconname, String} <unspec>   {iconify, Bool} false   {map, Bool} false Make it visible on the screen {title, String} <unspec> The title of the window. The default is the internal widget name which is platform specific. Window Options
Config-Only Description raise Raise window on top of all other windows. lower Lower window to background. Window Config-Only Options

The following example shows how to create a window and configure it to enable various events.

Button Radio Buttons, Check Buttons, and Ordinary Button

Buttons are the simplest and the most commonly used objects. You press them and get a click event. The following tables show the options for all button types.

{Option,Value} Default Description {align, Align} center Text alignment within the frame. {justify, left | center | right} center Justification is only valid when there are several lines of text. {label, Label} <unspec> Text or image to show. {select, Bool} false Check buttons and radio buttons. true means that the button is selected. {underline, Int} <unspec> Underline character N to indicate a keyboard accelerator. {group, Atom} <unspec> Radio button: only one per group is selected at one time. Check button: All in the same group are selected automatically. {value, Atom} <unspec> Radio buttons only. Groups radio buttons together within a group. Options for all Button Types
Config-Only Description flash Flash button invoke Explicit button press. toggle Check buttons only. Toggles select value. Config-Only Options for all Button types
Buttontype Event normal {gs, itemId, click, Data, [Text| _]} check {gs, itemId, click, Data, [Text, Group, Bool | _]} radio {gs, itemId, click, Data, [Text, Group, Value | _]} >Events for all Button types

Buttons and check buttons are simple to understand, radio buttons are more difficult. Each radio button has a group and a value option. The group option is used to group together two or more radio buttons. Normally, each radio button within a group has a unique value which means that only one radio button can be selected at a time. If two (or more) radio buttons share the same value and one of them is selected, then both will be selected and all others are de-selected. The following short example shows how to program radio button logic in a situation where two of them share the same value.

Radio Button Group with Last Button Selected

The example shown creates three radio buttons which are members of the same group. The default behavior is that all radio buttons created by the same process are members of the same group. Normally, only one in a group may be selected at the same time, but since we defined the value-option to have the same value for and , they will both be selected/de-selected simultaneously. The normal radio button group behavior is that all radio buttons within the same group have unique default values.

Label {Option,Value} Default Description {align,Align} center How the text is aligned within the frame. {justify,left|right|center} left How to justify several lines of text. {label,Label} <unspec> Text or image to show. {underline,Int} <unspec> Underline character N to indicate a keyboard accelerator. Label Options

A label is a simple text field which is used to display text to the user. It is possible to have several lines of text by inserting newline '\ ' characters between each line. The label object does not automatically adjust its size so that text will fit inside. This has to be done manually, or the text may be clipped at the edges.

Frame

The frame object acts as a container for other objects. Its main use is to logically and visually group objects together. Grouped objects can then be moved, displayed, or hidden in one single operation.

{Option,Value} Default Description {bw,Int} <unspec> Border width {packer_x,PackList} <unspec> Makes the frame pack its children. See the packer section. {packer_y,PackList} <unspec> Makes the frame pack its children. See the packer section. Frame Options

It is possible to have frame objects within frame objects so that large hierarchical structures of objects can be created.

Entry Label and Entry Objects for User Input {Option,Value} Default Description {justify, left|right|center} left Text justification in entry field. {text, String} <unspec> Use this option to initially set some text, and to read the text. Entry Options

Entrys are used to prompt the user for text input.

Config-Only Description {delete, {From, To}} Deletes the characters within index {From,To}. {delete, last} Deletes the last character. {delete, Index} Deletes the character at position Index. {insert, {Index, String}} Inserts text at the specific character position. Index starts from 0. {select, {From, To}} Selects a range. {select, clear} De-selects selected text. Entry Config-Only Options

A common usage of the entry object is to listen for the 'Return' key event and then read the text field. The following example shows a simple dialog which prompts the user for a name and returns the tuple when a name is entered, or if the cancel button is pressed.

The program draws the dialog and waits for the user to either press the return key or click one of the buttons. It then reads the text option of the entry and returns the string to the client process.

Listbox

A listbox is a list of labels with optional scroll bars attached. The user selects one or more predefined alternative entries. You can add and remove entries in the listbox. The first element in a listbox has index 0.

{Option,Value} Default Description {hscroll, Bool | top | bottom} true Horizontal scroll bar. {items, [String, String ... String]} <unspec> All items (entries) in the listbox. {scrollbg, Color} <unspec> Foreground color of scroll bar. {scrollfg, Color} <unspec> Background color of scroll bar. {selectmode, single | multiple} single Controls if it is possible to have several items selected at the same time. {vscroll, Bool | left | right} true Vertical scroll bar. Listbox Options
Config-Only Description {add, {Index, String}} Add an item at specified index. {add, String} Add an item last. {change, {Index,String}} Change one item. clear Delete all items. {del, Index | {From, To}} Delete an item at specified index, or all from index From to index To. {see, Index} Make the item at specified index visible. {selection, Index | {From,To}| clear} Select an item (highlight it). Clear erases the selection. Listbox Cinfig-only Options
Read-Only Return Description selection ListOfStrings Returns current selection. All selected item indices will be returned in a list. size Int The number of items (entries) in the listbox. {get, Index} String Returns item at specified index. Listbox Read-Only Options
Event {gs, ListBox, click, Data, [Index, Text,Bool | _]} {gs, ListBox, doubleclick, Data, [Index, Text,Bool | _]} Listbox Events

is true if object is selected, false if de-selected.

Note that and are two discrete events: if you have subscribed to both, you will receive both a event and a event when double-clicking on one item (since two rapid clickings are regarded as both a and a ). The subscription of events does result in the events being unsubscribed!

The following example shows a simple application which prompts the user for a text item. The user has the following options:

browse the items and then double-click the required item type the name into the entry field and then press the Return key select the required item and then click the OK button. Simple Browser Dialog
Canvas

The canvas object is a simple drawing area. The user can draw graphical objects and move them around the drawing area. The canvas also has optional scroll bars which can be used to scroll the drawing area. The graphical objects that can be created on a canvas object are:

arc image line oval polygon rectangle text.

These objects must have a canvas object as a parent, but they are otherwise similar to all other basic objects. The following tables show the options which apply to canvas objects.

{Option,Value} Default Description {bg, Color} <unspec> Color of the drawing area. {hscroll, Bool | top | bottom} false Horizontal scroll bar. {scrollbg, Color} <unspec> Foreground color of scroll bar. {scrollfg, Color} <unspec> Background color of scroll bar. {scrollregion, {X1,Y1,X2,Y2}} <unspec> The size of the drawing area to be scrolled. {vscroll, Bool | left | right} false Vertical scroll bar. Canvas Options
Read-Only Return Description {hit, {X,Y}} list of ObjectId Returns the canvas objects at X,Y. {hit, [{X1,Y1},{X2,Y2}]} list of ObjectId Returns the canvas objects which are hit by the rectangle. Canvas Read-Only Options

Canvas objects have the same types of events as other objects. The following Config-Only options also apply to canvas objects:

Config-Only Description lower Lowers the object. {move, {Dx, Dy}} Moves object relative to its current position. raise Raises the object above all other objects. Canvas Config-Only Options

The following sections describe the graphical objects which can be drawn on a canvas object.

The Canvas Arc Object

The canvas arc object is defined within a rectangle and is drawn from a start angle to the extent angle. Origo is in the center of the rectangle.

Canvas Arc Object {Option,Value} Default Description {bw, Int} 1 Defines the width. {coords, [{X1,Y1},{X2,Y2}]}   Defines a rectangle to draw the arc within. {extent, Degrees}     {fg, Color}     {fill, Color|none} none Defines fill color of arc object. {start, Degrees}     {style, arc}   No line segments. {style, chord}   A single line segment connects the two end points of the perimeter section. {style, pieslice} This Style Two lines are drawn between the center of the oval and each end of the perimeter section. Canvas Arc Options
The Canvas Image Object

The canvas image object displays images and moves them around in a simple way. The currently supported image formats are bitmap and gif.

Canvas Image Object {Option,Value} Default Description {anchor, Anchor} nw Anchor reference specified by {X,Y} . {bg, Color} <unspec> Background color. Pixel value 0. {bitmap, FileName} <unspec> A bitmap file which contains a bmp bitmap. {coords, [{X,Y}]} <unspec> Position on the canvas. {fg, Color} <unspec> Foreground color. Pixel value 1. {load_gif, FileName} <unspec> Loads a gif image. Canvas Image Object Options
The Canvas Line Object Line Object Drawn on a Canvas {Option,Value} Default Description {arrow, both | none | first | last} none Draws arrows at the end points of the line. {coords, [{X1,Y1},{X2,Y2}, ... {Xn,Yn}]} <unspec> A list of coordinates. The line will be drawn between all pairs in the list. {fg, Color} <unspec> The color of the line. {smooth, Bool} false Smoothing with Bezier splines. {splinesteps, Int} <unspec>   {width, Int} 1 The width of the line. Canvas Line Object Options
The Canvas Oval Object Oval Object Drawn on a Canvas {Option,Value} Default Description {bw, Int} 1 Width. {coords, [{X1,Y1},{X2,Y2}]} <unspec> Bounding rectangle which defines shape of object. {fg, Color}     {fill, Color|none} none Object fill color. Canvas Oval Object Options
The Canvas Polygon Object Canvas Polygon Object {Option,Value} Default Description {bw, Int} 1 Width. {coords, [{X1,Y1},{X2,Y2} | {Xn,Yn}]} <unspec> Defines all points in the polygon. There may be any number of points in the polygon. {fg, Color} black The color of the polygon outline. {fill, Color|none} none   {smooth, Bool} false Smoothing with Bezier splines. {splinesteps, Int} <unspec>   Canvas Polygon Object Options
The Canvas Rectangle Object Rectangle Object Created on a Canvas {Option,Value} Default Description {bw, Int} 1 The width of the border line. {coords, [{X1,Y1},{X2,Y2}]} <unspec> Defines rectangle coordinates. {fg, Color} <unspec> The color of the border line. {fill, Color|none} none Fill color of rectangle. Canvas Rectangle Object Options
The Canvas Text Object Canvas Text Object {Option,Value} Default Description {anchor, Anchor} nw Anchor reference specified by {X,Y}. {coords, [{X, Y}]} <unspec> Position in the canvas. {fg, Color} <unspec> Text color (background color is the canvas color). {justify, left | center | right} <unspec> Tex justification. Only valid with several lines of text. {text, String} <unspec> The text string to display. {width, Int}   The width in pixels. The text will be wrapped into several lines to fit inside the width. Canvas Text Object Options
Menu

Menus consist of four object types:

the menu bar the menu button the menu the menu item.
Menu Bar

The menu bar is a simple object. It is placed at the top of the window and contains menu items. {x,y} or width cannot be controlled since, by definition, the menu bar is placed at the top of the window.

{Option,Value} Default Description <only generic options>     Menu Bar Options
Menu Button

The menu button displays a menu when pressed. The width of the menu button is automatically determined by the size of the text.

{Option,Value} Default Description {align, Align} center Text alignment within the frame. {justify, left | center | right} center Justification is only valid when there are several lines of text. {label,{text,Text}} <unspec>   {side, left | right} <unspec> Placement on the menu bar. The menu button created first will have the left/right position. {underline, Int} <unspec> Underline character N to indicate an keyboard accelerator. Menu Button Options
Menu

The menu contains menu items, which are displayed vertically. Its width is automatically determined by the width of the menu items it contains.

{Option,Value} Default Description {selectcolor, Color} <unspec> The indicator color of radio buttons and check buttons. Menu Options
Config-Only Description {post_at,{X,Y}} Displays the menu as a pop-up menu at {X,Y} (coordinate system of the parent). Menu Config-Only Options
Menu Item

The menu item is an object of its own. It can send events when the user selects it.

{Option,Value} Default Description {group, Atom} <unspec> For {type, radio|check}. {itemtype, type} normal The type of this item. Cannot be reconfigured. {label, {text,Text}} <unspec> The text of the item. {underline, Int} <unspec> Underline character N to indicate an keyboard accelerator. {value, Atom} <unspec>   Menu Item Options

itemtype Event normal {gs, itemId, click, Data, [Text, Index | _]} check {gs, itemId, click, Data, [Text, Index, Group, Bool| _]} radio {gs, itemId, click, Data, [Text, Index, Group, Value| _]} Menu Item Events
Read-Only Return Description index Int Index in the menu. Starts counting from 0. Menu Item Read-Only Options
Menu Demo Simple Menu

The following example shows a short demo of the menus:

Grid

The grid object is similar to the listbox object. The main difference is that the grid is a multi-column object which is used to display tables. If needed, the grid can send click events when a user presses the mouse button in a table cell. Although the grid has a behavior which is similar to the listbox, the programming is somewhat different. The data in a table cell is represented as a pure object and can be treated as such. This object is called a grid line. It is located at a row in the parent grid. If a grid line is clicked, it sends an event to its owner.

Grid Line {Option,Value} Default Description {{bg, Column},Color} <unspec> The background color of a cell. {bg, {Column,Color}} <unspec> Equivalent to {{bg, Column},Color}. {bg, Color} <unspec> The background color of all cells. {click, Bool} true Turns click events on/off. {doubleclick, Bool} false Turns double-click events on/off. {{fg, Column},Color} <unspec> The foreground color of a cell. {fg, {Column,Color}} <unspec> Equivalent to {{fg, Column},Color} {fg,Color} <unspec> The foreground color of all cells. {text, {Column,Text}} <unspec> The text in the cell. {{text, Column},Text} <unspec> Equivalent to {text,{Column,Text}}. {text,Text} <unspec> The text for all cells. {row, {row}} <unspec> The grid row. Must not be occupied by another grid line. Grid Line Options
Event {gs, GridLineId, click, Data, [Col, row, Text | _]} {gs, GridLineId, doubleclick, Data, [Col, row, Text | _]} Gride Line Events
Grid {Option,Value} Default Description {font,Font} <unspec> A "global" grid font. {hscroll, Bool|top|bottom} true Horizontal scroll bar. {vscoll, Bool|left|right} true Vertical scroll bar. {rows, {Minrow,Maxrow}} <unspec> The rows which are currently displayed. {columnwidths, [WidthCol1,WidthCol2, ..., WidthColN}} <unspec> Defines the number of columns and their widths in coordinates. The size of the columns can be reconfigured, but not the number of columns. {fg, Color} <unspec> The color of the grid pattern and the text. {bg, Color} <unspec> The background color. Grid Options
Read-Only Return Description {obj_at_row, row} Object |undefined The grid line at row. Grid Read-Only Options

The rows and columns start counting at 1.

Grid Demo Simple Grid

The following simple example shows how to use the grid.

Editor

The editor object is a simple text editor.

{Option,Value} Default Description {hscroll, Bool | top | bottom} false Horizontal scroll bar. {insertpos,{row,Col}} <unspec> The position of the cursor. {insertpos,'end'} <unspec> The position of the cursor. {justify, left| right| center} left Text justification. {scrollbg, Color} <unspec> Background color of scroll bar. {scrollfg, Color} <unspec> Foreground color of scroll bar. {selection, {FromIndex,ToIndex}} <unspec> The text range that is currently selected. {vscroll, Bool | left | right} false Vertical scroll bar. {vscrollpos, row} <unspec> The top most visible row in the editor. {wrap, none|char | word} none How to wrap text when the line is full. Editor Options
Config-Only Description clear Clears the editor. {del, {FromIndex, ToIndex}}} Deletes text. {fg, {{FromIndex,ToIndex},Color}} Sets the foreground color of a range of text. {load, FileName} Read FileName into the editor. {insert, {Index, Text}} Inserts new text. {overwrite, {Index, Text}} Writes new text at index. {save, FileName} Writes editor contents to file. Editor Config-Only Options
Read-Only Return Description char_height Int The height of the editor window measured in characters. char_width Int The width of the editor window measured in characters. {fg,Index} Int The foreground color of the text at Index. {get,{FromIndex, ToIndex}} Text The text between the indices. size Int The number of rows in the editor. Editor Read-Only Options
Editor Demo Simple Editor
Scale

A scale object is used to select a value within a specified range.

{Option,Value} Default Description {orient, vertical | horizontal} horizontal The orientation of the scale. {pos, Int} <unspec> The current value of the scale objects within the range. {range, {Min, Max}} <unspec> The value range. {showvalue, Bool} true Turns showing of scale value on/off. {text, String} <unspec> If specified, a label will be attached to the scale. Scale Object Options
Event {gs, Scale, click, Data, [Value | _]} Scale Object Options

The following example prompts a user to specify an RGB-value for the background color of a window.

Scale Objects for Selecting RGB Values for a Window