#include "gtkintl.h"
#include "gtkprivate.h"
#include <gdk/gdkkeysyms.h>
+#include "gtkdnd.h"
#include "gtkalias.h"
#define GTK_EXPANDER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_EXPANDER, GtkExpanderPrivate))
GtkExpanderStyle expander_style;
guint animation_timeout;
+ guint expand_timer;
guint expanded : 1;
guint use_underline : 1;
guint prelight : 1;
};
-static void gtk_expander_class_init (GtkExpanderClass *klass);
-static void gtk_expander_init (GtkExpander *expander);
-
static void gtk_expander_set_property (GObject *object,
guint prop_id,
const GValue *value,
gboolean was_grabbed);
static void gtk_expander_state_changed (GtkWidget *widget,
GtkStateType previous_state);
+static gboolean gtk_expander_drag_motion (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time);
+static void gtk_expander_drag_leave (GtkWidget *widget,
+ GdkDragContext *context,
+ guint time);
static void gtk_expander_add (GtkContainer *container,
GtkWidget *widget);
static void get_expander_bounds (GtkExpander *expander,
GdkRectangle *rect);
-static GtkBinClass *parent_class = NULL;
-
-GType
-gtk_expander_get_type (void)
-{
- static GType expander_type = 0;
-
- if (!expander_type)
- {
- static const GTypeInfo expander_info =
- {
- sizeof (GtkExpanderClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_expander_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkExpander),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_expander_init,
- };
-
- expander_type = g_type_register_static (GTK_TYPE_BIN,
- I_("GtkExpander"),
- &expander_info, 0);
- }
-
- return expander_type;
-}
+G_DEFINE_TYPE (GtkExpander, gtk_expander, GTK_TYPE_BIN)
static void
gtk_expander_class_init (GtkExpanderClass *klass)
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
- parent_class = g_type_class_peek_parent (klass);
-
gobject_class = (GObjectClass *) klass;
object_class = (GtkObjectClass *) klass;
widget_class = (GtkWidgetClass *) klass;
widget_class->focus = gtk_expander_focus;
widget_class->grab_notify = gtk_expander_grab_notify;
widget_class->state_changed = gtk_expander_state_changed;
+ widget_class->drag_motion = gtk_expander_drag_motion;
+ widget_class->drag_leave = gtk_expander_drag_leave;
container_class->add = gtk_expander_add;
container_class->remove = gtk_expander_remove;
priv->use_markup = FALSE;
priv->button_down = FALSE;
priv->prelight = FALSE;
+ priv->expand_timer = 0;
+
+ gtk_drag_dest_set (GTK_WIDGET (expander), 0, NULL, 0, 0);
+ gtk_drag_dest_set_track_motion (GTK_WIDGET (expander), TRUE);
}
static void
priv->animation_timeout = 0;
}
- GTK_OBJECT_CLASS (parent_class)->destroy (object);
+ GTK_OBJECT_CLASS (gtk_expander_parent_class)->destroy (object);
}
static void
priv->event_window = NULL;
}
- GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
+ GTK_WIDGET_CLASS (gtk_expander_parent_class)->unrealize (widget);
}
static void
if (priv->label_widget)
gtk_widget_map (priv->label_widget);
- GTK_WIDGET_CLASS (parent_class)->map (widget);
+ GTK_WIDGET_CLASS (gtk_expander_parent_class)->map (widget);
if (priv->event_window)
gdk_window_show (priv->event_window);
if (priv->event_window)
gdk_window_hide (priv->event_window);
- GTK_WIDGET_CLASS (parent_class)->unmap (widget);
+ GTK_WIDGET_CLASS (gtk_expander_parent_class)->unmap (widget);
if (priv->label_widget)
gtk_widget_unmap (priv->label_widget);
ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL;
- x = widget->allocation.x + border_width;
- y = widget->allocation.y + border_width;
-
- if (ltr && interior_focus)
- x += expander_spacing * 2 + expander_size;
-
width = height = 0;
if (priv->label_widget && GTK_WIDGET_VISIBLE (priv->label_widget))
height = label_allocation.height;
}
+ width += 2 * focus_pad + 2 * focus_width;
+ height += 2 * focus_pad + 2 * focus_width;
+
+ x = widget->allocation.x + border_width;
+ y = widget->allocation.y + border_width;
+
+ if (ltr)
+ {
+ if (interior_focus)
+ x += expander_spacing * 2 + expander_size;
+ }
+ else
+ {
+ x += widget->allocation.width - 2 * border_width
+ - expander_spacing * 2 - expander_size - width;
+ }
+
if (!interior_focus)
{
width += expander_size + 2 * expander_spacing;
height = MAX (height, expander_size + 2 * expander_spacing);
}
- width += 2 * focus_pad + 2 * focus_width;
- height += 2 * focus_pad + 2 * focus_width;
-
gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
area, widget, "expander",
x, y, width, height);
if (GTK_WIDGET_HAS_FOCUS (expander))
gtk_expander_paint_focus (expander, &event->area);
- GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
+ GTK_WIDGET_CLASS (gtk_expander_parent_class)->expose_event (widget, event);
}
return FALSE;
return FALSE;
}
+static gboolean
+expand_timeout (gpointer data)
+{
+ GtkExpander *expander = GTK_EXPANDER (data);
+ GtkExpanderPrivate *priv = expander->priv;
+
+ priv->expand_timer = 0;
+ gtk_expander_set_expanded (expander, TRUE);
+
+ return FALSE;
+}
+
+static gboolean
+gtk_expander_drag_motion (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time)
+{
+ GtkExpander *expander = GTK_EXPANDER (widget);
+ GtkExpanderPrivate *priv = expander->priv;
+
+ if (!priv->expanded && !priv->expand_timer)
+ {
+ GtkSettings *settings;
+ guint timeout;
+
+ settings = gtk_widget_get_settings (widget);
+ g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
+
+ priv->expand_timer = g_timeout_add (timeout, (GSourceFunc) expand_timeout, expander);
+ }
+
+ return TRUE;
+}
+
+static void
+gtk_expander_drag_leave (GtkWidget *widget,
+ GdkDragContext *context,
+ guint time)
+{
+ GtkExpander *expander = GTK_EXPANDER (widget);
+ GtkExpanderPrivate *priv = expander->priv;
+
+ if (priv->expand_timer)
+ {
+ g_source_remove (priv->expand_timer);
+ priv->expand_timer = 0;
+ }
+}
+
typedef enum
{
FOCUS_NONE,
gtk_expander_add (GtkContainer *container,
GtkWidget *widget)
{
- GTK_CONTAINER_CLASS (parent_class)->add (container, widget);
+ GTK_CONTAINER_CLASS (gtk_expander_parent_class)->add (container, widget);
gtk_widget_set_child_visible (widget, GTK_EXPANDER (container)->priv->expanded);
gtk_widget_queue_resize (GTK_WIDGET (container));
if (GTK_EXPANDER (expander)->priv->label_widget == widget)
gtk_expander_set_label_widget (expander, NULL);
else
- GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
+ GTK_CONTAINER_CLASS (gtk_expander_parent_class)->remove (container, widget);
}
static void
gtk_expander_set_expanded (expander, !expander->priv->expanded);
}
-
/**
* gtk_expander_new:
* @label: the text of the label
if (priv->expanded != expanded)
{
+ GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (expander));
+ gboolean enable_animations;
+
priv->expanded = expanded;
- if (GTK_WIDGET_REALIZED (expander))
+ g_object_get (settings, "gtk-enable-animations", &enable_animations, NULL);
+
+ if (enable_animations && GTK_WIDGET_REALIZED (expander))
{
gtk_expander_start_animation (expander);
}
- else
+ else
{
priv->expander_style = expanded ? GTK_EXPANDER_EXPANDED :
GTK_EXPANDER_COLLAPSED;