Commit 10f9181e authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

added _valist() variants of all printf-style functions.

2006-09-28  Michael Natterer  <mitch@gimp.org>

	* app/display/gimpstatusbar.[ch]: added _valist() variants
	of all printf-style functions.

	* app/tools/gimptool.[ch] (gimp_tool_push_status)
	(gimp_tool_replace_status)
	(gimp_tool_message): take printf-style ... arguments and use the
	new valist() variants of the statusbar API to avoid additional
	strdups. Revert previous commit from Sven, he will add back that
	feature differently right away :)

	* app/tools/gimpmeasuretool.c
	* app/tools/gimppainttool.c: use the new printf-style status API
	where possible.

	* app/tools/gimptransformtool.c: accidentially removed
	"core/gimp.h", added it back.
parent afd2ab68
2006-09-28 Michael Natterer <mitch@gimp.org>
* app/display/gimpstatusbar.[ch]: added _valist() variants
of all printf-style functions.
* app/tools/gimptool.[ch] (gimp_tool_push_status)
(gimp_tool_replace_status)
(gimp_tool_message): take printf-style ... arguments and use the
new valist() variants of the statusbar API to avoid additional
strdups. Revert previous commit from Sven, he will add back that
feature differently right away :)
* app/tools/gimpmeasuretool.c
* app/tools/gimppainttool.c: use the new printf-style status API
where possible.
* app/tools/gimptransformtool.c: accidentially removed
"core/gimp.h", added it back.
2006-09-28 Sven Neumann <sven@gimp.org>
* app/core/gimp.[ch]: added gimp_message_valist().
......
......@@ -456,20 +456,34 @@ gimp_statusbar_push (GimpStatusbar *statusbar,
const gchar *context,
const gchar *format,
...)
{
va_list args;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (context != NULL);
g_return_if_fail (format != NULL);
va_start (args, format);
gimp_statusbar_push_valist (statusbar, context, format, args);
va_end (args);
}
void
gimp_statusbar_push_valist (GimpStatusbar *statusbar,
const gchar *context,
const gchar *format,
va_list args)
{
GimpStatusbarMsg *msg;
guint context_id;
GSList *list;
va_list args;
gchar *message;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (context != NULL);
g_return_if_fail (format != NULL);
va_start (args, format);
message = g_strdup_vprintf (format, args);
va_end (args);
context_id = gimp_statusbar_get_context_id (statusbar, context);
......@@ -606,20 +620,34 @@ gimp_statusbar_replace (GimpStatusbar *statusbar,
const gchar *context,
const gchar *format,
...)
{
va_list args;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (context != NULL);
g_return_if_fail (format != NULL);
va_start (args, format);
gimp_statusbar_replace_valist (statusbar, context, format, args);
va_end (args);
}
void
gimp_statusbar_replace_valist (GimpStatusbar *statusbar,
const gchar *context,
const gchar *format,
va_list args)
{
GimpStatusbarMsg *msg;
GSList *list;
guint context_id;
va_list args;
gchar *message;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (context != NULL);
g_return_if_fail (format != NULL);
va_start (args, format);
message = g_strdup_vprintf (format, args);
va_end (args);
context_id = gimp_statusbar_get_context_id (statusbar, context);
......@@ -685,17 +713,29 @@ void
gimp_statusbar_push_temp (GimpStatusbar *statusbar,
const gchar *format,
...)
{
va_list args;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (format != NULL);
va_start (args, format);
gimp_statusbar_push_temp_valist (statusbar, format, args);
va_end (args);
}
void
gimp_statusbar_push_temp_valist (GimpStatusbar *statusbar,
const gchar *format,
va_list args)
{
GimpStatusbarMsg *msg = NULL;
va_list args;
gchar *message;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (format != NULL);
va_start (args, format);
message = g_strdup_vprintf (format, args);
va_end (args);
if (statusbar->temp_timeout_id)
g_source_remove (statusbar->temp_timeout_id);
......
......@@ -69,40 +69,51 @@ struct _GimpStatusbarClass
};
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 *format,
...) G_GNUC_PRINTF(3,4);
void gimp_statusbar_push_coords (GimpStatusbar *statusbar,
const gchar *context,
const gchar *title,
gdouble x,
const gchar *separator,
gdouble y);
void gimp_statusbar_push_length (GimpStatusbar *statusbar,
const gchar *context,
const gchar *title,
GimpOrientationType axis,
gdouble value);
void gimp_statusbar_replace (GimpStatusbar *statusbar,
const gchar *context,
const gchar *format,
...) G_GNUC_PRINTF(3,4);
void gimp_statusbar_pop (GimpStatusbar *statusbar,
const gchar *context);
void gimp_statusbar_push_temp (GimpStatusbar *statusbar,
const gchar *format,
...) G_GNUC_PRINTF(2,3);
void gimp_statusbar_pop_temp (GimpStatusbar *statusbar);
void gimp_statusbar_set_cursor (GimpStatusbar *statusbar,
gdouble x,
gdouble y);
void gimp_statusbar_clear_cursor (GimpStatusbar *statusbar);
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 *format,
...) G_GNUC_PRINTF(3,4);
void gimp_statusbar_push_valist (GimpStatusbar *statusbar,
const gchar *context,
const gchar *format,
va_list args);
void gimp_statusbar_push_coords (GimpStatusbar *statusbar,
const gchar *context,
const gchar *title,
gdouble x,
const gchar *separator,
gdouble y);
void gimp_statusbar_push_length (GimpStatusbar *statusbar,
const gchar *context,
const gchar *title,
GimpOrientationType axis,
gdouble value);
void gimp_statusbar_replace (GimpStatusbar *statusbar,
const gchar *context,
const gchar *format,
...) G_GNUC_PRINTF(3,4);
void gimp_statusbar_replace_valist (GimpStatusbar *statusbar,
const gchar *context,
const gchar *format,
va_list args);
void gimp_statusbar_pop (GimpStatusbar *statusbar,
const gchar *context);
void gimp_statusbar_push_temp (GimpStatusbar *statusbar,
const gchar *format,
...) G_GNUC_PRINTF(2,3);
void gimp_statusbar_push_temp_valist (GimpStatusbar *statusbar,
const gchar *format,
va_list args);
void gimp_statusbar_pop_temp (GimpStatusbar *statusbar);
void gimp_statusbar_set_cursor (GimpStatusbar *statusbar,
gdouble x,
gdouble y);
void gimp_statusbar_clear_cursor (GimpStatusbar *statusbar);
G_END_DECLS
......
......@@ -747,7 +747,6 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure,
gdouble pixel_angle;
gdouble unit_angle;
gchar format[128];
gchar buf[128];
/* calculate distance and angle */
ax = measure->x[1] - measure->x[0];
......@@ -801,9 +800,10 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure,
if (shell->unit == GIMP_UNIT_PIXEL)
{
g_snprintf (buf, sizeof (buf), "%.1f %s, %.2f\302\260 (%d × %d)",
pixel_distance, _("pixels"), pixel_angle,
pixel_width, pixel_height);
gimp_tool_replace_status (GIMP_TOOL (measure), display,
"%.1f %s, %.2f\302\260 (%d × %d)",
pixel_distance, _("pixels"), pixel_angle,
pixel_width, pixel_height);
}
else
{
......@@ -814,14 +814,15 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure,
_gimp_unit_get_digits (image->gimp, shell->unit),
_gimp_unit_get_digits (image->gimp, shell->unit));
g_snprintf (buf, sizeof (buf), format, unit_distance, unit_angle,
unit_width, unit_height);
gimp_tool_replace_status (GIMP_TOOL (measure), display, format,
unit_distance, unit_angle,
unit_width, unit_height);
}
gimp_tool_replace_status (GIMP_TOOL (measure), display, buf);
if (measure->dialog)
{
gchar buf[128];
g_snprintf (format, sizeof (format), "%%.%df",
_gimp_unit_get_digits (image->gimp, shell->unit));
/* Distance */
......
......@@ -566,7 +566,6 @@ gimp_paint_tool_oper_update (GimpTool *tool,
* draw a line.
*/
gchar status_str[STATUSBAR_SIZE];
gchar *status_help;
gdouble dx, dy, dist;
gint off_x, off_y;
......@@ -597,8 +596,8 @@ gimp_paint_tool_oper_update (GimpTool *tool,
{
dist = sqrt (SQR (dx) + SQR (dy));
g_snprintf (status_str, sizeof (status_str), "%.1f %s. %s",
dist, _("pixels"), status_help);
gimp_tool_push_status (tool, display, "%.1f %s. %s",
dist, _("pixels"), status_help);
}
else
{
......@@ -613,11 +612,11 @@ gimp_paint_tool_oper_update (GimpTool *tool,
sqrt (SQR (dx / image->xresolution) +
SQR (dy / image->yresolution)));
g_snprintf (status_str, sizeof (status_str), format_str, dist,
status_help);
gimp_tool_push_status (tool, display, format_str,
dist, status_help);
}
g_free (status_help);
gimp_tool_push_status (tool, display, status_str);
paint_tool->draw_line = TRUE;
}
......@@ -629,10 +628,13 @@ gimp_paint_tool_oper_update (GimpTool *tool,
/* HACK: A paint tool may set status_ctrl to NULL to indicate that
* it ignores the Ctrl modifier (temporarily or permanently), so
* it should not be suggested. This is different from how
* gimp_suggest_modifiers() would interpret this parameter. */
* gimp_suggest_modifiers() would interpret this parameter.
*/
if (paint_tool->status_ctrl != NULL)
modifiers |= GDK_CONTROL_MASK;
/* suggest drawing lines only after the first point is set */
/* suggest drawing lines only after the first point is set
*/
if (display == tool->display)
modifiers |= GDK_SHIFT_MASK;
......
......@@ -714,19 +714,23 @@ gimp_tool_cursor_update (GimpTool *tool,
void
gimp_tool_push_status (GimpTool *tool,
GimpDisplay *display,
const gchar *message)
const gchar *format,
...)
{
GimpDisplayShell *shell;
va_list args;
g_return_if_fail (GIMP_IS_TOOL (tool));
g_return_if_fail (GIMP_IS_DISPLAY (display));
g_return_if_fail (message != NULL);
g_return_if_fail (format != NULL);
shell = GIMP_DISPLAY_SHELL (display->shell);
gimp_statusbar_push (GIMP_STATUSBAR (shell->statusbar),
G_OBJECT_TYPE_NAME (tool),
"%s", message);
va_start (args, format);
gimp_statusbar_push_valist (GIMP_STATUSBAR (shell->statusbar),
G_OBJECT_TYPE_NAME (tool),
format, args);
va_end (args);
}
void
......@@ -771,19 +775,23 @@ gimp_tool_push_status_length (GimpTool *tool,
void
gimp_tool_replace_status (GimpTool *tool,
GimpDisplay *display,
const gchar *message)
const gchar *format,
...)
{
GimpDisplayShell *shell;
va_list args;
g_return_if_fail (GIMP_IS_TOOL (tool));
g_return_if_fail (GIMP_IS_DISPLAY (display));
g_return_if_fail (message != NULL);
g_return_if_fail (format != NULL);
shell = GIMP_DISPLAY_SHELL (display->shell);
gimp_statusbar_replace (GIMP_STATUSBAR (shell->statusbar),
G_OBJECT_TYPE_NAME (tool),
"%s", message);
va_start (args, format);
gimp_statusbar_replace_valist (GIMP_STATUSBAR (shell->statusbar),
G_OBJECT_TYPE_NAME (tool),
format, args);
va_end (args);
}
void
......@@ -804,26 +812,22 @@ gimp_tool_pop_status (GimpTool *tool,
void
gimp_tool_message (GimpTool *tool,
GimpDisplay *display,
const gchar *message)
const gchar *format,
...)
{
GimpDisplayShell *shell;
va_list args;
g_return_if_fail (GIMP_IS_TOOL (tool));
g_return_if_fail (GIMP_IS_DISPLAY (display));
g_return_if_fail (message != NULL);
g_return_if_fail (format != NULL);
shell = GIMP_DISPLAY_SHELL (display->shell);
if (GTK_WIDGET_VISIBLE (shell->statusbar))
{
gimp_statusbar_push_temp (GIMP_STATUSBAR (shell->statusbar),
"%s", message);
}
else
{
gimp_message (tool->tool_info->gimp, GIMP_PROGRESS (display->shell),
"%s", message);
}
va_start (args, format);
gimp_statusbar_push_temp_valist (GIMP_STATUSBAR (shell->statusbar),
format, args);
va_end (args);
}
void
......
......@@ -175,7 +175,8 @@ void gimp_tool_cursor_update (GimpTool *tool,
void gimp_tool_push_status (GimpTool *tool,
GimpDisplay *display,
const gchar *message);
const gchar *format,
...) G_GNUC_PRINTF(3,4);
void gimp_tool_push_status_coords (GimpTool *tool,
GimpDisplay *display,
const gchar *title,
......@@ -189,13 +190,15 @@ void gimp_tool_push_status_length (GimpTool *tool,
gdouble value);
void gimp_tool_replace_status (GimpTool *tool,
GimpDisplay *display,
const gchar *message);
const gchar *format,
...) G_GNUC_PRINTF(3,4);
void gimp_tool_pop_status (GimpTool *tool,
GimpDisplay *display);
void gimp_tool_message (GimpTool *tool,
GimpDisplay *display,
const gchar *message);
const gchar *format,
...) G_GNUC_PRINTF(3,4);
void gimp_tool_set_cursor (GimpTool *tool,
GimpDisplay *display,
......
......@@ -31,6 +31,7 @@
#include "base/tile-manager.h"
#include "core/gimp.h"
#include "core/gimpchannel.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable-transform.h"
......
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