diff console/libgnt/gntbox.c @ 14041:27182f83b79b

[gaim-migrate @ 16647] Statusbox comes in. It's now possible to change the account status. There's nothing yet for creating custom statuses. It's also possible now to delete accounts. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 05 Aug 2006 11:31:54 +0000
parents 7573bd40a190
children 1a500db56415
line wrap: on
line diff
--- a/console/libgnt/gntbox.c	Sat Aug 05 09:19:14 2006 +0000
+++ b/console/libgnt/gntbox.c	Sat Aug 05 11:31:54 2006 +0000
@@ -245,6 +245,28 @@
 	} while (box->active != last);
 }
 
+static void
+find_prev_focus(GntBox *box)
+{
+	gpointer last = box->active;
+
+	if (!box->focus)
+		return;
+
+	do
+	{
+		GList *iter = g_list_find(box->focus, box->active);
+		if (!iter)
+			box->active = box->focus->data;
+		else if (!iter->prev)
+			box->active = g_list_last(box->focus)->data;
+		else
+			box->active = iter->prev->data;
+		if (!GNT_WIDGET_IS_FLAG_SET(box->active, GNT_WIDGET_INVISIBLE))
+			break;
+	} while (box->active != last);
+}
+
 static gboolean
 gnt_box_key_pressed(GntWidget *widget, const char *text)
 {
@@ -263,15 +285,7 @@
 	{
 		if (strcmp(text+1, GNT_KEY_LEFT) == 0)
 		{
-			GList *iter = g_list_find(box->focus, box->active);
-			if ((!iter || !iter->prev) && box->focus)
-			{
-				box->active = box->focus->data;
-			}
-			else
-			{
-				box->active = iter->prev->data;
-			}
+			find_prev_focus(box);
 		}
 		else if (strcmp(text+1, GNT_KEY_RIGHT) == 0)
 		{
@@ -689,3 +703,46 @@
 	box->fill = fill;
 }
 
+void gnt_box_move_focus(GntBox *box, int dir)
+{
+	GntWidget *now;
+
+	if (box->active == NULL)
+	{
+		find_focusable_widget(box);
+		return;
+	}
+
+	now = box->active;
+
+	if (dir == 1)
+		find_next_focus(box);
+	else if (dir == -1)
+		find_prev_focus(box);
+
+	if (now && now != box->active)
+	{
+		gnt_widget_set_focus(now, FALSE);
+		gnt_widget_set_focus(box->active, TRUE);
+	}
+
+	if (GNT_WIDGET(box)->window)
+		gnt_widget_draw(GNT_WIDGET(box));
+}
+
+void gnt_box_give_focus_to_child(GntBox *box, GntWidget *widget)
+{
+	GList *find = g_list_find(box->focus, widget);
+	gpointer now = box->active;
+	if (find)
+		box->active = widget;
+	if (now && now != box->active)
+	{
+		gnt_widget_set_focus(now, FALSE);
+		gnt_widget_set_focus(box->active, TRUE);
+	}
+
+	if (GNT_WIDGET(box)->window)
+		gnt_widget_draw(GNT_WIDGET(box));
+}
+