home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / app / ops_buttons.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-03  |  4.2 KB  |  151 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  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.
  8.  *
  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.
  13.  *
  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.
  17.  */
  18. #include "config.h"
  19.  
  20. #include <gtk/gtk.h>
  21.  
  22. #include "gimphelp.h"
  23. #include "ops_buttons.h"
  24.  
  25. #include "libgimp/gimppixmap.h"
  26.  
  27. #include "libgimp/gimpintl.h"
  28.  
  29. static void ops_button_pressed_callback  (GtkWidget      *widget,
  30.                       GdkEventButton *bevent,
  31.                       gpointer        data);
  32. static void ops_button_extended_callback (GtkWidget      *widget,
  33.                       gpointer        data);
  34.  
  35.  
  36. GtkWidget *
  37. ops_button_box_new (OpsButton     *ops_button,
  38.             OpsButtonType  ops_type)   
  39. {
  40.   GtkWidget *button;
  41.   GtkWidget *button_box;
  42.   GtkWidget *pixmap;
  43.   GSList    *group = NULL;
  44.  
  45.   button_box = gtk_hbox_new (TRUE, 1);
  46.  
  47.   while (ops_button->xpm_data)
  48.     {
  49.       pixmap = gimp_pixmap_new (ops_button->xpm_data);
  50.  
  51.       switch (ops_type)
  52.     {
  53.     case OPS_BUTTON_NORMAL:
  54.       button = gtk_button_new ();
  55.       break;
  56.  
  57.     case OPS_BUTTON_RADIO:
  58.       button = gtk_radio_button_new (group);
  59.       group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
  60.       gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
  61.       break;
  62.  
  63.     default:
  64.       g_warning ("ops_button_box_new: unknown type %d\n", ops_type);
  65.       continue;
  66.     }
  67.  
  68.       gtk_container_add (GTK_CONTAINER (button), pixmap);
  69.  
  70.       if (ops_button->ext_callbacks == NULL)
  71.     {
  72.       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
  73.                      GTK_SIGNAL_FUNC (ops_button->callback),
  74.                      NULL);
  75.     }
  76.       else
  77.     {
  78.       gtk_signal_connect (GTK_OBJECT (button), "button_press_event",
  79.                   GTK_SIGNAL_FUNC (ops_button_pressed_callback),
  80.                   ops_button);      
  81.       gtk_signal_connect (GTK_OBJECT (button), "clicked",
  82.                   GTK_SIGNAL_FUNC (ops_button_extended_callback),
  83.                   ops_button);
  84.     }
  85.  
  86.       gimp_help_set_help_data (button,
  87.                    gettext (ops_button->tooltip),
  88.                    ops_button->private_tip);
  89.  
  90.       gtk_box_pack_start (GTK_BOX (button_box), button, TRUE, TRUE, 0); 
  91.  
  92.       gtk_widget_show (pixmap);
  93.       gtk_widget_show (button);
  94.  
  95.       ops_button->widget = button;
  96.       ops_button->modifier = OPS_BUTTON_MODIFIER_NONE;
  97.  
  98.       ops_button++;
  99.     }
  100.  
  101.   return button_box;
  102. }
  103.  
  104. static void
  105. ops_button_pressed_callback (GtkWidget      *widget, 
  106.                  GdkEventButton *bevent,
  107.                  gpointer        data)
  108. {
  109.   OpsButton *ops_button;
  110.  
  111.   g_return_if_fail (data != NULL);
  112.   ops_button = (OpsButton *) data;
  113.  
  114.   if (bevent->state & GDK_SHIFT_MASK)
  115.     {
  116.       if (bevent->state & GDK_CONTROL_MASK)
  117.       ops_button->modifier = OPS_BUTTON_MODIFIER_SHIFT_CTRL;
  118.       else 
  119.     ops_button->modifier = OPS_BUTTON_MODIFIER_SHIFT;
  120.     }
  121.   else if (bevent->state & GDK_CONTROL_MASK)
  122.     ops_button->modifier = OPS_BUTTON_MODIFIER_CTRL;
  123.   else if (bevent->state & GDK_MOD1_MASK)
  124.     ops_button->modifier = OPS_BUTTON_MODIFIER_ALT;
  125.   else 
  126.     ops_button->modifier = OPS_BUTTON_MODIFIER_NONE;
  127. }
  128.  
  129. static void
  130. ops_button_extended_callback (GtkWidget *widget, 
  131.                   gpointer   data)
  132. {
  133.   OpsButton *ops_button;
  134.  
  135.   g_return_if_fail (data != NULL);
  136.   ops_button = (OpsButton *) data;
  137.  
  138.   if (ops_button->modifier > OPS_BUTTON_MODIFIER_NONE &&
  139.       ops_button->modifier < OPS_BUTTON_MODIFIER_LAST)
  140.     {
  141.       if (ops_button->ext_callbacks[ops_button->modifier - 1] != NULL)
  142.     (ops_button->ext_callbacks[ops_button->modifier - 1]) (widget, NULL);
  143.       else
  144.     (ops_button->callback) (widget, NULL);
  145.     } 
  146.   else 
  147.     (ops_button->callback) (widget, NULL);
  148.  
  149.   ops_button->modifier = OPS_BUTTON_MODIFIER_NONE;
  150. }
  151.