File: mc_combo.c

package info (click to toggle)
mlterm 3.1.2-1.3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 23,168 kB
  • sloc: ansic: 102,795; sh: 9,676; java: 2,018; perl: 1,601; makefile: 1,595; cpp: 771; sed: 16
file content (111 lines) | stat: -rw-r--r-- 2,553 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
/*
 *	$Id$
 */

#include <kiklib/kik_str.h>
#include  "mc_combo.h"


/* --- global functions --- */

GtkWidget *
mc_combo_new(
	const char *  label_name ,
	char **  item_names ,
	u_int  item_num ,
	char *  selected_item_name ,
	int  is_readonly ,
	gint (*callback)(GtkWidget * , gpointer) ,
	gpointer  data
	)
{
	return mc_combo_new_with_width(label_name, item_names, item_num,
				       selected_item_name, is_readonly,
				       callback, data, 0);
}

GtkWidget *
mc_combo_new_with_width(
	const char *  label_name ,
	char **  item_names ,
	u_int  item_num ,
	char *  selected_item_name ,
	int  is_readonly ,
	gint (*callback)(GtkWidget * , gpointer) ,
	gpointer  data,
	int entry_width
	)
{
	GtkWidget * hbox;
	GtkWidget * label;
	GtkWidget * combo;
	int item_found;
	u_int count;

	hbox = gtk_hbox_new(FALSE, 5);
	gtk_widget_show(hbox);

	label = gtk_label_new(label_name) ;
	gtk_widget_show(label) ;
	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);

#if  GTK_CHECK_VERSION(2,90,0)
	combo = gtk_combo_box_text_new_with_entry();
#else
	combo = gtk_combo_box_entry_new_text();
#endif
	gtk_widget_show(combo);

	item_found = 0;
	for(count = 0; count < item_num; count++)
	{
	    if(strcmp(selected_item_name, item_names[count]) == 0)
	    {
	    #if  GTK_CHECK_VERSION(2,90,0)
	        gtk_combo_box_text_prepend_text( GTK_COMBO_BOX_TEXT(combo) , item_names[count]) ;
	    #else
	        gtk_combo_box_prepend_text( GTK_COMBO_BOX(combo), item_names[count]);
	    #endif
		item_found = 1;
	    }
	    else
	    {
	    #if  GTK_CHECK_VERSION(2,90,0)
	        gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT(combo) , item_names[count]) ;
	    #else
	        gtk_combo_box_append_text( GTK_COMBO_BOX(combo), item_names[count]);
	    #endif
	    }
	}

	if(!item_found && !is_readonly)
	{
	#if  GTK_CHECK_VERSION(2,90,0)
	    gtk_combo_box_text_prepend_text( GTK_COMBO_BOX_TEXT(combo) , selected_item_name) ;
	#else
	    gtk_combo_box_prepend_text( GTK_COMBO_BOX(combo), selected_item_name);
	#endif
	}

	gtk_combo_box_set_active( GTK_COMBO_BOX(combo) , 0) ;
	
	g_signal_connect( gtk_bin_get_child( GTK_BIN(combo)),
		"changed", G_CALLBACK(callback), data);

	if( is_readonly)
	{
	    gtk_editable_set_editable( GTK_EDITABLE(gtk_bin_get_child( GTK_BIN(combo))), FALSE);
	}
	
	if( entry_width)
	{
	    gtk_widget_set_size_request( gtk_bin_get_child( GTK_BIN(combo)), entry_width, -1);
	    gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0);
	}
	else
	{
	    gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0);
	}

	return hbox;
}