On 19/01/2014 at 06:24, xxxxxxxx wrote:
Hi Niklas, sorry still very confusing.
I can now create a data structure and defined the TreeViewFunctions.
Not all of them, GetFirst and GetName, GetDown, GetNext and SetName.
I now get a window with a starting treeview and one little arrow.
No names however.
Is *root in my case always root (so I have to define it globally) or is it somewhere else defined?
Also, I seem to be mixing up class Node and class MyNode.
When to use which class?
#include "c4d.h"
#define ID_SHADER_BROWSER 11229405 // plugin id test
class Node {
public:
Node* next;
Node* pred;
Node* up;
Node* down;
String name;
Node() : next(nullptr), pred(nullptr), up(nullptr), down(nullptr), name("") { }
Node(const String& name) : next(nullptr), pred(nullptr), up(nullptr), down(nullptr), name(name) {
}
virtual ~Node() {
next = pred = up = down = nullptr;
}
void InsertAfter(Node* pred) {
if (pred->next) {
pred->next->pred = this;
this->next = pred->next;
}
pred->next = this;
this->pred = pred;
if (pred->up)
this->up = pred->up;
}
void InsertBefore(Node* next) {
if (next->pred) {
next->pred->next = this;
this->pred = next->pred;
}
next->pred = this;
this->next = next;
if (pred->up)
this->up = pred->up;
if (this->pred == nullptr && this->up)
this->up->down = this;
}
void InsertUnder(Node* up) {
if (up->down) {
this->InsertBefore(up->down);
}
else {
up->down = this;
this->up = up;
}
}
//void Remove() { code removed
};
class MyNode : public Node
{
typedef Node super;
public:
String name;
Bool selected, folded;
MyNode(const String& name) : super(), name(name), selected(false), folded(true) { }
};
GeListNode* GetNextElement(GeListNode* op)
{
if (!op)
return NULL;
// in case of material inspect shaders otherwise continue in usual mode
if (op->IsInstanceOf(Mmaterial) && ((BaseList2D* )op)->GetFirstShader())
{
return ((BaseList2D* )op)->GetFirstShader();
}
else if (op->GetDown())
return op->GetDown();
while (!op->GetNext() && op->GetUp())
op = op->GetUp();
return op->GetNext();
}
void UnselectNodes(BaseDocument *doc)
{
if (!doc)
return;
BaseList2D *mat = (BaseList2D* )doc->GetFirstMaterial();
if (!mat)
return;
while (mat)
{
mat->DelBit(BIT_ACTIVE);
mat = (BaseList2D* )GetNextElement(mat);
}
}
//----------------------------------------------------------------------------------------
///TreeView Functions Table class
//----------------------------------------------------------------------------------------
class CustomTree : public TreeViewFunctions
{
public:
virtual void* GetFirst(void* root, void* ud) {
if (root)
{
return static_cast<MyNode*>(root)->down;
}
return nullptr;
}
virtual String GetName(void* root, void* ud, void* obj) {
if (obj)
{
return static_cast<MyNode*>(obj)->name;
}
return "???";
}
// ...
virtual Bool IsOpened(void *root,void *userdata,void *obj)
{
return false;
}
virtual void Open(void* root, void* userdata, void* obj, Bool onoff)
{
return;
}
void SetName(void* root, void* userdata, void* obj, const String& str)
{
static_cast<MyNode*>(obj)->name = str;
return;
}
virtual void* GetDown(void *root,void *userdata,void *obj)
{
return static_cast<MyNode*>(root)->down;
}
virtual void* GetNext(void *root,void *userdata,void *obj)
{
return static_cast<MyNode*>(root)->next;
}
virtual void Select(void *root,void *userdata,void *obj,Int32 mode)
{
return;
}
virtual Bool IsSelected(void *root,void *userdata,void *obj)
{
return FALSE;
}
virtual Int GetId(void *root,void *userdata,void *obj)
{
return (Int)obj;
}
virtual Int32 GetDragType(void *root,void *userdata,void *obj)
{
return NOTOK;
}
};
//----------------------------------------------------------------------------------------
///Dialog class
//----------------------------------------------------------------------------------------
class CustomBrowser : public GeDialog
{
public:
CustomBrowser()
{
_customTreeGui = NULL;
}
~CustomBrowser()
{
}
// define dialog with some gadget build menus, title and so on
virtual Bool CreateLayout(void)
{
// call class parent function
Bool res = GeDialog::CreateLayout();
// set dialog title
SetTitle("Custom Tree Browser");
//attach treeview so the GUI element and define its parameter via treedata BaseContainer
BaseContainer treedata;
treedata.SetBool(TREEVIEW_ALTERNATE_BG,TRUE);
_customTreeGui = (TreeViewCustomGui* )AddCustomGui(1000, CUSTOMGUI_TREEVIEW, String(), BFH_SCALEFIT|BFV_SCALEFIT, 0, 0, treedata);
if (_customTreeGui)
{
BaseContainer layout;
// add column 0 with type LV_TREE so default tree with name
layout.SetInt32(0, LV_TREE);
// set column layout to the GUI element
if (!_customTreeGui->SetLayout(1,layout))
return FALSE;
}
return res;
}
// set tree root and update it
Bool UpdateTree(Node* root)
{
if (!_customTreeGui->SetRoot(root, &_customTree, NULL))
return FALSE;
// update tree GUI
_customTreeGui->Refresh();
return TRUE;
}
// initialize dialog
Bool InitValues(void)
{
// call parent function
if (!GeDialog::InitValues())
return FALSE;
// build tree datastructure
Node* root = new Node("ROOT");
Node* firstChild = new Node("First Entry");
firstChild->InsertUnder(root);
Node* secondChild = new Node("Second Entry");
secondChild->InsertUnder(firstChild);
Node* thirdChild = new Node("Third Entry");
thirdChild->InsertUnder(secondChild);
// build tree and set root
if (!UpdateTree(root))
return FALSE;
return TRUE;
}
// react toglobal notifications
Bool CoreMessage(Int32 id, const BaseContainer& msg)
{
//if (id == EVMSG_CHANGE)
//{
// get active document
// BaseDocument * doc = GetActiveDocument();
// if (!doc)
// return FALSE;
// build tree and set root How to get root?
// if (!UpdateTree(doc))
// return FALSE;
//}
return GeDialog::CoreMessage(id, msg);
}
private:
CustomTree _customTree;
TreeViewCustomGui *_customTreeGui;
};
...