app: add GimpToolItem; derive GimpToolInfo from it

Add GimpToolItem as a common base class for toolbox items.
Derive GimpToolInfo from GimpToolItem, representing an individual
tool.  The next commits add support for tool groups, represented by
an alternative subclass of GimpToolItem.

Most of the tool-info properties remain in GimpToolInfo, however,
GimpToolItem takes care of tool-item visibility.
This commit is contained in:
Ell
2020-01-29 19:33:14 +02:00
parent 7c4c475597
commit b3583041ac
10 changed files with 283 additions and 93 deletions

View File

@ -28,6 +28,7 @@
#include "core/gimpcontext.h"
#include "core/gimplist.h"
#include "core/gimptoolinfo.h"
#include "core/gimptoolpreset.h"
#include "widgets/gimpactiongroup.h"
#include "widgets/gimphelp-ids.h"

View File

@ -459,6 +459,8 @@ libappcore_a_sources = \
gimptilehandlerprojectable.h \
gimptoolinfo.c \
gimptoolinfo.h \
gimptoolitem.c \
gimptoolitem.h \
gimptooloptions.c \
gimptooloptions.h \
gimptoolpreset.c \

View File

@ -120,6 +120,7 @@ typedef struct _GimpToolOptions GimpToolOptions;
typedef struct _GimpPaintInfo GimpPaintInfo;
typedef struct _GimpToolInfo GimpToolInfo;
typedef struct _GimpToolItem GimpToolItem;
/* data objects */

View File

@ -23,7 +23,6 @@
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#include "core-types.h"
@ -35,31 +34,15 @@
#include "gimptooloptions.h"
#include "gimptoolpreset.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_VISIBLE
};
static void gimp_tool_info_dispose (GObject *object);
static void gimp_tool_info_finalize (GObject *object);
static void gimp_tool_info_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_tool_info_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gchar * gimp_tool_info_get_description (GimpViewable *viewable,
gchar **tooltip);
G_DEFINE_TYPE (GimpToolInfo, gimp_tool_info, GIMP_TYPE_VIEWABLE)
G_DEFINE_TYPE (GimpToolInfo, gimp_tool_info, GIMP_TYPE_TOOL_ITEM)
#define parent_class gimp_tool_info_parent_class
@ -72,17 +55,8 @@ gimp_tool_info_class_init (GimpToolInfoClass *klass)
object_class->dispose = gimp_tool_info_dispose;
object_class->finalize = gimp_tool_info_finalize;
object_class->get_property = gimp_tool_info_get_property;
object_class->set_property = gimp_tool_info_set_property;
viewable_class->get_description = gimp_tool_info_get_description;
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_VISIBLE,
"visible",
_("Visible"),
NULL,
TRUE,
GIMP_PARAM_STATIC_STRINGS);
}
static void
@ -121,44 +95,6 @@ gimp_tool_info_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_tool_info_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpToolInfo *tool_info = GIMP_TOOL_INFO (object);
switch (property_id)
{
case PROP_VISIBLE:
g_value_set_boolean (value, tool_info->visible);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_tool_info_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpToolInfo *tool_info = GIMP_TOOL_INFO (object);
switch (property_id)
{
case PROP_VISIBLE:
tool_info->visible = (g_value_get_boolean (value) && ! tool_info->hidden);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gchar *
gimp_tool_info_get_description (GimpViewable *viewable,
gchar **tooltip)

View File

@ -19,7 +19,7 @@
#define __GIMP_TOOL_INFO_H__
#include "gimpdata.h"
#include "gimptoolitem.h"
#define GIMP_TYPE_TOOL_INFO (gimp_tool_info_get_type ())
@ -34,7 +34,7 @@ typedef struct _GimpToolInfoClass GimpToolInfoClass;
struct _GimpToolInfo
{
GimpViewable parent_instance;
GimpToolItem parent_instance;
Gimp *gimp;
@ -51,8 +51,8 @@ struct _GimpToolInfo
gchar *help_domain;
gchar *help_id;
gboolean hidden; /* can't be made visible */
gboolean visible;
gboolean hidden;
GimpToolOptions *tool_options;
GimpPaintInfo *paint_info;
@ -61,32 +61,32 @@ struct _GimpToolInfo
struct _GimpToolInfoClass
{
GimpViewableClass parent_class;
GimpToolItemClass parent_class;
};
GType gimp_tool_info_get_type (void) G_GNUC_CONST;
GType gimp_tool_info_get_type (void) G_GNUC_CONST;
GimpToolInfo * gimp_tool_info_new (Gimp *gimp,
GType tool_type,
GType tool_options_type,
GimpContextPropMask context_props,
const gchar *identifier,
const gchar *label,
const gchar *tooltip,
const gchar *menu_label,
const gchar *menu_accel,
const gchar *help_domain,
const gchar *help_id,
const gchar *paint_core_name,
const gchar *icon_name);
GimpToolInfo * gimp_tool_info_new (Gimp *gimp,
GType tool_type,
GType tool_options_type,
GimpContextPropMask context_props,
const gchar *identifier,
const gchar *label,
const gchar *tooltip,
const gchar *menu_label,
const gchar *menu_accel,
const gchar *help_domain,
const gchar *help_id,
const gchar *paint_core_name,
const gchar *icon_name);
void gimp_tool_info_set_standard (Gimp *gimp,
GimpToolInfo *tool_info);
GimpToolInfo * gimp_tool_info_get_standard (Gimp *gimp);
void gimp_tool_info_set_standard (Gimp *gimp,
GimpToolInfo *tool_info);
GimpToolInfo * gimp_tool_info_get_standard (Gimp *gimp);
GFile * gimp_tool_info_get_options_file (GimpToolInfo *tool_info,
const gchar *suffix);
GFile * gimp_tool_info_get_options_file (GimpToolInfo *tool_info,
const gchar *suffix);
#endif /* __GIMP_TOOL_INFO_H__ */

186
app/core/gimptoolitem.c Normal file
View File

@ -0,0 +1,186 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimptoolitem.c
* Copyright (C) 2020 Ell
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#include "core-types.h"
#include "core/gimpmarshal.h"
#include "gimptoolitem.h"
enum
{
VISIBLE_CHANGED,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_VISIBLE
};
struct _GimpToolItemPrivate
{
gboolean visible;
};
/* local function prototypes */
static void gimp_tool_item_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_tool_item_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE_WITH_PRIVATE (GimpToolItem, gimp_tool_item, GIMP_TYPE_VIEWABLE)
#define parent_class gimp_tool_item_parent_class
static guint gimp_tool_item_signals[LAST_SIGNAL] = { 0 };
/* private functions */
static void
gimp_tool_item_class_init (GimpToolItemClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
gimp_tool_item_signals[VISIBLE_CHANGED] =
g_signal_new ("visible-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpToolItemClass, visible_changed),
NULL, NULL,
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->get_property = gimp_tool_item_get_property;
object_class->set_property = gimp_tool_item_set_property;
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_VISIBLE,
"visible", NULL, NULL,
TRUE,
GIMP_PARAM_STATIC_STRINGS);
}
static void
gimp_tool_item_init (GimpToolItem *tool_item)
{
tool_item->priv = gimp_tool_item_get_instance_private (tool_item);
}
static void
gimp_tool_item_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpToolItem *tool_item = GIMP_TOOL_ITEM (object);
switch (property_id)
{
case PROP_VISIBLE:
g_value_set_boolean (value, tool_item->priv->visible);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_tool_item_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpToolItem *tool_item = GIMP_TOOL_ITEM (object);
switch (property_id)
{
case PROP_VISIBLE:
gimp_tool_item_set_visible (tool_item, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/* public functions */
void
gimp_tool_item_set_visible (GimpToolItem *tool_item,
gboolean visible)
{
g_return_if_fail (GIMP_IS_TOOL_ITEM (tool_item));
if (visible != tool_item->priv->visible)
{
tool_item->priv->visible = visible;
g_signal_emit (tool_item, gimp_tool_item_signals[VISIBLE_CHANGED], 0);
g_object_notify (G_OBJECT (tool_item), "visible");
}
}
gboolean
gimp_tool_item_get_visible (GimpToolItem *tool_item)
{
g_return_val_if_fail (GIMP_IS_TOOL_ITEM (tool_item), FALSE);
return tool_item->priv->visible;
}
gboolean
gimp_tool_item_is_visible (GimpToolItem *tool_item)
{
GimpToolItem *parent;
g_return_val_if_fail (GIMP_IS_TOOL_ITEM (tool_item), FALSE);
parent = GIMP_TOOL_ITEM (
gimp_viewable_get_parent (GIMP_VIEWABLE (tool_item)));
return tool_item->priv->visible &&
(! parent || gimp_tool_item_is_visible (parent));
}

63
app/core/gimptoolitem.h Normal file
View File

@ -0,0 +1,63 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimptoolitem.h
* Copyright (C) 2020 Ell
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_TOOL_ITEM_H__
#define __GIMP_TOOL_ITEM_H__
#include "gimpviewable.h"
#define GIMP_TYPE_TOOL_ITEM (gimp_tool_item_get_type ())
#define GIMP_TOOL_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TOOL_ITEM, GimpToolItem))
#define GIMP_TOOL_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TOOL_ITEM, GimpToolItemClass))
#define GIMP_IS_TOOL_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TOOL_ITEM))
#define GIMP_IS_TOOL_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_TOOL_ITEM))
#define GIMP_TOOL_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_TOOL_ITEM, GimpToolItemClass))
typedef struct _GimpToolItemPrivate GimpToolItemPrivate;
typedef struct _GimpToolItemClass GimpToolItemClass;
struct _GimpToolItem
{
GimpViewable parent_instance;
GimpToolItemPrivate *priv;
};
struct _GimpToolItemClass
{
GimpViewableClass parent_class;
/* signals */
void (* visible_changed) (GimpToolItem *tool_item);
};
GType gimp_tool_item_get_type (void) G_GNUC_CONST;
void gimp_tool_item_set_visible (GimpToolItem *tool_item,
gboolean visible);
gboolean gimp_tool_item_get_visible (GimpToolItem *tool_item);
gboolean gimp_tool_item_is_visible (GimpToolItem *tool_item);
#endif /* __GIMP_TOOL_ITEM_H__ */

View File

@ -288,6 +288,8 @@ gimp_tools_restore (Gimp *gimp)
if (object)
{
GimpToolItem *tool_item = list->data;
while (! gimp_container_get_child_by_name (
gimp_list,
gimp_object_get_name (
@ -298,7 +300,7 @@ gimp_tools_restore (Gimp *gimp)
}
g_object_set (object,
"visible", GIMP_TOOL_INFO (list->data)->visible,
"visible", gimp_tool_item_is_visible (tool_item),
NULL);
gimp_container_reorder (gimp->tool_info_list,

View File

@ -170,7 +170,7 @@ gimp_tool_palette_size_allocate (GtkWidget *widget,
{
GimpToolInfo *tool_info = list->data;
if (tool_info->visible)
if (gimp_tool_item_get_visible (GIMP_TOOL_ITEM (tool_info)))
n_tools++;
}

View File

@ -194,7 +194,6 @@ app/core/gimpsymmetry-mirror.c
app/core/gimpsymmetry-tiling.c
app/core/gimptagcache.c
app/core/gimptemplate.c
app/core/gimptoolinfo.c
app/core/gimptooloptions.c
app/core/gimptoolpreset.c
app/core/gimptoolpreset-load.c