'=======================================================
'===efei super treeview
'===code by efei(草不含羞)
'===mailto:efei731@sina.com
'===2004.7
'=======================================================
dim tvwroot
dim tvwchild
dim tvwprevious
dim tvwnext
tvwroot = 0
tvwchild = 1
tvwprevious = 2
tvwnext = 3
'===树的类
class treeview
?public name???'对象名
?public treeview_name
?
?private arrnodes??'节点集合,从0开始
?
?private arrimage??'图标数组
?
?
?
?
?private addfromexpand??'节点的添加是否来自于父节点的展开
?
?'===一些设置
?
?public firstdisplaylevel?'初次显示几层
?public useconnectline??'使用节点之间的连接线
?'public imagepath???'图象目录
?public target????'链接目标
?public font_size???'文字大小
?public font_family???'字体
?public font_color???'颜色
?public selectedbgcolor??'选中的节点背景色
?
?'===图象目录=============================
?private limagepath???
?public property get imagepath()
??imagepath = limagepath
?end property
?public property let imagepath(byval vnewvalue)
??'更新之前先去掉原来的节点的边框
??limagepath = vnewvalue
??if right(limagepath,1) <> "/" then limagepath = limagepath & "/"
?end property
?'========================================
?
?private lselectednode??'被选择的节点
?public property get selectednode()
??set selectednode = lselectednode
?end property
?public property let selectednode(byval vnewvalue)
??'更新之前先去掉原来的节点的边框
??if not lselectednode is nothing then
???with document.getelementbyid("txt" & lselectednode.key).style
????.background = ""
???end with
??end if
??set lselectednode = vnewvalue
??with document.getelementbyid("txt" & lselectednode.key).style
???.background = selectedbgcolor
??end with
?end property
?
?private lmenunode
?private lpopupmenu
?
?'===类的析构函数,用于初始化对象==============
?private sub class_initialize()
??'===初始化树对象
??document.write "
??'===
??redim arrnodes(0)
??set arrnodes(0) = nothing
??name=""
??treeview_name = "efei super treeview"
??
??set lselectednode = nothing
??set lmenunode = nothing
??lpopupmenu = ""
??
??redim arrimage(1,2)
??arrimage(0,0) = "folderclose"
??arrimage(1,0) = "folderclose.gif"
??arrimage(0,1) = "folderopen"
??arrimage(1,1) = "folderopen.gif"
??arrimage(0,2) = "rplus"
??arrimage(1,2) = "rplus.gif"
??addimage "root","root.gif"
??addimage "file","file.gif"
??
??limagepath = "image/"
??firstdisplaylevel = 0
??useconnectline = true
??addfromexpand = false
??target = "_blank"
??
??font_size = "12px"
??font_family = "宋体"
??font_color = "#000000"
??selectedbgcolor = "#d4d0c8"
??
?end sub
?'===============================================
?
?'===功能:?添加一个节点
?'===参数:?text???节点显示的文本
?'???key????节点关键字,该关键字必须唯一
?'???hyperlink??节点要链接到的地址
?'???node???父节点或者兄弟节点
?'???addtype???添加类型,0-子节点,1-子节点,2-前置节点,3-后置节点
?'???image???节点的图片,如空,则使用关闭的文件夹
?public function add(byval text,byval key,byval hyperlink,byref node,byval addtype,byval image)
??dim i
??'先检查关键字是否已存在,参数是否合法
??key = trim(key)
??if key = "" then
???msgbox "关键字不能为空",vbinformation,treeview_name
???exit function
??end if
??if not me.nodes(key) is nothing then
???msgbox "关键字【" & key & "】已存在",vbinformation,treeview_name
???exit function
??end if
??text = trim(text)
??if text = "" then
???msgbox "节点文本不能为空",vbinformation,treeview_name
???exit function
??end if
??if isnumeric(addtype) = true then
???if addtype < 0 and addtype > 3 then
????addtype = 1
???end if
??else
???addtype = 1
??end if
??if node is nothing then
???if me.nodescount <> 0 then
????msgbox "根节点只能有一个",vbinformation,treeview_name
????exit function
???end if
???addtype = 0
??end if
???
??redim preserve arrnodes(me.nodescount)
??set arrnodes(ubound(arrnodes)) = new node
??
??
??
??with arrnodes(ubound(arrnodes))
???.key = key
???.text=text
???.hyperlink=hyperlink
???
???.addtype = addtype
???.image = image
???set .parentobject = me
???
???
???select case addtype
????case 0??'根节点
?????set .parentnode=nothing
?????set .nextnode = nothing
????case 1??'子节点
?????set .parentnode = node??????'父节点
?????if node.childrencount > 0 then
??????set .previousnode = node.children(node.childrencount)
??????set node.children(node.childrencount).nextnode = arrnodes(ubound(arrnodes))
?????end if
?????set .nextnode = nothing
????case 2??'插在前面
?????set .parentnode = node.parentnode
?????set .previousnode = node.previousnode
?????set node.previousnode.nextnode = arrnodes(ubound(arrnodes))
?????set node.previousnode = arrnodes(ubound(arrnodes))
?????set .nextnode = node
?????
????case 3??'插在后面
?????set .parentnode = node.parentnode