Help!!, clist selection..



Hi,

I posted this on gtk-app-devle-list yesterday but no answer yet :(
I know most of you subscribe both but hope someone else could help me..

While I'm playing with gtk I found a small problem, hope you can help me :)
I'd like to bring a dialog when one selects an item of clist.  Make a dialog is no problem but after the dialog is displayed mouse events don't work anymore - not dead, I can still make the cursor move around but no selection is made.  Yet keyboard events are working- I can navigate by using keyboard but I want to use mouse only!!  Is this a bug or I'm doing something wrong?  Any help is appreciated..

Jay

a sample code is followed..  To get out from color dialog, you have to use keyboard to select buttons of color dialog. Or kill the entire process..

=================================================================================
// standard header files
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>

// color structure
struct _Color
{
	GtkWidget	*wgt;
	int	back;
};

// close color selection dialog

gint color_close ( GtkWidget *wgt, struct _Color *color_info )
{
	gtk_main_quit ( );
	gtk_grab_remove ( wgt );
	g_free ( color_info );
	return FALSE;
}

// color change & close dialog
void color_change ( GtkWidget *wgt, struct _Color *color_info )
{
	// do something for color change
	// destroy the dialog box
	gtk_widget_destroy ( color_info->wgt );
}

// clist select - bring up color selection dialog
void clist_selection ( GtkCList *wgt, gint row, gint col, GdkEventButton *event,
gpointer data )
{
	static GtkWidget	*color_dlg ;
	struct _Color	*color_info;
	int	back = ( int ) data;

	// make color selction dlg
	color_dlg = gtk_color_selection_dialog_new  ( "Color Selection" );
	gtk_window_set_position ( GTK_WINDOW ( color_dlg ), GTK_WIN_POS_CENTER );

	// color information
	color_info = ( struct _Color * ) g_malloc ( sizeof ( struct _Color ));
	color_info->wgt = color_dlg;
	color_info->back = back;

	gtk_color_selection_set_opacity ( GTK_COLOR_SELECTION 
		( GTK_COLOR_SELECTION_DIALOG ( color_dlg )->colorsel ) , TRUE );
	gtk_color_selection_set_update_policy ( GTK_COLOR_SELECTION 
		( GTK_COLOR_SELECTION_DIALOG ( color_dlg )->colorsel ) ,
		GTK_UPDATE_CONTINUOUS );
	gtk_widget_destroy ( GTK_COLOR_SELECTION_DIALOG ( color_dlg )->help_button );

	// signal functions..
	gtk_signal_connect ( GTK_OBJECT ( color_dlg ), "destroy",
		GTK_SIGNAL_FUNC ( color_close ), color_info );
	gtk_signal_connect (
		GTK_OBJECT ( GTK_COLOR_SELECTION_DIALOG ( color_dlg )->ok_button ), 
		"clicked", GTK_SIGNAL_FUNC ( color_change ), color_info );
	gtk_signal_connect_object ( 
		GTK_OBJECT ( GTK_COLOR_SELECTION_DIALOG ( color_dlg )->cancel_button ),
		"clicked",	GTK_SIGNAL_FUNC ( gtk_widget_destroy ),
		GTK_OBJECT ( color_dlg ));

	gtk_widget_show ( color_dlg );
	gtk_grab_add ( color_dlg );
	gtk_main ( );
}

void MakeCList ( GtkWidget *win )
{
	GtkWidget *clist;
	gchar	*titles[] = { "Select", "Me!!" };
	char	*citem[2];
	int	i;

	// make clist widget 
	clist = gtk_clist_new_with_titles ( 2, titles );

	gtk_clist_freeze ( GTK_CLIST ( clist )); // freeze the widget
	gtk_clist_clear ( GTK_CLIST ( clist )); // clear clist
	for ( i = 0; i < 2; i++ )
		citem[i] = (char *) calloc ( 80, sizeof ( char ));		

	// clist items
	for ( i = 0; i < 8; i++ )
	{
		sprintf ( citem[0], "%dth row", i+1 );
		sprintf ( citem[1], "%d- selection test", i+1 );
		gtk_clist_append ( GTK_CLIST ( clist ), citem );
	}
	gtk_clist_thaw ( GTK_CLIST ( clist )); // unfreeze the list

	// clist style
	gtk_clist_set_selection_mode ( GTK_CLIST ( clist ), GTK_SELECTION_BROWSE );
	gtk_clist_set_shadow_type ( GTK_CLIST ( clist ), GTK_SHADOW_OUT );
	gtk_clist_set_column_width ( GTK_CLIST ( clist ), 0, 50 );
	// signal
	gtk_signal_connect ( GTK_OBJECT ( clist ), "select_row",
		GTK_SIGNAL_FUNC ( clist_selection ), NULL );
	gtk_container_add ( GTK_CONTAINER ( win ), clist );
}

// close or window
gint delete_event ( GtkWidget *wgt, gpointer *data )
{
	gtk_main_quit ( );
	return FALSE;
}

// main
int main ( int argc, char *argv[] )
{
	GtkWidget *win;
	GtkWidget	*vbox;
	GtkWidget	*button;

	gtk_init ( &argc, &argv );
	// main window
	win = gtk_window_new ( GTK_WINDOW_TOPLEVEL );
	gtk_window_set_title ( GTK_WINDOW ( win ), "CList Selection Test" );
	gtk_widget_set_usize ( win, 200, 200 );

	// signals
	gtk_signal_connect ( GTK_OBJECT ( win ), "delete_event", 
		GTK_SIGNAL_FUNC ( delete_event ), NULL);

	// vertical packing box
	vbox = gtk_vbox_new ( FALSE, 0 );
	gtk_container_add ( GTK_CONTAINER ( win ), vbox );
	gtk_widget_show ( vbox );
	MakeCList ( vbox );	// clist
	button = gtk_button_new_with_label ( "Close" );	// close button
	gtk_signal_connect ( GTK_OBJECT ( button ), "clicked",
		GTK_SIGNAL_FUNC ( delete_event ), NULL );
	gtk_container_add ( GTK_CONTAINER ( vbox ), button );
	gtk_widget_show_all ( win ); // show all
	gtk_main ( );
	exit ( 0 );
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]