~siretart/lcd4linux/debian

« back to all changes in this revision

Viewing changes to widget_keypad.c

  • Committer: Reinhard Tartler
  • Date: 2011-04-27 17:24:15 UTC
  • mto: This revision was merged to the branch mainline in revision 750.
  • Revision ID: siretart@tauware.de-20110427172415-6n4aptmvmz0eztvm
Tags: upstream-0.11.0~svn1143
ImportĀ upstreamĀ versionĀ 0.11.0~svn1143

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 $
 
3
 *
 
4
 * keypad widget handling
 
5
 *
 
6
 * Copyright (C) 2006 Chris Maj <cmaj@freedomcorpse.com>
 
7
 * Copyright (C) 2006 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
 
8
 *
 
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)
 
12
 * any later version.
 
13
 *
 
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.
 
18
 *
 
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.
 
22
 *
 
23
 */
 
24
 
 
25
/*
 
26
 * exported functions:
 
27
 *
 
28
 * WIDGET_CLASS Widget_Keypad
 
29
 *   the keypad widget
 
30
 *
 
31
 */
 
32
 
 
33
 
 
34
#include "config.h"
 
35
 
 
36
#include <stdlib.h>
 
37
#include <stdio.h>
 
38
#include <string.h>
 
39
#include <ctype.h>
 
40
 
 
41
#include "debug.h"
 
42
#include "cfg.h"
 
43
#include "property.h"
 
44
#include "timer.h"
 
45
#include "widget.h"
 
46
#include "widget_keypad.h"
 
47
 
 
48
#ifdef WITH_DMALLOC
 
49
#include <dmalloc.h>
 
50
#endif
 
51
 
 
52
 
 
53
int widget_keypad_draw(WIDGET * Self)
 
54
{
 
55
    WIDGET_KEYPAD *keypad = Self->data;
 
56
 
 
57
    /* evaluate properties */
 
58
    property_eval(&keypad->expression);
 
59
 
 
60
    return P2N(&keypad->expression);
 
61
}
 
62
 
 
63
 
 
64
int widget_keypad_init(WIDGET * Self)
 
65
{
 
66
    char *section;
 
67
    char *c;
 
68
    WIDGET_KEYPAD *keypad;
 
69
 
 
70
    /* prepare config section */
 
71
    /* strlen("Widget:")=7 */
 
72
    section = malloc(strlen(Self->name) + 8);
 
73
    strcpy(section, "Widget:");
 
74
    strcat(section, Self->name);
 
75
 
 
76
    keypad = malloc(sizeof(WIDGET_KEYPAD));
 
77
    memset(keypad, 0, sizeof(WIDGET_KEYPAD));
 
78
 
 
79
    /* load properties */
 
80
    property_load(section, "expression", NULL, &keypad->expression);
 
81
 
 
82
    /* state: pressed (default), released */
 
83
    c = cfg_get(section, "state", "pressed");
 
84
    if (!strcasecmp(c, "released"))
 
85
        keypad->key = WIDGET_KEY_RELEASED;
 
86
    else
 
87
        keypad->key = WIDGET_KEY_PRESSED;
 
88
 
 
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;
 
101
    else
 
102
        keypad->key += WIDGET_KEY_CONFIRM;
 
103
 
 
104
    free(section);
 
105
    Self->data = keypad;
 
106
    Self->x2 = NOCOORD;
 
107
    Self->y2 = NOCOORD;
 
108
 
 
109
    return 0;
 
110
}
 
111
 
 
112
int widget_keypad_find(WIDGET * Self, void *needle)
 
113
{
 
114
    WIDGET_KEYPAD *keypad;
 
115
    KEYPADKEY key = *(KEYPADKEY *) needle;
 
116
 
 
117
    if (Self && Self->data) {
 
118
        keypad = Self->data;
 
119
        if (keypad->key == key)
 
120
            return 0;
 
121
    }
 
122
 
 
123
    return -1;
 
124
}
 
125
 
 
126
int widget_keypad_quit(WIDGET * Self)
 
127
{
 
128
    if (Self && Self->data) {
 
129
        WIDGET_KEYPAD *keypad = Self->data;
 
130
        property_free(&keypad->expression);
 
131
        free(Self->data);
 
132
        Self->data = NULL;
 
133
    }
 
134
    return 0;
 
135
}
 
136
 
 
137
 
 
138
 
 
139
WIDGET_CLASS Widget_Keypad = {
 
140
    .name = "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,
 
146
};