qulogic/libgnt

Underline the selection in a checkbox.

2009-11-20, Sadrul Habib Chowdhury
a0e2ca5ee115
Parents 41a1d7d8de88
Children abe35d2fdf93
Underline the selection in a checkbox.

This makes it easier to notice when a checkbox has a focus when the color
selection is not great. Also, don't allocate memory when not necessary.
--- a/gntcheckbox.c Thu Nov 05 02:50:48 2009 +0000
+++ b/gntcheckbox.c Fri Nov 20 16:46:58 2009 +0000
@@ -20,6 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
+#include "gntinternal.h"
#include "gntcheckbox.h"
enum
@@ -36,21 +37,21 @@
{
GntCheckBox *cb = GNT_CHECK_BOX(widget);
GntColorType type;
- char *text;
+ gboolean focus = gnt_widget_has_focus(widget);
- if (gnt_widget_has_focus(widget))
+ if (focus)
type = GNT_COLOR_HIGHLIGHT;
else
type = GNT_COLOR_NORMAL;
wbkgdset(widget->window, '\0' | gnt_color_pair(type));
- text = g_strdup_printf("[%c]", cb->checked ? 'X' : ' ');
- mvwaddstr(widget->window, 0, 0, text);
- g_free(text);
+ mvwaddch(widget->window, 0, 0, '[');
+ mvwaddch(widget->window, 0, 1, (cb->checked ? 'X' : ' ') | (focus ? A_UNDERLINE : A_NORMAL));
+ mvwaddch(widget->window, 0, 2, ']');
wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL));
- mvwaddstr(widget->window, 0, 4, GNT_BUTTON(cb)->priv->text);
+ mvwaddstr(widget->window, 0, 4, (GNT_BUTTON(cb)->priv->text));
wmove(widget->window, 0, 1);
GNTDEBUG;