summaryrefslogtreecommitdiffstats
path: root/chrome/common/gtk_tree.h
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-12 02:49:34 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-12 02:49:34 +0000
commit15f1a32e4d437f10fed7bc056d8877fb7c9d7d21 (patch)
treee1aa223f7b19b151c7e0755c1468f225a0f96577 /chrome/common/gtk_tree.h
parent14239acc00731e94736ac62e80fc6b17c31ea131 (diff)
downloadchromium_src-15f1a32e4d437f10fed7bc056d8877fb7c9d7d21.zip
chromium_src-15f1a32e4d437f10fed7bc056d8877fb7c9d7d21.tar.gz
chromium_src-15f1a32e4d437f10fed7bc056d8877fb7c9d7d21.tar.bz2
Move common Gtk TreeModel handling code into gtk_tree::ModelAdapter.
Also add gtk_tree::SelectAndFocusRowNum. BUG=none TEST=cookie manage, bookmark editor, url picker, search engine manager should all still work. Review URL: http://codereview.chromium.org/165359 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23145 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/gtk_tree.h')
-rw-r--r--chrome/common/gtk_tree.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/chrome/common/gtk_tree.h b/chrome/common/gtk_tree.h
index 8a6f694..8caa64c 100644
--- a/chrome/common/gtk_tree.h
+++ b/chrome/common/gtk_tree.h
@@ -7,6 +7,11 @@
#include <gtk/gtk.h>
+#include "app/table_model_observer.h"
+#include "base/basictypes.h"
+
+class TableModel;
+
namespace gtk_tree {
// Get the row number corresponding to |path|.
@@ -20,6 +25,54 @@ gint GetRowNumForIter(GtkTreeModel* model, GtkTreeIter* iter);
gint GetTreeSortChildRowNumForPath(GtkTreeModel* sort_model,
GtkTreePath* sort_path);
+// Select the given row by number.
+void SelectAndFocusRowNum(int row, GtkTreeView* tree_view);
+
+// A helper class for populating a GtkListStore from a TableModel.
+class ModelAdapter : public TableModelObserver {
+ public:
+ class Delegate {
+ public:
+ // Should fill in the column and row.
+ virtual void SetColumnValues(int row, GtkTreeIter* iter) = 0;
+
+ // Called after any change to the TableModel. Overriding optional.
+ virtual void OnAnyModelUpdate() {}
+
+ // When the TableModel has been completely changed, called by OnModelChanged
+ // after clearing the list store. Can be overriden by the delegate if it
+ // needs to do extra initialization before the list store is populated.
+ virtual void OnModelChanged() {}
+ };
+
+ // |table_model| may be NULL.
+ explicit ModelAdapter(Delegate* delegate, GtkListStore* list_store,
+ TableModel* table_model);
+ virtual ~ModelAdapter() {}
+
+ // Replace the TableModel with a different one. If the list store currenty
+ // has items this would cause weirdness, so this should generally only be
+ // called during the Delegate's OnModelChanged call, or if the adapter was
+ // created with a NULL |table_model|.
+ void SetModel(TableModel* table_model);
+
+ // TableModelObserver implementation.
+ virtual void OnModelChanged();
+ virtual void OnItemsChanged(int start, int length);
+ virtual void OnItemsAdded(int start, int length);
+ virtual void OnItemsRemoved(int start, int length);
+
+ private:
+ // Add the values from |row| of the TableModel.
+ void AddNodeToList(int row);
+
+ Delegate* delegate_;
+ GtkListStore* list_store_;
+ TableModel* table_model_;
+
+ DISALLOW_COPY_AND_ASSIGN(ModelAdapter);
+};
+
} // namespace gtk_tree
#endif // CHROME_COMMON_GTK_TREE_H_