1998-12-07 15:19:00 +00:00
|
|
|
/* example-start buttons buttons.c */
|
1998-03-28 01:01:54 +00:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Create a new hbox with an image and a label packed into it
|
|
|
|
* and return the box. */
|
1998-03-28 01:01:54 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
GtkWidget *xpm_label_box( GtkWidget *parent,
|
|
|
|
gchar *xpm_filename,
|
|
|
|
gchar *label_text )
|
1998-03-28 01:01:54 +00:00
|
|
|
{
|
|
|
|
GtkWidget *box1;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *pixmapwid;
|
|
|
|
GdkPixmap *pixmap;
|
|
|
|
GdkBitmap *mask;
|
|
|
|
GtkStyle *style;
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Create box for xpm and label */
|
1998-03-28 01:01:54 +00:00
|
|
|
box1 = gtk_hbox_new (FALSE, 0);
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (box1), 2);
|
1998-03-28 01:01:54 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Get the style of the button to get the
|
|
|
|
* background color. */
|
1998-03-28 01:01:54 +00:00
|
|
|
style = gtk_widget_get_style(parent);
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Now on to the xpm stuff */
|
1998-03-28 01:01:54 +00:00
|
|
|
pixmap = gdk_pixmap_create_from_xpm (parent->window, &mask,
|
|
|
|
&style->bg[GTK_STATE_NORMAL],
|
|
|
|
xpm_filename);
|
|
|
|
pixmapwid = gtk_pixmap_new (pixmap, mask);
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Create a label for the button */
|
1998-03-28 01:01:54 +00:00
|
|
|
label = gtk_label_new (label_text);
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Pack the pixmap and label into the box */
|
1998-03-28 01:01:54 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box1),
|
|
|
|
pixmapwid, FALSE, FALSE, 3);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 3);
|
|
|
|
|
|
|
|
gtk_widget_show(pixmapwid);
|
|
|
|
gtk_widget_show(label);
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
return(box1);
|
1998-03-28 01:01:54 +00:00
|
|
|
}
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Our usual callback function */
|
|
|
|
void callback( GtkWidget *widget,
|
|
|
|
gpointer data )
|
1998-03-28 01:01:54 +00:00
|
|
|
{
|
|
|
|
g_print ("Hello again - %s was pressed\n", (char *) data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
int main( int argc,
|
|
|
|
char *argv[] )
|
1998-03-28 01:01:54 +00:00
|
|
|
{
|
|
|
|
/* GtkWidget is the storage type for widgets */
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *box1;
|
|
|
|
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Create a new window */
|
1998-03-28 01:01:54 +00:00
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Pixmap'd Buttons!");
|
|
|
|
|
|
|
|
/* It's a good idea to do this for all windows. */
|
|
|
|
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
|
|
|
GTK_SIGNAL_FUNC (gtk_exit), NULL);
|
|
|
|
|
|
|
|
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
|
|
|
|
GTK_SIGNAL_FUNC (gtk_exit), NULL);
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Sets the border width of the window. */
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
|
1998-03-28 01:01:54 +00:00
|
|
|
gtk_widget_realize(window);
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Create a new button */
|
1998-03-28 01:01:54 +00:00
|
|
|
button = gtk_button_new ();
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Connect the "clicked" signal of the button to our callback */
|
1998-03-28 01:01:54 +00:00
|
|
|
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
|
|
|
GTK_SIGNAL_FUNC (callback), (gpointer) "cool button");
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* This calls our box creating function */
|
1998-03-28 01:01:54 +00:00
|
|
|
box1 = xpm_label_box(window, "info.xpm", "cool button");
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Pack and show all our widgets */
|
1998-03-28 01:01:54 +00:00
|
|
|
gtk_widget_show(box1);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (button), box1);
|
|
|
|
|
|
|
|
gtk_widget_show(button);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), button);
|
|
|
|
|
|
|
|
gtk_widget_show (window);
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Rest in gtk_main and wait for the fun to begin! */
|
1998-03-28 01:01:54 +00:00
|
|
|
gtk_main ();
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
return(0);
|
1998-03-28 01:01:54 +00:00
|
|
|
}
|
1998-12-07 15:19:00 +00:00
|
|
|
/* example-end */
|