NetSurf
osk.c
Go to the documentation of this file.
1/*
2 * Copyright 2010 Vincent Sanders <vince@simtec.co.uk>
3 *
4 * Framebuffer windowing toolkit on screen keyboard.
5 *
6 * This file is part of NetSurf, http://www.netsurf-browser.org/
7 *
8 * NetSurf is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * NetSurf 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, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <stdbool.h>
22#include <limits.h>
23
24#include <libnsfb.h>
25#include <libnsfb_plot.h>
26#include <libnsfb_event.h>
27#include <libnsfb_cursor.h>
28
29#include "utils/log.h"
31
32#include "framebuffer/gui.h"
33#include "framebuffer/fbtk.h"
35
36#include "widget.h"
37
39 int x;
40 int y;
41 int w;
42 int h;
43 const char *t;
44 enum nsfb_key_code_e keycode;
45};
46
47#define KEYCOUNT 58
48
49static struct kbd_button_s kbdbase[KEYCOUNT] = {
50 { 0, 0, 20, 15, "`", NSFB_KEY_BACKQUOTE},
51 { 20, 0, 20, 15, "1", NSFB_KEY_1},
52 { 40, 0, 20, 15, "2", NSFB_KEY_2},
53 { 60, 0, 20, 15, "3", NSFB_KEY_3},
54 { 80, 0, 20, 15, "4", NSFB_KEY_4},
55 { 100, 0, 20, 15, "5", NSFB_KEY_5},
56 { 120, 0, 20, 15, "6", NSFB_KEY_6},
57 { 140, 0, 20, 15, "7", NSFB_KEY_7},
58 { 160, 0, 20, 15, "8", NSFB_KEY_8},
59 { 180, 0, 20, 15, "9", NSFB_KEY_9},
60 { 200, 0, 20, 15, "0", NSFB_KEY_0},
61 { 220, 0, 20, 15, "-", NSFB_KEY_MINUS},
62 { 240, 0, 20, 15, "=", NSFB_KEY_EQUALS},
63 { 260, 0, 40, 15, "\xe2\x8c\xab", NSFB_KEY_BACKSPACE},
64 { 0, 15, 30, 15, "\xe2\x86\xb9", NSFB_KEY_TAB},
65 { 30, 15, 20, 15, "q", NSFB_KEY_q},
66 { 50, 15, 20, 15, "w", NSFB_KEY_w},
67 { 70, 15, 20, 15, "e", NSFB_KEY_e},
68 { 90, 15, 20, 15, "r", NSFB_KEY_r},
69 { 110, 15, 20, 15, "t", NSFB_KEY_t},
70 { 130, 15, 20, 15, "y", NSFB_KEY_y},
71 { 150, 15, 20, 15, "u", NSFB_KEY_u},
72 { 170, 15, 20, 15, "i", NSFB_KEY_i},
73 { 190, 15, 20, 15, "o", NSFB_KEY_o},
74 { 210, 15, 20, 15, "p", NSFB_KEY_p},
75 { 230, 15, 20, 15, "[", NSFB_KEY_LEFTBRACKET},
76 { 250, 15, 20, 15, "]", NSFB_KEY_RIGHTBRACKET},
77 { 275, 15, 25, 30, "\xe2\x8f\x8e", NSFB_KEY_RETURN},
78 { 35, 30, 20, 15, "a", NSFB_KEY_a},
79 { 55, 30, 20, 15, "s", NSFB_KEY_s},
80 { 75, 30, 20, 15, "d", NSFB_KEY_d},
81 { 95, 30, 20, 15, "f", NSFB_KEY_f},
82 { 115, 30, 20, 15, "g", NSFB_KEY_g},
83 { 135, 30, 20, 15, "h", NSFB_KEY_h},
84 { 155, 30, 20, 15, "j", NSFB_KEY_j},
85 { 175, 30, 20, 15, "k", NSFB_KEY_k},
86 { 195, 30, 20, 15, "l", NSFB_KEY_l},
87 { 215, 30, 20, 15, ";", NSFB_KEY_SEMICOLON},
88 { 235, 30, 20, 15, "'", NSFB_KEY_l},
89 { 255, 30, 20, 15, "#", NSFB_KEY_HASH},
90 { 0, 45, 25, 15, "\xe2\x87\xa7", NSFB_KEY_LSHIFT},
91 { 25, 45, 20, 15, "\\", NSFB_KEY_SLASH},
92 { 45, 45, 20, 15, "z", NSFB_KEY_z},
93 { 65, 45, 20, 15, "x", NSFB_KEY_x},
94 { 85, 45, 20, 15, "c", NSFB_KEY_c},
95 { 105, 45, 20, 15, "v", NSFB_KEY_v},
96 { 125, 45, 20, 15, "b", NSFB_KEY_b},
97 { 145, 45, 20, 15, "n", NSFB_KEY_n},
98 { 165, 45, 20, 15, "m", NSFB_KEY_m},
99 { 185, 45, 20, 15, ",", NSFB_KEY_COMMA},
100 { 205, 45, 20, 15, ".", NSFB_KEY_PERIOD},
101 { 225, 45, 20, 15, "/", NSFB_KEY_BACKSLASH},
102 { 245, 45, 55, 15, "\xe2\x87\xa7", NSFB_KEY_RSHIFT},
103 { 40, 67, 185, 15, "", NSFB_KEY_SPACE},
104 { 250, 60, 20, 15, "\xe2\x96\xb2", NSFB_KEY_UP},
105 { 230, 67, 20, 15, "\xe2\x97\x80", NSFB_KEY_LEFT},
106 { 270, 67, 20, 15, "\xe2\x96\xb6", NSFB_KEY_RIGHT},
107 { 250, 75, 20, 15, "\xe2\x96\xbc", NSFB_KEY_DOWN},
108};
109
111
112static int
114{
115 if (cbi->event->type != NSFB_EVENT_KEY_UP)
116 return 0;
117
118 fbtk_set_mapping(osk, false);
119
120 return 0;
121}
122
123static int
125{
126 nsfb_event_t event;
127 struct kbd_button_s *kbd_button = cbi->context;
128
129 event.type = cbi->event->type;
130 event.value.keycode = kbd_button->keycode;
131 fbtk_input(widget, &event);
132
133 return 0;
134}
135
136/* exported function documented in fbtk.h */
137void
139{
140 fbtk_widget_t *widget;
141 int kloop;
142 int maxx = 0;
143 int maxy = 0;
144 int ww;
145 int wh;
147 int furniture_width = 18;
148
149 for (kloop=0; kloop < KEYCOUNT; kloop++) {
150 if ((kbdbase[kloop].x + kbdbase[kloop].w) > maxx)
151 maxx=kbdbase[kloop].x + kbdbase[kloop].w;
152 if ((kbdbase[kloop].y + kbdbase[kloop].h) > maxy)
153 maxy=kbdbase[kloop].y + kbdbase[kloop].h;
154 }
155
156 ww = fbtk_get_width(root);
157
158 /* scale window height apropriately */
159 wh = (maxy * ww) / maxx;
160
161 osk = fbtk_create_window(root, 0, fbtk_get_height(root) - wh, 0, wh, 0xff202020);
162
163 for (kloop=0; kloop < KEYCOUNT; kloop++) {
165 (kbdbase[kloop].x * ww) / maxx,
166 (kbdbase[kloop].y * ww) / maxx,
167 (kbdbase[kloop].w * ww) / maxx,
168 (kbdbase[kloop].h *ww) / maxx,
171 osk_click,
172 &kbdbase[kloop]);
173 fbtk_set_text(widget, kbdbase[kloop].t);
174 }
175
176 widget = fbtk_create_button(osk,
177 fbtk_get_width(osk) - furniture_width,
178 fbtk_get_height(osk) - furniture_width,
179 furniture_width,
180 furniture_width,
182 &osk_image,
183 osk_close,
184 NULL);
185}
186
187/* exported function documented in fbtk.h */
188void
190{
191 fbtk_set_zorder(osk, INT_MIN);
192 fbtk_set_mapping(osk, true);
193}
194
195/*
196 * Local Variables:
197 * c-basic-offset:8
198 * End:
199 */
Browser window creation and manipulation interface.
fbtk_widget_t * fbtk_get_root_widget(fbtk_widget_t *widget)
find the root widget from any widget in the toolkit hierarchy.
Definition: fbtk.c:412
int fbtk_set_mapping(fbtk_widget_t *widget, bool mapped)
Map a widget and request it is redrawn.
Definition: fbtk.c:127
#define FB_COLOUR_BLACK
Definition: fbtk.h:26
int fbtk_get_width(fbtk_widget_t *widget)
Get a widget's width.
Definition: fbtk.c:467
int fbtk_set_zorder(fbtk_widget_t *widget, int z)
Set the z order of a widget.
Definition: fbtk.c:181
#define FB_FRAME_COLOUR
Definition: fbtk.h:25
fbtk_widget_t * fbtk_create_window(fbtk_widget_t *parent, int x, int y, int width, int height, colour bg)
Create a window widget.
Definition: window.c:66
fbtk_widget_t * fbtk_create_text_button(fbtk_widget_t *window, int x, int y, int width, int height, colour bg, colour fg, fbtk_callback click, void *pw)
Create a button with text.
Definition: text.c:639
void fbtk_set_text(fbtk_widget_t *widget, const char *text)
Change the text of a text widget.
Definition: text.c:542
fbtk_widget_t * fbtk_create_button(fbtk_widget_t *window, int x, int y, int width, int height, colour c, struct fbtk_bitmap *image, fbtk_callback click, void *pw)
Create a button widget with an image.
Definition: bitmap.c:107
int fbtk_get_height(fbtk_widget_t *widget)
Get a widget's height.
Definition: fbtk.c:460
void fbtk_input(fbtk_widget_t *widget, nsfb_event_t *event)
Insert input into toolkit.
Definition: event.c:45
static struct directory * root
Definition: filename.c:55
fbtk_widget_t * fbtk
Definition: gui.c:63
struct fbtk_bitmap osk_image
static struct kbd_button_s kbdbase[KEYCOUNT]
Definition: osk.c:49
static int osk_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: osk.c:124
static int osk_close(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: osk.c:113
#define KEYCOUNT
Definition: osk.c:47
void map_osk(void)
show the osk.
Definition: osk.c:189
void fbtk_enable_oskb(fbtk_widget_t *fbtk)
enable the on screen keyboard for input
Definition: osk.c:138
static fbtk_widget_t * osk
Definition: osk.c:110
widget callback information
Definition: fbtk.h:52
nsfb_event_t * event
Definition: fbtk.h:55
void * context
Definition: fbtk.h:54
Widget description.
Definition: widget.h:120
int x
Definition: osk.c:39
enum nsfb_key_code_e keycode
Definition: osk.c:44
int y
Definition: osk.c:40
int w
Definition: osk.c:41
const char * t
Definition: osk.c:43
int h
Definition: osk.c:42