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.
23
#include "libgimpbase/gimpbase.h"
24
#include "libgimpcolor/gimpcolor.h"
25
#include "libgimpwidgets/gimpwidgets.h"
27
#include "dialogs-types.h"
29
#include "core/gimp.h"
30
#include "core/gimpcontainer.h"
31
#include "core/gimpcontext.h"
32
#include "core/gimpimage.h"
33
#include "core/gimppickable.h"
34
#include "core/gimptemplate.h"
35
#include "core/gimpunit.h"
37
#include "display/gimpdisplay.h"
38
#include "display/gimpdisplayshell.h"
40
#include "widgets/gimpcolorframe.h"
41
#include "widgets/gimphelp-ids.h"
42
#include "widgets/gimpviewabledialog.h"
44
#include "info-dialog.h"
45
#include "info-window.h"
47
#include "gimp-intl.h"
52
typedef struct _InfoWinData InfoWinData;
58
gchar dimensions_str[MAX_BUF];
59
gchar real_dimensions_str[MAX_BUF];
60
gchar scale_str[MAX_BUF];
61
gchar num_layers_str[MAX_BUF];
62
gchar memsize_str[MAX_BUF];
63
gchar color_type_str[MAX_BUF];
64
gchar visual_class_str[MAX_BUF];
65
gchar visual_depth_str[MAX_BUF];
66
gchar resolution_str[MAX_BUF];
67
gchar comment_str[MAX_BUF];
69
GtkWidget *pixel_labels[2];
70
GtkWidget *unit_labels[2];
71
GtkWidget *comment_label;
80
/* The different classes of visuals */
81
static const gchar *visual_classes[] =
93
info_window_response (GtkWidget *widget,
97
info_dialog_hide (info_win);
101
info_window_page_switch (GtkWidget *widget,
102
GtkNotebookPage *page,
104
InfoDialog *info_win)
106
InfoWinData *iwd = info_win->user_data;
108
iwd->show_cursor = (page_num == 1);
112
/* displays information:
114
* cursor pos in real units
119
info_window_create_cursor (InfoDialog *info_win,
122
InfoWinData *iwd = info_win->user_data;
128
vbox = gtk_vbox_new (FALSE, 12);
129
gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
130
gtk_notebook_append_page (GTK_NOTEBOOK (info_win->info_notebook),
131
vbox, gtk_label_new (_("Cursor")));
132
gtk_widget_show (vbox);
135
/* cursor information */
137
hbox = gtk_hbox_new (TRUE, 6);
138
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
139
gtk_widget_show (hbox);
141
frame = gimp_frame_new (_("Pixels"));
142
gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
143
gtk_widget_show (frame);
145
table = gtk_table_new (2, 2, FALSE);
146
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
147
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
148
gtk_container_add (GTK_CONTAINER (frame), table);
149
gtk_widget_show (table);
151
iwd->pixel_labels[0] = gtk_label_new (_("n/a"));
152
gtk_misc_set_alignment (GTK_MISC (iwd->pixel_labels[0]), 1.0, 0.5);
153
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
155
iwd->pixel_labels[0], 1, FALSE);
157
iwd->pixel_labels[1] = gtk_label_new (_("n/a"));
158
gtk_misc_set_alignment (GTK_MISC (iwd->pixel_labels[1]), 1.0, 0.5);
159
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
161
iwd->pixel_labels[1], 1, FALSE);
163
frame = gimp_frame_new (_("Units"));
164
gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
165
gtk_widget_show (frame);
167
table = gtk_table_new (2, 2, FALSE);
168
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
169
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
170
gtk_container_add (GTK_CONTAINER (frame), table);
171
gtk_widget_show (table);
173
iwd->unit_labels[0] = gtk_label_new (_("n/a"));
174
gtk_misc_set_alignment (GTK_MISC (iwd->unit_labels[0]), 1.0, 0.5);
175
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
177
iwd->unit_labels[0], 1, FALSE);
179
iwd->unit_labels[1] = gtk_label_new (_("n/a"));
180
gtk_misc_set_alignment (GTK_MISC (iwd->unit_labels[1]), 1.0, 0.5);
181
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
183
iwd->unit_labels[1], 1, FALSE);
186
/* color information */
188
hbox = gtk_hbox_new (TRUE, 6);
189
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
190
gtk_widget_show (hbox);
192
iwd->frame1 = gimp_color_frame_new ();
193
gimp_color_frame_set_mode (GIMP_COLOR_FRAME (iwd->frame1),
194
GIMP_COLOR_FRAME_MODE_PIXEL);
195
gtk_box_pack_start (GTK_BOX (hbox), iwd->frame1, TRUE, TRUE, 0);
196
gtk_widget_show (iwd->frame1);
198
iwd->frame2 = gimp_color_frame_new ();
199
gimp_color_frame_set_mode (GIMP_COLOR_FRAME (iwd->frame2),
200
GIMP_COLOR_FRAME_MODE_RGB);
201
gtk_box_pack_start (GTK_BOX (hbox), iwd->frame2, TRUE, TRUE, 0);
202
gtk_widget_show (iwd->frame2);
205
g_signal_connect (info_win->info_notebook, "switch_page",
206
G_CALLBACK (info_window_page_switch),
211
/* displays gimp-comment parasite
215
info_window_create_comment (InfoDialog *info_win,
218
InfoWinData *iwd = info_win->user_data;
222
GimpParasite *comment;
225
vbox = gtk_vbox_new (FALSE, 12);
226
gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
227
gtk_notebook_append_page (GTK_NOTEBOOK (info_win->info_notebook),
228
vbox, gtk_label_new (_("Comment")));
229
gtk_widget_show (vbox);
231
/* add the information field */
232
vbox2 = gtk_vbox_new (FALSE, 6);
233
gtk_box_pack_start (GTK_BOX (vbox), vbox2, TRUE, TRUE, 0);
234
gtk_widget_show (vbox2);
237
comment = gimp_image_parasite_find (gdisp->gimage, "gimp-comment");
241
gchar *str = g_strndup (gimp_parasite_data (comment),
242
gimp_parasite_data_size (comment));
244
utf8 = gimp_any_to_utf8 (str, -1, NULL);
248
utf8 = g_strdup (_("(none)"));
251
g_snprintf (iwd->comment_str, MAX_BUF, "%s", utf8);
255
label = gtk_label_new (iwd->comment_str);
256
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
257
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
258
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
259
gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
260
gtk_widget_show (label);
261
iwd->comment_label = label;
266
info_window_create (GimpDisplay *gdisp)
268
InfoDialog *info_win;
272
type = gimp_image_base_type (gdisp->gimage);
274
info_win = info_dialog_notebook_new (GIMP_VIEWABLE (gdisp->gimage),
275
_("Info Window"), "gimp-info-window",
277
_("Image Information"),
279
gimp_standard_help_func,
280
GIMP_HELP_INFO_DIALOG);
282
gtk_dialog_add_button (GTK_DIALOG (info_win->shell),
283
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
285
g_signal_connect (info_win->shell, "response",
286
G_CALLBACK (info_window_response),
289
iwd = g_new0 (InfoWinData, 1);
291
info_win->user_data = iwd;
293
/* add the information fields */
294
info_dialog_add_label (info_win, _("Pixel dimensions:"),
295
iwd->dimensions_str);
296
info_dialog_add_label (info_win, _("Print size:"),
297
iwd->real_dimensions_str);
298
info_dialog_add_label (info_win, _("Resolution:"),
299
iwd->resolution_str);
300
info_dialog_add_label (info_win, _("Scale ratio:"),
302
info_dialog_add_label (info_win, _("Number of layers:"),
303
iwd->num_layers_str);
304
info_dialog_add_label (info_win, _("Size in memory:"),
306
info_dialog_add_label (info_win, _("Display type:"),
307
iwd->color_type_str);
308
info_dialog_add_label (info_win, _("Visual class:"),
309
iwd->visual_class_str);
310
info_dialog_add_label (info_win, _("Visual depth:"),
311
iwd->visual_depth_str);
314
info_window_create_cursor (info_win, gdisp->gimage->gimp);
315
info_window_create_comment (info_win, gdisp);
317
/* Set back to first page */
318
gtk_notebook_set_current_page (GTK_NOTEBOOK (info_win->info_notebook), 0);
323
static InfoDialog *info_window_auto = NULL;
326
info_window_change_display (GimpContext *context,
327
GimpDisplay *newdisp,
330
GimpDisplay *gdisp = newdisp;
331
GimpDisplay *old_gdisp;
335
iwd = info_window_auto->user_data;
337
old_gdisp = (GimpDisplay *) iwd->gdisp;
339
if (!info_window_auto || gdisp == old_gdisp || !gdisp)
342
gimage = gdisp->gimage;
344
if (gimage && gimp_container_have (context->gimp->images,
345
GIMP_OBJECT (gimage)))
348
info_window_update (gdisp);
353
info_window_follow_auto (Gimp *gimp)
355
GimpContext *context;
358
g_return_if_fail (GIMP_IS_GIMP (gimp));
360
context = gimp_get_user_context (gimp);
362
gdisp = gimp_context_get_display (context);
367
if (! info_window_auto)
369
info_window_auto = info_window_create (gdisp);
371
g_signal_connect (context, "display_changed",
372
G_CALLBACK (info_window_change_display),
375
info_window_update (gdisp);
378
info_dialog_present (info_window_auto);
382
/* Updates all cursor information. */
385
info_window_update_cursor (GimpDisplay *gdisp,
389
InfoDialog *info_win;
393
info_win = GIMP_DISPLAY_SHELL (gdisp->shell)->info_dialog;
395
if (! info_win && info_window_auto != NULL)
396
info_win = info_window_auto;
401
iwd = info_win->user_data;
403
if (info_window_auto)
405
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (info_window_auto->shell),
406
GIMP_VIEWABLE (gdisp->gimage));
409
if (iwd->gdisp != gdisp)
413
info_window_update (gdisp);
416
gtk_label_set_text (GTK_LABEL (iwd->comment_label), iwd->comment_str);
418
if (! iwd || ! iwd->show_cursor)
421
/* fill in position information */
423
if (tx < 0.0 && ty < 0.0)
425
gtk_label_set_text (GTK_LABEL (iwd->pixel_labels[0]), _("n/a"));
426
gtk_label_set_text (GTK_LABEL (iwd->pixel_labels[1]), _("n/a"));
427
gtk_label_set_text (GTK_LABEL (iwd->unit_labels[0]), _("n/a"));
428
gtk_label_set_text (GTK_LABEL (iwd->unit_labels[1]), _("n/a"));
432
GimpImage *image = gdisp->gimage;
433
GimpUnit unit = GIMP_DISPLAY_SHELL (gdisp->shell)->unit;
436
const gchar *unit_str;
437
gchar format_buf[32];
440
if (unit == GIMP_UNIT_PIXEL)
441
unit = gimp_image_get_unit (image);
443
unit_factor = _gimp_unit_get_factor (image->gimp, unit);
444
unit_digits = _gimp_unit_get_digits (image->gimp, unit);
445
unit_str = _gimp_unit_get_abbreviation (image->gimp, unit);
447
g_snprintf (buf, sizeof (buf), "%d", (gint) tx);
448
gtk_label_set_text (GTK_LABEL (iwd->pixel_labels[0]), buf);
450
g_snprintf (buf, sizeof (buf), "%d", (gint) ty);
451
gtk_label_set_text (GTK_LABEL (iwd->pixel_labels[1]), buf);
453
g_snprintf (format_buf, sizeof (format_buf),
454
"%%.%df %s", unit_digits, unit_str);
456
g_snprintf (buf, sizeof (buf), format_buf,
457
tx * unit_factor / image->xresolution);
458
gtk_label_set_text (GTK_LABEL (iwd->unit_labels[0]), buf);
460
g_snprintf (buf, sizeof (buf), format_buf,
461
ty * unit_factor / image->yresolution);
462
gtk_label_set_text (GTK_LABEL (iwd->unit_labels[1]), buf);
466
/* fill in color information */
467
color = gimp_pickable_get_color_at (GIMP_PICKABLE (gdisp->gimage->projection),
470
if (! color || (tx < 0.0 && ty < 0.0))
472
gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (iwd->frame1));
473
gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (iwd->frame2));
477
GimpImageType sample_type;
480
sample_type = gimp_pickable_get_image_type (GIMP_PICKABLE (gdisp->gimage->projection));
482
gimp_rgba_set_uchar (&rgb,
488
gimp_color_frame_set_color (GIMP_COLOR_FRAME (iwd->frame1),
489
sample_type, &rgb, -1);
490
gimp_color_frame_set_color (GIMP_COLOR_FRAME (iwd->frame2),
491
sample_type, &rgb, -1);
498
info_window_free (InfoDialog *info_win)
502
if (! info_win && info_window_auto)
504
gtk_widget_set_sensitive (info_window_auto->vbox, FALSE);
511
iwd = info_win->user_data;
514
info_dialog_free (info_win);
518
info_window_update (GimpDisplay *gdisp)
520
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (gdisp->shell);
527
gchar format_buf[32];
528
InfoDialog *info_win;
530
info_win = shell->info_dialog;
532
if (! info_win && info_window_auto != NULL)
533
info_win = info_window_auto;
538
iwd = info_win->user_data;
540
if (info_window_auto)
541
gtk_widget_set_sensitive (info_window_auto->vbox, TRUE);
543
/* If doing info_window_auto then return if this display
544
* is not the one we are showing.
546
if (info_window_auto && iwd->gdisp != gdisp)
549
image = gdisp->gimage;
552
g_snprintf (iwd->dimensions_str, MAX_BUF, _("%d x %d pixels"),
553
image->width, image->height);
556
unit = GIMP_DISPLAY_SHELL (gdisp->shell)->unit;
558
if (unit == GIMP_UNIT_PIXEL)
559
unit = gimp_image_get_unit (image);
561
unit_factor = _gimp_unit_get_factor (image->gimp, unit);
562
unit_digits = _gimp_unit_get_digits (image->gimp, unit);
564
g_snprintf (format_buf, sizeof (format_buf), "%%.%df x %%.%df %s",
565
unit_digits + 1, unit_digits + 1,
566
_gimp_unit_get_plural (image->gimp, unit));
567
g_snprintf (iwd->real_dimensions_str, MAX_BUF, format_buf,
568
image->width * unit_factor / image->xresolution,
569
image->height * unit_factor / image->yresolution);
572
unit = gimp_image_get_unit (image);
573
unit_factor = _gimp_unit_get_factor (image->gimp, unit);
575
g_snprintf (format_buf, sizeof (format_buf), _("pixels/%s"),
576
_gimp_unit_get_abbreviation (image->gimp, unit));
577
g_snprintf (iwd->resolution_str, MAX_BUF, _("%g x %g %s"),
578
image->xresolution / unit_factor,
579
image->yresolution / unit_factor,
580
unit == GIMP_UNIT_INCH ? _("dpi") : format_buf);
582
/* user zoom ratio */
583
g_snprintf (iwd->scale_str, MAX_BUF, "%.2f", shell->scale * 100);
585
/* number of layers */
586
g_snprintf (iwd->num_layers_str, MAX_BUF, "%d",
587
gimp_container_num_children (image->layers));
591
GimpObject *object = GIMP_OBJECT (image);
594
str = gimp_memsize_to_string (gimp_object_get_memsize (object, NULL));
596
g_snprintf (iwd->memsize_str, MAX_BUF, "%s", str);
601
type = gimp_image_base_type (image);
607
g_snprintf (iwd->color_type_str, MAX_BUF, "%s", _("RGB Color"));
610
g_snprintf (iwd->color_type_str, MAX_BUF, "%s", _("Grayscale"));
613
g_snprintf (iwd->color_type_str, MAX_BUF, "%s (%d %s)",
614
_("Indexed Color"), image->num_cols, _("colors"));
620
GimpParasite *comment;
623
comment = gimp_image_parasite_find (gdisp->gimage, "gimp-comment");
627
gchar *str = g_strndup (gimp_parasite_data (comment),
628
gimp_parasite_data_size (comment));
630
utf8 = gimp_any_to_utf8 (str, -1, NULL);
634
utf8 = g_strdup (_("(none)"));
637
g_snprintf (iwd->comment_str, MAX_BUF, "%s", utf8);
643
GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (shell));
644
GdkVisual *visual = gdk_screen_get_rgb_visual (screen);
647
g_snprintf (iwd->visual_class_str, MAX_BUF, "%s",
648
gettext (visual_classes[visual->type]));
651
g_snprintf (iwd->visual_depth_str, MAX_BUF, "%d", visual->depth);
654
info_dialog_update (info_win);