From 7160379d24194aff10fb59a6fcee5239abebf9e6 Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Fri, 7 Dec 2012 13:42:17 +0000 Subject: Use a toolpalette that demands enough space GtkToolPalette will not request a minimum amount of space by default. Steal some code from the GIMP to always ensure we have enough space for the tools. --- tikzit/src/Makefile.am | 1 + tikzit/src/gtk/ToolBox.m | 4 +- tikzit/src/gtk/tztoolpalette.h | 52 ++++++++++++++++++ tikzit/src/gtk/tztoolpalette.m | 121 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 tikzit/src/gtk/tztoolpalette.h create mode 100644 tikzit/src/gtk/tztoolpalette.m diff --git a/tikzit/src/Makefile.am b/tikzit/src/Makefile.am index 8d51c60..e997409 100644 --- a/tikzit/src/Makefile.am +++ b/tikzit/src/Makefile.am @@ -70,6 +70,7 @@ tikzit_SOURCES = gtk/Application.m \ gtk/mkdtemp.m \ gtk/main.m \ gtk/tzstockitems.m \ + gtk/tztoolpalette.m \ common/CircleShape.m \ common/ColorRGB.m \ common/DiamondShape.m \ diff --git a/tikzit/src/gtk/ToolBox.m b/tikzit/src/gtk/ToolBox.m index c9cdd0b..9e4fa3b 100644 --- a/tikzit/src/gtk/ToolBox.m +++ b/tikzit/src/gtk/ToolBox.m @@ -21,6 +21,8 @@ #import "Configuration.h" #import "Tool.h" +#import "tztoolpalette.h" + static void tool_button_toggled_cb (GtkWidget *widget, ToolBox *toolBox); static void unretain (gpointer data); @@ -51,7 +53,7 @@ static void unretain (gpointer data); gtk_widget_show (mainLayout); gtk_container_add (GTK_CONTAINER (window), mainLayout); - GtkWidget *toolPalette = gtk_tool_palette_new (); + GtkWidget *toolPalette = tz_tool_palette_new (); gtk_widget_show (toolPalette); gtk_box_pack_start (GTK_BOX (mainLayout), toolPalette, diff --git a/tikzit/src/gtk/tztoolpalette.h b/tikzit/src/gtk/tztoolpalette.h new file mode 100644 index 0000000..70a4156 --- /dev/null +++ b/tikzit/src/gtk/tztoolpalette.h @@ -0,0 +1,52 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * tztoolpalette.h, based on gimptoolpalette.h + * Copyright (C) 2010 Michael Natterer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __TZ_TOOL_PALETTE_H__ +#define __TZ_TOOL_PALETTE_H__ + + +#define TZ_TYPE_TOOL_PALETTE (tz_tool_palette_get_type ()) +#define TZ_TOOL_PALETTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TZ_TYPE_TOOL_PALETTE, TzToolPalette)) +#define TZ_TOOL_PALETTE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TZ_TYPE_TOOL_PALETTE, TzToolPaletteClass)) +#define TZ_IS_TOOL_PALETTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TZ_TYPE_TOOL_PALETTE)) +#define TZ_IS_TOOL_PALETTE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TZ_TYPE_TOOL_PALETTE)) +#define TZ_TOOL_PALETTE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TZ_TYPE_TOOL_PALETTE, TzToolPaletteClass)) + + +typedef struct _TzToolPaletteClass TzToolPaletteClass; +typedef struct _TzToolPalette TzToolPalette; + +struct _TzToolPalette +{ + GtkToolPalette parent_instance; +}; + +struct _TzToolPaletteClass +{ + GtkToolPaletteClass parent_class; +}; + + +GType tz_tool_palette_get_type (void) G_GNUC_CONST; + +GtkWidget * tz_tool_palette_new (void); + + +#endif /* __TZ_TOOL_PALETTE_H__ */ diff --git a/tikzit/src/gtk/tztoolpalette.m b/tikzit/src/gtk/tztoolpalette.m new file mode 100644 index 0000000..1a6ab9a --- /dev/null +++ b/tikzit/src/gtk/tztoolpalette.m @@ -0,0 +1,121 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * tztoolpalette.c, based on gimptoolpalette.c + * Copyright (C) 2010 Michael Natterer + * Copyright (C) 2012 Alex Merry + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "tztoolpalette.h" + + +#define DEFAULT_TOOL_ICON_SIZE GTK_ICON_SIZE_BUTTON +#define DEFAULT_BUTTON_RELIEF GTK_RELIEF_NONE + +#define TOOL_BUTTON_DATA_KEY "tz-tool-palette-item" +#define TOOL_INFO_DATA_KEY "tz-tool-info" + + +typedef struct _TzToolPalettePrivate TzToolPalettePrivate; + +struct _TzToolPalettePrivate +{ + gint tool_rows; + gint tool_columns; +}; + +#define GET_PRIVATE(p) G_TYPE_INSTANCE_GET_PRIVATE (p, \ + TZ_TYPE_TOOL_PALETTE, \ + TzToolPalettePrivate) + + +static void tz_tool_palette_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); + + +G_DEFINE_TYPE (TzToolPalette, tz_tool_palette, GTK_TYPE_TOOL_PALETTE) + +#define parent_class tz_tool_palette_parent_class + + +static void +tz_tool_palette_class_init (TzToolPaletteClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + widget_class->size_allocate = tz_tool_palette_size_allocate; + + g_type_class_add_private (klass, sizeof (TzToolPalettePrivate)); +} + +static void +tz_tool_palette_init (TzToolPalette *palette) +{ +} + +static void +tz_tool_palette_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + TzToolPalettePrivate *private = GET_PRIVATE (widget); + GList *children; + GtkToolItemGroup *group; + + GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation); + + children = gtk_container_get_children (GTK_CONTAINER (widget)); + g_return_if_fail (children); + group = GTK_TOOL_ITEM_GROUP (children->data); + g_list_free (children); + + guint tool_count = gtk_tool_item_group_get_n_items (group); + if (tool_count > 0) + { + GtkWidget *tool_button; + GtkRequisition button_requisition; + gint tool_rows; + gint tool_columns; + + tool_button = GTK_WIDGET (gtk_tool_item_group_get_nth_item (group, 0)); + gtk_widget_size_request (tool_button, &button_requisition); + + tool_columns = MAX (1, (allocation->width / button_requisition.width)); + tool_rows = tool_count / tool_columns; + + if (tool_count % tool_columns) + tool_rows++; + + if (private->tool_rows != tool_rows || + private->tool_columns != tool_columns) + { + private->tool_rows = tool_rows; + private->tool_columns = tool_columns; + + gtk_widget_set_size_request (widget, -1, + tool_rows * button_requisition.height); + } + } +} + +GtkWidget * +tz_tool_palette_new (void) +{ + return g_object_new (TZ_TYPE_TOOL_PALETTE, NULL); +} + +// vim:ft=objc:ts=8:et:sts=2:sw=2:foldmethod=marker -- cgit v1.2.3