File: combobox_generic.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 (143 lines) | stat: -rw-r--r-- 3,675 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
	$Id: combobox_generic.cpp,v 1.12 2001/12/27 23:14:03 sphair Exp $
	
	ClanGUI, copyrights by various people. Have a look in the CREDITS file.
	
	This sourcecode is distributed using the Library GNU Public Licence,
	version 2 or (at your option) any later version. Please read LICENSE
	for details.
*/

#include "precomp.h"
#include "combobox_generic.h"
#include "API/GUI/component_options.h"

CL_ComboBox_Generic::CL_ComboBox_Generic(CL_ComboBox *self)
: combobox(self)
{
	highlighted_item = 0;
	select_button = NULL;
	activated = false;

	slot_set_options = self->sig_set_options().connect(this, &CL_ComboBox_Generic::on_set_options);
}

CL_ComboBox_Generic::~CL_ComboBox_Generic()
{
}

int CL_ComboBox_Generic::get_count() const
{
	return items.size();
}

std::list<std::string> &CL_ComboBox_Generic::get_items()
{
	return items;
}

std::string CL_ComboBox_Generic::get_current_text() const
{
	int count = highlighted_item;
	std::list<std::string>::const_iterator it;
	for (it = items.begin(); it != items.end() && count > 0; it++, count--);
		if (it != items.end())
			return *it;

	char buf[100];
	sprintf(buf, "Listbox has illegal value: %d", highlighted_item);
	throw CL_Error(buf);
}

std::string CL_ComboBox_Generic::get_text(int index) const
{
	return "";
}

int CL_ComboBox_Generic::get_current_item() const
{
	return 0;
}

bool CL_ComboBox_Generic::is_selected(int index) const
{
	return false;
}

int CL_ComboBox_Generic::insert_item(const std::string &text, int index)
{
	return 0;
}

void CL_ComboBox_Generic::remove_item(int index)
{
}

void CL_ComboBox_Generic::change_item(const std::string &text, int index)
{
}

void CL_ComboBox_Generic::set_current_item(int index)
{
	highlighted_item = index;
	sig_highlighted(highlighted_item);
}

void CL_ComboBox_Generic::clear_selection()
{
}

void CL_ComboBox_Generic::sort(bool ascending)
{
}

void CL_ComboBox_Generic::clear()
{
}

void CL_ComboBox_Generic::set_select_button(CL_Button *_select_button)
{
	// TODO: Fix this:
/*	select_button = _select_button;
	slot_clicked = select_button->sig_clicked().connect(
		this, &CL_ComboBox_Generic::select_clicked);
	combobox->add_child(select_button, true);

	CL_ComponentOptions b_options;
	#ifdef BORLAND
		b_options.options.insert(std::make_pair(std::string("x"), std::string("0")));
		b_options.options.insert(std::make_pair(std::string("y"), std::string("0")));
		b_options.options.insert(std::make_pair(std::string("width"), std::string(CL_String(combobox->get_width()-select_button->get_width()))));
		b_options.options.insert(std::make_pair(std::string("height"), std::string(CL_String(combobox->get_height()))));
	#else
		b_options.options.insert(std::make_pair<std::string, std::string>("x", "0"));
		b_options.options.insert(std::make_pair<std::string, std::string>("y", "0"));
		b_options.options.insert(std::make_pair<std::string, std::string>("width", CL_String(combobox->get_width()-select_button->get_width())));
		b_options.options.insert(std::make_pair<std::string, std::string>("height", CL_String(combobox->get_height())));
	#endif

	CL_Button *text_area_button = new CL_Button(b_options, this);
	slot_pressed = text_area_button->sig_pressed.connect(
		this, &CL_ComboBox::select_clicked);
	add_child(text_area_button, true);
*/
}

void CL_ComboBox_Generic::select_clicked()
{
/*	if (skip_next_activation)
	{
		skip_next_activation = false;
		return;
	}
	activated = !activated;
	if (activated) sig_activated(highlighted_item);
*/
}

void CL_ComboBox_Generic::on_set_options(const CL_ComponentOptions &options)
{
	int num_values = options.count("value");
	for (int i = 0; i < num_values; i++)
		items.push_back(options.get_value("value", i));
}