popupmenu class Provides a popup menu.
Inherits
object widget
Description
This widget can be used to display a popup menu. Technically, a popup menu consists of a list of menu items. You add items with insertItem(). An item can be a string. In addition, items can have an optional icon drawn on the very left side.
Functions

`$insertItem(<text:string>,[icon_id:string])`
Inserts menu items into a popup menu with optional icon and return the popup identifier.
`$addMenu(<popupmenu:hobject,[idx:uinteger])`
Add a popupmenu. With the optional parameter idx the popup will be inserted.
`$setTitle(<text:string>)`
Sets the popupmenu title to text.
`$exec([<widget:objects>,<x:uinteger>,<y:integer>])`
If called without parameters show the popup menu at the current pointer position. With the optional parameters show the popup menu at the coordinate x,y widget parameter relative.
`$removeItem(<popup_id:Uinteger>)`
Removes the menu item that has the identifier ID.
`$removeItemAt(<index:uinteger>)`
Removes the menu item at position index.
`$insertSeparator(<index:uinteger>)`
Inserts a separator at position index. If the index is negative the separator becomes the last menu item.
`$activatedEvent(<popup_id:uinteger>)`
This function is called when a menu item and return the the item ID. The default implementation emits the $activated() signal.
`$highligthtedEvent(<popup_id:uinteger>)`
This function is called when a menu item is highlighted (hovered) and return the item ID. The default implementation emits the $highlighted() signal.

Signals

`$activated()`
This signal is emitted by the default implementation of $activatedEvent().
`$highlighted()`
This signal is emitted by the default implementation of $highlightedEvent().

Examples

# First we define a class inherited from popupmenu
class(menu,popupmenu)
{
constructor()
{
# We store the item's ID for checking in activatedEvent
@%tile_id=@$insertItem("Tile",118)
@%cascade_id=@$insertItem("Cascade",115)
@$insertSeparator(3)
@%closeactw_id=@$insertItem("Close Active Window",08)
@%closeallw_id=@$insertItem("Close All Window",58)
}
activatedEvent()
{
# Now we emit a signals to the relative to the user choice
%id=$0
if (%id==@%tile_id) @$emit("tile")
else if(%id==@%cascade_id) @$emit("cascade")
else if (%id==@%closeactw_id) @$emit("closeactive")
else @$emit("closeallwindows")
# Deleting the popup
delete $$
}
}
class (ws,widget)
{
In the constructor we create everything that belong to the single widget.
constructor()
{
# Here we generate a loop to create our labels inside the widget.
%lay=$new(layout,$$)
we use a vbox to managing labels in vertical orientation
%vb=$new(vbox,$$)
# Then add the vbox to the main layout
%lay->$addWidget(%vb,0,0)
# Let's create our colorful labels
for(%i=0;%i<15;%i++)
{
@%label=$new(label,%vb)
@%label->$settext("Another class by N\&G")
# We set our foreground's colors using the hex array in a random way.
@%label->$setforegroundcolor($array($rand(255),$rand(255),$rand(255)))
}
}
customContextMenuRequestedEvent()
{
# We create the popupmenu relative to this widget at runtime.
%p=$new(menu,$$)
objects.connect %p tile @$parent tile
objects.connect %p cascade @$parent cascade
objects.connect %p closeactive @$parent closeactivewindow
objects.connect %p closeallwindows @$parent closeallwindows
%p->$exec($$,$($0+10),$($1+10))
}
}
# We create the workspace widget
%Workspace=$new(workspace)
# We use as space as we have
%size[]=%Workspace->$screenResolution()
# Resize it
%Workspace->$resize(%size[0],%size[1])
# Then create 20 subwidget
for(%i=0;%i<20;%i++)
{
%w=$new(ws,%Workspace)
# Let's add every widget to the workspace
%Workspace->$addSubWindow(%w)
# Then "shake it" a little bit around :-)
%w->$move($rand($(%size[0]-50)),$rand($(%size[1]-50)))
}
# Reimplement closeEvent to delete all this :-)
privateimpl(%Workspace,closeEvent)
{
delete $$
}
# Let's show!
%Workspace->$show()

Index, Object Classes