diff options
author | Pixel <pixel@nobis-crew.org> | 2009-11-04 11:56:41 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-11-04 11:59:33 -0800 |
commit | d577d991b97ae2b5ee1af23641bcffc3f83af5b2 (patch) | |
tree | 590639d50205d1bcfaff2a7d2dc6ebf3f373c7ed /iup/srclua5/tree.lua |
Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux.
Diffstat (limited to 'iup/srclua5/tree.lua')
-rwxr-xr-x | iup/srclua5/tree.lua | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/iup/srclua5/tree.lua b/iup/srclua5/tree.lua new file mode 100755 index 0000000..bd8daf7 --- /dev/null +++ b/iup/srclua5/tree.lua @@ -0,0 +1,76 @@ +------------------------------------------------------------------------------ +-- Tree class +------------------------------------------------------------------------------ +local ctrl = { + nick = "tree", + parent = WIDGET, + creation = "", + callback = { + selection_cb = "nn", + multiselection_cb = "nn", -- fake definition to be replaced by treefuncs module + branchopen_cb = "n", + branchclose_cb = "n", + executeleaf_cb = "n", + renamenode_cb = "ns", + noderemoved_cb = "ns", -- fake definition to be replaced by treefuncs module + rename_cb = "ns", + showrename_cb = "n", + rightclick_cb = "n", + dragdrop_cb = "nnnn", + }, + extrafuncs = 1, +} + +local function TreeSetAttributeHandle(handle, name, value) + if iupGetClass(value) == "iup handle" then value = ihandle_setname(value) end + SetAttribute(handle, name, value) +end + +function TreeSetNodeAttrib(handle, node, id) + if node.color then SetAttribute(handle, "COLOR"..id, node.color) end + if node.state then SetAttribute(handle, "STATE"..id, node.state) end + if node.titlefont then SetAttribute(handle, "TITLEFONT"..id, node.titlefont) end + if node.marked then SetAttribute(handle, "MARKED"..id, node.marked) end + if node.image then TreeSetAttributeHandle(handle, "IMAGE"..id, node.image) end + if node.imageexpanded then TreeSetAttributeHandle(handle, "IMAGEEXPANDED"..id, node.imageexpanded) end + if node.userid then TreeSetUserId(handle, id, node.userid) end +end + +function TreeSetValueRec(handle, t, id) + if t == nil then return end + local cont = #t + while cont >= 0 do + local node = t[cont] + if type(node) == "table" then + if node.branchname then + SetAttribute(handle, "ADDBRANCH"..id, node.branchname) + TreeSetNodeAttrib(handle, node, id+1) + TreeSetValueRec(handle, node, id+1) + elseif node.leafname then + SetAttribute(handle, "ADDLEAF"..id, node.leafname) + TreeSetNodeAttrib(handle, node, id+1) + end + else + if node then + SetAttribute(handle, "ADDLEAF"..id, node) + end + end + cont = cont - 1 + end +end + +function TreeSetValue(handle, t, id) + if (not id) then + id = 0 -- default is the root + if t.branchname then SetAttribute(handle, "TITLE0", t.branchname) end + TreeSetNodeAttrib(handle, t, 0) + end + TreeSetValueRec(handle, t, id) +end + +function ctrl.createElement(class, arg) + return Tree() +end + +iupRegisterWidget(ctrl) +iupSetClass(ctrl, "iup widget") |