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-11-11 23:07:58 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-11 23:07:58 +0000
commit42062e78622add4b84f872707530670d4894d5c9 (patch)
tree57555878cc6583012dbc2db4c3842282d1ec6ac5 /chrome/common/gtk_tree.h
parentdda7d9c65875b7650f36fa8c2a03b5813dc3ecd3 (diff)
downloadchromium_src-42062e78622add4b84f872707530670d4894d5c9.zip
chromium_src-42062e78622add4b84f872707530670d4894d5c9.tar.gz
chromium_src-42062e78622add4b84f872707530670d4894d5c9.tar.bz2
Linux: Convert Cookies options page from a list into a tree.
Add gtk_tree::TreeAdapter class. BUG=26713 TEST=compare behavior to windows impl Review URL: http://codereview.chromium.org/371079 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31732 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/gtk_tree.h')
-rw-r--r--chrome/common/gtk_tree.h81
1 files changed, 79 insertions, 2 deletions
diff --git a/chrome/common/gtk_tree.h b/chrome/common/gtk_tree.h
index af9aa88..b0759f2 100644
--- a/chrome/common/gtk_tree.h
+++ b/chrome/common/gtk_tree.h
@@ -6,8 +6,10 @@
#define CHROME_COMMON_GTK_TREE_H_
#include <gtk/gtk.h>
+#include <vector>
#include "app/table_model_observer.h"
+#include "app/tree_model.h"
#include "base/basictypes.h"
class TableModel;
@@ -28,6 +30,12 @@ gint GetTreeSortChildRowNumForPath(GtkTreeModel* sort_model,
// Select the given row by number.
void SelectAndFocusRowNum(int row, GtkTreeView* tree_view);
+// Remove the row and all its children from the |tree_store|. If there is a
+// following row, |iter| will be updated to point to the it and the return value
+// will be true, otherwise the return will be false and |iter| is no longer
+// valid.
+bool RemoveRecursively(GtkTreeStore* tree_store, GtkTreeIter* iter);
+
// A helper class for populating a GtkListStore from a TableModel.
class TableAdapter : public TableModelObserver {
public:
@@ -36,10 +44,11 @@ class TableAdapter : public TableModelObserver {
// Should fill in the column and row.
virtual void SetColumnValues(int row, GtkTreeIter* iter) = 0;
- // Called before any change to the TableModel. Overriding optional.
+ // Called after any change to the TableModel but before the corresponding
+ // change to the GtkListStore.
virtual void OnAnyModelUpdateStart() {}
- // Called after any change to the TableModel. Overriding optional.
+ // Called after any change to the TableModel.
virtual void OnAnyModelUpdate() {}
// When the TableModel has been completely changed, called by OnModelChanged
@@ -76,6 +85,74 @@ class TableAdapter : public TableModelObserver {
DISALLOW_COPY_AND_ASSIGN(TableAdapter);
};
+// A helper class for populating a GtkTreeStore from a TreeModel.
+// TODO(mattm): support SetRootShown(true)
+// TODO(mattm): implement TreeNodeChildrenReordered
+class TreeAdapter : public TreeModelObserver {
+ public:
+ // Column ids for |tree_store_|.
+ enum {
+ COL_ICON,
+ COL_TITLE,
+ COL_NODE_PTR,
+ COL_COUNT,
+ };
+
+ class Delegate {
+ public:
+ // Called after any change to the TreeModel but before the corresponding
+ // change to the GtkTreeStore.
+ virtual void OnAnyModelUpdateStart() {}
+
+ // Called after any change to the GtkTreeStore.
+ virtual void OnAnyModelUpdate() {}
+ };
+
+ TreeAdapter(Delegate* delegate, TreeModel* tree_model);
+ virtual ~TreeAdapter();
+
+ // Populate the tree store from the |tree_model_|.
+ void Init();
+
+ // Return the tree store.
+ GtkTreeStore* tree_store() { return tree_store_; }
+
+ // Get the TreeModelNode corresponding to iter in the tree store.
+ TreeModelNode* GetNode(GtkTreeIter* iter);
+
+ // TreeModelObserver implementation.
+ virtual void TreeNodesAdded(TreeModel* model,
+ TreeModelNode* parent,
+ int start,
+ int count);
+ virtual void TreeNodesRemoved(TreeModel* model,
+ TreeModelNode* parent,
+ int start,
+ int count);
+ virtual void TreeNodeChildrenReordered(TreeModel* model,
+ TreeModelNode* parent);
+ virtual void TreeNodeChanged(TreeModel* model, TreeModelNode* node);
+
+ private:
+ // Fill the tree store values for a given node.
+ void FillRow(GtkTreeIter* iter, TreeModelNode* node);
+
+ // Fill the tree store for a row and all its descendants.
+ void Fill(GtkTreeIter* parent_iter, TreeModelNode* parent_node);
+
+ // Get the GtkTreePath in the tree store for the given node.
+ // The returned path should be freed with gtk_tree_path_free.
+ GtkTreePath* GetTreePath(TreeModelNode* node);
+
+ // Get the GtkTreeIter in the tree store for the given node.
+ bool GetTreeIter(TreeModelNode* node, GtkTreeIter* iter);
+
+ Delegate* delegate_;
+ GtkTreeStore* tree_store_;
+ TreeModel* tree_model_;
+ std::vector<GdkPixbuf*> pixbufs_;
+};
+
} // namespace gtk_tree
#endif // CHROME_COMMON_GTK_TREE_H_