Resizable and Scrollable TreeView

From: Date: Wed, 07 Mar 2007 15:18:06 +0000
Subject: Resizable and Scrollable TreeView
Groups: php.gtk.dev 
Request: Send a blank email to php-gtk-dev+get-3771@lists.php.net to get a copy of this message
Hi, I'm trying to create a tree view which is resizable, but when the contents are larger than the TreeView, there must come a scroll bar too. But the width of the TreeView is fixed, and I can't resize it. Here is the code to reproduce it: <?php /** * Example Tree view GTK application */ class TreeExample extends GtkWindow { /**
    * An large array containig all menu items
    *
    * @var array
    */
private $menus; /**
    * Constructor, Initializes the window
    */
public function __construct() {
       parent::__construct();
       $this -> add($this -> build_gui());
       $this -> connect_simple('destroy', array($this, 'quit'));
       $this -> set_title('RSS Reader');
       $this -> set_default_size(800, 600);
       $this -> set_position(Gtk::WIN_POS_CENTER);
       $this -> show_all();
} /**
    * Sets up the main GUI
    * @return GtkVbox Container with menu, toolbar and the rest
    */
protected function build_gui() {
       $vbox = new GtkVBox();
       $vbox -> pack_start($this -> build_content(), true, true, 2);
       //
       // TODO: Add toolbar, and main content
       //
       return $vbox;
} /**
    * Sets up the RSS content
    * @return GtkHBox Container with the RSS content
    */
protected function build_content() {
       $hbox = new GtkHBox();
       $hbox -> pack_start($this -> build_feed_tree(), false, false);
       $hbox -> pack_start(new GtkVSeparator(), false, false, 2);
       return $hbox;
} /**
    * Loads all feeds, and puts it in a GtkTreeStore object
    * @return GtkScrolledWindow
    */
protected function build_feed_tree() {
       $tree_store = new GtkTreeStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING);
       // Items to add into the tree view
       $feeds = array(
           'Feed Folder 1' => array(
               'Feed1' => 'url',
               'Feed2' => 'url',
           ),
           'Feed Folder 2' => array(
               'Sub Folder' => array(
                   'Feed 3' => 'url',
                   'Feed 4' => 'url'
               ),
               'Feed 5' => 'url'
           )
       );
       $this -> add_feeds_to_tree($tree_store, $feeds);
       // Building the TreeView
       $tree_view = new GtkTreeView($tree_store);
       $tree_column = new GtkTreeViewColumn('RSS Feeds', new
GtkCellRendererText(), 'text', 0);
       $tree_column -> set_resizable(true);
       $tree_column -> set_min_width(150);
       $tree_view -> append_column($tree_column);
       // Put it in a scrolled window
       $scroll = new GtkScrolledWindow();
       $scroll -> set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
       $scroll -> add($tree_view);
       return $scroll;
} /**
    * Adds the feeds recursive to the tree
    * @param GtkTreeStore $tree_store The GtkTreeStoreO Object to add the
feeds to
    * @param array $feeds An array with feeds to add
    * @param GtkTreeIter $parent The parent of the feed
    */
protected function add_feeds_to_tree(GtkTreeStore &$tree_store, array $feeds, $parent = null) {
       $pos = 0;
       foreach($feeds as $name => $contents)
       {
           $row = $tree_store -> insert($pos++, $parent);
           $tree_store -> set($row, 0, $name);
           if(is_array($contents))
           {
               $this -> add_feeds_to_tree($tree_store, $contents, $row);
           }
           else
           {
               $tree_store -> set($row, 1, $contents);
           }
       }
} /**
    * Event triggered when a menu item is clicked
    * @param string $name Name of the menu item
    */
public function OnMenuActivated($name) {
       if(method_exists($this, $name))
       {
           $this -> $name();
       }
} /**
    * Quits the application
    */
public function quit() {
       Gtk::main_quit();
} } new TreeExample(); Gtk::main(); ?> Does anybody know why I can't resize it, and how I can fix this? Thanks in advance. -- Lucas

« previous php.gtk.dev (#3771) next »