OxyScripts.com
Menu spacer Home Tutorials Articles Code Forums irc.freenode.net #oxyscripts
Main (PHP)
Home Forums PHP News PHP Tutorials Articles PHP Code Snippets Contact Us Sysadmin Resources Books Template Shop
3rd Party Streams
SlashDot PHPDeveloper.org PHP.Net
Resources
PHP Manual MySQL Manual Smarty Manual PEAR Manual PHP-GTK Manual Symfony Manual
Code Snippets
Authentication Database Graphics HTTP Miscellaneous Time/Date
Affiliates
Scripts TutorialMan TutorialGuide CodingForums.com PHP Scripts Cheap Web Hosting Affordable Web Hosting Dreamweaver Templates

Search This Site :     PHP Function Reference :
 
GtkCombo Constructor

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.

Example 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();

?>

 
   Print this page

Top Sponsor
Symantec\'s Norton SystemWorks 2006
Sponsors
CA
Sponsors
AdWords Dominator 125*125
Advertisting

Affiliates
VertexTemplates PHPFreaks CodeWalkers StarGeek DevScripts CGI & PHP Scripts PHP CMS

Shopping Rebates   Sell It 4 You   Flash Page Counters   Get Insured
GPS Tracking Service   Charity Donate Info   Web Site Hosting   VOIP Service

Privacy Policy | Links | Site Map | Advertising

All content on OxyScripts.com is (©)2002-2007

 
Powered by Adrastea - Version 1.0.0. Copyright © Rune Solutions, 2004-2005