imap_statusbar.c 4.52 KB
Newer Older
Sven Neumann's avatar
Sven Neumann committed
1
/*
2
 * This is a plug-in for GIMP.
Sven Neumann's avatar
Sven Neumann committed
3 4 5
 *
 * Generates clickable image maps.
 *
6
 * Copyright (C) 1998-2003 Maurits Rijk  lpeek.mrijk@consunet.nl
Sven Neumann's avatar
Sven Neumann committed
7
 *
8
 * This program is free software: you can redistribute it and/or modify
Sven Neumann's avatar
Sven Neumann committed
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
Sven Neumann's avatar
Sven Neumann committed
11 12 13 14 15 16 17 18
 * (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
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Sven Neumann's avatar
Sven Neumann committed
20 21 22
 *
 */

23 24
#include "config.h"

Sven Neumann's avatar
Sven Neumann committed
25 26 27
#include <stdarg.h>
#include <stdio.h>

28
#include <gtk/gtk.h>
Sven Neumann's avatar
Sven Neumann committed
29

30 31
#include <libgimpwidgets/gimpwidgets.h>

Sven Neumann's avatar
Sven Neumann committed
32
#include "imap_statusbar.h"
33
#include "imap_stock.h"
34

Sven Neumann's avatar
Sven Neumann committed
35 36 37
StatusBar_t*
make_statusbar(GtkWidget *main_vbox, GtkWidget *window)
{
38 39
   StatusBar_t  *statusbar = g_new(StatusBar_t, 1);
   GtkWidget    *hbox, *iconw;
Sven Neumann's avatar
Sven Neumann committed
40

41
   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 1);
Sven Neumann's avatar
Sven Neumann committed
42 43 44 45 46 47 48 49 50 51
   gtk_box_pack_start(GTK_BOX(main_vbox), hbox, FALSE, FALSE, 0);

   /* Status info */
   statusbar->status = gtk_statusbar_new();
   statusbar->status_id = gtk_statusbar_get_context_id(
      GTK_STATUSBAR(statusbar->status), "general_status");
   gtk_box_pack_start(GTK_BOX(hbox), statusbar->status, TRUE, TRUE, 0);
   gtk_widget_show(statusbar->status);

   /* (x, y) coordinate */
52
   iconw = gtk_image_new_from_stock(IMAP_STOCK_COORD,
53
                                    GTK_ICON_SIZE_SMALL_TOOLBAR);
54

Sven Neumann's avatar
Sven Neumann committed
55 56 57 58
   gtk_box_pack_start(GTK_BOX(hbox), iconw, FALSE, FALSE, 10);
   gtk_widget_show(iconw);

   statusbar->xy = gtk_entry_new();
59 60
   gtk_widget_set_size_request(statusbar->xy, 96, -1);
   gtk_editable_set_editable(GTK_EDITABLE(statusbar->xy), FALSE);
61
   gtk_widget_set_can_focus (statusbar->xy, FALSE);
Sven Neumann's avatar
Sven Neumann committed
62 63 64 65
   gtk_box_pack_start(GTK_BOX(hbox), statusbar->xy, FALSE, FALSE, 0);
   gtk_widget_show(statusbar->xy);

   /* Dimension info */
66
   iconw = gtk_image_new_from_stock(IMAP_STOCK_DIMENSION,
67
                                    GTK_ICON_SIZE_SMALL_TOOLBAR);
Sven Neumann's avatar
Sven Neumann committed
68 69 70 71
   gtk_box_pack_start(GTK_BOX(hbox), iconw, FALSE, FALSE, 10);
   gtk_widget_show(iconw);

   statusbar->dimension = gtk_entry_new();
72 73
   gtk_widget_set_size_request(statusbar->dimension, 96, -1);
   gtk_editable_set_editable(GTK_EDITABLE(statusbar->dimension), FALSE);
74
   gtk_widget_set_can_focus (statusbar->dimension, FALSE);
Sven Neumann's avatar
Sven Neumann committed
75 76 77 78 79
   gtk_box_pack_start(GTK_BOX(hbox), statusbar->dimension, FALSE, FALSE, 0);
   gtk_widget_show(statusbar->dimension);

   /* Zoom info */
   statusbar->zoom = gtk_statusbar_new();
80
   gtk_widget_set_size_request(statusbar->zoom, 48, -1);
Sven Neumann's avatar
Sven Neumann committed
81 82 83 84 85 86 87 88 89 90
   statusbar->zoom_id = gtk_statusbar_get_context_id(
      GTK_STATUSBAR(statusbar->zoom), "zoom_status");
   gtk_box_pack_start(GTK_BOX(hbox), statusbar->zoom, FALSE, FALSE, 5);
   gtk_widget_show(statusbar->zoom);

   gtk_widget_show(hbox);

   return statusbar;
}

91
void
Sven Neumann's avatar
Sven Neumann committed
92 93 94 95 96 97 98 99 100 101
statusbar_set_status(StatusBar_t *statusbar, const gchar *format, ...)
{
   va_list ap;
   char scratch[256];

   va_start(ap, format);
   vsprintf(scratch, format, ap);
   va_end(ap);

   statusbar_clear_status(statusbar);
102
   statusbar->message_id =
103 104
                        gtk_statusbar_push(GTK_STATUSBAR(statusbar->status),
                                           statusbar->status_id, scratch);
Sven Neumann's avatar
Sven Neumann committed
105 106
}

107
void
Sven Neumann's avatar
Sven Neumann committed
108 109 110
statusbar_clear_status(StatusBar_t *statusbar)
{
   if (statusbar->message_id)
111
      gtk_statusbar_remove(GTK_STATUSBAR(statusbar->status),
112 113
                           statusbar->status_id,
                           statusbar->message_id);
Sven Neumann's avatar
Sven Neumann committed
114 115
}

116
void
Sven Neumann's avatar
Sven Neumann committed
117 118 119
statusbar_set_xy(StatusBar_t *statusbar, gint x, gint y)
{
   char scratch[16];
120

Sven Neumann's avatar
Sven Neumann committed
121 122 123 124 125 126 127 128 129
   sprintf(scratch, "%d, %d", (int) x, (int) y);
   gtk_entry_set_text(GTK_ENTRY(statusbar->xy), scratch);
}

void statusbar_clear_xy(StatusBar_t *statusbar)
{
   gtk_entry_set_text(GTK_ENTRY(statusbar->xy), "");
}

130
void
Sven Neumann's avatar
Sven Neumann committed
131 132
statusbar_set_dimension(StatusBar_t *statusbar, gint w, gint h)
{
133
   gchar scratch[16];
134

135
   g_snprintf (scratch, sizeof (scratch), "%d × %d", (gint) w, (gint) h);
Sven Neumann's avatar
Sven Neumann committed
136 137 138
   gtk_entry_set_text(GTK_ENTRY(statusbar->dimension), scratch);
}

139
void
Sven Neumann's avatar
Sven Neumann committed
140 141 142 143 144
statusbar_clear_dimension(StatusBar_t *statusbar)
{
   gtk_entry_set_text(GTK_ENTRY(statusbar->dimension), "");
}

145
void
Sven Neumann's avatar
Sven Neumann committed
146 147 148
statusbar_set_zoom(StatusBar_t *statusbar, gint factor)
{
   char scratch[16];
149

Sven Neumann's avatar
Sven Neumann committed
150
   sprintf(scratch, "1:%d", factor);
151
   gtk_statusbar_push(GTK_STATUSBAR(statusbar->zoom), statusbar->zoom_id,
152
                      scratch);
Sven Neumann's avatar
Sven Neumann committed
153
}