* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Author:
* Emmanuele Bassi <ebassi@linux.intel.com>
#include "gtkapplicationprivate.h"
#include "gtkactionable.h"
#include "a11y/gtkswitchaccessible.h"
+#include "gtkactionhelper.h"
#include <math.h>
{
GdkWindow *event_window;
GtkAction *action;
-
- gchar *action_name;
- GVariant *action_target;
- GSimpleActionObserver *action_observer;
+ GtkActionHelper *action_helper;
gint handle_x;
gint offset;
static GParamSpec *switch_props[LAST_PROP] = { NULL, };
-static void gtk_switch_hierarchy_changed (GtkWidget *widget,
- GtkWidget *previous_toplevel);
-
static void gtk_switch_actionable_iface_init (GtkActionableInterface *iface);
static void gtk_switch_activatable_interface_init (GtkActivatableIface *iface);
gint *minimum,
gint *natural)
{
- GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding;
PangoRectangle logical_rect;
context = gtk_widget_get_style_context (widget);
- state = gtk_widget_get_state_flags (widget);
-
- if (priv->is_active)
- state |= GTK_STATE_FLAG_ACTIVE;
+ state = gtk_style_context_get_state (context);
gtk_style_context_save (context);
- gtk_style_context_set_state (context, state);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER);
gtk_style_context_get_padding (context, state, &padding);
gint *minimum,
gint *natural)
{
- GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding;
gchar *str;
context = gtk_widget_get_style_context (widget);
- state = gtk_widget_get_state_flags (widget);
-
- if (priv->is_active)
- state |= GTK_STATE_FLAG_ACTIVE;
+ state = gtk_style_context_get_state (context);
gtk_style_context_save (context);
- gtk_style_context_set_state (context, state);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER);
gtk_style_context_get_padding (context, state, &padding);
cairo_t *cr,
GdkRectangle *box)
{
- GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
GtkStyleContext *context = gtk_widget_get_style_context (widget);
- GtkStateFlags state;
-
- state = gtk_widget_get_state_flags (widget);
-
- if (priv->is_active)
- state |= GTK_STATE_FLAG_ACTIVE;
gtk_style_context_save (context);
- gtk_style_context_set_state (context, state);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER);
gtk_render_slider (context, cr,
const PangoFontDescription *style_desc;
PangoRectangle rect;
gint label_x, label_y;
- GtkStateFlags state;
GtkBorder padding;
+ GtkStateFlags state;
gint focus_width, focus_pad;
gint x, y, width, height;
gint font_size, style_font_size;
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
- if (priv->is_active)
- state |= GTK_STATE_FLAG_ACTIVE;
-
gtk_style_context_save (context);
- gtk_style_context_set_state (context, state);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER);
gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);
- gtk_style_context_set_state (context, state);
gtk_render_background (context, cr, x, y, width, height);
gtk_render_frame (context, cr, x, y, width, height);
}
}
-static void
-gtk_switch_update_action_observer (GtkSwitch *sw)
-{
- GtkWidget *window;
-
- /* we are the only owner so this will clear all the signals */
- g_clear_object (&sw->priv->action_observer);
-
- window = gtk_widget_get_toplevel (GTK_WIDGET (sw));
-
- if (GTK_IS_APPLICATION_WINDOW (window) && sw->priv->action_name)
- {
- GSimpleActionObserver *observer;
-
- observer = gtk_application_window_get_observer (GTK_APPLICATION_WINDOW (window),
- sw->priv->action_name,
- sw->priv->action_target);
-
- if (g_object_class_find_property (G_OBJECT_GET_CLASS (sw), "active"))
- g_object_bind_property (observer, "active", sw, "active", G_BINDING_SYNC_CREATE);
- g_object_bind_property (observer, "enabled", sw, "sensitive", G_BINDING_SYNC_CREATE);
-
- sw->priv->action_observer = observer;
- }
-}
-
static void
gtk_switch_set_action_name (GtkActionable *actionable,
const gchar *action_name)
{
GtkSwitch *sw = GTK_SWITCH (actionable);
- g_return_if_fail (GTK_IS_SWITCH (sw));
-
- if (g_strcmp0 (action_name, sw->priv->action_name) != 0)
- {
- g_free (sw->priv->action_name);
- sw->priv->action_name = g_strdup (action_name);
-
- gtk_switch_update_action_observer (sw);
+ if (!sw->priv->action_helper)
+ sw->priv->action_helper = gtk_action_helper_new (actionable);
- g_object_notify (G_OBJECT (sw), "action-name");
- }
+ gtk_action_helper_set_action_name (sw->priv->action_helper, action_name);
}
static void
{
GtkSwitch *sw = GTK_SWITCH (actionable);
- g_return_if_fail (GTK_IS_SWITCH (sw));
+ if (!sw->priv->action_helper)
+ sw->priv->action_helper = gtk_action_helper_new (actionable);
- if (action_target != sw->priv->action_target &&
- (!action_target || !sw->priv->action_target ||
- !g_variant_equal (action_target, sw->priv->action_target)))
- {
- if (sw->priv->action_target)
- g_variant_unref (sw->priv->action_target);
-
- sw->priv->action_target = NULL;
-
- if (action_target)
- sw->priv->action_target = g_variant_ref_sink (action_target);
-
- gtk_switch_update_action_observer (sw);
-
- g_object_notify (G_OBJECT (sw), "action-target");
- }
+ gtk_action_helper_set_action_target_value (sw->priv->action_helper, action_target);
}
static const gchar *
{
GtkSwitch *sw = GTK_SWITCH (actionable);
- return sw->priv->action_name;
+ return gtk_action_helper_get_action_name (sw->priv->action_helper);
}
static GVariant *
{
GtkSwitch *sw = GTK_SWITCH (actionable);
- return sw->priv->action_target;
+ return gtk_action_helper_get_action_target_value (sw->priv->action_helper);
}
static void
iface->set_action_target_value = gtk_switch_set_action_target_value;
}
-static void
-gtk_switch_hierarchy_changed (GtkWidget *widget,
- GtkWidget *previous_toplevel)
-{
- GtkSwitch *sw = GTK_SWITCH (widget);
- GtkWidgetClass *parent_class;
-
- parent_class = GTK_WIDGET_CLASS (gtk_switch_parent_class);
- if (parent_class->hierarchy_changed)
- parent_class->hierarchy_changed (widget, previous_toplevel);
-
- if (sw->priv->action_name)
- {
- GtkWidget *toplevel;
-
- toplevel = gtk_widget_get_toplevel (widget);
-
- if (toplevel != previous_toplevel)
- gtk_switch_update_action_observer (sw);
- }
-}
-
static void
gtk_switch_set_property (GObject *gobject,
guint prop_id,
break;
case PROP_ACTION_NAME:
- g_value_set_string (value, priv->action_name);
+ g_value_set_string (value, gtk_action_helper_get_action_name (priv->action_helper));
break;
case PROP_ACTION_TARGET:
- g_value_set_variant (value, priv->action_target);
+ g_value_set_variant (value, gtk_action_helper_get_action_target_value (priv->action_helper));
break;
default:
{
GtkSwitchPrivate *priv = GTK_SWITCH (object)->priv;
- g_clear_object (&priv->action_observer);
-
- if (priv->action_name)
- {
- g_free (priv->action_name);
- priv->action_name = NULL;
- }
+ g_clear_object (&priv->action_helper);
if (priv->action)
{
widget_class->motion_notify_event = gtk_switch_motion;
widget_class->enter_notify_event = gtk_switch_enter;
widget_class->leave_notify_event = gtk_switch_leave;
- widget_class->hierarchy_changed = gtk_switch_hierarchy_changed;
klass->activate = gtk_switch_activate;
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_observer)
- g_simple_action_observer_activate (priv->action_observer);
+ if (priv->action_helper)
+ gtk_action_helper_activate (priv->action_helper);
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);
- }
+ 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));
}