Ejemplo n.º 1
0
static gboolean
check_for_trigger(GntMenu *menu, char trigger)
{
	/* check for a trigger key */
	GList *iter;
	GList *find;
	GList *nth = g_list_find(menu->list, gnt_tree_get_selection_data(GNT_TREE(menu)));

	if (nth == NULL)
		return FALSE;

	find = find_item_with_trigger(nth->next, NULL, trigger);
	if (!find)
		find = find_item_with_trigger(menu->list, nth->next, trigger);
	if (!find)
		return FALSE;
	if (find != nth) {
		gnt_tree_set_selected(GNT_TREE(menu), find->data);
		iter = find_item_with_trigger(find->next, NULL, trigger);
		if (iter != NULL && iter != find)
			return TRUE;
		iter = find_item_with_trigger(menu->list, nth, trigger);
		if (iter != NULL && iter != find)
			return TRUE;
	}
	gnt_widget_activate(GNT_WIDGET(menu));
	return TRUE;
}
Ejemplo n.º 2
0
static gboolean
gnt_button_clicked(GntWidget *widget, GntMouseEvent event, int x, int y)
{
    if (event == GNT_LEFT_MOUSE_DOWN) {
        gnt_widget_activate(widget);
        return TRUE;
    }
    return FALSE;
}
Ejemplo n.º 3
0
static gboolean
gnt_menu_clicked(GntWidget *widget, GntMouseEvent event, int x, int y)
{
	if (GNT_MENU(widget)->type != GNT_MENU_POPUP)
		return FALSE;

	if (org_clicked && org_clicked(widget, event, x, y))
		return TRUE;
	gnt_widget_activate(widget);
	return TRUE;
}
Ejemplo n.º 4
0
static gboolean
show_menu(GntBindable *bind, GList *null)
{
	GntWindow *win = GNT_WINDOW(bind);
	if (win->menu) {
		GntMenu *menu = win->menu;

		gnt_screen_menu_show(menu);
		if (menu->type == GNT_MENU_TOPLEVEL) {
			GntMenuItem *item;
			item = g_list_nth_data(menu->list, menu->selected);
			if (item && gnt_menuitem_get_submenu(item)) {
				gnt_widget_activate(GNT_WIDGET(menu));
			}
		}
		return TRUE;
	}
	return FALSE;
}
Ejemplo n.º 5
0
static gboolean
gnt_menu_key_pressed(GntWidget *widget, const char *text)
{
	GntMenu *menu = GNT_MENU(widget);
	guint current = menu->selected;

	if (menu->submenu) {
		GntMenu *sub = menu;
		do sub = sub->submenu; while (sub->submenu);
		if (gnt_widget_key_pressed(GNT_WIDGET(sub), text))
			return TRUE;
		if (menu->type != GNT_MENU_TOPLEVEL)
			return FALSE;
	}

	if ((text[0] == 27 && text[1] == 0) ||
			(menu->type != GNT_MENU_TOPLEVEL && strcmp(text, GNT_KEY_LEFT) == 0)) {
		/* Escape closes menu */
		GntMenu *par = menu->parentmenu;
		if (par != NULL) {
			par->submenu = NULL;
			gnt_widget_hide(widget);
		} else
			gnt_widget_hide(widget);
		if (par && par->type == GNT_MENU_TOPLEVEL)
			gnt_menu_key_pressed(GNT_WIDGET(par), text);
		return TRUE;
	}

	if (menu->type == GNT_MENU_TOPLEVEL) {
		GntMenuItem *item;
		GList *it;
		if (strcmp(text, GNT_KEY_LEFT) == 0) {
			do {
				if (menu->selected == 0)
					menu->selected = g_list_length(menu->list) - 1;
				else
					menu->selected--;
				it = g_list_nth(menu->list, menu->selected);
				item = it ? it->data : NULL;
			} while (!gnt_menuitem_is_visible(item));
		} else if (strcmp(text, GNT_KEY_RIGHT) == 0) {
			do {
				menu->selected++;
				if (menu->selected >= g_list_length(menu->list))
					menu->selected = 0;
				it = g_list_nth(menu->list, menu->selected);
				item = it ? it->data : NULL;
			} while (!gnt_menuitem_is_visible(item));
		} else if (strcmp(text, GNT_KEY_ENTER) == 0 ||
				strcmp(text, GNT_KEY_DOWN) == 0) {
			gnt_widget_activate(widget);
		}

		if (current != menu->selected) {
			GntMenu *sub = menu->submenu;
			if (sub)
				gnt_widget_hide(GNT_WIDGET(sub));
			show_submenu(menu);
			gnt_widget_draw(widget);
			return TRUE;
		}
	} else {
		if (text[1] == '\0') {
			if (check_for_trigger(menu, text[0]))
				return TRUE;
		} else if (strcmp(text, GNT_KEY_RIGHT) == 0) {
			GntMenuItem *item = gnt_tree_get_selection_data(GNT_TREE(menu));
			if (item && item->submenu) {
				menuitem_activate(menu, item);
				return TRUE;
			}
		}
		if (gnt_bindable_perform_action_key(GNT_BINDABLE(widget), text))
			return TRUE;
		return org_key_pressed(widget, text);
	}

	return gnt_bindable_perform_action_key(GNT_BINDABLE(widget), text);
}
Ejemplo n.º 6
0
static gboolean
button_activate(GntBindable *bind, GList *null)
{
    gnt_widget_activate(GNT_WIDGET(bind));
    return TRUE;
}
Ejemplo n.º 7
0
static gboolean
gnt_entry_key_pressed(GntWidget *widget, const char *text)
{
	GntEntry *entry = GNT_ENTRY(widget);

	if (text[0] == 27)
	{
		if (text[1] == 0)
		{
			destroy_suggest(entry);
			return TRUE;
		}

		return FALSE;
	}

	if ((text[0] == '\r' || text[0] == ' ' || text[0] == '\n') && entry->ddown)
	{
		char *text = g_strdup(gnt_tree_get_selection_data(GNT_TREE(entry->ddown)));
		destroy_suggest(entry);
		complete_suggest(entry, text);
		g_free(text);
		update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
		entry_text_changed(entry);
		return TRUE;
	}

	if (!iscntrl(text[0]))
	{
		const char *str, *next;

		for (str = text; *str; str = next)
		{
			int len;
			next = g_utf8_find_next_char(str, NULL);
			len = next - str;

			/* Valid input? */
			/* XXX: Is it necessary to use _unichar_ variants here? */
			if (ispunct(*str) && (entry->flag & GNT_ENTRY_FLAG_NO_PUNCT))
				continue;
			if (isspace(*str) && (entry->flag & GNT_ENTRY_FLAG_NO_SPACE))
				continue;
			if (isalpha(*str) && !(entry->flag & GNT_ENTRY_FLAG_ALPHA))
				continue;
			if (isdigit(*str) && !(entry->flag & GNT_ENTRY_FLAG_INT))
				continue;

			/* Reached the max? */
			if (entry->max && g_utf8_pointer_to_offset(entry->start, entry->end) >= entry->max)
				continue;

			if (entry->end + len - entry->start >= entry->buffer)
			{
				/* This will cause the buffer to grow */
				char *tmp = g_strdup(entry->start);
				gnt_entry_set_text_internal(entry, tmp);
				g_free(tmp);
			}

			memmove(entry->cursor + len, entry->cursor, entry->end - entry->cursor + 1);
			entry->end += len;

			while (str < next)
			{
				if (*str == '\r' || *str == '\n')
					*entry->cursor = ' ';
				else
					*entry->cursor = *str;
				entry->cursor++;
				str++;
			}

			while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width)
				entry->scroll = g_utf8_find_next_char(entry->scroll, NULL);

			if (entry->ddown)
				show_suggest_dropdown(entry);
		}
		update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
		entry_redraw(widget);
		entry_text_changed(entry);
		return TRUE;
	}

	if (text[0] == '\r' || text[0] == '\n') {
		gnt_widget_activate(widget);
		return TRUE;
	}

	return FALSE;
}