示例#1
0
static gboolean
gnt_combo_box_key_pressed(GntWidget *widget, const char *text)
{
	GntComboBox *box = GNT_COMBO_BOX(widget);
	gboolean showing = !!GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED);

	if (showing) {
		if (text[1] == 0) {
			switch (text[0]) {
				case '\r':
				case '\t':
				case '\n':
					hide_popup(box, TRUE);
					return TRUE;
				case 27:
					hide_popup(box, FALSE);
					return TRUE;
			}
		}
	}

	if (gnt_widget_key_pressed(box->dropdown, text)) {
		if (!showing)
			popup_dropdown(box);
		return TRUE;
	}

	{
#define SEARCH_IN_RANGE(start, end) do { \
		GntTreeRow *row; \
		for (row = start; row != end; \
				row = gnt_tree_row_get_next(tree, row)) { \
			gpointer key = gnt_tree_row_get_key(tree, row); \
			GList *list = gnt_tree_get_row_text_list(tree, key); \
			gboolean found = FALSE; \
			found = (list->data && g_ascii_strncasecmp(text, list->data, len) == 0); \
			g_list_foreach(list, (GFunc)g_free, NULL); \
			g_list_free(list); \
			if (found) { \
				if (!showing) \
					popup_dropdown(box); \
				gnt_tree_set_selected(tree, key); \
				return TRUE; \
			} \
		} \
} while (0)

		int len = strlen(text);
		GntTree *tree = GNT_TREE(box->dropdown);
		GntTreeRow *current = tree->current;

		SEARCH_IN_RANGE(gnt_tree_row_get_next(tree, current), NULL);
		SEARCH_IN_RANGE(tree->top, current);

#undef SEARCH_IN_RANGE
	}

	return FALSE;
}
示例#2
0
static gboolean
dropdown_menu(GntBindable *b, GList *null)
{
	if (GNT_WIDGET_IS_FLAG_SET(GNT_COMBO_BOX(b)->dropdown->parent, GNT_WIDGET_MAPPED))
		return FALSE;
	popup_dropdown(GNT_COMBO_BOX(b));
	return TRUE;
}
示例#3
0
static gboolean
gnt_combo_box_clicked(GntWidget *widget, GntMouseEvent event, int x, int y)
{
	GntComboBox *box = GNT_COMBO_BOX(widget);
	gboolean dshowing = GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED);

	if (event == GNT_MOUSE_SCROLL_UP) {
		if (dshowing)
			gnt_widget_key_pressed(box->dropdown, GNT_KEY_UP);
	} else if (event == GNT_MOUSE_SCROLL_DOWN) {
		if (dshowing)
			gnt_widget_key_pressed(box->dropdown, GNT_KEY_DOWN);
	} else if (event == GNT_LEFT_MOUSE_DOWN) {
		if (dshowing) {
			hide_popup(box, TRUE);
		} else {
			popup_dropdown(GNT_COMBO_BOX(widget));
		}
	} else
		return FALSE;
	return TRUE;
}
示例#4
0
static gboolean
gnt_combo_box_key_pressed(GntWidget *widget, const char *text)
{
	GntComboBox *box = GNT_COMBO_BOX(widget);
	if (GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED))
	{
		if (text[1] == 0)
		{
			switch (text[0])
			{
				case '\r':
				case '\t':
				case '\n':
					hide_popup(box, TRUE);
					return TRUE;
				case 27:
					hide_popup(box, FALSE);
					return TRUE;
			}
		}
		if (gnt_widget_key_pressed(box->dropdown, text))
			return TRUE;
	}
	else
	{
		if (text[0] == 27)
		{
			if (strcmp(text, GNT_KEY_UP) == 0 ||
					strcmp(text, GNT_KEY_DOWN) == 0)
			{
				popup_dropdown(box);
				return TRUE;
			}
		}
	}

	return FALSE;
}