Initial check-in
[him-cellwriter] / src / keys.h
1
2 /*
3
4 cellwriter -- a character recognition input method
5 Copyright (C) 2007 Michael Levin <risujin@risujin.org>
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
21 */
22
23 /*
24         Key events
25 */
26
27 typedef struct {
28         unsigned char shift;
29         unsigned int keysym;
30 } KeyEvent;
31
32 extern int key_shifted, key_num_locked, key_caps_locked;
33
34 void key_event_new(KeyEvent *key_event, unsigned int keysym);
35 void key_event_free(KeyEvent *key_event);
36 void key_event_press(KeyEvent *key_event);
37 void key_event_release(KeyEvent *key_event);
38 void key_event_send_char(int unichar);
39 void key_event_send_enter(void);
40 void key_event_update_mappings(void);
41
42 /*
43         Key widget
44 */
45
46 /* Key flags */
47 #define KEY_ARROW               0x0001
48 #define KEY_TOGGLE_ON           0x0002
49 #define KEY_TOGGLE_OFF          0x0003
50 #define KEY_ICON_MASK           0x000f
51 #define KEY_STICKY              0x0010
52 #define KEY_SHIFT               0x0020
53 #define KEY_SHIFTABLE           0x0040
54 #define KEY_CAPS_LOCK           0x0080
55 #define KEY_ICON_SHIFT          0x0100
56 #define KEY_NUM_LOCK            0x0200
57 #define KEY_NUM_LOCKABLE        0x0400
58
59 typedef struct {
60         char active;
61         short flags;
62         const char *string, *string_shift;
63         unsigned int keysym, keysym_shift;
64         int x, y, width, height, rotate;
65         KeyEvent key_event;
66 } Key;
67
68 typedef struct {
69         GtkWidget *drawing_area;
70         GdkPixmap *pixmap;
71         GdkGC *pixmap_gc;
72         cairo_t *cairo;
73         PangoContext *pango;
74         PangoFontDescription *pango_font_desc;
75         int slaved, len, max_len, x, y, width, height, active, x_range, y_range,
76             min_height;
77         Key keys[];
78 } KeyWidget;
79
80 extern int keyboard_size;
81
82 /* Create slaved or non-slaved keyboard */
83 KeyWidget *key_widget_new_small(GtkWidget *drawing_area);
84 KeyWidget *key_widget_new_full(void);
85
86 /* Functions for slaved keyboards only */
87 gboolean key_widget_button_press(GtkWidget *widget, GdkEventButton *event,
88                                  KeyWidget *key_widget);
89 gboolean key_widget_button_release(GtkWidget *widget, GdkEventButton *event,
90                                    KeyWidget *key_widget);
91 void key_widget_render(KeyWidget *key_widget);
92 void key_widget_configure(KeyWidget *key_widget, int x, int y,
93                           int width, int height);
94
95 /* Functions to update keyboards */
96 int key_widget_update_colors(void);
97 void key_widget_cleanup(KeyWidget *key_widget);
98