# IupTreeView

Definition: | include pGUI.e Ihandle ih = IupTreeView(sequence tree_nodes, atom branchopen_cb=NULL, string attributes="", dword_seq args={})
Description: | Creates a nested tree control with expandable/collapsable nodes from a recursive [callback] data structure. An IupTreeView is a Phix/pGUI invention, expressly written for pwa/p2js, but can of course be used for desktop/Phix-only purposes. The desktop version wraps IupFlatTree() with IupTreeAddNodes(), in other words a restricted/easier subset. The equivalent functionality is implemented in the browser using nested ul/li with a tiny embedded gif and a a small handful of suitable unicode characters, plus of course about 300 lines of handcrafted javascript/CSS. The main purpose of this page is to show only pwa/p2js supported features, in preference to littering the IupFlatTree page with dozens if not hundreds of "not supported" markers. Note, for example, that USERDATA is used internally, so that and IupTreeSet/Get[User]Id() are not available to the application, at least not in any generally useful way, other than as dictated below. In fact, IupTreeGetUserId() is effectively a null-op on the browser, however it is required on the desktop because of the way IUP renumbers nodes as predecessors are inserted. tree_nodes: a nested construct of the form {"text"[,attr][,children]}, suitable for passing to IupTreeAddNodes(). It may be empty, however the latter routine must then be invoked before display to populate it with something, even partial, otherwise the desktop version crashes. branchopen_cb: an Icallback for deferred loading, or NULL if tree_nodes is complete. For more information on the attributes and args parameters see IupSetAttributes. Returns: the identifier of the created element.
pwa/p2js: | Supported.
See Also: | IupTreeAddNodes
Example: | Desktop appearance: Browser appearance:
    -- pwa\phix\IupTreeView.exw
    include pGUI.e
    sequence tree_nodes = {"Figures",               -- (branch with 5 children)
                           {"Other",                -- (leaf)
                            {"triangle",            -- (branch with 3 children)
                             {"STATE","COLLAPSED"},
                             {"equilateral",
                              {"isoceles",          -- (branch with 2 children)
                               {"STATE","COLLAPSED"},
                               {"acute",
                                "obtuse"}},
                              "scalenus"}},
                            {"parallelogram",       -- (branch with 2 children)
                             {"square",
                              "diamond"}},
                            "2D",                   -- (leaf)
                            {"3D",                  -- (branch)
                             {"STATE","COLLAPSED"}, -- (needed here)
                             {}},                   -- (empty)
                            {"4D",
                             {"STATE","COLLAPSED"},
                              {"some",
                               "other",
                               "branch"}}
                           }
                          }
    IupOpen()
    Ihandle tree = IupTreeView(tree_nodes)
    Ihandle dlg = IupDialog(tree)
    IupSetAttribute(dlg,"TITLE","IupTreeView basic demo")
    IupSetAttribute(dlg,"RASTERSIZE","260x230")
    IupShow(dlg)
    IupSetAttribute(dlg,"RASTERSIZE", NULL);
    if platform()!=JS then
        IupMainLoop()
        IupClose()
    end if
Attributes: |
Marks | (non inheritable)
MARKMODE | (not yet implemented , but planned) defines how the nodes can be selected. Can be: SINGLE or MULTIPLE. Default: SINGLE.
Callbacks: |
BRANCHOPEN_CB+ | Action generated when a branch is expanded. This action occurs when the user clicks the "+" sign on the left of the branch, or when double clicks the branch, or hits Enter on a collapsed branch. function branchopen_cb(Ihandle ih, integer id) ih: identifier of the element that activated the event. id: node identifier. Returns: IUP_IGNORE for the branch not to be opened, or IUP_DEFAULT for the branch to be opened.
Examples: | See pwa/phix/IupTreeView.exw and pwa/phix/IupTreeView2.exw