📄 matchbox-keyboard-key.c.svn-base
字号:
/* * Matchbox Keyboard - A lightweight software keyboard. * * Authored By Matthew Allum <mallum@o-hand.com> * * Copyright (c) 2005 OpenedHand Ltd - http://o-hand.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */#include "matchbox-keyboard.h"#define MBKB_N_KEY_STATES 5typedef struct MBKeyboardKeyFace{ MBKeyboardKeyFaceType type; union { MBKeyboardImage *image; char *str; } u;} MBKeyboardKeyFace;typedef struct MBKeyboardKeyAction{ MBKeyboardKeyActionType type; union { char *glyph; KeySym keysym; MBKeyboardKeyModType type; MBKeyboardLayoutType layout_type; } u;} MBKeyboardKeyAction;/* A key can have 5 different 'states' */typedef struct MBKeyboardKeyState{ MBKeyboardKeyAction action; MBKeyboardKeyFace face;} MBKeyboardKeyState;struct MBKeyboardKey{ MBKeyboard *kbd; MBKeyboardKeyState *states[N_MBKeyboardKeyStateTypes]; MBKeyboardRow *row; int alloc_x, alloc_y, alloc_width, alloc_height; int extra_width_pad; /* via win resizes */ int extra_height_pad; boolean obeys_caps; boolean fill; /* width fills avialble space */ int req_uwidth; /* unit width in 1/1000's */ boolean is_blank; /* 'blank' keys are spacers */ boolean extended; /* only show in landscape */ char *normal_image; /* The normal image */ char *push_image; /* The push down image */ MBKeyboardStateType sets_kbdstate; /* needed */};static void_mb_kbd_key_init_state(MBKeyboardKey *key, MBKeyboardKeyStateType state){ key->states[state] = util_malloc0(sizeof(MBKeyboardKeyState));}MBKeyboardKey*mb_kbd_key_new(MBKeyboard *kbd){ MBKeyboardKey *key = NULL; int i; key = util_malloc0(sizeof(MBKeyboardKey)); key->kbd = kbd; for (i=0; i<N_MBKeyboardKeyStateTypes; i++) key->states[i] = NULL; return key;}voidmb_kbd_key_set_normal_image(MBKeyboardKey *key, const char *image){ key->normal_image = strdup(image);}const char *mb_kbd_key_get_normal_image(MBKeyboardKey *key){ return key->normal_image;}voidmb_kbd_key_set_push_image(MBKeyboardKey *key, const char *image){ key->push_image = strdup(image);}const char *mb_kbd_key_get_push_image(MBKeyboardKey *key){ return key->push_image;}voidmb_kbd_key_set_obey_caps(MBKeyboardKey *key, boolean obey){ key->obeys_caps = obey;}booleanmb_kbd_key_get_obey_caps(MBKeyboardKey *key){ return key->obeys_caps;}voidmb_kbd_key_set_req_uwidth(MBKeyboardKey *key, int uwidth){ key->req_uwidth = uwidth;}intmb_kbd_key_get_req_uwidth(MBKeyboardKey *key){ return key->req_uwidth;}voidmb_kbd_key_set_fill(MBKeyboardKey *key, boolean fill){ MARK(); key->fill = fill;}booleanmb_kbd_key_get_fill(MBKeyboardKey *key){ return key->fill;}voidmb_kbd_key_set_blank(MBKeyboardKey *key, boolean blank){ key->is_blank = blank;}booleanmb_kbd_key_is_blank(MBKeyboardKey *key){ return key->is_blank;}voidmb_kbd_key_set_geometry(MBKeyboardKey *key, int x, int y, int width, int height){ if (x != -1) key->alloc_x = x; if (y != -1) key->alloc_y = y; if (width != -1) key->alloc_width = width; if (height != -1) key->alloc_height = height;}int mb_kbd_key_abs_x(MBKeyboardKey *key) { return mb_kbd_row_x(key->row) + key->alloc_x;}int mb_kbd_key_abs_y(MBKeyboardKey *key) { return mb_kbd_row_y(key->row) + key->alloc_y;}int mb_kbd_key_x(MBKeyboardKey *key) { return key->alloc_x;}int mb_kbd_key_y(MBKeyboardKey *key) { return key->alloc_y;}int mb_kbd_key_width(MBKeyboardKey *key) { return key->alloc_width;}int mb_kbd_key_height(MBKeyboardKey *key) { return key->alloc_height;}voidmb_kbd_key_set_extra_width_pad(MBKeyboardKey *key, int pad){ key->alloc_width -= key->extra_width_pad; key->extra_width_pad = pad; key->alloc_width += key->extra_width_pad;}voidmb_kbd_key_set_extra_height_pad(MBKeyboardKey *key, int pad){ key->alloc_height -= key->extra_height_pad; key->extra_height_pad = pad; key->alloc_height += key->extra_height_pad;}intmb_kbd_key_get_extra_height_pad(MBKeyboardKey *key){ return key->extra_height_pad;}intmb_kbd_key_get_extra_width_pad(MBKeyboardKey *key){ return key->extra_width_pad;}voidmb_kbd_key_set_extended(MBKeyboardKey *key, boolean extend){ key->extended = extend;}booleanmb_kbd_key_get_extended(MBKeyboardKey *key){ return key->extended;}/* URG Nasty - some stuf should be public-ish */void mb_kbd_key_set_row(MBKeyboardKey *key, MBKeyboardRow *row) { key->row = row;}booleanmb_kdb_key_has_state(MBKeyboardKey *key, MBKeyboardKeyStateType state){ return (key->states[state] != NULL);}voidmb_kbd_key_set_glyph_face(MBKeyboardKey *key, MBKeyboardKeyStateType state, const char *glyph){ if (key->states[state] == NULL) _mb_kbd_key_init_state(key, state); key->states[state]->face.type = MBKeyboardKeyFaceGlyph; key->states[state]->face.u.str = strdup(glyph);}const char*mb_kbd_key_get_glyph_face(MBKeyboardKey *key, MBKeyboardKeyStateType state){ if (key->states[state] && key->states[state]->face.type == MBKeyboardKeyFaceGlyph) { return key->states[state]->face.u.str; } return NULL;}voidmb_kbd_key_set_image_face(MBKeyboardKey *key, MBKeyboardKeyStateType state, MBKeyboardImage *image){ if (key->states[state] == NULL) _mb_kbd_key_init_state(key, state); key->states[state]->face.type = MBKeyboardKeyFaceImage; key->states[state]->face.u.image = image;}MBKeyboardImage*mb_kbd_key_get_image_face(MBKeyboardKey *key, MBKeyboardKeyStateType state){ if (key->states[state] && key->states[state]->face.type == MBKeyboardKeyFaceImage) { return key->states[state]->face.u.image; } return NULL;}voidmb_kbd_key_set_char_action(MBKeyboardKey *key, MBKeyboardKeyStateType state, const char *glyphs){ if (key->states[state] == NULL) _mb_kbd_key_init_state(key, state); key->states[state]->action.type = MBKeyboardKeyActionGlyph; key->states[state]->action.u.glyph = strdup(glyphs);}const char*mb_kbd_key_get_char_action(MBKeyboardKey *key, MBKeyboardKeyStateType state){ if (key->states[state] && key->states[state]->action.type == MBKeyboardKeyActionGlyph) return key->states[state]->action.u.glyph; return NULL;}voidmb_kbd_key_set_keysym_action(MBKeyboardKey *key,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -