-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.c
101 lines (82 loc) · 2.54 KB
/
gui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#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;
gboolean ret;
char *entryText;
ret = true;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "model-ghdl");
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);
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);
}
buttonBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
if (MESSAGE_IS_INPUT(message_type)) {
gtk_box_pack_start(GTK_BOX(buttonBox), buttonCancel, true, true, 0);
}
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);
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);
gtk_widget_show(mainBox);
g_signal_connect (window, "destroy",
G_CALLBACK (cancel), NULL);
gtk_container_add(GTK_CONTAINER(window), mainBox);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 320, 10);
gtk_window_present(GTK_WINDOW(window));
gtk_main();
if (MESSAGE_IS_INPUT(message_type)) {
entryText = (char*) gtk_entry_get_text(GTK_ENTRY(entry));
if (entryText[0] == 0) {
ret = false;
}
else {
*reply = realloc(*reply, sizeof(char)*strlen(entryText));
if (*reply != NULL)
strcpy(*reply, entryText);
ret = true;
}
}
gtk_widget_destroy(window);
return ret;
}
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();
}