File: table-list.hh

package info (click to toggle)
gelemental 1.2.0-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,412 kB
  • ctags: 705
  • sloc: sh: 11,797; cpp: 5,255; makefile: 197
file content (156 lines) | stat: -rw-r--r-- 3,909 bytes parent folder | download | duplicates (7)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * This file is part of gElemental, a periodic table viewer with detailed
 * information on elements.
 *
 * Copyright (C) 2006-2007 Kevin Daughtridge <kevin@kdau.com>
 * Copyright (C) 2003 Jonas Frantz <jonas.frantz@welho.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef GELEMENTAL__TABLE_LIST_HH
#define GELEMENTAL__TABLE_LIST_HH

#include "misc.hh"

#include <gtkmm/actiongroup.h>
#include <gtkmm/liststore.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/treeview.h>
#include <gtkmm/uimanager.h>

//******************************************************************************

namespace gElemental {

//******************************************************************************

class TableListColumns
:	public Gtk::TreeModelColumnRecord
{
public:
	
	static TableListColumns& get ();

	Gtk::TreeModelColumn<unsigned int> number;
	Gtk::TreeModelColumn<std::string> symbol;
	Gtk::TreeModelColumn<Gdk::Color> color, compliment;
	Gtk::TreeModelColumn<ustring> name;
	Gtk::TreeModelColumn<Int> group, period;
	Gtk::TreeModelColumn<Block> block;
	Gtk::TreeModelColumn<const Element*> el;

protected:

	TableListColumns ();
};

//******************************************************************************

class TableListStore
:	public Gtk::ListStore
{
public:

	static RefPtr<TableListStore> create ();

	static int default_sort (const Gtk::TreeIter& a, const Gtk::TreeIter& b);

protected:

	TableListStore ();

	template<class T1> int on_value_sort (const Gtk::TreeIter& a,
		const Gtk::TreeIter& b, const Gtk::TreeModelColumn<T1>& col);

	TableListColumns &cols;
};

//******************************************************************************

class PropertyColumn
:	public SortColumn
{
public:

	PropertyColumn (const RefPtr<Gtk::ListStore>& store,
		Gtk::RadioButtonGroup& group);
	
	PropertyBase* get_property () const;
	void set_property (PropertyBase* property);
	
	sigc::signal<void> signal_unavailable;
	
protected:

	virtual int on_value_sort (const Gtk::TreeIter& a, const Gtk::TreeIter& b);

	virtual void on_cell_data (Gtk::CellRenderer* cell,
		const Gtk::TreeIter& iter);

private:

	RefPtr<Gtk::ListStore> store;
	Gtk::TreeModelColumn<const Element*> &el_col;
	PropertyBase *property;
};

//******************************************************************************

class TableList
:	public Gtk::ScrolledWindow
{
public:

	TableList (const RefPtr<Gtk::UIManager>& ui);
	virtual ~TableList ();

	struct State
	{
		int sort_column;
		Gtk::SortType sort_order;
		PropertyBase *extra_property;
	};
	
	State get_state () const;
	void set_state (State& state);

private:

	void on_order_activated (Gtk::SortType order);
	void on_sort_column_changed ();

	static bool c_on_extra_column_clicked (GtkWidget*, GdkEventButton* ev,
		TableList* self);
	bool on_extra_column_clicked (GdkEventButton* ev);

	void on_row_activated (const Gtk::TreePath& treepath, Gtk::TreeViewColumn*);

	TableListColumns &cols;
	RefPtr<TableListStore> store;
	Gtk::TreeView view;
	
	RefPtr<Gtk::UIManager> ui;
	Gtk::UIManager::ui_merge_id ui_id;
	RefPtr<Gtk::ActionGroup> actions;
	RefPtr<Gtk::RadioAction> ascending, descending;
	bool order_recursing;

	Gtk::RadioButtonGroup sort_group;
	PropertyColumn prop_col;
};

} // namespace gElemental

#endif // GELEMENTAL__TABLE_LIST_HH