1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
#include "libgimpbase/gimpbase.h"
27
#include "display-types.h"
29
#include "config/gimpdisplayconfig.h"
31
#include "core/gimp.h"
32
#include "core/gimpcontainer.h"
33
#include "core/gimpimage.h"
34
#include "core/gimpitem.h"
35
#include "core/gimpunit.h"
37
#include "file/file-utils.h"
40
#warning FIXME #include "dialogs/dialogs-types.h"
42
#include "dialogs/dialogs-types.h"
43
#include "dialogs/info-window.h"
45
#include "gimpdisplay.h"
46
#include "gimpdisplayshell.h"
47
#include "gimpdisplayshell-scale.h"
48
#include "gimpdisplayshell-title.h"
49
#include "gimpstatusbar.h"
51
#include "gimp-intl.h"
54
#define MAX_TITLE_BUF 256
57
static gboolean gimp_display_shell_update_title_idle (gpointer data);
58
static void gimp_display_shell_format_title (GimpDisplayShell *gdisp,
64
/* public functions */
67
gimp_display_shell_title_init (GimpDisplayShell *shell)
69
GimpDisplayConfig *config;
70
gchar title[MAX_TITLE_BUF];
72
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
74
config = GIMP_DISPLAY_CONFIG (shell->gdisp->gimage->gimp->config);
76
gimp_display_shell_format_title (shell, title, sizeof (title),
77
config->image_status_format);
79
gimp_statusbar_push (GIMP_STATUSBAR (shell->statusbar), "title", title);
83
gimp_display_shell_title_update (GimpDisplayShell *shell)
85
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
87
if (shell->title_idle_id)
88
g_source_remove (shell->title_idle_id);
90
shell->title_idle_id = g_idle_add (gimp_display_shell_update_title_idle,
95
/* private functions */
98
gimp_display_shell_update_title_idle (gpointer data)
100
GimpDisplayShell *shell;
101
GimpDisplayConfig *config;
102
gchar title[MAX_TITLE_BUF];
104
shell = GIMP_DISPLAY_SHELL (data);
105
config = GIMP_DISPLAY_CONFIG (shell->gdisp->gimage->gimp->config);
107
shell->title_idle_id = 0;
109
/* format the title */
110
gimp_display_shell_format_title (shell, title, sizeof (title),
111
config->image_title_format);
112
gdk_window_set_title (GTK_WIDGET (shell)->window, title);
114
/* format the statusbar */
115
if (strcmp (config->image_title_format, config->image_status_format))
117
gimp_display_shell_format_title (shell, title, sizeof (title),
118
config->image_status_format);
121
gimp_statusbar_replace (GIMP_STATUSBAR (shell->statusbar), "title", title);
124
#warning FIXME: dont call info_window_update() here.
126
info_window_update (shell->gdisp);
132
static gint print (gchar *buf,
136
...) G_GNUC_PRINTF (4, 5);
148
va_start (args, fmt);
150
printed = g_vsnprintf (buf + start, len - start, fmt, args);
152
printed = len - start;
160
gimp_display_shell_format_title (GimpDisplayShell *shell,
170
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
172
image = shell->gdisp->gimage;
175
gimp_display_shell_scale_get_fraction (shell->scale, &num, &denom);
177
while (i < title_len && *format)
186
/* format string ends within %-sequence, print literal '%' */
192
case 'f': /* pruned filename */
194
const gchar *uri = gimp_image_get_uri (image);
197
basename = file_utils_uri_to_utf8_basename (uri);
199
i += print (title, title_len, i, "%s", basename);
205
case 'F': /* full filename */
208
const gchar *uri = gimp_image_get_uri (image);
210
filename = file_utils_uri_to_utf8_filename (uri);
212
i += print (title, title_len, i, "%s", filename);
218
case 'p': /* PDB id */
219
i += print (title, title_len, i, "%d", gimp_image_get_ID (image));
222
case 'i': /* instance */
223
i += print (title, title_len, i, "%d", shell->gdisp->instance);
228
const gchar *image_type_str = NULL;
229
gboolean empty = gimp_image_is_empty (image);
231
switch (gimp_image_base_type (image))
234
image_type_str = empty ? _("RGB-empty") : _("RGB");
237
image_type_str = empty ? _("grayscale-empty") : _("grayscale");
240
image_type_str = empty ? _("indexed-empty") : _("indexed");
243
g_assert_not_reached ();
247
i += print (title, title_len, i, "%s", image_type_str);
251
case 's': /* user source zoom factor */
252
i += print (title, title_len, i, "%d", denom);
255
case 'd': /* user destination zoom factor */
256
i += print (title, title_len, i, "%d", num);
259
case 'z': /* user zoom factor (percentage) */
260
i += print (title, title_len, i,
261
shell->scale >= 0.15 ? "%.0f" : "%.2f",
265
case 'D': /* dirty flag */
268
/* format string ends within %D-sequence, print literal '%D' */
269
i += print (title, title_len, i, "%%D");
273
title[i++] = format[1];
277
case 'C': /* clean flag */
280
/* format string ends within %C-sequence, print literal '%C' */
281
i += print (title, title_len, i, "%%C");
285
title[i++] = format[1];
289
case 'B': /* dirty flag (long) */
291
i += print (title, title_len, i, "%s",
295
case 'A': /* clean flag (long) */
297
i += print (title, title_len, i, "%s",
301
case 'm': /* memory used by image */
303
GimpObject *object = GIMP_OBJECT (image);
306
str = gimp_memsize_to_string (gimp_object_get_memsize (object,
309
i += print (title, title_len, i, "%s", str);
315
case 'l': /* number of layers */
316
i += print (title, title_len, i, "%d",
317
gimp_container_num_children (image->layers));
320
case 'L': /* number of layers (long) */
322
gint num = gimp_container_num_children (image->layers);
324
i += print (title, title_len, i,
325
num == 1 ? _("1 layer") : _("%d layers"), num);
329
case 'n': /* active drawable name */
331
GimpDrawable *drawable = gimp_image_active_drawable (image);
334
i += print (title, title_len, i, "%s",
335
gimp_object_get_name (GIMP_OBJECT (drawable)));
337
i += print (title, title_len, i, "%s", _("(none)"));
341
case 'P': /* active drawable PDB id */
343
GimpDrawable *drawable = gimp_image_active_drawable (image);
346
i += print (title, title_len, i, "%d",
347
gimp_item_get_ID (GIMP_ITEM (drawable)));
349
i += print (title, title_len, i, "%s", _("(none)"));
353
case 'W': /* width in real-world units */
354
if (shell->unit != GIMP_UNIT_PIXEL)
356
gchar unit_format[8];
358
g_snprintf (unit_format, sizeof (unit_format), "%%.%df",
359
_gimp_unit_get_digits (gimp, shell->unit) + 1);
360
i += print (title, title_len, i, unit_format,
362
_gimp_unit_get_factor (gimp, shell->unit) /
363
image->xresolution));
367
case 'w': /* width in pixels */
368
i += print (title, title_len, i, "%d", image->width);
371
case 'H': /* height in real-world units */
372
if (shell->unit != GIMP_UNIT_PIXEL)
374
gchar unit_format[8];
376
g_snprintf (unit_format, sizeof (unit_format), "%%.%df",
377
_gimp_unit_get_digits (gimp, shell->unit) + 1);
378
i += print (title, title_len, i, unit_format,
380
_gimp_unit_get_factor (gimp, shell->unit) /
381
image->yresolution));
385
case 'h': /* height in pixels */
386
i += print (title, title_len, i, "%d", image->height);
389
case 'u': /* unit symbol */
390
i += print (title, title_len, i, "%s",
391
_gimp_unit_get_symbol (gimp, shell->unit));
394
case 'U': /* unit abbreviation */
395
i += print (title, title_len, i, "%s",
396
_gimp_unit_get_abbreviation (gimp, shell->unit));
399
/* Other cool things to be added:
402
* %� = image's fractal dimension
403
* %� = the answer to everything
407
/* format string contains unknown %-sequence, print it literally */
408
i += print (title, title_len, i, "%%%c", *format);
414
title[i++] = *format;
421
title[MIN (i, title_len - 1)] = '\0';