File: gtkutil.c

package info (click to toggle)
gfcc 0.7.4-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,084 kB
  • ctags: 320
  • sloc: sh: 7,159; ansic: 4,082; makefile: 101
file content (171 lines) | stat: -rw-r--r-- 4,460 bytes parent folder | download | duplicates (2)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>

#include "gfcc.h"

static void close_dialog(GtkWidget *, gpointer);

void (* tcallback)();

GtkWidget *gfcc_toggle_new(GtkWidget *box,
		GtkSignalFunc callback, gpointer data)
{
	GtkWidget *button;

	button = gtk_toggle_button_new_with_label("!");
	gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
	gtk_widget_show(button);
	gtk_widget_set_usize(button, 12, 10);
	gtk_widget_realize(button);
	gtk_signal_connect(GTK_OBJECT(button), "toggled", callback, data);
	
	return button;
}

void menu_separator(GtkWidget *menu)
{
	GtkWidget *menu_item = gtk_menu_item_new();
	gtk_menu_append(GTK_MENU(menu), menu_item);
	gtk_widget_set_sensitive(menu_item, FALSE);
	gtk_widget_show(menu_item);
}

static void close_dialog(GtkWidget *widget, gpointer data)
{
	gtk_widget_destroy(gtk_widget_get_toplevel(widget));
	tcallback();
}

void dialog_window(gchar *message, GtkSignalFunc callback)
{
	GtkWidget *dwin, *label, *button;
	
	dwin = gtk_dialog_new();
	gtk_window_set_title(GTK_WINDOW(dwin), "Message Window");
	gtk_window_set_position(GTK_WINDOW(dwin), GTK_WIN_POS_CENTER);
	gtk_container_set_border_width(GTK_CONTAINER(dwin), 0);
	gtk_widget_set_usize(dwin, 250, 150);
	
	label = gtk_label_new(message);
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dwin)->vbox), label,TRUE,TRUE,0);
	gtk_widget_show(label);
	
	if(callback) {
		tcallback = callback;
		button = gtk_button_new_with_label("OK");
		gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
			GTK_SIGNAL_FUNC(close_dialog), GTK_OBJECT(dwin));
		gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dwin)->action_area),
				button, TRUE, TRUE, 0);
		gtk_widget_show(button);

		button = gtk_button_new_with_label("Cancel");
	} else
		button = gtk_button_new_with_label("OK");
	
	gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
			GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(dwin));
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dwin)->action_area), button,
			TRUE, TRUE, 0);
	gtk_widget_show(button);
	
	gtk_widget_show(dwin);
}

GtkWidget *gfcc_pixmap_button_new(GtkWidget *box, gchar **pixmapdata,
		gint width, gint height, GtkSignalFunc callback, gpointer data)
{
	GtkWidget *button;
	GtkWidget *pixmap;

	button = gtk_button_new();
	gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
	gtk_widget_show(button);
	gtk_widget_realize(button);

	pixmap = new_pixmap(button, pixmapdata);
	gtk_container_add(GTK_CONTAINER(button), pixmap);
	gtk_widget_show(pixmap);
	
	gtk_signal_connect(GTK_OBJECT(button), "clicked", callback, data);
	gtk_widget_set_usize(button, width, height);
	gtk_widget_show(button);

	return button;
}

GtkWidget *new_pixmap(GtkWidget *w, gchar **data)
{
	GdkPixmap *gdkpixmap;
	GdkBitmap *pmask;
	GtkWidget *pixmap;
	
	gdkpixmap = gdk_pixmap_create_from_xpm_d(w->window, &pmask,
			&w->style->bg[GTK_STATE_NORMAL], data);
	pixmap = gtk_pixmap_new(gdkpixmap, pmask);
	
	gdk_pixmap_unref(gdkpixmap);
	gdk_pixmap_unref(pmask);
	
	return pixmap;
}

GtkWidget * append_submenu_item(
		GtkWidget *submenu, GtkSignalFunc func, gchar *text)
{
	GtkWidget *menuitem = gtk_menu_item_new_with_label(text);
	gtk_widget_show(menuitem);
	gtk_menu_append(GTK_MENU(submenu), menuitem);
	
	gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
			GTK_SIGNAL_FUNC(func), text);

	return menuitem;
}

GtkWidget *create_menu_item(GtkWidget *menu, gchar *label,
	gint sensitive_flag, GtkSignalFunc this_func, gpointer this_func_data)
{
	GtkWidget *menu_item;

	menu_item = gtk_menu_item_new_with_label(label);
	gtk_menu_append(GTK_MENU(menu), menu_item);
	gtk_widget_set_sensitive(menu_item, sensitive_flag);
	gtk_widget_show(menu_item);
	gtk_signal_connect(GTK_OBJECT(menu_item), "activate",
			GTK_SIGNAL_FUNC(this_func), this_func_data);
	
	return menu_item;
}

GtkWidget *gfcc_entry_new(GtkWidget *box, gint max, gint width,
					gint height, gchar *defaultval)
{
	GtkWidget *newentry;
	
	if(max)
		newentry = gtk_entry_new_with_max_length(max);
	else
		newentry = gtk_entry_new();
	
	gtk_box_pack_start(GTK_BOX(box), newentry, FALSE, FALSE, 0);
	gtk_widget_set_usize(newentry, width, height);
	gtk_widget_show(newentry);
	
	if(defaultval)
		gtk_entry_set_text(GTK_ENTRY(newentry), defaultval);
	
	return newentry;
}

GtkWidget *gfcc_label_new(GtkWidget *box, gchar *message)
{
	GtkWidget *label;
	
	label = gtk_label_new(message);
	gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
	gtk_widget_show(label);
	
	return label;
}