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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
/*
* Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
*
* 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; version 2 of the
* License.
*
* 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 St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef _LF_TREENODEVIEW_H_
#define _LF_TREENODEVIEW_H_
#include <mforms/mforms.h>
#include "lf_view.h"
namespace mforms {
namespace gtk {
struct TreeNodeDataRef
{
TreeNodeData *_data;
TreeNodeDataRef()
: _data(0)
{
}
TreeNodeDataRef(TreeNodeData *data)
: _data(data)
{
if (_data) _data->retain();
}
TreeNodeDataRef(const TreeNodeDataRef &other)
: _data(other._data)
{
if (_data) _data->retain();
}
~TreeNodeDataRef()
{
if (_data) _data->release();
}
TreeNodeDataRef& operator= (const TreeNodeDataRef &other)
{
if (_data != other._data)
{
if (_data) _data->release();
_data = other._data;
if (_data) _data->retain();
}
return *this;
}
};
class TreeNodeViewImpl : public ViewImpl
{
friend class RootTreeNodeImpl;
friend class TreeNodeImpl;
private:
class ColumnRecord : public Gtk::TreeModelColumnRecord
{
template<class C>
Gtk::TreeModelColumn<C> *add_model_column()
{
Gtk::TreeModelColumn<C> *col = new Gtk::TreeModelColumn<C>();
columns.push_back(col);
add(*col);
return col;
}
void on_cell_editing_started(Gtk::CellEditable* e, const Glib::ustring &path);
bool on_focus_out(GdkEventFocus *event, Gtk::Entry *e);
public:
std::vector<Gtk::TreeModelColumnBase*> columns;
Gtk::TreeModelColumn<std::string> _tag_column;
Gtk::TreeModelColumn<TreeNodeDataRef> _data_column;
std::vector<int> column_value_index;
std::vector<int> column_attr_index;
template<class C>
const Gtk::TreeModelColumn<C> &get(int column)
{
Gtk::TreeModelColumnBase* c= columns[column];
return *static_cast<Gtk::TreeModelColumn<C>*>(c);
}
virtual ~ColumnRecord();
void add_tag_column();
void add_data_column();
Gtk::TreeModelColumn<std::string>& tag_column();
Gtk::TreeModelColumn<TreeNodeDataRef>& data_column();
int add_string(Gtk::TreeView *tree, const std::string &title, bool editable, bool attr, bool with_icon, bool align_right = false);
int add_integer(Gtk::TreeView *tree, const std::string &title, bool editable, bool attr);
int add_long_integer(Gtk::TreeView *tree, const std::string &title, bool editable, bool attr);
int add_float(Gtk::TreeView *tree, const std::string &title, bool editable, bool attr);
int add_check(Gtk::TreeView *tree, const std::string &title, bool editable, bool attr);
int add_tri_check(Gtk::TreeView *tree, const std::string &title, bool editable, bool attr);
void format_tri_check(Gtk::CellRenderer* cell, const Gtk::TreeIter& iter, const Gtk::TreeModelColumn<int>& column);
};
bool _is_drag_source;
ColumnRecord _columns;
Gtk::ScrolledWindow _swin;
Gtk::TreeView _tree;
sigc::connection _conn;
int _row_height;
bool _flat_list;
bool _tagmap_enabled;
bool _drag_source_enabled;
Gtk::TreePath _overlayed_row;
std::vector<Cairo::RefPtr<Cairo::ImageSurface> > _overlay_icons;
int _hovering_overlay;
int _clicking_overlay;
bool _mouse_inside;
GdkEventButton *_org_event;
int _drag_button;
int _drag_start_x;
int _drag_start_y;
bool _drag_in_progress;
Glib::RefPtr<Gtk::TreeStore> _tree_store;
Glib::RefPtr<Gtk::TreeModelSort> _sort_model;
std::map<std::string, Glib::RefPtr<Gdk::Pixbuf> > _pixbufs;
std::map<std::string, Gtk::TreeRowReference> _tagmap;
mforms::TreeNodeRef _root_node;
mforms::TreeNodeRef find_node_at_row(const Gtk::TreeModel::Children &trow, int &c, int row);
Gtk::TreeView *tree_view() { return &_tree; }
virtual Gtk::Widget *get_outer() const { return &(const_cast<Gtk::ScrolledWindow&>(_swin)); }
virtual Gtk::Widget *get_inner() const { return &(const_cast<Gtk::TreeView&>(_tree)); }
TreeNodeViewImpl(TreeNodeView *self, mforms::TreeOptions opts);
~TreeNodeViewImpl();
void string_edited(const Glib::ustring &path, const Glib::ustring &new_text, int column);
void toggle_edited(const Glib::ustring &path, int column);
void on_activated(const Gtk::TreeModel::Path&, Gtk::TreeViewColumn*);
void on_will_expand(const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path);
void on_collapsed(const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path);
void on_realize();
bool on_header_button_event(GdkEventButton *ev, int);
bool on_key_release(GdkEventKey *ev);
bool on_button_event(GdkEventButton *ev);
bool on_button_release(GdkEventButton* ev);
bool on_motion_notify(GdkEventMotion* ev);
bool on_expose_event(GdkEventExpose *ev);
bool on_enter_notify(GdkEventCrossing *ev);
bool on_leave_notify(GdkEventCrossing *ev);
void slot_drag_end(const Glib::RefPtr<Gdk::DragContext> &context);
bool slot_drag_failed(const Glib::RefPtr<Gdk::DragContext> &context,Gtk::DragResult result);
void set_allow_sorting(bool flag);
int add_column(TreeColumnType type, const std::string &name, int initial_width, bool editable, bool attributed);
void end_columns();
static bool create(TreeNodeView *self, mforms::TreeOptions opt);
static int add_column(TreeNodeView *self, TreeColumnType type, const std::string &name, int width, bool editable, bool attr);
static void end_columns(TreeNodeView *self);
static void clear(TreeNodeView *self);
static TreeNodeRef root_node(TreeNodeView *self);
static TreeNodeRef get_selected_node(TreeNodeView *self);
static std::list<TreeNodeRef> get_selection(TreeNodeView *self);
static void set_selected(TreeNodeView* self, TreeNodeRef node, bool flag);
static TreeSelectionMode get_selection_mode(TreeNodeView *self);
static void set_selection_mode(TreeNodeView *self, TreeSelectionMode mode);
static void clear_selection(TreeNodeView *self);
static int row_for_node(TreeNodeView *self, TreeNodeRef node);
static TreeNodeRef node_at_row(TreeNodeView *self, int row);
static TreeNodeRef node_with_tag(TreeNodeView *self, const std::string &tag);
static void set_row_height(TreeNodeView *self, int height);
static void set_allow_sorting(TreeNodeView* self, bool flag);
static void freeze_refresh(TreeNodeView* self, bool flag);
static void set_column_visible(TreeNodeView* self, int column, bool flag);
static bool get_column_visible(TreeNodeView* self, int column);
static void set_column_title(TreeNodeView* self, int column, const std::string &title);
static void set_column_width(TreeNodeView* self, int column, int width);
static int get_column_width(TreeNodeView* self, int column);
static TreeNodeRef node_at_position(TreeNodeView* self, base::Point position);
Gtk::TreeModel::iterator to_list_iter(const Gtk::TreeModel::iterator &it);
Gtk::TreeModel::Path to_list_path(const Gtk::TreeModel::Path &path);
Gtk::TreeModel::iterator to_sort_iter(const Gtk::TreeModel::iterator &it);
Gtk::TreeModel::Path to_sort_path(const Gtk::TreeModel::Path &path);
void header_clicked(Gtk::TreeModelColumnBase*, Gtk::TreeViewColumn*);
virtual void set_back_color(const std::string &color);
protected:
mforms::DropPosition get_drop_position();
public:
static void init();
int index_for_column_attr(int i) { return _columns.column_attr_index[i]; }
int index_for_column(int i) { return _columns.column_value_index[i]; }
Glib::RefPtr<Gtk::TreeStore> tree_store() { return _tree_store; }
TreeNodeView* get_owner();
};
}
}
#endif
|