Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 24 May 2015, 17:35
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
SOLVED:gtk eventbox - user data parsing
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count_1  
Author Message

Joined: 07 Dec 2008
Posts: 805

PostPosted: Mon 10 Jun 2013, 14:01    Post_subject:  SOLVED:gtk eventbox - user data parsing  

I am trying to trap clicks on gtk labels. I can use an eventbox to do that.
I want to parse some user data as well but cant get that working.
Below code uses the same callback function for the button and the eventbox - the button-callback parses the userdata (act) but the eventbox does not:
/* example-start eventbox event_test.c */
//compile with
//gcc event_test.c $(/usr/local/bin/gtk-config --cflags) -o eventbox $(/usr/local/bin/gtk-config --libs)

#include <gtk/gtk.h>

void callback ( GtkWidget *widget, gpointer str) {   
   g_print ("str is: %s\n", (char *)str);

int main( int argc, char *argv[] ) {
    GtkWidget *window, *event_box, *label, *button, *box1, *box2;
    char *act="This is the content of char act";
    ///the usual window things
    gtk_init (&argc, &argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_signal_connect (GTK_OBJECT (window), "destroy",
                        GTK_SIGNAL_FUNC (gtk_exit), NULL);
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    gtk_widget_show (window);
    ///the button in box1 - sends value of act without problems.
   box1 = gtk_hbox_new (FALSE, 0);
   button = gtk_button_new_with_label ("click me");
   gtk_box_pack_start (GTK_BOX (box1), button, TRUE, TRUE, 0);
   gtk_widget_show (button);
   gtk_container_add (GTK_CONTAINER (window), box1);
   gtk_signal_connect (GTK_OBJECT (button), "clicked",
                        GTK_SIGNAL_FUNC (callback), (gpointer) act);
   ///the event-thing in box2 - this one wont send the value of act..
   box2 = gtk_hbox_new (FALSE, 0);
   event_box = gtk_event_box_new ();
   gtk_box_pack_start (GTK_BOX (box2), event_box, TRUE, TRUE, 0);
   gtk_widget_show (event_box);
label = gtk_label_new ("Click here to view events from the eventbox...");
    gtk_container_add (GTK_CONTAINER (event_box), label);
    gtk_widget_show (label);
    gtk_widget_set_events (event_box, GDK_BUTTON_PRESS_MASK);
    gtk_signal_connect (GTK_OBJECT(event_box), "button_press_event",
                   GTK_SIGNAL_FUNC (callback), (gpointer) act);
    gtk_container_add (GTK_CONTAINER(box1), box2);               
    gtk_widget_realize (event_box);
    gtk_widget_show (window);
    gtk_main ();

I really would like to get this working - any suggestions?
UPDATE: If I change the callback function from the eventbox to:
void callback ( GtkWidget *widget, GdkEvent *event, gpointer str) {   
   g_print ("str is: %s\n", (char *)str);
the user data is passed. This callback does not work for the button so need two different functions.
Back to top
View user's profile Send_private_message Visit_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count_1  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot attach files in this forum
You can download files in this forum

Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0463s ][ Queries: 11 (0.0049s) ][ GZIP on ]