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