File: document.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 (95 lines) | stat: -rw-r--r-- 2,337 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

#pragma warning(disable:4786)

#include "document.h"
#include "component_node.h"
#include <ClanLib/Core/IOData/inputsource_provider.h>

/////////////////////////////////////////////////////////////////////////////
// Document construction:

Document::Document()
{
	load("test.gui");
}

Document::~Document()
{
}

/////////////////////////////////////////////////////////////////////////////
// Document attributes:


/////////////////////////////////////////////////////////////////////////////
// Document operations:

void Document::clear()
{
}

void Document::load(const std::string &gui_file)
{
	CL_GUIFileParser parser(
		gui_file, 
		CL_InputSourceProvider::create_file_provider(".")->open_source(gui_file));

	CL_GUIFileParser::component_sort_map_t::iterator it;
	it = parser.get_sorted_components().find(0);
	while (it != parser.get_sorted_components().end())
	{
		// Only enumerate first level components:
		if (it->first != 0) break;

		CL_GUIFileParser::ComponentInfo *info = it->second;
		ComponentNode *node = new ComponentNode(info->name, info->type, info->options, this);
		nodes.push_back(node);

		std::list<CL_GUIFileParser::ComponentInfo *>::iterator it_child;
		for (it_child = info->children.begin(); it_child != info->children.end(); it_child++)
		{
			add_node_child(node, *it_child);
		}

		it++;
	}
}

void Document::save(const std::string &gui_file)
{
}

ComponentNode *Document::add_node(const std::string &type)
{
	CL_ComponentOptions options;
	ComponentNode *node = new ComponentNode("", type, options, this);
	nodes.push_back(node);
	sig_node_added(node);
	return node;
}

void Document::remove_node(ComponentNode *node)
{
	nodes.remove(node);
	sig_node_removed(node);
	delete node;
}

/////////////////////////////////////////////////////////////////////////////
// Document signals:


/////////////////////////////////////////////////////////////////////////////
// Document implementation:

void Document::add_node_child(ComponentNode *parent, CL_GUIFileParser::ComponentInfo *info)
{
	ComponentNode *node = new ComponentNode(info->name, info->type, info->options, parent);
	parent->nodes.push_back(node);

	std::list<CL_GUIFileParser::ComponentInfo *>::iterator it_child;
	for (it_child = info->children.begin(); it_child != info->children.end(); it_child++)
	{
		add_node_child(node, *it_child);
	}
}