1
/* $Id: widget_keypad.c 996 2009-03-23 17:22:24Z volker $
2
* $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/widget_keypad.c $
4
* keypad widget handling
6
* Copyright (C) 2006 Chris Maj <cmaj@freedomcorpse.com>
7
* Copyright (C) 2006 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2, or (at your option)
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
* WIDGET_CLASS Widget_Keypad
46
#include "widget_keypad.h"
53
int widget_keypad_draw(WIDGET * Self)
55
WIDGET_KEYPAD *keypad = Self->data;
57
/* evaluate properties */
58
property_eval(&keypad->expression);
60
return P2N(&keypad->expression);
64
int widget_keypad_init(WIDGET * Self)
68
WIDGET_KEYPAD *keypad;
70
/* prepare config section */
71
/* strlen("Widget:")=7 */
72
section = malloc(strlen(Self->name) + 8);
73
strcpy(section, "Widget:");
74
strcat(section, Self->name);
76
keypad = malloc(sizeof(WIDGET_KEYPAD));
77
memset(keypad, 0, sizeof(WIDGET_KEYPAD));
80
property_load(section, "expression", NULL, &keypad->expression);
82
/* state: pressed (default), released */
83
c = cfg_get(section, "state", "pressed");
84
if (!strcasecmp(c, "released"))
85
keypad->key = WIDGET_KEY_RELEASED;
87
keypad->key = WIDGET_KEY_PRESSED;
89
/* position: confirm (default), up, down, left, right, cancel */
90
c = cfg_get(section, "position", "confirm");
91
if (!strcasecmp(c, "up"))
92
keypad->key += WIDGET_KEY_UP;
93
else if (!strcasecmp(c, "down"))
94
keypad->key += WIDGET_KEY_DOWN;
95
else if (!strcasecmp(c, "left"))
96
keypad->key += WIDGET_KEY_LEFT;
97
else if (!strcasecmp(c, "right"))
98
keypad->key += WIDGET_KEY_RIGHT;
99
else if (!strcasecmp(c, "cancel"))
100
keypad->key += WIDGET_KEY_CANCEL;
102
keypad->key += WIDGET_KEY_CONFIRM;
112
int widget_keypad_find(WIDGET * Self, void *needle)
114
WIDGET_KEYPAD *keypad;
115
KEYPADKEY key = *(KEYPADKEY *) needle;
117
if (Self && Self->data) {
119
if (keypad->key == key)
126
int widget_keypad_quit(WIDGET * Self)
128
if (Self && Self->data) {
129
WIDGET_KEYPAD *keypad = Self->data;
130
property_free(&keypad->expression);
139
WIDGET_CLASS Widget_Keypad = {
141
.type = WIDGET_TYPE_KEYPAD,
142
.init = widget_keypad_init,
143
.draw = widget_keypad_draw,
144
.find = widget_keypad_find,
145
.quit = widget_keypad_quit,