mofofish |
04-13-2004 12:32 PM |
GTK+ and c question
i am currently teaching myself C and gtk at the same time by writing a simple/silly program for converting human years into cat or dog years. my question is how do i get the address/pointer/hopeyouknowehatimean of a gtkwidget radio button in a function so i can check to see if it is active? here is the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#define DOGYEARS 7
#define CATYEARS 4
static void destroy( GtkWidget *widget,
gpointer data )
{
gtk_main_quit ();
}
static void to_dog( GtkWidget *widget,
GtkWidget *text )
{
const gchar *entry_text;
gchar *dog_years;
float years;
entry_text = gtk_entry_get_text (GTK_ENTRY (text));
printf ("Text: %s\n", entry_text);
years = (atof (entry_text)) * DOGYEARS;
sprintf (dog_years, "%.0f", years);
gtk_entry_set_text (text, dog_years);
printf ("Years: %.0f\n", years);
}
int main( int argc,
char *argv[] )
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *vboxr;
GtkWidget *button;
GtkWidget *text;
GtkWidget *radiocat;
GtkWidget *radiodog;
GSList *group;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (destroy), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 2);
vbox = gtk_vbox_new (TRUE, 0);
gtk_widget_show (vbox);
vboxr = gtk_vbox_new (TRUE,0);
gtk_widget_show (vboxr);
text = gtk_entry_new();
gtk_widget_show (text);
button = gtk_button_new_with_label ("To dog years");
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (to_dog), (gpointer) text);
gtk_widget_show (button);
radiocat = gtk_radio_button_new_with_label (NULL, "Cat years");
gtk_box_pack_start (GTK_BOX (vboxr), radiocat, FALSE, FALSE, 0);
gtk_widget_show (radiocat);
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiocat));
radiodog = gtk_radio_button_new_with_label (group, "Dog years");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiodog), TRUE);
gtk_box_pack_start (GTK_BOX (vboxr), radiodog, FALSE, FALSE, 0);
gtk_widget_show (radiodog);
gtk_widget_show (vboxr);
gtk_box_pack_start (GTK_BOX (vbox), text, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), vboxr, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (window);
gtk_main();
return 0;
}
i need to check the state of the radiocat widget from the function to_dog using the function "gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radiocat))" but as i said, im not sure how to access this variable from the function to_dog
cheers
mofofish
|