home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / imagemap / imap_statusbar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-25  |  4.7 KB  |  157 lines

  1. /*
  2.  * This is a plug-in for the GIMP.
  3.  *
  4.  * Generates clickable image maps.
  5.  *
  6.  * Copyright (C) 1998-1999 Maurits Rijk  lpeek.mrijk@consunet.nl
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21.  *
  22.  */
  23.  
  24. #include <stdarg.h>
  25. #include <stdio.h>
  26.  
  27. #include "coord.xpm"
  28. #include "dimension.xpm"
  29.  
  30. #include "imap_statusbar.h"
  31.  
  32. StatusBar_t*
  33. make_statusbar(GtkWidget *main_vbox, GtkWidget *window)
  34. {
  35.    StatusBar_t     *statusbar = g_new(StatusBar_t, 1);
  36.    GtkWidget     *hbox, *iconw;
  37.    GdkPixmap     *icon;
  38.    GdkBitmap     *mask;
  39.    GtkStyle      *style;
  40.  
  41.    hbox = gtk_hbox_new(FALSE, 1);
  42.    gtk_box_pack_start(GTK_BOX(main_vbox), hbox, FALSE, FALSE, 0);
  43.  
  44.    /* Status info */
  45.    statusbar->status = gtk_statusbar_new();
  46.    statusbar->status_id = gtk_statusbar_get_context_id(
  47.       GTK_STATUSBAR(statusbar->status), "general_status");
  48.    gtk_box_pack_start(GTK_BOX(hbox), statusbar->status, TRUE, TRUE, 0);
  49.    gtk_widget_show(statusbar->status);
  50.  
  51.    /* (x, y) coordinate */
  52.    style = gtk_widget_get_style(window);
  53.    icon = gdk_pixmap_create_from_xpm_d(window->window, &mask,
  54.                        &style->bg[GTK_STATE_NORMAL], 
  55.                        coord_xpm);
  56.    iconw = gtk_pixmap_new(icon, mask);
  57.    gtk_box_pack_start(GTK_BOX(hbox), iconw, FALSE, FALSE, 10);
  58.    gtk_widget_show(iconw);
  59.  
  60.    statusbar->xy = gtk_entry_new();
  61.    gtk_widget_set_usize(statusbar->xy, 64, -1);
  62.    gtk_entry_set_editable(GTK_ENTRY(statusbar->xy), FALSE);
  63.    GTK_WIDGET_UNSET_FLAGS(statusbar->xy, GTK_CAN_FOCUS);
  64.    gtk_box_pack_start(GTK_BOX(hbox), statusbar->xy, FALSE, FALSE, 0);
  65.    gtk_widget_show(statusbar->xy);
  66.  
  67.    /* Dimension info */
  68.    icon = gdk_pixmap_create_from_xpm_d(window->window, &mask,
  69.                        &style->bg[GTK_STATE_NORMAL], 
  70.                        dimension_xpm);
  71.    iconw = gtk_pixmap_new(icon, mask); 
  72.    gtk_box_pack_start(GTK_BOX(hbox), iconw, FALSE, FALSE, 10);
  73.    gtk_widget_show(iconw);
  74.  
  75.    statusbar->dimension = gtk_entry_new();
  76.    gtk_widget_set_usize(statusbar->dimension, 64, -1);
  77.    gtk_entry_set_editable(GTK_ENTRY(statusbar->dimension), FALSE);
  78.    GTK_WIDGET_UNSET_FLAGS(statusbar->dimension, GTK_CAN_FOCUS);
  79.    gtk_box_pack_start(GTK_BOX(hbox), statusbar->dimension, FALSE, FALSE, 0);
  80.    gtk_widget_show(statusbar->dimension);
  81.  
  82.    /* Zoom info */
  83.    statusbar->zoom = gtk_statusbar_new();
  84.    statusbar->zoom_id = gtk_statusbar_get_context_id(
  85.       GTK_STATUSBAR(statusbar->zoom), "zoom_status");
  86.    gtk_box_pack_start(GTK_BOX(hbox), statusbar->zoom, FALSE, FALSE, 5);
  87.    gtk_widget_show(statusbar->zoom);
  88.  
  89.    gtk_widget_show(hbox);
  90.  
  91.    return statusbar;
  92. }
  93.  
  94. void 
  95. statusbar_set_status(StatusBar_t *statusbar, const gchar *format, ...)
  96. {
  97.    va_list ap;
  98.    char scratch[256];
  99.  
  100.    va_start(ap, format);
  101.    vsprintf(scratch, format, ap);
  102.    va_end(ap);
  103.  
  104.    statusbar_clear_status(statusbar);
  105.    statusbar->message_id = 
  106.             gtk_statusbar_push(GTK_STATUSBAR(statusbar->status), 
  107.                        statusbar->status_id, scratch);
  108. }
  109.  
  110. void 
  111. statusbar_clear_status(StatusBar_t *statusbar)
  112. {
  113.    if (statusbar->message_id)
  114.       gtk_statusbar_remove(GTK_STATUSBAR(statusbar->status), 
  115.                statusbar->status_id,
  116.                statusbar->message_id);
  117. }
  118.  
  119. void 
  120. statusbar_set_xy(StatusBar_t *statusbar, gint x, gint y)
  121. {
  122.    char scratch[16];
  123.  
  124.    sprintf(scratch, "%d, %d", (int) x, (int) y);
  125.    gtk_entry_set_text(GTK_ENTRY(statusbar->xy), scratch);
  126. }
  127.  
  128. void statusbar_clear_xy(StatusBar_t *statusbar)
  129. {
  130.    gtk_entry_set_text(GTK_ENTRY(statusbar->xy), "");
  131. }
  132.  
  133. void 
  134. statusbar_set_dimension(StatusBar_t *statusbar, gint w, gint h)
  135. {
  136.    char scratch[16];
  137.  
  138.    sprintf(scratch, "%d x %d", (int) w, (int) h);
  139.    gtk_entry_set_text(GTK_ENTRY(statusbar->dimension), scratch);
  140. }
  141.  
  142. void 
  143. statusbar_clear_dimension(StatusBar_t *statusbar)
  144. {
  145.    gtk_entry_set_text(GTK_ENTRY(statusbar->dimension), "");
  146. }
  147.  
  148. void 
  149. statusbar_set_zoom(StatusBar_t *statusbar, gint factor)
  150. {
  151.    char scratch[16];
  152.  
  153.    sprintf(scratch, "1:%d", factor);
  154.    gtk_statusbar_push(GTK_STATUSBAR(statusbar->zoom), statusbar->zoom_id, 
  155.               scratch);
  156. }
  157.