forked from harshitbansal373/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack_push_and_pop_gui.c
93 lines (76 loc) · 2.48 KB
/
stack_push_and_pop_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
#include <stdlib.h>
#include <gtk/gtk.h>
#include <glib.h>
static int count = 1;
GtkWidget *status_bar;
static void push_item( GtkWidget *widget,
gpointer data )
{
gchar *buff;
if(count<=10)
{
buff = g_strdup_printf ("Item %d", count++);
gtk_statusbar_push (GTK_STATUSBAR (status_bar), GPOINTER_TO_INT (data), buff);
g_free (buff);
}
else
{
buff = g_strdup_printf("Stack is in Overflow condition");
gtk_statusbar_push(GTK_STATUSBAR(status_bar),GPOINTER_TO_INT (data),buff);
g_free(buff);
}
}
static void pop_item( GtkWidget *widget,
gpointer data )
{
gchar *buff;
if(count>0)
{
gtk_statusbar_pop (GTK_STATUSBAR (status_bar), GPOINTER_TO_INT (data));
count--;
}
else
{
buff = g_strdup_printf("Stack is in underflow condition");
gtk_statusbar_push(GTK_STATUSBAR(status_bar),GPOINTER_TO_INT (data),buff);
g_free(buff);
}
}
int main( int argc,
char *argv[] )
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *button;
gint context_id;
gtk_init (&argc, &argv);
/* create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (GTK_WIDGET (window), 500, 400);
gtk_window_set_title (GTK_WINDOW (window), "Stack Working Example");
g_signal_connect (window, "delete-event",
G_CALLBACK (exit), NULL);
vbox = gtk_vbox_new (FALSE, 1);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);
status_bar = gtk_statusbar_new ();
gtk_box_pack_start (GTK_BOX (vbox), status_bar, TRUE, TRUE, 0);
gtk_widget_show (status_bar);
context_id = gtk_statusbar_get_context_id(
GTK_STATUSBAR (status_bar), "Statusbar example");
button = gtk_button_new_with_label ("push item");
g_signal_connect (button, "clicked",
G_CALLBACK (push_item), GINT_TO_POINTER (context_id));
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 2);
gtk_widget_show (button);
button = gtk_button_new_with_label ("pop last item");
g_signal_connect (button, "clicked",
G_CALLBACK (pop_item), GINT_TO_POINTER (context_id));
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 2);
gtk_widget_show (button);
/* always display the window as the last step so it all splashes on
* the screen at once. */
gtk_widget_show (window);
gtk_main ();
return 0;
}