/*
 * Gnophone: A client for the Asterisk PBX
 *
 * Copyright (C) 2000, Linux Support Services, Inc.
 *
 * Written by Mark Spencer
 *
 * Linux/UNIX version distributed under the terms of
 * the GNU General Public License
 *
 * utils.c: Various tools that are used in several files
 *
 */

#include <gtk/gtk.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>

GtkWidget *image_button_new(GtkWidget *win, int type, char *text, char **xpm)
{
	GtkWidget *button;
	GdkPixmap *pm;
	GdkBitmap *bm;
	GtkWidget *pixmap;
	GtkWidget *label;
	GtkWidget *hbox;

	if (type == 0)
		button = gtk_button_new();
	else if (type == 1)
		button = gtk_toggle_button_new();
	else
		button = gtk_button_new();

	hbox = gtk_hbox_new(FALSE, 0);

	label = gtk_label_new(text);
	pm = gdk_pixmap_create_from_xpm_d(win->window, &bm, NULL, xpm);
	pixmap = gtk_pixmap_new(pm, bm);

	/* We wanna left align the label and right align the pixmap */
	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
	gtk_misc_set_alignment(GTK_MISC(pixmap), 1.0, 0.5);

	gtk_box_pack_start(GTK_BOX(hbox), pixmap, TRUE, TRUE, 2);
	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 2);

	gtk_container_add(GTK_CONTAINER(button), hbox);

	gtk_container_set_border_width(GTK_CONTAINER(button), 5);

	gtk_widget_show_all(GTK_WIDGET(button));

	gtk_widget_set_usize(GTK_WIDGET(button), -1, 40);

	gdk_pixmap_unref(pm);
	gdk_bitmap_unref(bm);

	return button;
}
