~bless/bless/trunk

« back to all changes in this revision

Viewing changes to src/app_input.h

  • Committer: Alexandros Frantzis
  • Date: 2010-02-28 21:33:08 UTC
  • Revision ID: alf82@freemail.gr-20100228213308-nuor1zssp1o4zysc
Initial commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2009 Alexandros Frantzis
 
3
 *
 
4
 * This file is part of bless.
 
5
 *
 
6
 * bless is free software: you can redistribute it and/or modify it under the
 
7
 * terms of the GNU Lesser General Public License as published by the Free
 
8
 * Software Foundation, either version 3 of the License, or (at your option)
 
9
 * any later version.
 
10
 *
 
11
 * bless is distributed in the hope that it will be useful, but WITHOUT ANY
 
12
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
14
 * details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License along with
 
17
 * bless.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
/**
 
21
 * @file app_input.h
 
22
 *
 
23
 * Input handling API.
 
24
 */
 
25
#ifndef _BLESS_APP_INPUT_H
 
26
#define _BLESS_APP_INPUT_H
 
27
 
 
28
#ifdef __cplusplus
 
29
extern "C" {
 
30
#endif
 
31
        
 
32
#include <bless-ui/pos.h>
 
33
#include "app_action.h"
 
34
        
 
35
/**
 
36
 * @defgroup app_input Input handling
 
37
 *
 
38
 * @{
 
39
 */
 
40
        
 
41
/** 
 
42
 * Input handler modes.
 
43
 */
 
44
enum {
 
45
        BLESS_APP_INPUT_MODE_NORMAL = 0,
 
46
        BLESS_APP_INPUT_MODE_INSERT
 
47
};
 
48
 
 
49
/** 
 
50
 * Domains in which to apply keymaps in the input handler.
 
51
 */
 
52
enum {
 
53
        BLESS_APP_INPUT_DOMAIN_NORMAL = 0,
 
54
        BLESS_APP_INPUT_DOMAIN_INSERT,
 
55
        BLESS_APP_INPUT_DOMAIN_OBJECT
 
56
};
 
57
 
 
58
/** 
 
59
 * Argument types for input handler actions
 
60
 */
 
61
enum {
 
62
        BLESS_APP_INPUT_ARG_TYPE_INFO = 1,
 
63
        BLESS_APP_INPUT_ARG_TYPE_OBJECT,
 
64
        BLESS_APP_INPUT_ARG_TYPE_STRING
 
65
};
 
66
 
 
67
/** 
 
68
 * The result of key processing.
 
69
 */
 
70
enum {
 
71
        BLESS_APP_INPUT_RESULT_HANDLED = 0,
 
72
        BLESS_APP_INPUT_RESULT_NOT_HANDLED,
 
73
        BLESS_APP_INPUT_RESULT_PENDING,
 
74
        BLESS_APP_INPUT_RESULT_FAILED
 
75
};
 
76
 
 
77
/** 
 
78
 * Flags indicating whether an action can be used as a regular action,
 
79
 * a data object or both.
 
80
 */
 
81
enum {
 
82
        BLESS_APP_INPUT_ACTION_FLAG_ACTION = 1,
 
83
        BLESS_APP_INPUT_ACTION_FLAG_OBJECT = 2
 
84
};
 
85
 
 
86
typedef struct bless_app_input bless_app_input_t;
 
87
 
 
88
/** 
 
89
 * Data associated with key processing result.
 
90
 */
 
91
struct bless_app_input_result {
 
92
        /** The actual result (BLESS_APP_INPUT_RESULT_*) */
 
93
        int result;
 
94
        /** Pointer the key sequence */
 
95
        char *key_sequence;
 
96
        /** Pointer the next key to process */
 
97
        char *next_key;
 
98
};
 
99
 
 
100
/** 
 
101
 * Structure used to pass information to set a keymap.
 
102
 */
 
103
struct bless_app_input_keymap {
 
104
        /** The BLESS_APP_INPUT_DOMAIN_* for which this keymap will apply */
 
105
        int domain;
 
106
        /** Whether the mapping may be remapped */
 
107
        int remap;
 
108
        /** The key sequence to map */
 
109
        char *key_sequence;
 
110
        /** The key sequence to map to */
 
111
        char *key_mapping;
 
112
};
 
113
 
 
114
 
 
115
/** 
 
116
 * Structure used to pass information to register an action.
 
117
 */
 
118
struct bless_app_input_action {
 
119
        /** The key sequence associated with the action */
 
120
        char *key_sequence;
 
121
        /** The action */
 
122
        struct bless_app_action *action;
 
123
        /** User data associated with the action */
 
124
        void *data;
 
125
        /** Action usage flags (BLESS_APP_INPUT_ACTION_FLAG_*) */
 
126
        int flags;
 
127
};
 
128
 
 
129
/** 
 
130
 * A data object argument to an input action.
 
131
 */
 
132
struct bless_app_input_arg_data_object {
 
133
        /** The start of the data object */
 
134
        struct bless_pos start;
 
135
        /** The end of the data object */
 
136
        struct bless_pos end;
 
137
};
 
138
 
 
139
/** 
 
140
 * An info argument to an input action.
 
141
 */
 
142
struct bless_app_input_arg_info {
 
143
        /** The purpose of the action invocation (BLESS_APP_INPUT_ACTION_FLAG_*) */
 
144
        int flags;
 
145
        /** The count associated with the action invocation */
 
146
        off_t count;
 
147
};
 
148
 
 
149
int bless_app_input_new(bless_app_input_t **input);
 
150
int bless_app_input_free(bless_app_input_t *input);
 
151
 
 
152
int bless_app_input_register_action(bless_app_input_t *input,
 
153
                struct bless_app_input_action *action);
 
154
        
 
155
int bless_app_input_set_keymap(bless_app_input_t *input,
 
156
                struct bless_app_input_keymap *keymap);
 
157
 
 
158
int bless_app_input_set_mode(bless_app_input_t *input, int mode);
 
159
int bless_app_input_get_mode(bless_app_input_t *input, int *mode);
 
160
 
 
161
int bless_app_input_append_keys(bless_app_input_t *input, char *keys);
 
162
 
 
163
int bless_app_input_inject_keys(bless_app_input_t *input, char *keys);
 
164
 
 
165
int bless_app_input_process_keys(bless_app_input_t *input,
 
166
                struct bless_app_input_result *result);
 
167
 
 
168
int bless_app_input_reset(bless_app_input_t *input);
 
169
int bless_app_input_skip_keys(bless_app_input_t *input, size_t nskip);
 
170
 
 
171
/** @} */
 
172
 
 
173
#ifdef __cplusplus
 
174
}
 
175
#endif
 
176
 
 
177
#endif