File: treebar.cpp

package info (click to toggle)
clanlib 0.5.4-1-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 10,320 kB
  • ctags: 10,893
  • sloc: cpp: 76,056; xml: 3,281; sh: 2,961; perl: 1,204; asm: 837; makefile: 775
file content (113 lines) | stat: -rw-r--r-- 2,864 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

#ifdef WIN32
#pragma warning(disable : 4355)
#pragma warning(disable : 4786)
#endif

#include "treebar.h"
#include "mainframe.h"
#include "component_node.h"

/////////////////////////////////////////////////////////////////////////////
// TreeBar construction:

TreeBar::TreeBar(MainFrame *mainframe)
: CL_Component(mainframe), mainframe(mainframe), tree(this)
{
	Document &doc = get_document();

	std::list<ComponentNode *>::iterator it;
	for (it = doc.nodes.begin(); it != doc.nodes.end(); it++)
	{
		on_node_added(*it);
	}

	slots.connect(sig_resize(), this, &TreeBar::on_resize);
	slots.connect(tree.sig_selection_changed(), this, &TreeBar::on_tree_selection_changed);
	slots.connect(doc.sig_node_added, this, &TreeBar::on_node_added);
	slots.connect(doc.sig_node_removed, this, &TreeBar::on_node_removed);
	slots.connect(doc.sig_node_options_changed, this, &TreeBar::on_node_options_changed);
	slots.connect(doc.sig_node_type_changed, this, &TreeBar::on_node_type_changed);
	slots.connect(mainframe->sig_selection_changed, this, &TreeBar::on_selection_changed);

	on_resize(get_width(), get_height());
}

TreeBar::~TreeBar()
{
}

/////////////////////////////////////////////////////////////////////////////
// TreeBar attributes:

Document &TreeBar::get_document()
{
	return mainframe->document;
}

/////////////////////////////////////////////////////////////////////////////
// TreeBar operations:


/////////////////////////////////////////////////////////////////////////////
// TreeBar implementation:

void TreeBar::on_tree_selection_changed(const CL_TreeView_Node &node)
{
}

void TreeBar::on_resize(int old_width, int old_height)
{
	int width = get_width();
	int height = get_height();

	tree.set_position(CL_Rect(4, 4, width-4, height-4));
}

void TreeBar::on_node_added(ComponentNode *node)
{
	CL_TreeView_Node *parent = &tree;
	if (node->get_parent() != 0)
	{
		std::map<ComponentNode *, CL_TreeView_Node *>::iterator it_comp;
		it_comp = tree_nodes.find(node->get_parent());
		if (it_comp != tree_nodes.end()) parent = it_comp->second;
	}

	std::string name = node->get_type();
	if (!node->get_name().empty())
		name = name + " [" + node->get_name() + "]";

	CL_TreeView_Node *tree_node = parent->insert_item(name);
	tree_nodes[node] = tree_node;

	std::list<ComponentNode *>::iterator it;
	for (it = node->nodes.begin(); it != node->nodes.end(); it++)
	{
		on_node_added(*it);
	}
}

void TreeBar::on_node_removed(ComponentNode *node)
{
}

void TreeBar::on_node_options_changed(ComponentNode *node)
{
}

void TreeBar::on_node_type_changed(ComponentNode *node)
{
}

void TreeBar::on_selection_changed(std::list<ComponentNode *> &selection)
{
	tree.clear_selection();

	std::list<ComponentNode *>::iterator it;
	for (it = selection.begin(); it != selection.end(); it++)
	{
		ComponentNode *node = *it;
		tree_nodes[node]->set_selected(true);
	}
}