CommonCtrl.ContextMenu
Context menu, using a tree view internally for sub level menus. It has a modern appearance.
Title |
Context menu, using a tree view internally for sub level menus. It has a modern appearance. |
Author(s) |
LiXizhi |
Date |
2007/9/24 |
File |
script/ide/ContextMenu.lua |
Description
Member Functions
ContextMenu:new
common control library
NPL.load("(gl)script/ide/common_control.lua");
NPL.load("(gl)script/ide/TreeView.lua");
NPL.load("(gl)script/ide/WindowFrame.lua");
define a new control in the common control libary
default member attributes
local ContextMenu = {
-- the top level control name
name = "ContextMenu1",
-- normal window size
width = 400,
height = 290,
-- this is the maximum height, a scroll bar will be used if there are too many menu items.
MaxHeight = 500,
-- this is the minimum height of the content menu, unless there are so few items to display
MinHeight = 40,
-- auto positioning method: it can be
-- "_lt": left top, where the mouse x, y will be the left top point of the menu container. This is the default mode.
-- "_lb": left bottom, where the mouse x, y will be the left bottom point of the menu container.
AutoPositionMode = "_lt",
-- the background of container
container_bg = nil,
-- The root tree node. containing all tree node data
RootNode = nil,
-- Default height of Tree Node
DefaultNodeHeight = 22,
-- default icon size
DefaultIconSize = 16,
-- default indentation
DefaultIndentation = 16,
-- Gets or sets a function by which the individual TreeNode control is drawn. The function should be of the format:
-- function DrawNodeEventHandler(parent,treeNode) end, where parent is the parent container in side which contents should be drawn. And treeNode is the TreeNode object to be drawn
-- if DrawNode is nil, the default ContextMenu.DrawMenuItemHandler function will be used.
DrawNodeHandler = nil,
-- Force no clipping or always using fast render. Unless you know that the unit scroll step is interger times of all TreeNode height. You can disable clipping at your own risk.
-- Software clipping is always used to clip all invisible TreeNodes. However, this option allows you to specify whether to use clipping for partially visible TreeNode.
NoClipping = nil,
-- a function of type function (MenuItem, param1) or nil. this function will be called for each menuitem onclick except the group node.
onclick = nil,
-- NOTE by Andy 2008/12/7: add a style to allow customized menu apperance
-- define menu apperance style
style = nil,
-------------------------------------------
-- private functions
-------------------------------------------
IsModified = true,
}
CommonCtrl.ContextMenu = ContextMenu;
ContextMenu.DefaultStyle = {
borderTop = 4,
borderBottom = 4,
borderLeft = 0,
borderRight = 0,
fillLeft = -20,
fillTop = -15,
fillWidth = -19,
fillHeight = -24,
menu_bg = "Texture/Aquarius/Common/ContextMenu_BG_32bits.png: 31 27 31 36",
shadow_bg = nil,
separator_bg = "Texture/Aquarius/Common/ContextMenu_Separator.png: 1 1 1 4",
item_bg = "Texture/Aquarius/Common/ContextMenu_ItemBG_32bits.png: 1 1 1 1",
expand_bg = "Texture/Aquarius/Common/ContextMenu_Expand.png",
expand_bg_mouseover = "Texture/Aquarius/Common/ContextMenu_Expand_MouseOver.png",
menuitemHeight = 22,
separatorHeight = 8,
titleHeight = 22,
titleFont = "System;14;bold";
}
;
constructor
syntax
function ContextMenu:new (o)
parameters
ContextMenu:Destroy
Destroy the UI control
syntax
function ContextMenu:Destroy ()
ContextMenu.ShowContainerWithAnimation
show the container with animation
syntax
function ContextMenu.ShowContainerWithAnimation(obj)
parameters
ContextMenu.HideContainerWithAnimation
hide the container with animation
syntax
function ContextMenu.HideContainerWithAnimation(obj)
parameters
ContextMenu:Show
- param x : where to display. if nil, mouse_x is used
- param y : where to display. if nil, mouse_y is used
- param param1 : a optional parameter object to be passed to onclick event
syntax
function ContextMenu:Show(x, y, param1)
parameters
x |
where to display. if nil, mouse_x is used |
y |
|
param1 |
a optional parameter object to be passed to onclick event |
ContextMenu:Hide
hide the context menu
- return true : if object is original shown, and is hidden now. if the control is already hidden prior to this call, the function return nil.
syntax
function ContextMenu:Hide()
parameters
return |
if object is original shown, and is hidden now. if the control is already hidden prior to this call, the function return nil. |
ContextMenu.OnClose
close the given control
syntax
function ContextMenu.OnClose(sCtrlName)
parameters
ContextMenu.OnMouseClickCont
this is a click outside the menu container, we will therefore hide the container.
syntax
function ContextMenu.OnMouseClickCont(sCtrlName)
parameters
ContextMenu.OnMouseDownCont
this is a click outside the menu container, we will therefore hide the container.
syntax
function ContextMenu.OnMouseDownCont(sCtrlName)
parameters
ContextMenu.OnMouseUpCont
this is a click outside the menu container, we will therefore close the container.
syntax
function ContextMenu.OnMouseUpCont(sCtrlName)
parameters
ContextMenu.OnClickItem
onclick event handler
syntax
function ContextMenu.OnClickItem(sCtrlName, nodePath)
parameters
ContextMenu.OnMouseEnterItem
onmouseenter event handler
syntax
function ContextMenu.OnMouseEnterItem(sCtrlName, index)
parameters
ContextMenu.OnMouseLeaveItem
onmouseleave event handler
syntax
function ContextMenu.OnMouseLeaveItem(sCtrlName, index)
parameters
ContextMenu:SetModified
set modified, always call this function after you have changed the menu items.
this will cause the content menu to redraw next time it shows up.
syntax
function ContextMenu:SetModified(bModified)
parameters
ContextMenu.OnToggleNode
private function: called by default
TreeNode UI
syntax
function ContextMenu.OnToggleNode(sCtrlName, nodePath)
parameters
ContextMenu.OnClickNode
private function: called by default
TreeNode UI
syntax
function ContextMenu.OnClickNode(sCtrlName, nodePath)
parameters
ContextMenu.DrawMenuItemHandler
default node renderer: it display a clickable check box for expandable node, followed by node text
syntax
function ContextMenu.DrawMenuItemHandler(_parent,treeNode)
parameters