1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_TREE_MODEL_H_ 6#define CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_TREE_MODEL_H_ 7#pragma once 8 9#include "base/basictypes.h" 10#include "base/string16.h" 11 12class BookmarkModel; 13class BookmarkNode; 14 15typedef struct _GtkCellRenderer GtkCellRenderer; 16typedef struct _GtkTreeIter GtkTreeIter; 17typedef struct _GtkTreeModel GtkTreeModel; 18typedef struct _GtkTreeStore GtkTreeStore; 19typedef struct _GtkTreeView GtkTreeView; 20typedef struct _GdkPixbuf GdkPixbuf; 21typedef struct _GtkWidget GtkWidget; 22 23namespace bookmark_utils { 24 25enum FolderTreeStoreColumns { 26 FOLDER_ICON, 27 FOLDER_NAME, 28 ITEM_ID, 29 IS_EDITABLE, 30 FOLDER_STORE_NUM_COLUMNS 31}; 32 33// Make a tree store that has two columns: name and id. 34GtkTreeStore* MakeFolderTreeStore(); 35 36// Copies the folders in the model's root node into a GtkTreeStore. We 37// want the user to be able to modify the tree of folders, but to be able to 38// click Cancel and discard their modifications. |selected_id| is the 39// node->id() of the BookmarkNode that should selected on 40// node->screen. |selected_iter| is an out value that points to the 41// node->representation of the node associated with |selected_id| in |store|. 42// |recursive| indicates whether to recurse into sub-directories (if false, 43// the tree store will effectively be a list). |only_folders| indicates whether 44// to include bookmarks in the tree, or to only show folders. 45void AddToTreeStore(BookmarkModel* model, int64 selected_id, 46 GtkTreeStore* store, GtkTreeIter* selected_iter); 47 48// As above, but inserts just the tree rooted at |node| as a child of |parent|. 49// If |parent| is NULL, add it at the top level. 50void AddToTreeStoreAt(const BookmarkNode* node, int64 selected_id, 51 GtkTreeStore* store, GtkTreeIter* selected_iter, 52 GtkTreeIter* parent); 53 54// Makes a tree view for the store. This will take ownership of |store| and the 55// returned widget has a floating reference. 56GtkWidget* MakeTreeViewForStore(GtkTreeStore* store); 57 58// A helper method for getting pointer back to the GtkCellRendererText used for 59// the folder names. 60GtkCellRenderer* GetCellRendererText(GtkTreeView* tree_view); 61 62// Commits changes to a GtkTreeStore built from BuildTreeStoreFrom() back 63// into the BookmarkModel it was generated from. Returns the BookmarkNode that 64// represented by |selected|. 65const BookmarkNode* CommitTreeStoreDifferencesBetween( 66 BookmarkModel* model, GtkTreeStore* tree_store, 67 GtkTreeIter* selected); 68 69// Returns the id field of the row pointed to by |iter|. 70int64 GetIdFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter); 71 72// Returns the title field in utf8 of the row pointed to by |iter|. 73string16 GetTitleFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter); 74 75} // namespace bookmark_utils 76 77#endif // CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_TREE_MODEL_H_ 78