massively changed: removed message_ids, the message mem chunk and all

2004-07-14  Michael Natterer  <mitch@gimp.org>

	* app/display/gimpstatusbar.[ch]: massively changed: removed
	message_ids, the message mem chunk and all signals. Added new
	function gimp_statusbar_replace() which updates a message without
	moving it to the top of the stack. Fixes bug #120175.

	* app/display/gimpdisplayshell-title.[ch]: renamed
	gimp_display_shell_update_title() to
	gimp_display_shell_title_update() and switched from pop()/push()
	to replace() so the title message keeps its place in the stack.
	Added new function gimp_display_shell_title_init() which push()es
	the title message to the stack.

	* app/display/gimpdisplayshell.c (gimp_display_shell_new): call
	gimp_display_shell_title_init() so the "title" message is at the
	bottom of the stack.

	* app/display/gimpdisplayshell-callbacks.c
	* app/display/gimpdisplayshell-handlers.c: changed accordingly.
This commit is contained in:
Michael Natterer
2004-07-14 16:37:13 +00:00
committed by Michael Natterer
parent 6d4d038f2d
commit 178d7d3ff1
8 changed files with 227 additions and 236 deletions

View File

@ -1,3 +1,24 @@
2004-07-14 Michael Natterer <mitch@gimp.org>
* app/display/gimpstatusbar.[ch]: massively changed: removed
message_ids, the message mem chunk and all signals. Added new
function gimp_statusbar_replace() which updates a message without
moving it to the top of the stack. Fixes bug #120175.
* app/display/gimpdisplayshell-title.[ch]: renamed
gimp_display_shell_update_title() to
gimp_display_shell_title_update() and switched from pop()/push()
to replace() so the title message keeps its place in the stack.
Added new function gimp_display_shell_title_init() which push()es
the title message to the stack.
* app/display/gimpdisplayshell.c (gimp_display_shell_new): call
gimp_display_shell_title_init() so the "title" message is at the
bottom of the stack.
* app/display/gimpdisplayshell-callbacks.c
* app/display/gimpdisplayshell-handlers.c: changed accordingly.
2004-07-14 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/script-fu-console.[ch]

View File

@ -291,7 +291,7 @@ gimp_display_shell_canvas_realize (GtkWidget *canvas,
gimp_display_shell_get_padding (shell, &padding_mode, &padding_color);
gimp_display_shell_set_padding (shell, padding_mode, &padding_color);
gimp_display_shell_update_title (shell);
gimp_display_shell_title_update (shell);
shell->disp_width = canvas->allocation.width;
shell->disp_height = canvas->allocation.height;

View File

@ -341,7 +341,7 @@ static void
gimp_display_shell_clean_dirty_handler (GimpImage *gimage,
GimpDisplayShell *shell)
{
gimp_display_shell_update_title (shell);
gimp_display_shell_title_update (shell);
}
static void
@ -350,7 +350,7 @@ gimp_display_shell_undo_event_handler (GimpImage *gimage,
GimpUndo *undo,
GimpDisplayShell *shell)
{
gimp_display_shell_update_title (shell);
gimp_display_shell_title_update (shell);
}
static void
@ -374,7 +374,7 @@ static void
gimp_display_shell_name_changed_handler (GimpImage *gimage,
GimpDisplayShell *shell)
{
gimp_display_shell_update_title (shell);
gimp_display_shell_title_update (shell);
}
static void
@ -520,7 +520,7 @@ gimp_display_shell_title_notify_handler (GObject *config,
GParamSpec *param_spec,
GimpDisplayShell *shell)
{
gimp_display_shell_update_title (shell);
gimp_display_shell_title_update (shell);
}
static void

View File

@ -65,7 +65,23 @@ static void gimp_display_shell_format_title (GimpDisplayShell *gdisp,
/* public functions */
void
gimp_display_shell_update_title (GimpDisplayShell *shell)
gimp_display_shell_title_init (GimpDisplayShell *shell)
{
GimpDisplayConfig *config;
gchar title[MAX_TITLE_BUF];
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
config = GIMP_DISPLAY_CONFIG (shell->gdisp->gimage->gimp->config);
gimp_display_shell_format_title (shell, title, sizeof (title),
config->image_status_format);
gimp_statusbar_push (GIMP_STATUSBAR (shell->statusbar), "title", title);
}
void
gimp_display_shell_title_update (GimpDisplayShell *shell)
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
@ -103,8 +119,7 @@ gimp_display_shell_update_title_idle (gpointer data)
config->image_status_format);
}
gimp_statusbar_pop (GIMP_STATUSBAR (shell->statusbar), "title");
gimp_statusbar_push (GIMP_STATUSBAR (shell->statusbar), "title", title);
gimp_statusbar_replace (GIMP_STATUSBAR (shell->statusbar), "title", title);
#ifdef __GNUC__
#warning FIXME: dont call info_window_update() here.

View File

@ -20,7 +20,8 @@
#define __GIMP_DISPLAY_SHELL_TITLE_H__
void gimp_display_shell_update_title (GimpDisplayShell *shell);
void gimp_display_shell_title_init (GimpDisplayShell *shell);
void gimp_display_shell_title_update (GimpDisplayShell *shell);
#endif /* __GIMP_DISPLAY_SHELL_TITLE_H__ */

View File

@ -540,7 +540,7 @@ gimp_display_shell_real_scaled (GimpDisplayShell *shell)
if (! shell->gdisp)
return;
gimp_display_shell_update_title (shell);
gimp_display_shell_title_update (shell);
/* update the <Image>/View/Zoom menu */
gimp_ui_manager_update (shell->menubar_manager, shell);
@ -967,6 +967,8 @@ gimp_display_shell_new (GimpDisplay *gdisp,
gimp_display_shell_connect (shell);
gimp_display_shell_title_init (shell);
return GTK_WIDGET (shell);
}
@ -1219,7 +1221,7 @@ gimp_display_shell_flush (GimpDisplayShell *shell,
return;
}
gimp_display_shell_update_title (shell);
gimp_display_shell_title_update (shell);
if (now)
{

View File

@ -44,16 +44,8 @@ typedef struct _GimpStatusbarMsg GimpStatusbarMsg;
struct _GimpStatusbarMsg
{
gchar *text;
guint context_id;
guint message_id;
};
enum
{
SIGNAL_TEXT_PUSHED,
SIGNAL_TEXT_POPPED,
SIGNAL_LAST
gchar *text;
};
/* maximal width of the string holding the cursor-coordinates for
@ -62,23 +54,23 @@ enum
#define CURSOR_LEN 256
static void gimp_statusbar_class_init (GimpStatusbarClass *klass);
static void gimp_statusbar_init (GimpStatusbar *statusbar);
static void gimp_statusbar_destroy (GtkObject *object);
static void gimp_statusbar_class_init (GimpStatusbarClass *klass);
static void gimp_statusbar_init (GimpStatusbar *statusbar);
static void gimp_statusbar_update (GimpStatusbar *statusbar,
const gchar *context_id,
const gchar *text);
static void gimp_statusbar_unit_changed (GimpUnitComboBox *combo,
GimpStatusbar *statusbar);
static void gimp_statusbar_scale_changed (GimpScaleComboBox *combo,
GimpStatusbar *statusbar);
static void gimp_statusbar_shell_scaled (GimpDisplayShell *shell,
GimpStatusbar *statusbar);
static void gimp_statusbar_destroy (GtkObject *object);
static void gimp_statusbar_update (GimpStatusbar *statusbar);
static void gimp_statusbar_unit_changed (GimpUnitComboBox *combo,
GimpStatusbar *statusbar);
static void gimp_statusbar_scale_changed (GimpScaleComboBox *combo,
GimpStatusbar *statusbar);
static void gimp_statusbar_shell_scaled (GimpDisplayShell *shell,
GimpStatusbar *statusbar);
static guint gimp_statusbar_get_context_id (GimpStatusbar *statusbar,
const gchar *context);
static GtkHBoxClass *parent_class;
static guint statusbar_signals[SIGNAL_LAST] = { 0 };
static GtkHBoxClass *parent_class = NULL;
GType
@ -91,14 +83,14 @@ gimp_statusbar_get_type (void)
static const GTypeInfo statusbar_info =
{
sizeof (GimpStatusbarClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_statusbar_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpStatusbar),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_statusbar_init,
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_statusbar_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpStatusbar),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_statusbar_init,
};
statusbar_type = g_type_register_static (GTK_TYPE_HBOX,
@ -119,32 +111,6 @@ gimp_statusbar_class_init (GimpStatusbarClass *klass)
object_class->destroy = gimp_statusbar_destroy;
klass->messages_mem_chunk = g_mem_chunk_new ("GimpStatusbar messages",
sizeof (GimpStatusbarMsg),
sizeof (GimpStatusbarMsg) * 64,
G_ALLOC_AND_FREE);
statusbar_signals[SIGNAL_TEXT_PUSHED] =
g_signal_new ("text_pushed",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GimpStatusbarClass, text_pushed),
NULL, NULL,
gimp_marshal_VOID__UINT_STRING,
G_TYPE_NONE, 2,
G_TYPE_UINT,
G_TYPE_STRING);
statusbar_signals[SIGNAL_TEXT_POPPED] =
g_signal_new ("text_popped",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GimpStatusbarClass, text_popped),
NULL, NULL,
gimp_marshal_VOID__UINT_STRING,
G_TYPE_NONE, 2,
G_TYPE_UINT,
G_TYPE_STRING);
gtk_widget_class_install_style_property (widget_class,
g_param_spec_enum ("shadow_type",
_("Shadow type"),
@ -152,9 +118,6 @@ gimp_statusbar_class_init (GimpStatusbarClass *klass)
GTK_TYPE_SHADOW_TYPE,
GTK_SHADOW_IN,
G_PARAM_READABLE));
klass->text_pushed = gimp_statusbar_update;
klass->text_popped = gimp_statusbar_update;
}
static void
@ -166,7 +129,7 @@ gimp_statusbar_init (GimpStatusbar *statusbar)
GimpUnitStore *store;
GtkShadowType shadow_type;
box->spacing = 2;
box->spacing = 2;
box->homogeneous = FALSE;
statusbar->shell = NULL;
@ -243,25 +206,22 @@ gimp_statusbar_init (GimpStatusbar *statusbar)
"GIMP");
statusbar->seq_context_id = 1;
statusbar->seq_message_id = 1;
statusbar->messages = NULL;
statusbar->keys = NULL;
}
static void
gimp_statusbar_destroy (GtkObject *object)
{
GimpStatusbar *statusbar = GIMP_STATUSBAR (object);
GimpStatusbarClass *class = GIMP_STATUSBAR_GET_CLASS (statusbar);
GSList *list;
GimpStatusbar *statusbar = GIMP_STATUSBAR (object);
GSList *list;
for (list = statusbar->messages; list; list = list->next)
{
GimpStatusbarMsg *msg = list->data;
g_free (msg->text);
g_mem_chunk_free (class->messages_mem_chunk, msg);
g_free (msg);
}
g_slist_free (statusbar->messages);
@ -277,10 +237,17 @@ gimp_statusbar_destroy (GtkObject *object)
}
static void
gimp_statusbar_update (GimpStatusbar *statusbar,
const gchar *context_id,
const gchar *text)
gimp_statusbar_update (GimpStatusbar *statusbar)
{
gchar *text = NULL;
if (statusbar->messages)
{
GimpStatusbarMsg *msg = statusbar->messages->data;
text = msg->text;
}
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (statusbar->progressbar),
text ? text : "");
}
@ -303,131 +270,45 @@ gimp_statusbar_new (GimpDisplayShell *shell)
return GTK_WIDGET (statusbar);
}
guint
void
gimp_statusbar_push (GimpStatusbar *statusbar,
const gchar *context,
const gchar *message)
{
GimpStatusbarMsg *msg;
GimpStatusbarClass *class;
guint context_id;
GimpStatusbarMsg *msg;
guint context_id;
GSList *list;
g_return_val_if_fail (GIMP_IS_STATUSBAR (statusbar), 0);
g_return_val_if_fail (message != NULL, 0);
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (message != NULL);
class = GIMP_STATUSBAR_GET_CLASS (statusbar);
context_id = gimp_statusbar_get_context_id (statusbar, context);
msg = g_chunk_new (GimpStatusbarMsg, class->messages_mem_chunk);
for (list = statusbar->messages; list; list = g_slist_next (list))
{
msg = list->data;
if (msg->context_id == context_id)
{
statusbar->messages = g_slist_remove (statusbar->messages, msg);
g_free (msg->text);
g_free (msg);
break;
}
}
msg = g_new0 (GimpStatusbarMsg, 1);
msg->text = g_strdup (message);
msg->context_id = context_id;
msg->message_id = statusbar->seq_message_id++;
msg->text = g_strdup (message);
statusbar->messages = g_slist_prepend (statusbar->messages, msg);
g_signal_emit (statusbar,
statusbar_signals[SIGNAL_TEXT_PUSHED],
0,
msg->context_id,
msg->text);
return msg->message_id;
gimp_statusbar_update (statusbar);
}
void
gimp_statusbar_pop (GimpStatusbar *statusbar,
const gchar *context)
{
GimpStatusbarClass *class;
GimpStatusbarMsg *msg;
guint context_id;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
class = GIMP_STATUSBAR_GET_CLASS (statusbar);
context_id = gimp_statusbar_get_context_id (statusbar, context);
if (statusbar->messages)
{
GSList *list;
for (list = statusbar->messages; list; list = list->next)
{
msg = list->data;
if (msg->context_id == context_id)
{
statusbar->messages = g_slist_remove_link (statusbar->messages,
list);
g_free (msg->text);
g_mem_chunk_free (class->messages_mem_chunk, msg);
g_slist_free_1 (list);
break;
}
}
}
msg = statusbar->messages ? statusbar->messages->data : NULL;
g_signal_emit (statusbar,
statusbar_signals[SIGNAL_TEXT_POPPED],
0,
(guint) (msg ? msg->context_id : 0),
msg ? msg->text : NULL);
}
void
gimp_statusbar_remove (GimpStatusbar *statusbar,
const gchar *context,
guint message_id)
{
GimpStatusbarClass *class;
GimpStatusbarMsg *msg;
guint context_id;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (message_id > 0);
class = GIMP_STATUSBAR_GET_CLASS (statusbar);
context_id = gimp_statusbar_get_context_id (statusbar, context);
msg = statusbar->messages ? statusbar->messages->data : NULL;
if (msg)
{
GSList *list;
/* care about signal emission if the topmost item is removed */
if (msg->context_id == context_id &&
msg->message_id == message_id)
{
gimp_statusbar_pop (statusbar, context);
return;
}
for (list = statusbar->messages; list; list = list->next)
{
msg = list->data;
if (msg->context_id == context_id &&
msg->message_id == message_id)
{
statusbar->messages = g_slist_remove_link (statusbar->messages,
list);
g_free (msg->text);
g_mem_chunk_free (class->messages_mem_chunk, msg);
g_slist_free_1 (list);
break;
}
}
}
}
guint
gimp_statusbar_push_coords (GimpStatusbar *statusbar,
const gchar *context,
const gchar *title,
@ -438,16 +319,16 @@ gimp_statusbar_push_coords (GimpStatusbar *statusbar,
GimpDisplayShell *shell;
gchar buf[CURSOR_LEN];
g_return_val_if_fail (GIMP_IS_STATUSBAR (statusbar), 0);
g_return_val_if_fail (title != NULL, 0);
g_return_val_if_fail (separator != NULL, 0);
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (title != NULL);
g_return_if_fail (separator != NULL);
shell = statusbar->shell;
if (shell->unit == GIMP_UNIT_PIXEL)
{
g_snprintf (buf, sizeof (buf), statusbar->cursor_format_str,
title,
title,
ROUND (x),
separator,
ROUND (y));
@ -465,9 +346,89 @@ gimp_statusbar_push_coords (GimpStatusbar *statusbar,
y * unit_factor / image->yresolution);
}
return gimp_statusbar_push (statusbar, context, buf);
gimp_statusbar_push (statusbar, context, buf);
}
void
gimp_statusbar_replace (GimpStatusbar *statusbar,
const gchar *context,
const gchar *message)
{
GimpStatusbarMsg *msg;
guint context_id;
GSList *list;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (message != NULL);
if (! statusbar->messages)
{
gimp_statusbar_push (statusbar, context, message);
return;
}
context_id = gimp_statusbar_get_context_id (statusbar, context);
msg = statusbar->messages->data;
if (msg->context_id == context_id)
{
gimp_statusbar_pop (statusbar, context);
gimp_statusbar_push (statusbar, context, message);
return;
}
for (list = statusbar->messages; list; list = g_slist_next (list))
{
msg = list->data;
if (msg->context_id == context_id)
{
g_free (msg->text);
msg->text = g_strdup (message);
return;
}
}
msg = g_new0 (GimpStatusbarMsg, 1);
msg->context_id = context_id;
msg->text = g_strdup (message);
statusbar->messages = g_slist_prepend (statusbar->messages, msg);
gimp_statusbar_update (statusbar);
}
void
gimp_statusbar_pop (GimpStatusbar *statusbar,
const gchar *context)
{
guint context_id;
GSList *list;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
context_id = gimp_statusbar_get_context_id (statusbar, context);
for (list = statusbar->messages; list; list = list->next)
{
GimpStatusbarMsg *msg = list->data;
if (msg->context_id == context_id)
{
statusbar->messages = g_slist_remove (statusbar->messages, msg);
g_free (msg->text);
g_free (msg);
break;
}
}
gimp_statusbar_update (statusbar);
}
void
gimp_statusbar_set_cursor (GimpStatusbar *statusbar,
@ -492,7 +453,7 @@ gimp_statusbar_set_cursor (GimpStatusbar *statusbar,
{
g_snprintf (buffer, sizeof (buffer),
statusbar->cursor_format_str,
"", ROUND (x), ", ", ROUND (y));
"", ROUND (x), ", ", ROUND (y));
}
else /* show real world units */
{
@ -500,7 +461,7 @@ gimp_statusbar_set_cursor (GimpStatusbar *statusbar,
g_snprintf (buffer, sizeof (buffer),
statusbar->cursor_format_str,
"", x, ", ", y);
"", x, ", ", y);
}
gtk_label_set_text (GTK_LABEL (statusbar->cursor_label), buffer);
@ -546,13 +507,13 @@ gimp_statusbar_shell_scaled (GimpDisplayShell *shell,
{
g_snprintf (statusbar->cursor_format_str,
sizeof (statusbar->cursor_format_str),
"%%s%%d%%s%%d");
"%%s%%d%%s%%d");
}
else /* show real world units */
{
g_snprintf (statusbar->cursor_format_str,
sizeof (statusbar->cursor_format_str),
"%%s%%.%df%%s%%.%df",
"%%s%%.%df%%s%%.%df",
_gimp_unit_get_digits (image->gimp, shell->unit),
_gimp_unit_get_digits (image->gimp, shell->unit));
}
@ -601,18 +562,18 @@ gimp_statusbar_scale_changed (GimpScaleComboBox *combo,
gimp_scale_combo_box_get_scale (combo));
}
guint
static guint
gimp_statusbar_get_context_id (GimpStatusbar *statusbar,
const gchar *context_description)
const gchar *context)
{
gchar *string;
guint *id;
g_return_val_if_fail (GIMP_IS_STATUSBAR (statusbar), 0);
g_return_val_if_fail (context_description != NULL, 0);
g_return_val_if_fail (context != NULL, 0);
/* we need to preserve namespaces on object datas */
string = g_strconcat ("gimp-status-bar-context:", context_description, NULL);
string = g_strconcat ("gimp-status-bar-context:", context, NULL);
id = g_object_get_data (G_OBJECT (statusbar), string);
if (!id)

View File

@ -43,7 +43,6 @@ struct _GimpStatusbar
GSList *messages;
GSList *keys;
guint seq_context_id;
guint seq_message_id;
GimpDisplayShell *shell;
@ -60,41 +59,33 @@ struct _GimpStatusbar
struct _GimpStatusbarClass
{
GtkHBoxClass parent_class;
GMemChunk *messages_mem_chunk;
void (*text_pushed) (GimpStatusbar *statusbar,
const gchar *context_id,
const gchar *text);
void (*text_popped) (GimpStatusbar *statusbar,
const gchar *context_id,
const gchar *text);
GtkHBoxClass parent_class;
};
GType gimp_statusbar_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_statusbar_new (GimpDisplayShell *shell);
void gimp_statusbar_pop (GimpStatusbar *statusbar,
const gchar *context);
void gimp_statusbar_remove (GimpStatusbar *statusbar,
const gchar *context,
guint message_id);
guint gimp_statusbar_push_coords (GimpStatusbar *statusbar,
const gchar *context,
const gchar *title,
gdouble x,
const gchar *separator,
gdouble y);
guint gimp_statusbar_push (GimpStatusbar *statusbar,
const gchar *context,
const gchar *message);
void gimp_statusbar_set_cursor (GimpStatusbar *statusbar,
gdouble x,
gdouble y);
void gimp_statusbar_clear_cursor (GimpStatusbar *statusbar);
guint gimp_statusbar_get_context_id (GimpStatusbar *statusbar,
const gchar *context_description);
GType gimp_statusbar_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_statusbar_new (GimpDisplayShell *shell);
void gimp_statusbar_push (GimpStatusbar *statusbar,
const gchar *context,
const gchar *message);
void gimp_statusbar_push_coords (GimpStatusbar *statusbar,
const gchar *context,
const gchar *title,
gdouble x,
const gchar *separator,
gdouble y);
void gimp_statusbar_replace (GimpStatusbar *statusbar,
const gchar *context,
const gchar *message);
void gimp_statusbar_pop (GimpStatusbar *statusbar,
const gchar *context);
void gimp_statusbar_set_cursor (GimpStatusbar *statusbar,
gdouble x,
gdouble y);
void gimp_statusbar_clear_cursor (GimpStatusbar *statusbar);
G_END_DECLS