summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authormdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 23:28:10 +0000
committermdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 23:28:10 +0000
commit650e6918651545098d70fc85d37336bca49c74bf (patch)
tree65ba9756282a57c3b1033edbc3c3ae106de1a232 /chrome/common
parent7e9c5769dd8aaa4a72f2d272d17fbe57703cd143 (diff)
downloadchromium_src-650e6918651545098d70fc85d37336bca49c74bf.zip
chromium_src-650e6918651545098d70fc85d37336bca49c74bf.tar.gz
chromium_src-650e6918651545098d70fc85d37336bca49c74bf.tar.bz2
Linux: factor out some shared GTK tree utility code.
BUG=none TEST=none Review URL: http://codereview.chromium.org/160356 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22019 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/gtk_tree_util.cc35
-rw-r--r--chrome/common/gtk_tree_util.h29
2 files changed, 64 insertions, 0 deletions
diff --git a/chrome/common/gtk_tree_util.cc b/chrome/common/gtk_tree_util.cc
new file mode 100644
index 0000000..bc4ed021
--- /dev/null
+++ b/chrome/common/gtk_tree_util.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/gtk_tree_util.h"
+
+#include "base/logging.h"
+
+// static
+gint GtkTreeUtil::GetRowNumForPath(GtkTreePath* path) {
+ gint* indices = gtk_tree_path_get_indices(path);
+ if (!indices) {
+ NOTREACHED();
+ return -1;
+ }
+ return indices[0];
+}
+
+// static
+gint GtkTreeUtil::GetRowNumForIter(GtkTreeModel* model, GtkTreeIter* iter) {
+ GtkTreePath* path = gtk_tree_model_get_path(model, iter);
+ int row = GetRowNumForPath(path);
+ gtk_tree_path_free(path);
+ return row;
+}
+
+// static
+gint GtkTreeUtil::GetTreeSortChildRowNumForPath(GtkTreeModel* sort_model,
+ GtkTreePath* sort_path) {
+ GtkTreePath *child_path = gtk_tree_model_sort_convert_path_to_child_path(
+ GTK_TREE_MODEL_SORT(sort_model), sort_path);
+ int row = GetRowNumForPath(child_path);
+ gtk_tree_path_free(child_path);
+ return row;
+}
diff --git a/chrome/common/gtk_tree_util.h b/chrome/common/gtk_tree_util.h
new file mode 100644
index 0000000..abd9ee6
--- /dev/null
+++ b/chrome/common/gtk_tree_util.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_GTK_TREE_UTIL_H_
+#define CHROME_COMMON_GTK_TREE_UTIL_H_
+
+#include <gtk/gtk.h>
+
+#include "base/basictypes.h"
+
+class GtkTreeUtil {
+ public:
+ // Get the row number corresponding to |path|.
+ static gint GetRowNumForPath(GtkTreePath* path);
+
+ // Get the row number corresponding to |iter|.
+ static gint GetRowNumForIter(GtkTreeModel* model, GtkTreeIter* iter);
+
+ // Get the row number in the child tree model corresponding to |sort_path| in
+ // the parent tree model.
+ static gint GetTreeSortChildRowNumForPath(GtkTreeModel* sort_model,
+ GtkTreePath* sort_path);
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(GtkTreeUtil);
+};
+
+#endif // CHROME_COMMON_GTK_TREE_UTIL_H_