Commit 42312eca authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added new virtual function GimpDocked::get_title() which returns a custom

2003-10-21  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpdocked.[ch]: added new virtual function
	GimpDocked::get_title() which returns a custom title. Added signal
	"title_changed". Added public wrappers around the new stuff.

	* app/widgets/gimpdockable.c: implement GtkContainer::add() and
	::remove() and connect to the child's "title_changed" signal. Use
	the GimpDocked's title if it provides one.

	* app/widgets/gimptooloptionseditor.c: implement
	GimpDocked::get_title() and return e.g. "Paintbrush Options". Emit
	"title_changed" when the active tool changes. Simplified
	GimpDocked::get_preview()'s implementation a lot since it does not
	include a label any more.
parent f142ca8e
2003-10-21 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpdocked.[ch]: added new virtual function
GimpDocked::get_title() which returns a custom title. Added signal
"title_changed". Added public wrappers around the new stuff.
* app/widgets/gimpdockable.c: implement GtkContainer::add() and
::remove() and connect to the child's "title_changed" signal. Use
the GimpDocked's title if it provides one.
* app/widgets/gimptooloptionseditor.c: implement
GimpDocked::get_title() and return e.g. "Paintbrush Options". Emit
"title_changed" when the active tool changes. Simplified
GimpDocked::get_preview()'s implementation a lot since it does not
include a label any more.
2003-10-21 Sven Neumann <sven@gimp.org>
* app/tools/gimpcoloroptions.c: changed the default value for
......@@ -65,6 +65,10 @@ static gboolean gimp_dockable_expose_event (GtkWidget *widget,
GdkEventExpose *event);
static gboolean gimp_dockable_popup_menu (GtkWidget *widget);
static void gimp_dockable_add (GtkContainer *container,
GtkWidget *widget);
static void gimp_dockable_remove (GtkContainer *container,
GtkWidget *widget);
static GType gimp_dockable_child_type (GtkContainer *container);
static void gimp_dockable_forall (GtkContainer *container,
gboolean include_internals,
......@@ -81,6 +85,9 @@ static void gimp_dockable_close_clicked (GtkWidget *button,
GimpDockable *dockable);
static gboolean gimp_dockable_show_menu (GimpDockable *dockable);
static void gimp_dockable_title_changed (GimpDocked *docked,
GimpDockable *dockable);
static GtkBinClass *parent_class = NULL;
......@@ -144,6 +151,8 @@ gimp_dockable_class_init (GimpDockableClass *klass)
widget_class->expose_event = gimp_dockable_expose_event;
widget_class->popup_menu = gimp_dockable_popup_menu;
container_class->add = gimp_dockable_add;
container_class->remove = gimp_dockable_remove;
container_class->child_type = gimp_dockable_child_type;
container_class->forall = gimp_dockable_forall;
......@@ -515,10 +524,21 @@ gimp_dockable_expose_event (GtkWidget *widget,
gint text_x;
gint text_y;
if (!dockable->title_layout)
if (! dockable->title_layout)
{
dockable->title_layout =
gtk_widget_create_pango_layout (widget, dockable->blurb);
GtkBin *bin = GTK_BIN (dockable);
gchar *title = NULL;
if (bin->child)
title = gimp_docked_get_title (GIMP_DOCKED (bin->child));
if (! title)
title = g_strdup (dockable->blurb);
dockable->title_layout = gtk_widget_create_pango_layout (widget,
title);
g_free (title);
}
pango_layout_get_pixel_size (dockable->title_layout,
......@@ -551,6 +571,32 @@ gimp_dockable_popup_menu (GtkWidget *widget)
return gimp_dockable_show_menu (GIMP_DOCKABLE (widget));
}
static void
gimp_dockable_add (GtkContainer *container,
GtkWidget *widget)
{
g_return_if_fail (GTK_BIN (container)->child == NULL);
GTK_CONTAINER_CLASS (parent_class)->add (container, widget);
g_signal_connect (widget, "title_changed",
G_CALLBACK (gimp_dockable_title_changed),
container);
}
static void
gimp_dockable_remove (GtkContainer *container,
GtkWidget *widget)
{
g_return_if_fail (GTK_BIN (container)->child == widget);
g_signal_handlers_disconnect_by_func (widget,
gimp_dockable_title_changed,
container);
GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
}
static GType
gimp_dockable_child_type (GtkContainer *container)
{
......@@ -908,3 +954,24 @@ gimp_dockable_show_menu (GimpDockable *dockable)
return TRUE;
}
static void
gimp_dockable_title_changed (GimpDocked *docked,
GimpDockable *dockable)
{
if (dockable->title_layout)
{
g_object_unref (dockable->title_layout);
dockable->title_layout = NULL;
}
if (GTK_WIDGET (dockable)->window)
{
GdkRectangle title_area;
gimp_dockable_get_title_area (dockable, &title_area);
gdk_window_invalidate_rect (GTK_WIDGET (dockable)->window,
&title_area, FALSE);
}
}
......@@ -26,13 +26,24 @@
#include "widgets-types.h"
#include "core/gimpcontext.h"
#include "core/gimpmarshal.h"
#include "gimpdocked.h"
enum
{
TITLE_CHANGED,
LAST_SIGNAL
};
static void gimp_docked_iface_base_init (GimpDockedInterface *docked_iface);
static guint docked_signals[LAST_SIGNAL] = { 0 };
GType
gimp_docked_interface_get_type (void)
{
......@@ -61,6 +72,29 @@ gimp_docked_interface_get_type (void)
static void
gimp_docked_iface_base_init (GimpDockedInterface *docked_iface)
{
static gboolean initialized = FALSE;
if (! initialized)
{
docked_signals[TITLE_CHANGED] =
g_signal_new ("title_changed",
GIMP_TYPE_DOCKED,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpDockedInterface, title_changed),
NULL, NULL,
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
initialized = TRUE;
}
}
void
gimp_docked_title_changed (GimpDocked *docked)
{
g_return_if_fail (GIMP_IS_DOCKED (docked));
g_signal_emit (docked, docked_signals[TITLE_CHANGED], 0);
}
void
......@@ -109,23 +143,6 @@ gimp_docked_get_preview (GimpDocked *docked,
return NULL;
}
void
gimp_docked_set_context (GimpDocked *docked,
GimpContext *context,
GimpContext *prev_context)
{
GimpDockedInterface *docked_iface;
g_return_if_fail (GIMP_IS_DOCKED (docked));
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
g_return_if_fail (prev_context == NULL || GIMP_IS_CONTEXT (prev_context));
docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
if (docked_iface->set_context)
docked_iface->set_context (docked, context, prev_context);
}
GimpItemFactory *
gimp_docked_get_menu (GimpDocked *docked,
gpointer *item_factory_data)
......@@ -157,3 +174,35 @@ gimp_docked_get_menu (GimpDocked *docked,
return NULL;
}
gchar *
gimp_docked_get_title (GimpDocked *docked)
{
GimpDockedInterface *docked_iface;
g_return_val_if_fail (GIMP_IS_DOCKED (docked), NULL);
docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
if (docked_iface->get_title)
return docked_iface->get_title (docked);
return NULL;
}
void
gimp_docked_set_context (GimpDocked *docked,
GimpContext *context,
GimpContext *prev_context)
{
GimpDockedInterface *docked_iface;
g_return_if_fail (GIMP_IS_DOCKED (docked));
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
g_return_if_fail (prev_context == NULL || GIMP_IS_CONTEXT (prev_context));
docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
if (docked_iface->set_context)
docked_iface->set_context (docked, context, prev_context);
}
......@@ -33,23 +33,31 @@ struct _GimpDockedInterface
{
GTypeInterface base_iface;
void (* set_aux_info) (GimpDocked *docked,
GList *aux_info);
GList * (* get_aux_info) (GimpDocked *docked);
GtkWidget * (* get_preview) (GimpDocked *docked,
GimpContext *context,
GtkIconSize size);
void (* set_context) (GimpDocked *docked,
GimpContext *context,
GimpContext *prev_context);
GimpItemFactory * (* get_menu) (GimpDocked *docked,
gpointer *item_factory_data);
/* signals */
void (* title_changed) (GimpDocked *docked);
/* virtual functions */
void (* set_aux_info) (GimpDocked *docked,
GList *aux_info);
GList * (* get_aux_info) (GimpDocked *docked);
GtkWidget * (* get_preview) (GimpDocked *docked,
GimpContext *context,
GtkIconSize size);
GimpItemFactory * (* get_menu) (GimpDocked *docked,
gpointer *item_factory_data);
gchar * (* get_title) (GimpDocked *docked);
void (* set_context) (GimpDocked *docked,
GimpContext *context,
GimpContext *prev_context);
};
GType gimp_docked_interface_get_type (void) G_GNUC_CONST;
void gimp_docked_title_changed (GimpDocked *docked);
void gimp_docked_set_aux_info (GimpDocked *docked,
GList *aux_info);
GList * gimp_docked_get_aux_info (GimpDocked *docked);
......@@ -57,11 +65,13 @@ GList * gimp_docked_get_aux_info (GimpDocked *docked);
GtkWidget * gimp_docked_get_preview (GimpDocked *docked,
GimpContext *context,
GtkIconSize size);
GimpItemFactory * gimp_docked_get_menu (GimpDocked *docked,
gpointer *item_factory_data);
gchar * gimp_docked_get_title (GimpDocked *docked);
void gimp_docked_set_context (GimpDocked *docked,
GimpContext *context,
GimpContext *prev_context);
GimpItemFactory * gimp_docked_get_menu (GimpDocked *docked,
gpointer *item_factory_data);
#endif /* __GIMP_DOCKED_H__ */
......@@ -38,6 +38,9 @@
#include "gimphelp-ids.h"
#include "gimpitemfactory.h"
#include "gimpmenufactory.h"
#include "gimppreview.h"
#include "gimppreviewrenderer.h"
#include "gimppropwidgets.h"
#include "gimptooloptionseditor.h"
#include "gimpwidgets-utils.h"
......@@ -53,7 +56,7 @@ static void gimp_tool_options_editor_destroy (GtkObject *o
static GtkWidget *gimp_tool_options_editor_get_preview (GimpDocked *docked,
GimpContext *context,
GtkIconSize size);
static gchar *gimp_tool_options_editor_get_title (GimpDocked *docked);
static void gimp_tool_options_editor_save_clicked (GtkWidget *widget,
GimpToolOptionsEditor *editor);
......@@ -199,6 +202,7 @@ static void
gimp_tool_options_editor_docked_iface_init (GimpDockedInterface *docked_iface)
{
docked_iface->get_preview = gimp_tool_options_editor_get_preview;
docked_iface->get_title = gimp_tool_options_editor_get_title;
}
static void
......@@ -228,64 +232,37 @@ gimp_tool_options_editor_destroy (GtkObject *object)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
gimp_tool_options_preview_tool_changed (GimpContext *context,
GimpToolInfo *tool_info,
GtkLabel *label)
{
GtkImage *image;
if ((image = g_object_get_data (G_OBJECT (label), "tool-icon")))
{
const gchar *stock_id;
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
gtk_image_set_from_stock (image, stock_id, image->icon_size);
}
gtk_label_set_text (label, tool_info->blurb);
gimp_help_set_help_data (GTK_WIDGET (label)->parent->parent,
tool_info->help, tool_info->help_id);
}
static GtkWidget *
gimp_tool_options_editor_get_preview (GimpDocked *docked,
GimpContext *context,
GtkIconSize size)
{
GimpToolInfo *tool_info;
GtkWidget *hbox;
GtkWidget *image;
GtkWidget *label;
gint width;
gint height;
const gchar *stock_id;
GtkWidget *preview;
gint width;
gint height;
gtk_icon_size_lookup (size, &width, &height);
tool_info = gimp_context_get_tool (context);
hbox = gtk_hbox_new (FALSE, 2);
preview = gimp_prop_preview_new (G_OBJECT (context), "tool", height);
GIMP_PREVIEW (preview)->renderer->size = -1;
gimp_preview_renderer_set_size_full (GIMP_PREVIEW (preview)->renderer,
width, height, 0);
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
image = gtk_image_new_from_stock (stock_id, size);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
label = gtk_label_new (tool_info->blurb);
return preview;
}
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
static gchar *
gimp_tool_options_editor_get_title (GimpDocked *docked)
{
GimpToolOptionsEditor *editor = GIMP_TOOL_OPTIONS_EDITOR (docked);
GimpContext *context;
GimpToolInfo *tool_info;
g_object_set_data (G_OBJECT (label), "tool-icon", image);
context = gimp_get_user_context (editor->gimp);
g_signal_connect_object (context, "tool_changed",
G_CALLBACK (gimp_tool_options_preview_tool_changed),
label,
0);
tool_info = gimp_context_get_tool (context);
return hbox;
return g_strdup_printf (_("%s Options"), tool_info->blurb);
}
GtkWidget *
......@@ -524,6 +501,8 @@ gimp_tool_options_editor_tool_changed (GimpContext *context,
}
gimp_tool_options_editor_presets_changed (presets, NULL, editor);
gimp_docked_title_changed (GIMP_DOCKED (editor));
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment