2015-10-22 20:23:24 +02:00
|
|
|
#include "gui.h"
|
|
|
|
|
|
|
|
#define true 1
|
|
|
|
#define false 0
|
|
|
|
|
|
|
|
int gui_init(int *argc, char ***argv) {
|
|
|
|
gtk_init (argc, argv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int showMessage(int message_type, char *text, char *defaultText, char **reply) {
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *entry;
|
|
|
|
GtkWidget *buttonOkay;
|
|
|
|
GtkWidget *buttonCancel;
|
|
|
|
GtkWidget *buttonBox;
|
|
|
|
GtkWidget *mainBox;
|
|
|
|
GtkWidget *label;
|
2016-05-08 16:17:11 +02:00
|
|
|
gboolean ret;
|
2015-10-22 20:23:24 +02:00
|
|
|
char *entryText;
|
|
|
|
|
2016-05-08 16:17:11 +02:00
|
|
|
ret = true;
|
|
|
|
|
2015-10-22 20:23:24 +02:00
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2015-10-23 20:47:21 +02:00
|
|
|
gtk_window_set_title(GTK_WINDOW(window), "model-ghdl");
|
2015-10-22 20:23:24 +02:00
|
|
|
|
|
|
|
label = gtk_label_new(text);
|
|
|
|
gtk_widget_show(label);
|
|
|
|
|
|
|
|
entry = gtk_entry_new();
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry), (char*) defaultText);
|
|
|
|
g_signal_connect (entry, "activate",
|
|
|
|
G_CALLBACK(okay), entry);
|
|
|
|
|
|
|
|
buttonOkay = gtk_button_new_with_label("Okay!");
|
|
|
|
gtk_widget_show(buttonOkay);
|
2015-10-23 20:47:21 +02:00
|
|
|
|
|
|
|
if (MESSAGE_IS_INPUT(message_type)) {
|
|
|
|
buttonCancel = gtk_button_new_with_label("Cancel");
|
|
|
|
g_signal_connect (buttonCancel, "clicked",
|
|
|
|
G_CALLBACK(cancel), entry);
|
|
|
|
gtk_widget_show(buttonCancel);
|
|
|
|
|
|
|
|
gtk_widget_show(entry);
|
|
|
|
}
|
2015-10-22 20:23:24 +02:00
|
|
|
|
|
|
|
buttonBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
|
2015-10-23 20:47:21 +02:00
|
|
|
if (MESSAGE_IS_INPUT(message_type)) {
|
|
|
|
gtk_box_pack_start(GTK_BOX(buttonBox), buttonCancel, true, true, 0);
|
|
|
|
}
|
2015-10-22 20:23:24 +02:00
|
|
|
gtk_box_pack_start(GTK_BOX(buttonBox), buttonOkay, true, true, 0);
|
|
|
|
g_signal_connect (buttonOkay, "clicked",
|
|
|
|
G_CALLBACK(okay), entry);
|
|
|
|
gtk_widget_show(buttonBox);
|
|
|
|
|
|
|
|
mainBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
|
2015-10-23 20:47:21 +02:00
|
|
|
gtk_box_pack_start(GTK_BOX(mainBox), label, true, true, 10);
|
|
|
|
if (MESSAGE_IS_INPUT(message_type)) {
|
|
|
|
gtk_box_pack_start(GTK_BOX(mainBox), entry, true, true, 0);
|
|
|
|
}
|
|
|
|
gtk_box_pack_start(GTK_BOX(mainBox), buttonBox, false, false, 0);
|
2015-10-22 20:23:24 +02:00
|
|
|
gtk_widget_show(mainBox);
|
|
|
|
|
|
|
|
g_signal_connect (window, "destroy",
|
2015-10-23 20:47:21 +02:00
|
|
|
G_CALLBACK (cancel), NULL);
|
2015-10-22 20:23:24 +02:00
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(window), mainBox);
|
2015-10-23 20:47:21 +02:00
|
|
|
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
|
|
|
|
gtk_window_set_default_size(GTK_WINDOW(window), 320, 10);
|
2015-10-22 20:23:24 +02:00
|
|
|
gtk_widget_show (window);
|
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
|
2015-10-23 20:47:21 +02:00
|
|
|
if (MESSAGE_IS_INPUT(message_type)) {
|
|
|
|
entryText = (char*) gtk_entry_get_text(GTK_ENTRY(entry));
|
|
|
|
if (entryText[0] == 0) {
|
2016-05-08 16:17:11 +02:00
|
|
|
ret = false;
|
2015-10-23 20:47:21 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*reply = realloc(*reply, sizeof(char)*strlen(entryText));
|
|
|
|
if (*reply != NULL)
|
|
|
|
strcpy(*reply, entryText);
|
2016-05-08 16:17:11 +02:00
|
|
|
ret = true;
|
2015-10-23 20:47:21 +02:00
|
|
|
}
|
2015-10-22 20:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy(window);
|
2016-05-08 16:17:11 +02:00
|
|
|
return ret;
|
2015-10-22 20:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void okay( GtkWidget *widget,
|
|
|
|
gpointer data )
|
|
|
|
{
|
|
|
|
//g_print ("TEXT = %s\n", gtk_entry_get_text(GTK_ENTRY(data)));
|
|
|
|
gtk_main_quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cancel( GtkWidget *widget,
|
|
|
|
gpointer data )
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(data), "");
|
|
|
|
gtk_main_quit();
|
|
|
|
}
|