Double clicks
| From: | Madeleine D. | Date: | Wed, 09 Jul 2003 19:48:05 +0000 |
| Subject: | Double clicks | ||
| Groups: | php.gtk.general | ||
| Request: | Send a blank email to php-gtk-general+get-3612@lists.php.net to get a copy of this message | ||
I finally got the double click working on our CLists, so I am posting it to
the list to help the next poor soul who comes behind me.
Following creation and population of GtkClist, this code will allow the
user to double-click on a CList row and return the data to a calling screen:
------------------------------
$titles = array("ID","Status","Acct No.","Last
Name","First Name");
$dest = "PMWin_members";
$clist = &new GtkCList(count($titles), $titles);
$clist->set_selection_mode(GTK_SELECTION_SINGLE);
(Populate clist with data here)
$clist->connect_object("button_press_event", "PMbuttonPress",
$clist, "PMWin_search", $titles, $dest);
( Finish out calling screen here)
function PMbuttonPress($event,$widget,$source,$titles,$dest) {
switch($source) {
case 'PMWin_search':
// Read event type to determine Mouse Double Click
if ($event->type == GDK_2BUTTON_PRESS) {
PMschRtnData($widget,$dest,$titles);
}
break;
case 'PMWin_trans':
break;
} //End switch
} // End PMbuttonPress
function PMschRtnData($clist,$dest,$titles) {
$clist->freeze();
// Read selection to determine row data
$selection = $clist->selection;
for ($x = 0 ; $x != count($selection) ; $x++) {
for ($i = 0 ; $i != count($titles) ; $i++) {
$rowData[] = $clist->get_text($selection[$x], intval($i));
}
}
if ($rowData) {
switch($dest) {
case 'PMWin_members':
// Read first column; contains ID field for DB record
$id = $rowData[0];
// Query DB based on ID field
if ($query = mysql_query("Select * from MBRS where MBR_ID = '$id'")) {
// Send query to function to populate screen fields
PMsetData($dest,$query);
}
break;
case 'PMWin_trans':
break;
} //End switch
} //End check $rowData
$clist->thaw();
} //End PMschRtnData
(PMsetData function reads the MySQL query and loads the matching fields
in the destination screen. We don't unselect the row because PMsetData
closes the clist screen, in this case 'PMWin_search')