/** * gtk_switch_set_state: * @sw: a #GtkSwitch * @state: the new state * * Sets the underlying state of the #GtkSwitch. * * Normally, this is the same as #GtkSwitch:active, unless the switch * is set up for delayed state changes. This function is typically * called from a #GtkSwitch::state-set signal handler. * * See #GtkSwitch::state-set for details. * * Since: 3.14 */ void gtk_switch_set_state (GtkSwitch *sw, gboolean state) { g_return_if_fail (GTK_IS_SWITCH (sw)); state = state != FALSE; if (sw->priv->state == state) return; sw->priv->state = state; /* This will be a no-op if we're switching the state in response * to a UI change. We're setting active anyway, to catch 'spontaneous' * state changes. */ gtk_switch_set_active (sw, state); if (state) gtk_widget_set_state_flags (GTK_WIDGET (sw), GTK_STATE_FLAG_CHECKED, FALSE); else gtk_widget_unset_state_flags (GTK_WIDGET (sw), GTK_STATE_FLAG_CHECKED); g_object_notify (G_OBJECT (sw), "state"); }
/** * gtk_switch_get_active: * @sw: a #GtkSwitch * * Gets whether the #GtkSwitch is in its “on” or “off” state. * * Returns: %TRUE if the #GtkSwitch is active, and %FALSE otherwise * * Since: 3.0 */ gboolean gtk_switch_get_active (GtkSwitch *sw) { g_return_val_if_fail (GTK_IS_SWITCH (sw), FALSE); return sw->priv->is_active; }
static void ide_editor_spell_widget__highlight_switch_toggled_cb (IdeEditorSpellWidget *self, gboolean state, GtkSwitch *switch_button) { GspellTextView *spell_text_view; g_assert (IDE_IS_EDITOR_SPELL_WIDGET (self)); g_assert (GTK_IS_SWITCH (switch_button)); gtk_switch_set_state (switch_button, state); spell_text_view = gspell_text_view_get_from_gtk_text_view (GTK_TEXT_VIEW (self->view)); gspell_text_view_set_inline_spell_checking (spell_text_view, state); }
static void on_gsettings_changed (GSettings *settings, gchar *key, GtkWidget *widget) { if (GTK_IS_SWITCH (widget)) { gboolean active1 = g_settings_get_boolean (settings, key); gboolean active2 = gtk_switch_get_active (GTK_SWITCH (widget)); if (active1 != active2) gtk_switch_set_active (GTK_SWITCH (widget), active1); } else if (GTK_IS_COMBO_BOX (widget)) { gchar *id; gboolean retval; id = g_settings_get_string (settings, key); retval = gtk_combo_box_set_active_id (GTK_COMBO_BOX (widget), id); if (retval == FALSE && g_strcmp0 (key, "default-engine") == 0) g_settings_set_string (settings, key, "nimf-system-keyboard"); g_free (id); } else if (GTK_IS_TREE_VIEW (widget)) { GtkTreeModel *model; gchar **vals; GtkTreeIter iter; gint i; vals = g_settings_get_strv (settings, key); model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); gtk_list_store_clear (GTK_LIST_STORE (model)); for (i = 0; vals[i] != NULL; i++) { gtk_list_store_append (GTK_LIST_STORE (model), &iter); gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, vals[i], -1); } g_strfreev (vals); } }
/** * gtk_switch_set_active: * @sw: a #GtkSwitch * @is_active: %TRUE if @sw should be active, and %FALSE otherwise * * Changes the state of @sw to the desired one. * * Since: 3.0 */ void gtk_switch_set_active (GtkSwitch *sw, gboolean is_active) { GtkSwitchPrivate *priv; g_return_if_fail (GTK_IS_SWITCH (sw)); is_active = !!is_active; priv = sw->priv; if (priv->is_active != is_active) { AtkObject *accessible; GtkWidget *widget; GtkStyleContext *context; widget = GTK_WIDGET (sw); priv->is_active = is_active; g_object_notify_by_pspec (G_OBJECT (sw), switch_props[PROP_ACTIVE]); if (priv->action) gtk_action_activate (priv->action); accessible = gtk_widget_get_accessible (GTK_WIDGET (sw)); atk_object_notify_state_change (accessible, ATK_STATE_CHECKED, priv->is_active); if (gtk_widget_get_realized (widget)) { context = gtk_widget_get_style_context (widget); gtk_style_context_notify_state_change (context, gtk_widget_get_window (widget), NULL, GTK_STATE_ACTIVE, is_active); } gtk_widget_queue_draw (GTK_WIDGET (sw)); } }
/** * gtk_switch_set_active: * @sw: a #GtkSwitch * @is_active: %TRUE if @sw should be active, and %FALSE otherwise * * Changes the state of @sw to the desired one. * * Since: 3.0 */ void gtk_switch_set_active (GtkSwitch *sw, gboolean is_active) { GtkSwitchPrivate *priv; g_return_if_fail (GTK_IS_SWITCH (sw)); is_active = !!is_active; priv = sw->priv; if (priv->is_active != is_active) { AtkObject *accessible; priv->is_active = is_active; g_object_notify_by_pspec (G_OBJECT (sw), switch_props[PROP_ACTIVE]); if (priv->action_helper) gtk_action_helper_activate (priv->action_helper); G_GNUC_BEGIN_IGNORE_DEPRECATIONS; if (priv->action) gtk_action_activate (priv->action); G_GNUC_END_IGNORE_DEPRECATIONS; accessible = gtk_widget_get_accessible (GTK_WIDGET (sw)); atk_object_notify_state_change (accessible, ATK_STATE_CHECKED, priv->is_active); if (priv->is_active) gtk_widget_set_state_flags (GTK_WIDGET (sw), GTK_STATE_FLAG_ACTIVE, FALSE); else gtk_widget_unset_state_flags (GTK_WIDGET (sw), GTK_STATE_FLAG_ACTIVE); gtk_widget_queue_draw (GTK_WIDGET (sw)); } }
/** * gtk_switch_set_active: * @sw: a #GtkSwitch * @is_active: %TRUE if @sw should be active, and %FALSE otherwise * * Changes the state of @sw to the desired one. * * Since: 3.0 */ void gtk_switch_set_active (GtkSwitch *sw, gboolean is_active) { GtkSwitchPrivate *priv; g_return_if_fail (GTK_IS_SWITCH (sw)); gtk_switch_end_toggle_animation (sw); is_active = !!is_active; priv = sw->priv; if (priv->is_active != is_active) { AtkObject *accessible; gboolean handled; priv->is_active = is_active; if (priv->is_active) priv->handle_pos = 1.0; else priv->handle_pos = 0.0; g_signal_emit (sw, signals[STATE_SET], 0, is_active, &handled); g_object_notify_by_pspec (G_OBJECT (sw), switch_props[PROP_ACTIVE]); accessible = gtk_widget_get_accessible (GTK_WIDGET (sw)); atk_object_notify_state_change (accessible, ATK_STATE_CHECKED, priv->is_active); gtk_widget_queue_allocate (GTK_WIDGET (sw)); } }