mirror of https://github.com/GNOME/gimp.git
app: factor out duplicated code to gimp_tool_palette_get_button_size()
and use that function in GimpToolPalette and GimpToolbox.
This commit is contained in:
parent
281969b45d
commit
e4a96c738e
|
@ -57,8 +57,6 @@
|
|||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
#define TOOL_BUTTON_DATA_KEY "gimp-tool-palette-item"
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
|
@ -650,38 +648,27 @@ static void
|
|||
gimp_toolbox_set_host_geometry_hints (GimpDock *dock,
|
||||
GtkWindow *window)
|
||||
{
|
||||
GimpToolbox *toolbox = GIMP_TOOLBOX (dock);
|
||||
Gimp *gimp;
|
||||
GimpToolInfo *tool_info;
|
||||
GtkWidget *tool_button;
|
||||
GimpToolbox *toolbox = GIMP_TOOLBOX (dock);
|
||||
gint button_width;
|
||||
gint button_height;
|
||||
|
||||
gimp = gimp_toolbox_get_context (toolbox)->gimp;
|
||||
|
||||
tool_info = gimp_get_tool_info (gimp, "gimp-rect-select-tool");
|
||||
tool_button = g_object_get_data (G_OBJECT (tool_info), TOOL_BUTTON_DATA_KEY);
|
||||
|
||||
if (tool_button)
|
||||
if (gimp_tool_palette_get_button_size (GIMP_TOOL_PALETTE (toolbox->p->tool_palette),
|
||||
&button_width, &button_height))
|
||||
{
|
||||
GtkWidget *main_vbox = gimp_dock_get_main_vbox (GIMP_DOCK (toolbox));
|
||||
GtkRequisition button_requisition;
|
||||
gint border_width;
|
||||
GdkGeometry geometry;
|
||||
|
||||
gtk_widget_size_request (tool_button, &button_requisition);
|
||||
GtkWidget *main_vbox = gimp_dock_get_main_vbox (GIMP_DOCK (toolbox));
|
||||
gint border_width;
|
||||
GdkGeometry geometry;
|
||||
|
||||
gtk_widget_set_size_request (toolbox->p->header,
|
||||
-1,
|
||||
button_requisition.height *
|
||||
PANGO_SCALE_SMALL);
|
||||
-1, button_height * PANGO_SCALE_SMALL);
|
||||
|
||||
border_width = gtk_container_get_border_width (GTK_CONTAINER (main_vbox));
|
||||
|
||||
geometry.min_width = (2 * border_width +
|
||||
2 * button_requisition.width);
|
||||
geometry.min_width = (2 * border_width + 2 * button_width);
|
||||
geometry.min_height = -1;
|
||||
geometry.width_inc = button_requisition.width;
|
||||
geometry.width_inc = button_width;
|
||||
geometry.height_inc = (gimp_dock_get_dockbooks (GIMP_DOCK (toolbox)) ?
|
||||
1 : button_requisition.height);
|
||||
1 : button_height);
|
||||
|
||||
gtk_window_set_geometry_hints (window,
|
||||
NULL,
|
||||
|
|
|
@ -344,38 +344,31 @@ gimp_tool_palette_size_allocate (GtkWidget *widget,
|
|||
GtkAllocation *allocation)
|
||||
{
|
||||
GimpToolPalettePrivate *private = GET_PRIVATE (widget);
|
||||
Gimp *gimp;
|
||||
GimpToolInfo *tool_info;
|
||||
GtkWidget *tool_button;
|
||||
gint button_width;
|
||||
gint button_height;
|
||||
|
||||
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
|
||||
|
||||
gimp = private->context->gimp;
|
||||
|
||||
tool_info = gimp_get_tool_info (gimp, "gimp-rect-select-tool");
|
||||
tool_button = g_object_get_data (G_OBJECT (tool_info), TOOL_BUTTON_DATA_KEY);
|
||||
|
||||
if (tool_button)
|
||||
if (gimp_tool_palette_get_button_size (GIMP_TOOL_PALETTE (widget),
|
||||
&button_width, &button_height))
|
||||
{
|
||||
GtkRequisition button_requisition;
|
||||
GList *list;
|
||||
gint n_tools;
|
||||
gint tool_rows;
|
||||
gint tool_columns;
|
||||
|
||||
gtk_widget_size_request (tool_button, &button_requisition);
|
||||
Gimp *gimp = private->context->gimp;
|
||||
GList *list;
|
||||
gint n_tools;
|
||||
gint tool_rows;
|
||||
gint tool_columns;
|
||||
|
||||
for (list = gimp_get_tool_info_iter (gimp), n_tools = 0;
|
||||
list;
|
||||
list = list->next)
|
||||
{
|
||||
tool_info = list->data;
|
||||
GimpToolInfo *tool_info = list->data;
|
||||
|
||||
if (tool_info->visible)
|
||||
n_tools++;
|
||||
}
|
||||
|
||||
tool_columns = MAX (1, (allocation->width / button_requisition.width));
|
||||
tool_columns = MAX (1, (allocation->width / button_width));
|
||||
tool_rows = n_tools / tool_columns;
|
||||
|
||||
if (n_tools % tool_columns)
|
||||
|
@ -388,7 +381,7 @@ gimp_tool_palette_size_allocate (GtkWidget *widget,
|
|||
private->tool_columns = tool_columns;
|
||||
|
||||
gtk_widget_set_size_request (widget, -1,
|
||||
tool_rows * button_requisition.height);
|
||||
tool_rows * button_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -448,6 +441,40 @@ gimp_tool_palette_new (GimpContext *context,
|
|||
NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_tool_palette_get_button_size (GimpToolPalette *palette,
|
||||
gint *width,
|
||||
gint *height)
|
||||
{
|
||||
GimpToolPalettePrivate *private;
|
||||
GimpToolInfo *tool_info;
|
||||
GtkWidget *tool_button;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_TOOL_PALETTE (palette), FALSE);
|
||||
g_return_val_if_fail (width != NULL, FALSE);
|
||||
g_return_val_if_fail (height != NULL, FALSE);
|
||||
|
||||
private = GET_PRIVATE (palette);
|
||||
|
||||
tool_info = gimp_get_tool_info (private->context->gimp,
|
||||
"gimp-rect-select-tool");
|
||||
tool_button = g_object_get_data (G_OBJECT (tool_info), TOOL_BUTTON_DATA_KEY);
|
||||
|
||||
if (tool_button)
|
||||
{
|
||||
GtkRequisition button_requisition;
|
||||
|
||||
gtk_widget_size_request (tool_button, &button_requisition);
|
||||
|
||||
*width = button_requisition.width;
|
||||
*height = button_requisition.height;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
|
|
|
@ -43,11 +43,14 @@ struct _GimpToolPaletteClass
|
|||
};
|
||||
|
||||
|
||||
GType gimp_tool_palette_get_type (void) G_GNUC_CONST;
|
||||
GType gimp_tool_palette_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget * gimp_tool_palette_new (GimpContext *context,
|
||||
GimpUIManager *ui_manager,
|
||||
GimpDialogFactory *dialog_factory);
|
||||
GtkWidget * gimp_tool_palette_new (GimpContext *context,
|
||||
GimpUIManager *ui_manager,
|
||||
GimpDialogFactory *dialog_factory);
|
||||
gboolean gimp_tool_palette_get_button_size (GimpToolPalette *palette,
|
||||
gint *width,
|
||||
gint *height);
|
||||
|
||||
|
||||
#endif /* __GIMP_TOOL_PALETTE_H__ */
|
||||
|
|
Loading…
Reference in New Issue