comparison finch/libgnt/gntcheckbox.c @ 28983:8356e2f2486a

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.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 20 Nov 2009 16:46:58 +0000
parents c67d43408daa
children a18f421696dc
comparison
equal deleted inserted replaced
28982:a169c5c81ef5 28983:8356e2f2486a
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
21 */ 21 */
22 22
23 #include "gntinternal.h"
23 #include "gntcheckbox.h" 24 #include "gntcheckbox.h"
24 25
25 enum 26 enum
26 { 27 {
27 SIG_TOGGLED = 1, 28 SIG_TOGGLED = 1,
34 static void 35 static void
35 gnt_check_box_draw(GntWidget *widget) 36 gnt_check_box_draw(GntWidget *widget)
36 { 37 {
37 GntCheckBox *cb = GNT_CHECK_BOX(widget); 38 GntCheckBox *cb = GNT_CHECK_BOX(widget);
38 GntColorType type; 39 GntColorType type;
39 char *text; 40 gboolean focus = gnt_widget_has_focus(widget);
40 41
41 if (gnt_widget_has_focus(widget)) 42 if (focus)
42 type = GNT_COLOR_HIGHLIGHT; 43 type = GNT_COLOR_HIGHLIGHT;
43 else 44 else
44 type = GNT_COLOR_NORMAL; 45 type = GNT_COLOR_NORMAL;
45 46
46 wbkgdset(widget->window, '\0' | gnt_color_pair(type)); 47 wbkgdset(widget->window, '\0' | gnt_color_pair(type));
47 48
48 text = g_strdup_printf("[%c]", cb->checked ? 'X' : ' '); 49 mvwaddch(widget->window, 0, 0, '[');
49 mvwaddstr(widget->window, 0, 0, text); 50 mvwaddch(widget->window, 0, 1, (cb->checked ? 'X' : ' ') | (focus ? A_UNDERLINE : A_NORMAL));
50 g_free(text); 51 mvwaddch(widget->window, 0, 2, ']');
51 52
52 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); 53 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL));
53 mvwaddstr(widget->window, 0, 4, GNT_BUTTON(cb)->priv->text); 54 mvwaddstr(widget->window, 0, 4, (GNT_BUTTON(cb)->priv->text));
54 wmove(widget->window, 0, 1); 55 wmove(widget->window, 0, 1);
55 56
56 GNTDEBUG; 57 GNTDEBUG;
57 } 58 }
58 59