tooltips and color change



Can someone please explain what I'm doing wrong in the following code?
By pressing the color change button, I would expect the tooltips to
switch to different colors.  Instead, I always get black letters on
a green background.  Thanks.

rajat





/* demonstrate tooltips
 */
#include <gtk/gtk.h>
#include <gdk/gdk.h>


GtkWidget *window, *vbox;
GtkWidget *enable_button, *disable_button, *color_change_button, *close_button;
GtkTooltips *tooltips;

int tooltips_enabled = 0;
int color_mode = 0;




/* The enable tooltips button has been pressed.  From now on, tooltips will work
 */
void enable_tooltips( GtkWidget *widget, gpointer *data ) {

	if (tooltips_enabled)
		return;

	tooltips_enabled = 1;

	gtk_tooltips_enable( tooltips );
}



/* The disable tooltips button has been pressed.  No more tooltips after this.
 */
void disable_tooltips( GtkWidget *widget, gpointer *data ) {

	if (tooltips_enabled == 0)
		return;
	tooltips_enabled = 0;

	gtk_tooltips_disable( tooltips );
}



/* Change the background and foreground colors of the tooltips
 */
void color_change_tooltips( GtkWidget *widget, gpointer *data ) {
	GdkColor background, foreground;
	GdkColormap *colormap;

	switch( color_mode ) {
	case 0:
		color_mode = 1;
		gdk_color_parse( "yellow", &background );
		gdk_color_parse( "black", &foreground );
		break;
	case 1:
		color_mode = 0;
		gdk_color_parse( "black", &background );
		gdk_color_parse( "yellow", &foreground );
		break;
	}

	/* Why doesn't this line work???? */
	gtk_tooltips_set_colors( tooltips, &background, &foreground );
}



/* close the application
 */
void close_application( GtkWidget *widget, gpointer *data ) {
	gtk_main_quit();
}




int main( int argc, char *argv[] ) {
	/* initialize gtk and create the main window */
	gtk_init( &argc, &argv );

	window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
    gtk_signal_connect (GTK_OBJECT (window), "destroy",
			GTK_SIGNAL_FUNC( close_application ), NULL);
    gtk_container_border_width (GTK_CONTAINER (window), 10);

	vbox = gtk_vbox_new( FALSE, 0 );
	gtk_container_add( GTK_CONTAINER(window), vbox );

	/* Create and add the four buttons to the main window */
	enable_button = gtk_button_new_with_label( "Enable Tooltips" );
	gtk_signal_connect( GTK_OBJECT(enable_button), "clicked",
						GTK_SIGNAL_FUNC( enable_tooltips ), GTK_OBJECT(window) );
	gtk_box_pack_start( GTK_BOX( vbox ), enable_button, FALSE, FALSE, 0);
	
	disable_button = gtk_button_new_with_label( "Disable Tooltips" );
	gtk_signal_connect( GTK_OBJECT(disable_button), "clicked",
						GTK_SIGNAL_FUNC( disable_tooltips ), GTK_OBJECT(window) );
	gtk_box_pack_start( GTK_BOX( vbox ), disable_button, FALSE, FALSE, 0);
	
	color_change_button = gtk_button_new_with_label( "Color_Change Tooltips" );
	gtk_signal_connect( GTK_OBJECT(color_change_button), "clicked",
						GTK_SIGNAL_FUNC( color_change_tooltips ), GTK_OBJECT(window) );
	gtk_box_pack_start( GTK_BOX( vbox ), color_change_button, FALSE, FALSE, 0);
	
	close_button = gtk_button_new_with_label( "Close Tooltips" );
	gtk_signal_connect( GTK_OBJECT(close_button), "clicked",
						GTK_SIGNAL_FUNC( close_application ), GTK_OBJECT(window) );
	gtk_box_pack_start( GTK_BOX( vbox ), close_button, FALSE, FALSE, 0);

	/* add the tooltips */
	tooltips = gtk_tooltips_new();

	gtk_tooltips_set_tips( tooltips, enable_button, "enable tooltips" );
	gtk_tooltips_set_tips( tooltips, disable_button, "disable tooltips" );
	gtk_tooltips_set_tips( tooltips, color_change_button, "change color of tooltips
" );
	gtk_tooltips_set_tips( tooltips, close_button, "terminate application" );

	tooltips_enabled = 1;
	
	/* now show everything */
	gtk_widget_show( enable_button );
	gtk_widget_show( disable_button );
	gtk_widget_show( color_change_button );
	gtk_widget_show( close_button );

	gtk_widget_show( vbox );
	gtk_widget_show( window );

	gtk_main();

	return 0;
}



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