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 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
#include "multi_view.h"
#define HORIZONTAL_LAYOUT_ITEM_WIDTH 200
#define VERTICAL_LAYOUT_ITEM_WIDTH 100
MultiView::MultiView(bool tree_view, bool icon_view)
: Gtk::VBox(false, 0), _tree_view(0), _icon_view(0)
{
if (tree_view)
{
_tree_view= Gtk::manage(new Gtk::TreeView());
pack_start(*_tree_view, false, false);
_tree_view->signal_row_activated().connect(sigc::mem_fun(this, &MultiView::tree_row_activated));
_tree_view->signal_button_release_event().
connect_notify(sigc::mem_fun(*this, &MultiView::tree_button_release_event));
_selection = _tree_view->get_selection();
_selection->signal_changed().connect(sigc::mem_fun(this, &MultiView::tree_selection_changed));
//TODO: There was a possible leak when connecting signal by _tree_view->get_selection()->signal_changed().connect(sigc::mem_fun(this, &MultiView::tree_selection_changed));
//TODO: Check if it still leaks after selection is moved to explicit member variable
//TODO: Try to disconnect signal in dtor
}
if (icon_view)
{
_icon_view= Gtk::manage(new EditableIconView());
pack_start(*_icon_view, false, false);
_icon_view->set_orientation(Gtk::ORIENTATION_HORIZONTAL);
_icon_view->set_selection_mode(Gtk::SELECTION_MULTIPLE);
_icon_view->set_item_width(HORIZONTAL_LAYOUT_ITEM_WIDTH);
_icon_view->set_row_spacing(0);
_icon_view->signal_item_activated().connect(sigc::mem_fun(this, &MultiView::icon_activated));
_icon_view->signal_button_release_event().
connect_notify(sigc::mem_fun(*this, &MultiView::icon_button_release_event));
_icon_view->signal_selection_changed().connect(sigc::mem_fun(this, &MultiView::icon_selection_changed));
}
if (tree_view)
//_tree_view->show();
set_icon_mode(false);
else if (icon_view)
set_icon_mode(true);
//_icon_view->show();
}
MultiView::~MultiView()
{
}
void MultiView::set_icon_mode(bool flag, bool horizontal_icons)
{
if (_tree_view && _icon_view)
{
if (flag)
{
_tree_view->hide();
_icon_view->show();
_icon_view->set_orientation(horizontal_icons ? Gtk::ORIENTATION_HORIZONTAL : Gtk::ORIENTATION_VERTICAL);
if (horizontal_icons)
_icon_view->set_item_width(HORIZONTAL_LAYOUT_ITEM_WIDTH);
else
_icon_view->set_item_width(VERTICAL_LAYOUT_ITEM_WIDTH);
}
else
{
_tree_view->show();
_icon_view->hide();
}
}
else if (_icon_view)
_icon_view->set_orientation(horizontal_icons ? Gtk::ORIENTATION_HORIZONTAL : Gtk::ORIENTATION_VERTICAL);
}
void MultiView::set_tree_model(const Glib::RefPtr<TreeModelWrapper> &model)
{
_tv_model= model;
if (_tree_view)
_tree_view->set_model(model);
}
void MultiView::set_icon_model(const Glib::RefPtr<TreeModelWrapper> &model)
{
_iv_model= model;
if (_icon_view)
_icon_view->set_model(model);
}
void MultiView::unset_models()
{
if (_icon_view)
_icon_view->unset_model();
if (_tree_view)
_tree_view->unset_model();
}
void MultiView::select_node(const bec::NodeId& node)
{
if (!node.is_valid())
{
if (_tree_view)
_tree_view->get_selection()->unselect_all();
if (_icon_view)
_icon_view->unselect_all();
return;
}
Gtk::TreeModel::Path path = node2path(node);
if (_tree_view)
_tree_view->set_cursor(path);
if (_icon_view)
_icon_view->select_path(path);
}
void MultiView::refresh()
{
if (_tree_view)
{
bec::ListModel* m = _tv_model->get_be_model();
_tv_model->set_be_model(0);
_tree_view->unset_model();
_tree_view->set_model(_tv_model);
_tv_model->set_be_model(m);
//_model->refresh(); // TODO: this call is useless as OverviewBE::refresh is empty/commented out
_tree_view->unset_model();
_tree_view->set_model(_tv_model);
}
if (_icon_view)
{
_icon_view->set_model(Glib::RefPtr<ListModelWrapper>());
_icon_view->set_model(_iv_model);
}
}
void MultiView::tree_row_activated(const Gtk::TreeModel::Path &path,
const Gtk::TreeViewColumn *column)
{
_activate_item(path);
}
void MultiView::icon_activated(const Gtk::TreeModel::Path &path)
{
_activate_item(path);
}
void MultiView::icon_button_release_event(GdkEventButton* event)
{
if ( GDK_BUTTON_RELEASE == event->type && 3 == event->button )
{
Gtk::TreeModel::Path path;
if (_icon_view->get_item_at_pos(event->x, event->y, path))
_icon_view->select_path(path);
std::vector<Gtk::TreeModel::Path> selected_items = _icon_view->get_selected_items();
if ( selected_items.size() > 0 )
{
_popup_menu.emit(selected_items[0], event->time);
return;
}
_popup_menu.emit(Gtk::TreeModel::Path(), event->time);
}
}
void MultiView::tree_button_release_event(GdkEventButton* event)
{
if ( GDK_BUTTON_RELEASE == event->type && 3 == event->button )
{
Glib::RefPtr<Gtk::TreeView::Selection> selection= _tree_view->get_selection();
if ( selection->count_selected_rows() > 0 )
{
std::vector<Gtk::TreeModel::Path> selected= selection->get_selected_rows();
_popup_menu.emit(selected[0], event->time);
}
_popup_menu.emit(Gtk::TreeModel::Path(), event->time);
}
}
void MultiView::on_selection_changed(const std::vector<bec::NodeId>& sel)
{}
void MultiView::icon_selection_changed()
{
const std::vector<Gtk::TreeModel::Path> paths = _icon_view->get_selected_items();
std::vector<bec::NodeId> nodes;
const int paths_size = paths.size();
for ( int i = 0; i < paths_size; ++i )
nodes.push_back(_iv_model->get_node_for_path(paths[i]));
on_selection_changed(nodes);
_selection_changed.emit(nodes);
}
void MultiView::tree_selection_changed()
{
const std::vector<Gtk::TreeModel::Path> paths = _tree_view->get_selection()->get_selected_rows();
std::vector<bec::NodeId> nodes;
const int paths_size = paths.size();
for ( int i = 0; i < paths_size; ++i )
nodes.push_back(_tv_model->get_node_for_path(paths[i]));
on_selection_changed(nodes);
_selection_changed.emit(nodes);
}
Gtk::TreeModel::Path MultiView::get_selected()
{
if (_icon_view && _icon_view->is_visible())
{
std::vector<Gtk::TreeModel::Path> selected_items = _icon_view->get_selected_items();
if ( selected_items.size() > 0 )
return selected_items[0];
}
if (_tree_view && _tree_view->is_visible())
{
Glib::RefPtr<Gtk::TreeView::Selection> selection= _tree_view->get_selection();
if ( selection->count_selected_rows() > 0 )
{
std::vector<Gtk::TreeModel::Path> selected= selection->get_selected_rows();
return selected[0];
}
}
return Gtk::TreeModel::Path();
}
|