Add missing files.
git-svn-id: svn://localhost/ardour2/branches/3.0@10342 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
db429c2362
commit
1006458750
233
gtk2_ardour/visibility_group.cc
Normal file
233
gtk2_ardour/visibility_group.cc
Normal file
@ -0,0 +1,233 @@
|
||||
/*
|
||||
Copyright (C) 2011 Paul Davis
|
||||
Author: Carl Hetherington <cth@carlh.net>
|
||||
|
||||
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
*/
|
||||
|
||||
#include <gtkmm/menu.h>
|
||||
#include <gtkmm/menushell.h>
|
||||
#include <gtkmm/treeview.h>
|
||||
#include "pbd/xml++.h"
|
||||
#include "visibility_group.h"
|
||||
|
||||
#include "i18n.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
VisibilityGroup::VisibilityGroup (std::string const & name)
|
||||
: _xml_property_name (name)
|
||||
, _ignore_list_view_change (false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/** Add a widget to the group.
|
||||
* @param widget The widget.
|
||||
* @param id Some single-word ID to be used for the state of this member in XML.
|
||||
* @param name User-visible name for the widget.
|
||||
* @param visible true to default to visible, otherwise false.
|
||||
*/
|
||||
|
||||
void
|
||||
VisibilityGroup::add (Gtk::Widget* widget, string const & id, string const & name, bool visible)
|
||||
{
|
||||
Member m;
|
||||
m.widget = widget;
|
||||
m.id = id;
|
||||
m.name = name;
|
||||
m.visible = visible;
|
||||
|
||||
_members.push_back (m);
|
||||
}
|
||||
|
||||
/** Pop up a menu (on right-click) to configure visibility of members */
|
||||
bool
|
||||
VisibilityGroup::button_press_event (GdkEventButton* ev)
|
||||
{
|
||||
if (ev->button != 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
menu()->popup (1, ev->time);
|
||||
return true;
|
||||
}
|
||||
|
||||
Gtk::Menu*
|
||||
VisibilityGroup::menu ()
|
||||
{
|
||||
using namespace Gtk::Menu_Helpers;
|
||||
|
||||
Gtk::Menu* m = Gtk::manage (new Gtk::Menu);
|
||||
MenuList& items = m->items ();
|
||||
|
||||
for (vector<Member>::iterator i = _members.begin(); i != _members.end(); ++i) {
|
||||
items.push_back (CheckMenuElem (i->name));
|
||||
Gtk::CheckMenuItem* j = dynamic_cast<Gtk::CheckMenuItem*> (&items.back ());
|
||||
j->set_active (i->visible);
|
||||
j->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &VisibilityGroup::toggle), i));
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/** Update visible consequences of any changes to our _members vector */
|
||||
void
|
||||
VisibilityGroup::update ()
|
||||
{
|
||||
for (vector<Member>::iterator i = _members.begin(); i != _members.end(); ++i) {
|
||||
if (i->widget) {
|
||||
if (i->visible) {
|
||||
cout << "VG show " << i->name << "\n";
|
||||
i->widget->show ();
|
||||
} else {
|
||||
cout << "VG hide " << i->name << "\n";
|
||||
i->widget->hide ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_list_view ();
|
||||
|
||||
VisibilityChanged (); /* EMIT SIGNAL */
|
||||
}
|
||||
|
||||
void
|
||||
VisibilityGroup::toggle (vector<Member>::iterator m)
|
||||
{
|
||||
m->visible = !m->visible;
|
||||
update ();
|
||||
}
|
||||
|
||||
void
|
||||
VisibilityGroup::set_state (XMLNode const & node)
|
||||
{
|
||||
XMLProperty const * p = node.property (_xml_property_name);
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
|
||||
set_state (p->value ());
|
||||
}
|
||||
|
||||
void
|
||||
VisibilityGroup::set_state (string v)
|
||||
{
|
||||
for (vector<Member>::iterator i = _members.begin(); i != _members.end(); ++i) {
|
||||
i->visible = false;
|
||||
}
|
||||
|
||||
do {
|
||||
string::size_type const comma = v.find_first_of (',');
|
||||
string segment = v.substr (0, comma);
|
||||
|
||||
for (vector<Member>::iterator i = _members.begin(); i != _members.end(); ++i) {
|
||||
if (segment == i->id) {
|
||||
i->visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (comma == string::npos) {
|
||||
break;
|
||||
}
|
||||
|
||||
v = v.substr (comma + 1);
|
||||
|
||||
} while (1);
|
||||
|
||||
update ();
|
||||
}
|
||||
|
||||
string
|
||||
VisibilityGroup::get_state_name () const
|
||||
{
|
||||
return _xml_property_name;
|
||||
}
|
||||
|
||||
string
|
||||
VisibilityGroup::get_state_value () const
|
||||
{
|
||||
string result;
|
||||
for (vector<Member>::const_iterator i = _members.begin(); i != _members.end(); ++i) {
|
||||
if (i->visible) {
|
||||
if (!result.empty ()) {
|
||||
result += ',';
|
||||
}
|
||||
result += i->id;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
VisibilityGroup::update_list_view ()
|
||||
{
|
||||
if (!_model) {
|
||||
return;
|
||||
}
|
||||
|
||||
_ignore_list_view_change = true;
|
||||
|
||||
_model->clear ();
|
||||
|
||||
for (vector<Member>::iterator i = _members.begin(); i != _members.end(); ++i) {
|
||||
Gtk::TreeModel::iterator j = _model->append ();
|
||||
Gtk::TreeModel::Row row = *j;
|
||||
row[_model_columns._visible] = i->visible;
|
||||
row[_model_columns._name] = i->name;
|
||||
row[_model_columns._iterator] = i;
|
||||
}
|
||||
|
||||
_ignore_list_view_change = false;
|
||||
}
|
||||
|
||||
Gtk::Widget *
|
||||
VisibilityGroup::list_view ()
|
||||
{
|
||||
_model = Gtk::ListStore::create (_model_columns);
|
||||
|
||||
update_list_view ();
|
||||
|
||||
Gtk::TreeView* v = Gtk::manage (new Gtk::TreeView (_model));
|
||||
v->set_headers_visible (false);
|
||||
v->append_column (_(""), _model_columns._visible);
|
||||
v->append_column (_(""), _model_columns._name);
|
||||
|
||||
Gtk::CellRendererToggle* visible_cell = dynamic_cast<Gtk::CellRendererToggle*> (v->get_column_cell_renderer (0));
|
||||
visible_cell->property_activatable() = true;
|
||||
visible_cell->signal_toggled().connect (sigc::mem_fun (*this, &VisibilityGroup::list_view_visible_changed));
|
||||
return v;
|
||||
}
|
||||
|
||||
void
|
||||
VisibilityGroup::list_view_visible_changed (string const & path)
|
||||
{
|
||||
if (_ignore_list_view_change) {
|
||||
return;
|
||||
}
|
||||
|
||||
Gtk::TreeModel::iterator i = _model->get_iter (path);
|
||||
if (!i) {
|
||||
return;
|
||||
}
|
||||
|
||||
vector<Member>::iterator j = (*i)[_model_columns._iterator];
|
||||
j->visible = !j->visible;
|
||||
(*i)[_model_columns._visible] = j->visible;
|
||||
|
||||
update ();
|
||||
}
|
85
gtk2_ardour/visibility_group.h
Normal file
85
gtk2_ardour/visibility_group.h
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
Copyright (C) 2011 Paul Davis
|
||||
Author: Carl Hetherington <cth@carlh.net>
|
||||
|
||||
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef __ardour_visibility_group__
|
||||
#define __ardour_visibility_group__
|
||||
|
||||
#include <gtkmm/liststore.h>
|
||||
#include "pbd/signals.h"
|
||||
|
||||
class XMLNode;
|
||||
class XMLProperty;
|
||||
|
||||
/** A class to manage a group of widgets where the visibility of each
|
||||
* can be configured by the user. The class can generate a menu to
|
||||
* set up visibility, and save and restore visibility state to XML.
|
||||
*/
|
||||
|
||||
class VisibilityGroup
|
||||
{
|
||||
public:
|
||||
VisibilityGroup (std::string const &);
|
||||
|
||||
void add (Gtk::Widget *, std::string const &, std::string const &, bool visible = true);
|
||||
Gtk::Menu* menu ();
|
||||
Gtk::Widget* list_view ();
|
||||
bool button_press_event (GdkEventButton *);
|
||||
void update ();
|
||||
void set_state (XMLNode const &);
|
||||
void set_state (std::string);
|
||||
std::string get_state_name () const;
|
||||
std::string get_state_value () const;
|
||||
|
||||
PBD::Signal0<void> VisibilityChanged;
|
||||
|
||||
private:
|
||||
|
||||
struct Member {
|
||||
Gtk::Widget* widget;
|
||||
std::string id;
|
||||
std::string name;
|
||||
bool visible;
|
||||
};
|
||||
|
||||
class ModelColumns : public Gtk::TreeModelColumnRecord {
|
||||
public:
|
||||
ModelColumns () {
|
||||
add (_visible);
|
||||
add (_name);
|
||||
add (_iterator);
|
||||
}
|
||||
|
||||
Gtk::TreeModelColumn<bool> _visible;
|
||||
Gtk::TreeModelColumn<std::string> _name;
|
||||
Gtk::TreeModelColumn<std::vector<Member>::iterator> _iterator;
|
||||
};
|
||||
|
||||
void toggle (std::vector<Member>::iterator);
|
||||
void list_view_visible_changed (std::string const &);
|
||||
void update_list_view ();
|
||||
|
||||
std::vector<Member> _members;
|
||||
std::string _xml_property_name;
|
||||
ModelColumns _model_columns;
|
||||
Glib::RefPtr<Gtk::ListStore> _model;
|
||||
bool _ignore_list_view_change;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user