ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-gtk-dev
php-gtk-dev
[PHP-GTK-DEV] Resizable and Scrollable TreeView
by Lucky Luke other posts by this author
Mar 7 2007 7:30AM messages near this date
Re: [PHP-GTK-DEV] Custom Signals Support | [PHP-GTK-DEV] Re: Resizable and Scrollable TreeView
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
Thread:
Lucky Luke
Elizabeth Smith

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved