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
|
/*
* Copyright © 2004-2006 Jens Oknelid, paskharen@gmail.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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef WULFOR_TREE_VIEW_HH
#define WULFOR_TREE_VIEW_HH
#include <gtk/gtk.h>
#include <string>
#include <vector>
#include <map>
#include "settingsmanager.hh"
#include "WulforUtil.hh"
class TreeView
{
public:
typedef enum
{
STRING,
STRINGR,
INT,
BOOL,
PIXBUF,
PIXBUF_STRING,
EDIT_STRING,
PROGRESS
} columnType;
TreeView();
~TreeView();
void setView(GtkTreeView *view);
void setView(GtkTreeView *view, bool padding, const string &name = "");
GtkTreeView *get();
void insertColumn(const std::string &title, const GType >ype, const columnType type, const int width, const string &linkedCol = "");
void insertHiddenColumn(const std::string &title, const GType >ype);
void finalize();
int getColCount();
int getRowCount();
GType* getGTypes();
void setSortColumn_gui(std::string column, std::string sortColumn);
int col(const std::string &title);
void saveSettings();
string getString(GtkTreeIter *i, std::string column, GtkTreeModel *m = NULL);
template<class T, class C>
C getValue(GtkTreeIter *i, std::string column, GtkTreeModel *m = NULL)
{
if (m == NULL)
m = gtk_tree_view_get_model(view);
T value;
dcassert(gtk_tree_model_get_column_type(m, col(column)) != G_TYPE_STRING);
gtk_tree_model_get(m, i, col(column), &value, -1);
return C(value);
}
template<class T>
T getValue(GtkTreeIter *i, std::string column, GtkTreeModel *m = NULL)
{
if (m == NULL)
m = gtk_tree_view_get_model(view);
T value;
dcassert(gtk_tree_model_get_column_type(m, col(column)) != G_TYPE_STRING);
gtk_tree_model_get(m, i, col(column), &value, -1);
return value;
}
private:
class Column
{
public:
Column() {};
Column(std::string title, int id, GType gtype, TreeView::columnType type, int width, std::string linkedCol = "") :
title(title), id(id), gtype(gtype), type(type), width(width), pos(id), linkedCol(linkedCol), visible(true) {};
Column(std::string title, int id, GType gtype) :
title(title), id(id), gtype(gtype) {};
std::string title;
int id;
GType gtype;
TreeView::columnType type;
int width;
int pos;
std::string linkedCol;
bool visible;
bool operator<(const Column &right) const
{
return pos < right.pos;
}
};
void addColumn_gui(Column column);
void restoreSettings();
static gboolean popupMenu_gui(GtkWidget *widget, GdkEventButton *event, gpointer data);
static void toggleColumnVisibility(GtkMenuItem *item, gpointer data);
GtkTreeView *view;
std::string name; // Used to save settings
bool padding;
int count;
int visibleColumns;
GtkMenu *menu;
GType *gtypes;
hash_map<std::string, GtkWidget*> colMenuItems;
typedef hash_map<std::string, Column> ColMap;
typedef hash_map<int, std::string> SortedColMap;
typedef ColMap::iterator ColIter;
typedef SortedColMap::iterator SortedColIter;
ColMap columns;
SortedColMap sortedColumns;
ColMap hiddenColumns;
SortedColMap sortedHiddenColumns;
};
#else
class TreeView;
#endif
|