diff options
author | Ian C <ianc@noddybox.co.uk> | 2006-08-28 22:40:44 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2006-08-28 22:40:44 +0000 |
commit | cb4cd60cbce11439b0e0529df20e671e5b49b6f1 (patch) | |
tree | 4e8e3acda1e587b7ff011a5f6f0bae2b1815441b /gtkutil.c | |
parent | 94a1cc07e45c2d7dbbe076353800731597a1cb7f (diff) |
Moved dialog to gtkutil
Diffstat (limited to 'gtkutil.c')
-rw-r--r-- | gtkutil.c | 239 |
1 files changed, 239 insertions, 0 deletions
diff --git a/gtkutil.c b/gtkutil.c new file mode 100644 index 0000000..da08e1b --- /dev/null +++ b/gtkutil.c @@ -0,0 +1,239 @@ +/* + + z80 - Z80 Emulation + + Copyright (C) 2006 Ian Cowburn (ianc@noddybox.demon.co.uk) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ------------------------------------------------------------------------- + + Simple dialogs + + $Id$ + +*/ + +/* ---------------------------------------- INCLUDES +*/ +#include <stdio.h> +#include <string.h> +#include <stdarg.h> + +#include "gtkutil.h" + + +/* ---------------------------------------- CONSTS +*/ + +/* ---------------------------------------- GLOBALS +*/ +static GtkWidget *parent; +static GtkWidget *dialog; + +static int dial_done=FALSE; +static int selected=FALSE; + +static char saved_path[PATH_MAX+1]; + + +/* ---------------------------------------- CALLBACKS +*/ +static void Callback(GtkWidget *w, gpointer data) +{ + dial_done=TRUE; + selected=(int)data; + gtk_widget_destroy(dialog); +} + + +static gint DestroyCB(GtkWidget *w, GdkEvent *ev, gpointer data) +{ + Callback(w,data); + return TRUE; +} + + +static gint NoDestroyCB(GtkWidget *w, GdkEvent *ev, gpointer data) +{ + dial_done=TRUE; + selected=(int)data; + return TRUE; +} + + +static void FselCallback(GtkWidget *w, gpointer data) +{ + dial_done=TRUE; + selected=(int)data; + + if (selected) + strcpy(saved_path, + gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog))); +} + + +/* ---------------------------------------- DialogParent() +*/ +void DialogParent(GtkWidget *w) +{ + parent=w; +} + + +/* ---------------------------------------- DialogOK() +*/ +void DialogOK(const char *format, ...) +{ + va_list va; + char text[1024]; + GtkWidget *button; + GtkWidget *label; + + va_start(va,format); + vsnprintf(text,sizeof text,format,va); + va_end(va); + + dialog=gtk_dialog_new(); + gtk_window_set_title (GTK_WINDOW (dialog), "GEMMA -- Alert"); + button=gtk_button_new_with_label("OK"); + label=gtk_label_new(text); + + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), + button,TRUE,TRUE,0); + + gtk_container_set_border_width(GTK_CONTAINER(dialog),10); + + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), + label,TRUE,TRUE,0); + + gtk_signal_connect_object(GTK_OBJECT (button),"clicked", + GTK_SIGNAL_FUNC (gtk_widget_destroy), + GTK_OBJECT (dialog)); + + gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parent)); + gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); + gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ON_PARENT); + + gtk_widget_show(button); + gtk_widget_show(label); + gtk_widget_show(dialog); +} + + +/* ---------------------------------------- DialogYesNo() +*/ +int DialogYesNo(const char *format, ...) +{ + va_list va; + char text[1024]; + GtkWidget *yes; + GtkWidget *no; + GtkWidget *label; + + va_start(va,format); + vsnprintf(text,sizeof text,format,va); + va_end(va); + + dialog=gtk_dialog_new(); + gtk_window_set_title (GTK_WINDOW (dialog), "GEMMA -- Question"); + yes=gtk_button_new_with_label("Yes"); + no=gtk_button_new_with_label("No"); + label=gtk_label_new(text); + + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), + yes,TRUE,TRUE,0); + + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), + no,TRUE,TRUE,0); + + gtk_container_set_border_width(GTK_CONTAINER(dialog),10); + + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), + label,TRUE,TRUE,0); + + gtk_signal_connect(GTK_OBJECT (yes),"clicked", + GTK_SIGNAL_FUNC (Callback), + (gpointer)1); + + gtk_signal_connect(GTK_OBJECT (no),"clicked", + GTK_SIGNAL_FUNC (Callback), + (gpointer)0); + + gtk_signal_connect(GTK_OBJECT(dialog), "delete_event", + GTK_SIGNAL_FUNC(DestroyCB), (gpointer)0); + + gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parent)); + gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); + gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ON_PARENT); + /* gtk_object_set(GTK_OBJECT(dialog),"type",GTK_WINDOW_POPUP,NULL); */ + + gtk_widget_show(yes); + gtk_widget_show(no); + gtk_widget_show(label); + gtk_widget_show(dialog); + + dial_done=FALSE; + + while(!dial_done) + gtk_main_iteration(); + + return selected; +} + + +/* ---------------------------------------- DialogFSelect() +*/ +int DialogFSelect(const char *title, char path[]) +{ + dialog=gtk_file_selection_new(title); + + if (path[0]) + gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog),path); + + gtk_signal_connect(GTK_OBJECT (GTK_FILE_SELECTION(dialog)->ok_button), + "clicked", + GTK_SIGNAL_FUNC (FselCallback), + (gpointer)1); + + gtk_signal_connect(GTK_OBJECT (GTK_FILE_SELECTION(dialog)->cancel_button), + "clicked", + GTK_SIGNAL_FUNC (FselCallback), + (gpointer)0); + + gtk_signal_connect(GTK_OBJECT(dialog), "delete_event", + GTK_SIGNAL_FUNC(NoDestroyCB), (gpointer)0); + + gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parent)); + gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); + gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ON_PARENT); + + gtk_widget_show(dialog); + + dial_done=FALSE; + + while(!dial_done) + gtk_main_iteration(); + + if (selected) + strcpy(path,saved_path); + + gtk_widget_destroy(dialog); + + return selected; +} + + +/* END OF FILE */ |