/** * Construct treeview */ function __construct() { parent::__construct(); parent::set_headers_visible(FALSE); $this->model = new GtkTreeStore(GObject::TYPE_OBJECT, GObject::TYPE_STRING, GObject::TYPE_PHP_VALUE, GObject::TYPE_STRING); parent::set_model($this->model); parent::connect('row-activated', array($this, 'onClick')); $column1 = new GtkTreeViewColumn(); $cell_renderer1 = new GtkCellRendererPixbuf(); $cell_renderer2 = new GtkCellRendererText(); $column1->pack_start($cell_renderer1, false); $column1->pack_start($cell_renderer2, false); $column1->set_attributes($cell_renderer1, 'pixbuf', 0); $column1->set_attributes($cell_renderer2, 'text', 1); parent::append_column($column1); }
function __create_box() { $box = new GtkVBox(); $box->pack_start(new GtkLabel('Double click with the mouse on a file, or select by key and press return'), false); $paned = new GtkHPaned(); $paned->set_position(200); //filename, markup-filename, fullpath, is_dir, preview image $mFile = new GtkListStore(GObject::TYPE_STRING, GObject::TYPE_STRING, GObject::TYPE_STRING, GObject::TYPE_BOOLEAN, GdkPixbuf::gtype); $mFile->set_sort_column_id(0, Gtk::SORT_ASCENDING); $vFile = new GtkTreeView($mFile); $col = new GtkTreeViewColumn('Image', new GtkCellRendererPixbuf(), 'pixbuf', 4); $text = new GtkCellRendererText(); $col->pack_start($text); $col->add_attribute($text, 'markup', 1); $vFile->append_column($col); $vFile->set_headers_visible(false); $vFile->connect('key-press-event', array($this, 'onPressFile')); $vFile->connect('button-press-event', array($this, 'onPressFile')); /* GtkIconView has some problems with text that are too long and missing icons $vFile = new GtkIconView(); $vFile->set_model($mFile); $vFile->set_columns(1); $vFile->set_pixbuf_column(3); $vFile->set_text_column(0); $vFile->set_item_width(100); */ $this->loadFiles($mFile, getcwd()); $scrwndFiles = new GtkScrolledWindow(); $scrwndFiles->add($vFile); $scrwndFiles->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); $vboxFile = new GtkVBox(); $vboxFile->pack_start($scrwndFiles); $chkImg = new GtkCheckbutton('Load preview images'); $chkImg->set_active(true); $chkImg->connect('toggled', array($this, 'onCheckPreview')); $vboxFile->pack_start($chkImg, false); $paned->add1($vboxFile); $this->img = new GtkImage(); $scrwndImg = new GtkScrolledWindow(); $scrwndImg->add_with_viewport($this->img); $scrwndImg->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); $paned->add2($scrwndImg); $box->pack_end($paned); return $box; }
/** * Cria o treeview apartir de um XML * * @name treeviewLoadXML * @param string $file Caminho do arquivo XML com as definições do treeview * @param object $mainObject Objeto onde está os métodos callback do treeview */ public function treeviewLoadXML($file, $mainObject = NULL) { // Lê o XML $xml = new SimpleXMLElement(file_get_contents($file)); // Seta a coluna para a busca $searchcolumn = isset($xml['searchcolumn']) ? (int) $xml['searchcolumn'] : 0; parent::set_search_column($searchcolumn); // Configura a visibilidade do header da coluna switch (strtoupper((string) $xml['hvisible'])) { case "FALSE": $hvisible = FALSE; break; case "TRUE": default: $hvisible = TRUE; break; } parent::set_headers_visible($hvisible); // Verifica se existe evento button-press-event $buttonpressevent = (string) $xml['buttonpressevent']; if (strlen($buttonpressevent) > 0) { // Verifica se é orientado à objeto if ($mainObject != NULL) { // Cria o método callback $function = array($mainObject, $buttonpressevent); } else { // Cria a função callback $function = $buttonpressevent; } parent::connect("button-press-event", $function); } // Verifica se existe evento cursor-changed $cursorchanged = (string) $xml['cursorchanged']; if (strlen($cursorchanged) > 0) { // Verifica se é orientado à objeto if ($mainObject != NULL) { // Cria o método callback $function = array($mainObject, $cursorchanged); } else { // Cria a função callback $function = $cursorchanged; } parent::connect("cursor-changed", $function); } // Percorre as configurações foreach ($xml as $configs) { // Verifica se são as configurações das colunas if ($configs->getName() == "columns") { // Percorre as colunas $counter = 0; $columnModel = array(); foreach ($configs as $column) { // Busca as configurações $title = (string) $column['title']; $visible = (string) $column['visible']; // Cria a coluna $modelType = Gobject::TYPE_STRING; if (strtoupper($visible) != "FALSE") { // Verifica o tipo e o render switch (strtoupper((string) $column['type'])) { // Toggle case "TOGGLE": // Cria o render $render = new GtkCellRendererToggle(); $render->set_property("activatable", TRUE); // Verifica se deve usar o autocheck switch (strtoupper((string) $column['autocheck'])) { case "FALSE": break; case "TRUE": default: $render->connect("toggled", array($this, "__onToggle"), $counter); break; } // Verifica se existe evento onclick da coluna $onclick = (string) $column['onclick']; if (strlen($onclick) > 0) { // Verifica se é orientado à objeto if ($mainObject != NULL) { // Cria o método callback $function = array($mainObject, $onclick); } else { // Cria a função callback $function = $onclick; } // Conecta o callback de check $render->connect("toggled", $function, $counter); } // Armazena o atributo e o model $attribute = "active"; $modelType = Gobject::TYPE_BOOLEAN; break; // Texto // Texto case "TEXT": default: $render = new GtkCellRendererText(); // Verifica se a coluna é editavel switch (strtoupper((string) $column['editable'])) { case "TRUE": $render->set_property("editable", TRUE); break; case "FALSE": default: break; } // Verifica se existe sinal para edição $onedited = (string) $column['onedited']; if (strlen($onedited) > 0) { // Verifica se é orientado à objeto if ($mainObject != NULL) { // Cria o método callback $function = array($mainObject, $onedited); } else { // Cria a função callback $function = $onedited; } // Conecta a coluna ao callback $render->connect("edited", $function, $this, $counter); } // Armazena os atributos $attribute = "text"; $modelType = Gobject::TYPE_STRING; } // Cria a coluna com as configurações $trvColumn = new GtkTreeViewColumn($title, $render, $attribute, $counter); parent::append_column($trvColumn); // Verifica se existe parametrização do tamanho da coluna if (isset($column['width'])) { $trvColumn->set_fixed_width((int) $column['width']); $trvColumn->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED); } // Verifica se existe parametrização da formatação if (isset($column['onformat'])) { $onformat = (string) $column['onformat']; // Verifica se é orientado à objeto if ($mainObject != NULL) { // Cria o método callback $function = array($mainObject, $onformat); } else { // Cria a função callback $function = $onformat; } // Conecta o callback de renderização $trvColumn->set_cell_data_func($render, $function, $counter); } } // Armazena o model $columnModel[$counter++] = $modelType; } // Seta o model $model = new GtkTreeStore(); $model->set_column_types($columnModel); parent::set_model($model); } } }