]> Pileus Git - ~andy/gtk/blob - gtk/gtktogglebutton.c
Add optional colord support to the CUPS print module
[~andy/gtk] / gtk / gtktogglebutton.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #include "config.h"
28
29 #include "gtktogglebutton.h"
30
31 #include "gtkbuttonprivate.h"
32 #include "gtklabel.h"
33 #include "gtkmain.h"
34 #include "gtkmarshalers.h"
35 #include "gtktoggleaction.h"
36 #include "gtkactivatable.h"
37 #include "gtkprivate.h"
38 #include "gtkintl.h"
39
40
41 /**
42  * SECTION:gtktogglebutton
43  * @Short_description: Create buttons which retain their state
44  * @Title: GtkToggleButton
45  * @See_also: #GtkButton, #GtkCheckButton, #GtkCheckMenuItem
46  *
47  * A #GtkToggleButton is a #GtkButton which will remain 'pressed-in' when
48  * clicked. Clicking again will cause the toggle button to return to its
49  * normal state.
50  *
51  * A toggle button is created by calling either gtk_toggle_button_new() or
52  * gtk_toggle_button_new_with_label(). If using the former, it is advisable to
53  * pack a widget, (such as a #GtkLabel and/or a #GtkPixmap), into the toggle
54  * button's container. (See #GtkButton for more information).
55  *
56  * The state of a #GtkToggleButton can be set specifically using
57  * gtk_toggle_button_set_active(), and retrieved using
58  * gtk_toggle_button_get_active().
59  *
60  * To simply switch the state of a toggle button, use gtk_toggle_button_toggled().
61  *
62  * <example>
63  * <title>Creating two #GtkToggleButton widgets.</title>
64  * <programlisting>
65  * void make_toggles (void) {
66  *    GtkWidget *dialog, *toggle1, *toggle2;
67  *
68  *    dialog = gtk_dialog_new (<!-- -->);
69  *    toggle1 = gtk_toggle_button_new_with_label ("Hi, i'm a toggle button.");
70  *
71  *    // Makes this toggle button invisible
72  *    gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle1), TRUE);
73  *
74  *    g_signal_connect (toggle1, "toggled",
75  *                      G_CALLBACK (output_state), NULL);
76  *    gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
77  *                        toggle1, FALSE, FALSE, 2);
78  *
79  *    toggle2 = gtk_toggle_button_new_with_label ("Hi, i'm another toggle button.");
80  *    gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle2), FALSE);
81  *    g_signal_connect (toggle2, "toggled",
82  *                      G_CALLBACK (output_state), NULL);
83  *    gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
84  *                        toggle2, FALSE, FALSE, 2);
85  *
86  *    gtk_widget_show_all (dialog);
87  * }
88  * </programlisting>
89  * </example>
90  */
91
92
93 #define DEFAULT_LEFT_POS  4
94 #define DEFAULT_TOP_POS   4
95 #define DEFAULT_SPACING   7
96
97 struct _GtkToggleButtonPrivate
98 {
99   guint active         : 1;
100   guint draw_indicator : 1;
101   guint inconsistent   : 1;
102 };
103
104 enum {
105   TOGGLED,
106   LAST_SIGNAL
107 };
108
109 enum {
110   PROP_0,
111   PROP_ACTIVE,
112   PROP_INCONSISTENT,
113   PROP_DRAW_INDICATOR
114 };
115
116
117 static gint gtk_toggle_button_draw         (GtkWidget            *widget,
118                                             cairo_t              *cr);
119 static gboolean gtk_toggle_button_mnemonic_activate  (GtkWidget            *widget,
120                                                       gboolean              group_cycling);
121 static void gtk_toggle_button_pressed       (GtkButton            *button);
122 static void gtk_toggle_button_released      (GtkButton            *button);
123 static void gtk_toggle_button_clicked       (GtkButton            *button);
124 static void gtk_toggle_button_set_property  (GObject              *object,
125                                              guint                 prop_id,
126                                              const GValue         *value,
127                                              GParamSpec           *pspec);
128 static void gtk_toggle_button_get_property  (GObject              *object,
129                                              guint                 prop_id,
130                                              GValue               *value,
131                                              GParamSpec           *pspec);
132 static void gtk_toggle_button_update_state  (GtkButton            *button);
133
134
135 static void gtk_toggle_button_activatable_interface_init (GtkActivatableIface  *iface);
136 static void gtk_toggle_button_update                 (GtkActivatable       *activatable,
137                                                       GtkAction            *action,
138                                                       const gchar          *property_name);
139 static void gtk_toggle_button_sync_action_properties (GtkActivatable       *activatable,
140                                                       GtkAction            *action);
141
142 static GtkActivatableIface *parent_activatable_iface;
143 static guint                toggle_button_signals[LAST_SIGNAL] = { 0 };
144
145 G_DEFINE_TYPE_WITH_CODE (GtkToggleButton, gtk_toggle_button, GTK_TYPE_BUTTON,
146                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
147                                                 gtk_toggle_button_activatable_interface_init))
148
149 static void
150 gtk_toggle_button_class_init (GtkToggleButtonClass *class)
151 {
152   GObjectClass *gobject_class;
153   GtkWidgetClass *widget_class;
154   GtkButtonClass *button_class;
155
156   gobject_class = G_OBJECT_CLASS (class);
157   widget_class = (GtkWidgetClass*) class;
158   button_class = (GtkButtonClass*) class;
159
160   gobject_class->set_property = gtk_toggle_button_set_property;
161   gobject_class->get_property = gtk_toggle_button_get_property;
162
163   widget_class->draw = gtk_toggle_button_draw;
164   widget_class->mnemonic_activate = gtk_toggle_button_mnemonic_activate;
165
166   button_class->pressed = gtk_toggle_button_pressed;
167   button_class->released = gtk_toggle_button_released;
168   button_class->clicked = gtk_toggle_button_clicked;
169   button_class->enter = gtk_toggle_button_update_state;
170   button_class->leave = gtk_toggle_button_update_state;
171
172   class->toggled = NULL;
173
174   g_object_class_install_property (gobject_class,
175                                    PROP_ACTIVE,
176                                    g_param_spec_boolean ("active",
177                                                          P_("Active"),
178                                                          P_("If the toggle button should be pressed in"),
179                                                          FALSE,
180                                                          GTK_PARAM_READWRITE));
181
182   g_object_class_install_property (gobject_class,
183                                    PROP_INCONSISTENT,
184                                    g_param_spec_boolean ("inconsistent",
185                                                          P_("Inconsistent"),
186                                                          P_("If the toggle button is in an \"in between\" state"),
187                                                          FALSE,
188                                                          GTK_PARAM_READWRITE));
189
190   g_object_class_install_property (gobject_class,
191                                    PROP_DRAW_INDICATOR,
192                                    g_param_spec_boolean ("draw-indicator",
193                                                          P_("Draw Indicator"),
194                                                          P_("If the toggle part of the button is displayed"),
195                                                          FALSE,
196                                                          GTK_PARAM_READWRITE));
197
198   /**
199    * GtkToggleButton::toggled:
200    * @togglebutton: the object which received the signal.
201    *
202    * Should be connected if you wish to perform an action whenever the
203    * #GtkToggleButton's state is changed.
204    */
205   toggle_button_signals[TOGGLED] =
206     g_signal_new (I_("toggled"),
207                   G_OBJECT_CLASS_TYPE (gobject_class),
208                   G_SIGNAL_RUN_FIRST,
209                   G_STRUCT_OFFSET (GtkToggleButtonClass, toggled),
210                   NULL, NULL,
211                   _gtk_marshal_VOID__VOID,
212                   G_TYPE_NONE, 0);
213
214   g_type_class_add_private (class, sizeof (GtkToggleButtonPrivate));
215 }
216
217 static void
218 gtk_toggle_button_init (GtkToggleButton *toggle_button)
219 {
220   GtkToggleButtonPrivate *priv;
221
222   toggle_button->priv = G_TYPE_INSTANCE_GET_PRIVATE (toggle_button,
223                                                      GTK_TYPE_TOGGLE_BUTTON,
224                                                      GtkToggleButtonPrivate);
225   priv = toggle_button->priv;
226
227   priv->active = FALSE;
228   priv->draw_indicator = FALSE;
229   GTK_BUTTON (toggle_button)->priv->depress_on_activate = TRUE;
230 }
231
232 static void
233 gtk_toggle_button_activatable_interface_init (GtkActivatableIface *iface)
234 {
235   parent_activatable_iface = g_type_interface_peek_parent (iface);
236   iface->update = gtk_toggle_button_update;
237   iface->sync_action_properties = gtk_toggle_button_sync_action_properties;
238 }
239
240 static void
241 gtk_toggle_button_update (GtkActivatable *activatable,
242                           GtkAction      *action,
243                           const gchar    *property_name)
244 {
245   GtkToggleButton *button;
246
247   parent_activatable_iface->update (activatable, action, property_name);
248
249   button = GTK_TOGGLE_BUTTON (activatable);
250
251   if (strcmp (property_name, "active") == 0)
252     {
253       gtk_action_block_activate (action);
254       gtk_toggle_button_set_active (button, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
255       gtk_action_unblock_activate (action);
256     }
257
258 }
259
260 static void
261 gtk_toggle_button_sync_action_properties (GtkActivatable *activatable,
262                                           GtkAction      *action)
263 {
264   GtkToggleButton *button;
265
266   parent_activatable_iface->sync_action_properties (activatable, action);
267
268   if (!GTK_IS_TOGGLE_ACTION (action))
269     return;
270
271   button = GTK_TOGGLE_BUTTON (activatable);
272
273   gtk_action_block_activate (action);
274   gtk_toggle_button_set_active (button, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
275   gtk_action_unblock_activate (action);
276 }
277
278 /**
279  * gtk_toggle_button_new:
280  *
281  * Creates a new toggle button. A widget should be packed into the button, as in gtk_button_new().
282  *
283  * Returns: a new toggle button.
284  */
285 GtkWidget*
286 gtk_toggle_button_new (void)
287 {
288   return g_object_new (GTK_TYPE_TOGGLE_BUTTON, NULL);
289 }
290
291 /**
292  * gtk_toggle_button_new_with_label:
293  * @label: a string containing the message to be placed in the toggle button.
294  *
295  * Creates a new toggle button with a text label.
296  *
297  * Returns: a new toggle button.
298  */
299 GtkWidget*
300 gtk_toggle_button_new_with_label (const gchar *label)
301 {
302   return g_object_new (GTK_TYPE_TOGGLE_BUTTON, "label", label, NULL);
303 }
304
305 /**
306  * gtk_toggle_button_new_with_mnemonic:
307  * @label: the text of the button, with an underscore in front of the
308  *         mnemonic character
309  * @returns: a new #GtkToggleButton
310  *
311  * Creates a new #GtkToggleButton containing a label. The label
312  * will be created using gtk_label_new_with_mnemonic(), so underscores
313  * in @label indicate the mnemonic for the button.
314  **/
315 GtkWidget*
316 gtk_toggle_button_new_with_mnemonic (const gchar *label)
317 {
318   return g_object_new (GTK_TYPE_TOGGLE_BUTTON, 
319                        "label", label, 
320                        "use-underline", TRUE, 
321                        NULL);
322 }
323
324 static void
325 gtk_toggle_button_set_property (GObject      *object,
326                                 guint         prop_id,
327                                 const GValue *value,
328                                 GParamSpec   *pspec)
329 {
330   GtkToggleButton *tb;
331
332   tb = GTK_TOGGLE_BUTTON (object);
333
334   switch (prop_id)
335     {
336     case PROP_ACTIVE:
337       gtk_toggle_button_set_active (tb, g_value_get_boolean (value));
338       break;
339     case PROP_INCONSISTENT:
340       gtk_toggle_button_set_inconsistent (tb, g_value_get_boolean (value));
341       break;
342     case PROP_DRAW_INDICATOR:
343       gtk_toggle_button_set_mode (tb, g_value_get_boolean (value));
344       break;
345     default:
346       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
347       break;
348     }
349 }
350
351 static void
352 gtk_toggle_button_get_property (GObject      *object,
353                                 guint         prop_id,
354                                 GValue       *value,
355                                 GParamSpec   *pspec)
356 {
357   GtkToggleButton *tb = GTK_TOGGLE_BUTTON (object);
358   GtkToggleButtonPrivate *priv = tb->priv;
359
360   switch (prop_id)
361     {
362     case PROP_ACTIVE:
363       g_value_set_boolean (value, priv->active);
364       break;
365     case PROP_INCONSISTENT:
366       g_value_set_boolean (value, priv->inconsistent);
367       break;
368     case PROP_DRAW_INDICATOR:
369       g_value_set_boolean (value, priv->draw_indicator);
370       break;
371     default:
372       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
373       break;
374     }
375 }
376
377 /**
378  * gtk_toggle_button_set_mode:
379  * @toggle_button: a #GtkToggleButton
380  * @draw_indicator: if %TRUE, draw the button as a separate indicator
381  * and label; if %FALSE, draw the button like a normal button
382  *
383  * Sets whether the button is displayed as a separate indicator and label.
384  * You can call this function on a checkbutton or a radiobutton with
385  * @draw_indicator = %FALSE to make the button look like a normal button
386  *
387  * This function only affects instances of classes like #GtkCheckButton
388  * and #GtkRadioButton that derive from #GtkToggleButton,
389  * not instances of #GtkToggleButton itself.
390  */
391 void
392 gtk_toggle_button_set_mode (GtkToggleButton *toggle_button,
393                             gboolean         draw_indicator)
394 {
395   GtkToggleButtonPrivate *priv;
396
397   g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
398
399   priv = toggle_button->priv;
400
401   draw_indicator = draw_indicator ? TRUE : FALSE;
402
403   if (priv->draw_indicator != draw_indicator)
404     {
405       GtkStyleContext *context;
406
407       priv->draw_indicator = draw_indicator;
408       GTK_BUTTON (toggle_button)->priv->depress_on_activate = !draw_indicator;
409
410       if (gtk_widget_get_visible (GTK_WIDGET (toggle_button)))
411         gtk_widget_queue_resize (GTK_WIDGET (toggle_button));
412
413       g_object_notify (G_OBJECT (toggle_button), "draw-indicator");
414
415       /* Make toggle buttons conditionally have the "button"
416        * class depending on draw_indicator.
417        */
418       context = gtk_widget_get_style_context (GTK_WIDGET (toggle_button));
419
420       if (draw_indicator)
421         gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BUTTON);
422       else
423         gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
424     }
425 }
426
427 /**
428  * gtk_toggle_button_get_mode:
429  * @toggle_button: a #GtkToggleButton
430  *
431  * Retrieves whether the button is displayed as a separate indicator
432  * and label. See gtk_toggle_button_set_mode().
433  *
434  * Return value: %TRUE if the togglebutton is drawn as a separate indicator
435  *   and label.
436  **/
437 gboolean
438 gtk_toggle_button_get_mode (GtkToggleButton *toggle_button)
439 {
440   g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button), FALSE);
441
442   return toggle_button->priv->draw_indicator;
443 }
444
445 /**
446  * gtk_toggle_button_set_active:
447  * @toggle_button: a #GtkToggleButton.
448  * @is_active: %TRUE or %FALSE.
449  *
450  * Sets the status of the toggle button. Set to %TRUE if you want the
451  * GtkToggleButton to be 'pressed in', and %FALSE to raise it.
452  * This action causes the toggled signal to be emitted.
453  */
454 void
455 gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
456                               gboolean         is_active)
457 {
458   GtkToggleButtonPrivate *priv;
459
460   g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
461
462   priv = toggle_button->priv;
463
464   is_active = is_active != FALSE;
465
466   if (priv->active != is_active)
467     gtk_button_clicked (GTK_BUTTON (toggle_button));
468 }
469
470 void
471 _gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
472                                gboolean         is_active)
473 {
474   toggle_button->priv->active = is_active;
475 }
476
477 /**
478  * gtk_toggle_button_get_active:
479  * @toggle_button: a #GtkToggleButton.
480  *
481  * Queries a #GtkToggleButton and returns its current state. Returns %TRUE if
482  * the toggle button is pressed in and %FALSE if it is raised.
483  *
484  * Returns: a #gboolean value.
485  */
486 gboolean
487 gtk_toggle_button_get_active (GtkToggleButton *toggle_button)
488 {
489   g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button), FALSE);
490
491   return toggle_button->priv->active;
492 }
493
494 /**
495  * gtk_toggle_button_toggled:
496  * @toggle_button: a #GtkToggleButton.
497  *
498  * Emits the #GtkToggleButton::toggled signal on the
499  * #GtkToggleButton. There is no good reason for an
500  * application ever to call this function.
501  */
502 void
503 gtk_toggle_button_toggled (GtkToggleButton *toggle_button)
504 {
505   g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
506
507   g_signal_emit (toggle_button, toggle_button_signals[TOGGLED], 0);
508 }
509
510 /**
511  * gtk_toggle_button_set_inconsistent:
512  * @toggle_button: a #GtkToggleButton
513  * @setting: %TRUE if state is inconsistent
514  *
515  * If the user has selected a range of elements (such as some text or
516  * spreadsheet cells) that are affected by a toggle button, and the
517  * current values in that range are inconsistent, you may want to
518  * display the toggle in an "in between" state. This function turns on
519  * "in between" display.  Normally you would turn off the inconsistent
520  * state again if the user toggles the toggle button. This has to be
521  * done manually, gtk_toggle_button_set_inconsistent() only affects
522  * visual appearance, it doesn't affect the semantics of the button.
523  * 
524  **/
525 void
526 gtk_toggle_button_set_inconsistent (GtkToggleButton *toggle_button,
527                                     gboolean         setting)
528 {
529   GtkToggleButtonPrivate *priv;
530
531   g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
532
533   priv = toggle_button->priv;
534
535   setting = setting != FALSE;
536
537   if (setting != priv->inconsistent)
538     {
539       priv->inconsistent = setting;
540
541       gtk_toggle_button_update_state (GTK_BUTTON (toggle_button));
542       gtk_widget_queue_draw (GTK_WIDGET (toggle_button));
543
544       g_object_notify (G_OBJECT (toggle_button), "inconsistent");      
545     }
546 }
547
548 /**
549  * gtk_toggle_button_get_inconsistent:
550  * @toggle_button: a #GtkToggleButton
551  * 
552  * Gets the value set by gtk_toggle_button_set_inconsistent().
553  * 
554  * Return value: %TRUE if the button is displayed as inconsistent, %FALSE otherwise
555  **/
556 gboolean
557 gtk_toggle_button_get_inconsistent (GtkToggleButton *toggle_button)
558 {
559   g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button), FALSE);
560
561   return toggle_button->priv->inconsistent;
562 }
563
564 static gint
565 gtk_toggle_button_draw (GtkWidget *widget,
566                         cairo_t   *cr)
567 {
568   GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (widget);
569   GtkToggleButtonPrivate *priv = toggle_button->priv;
570   GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
571   GtkButton *button = GTK_BUTTON (widget);
572   GtkStateType state;
573
574   state = gtk_widget_get_state_flags (widget);
575
576   if (priv->inconsistent)
577     state |= GTK_STATE_FLAG_INCONSISTENT;
578   else if (button->priv->depressed)
579     state |= GTK_STATE_FLAG_ACTIVE;
580
581   _gtk_button_paint (button, cr,
582                      gtk_widget_get_allocated_width (widget),
583                      gtk_widget_get_allocated_height (widget),
584                      state);
585
586   if (child)
587     gtk_container_propagate_draw (GTK_CONTAINER (widget), child, cr);
588
589   return FALSE;
590 }
591
592 static gboolean
593 gtk_toggle_button_mnemonic_activate (GtkWidget *widget,
594                                      gboolean   group_cycling)
595 {
596   /*
597    * We override the standard implementation in 
598    * gtk_widget_real_mnemonic_activate() in order to focus the widget even
599    * if there is no mnemonic conflict.
600    */
601   if (gtk_widget_get_can_focus (widget))
602     gtk_widget_grab_focus (widget);
603
604   if (!group_cycling)
605     gtk_widget_activate (widget);
606
607   return TRUE;
608 }
609
610 static void
611 gtk_toggle_button_pressed (GtkButton *button)
612 {
613   button->priv->button_down = TRUE;
614
615   gtk_toggle_button_update_state (button);
616   gtk_widget_queue_draw (GTK_WIDGET (button));
617 }
618
619 static void
620 gtk_toggle_button_released (GtkButton *button)
621 {
622   if (button->priv->button_down)
623     {
624       button->priv->button_down = FALSE;
625
626       if (button->priv->in_button)
627         gtk_button_clicked (button);
628
629       gtk_toggle_button_update_state (button);
630       gtk_widget_queue_draw (GTK_WIDGET (button));
631     }
632 }
633
634 static void
635 gtk_toggle_button_clicked (GtkButton *button)
636 {
637   GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
638   GtkToggleButtonPrivate *priv = toggle_button->priv;
639
640   priv->active = !priv->active;
641
642   gtk_toggle_button_toggled (toggle_button);
643
644   gtk_toggle_button_update_state (button);
645
646   g_object_notify (G_OBJECT (toggle_button), "active");
647
648   if (GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked)
649     GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked (button);
650 }
651
652 static void
653 gtk_toggle_button_update_state (GtkButton *button)
654 {
655   GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
656   GtkToggleButtonPrivate *priv = toggle_button->priv;
657   gboolean depressed, touchscreen;
658   GtkStateFlags new_state = 0;
659
660   g_object_get (gtk_widget_get_settings (GTK_WIDGET (button)),
661                 "gtk-touchscreen-mode", &touchscreen,
662                 NULL);
663
664   new_state = gtk_widget_get_state_flags (GTK_WIDGET (button)) &
665     ~(GTK_STATE_FLAG_INCONSISTENT |
666       GTK_STATE_FLAG_PRELIGHT |
667       GTK_STATE_FLAG_ACTIVE);
668
669   if (priv->inconsistent)
670     new_state |= GTK_STATE_FLAG_INCONSISTENT;
671
672   if (priv->inconsistent)
673     depressed = FALSE;
674   else if (button->priv->in_button && button->priv->button_down)
675     depressed = TRUE;
676   else
677     depressed = priv->active;
678
679   if (!touchscreen && button->priv->in_button && (!button->priv->button_down || priv->draw_indicator))
680     new_state |= GTK_STATE_FLAG_PRELIGHT;
681
682   if (depressed)
683     new_state |= GTK_STATE_FLAG_ACTIVE;
684
685   _gtk_button_set_depressed (button, depressed);
686   gtk_widget_set_state_flags (GTK_WIDGET (toggle_button), new_state, TRUE);
687 }