function append_stock($stock, $index, $callback = null) { $button = GtkToolButton::new_from_stock($stock); $this->add($button); $button->set_visible_horizontal(true); $button->set_visible_vertical(true); if ($callback) { $button->connect('clicked', $callback); } return $button; }
function setup_toolbar($vbox, $toolbar_definition) { // note 1 $toolbar = new GtkToolBar(); // note 2 $vbox->pack_start($toolbar, 0, 0); foreach ($toolbar_definition as $item) { if ($item == '<hr>') { $toolbar->insert(new GtkSeparatorToolItem(), -1); } else { $stock_image_name = 'Gtk::STOCK_' . strtoupper($item); // note 3 if (defined($stock_image_name)) { $toolbar_item = GtkToolButton::new_from_stock(constant($stock_image_name)); $toolbar->insert($toolbar_item, -1); // note 5 $toolbar_item->connect('clicked', 'on_toolbar_button', $item); } } } }
/** * Adiciona um botão no final do toolbar apartir de um stockitem * * @name append_button_from_stock($stock_id, $label=NULL, $tip=NULL) * @param GtkStockItem $stock_id Id do stock a ser adicionado * @param string $label Label do botão caso não for usar o padrão * @param string $tip String para mostrar como tooltip * @return GtkToolButton */ public function append_button_from_stock($stock_id, $label = NULL, $tip = NULL) { // Cria o botão $toolbutton = GtkToolButton::new_from_stock($stock_id); // Verifica se existe label if ($label != NULL) { $toolbutton->set_label($label); } // Verifica se existe tooltip if ($tip != NULL) { // Adiciona o tooltip $toolbutton->set_tooltip_text($tip); } // Adiciona o callback do click $toolbutton->connect_simple("clicked", array($this, "__onclick"), ++$this->__counter); // Armazena o botão $this->__buttons[$this->__counter] = $toolbutton; // Adiciona o botão ao toolbar parent::insert($toolbutton, -1); // Retorna o botão return $toolbutton; }
public function toolbarLoadXML($file, $mainObject = NULL) { // Lê o XML // @since rev 1 $xml = new SimpleXMLElement(file_get_contents($file)); // Cria o frame, o scrool e o treeview // @since rev 1 $obj['object'] = new GtkToolBar(); $toolbarName = (string) $xml['name']; $obj['object']->set_tooltips(TRUE); $clicked = (string) $xml['clicked']; // Percorre as configurações // @since rev 1 $counter = 0; foreach ($xml as $toolitems) { // Verifica o tipo de configuração // @since rev 1 if ($toolitems->getName() == "stockitem") { // Ajusta as informações // @since rev 1 $toolitems = $toolitems[0]; // Busca as configurações // @since rev 1 $title = (string) $toolitems['title']; $name = (string) $toolitems['name']; $stock = (string) $toolitems['stock']; // Cria o botao // @since rev 1 $obj[$name] = GtkToolButton::new_from_stock(constant($stock)); $obj['object']->insert($obj[$name], $counter); // Adiciona o evento se houver // @since rev 1 if (strlen($clicked) > 0) { // Verifica se é orientado à objeto // @since rev 1 if ($mainObject != NULL) { $function = array($mainObject, $clicked); } else { $function = $clicked; } $obj[$name]->connect("clicked", $function, $name); } // Verifica se esta desabilitado // @since rev 1 switch (strtoupper((string) $toolitems['enabled'])) { case "FALSE": $enabled = FALSE; break; case "TRUE": default: $enabled = TRUE; break; } $obj[$name]->set_sensitive($enabled); // Verifica se possui tooltip // @since rev if (isset($toolitems['tooltip'])) { $tt = new GtkTooltips(); $tt->set_tip($obj[$name], (string) $toolitems['tooltip']); unset($tt); } } else { if ($toolitems->getName() == "separator") { $obj['object']->insert(new GtkSeparatorToolItem(), $counter); } else { if ($toolitems->getName() == "toolitem") { // Busca o nome do item $name = (string) $toolitems['name']; // Cria o item $obj[$name] = new GtkToolItem(); // Adiciona o item ao toolbar $obj['object']->insert($obj[$name], $counter); } } } // Soma o contador // @since rev 1 $counter++; } // Retorna o toolbar // @since rev 1 return $obj; }