Re: [gtk-list] Re: New problem, broken toggle button code.



On Wed, 4 Mar 1998, Tim Janik wrote:

> On Wed, 4 Mar 1998, Leeman Strout wrote:
> 
> > 
> > When I set an active toggle button to being insensitive, the button pops
> > back out to being inactive.  My problem with that is I have 2 toggle
> > buttons setup for radio behaviour, and to help enforce that radio
> > behaviour I set the active button insensitive.  Everything still works,
> > but the active button no longer looks active.  I haven't checked yet
> > whether the actual (button)->active value is actually reset or not tho.
> > 

> hm, though i don't really get the difference you are mentioning, you
> might just want to use ordinary radio buttons and do a
> gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (radio_button), FALSE);
> on each of them.

Ok in answer to 'you might...'  I didn't to begin with because I want a
full size button, not a little diamond radio button.  And lastly I'll
attach a sample program to show you what I am talking about.

And lastly, after you get what I'm talking about... can we restore the old
behaviour?  (An active but insensitive toggle still looks active, but also
insensitive)

Leeman
alaric@ct2.nai.net

#include <gtk/gtk.h>

GtkWidget *button;
GtkWidget *button2;

void print_toggle_button_state (GtkWidget *toggle_button,
                           gpointer  user_data)
{
  g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));

  printf ("togglebutton: active=%d\n", GTK_TOGGLE_BUTTON (toggle_button)->active);
}

void sensitivity (GtkWidget *button2, gpointer data)
{
  if (GTK_TOGGLE_BUTTON(button2)->active) {
    gtk_widget_set_sensitive (GTK_WIDGET(button), FALSE);
    printf ("insensitive\n");
  } else {
    gtk_widget_set_sensitive (GTK_WIDGET(button), TRUE);
    printf ("sensitive\n");
  }
}


int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *box;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  button = gtk_toggle_button_new_with_label ("click me");
  gtk_widget_show (button);
  gtk_widget_show (button2);
  gtk_signal_connect (GTK_OBJECT (button), "clicked", 
                     GTK_SIGNAL_FUNC (print_toggle_button_state), NULL);
  button2 = gtk_toggle_button_new_with_label ("me next");
  gtk_signal_connect (GTK_OBJECT (button2), "clicked",
                     GTK_SIGNAL_FUNC (sensitivity), NULL);

  gtk_widget_show (button2);
  box = gtk_vbox_new (FALSE, FALSE);
  gtk_box_pack_start (GTK_BOX(box), button, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX(box), button2, TRUE, TRUE, 0);
  gtk_widget_show (box);

  gtk_container_add (GTK_CONTAINER (window), box);
  gtk_widget_show (window);

  gtk_main ();

  return 0;
}



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