* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Mathias Hasselmann
*/
-#include "gtktoolpaletteprivate.h"
-#include "gtkmarshalers.h"
+#include "config.h"
-#include <gtk/gtk.h>
#include <string.h>
+#include <gtk/gtk.h>
+
+#include "gtktoolpaletteprivate.h"
+#include "gtkmarshalers.h"
+#include "gtktypebuiltins.h"
+#include "gtkprivate.h"
+#include "gtkscrollable.h"
+#include "gtkorientableprivate.h"
+#include "gtkintl.h"
#define DEFAULT_ICON_SIZE GTK_ICON_SIZE_SMALL_TOOLBAR
#define DEFAULT_ORIENTATION GTK_ORIENTATION_VERTICAL
#define DEFAULT_CHILD_EXCLUSIVE FALSE
#define DEFAULT_CHILD_EXPAND FALSE
-#define P_(msgid) (msgid)
-
/**
- * SECTION:GtkToolPalette
- * @short_description: A tool palette with categories
- * @include: gtktoolpalette.h
+ * SECTION:gtktoolpalette
+ * @Short_description: A tool palette with categories
+ * @Title: GtkToolPalette
*
- * An #GtkToolPalette allows it to add #GtkToolItem<!-- -->s to a palette like container
- * with different categories and drag and drop support.
+ * A #GtkToolPalette allows you to add #GtkToolItem<!-- -->s to a palette-like
+ * container with different categories and drag and drop support.
*
- * An #GtkToolPalette is created with a call to gtk_tool_palette_new().
+ * A #GtkToolPalette is created with a call to gtk_tool_palette_new().
*
- * #GtkToolItem<!-- -->s cannot be added directly to an #GtkToolPalette, instead they
- * are added to an #GtkToolItemGroup which can than be added to an #GtkToolPalette. To add
- * an #GtkToolItemGroup to an #GtkToolPalette use gtk_container_add().
+ * #GtkToolItem<!-- -->s cannot be added directly to a #GtkToolPalette -
+ * instead they are added to a #GtkToolItemGroup which can than be added
+ * to a #GtkToolPalette. To add a #GtkToolItemGroup to a #GtkToolPalette,
+ * use gtk_container_add().
*
* |[
* GtkWidget *palette, *group;
* gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
* ]|
*
- * The easiest way to use drag and drop with GtkToolPalette is to call gtk_tool_palette_add_drag_dest()
- * with the desired drag source @palette and the desired drag target @widget. Than gtk_tool_palette_get_drag_item()
- * can be used to get the dragged item in the #GtkWidget::drag-data-received signal handler of the drag target.
+ * The easiest way to use drag and drop with #GtkToolPalette is to call
+ * gtk_tool_palette_add_drag_dest() with the desired drag source @palette
+ * and the desired drag target @widget. Then gtk_tool_palette_get_drag_item()
+ * can be used to get the dragged item in the #GtkWidget::drag-data-received
+ * signal handler of the drag target.
*
* |[
* static void
* GtkWidget *item;
*
* /<!-- -->* Get the dragged item *<!-- -->/
- * palette = gtk_widget_get_ancestor (gtk_drag_get_source_widget (context), GTK_TYPE_TOOL_PALETTE);
+ * palette = gtk_widget_get_ancestor (gtk_drag_get_source_widget (context),
+ * GTK_TYPE_TOOL_PALETTE);
* if (palette != NULL)
- * item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette), selection);
+ * item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette),
+ * selection);
*
* /<!-- -->* Do something with item *<!-- -->/
* }
* target = gtk_drawing_area_new ();
*
* g_signal_connect (G_OBJECT (target), "drag-data-received",
- * G_CALLBACK (passive_canvas_drag_data_received), NULL);
+ * G_CALLBACK (passive_canvas_drag_data_received), NULL);
* gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette), target,
* GTK_DEST_DEFAULT_ALL,
* GTK_TOOL_PALETTE_DRAG_ITEMS,
* GDK_ACTION_COPY);
* ]|
*
- * Since: 2.18
+ * Since: 2.20
*/
typedef struct _GtkToolItemGroupInfo GtkToolItemGroupInfo;
{
PROP_NONE,
PROP_ICON_SIZE,
+ PROP_ICON_SIZE_SET,
PROP_ORIENTATION,
PROP_TOOLBAR_STYLE,
+ PROP_HADJUSTMENT,
+ PROP_VADJUSTMENT,
+ PROP_HSCROLL_POLICY,
+ PROP_VSCROLL_POLICY
};
enum
{
GtkToolItemGroup *widget;
- guint notify_collapsed;
+ gulong notify_collapsed;
+ guint pos;
guint exclusive : 1;
guint expand : 1;
};
struct _GtkToolPalettePrivate
{
- GtkToolItemGroupInfo *groups;
- gsize groups_size;
- gsize groups_length;
+ GPtrArray* groups;
GtkAdjustment *hadjustment;
GtkAdjustment *vadjustment;
GtkIconSize icon_size;
+ gboolean icon_size_set;
GtkOrientation orientation;
GtkToolbarStyle style;
+ gboolean style_set;
GtkWidget *expanding_child;
GtkSizeGroup *text_size_group;
- guint sparse_groups : 1;
+ GtkSettings *settings;
+ gulong settings_connection;
+
guint drag_source : 2;
+
+ /* GtkScrollablePolicy needs to be checked when
+ * driving the scrollable adjustment values */
+ guint hscroll_policy : 1;
+ guint vscroll_policy : 1;
};
struct _GtkToolPaletteDragData
static const GtkTargetEntry dnd_targets[] =
{
- { "application/x-GTK-tool-palette-item", GTK_TARGET_SAME_APP, 0 },
- { "application/x-GTK-tool-palette-group", GTK_TARGET_SAME_APP, 0 },
+ { "application/x-gtk-tool-palette-item", GTK_TARGET_SAME_APP, 0 },
+ { "application/x-gtk-tool-palette-group", GTK_TARGET_SAME_APP, 0 },
};
+static void gtk_tool_palette_set_hadjustment (GtkToolPalette *palette,
+ GtkAdjustment *adjustment);
+static void gtk_tool_palette_set_vadjustment (GtkToolPalette *palette,
+ GtkAdjustment *adjustment);
+
+
G_DEFINE_TYPE_WITH_CODE (GtkToolPalette,
gtk_tool_palette,
GTK_TYPE_CONTAINER,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
static void
gtk_tool_palette_init (GtkToolPalette *palette)
GTK_TYPE_TOOL_PALETTE,
GtkToolPalettePrivate);
- palette->priv->groups_size = 4;
- palette->priv->groups_length = 0;
- palette->priv->groups = g_new0 (GtkToolItemGroupInfo, palette->priv->groups_size);
+ palette->priv->groups = g_ptr_array_sized_new (4);
+ g_ptr_array_set_free_func (palette->priv->groups, g_free);
palette->priv->icon_size = DEFAULT_ICON_SIZE;
+ palette->priv->icon_size_set = FALSE;
palette->priv->orientation = DEFAULT_ORIENTATION;
palette->priv->style = DEFAULT_TOOLBAR_STYLE;
+ palette->priv->style_set = FALSE;
palette->priv->text_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
}
{
guint i;
- for (i = 0; i < palette->priv->groups_length; ++i)
+ for (i = 0; i < palette->priv->groups->len; ++i)
{
- if (palette->priv->groups[i].widget)
- _gtk_tool_item_group_palette_reconfigured (palette->priv->groups[i].widget);
+ GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
+ if (info->widget)
+ _gtk_tool_item_group_palette_reconfigured (info->widget);
}
gtk_widget_queue_resize_no_redraw (GTK_WIDGET (palette));
}
break;
+ case PROP_ICON_SIZE_SET:
+ if ((guint) g_value_get_enum (value) != palette->priv->icon_size)
+ {
+ palette->priv->icon_size_set = g_value_get_enum (value);
+ gtk_tool_palette_reconfigured (palette);
+ }
+ break;
+
case PROP_ORIENTATION:
if ((guint) g_value_get_enum (value) != palette->priv->orientation)
{
palette->priv->orientation = g_value_get_enum (value);
+ _gtk_orientable_set_style_classes (GTK_ORIENTABLE (palette));
gtk_tool_palette_reconfigured (palette);
}
break;
}
break;
+ case PROP_HADJUSTMENT:
+ gtk_tool_palette_set_hadjustment (palette, g_value_get_object (value));
+ break;
+
+ case PROP_VADJUSTMENT:
+ gtk_tool_palette_set_vadjustment (palette, g_value_get_object (value));
+ break;
+
+ case PROP_HSCROLL_POLICY:
+ palette->priv->hscroll_policy = g_value_get_enum (value);
+ gtk_widget_queue_resize (GTK_WIDGET (palette));
+ break;
+
+ case PROP_VSCROLL_POLICY:
+ palette->priv->vscroll_policy = g_value_get_enum (value);
+ gtk_widget_queue_resize (GTK_WIDGET (palette));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
g_value_set_enum (value, gtk_tool_palette_get_icon_size (palette));
break;
+ case PROP_ICON_SIZE_SET:
+ g_value_set_boolean (value, palette->priv->icon_size_set);
+ break;
+
case PROP_ORIENTATION:
g_value_set_enum (value, palette->priv->orientation);
break;
g_value_set_enum (value, gtk_tool_palette_get_style (palette));
break;
+ case PROP_HADJUSTMENT:
+ g_value_set_object (value, palette->priv->hadjustment);
+ break;
+
+ case PROP_VADJUSTMENT:
+ g_value_set_object (value, palette->priv->vadjustment);
+ break;
+
+ case PROP_HSCROLL_POLICY:
+ g_value_set_enum (value, palette->priv->hscroll_policy);
+ break;
+
+ case PROP_VSCROLL_POLICY:
+ g_value_set_enum (value, palette->priv->vscroll_policy);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
palette->priv->vadjustment = NULL;
}
- for (i = 0; i < palette->priv->groups_size; ++i)
+ for (i = 0; i < palette->priv->groups->len; ++i)
{
- GtkToolItemGroupInfo *group = &palette->priv->groups[i];
+ GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
if (group->notify_collapsed)
{
palette->priv->text_size_group = NULL;
}
+ if (palette->priv->settings_connection > 0)
+ {
+ g_signal_handler_disconnect (palette->priv->settings, palette->priv->settings_connection);
+ palette->priv->settings_connection = 0;
+ }
+
+ g_clear_object (&palette->priv->settings);
+
G_OBJECT_CLASS (gtk_tool_palette_parent_class)->dispose (object);
}
{
GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
- if (palette->priv->groups)
- {
- palette->priv->groups_length = 0;
- g_free (palette->priv->groups);
- palette->priv->groups = NULL;
- }
+ g_ptr_array_free (palette->priv->groups, TRUE);
G_OBJECT_CLASS (gtk_tool_palette_parent_class)->finalize (object);
}
gtk_tool_palette_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
- const gint border_width = GTK_CONTAINER (widget)->border_width;
GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
GtkRequisition child_requisition;
+ guint border_width;
guint i;
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
requisition->width = 0;
requisition->height = 0;
- for (i = 0; i < palette->priv->groups_length; ++i)
+ for (i = 0; i < palette->priv->groups->len; ++i)
{
- GtkToolItemGroupInfo *group = &palette->priv->groups[i];
+ GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
if (!group->widget)
continue;
- gtk_widget_size_request (GTK_WIDGET (group->widget), &child_requisition);
+ gtk_widget_get_preferred_size (GTK_WIDGET (group->widget),
+ &child_requisition, NULL);
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
{
requisition->height += border_width * 2;
}
+static void
+gtk_tool_palette_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ GtkRequisition requisition;
+
+ gtk_tool_palette_size_request (widget, &requisition);
+
+ *minimum = *natural = requisition.width;
+}
+
+static void
+gtk_tool_palette_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ GtkRequisition requisition;
+
+ gtk_tool_palette_size_request (widget, &requisition);
+
+ *minimum = *natural = requisition.height;
+}
+
+
static void
gtk_tool_palette_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
- const gint border_width = GTK_CONTAINER (widget)->border_width;
GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
GtkAdjustment *adjustment = NULL;
GtkAllocation child_allocation;
gint remaining_space = 0;
gint expand_space = 0;
- gint page_start, page_size = 0;
+ gint total_size, page_size;
gint offset = 0;
guint i;
+ guint border_width;
gint min_offset = -1, max_offset = -1;
gint x;
- gint *group_sizes = g_newa(gint, palette->priv->groups_length);
+ gint *group_sizes = g_newa (gint, palette->priv->groups->len);
+ GtkTextDirection direction;
- GtkTextDirection direction = gtk_widget_get_direction (widget);
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+ direction = gtk_widget_get_direction (widget);
GTK_WIDGET_CLASS (gtk_tool_palette_parent_class)->size_allocate (widget, allocation);
remaining_space = allocation->width;
/* figure out the required size of all groups to be able to distribute the
- * remaining space on allocation */
- for (i = 0; i < palette->priv->groups_length; ++i)
+ * remaining space on allocation
+ */
+ for (i = 0; i < palette->priv->groups->len; ++i)
{
- GtkToolItemGroupInfo *group = &palette->priv->groups[i];
+ GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
gint size;
+ group_sizes[i] = 0;
+
if (!group->widget)
continue;
remaining_space -= size;
group_sizes[i] = size;
- /* if the widget is currently expanding an offset which allows to display as much of the
- * widget as possible is calculated */
+ /* if the widget is currently expanding an offset which allows to
+ * display as much of the widget as possible is calculated
+ */
if (widget == palette->priv->expanding_child)
{
gint limit =
x -= offset;
/* allocate all groups at the calculated positions */
- for (i = 0; i < palette->priv->groups_length; ++i)
+ for (i = 0; i < palette->priv->groups->len; ++i)
{
- GtkToolItemGroupInfo *group = &palette->priv->groups[i];
+ GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
GtkWidget *widget;
if (!group->widget)
child_allocation.y += border_width;
child_allocation.y += offset;
- page_start = child_allocation.y;
+ total_size = child_allocation.y;
}
else
{
x += border_width;
x += offset;
- page_start = x;
+ total_size = x;
}
/* update the scrollbar to match the displayed adjustment */
if (adjustment)
{
- gdouble value;
+ gdouble lower, upper;
- adjustment->page_increment = page_size * 0.9;
- adjustment->step_increment = page_size * 0.1;
- adjustment->page_size = page_size;
+ total_size = MAX (0, total_size);
+ page_size = MIN (total_size, page_size);
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation ||
GTK_TEXT_DIR_LTR == direction)
{
- adjustment->lower = 0;
- adjustment->upper = MAX (0, page_start);
-
- value = MIN (offset, adjustment->upper - adjustment->page_size);
- gtk_adjustment_clamp_page (adjustment, value, offset + page_size);
+ lower = 0;
+ upper = total_size;
}
else
{
- adjustment->lower = page_size - MAX (0, page_start);
- adjustment->upper = page_size;
+ lower = page_size - total_size;
+ upper = page_size;
offset = -offset;
-
- value = MAX (offset, adjustment->lower);
- gtk_adjustment_clamp_page (adjustment, offset, value + page_size);
}
- gtk_adjustment_changed (adjustment);
+ gtk_adjustment_configure (adjustment,
+ offset,
+ lower,
+ upper,
+ page_size * 0.1,
+ page_size * 0.9,
+ page_size);
}
}
-static gboolean
-gtk_tool_palette_expose_event (GtkWidget *widget,
- GdkEventExpose *event)
-{
- GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
- GdkDisplay *display;
- cairo_t *cr;
- guint i;
-
- display = gdk_drawable_get_display (widget->window);
-
- if (!gdk_display_supports_composite (display))
- return FALSE;
-
- cr = gdk_cairo_create (widget->window);
- gdk_cairo_region (cr, event->region);
- cairo_clip (cr);
-
- cairo_push_group (cr);
-
- for (i = 0; i < palette->priv->groups_length; ++i)
- if (palette->priv->groups[i].widget)
- _gtk_tool_item_group_paint (palette->priv->groups[i].widget, cr);
-
- cairo_pop_group_to_source (cr);
-
- cairo_paint (cr);
- cairo_destroy (cr);
-
- return FALSE;
-}
-
static void
gtk_tool_palette_realize (GtkWidget *widget)
{
- const gint border_width = GTK_CONTAINER (widget)->border_width;
- gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ GtkAllocation allocation;
+ GdkWindow *window;
GdkWindowAttr attributes;
+ gint attributes_mask;
+ guint border_width;
+
+ gtk_widget_set_realized (widget, TRUE);
+
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
+ gtk_widget_get_allocation (widget, &allocation);
attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = widget->allocation.x + border_width;
- attributes.y = widget->allocation.y + border_width;
- attributes.width = widget->allocation.width - border_width * 2;
- attributes.height = widget->allocation.height - border_width * 2;
+ attributes.x = allocation.x + border_width;
+ attributes.y = allocation.y + border_width;
+ attributes.width = allocation.width - border_width * 2;
+ attributes.height = allocation.height - border_width * 2;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
- attributes.colormap = gtk_widget_get_colormap (widget);
- attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
- | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
- | GDK_BUTTON_MOTION_MASK;
-
- widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
- &attributes, attributes_mask);
-
- gdk_window_set_user_data (widget->window, widget);
- widget->style = gtk_style_attach (widget->style, widget->window);
- gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
- GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+ attributes.event_mask = gtk_widget_get_events (widget)
+ | GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
+ | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+ | GDK_BUTTON_MOTION_MASK
+ | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK
+ | GDK_TOUCH_MASK;
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+
+ window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes, attributes_mask);
+ gtk_widget_set_window (widget, window);
+ gtk_widget_register_window (widget, window);
+
+ gtk_style_context_set_background (gtk_widget_get_style_context (widget),
+ window);
gtk_container_forall (GTK_CONTAINER (widget),
(GtkCallback) gtk_widget_set_parent_window,
- widget->window);
+ window);
gtk_widget_queue_resize_no_redraw (widget);
}
static void
-gtk_tool_palette_adjustment_value_changed (GtkAdjustment *adjustment G_GNUC_UNUSED,
+gtk_tool_palette_adjustment_value_changed (GtkAdjustment *adjustment,
gpointer data)
{
+ GtkAllocation allocation;
GtkWidget *widget = GTK_WIDGET (data);
- gtk_tool_palette_size_allocate (widget, &widget->allocation);
-}
-
-static void
-gtk_tool_palette_set_scroll_adjustments (GtkWidget *widget,
- GtkAdjustment *hadjustment,
- GtkAdjustment *vadjustment)
-{
- GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
-
- if (palette->priv->hadjustment)
- g_object_unref (palette->priv->hadjustment);
- if (palette->priv->vadjustment)
- g_object_unref (palette->priv->vadjustment);
-
- if (hadjustment)
- g_object_ref_sink (hadjustment);
- if (vadjustment)
- g_object_ref_sink (vadjustment);
- palette->priv->hadjustment = hadjustment;
- palette->priv->vadjustment = vadjustment;
-
- if (palette->priv->hadjustment)
- g_signal_connect (palette->priv->hadjustment, "value-changed",
- G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
- palette);
- if (palette->priv->vadjustment)
- g_signal_connect (palette->priv->vadjustment, "value-changed",
- G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
- palette);
-}
-
-static void
-gtk_tool_palette_repack (GtkToolPalette *palette)
-{
- guint si, di;
-
- for (si = di = 0; di < palette->priv->groups_length; ++si)
- {
- if (palette->priv->groups[si].widget)
- {
- palette->priv->groups[di] = palette->priv->groups[si];
- ++di;
- }
- else
- --palette->priv->groups_length;
- }
-
- palette->priv->sparse_groups = FALSE;
+ gtk_widget_get_allocation (widget, &allocation);
+ gtk_tool_palette_size_allocate (widget, &allocation);
}
static void
GtkWidget *child)
{
GtkToolPalette *palette;
+ GtkToolItemGroupInfo *info = g_new0(GtkToolItemGroupInfo, 1);
g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (child));
palette = GTK_TOOL_PALETTE (container);
- if (palette->priv->groups_length == palette->priv->groups_size)
- gtk_tool_palette_repack (palette);
-
- if (palette->priv->groups_length == palette->priv->groups_size)
- {
- gsize old_size = palette->priv->groups_size;
- gsize new_size = old_size * 2;
-
- palette->priv->groups = g_renew (GtkToolItemGroupInfo,
- palette->priv->groups,
- new_size);
-
- memset (palette->priv->groups + old_size, 0,
- sizeof (GtkToolItemGroupInfo) * old_size);
-
- palette->priv->groups_size = new_size;
- }
-
- palette->priv->groups[palette->priv->groups_length].widget = g_object_ref_sink (child);
- palette->priv->groups_length += 1;
+ g_ptr_array_add (palette->priv->groups, info);
+ info->pos = palette->priv->groups->len - 1;
+ info->widget = g_object_ref_sink (child);
gtk_widget_set_parent (child, GTK_WIDGET (palette));
}
g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
palette = GTK_TOOL_PALETTE (container);
- for (i = 0; i < palette->priv->groups_length; ++i)
- if ((GtkWidget*) palette->priv->groups[i].widget == child)
- {
- g_object_unref (child);
- gtk_widget_unparent (child);
+ for (i = 0; i < palette->priv->groups->len; ++i)
+ {
+ GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
+ if (GTK_WIDGET(info->widget) == child)
+ {
+ g_object_unref (child);
+ gtk_widget_unparent (child);
- memset (&palette->priv->groups[i], 0, sizeof (GtkToolItemGroupInfo));
- palette->priv->sparse_groups = TRUE;
- }
+ g_ptr_array_remove_index (palette->priv->groups, i);
+ }
+ }
}
static void
gtk_tool_palette_forall (GtkContainer *container,
- gboolean internals G_GNUC_UNUSED,
+ gboolean internals,
GtkCallback callback,
gpointer callback_data)
{
GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
- guint i;
+ guint i, len;
- if (palette->priv->groups)
+ for (i = 0; i < palette->priv->groups->len; ++i)
{
- for (i = 0; i < palette->priv->groups_length; ++i)
- if (palette->priv->groups[i].widget)
- callback (GTK_WIDGET (palette->priv->groups[i].widget),
- callback_data);
+ GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
+
+ len = palette->priv->groups->len;
+
+ if (info->widget)
+ callback (GTK_WIDGET (info->widget),
+ callback_data);
+
+ /* At destroy time, 'callback' results in removing a widget,
+ * here we just reset the current index to account for the removed widget. */
+ i -= (len - palette->priv->groups->len);
}
}
static GType
-gtk_tool_palette_child_type (GtkContainer *container G_GNUC_UNUSED)
+gtk_tool_palette_child_type (GtkContainer *container)
{
return GTK_TYPE_TOOL_ITEM_GROUP;
}
switch (prop_id)
{
case CHILD_PROP_EXCLUSIVE:
- gtk_tool_palette_set_exclusive (palette, child, g_value_get_boolean (value));
+ gtk_tool_palette_set_exclusive (palette, GTK_TOOL_ITEM_GROUP (child),
+ g_value_get_boolean (value));
break;
case CHILD_PROP_EXPAND:
- gtk_tool_palette_set_expand (palette, child, g_value_get_boolean (value));
+ gtk_tool_palette_set_expand (palette, GTK_TOOL_ITEM_GROUP (child),
+ g_value_get_boolean (value));
break;
default:
switch (prop_id)
{
case CHILD_PROP_EXCLUSIVE:
- g_value_set_boolean (value, gtk_tool_palette_get_exclusive (palette, child));
+ g_value_set_boolean (value,
+ gtk_tool_palette_get_exclusive (palette, GTK_TOOL_ITEM_GROUP (child)));
break;
case CHILD_PROP_EXPAND:
- g_value_set_boolean (value, gtk_tool_palette_get_expand (palette, child));
+ g_value_set_boolean (value,
+ gtk_tool_palette_get_expand (palette, GTK_TOOL_ITEM_GROUP (child)));
break;
default:
}
}
+static void
+style_change_notify (GtkToolPalette *palette)
+{
+ GtkToolPalettePrivate* priv = palette->priv;
+
+ if (!priv->style_set)
+ {
+ /* pretend it was set, then unset, thus reverting to new default */
+ priv->style_set = TRUE;
+ gtk_tool_palette_unset_style (palette);
+ }
+}
+
+static void
+icon_size_change_notify (GtkToolPalette *palette)
+{
+ GtkToolPalettePrivate* priv = palette->priv;
+
+ if (!priv->icon_size_set)
+ {
+ /* pretend it was set, then unset, thus reverting to new default */
+ priv->icon_size_set = TRUE;
+ gtk_tool_palette_unset_icon_size (palette);
+ }
+}
+
+static void
+gtk_tool_palette_settings_change_notify (GtkSettings *settings,
+ const GParamSpec *pspec,
+ GtkToolPalette *palette)
+{
+ if (strcmp (pspec->name, "gtk-toolbar-style") == 0)
+ style_change_notify (palette);
+ else if (strcmp (pspec->name, "gtk-toolbar-icon-size") == 0)
+ icon_size_change_notify (palette);
+}
+
+static void
+gtk_tool_palette_screen_changed (GtkWidget *widget,
+ GdkScreen *previous_screen)
+{
+ GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
+ GtkToolPalettePrivate* priv = palette->priv;
+ GtkSettings *old_settings = priv->settings;
+ GtkSettings *settings;
+
+ if (gtk_widget_has_screen (GTK_WIDGET (palette)))
+ settings = gtk_widget_get_settings (GTK_WIDGET (palette));
+ else
+ settings = NULL;
+
+ if (settings == old_settings)
+ return;
+
+ if (old_settings)
+ {
+ g_signal_handler_disconnect (old_settings, priv->settings_connection);
+ priv->settings_connection = 0;
+ g_object_unref (old_settings);
+ }
+
+ if (settings)
+ {
+ priv->settings_connection =
+ g_signal_connect (settings, "notify",
+ G_CALLBACK (gtk_tool_palette_settings_change_notify),
+ palette);
+ priv->settings = g_object_ref (settings);
+ }
+ else
+ priv->settings = NULL;
+
+ gtk_tool_palette_reconfigured (palette);
+}
+
+
static void
gtk_tool_palette_class_init (GtkToolPaletteClass *cls)
{
oclass->dispose = gtk_tool_palette_dispose;
oclass->finalize = gtk_tool_palette_finalize;
- wclass->size_request = gtk_tool_palette_size_request;
+ wclass->get_preferred_width = gtk_tool_palette_get_preferred_width;
+ wclass->get_preferred_height= gtk_tool_palette_get_preferred_height;
wclass->size_allocate = gtk_tool_palette_size_allocate;
- wclass->expose_event = gtk_tool_palette_expose_event;
wclass->realize = gtk_tool_palette_realize;
cclass->add = gtk_tool_palette_add;
cclass->set_child_property = gtk_tool_palette_set_child_property;
cclass->get_child_property = gtk_tool_palette_get_child_property;
- cls->set_scroll_adjustments = gtk_tool_palette_set_scroll_adjustments;
+ /* Handle screen-changed so we can update our GtkSettings.
+ */
+ wclass->screen_changed = gtk_tool_palette_screen_changed;
+
+ g_object_class_override_property (oclass, PROP_ORIENTATION, "orientation");
+
+ g_object_class_override_property (oclass, PROP_HADJUSTMENT, "hadjustment");
+ g_object_class_override_property (oclass, PROP_VADJUSTMENT, "vadjustment");
+ g_object_class_override_property (oclass, PROP_HSCROLL_POLICY, "hscroll-policy");
+ g_object_class_override_property (oclass, PROP_VSCROLL_POLICY, "vscroll-policy");
+
/**
- * GtkToolPalette::set-scroll-adjustments:
- * @widget: the GtkToolPalette that received the signal
- * @hadjustment: The horizontal adjustment
- * @vadjustment: The vertical adjustment
+ * GtkToolPalette:icon-size:
*
- * The ::set-scroll-adjustments when FIXME
+ * The size of the icons in a tool palette is normally determined by
+ * the #GtkSettings:gtk-toolbar-icon-size setting. When this property is set,
+ * it overrides the setting.
*
- * Since: 2.18
+ * This should only be used for special-purpose tool palettes, normal
+ * application tool palettes should respect the user preferences for the
+ * size of icons.
+ *
+ * Since: 2.20
*/
- wclass->set_scroll_adjustments_signal =
- g_signal_new ("set-scroll-adjustments",
- G_TYPE_FROM_CLASS (oclass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GtkToolPaletteClass, set_scroll_adjustments),
- NULL, NULL,
- _gtk_marshal_VOID__OBJECT_OBJECT,
- G_TYPE_NONE, 2,
- GTK_TYPE_ADJUSTMENT,
- GTK_TYPE_ADJUSTMENT);
-
- g_object_class_install_property (oclass, PROP_ICON_SIZE,
+ g_object_class_install_property (oclass,
+ PROP_ICON_SIZE,
g_param_spec_enum ("icon-size",
- P_("Icon Size"),
- P_("The size of palette icons"),
+ P_("Icon size"),
+ P_("Size of icons in this tool palette"),
GTK_TYPE_ICON_SIZE,
DEFAULT_ICON_SIZE,
- G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ GTK_PARAM_READWRITE));
- g_object_class_override_property (oclass, PROP_ORIENTATION,
- "orientation");
+ /**
+ * GtkToolPalette:icon-size-set:
+ *
+ * Is %TRUE if the #GtkToolPalette:icon-size property has been set.
+ *
+ * Since: 2.20
+ */
+ g_object_class_install_property (oclass,
+ PROP_ICON_SIZE_SET,
+ g_param_spec_boolean ("icon-size-set",
+ P_("Icon size set"),
+ P_("Whether the icon-size property has been set"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+ /**
+ * GtkToolPalette:toolbar-style:
+ *
+ * The style of items in the tool palette.
+ *
+ * Since: 2.20
+ */
g_object_class_install_property (oclass, PROP_TOOLBAR_STYLE,
g_param_spec_enum ("toolbar-style",
P_("Toolbar Style"),
P_("Style of items in the tool palette"),
GTK_TYPE_TOOLBAR_STYLE,
DEFAULT_TOOLBAR_STYLE,
- G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkToolPalette:exclusive:
+ *
+ * Whether the item group should be the only one that is expanded
+ * at a given time.
+ *
+ * Since: 2.20
+ */
gtk_container_class_install_child_property (cclass, CHILD_PROP_EXCLUSIVE,
g_param_spec_boolean ("exclusive",
P_("Exclusive"),
P_("Whether the item group should be the only expanded at a given time"),
DEFAULT_CHILD_EXCLUSIVE,
- G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ GTK_PARAM_READWRITE));
+ /**
+ * GtkToolPalette:expand:
+ *
+ * Whether the item group should receive extra space when the palette grows.
+ * at a given time.
+ *
+ * Since: 2.20
+ */
gtk_container_class_install_child_property (cclass, CHILD_PROP_EXPAND,
g_param_spec_boolean ("expand",
P_("Expand"),
P_("Whether the item group should receive extra space when the palette grows"),
DEFAULT_CHILD_EXPAND,
- G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ GTK_PARAM_READWRITE));
g_type_class_add_private (cls, sizeof (GtkToolPalettePrivate));
*
* Creates a new tool palette.
*
- * Returns: a new #GtkToolPalette.
+ * Returns: a new #GtkToolPalette
*
- * Since: 2.18
+ * Since: 2.20
*/
GtkWidget*
gtk_tool_palette_new (void)
/**
* gtk_tool_palette_set_icon_size:
- * @palette: an #GtkToolPalette.
- * @icon_size: the #GtkIconSize that icons in the tool palette shall have.
+ * @palette: a #GtkToolPalette
+ * @icon_size: (type int): the #GtkIconSize that icons in the tool
+ * palette shall have
*
* Sets the size of icons in the tool palette.
*
- * Since: 2.18
+ * Since: 2.20
*/
void
gtk_tool_palette_set_icon_size (GtkToolPalette *palette,
GtkIconSize icon_size)
{
+ GtkToolPalettePrivate *priv;
+
+ g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
+ g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
+
+ priv = palette->priv;
+
+ if (!priv->icon_size_set)
+ {
+ priv->icon_size_set = TRUE;
+ g_object_notify (G_OBJECT (palette), "icon-size-set");
+ }
+
+ if (priv->icon_size == icon_size)
+ return;
+
+ priv->icon_size = icon_size;
+ g_object_notify (G_OBJECT (palette), "icon-size");
+
+ gtk_tool_palette_reconfigured (palette);
+
+ gtk_widget_queue_resize (GTK_WIDGET (palette));
+}
+
+static GtkSettings *
+toolpalette_get_settings (GtkToolPalette *palette)
+{
+ GtkToolPalettePrivate *priv = palette->priv;
+ return priv->settings;
+}
+
+/**
+ * gtk_tool_palette_unset_icon_size:
+ * @palette: a #GtkToolPalette
+ *
+ * Unsets the tool palette icon size set with gtk_tool_palette_set_icon_size(),
+ * so that user preferences will be used to determine the icon size.
+ *
+ * Since: 2.20
+ */
+void
+gtk_tool_palette_unset_icon_size (GtkToolPalette *palette)
+{
+ GtkToolPalettePrivate* priv = palette->priv;
+ GtkIconSize size;
+
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
- if (icon_size != palette->priv->icon_size)
- g_object_set (palette, "icon-size", icon_size, NULL);
+ if (palette->priv->icon_size_set)
+ {
+ GtkSettings *settings = toolpalette_get_settings (palette);
+
+ if (settings)
+ {
+ g_object_get (settings,
+ "gtk-toolbar-icon-size", &size,
+ NULL);
+ }
+ else
+ size = DEFAULT_ICON_SIZE;
+
+ if (size != palette->priv->icon_size)
+ {
+ gtk_tool_palette_set_icon_size (palette, size);
+ g_object_notify (G_OBJECT (palette), "icon-size");
+ }
+
+ priv->icon_size_set = FALSE;
+ g_object_notify (G_OBJECT (palette), "icon-size-set");
+ }
}
+/* Set the "toolbar-style" property and do appropriate things.
+ * GtkToolbar does this by emitting a signal instead of just
+ * calling a function...
+ */
+static void
+gtk_tool_palette_change_style (GtkToolPalette *palette,
+ GtkToolbarStyle style)
+{
+ GtkToolPalettePrivate* priv = palette->priv;
+
+ if (priv->style != style)
+ {
+ priv->style = style;
+
+ gtk_tool_palette_reconfigured (palette);
+
+ gtk_widget_queue_resize (GTK_WIDGET (palette));
+ g_object_notify (G_OBJECT (palette), "toolbar-style");
+ }
+}
+
+
/**
* gtk_tool_palette_set_style:
- * @palette: an #GtkToolPalette.
- * @style: the #GtkToolbarStyle that items in the tool palette shall have.
+ * @palette: a #GtkToolPalette
+ * @style: the #GtkToolbarStyle that items in the tool palette shall have
*
* Sets the style (text, icons or both) of items in the tool palette.
*
- * Since: 2.18
+ * Since: 2.20
*/
void
gtk_tool_palette_set_style (GtkToolPalette *palette,
{
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
- if (style != palette->priv->style)
- g_object_set (palette, "toolbar-style", style, NULL);
+ palette->priv->style_set = TRUE;
+ gtk_tool_palette_change_style (palette, style);
+}
+
+
+/**
+ * gtk_tool_palette_unset_style:
+ * @palette: a #GtkToolPalette
+ *
+ * Unsets a toolbar style set with gtk_tool_palette_set_style(),
+ * so that user preferences will be used to determine the toolbar style.
+ *
+ * Since: 2.20
+ */
+void
+gtk_tool_palette_unset_style (GtkToolPalette *palette)
+{
+ GtkToolPalettePrivate* priv = palette->priv;
+ GtkToolbarStyle style;
+
+ g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
+
+ if (priv->style_set)
+ {
+ GtkSettings *settings = toolpalette_get_settings (palette);
+
+ if (settings)
+ g_object_get (settings,
+ "gtk-toolbar-style", &style,
+ NULL);
+ else
+ style = DEFAULT_TOOLBAR_STYLE;
+
+ if (style != priv->style)
+ gtk_tool_palette_change_style (palette, style);
+
+ priv->style_set = FALSE;
+ }
}
/**
* gtk_tool_palette_get_icon_size:
- * @palette: an #GtkToolPalette.
+ * @palette: a #GtkToolPalette
*
- * Gets the size of icons in the tool palette. See gtk_tool_palette_set_icon_size().
- *
- * Returns: the #GtkIconSize of icons in the tool palette.
+ * Gets the size of icons in the tool palette.
+ * See gtk_tool_palette_set_icon_size().
*
- * Since: 2.18
+ * Returns: (type int): the #GtkIconSize of icons in the tool palette
+ *
+ * Since: 2.20
*/
GtkIconSize
gtk_tool_palette_get_icon_size (GtkToolPalette *palette)
{
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_ICON_SIZE);
+
return palette->priv->icon_size;
}
/**
* gtk_tool_palette_get_style:
- * @palette: an #GtkToolPalette.
+ * @palette: a #GtkToolPalette
*
* Gets the style (icons, text or both) of items in the tool palette.
*
* Returns: the #GtkToolbarStyle of items in the tool palette.
*
- * Since: 2.18
+ * Since: 2.20
*/
GtkToolbarStyle
gtk_tool_palette_get_style (GtkToolPalette *palette)
{
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_TOOLBAR_STYLE);
+
return palette->priv->style;
}
+static gint
+gtk_tool_palette_compare_groups (gconstpointer a,
+ gconstpointer b)
+{
+ const GtkToolItemGroupInfo *group_a = a;
+ const GtkToolItemGroupInfo *group_b = b;
+
+ return group_a->pos - group_b->pos;
+}
+
/**
* gtk_tool_palette_set_group_position:
- * @palette: an #GtkToolPalette.
- * @group: an #GtkToolItemGroup which is a child of palette.
- * @position: a new index for group.
+ * @palette: a #GtkToolPalette
+ * @group: a #GtkToolItemGroup which is a child of palette
+ * @position: a new index for group
*
* Sets the position of the group as an index of the tool palette.
* If position is 0 the group will become the first child, if position is
* -1 it will become the last child.
*
- * Since: 2.18
+ * Since: 2.20
*/
void
-gtk_tool_palette_set_group_position (GtkToolPalette *palette,
- GtkWidget *group,
- gint position)
+gtk_tool_palette_set_group_position (GtkToolPalette *palette,
+ GtkToolItemGroup *group,
+ gint position)
{
- GtkToolItemGroupInfo group_info;
+ GtkToolItemGroupInfo *group_new;
+ GtkToolItemGroupInfo *group_old;
gint old_position;
- gpointer src, dst;
- gsize len;
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
-
- gtk_tool_palette_repack (palette);
-
g_return_if_fail (position >= -1);
if (-1 == position)
- position = palette->priv->groups_length - 1;
+ position = palette->priv->groups->len - 1;
- g_return_if_fail ((guint) position < palette->priv->groups_length);
+ g_return_if_fail ((guint) position < palette->priv->groups->len);
- if (GTK_TOOL_ITEM_GROUP (group) == palette->priv->groups[position].widget)
+ group_new = g_ptr_array_index (palette->priv->groups, position);
+
+ if (GTK_TOOL_ITEM_GROUP (group) == group_new->widget)
return;
old_position = gtk_tool_palette_get_group_position (palette, group);
g_return_if_fail (old_position >= 0);
- group_info = palette->priv->groups[old_position];
+ group_old = g_ptr_array_index (palette->priv->groups, old_position);
- if (position < old_position)
- {
- dst = palette->priv->groups + position + 1;
- src = palette->priv->groups + position;
- len = old_position - position;
- }
- else
- {
- dst = palette->priv->groups + old_position;
- src = palette->priv->groups + old_position + 1;
- len = position - old_position;
- }
+ group_new->pos = position;
+ group_old->pos = old_position;
- memmove (dst, src, len * sizeof (*palette->priv->groups));
- palette->priv->groups[position] = group_info;
+ g_ptr_array_sort (palette->priv->groups, gtk_tool_palette_compare_groups);
gtk_widget_queue_resize (GTK_WIDGET (palette));
}
static void
gtk_tool_palette_group_notify_collapsed (GtkToolItemGroup *group,
- GParamSpec *pspec G_GNUC_UNUSED,
+ GParamSpec *pspec,
gpointer data)
{
GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
if (gtk_tool_item_group_get_collapsed (group))
return;
- for (i = 0; i < palette->priv->groups_size; ++i)
+ for (i = 0; i < palette->priv->groups->len; ++i)
{
- GtkToolItemGroup *current_group = palette->priv->groups[i].widget;
+ GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
+ GtkToolItemGroup *current_group = info->widget;
if (current_group && current_group != group)
- gtk_tool_item_group_set_collapsed (palette->priv->groups[i].widget, TRUE);
+ gtk_tool_item_group_set_collapsed (current_group, TRUE);
}
}
/**
* gtk_tool_palette_set_exclusive:
- * @palette: an #GtkToolPalette.
- * @group: an #GtkToolItemGroup which is a child of palette.
- * @exclusive: whether the group should be exclusive or not.
+ * @palette: a #GtkToolPalette
+ * @group: a #GtkToolItemGroup which is a child of palette
+ * @exclusive: whether the group should be exclusive or not
*
- * Sets whether the group should be exclusive or not. If an exclusive group is expanded
- * all other groups are collapsed.
+ * Sets whether the group should be exclusive or not.
+ * If an exclusive group is expanded all other groups are collapsed.
*
- * Since: 2.18
+ * Since: 2.20
*/
void
-gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
- GtkWidget *group,
- gboolean exclusive)
+gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
+ GtkToolItemGroup *group,
+ gboolean exclusive)
{
GtkToolItemGroupInfo *group_info;
gint position;
position = gtk_tool_palette_get_group_position (palette, group);
g_return_if_fail (position >= 0);
- group_info = &palette->priv->groups[position];
+ group_info = g_ptr_array_index (palette->priv->groups, position);
if (exclusive == group_info->exclusive)
return;
}
gtk_tool_palette_group_notify_collapsed (group_info->widget, NULL, palette);
- gtk_widget_child_notify (group, "exclusive");
+ gtk_widget_child_notify (GTK_WIDGET (group), "exclusive");
}
/**
* gtk_tool_palette_set_expand:
- * @palette: an #GtkToolPalette.
- * @group: an #GtkToolItemGroup which is a child of palette.
- * @expand: whether the group should be given extra space.
+ * @palette: a #GtkToolPalette
+ * @group: a #GtkToolItemGroup which is a child of palette
+ * @expand: whether the group should be given extra space
*
* Sets whether the group should be given extra space.
*
- * Since: 2.18
+ * Since: 2.20
*/
void
-gtk_tool_palette_set_expand (GtkToolPalette *palette,
- GtkWidget *group,
+gtk_tool_palette_set_expand (GtkToolPalette *palette,
+ GtkToolItemGroup *group,
gboolean expand)
{
GtkToolItemGroupInfo *group_info;
position = gtk_tool_palette_get_group_position (palette, group);
g_return_if_fail (position >= 0);
- group_info = &palette->priv->groups[position];
+ group_info = g_ptr_array_index (palette->priv->groups, position);
if (expand != group_info->expand)
{
group_info->expand = expand;
gtk_widget_queue_resize (GTK_WIDGET (palette));
- gtk_widget_child_notify (group, "expand");
+ gtk_widget_child_notify (GTK_WIDGET (group), "expand");
}
}
/**
* gtk_tool_palette_get_group_position:
- * @palette: an #GtkToolPalette.
- * @group: an #GtkToolItemGroup.
+ * @palette: a #GtkToolPalette
+ * @group: a #GtkToolItemGroup
*
- * Gets the position of @group in @palette as index. see gtk_tool_palette_set_group_position().
+ * Gets the position of @group in @palette as index.
+ * See gtk_tool_palette_set_group_position().
*
- * Returns: the index of group or -1 if @group is not a child of @palette.
+ * Returns: the index of group or -1 if @group is not a child of @palette
*
- * Since: 2.18
+ * Since: 2.20
*/
gint
-gtk_tool_palette_get_group_position (GtkToolPalette *palette,
- GtkWidget *group)
+gtk_tool_palette_get_group_position (GtkToolPalette *palette,
+ GtkToolItemGroup *group)
{
guint i;
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), -1);
g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), -1);
- for (i = 0; i < palette->priv->groups_length; ++i)
- if ((gpointer) group == palette->priv->groups[i].widget)
- return i;
+ for (i = 0; i < palette->priv->groups->len; ++i)
+ {
+ GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
+ if ((gpointer) group == info->widget)
+ return i;
+ }
return -1;
}
/**
* gtk_tool_palette_get_exclusive:
- * @palette: an #GtkToolPalette.
- * @group: an #GtkToolItemGroup which is a child of palette.
+ * @palette: a #GtkToolPalette
+ * @group: a #GtkToolItemGroup which is a child of palette
*
- * Gets whether group is exclusive or not. See gtk_tool_palette_set_exclusive().
+ * Gets whether @group is exclusive or not.
+ * See gtk_tool_palette_set_exclusive().
*
- * Returns: %TRUE if group is exclusive.
+ * Returns: %TRUE if @group is exclusive
*
- * Since: 2.18
+ * Since: 2.20
*/
gboolean
-gtk_tool_palette_get_exclusive (GtkToolPalette *palette,
- GtkWidget *group)
+gtk_tool_palette_get_exclusive (GtkToolPalette *palette,
+ GtkToolItemGroup *group)
{
gint position;
+ GtkToolItemGroupInfo *info;
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXCLUSIVE);
g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXCLUSIVE);
position = gtk_tool_palette_get_group_position (palette, group);
g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXCLUSIVE);
- return palette->priv->groups[position].exclusive;
+ info = g_ptr_array_index (palette->priv->groups, position);
+
+ return info->exclusive;
}
/**
* gtk_tool_palette_get_expand:
- * @palette: an #GtkToolPalette.
- * @group: an #GtkToolItemGroup which is a child of palette.
+ * @palette: a #GtkToolPalette
+ * @group: a #GtkToolItemGroup which is a child of palette
*
- * Gets whether group should be given extra space. See gtk_tool_palette_set_expand().
+ * Gets whether group should be given extra space.
+ * See gtk_tool_palette_set_expand().
*
- * Returns: %TRUE if group should be given extra space, %FALSE otherwise.
+ * Returns: %TRUE if group should be given extra space, %FALSE otherwise
*
- * Since: 2.18
+ * Since: 2.20
*/
gboolean
-gtk_tool_palette_get_expand (GtkToolPalette *palette,
- GtkWidget *group)
+gtk_tool_palette_get_expand (GtkToolPalette *palette,
+ GtkToolItemGroup *group)
{
gint position;
+ GtkToolItemGroupInfo *info;
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXPAND);
g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXPAND);
position = gtk_tool_palette_get_group_position (palette, group);
g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXPAND);
- return palette->priv->groups[position].expand;
+ info = g_ptr_array_index (palette->priv->groups, position);
+
+ return info->expand;
}
/**
* gtk_tool_palette_get_drop_item:
- * @palette: an #GtkToolPalette.
- * @x: the x position.
- * @y: the y position.
+ * @palette: a #GtkToolPalette
+ * @x: the x position
+ * @y: the y position
*
- * Gets the item at position (x, y). See gtk_tool_palette_get_drop_group().
+ * Gets the item at position (x, y).
+ * See gtk_tool_palette_get_drop_group().
*
- * Returns: the #GtkToolItem at position or %NULL if there is no such item.
+ * Returns: (transfer none): the #GtkToolItem at position or %NULL if there is no such item
*
- * Since: 2.18
+ * Since: 2.20
*/
GtkToolItem*
gtk_tool_palette_get_drop_item (GtkToolPalette *palette,
gint x,
gint y)
{
- GtkWidget *group = gtk_tool_palette_get_drop_group (palette, x, y);
+ GtkAllocation allocation;
+ GtkToolItemGroup *group = gtk_tool_palette_get_drop_group (palette, x, y);
+ GtkWidget *widget = GTK_WIDGET (group);
if (group)
- return gtk_tool_item_group_get_drop_item (GTK_TOOL_ITEM_GROUP (group),
- x - group->allocation.x,
- y - group->allocation.y);
+ {
+ gtk_widget_get_allocation (widget, &allocation);
+ return gtk_tool_item_group_get_drop_item (group,
+ x - allocation.x,
+ y - allocation.y);
+ }
return NULL;
}
/**
* gtk_tool_palette_get_drop_group:
- * @palette: an #GtkToolPalette.
- * @x: the x position.
- * @y: the y position.
+ * @palette: a #GtkToolPalette
+ * @x: the x position
+ * @y: the y position
*
* Gets the group at position (x, y).
*
- * Returns: the #GtkToolItemGroup at position or %NULL if there is no such group.
+ * Returns: (transfer none): the #GtkToolItemGroup at position or %NULL
+ * if there is no such group
*
- * Since: 2.18
+ * Since: 2.20
*/
-GtkWidget*
+GtkToolItemGroup*
gtk_tool_palette_get_drop_group (GtkToolPalette *palette,
gint x,
gint y)
{
- GtkAllocation *allocation;
+ GtkAllocation allocation;
guint i;
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
- allocation = >K_WIDGET (palette)->allocation;
+ gtk_widget_get_allocation (GTK_WIDGET (palette), &allocation);
- g_return_val_if_fail (x >= 0 && x < allocation->width, NULL);
- g_return_val_if_fail (y >= 0 && y < allocation->height, NULL);
+ g_return_val_if_fail (x >= 0 && x < allocation.width, NULL);
+ g_return_val_if_fail (y >= 0 && y < allocation.height, NULL);
- for (i = 0; i < palette->priv->groups_length; ++i)
+ for (i = 0; i < palette->priv->groups->len; ++i)
{
- GtkToolItemGroupInfo *group = &palette->priv->groups[i];
+ GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
GtkWidget *widget;
gint x0, y0;
continue;
widget = GTK_WIDGET (group->widget);
+ gtk_widget_get_allocation (widget, &allocation);
- x0 = x - widget->allocation.x;
- y0 = y - widget->allocation.y;
+ x0 = x - allocation.x;
+ y0 = y - allocation.y;
- if (x0 >= 0 && x0 < widget->allocation.width &&
- y0 >= 0 && y0 < widget->allocation.height)
- return widget;
+ if (x0 >= 0 && x0 < allocation.width &&
+ y0 >= 0 && y0 < allocation.height)
+ return GTK_TOOL_ITEM_GROUP (widget);
}
return NULL;
/**
* gtk_tool_palette_get_drag_item:
- * @palette: an #GtkToolPalette.
- * @selection: a #GtkSelectionData.
+ * @palette: a #GtkToolPalette
+ * @selection: a #GtkSelectionData
*
- * Get the dragged item from the selection. This could be a #GtkToolItem or
- * an #GtkToolItemGroup.
+ * Get the dragged item from the selection.
+ * This could be a #GtkToolItem or a #GtkToolItemGroup.
*
- * Returns: the dragged item in selection.
+ * Returns: (transfer none): the dragged item in selection
*
- * Since: 2.18
+ * Since: 2.20
*/
GtkWidget*
gtk_tool_palette_get_drag_item (GtkToolPalette *palette,
const GtkSelectionData *selection)
{
GtkToolPaletteDragData *data;
+ GdkAtom target;
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
g_return_val_if_fail (NULL != selection, NULL);
- g_return_val_if_fail (selection->format == 8, NULL);
- g_return_val_if_fail (selection->length == sizeof (GtkToolPaletteDragData), NULL);
- g_return_val_if_fail (selection->target == dnd_target_atom_item ||
- selection->target == dnd_target_atom_group,
+ g_return_val_if_fail (gtk_selection_data_get_format (selection) == 8, NULL);
+ g_return_val_if_fail (gtk_selection_data_get_length (selection) == sizeof (GtkToolPaletteDragData), NULL);
+ target = gtk_selection_data_get_target (selection);
+ g_return_val_if_fail (target == dnd_target_atom_item ||
+ target == dnd_target_atom_group,
NULL);
- data = (GtkToolPaletteDragData*) selection->data;
+ data = (GtkToolPaletteDragData*) gtk_selection_data_get_data (selection);
g_return_val_if_fail (data->palette == palette, NULL);
- if (dnd_target_atom_item == selection->target)
+ if (dnd_target_atom_item == target)
g_return_val_if_fail (GTK_IS_TOOL_ITEM (data->item), NULL);
- else if (dnd_target_atom_group == selection->target)
+ else if (dnd_target_atom_group == target)
g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (data->item), NULL);
return data->item;
/**
* gtk_tool_palette_set_drag_source:
- * @palette: an #GtkToolPalette.
- * @targets: the #GtkToolPaletteDragTargets which the widget should support.
- *
- * Sets the tool palette as a drag source. Enables all groups and items in
- * the tool palette as drag sources on button 1 and button 3 press with copy
- * and move actions.
+ * @palette: a #GtkToolPalette
+ * @targets: the #GtkToolPaletteDragTargets
+ * which the widget should support
*
+ * Sets the tool palette as a drag source.
+ * Enables all groups and items in the tool palette as drag sources
+ * on button 1 and button 3 press with copy and move actions.
* See gtk_drag_source_set().
*
- * Since: 2.18
- *
+ * Since: 2.20
*/
void
gtk_tool_palette_set_drag_source (GtkToolPalette *palette,
palette->priv->drag_source |= targets;
- for (i = 0; i < palette->priv->groups_length; ++i)
+ for (i = 0; i < palette->priv->groups->len; ++i)
{
- if (palette->priv->groups[i].widget)
- gtk_container_forall (GTK_CONTAINER (palette->priv->groups[i].widget),
+ GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
+ if (info->widget)
+ gtk_container_forall (GTK_CONTAINER (info->widget),
_gtk_tool_palette_child_set_drag_source,
palette);
}
/**
* gtk_tool_palette_add_drag_dest:
- * @palette: an #GtkToolPalette.
- * @widget: a #GtkWidget which should be a drag destination for palette.
- * @flags: the flags that specify what actions GTK+ should take for drops on that widget.
- * @targets: the #GtkToolPaletteDragTargets which the widget should support.
- * @actions: the #GdkDragAction<!-- -->s which the widget should suppport.
- *
- * Sets the tool palette as drag source (see gtk_tool_palette_set_drag_source) and
- * sets widget as a drag destination for drags from palette. With flags the actions
- * (like highlighting and target checking) which should be performed by GTK+ for
- * drops on widget can be specified. With targets the supported drag targets
- * (groups and/or items) can be specified. With actions the supported drag actions
- * (copy and move) can be specified.
- *
+ * @palette: a #GtkToolPalette
+ * @widget: a #GtkWidget which should be a drag destination for @palette
+ * @flags: the flags that specify what actions GTK+ should take for drops
+ * on that widget
+ * @targets: the #GtkToolPaletteDragTargets which the widget
+ * should support
+ * @actions: the #GdkDragAction<!-- -->s which the widget should suppport
+ *
+ * Sets @palette as drag source (see gtk_tool_palette_set_drag_source())
+ * and sets @widget as a drag destination for drags from @palette.
* See gtk_drag_dest_set().
*
- * Since: 2.18
+ * Since: 2.20
*/
void
gtk_tool_palette_add_drag_dest (GtkToolPalette *palette,
max_rows = 0;
/* iterate over all groups and calculate the max item_size and max row request */
- for (i = 0; i < palette->priv->groups_length; ++i)
+ for (i = 0; i < palette->priv->groups->len; ++i)
{
GtkRequisition requisition;
gint rows;
- GtkToolItemGroupInfo *group = &palette->priv->groups[i];
+ GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
if (!group->widget)
continue;
static void
gtk_tool_palette_item_drag_data_get (GtkWidget *widget,
- GdkDragContext *context G_GNUC_UNUSED,
+ GdkDragContext *context,
GtkSelectionData *selection,
- guint info G_GNUC_UNUSED,
- guint time G_GNUC_UNUSED,
+ guint info,
+ guint time,
gpointer data)
{
GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
+ GdkAtom target;
- if (selection->target == dnd_target_atom_item)
+ target = gtk_selection_data_get_target (selection);
+
+ if (target == dnd_target_atom_item)
drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
if (drag_data.item)
- gtk_selection_data_set (selection, selection->target, 8,
+ gtk_selection_data_set (selection, target, 8,
(guchar*) &drag_data, sizeof (drag_data));
}
static void
gtk_tool_palette_child_drag_data_get (GtkWidget *widget,
- GdkDragContext *context G_GNUC_UNUSED,
+ GdkDragContext *context,
GtkSelectionData *selection,
- guint info G_GNUC_UNUSED,
- guint time G_GNUC_UNUSED,
+ guint info,
+ guint time,
gpointer data)
{
GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
+ GdkAtom target;
+
+ target = gtk_selection_data_get_target (selection);
- if (selection->target == dnd_target_atom_group)
+ if (target == dnd_target_atom_group)
drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM_GROUP);
if (drag_data.item)
- gtk_selection_data_set (selection, selection->target, 8,
+ gtk_selection_data_set (selection, target, 8,
(guchar*) &drag_data, sizeof (drag_data));
}
G_CALLBACK (gtk_tool_palette_item_drag_data_get),
palette);
}
- else if (GTK_IS_BUTTON (child) &&
+ else if (GTK_IS_BUTTON (child) &&
(palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_GROUPS))
{
gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
/**
* gtk_tool_palette_get_drag_target_item:
*
- * Get the target entry for a dragged #GtkToolItem.
+ * Gets the target entry for a dragged #GtkToolItem.
*
- * Returns: the #GtkTargetEntry for a dragged item.
+ * Returns: (transfer none): the #GtkTargetEntry for a dragged item.
*
- * Since: 2.18
+ * Since: 2.20
*/
-G_CONST_RETURN GtkTargetEntry*
+const GtkTargetEntry*
gtk_tool_palette_get_drag_target_item (void)
{
return &dnd_targets[0];
*
* Get the target entry for a dragged #GtkToolItemGroup.
*
- * Returns: the #GtkTargetEntry for a dragged group.
+ * Returns: (transfer none): the #GtkTargetEntry for a dragged group
*
- * Since: 2.18
+ * Since: 2.20
*/
-G_CONST_RETURN GtkTargetEntry*
+const GtkTargetEntry*
gtk_tool_palette_get_drag_target_group (void)
{
return &dnd_targets[1];
palette->priv->expanding_child = widget;
}
+/**
+ * gtk_tool_palette_get_hadjustment:
+ * @palette: a #GtkToolPalette
+ *
+ * Gets the horizontal adjustment of the tool palette.
+ *
+ * Returns: (transfer none): the horizontal adjustment of @palette
+ *
+ * Since: 2.20
+ *
+ * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment()
+ */
GtkAdjustment*
gtk_tool_palette_get_hadjustment (GtkToolPalette *palette)
{
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
+
return palette->priv->hadjustment;
}
+static void
+gtk_tool_palette_set_hadjustment (GtkToolPalette *palette,
+ GtkAdjustment *adjustment)
+{
+ GtkToolPalettePrivate *priv = palette->priv;
+
+ if (adjustment && priv->hadjustment == adjustment)
+ return;
+
+ if (priv->hadjustment != NULL)
+ {
+ g_signal_handlers_disconnect_by_func (priv->hadjustment,
+ gtk_tool_palette_adjustment_value_changed,
+ palette);
+ g_object_unref (priv->hadjustment);
+ }
+
+ if (adjustment == NULL)
+ adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0);
+
+ g_signal_connect (adjustment, "value-changed",
+ G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
+ palette);
+ priv->hadjustment = g_object_ref_sink (adjustment);
+ /* FIXME: Adjustment should probably have its values updated now */
+ g_object_notify (G_OBJECT (palette), "hadjustment");
+}
+
+/**
+ * gtk_tool_palette_get_vadjustment:
+ * @palette: a #GtkToolPalette
+ *
+ * Gets the vertical adjustment of the tool palette.
+ *
+ * Returns: (transfer none): the vertical adjustment of @palette
+ *
+ * Since: 2.20
+ *
+ * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment()
+ */
GtkAdjustment*
gtk_tool_palette_get_vadjustment (GtkToolPalette *palette)
{
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
+
return palette->priv->vadjustment;
}
+static void
+gtk_tool_palette_set_vadjustment (GtkToolPalette *palette,
+ GtkAdjustment *adjustment)
+{
+ GtkToolPalettePrivate *priv = palette->priv;
+
+ if (adjustment && priv->vadjustment == adjustment)
+ return;
+
+ if (priv->vadjustment != NULL)
+ {
+ g_signal_handlers_disconnect_by_func (priv->vadjustment,
+ gtk_tool_palette_adjustment_value_changed,
+ palette);
+ g_object_unref (priv->vadjustment);
+ }
+
+ if (adjustment == NULL)
+ adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0);
+
+ g_signal_connect (adjustment, "value-changed",
+ G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
+ palette);
+ priv->vadjustment = g_object_ref_sink (adjustment);
+ /* FIXME: Adjustment should probably have its values updated now */
+ g_object_notify (G_OBJECT (palette), "vadjustment");
+}
+
GtkSizeGroup *
_gtk_tool_palette_get_size_group (GtkToolPalette *palette)
{