File: xpm_button.c

package info (click to toggle)
xfreecd 0.7.8-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 788 kB
  • ctags: 332
  • sloc: ansic: 5,266; makefile: 65
file content (67 lines) | stat: -rw-r--r-- 2,507 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* -----------------------------------------------------------------------
   xpm button routines for XfreeCD
   
   Copyright 1998 by Brian C. Lane
   ----------------------------------------------------------------------- */
#include <gtk/gtk.h>
#include "xpm_button.h"

/* Create a button with 2 xpm pixmaps for pressed and unpressed states */
GtkWidget *xpm_button( GtkWidget *parent, struct _pbutton *pb )
{
  GtkWidget	*event_box;
  GtkWidget	*hbox;
  GtkStyle	*style;

  /* get style of button.. I assume it's to get the background color.
   * if someone knows the real reason, please enlighten me. */
  style = gtk_widget_get_style( parent );

  /* Make a hbox to hold the image */
  hbox = gtk_hbox_new( FALSE, 0 );
  gtk_container_border_width( GTK_CONTAINER( hbox ), 0 );

  /* now on to the xpm stuff.. load xpm */
  pb->image.up_pixmap = gdk_pixmap_create_from_xpm_d (parent->window,
                                       &pb->image.up_mask,
                                       &style->bg[GTK_STATE_NORMAL],
                                       (gchar **) pb->up_xpm);

  pb->image.dn_pixmap = gdk_pixmap_create_from_xpm_d (parent->window,
                                       &pb->image.dn_mask,
                                       &style->bg[GTK_STATE_NORMAL],
                                       (gchar **) pb->dn_xpm);

  /* Start with the up image */
  pb->wid = gtk_pixmap_new (pb->image.up_pixmap, pb->image.up_mask);

  gtk_box_pack_start (GTK_BOX (hbox), pb->wid, FALSE, FALSE, 0);

  gtk_widget_show(pb->wid);
     
  /* Create the event box that will hold the image and callbacks */
  event_box = gtk_event_box_new();
/*  gtk_container_add (GTK_CONTAINER(parent), event_box);          
 * gtk_widget_show (event_box);
 */

  /* Add the box containing the image to the button */
  gtk_container_add (GTK_CONTAINER (event_box), hbox);  

  /* Make sure that the image is visible */
  gtk_widget_show( hbox );

  /* Set the clipping size (this should come from the pixmap somehow) */
/*  gtk_widget_set_usize (hbox, 29, 30); */

  /* Add the callback functions */
  gtk_widget_set_events( event_box, GDK_BUTTON_PRESS_MASK |
                                    GDK_BUTTON_RELEASE_MASK );

  gtk_signal_connect (GTK_OBJECT (event_box), "button_press_event",
                      GTK_SIGNAL_FUNC (pb->press), NULL );
  gtk_signal_connect (GTK_OBJECT (event_box), "button_release_event",
                      GTK_SIGNAL_FUNC (pb->release), NULL );

  return( event_box );
}