2003-01-04 02:01:30 +08:00
|
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
*
|
|
|
|
|
* 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 2 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, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
|
|
|
|
|
#include "display-types.h"
|
|
|
|
|
|
|
|
|
|
#include "config/gimpdisplayconfig.h"
|
|
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
|
#include "core/gimpimage.h"
|
2004-01-27 20:43:53 +08:00
|
|
|
|
#include "core/gimpitem.h"
|
2004-06-02 06:04:20 +08:00
|
|
|
|
#include "core/gimpunit.h"
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
|
|
|
|
#include "file/file-utils.h"
|
|
|
|
|
|
|
|
|
|
#include "gimpdisplay.h"
|
|
|
|
|
#include "gimpdisplayshell.h"
|
2004-01-30 06:22:29 +08:00
|
|
|
|
#include "gimpdisplayshell-scale.h"
|
2003-01-04 02:01:30 +08:00
|
|
|
|
#include "gimpdisplayshell-title.h"
|
|
|
|
|
#include "gimpstatusbar.h"
|
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
|
#include "gimp-intl.h"
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX_TITLE_BUF 256
|
|
|
|
|
|
|
|
|
|
|
2003-02-26 03:01:10 +08:00
|
|
|
|
static gboolean gimp_display_shell_update_title_idle (gpointer data);
|
|
|
|
|
static void gimp_display_shell_format_title (GimpDisplayShell *gdisp,
|
|
|
|
|
gchar *title,
|
|
|
|
|
gint title_len,
|
|
|
|
|
const gchar *format);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
|
|
|
|
void
|
2004-07-15 00:37:13 +08:00
|
|
|
|
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)
|
2003-01-04 02:01:30 +08:00
|
|
|
|
{
|
2003-02-26 03:01:10 +08:00
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
|
|
if (shell->title_idle_id)
|
|
|
|
|
g_source_remove (shell->title_idle_id);
|
|
|
|
|
|
|
|
|
|
shell->title_idle_id = g_idle_add (gimp_display_shell_update_title_idle,
|
|
|
|
|
shell);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gimp_display_shell_update_title_idle (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GimpDisplayShell *shell;
|
2003-01-04 02:01:30 +08:00
|
|
|
|
GimpDisplayConfig *config;
|
|
|
|
|
gchar title[MAX_TITLE_BUF];
|
|
|
|
|
|
2003-02-26 03:01:10 +08:00
|
|
|
|
shell = GIMP_DISPLAY_SHELL (data);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
config = GIMP_DISPLAY_CONFIG (shell->gdisp->gimage->gimp->config);
|
|
|
|
|
|
2003-02-26 03:01:10 +08:00
|
|
|
|
shell->title_idle_id = 0;
|
|
|
|
|
|
2003-01-04 02:01:30 +08:00
|
|
|
|
/* format the title */
|
|
|
|
|
gimp_display_shell_format_title (shell, title, sizeof (title),
|
|
|
|
|
config->image_title_format);
|
|
|
|
|
gdk_window_set_title (GTK_WIDGET (shell)->window, title);
|
|
|
|
|
|
|
|
|
|
/* format the statusbar */
|
|
|
|
|
if (strcmp (config->image_title_format, config->image_status_format))
|
|
|
|
|
{
|
|
|
|
|
gimp_display_shell_format_title (shell, title, sizeof (title),
|
|
|
|
|
config->image_status_format);
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-15 00:37:13 +08:00
|
|
|
|
gimp_statusbar_replace (GIMP_STATUSBAR (shell->statusbar), "title", title);
|
2003-02-26 03:01:10 +08:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
2003-01-04 02:01:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gint print (gchar *buf,
|
|
|
|
|
gint len,
|
|
|
|
|
gint start,
|
|
|
|
|
const gchar *fmt,
|
|
|
|
|
...) G_GNUC_PRINTF (4, 5);
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
print (gchar *buf,
|
|
|
|
|
gint len,
|
|
|
|
|
gint start,
|
|
|
|
|
const gchar *fmt,
|
|
|
|
|
...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
gint printed;
|
|
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
|
|
|
|
|
|
|
|
|
printed = g_vsnprintf (buf + start, len - start, fmt, args);
|
|
|
|
|
if (printed < 0)
|
|
|
|
|
printed = len - start;
|
|
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
|
|
return printed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_display_shell_format_title (GimpDisplayShell *shell,
|
|
|
|
|
gchar *title,
|
|
|
|
|
gint title_len,
|
|
|
|
|
const gchar *format)
|
|
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
|
Gimp *gimp;
|
|
|
|
|
GimpImage *image;
|
2004-01-30 06:22:29 +08:00
|
|
|
|
gint num, denom;
|
2004-01-27 20:43:53 +08:00
|
|
|
|
gint i = 0;
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
2004-06-02 06:04:20 +08:00
|
|
|
|
image = shell->gdisp->gimage;
|
|
|
|
|
gimp = image->gimp;
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
2004-01-30 06:22:29 +08:00
|
|
|
|
gimp_display_shell_scale_get_fraction (shell->scale, &num, &denom);
|
|
|
|
|
|
2003-01-04 02:01:30 +08:00
|
|
|
|
while (i < title_len && *format)
|
|
|
|
|
{
|
|
|
|
|
switch (*format)
|
|
|
|
|
{
|
|
|
|
|
case '%':
|
|
|
|
|
format++;
|
|
|
|
|
switch (*format)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
2004-08-25 22:38:49 +08:00
|
|
|
|
/* format string ends within %-sequence, print literal '%' */
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
|
title[i++] = '%';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'f': /* pruned filename */
|
|
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
|
const gchar *uri = gimp_image_get_uri (image);
|
2004-01-27 20:43:53 +08:00
|
|
|
|
gchar *basename;
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
2004-01-27 20:43:53 +08:00
|
|
|
|
basename = file_utils_uri_to_utf8_basename (uri);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
|
|
|
|
i += print (title, title_len, i, "%s", basename);
|
|
|
|
|
|
|
|
|
|
g_free (basename);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'F': /* full filename */
|
|
|
|
|
{
|
|
|
|
|
gchar *filename;
|
2004-06-02 06:04:20 +08:00
|
|
|
|
const gchar *uri = gimp_image_get_uri (image);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
2004-01-27 20:43:53 +08:00
|
|
|
|
filename = file_utils_uri_to_utf8_filename (uri);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
|
|
|
|
i += print (title, title_len, i, "%s", filename);
|
|
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'p': /* PDB id */
|
2004-06-02 06:04:20 +08:00
|
|
|
|
i += print (title, title_len, i, "%d", gimp_image_get_ID (image));
|
2003-01-04 02:01:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'i': /* instance */
|
|
|
|
|
i += print (title, title_len, i, "%d", shell->gdisp->instance);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 't': /* type */
|
2004-01-27 20:43:53 +08:00
|
|
|
|
{
|
|
|
|
|
const gchar *image_type_str = NULL;
|
2004-06-02 06:04:20 +08:00
|
|
|
|
gboolean empty = gimp_image_is_empty (image);
|
2004-01-27 20:43:53 +08:00
|
|
|
|
|
2004-06-02 06:04:20 +08:00
|
|
|
|
switch (gimp_image_base_type (image))
|
2004-01-27 20:43:53 +08:00
|
|
|
|
{
|
|
|
|
|
case GIMP_RGB:
|
|
|
|
|
image_type_str = empty ? _("RGB-empty") : _("RGB");
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_GRAY:
|
|
|
|
|
image_type_str = empty ? _("grayscale-empty") : _("grayscale");
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_INDEXED:
|
|
|
|
|
image_type_str = empty ? _("indexed-empty") : _("indexed");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i += print (title, title_len, i, "%s", image_type_str);
|
|
|
|
|
}
|
2003-01-04 02:01:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 's': /* user source zoom factor */
|
2004-01-30 06:22:29 +08:00
|
|
|
|
i += print (title, title_len, i, "%d", denom);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'd': /* user destination zoom factor */
|
2004-01-30 06:22:29 +08:00
|
|
|
|
i += print (title, title_len, i, "%d", num);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'z': /* user zoom factor (percentage) */
|
2004-01-30 06:22:29 +08:00
|
|
|
|
i += print (title, title_len, i,
|
|
|
|
|
shell->scale >= 0.15 ? "%.0f" : "%.2f",
|
|
|
|
|
100 * shell->scale);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'D': /* dirty flag */
|
|
|
|
|
if (format[1] == 0)
|
|
|
|
|
{
|
2004-08-25 22:38:49 +08:00
|
|
|
|
/* format string ends within %D-sequence, print literal '%D' */
|
|
|
|
|
i += print (title, title_len, i, "%%D");
|
2003-01-04 02:01:30 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2004-06-02 06:04:20 +08:00
|
|
|
|
if (image->dirty)
|
2003-01-04 02:01:30 +08:00
|
|
|
|
title[i++] = format[1];
|
|
|
|
|
format++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'C': /* clean flag */
|
|
|
|
|
if (format[1] == 0)
|
|
|
|
|
{
|
2004-08-25 22:38:49 +08:00
|
|
|
|
/* format string ends within %C-sequence, print literal '%C' */
|
|
|
|
|
i += print (title, title_len, i, "%%C");
|
2003-01-04 02:01:30 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2004-06-02 06:04:20 +08:00
|
|
|
|
if (! image->dirty)
|
2003-01-04 02:01:30 +08:00
|
|
|
|
title[i++] = format[1];
|
|
|
|
|
format++;
|
|
|
|
|
break;
|
|
|
|
|
|
2004-07-13 07:36:45 +08:00
|
|
|
|
case 'B': /* dirty flag (long) */
|
|
|
|
|
if (image->dirty)
|
|
|
|
|
i += print (title, title_len, i, "%s",
|
|
|
|
|
_("(modified)"));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'A': /* clean flag (long) */
|
|
|
|
|
if (! image->dirty)
|
|
|
|
|
i += print (title, title_len, i, "%s",
|
|
|
|
|
_("(clean)"));
|
|
|
|
|
break;
|
|
|
|
|
|
2003-01-04 02:01:30 +08:00
|
|
|
|
case 'm': /* memory used by image */
|
|
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
|
GimpObject *object = GIMP_OBJECT (image);
|
2003-11-17 01:51:36 +08:00
|
|
|
|
gchar *str;
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
2003-11-17 01:51:36 +08:00
|
|
|
|
str = gimp_memsize_to_string (gimp_object_get_memsize (object,
|
|
|
|
|
NULL));
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
2003-11-17 01:51:36 +08:00
|
|
|
|
i += print (title, title_len, i, "%s", str);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
2003-11-17 01:51:36 +08:00
|
|
|
|
g_free (str);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'l': /* number of layers */
|
|
|
|
|
i += print (title, title_len, i, "%d",
|
2004-06-02 06:04:20 +08:00
|
|
|
|
gimp_container_num_children (image->layers));
|
2003-01-04 02:01:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2003-10-15 07:00:16 +08:00
|
|
|
|
case 'L': /* number of layers (long) */
|
2003-01-04 02:01:30 +08:00
|
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
|
gint num = gimp_container_num_children (image->layers);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
2003-10-15 07:00:16 +08:00
|
|
|
|
i += print (title, title_len, i,
|
2005-09-13 20:38:37 +08:00
|
|
|
|
ngettext ("%d layer", "%d layers", num), num);
|
2003-10-15 07:00:16 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'n': /* active drawable name */
|
|
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
|
GimpDrawable *drawable = gimp_image_active_drawable (image);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
|
|
|
|
if (drawable)
|
|
|
|
|
i += print (title, title_len, i, "%s",
|
|
|
|
|
gimp_object_get_name (GIMP_OBJECT (drawable)));
|
|
|
|
|
else
|
2003-02-26 03:01:10 +08:00
|
|
|
|
i += print (title, title_len, i, "%s", _("(none)"));
|
2003-01-04 02:01:30 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2004-01-27 20:43:53 +08:00
|
|
|
|
case 'P': /* active drawable PDB id */
|
|
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
|
GimpDrawable *drawable = gimp_image_active_drawable (image);
|
2004-01-27 20:43:53 +08:00
|
|
|
|
|
|
|
|
|
if (drawable)
|
|
|
|
|
i += print (title, title_len, i, "%d",
|
|
|
|
|
gimp_item_get_ID (GIMP_ITEM (drawable)));
|
|
|
|
|
else
|
|
|
|
|
i += print (title, title_len, i, "%s", _("(none)"));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2004-05-07 23:45:56 +08:00
|
|
|
|
case 'W': /* width in real-world units */
|
2004-06-02 06:04:20 +08:00
|
|
|
|
if (shell->unit != GIMP_UNIT_PIXEL)
|
2004-05-07 23:45:56 +08:00
|
|
|
|
{
|
|
|
|
|
gchar unit_format[8];
|
|
|
|
|
|
|
|
|
|
g_snprintf (unit_format, sizeof (unit_format), "%%.%df",
|
2004-06-02 06:04:20 +08:00
|
|
|
|
_gimp_unit_get_digits (gimp, shell->unit) + 1);
|
2004-05-07 23:45:56 +08:00
|
|
|
|
i += print (title, title_len, i, unit_format,
|
2004-06-02 06:04:20 +08:00
|
|
|
|
(image->width *
|
|
|
|
|
_gimp_unit_get_factor (gimp, shell->unit) /
|
|
|
|
|
image->xresolution));
|
2004-05-07 23:45:56 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
/* else fallthru */
|
2003-01-04 02:01:30 +08:00
|
|
|
|
case 'w': /* width in pixels */
|
2004-06-02 06:04:20 +08:00
|
|
|
|
i += print (title, title_len, i, "%d", image->width);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2004-05-07 23:45:56 +08:00
|
|
|
|
case 'H': /* height in real-world units */
|
2004-06-02 06:04:20 +08:00
|
|
|
|
if (shell->unit != GIMP_UNIT_PIXEL)
|
2004-05-07 23:45:56 +08:00
|
|
|
|
{
|
|
|
|
|
gchar unit_format[8];
|
|
|
|
|
|
|
|
|
|
g_snprintf (unit_format, sizeof (unit_format), "%%.%df",
|
2004-06-02 06:04:20 +08:00
|
|
|
|
_gimp_unit_get_digits (gimp, shell->unit) + 1);
|
2004-05-07 23:45:56 +08:00
|
|
|
|
i += print (title, title_len, i, unit_format,
|
2004-06-02 06:04:20 +08:00
|
|
|
|
(image->height *
|
|
|
|
|
_gimp_unit_get_factor (gimp, shell->unit) /
|
|
|
|
|
image->yresolution));
|
2004-05-07 23:45:56 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
/* else fallthru */
|
2003-01-04 02:01:30 +08:00
|
|
|
|
case 'h': /* height in pixels */
|
2004-06-02 06:04:20 +08:00
|
|
|
|
i += print (title, title_len, i, "%d", image->height);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'u': /* unit symbol */
|
|
|
|
|
i += print (title, title_len, i, "%s",
|
2004-06-02 06:04:20 +08:00
|
|
|
|
_gimp_unit_get_symbol (gimp, shell->unit));
|
2003-01-04 02:01:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'U': /* unit abbreviation */
|
|
|
|
|
i += print (title, title_len, i, "%s",
|
2004-06-02 06:04:20 +08:00
|
|
|
|
_gimp_unit_get_abbreviation (gimp, shell->unit));
|
2003-01-04 02:01:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* Other cool things to be added:
|
|
|
|
|
* %r = xresolution
|
|
|
|
|
* %R = yresolution
|
|
|
|
|
* %<EFBFBD> = image's fractal dimension
|
|
|
|
|
* %<EFBFBD> = the answer to everything
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
default:
|
2004-08-25 22:38:49 +08:00
|
|
|
|
/* format string contains unknown %-sequence, print it literally */
|
|
|
|
|
i += print (title, title_len, i, "%%%c", *format);
|
|
|
|
|
break;
|
2003-01-04 02:01:30 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
title[i++] = *format;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
format++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
title[MIN (i, title_len - 1)] = '\0';
|
|
|
|
|
}
|