CVS: sylpheedclaws/sylpheed-claws/src/gtk combobox.c,1.1.2.3,1.1.2.4 combobox.h,1.1.2.3,1.1.2.4 gtkutils.c,1.5.2.45,1.5.2.46 gtkutils.h,1.4.2.27,1.4.2.28

[email protected]
Newsgroups gmane.mail.sylpheed.claws.cvs
Message-ID <[email protected]>
Update of /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/gtk
In directory sunsite.dk:/tmp/cvs-serv2572/src/gtk

Modified Files:
      Tag: gtk2
	combobox.c combobox.h gtkutils.c gtkutils.h 
Log Message:
2006-12-05 [wwp]	2.6.1cvs5

	* src/message_search.c
	* src/summary_search.c
	* src/gtk/combobox.c
	* src/gtk/combobox.h
	* src/gtk/gtkutils.c
	* src/gtk/gtkutils.h
		make up and down arrow keys in modern gtk_combo_box_entry widgets
		behave like w/ old comboboxes (summary and message search only).

Index: combobox.c
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/gtk/Attic/combobox.c,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -d -r1.1.2.3 -r1.1.2.4
--- combobox.c	2006/12/01 10:00:57	1.1.2.3
+++ combobox.c	2006/12/05 14:59:19	1.1.2.4
@@ -23,6 +23,7 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
+#include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 #include <utils.h>
 
@@ -103,4 +104,60 @@
 
 	for (cur = list; cur != NULL; cur = g_list_next(cur))
 		gtk_combo_box_append_text(combobox, (const gchar*) cur->data);
+}
+
+gboolean combobox_set_value_from_arrow_key(GtkComboBox *combobox,
+				 guint keyval)
+/* used from key_press events upon gtk_combo_box_entry with one text column 
+   (gtk_combo_box_new_text() and with GtkComboBoxEntry's for instance),
+   make sure that up and down arrow keys behave the same as old with old
+   gtk_combo widgets:
+    when pressing Up:
+	  if the current text in entry widget is not found in combo list,
+	    get last value from combo list
+	  if the current text in entry widget exists in combo list,
+	    get prev value from combo list
+    when pressing Down:
+	  if the current text in entry widget is not found in combo list,
+	    get first value from combo list
+	  if the current text in entry widget exists in combo list,
+	    get next value from combo list
+*/
+{
+	gboolean valid = FALSE;
+
+	g_return_val_if_fail(combobox != NULL, FALSE);
+
+	/* reproduce the behaviour of old gtk_combo_box */
+	GtkTreeModel *model = gtk_combo_box_get_model(combobox);
+	GtkTreeIter iter;
+
+	if (gtk_combo_box_get_active_iter(combobox, &iter)) {
+		/* if current text is in list, get prev or next one */
+
+		if (keyval == GDK_Up)
+			valid = gtkut_tree_model_text_iter_prev(model, &iter,
+						gtk_combo_box_get_active_text(combobox));
+		else
+		if (keyval == GDK_Down)
+			valid = gtk_tree_model_iter_next(model, &iter);
+
+		if (valid)
+			gtk_combo_box_set_active_iter(combobox, &iter);
+
+	} else {
+		/* current text is not in list, get first or next one */
+
+		if (keyval == GDK_Up)
+			valid = gtkut_tree_model_get_iter_last(model, &iter);
+		else
+		if (keyval == GDK_Down)
+			valid = gtk_tree_model_get_iter_first(model, &iter);
+
+		if (valid)
+			gtk_combo_box_set_active_iter(combobox, &iter);
+	}
+
+	/* return TRUE if value could be set */
+	return valid;
 }

Index: combobox.h
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/gtk/Attic/combobox.h,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -d -r1.1.2.3 -r1.1.2.4
--- combobox.h	2006/12/01 10:00:57	1.1.2.3
+++ combobox.h	2006/12/05 14:59:19	1.1.2.4
@@ -41,5 +41,7 @@
 void combobox_unset_popdown_strings(GtkComboBox		*combobox);
 void combobox_set_popdown_strings(GtkComboBox		*combobox,
 				 GList       *list);
+gboolean combobox_set_value_from_arrow_key(GtkComboBox *combobox,
+				 guint keyval);
 
 #endif /* __COMBOBOX_H__ */

Index: gtkutils.c
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/gtk/gtkutils.c,v
retrieving revision 1.5.2.45
retrieving revision 1.5.2.46
diff -u -d -r1.5.2.45 -r1.5.2.46
--- gtkutils.c	2006/12/01 14:24:50	1.5.2.45
+++ gtkutils.c	2006/12/05 14:59:19	1.5.2.46
@@ -1482,3 +1482,58 @@
 		}
 	}
 }
+
+gboolean gtkut_tree_model_text_iter_prev(GtkTreeModel *model,
+				 GtkTreeIter *iter,
+				 const gchar* text)
+/* do the same as gtk_tree_model_iter_next, but _prev instead.
+   to use with widgets with one text column (gtk_combo_box_new_text()
+   and with GtkComboBoxEntry's for instance),
+*/
+{
+	GtkTreeIter cur_iter;
+	gchar *cur_value;
+	gboolean valid;
+	gint count;
+
+	g_return_val_if_fail(model != NULL, FALSE);
+	g_return_val_if_fail(iter != NULL, FALSE);
+
+	if (text == NULL || *text == '\0')
+		return FALSE;
+
+	valid = gtk_tree_model_get_iter_first(model, &cur_iter);
+	count = 0;
+	while (valid) {
+		gtk_tree_model_get(model, &cur_iter, 0, &cur_value, -1);
+
+		if (strcmp(text, cur_value) == 0) {
+			if (count <= 0)
+				return FALSE;
+
+			return gtk_tree_model_iter_nth_child(model, iter, NULL, count - 1);
+		}
+
+		valid = gtk_tree_model_iter_next(model, &cur_iter);
+		count++;
+	}
+	return FALSE;		
+}
+
+gboolean gtkut_tree_model_get_iter_last(GtkTreeModel *model,
+				 GtkTreeIter *iter)
+/* do the same as gtk_tree_model_get_iter_first, but _last instead.
+*/
+{
+	gint count;
+
+	g_return_val_if_fail(model != NULL, FALSE);
+	g_return_val_if_fail(iter != NULL, FALSE);
+
+	count = gtk_tree_model_iter_n_children(model, NULL);
+
+	if (count <= 0)
+		return FALSE;
+
+	return gtk_tree_model_iter_nth_child(model, iter, NULL, count - 1);
+}

Index: gtkutils.h
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/gtk/gtkutils.h,v
retrieving revision 1.4.2.27
retrieving revision 1.4.2.28
diff -u -d -r1.4.2.27 -r1.4.2.28
--- gtkutils.h	2006/12/01 14:24:50	1.4.2.27
+++ gtkutils.h	2006/12/05 14:59:19	1.4.2.28
@@ -34,6 +34,7 @@
 #include <gtk/gtkcombo.h>
 #include <gtk/gtktextview.h>
 #include <gtk/gtkitemfactory.h>
+#include <gtk/gtktreemodel.h>
 #include <stdlib.h>
 #if HAVE_WCHAR_H
 #  include <wchar.h>
@@ -225,4 +226,11 @@
 gboolean gtkutils_scroll_page	(GtkWidget *widget, 
 				 GtkAdjustment *vadj, 
 				 gboolean up);
+
+gboolean gtkut_tree_model_text_iter_prev(GtkTreeModel *model,
+				 GtkTreeIter *iter,
+				 const gchar* text);
+gboolean gtkut_tree_model_get_iter_last(GtkTreeModel *model,
+				 GtkTreeIter *iter);
+
 #endif /* __GTKUTILS_H__ */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.