Re: Message boxes



Deekshit Mantampady wrote:
> 
>   I want to know how o display error message boxes, cofirmation
> boxes(with yes no buttons). Please help me.
> 

Attached is code for a generic confirmation dialog.

Chris
--
pencilnecks on the poop deck
#include <gtk/gtk.h>

#include "yesno.h"

static void yesno_cancel(GtkWidget *, gpointer);

void yesno_dialog(const gchar *msg,
	void (*yescb)(GtkWidget *, gpointer),
	void (*nocb)(GtkWidget *, gpointer),
	gpointer data) {
	GtkWidget *dialog, *widget;

	dialog = gtk_dialog_new();
	gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
	gtk_window_set_title(GTK_WINDOW(dialog), "Confirmation");
	gtk_container_set_border_width(GTK_CONTAINER(dialog), 10);
	gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
		GTK_SIGNAL_FUNC(destroy_dialog_event), dialog);

	widget = gtk_label_new(msg);
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), widget,
		TRUE, TRUE, 5);
	gtk_widget_show(widget);

	widget = gtk_button_new_with_label("OK");
	gtk_signal_connect(GTK_OBJECT(widget), "clicked",
		GTK_SIGNAL_FUNC(yescb), data);
	gtk_object_set_data(GTK_OBJECT(widget), "dialog", dialog);
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), widget,
		TRUE, TRUE, 5);
	gtk_widget_show(widget);

	widget = gtk_button_new_with_label("Cancel");
	if(nocb)
		gtk_signal_connect(GTK_OBJECT(widget), "clicked",
			GTK_SIGNAL_FUNC(nocb), data);
	else
		gtk_signal_connect(GTK_OBJECT(widget), "clicked",
			GTK_SIGNAL_FUNC(yesno_cancel), NULL);
	gtk_object_set_data(GTK_OBJECT(widget), "dialog", dialog);
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), widget,
		TRUE, TRUE, 5);
	gtk_widget_show(widget);

	gtk_widget_show(dialog);
}

/* default callback fo the Cancel button in a `yesno dialog' */
void yesno_cancel(GtkWidget *widget, gpointer data) {
	GtkWidget *dialog = gtk_object_get_data(GTK_OBJECT(widget), "dialog");
	gtk_widget_destroy(GTK_WIDGET(dialog));
}
#ifndef YESNO_DIALOG_H
#define YESNO_DIALOG_H

void yesno_dialog(const gchar *,          /* message to display in dialog */
	void (*yescb)(GtkWidget *, gpointer), /* callback if user presses 'yes' */
	void (*nocb)(GtkWidget *, gpointer),  /* callback if user presses 'no'
	                                         can be NULL - just closes dialog */
	gpointer);                            /* data to pass to callbacks */

#endif /* YESNO_DIALOG_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]