changeset 18506:9f029b7208f1

Allow one-line high buttons. Specify 'small-button = true' under 'general', or 'finch'. This gets rid of the border from the buttons, and does the highlighting a little differently.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 12 Jul 2007 23:57:56 +0000
parents 8925181f26ec
children a7d694b63e3d
files finch/libgnt/gntbutton.c finch/libgnt/gntstyle.c finch/libgnt/gntstyle.h
diffstat 3 files changed, 50 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/finch/libgnt/gntbutton.c	Thu Jul 12 03:19:38 2007 +0000
+++ b/finch/libgnt/gntbutton.c	Thu Jul 12 23:57:56 2007 +0000
@@ -20,9 +20,11 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <stdlib.h>
 #include <string.h>
 
 #include "gntbutton.h"
+#include "gntstyle.h"
 #include "gntutils.h"
 
 enum
@@ -31,20 +33,26 @@
 };
 
 static GntWidgetClass *parent_class = NULL;
+static gboolean small_button = FALSE;
 
 static void
 gnt_button_draw(GntWidget *widget)
 {
 	GntButton *button = GNT_BUTTON(widget);
 	GntColorType type;
+	gboolean focus;
 
-	if (gnt_widget_has_focus(widget))
+	if ((focus = gnt_widget_has_focus(widget)))
 		type = GNT_COLOR_HIGHLIGHT;
 	else
 		type = GNT_COLOR_NORMAL;
-	
+
 	wbkgdset(widget->window, '\0' | COLOR_PAIR(type));
-	mvwaddstr(widget->window, 1, 2, button->priv->text);
+	mvwaddstr(widget->window, (small_button) ? 0 : 1, 2, button->priv->text);
+	if (small_button) {
+		type = GNT_COLOR_HIGHLIGHT;
+		mvwchgat(widget->window, 0, 0, widget->priv.width, focus ? A_BOLD : A_REVERSE, type, NULL);
+	}
 
 	GNTDEBUG;
 }
@@ -92,6 +100,8 @@
 static void
 gnt_button_class_init(GntWidgetClass *klass)
 {
+	char *style;
+
 	parent_class = GNT_WIDGET_CLASS(klass);
 	parent_class->draw = gnt_button_draw;
 	parent_class->map = gnt_button_map;
@@ -99,6 +109,8 @@
 	parent_class->key_pressed = gnt_button_key_pressed;
 	parent_class->clicked = gnt_button_clicked;
 
+	style = gnt_style_get_from_name(NULL, "small-button");
+	small_button = gnt_style_parse_bool(style);
 	GNTDEBUG;
 }
 
@@ -110,7 +122,9 @@
 	button->priv = g_new0(GntButtonPriv, 1);
 
 	widget->priv.minw = 4;
-	widget->priv.minh = 3;
+	widget->priv.minh = small_button ? 1 : 3;
+	if (small_button)
+		GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
 	GNTDEBUG;
 }
 
--- a/finch/libgnt/gntstyle.c	Thu Jul 12 03:19:38 2007 +0000
+++ b/finch/libgnt/gntstyle.c	Thu Jul 12 23:57:56 2007 +0000
@@ -48,13 +48,14 @@
 char *gnt_style_get_from_name(const char *group, const char *key)
 {
 #if GLIB_CHECK_VERSION(2,6,0)
+	if ((group == NULL && (group = g_get_prgname()) == NULL) || *group == '\0')
+		group = "general";
 	return g_key_file_get_value(gkfile, group, key, NULL);
 #endif
 }
 
 gboolean gnt_style_get_bool(GntStyle style, gboolean def)
 {
-	int i;
 	const char * str;
 
 	if (bool_styles[style] != -1)
@@ -62,11 +63,20 @@
 	
 	str = gnt_style_get(style);
 
+	bool_styles[style] = str ? gnt_style_parse_bool(str) : def;
+	return bool_styles[style];
+}
+
+gboolean gnt_style_parse_bool(const char *str)
+{
+	gboolean def = FALSE;
+	int i;
+
 	if (str)
 	{
-		if (strcmp(str, "false") == 0)
+		if (g_ascii_strcasecmp(str, "false") == 0)
 			def = FALSE;
-		else if (strcmp(str, "true") == 0)
+		else if (g_ascii_strcasecmp(str, "true") == 0)
 			def = TRUE;
 		else if (sscanf(str, "%d", &i) == 1)
 		{
@@ -76,9 +86,7 @@
 				def = FALSE;
 		}
 	}
-
-	bool_styles[style] = def;
-	return bool_styles[style];
+	return def;
 }
 
 static void
--- a/finch/libgnt/gntstyle.h	Thu Jul 12 03:19:38 2007 +0000
+++ b/finch/libgnt/gntstyle.h	Thu Jul 12 23:57:56 2007 +0000
@@ -45,9 +45,27 @@
 
 const char *gnt_style_get(GntStyle style);
 
+/**
+ * Get the value of a preference in ~/.gntrc.
+ *
+ * @param group   The name of the group in the keyfile. If @c NULL, the prgname
+ *                will be used first, if available. Otherwise, "general" will be used.
+ * @param key     The key
+ *
+ * @return  The value of the setting as a string, or @c NULL
+ */
 char *gnt_style_get_from_name(const char *group, const char *key);
 
 /**
+ * Parse a boolean preference. For example, if 'value' is "false" (ignoring case)
+ * or "0", the return value will be @c FALSE, otherwise @c TRUE.
+ *
+ * @param value   The value of the boolean setting as a string
+ * @return    The boolean value
+ */
+gboolean gnt_style_parse_bool(const char *value);
+
+/**
  * 
  * @param style
  * @param def