1 /*
2  * Copyright © 2016  Red Hat, Inc. All rights reserved.
3  * Copyright © 2016  Ding-Yi Chen <dchen@redhat.com>
4  *
5  * This file is part of the ibus-chewing Project.
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  * ibus_chewing_pre_edit private function definitions
24  * Put it here so they can be tested.
25  */
26 #ifndef _IBUS_CHEWING_PRE_EDIT_PRIVATE_H_
27 #define _IBUS_CHEWING_PRE_EDIT_PRIVATE_H_
28 
29 /*== Frequent used shortcut ==*/
30 #define cursor_current chewing_cursor_Current(self->context)
31 #define total_choice chewing_cand_TotalChoice(self->context)
32 #define default_english_case_short \
33     (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "default-english-case"), "lowercase")) ? 'l' : \
34 (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "default-english-case"), "uppercase") ? 'u' : 'n')
35 
36 /*== Conditional Expression Shortcut ==*/
37 #define is_plain_zhuyin ibus_chewing_pre_edit_get_property_boolean(self, "plain-zhuyin")
38 #define bpmf_check ibus_chewing_bopomofo_check(self->context)
39 #define table_is_showing ibus_chewing_pre_edit_has_flag(self,FLAG_TABLE_SHOW)
40 
41 #define is_capslock (umaskedMod == IBUS_LOCK_MASK)
42 #define is_shift_only (maskedMod == IBUS_SHIFT_MASK)
43 #define is_shift (unmaskedMod & IBUS_SHIFT_MASK)
44 #define is_ctrl_only (maskedMod == IBUS_CONTROL_MASK)
45 #define buffer_is_empty (ibus_chewing_pre_edit_is_empty(self))
46 
47 
48 /*== Event processing ==*/
49 /* We only recognize the combination of shift, control and alt */
50 #define modifiers_mask(unmaskedMod) unmaskedMod & (IBUS_SHIFT_MASK | IBUS_CONTROL_MASK | IBUS_MOD1_MASK)
51 
52 /**
53  * filter_modifier:
54  * @allowed Allowed modifler.
55  *
56  * allowed=0 means only the keysym is allowed, no shift, alt, control are allowed.
57  * allowed=IBUS_SHIFT_MASK means both keysym without modifier or shift are allowed.
58  */
59 #define filter_modifiers(allowed) KeyModifiers maskedMod = modifiers_mask(unmaskedMod); \
60 							if ( (maskedMod) & (~(allowed))){ return EVENT_RESPONSE_IGNORE; }
61 #define absorb_when_release if (event_is_released(unmaskedMod)){ return EVENT_RESPONSE_ABSORB; }
62 #define ignore_when_buffer_is_empty if (buffer_is_empty) { return EVENT_RESPONSE_IGNORE;}
63 
64 #define event_is_released(unmaskedMod) ((unmaskedMod & IBUS_RELEASE_MASK) !=0 )
65 #define event_process_or_ignore(cond) (cond) ? EVENT_RESPONSE_PROCESS: EVENT_RESPONSE_IGNORE
66 
67 #define handle_log(funcName) IBUS_CHEWING_LOG(INFO, "* self_handle_%s(-,%x(%s),%x(%s))", funcName, kSym, key_sym_get_name(kSym), unmaskedMod, modifiers_to_string(unmaskedMod));
68 
69 KSym self_key_sym_fix(IBusChewingPreEdit * self, KSym kSym,
70 		 KeyModifiers unmaskedMod);
71 
72 EventResponse self_handle_key_sym_default(IBusChewingPreEdit * self,
73 					  KSym kSym,
74 					  KeyModifiers unmaskedMod);
75 
76 void ibus_chewing_pre_edit_update(IBusChewingPreEdit * self);
77 #endif				/* _IBUS_CHEWING_PRE_EDIT_PRIVATE_H_ */
78