* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#undef GDK_DISABLE_DEPRECATED /* gdk_input_set_extension_events() */
#include "gtkrc.h"
#include "gtkselection.h"
#include "gtksettings.h"
-#include "gtksizegroup.h"
+#include "gtksizegroup-private.h"
#include "gtkwidget.h"
+#include "gtkwidgetprivate.h"
#include "gtkwindow.h"
#include "gtkbindings.h"
#include "gtkprivate.h"
#include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
#include <gobject/gvaluecollector.h>
#include <gobject/gobjectnotifyqueue.c>
+#include <cairo-gobject.h>
#include "gdk/gdkkeysyms.h"
#include "gtkaccessible.h"
#include "gtktooltip.h"
#include "gtkbuildable.h"
#include "gtkbuilderprivate.h"
#include "gtksizerequest.h"
+#include "gtkdebug.h"
/**
* GtkWidget is the base class all widgets in GTK+ derive from. It manages the
* widget lifecycle, states and style.
*
+ * <refsect2 id="geometry-management">
+ * <title>Height-for-width Geometry Management</title>
+ * <para>
+ * GTK+ uses a height-for-width (and width-for-height) geometry management
+ * system Height-for-width means that a widget can change how much
+ * vertical space it needs, depending on the amount of horizontal space
+ * that it is given (and similar for width-for-height). The most common
+ * example is a label that reflows to fill up the available width, wraps
+ * to fewer lines, and therefore needs less height.
+ *
+ * Height-for-width geometry management is implemented in GTK+ by way
+ * of five virtual methods:
+ * <variablelist>
+ * <varlistentry>
+ * <term>#GtkWidgetClass.get_request_mode()</term>
+ * <listitem>
+ * This allows a widget to tell it's parent container whether
+ * it preferrs to be allocated in %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH
+ * or %GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT mode.
+ * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH means the widget prefers to
+ * have #GtkWidgetClass.get_preferred_width() called and then
+ * #GtkWidgetClass.get_preferred_height_for_width() and is the
+ * default return for unimplemented cases.
+ * However it's important to note (as described below) that any
+ * widget which trades height-for-width must respond properly to
+ * both #GtkSizeRequestModes since it might be queried in either
+ * orientation by it's parent container.
+ * </listitem>
+ * </varlistentry>
+ * <varlistentry>
+ * <term>#GtkWidgetClass.get_preferred_width()</term>
+ * <listitem>
+ * This is called by containers to obtain the minimum and
+ * natural width of a widget. A widget will never be allocated
+ * a width less than it's minimum and will only ever be allocated
+ * a width greater than the natural width once all of the said
+ * widget's siblings have received their natural widths.
+ * Furthermore a widget will only ever be allocated a width greater
+ * than it's natural width if it was configured to receive extra
+ * expand space from it's parent container.
+ * </listitem>
+ * </varlistentry>
+ * <varlistentry>
+ * <term>#GtkWidgetClass.get_preferred_height()</term>
+ * <listitem>
+ * This is called by containers to obtain the minimum and
+ * natural height of a widget.
+ * A widget that does not actually trade any height for width
+ * or width for height only has to implement these two virtual
+ * methods (#GtkWidgetClass.get_preferred_width() and
+ * #GtkWidgetClass.get_preferred_height()).
+ * </listitem>
+ * </varlistentry>
+ * <varlistentry>
+ * <term>#GtkWidgetClass.get_preferred_height_for_width()</term>
+ * <listitem>
+ * This is similar to #GtkWidgetClass.get_preferred_height() except
+ * that it is passed a contextual width to request height for. By
+ * implementing this virtual method it is possible for a #GtkLabel
+ * to tell it's parent how much height would be required if the
+ * label were to be allocated a said width.
+ * </listitem>
+ * </varlistentry>
+ * <varlistentry>
+ * <term>#GtkWidgetClass.get_preferred_width_for_height()</term>
+ * <listitem>
+ * This is analogous to #GtkWidgetClass.get_preferred_height_for_width()
+ * except that it operates in the oposite orientation. It's rare that
+ * a widget actually does %GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT requests
+ * but can happen when for example; a widget or container gets additional
+ * columns to compensate for a smaller allocated height.
+ * </listitem>
+ * </varlistentry>
+ * </variablelist>
+ *
+ * There are some important things to keep in mind when implementing
+ * height-for-width and when using it in container implementations.
+ *
+ * The geometry management system will query a widget hierarchy in
+ * only one orientation at a time. When widgets are initially queried
+ * for their minimum sizes it is generally done in two initial passes
+ * in the #GtkSizeRequestMode chosen by the toplevel.
+ *
+ * For example, when queried in the normal
+ * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
+ * First, the default minimum and natural width for each widget
+ * in the interface will be computed using gtk_width_get_preferred_width().
+ * Because the preferred widths for each container depends on the preferred
+ * widths of thier children, this information propagates up the hierarchy,
+ * and finally a minimum and natural width is determined for the entire
+ * toplevel. Next, the toplevel will use the minimum width to query for the
+ * minimum height contextual to that width using
+ * gtk_widget_get_preferred_height_for_width(), which will also be a highly
+ * recursive operation. The minimum height for the minimum width is normally
+ * used to set the minimum size constraint on the toplevel
+ * (unless gtk_window_set_geometry_hints() is explicitly used instead).
+ *
+ * After the toplevel window has initially requested it's size in both
+ * dimensions it can go on to allocate itself a reasonable size (or a size
+ * previously specified with gtk_window_set_default_size()). During the
+ * recursive allocation process it's important to note that request cycles
+ * will be recursively executed while container widgets allocate their children.
+ * Each container widget, once allocated a size will go on to first share the
+ * space in one orientation among its children and then request each child's
+ * height for their target allocated width or width for allocated height
+ * depending. In this way a #GtkWidget will typically be requested its size
+ * a number of times before actually being allocated a size, the size a
+ * widget is finally allocated can of course differ from the size it
+ * requested. For this reason; #GtkWidget caches a small number of results
+ * to avoid re-querying for the same sizes in one allocation cycle.
+ *
+ * See <link linkend="container-geometry-management">GtkContainer's
+ * geometry management section</link>
+ * to learn more about how height-for-width allocations are performed
+ * by container widgets.
+ *
+ * If a widget does move content around to smartly use up the
+ * allocated size, then it must support the request in both
+ * #GtkSizeRequestModes even if the widget in question only
+ * trades sizes in a single orientation.
+ *
+ * For instance, a #GtkLabel that does height-for-width word wrapping
+ * will not expect to have #GtkWidgetClass.get_preferred_height() called
+ * because that call is specific to a width-for-height request. In this
+ * case the label must return the heights required for it's own minimum
+ * possible width. By following this rule any widget that handles
+ * height-for-width or width-for-height requests will always be allocated
+ * at least enough space to fit its own content.
+ *
+ * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
+ * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
+ * it will do:
+ * <programlisting><![CDATA[
+ * static void
+ * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
+ * {
+ * if (i_am_in_height_for_width_mode)
+ * {
+ * gint min_width;
+ *
+ * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
+ * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
+ * min_height, nat_height);
+ * }
+ * else
+ * {
+ * ... some widgets do both, for instance if a GtkLabel is rotated to 90 degrees
+ * it will return the minimum and natural height for the rotated label here.
+ * }
+ * }
+ * ]]></programlisting>
+ *
+ * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
+ * the minimum and natural width:
+ *
+ * <programlisting><![CDATA[
+ * static void
+ * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
+ * gint *min_width, gint *nat_width)
+ * {
+ * if (i_am_in_height_for_width_mode)
+ * {
+ * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
+ * }
+ * else
+ * {
+ * ... again if a widget is sometimes operating in width-for-height mode
+ * (like a rotated GtkLabel) it can go ahead and do it's real width for
+ * height calculation here.
+ * }
+ * }
+ * ]]></programlisting>
+ *
+ * Often a widget needs to get its own request during size request or
+ * allocation, for example when computing height it may need to also
+ * compute width, or when deciding how to use an allocation the widget
+ * may need to know its natural size. In these cases, the widget should
+ * be careful to call its virtual methods directly, like this:
+ * <example>
+ * <title>Widget calling its own size request method.</title>
+ * <programlisting>
+ * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
+ * &min, &natural);
+ * </programlisting>
+ * </example>
+ *
+ * It will not work to use the wrapper functions, such as
+ * gtk_widget_get_preferred_width(), inside your own size request
+ * implementation. These return a request adjusted by #GtkSizeGroup
+ * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
+ * widget used the wrappers inside its virtual method implementations,
+ * then the adjustments (such as widget margins) would be applied
+ * twice. GTK+ therefore does not allow this and will warn if you try
+ * to do it.
+ *
+ * Of course if you are getting the size request for
+ * <emphasis>another</emphasis> widget, such as a child of a
+ * container, you <emphasis>must</emphasis> use the wrapper APIs;
+ * otherwise, you would not properly consider widget margins,
+ * #GtkSizeGroup, and so forth.
+ * </para>
+ * </refsect2>
* <refsect2 id="style-properties">
+ * <title>Style Properties</title>
* <para>
* <structname>GtkWidget</structname> introduces <firstterm>style
* properties</firstterm> - these are basically object properties that are stored
#define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
#define INIT_PATH_SIZE (512)
+struct _GtkWidgetPrivate
+{
+ /* The state of the widget. There are actually only
+ * 5 widget states (defined in "gtkenums.h")
+ * so 3 bits.
+ */
+ guint state : 3;
+
+ /* The saved state of the widget. When a widget's state
+ * is changed to GTK_STATE_INSENSITIVE via
+ * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
+ * the old state is kept around in this field. The state
+ * will be restored once the widget gets sensitive again.
+ */
+ guint saved_state : 3;
+
+ guint direction : 2;
+
+ guint in_destruction : 1;
+ guint toplevel : 1;
+ guint anchored : 1;
+ guint composite_child : 1;
+ guint no_window : 1;
+ guint realized : 1;
+ guint mapped : 1;
+ guint visible : 1;
+ guint sensitive : 1;
+ guint parent_sensitive : 1;
+ guint can_focus : 1;
+ guint has_focus : 1;
+ guint can_default : 1;
+ guint has_default : 1;
+ guint receives_default : 1;
+ guint has_grab : 1;
+ guint shadowed : 1;
+ guint rc_style : 1;
+ guint user_style : 1;
+ guint app_paintable : 1;
+ guint double_buffered : 1;
+ guint redraw_on_alloc : 1;
+ guint no_show_all : 1;
+ guint child_visible : 1;
+ guint multidevice : 1;
+ guint has_shape_mask : 1;
+ guint in_reparent : 1;
+ guint resize_pending : 1;
+ guint alloc_needed : 1;
+ guint width_request_needed : 1;
+ guint height_request_needed : 1;
+
+ /* Expand-related flags */
+ guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
+ guint computed_hexpand : 1; /* computed results (composite of child flags) */
+ guint computed_vexpand : 1;
+ guint hexpand : 1; /* application-forced expand */
+ guint vexpand : 1;
+ guint hexpand_set : 1; /* whether to use application-forced */
+ guint vexpand_set : 1; /* instead of computing from children */
+
+ /* The widget's name. If the widget does not have a name
+ * (the name is NULL), then its name (as returned by
+ * "gtk_widget_get_name") is its class's name.
+ * Among other things, the widget name is used to determine
+ * the style to use for a widget.
+ */
+ gchar *name;
+
+ /* The style for the widget. The style contains the
+ * colors the widget should be drawn in for each state
+ * along with graphics contexts used to draw with and
+ * the font to use for text.
+ */
+ GtkStyle *style;
+
+ /* The widget's allocated size.
+ */
+ GtkAllocation allocation;
+
+ /* The widget's requested sizes */
+ SizeRequestCache requests;
+
+ /* The widget's window or its parent window if it does
+ * not have a window. (Which will be indicated by the
+ * GTK_NO_WINDOW flag being set).
+ */
+ GdkWindow *window;
+
+ /* The widget's parent.
+ */
+ GtkWidget *parent;
+};
enum {
+ DESTROY,
SHOW,
HIDE,
MAP,
DIRECTION_CHANGED,
GRAB_NOTIFY,
CHILD_NOTIFY,
+ DRAW,
MNEMONIC_ACTIVATE,
GRAB_FOCUS,
FOCUS,
MOVE_FOCUS,
+ KEYNAV_FAILED,
EVENT,
EVENT_AFTER,
BUTTON_PRESS_EVENT,
SELECTION_RECEIVED,
PROXIMITY_IN_EVENT,
PROXIMITY_OUT_EVENT,
+ CLIENT_EVENT,
+ NO_EXPOSE_EVENT,
+ VISIBILITY_NOTIFY_EVENT,
+ WINDOW_STATE_EVENT,
+ DAMAGE_EVENT,
+ GRAB_BROKEN_EVENT,
DRAG_BEGIN,
DRAG_END,
DRAG_DATA_DELETE,
DRAG_DROP,
DRAG_DATA_GET,
DRAG_DATA_RECEIVED,
- CLIENT_EVENT,
- NO_EXPOSE_EVENT,
- VISIBILITY_NOTIFY_EVENT,
- WINDOW_STATE_EVENT,
POPUP_MENU,
SHOW_HELP,
ACCEL_CLOSURES_CHANGED,
SCREEN_CHANGED,
CAN_ACTIVATE_ACCEL,
- GRAB_BROKEN,
COMPOSITED_CHANGED,
QUERY_TOOLTIP,
- KEYNAV_FAILED,
DRAG_FAILED,
- DAMAGE_EVENT,
LAST_SIGNAL
};
PROP_TOOLTIP_MARKUP,
PROP_TOOLTIP_TEXT,
PROP_WINDOW,
- PROP_DOUBLE_BUFFERED
+ PROP_DOUBLE_BUFFERED,
+ PROP_HALIGN,
+ PROP_VALIGN,
+ PROP_MARGIN_LEFT,
+ PROP_MARGIN_RIGHT,
+ PROP_MARGIN_TOP,
+ PROP_MARGIN_BOTTOM,
+ PROP_MARGIN,
+ PROP_HEXPAND,
+ PROP_VEXPAND,
+ PROP_HEXPAND_SET,
+ PROP_VEXPAND_SET,
+ PROP_EXPAND
};
typedef struct _GtkStateData GtkStateData;
GValue *value,
GParamSpec *pspec);
static void gtk_widget_dispose (GObject *object);
-static void gtk_widget_real_destroy (GtkObject *object);
+static void gtk_widget_real_destroy (GtkWidget *object);
static void gtk_widget_finalize (GObject *object);
static void gtk_widget_real_show (GtkWidget *widget);
static void gtk_widget_real_hide (GtkWidget *widget);
static void gtk_widget_real_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_widget_real_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
+ GtkAllocation *allocation);
static void gtk_widget_real_style_set (GtkWidget *widget,
GtkStyle *previous_style);
static void gtk_widget_real_direction_changed(GtkWidget *widget,
GdkEvent *event);
static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling);
+static void gtk_widget_real_get_width (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size);
+static void gtk_widget_real_get_height (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size);
+static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
+ gint width,
+ gint *minimum_height,
+ gint *natural_height);
+static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
+ gint height,
+ gint *minimum_width,
+ gint *natural_width);
+static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
GtkBuilder *builder);
-static void gtk_widget_size_request_init (GtkSizeRequestIface *iface);
-static void gtk_widget_real_get_width (GtkSizeRequest *widget,
+static void gtk_widget_real_get_width (GtkWidget *widget,
gint *minimum_size,
gint *natural_size);
-static void gtk_widget_real_get_height (GtkSizeRequest *widget,
+static void gtk_widget_real_get_height (GtkWidget *widget,
gint *minimum_size,
gint *natural_size);
static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
-
-static void gtk_widget_set_usize_internal (GtkWidget *widget,
- gint width,
- gint height);
+
+
+static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint *minimum_size,
+ gint *natural_size);
+static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint *natural_size,
+ gint *allocated_pos,
+ gint *allocated_size);
+
+static void gtk_widget_set_usize_internal (GtkWidget *widget,
+ gint width,
+ gint height,
+ GtkQueueResizeFlags flags);
static void gtk_widget_add_events_internal (GtkWidget *widget,
GdkDevice *device,
static gpointer gtk_widget_parent_class = NULL;
static guint widget_signals[LAST_SIGNAL] = { 0 };
static GtkStyle *gtk_default_style = NULL;
-static GSList *colormap_stack = NULL;
static guint composite_child_stack = 0;
static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
static GParamSpecPool *style_property_spec_pool = NULL;
+/* XXX Temporarily here to fire warnings from gtksizerequest.c */
+guint _size_request_signal_id = 0;
+
static GQuark quark_property_parser = 0;
static GQuark quark_aux_info = 0;
static GQuark quark_accel_path = 0;
static GQuark quark_pointer_window = 0;
static GQuark quark_shape_info = 0;
static GQuark quark_input_shape_info = 0;
-static GQuark quark_colormap = 0;
static GQuark quark_pango_context = 0;
static GQuark quark_rc_style = 0;
static GQuark quark_accessible_object = 0;
static GQuark quark_tooltip_markup = 0;
static GQuark quark_has_tooltip = 0;
static GQuark quark_tooltip_window = 0;
+static GQuark quark_visual = 0;
GParamSpecPool *_gtk_widget_child_property_pool = NULL;
GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
NULL /* interface data */
};
- const GInterfaceInfo layout_info =
- {
- (GInterfaceInitFunc) gtk_widget_size_request_init,
- (GInterfaceFinalizeFunc) NULL,
- NULL /* interface data */
- };
-
- widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
- &widget_info, G_TYPE_FLAG_ABSTRACT);
+ widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
+ &widget_info, G_TYPE_FLAG_ABSTRACT);
g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
&accessibility_info) ;
g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
&buildable_info) ;
- g_type_add_interface_static (widget_type, GTK_TYPE_SIZE_REQUEST,
- &layout_info) ;
}
return widget_type;
GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
}
+/* We guard against the draw signal callbacks modifying the state of the
+ * cairo context by surounding it with save/restore.
+ * Maybe we should also cairo_new_path() just to be sure?
+ */
+static void
+gtk_widget_draw_marshaller (GClosure *closure,
+ GValue *return_value,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data)
+{
+ cairo_t *cr = g_value_get_boxed (¶m_values[1]);
+
+ cairo_save (cr);
+
+ _gtk_marshal_BOOLEAN__BOXED (closure,
+ return_value,
+ n_param_values,
+ param_values,
+ invocation_hint,
+ marshal_data);
+
+ cairo_restore (cr);
+}
+
static void
gtk_widget_class_init (GtkWidgetClass *klass)
{
static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
GtkBindingSet *binding_set;
gtk_widget_parent_class = g_type_class_peek_parent (klass);
quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
- quark_colormap = g_quark_from_static_string ("gtk-colormap");
quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
+ quark_visual = g_quark_from_static_string ("gtk-widget-visual");
style_property_spec_pool = g_param_spec_pool_new (FALSE);
_gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
gobject_class->set_property = gtk_widget_set_property;
gobject_class->get_property = gtk_widget_get_property;
- object_class->destroy = gtk_widget_real_destroy;
-
+ klass->destroy = gtk_widget_real_destroy;
+
klass->activate_signal = 0;
- klass->set_scroll_adjustments_signal = 0;
klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
klass->show = gtk_widget_real_show;
klass->show_all = gtk_widget_show;
klass->hide = gtk_widget_real_hide;
- klass->hide_all = gtk_widget_hide;
klass->map = gtk_widget_real_map;
klass->unmap = gtk_widget_real_unmap;
klass->realize = gtk_widget_real_realize;
klass->unrealize = gtk_widget_real_unrealize;
klass->size_request = gtk_widget_real_size_request;
klass->size_allocate = gtk_widget_real_size_allocate;
+ klass->get_preferred_width = gtk_widget_real_get_width;
+ klass->get_preferred_height = gtk_widget_real_get_height;
+ klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
+ klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
klass->state_changed = NULL;
klass->parent_set = NULL;
klass->hierarchy_changed = NULL;
klass->direction_changed = gtk_widget_real_direction_changed;
klass->grab_notify = NULL;
klass->child_notify = NULL;
+ klass->draw = NULL;
klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
klass->grab_focus = gtk_widget_real_grab_focus;
klass->focus = gtk_widget_real_focus;
+ klass->move_focus = gtk_widget_real_move_focus;
+ klass->keynav_failed = gtk_widget_real_keynav_failed;
klass->event = NULL;
klass->button_press_event = NULL;
klass->button_release_event = NULL;
klass->motion_notify_event = NULL;
klass->delete_event = NULL;
klass->destroy_event = NULL;
- klass->expose_event = NULL;
klass->key_press_event = gtk_widget_real_key_press_event;
klass->key_release_event = gtk_widget_real_key_release_event;
klass->enter_notify_event = NULL;
klass->query_tooltip = gtk_widget_real_query_tooltip;
klass->show_help = gtk_widget_real_show_help;
-
+
/* Accessibility support */
klass->get_accessible = gtk_widget_real_get_accessible;
klass->no_expose_event = NULL;
+ klass->adjust_size_request = gtk_widget_real_adjust_size_request;
+ klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
+
g_object_class_install_property (gobject_class,
PROP_NAME,
g_param_spec_string ("name",
g_object_class_install_property (gobject_class,
PROP_PARENT,
g_param_spec_object ("parent",
- P_("Parent widget"),
+ P_("Parent widget"),
P_("The parent widget of this widget. Must be a Container widget"),
GTK_TYPE_CONTAINER,
GTK_PARAM_READWRITE));
/**
* GtkWidget:has-tooltip:
*
- * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
+ * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
* A value of %TRUE indicates that @widget can have a tooltip, in this case
* the widget will be queried using #GtkWidget::query-tooltip to determine
* whether it will provide a tooltip or not.
TRUE,
GTK_PARAM_READWRITE));
+ /**
+ * GtkWidget:halign:
+ *
+ * How to distribute horizontal space if widget gets extra space, see #GtkAlign
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_HALIGN,
+ g_param_spec_enum ("halign",
+ P_("Horizontal Alignment"),
+ P_("How to position in extra horizontal space"),
+ GTK_TYPE_ALIGN,
+ GTK_ALIGN_FILL,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWidget:valign:
+ *
+ * How to distribute vertical space if widget gets extra space, see #GtkAlign
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_VALIGN,
+ g_param_spec_enum ("valign",
+ P_("Vertical Alignment"),
+ P_("How to position in extra vertical space"),
+ GTK_TYPE_ALIGN,
+ GTK_ALIGN_FILL,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWidget:margin-left
+ *
+ * Margin on left side of widget.
+ *
+ * This property adds margin outside of the widget's normal size
+ * request, the margin will be added in addition to the size from
+ * gtk_widget_set_size_request() for example.
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_MARGIN_LEFT,
+ g_param_spec_int ("margin-left",
+ P_("Margin on Left"),
+ P_("Pixels of extra space on the left side"),
+ 0,
+ G_MAXINT16,
+ 0,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWidget:margin-right
+ *
+ * Margin on right side of widget.
+ *
+ * This property adds margin outside of the widget's normal size
+ * request, the margin will be added in addition to the size from
+ * gtk_widget_set_size_request() for example.
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_MARGIN_RIGHT,
+ g_param_spec_int ("margin-right",
+ P_("Margin on Right"),
+ P_("Pixels of extra space on the right side"),
+ 0,
+ G_MAXINT16,
+ 0,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWidget:margin-top
+ *
+ * Margin on top side of widget.
+ *
+ * This property adds margin outside of the widget's normal size
+ * request, the margin will be added in addition to the size from
+ * gtk_widget_set_size_request() for example.
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_MARGIN_TOP,
+ g_param_spec_int ("margin-top",
+ P_("Margin on Top"),
+ P_("Pixels of extra space on the top side"),
+ 0,
+ G_MAXINT16,
+ 0,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWidget:margin-bottom
+ *
+ * Margin on bottom side of widget.
+ *
+ * This property adds margin outside of the widget's normal size
+ * request, the margin will be added in addition to the size from
+ * gtk_widget_set_size_request() for example.
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_MARGIN_BOTTOM,
+ g_param_spec_int ("margin-bottom",
+ P_("Margin on Bottom"),
+ P_("Pixels of extra space on the bottom side"),
+ 0,
+ G_MAXINT16,
+ 0,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWidget:margin
+ *
+ * Sets all four sides' margin at once. If read, returns max
+ * margin on any side.
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_MARGIN,
+ g_param_spec_int ("margin",
+ P_("All Margins"),
+ P_("Pixels of extra space on all four sides"),
+ 0,
+ G_MAXINT16,
+ 0,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWidget::destroy:
+ * @object: the object which received the signal
+ *
+ * Signals that all holders of a reference to the widget should release
+ * the reference that they hold. May result in finalization of the widget
+ * if all references are released.
+ */
+ widget_signals[DESTROY] =
+ g_signal_new (I_("destroy"),
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+ G_STRUCT_OFFSET (GtkWidgetClass, destroy),
+ NULL, NULL,
+ _gtk_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ /**
+ * GtkWidget:hexpand
+ *
+ * Whether to expand horizontally. See gtk_widget_set_hexpand().
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_HEXPAND,
+ g_param_spec_boolean ("hexpand",
+ P_("Horizontal Expand"),
+ P_("Whether widget wants more horizontal space"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWidget:hexpand-set
+ *
+ * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_HEXPAND_SET,
+ g_param_spec_boolean ("hexpand-set",
+ P_("Horizontal Expand Set"),
+ P_("Whether to use the hexpand property"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWidget:vexpand
+ *
+ * Whether to expand vertically. See gtk_widget_set_vexpand().
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_VEXPAND,
+ g_param_spec_boolean ("vexpand",
+ P_("Vertical Expand"),
+ P_("Whether widget wants more vertical space"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWidget:vexpand-set
+ *
+ * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_VEXPAND_SET,
+ g_param_spec_boolean ("vexpand-set",
+ P_("Vertical Expand Set"),
+ P_("Whether to use the vexpand property"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWidget:expand
+ *
+ * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_EXPAND,
+ g_param_spec_boolean ("expand",
+ P_("Expand Both"),
+ P_("Whether widget wants to expand in both directions"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
/**
* GtkWidget::show:
* @widget: the object which received the signal.
* GtkWidget::size-request:
* @widget: the object which received the signal.
* @requisition:
+ *
+ * Deprecated: 3.0: Either implement
+ * <link linkend="geometry-management">height-for-width geometry management</link> or
+ * use gtk_widget_set_size_request() instead of handling this signal.
*/
- widget_signals[SIZE_REQUEST] =
+ _size_request_signal_id = widget_signals[SIZE_REQUEST] =
g_signal_new (I_("size-request"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_FIRST,
* @widget: the object which received the signal.
* @allocation:
*/
- widget_signals[SIZE_ALLOCATE] =
+ widget_signals[SIZE_ALLOCATE] =
g_signal_new (I_("size-allocate"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_FIRST,
* @old_parent: (allow-none): the previous parent, or %NULL if the widget
* just got its initial parent.
*
- * The ::parent-set signal is emitted when a new parent
- * has been set on a widget.
+ * The ::parent-set signal is emitted when a new parent
+ * has been set on a widget.
*/
widget_signals[PARENT_SET] =
g_signal_new (I_("parent-set"),
* GtkWidget::style-set:
* @widget: the object on which the signal is emitted
* @previous_style: (allow-none): the previous style, or %NULL if the widget
- * just got its initial style
+ * just got its initial style
*
- * The ::style-set signal is emitted when a new style has been set
- * on a widget. Note that style-modifying functions like
+ * The ::style-set signal is emitted when a new style has been set
+ * on a widget. Note that style-modifying functions like
* gtk_widget_modify_base() also cause this signal to be emitted.
*/
widget_signals[STYLE_SET] =
_gtk_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GTK_TYPE_STYLE);
-/**
- * GtkWidget::direction-changed:
- * @widget: the object on which the signal is emitted
- * @previous_direction: the previous text direction of @widget
- *
- * The ::direction-changed signal is emitted when the text direction
- * of a widget changes.
- */
+
+ /**
+ * GtkWidget::direction-changed:
+ * @widget: the object on which the signal is emitted
+ * @previous_direction: the previous text direction of @widget
+ *
+ * The ::direction-changed signal is emitted when the text direction
+ * of a widget changes.
+ */
widget_signals[DIRECTION_CHANGED] =
g_signal_new (I_("direction-changed"),
G_TYPE_FROM_CLASS (gobject_class),
* if it becomes unshadowed
*
* The ::grab-notify signal is emitted when a widget becomes
- * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
- * another widget, or when it becomes unshadowed due to a grab
+ * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
+ * another widget, or when it becomes unshadowed due to a grab
* being removed.
- *
- * A widget is shadowed by a gtk_grab_add() when the topmost
- * grab widget in the grab stack of its window group is not
+ *
+ * A widget is shadowed by a gtk_grab_add() when the topmost
+ * grab widget in the grab stack of its window group is not
* its ancestor.
*/
widget_signals[GRAB_NOTIFY] =
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
-/**
- * GtkWidget::child-notify:
- * @widget: the object which received the signal
- * @pspec: the #GParamSpec of the changed child property
- *
- * The ::child-notify signal is emitted for each
- * <link linkend="child-properties">child property</link> that has
- * changed on an object. The signal's detail holds the property name.
- */
+ /**
+ * GtkWidget::child-notify:
+ * @widget: the object which received the signal
+ * @pspec: the #GParamSpec of the changed child property
+ *
+ * The ::child-notify signal is emitted for each
+ * <link linkend="child-properties">child property</link> that has
+ * changed on an object. The signal's detail holds the property name.
+ */
widget_signals[CHILD_NOTIFY] =
g_signal_new (I_("child-notify"),
G_TYPE_FROM_CLASS (gobject_class),
G_TYPE_NONE, 1,
G_TYPE_PARAM);
+ /**
+ * GtkWidget::draw:
+ * @widget: the object which received the signal
+ * @cr: the cairo context to draw to
+ *
+ * This signal is emitted when a widget is supposed to render itself.
+ * The @widget's top left corner must be painted at the origin of
+ * the passed in context and be sized to the values returned by
+ * gtk_widget_get_allocated_width() and
+ * gtk_widget_get_allocated_height().
+ *
+ * Signal handlers connected to this signal can modify the cairo
+ * context passed as @cr in any way they like and don't need to
+ * restore it. The signal emission takes care of calling cairo_save()
+ * before and cairo_restore() after invoking the handler.
+ */
+ widget_signals[DRAW] =
+ g_signal_new (I_("draw"),
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkWidgetClass, draw),
+ _gtk_boolean_handled_accumulator, NULL,
+ gtk_widget_draw_marshaller,
+ G_TYPE_BOOLEAN, 1,
+ CAIRO_GOBJECT_TYPE_CONTEXT);
+
/**
* GtkWidget::mnemonic-activate:
* @widget: the object which received the signal.
*/
widget_signals[FOCUS] =
g_signal_new (I_("focus"),
- G_TYPE_FROM_CLASS (object_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, focus),
_gtk_boolean_handled_accumulator, NULL,
* @direction:
*/
widget_signals[MOVE_FOCUS] =
- g_signal_new_class_handler (I_("move-focus"),
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_CALLBACK (gtk_widget_real_move_focus),
- NULL, NULL,
- _gtk_marshal_VOID__ENUM,
- G_TYPE_NONE,
- 1,
- GTK_TYPE_DIRECTION_TYPE);
+ g_signal_new (I_("move-focus"),
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
+ NULL, NULL,
+ _gtk_marshal_VOID__ENUM,
+ G_TYPE_NONE,
+ 1,
+ GTK_TYPE_DIRECTION_TYPE);
+
+ /**
+ * GtkWidget::keynav-failed:
+ * @widget: the object which received the signal
+ * @direction: the direction of movement
+ *
+ * Gets emitted if keyboard navigation fails.
+ * See gtk_widget_keynav_failed() for details.
+ *
+ * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
+ * if the emitting widget should try to handle the keyboard
+ * navigation attempt in its parent container(s).
+ *
+ * Since: 2.12
+ **/
+ widget_signals[KEYNAV_FAILED] =
+ g_signal_new (I_("keynav-failed"),
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
+ _gtk_boolean_handled_accumulator, NULL,
+ _gtk_marshal_BOOLEAN__ENUM,
+ G_TYPE_BOOLEAN, 1,
+ GTK_TYPE_DIRECTION_TYPE);
+
/**
* GtkWidget::event:
* @widget: the object which received the signal.
*
* The GTK+ main loop will emit three signals for each GDK event delivered
* to a widget: one generic ::event signal, another, more specific,
- * signal that matches the type of event delivered (e.g.
- * #GtkWidget::key-press-event) and finally a generic
+ * signal that matches the type of event delivered (e.g.
+ * #GtkWidget::key-press-event) and finally a generic
* #GtkWidget::event-after signal.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event
+ * Returns: %TRUE to stop other handlers from being invoked for the event
* and to cancel the emission of the second specific ::event signal.
- * %FALSE to propagate the event further and to allow the emission of
+ * %FALSE to propagate the event further and to allow the emission of
* the second signal. The ::event-after signal is emitted regardless of
* the return value.
*/
widget_signals[EVENT] =
g_signal_new (I_("event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, event),
_gtk_boolean_handled_accumulator, NULL,
* @widget: the object which received the signal.
* @event: the #GdkEvent which triggered this signal
*
- * After the emission of the #GtkWidget::event signal and (optionally)
- * the second more specific signal, ::event-after will be emitted
+ * After the emission of the #GtkWidget::event signal and (optionally)
+ * the second more specific signal, ::event-after will be emitted
* regardless of the previous two signals handlers return values.
*
*/
widget_signals[EVENT_AFTER] =
g_signal_new (I_("event-after"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
0,
0,
NULL, NULL,
* The ::button-press-event signal will be emitted when a button
* (typically from a mouse) is pressed.
*
- * To receive this signal, the #GdkWindow associated to the
+ * To receive this signal, the #GdkWindow associated to the
* widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
*
* This signal will be sent to the grab widget if there is one.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[BUTTON_PRESS_EVENT] =
g_signal_new (I_("button-press-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
_gtk_boolean_handled_accumulator, NULL,
* The ::button-release-event signal will be emitted when a button
* (typically from a mouse) is released.
*
- * To receive this signal, the #GdkWindow associated to the
+ * To receive this signal, the #GdkWindow associated to the
* widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
*
* This signal will be sent to the grab widget if there is one.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[BUTTON_RELEASE_EVENT] =
g_signal_new (I_("button-release-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
_gtk_boolean_handled_accumulator, NULL,
* this signal.
*
* The ::scroll-event signal is emitted when a button in the 4 to 7
- * range is pressed. Wheel mice are usually configured to generate
+ * range is pressed. Wheel mice are usually configured to generate
* button press events for buttons 4 and 5 when the wheel is turned.
*
* To receive this signal, the #GdkWindow associated to the widget needs
*
* This signal will be sent to the grab widget if there is one.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[SCROLL_EVENT] =
g_signal_new (I_("scroll-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
_gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__BOXED,
G_TYPE_BOOLEAN, 1,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+
/**
* GtkWidget::motion-notify-event:
* @widget: the object which received the signal.
* @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
* this signal.
*
- * The ::motion-notify-event signal is emitted when the pointer moves
+ * The ::motion-notify-event signal is emitted when the pointer moves
* over the widget's #GdkWindow.
*
- * To receive this signal, the #GdkWindow associated to the widget
+ * To receive this signal, the #GdkWindow associated to the widget
* needs to enable the #GDK_POINTER_MOTION_MASK mask.
*
* This signal will be sent to the grab widget if there is one.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[MOTION_NOTIFY_EVENT] =
g_signal_new (I_("motion-notify-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
_gtk_boolean_handled_accumulator, NULL,
* @widget: the object on which the signal is emitted
*
* The ::composited-changed signal is emitted when the composited
- * status of @widget<!-- -->s screen changes.
+ * status of @widget<!-- -->s screen changes.
* See gdk_screen_is_composited().
*/
widget_signals[COMPOSITED_CHANGED] =
g_signal_new (I_("composited-changed"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
- /**
- * GtkWidget::keynav-failed:
- * @widget: the object which received the signal
- * @direction: the direction of movement
- *
- * Gets emitted if keyboard navigation fails.
- * See gtk_widget_keynav_failed() for details.
- *
- * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
- * if the emitting widget should try to handle the keyboard
- * navigation attempt in its parent container(s).
- *
- * Since: 2.12
- **/
- widget_signals[KEYNAV_FAILED] =
- g_signal_new_class_handler (I_("keynav-failed"),
- G_TYPE_FROM_CLASS (gobject_class),
- G_SIGNAL_RUN_LAST,
- G_CALLBACK (gtk_widget_real_keynav_failed),
- _gtk_boolean_handled_accumulator, NULL,
- _gtk_marshal_BOOLEAN__ENUM,
- G_TYPE_BOOLEAN, 1,
- GTK_TYPE_DIRECTION_TYPE);
-
/**
* GtkWidget::delete-event:
* @widget: the object which received the signal
* this signal will cause the window to be hidden instead, so that
* it can later be shown again without reconstructing it.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[DELETE_EVENT] =
g_signal_new (I_("delete-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
_gtk_boolean_handled_accumulator, NULL,
* @event: the event which triggered this signal
*
* The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
- * You rarely get this signal, because most widgets disconnect themselves
- * from their window before they destroy it, so no widget owns the
+ * You rarely get this signal, because most widgets disconnect themselves
+ * from their window before they destroy it, so no widget owns the
* window at destroy time.
- *
+ *
* To receive this signal, the #GdkWindow associated to the widget needs
* to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
* automatically for all new windows.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[DESTROY_EVENT] =
g_signal_new (I_("destroy-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
_gtk_boolean_handled_accumulator, NULL,
G_TYPE_BOOLEAN, 1,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
- /**
- * GtkWidget::expose-event:
- * @widget: the object which received the signal.
- * @event: (type Gdk.EventExpose): the #GdkEventExpose which triggered
- * this signal.
- *
- * The ::expose-event signal is emitted when an area of a previously
- * obscured #GdkWindow is made visible and needs to be redrawn.
- * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
- * widget.
- *
- * To receive this signal, the #GdkWindow associated to the widget needs
- * to enable the #GDK_EXPOSURE_MASK mask.
- *
- * Returns: %TRUE to stop other handlers from being invoked for the event.
- * %FALSE to propagate the event further.
- */
- widget_signals[EXPOSE_EVENT] =
- g_signal_new (I_("expose-event"),
- G_TYPE_FROM_CLASS (gobject_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
- _gtk_boolean_handled_accumulator, NULL,
- _gtk_marshal_BOOLEAN__BOXED,
- G_TYPE_BOOLEAN, 1,
- GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
-
/**
* GtkWidget::key-press-event:
* @widget: the object which received the signal
*
* This signal will be sent to the grab widget if there is one.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[KEY_PRESS_EVENT] =
g_signal_new (I_("key-press-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
_gtk_boolean_handled_accumulator, NULL,
*
* This signal will be sent to the grab widget if there is one.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[KEY_RELEASE_EVENT] =
g_signal_new (I_("key-release-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
_gtk_boolean_handled_accumulator, NULL,
*
* This signal will be sent to the grab widget if there is one.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[ENTER_NOTIFY_EVENT] =
g_signal_new (I_("enter-notify-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
_gtk_boolean_handled_accumulator, NULL,
*
* This signal will be sent to the grab widget if there is one.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[LEAVE_NOTIFY_EVENT] =
g_signal_new (I_("leave-notify-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
_gtk_boolean_handled_accumulator, NULL,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
- * GtkWidget::configure-event
+ * GtkWidget::configure-event:
* @widget: the object which received the signal
* @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
* this signal.
* to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
* automatically for all new windows.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[CONFIGURE_EVENT] =
g_signal_new (I_("configure-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
_gtk_boolean_handled_accumulator, NULL,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
- * GtkWidget::focus-in-event
+ * GtkWidget::focus-in-event:
* @widget: the object which received the signal
* @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
* this signal.
* To receive this signal, the #GdkWindow associated to the widget needs
* to enable the #GDK_FOCUS_CHANGE_MASK mask.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[FOCUS_IN_EVENT] =
g_signal_new (I_("focus-in-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
_gtk_boolean_handled_accumulator, NULL,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
- * GtkWidget::focus-out-event
+ * GtkWidget::focus-out-event:
* @widget: the object which received the signal
* @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
* signal.
* To receive this signal, the #GdkWindow associated to the widget needs
* to enable the #GDK_FOCUS_CHANGE_MASK mask.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[FOCUS_OUT_EVENT] =
g_signal_new (I_("focus-out-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
_gtk_boolean_handled_accumulator, NULL,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
- * GtkWidget::map-event
+ * GtkWidget::map-event:
* @widget: the object which received the signal
* @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
*
* to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
* automatically for all new windows.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[MAP_EVENT] =
g_signal_new (I_("map-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, map_event),
_gtk_boolean_handled_accumulator, NULL,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
- * GtkWidget::unmap-event
+ * GtkWidget::unmap-event:
* @widget: the object which received the signal
* @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
*
* to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
* automatically for all new windows.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[UNMAP_EVENT] =
g_signal_new (I_("unmap-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
_gtk_boolean_handled_accumulator, NULL,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
- * GtkWidget::property-notify-event
+ * GtkWidget::property-notify-event:
* @widget: the object which received the signal
* @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
* this signal.
* To receive this signal, the #GdkWindow associated to the widget needs
* to enable the #GDK_PROPERTY_CHANGE_MASK mask.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[PROPERTY_NOTIFY_EVENT] =
g_signal_new (I_("property-notify-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
_gtk_boolean_handled_accumulator, NULL,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
- * GtkWidget::selection-clear-event
+ * GtkWidget::selection-clear-event:
* @widget: the object which received the signal
* @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
* this signal.
* The ::selection-clear-event signal will be emitted when the
* the @widget's window has lost ownership of a selection.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[SELECTION_CLEAR_EVENT] =
g_signal_new (I_("selection-clear-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
_gtk_boolean_handled_accumulator, NULL,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
- * GtkWidget::selection-request-event
+ * GtkWidget::selection-request-event:
* @widget: the object which received the signal
* @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
* this signal.
* another client requests ownership of the selection owned by
* the @widget's window.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[SELECTION_REQUEST_EVENT] =
g_signal_new (I_("selection-request-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
_gtk_boolean_handled_accumulator, NULL,
*/
widget_signals[SELECTION_NOTIFY_EVENT] =
g_signal_new (I_("selection-notify-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
_gtk_boolean_handled_accumulator, NULL,
*/
widget_signals[SELECTION_RECEIVED] =
g_signal_new (I_("selection-received"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
NULL, NULL,
*/
widget_signals[SELECTION_GET] =
g_signal_new (I_("selection-get"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
NULL, NULL,
G_TYPE_UINT);
/**
- * GtkWidget::proximity-in-event
+ * GtkWidget::proximity-in-event:
* @widget: the object which received the signal
* @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
* this signal.
*
* This signal will be sent to the grab widget if there is one.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[PROXIMITY_IN_EVENT] =
g_signal_new (I_("proximity-in-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
_gtk_boolean_handled_accumulator, NULL,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
- * GtkWidget::proximity-out-event
+ * GtkWidget::proximity-out-event:
* @widget: the object which received the signal
* @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
* this signal.
*
* This signal will be sent to the grab widget if there is one.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[PROXIMITY_OUT_EVENT] =
g_signal_new (I_("proximity-out-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
_gtk_boolean_handled_accumulator, NULL,
* @drag_context: the drag context
* @time: the timestamp of the motion event
*
- * The ::drag-leave signal is emitted on the drop site when the cursor
- * leaves the widget. A typical reason to connect to this signal is to
- * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
+ * The ::drag-leave signal is emitted on the drop site when the cursor
+ * leaves the widget. A typical reason to connect to this signal is to
+ * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
* with gtk_drag_unhighlight()
*/
widget_signals[DRAG_LEAVE] =
g_signal_new (I_("drag-leave"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
NULL, NULL,
* @widget: the object which received the signal
* @drag_context: the drag context
*
- * The ::drag-begin signal is emitted on the drag source when a drag is
- * started. A typical reason to connect to this signal is to set up a
+ * The ::drag-begin signal is emitted on the drag source when a drag is
+ * started. A typical reason to connect to this signal is to set up a
* custom drag icon with gtk_drag_source_set_icon().
*
* Note that some widgets set up a drag icon in the default handler of
*/
widget_signals[DRAG_BEGIN] =
g_signal_new (I_("drag-begin"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
NULL, NULL,
* @widget: the object which received the signal
* @drag_context: the drag context
*
- * The ::drag-end signal is emitted on the drag source when a drag is
- * finished. A typical reason to connect to this signal is to undo
+ * The ::drag-end signal is emitted on the drag source when a drag is
+ * finished. A typical reason to connect to this signal is to undo
* things done in #GtkWidget::drag-begin.
*/
widget_signals[DRAG_END] =
g_signal_new (I_("drag-end"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
NULL, NULL,
* @widget: the object which received the signal
* @drag_context: the drag context
*
- * The ::drag-data-delete signal is emitted on the drag source when a drag
- * with the action %GDK_ACTION_MOVE is successfully completed. The signal
- * handler is responsible for deleting the data that has been dropped. What
- * "delete" means depends on the context of the drag operation.
+ * The ::drag-data-delete signal is emitted on the drag source when a drag
+ * with the action %GDK_ACTION_MOVE is successfully completed. The signal
+ * handler is responsible for deleting the data that has been dropped. What
+ * "delete" means depends on the context of the drag operation.
*/
widget_signals[DRAG_DATA_DELETE] =
g_signal_new (I_("drag-data-delete"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
NULL, NULL,
*/
widget_signals[DRAG_FAILED] =
g_signal_new (I_("drag-failed"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, _gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__OBJECT_ENUM,
* guint time)
* {
* GdkAtom target;
- *
+ *
* PrivateData *private_data = GET_PRIVATE_DATA (widget);
- *
- * if (!private_data->drag_highlight)
+ *
+ * if (!private_data->drag_highlight)
* {
* private_data->drag_highlight = 1;
* gtk_drag_highlight (widget);
* }
- *
+ *
* target = gtk_drag_dest_find_target (widget, context, NULL);
* if (target == GDK_NONE)
* gdk_drag_status (context, 0, time);
- * else
+ * else
* {
* private_data->pending_status = context->suggested_action;
* gtk_drag_get_data (widget, context, target, time);
* }
- *
+ *
* return TRUE;
* }
- *
+ *
* static void
* drag_data_received (GtkWidget *widget,
* GdkDragContext *context,
* guint time)
* {
* PrivateData *private_data = GET_PRIVATE_DATA (widget);
- *
- * if (private_data->suggested_action)
+ *
+ * if (private_data->suggested_action)
* {
* private_data->suggested_action = 0;
- *
+ *
* /* We are getting this data due to a request in drag_motion,
* * rather than due to a request in drag_drop, so we are just
- * * supposed to call gdk_drag_status (), not actually paste in
+ * * supposed to call gdk_drag_status (), not actually paste in
* * the data.
* */
* str = gtk_selection_data_get_text (selection_data);
- * if (!data_is_acceptable (str))
+ * if (!data_is_acceptable (str))
* gdk_drag_status (context, 0, time);
* else
* gdk_drag_status (context, private_data->suggested_action, time);
*/
widget_signals[DRAG_MOTION] =
g_signal_new (I_("drag-motion"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
_gtk_boolean_handled_accumulator, NULL,
* @time: the timestamp of the motion event
* @returns: whether the cursor position is in a drop zone
*
- * The ::drag-drop signal is emitted on the drop site when the user drops
- * the data onto the widget. The signal handler must determine whether
- * the cursor position is in a drop zone or not. If it is not in a drop
- * zone, it returns %FALSE and no further processing is necessary.
- * Otherwise, the handler returns %TRUE. In this case, the handler must
- * ensure that gtk_drag_finish() is called to let the source know that
- * the drop is done. The call to gtk_drag_finish() can be done either
- * directly or in a #GtkWidget::drag-data-received handler which gets
- * triggered by calling gtk_drag_get_data() to receive the data for one
+ * The ::drag-drop signal is emitted on the drop site when the user drops
+ * the data onto the widget. The signal handler must determine whether
+ * the cursor position is in a drop zone or not. If it is not in a drop
+ * zone, it returns %FALSE and no further processing is necessary.
+ * Otherwise, the handler returns %TRUE. In this case, the handler must
+ * ensure that gtk_drag_finish() is called to let the source know that
+ * the drop is done. The call to gtk_drag_finish() can be done either
+ * directly or in a #GtkWidget::drag-data-received handler which gets
+ * triggered by calling gtk_drag_get_data() to receive the data for one
* or more of the supported targets.
*/
widget_signals[DRAG_DROP] =
g_signal_new (I_("drag-drop"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
_gtk_boolean_handled_accumulator, NULL,
* @widget: the object which received the signal
* @drag_context: the drag context
* @data: the #GtkSelectionData to be filled with the dragged data
- * @info: the info that has been registered with the target in the
+ * @info: the info that has been registered with the target in the
* #GtkTargetList
* @time: the timestamp at which the data was requested
*
- * The ::drag-data-get signal is emitted on the drag source when the drop
- * site requests the data which is dragged. It is the responsibility of
- * the signal handler to fill @data with the data in the format which
- * is indicated by @info. See gtk_selection_data_set() and
+ * The ::drag-data-get signal is emitted on the drag source when the drop
+ * site requests the data which is dragged. It is the responsibility of
+ * the signal handler to fill @data with the data in the format which
+ * is indicated by @info. See gtk_selection_data_set() and
* gtk_selection_data_set_text().
*/
widget_signals[DRAG_DATA_GET] =
g_signal_new (I_("drag-data-get"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
NULL, NULL,
* @x: where the drop happened
* @y: where the drop happened
* @data: the received data
- * @info: the info that has been registered with the target in the
+ * @info: the info that has been registered with the target in the
* #GtkTargetList
* @time: the timestamp at which the data was received
*
- * The ::drag-data-received signal is emitted on the drop site when the
- * dragged data has been received. If the data was received in order to
- * determine whether the drop will be accepted, the handler is expected
- * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
- * If the data was received in response to a #GtkWidget::drag-drop signal
- * (and this is the last target to be received), the handler for this
- * signal is expected to process the received data and then call
- * gtk_drag_finish(), setting the @success parameter depending on whether
- * the data was processed successfully.
- *
- * The handler may inspect and modify @drag_context->action before calling
- * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
+ * The ::drag-data-received signal is emitted on the drop site when the
+ * dragged data has been received. If the data was received in order to
+ * determine whether the drop will be accepted, the handler is expected
+ * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
+ * If the data was received in response to a #GtkWidget::drag-drop signal
+ * (and this is the last target to be received), the handler for this
+ * signal is expected to process the received data and then call
+ * gtk_drag_finish(), setting the @success parameter depending on whether
+ * the data was processed successfully.
+ *
+ * The handler may inspect and modify @drag_context->action before calling
+ * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
* following example:
* |[
- * void
+ * void
* drag_data_received (GtkWidget *widget,
* GdkDragContext *drag_context,
* gint x,
* {
* if ((data->length >= 0) && (data->format == 8))
* {
- * if (drag_context->action == GDK_ACTION_ASK)
+ * if (drag_context->action == GDK_ACTION_ASK)
* {
* GtkWidget *dialog;
* gint response;
- *
+ *
* dialog = gtk_message_dialog_new (NULL,
- * GTK_DIALOG_MODAL |
+ * GTK_DIALOG_MODAL |
* GTK_DIALOG_DESTROY_WITH_PARENT,
* GTK_MESSAGE_INFO,
* GTK_BUTTONS_YES_NO,
* "Move the data ?\n");
* response = gtk_dialog_run (GTK_DIALOG (dialog));
* gtk_widget_destroy (dialog);
- *
+ *
* if (response == GTK_RESPONSE_YES)
* drag_context->action = GDK_ACTION_MOVE;
* else
* drag_context->action = GDK_ACTION_COPY;
* }
- *
+ *
* gtk_drag_finish (drag_context, TRUE, FALSE, time);
* return;
* }
- *
+ *
* gtk_drag_finish (drag_context, FALSE, FALSE, time);
* }
* ]|
*/
widget_signals[DRAG_DATA_RECEIVED] =
g_signal_new (I_("drag-data-received"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
NULL, NULL,
GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
G_TYPE_UINT,
G_TYPE_UINT);
-
+
/**
* GtkWidget::visibility-notify-event:
* @widget: the object which received the signal
* To receive this signal the #GdkWindow associated to the widget needs
* to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[VISIBILITY_NOTIFY_EVENT] =
g_signal_new (I_("visibility-notify-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
_gtk_boolean_handled_accumulator, NULL,
* receives a message (via a ClientMessage event) from another
* application.
*
- * Returns: %TRUE to stop other handlers from being invoked for
+ * Returns: %TRUE to stop other handlers from being invoked for
* the event. %FALSE to propagate the event further.
*/
widget_signals[CLIENT_EVENT] =
g_signal_new (I_("client-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, client_event),
_gtk_boolean_handled_accumulator, NULL,
* @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
* this signal.
*
- * The ::no-expose-event will be emitted when the @widget's window is
+ * The ::no-expose-event will be emitted when the @widget's window is
* drawn as a copy of another #GdkDrawable which was completely unobscured.
* If the source window was partially obscured #GdkEventExpose events will
* be generated for those areas.
*
- * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
* %FALSE to propagate the event further.
*/
widget_signals[NO_EXPOSE_EVENT] =
g_signal_new (I_("no-expose-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
_gtk_boolean_handled_accumulator, NULL,
* @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
* triggered this signal.
*
- * The ::window-state-event will be emitted when the state of the
+ * The ::window-state-event will be emitted when the state of the
* toplevel window associated to the @widget changes.
*
- * To receive this signal the #GdkWindow associated to the widget
- * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
+ * To receive this signal the #GdkWindow associated to the widget
+ * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
* this mask automatically for all new windows.
*
- * Returns: %TRUE to stop other handlers from being invoked for the
+ * Returns: %TRUE to stop other handlers from being invoked for the
* event. %FALSE to propagate the event further.
*/
widget_signals[WINDOW_STATE_EVENT] =
g_signal_new (I_("window-state-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
_gtk_boolean_handled_accumulator, NULL,
*/
widget_signals[DAMAGE_EVENT] =
g_signal_new (I_("damage-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
- 0,
+ G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
_gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__BOXED,
G_TYPE_BOOLEAN, 1,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+
/**
* GtkWidget::grab-broken-event:
* @widget: the object which received the signal
* @event: the #GdkEventGrabBroken event
*
- * Emitted when a pointer or keyboard grab on a window belonging
- * to @widget gets broken.
- *
- * On X11, this happens when the grab window becomes unviewable
- * (i.e. it or one of its ancestors is unmapped), or if the same
+ * Emitted when a pointer or keyboard grab on a window belonging
+ * to @widget gets broken.
+ *
+ * On X11, this happens when the grab window becomes unviewable
+ * (i.e. it or one of its ancestors is unmapped), or if the same
* application grabs the pointer or keyboard again.
*
- * Returns: %TRUE to stop other handlers from being invoked for
+ * Returns: %TRUE to stop other handlers from being invoked for
* the event. %FALSE to propagate the event further.
*
* Since: 2.8
*/
- widget_signals[GRAB_BROKEN] =
+ widget_signals[GRAB_BROKEN_EVENT] =
g_signal_new (I_("grab-broken-event"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
_gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__BOXED,
G_TYPE_BOOLEAN, 1,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+
/**
* GtkWidget::query-tooltip:
* @widget: the object which received the signal
- * @x: the x coordinate of the cursor position where the request has
+ * @x: the x coordinate of the cursor position where the request has
* been emitted, relative to @widget->window
- * @y: the y coordinate of the cursor position where the request has
+ * @y: the y coordinate of the cursor position where the request has
* been emitted, relative to @widget->window
* @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
* @tooltip: a #GtkTooltip
*
- * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
- * has expired with the cursor hovering "above" @widget; or emitted when @widget got
+ * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
+ * has expired with the cursor hovering "above" @widget; or emitted when @widget got
* focus in keyboard mode.
*
* Using the given coordinates, the signal handler should determine
*/
widget_signals[QUERY_TOOLTIP] =
g_signal_new (I_("query-tooltip"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
_gtk_boolean_handled_accumulator, NULL,
* GtkWidget::popup-menu
* @widget: the object which received the signal
*
- * This signal gets emitted whenever a widget should pop up a context
- * menu. This usually happens through the standard key binding mechanism;
- * by pressing a certain key while a widget is focused, the user can cause
- * the widget to pop up a menu. For example, the #GtkEntry widget creates
- * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
+ * This signal gets emitted whenever a widget should pop up a context
+ * menu. This usually happens through the standard key binding mechanism;
+ * by pressing a certain key while a widget is focused, the user can cause
+ * the widget to pop up a menu. For example, the #GtkEntry widget creates
+ * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
* for an example of how to use this signal.
*
* Returns: %TRUE if a menu was activated
*/
widget_signals[POPUP_MENU] =
g_signal_new (I_("popup-menu"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
_gtk_boolean_handled_accumulator, NULL,
*/
widget_signals[SHOW_HELP] =
g_signal_new (I_("show-help"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkWidgetClass, show_help),
_gtk_boolean_handled_accumulator, NULL,
*/
widget_signals[ACCEL_CLOSURES_CHANGED] =
g_signal_new (I_("accel-closures-changed"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
0,
0,
NULL, NULL,
*/
widget_signals[SCREEN_CHANGED] =
g_signal_new (I_("screen-changed"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
NULL, NULL,
*/
widget_signals[CAN_ACTIVATE_ACCEL] =
g_signal_new (I_("can-activate-accel"),
- G_TYPE_FROM_CLASS (gobject_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
_gtk_boolean_handled_accumulator, NULL,
G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
binding_set = gtk_binding_set_by_class (klass);
- gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
+ "popup-menu", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
"popup-menu", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
- "popup-menu", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
"show-help", 1,
GTK_TYPE_WIDGET_HELP_TYPE,
GTK_WIDGET_HELP_TOOLTIP);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
"show-help", 1,
GTK_TYPE_WIDGET_HELP_TYPE,
GTK_WIDGET_HELP_TOOLTIP);
- gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
"show-help", 1,
GTK_TYPE_WIDGET_HELP_TYPE,
- GTK_WIDGET_HELP_WHATS_THIS);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
+ GTK_WIDGET_HELP_WHATS_THIS);
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
"show-help", 1,
GTK_TYPE_WIDGET_HELP_TYPE,
GTK_WIDGET_HELP_WHATS_THIS);
/**
* GtkWidget:wide-separators:
*
- * The "wide-separators" style property defines whether separators have
+ * The "wide-separators" style property defines whether separators have
* configurable width and should be drawn using a box instead of a line.
*
* Since: 2.10
/**
* GtkWidget:scroll-arrow-hlength:
*
- * The "scroll-arrow-hlength" style property defines the length of
+ * The "scroll-arrow-hlength" style property defines the length of
* horizontal scroll arrows.
*
* Since: 2.10
/**
* GtkWidget:scroll-arrow-vlength:
*
- * The "scroll-arrow-vlength" style property defines the length of
+ * The "scroll-arrow-vlength" style property defines the length of
* vertical scroll arrows.
*
* Since: 2.10
P_("The length of vertical scroll arrows"),
1, G_MAXINT, 16,
GTK_PARAM_READABLE));
+
+ g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
}
static void
gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
break;
case PROP_WIDTH_REQUEST:
- gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
+ gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
break;
case PROP_HEIGHT_REQUEST:
- gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
+ gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
break;
case PROP_VISIBLE:
gtk_widget_set_visible (widget, g_value_get_boolean (value));
tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
tooltip_markup = g_value_dup_string (value);
- /* Treat an empty string as a NULL string,
+ /* Treat an empty string as a NULL string,
* because an empty string would be useless for a tooltip:
*/
if (tooltip_markup && (strlen (tooltip_markup) == 0))
tooltip_text = g_value_get_string (value);
- /* Treat an empty string as a NULL string,
+ /* Treat an empty string as a NULL string,
* because an empty string would be useless for a tooltip:
*/
if (tooltip_text && (strlen (tooltip_text) == 0))
case PROP_DOUBLE_BUFFERED:
gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
break;
+ case PROP_HALIGN:
+ gtk_widget_set_halign (widget, g_value_get_enum (value));
+ break;
+ case PROP_VALIGN:
+ gtk_widget_set_valign (widget, g_value_get_enum (value));
+ break;
+ case PROP_MARGIN_LEFT:
+ gtk_widget_set_margin_left (widget, g_value_get_int (value));
+ break;
+ case PROP_MARGIN_RIGHT:
+ gtk_widget_set_margin_right (widget, g_value_get_int (value));
+ break;
+ case PROP_MARGIN_TOP:
+ gtk_widget_set_margin_top (widget, g_value_get_int (value));
+ break;
+ case PROP_MARGIN_BOTTOM:
+ gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
+ break;
+ case PROP_MARGIN:
+ g_object_freeze_notify (G_OBJECT (widget));
+ gtk_widget_set_margin_left (widget, g_value_get_int (value));
+ gtk_widget_set_margin_right (widget, g_value_get_int (value));
+ gtk_widget_set_margin_top (widget, g_value_get_int (value));
+ gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
+ g_object_thaw_notify (G_OBJECT (widget));
+ break;
+ case PROP_HEXPAND:
+ gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
+ break;
+ case PROP_HEXPAND_SET:
+ gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
+ break;
+ case PROP_VEXPAND:
+ gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
+ break;
+ case PROP_VEXPAND_SET:
+ gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
+ break;
+ case PROP_EXPAND:
+ g_object_freeze_notify (G_OBJECT (widget));
+ gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
+ gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
+ g_object_thaw_notify (G_OBJECT (widget));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
GParamSpec *pspec)
{
GtkWidget *widget = GTK_WIDGET (object);
-
+ GtkWidgetPrivate *priv = widget->priv;
+
switch (prop_id)
{
gpointer *eventp;
gpointer *modep;
case PROP_NAME:
- if (widget->name)
- g_value_set_string (value, widget->name);
+ if (priv->name)
+ g_value_set_string (value, priv->name);
else
g_value_set_static_string (value, "");
break;
case PROP_PARENT:
- g_value_set_object (value, widget->parent);
+ g_value_set_object (value, priv->parent);
break;
case PROP_WIDTH_REQUEST:
{
g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
break;
case PROP_COMPOSITE_CHILD:
- g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
+ g_value_set_boolean (value, widget->priv->composite_child);
break;
case PROP_STYLE:
g_value_set_object (value, gtk_widget_get_style (widget));
case PROP_DOUBLE_BUFFERED:
g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
break;
+ case PROP_HALIGN:
+ g_value_set_enum (value, gtk_widget_get_halign (widget));
+ break;
+ case PROP_VALIGN:
+ g_value_set_enum (value, gtk_widget_get_valign (widget));
+ break;
+ case PROP_MARGIN_LEFT:
+ g_value_set_int (value, gtk_widget_get_margin_left (widget));
+ break;
+ case PROP_MARGIN_RIGHT:
+ g_value_set_int (value, gtk_widget_get_margin_right (widget));
+ break;
+ case PROP_MARGIN_TOP:
+ g_value_set_int (value, gtk_widget_get_margin_top (widget));
+ break;
+ case PROP_MARGIN_BOTTOM:
+ g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
+ break;
+ case PROP_MARGIN:
+ {
+ GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
+ if (aux_info == NULL)
+ {
+ g_value_set_int (value, 0);
+ }
+ else
+ {
+ g_value_set_int (value, MAX (MAX (aux_info->margin.left,
+ aux_info->margin.right),
+ MAX (aux_info->margin.top,
+ aux_info->margin.bottom)));
+ }
+ }
+ break;
+ case PROP_HEXPAND:
+ g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
+ break;
+ case PROP_HEXPAND_SET:
+ g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
+ break;
+ case PROP_VEXPAND:
+ g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
+ break;
+ case PROP_VEXPAND_SET:
+ g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
+ break;
+ case PROP_EXPAND:
+ g_value_set_boolean (value,
+ gtk_widget_get_hexpand (widget) &&
+ gtk_widget_get_vexpand (widget));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
static void
gtk_widget_init (GtkWidget *widget)
{
- GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
- widget->state = GTK_STATE_NORMAL;
- widget->saved_state = GTK_STATE_NORMAL;
- widget->name = NULL;
- widget->requisition.width = 0;
- widget->requisition.height = 0;
- widget->allocation.x = -1;
- widget->allocation.y = -1;
- widget->allocation.width = 1;
- widget->allocation.height = 1;
- widget->window = NULL;
- widget->parent = NULL;
-
- GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
- GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
- GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
- gtk_widget_set_double_buffered (widget, TRUE);
-
- GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
- GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
- GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
- GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
- GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
+ GtkWidgetPrivate *priv;
+
+ widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
+ GTK_TYPE_WIDGET,
+ GtkWidgetPrivate);
+ priv = widget->priv;
+
+ priv->child_visible = TRUE;
+ priv->state = GTK_STATE_NORMAL;
+ priv->saved_state = GTK_STATE_NORMAL;
+ priv->name = NULL;
+ priv->allocation.x = -1;
+ priv->allocation.y = -1;
+ priv->allocation.width = 1;
+ priv->allocation.height = 1;
+ priv->window = NULL;
+ priv->parent = NULL;
+
+ priv->sensitive = TRUE;
+ priv->parent_sensitive = TRUE;
+ priv->composite_child = composite_child_stack != 0;
+ priv->double_buffered = TRUE;
+ priv->redraw_on_alloc = TRUE;
+ priv->width_request_needed = TRUE;
+ priv->height_request_needed = TRUE;
+ priv->alloc_needed = TRUE;
+
+ /* this will be set to TRUE if the widget gets a child or if the
+ * expand flag is set on the widget, but until one of those happen
+ * we know the expand is already properly FALSE.
+ *
+ * We really want to default FALSE here to avoid computing expand
+ * all over the place while initially building a widget tree.
+ */
+ priv->need_compute_expand = FALSE;
- widget->style = gtk_widget_get_default_style ();
- g_object_ref (widget->style);
+ priv->style = gtk_widget_get_default_style ();
+ g_object_ref (priv->style);
}
guint n_pspecs,
GParamSpec **pspecs)
{
- GtkWidget *container = widget->parent;
+ GtkWidgetPrivate *priv = widget->priv;
+ GtkWidget *container = priv->parent;
guint i;
- for (i = 0; widget->parent == container && i < n_pspecs; i++)
+ for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
}
/**
* gtk_widget_freeze_child_notify:
* @widget: a #GtkWidget
- *
- * Stops emission of #GtkWidget::child-notify signals on @widget. The
- * signals are queued until gtk_widget_thaw_child_notify() is called
- * on @widget.
+ *
+ * Stops emission of #GtkWidget::child-notify signals on @widget. The
+ * signals are queued until gtk_widget_thaw_child_notify() is called
+ * on @widget.
*
* This is the analogue of g_object_freeze_notify() for child properties.
**/
/**
* gtk_widget_child_notify:
* @widget: a #GtkWidget
- * @child_property: the name of a child property installed on the
+ * @child_property: the name of a child property installed on the
* class of @widget<!-- -->'s parent
- *
- * Emits a #GtkWidget::child-notify signal for the
- * <link linkend="child-properties">child property</link> @child_property
+ *
+ * Emits a #GtkWidget::child-notify signal for the
+ * <link linkend="child-properties">child property</link> @child_property
* on @widget.
*
* This is the analogue of g_object_notify() for child properties.
gtk_widget_child_notify (GtkWidget *widget,
const gchar *child_property)
{
+ GtkWidgetPrivate *priv = widget->priv;
GParamSpec *pspec;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (child_property != NULL);
- if (!G_OBJECT (widget)->ref_count || !widget->parent)
+ if (!G_OBJECT (widget)->ref_count || !priv->parent)
return;
g_object_ref (widget);
pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
child_property,
- G_OBJECT_TYPE (widget->parent),
+ G_OBJECT_TYPE (priv->parent),
TRUE);
if (!pspec)
g_warning ("%s: container class `%s' has no child property named `%s'",
G_STRLOC,
- G_OBJECT_TYPE_NAME (widget->parent),
+ G_OBJECT_TYPE_NAME (priv->parent),
child_property);
else
{
* @widget: a #GtkWidget
*
* Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
- * This causes all queued #GtkWidget::child-notify signals on @widget to be
+ * This causes all queued #GtkWidget::child-notify signals on @widget to be
* emitted.
- */
+ */
void
gtk_widget_thaw_child_notify (GtkWidget *widget)
{
* gtk_widget_new:
* @type: type ID of the widget to create
* @first_property_name: name of first property to set
- * @Varargs: value of first property, followed by more properties,
+ * @Varargs: value of first property, followed by more properties,
* %NULL-terminated
- *
+ *
* This is a convenience function for creating a widget and setting
* its properties in one go. For example you might write:
* <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
* 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
* g_object_new(), but returns a widget so you don't have to
* cast the object yourself.
- *
+ *
* Return value: a new #GtkWidget of type @widget_type
**/
GtkWidget*
{
GtkWidget *widget;
va_list var_args;
-
+
g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
-
+
va_start (var_args, first_property_name);
widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
va_end (var_args);
return widget;
}
-static inline void
+static inline void
gtk_widget_queue_draw_child (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv = widget->priv;
GtkWidget *parent;
- parent = widget->parent;
+ parent = priv->parent;
if (parent && gtk_widget_is_drawable (parent))
gtk_widget_queue_draw_area (parent,
- widget->allocation.x,
- widget->allocation.y,
- widget->allocation.width,
- widget->allocation.height);
+ priv->allocation.x,
+ priv->allocation.y,
+ priv->allocation.width,
+ priv->allocation.height);
}
/**
* gtk_widget_unparent:
* @widget: a #GtkWidget
- *
+ *
* This function is only for use in widget implementations.
* Should be called by implementations of the remove method
* on #GtkContainer, to dissociate a child from the container.
void
gtk_widget_unparent (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv;
GObjectNotifyQueue *nqueue;
GtkWidget *toplevel;
GtkWidget *old_parent;
-
+
g_return_if_fail (GTK_IS_WIDGET (widget));
- if (widget->parent == NULL)
+
+ priv = widget->priv;
+
+ if (priv->parent == NULL)
return;
-
+
/* keep this function in sync with gtk_menu_detach()
*/
if (gtk_widget_is_toplevel (toplevel))
_gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
- if (gtk_container_get_focus_child (GTK_CONTAINER (widget->parent)) == widget)
- gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
+ if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
+ gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
/* If we are unanchoring the child, we save around the toplevel
* to emit hierarchy changed
*/
- if (GTK_WIDGET_ANCHORED (widget->parent))
+ if (priv->parent->priv->anchored)
g_object_ref (toplevel);
else
toplevel = NULL;
* allocation is smaller than 1x1 and we actually want a size of 1x1...
* (would 0x0 be OK here?)
*/
- widget->allocation.width = 1;
- widget->allocation.height = 1;
-
+ priv->allocation.width = 1;
+ priv->allocation.height = 1;
+
if (gtk_widget_get_realized (widget))
{
- if (GTK_WIDGET_IN_REPARENT (widget))
+ if (priv->in_reparent)
gtk_widget_unmap (widget);
else
gtk_widget_unrealize (widget);
* flag to the default state, so it doesn't affect the child
* in the next parent.
*/
- GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
-
- old_parent = widget->parent;
- widget->parent = NULL;
+ priv->child_visible = TRUE;
+
+ old_parent = priv->parent;
+ priv->parent = NULL;
gtk_widget_set_parent_window (widget, NULL);
+
+ /* parent may no longer expand if the removed
+ * child was expand=TRUE and could therefore
+ * be forcing it to.
+ */
+ if (gtk_widget_get_visible (widget) &&
+ (priv->need_compute_expand ||
+ priv->computed_hexpand ||
+ priv->computed_vexpand))
+ {
+ gtk_widget_queue_compute_expand (old_parent);
+ }
+
g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
if (toplevel)
{
_gtk_widget_propagate_hierarchy_changed (widget, toplevel);
g_object_unref (toplevel);
}
-
+
g_object_notify (G_OBJECT (widget), "parent");
g_object_thaw_notify (G_OBJECT (widget));
- if (!widget->parent)
+ if (!priv->parent)
g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
g_object_unref (widget);
* gtk_widget_destroy:
* @widget: a #GtkWidget
*
- * Destroys a widget. Equivalent to gtk_object_destroy(), except that
- * you don't have to cast the widget to #GtkObject. When a widget is
+ * Destroys a widget.
+ *
+ * When a widget is
* destroyed, it will break any references it holds to other objects.
* If the widget is inside a container, the widget will be removed
* from the container. If the widget is a toplevel (derived from
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- gtk_object_destroy ((GtkObject*) widget);
+ if (!widget->priv->in_destruction)
+ g_object_run_dispose (G_OBJECT (widget));
}
/**
/**
* gtk_widget_show:
* @widget: a #GtkWidget
- *
+ *
* Flags a widget to be displayed. Any widget that isn't shown will
* not appear on the screen. If you want to show all the widgets in a
* container, it's easier to call gtk_widget_show_all() on the
g_object_ref (widget);
if (!gtk_widget_is_toplevel (widget))
gtk_widget_queue_resize (widget);
+
+ /* see comment in set_parent() for why this should and can be
+ * conditional
+ */
+ if (widget->priv->need_compute_expand ||
+ widget->priv->computed_hexpand ||
+ widget->priv->computed_vexpand)
+ {
+ if (widget->priv->parent != NULL)
+ gtk_widget_queue_compute_expand (widget->priv->parent);
+ }
+
g_signal_emit (widget, widget_signals[SHOW], 0);
g_object_notify (G_OBJECT (widget), "visible");
g_object_unref (widget);
static void
gtk_widget_real_show (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv = widget->priv;
+
if (!gtk_widget_get_visible (widget))
{
- GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
+ priv->visible = TRUE;
- if (widget->parent &&
- gtk_widget_get_mapped (widget->parent) &&
- GTK_WIDGET_CHILD_VISIBLE (widget) &&
+ if (priv->parent &&
+ gtk_widget_get_mapped (priv->parent) &&
+ gtk_widget_get_child_visible (widget) &&
!gtk_widget_get_mapped (widget))
gtk_widget_map (widget);
}
{
*flag = TRUE;
g_signal_handlers_disconnect_by_func (widget,
- gtk_widget_show_map_callback,
+ gtk_widget_show_map_callback,
flag);
}
/**
* gtk_widget_show_now:
* @widget: a #GtkWidget
- *
+ *
* Shows a widget. If the widget is an unmapped toplevel widget
* (i.e. a #GtkWindow that has not yet been shown), enter the main
* loop and wait for the window to actually be mapped. Be careful;
gtk_widget_show_now (GtkWidget *widget)
{
gint flag = FALSE;
-
+
g_return_if_fail (GTK_IS_WIDGET (widget));
/* make sure we will get event */
gtk_widget_show (widget);
g_signal_connect (widget, "map-event",
- G_CALLBACK (gtk_widget_show_map_callback),
+ G_CALLBACK (gtk_widget_show_map_callback),
&flag);
while (!flag)
/**
* gtk_widget_hide:
* @widget: a #GtkWidget
- *
+ *
* Reverses the effects of gtk_widget_show(), causing the widget to be
* hidden (invisible to the user).
**/
gtk_widget_hide (GtkWidget *widget)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
-
+
if (gtk_widget_get_visible (widget))
{
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
-
+
g_object_ref (widget);
if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
_gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
+ /* a parent may now be expand=FALSE since we're hidden. */
+ if (widget->priv->need_compute_expand ||
+ widget->priv->computed_hexpand ||
+ widget->priv->computed_vexpand)
+ {
+ gtk_widget_queue_compute_expand (widget);
+ }
+
g_signal_emit (widget, widget_signals[HIDE], 0);
if (!gtk_widget_is_toplevel (widget))
gtk_widget_queue_resize (widget);
{
if (gtk_widget_get_visible (widget))
{
- GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
-
+ widget->priv->visible = FALSE;
+
if (gtk_widget_get_mapped (widget))
gtk_widget_unmap (widget);
}
/**
* gtk_widget_hide_on_delete:
* @widget: a #GtkWidget
- *
+ *
* Utility function; intended to be connected to the #GtkWidget::delete-event
* signal on a #GtkWindow. The function calls gtk_widget_hide() on its
* argument, then returns %TRUE. If connected to ::delete-event, the
* window frame, top right corner usually) will hide but not destroy
* the window. By default, GTK+ destroys windows when ::delete-event
* is received.
- *
+ *
* Return value: %TRUE
**/
gboolean
gtk_widget_hide_on_delete (GtkWidget *widget)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
-
+
gtk_widget_hide (widget);
-
+
return TRUE;
}
/**
* gtk_widget_show_all:
* @widget: a #GtkWidget
- *
+ *
* Recursively shows a widget, and any child widgets (if the widget is
* a container).
**/
class->show_all (widget);
}
-/**
- * gtk_widget_hide_all:
- * @widget: a #GtkWidget
- *
- * Recursively hides a widget and any child widgets.
- **/
-void
-gtk_widget_hide_all (GtkWidget *widget)
-{
- GtkWidgetClass *class;
-
- g_return_if_fail (GTK_IS_WIDGET (widget));
-
- if (gtk_widget_get_no_show_all (widget))
- return;
-
- class = GTK_WIDGET_GET_CLASS (widget);
-
- if (class->hide_all)
- class->hide_all (widget);
-}
-
/**
* gtk_widget_map:
* @widget: a #GtkWidget
- *
+ *
* This function is only for use in widget implementations. Causes
* a widget to be mapped if it isn't already.
**/
void
gtk_widget_map (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (gtk_widget_get_visible (widget));
- g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
-
+ g_return_if_fail (gtk_widget_get_child_visible (widget));
+
+ priv = widget->priv;
+
if (!gtk_widget_get_mapped (widget))
{
if (!gtk_widget_get_realized (widget))
g_signal_emit (widget, widget_signals[MAP], 0);
if (!gtk_widget_get_has_window (widget))
- gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
+ gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
}
}
void
gtk_widget_unmap (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
-
+
+ priv = widget->priv;
+
if (gtk_widget_get_mapped (widget))
{
if (!gtk_widget_get_has_window (widget))
- gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
+ gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
_gtk_tooltip_hide (widget);
g_signal_emit (widget, widget_signals[UNMAP], 0);
}
GdkExtensionMode mode,
GList *window_list)
{
+ GtkWidgetPrivate *priv = widget->priv;
GList *free_list = NULL;
GList *l;
if (window_list == NULL)
{
if (gtk_widget_get_has_window (widget))
- window_list = g_list_prepend (NULL, widget->window);
+ window_list = g_list_prepend (NULL, priv->window);
else
- window_list = gdk_window_get_children (widget->window);
+ window_list = gdk_window_get_children (priv->window);
free_list = window_list;
}
/**
* gtk_widget_realize:
* @widget: a #GtkWidget
- *
+ *
* Creates the GDK (windowing system) resources associated with a
* widget. For example, @widget->window will be created when a widget
* is realized. Normally realization happens implicitly; if you show
* a widget and all its parent containers, then the widget will be
* realized and mapped automatically.
- *
+ *
* Realizing a widget requires all
* the widget's parent widgets to be realized; calling
* gtk_widget_realize() realizes the widget's parents in addition to
* isn't very useful otherwise. Many times when you think you might
* need it, a better approach is to connect to a signal that will be
* called after the widget is realized automatically, such as
- * GtkWidget::expose-event. Or simply g_signal_connect () to the
- * GtkWidget::realize signal.
+ * #GtkWidget::expose-event. Or simply g_signal_connect () to the
+ * #GtkWidget::realize signal.
**/
void
gtk_widget_realize (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv;
GdkExtensionMode mode;
- GtkWidgetShapeInfo *shape_info;
-
+ cairo_region_t *region;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
- g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
+ g_return_if_fail (widget->priv->anchored ||
GTK_IS_INVISIBLE (widget));
-
+
+ priv = widget->priv;
+
if (!gtk_widget_get_realized (widget))
{
/*
g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
*/
- if (widget->parent == NULL &&
+ if (priv->parent == NULL &&
!gtk_widget_is_toplevel (widget))
g_warning ("Calling gtk_widget_realize() on a widget that isn't "
"inside a toplevel window is not going to work very well. "
"Widgets must be inside a toplevel container before realizing them.");
-
- if (widget->parent && !gtk_widget_get_realized (widget->parent))
- gtk_widget_realize (widget->parent);
+
+ if (priv->parent && !gtk_widget_get_realized (priv->parent))
+ gtk_widget_realize (priv->parent);
gtk_widget_ensure_style (widget);
-
+
g_signal_emit (widget, widget_signals[REALIZE], 0);
gtk_widget_real_set_has_tooltip (widget,
GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
TRUE);
- if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
+ if (priv->has_shape_mask)
{
- shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
- gdk_window_shape_combine_mask (widget->window,
- shape_info->shape_mask,
- shape_info->offset_x,
- shape_info->offset_y);
+ region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
+ gdk_window_shape_combine_region (priv->window, region, 0, 0);
}
-
- shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
- if (shape_info)
- gdk_window_input_shape_combine_mask (widget->window,
- shape_info->shape_mask,
- shape_info->offset_x,
- shape_info->offset_y);
+
+ region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
+ if (region)
+ gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
mode = gtk_widget_get_extension_events (widget);
if (mode != GDK_EXTENSION_EVENTS_NONE)
gtk_widget_set_extension_events_internal (widget, mode, NULL);
- if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
- gdk_window_set_support_multidevice (widget->window, TRUE);
+ if (priv->multidevice)
+ gdk_window_set_support_multidevice (priv->window, TRUE);
_gtk_widget_enable_device_events (widget);
}
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
- gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
+ if (widget->priv->has_shape_mask)
+ gtk_widget_shape_combine_region (widget, NULL);
if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
- gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
+ gtk_widget_input_shape_combine_region (widget, NULL);
if (gtk_widget_get_realized (widget))
{
*****************************************/
/**
- * gtk_widget_queue_draw_area:
+ * gtk_widget_queue_draw_region:
* @widget: a #GtkWidget
- * @x: x coordinate of upper-left corner of rectangle to redraw
- * @y: y coordinate of upper-left corner of rectangle to redraw
- * @width: width of region to draw
- * @height: height of region to draw
+ * @region: region to draw
*
- * Invalidates the rectangular area of @widget defined by @x, @y,
- * @width and @height by calling gdk_window_invalidate_rect() on the
- * widget's window and all its child windows. Once the main loop
- * becomes idle (after the current batch of events has been processed,
- * roughly), the window will receive expose events for the union of
- * all regions that have been invalidated.
+ * Invalidates the rectangular area of @widget defined by @region by
+ * calling gdk_window_invalidate_region() on the widget's window and
+ * all its child windows. Once the main loop becomes idle (after the
+ * current batch of events has been processed, roughly), the window
+ * will receive expose events for the union of all regions that have
+ * been invalidated.
*
* Normally you would only use this function in widget
- * implementations. You might also use it, or
- * gdk_window_invalidate_rect() directly, to schedule a redraw of a
+ * implementations. You might also use it to schedule a redraw of a
* #GtkDrawingArea or some portion thereof.
- *
- * Frequently you can just call gdk_window_invalidate_rect() or
- * gdk_window_invalidate_region() instead of this function. Those
- * functions will invalidate only a single window, instead of the
- * widget and all its children.
- *
- * The advantage of adding to the invalidated region compared to
- * simply drawing immediately is efficiency; using an invalid region
- * ensures that you only have to redraw one time.
**/
-void
-gtk_widget_queue_draw_area (GtkWidget *widget,
- gint x,
- gint y,
- gint width,
- gint height)
+void
+gtk_widget_queue_draw_region (GtkWidget *widget,
+ cairo_region_t *region)
{
- GdkRectangle invalid_rect;
+ GtkWidgetPrivate *priv;
GtkWidget *w;
-
+
g_return_if_fail (GTK_IS_WIDGET (widget));
+ priv = widget->priv;
+
if (!gtk_widget_get_realized (widget))
return;
-
+
/* Just return if the widget or one of its ancestors isn't mapped */
- for (w = widget; w != NULL; w = w->parent)
+ for (w = widget; w != NULL; w = w->priv->parent)
if (!gtk_widget_get_mapped (w))
return;
- /* Find the correct widget */
+ gdk_window_invalidate_region (priv->window, region, TRUE);
+}
- if (gtk_widget_get_has_window (widget))
- {
- if (widget->parent)
- {
- /* Translate widget relative to window-relative */
-
- gint wx, wy, wwidth, wheight;
-
- gdk_window_get_position (widget->window, &wx, &wy);
- x -= wx - widget->allocation.x;
- y -= wy - widget->allocation.y;
-
- gdk_drawable_get_size (widget->window, &wwidth, &wheight);
-
- if (x + width <= 0 || y + height <= 0 ||
- x >= wwidth || y >= wheight)
- return;
-
- if (x < 0)
- {
- width += x; x = 0;
- }
- if (y < 0)
- {
- height += y; y = 0;
- }
- if (x + width > wwidth)
- width = wwidth - x;
- if (y + height > wheight)
- height = wheight - y;
- }
- }
+/**
+ * gtk_widget_queue_draw_area:
+ * @widget: a #GtkWidget
+ * @x: x coordinate of upper-left corner of rectangle to redraw
+ * @y: y coordinate of upper-left corner of rectangle to redraw
+ * @width: width of region to draw
+ * @height: height of region to draw
+ *
+ * Convenience function that calls gtk_widget_queue_draw_region() on
+ * the region created from the given coordinates.
+ **/
+void
+gtk_widget_queue_draw_area (GtkWidget *widget,
+ gint x,
+ gint y,
+ gint width,
+ gint height)
+{
+ GdkRectangle rect;
+ cairo_region_t *region;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ rect.x = x;
+ rect.y = y;
+ rect.width = width;
+ rect.height = height;
- invalid_rect.x = x;
- invalid_rect.y = y;
- invalid_rect.width = width;
- invalid_rect.height = height;
-
- gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
+ region = cairo_region_create_rectangle (&rect);
+ gtk_widget_queue_draw_region (widget, region);
+ cairo_region_destroy (region);
}
/**
* Equivalent to calling gtk_widget_queue_draw_area() for the
* entire area of a widget.
**/
-void
+void
gtk_widget_queue_draw (GtkWidget *widget)
{
GdkRectangle rect;
-
+
g_return_if_fail (GTK_IS_WIDGET (widget));
gtk_widget_get_allocation (widget, &rect);
if (gtk_widget_get_realized (widget))
gtk_widget_queue_shallow_draw (widget);
-
- _gtk_size_group_queue_resize (widget);
+
+ _gtk_size_group_queue_resize (widget, 0);
}
/**
* gtk_widget_queue_resize_no_redraw:
* @widget: a #GtkWidget
*
- * This function works like gtk_widget_queue_resize(),
+ * This function works like gtk_widget_queue_resize(),
* except that the widget is not invalidated.
*
* Since: 2.4
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- _gtk_size_group_queue_resize (widget);
+ _gtk_size_group_queue_resize (widget, 0);
}
/**
* gtk_widget_size_request:
* @widget: a #GtkWidget
* @requisition: (out): a #GtkRequisition to be filled in
- *
+ *
* This function is typically used when implementing a #GtkContainer
* subclass. Obtains the preferred size of a widget. The container
* uses this information to arrange its child widgets and decide what
* Also remember that the size request is not necessarily the size
* a widget will actually be allocated.
*
- * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
+ * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
**/
void
gtk_widget_size_request (GtkWidget *widget,
{
g_return_if_fail (GTK_IS_WIDGET (widget));
-#ifdef G_ENABLE_DEBUG
- if (requisition == &widget->requisition)
- g_warning ("gtk_widget_size_request() called on child widget with request equal\n"
- "to widget->requisition. gtk_widget_set_usize() may not work properly.");
-#endif /* G_ENABLE_DEBUG */
-
- gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
+ gtk_widget_get_preferred_size (widget, requisition, NULL);
}
/**
* gtk_widget_get_child_requisition:
* @widget: a #GtkWidget
* @requisition: (out): a #GtkRequisition to be filled in
- *
+ *
* This function is only for use in widget implementations. Obtains
* @widget->requisition, unless someone has forced a particular
* geometry on the widget (e.g. with gtk_widget_set_size_request()),
* gtk_widget_size_request().
*
*
- * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
+ * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
**/
void
gtk_widget_get_child_requisition (GtkWidget *widget,
GtkRequisition *requisition)
{
- gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
+ gtk_widget_get_preferred_size (widget, requisition, NULL);
}
static gboolean
gtk_widget_invalidate_widget_windows (GtkWidget *widget,
cairo_region_t *region)
{
+ GtkWidgetPrivate *priv = widget->priv;
+
if (!gtk_widget_get_realized (widget))
return;
-
- if (gtk_widget_get_has_window (widget) && widget->parent)
+
+ if (gtk_widget_get_has_window (widget) && priv->parent)
{
int x, y;
-
- gdk_window_get_position (widget->window, &x, &y);
+
+ gdk_window_get_position (priv->window, &x, &y);
cairo_region_translate (region, -x, -y);
}
- gdk_window_invalidate_maybe_recurse (widget->window, region,
+ gdk_window_invalidate_maybe_recurse (priv->window, region,
invalidate_predicate, widget);
}
* @allocation: (inout): position and size to be allocated to @widget
*
* This function is only used by #GtkContainer subclasses, to assign a size
- * and position to their child widgets.
+ * and position to their child widgets.
+ *
+ * In this function, the allocation may be adjusted. It will be forced
+ * to a 1x1 minimum size, and the adjust_size_allocation virtual
+ * method on the child will be used to adjust the allocation. Standard
+ * adjustments include removing the widget's margins, and applying the
+ * widget's #GtkWidget:halign and #GtkWidget:valign properties.
**/
void
gtk_widget_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
- GtkWidgetAuxInfo *aux_info;
+ GtkWidgetPrivate *priv;
GdkRectangle real_allocation;
GdkRectangle old_allocation;
+ GdkRectangle adjusted_allocation;
gboolean alloc_needed;
gboolean size_changed;
gboolean position_changed;
-
+ gint natural_width, natural_height;
+ gint min_width, min_height;
+
+ priv = widget->priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
-
+
#ifdef G_ENABLE_DEBUG
- if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
+ if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
{
gint depth;
GtkWidget *parent;
depth++;
parent = gtk_widget_get_parent (parent);
}
-
+
name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
- g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
- 2 * depth, " ", name,
+ g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
+ 2 * depth, " ", name,
allocation->width, allocation->height);
}
#endif /* G_ENABLE_DEBUG */
-
- alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
- if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
- GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
- old_allocation = widget->allocation;
+ alloc_needed = priv->alloc_needed;
+ if (!priv->width_request_needed && !priv->height_request_needed)
+ /* Preserve request/allocate ordering */
+ priv->alloc_needed = FALSE;
+
+ old_allocation = priv->allocation;
real_allocation = *allocation;
- aux_info =_gtk_widget_get_aux_info (widget, FALSE);
-
- if (aux_info)
+
+ adjusted_allocation = real_allocation;
+ if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
+ {
+ /* Go ahead and request the height for allocated width, note that the internals
+ * of get_height_for_width will internally limit the for_size to natural size
+ * when aligning implicitly.
+ */
+ gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
+ gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, NULL, &natural_height);
+ }
+ else
+ {
+ /* Go ahead and request the width for allocated height, note that the internals
+ * of get_width_for_height will internally limit the for_size to natural size
+ * when aligning implicitly.
+ */
+ gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
+ gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, NULL, &natural_width);
+ }
+
+ /* Now that we have the right natural height and width, go ahead and remove any margins from the
+ * allocated sizes and possibly limit them to the natural sizes */
+ GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
+ GTK_ORIENTATION_HORIZONTAL,
+ &natural_width,
+ &adjusted_allocation.x,
+ &adjusted_allocation.width);
+ GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
+ GTK_ORIENTATION_VERTICAL,
+ &natural_height,
+ &adjusted_allocation.y,
+ &adjusted_allocation.height);
+
+ if (adjusted_allocation.x < real_allocation.x ||
+ adjusted_allocation.y < real_allocation.y ||
+ (adjusted_allocation.x + adjusted_allocation.width) >
+ (real_allocation.x + real_allocation.width) ||
+ (adjusted_allocation.y + adjusted_allocation.height >
+ real_allocation.y + real_allocation.height))
+ {
+ g_warning ("%s %p attempted to adjust its size allocation from %d,%d %dx%d to %d,%d %dx%d. adjust_size_allocation must keep allocation inside original bounds",
+ G_OBJECT_TYPE_NAME (widget), widget,
+ real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
+ adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
+ adjusted_allocation = real_allocation; /* veto it */
+ }
+ else
{
- if (aux_info->x_set)
- real_allocation.x = aux_info->x;
- if (aux_info->y_set)
- real_allocation.y = aux_info->y;
+ real_allocation = adjusted_allocation;
}
if (real_allocation.width < 0 || real_allocation.height < 0)
real_allocation.width,
real_allocation.height);
}
-
+
real_allocation.width = MAX (real_allocation.width, 1);
real_allocation.height = MAX (real_allocation.height, 1);
if (!alloc_needed && !size_changed && !position_changed)
return;
-
+
g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
if (gtk_widget_get_mapped (widget))
{
- if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
+ if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
{
- /* Invalidate union(old_allaction,widget->allocation) in widget->window
+ /* Invalidate union(old_allaction,priv->allocation) in priv->window
*/
- cairo_region_t *invalidate = cairo_region_create_rectangle (&widget->allocation);
+ cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
cairo_region_union_rectangle (invalidate, &old_allocation);
- gdk_window_invalidate_region (widget->window, invalidate, FALSE);
+ gdk_window_invalidate_region (priv->window, invalidate, FALSE);
cairo_region_destroy (invalidate);
}
-
+
if (size_changed)
{
- if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
+ if (priv->redraw_on_alloc)
{
- /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
+ /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
*/
- cairo_region_t *invalidate = cairo_region_create_rectangle (&widget->allocation);
+ cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
cairo_region_union_rectangle (invalidate, &old_allocation);
gtk_widget_invalidate_widget_windows (widget, invalidate);
}
}
- if ((size_changed || position_changed) && widget->parent &&
- gtk_widget_get_realized (widget->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (widget->parent)))
+ if ((size_changed || position_changed) && priv->parent &&
+ gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
{
- cairo_region_t *invalidate = cairo_region_create_rectangle (&widget->parent->allocation);
- gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
+ cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
+ gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
cairo_region_destroy (invalidate);
}
}
* gtk_widget_common_ancestor:
* @widget_a: a #GtkWidget
* @widget_b: a #GtkWidget
- *
+ *
* Find the common ancestor of @widget_a and @widget_b that
* is closest to the two widgets.
- *
+ *
* Return value: the closest common ancestor of @widget_a and
* @widget_b or %NULL if @widget_a and @widget_b do not
* share a common ancestor.
gint depth_b = 0;
parent_a = widget_a;
- while (parent_a->parent)
+ while (parent_a->priv->parent)
{
- parent_a = parent_a->parent;
+ parent_a = parent_a->priv->parent;
depth_a++;
}
parent_b = widget_b;
- while (parent_b->parent)
+ while (parent_b->priv->parent)
{
- parent_b = parent_b->parent;
+ parent_b = parent_b->priv->parent;
depth_b++;
}
while (depth_a > depth_b)
{
- widget_a = widget_a->parent;
+ widget_a = widget_a->priv->parent;
depth_a--;
}
while (depth_b > depth_a)
{
- widget_b = widget_b->parent;
+ widget_b = widget_b->priv->parent;
depth_b--;
}
while (widget_a != widget_b)
{
- widget_a = widget_a->parent;
- widget_b = widget_b->parent;
+ widget_a = widget_a->priv->parent;
+ widget_b = widget_b->priv->parent;
}
return widget_a;
* relative to @dest_widget's allocations. In order to perform this
* operation, both widgets must be realized, and must share a common
* toplevel.
- *
+ *
* Return value: %FALSE if either widget was not realized, or there
* was no common ancestor. In this case, nothing is stored in
* *@dest_x and *@dest_y. Otherwise %TRUE.
gint *dest_x,
gint *dest_y)
{
+ GtkWidgetPrivate *src_priv = src_widget->priv;
+ GtkWidgetPrivate *dest_priv = dest_widget->priv;
GtkWidget *ancestor;
GdkWindow *window;
GList *dest_list = NULL;
return FALSE;
/* Translate from allocation relative to window relative */
- if (gtk_widget_get_has_window (src_widget) && src_widget->parent)
+ if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
{
gint wx, wy;
- gdk_window_get_position (src_widget->window, &wx, &wy);
+ gdk_window_get_position (src_priv->window, &wx, &wy);
- src_x -= wx - src_widget->allocation.x;
- src_y -= wy - src_widget->allocation.y;
+ src_x -= wx - src_priv->allocation.x;
+ src_y -= wy - src_priv->allocation.y;
}
else
{
- src_x += src_widget->allocation.x;
- src_y += src_widget->allocation.y;
+ src_x += src_priv->allocation.x;
+ src_y += src_priv->allocation.y;
}
/* Translate to the common ancestor */
- window = src_widget->window;
- while (window != ancestor->window)
+ window = src_priv->window;
+ while (window != ancestor->priv->window)
{
gdouble dx, dy;
}
/* And back */
- window = dest_widget->window;
- while (window != ancestor->window)
+ window = dest_priv->window;
+ while (window != ancestor->priv->window)
{
dest_list = g_list_prepend (dest_list, window);
}
/* Translate from window relative to allocation relative */
- if (gtk_widget_get_has_window (dest_widget) && dest_widget->parent)
+ if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
{
gint wx, wy;
- gdk_window_get_position (dest_widget->window, &wx, &wy);
+ gdk_window_get_position (dest_priv->window, &wx, &wy);
- src_x += wx - dest_widget->allocation.x;
- src_y += wy - dest_widget->allocation.y;
+ src_x += wx - dest_priv->allocation.x;
+ src_y += wy - dest_priv->allocation.y;
}
else
{
- src_x -= dest_widget->allocation.x;
- src_y -= dest_widget->allocation.y;
+ src_x -= dest_priv->allocation.x;
+ src_y -= dest_priv->allocation.y;
}
if (dest_x)
gtk_widget_real_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
- widget->allocation = *allocation;
-
+ GtkWidgetPrivate *priv = widget->priv;
+
+ priv->allocation = *allocation;
+
if (gtk_widget_get_realized (widget) &&
gtk_widget_get_has_window (widget))
{
- gdk_window_move_resize (widget->window,
+ gdk_window_move_resize (priv->window,
allocation->x, allocation->y,
allocation->width, allocation->height);
}
}
-static gboolean
-gtk_widget_real_can_activate_accel (GtkWidget *widget,
- guint signal_id)
+static void
+adjust_for_align(GtkAlign align,
+ gint *natural_size,
+ gint *allocated_pos,
+ gint *allocated_size)
{
- /* widgets must be onscreen for accels to take effect */
- return gtk_widget_is_sensitive (widget) &&
- gtk_widget_is_drawable (widget) &&
- gdk_window_is_viewable (widget->window);
-}
-
-/**
- * gtk_widget_can_activate_accel:
- * @widget: a #GtkWidget
- * @signal_id: the ID of a signal installed on @widget
- *
- * Determines whether an accelerator that activates the signal
- * identified by @signal_id can currently be activated.
+ switch (align)
+ {
+ case GTK_ALIGN_FILL:
+ /* change nothing */
+ break;
+ case GTK_ALIGN_START:
+ /* keep *allocated_pos where it is */
+ *allocated_size = MIN (*allocated_size, *natural_size);
+ break;
+ case GTK_ALIGN_END:
+ if (*allocated_size > *natural_size)
+ {
+ *allocated_pos += (*allocated_size - *natural_size);
+ *allocated_size = *natural_size;
+ }
+ break;
+ case GTK_ALIGN_CENTER:
+ if (*allocated_size > *natural_size)
+ {
+ *allocated_pos += (*allocated_size - *natural_size) / 2;
+ *allocated_size = MIN (*allocated_size, *natural_size);
+ }
+ break;
+ }
+}
+
+static void
+adjust_for_margin(gint start_margin,
+ gint end_margin,
+ gint *natural_size,
+ gint *allocated_pos,
+ gint *allocated_size)
+{
+ *natural_size -= (start_margin + end_margin);
+ *allocated_pos += start_margin;
+ *allocated_size -= (start_margin + end_margin);
+}
+
+static void
+gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint *natural_size,
+ gint *allocated_pos,
+ gint *allocated_size)
+{
+ const GtkWidgetAuxInfo *aux_info;
+
+ aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ adjust_for_margin (aux_info->margin.left,
+ aux_info->margin.right,
+ natural_size, allocated_pos, allocated_size);
+ adjust_for_align (aux_info->halign,
+ natural_size, allocated_pos, allocated_size);
+ }
+ else
+ {
+ adjust_for_margin (aux_info->margin.top,
+ aux_info->margin.bottom,
+ natural_size, allocated_pos, allocated_size);
+ adjust_for_align (aux_info->valign,
+ natural_size, allocated_pos, allocated_size);
+ }
+}
+
+static gboolean
+gtk_widget_real_can_activate_accel (GtkWidget *widget,
+ guint signal_id)
+{
+ GtkWidgetPrivate *priv = widget->priv;
+
+ /* widgets must be onscreen for accels to take effect */
+ return gtk_widget_is_sensitive (widget) &&
+ gtk_widget_is_drawable (widget) &&
+ gdk_window_is_viewable (priv->window);
+}
+
+/**
+ * gtk_widget_can_activate_accel:
+ * @widget: a #GtkWidget
+ * @signal_id: the ID of a signal installed on @widget
+ *
+ * Determines whether an accelerator that activates the signal
+ * identified by @signal_id can currently be activated.
* This is done by emitting the #GtkWidget::can-activate-accel
* signal on @widget; if the signal isn't overridden by a
* handler or in a derived widget, then the default check is
g_closure_set_marshal (closure, closure_accel_activate);
}
g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
-
+
aclosure = (AccelClosure*) closure;
g_assert (closure->data == widget);
g_assert (closure->marshal == closure_accel_activate);
GtkAccelGroupEntry *ag_entry;
GList *slist, *clist;
guint n;
-
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
}
/**
- * gtk_widget_list_accel_closures
+ * gtk_widget_list_accel_closures:
* @widget: widget to list accelerator closures for
- * @returns: a newly allocated #GList of closures
*
* Lists the closures used by @widget for accelerator group connections
* with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
* The closures can be used to monitor accelerator changes on @widget,
- * by connecting to the @GtkAccelGroup::accel-changed signal of the
- * #GtkAccelGroup of a closure which can be found out with
+ * by connecting to the @GtkAccelGroup::accel-changed signal of the
+ * #GtkAccelGroup of a closure which can be found out with
* gtk_accel_group_from_accel_closure().
+ *
+ * Return value: (transfer container) (element-type GClosure):
+ * a newly allocated #GList of closures
*/
GList*
gtk_widget_list_accel_closures (GtkWidget *widget)
/* closures_destroy takes care of unrefing the closure */
g_object_unref (apath->accel_group);
-
+
g_slice_free (AccelPath, apath);
}
* Even when you you aren't using #GtkUIManager, if you only want to
* set up accelerators on menu items gtk_menu_item_set_accel_path()
* provides a somewhat more convenient interface.
- *
+ *
* Note that @accel_path string will be stored in a #GQuark. Therefore, if you
- * pass a static string, you can save some memory by interning it first with
+ * pass a static string, you can save some memory by interning it first with
* g_intern_static_string().
**/
void
* @group_cycling: %TRUE if there are other widgets with the same mnemonic
*
* Emits the #GtkWidget::mnemonic-activate signal.
- *
+ *
* The default handler for this signal activates the @widget if
* @group_cycling is %FALSE, and just grabs the focus if @group_cycling
* is %TRUE.
gboolean group_cycling)
{
gboolean handled;
-
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
group_cycling = group_cycling != FALSE;
return TRUE;
}
+static const cairo_user_data_key_t event_key;
+
+GdkEventExpose *
+_gtk_cairo_get_event (cairo_t *cr)
+{
+ g_return_val_if_fail (cr != NULL, NULL);
+
+ return cairo_get_user_data (cr, &event_key);
+}
+
+static void
+gtk_cairo_set_event (cairo_t *cr,
+ GdkEventExpose *event)
+{
+ cairo_set_user_data (cr, &event_key, event, NULL);
+}
+
+/**
+ * gtk_cairo_should_draw_window:
+ * @cr: a cairo context
+ * @window: the window to check
+ *
+ * This function is supposed to be called in #GtkWidget::draw
+ * implementations for widgets that support multiple windows.
+ * @cr must be untransformed from invoking of the draw function.
+ * This function will return %TRUE if the contents of the given
+ * @window are supposed to be drawn and %FALSE otherwise. Note
+ * that when the drawing was not initiated by the windowing
+ * system this function will return %TRUE for all windows, so
+ * you need to draw the bottommost window first. Also, do not
+ * use "else if" statements to check which window should be drawn.
+ *
+ * Returns: %TRUE if @window should be drawn
+ **/
+gboolean
+gtk_cairo_should_draw_window (cairo_t *cr,
+ GdkWindow *window)
+{
+ GdkEventExpose *event;
+
+ g_return_val_if_fail (cr != NULL, FALSE);
+ g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
+
+ event = _gtk_cairo_get_event (cr);
+
+ return event == NULL ||
+ event->window == window;
+}
+
+/* code shared by gtk_container_propagate_draw() and
+ * gtk_widget_draw()
+ */
+void
+_gtk_widget_draw_internal (GtkWidget *widget,
+ cairo_t *cr,
+ gboolean clip_to_size)
+{
+ if (!gtk_widget_is_drawable (widget))
+ return;
+
+ if (clip_to_size)
+ {
+ cairo_rectangle (cr,
+ 0, 0,
+ widget->priv->allocation.width,
+ widget->priv->allocation.height);
+ cairo_clip (cr);
+ }
+
+ if (gdk_cairo_get_clip_rectangle (cr, NULL))
+ {
+ gboolean result;
+
+ g_signal_emit (widget, widget_signals[DRAW],
+ 0, cr,
+ &result);
+ }
+}
+
+/**
+ * gtk_widget_draw:
+ * @widget: the widget to draw. It must be drawable (see
+ * gtk_widget_is_drawable()) and a size must have been allocated.
+ * @cr: a cairo context to draw to
+ *
+ * Draws @widget to @cr. The top left corner of the widget will be
+ * drawn to the currently set origin point of @cr.
+ *
+ * You should pass a cairo context as @cr argument that is in an
+ * original state. Otherwise the resulting drawing is undefined. For
+ * example changing the operator using cairo_set_operator() or the
+ * line width using cairo_set_line_width() might have unwanted side
+ * effects.
+ * You may however change the context's transform matrix - like with
+ * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
+ * region with cairo_clip() prior to calling this function. Also, it
+ * is fine to modify the context with cairo_save() and
+ * cairo_push_group() prior to calling this function.
+ *
+ * <note><para>Special purpose widgets may contain special code for
+ * rendering to the screen and might appear differently on screen
+ * and when rendered using gtk_widget_draw().</para></note>
+ **/
+void
+gtk_widget_draw (GtkWidget *widget,
+ cairo_t *cr)
+{
+ GdkEventExpose *tmp_event;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (!widget->priv->alloc_needed);
+ g_return_if_fail (cr != NULL);
+
+ cairo_save (cr);
+ /* We have to reset the event here so that draw functions can call
+ * gtk_widget_draw() on random other widgets and get the desired
+ * effect: Drawing all contents, not just the current window.
+ */
+ tmp_event = _gtk_cairo_get_event (cr);
+ gtk_cairo_set_event (cr, NULL);
+
+ _gtk_widget_draw_internal (widget, cr, TRUE);
+
+ gtk_cairo_set_event (cr, tmp_event);
+ cairo_restore (cr);
+}
+
static gboolean
gtk_widget_real_key_press_event (GtkWidget *widget,
GdkEventKey *event)
{
- return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
+ return gtk_bindings_activate_event (G_OBJECT (widget), event);
}
static gboolean
gtk_widget_real_key_release_event (GtkWidget *widget,
GdkEventKey *event)
{
- return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
+ return gtk_bindings_activate_event (G_OBJECT (widget), event);
}
static gboolean
* gtk_widget_event:
* @widget: a #GtkWidget
* @event: a #GdkEvent
- *
+ *
* Rarely-used function. This function is used to emit
* the event signals on a widget (those signals should never
* be emitted without using this function to do so).
* it were in the event queue. Don't synthesize expose events; instead,
* use gdk_window_invalidate_rect() to invalidate a region of the
* window.
- *
- * Return value: return from the event signal emission (%TRUE if
+ *
+ * Return value: return from the event signal emission (%TRUE if
* the event was handled)
**/
gboolean
"followed by gdk_window_process_updates().");
return TRUE;
}
-
+
return gtk_widget_event_internal (widget, event);
}
+/* Returns TRUE if a translation should be done */
+static gboolean
+gtk_widget_get_translation_to_window (GtkWidget *widget,
+ GdkWindow *window,
+ int *x,
+ int *y)
+{
+ GdkWindow *w, *widget_window;
+
+ if (!gtk_widget_get_has_window (widget))
+ {
+ *x = -widget->priv->allocation.x;
+ *y = -widget->priv->allocation.y;
+ }
+ else
+ {
+ *x = 0;
+ *y = 0;
+ }
+
+ widget_window = gtk_widget_get_window (widget);
+
+ for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
+ {
+ int wx, wy;
+ gdk_window_get_position (w, &wx, &wy);
+ *x += wx;
+ *y += wy;
+ }
+
+ if (w == NULL)
+ {
+ *x = 0;
+ *y = 0;
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/**
+ * gtk_cairo_transform_to_window:
+ * @cr: the cairo context to transform
+ * @widget: the widget the context is currently centered for
+ * @window: the window to transform the context to
+ *
+ * Transforms the given cairo context @cr that from @widget-relative
+ * coordinates to @window-relative coordinates.
+ * If the @widget's window is not an ancestor of @window, no
+ * modification will be applied.
+ *
+ * This is the inverse to the transformation GTK applies when
+ * preparing an expose event to be emitted with the #GtkWidget::draw
+ * signal. It is intended to help porting multiwindow widgets from
+ * GTK+ 2 to the rendering architecture of GTK+ 3.
+ **/
+void
+gtk_cairo_transform_to_window (cairo_t *cr,
+ GtkWidget *widget,
+ GdkWindow *window)
+{
+ int x, y;
+
+ g_return_if_fail (cr != NULL);
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (GDK_IS_WINDOW (window));
+
+ if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
+ cairo_translate (cr, x, y);
+}
/**
* gtk_widget_send_expose:
* @widget: a #GtkWidget
* @event: a expose #GdkEvent
- *
+ *
* Very rarely-used function. This function is used to emit
- * an expose event signals on a widget. This function is not
- * normally used directly. The only time it is used is when
- * propagating an expose event to a child %NO_WINDOW widget, and
- * that is normally done using gtk_container_propagate_expose().
+ * an expose event on a widget. This function is not normally used
+ * directly. The only time it is used is when propagating an expose
+ * event to a child %NO_WINDOW widget, and that is normally done
+ * using gtk_container_propagate_draw().
*
- * If you want to force an area of a window to be redrawn,
+ * If you want to force an area of a window to be redrawn,
* use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
* To cause the redraw to be done immediately, follow that call
* with a call to gdk_window_process_updates().
- *
- * Return value: return from the event signal emission (%TRUE if
+ *
+ * Return value: return from the event signal emission (%TRUE if
* the event was handled)
**/
gint
gtk_widget_send_expose (GtkWidget *widget,
GdkEvent *event)
{
+ gboolean result = FALSE;
+ cairo_t *cr;
+ int x, y;
+ gboolean do_clip;
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
g_return_val_if_fail (event != NULL, TRUE);
g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
- return gtk_widget_event_internal (widget, event);
+ cr = gdk_cairo_create (event->expose.window);
+ gtk_cairo_set_event (cr, &event->expose);
+
+ gdk_cairo_region (cr, event->expose.region);
+ cairo_clip (cr);
+
+ do_clip = gtk_widget_get_translation_to_window (widget,
+ event->expose.window,
+ &x, &y);
+ cairo_translate (cr, -x, -y);
+
+ _gtk_widget_draw_internal (widget, cr, do_clip);
+
+ /* unset here, so if someone keeps a reference to cr we
+ * don't leak the window. */
+ gtk_cairo_set_event (cr, NULL);
+ cairo_destroy (cr);
+
+ return result;
}
static gboolean
event_window_is_still_viewable (GdkEvent *event)
{
- /* Some programs, such as gnome-theme-manager, fake widgets
- * into exposing onto a pixmap by sending expose events with
- * event->window pointing to a pixmap
- */
- if (GDK_IS_PIXMAP (event->any.window))
- return event->type == GDK_EXPOSE;
-
/* Check that we think the event's window is viewable before
* delivering the event, to prevent suprises. We do this here
* at the last moment, since the event may have been queued
case GDK_KEY_RELEASE:
case GDK_LEAVE_NOTIFY:
case GDK_PROXIMITY_OUT:
-#endif
-
+#endif
+
default:
/* Remaining events would make sense on an not-viewable window,
* or don't have an associated window.
signal_num = VISIBILITY_NOTIFY_EVENT;
break;
case GDK_GRAB_BROKEN:
- signal_num = GRAB_BROKEN;
+ signal_num = GRAB_BROKEN_EVENT;
break;
case GDK_DAMAGE:
signal_num = DAMAGE_EVENT;
/**
* gtk_widget_activate:
* @widget: a #GtkWidget that's activatable
- *
+ *
* For widgets that can be "activated" (buttons, menu items, etc.)
* this function activates them. Activation is what happens when you
- * press Enter on a widget during key navigation. If @widget isn't
+ * press Enter on a widget during key navigation. If @widget isn't
* activatable, the function returns %FALSE.
- *
+ *
* Return value: %TRUE if the widget was activatable
**/
gboolean
gtk_widget_activate (GtkWidget *widget)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
-
+
if (WIDGET_CLASS (widget)->activate_signal)
{
/* FIXME: we should eventually check the signals signature here */
return FALSE;
}
-/**
- * gtk_widget_set_scroll_adjustments:
- * @widget: a #GtkWidget
- * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
- * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
- *
- * For widgets that support scrolling, sets the scroll adjustments and
- * returns %TRUE. For widgets that don't support scrolling, does
- * nothing and returns %FALSE. Widgets that don't support scrolling
- * can be scrolled by placing them in a #GtkViewport, which does
- * support scrolling.
- *
- * Return value: %TRUE if the widget supports scrolling
- **/
-gboolean
-gtk_widget_set_scroll_adjustments (GtkWidget *widget,
- GtkAdjustment *hadjustment,
- GtkAdjustment *vadjustment)
-{
- guint signal_id;
- GSignalQuery query;
-
- g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
-
- if (hadjustment)
- g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
- if (vadjustment)
- g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
-
- signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
- if (!signal_id)
- return FALSE;
-
- g_signal_query (signal_id, &query);
- if (!query.signal_id ||
- !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
- query.return_type != G_TYPE_NONE ||
- query.n_params != 2 ||
- query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
- query.param_types[1] != GTK_TYPE_ADJUSTMENT)
- {
- g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
- G_OBJECT_TYPE_NAME (widget), query.signal_name);
- return FALSE;
- }
-
- g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
- return TRUE;
-}
-
static void
gtk_widget_reparent_subwindows (GtkWidget *widget,
GdkWindow *new_window)
{
+ GtkWidgetPrivate *priv = widget->priv;
+
if (!gtk_widget_get_has_window (widget))
{
- GList *children = gdk_window_get_children (widget->window);
+ GList *children = gdk_window_get_children (priv->window);
GList *tmp_list;
for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
gdk_window_get_user_data (window, &child);
while (child && child != widget)
- child = ((GtkWidget*) child)->parent;
+ child = ((GtkWidget*) child)->priv->parent;
if (child)
gdk_window_reparent (window, new_window, 0, 0);
GdkWindow *parent;
GList *tmp_list, *children;
- parent = gdk_window_get_parent (widget->window);
+ parent = gdk_window_get_parent (priv->window);
if (parent == NULL)
- gdk_window_reparent (widget->window, new_window, 0, 0);
+ gdk_window_reparent (priv->window, new_window, 0, 0);
else
{
children = gdk_window_get_children (parent);
-
+
for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
{
GdkWindow *window = tmp_list->data;
if (child == widget)
gdk_window_reparent (window, new_window, 0, 0);
}
-
+
g_list_free (children);
}
}
gtk_widget_reparent_fixup_child (GtkWidget *widget,
gpointer client_data)
{
+ GtkWidgetPrivate *priv = widget->priv;
+
g_assert (client_data != NULL);
-
+
if (!gtk_widget_get_has_window (widget))
{
- if (widget->window)
- g_object_unref (widget->window);
- widget->window = (GdkWindow*) client_data;
- if (widget->window)
- g_object_ref (widget->window);
+ if (priv->window)
+ g_object_unref (priv->window);
+ priv->window = (GdkWindow*) client_data;
+ if (priv->window)
+ g_object_ref (priv->window);
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget),
gtk_widget_reparent (GtkWidget *widget,
GtkWidget *new_parent)
{
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (GTK_IS_CONTAINER (new_parent));
- g_return_if_fail (widget->parent != NULL);
-
- if (widget->parent != new_parent)
+ priv = widget->priv;
+ g_return_if_fail (priv->parent != NULL);
+
+ if (priv->parent != new_parent)
{
/* First try to see if we can get away without unrealizing
* the widget as we reparent it. if so we set a flag so
* that gtk_widget_unparent doesn't unrealize widget
*/
if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
- GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
-
+ priv->in_reparent = TRUE;
+
g_object_ref (widget);
- gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
+ gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
gtk_container_add (GTK_CONTAINER (new_parent), widget);
g_object_unref (widget);
-
- if (GTK_WIDGET_IN_REPARENT (widget))
+
+ if (priv->in_reparent)
{
- GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
+ priv->in_reparent = FALSE;
gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
gtk_widget_reparent_fixup_child (widget,
* @widget: a #GtkWidget
* @area: a rectangle
* @intersection: rectangle to store intersection of @widget and @area
- *
+ *
* Computes the intersection of a @widget's area and @area, storing
* the intersection in @intersection, and returns %TRUE if there was
* an intersection. @intersection may be %NULL if you're only
* interested in whether there was an intersection.
- *
+ *
* Return value: %TRUE if there was an intersection
**/
gboolean
const GdkRectangle *area,
GdkRectangle *intersection)
{
+ GtkWidgetPrivate *priv;
GdkRectangle *dest;
GdkRectangle tmp;
gint return_val;
-
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
g_return_val_if_fail (area != NULL, FALSE);
-
+
+ priv = widget->priv;
+
if (intersection)
dest = intersection;
else
dest = &tmp;
-
- return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
-
+
+ return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
+
if (return_val && intersection && gtk_widget_get_has_window (widget))
{
- intersection->x -= widget->allocation.x;
- intersection->y -= widget->allocation.y;
+ intersection->x -= priv->allocation.x;
+ intersection->y -= priv->allocation.y;
}
-
+
return return_val;
}
/**
* gtk_widget_region_intersect:
* @widget: a #GtkWidget
- * @region: a #cairo_region_t, in the same coordinate system as
+ * @region: a #cairo_region_t, in the same coordinate system as
* @widget->allocation. That is, relative to @widget->window
* for %NO_WINDOW widgets; relative to the parent window
* of @widget->window for widgets with their own window.
* relative to @widget->window for %NO_WINDOW widgets, and
* relative to the parent window of @widget->window for
* widgets with their own window.
- *
+ *
* Computes the intersection of a @widget's area and @region, returning
* the intersection. The result may be empty, use cairo_region_is_empty() to
* check.
{
GdkRectangle rect;
cairo_region_t *dest;
-
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_val_if_fail (region != NULL, NULL);
gtk_widget_get_allocation (widget, &rect);
-
+
dest = cairo_region_create_rectangle (&rect);
-
+
cairo_region_intersect (dest, region);
return dest;
* _gtk_widget_grab_notify:
* @widget: a #GtkWidget
* @was_grabbed: whether a grab is now in effect
- *
+ *
* Emits the #GtkWidget::grab-notify signal on @widget.
- *
+ *
* Since: 2.6
**/
void
/**
* gtk_widget_grab_focus:
* @widget: a #GtkWidget
- *
+ *
* Causes @widget to have the keyboard focus for the #GtkWindow it's
* inside. @widget must be a focusable widget, such as a #GtkEntry;
* something like #GtkFrame won't work.
if (!gtk_widget_is_sensitive (widget))
return;
-
+
g_object_ref (widget);
g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
g_object_notify (G_OBJECT (widget), "has-focus");
{
GtkWidget *toplevel;
GtkWidget *widget;
-
+
/* clear the current focus setting, break if the current widget
* is the focus widget's parent, since containers above that will
* be set by the next loop.
if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
{
widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
+
if (widget == focus_widget)
{
/* We call _gtk_window_internal_set_focus() here so that the
return;
}
-
+
if (widget)
{
- while (widget->parent && widget->parent != focus_widget->parent)
+ while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
{
- widget = widget->parent;
+ widget = widget->priv->parent;
gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
}
}
/* gtk_widget_grab_focus() operates on a tree without window...
* actually, this is very questionable behaviour.
*/
-
+
gtk_container_foreach (GTK_CONTAINER (toplevel),
reset_focus_recurse,
NULL);
* set it on the window
*/
widget = focus_widget;
- while (widget->parent)
+ while (widget->priv->parent)
{
- gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
- widget = widget->parent;
+ gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
+ widget = widget->priv->parent;
}
if (GTK_IS_WINDOW (widget))
_gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
{
if (!gtk_widget_get_can_focus (widget))
return FALSE;
-
+
if (!gtk_widget_is_focus (widget))
{
gtk_widget_grab_focus (widget);
{
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
- if (GTK_IS_WINDOW (toplevel) &&
- GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
+ if (widget != toplevel && GTK_IS_WINDOW (toplevel))
{
- GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
- direction);
+ g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
+ direction);
}
}
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- if (can_focus != gtk_widget_get_can_focus (widget))
+ if (widget->priv->can_focus != can_focus)
{
- if (can_focus)
- GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
+ widget->priv->can_focus = can_focus;
gtk_widget_queue_resize (widget);
g_object_notify (G_OBJECT (widget), "can-focus");
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
+ return widget->priv->can_focus;
}
/**
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
+ return widget->priv->has_focus;
}
/**
* gtk_widget_is_focus:
* @widget: a #GtkWidget
- *
+ *
* Determines if the widget is the focus widget within its
* toplevel. (This does not mean that the %HAS_FOCUS flag is
* necessarily set; %HAS_FOCUS will only be set if the
* toplevel widget additionally has the global input focus.)
- *
+ *
* Return value: %TRUE if the widget is the focus widget.
**/
gboolean
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
toplevel = gtk_widget_get_toplevel (widget);
-
+
if (GTK_IS_WINDOW (toplevel))
return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
else
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- if (can_default != gtk_widget_get_can_default (widget))
+ if (widget->priv->can_default != can_default)
{
- if (can_default)
- GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
+ widget->priv->can_default = can_default;
gtk_widget_queue_resize (widget);
g_object_notify (G_OBJECT (widget), "can-default");
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
+ return widget->priv->can_default;
}
/**
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
+ return widget->priv->has_default;
}
void
_gtk_widget_set_has_default (GtkWidget *widget,
gboolean has_default)
{
- if (has_default)
- GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
+ widget->priv->has_default = has_default;
}
/**
* Causes @widget to become the default widget. @widget must have the
* %GTK_CAN_DEFAULT flag set; typically you have to set this flag
* yourself by calling <literal>gtk_widget_set_can_default (@widget,
- * %TRUE)</literal>. The default widget is activated when
- * the user presses Enter in a window. Default widgets must be
+ * %TRUE)</literal>. The default widget is activated when
+ * the user presses Enter in a window. Default widgets must be
* activatable, that is, gtk_widget_activate() should affect them. Note
* that #GtkEntry widgets require the "activates-default" property
* set to %TRUE before they activate the default widget when Enter
gtk_widget_grab_default (GtkWidget *widget)
{
GtkWidget *window;
-
+
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (gtk_widget_get_can_default (widget));
-
+
window = gtk_widget_get_toplevel (widget);
-
+
if (window && gtk_widget_is_toplevel (window))
gtk_window_set_default (GTK_WINDOW (window), widget);
else
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- if (receives_default != gtk_widget_get_receives_default (widget))
+ if (widget->priv->receives_default != receives_default)
{
- if (receives_default)
- GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
+ widget->priv->receives_default = receives_default;
g_object_notify (G_OBJECT (widget), "receives-default");
}
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
+ return widget->priv->receives_default;
}
/**
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
+ return widget->priv->has_grab;
}
void
_gtk_widget_set_has_grab (GtkWidget *widget,
gboolean has_grab)
{
- if (has_grab)
- GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
+ widget->priv->has_grab = has_grab;
}
/**
!gtk_widget_is_ancestor (widget, grab_widget))
return TRUE;
- if (group->grabs)
- {
- grab_widget = group->grabs->data;
-
- if (widget != grab_widget &&
- !gtk_widget_is_ancestor (widget, grab_widget))
- return TRUE;
- }
+ grab_widget = gtk_window_group_get_current_grab (group);
+ if (grab_widget && widget != grab_widget &&
+ !gtk_widget_is_ancestor (widget, grab_widget))
+ return TRUE;
return FALSE;
}
* gtkrc file. You can apply a style to widgets with a particular name
* in the gtkrc file. See the documentation for gtkrc files (on the
* same page as the docs for #GtkRcStyle).
- *
- * Note that widget names are separated by periods in paths (see
+ *
+ * Note that widget names are separated by periods in paths (see
* gtk_widget_path()), so names with embedded periods may cause confusion.
**/
void
gtk_widget_set_name (GtkWidget *widget,
const gchar *name)
{
+ GtkWidgetPrivate *priv;
gchar *new_name;
-
+
g_return_if_fail (GTK_IS_WIDGET (widget));
+ priv = widget->priv;
+
new_name = g_strdup (name);
- g_free (widget->name);
- widget->name = new_name;
+ g_free (priv->name);
+ priv->name = new_name;
- if (gtk_widget_has_rc_style (widget))
+ if (priv->rc_style)
gtk_widget_reset_rc_style (widget);
g_object_notify (G_OBJECT (widget), "name");
/**
* gtk_widget_get_name:
* @widget: a #GtkWidget
- *
+ *
* Retrieves the name of a widget. See gtk_widget_set_name() for the
* significance of widget names.
- *
+ *
* Return value: name of the widget. This string is owned by GTK+ and
* should not be modified or freed
**/
G_CONST_RETURN gchar*
gtk_widget_get_name (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv;
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-
- if (widget->name)
- return widget->name;
+
+ priv = widget->priv;
+
+ if (priv->name)
+ return priv->name;
return G_OBJECT_TYPE_NAME (widget);
}
gtk_widget_set_state (GtkWidget *widget,
GtkStateType state)
{
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
+ priv = widget->priv;
+
if (state == gtk_widget_get_state (widget))
return;
data.state = state;
data.state_restoration = FALSE;
data.use_forall = FALSE;
- if (widget->parent)
- data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
+ if (priv->parent)
+ data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
else
data.parent_sensitive = TRUE;
gtk_widget_propagate_state (widget, &data);
-
+
if (gtk_widget_is_drawable (widget))
gtk_widget_queue_draw (widget);
}
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
- return widget->state;
+ return widget->priv->state;
}
/**
}
}
+void
+_gtk_widget_set_visible_flag (GtkWidget *widget,
+ gboolean visible)
+{
+ widget->priv->visible = visible;
+}
+
/**
* gtk_widget_get_visible:
* @widget: a #GtkWidget
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
+ return widget->priv->visible;
}
/**
* (gtk_widget_get_window() never returns a %NULL window when a widget
* is realized), but for many of them it's actually the #GdkWindow of
* one of its parent widgets. Widgets that do not create a %window for
- * themselves in GtkWidget::realize() must announce this by
+ * themselves in #GtkWidget::realize must announce this by
* calling this function with @has_window = %FALSE.
*
* This function should only be called by widget implementations,
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- if (has_window)
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
- else
- GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
+ widget->priv->no_window = !has_window;
}
/**
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
+ return ! widget->priv->no_window;
}
/**
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
+ return widget->priv->toplevel;
}
void
_gtk_widget_set_is_toplevel (GtkWidget *widget,
gboolean is_toplevel)
{
- if (is_toplevel)
- GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
+ widget->priv->toplevel = is_toplevel;
}
/**
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
+ return widget->priv->realized;
}
/**
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- if (realized)
- GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
+ widget->priv->realized = realized;
}
/**
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
+ return widget->priv->mapped;
}
/**
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- if (mapped)
- GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
+ widget->priv->mapped = mapped;
}
/**
* @app_paintable: %TRUE if the application will paint on the widget
*
* Sets whether the application intends to draw on the widget in
- * an #GtkWidget::expose-event handler.
+ * an #GtkWidget::draw handler.
*
- * This is a hint to the widget and does not affect the behavior of
- * the GTK+ core; many widgets ignore this flag entirely. For widgets
- * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
- * the effect is to suppress default themed drawing of the widget's
- * background. (Children of the widget will still be drawn.) The application
+ * This is a hint to the widget and does not affect the behavior of
+ * the GTK+ core; many widgets ignore this flag entirely. For widgets
+ * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
+ * the effect is to suppress default themed drawing of the widget's
+ * background. (Children of the widget will still be drawn.) The application
* is then entirely responsible for drawing the widget background.
*
* Note that the background is still drawn when the widget is mapped.
- * If this is not suitable (e.g. because you want to make a transparent
- * window using an RGBA visual), you can work around this by doing:
- * |[
- * gtk_widget_realize (window);
- * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
- * gtk_widget_show (window);
- * ]|
**/
void
gtk_widget_set_app_paintable (GtkWidget *widget,
app_paintable = (app_paintable != FALSE);
- if (gtk_widget_get_app_paintable (widget) != app_paintable)
+ if (widget->priv->app_paintable != app_paintable)
{
- if (app_paintable)
- GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
+ widget->priv->app_paintable = app_paintable;
if (gtk_widget_is_drawable (widget))
gtk_widget_queue_draw (widget);
* @widget: a #GtkWidget
*
* Determines whether the application intends to draw on the widget in
- * an #GtkWidget::expose-event handler.
+ * an #GtkWidget::draw handler.
*
* See gtk_widget_set_app_paintable()
*
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
+ return widget->priv->app_paintable;
}
/**
* In very simple terms, double buffered widgets don't flicker,
* so you would only use this function to turn off double buffering
* if you had special needs and really knew what you were doing.
- *
+ *
* Note: if you turn off double-buffering, you have to handle
- * expose events, since even the clearing to the background color or
- * pixmap will not happen automatically (as it is done in
+ * expose events, since even the clearing to the background color or
+ * pixmap will not happen automatically (as it is done in
* gdk_window_begin_paint()).
**/
void
double_buffered = (double_buffered != FALSE);
- if (double_buffered != gtk_widget_get_double_buffered (widget))
+ if (widget->priv->double_buffered != double_buffered)
{
- if (double_buffered)
- GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
+ widget->priv->double_buffered = double_buffered;
g_object_notify (G_OBJECT (widget), "double-buffered");
}
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
+ return widget->priv->double_buffered;
}
/**
* when it is allocated to a new size. Otherwise, only the
* new portion of the widget will be redrawn.
*
- * Sets whether the entire widget is queued for drawing when its size
+ * Sets whether the entire widget is queued for drawing when its size
* allocation changes. By default, this setting is %TRUE and
* the entire widget is redrawn on every size change. If your widget
* leaves the upper left unchanged when made bigger, turning this
* off all allocation on resizing: the widget will not even redraw if
* its position changes; this is to allow containers that don't draw
* anything to avoid excess invalidations. If you set this flag on a
- * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
- * you are responsible for invalidating both the old and new allocation
+ * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
+ * you are responsible for invalidating both the old and new allocation
* of the widget when the widget is moved and responsible for invalidating
* regions newly when the widget increases size.
**/
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- if (redraw_on_allocate)
- GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
- else
- GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
+ widget->priv->redraw_on_alloc = redraw_on_allocate;
}
/**
gtk_widget_set_sensitive (GtkWidget *widget,
gboolean sensitive)
{
+ GtkWidgetPrivate *priv;
GtkStateData data;
g_return_if_fail (GTK_IS_WIDGET (widget));
+ priv = widget->priv;
+
sensitive = (sensitive != FALSE);
- if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
+ if (widget->priv->sensitive == sensitive)
return;
if (sensitive)
{
- GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
- data.state = widget->saved_state;
+ widget->priv->sensitive = TRUE;
+ data.state = priv->saved_state;
}
else
{
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
+ widget->priv->sensitive = FALSE;
data.state = gtk_widget_get_state (widget);
}
data.state_restoration = TRUE;
data.use_forall = TRUE;
- if (widget->parent)
- data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
+ if (priv->parent)
+ data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
else
data.parent_sensitive = TRUE;
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
+ return widget->priv->sensitive;
}
/**
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (gtk_widget_get_sensitive (widget) &&
- (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
+ return widget->priv->sensitive && widget->priv->parent_sensitive;
}
/**
* @widget: a #GtkWidget
* @parent: parent container
*
- * This function is useful only when implementing subclasses of
+ * This function is useful only when implementing subclasses of
* #GtkContainer.
* Sets the container as the parent of @widget, and takes care of
* some details such as updating the state and style of the child
gtk_widget_set_parent (GtkWidget *widget,
GtkWidget *parent)
{
+ GtkWidgetPrivate *priv;
GtkStateData data;
-
+
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (GTK_IS_WIDGET (parent));
g_return_if_fail (widget != parent);
- if (widget->parent != NULL)
+
+ priv = widget->priv;
+
+ if (priv->parent != NULL)
{
g_warning ("Can't set a parent on widget which has a parent\n");
return;
*/
g_object_ref_sink (widget);
- widget->parent = parent;
+ priv->parent = parent;
if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
data.state = gtk_widget_get_state (parent);
data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
gtk_widget_propagate_state (widget, &data);
-
+
gtk_widget_reset_rc_styles (widget);
g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
- if (GTK_WIDGET_ANCHORED (widget->parent))
+ if (priv->parent->priv->anchored)
_gtk_widget_propagate_hierarchy_changed (widget, NULL);
g_object_notify (G_OBJECT (widget), "parent");
/* Enforce realized/mapped invariants
*/
- if (gtk_widget_get_realized (widget->parent))
+ if (gtk_widget_get_realized (priv->parent))
gtk_widget_realize (widget);
- if (gtk_widget_get_visible (widget->parent) &&
+ if (gtk_widget_get_visible (priv->parent) &&
gtk_widget_get_visible (widget))
{
- if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
- gtk_widget_get_mapped (widget->parent))
+ if (gtk_widget_get_child_visible (widget) &&
+ gtk_widget_get_mapped (priv->parent))
gtk_widget_map (widget);
gtk_widget_queue_resize (widget);
}
+
+ /* child may cause parent's expand to change, if the child is
+ * expanded. If child is not expanded, then it can't modify the
+ * parent's expand. If the child becomes expanded later then it will
+ * queue compute_expand then. This optimization plus defaulting
+ * newly-constructed widgets to need_compute_expand=FALSE should
+ * mean that initially building a widget tree doesn't have to keep
+ * walking up setting need_compute_expand on parents over and over.
+ *
+ * We can't change a parent to need to expand unless we're visible.
+ */
+ if (gtk_widget_get_visible (widget) &&
+ (priv->need_compute_expand ||
+ priv->computed_hexpand ||
+ priv->computed_vexpand))
+ {
+ gtk_widget_queue_compute_expand (parent);
+ }
}
/**
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
- return widget->parent;
+ return widget->priv->parent;
}
/*****************************************
void
gtk_widget_style_attach (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (gtk_widget_get_realized (widget));
- widget->style = gtk_style_attach (widget->style, widget->window);
+ priv = widget->priv;
+
+ priv->style = gtk_style_attach (priv->style, priv->window);
}
/**
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
+ return widget->priv->rc_style;
}
/**
{
gboolean initial_emission;
- initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
-
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
- GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
-
- gtk_widget_set_style_internal (widget, style, initial_emission);
+ initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
+
+ widget->priv->rc_style = FALSE;
+ widget->priv->user_style = TRUE;
+
+ gtk_widget_set_style_internal (widget, style, initial_emission);
}
else
{
- if (GTK_WIDGET_USER_STYLE (widget))
+ if (widget->priv->user_style)
gtk_widget_reset_rc_style (widget);
}
}
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- if (!GTK_WIDGET_USER_STYLE (widget) &&
- !gtk_widget_has_rc_style (widget))
+ if (!widget->priv->rc_style && !widget->priv->user_style)
gtk_widget_reset_rc_style (widget);
}
static void
gtk_widget_reset_rc_style (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv = widget->priv;
GtkStyle *new_style = NULL;
gboolean initial_emission;
-
- initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
- GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
- GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
-
+ initial_emission = !priv->rc_style && !priv->user_style;
+
+ priv->user_style = FALSE;
+ priv->rc_style = TRUE;
+
if (gtk_widget_has_screen (widget))
new_style = gtk_rc_get_style (widget);
if (!new_style)
new_style = gtk_widget_get_default_style ();
- if (initial_emission || new_style != widget->style)
+ if (initial_emission || new_style != priv->style)
gtk_widget_set_style_internal (widget, new_style, initial_emission);
}
/**
* gtk_widget_get_style:
* @widget: a #GtkWidget
- *
+ *
* Simply an accessor function that returns @widget->style.
*
* Return value: (transfer none): the widget's #GtkStyle
gtk_widget_get_style (GtkWidget *widget)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-
- return widget->style;
+
+ return widget->priv->style;
}
/**
* gtk_widget_modify_style:
* @widget: a #GtkWidget
* @style: the #GtkRcStyle holding the style modifications
- *
+ *
* Modifies style values on the widget. Modifications made using this
* technique take precedence over style values set via an RC file,
* however, they will be overriden if a style is explicitely set on
* to such functions gtk_widget_modify_fg() will have a cumulative
* effect with the initial modifications.
**/
-void
+void
gtk_widget_modify_style (GtkWidget *widget,
GtkRcStyle *style)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (GTK_IS_RC_STYLE (style));
-
+
g_object_set_qdata_full (G_OBJECT (widget),
quark_rc_style,
gtk_rc_style_copy (style),
/* note that "style" may be invalid here if it was the old
* modifier style and the only reference was our own.
*/
-
- if (gtk_widget_has_rc_style (widget))
+
+ if (widget->priv->rc_style)
gtk_widget_reset_rc_style (widget);
}
/**
* gtk_widget_get_modifier_style:
* @widget: a #GtkWidget
- *
+ *
* Returns the current modifier style for the widget. (As set by
* gtk_widget_modify_style().) If no style has previously set, a new
* #GtkRcStyle will be created with all values unset, and set as the
gtk_widget_get_modifier_style (GtkWidget *widget)
{
GtkRcStyle *rc_style;
-
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
GtkStateType state,
const GdkColor *color)
{
- GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
+ GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
if (color)
{
default:
g_assert_not_reached();
}
-
+
rc_style->color_flags[state] |= component;
}
else
*
* Sets the background color for a widget in a particular state.
* All other style values are left untouched. See also
- * gtk_widget_modify_style().
+ * gtk_widget_modify_style().
*
* Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
- * draw on their parent container's window and thus may not draw any
- * background themselves. This is the case for e.g. #GtkLabel. To modify
- * the background of such widgets, you have to set the background color
- * on their parent; if you want to set the background of a rectangular
- * area around a label, try placing the label in a #GtkEventBox widget
+ * draw on their parent container's window and thus may not draw any
+ * background themselves. This is the case for e.g. #GtkLabel. To modify
+ * the background of such widgets, you have to set the background color
+ * on their parent; if you want to set the background of a rectangular
+ * area around a label, try placing the label in a #GtkEventBox widget
* and setting the background color on that.
**/
void
* and #GtkTextView. See also gtk_widget_modify_style().
*
* Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
- * draw on their parent container's window and thus may not draw any
- * background themselves. This is the case for e.g. #GtkLabel. To modify
- * the background of such widgets, you have to set the base color on their
- * parent; if you want to set the background of a rectangular area around
- * a label, try placing the label in a #GtkEventBox widget and setting
+ * draw on their parent container's window and thus may not draw any
+ * background themselves. This is the case for e.g. #GtkLabel. To modify
+ * the background of such widgets, you have to set the base color on their
+ * parent; if you want to set the background of a rectangular area around
+ * a label, try placing the label in a #GtkEventBox widget and setting
* the base color on that.
**/
void
*
* Sets the cursor color to use in a widget, overriding the
* #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
- * style properties. All other style values are left untouched.
+ * style properties. All other style values are left untouched.
* See also gtk_widget_modify_style().
*
* Since: 2.12
g_return_if_fail (GTK_IS_WIDGET (widget));
- rc_style = gtk_widget_get_modifier_style (widget);
+ rc_style = gtk_widget_get_modifier_style (widget);
if (rc_style->font_desc)
pango_font_description_free (rc_style->font_desc);
rc_style->font_desc = pango_font_description_copy (font_desc);
else
rc_style->font_desc = NULL;
-
+
gtk_widget_modify_style (widget, rc_style);
}
gtk_widget_real_style_set (GtkWidget *widget,
GtkStyle *previous_style)
{
+ GtkWidgetPrivate *priv = widget->priv;
+
if (gtk_widget_get_realized (widget) &&
gtk_widget_get_has_window (widget))
- gtk_style_set_background (widget->style, widget->window, widget->state);
+ gtk_style_set_background (priv->style, priv->window, priv->state);
}
static void
GtkStyle *style,
gboolean initial_emission)
{
+ GtkWidgetPrivate *priv = widget->priv;
+
g_object_ref (widget);
g_object_freeze_notify (G_OBJECT (widget));
- if (widget->style != style)
+ if (priv->style != style)
{
GtkStyle *previous_style;
if (gtk_widget_get_realized (widget))
{
gtk_widget_reset_shapes (widget);
- gtk_style_detach (widget->style);
+ gtk_style_detach (priv->style);
}
-
- previous_style = widget->style;
- widget->style = style;
- g_object_ref (widget->style);
-
+
+ previous_style = priv->style;
+ priv->style = style;
+ g_object_ref (priv->style);
+
if (gtk_widget_get_realized (widget))
- widget->style = gtk_style_attach (widget->style, widget->window);
+ priv->style = gtk_style_attach (priv->style, priv->window);
gtk_widget_update_pango_context (widget);
g_signal_emit (widget,
initial_emission ? NULL : previous_style);
g_object_unref (previous_style);
- if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
+ if (priv->anchored && !initial_emission)
gtk_widget_queue_resize (widget);
}
else if (initial_emission)
if (context)
g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
}
-
+
_gtk_tooltip_hide (widget);
g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
}
gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
gpointer client_data)
{
+ GtkWidgetPrivate *priv = widget->priv;
HierarchyChangedInfo *info = client_data;
gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
- (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
+ (priv->parent && priv->parent->priv->anchored);
- if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
+ if (priv->anchored != new_anchored)
{
g_object_ref (widget);
-
- if (new_anchored)
- GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
- else
- GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
-
+
+ priv->anchored = new_anchored;
+
g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
do_screen_change (widget, info->previous_screen, info->new_screen);
-
+
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget),
gtk_widget_propagate_hierarchy_changed_recurse,
client_data);
-
+
g_object_unref (widget);
}
}
* _gtk_widget_propagate_hierarchy_changed:
* @widget: a #GtkWidget
* @previous_toplevel: Previous toplevel
- *
+ *
* Propagates changes in the anchored state to a widget and all
* children, unsetting or setting the %ANCHORED flag, and
* emitting #GtkWidget::hierarchy-changed.
**/
void
-_gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
- GtkWidget *previous_toplevel)
+_gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
+ GtkWidget *previous_toplevel)
{
+ GtkWidgetPrivate *priv = widget->priv;
HierarchyChangedInfo info;
info.previous_toplevel = previous_toplevel;
info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
if (gtk_widget_is_toplevel (widget) ||
- (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
+ (priv->parent && priv->parent->priv->anchored))
info.new_screen = gtk_widget_get_screen (widget);
else
info.new_screen = NULL;
HierarchyChangedInfo *info = client_data;
g_object_ref (widget);
-
+
do_screen_change (widget, info->previous_screen, info->new_screen);
-
+
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget),
gtk_widget_propagate_screen_changed_recurse,
client_data);
-
+
g_object_unref (widget);
}
/**
* gtk_widget_is_composited:
* @widget: a #GtkWidget
- *
+ *
* Whether @widget can rely on having its alpha channel
* drawn correctly. On X11 this function returns whether a
* compositing manager is running for @widget's screen.
* Please note that the semantics of this call will change
* in the future if used on a widget that has a composited
* window in its hierarchy (as set by gdk_window_set_composited()).
- *
+ *
* Return value: %TRUE if the widget can rely on its alpha
* channel being drawn correctly.
- *
+ *
* Since: 2.10
*/
gboolean
GdkScreen *screen;
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
-
+
screen = gtk_widget_get_screen (widget);
-
+
return gdk_screen_is_composited (screen);
}
propagate_composited_changed,
NULL);
}
-
+
g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
}
* _gtk_widget_propagate_screen_changed:
* @widget: a #GtkWidget
* @previous_screen: Previous screen
- *
+ *
* Propagates changes in the screen for a widget to all
* children, emitting #GtkWidget::screen-changed.
**/
static void
reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
{
- if (gtk_widget_has_rc_style (widget))
+ if (widget->priv->rc_style)
gtk_widget_reset_rc_style (widget);
-
+
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget),
reset_rc_styles_recurse,
/**
* gtk_widget_get_default_style:
- *
+ *
* Returns the default style used by all widgets initially.
*
* Returns: (transfer none): the default style. This #GtkStyle object is owned
gtk_default_style = gtk_style_new ();
g_object_ref (gtk_default_style);
}
-
+
return gtk_default_style;
}
/**
* gtk_widget_get_pango_context:
* @widget: a #GtkWidget
- *
+ *
* Gets a #PangoContext with the appropriate font map, font description,
* and base direction for this widget. Unlike the context returned
* by gtk_widget_create_pango_context(), this context is owned by
*
* If you create and keep a #PangoLayout using this context, you must
* deal with changes to the context by calling pango_layout_context_changed()
- * on the layout in response to the #GtkWidget::style-set and
+ * on the layout in response to the #GtkWidget::style-set and
* #GtkWidget::direction-changed signals for the widget.
*
* Return value: (transfer none): the #PangoContext for the widget.
PangoContext *context;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-
+
context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
if (!context)
{
update_pango_context (GtkWidget *widget,
PangoContext *context)
{
- pango_context_set_font_description (context, widget->style->font_desc);
+ GtkWidgetPrivate *priv = widget->priv;
+
+ pango_context_set_font_description (context, priv->style->font_desc);
pango_context_set_base_dir (context,
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
gtk_widget_update_pango_context (GtkWidget *widget)
{
PangoContext *context = gtk_widget_peek_pango_context (widget);
-
+
if (context)
{
GdkScreen *screen;
/**
* gtk_widget_create_pango_context:
* @widget: a #GtkWidget
- *
+ *
* Creates a new #PangoContext with the appropriate font map,
* font description, and base direction for drawing text for
* this widget. See also gtk_widget_get_pango_context().
- *
- * Return value: the new #PangoContext
+ *
+ * Return value: (transfer full): the new #PangoContext
**/
PangoContext *
gtk_widget_create_pango_context (GtkWidget *widget)
* gtk_widget_create_pango_layout:
* @widget: a #GtkWidget
* @text: text to set on the layout (can be %NULL)
- *
+ *
* Creates a new #PangoLayout with the appropriate font map,
* font description, and base direction for drawing text for
* this widget.
* If you keep a #PangoLayout created in this way around, in order to
* notify the layout of changes to the base direction or font of this
* widget, you must call pango_layout_context_changed() in response to
- * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
+ * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
* for the widget.
- *
- * Return value: the new #PangoLayout
+ *
+ * Return value: (transfer full): the new #PangoLayout
**/
PangoLayout *
gtk_widget_create_pango_layout (GtkWidget *widget,
* gtk_widget_render_icon:
* @widget: a #GtkWidget
* @stock_id: a stock ID
- * @size: (type int) a stock size. A size of (GtkIconSize)-1 means
+ * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
* render at the size of the source and don't scale (if there are
* multiple source sizes, GTK+ picks one of the available sizes).
* @detail: (allow-none): render detail to pass to theme engine
* the application and should not be modified. The pixbuf should be freed
* after use with g_object_unref().
*
- * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
+ * Return value: (transfer full): a new pixbuf, or %NULL if the
+ * stock ID wasn't known
**/
GdkPixbuf*
gtk_widget_render_icon (GtkWidget *widget,
GtkIconSize size,
const gchar *detail)
{
+ GtkWidgetPrivate *priv;
GtkIconSet *icon_set;
GdkPixbuf *retval;
-
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_val_if_fail (stock_id != NULL, NULL);
g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
-
+
+ priv = widget->priv;
+
gtk_widget_ensure_style (widget);
-
- icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
+
+ icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
if (icon_set == NULL)
return NULL;
retval = gtk_icon_set_render_icon (icon_set,
- widget->style,
+ priv->style,
gtk_widget_get_direction (widget),
gtk_widget_get_state (widget),
size,
* gtk_widget_set_parent_window:
* @widget: a #GtkWidget.
* @parent_window: the new parent window.
- *
+ *
* Sets a non default parent window for @widget.
**/
void
GdkWindow *old_parent_window;
g_return_if_fail (GTK_IS_WIDGET (widget));
-
+
old_parent_window = g_object_get_qdata (G_OBJECT (widget),
quark_parent_window);
if (parent_window != old_parent_window)
{
- g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
+ g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
parent_window);
if (old_parent_window)
g_object_unref (old_parent_window);
GdkWindow *
gtk_widget_get_parent_window (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv;
GdkWindow *parent_window;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+ priv = widget->priv;
+
parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
return (parent_window != NULL) ? parent_window :
- (widget->parent != NULL) ? widget->parent->window : NULL;
+ (priv->parent != NULL) ? priv->parent->priv->window : NULL;
}
* @is_visible: if %TRUE, @widget should be mapped along with its parent.
*
* Sets whether @widget should be mapped along with its when its parent
- * is mapped and @widget has been shown with gtk_widget_show().
+ * is mapped and @widget has been shown with gtk_widget_show().
*
* The child visibility can be set for widget before it is added to
* a container with gtk_widget_set_parent(), to avoid mapping
* children unnecessary before immediately unmapping them. However
* it will be reset to its default state of %TRUE when the widget
* is removed from a container.
- *
+ *
* Note that changing the child visibility of a widget does not
* queue a resize on the widget. Most of the time, the size of
* a widget is computed from all visible children, whether or
gtk_widget_set_child_visible (GtkWidget *widget,
gboolean is_visible)
{
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (!gtk_widget_is_toplevel (widget));
+ priv = widget->priv;
+
g_object_ref (widget);
if (is_visible)
- GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
+ priv->child_visible = TRUE;
else
{
GtkWidget *toplevel;
-
- GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
+
+ priv->child_visible = FALSE;
toplevel = gtk_widget_get_toplevel (widget);
if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
_gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
}
- if (widget->parent && gtk_widget_get_realized (widget->parent))
+ if (priv->parent && gtk_widget_get_realized (priv->parent))
{
- if (gtk_widget_get_mapped (widget->parent) &&
- GTK_WIDGET_CHILD_VISIBLE (widget) &&
+ if (gtk_widget_get_mapped (priv->parent) &&
+ priv->child_visible &&
gtk_widget_get_visible (widget))
gtk_widget_map (widget);
else
/**
* gtk_widget_get_child_visible:
* @widget: a #GtkWidget
- *
+ *
* Gets the value set with gtk_widget_set_child_visible().
* If you feel a need to use this function, your code probably
- * needs reorganization.
+ * needs reorganization.
*
* This function is only useful for container implementations and
* never should be called by an application.
gtk_widget_get_child_visible (GtkWidget *widget)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
-
- return GTK_WIDGET_CHILD_VISIBLE (widget);
+
+ return widget->priv->child_visible;
}
static GdkScreen *
gtk_widget_get_screen_unchecked (GtkWidget *widget)
{
GtkWidget *toplevel;
-
+
toplevel = gtk_widget_get_toplevel (widget);
if (gtk_widget_is_toplevel (toplevel))
/**
* gtk_widget_get_screen:
* @widget: a #GtkWidget
- *
+ *
* Get the #GdkScreen from the toplevel window associated with
* this widget. This function can only be called after the widget
* has been added to a widget hierarchy with a #GtkWindow
gtk_widget_get_screen (GtkWidget *widget)
{
GdkScreen *screen;
-
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
screen = gtk_widget_get_screen_unchecked (widget);
/**
* gtk_widget_has_screen:
* @widget: a #GtkWidget
- *
+ *
* Checks whether there is a #GdkScreen is associated with
* this widget. All toplevel widgets have an associated
* screen, and all widgets added into a hierarchy with a toplevel
* window at the top.
- *
+ *
* Return value: %TRUE if there is a #GdkScreen associcated
* with the widget.
*
/**
* gtk_widget_get_display:
* @widget: a #GtkWidget
- *
+ *
* Get the #GdkDisplay for the toplevel window associated with
* this widget. This function can only be called after the widget
* has been added to a widget hierarchy with a #GtkWindow at the top.
gtk_widget_get_display (GtkWidget *widget)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-
+
return gdk_screen_get_display (gtk_widget_get_screen (widget));
}
/**
* gtk_widget_get_root_window:
* @widget: a #GtkWidget
- *
+ *
* Get the root window where this widget is located. This function can
* only be called after the widget has been added to a widget
* hierarchy with #GtkWindow at the top.
* to a particular widget, and gtk_container_set_focus_chain() to
* change the focus tab order. So you may want to investigate those
* functions instead.
- *
+ *
* gtk_widget_child_focus() is called by containers as the user moves
* around the window using keyboard shortcuts. @direction indicates
* what kind of motion is taking place (up, down, left, right, tab
if (!GTK_IS_CONTAINER (widget) &&
!gtk_widget_get_can_focus (widget))
return FALSE;
-
+
g_signal_emit (widget,
widget_signals[FOCUS],
0,
* navigation outside the widget, e.g. by calling
* gtk_widget_child_focus() on the widget's toplevel.
*
- * The default ::keynav-failed handler returns %TRUE for
- * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
- * values of #GtkDirectionType, it looks at the
- * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
+ * The default ::keynav-failed handler returns %TRUE for
+ * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
+ * values of #GtkDirectionType, it looks at the
+ * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
* if the setting is %TRUE. This way the entire user interface
* becomes cursor-navigatable on input devices such as mobile phones
* which only have cursor keys but no tab key.
* gtk_widget_error_bell() to notify the user of the failed keyboard
* navigation.
*
- * A use case for providing an own implementation of ::keynav-failed
+ * A use case for providing an own implementation of ::keynav-failed
* (either by connecting to it or by overriding it) would be a row of
* #GtkEntry widgets where the user should be able to navigate the
- * entire row with the cursor keys, as e.g. known from user interfaces
+ * entire row with the cursor keys, as e.g. known from user interfaces
* that require entering license keys.
*
* Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
* gtk_widget_error_bell:
* @widget: a #GtkWidget
*
- * Notifies the user about an input-related error on this widget.
+ * Notifies the user about an input-related error on this widget.
* If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
* gdk_window_beep(), otherwise it does nothing.
*
void
gtk_widget_error_bell (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv;
GtkSettings* settings;
gboolean beep;
g_return_if_fail (GTK_IS_WIDGET (widget));
+ priv = widget->priv;
+
settings = gtk_widget_get_settings (widget);
if (!settings)
return;
"gtk-error-bell", &beep,
NULL);
- if (beep && widget->window)
- gdk_window_beep (widget->window);
+ if (beep && priv->window)
+ gdk_window_beep (priv->window);
}
static void
-gtk_widget_set_usize_internal (GtkWidget *widget,
- gint width,
- gint height)
+gtk_widget_set_usize_internal (GtkWidget *widget,
+ gint width,
+ gint height,
+ GtkQueueResizeFlags flags)
{
GtkWidgetAuxInfo *aux_info;
gboolean changed = FALSE;
-
+
g_object_freeze_notify (G_OBJECT (widget));
aux_info = _gtk_widget_get_aux_info (widget, TRUE);
-
+
if (width > -2 && aux_info->width != width)
{
- g_object_notify (G_OBJECT (widget), "width-request");
+ if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
+ g_object_notify (G_OBJECT (widget), "width-request");
aux_info->width = width;
changed = TRUE;
}
if (height > -2 && aux_info->height != height)
{
- g_object_notify (G_OBJECT (widget), "height-request");
+ if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
+ g_object_notify (G_OBJECT (widget), "height-request");
aux_info->height = height;
changed = TRUE;
}
-
+
if (gtk_widget_get_visible (widget) && changed)
- gtk_widget_queue_resize (widget);
+ {
+ if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
+ gtk_widget_queue_resize (widget);
+ else
+ _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
+ }
g_object_thaw_notify (G_OBJECT (widget));
}
* will force them to leave the window at least as large as the size
* request. When dealing with window sizes,
* gtk_window_set_geometry_hints() can be a useful function as well.
- *
+ *
* Note the inherent danger of setting any fixed size - themes,
* translations into other languages, different fonts, and user action
* can all change the appropriate size for a given widget. So, it's
*
* Widgets can't actually be allocated a size less than 1 by 1, but
* you can pass 0,0 to this function to mean "as small as possible."
+ *
+ * The size request set here does not include any margin from the
+ * #GtkWidget properties margin-left, margin-right, margin-top, and
+ * margin-bottom, but it does include pretty much all other padding
+ * or border properties set by any subclass of #GtkWidget.
**/
void
gtk_widget_set_size_request (GtkWidget *widget,
width = 1;
if (height == 0)
height = 1;
-
- gtk_widget_set_usize_internal (widget, width, height);
+
+ gtk_widget_set_usize_internal (widget, width, height, 0);
}
* @height indicates that that dimension has not been set explicitly
* and the natural requisition of the widget will be used intead. See
* gtk_widget_set_size_request(). To get the size a widget will
- * actually use, call gtk_widget_size_request() instead of
+ * actually request, call gtk_widget_get_preferred_size() instead of
* this function.
**/
void
gint *width,
gint *height)
{
- GtkWidgetAuxInfo *aux_info;
+ const GtkWidgetAuxInfo *aux_info;
g_return_if_fail (GTK_IS_WIDGET (widget));
- aux_info = _gtk_widget_get_aux_info (widget, FALSE);
+ aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
if (width)
- *width = aux_info ? aux_info->width : -1;
+ *width = aux_info->width;
if (height)
- *height = aux_info ? aux_info->height : -1;
+ *height = aux_info->height;
+}
+
+/**
+ * _gtk_widget_override_size_request:
+ * @widget: a #GtkWidget
+ * @width: new forced minimum width
+ * @height: new forced minimum height
+ * @old_width: location to store previous forced minimum width
+ * @old_width: location to store previous forced minumum height
+ *
+ * Temporarily establishes a forced minimum size for a widget; this
+ * is used by GtkWindow when calculating the size to add to the
+ * window's geometry widget. Cached sizes for the widget and its
+ * parents are invalidated, so that subsequent calls to the size
+ * negotiation machinery produce the overriden result, but the
+ * widget is not queued for relayout or redraw. The old size must
+ * be restored with _gtk_widget_restore_size_request() or things
+ * will go screwy.
+ */
+void
+_gtk_widget_override_size_request (GtkWidget *widget,
+ int width,
+ int height,
+ int *old_width,
+ int *old_height)
+{
+ gtk_widget_get_size_request (widget, old_width, old_height);
+ gtk_widget_set_usize_internal (widget, width, height,
+ GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
+}
+
+/**
+ * _gtk_widget_restore_size_request:
+ * @widget: a #GtkWidget
+ * @old_width: saved forced minimum size
+ * @old_height: saved forced minimum size
+ *
+ * Undoes the operation of_gtk_widget_override_size_request().
+ */
+void
+_gtk_widget_restore_size_request (GtkWidget *widget,
+ int old_width,
+ int old_height)
+{
+ gtk_widget_set_usize_internal (widget, old_width, old_height,
+ GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
}
/**
{
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (!gtk_widget_get_realized (widget));
-
+
g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
GINT_TO_POINTER (events));
g_object_notify (G_OBJECT (widget), "events");
GdkDevice *device,
gint events)
{
+ GtkWidgetPrivate *priv = widget->priv;
GList *window_list;
if (!gtk_widget_get_has_window (widget))
- window_list = gdk_window_get_children (widget->window);
+ window_list = gdk_window_get_children (priv->window);
else
- window_list = g_list_prepend (NULL, widget->window);
+ window_list = g_list_prepend (NULL, priv->window);
gtk_widget_add_events_internal_list (widget, device, events, window_list);
/**
* gtk_widget_get_toplevel:
* @widget: a #GtkWidget
- *
+ *
* This function returns the topmost widget in the container hierarchy
* @widget is a part of. If @widget has no parent widgets, it will be
* returned as the topmost widget. No reference will be added to the
* returned widget; it should not be unreferenced.
*
* Note the difference in behavior vs. gtk_widget_get_ancestor();
- * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
+ * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
* would return
* %NULL if @widget wasn't inside a toplevel window, and if the
* window was inside a #GtkWindow-derived widget which was in turn
* inside the toplevel #GtkWindow. While the second case may
* seem unlikely, it actually happens when a #GtkPlug is embedded
* inside a #GtkSocket within the same application.
- *
+ *
* To reliably find the toplevel #GtkWindow, use
* gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
* is set on the result.
gtk_widget_get_toplevel (GtkWidget *widget)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-
- while (widget->parent)
- widget = widget->parent;
-
+
+ while (widget->priv->parent)
+ widget = widget->priv->parent;
+
return widget;
}
* gtk_widget_get_ancestor:
* @widget: a #GtkWidget
* @widget_type: ancestor type
- *
+ *
* Gets the first ancestor of @widget with type @widget_type. For example,
- * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
- * the first #GtkBox that's an ancestor of @widget. No reference will be
- * added to the returned widget; it should not be unreferenced. See note
- * about checking for a toplevel #GtkWindow in the docs for
+ * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
+ * the first #GtkBox that's an ancestor of @widget. No reference will be
+ * added to the returned widget; it should not be unreferenced. See note
+ * about checking for a toplevel #GtkWindow in the docs for
* gtk_widget_get_toplevel().
- *
- * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
+ *
+ * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
* considers @widget to be an ancestor of itself.
*
* Return value: (transfer none): the ancestor widget, or %NULL if not found
GType widget_type)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-
+
while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
- widget = widget->parent;
-
+ widget = widget->priv->parent;
+
if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
return NULL;
-
+
return widget;
}
/**
- * gtk_widget_get_colormap:
+ * gtk_widget_set_visual:
* @widget: a #GtkWidget
- *
- * Gets the colormap that will be used to render @widget. No reference will
- * be added to the returned colormap; it should not be unreferenced.
+ * @visual: visual to be used or %NULL to unset a previous one
+ *
+ * Sets the visual that should be used for by widget and its children for
+ * creating #GdkWindows. The visual must be on the same #GdkScreen as
+ * returned by gdk_widget_get_screen(), so handling the
+ * #GtkWidget::screen-changed signal is necessary.
*
- * Return value: (transfer none): the colormap used by @widget
+ * Setting a new @visual will not cause @widget to recreate its windows,
+ * so you should call this function before @widget is realized.
**/
-GdkColormap*
-gtk_widget_get_colormap (GtkWidget *widget)
+void
+gtk_widget_set_visual (GtkWidget *widget,
+ GdkVisual *visual)
{
- GdkColormap *colormap;
- GtkWidget *tmp_widget;
-
- g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-
- if (widget->window)
- {
- colormap = gdk_drawable_get_colormap (widget->window);
- /* If window was destroyed previously, we'll get NULL here */
- if (colormap)
- return colormap;
- }
-
- tmp_widget = widget;
- while (tmp_widget)
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
+ if (visual)
{
- colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
- if (colormap)
- return colormap;
-
- tmp_widget= tmp_widget->parent;
+ g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
}
- return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
+ g_object_set_qdata_full (G_OBJECT (widget),
+ quark_visual,
+ g_object_ref (visual),
+ g_object_unref);
}
/**
* gtk_widget_get_visual:
* @widget: a #GtkWidget
- *
+ *
* Gets the visual that will be used to render @widget.
*
* Return value: (transfer none): the visual for @widget
GdkVisual*
gtk_widget_get_visual (GtkWidget *widget)
{
+ GtkWidget *w;
+ GdkVisual *visual;
+ GdkScreen *screen;
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
- return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
+ if (gtk_widget_get_has_window (widget) &&
+ widget->priv->window)
+ return gdk_window_get_visual (widget->priv->window);
+
+ screen = gtk_widget_get_screen (widget);
+
+ for (w = widget; w != NULL; w = w->priv->parent)
+ {
+ visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
+ if (visual)
+ {
+ if (gdk_visual_get_screen (visual) == screen)
+ return visual;
+
+ g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
+ gtk_widget_get_name (widget));
+ }
+ }
+
+ return gdk_screen_get_system_visual (screen);
}
/**
* gtk_widget_get_settings:
* @widget: a #GtkWidget
- *
+ *
* Gets the settings object holding the settings (global property
* settings, RC file information, etc) used for this widget.
*
gtk_widget_get_settings (GtkWidget *widget)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-
- return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
-}
-
-/**
- * gtk_widget_set_colormap:
- * @widget: a #GtkWidget
- * @colormap: a colormap
- *
- * Sets the colormap for the widget to the given value. Widget must not
- * have been previously realized. This probably should only be used
- * from an <function>init()</function> function (i.e. from the constructor
- * for the widget).
- **/
-void
-gtk_widget_set_colormap (GtkWidget *widget,
- GdkColormap *colormap)
-{
- g_return_if_fail (GTK_IS_WIDGET (widget));
- g_return_if_fail (!gtk_widget_get_realized (widget));
- g_return_if_fail (GDK_IS_COLORMAP (colormap));
- g_object_ref (colormap);
-
- g_object_set_qdata_full (G_OBJECT (widget),
- quark_colormap,
- colormap,
- g_object_unref);
+ return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
}
/**
* gtk_widget_get_events:
* @widget: a #GtkWidget
- *
+ *
* Returns the event mask for the widget (a bitfield containing flags
* from the #GdkEventMask enumeration). These are the events that the widget
* will receive.
- *
+ *
* Return value: event mask for @widget
**/
gint
/**
* gtk_widget_get_extension_events:
* @widget: a #GtkWidget
- *
+ *
* Retrieves the extension events the widget will receive; see
* gdk_input_set_extension_events().
- *
+ *
* Return value: extension events for @widget
**/
GdkExtensionMode
gint *x,
gint *y)
{
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
-
+
+ priv = widget->priv;
+
if (x)
*x = -1;
if (y)
*y = -1;
-
+
if (gtk_widget_get_realized (widget))
{
- gdk_window_get_pointer (widget->window, x, y, NULL);
-
+ gdk_window_get_pointer (priv->window, x, y, NULL);
+
if (!gtk_widget_get_has_window (widget))
{
if (x)
- *x -= widget->allocation.x;
+ *x -= priv->allocation.x;
if (y)
- *y -= widget->allocation.y;
+ *y -= priv->allocation.y;
}
}
}
* gtk_widget_is_ancestor:
* @widget: a #GtkWidget
* @ancestor: another #GtkWidget
- *
+ *
* Determines whether @widget is somewhere inside @ancestor, possibly with
* intermediate containers.
- *
- * Return value: %TRUE if @ancestor contains @widget as a child,
+ *
+ * Return value: %TRUE if @ancestor contains @widget as a child,
* grandchild, great grandchild, etc.
**/
gboolean
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
g_return_val_if_fail (ancestor != NULL, FALSE);
-
+
while (widget)
{
- if (widget->parent == ancestor)
+ if (widget->priv->parent == ancestor)
return TRUE;
- widget = widget->parent;
+ widget = widget->priv->parent;
}
-
+
return FALSE;
}
* gtk_widget_set_composite_name:
* @widget: a #GtkWidget.
* @name: the name to set
- *
+ *
* Sets a widgets composite name. The widget must be
* a composite child of its parent; see gtk_widget_push_composite_child().
**/
const gchar *name)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
+ g_return_if_fail (widget->priv->composite_child);
g_return_if_fail (name != NULL);
if (!quark_composite_name)
* gtk_widget_get_composite_name:
* @widget: a #GtkWidget
*
- * Obtains the composite name of a widget.
+ * Obtains the composite name of a widget.
*
* Returns: the composite name of @widget, or %NULL if @widget is not
- * a composite child. The string should be freed when it is no
+ * a composite child. The string should be freed when it is no
* longer needed.
**/
gchar*
gtk_widget_get_composite_name (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv;
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
- if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && widget->parent)
- return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
+ priv = widget->priv;
+
+ if (widget->priv->composite_child && priv->parent)
+ return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
widget);
else
return NULL;
/**
* gtk_widget_push_composite_child:
- *
+ *
* Makes all newly-created widgets as composite children until
* the corresponding gtk_widget_pop_composite_child() call.
- *
+ *
* A composite child is a child that's an implementation detail of the
* container it's inside and should not be visible to people using the
* container. Composite children aren't treated differently by GTK (but
- * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
+ * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
* builders might want to treat them in a different way.
- *
+ *
* Here is a simple example:
* |[
* gtk_widget_push_composite_child ();
- * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
+ * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
* gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
* gtk_widget_pop_composite_child ();
- * gtk_widget_set_parent (scrolled_window->hscrollbar,
+ * gtk_widget_set_parent (scrolled_window->hscrollbar,
* GTK_WIDGET (scrolled_window));
* g_object_ref (scrolled_window->hscrollbar);
* ]|
* gtk_widget_pop_composite_child:
*
* Cancels the effect of a previous call to gtk_widget_push_composite_child().
- **/
+ **/
void
gtk_widget_pop_composite_child (void)
{
composite_child_stack--;
}
-/**
- * gtk_widget_push_colormap:
- * @cmap: a #GdkColormap
- *
- * Pushes @cmap onto a global stack of colormaps; the topmost
- * colormap on the stack will be used to create all widgets.
- * Remove @cmap with gtk_widget_pop_colormap(). There's little
- * reason to use this function.
- **/
-void
-gtk_widget_push_colormap (GdkColormap *cmap)
-{
- g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
-
- colormap_stack = g_slist_prepend (colormap_stack, cmap);
-}
-
-/**
- * gtk_widget_pop_colormap:
- *
- * Removes a colormap pushed with gtk_widget_push_colormap().
- **/
-void
-gtk_widget_pop_colormap (void)
-{
- if (colormap_stack)
- colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
-}
-
-/**
- * gtk_widget_set_default_colormap:
- * @colormap: a #GdkColormap
- *
- * Sets the default colormap to use when creating widgets.
- * gtk_widget_push_colormap() is a better function to use if
- * you only want to affect a few widgets, rather than all widgets.
- **/
-void
-gtk_widget_set_default_colormap (GdkColormap *colormap)
-{
- g_return_if_fail (GDK_IS_COLORMAP (colormap));
-
- gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
- colormap);
-}
-
-/**
- * gtk_widget_get_default_colormap:
- *
- * Obtains the default colormap used to create widgets.
- *
- * Return value: (transfer none): default widget colormap
- **/
-GdkColormap*
-gtk_widget_get_default_colormap (void)
-{
- return gdk_screen_get_default_colormap (gdk_screen_get_default ());
-}
-
-/**
- * gtk_widget_get_default_visual:
- *
- * Obtains the visual of the default colormap. Not really useful;
- * used to be useful before gdk_colormap_get_visual() existed.
- *
- * Return value: (transfer none): visual of the default colormap
- **/
-GdkVisual*
-gtk_widget_get_default_visual (void)
-{
- return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
-}
-
static void
gtk_widget_emit_direction_changed (GtkWidget *widget,
GtkTextDirection old_dir)
{
gtk_widget_update_pango_context (widget);
-
+
g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
}
* gtk_widget_set_direction:
* @widget: a #GtkWidget
* @dir: the new direction
- *
+ *
* Sets the reading direction on a particular widget. This direction
* controls the primary direction for widgets containing text,
* and also the direction in which the children of a container are
GtkTextDirection dir)
{
GtkTextDirection old_dir;
-
+
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
old_dir = gtk_widget_get_direction (widget);
-
- if (dir == GTK_TEXT_DIR_NONE)
- GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
- else
- {
- GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
- if (dir == GTK_TEXT_DIR_LTR)
- GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
- else
- GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
- }
+
+ widget->priv->direction = dir;
if (old_dir != gtk_widget_get_direction (widget))
gtk_widget_emit_direction_changed (widget, old_dir);
/**
* gtk_widget_get_direction:
* @widget: a #GtkWidget
- *
+ *
* Gets the reading direction for a particular widget. See
* gtk_widget_set_direction().
- *
+ *
* Return value: the reading direction for the widget.
**/
GtkTextDirection
gtk_widget_get_direction (GtkWidget *widget)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
-
- if (GTK_WIDGET_DIRECTION_SET (widget))
- return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
- else
+
+ if (widget->priv->direction == GTK_TEXT_DIR_NONE)
return gtk_default_direction;
+ else
+ return widget->priv->direction;
}
static void
GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
g_object_ref (widget);
-
- if (!GTK_WIDGET_DIRECTION_SET (widget))
+
+ if (widget->priv->direction == GTK_TEXT_DIR_NONE)
gtk_widget_emit_direction_changed (widget, old_dir);
-
+
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget),
gtk_widget_set_default_direction_recurse,
* gtk_widget_set_default_direction:
* @dir: the new default direction. This cannot be
* %GTK_TEXT_DIR_NONE.
- *
+ *
* Sets the default reading direction for widgets where the
* direction has not been explicitly set by gtk_widget_set_direction().
**/
{
GList *toplevels, *tmp_list;
GtkTextDirection old_dir = gtk_default_direction;
-
+
gtk_default_direction = dir;
tmp_list = toplevels = gtk_window_list_toplevels ();
g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
-
+
while (tmp_list)
{
gtk_widget_set_default_direction_recurse (tmp_list->data,
/**
* gtk_widget_get_default_direction:
- *
+ *
* Obtains the current default reading direction. See
* gtk_widget_set_default_direction().
*
- * Return value: the current default direction.
+ * Return value: the current default direction.
**/
GtkTextDirection
gtk_widget_get_default_direction (void)
gtk_widget_dispose (GObject *object)
{
GtkWidget *widget = GTK_WIDGET (object);
+ GtkWidgetPrivate *priv = widget->priv;
- if (widget->parent)
- gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
+ if (priv->parent)
+ gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
else if (gtk_widget_get_visible (widget))
gtk_widget_hide (widget);
- GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
+ priv->visible = FALSE;
if (gtk_widget_get_realized (widget))
gtk_widget_unrealize (widget);
-
+
+ if (!priv->in_destruction)
+ {
+ priv->in_destruction = TRUE;
+ g_signal_emit (object, widget_signals[DESTROY], 0);
+ priv->in_destruction = FALSE;
+ }
+
G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
}
static void
-gtk_widget_real_destroy (GtkObject *object)
+gtk_widget_real_destroy (GtkWidget *object)
{
/* gtk_object_destroy() will already hold a refcount on object */
GtkWidget *widget = GTK_WIDGET (object);
+ GtkWidgetPrivate *priv = widget->priv;
/* wipe accelerator closures (keep order) */
g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
/* Callers of add_mnemonic_label() should disconnect on ::destroy */
g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
-
+
gtk_grab_remove (widget);
-
- g_object_unref (widget->style);
- widget->style = gtk_widget_get_default_style ();
- g_object_ref (widget->style);
- GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
+ g_object_unref (priv->style);
+ priv->style = gtk_widget_get_default_style ();
+ g_object_ref (priv->style);
}
static void
gtk_widget_finalize (GObject *object)
{
GtkWidget *widget = GTK_WIDGET (object);
+ GtkWidgetPrivate *priv = widget->priv;
GtkWidgetAuxInfo *aux_info;
GtkAccessible *accessible;
-
+
gtk_grab_remove (widget);
- g_object_unref (widget->style);
- widget->style = NULL;
+ g_object_unref (priv->style);
+ priv->style = NULL;
+
+ g_free (priv->name);
- g_free (widget->name);
-
aux_info =_gtk_widget_get_aux_info (widget, FALSE);
if (aux_info)
gtk_widget_aux_info_destroy (aux_info);
if (accessible)
g_object_unref (accessible);
+ if (g_object_is_floating (object))
+ g_warning ("A floating object was finalized. This means that someone\n"
+ "called g_object_unref() on an object that had only a floating\n"
+ "reference; the initial floating reference is not owned by anyone\n"
+ "and must be removed with g_object_ref_sink().");
+
G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
}
static void
gtk_widget_real_map (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv = widget->priv;
+
g_assert (gtk_widget_get_realized (widget));
-
+
if (!gtk_widget_get_mapped (widget))
{
gtk_widget_set_mapped (widget, TRUE);
-
+
if (gtk_widget_get_has_window (widget))
- gdk_window_show (widget->window);
+ gdk_window_show (priv->window);
}
}
static void
gtk_widget_real_unmap (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv = widget->priv;
+
if (gtk_widget_get_mapped (widget))
{
gtk_widget_set_mapped (widget, FALSE);
if (gtk_widget_get_has_window (widget))
- gdk_window_hide (widget->window);
+ gdk_window_hide (priv->window);
}
}
static void
gtk_widget_real_realize (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv = widget->priv;
+
g_assert (!gtk_widget_get_has_window (widget));
-
+
gtk_widget_set_realized (widget, TRUE);
- if (widget->parent)
+ if (priv->parent)
{
- widget->window = gtk_widget_get_parent_window (widget);
- g_object_ref (widget->window);
+ priv->window = gtk_widget_get_parent_window (widget);
+ g_object_ref (priv->window);
}
- widget->style = gtk_style_attach (widget->style, widget->window);
+ priv->style = gtk_style_attach (priv->style, priv->window);
}
/*****************************************
static void
gtk_widget_real_unrealize (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv = widget->priv;
+
if (gtk_widget_get_mapped (widget))
gtk_widget_real_unmap (widget);
/* We must do unrealize child widget BEFORE container widget.
* gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
- * So, unrealizing container widget bofore its children causes the problem
+ * So, unrealizing container widget bofore its children causes the problem
* (for example, gdk_ic_destroy () with destroyed window causes crash. )
*/
(GtkCallback) gtk_widget_unrealize,
NULL);
- gtk_style_detach (widget->style);
+ gtk_style_detach (priv->style);
if (gtk_widget_get_has_window (widget))
{
- gdk_window_set_user_data (widget->window, NULL);
- gdk_window_destroy (widget->window);
- widget->window = NULL;
+ gdk_window_set_user_data (priv->window, NULL);
+ gdk_window_destroy (priv->window);
+ priv->window = NULL;
}
else
{
- g_object_unref (widget->window);
- widget->window = NULL;
+ g_object_unref (priv->window);
+ priv->window = NULL;
}
gtk_selection_remove_all (widget);
-
+
gtk_widget_set_realized (widget, FALSE);
}
gtk_widget_real_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
- requisition->width = widget->requisition.width;
- requisition->height = widget->requisition.height;
+ requisition->width = 0;
+ requisition->height = 0;
}
-/**
- * _gtk_widget_peek_colormap:
- *
- * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
- *
- * Return value: the currently pushed colormap, or %NULL if there is none.
- **/
-GdkColormap*
-_gtk_widget_peek_colormap (void)
+static void
+gtk_widget_real_adjust_size_request (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint *minimum_size,
+ gint *natural_size)
{
- if (colormap_stack)
- return (GdkColormap*) colormap_stack->data;
- return NULL;
+ const GtkWidgetAuxInfo *aux_info;
+
+ aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL &&
+ aux_info->width > 0)
+ {
+ *minimum_size = MAX (*minimum_size, aux_info->width);
+ }
+ else if (orientation == GTK_ORIENTATION_VERTICAL &&
+ aux_info->height > 0)
+ {
+ *minimum_size = MAX (*minimum_size, aux_info->height);
+ }
+
+ /* Fix it if set_size_request made natural size smaller than min size.
+ * This would also silently fix broken widgets, but we warn about them
+ * in gtksizerequest.c when calling their size request vfuncs.
+ */
+ *natural_size = MAX (*natural_size, *minimum_size);
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ *minimum_size += (aux_info->margin.left + aux_info->margin.right);
+ *natural_size += (aux_info->margin.left + aux_info->margin.right);
+ }
+ else
+ {
+ *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
+ *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
+ }
}
-/*
+/**
+ * _gtk_widget_peek_request_cache:
+ *
+ * Returns the address of the widget's request cache (strictly for
+ * internal use in gtksizerequest.c)
+ *
+ * Return value: the address of @widget's size request cache.
+ **/
+gpointer
+_gtk_widget_peek_request_cache (GtkWidget *widget)
+{
+ /* Don't bother slowing things down with the return_if_fail guards here */
+ return &widget->priv->requests;
+}
+
+/*
* _gtk_widget_set_device_window:
* @widget: a #GtkWidget.
* @device: a #GdkDevice.
GdkDevice *device,
GdkWindow *window)
{
+ GtkWidgetPrivate *priv;
GdkScreen *screen;
GHashTable *device_window;
g_return_if_fail (GDK_IS_DEVICE (device));
g_return_if_fail (!window || GDK_IS_WINDOW (window));
+ priv = widget->priv;
+
if (!gtk_widget_get_realized (widget))
return;
- screen = gdk_drawable_get_screen (widget->window);
+ screen = gdk_window_get_screen (priv->window);
device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
if (G_UNLIKELY (!device_window))
_gtk_widget_get_device_window (GtkWidget *widget,
GdkDevice *device)
{
+ GtkWidgetPrivate *priv;
GdkScreen *screen;
GHashTable *device_window;
GdkWindow *window;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
+ priv = widget->priv;
+
if (!gtk_widget_get_realized (widget))
return NULL;
- screen = gdk_drawable_get_screen (widget->window);
+ screen = gdk_window_get_screen (priv->window);
device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
if (G_UNLIKELY (!device_window))
GList *
_gtk_widget_list_devices (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv;
GdkScreen *screen;
GHashTableIter iter;
GHashTable *device_window;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+ priv = widget->priv;
+
if (!gtk_widget_get_realized (widget))
return NULL;
- screen = gdk_drawable_get_screen (widget->window);
+ screen = gdk_window_get_screen (priv->window);
device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
if (G_UNLIKELY (!device_window))
from_window = _gtk_widget_get_device_window (from, device);
if (!from_window)
- from_window = from->window;
+ from_window = from->priv->window;
}
if (to != NULL)
to_window = _gtk_widget_get_device_window (to, device);
if (!to_window)
- to_window = to->window;
+ to_window = to->priv->window;
}
if (from_window == NULL && to_window == NULL)
synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
device, mode, GDK_NOTIFY_INFERIOR);
for (list = to_ancestors; list; list = list->next)
- synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
+ synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
device, mode, GDK_NOTIFY_VIRTUAL);
synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
device, mode, GDK_NOTIFY_ANCESTOR);
}
else
{
- while (from_ancestors != NULL && to_ancestors != NULL
+ while (from_ancestors != NULL && to_ancestors != NULL
&& from_ancestors->data == to_ancestors->data)
{
- from_ancestors = g_list_delete_link (from_ancestors,
+ from_ancestors = g_list_delete_link (from_ancestors,
from_ancestors);
to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
}
gtk_widget_propagate_state (GtkWidget *widget,
GtkStateData *data)
{
+ GtkWidgetPrivate *priv = widget->priv;
guint8 old_state = gtk_widget_get_state (widget);
- guint8 old_saved_state = widget->saved_state;
+ guint8 old_saved_state = priv->saved_state;
/* don't call this function with state==GTK_STATE_INSENSITIVE,
* parent_sensitive==TRUE on a sensitive widget
*/
- if (data->parent_sensitive)
- GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
+ priv->parent_sensitive = data->parent_sensitive;
if (gtk_widget_is_sensitive (widget))
{
if (data->state_restoration)
- widget->state = widget->saved_state;
+ priv->state = priv->saved_state;
else
- widget->state = data->state;
+ priv->state = data->state;
}
else
{
if (!data->state_restoration)
{
if (data->state != GTK_STATE_INSENSITIVE)
- widget->saved_state = data->state;
+ priv->saved_state = data->state;
}
else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
- widget->saved_state = gtk_widget_get_state (widget);
- widget->state = GTK_STATE_INSENSITIVE;
+ priv->saved_state = gtk_widget_get_state (widget);
+ priv->state = GTK_STATE_INSENSITIVE;
}
if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
}
if (old_state != gtk_widget_get_state (widget) ||
- old_saved_state != widget->saved_state)
+ old_saved_state != priv->saved_state)
{
g_object_ref (widget);
g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
- if (!GTK_WIDGET_SHADOWED (widget))
+ if (!priv->shadowed)
{
GList *event_windows = NULL;
GList *devices, *d;
}
}
+static const GtkWidgetAuxInfo default_aux_info = {
+ -1, -1,
+ GTK_ALIGN_FILL,
+ GTK_ALIGN_FILL,
+ { 0, 0, 0, 0 }
+};
+
/*
* _gtk_widget_get_aux_info:
* @widget: a #GtkWidget
* @create: if %TRUE, create the structure if it doesn't exist
- *
+ *
* Get the #GtkWidgetAuxInfo structure for the widget.
- *
+ *
* Return value: the #GtkAuxInfo structure for the widget, or
* %NULL if @create is %FALSE and one doesn't already exist.
*/
gboolean create)
{
GtkWidgetAuxInfo *aux_info;
-
+
aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
if (!aux_info && create)
{
aux_info = g_slice_new0 (GtkWidgetAuxInfo);
- aux_info->width = -1;
- aux_info->height = -1;
+ *aux_info = default_aux_info;
g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
}
-
+
return aux_info;
}
+static const GtkWidgetAuxInfo*
+_gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
+{
+ GtkWidgetAuxInfo *aux_info;
+
+ aux_info = _gtk_widget_get_aux_info (widget, FALSE);
+ if (aux_info == NULL)
+ {
+ return &default_aux_info;
+ }
+ else
+ {
+ return aux_info;
+ }
+}
/*****************************************
* gtk_widget_aux_info_destroy:
g_slice_free (GtkWidgetAuxInfo, aux_info);
}
-static void
-gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
-{
- g_object_unref (info->shape_mask);
- g_slice_free (GtkWidgetShapeInfo, info);
-}
-
/**
- * gtk_widget_shape_combine_mask:
+ * gtk_widget_shape_combine_region:
* @widget: a #GtkWidget
- * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
- * @offset_x: X position of shape mask with respect to @window
- * @offset_y: Y position of shape mask with respect to @window
- *
+ * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
+ *
* Sets a shape for this widget's GDK window. This allows for
- * transparent windows etc., see gdk_window_shape_combine_mask()
+ * transparent windows etc., see gdk_window_shape_combine_region()
* for more information.
+ *
+ * Since: 3.0
**/
void
-gtk_widget_shape_combine_mask (GtkWidget *widget,
- GdkBitmap *shape_mask,
- gint offset_x,
- gint offset_y)
+gtk_widget_shape_combine_region (GtkWidget *widget,
+ cairo_region_t *region)
{
- GtkWidgetShapeInfo* shape_info;
-
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
/* set_shape doesn't work on widgets without gdk window */
g_return_if_fail (gtk_widget_get_has_window (widget));
- if (!shape_mask)
+ priv = widget->priv;
+
+ if (region == NULL)
{
- GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
-
- if (widget->window)
- gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
-
+ priv->has_shape_mask = FALSE;
+
+ if (priv->window)
+ gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
+
g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
}
else
{
- GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
-
- shape_info = g_slice_new (GtkWidgetShapeInfo);
- g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
- (GDestroyNotify) gtk_widget_shape_info_destroy);
-
- shape_info->shape_mask = g_object_ref (shape_mask);
- shape_info->offset_x = offset_x;
- shape_info->offset_y = offset_y;
-
+ priv->has_shape_mask = TRUE;
+
+ g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
+ cairo_region_copy (region),
+ (GDestroyNotify) cairo_region_destroy);
+
/* set shape if widget has a gdk window already.
* otherwise the shape is scheduled to be set by gtk_widget_realize().
*/
- if (widget->window)
- gdk_window_shape_combine_mask (widget->window, shape_mask,
- offset_x, offset_y);
+ if (priv->window)
+ gdk_window_shape_combine_region (priv->window, region, 0, 0);
}
}
/**
- * gtk_widget_input_shape_combine_mask:
+ * gtk_widget_input_shape_combine_region:
* @widget: a #GtkWidget
- * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
- * @offset_x: X position of shape mask with respect to @window
- * @offset_y: Y position of shape mask with respect to @window
+ * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
*
* Sets an input shape for this widget's GDK window. This allows for
- * windows which react to mouse click in a nonrectangular region, see
- * gdk_window_input_shape_combine_mask() for more information.
+ * windows which react to mouse click in a nonrectangular region, see
+ * gdk_window_input_shape_combine_region() for more information.
*
- * Since: 2.10
+ * Since: 3.0
**/
void
-gtk_widget_input_shape_combine_mask (GtkWidget *widget,
- GdkBitmap *shape_mask,
- gint offset_x,
- gint offset_y)
+gtk_widget_input_shape_combine_region (GtkWidget *widget,
+ cairo_region_t *region)
{
- GtkWidgetShapeInfo* shape_info;
-
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
/* set_shape doesn't work on widgets without gdk window */
g_return_if_fail (gtk_widget_get_has_window (widget));
- if (!shape_mask)
+ priv = widget->priv;
+
+ if (region == NULL)
{
- if (widget->window)
- gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
-
+ if (priv->window)
+ gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
+
g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
}
else
{
- shape_info = g_slice_new (GtkWidgetShapeInfo);
- g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
- shape_info,
- (GDestroyNotify) gtk_widget_shape_info_destroy);
-
- shape_info->shape_mask = g_object_ref (shape_mask);
- shape_info->offset_x = offset_x;
- shape_info->offset_y = offset_y;
-
+ g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
+ cairo_region_copy (region),
+ (GDestroyNotify) cairo_region_destroy);
+
/* set shape if widget has a gdk window already.
* otherwise the shape is scheduled to be set by gtk_widget_realize().
*/
- if (widget->window)
- gdk_window_input_shape_combine_mask (widget->window, shape_mask,
- offset_x, offset_y);
+ if (priv->window)
+ gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
}
}
if (data != widget)
return;
- gdk_window_shape_combine_mask (window, NULL, 0, 0);
+ gdk_window_shape_combine_region (window, NULL, 0, 0);
for (list = gdk_window_peek_children (window); list; list = list->next)
gtk_reset_shapes_recurse (widget, list->data);
}
void
gtk_widget_reset_shapes (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (gtk_widget_get_realized (widget));
- if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
- gtk_reset_shapes_recurse (widget, widget->window);
-}
-
-static void
-expose_window (GdkWindow *window)
-{
- GdkEvent event;
- GList *l, *children;
- gpointer user_data;
- gboolean is_double_buffered;
-
- gdk_window_get_user_data (window, &user_data);
-
- if (user_data)
- is_double_buffered = gtk_widget_get_double_buffered (GTK_WIDGET (user_data));
- else
- is_double_buffered = FALSE;
-
- event.expose.type = GDK_EXPOSE;
- event.expose.window = g_object_ref (window);
- event.expose.send_event = FALSE;
- event.expose.count = 0;
- event.expose.area.x = 0;
- event.expose.area.y = 0;
- gdk_drawable_get_size (GDK_DRAWABLE (window),
- &event.expose.area.width,
- &event.expose.area.height);
- event.expose.region = cairo_region_create_rectangle (&event.expose.area);
-
- /* If this is not double buffered, force a double buffer so that
- redirection works. */
- if (!is_double_buffered)
- gdk_window_begin_paint_region (window, event.expose.region);
-
- gtk_main_do_event (&event);
-
- if (!is_double_buffered)
- gdk_window_end_paint (window);
-
- children = gdk_window_peek_children (window);
- for (l = children; l != NULL; l = l->next)
- {
- GdkWindow *child = l->data;
-
- /* Don't expose input-only windows */
- if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
- expose_window (l->data);
- }
-
- g_object_unref (window);
-}
-
-/**
- * gtk_widget_get_snapshot:
- * @widget: a #GtkWidget
- * @clip_rect: (allow-none): a #GdkRectangle or %NULL
- *
- * Create a #GdkPixmap of the contents of the widget and its children.
- *
- * Works even if the widget is obscured. The depth and visual of the
- * resulting pixmap is dependent on the widget being snapshot and likely
- * differs from those of a target widget displaying the pixmap.
- * The function gdk_pixbuf_get_from_drawable() can be used to convert
- * the pixmap to a visual independant representation.
- *
- * The snapshot area used by this function is the @widget's allocation plus
- * any extra space occupied by additional windows belonging to this widget
- * (such as the arrows of a spin button).
- * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
- *
- * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
- * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
- * interpreted widget relative. If width or height of @clip_rect are 0 or
- * negative, the width or height of the resulting pixmap will be shrunken
- * by the respective amount.
- * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
- * chop off 5 pixels at each side of the snapshot pixmap.
- * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
- * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
- * can be used to preserve the auto-grown snapshot area and use @clip_rect
- * as a pure output parameter.
- *
- * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
- *
- * Return value: #GdkPixmap snapshot of the widget
- *
- * Since: 2.14
- **/
-GdkPixmap*
-gtk_widget_get_snapshot (GtkWidget *widget,
- GdkRectangle *clip_rect)
-{
- int x, y, width, height;
- GdkWindow *parent_window = NULL;
- GdkPixmap *pixmap;
- GList *windows = NULL, *list;
-
- g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
- if (!gtk_widget_get_visible (widget))
- return NULL;
-
- /* the widget (and parent_window) must be realized to be drawable */
- if (widget->parent && !gtk_widget_get_realized (widget->parent))
- gtk_widget_realize (widget->parent);
- if (!gtk_widget_get_realized (widget))
- gtk_widget_realize (widget);
-
- /* determine snapshot rectangle */
- x = widget->allocation.x;
- y = widget->allocation.y;
- width = widget->allocation.width;
- height = widget->allocation.height;
-
- if (widget->parent && gtk_widget_get_has_window (widget))
- {
- /* grow snapshot rectangle to cover all widget windows */
- parent_window = gtk_widget_get_parent_window (widget);
- for (list = gdk_window_peek_children (parent_window); list; list = list->next)
- {
- GdkWindow *subwin = list->data;
- gpointer windata;
- int wx, wy, ww, wh;
- gdk_window_get_user_data (subwin, &windata);
- if (windata != widget)
- continue;
- windows = g_list_prepend (windows, subwin);
- gdk_window_get_position (subwin, &wx, &wy);
- gdk_drawable_get_size (subwin, &ww, &wh);
- /* grow snapshot rectangle by extra widget sub window */
- if (wx < x)
- {
- width += x - wx;
- x = wx;
- }
- if (wy < y)
- {
- height += y - wy;
- y = wy;
- }
- if (x + width < wx + ww)
- width += wx + ww - (x + width);
- if (y + height < wy + wh)
- height += wy + wh - (y + height);
- }
- }
- else if (!widget->parent)
- x = y = 0; /* toplevel */
-
- /* at this point, (x,y,width,height) is the parent_window relative
- * snapshot area covering all of widget's windows.
- */
-
- /* shrink snapshot size by clip_rectangle */
- if (clip_rect)
- {
- GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
- clip.x = clip.x < 0 ? x : clip.x;
- clip.y = clip.y < 0 ? y : clip.y;
- clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
- clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
- if (widget->parent)
- {
- /* offset clip_rect, so it's parent_window relative */
- if (clip_rect->x >= 0)
- clip.x += widget->allocation.x;
- if (clip_rect->y >= 0)
- clip.y += widget->allocation.y;
- }
- if (!gdk_rectangle_intersect (&snap, &clip, &snap))
- {
- g_list_free (windows);
- clip_rect->width = clip_rect->height = 0;
- return NULL; /* empty snapshot area */
- }
- x = snap.x;
- y = snap.y;
- width = snap.width;
- height = snap.height;
- }
-
- /* render snapshot */
- pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
- for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
- {
- GdkWindow *subwin = list->data;
- int wx, wy;
- if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
- continue; /* Input only window */
- gdk_window_get_position (subwin, &wx, &wy);
- gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
- MAX (0, wx - x), MAX (0, wy - y), width, height);
-
- expose_window (subwin);
- }
- if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
- {
- gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
- expose_window (widget->window);
- }
- for (list = windows; list; list = list->next)
- gdk_window_remove_redirection (list->data);
- if (!windows) /* NO_WINDOW || toplevel */
- gdk_window_remove_redirection (widget->window);
- g_list_free (windows);
+ priv = widget->priv;
- /* return pixmap and snapshot rectangle coordinates */
- if (clip_rect)
- {
- clip_rect->x = x;
- clip_rect->y = y;
- clip_rect->width = width;
- clip_rect->height = height;
- if (widget->parent)
- {
- /* offset clip_rect from parent_window so it's widget relative */
- clip_rect->x -= widget->allocation.x;
- clip_rect->y -= widget->allocation.y;
- }
- if (0)
- g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
- G_OBJECT_TYPE_NAME (widget),
- clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
- }
- return pixmap;
+ if (!priv->has_shape_mask)
+ gtk_reset_shapes_recurse (widget, priv->window);
}
/* style properties
* @klass: a #GtkWidgetClass
* @pspec: the #GParamSpec for the style property
* @parser: the parser for the style property
- *
- * Installs a style property on a widget class.
+ *
+ * Installs a style property on a widget class.
**/
void
gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
g_return_if_fail (G_IS_PARAM_SPEC (pspec));
g_return_if_fail (pspec->flags & G_PARAM_READABLE);
g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
-
+
if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
{
g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
* gtk_widget_class_install_style_property:
* @klass: a #GtkWidgetClass
* @pspec: the #GParamSpec for the property
- *
+ *
* Installs a style property on a widget class. The parser for the
* style property is determined by the value type of @pspec.
**/
* gtk_widget_class_list_style_properties:
* @klass: a #GtkWidgetClass
* @n_properties: location to return the number of style properties found
- * @returns: an newly allocated array of #GParamSpec*. The array must
+ * @returns: an newly allocated array of #GParamSpec*. The array must
* be freed with g_free().
*
* Returns all style properties of a widget class.
* gtk_widget_style_get_property:
* @widget: a #GtkWidget
* @property_name: the name of a style property
- * @value: location to return the property value
+ * @value: location to return the property value
*
* Gets the value of a style property of @widget.
*/
const gchar *property_name,
GValue *value)
{
+ GtkWidgetPrivate *priv;
GParamSpec *pspec;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (property_name != NULL);
g_return_if_fail (G_IS_VALUE (value));
+ priv = widget->priv;
+
g_object_ref (widget);
pspec = g_param_spec_pool_lookup (style_property_spec_pool,
property_name,
{
const GValue *peek_value;
- peek_value = _gtk_style_peek_property_value (widget->style,
+ peek_value = _gtk_style_peek_property_value (priv->style,
G_OBJECT_TYPE (widget),
pspec,
(GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
-
+
/* auto-conversion of the caller's value type
*/
if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
* @var_args: a <type>va_list</type> of pairs of property names and
* locations to return the property values, starting with the location
* for @first_property_name.
- *
- * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
+ *
+ * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
* bindings.
- */
+ */
void
gtk_widget_style_get_valist (GtkWidget *widget,
const gchar *first_property_name,
va_list var_args)
{
+ GtkWidgetPrivate *priv;
const gchar *name;
g_return_if_fail (GTK_IS_WIDGET (widget));
+ priv = widget->priv;
+
g_object_ref (widget);
name = first_property_name;
}
/* style pspecs are always readable so we can spare that check here */
- peek_value = _gtk_style_peek_property_value (widget->style,
+ peek_value = _gtk_style_peek_property_value (priv->style,
G_OBJECT_TYPE (widget),
pspec,
(GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
* gtk_widget_style_get:
* @widget: a #GtkWidget
* @first_property_name: the name of the first property to get
- * @Varargs: pairs of property names and locations to
- * return the property values, starting with the location for
+ * @Varargs: pairs of property names and locations to
+ * return the property values, starting with the location for
* @first_property_name, terminated by %NULL.
*
* Gets the values of a multiple style properties of @widget.
static gchar *rev_path = NULL;
static guint tmp_path_len = 0;
guint len;
-
+
g_return_if_fail (GTK_IS_WIDGET (widget));
-
+
len = 0;
do
{
const gchar *s;
gchar *d;
guint l;
-
+
string = gtk_widget_get_name (widget);
l = strlen (string);
while (tmp_path_len <= len + l + 1)
while (s >= string)
*(d++) = *(s--);
len += l;
-
- widget = widget->parent;
-
+
+ widget = widget->priv->parent;
+
if (widget)
rev_path[len++] = '.';
else
rev_path[len++] = 0;
}
while (widget);
-
+
if (path_length)
*path_length = len - 1;
if (path_reversed)
*
* Same as gtk_widget_path(), but always uses the name of a widget's type,
* never uses a custom name set with gtk_widget_set_name().
- *
+ *
**/
void
gtk_widget_class_path (GtkWidget *widget,
static gchar *rev_path = NULL;
static guint tmp_path_len = 0;
guint len;
-
+
g_return_if_fail (GTK_IS_WIDGET (widget));
-
+
len = 0;
do
{
const gchar *s;
gchar *d;
guint l;
-
+
string = g_type_name (G_OBJECT_TYPE (widget));
l = strlen (string);
while (tmp_path_len <= len + l + 1)
while (s >= string)
*(d++) = *(s--);
len += l;
-
- widget = widget->parent;
-
+
+ widget = widget->priv->parent;
+
if (widget)
rev_path[len++] = '.';
else
rev_path[len++] = 0;
}
while (widget);
-
+
if (path_length)
*path_length = len - 1;
if (path_reversed)
/**
* gtk_requisition_free:
* @requisition: a #GtkRequisition
- *
+ *
* Frees a #GtkRequisition.
**/
void
return klass->get_accessible (widget);
}
-static AtkObject*
+static AtkObject*
gtk_widget_real_get_accessible (GtkWidget *widget)
{
AtkObject* accessible;
- accessible = g_object_get_qdata (G_OBJECT (widget),
+ accessible = g_object_get_qdata (G_OBJECT (widget),
quark_accessible_object);
if (!accessible)
{
AtkRegistry *default_registry;
default_registry = atk_get_default_registry ();
- factory = atk_registry_get_factory (default_registry,
+ factory = atk_registry_get_factory (default_registry,
G_TYPE_FROM_INSTANCE (widget));
accessible =
atk_object_factory_create_accessible (factory,
G_OBJECT (widget));
- g_object_set_qdata (G_OBJECT (widget),
+ g_object_set_qdata (G_OBJECT (widget),
quark_accessible_object,
accessible);
}
}
/*
- * GtkBuildable implementation
+ * Expand flag management
*/
-static GQuark quark_builder_has_default = 0;
-static GQuark quark_builder_has_focus = 0;
-static GQuark quark_builder_atk_relations = 0;
-static GQuark quark_builder_set_name = 0;
static void
-gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
+gtk_widget_update_computed_expand (GtkWidget *widget)
{
- quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
- quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
- quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
- quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
+ GtkWidgetPrivate *priv;
- iface->set_name = gtk_widget_buildable_set_name;
- iface->get_name = gtk_widget_buildable_get_name;
- iface->get_internal_child = gtk_widget_buildable_get_internal_child;
- iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
- iface->parser_finished = gtk_widget_buildable_parser_finished;
- iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
- iface->custom_finished = gtk_widget_buildable_custom_finished;
-}
+ priv = widget->priv;
-static void
-gtk_widget_buildable_set_name (GtkBuildable *buildable,
- const gchar *name)
-{
- g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
- g_strdup (name), g_free);
+ if (priv->need_compute_expand)
+ {
+ gboolean h, v;
+
+ if (priv->hexpand_set)
+ h = priv->hexpand;
+ else
+ h = FALSE;
+
+ if (priv->vexpand_set)
+ v = priv->vexpand;
+ else
+ v = FALSE;
+
+ /* we don't need to use compute_expand if both expands are
+ * forced by the app
+ */
+ if (!(priv->hexpand_set && priv->vexpand_set))
+ {
+ if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
+ {
+ gboolean ignored;
+
+ GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
+ priv->hexpand_set ? &ignored : &h,
+ priv->vexpand_set ? &ignored : &v);
+ }
+ }
+
+ priv->need_compute_expand = FALSE;
+ priv->computed_hexpand = h != FALSE;
+ priv->computed_vexpand = v != FALSE;
+ }
}
-static const gchar *
-gtk_widget_buildable_get_name (GtkBuildable *buildable)
+/**
+ * gtk_widget_queue_compute_expand:
+ * @widget: a #GtkWidget
+ *
+ * Mark @widget as needing to recompute its expand flags. Call
+ * this function when setting legacy expand child properties
+ * on the child of a container.
+ *
+ * See gtk_widget_compute_expand().
+ */
+void
+gtk_widget_queue_compute_expand (GtkWidget *widget)
{
- return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
+ GtkWidget *parent;
+ gboolean changed_anything;
+
+ if (widget->priv->need_compute_expand)
+ return;
+
+ changed_anything = FALSE;
+ parent = widget;
+ while (parent != NULL)
+ {
+ if (!parent->priv->need_compute_expand)
+ {
+ parent->priv->need_compute_expand = TRUE;
+ changed_anything = TRUE;
+ }
+
+ /* Note: if we had an invariant that "if a child needs to
+ * compute expand, its parents also do" then we could stop going
+ * up when we got to a parent that already needed to
+ * compute. However, in general we compute expand lazily (as
+ * soon as we see something in a subtree that is expand, we know
+ * we're expanding) and so this invariant does not hold and we
+ * have to always walk all the way up in case some ancestor
+ * is not currently need_compute_expand.
+ */
+
+ parent = parent->priv->parent;
+ }
+
+ /* recomputing expand always requires
+ * a relayout as well
+ */
+ if (changed_anything)
+ gtk_widget_queue_resize (widget);
}
-static GObject *
-gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
- GtkBuilder *builder,
- const gchar *childname)
+/**
+ * gtk_widget_compute_expand:
+ * @widget: the widget
+ * @orientation: expand direction
+ *
+ * Computes whether a container should give this widget extra space
+ * when possible. Containers should check this, rather than
+ * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
+ *
+ * This function already checks whether the widget is visible, so
+ * visibility does not need to be checked separately. Non-visible
+ * widgets are not expanded.
+ *
+ * The computed expand value uses either the expand setting explicitly
+ * set on the widget itself, or, if none has been explicitly set,
+ * the widget may expand if some of its children do.
+ *
+ * Return value: whether widget tree rooted here should be expanded
+ */
+gboolean
+gtk_widget_compute_expand (GtkWidget *widget,
+ GtkOrientation orientation)
{
- if (strcmp (childname, "accessible") == 0)
- return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return NULL;
+ /* We never make a widget expand if not even showing. */
+ if (!gtk_widget_get_visible (widget))
+ return FALSE;
+
+ gtk_widget_update_computed_expand (widget);
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ return widget->priv->computed_hexpand;
+ }
+ else
+ {
+ return widget->priv->computed_vexpand;
+ }
}
static void
-gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
- GtkBuilder *builder,
- const gchar *name,
- const GValue *value)
+gtk_widget_set_expand (GtkWidget *widget,
+ GtkOrientation orientation,
+ gboolean expand)
{
- if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
- g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
- GINT_TO_POINTER (TRUE));
- else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
- g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
- GINT_TO_POINTER (TRUE));
+ const char *expand_prop;
+ const char *expand_set_prop;
+ gboolean was_both;
+ GtkWidgetPrivate *priv;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ priv = widget->priv;
+
+ expand = expand != FALSE;
+
+ was_both = priv->hexpand && priv->vexpand;
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ if (priv->hexpand_set &&
+ priv->hexpand == expand)
+ return;
+
+ priv->hexpand_set = TRUE;
+ priv->hexpand = expand;
+
+ expand_prop = "hexpand";
+ expand_set_prop = "hexpand-set";
+ }
else
- g_object_set_property (G_OBJECT (buildable), name, value);
-}
+ {
+ if (priv->vexpand_set &&
+ priv->vexpand == expand)
+ return;
-typedef struct
-{
- gchar *action_name;
- GString *description;
- gchar *context;
- gboolean translatable;
-} AtkActionData;
+ priv->vexpand_set = TRUE;
+ priv->vexpand = expand;
-typedef struct
-{
- gchar *target;
- gchar *type;
-} AtkRelationData;
+ expand_prop = "vexpand";
+ expand_set_prop = "vexpand-set";
+ }
-static void
-free_action (AtkActionData *data, gpointer user_data)
-{
- g_free (data->action_name);
- g_string_free (data->description, TRUE);
- g_free (data->context);
- g_slice_free (AtkActionData, data);
+ gtk_widget_queue_compute_expand (widget);
+
+ g_object_freeze_notify (G_OBJECT (widget));
+ g_object_notify (G_OBJECT (widget), expand_prop);
+ g_object_notify (G_OBJECT (widget), expand_set_prop);
+ if (was_both != (priv->hexpand && priv->vexpand))
+ g_object_notify (G_OBJECT (widget), "expand");
+ g_object_thaw_notify (G_OBJECT (widget));
}
static void
-free_relation (AtkRelationData *data, gpointer user_data)
+gtk_widget_set_expand_set (GtkWidget *widget,
+ GtkOrientation orientation,
+ gboolean set)
{
- g_free (data->target);
- g_free (data->type);
- g_slice_free (AtkRelationData, data);
-}
+ GtkWidgetPrivate *priv;
+ const char *prop;
+
+ priv = widget->priv;
+
+ set = set != FALSE;
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ if (set == priv->hexpand_set)
+ return;
+
+ priv->hexpand_set = set;
+ prop = "hexpand-set";
+ }
+ else
+ {
+ if (set == priv->vexpand_set)
+ return;
+
+ priv->vexpand_set = set;
+ prop = "vexpand-set";
+ }
+
+ gtk_widget_queue_compute_expand (widget);
+
+ g_object_notify (G_OBJECT (widget), prop);
+}
+
+/**
+ * gtk_widget_get_hexpand:
+ * @widget: the widget
+ *
+ * Gets whether the widget would like any available extra horizontal
+ * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
+ * generally receive the extra space. For example, a list or
+ * scrollable area or document in your window would often be set to
+ * expand.
+ *
+ * Containers should use gtk_widget_compute_expand() rather than
+ * this function, to see whether a widget, or any of its children,
+ * has the expand flag set. If any child of a widget wants to
+ * expand, the parent may ask to expand also.
+ *
+ * This function only looks at the widget's own hexpand flag, rather
+ * than computing whether the entire widget tree rooted at this widget
+ * wants to expand.
+ *
+ * Return value: whether hexpand flag is set
+ */
+gboolean
+gtk_widget_get_hexpand (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+
+ return widget->priv->hexpand;
+}
+
+/**
+ * gtk_widget_set_hexpand:
+ * @widget: the widget
+ * @expand: whether to expand
+ *
+ * Sets whether the widget would like any available extra horizontal
+ * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
+ * generally receive the extra space. For example, a list or
+ * scrollable area or document in your window would often be set to
+ * expand.
+ *
+ * Call this function to set the expand flag if you would like your
+ * widget to become larger horizontally when the window has extra
+ * room.
+ *
+ * By default, widgets automatically expand if any of their children
+ * want to expand. (To see if a widget will automatically expand given
+ * its current children and state, call gtk_widget_compute_expand(). A
+ * container can decide how the expandability of children affects the
+ * expansion of the container by overriding the compute_expand virtual
+ * method on #GtkWidget.).
+ *
+ * Setting hexpand explicitly with this function will override the
+ * automatic expand behavior.
+ *
+ * This function forces the widget to expand or not to expand,
+ * regardless of children. The override occurs because
+ * gtk_widget_set_hexpand() sets the hexpand-set property (see
+ * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
+ * value to be used, rather than looking at children and widget state.
+ */
+void
+gtk_widget_set_hexpand (GtkWidget *widget,
+ gboolean expand)
+{
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
+}
+
+/**
+ * gtk_widget_get_hexpand_set:
+ * @widget: the widget
+ *
+ * Gets whether gtk_widget_set_hexpand() has been used to
+ * explicitly set the expand flag on this widget.
+ *
+ * If hexpand is set, then it overrides any computed
+ * expand value based on child widgets. If hexpand is not
+ * set, then the expand value depends on whether any
+ * children of the widget would like to expand.
+ *
+ * There are few reasons to use this function, but it's here
+ * for completeness and consistency.
+ *
+ * Return value: whether hexpand has been explicitly set
+ */
+gboolean
+gtk_widget_get_hexpand_set (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+
+ return widget->priv->hexpand_set;
+}
+
+/**
+ * gtk_widget_set_hexpand_set:
+ * @widget: the widget
+ * @set: value for hexpand-set property
+ *
+ * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
+ * be used.
+ *
+ * The hexpand-set property will be set automatically when you call
+ * gtk_widget_set_hexpand() to set hexpand, so the most likely
+ * reason to use this function would be to unset an explicit expand
+ * flag.
+ *
+ * If hexpand is set, then it overrides any computed
+ * expand value based on child widgets. If hexpand is not
+ * set, then the expand value depends on whether any
+ * children of the widget would like to expand.
+ *
+ * There are few reasons to use this function, but it's here
+ * for completeness and consistency.
+ *
+ * Return value: whether hexpand has been explicitly set
+ */
+void
+gtk_widget_set_hexpand_set (GtkWidget *widget,
+ gboolean set)
+{
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
+}
+
+
+/**
+ * gtk_widget_get_vexpand:
+ * @widget: the widget
+ *
+ * Gets whether the widget would like any available extra vertical
+ * space.
+ *
+ * See gtk_widget_get_hexpand() for more detail.
+ *
+ * Return value: whether vexpand flag is set
+ */
+gboolean
+gtk_widget_get_vexpand (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+
+ return widget->priv->vexpand;
+}
+
+/**
+ * gtk_widget_set_vexpand:
+ * @widget: the widget
+ * @expand: whether to expand
+ *
+ * Sets whether the widget would like any available extra vertical
+ * space.
+ *
+ * See gtk_widget_set_hexpand() for more detail.
+ */
+void
+gtk_widget_set_vexpand (GtkWidget *widget,
+ gboolean expand)
+{
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
+}
+
+/**
+ * gtk_widget_get_vexpand_set:
+ * @widget: the widget
+ *
+ * Gets whether gtk_widget_set_vexpand() has been used to
+ * explicitly set the expand flag on this widget.
+ *
+ * See gtk_widget_get_hexpand_set() for more detail.
+ *
+ * Return value: whether vexpand has been explicitly set
+ */
+gboolean
+gtk_widget_get_vexpand_set (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+
+ return widget->priv->vexpand_set;
+}
+
+/**
+ * gtk_widget_set_vexpand_set:
+ * @widget: the widget
+ * @set: value for vexpand-set property
+ *
+ * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
+ * be used.
+ *
+ * See gtk_widget_set_hexpand_set() for more detail.
+ *
+ * Return value: whether vexpand has been explicitly set
+ */
+void
+gtk_widget_set_vexpand_set (GtkWidget *widget,
+ gboolean set)
+{
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
+}
+
+/*
+ * GtkBuildable implementation
+ */
+static GQuark quark_builder_has_default = 0;
+static GQuark quark_builder_has_focus = 0;
+static GQuark quark_builder_atk_relations = 0;
+static GQuark quark_builder_set_name = 0;
+
+static void
+gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
+{
+ quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
+ quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
+ quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
+ quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
+
+ iface->set_name = gtk_widget_buildable_set_name;
+ iface->get_name = gtk_widget_buildable_get_name;
+ iface->get_internal_child = gtk_widget_buildable_get_internal_child;
+ iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
+ iface->parser_finished = gtk_widget_buildable_parser_finished;
+ iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
+ iface->custom_finished = gtk_widget_buildable_custom_finished;
+}
+
+static void
+gtk_widget_buildable_set_name (GtkBuildable *buildable,
+ const gchar *name)
+{
+ g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
+ g_strdup (name), g_free);
+}
+
+static const gchar *
+gtk_widget_buildable_get_name (GtkBuildable *buildable)
+{
+ return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
+}
+
+static GObject *
+gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ const gchar *childname)
+{
+ if (strcmp (childname, "accessible") == 0)
+ return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
+
+ return NULL;
+}
+
+static void
+gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ const gchar *name,
+ const GValue *value)
+{
+ if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
+ g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
+ GINT_TO_POINTER (TRUE));
+ else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
+ g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
+ GINT_TO_POINTER (TRUE));
+ else
+ g_object_set_property (G_OBJECT (buildable), name, value);
+}
+
+typedef struct
+{
+ gchar *action_name;
+ GString *description;
+ gchar *context;
+ gboolean translatable;
+} AtkActionData;
+
+typedef struct
+{
+ gchar *target;
+ gchar *type;
+} AtkRelationData;
+
+static void
+free_action (AtkActionData *data, gpointer user_data)
+{
+ g_free (data->action_name);
+ g_string_free (data->description, TRUE);
+ g_free (data->context);
+ g_slice_free (AtkActionData, data);
+}
+
+static void
+free_relation (AtkRelationData *data, gpointer user_data)
+{
+ g_free (data->target);
+ g_free (data->type);
+ g_slice_free (AtkRelationData, data);
+}
static void
gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
}
}
-/*
- * GtkSizeRequest implementation
- */
static void
-gtk_widget_real_get_width (GtkSizeRequest *widget,
- gint *minimum_size,
- gint *natural_size)
+gtk_widget_real_get_width (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
{
- /* Set the initial values so that unimplemented classes will fall back
- * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
- */
if (minimum_size)
- *minimum_size = GTK_WIDGET (widget)->requisition.width;
+ *minimum_size = 0;
if (natural_size)
- *natural_size = GTK_WIDGET (widget)->requisition.width;
+ *natural_size = 0;
}
static void
-gtk_widget_real_get_height (GtkSizeRequest *widget,
- gint *minimum_size,
- gint *natural_size)
+gtk_widget_real_get_height (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
{
- /* Set the initial values so that unimplemented classes will fall back
- * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
- */
if (minimum_size)
- *minimum_size = GTK_WIDGET (widget)->requisition.height;
+ *minimum_size = 0;
if (natural_size)
- *natural_size = GTK_WIDGET (widget)->requisition.height;
+ *natural_size = 0;
}
static void
-gtk_widget_real_get_height_for_width (GtkSizeRequest *layout,
+gtk_widget_real_get_height_for_width (GtkWidget *widget,
gint width,
gint *minimum_height,
gint *natural_height)
{
- gtk_size_request_get_height (layout, minimum_height, natural_height);
+ GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
}
static void
-gtk_widget_real_get_width_for_height (GtkSizeRequest *layout,
+gtk_widget_real_get_width_for_height (GtkWidget *widget,
gint height,
gint *minimum_width,
gint *natural_width)
-{
- gtk_size_request_get_width (layout, minimum_width, natural_width);
+{
+ GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
}
-static void
-gtk_widget_size_request_init (GtkSizeRequestIface *iface)
+/**
+ * gtk_widget_get_halign:
+ * @widget: a #GtkWidget
+ *
+ * Gets the value of the #GtkWidget:halign property.
+ *
+ * Returns: the horizontal alignment of @widget
+ */
+GtkAlign
+gtk_widget_get_halign (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
+ return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
+}
+
+/**
+ * gtk_widget_set_halign:
+ * @widget: a #GtkWidget
+ * @align: the horizontal alignment
+ *
+ * Sets the horizontal alignment of @widget.
+ * See the #GtkWidget:halign property.
+ */
+void
+gtk_widget_set_halign (GtkWidget *widget,
+ GtkAlign align)
+{
+ GtkWidgetAuxInfo *aux_info;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+
+ if (aux_info->halign == align)
+ return;
+
+ aux_info->halign = align;
+ gtk_widget_queue_resize (widget);
+ g_object_notify (G_OBJECT (widget), "halign");
+}
+
+/**
+ * gtk_widget_get_valign:
+ * @widget: a #GtkWidget
+ *
+ * Gets the value of the #GtkWidget:valign property.
+ *
+ * Returns: the vertical alignment of @widget
+ */
+GtkAlign
+gtk_widget_get_valign (GtkWidget *widget)
{
- iface->get_width = gtk_widget_real_get_width;
- iface->get_height = gtk_widget_real_get_height;
- iface->get_width_for_height = gtk_widget_real_get_width_for_height;
- iface->get_height_for_width = gtk_widget_real_get_height_for_width;
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
+ return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
}
-
-
+
+/**
+ * gtk_widget_set_valign:
+ * @widget: a #GtkWidget
+ * @align: the vertical alignment
+ *
+ * Sets the vertical alignment of @widget.
+ * See the #GtkWidget:valign property.
+ */
+void
+gtk_widget_set_valign (GtkWidget *widget,
+ GtkAlign align)
+{
+ GtkWidgetAuxInfo *aux_info;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+
+ if (aux_info->valign == align)
+ return;
+
+ aux_info->valign = align;
+ gtk_widget_queue_resize (widget);
+ g_object_notify (G_OBJECT (widget), "valign");
+}
+
+/**
+ * gtk_widget_get_margin_left:
+ * @widget: a #GtkWidget
+ *
+ * Gets the value of the #GtkWidget:margin-left property.
+ *
+ * Returns: The left margin of @widget
+ */
+gint
+gtk_widget_get_margin_left (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+ return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
+}
+
+/**
+ * gtk_widget_set_margin_left:
+ * @widget: a #GtkWidget
+ * @margin: the left margin
+ *
+ * Sets the left margin of @widget.
+ * See the #GtkWidget:margin-left property.
+ */
+void
+gtk_widget_set_margin_left (GtkWidget *widget,
+ gint margin)
+{
+ GtkWidgetAuxInfo *aux_info;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (margin <= G_MAXINT16);
+
+ aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+
+ if (aux_info->margin.left == margin)
+ return;
+
+ aux_info->margin.left = margin;
+ gtk_widget_queue_resize (widget);
+ g_object_notify (G_OBJECT (widget), "margin-left");
+}
+
+/**
+ * gtk_widget_get_margin_right:
+ * @widget: a #GtkWidget
+ *
+ * Gets the value of the #GtkWidget:margin-right property.
+ *
+ * Returns: The left margin of @widget
+ */
+gint
+gtk_widget_get_margin_right (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+ return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
+}
+
+/**
+ * gtk_widget_set_margin_right:
+ * @widget: a #GtkWidget
+ * @margin: the right margin
+ *
+ * Sets the right margin of @widget.
+ * See the #GtkWidget:margin-right property.
+ */
+void
+gtk_widget_set_margin_right (GtkWidget *widget,
+ gint margin)
+{
+ GtkWidgetAuxInfo *aux_info;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (margin <= G_MAXINT16);
+
+ aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+
+ if (aux_info->margin.right == margin)
+ return;
+
+ aux_info->margin.right = margin;
+ gtk_widget_queue_resize (widget);
+ g_object_notify (G_OBJECT (widget), "margin-right");
+}
+
+/**
+ * gtk_widget_get_margin_top:
+ * @widget: a #GtkWidget
+ *
+ * Gets the value of the #GtkWidget:margin-top property.
+ *
+ * Returns: The top margin of @widget
+ */
+gint
+gtk_widget_get_margin_top (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+ return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
+}
+
+/**
+ * gtk_widget_set_margin_top:
+ * @widget: a #GtkWidget
+ * @margin: the top margin
+ *
+ * Sets the top margin of @widget.
+ * See the #GtkWidget:margin-top property.
+ */
+void
+gtk_widget_set_margin_top (GtkWidget *widget,
+ gint margin)
+{
+ GtkWidgetAuxInfo *aux_info;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (margin <= G_MAXINT16);
+
+ aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+
+ if (aux_info->margin.top == margin)
+ return;
+
+ aux_info->margin.top = margin;
+ gtk_widget_queue_resize (widget);
+ g_object_notify (G_OBJECT (widget), "margin-top");
+}
+
+/**
+ * gtk_widget_get_margin_bottom:
+ * @widget: a #GtkWidget
+ *
+ * Gets the value of the #GtkWidget:margin-bottom property.
+ *
+ * Returns: The bottom margin of @widget
+ */
+gint
+gtk_widget_get_margin_bottom (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+ return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
+}
+
+/**
+ * gtk_widget_set_margin_bottom:
+ * @widget: a #GtkWidget
+ * @margin: the bottom margin
+ *
+ * Sets the bottom margin of @widget.
+ * See the #GtkWidget:margin-bottom property.
+ */
+void
+gtk_widget_set_margin_bottom (GtkWidget *widget,
+ gint margin)
+{
+ GtkWidgetAuxInfo *aux_info;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (margin <= G_MAXINT16);
+
+ aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+
+ if (aux_info->margin.bottom == margin)
+ return;
+
+ aux_info->margin.bottom = margin;
+ gtk_widget_queue_resize (widget);
+ g_object_notify (G_OBJECT (widget), "margin-bottom");
+}
+
/**
* gtk_widget_get_clipboard:
* @widget: a #GtkWidget
* to use. %GDK_SELECTION_CLIPBOARD gives the
* default clipboard. Another common value
* is %GDK_SELECTION_PRIMARY, which gives
- * the primary X selection.
- *
+ * the primary X selection.
+ *
* Returns the clipboard object for the given selection to
* be used with @widget. @widget must have a #GdkDisplay
* associated with it, so must be attached to a toplevel
{
GList *list = NULL;
GSList *l;
-
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
* gtk_widget_add_mnemonic_label:
* @widget: a #GtkWidget
* @label: a #GtkWidget that acts as a mnemonic label for @widget
- *
+ *
* Adds a widget to the list of mnemonic labels for
* this widget. (See gtk_widget_list_mnemonic_labels()). Note the
* list of mnemonic labels for the widget is cleared when the
old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
new_list = g_slist_prepend (old_list, label);
-
+
g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
new_list, (GDestroyNotify) g_slist_free);
}
* @widget: a #GtkWidget
* @label: a #GtkWidget that was previously set as a mnemnic label for
* @widget with gtk_widget_add_mnemonic_label().
- *
+ *
* Removes a widget from the list of mnemonic labels for
* this widget. (See gtk_widget_list_mnemonic_labels()). The widget
* must have previously been added to the list with
/**
* gtk_widget_get_no_show_all:
* @widget: a #GtkWidget
- *
- * Returns the current value of the GtkWidget:no-show-all property,
- * which determines whether calls to gtk_widget_show_all() and
- * gtk_widget_hide_all() will affect this widget.
- *
+ *
+ * Returns the current value of the #GtkWidget:no-show-all property,
+ * which determines whether calls to gtk_widget_show_all()
+ * will affect this widget.
+ *
* Return value: the current value of the "no-show-all" property.
*
* Since: 2.4
gtk_widget_get_no_show_all (GtkWidget *widget)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
-
- return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
+
+ return widget->priv->no_show_all;
}
/**
* gtk_widget_set_no_show_all:
* @widget: a #GtkWidget
* @no_show_all: the new value for the "no-show-all" property
- *
- * Sets the #GtkWidget:no-show-all property, which determines whether
- * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
- * this widget.
+ *
+ * Sets the #GtkWidget:no-show-all property, which determines whether
+ * calls to gtk_widget_show_all() will affect this widget.
*
* This is mostly for use in constructing widget hierarchies with externally
* controlled visibility, see #GtkUIManager.
- *
+ *
* Since: 2.4
**/
void
no_show_all = (no_show_all != FALSE);
- if (no_show_all == gtk_widget_get_no_show_all (widget))
- return;
+ if (widget->priv->no_show_all != no_show_all)
+ {
+ widget->priv->no_show_all = no_show_all;
- if (no_show_all)
- GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
-
- g_object_notify (G_OBJECT (widget), "no-show-all");
+ g_object_notify (G_OBJECT (widget), "no-show-all");
+ }
}
gboolean has_tooltip,
gboolean force)
{
+ GtkWidgetPrivate *priv = widget->priv;
gboolean priv_has_tooltip;
priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
if (priv_has_tooltip)
{
if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
- gdk_window_set_events (widget->window,
- gdk_window_get_events (widget->window) |
+ gdk_window_set_events (priv->window,
+ gdk_window_get_events (priv->window) |
GDK_LEAVE_NOTIFY_MASK |
GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK);
* @text: the contents of the tooltip for @widget
*
* Sets @text as the contents of the tooltip. This function will take
- * care of setting GtkWidget:has-tooltip to %TRUE and of the default
- * handler for the GtkWidget::query-tooltip signal.
+ * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
+ * handler for the #GtkWidget::query-tooltip signal.
*
- * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
+ * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
*
* Since: 2.12
*/
* Sets @markup as the contents of the tooltip, which is marked up with
* the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
*
- * This function will take care of setting GtkWidget:has-tooltip to %TRUE
- * and of the default handler for the GtkWidget::query-tooltip signal.
+ * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
+ * and of the default handler for the #GtkWidget::query-tooltip signal.
*
- * See also the GtkWidget:tooltip-markup property and
+ * See also the #GtkWidget:tooltip-markup property and
* gtk_tooltip_set_markup().
*
* Since: 2.12
* @has_tooltip: whether or not @widget has a tooltip.
*
* Sets the has-tooltip property on @widget to @has_tooltip. See
- * GtkWidget:has-tooltip for more information.
+ * #GtkWidget:has-tooltip for more information.
*
* Since: 2.12
*/
* @widget: a #GtkWidget
*
* Returns the current value of the has-tooltip property. See
- * GtkWidget:has-tooltip for more information.
+ * #GtkWidget:has-tooltip for more information.
*
* Return value: current value of has-tooltip on @widget.
*
*
* Retrieves the widget's allocation.
*
+ * Note, when implementing a #GtkContainer: a widget's allocation will
+ * be its "adjusted" allocation, that is, the widget's parent
+ * container typically calls gtk_widget_size_allocate() with an
+ * allocation, and that allocation is then adjusted (to handle margin
+ * and alignment for example) before assignment to the widget.
+ * gtk_widget_get_allocation() returns the adjusted allocation that
+ * was actually assigned to the widget. The adjusted allocation is
+ * guaranteed to be completely contained within the
+ * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
+ * is guaranteed that its children stay inside the assigned bounds,
+ * but not that they have exactly the bounds the container assigned.
+ * There is no way to get the original allocation assigned by
+ * gtk_widget_size_allocate(), since it isn't stored; if a container
+ * implementation needs that information it will have to track it itself.
+ *
* Since: 2.18
*/
void
gtk_widget_get_allocation (GtkWidget *widget,
GtkAllocation *allocation)
{
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (allocation != NULL);
- *allocation = widget->allocation;
+ priv = widget->priv;
+
+ *allocation = priv->allocation;
}
/**
* Sets the widget's allocation. This should not be used
* directly, but from within a widget's size_allocate method.
*
+ * The allocation set should be the "adjusted" or actual
+ * allocation. If you're implementing a #GtkContainer, you want to use
+ * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
+ * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
+ * allocation inside gtk_widget_size_allocate() to create an adjusted
+ * allocation.
+ *
* Since: 2.18
*/
void
gtk_widget_set_allocation (GtkWidget *widget,
const GtkAllocation *allocation)
{
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (allocation != NULL);
- widget->allocation = *allocation;
+ priv = widget->priv;
+
+ priv->allocation = *allocation;
+}
+
+/**
+ * gtk_widget_get_allocated_width:
+ * @widget: the widget to query
+ *
+ * Returns the width that has currently been allocated to @widget.
+ * This function is intended to be used when implementing handlers
+ * for the #GtkWidget::draw function.
+ *
+ * Returns: the width of the @widget
+ **/
+int
+gtk_widget_get_allocated_width (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+ return widget->priv->allocation.width;
+}
+
+/**
+ * gtk_widget_get_allocated_height:
+ * @widget: the widget to query
+ *
+ * Returns the height that has currently been allocated to @widget.
+ * This function is intended to be used when implementing handlers
+ * for the #GtkWidget::draw function.
+ *
+ * Returns: the height of the @widget
+ **/
+int
+gtk_widget_get_allocated_height (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+ return widget->priv->allocation.height;
}
/**
* Normally, gtk_widget_size_request() should be used.
*
* Since: 2.20
+ *
+ * Deprecated: 3.0: The #GtkRequisition cache on the widget was
+ * removed, If you need to cache sizes across requests and allocations,
+ * add an explicit cache to the widget in question instead.
*/
void
gtk_widget_get_requisition (GtkWidget *widget,
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (requisition != NULL);
- *requisition = widget->requisition;
+ gtk_widget_get_preferred_size (widget, requisition, NULL);
}
/**
* @window: a #GdkWindow
*
* Sets a widget's window. This function should only be used in a
- * widget's GtkWidget::realize() implementation. The %window passed is
+ * widget's #GtkWidget::realize implementation. The %window passed is
* usually either new window created with gdk_window_new(), or the
* window of its parent widget as returned by
* gtk_widget_get_parent_window().
* by calling gtk_widget_set_has_window(). This is usually done in the
* widget's init() function.
*
+ * <note><para>This function does not add any reference to @window.</para></note>
+ *
* Since: 2.18
*/
void
gtk_widget_set_window (GtkWidget *widget,
GdkWindow *window)
{
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
- if (widget->window != window)
+ priv = widget->priv;
+
+ if (priv->window != window)
{
- widget->window = window;
+ priv->window = window;
g_object_notify (G_OBJECT (widget), "window");
}
}
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
- return widget->window;
+ return widget->priv->window;
}
/**
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
+ return widget->priv->multidevice;
}
/**
gtk_widget_set_support_multidevice (GtkWidget *widget,
gboolean support_multidevice)
{
+ GtkWidgetPrivate *priv;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
+ priv = widget->priv;
+
if (support_multidevice)
{
- GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
+ priv->multidevice = TRUE;
gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
}
else
{
- GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
+ priv->multidevice = FALSE;
gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
}
if (gtk_widget_get_realized (widget))
- gdk_window_set_support_multidevice (widget->window, support_multidevice);
+ gdk_window_set_support_multidevice (priv->window, support_multidevice);
}
static void
_gtk_widget_set_has_focus (GtkWidget *widget,
gboolean has_focus)
{
- if (has_focus)
- GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
- else
- GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
+ widget->priv->has_focus = has_focus;
}
/**
return res;
}
+
+/**
+ * gtk_widget_in_destruction:
+ * @widget: a #GtkWidget
+ *
+ * Returns whether the widget is currently being destroyed.
+ * This information can sometimes be used to avoid doing
+ * unnecessary work.
+ *
+ * Returns: %TRUE if @widget is being destroyed
+ */
+gboolean
+gtk_widget_in_destruction (GtkWidget *widget)
+{
+ return widget->priv->in_destruction;
+}
+
+gboolean
+_gtk_widget_get_resize_pending (GtkWidget *widget)
+{
+ return widget->priv->resize_pending;
+}
+
+void
+_gtk_widget_set_resize_pending (GtkWidget *widget,
+ gboolean resize_pending)
+{
+ widget->priv->resize_pending = resize_pending;
+}
+
+gboolean
+_gtk_widget_get_in_reparent (GtkWidget *widget)
+{
+ return widget->priv->in_reparent;
+}
+
+void
+_gtk_widget_set_in_reparent (GtkWidget *widget,
+ gboolean in_reparent)
+{
+ widget->priv->in_reparent = in_reparent;
+}
+
+gboolean
+_gtk_widget_get_anchored (GtkWidget *widget)
+{
+ return widget->priv->anchored;
+}
+
+void
+_gtk_widget_set_anchored (GtkWidget *widget,
+ gboolean anchored)
+{
+ widget->priv->anchored = anchored;
+}
+
+gboolean
+_gtk_widget_get_shadowed (GtkWidget *widget)
+{
+ return widget->priv->shadowed;
+}
+
+void
+_gtk_widget_set_shadowed (GtkWidget *widget,
+ gboolean shadowed)
+{
+ widget->priv->shadowed = shadowed;
+}
+
+gboolean
+_gtk_widget_get_alloc_needed (GtkWidget *widget)
+{
+ return widget->priv->alloc_needed;
+}
+
+void
+_gtk_widget_set_alloc_needed (GtkWidget *widget,
+ gboolean alloc_needed)
+{
+ widget->priv->alloc_needed = alloc_needed;
+}
+
+gboolean
+_gtk_widget_get_width_request_needed (GtkWidget *widget)
+{
+ return widget->priv->width_request_needed;
+}
+
+void
+_gtk_widget_set_width_request_needed (GtkWidget *widget,
+ gboolean width_request_needed)
+{
+ widget->priv->width_request_needed = width_request_needed;
+}
+
+gboolean
+_gtk_widget_get_height_request_needed (GtkWidget *widget)
+{
+ return widget->priv->height_request_needed;
+}
+
+void
+_gtk_widget_set_height_request_needed (GtkWidget *widget,
+ gboolean height_request_needed)
+{
+ widget->priv->height_request_needed = height_request_needed;
+}