PHPマニュアル/PEARマニュアル | ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot

GtkCombo Constructor | JavaScript入門&応用&リファレンスなら「JavaScriptist」

  

GtkCombo Constructor

GtkCombo (void);

When the GtkListItem has been selected in a GtkCombo, the combo's entry text is picked up from the item, and the combo's list is searched for a data match. The "unselect-child" signal is fired by the list during this routine in order to clear previously existing data. If you connect to either that or the "deselect" signal, your callback function will run twice. The same applies to the "select-child" and "select" signals, as the deselection allows the item to be selected again - which it is, when select_child() is called immediately afterwards.

There are many ways of working around this. One is given in the sample below.

例 9. Associating data with a GtkListItem

<?php

if( !extension_loaded('gtk')) {	
    dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); 
}

function on_click($item, $event, $i) {
  echo $item->get_data($i)."\n";
  flush();
}

function on_key($item, $i) {
  echo $item->get_data($i)."\n";
  flush();
}

$window = &new GtkWindow();
$window->set_position(GTK_WIN_POS_CENTER);
$window->connect_object("destroy", array("gtk", 
"main_quit"));

$combo = &new GtkCombo();
/* The GtkEntry and GtkList are accessible through the combo's properties */
$entry = $combo->entry;
$entry->set_text('Choose some fruit');
$list = $combo->list;
$list->set_selection_mode(GTK_SELECTION_SINGLE);

$fruit = array('apples', 'bananas', 'cherries', 'damsons', 'eggplants', 
'figs', 'grapes');

for($i = 0; $i < count($fruit); $i++) {
  $item = &new GtkListItem();
/* You can put pretty much anything into a GtkListItem */
  $box = &new GtkHBox();
  $arrow = &new GtkArrow(GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
  $box->pack_start($arrow, false, false, 5);
  $label = &new GtkLabel('Item  '.($i+1));
  $box->pack_start($label, false, false, 10);
  $item->add($box);
  $combo->set_item_string($item, "You chose $fruit[$i]");
  $data = $fruit[$i];
/* This data will be carried with the $item.  The key here is $i. */
  $item->set_data($i, $data);
/* Two separate signals to get around the 'select' problem. */
  $item->connect('button-press-event', 'on_click', $i);
  $item->connect('toggle', 'on_key', $i);
  $list->add($item);
  $item->show_all();
}

$window->add($combo);
$window->show_all();

gtk::main();

?>

忘却曲線を使ってこの知識を確実に記憶に残す

フォーラムで「GtkCombo Constructor」について話す
各種マニュアル: PHPマニュアル | PEARマニュアル | Smarty(英語)マニュアル | PHP-GTKマニュアル | GtkCombo Constructor」をGoogle検索
copyright © 1997-2024 PHP ドキュメント作成グループ(ライセンス). provided by php spot. マニュアル: