summaryrefslogtreecommitdiff
path: root/src/gtk
diff options
context:
space:
mode:
authorDaniel Burrows <dburrows@debian.org>2010-05-11 22:00:20 -0700
committerDaniel Burrows <dburrows@debian.org>2010-05-11 22:00:20 -0700
commitce2d214a5ccd6e235c1be78abc019d1a5a6264c5 (patch)
tree09eb1defbd689ba08ba4bd208814cb4ac1cda5aa /src/gtk
parent2c48ec95f1f4263355facf2afaaf25b3e9d68f1d (diff)
downloadaptitude-ce2d214a5ccd6e235c1be78abc019d1a5a6264c5.tar.gz
Add an interface that abstracts over a view displaying exactly one tab at a time.
This will be needed by the main window, so it can update menu items appropriately and so on.
Diffstat (limited to 'src/gtk')
-rw-r--r--src/gtk/toplevel/Makefile.am3
-rw-r--r--src/gtk/toplevel/SConscript3
-rw-r--r--src/gtk/toplevel/tabs_notebook.cc52
-rw-r--r--src/gtk/toplevel/tabs_notebook.h10
-rw-r--r--src/gtk/toplevel/view.h62
5 files changed, 117 insertions, 13 deletions
diff --git a/src/gtk/toplevel/Makefile.am b/src/gtk/toplevel/Makefile.am
index a96b381c..49bfe829 100644
--- a/src/gtk/toplevel/Makefile.am
+++ b/src/gtk/toplevel/Makefile.am
@@ -9,4 +9,5 @@ libgtk_toplevel_a_SOURCES = \
area.h \
sidebar.h \
tabs_notebook.cc \
- tabs_notebook.h \ No newline at end of file
+ tabs_notebook.h \
+ view.h \ No newline at end of file
diff --git a/src/gtk/toplevel/SConscript b/src/gtk/toplevel/SConscript
index 5e732df9..5a443275 100644
--- a/src/gtk/toplevel/SConscript
+++ b/src/gtk/toplevel/SConscript
@@ -5,7 +5,8 @@ toplevel_srcs = map(File, [
'area.h',
'sidebar.h',
'tabs_notebook.cc',
- 'tabs_notebook.h'
+ 'tabs_notebook.h',
+ 'view.h'
])
srcs = toplevel_srcs
diff --git a/src/gtk/toplevel/tabs_notebook.cc b/src/gtk/toplevel/tabs_notebook.cc
index cf20441c..eeda019d 100644
--- a/src/gtk/toplevel/tabs_notebook.cc
+++ b/src/gtk/toplevel/tabs_notebook.cc
@@ -24,6 +24,7 @@
#include <loggers.h>
#include <gtk/util/property.h>
+#include <boost/make_shared.hpp>
#include <boost/weak_ptr.hpp>
#include <gtkmm.h>
@@ -31,6 +32,7 @@
using aptitude::Loggers;
using aptitude::util::dynamic_set;
using aptitude::util::enumerator;
+using boost::make_shared;
using boost::shared_ptr;
using boost::weak_ptr;
@@ -68,15 +70,17 @@ namespace gui
// switch.
shared_ptr<tab_display_info> last_active_tab;
- /** \brief Get the tab of the currently selected page, or NULL
- * if nothing is selected (or if the selected page has no
- * tab, but that should be impossible).
- */
- shared_ptr<tab_display_info> get_current_tab();
+ sigc::signal<void, shared_ptr<tab_display_info> > signal_active_tab_changed;
public:
tabs_notebook();
+ /** \brief Register a slot to be invoked when the currently
+ * displayed tab changes.
+ */
+ sigc::connection
+ connect_active_tab_changed(const sigc::slot<void, shared_ptr<tab_display_info> > &slot);
+
/** \brief Set the tabs shown by this tab object.
*
* Closes all the tabs currently displayed, then adds the new
@@ -84,6 +88,12 @@ namespace gui
*/
void set_tabs(const shared_ptr<dynamic_set<shared_ptr<tab_display_info> > > &tabs);
+ /** \brief Get the tab of the currently selected page, or NULL
+ * if nothing is selected (or if the selected page has no
+ * tab, but that should be impossible).
+ */
+ shared_ptr<tab_display_info> get_current_tab();
+
private:
void handle_inserted(const shared_ptr<tab_display_info> &tab);
void handle_removed(const shared_ptr<tab_display_info> &tab);
@@ -269,15 +279,43 @@ namespace gui
last_active_tab = new_tab;
new_tab->set_active(true);
+ signal_active_tab_changed(new_tab);
+ }
+
+ sigc::connection
+ tabs_notebook::connect_active_tab_changed(const sigc::slot<void, shared_ptr<tab_display_info> > &slot)
+ {
+ return signal_active_tab_changed.connect(slot);
}
}
- Gtk::Widget *
+ class tabs_notebook_view : public view
+ {
+ // Awkwardly, this could be zapped at any time. Any better way
+ // to do this?
+ tabs_notebook *notebook;
+
+ public:
+ tabs_notebook_view(tabs_notebook *_notebook)
+ : notebook(_notebook)
+ {
+ }
+
+ Gtk::Widget *get_widget() { return notebook; }
+ shared_ptr<tab_display_info> get_active_tab() { return notebook->get_current_tab(); }
+ sigc::connection
+ connect_active_tab_changed(const sigc::slot<void, shared_ptr<tab_display_info> > &slot)
+ {
+ return notebook->connect_active_tab_changed(slot);
+ }
+ };
+
+ shared_ptr<view>
create_tabs_notebook(const shared_ptr<dynamic_set<shared_ptr<tab_display_info> > > &tabs)
{
tabs_notebook *rval = new tabs_notebook;
rval->set_tabs(tabs);
- return rval;
+ return make_shared<tabs_notebook_view>(rval);
}
}
}
diff --git a/src/gtk/toplevel/tabs_notebook.h b/src/gtk/toplevel/tabs_notebook.h
index a9c5a670..478fceff 100644
--- a/src/gtk/toplevel/tabs_notebook.h
+++ b/src/gtk/toplevel/tabs_notebook.h
@@ -22,6 +22,7 @@
#define TOPLEVEL_TABS_NOTEBOOK_H
#include "area.h"
+#include "view.h"
#include <boost/shared_ptr.hpp>
@@ -36,10 +37,11 @@ namespace gui
* assumes that they have a floating reference and sinks that
* reference using manage().
*/
- Gtk::Widget *create_tabs_notebook(const boost::shared_ptr<
- aptitude::util::dynamic_set<
- boost::shared_ptr<
- tab_display_info> > > &tabs);
+ boost::shared_ptr<view>
+ create_tabs_notebook(const boost::shared_ptr<
+ aptitude::util::dynamic_set<
+ boost::shared_ptr<
+ tab_display_info> > > &tabs);
}
}
diff --git a/src/gtk/toplevel/view.h b/src/gtk/toplevel/view.h
new file mode 100644
index 00000000..fdbe76e9
--- /dev/null
+++ b/src/gtk/toplevel/view.h
@@ -0,0 +1,62 @@
+/** \file view.h */ // -*-c++-*-
+
+// Copyright (C) 2010 Daniel Burrows
+//
+// 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; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+
+#ifndef APTITUDE_GTK_TOPLEVEL_VIEW_H
+#define APTITUDE_GTK_TOPLEVEL_VIEW_H
+
+namespace gui
+{
+ namespace toplevel
+ {
+ class tab_info;
+
+ /** \brief Interface providing information about a multiplexing
+ * view onto a set of tabs, where only one tab can be displayed
+ * at a time.
+ */
+ class view
+ {
+ public:
+ /** \brief Retrieve the top-level widget of the view.
+ *
+ * The view object does not own this widget; the widget could
+ * be destroyed while the view is still alive.
+ */
+ virtual Gtk::Widget *get_widget() = 0;
+
+ /** \brief Retrieve the currently displayed tab.
+ *
+ * \return the currently displayed tab, or \b NULL if no tab is
+ * being displayed.
+ */
+ virtual boost::shared_ptr<tab_display_info> get_active_tab() = 0;
+
+ /** \brief Register a slot to be invoked when the currently
+ * displayed tab changes.
+ *
+ * The tab_info passed to the slot is the newly active tab, or
+ * \b NULL if no tab is being shown now.
+ */
+ virtual sigc::connection connect_active_tab_changed(const sigc::slot<void, boost::shared_ptr<tab_display_info> > &slot) = 0;
+ };
+ }
+}
+
+#endif // APTITUDE_GTK_TOPLEVEL_VIEW_H