xfreecd

Audio CD player for X
git clone https://www.brianlane.com/git/xfreecd
Log | Files | Refs | README | LICENSE

xpm_button.c (2507B)


      1 /* -----------------------------------------------------------------------
      2    xpm button routines for XfreeCD
      3    
      4    Copyright 1998 by Brian C. Lane
      5    ----------------------------------------------------------------------- */
      6 #include <gtk/gtk.h>
      7 #include "xpm_button.h"
      8 
      9 /* Create a button with 2 xpm pixmaps for pressed and unpressed states */
     10 GtkWidget *xpm_button( GtkWidget *parent, struct _pbutton *pb )
     11 {
     12   GtkWidget	*event_box;
     13   GtkWidget	*hbox;
     14   GtkStyle	*style;
     15 
     16   /* get style of button.. I assume it's to get the background color.
     17    * if someone knows the real reason, please enlighten me. */
     18   style = gtk_widget_get_style( parent );
     19 
     20   /* Make a hbox to hold the image */
     21   hbox = gtk_hbox_new( FALSE, 0 );
     22   gtk_container_border_width( GTK_CONTAINER( hbox ), 0 );
     23 
     24   /* now on to the xpm stuff.. load xpm */
     25   pb->image.up_pixmap = gdk_pixmap_create_from_xpm_d (parent->window,
     26                                        &pb->image.up_mask,
     27                                        &style->bg[GTK_STATE_NORMAL],
     28                                        (gchar **) pb->up_xpm);
     29 
     30   pb->image.dn_pixmap = gdk_pixmap_create_from_xpm_d (parent->window,
     31                                        &pb->image.dn_mask,
     32                                        &style->bg[GTK_STATE_NORMAL],
     33                                        (gchar **) pb->dn_xpm);
     34 
     35   /* Start with the up image */
     36   pb->wid = gtk_pixmap_new (pb->image.up_pixmap, pb->image.up_mask);
     37 
     38   gtk_box_pack_start (GTK_BOX (hbox), pb->wid, FALSE, FALSE, 0);
     39 
     40   gtk_widget_show(pb->wid);
     41      
     42   /* Create the event box that will hold the image and callbacks */
     43   event_box = gtk_event_box_new();
     44 /*  gtk_container_add (GTK_CONTAINER(parent), event_box);          
     45  * gtk_widget_show (event_box);
     46  */
     47 
     48   /* Add the box containing the image to the button */
     49   gtk_container_add (GTK_CONTAINER (event_box), hbox);  
     50 
     51   /* Make sure that the image is visible */
     52   gtk_widget_show( hbox );
     53 
     54   /* Set the clipping size (this should come from the pixmap somehow) */
     55 /*  gtk_widget_set_usize (hbox, 29, 30); */
     56 
     57   /* Add the callback functions */
     58   gtk_widget_set_events( event_box, GDK_BUTTON_PRESS_MASK |
     59                                     GDK_BUTTON_RELEASE_MASK );
     60 
     61   gtk_signal_connect (GTK_OBJECT (event_box), "button_press_event",
     62                       GTK_SIGNAL_FUNC (pb->press), NULL );
     63   gtk_signal_connect (GTK_OBJECT (event_box), "button_release_event",
     64                       GTK_SIGNAL_FUNC (pb->release), NULL );
     65 
     66   return( event_box );
     67 }