summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Huang <shawn.p.huang@gmail.com>2010-05-30 21:39:08 +0800
committerPeng Huang <shawn.p.huang@gmail.com>2010-05-30 21:39:08 +0800
commit502b8e814fe1aa59c7f607a04c363ef0c03e476f (patch)
treed4cacd640494a25822a0602ee84f4e75772e548e
parent9211cbcd3d580cf96a2bea7d8dd3ec8beefca9a7 (diff)
downloadibus-libpinyin-502b8e814fe1aa59c7f607a04c363ef0c03e476f.tar.gz
ibus-libpinyin-502b8e814fe1aa59c7f607a04c363ef0c03e476f.tar.xz
ibus-libpinyin-502b8e814fe1aa59c7f607a04c363ef0c03e476f.zip
Use inline function and const value to replace some macors.
-rw-r--r--src/BopomofoEditor.cc2
-rw-r--r--src/BopomofoEngine.cc4
-rw-r--r--src/DoublePinyinEditor.cc2
-rw-r--r--src/FallbackEditor.cc2
-rw-r--r--src/PhoneticEditor.cc4
-rw-r--r--src/PinyinEditor.cc6
-rw-r--r--src/PinyinEngine.cc4
-rw-r--r--src/PunctEditor.cc4
-rw-r--r--src/Util.h60
9 files changed, 48 insertions, 40 deletions
diff --git a/src/BopomofoEditor.cc b/src/BopomofoEditor.cc
index 5d0eaeb..32becf4 100644
--- a/src/BopomofoEditor.cc
+++ b/src/BopomofoEditor.cc
@@ -310,7 +310,7 @@ BopomofoEditor::processNumberWithShift (guint keyval, guint keycode, guint modif
inline gboolean
BopomofoEditor::processBopomofo (guint keyval, guint keycode, guint modifiers)
{
- if (G_UNLIKELY (CMSHM_FILTER (modifiers) != 0))
+ if (G_UNLIKELY (cmshm_filter (modifiers) != 0))
return m_text ? TRUE : FALSE;
if (keyvalToBopomofo (keyval) == BOPOMOFO_ZERO)
diff --git a/src/BopomofoEngine.cc b/src/BopomofoEngine.cc
index 08adf8c..3a89de7 100644
--- a/src/BopomofoEngine.cc
+++ b/src/BopomofoEngine.cc
@@ -89,7 +89,7 @@ BopomofoEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers)
}
/* Toggle simp/trad Chinese Mode when hotkey Ctrl + Shift + F pressed */
- if (keyval == IBUS_F && SCMSHM_TEST (modifiers, (IBUS_SHIFT_MASK | IBUS_CONTROL_MASK))) {
+ if (keyval == IBUS_F && scmshm_test (modifiers, (IBUS_SHIFT_MASK | IBUS_CONTROL_MASK))) {
m_props.toggleModeSimp();
m_prev_pressed_key = IBUS_F;
return TRUE;
@@ -98,7 +98,7 @@ BopomofoEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers)
if (m_props.modeChinese ()) {
if (G_UNLIKELY (m_input_mode == MODE_INIT &&
m_editors[MODE_INIT]->text ().empty () &&
- (CMSHM_FILTER (modifiers)) == 0) &&
+ (cmshm_filter (modifiers)) == 0) &&
keyval == IBUS_grave) {
/* if BopomofoEditor is empty and get a grave key,
* switch current editor to PunctEditor */
diff --git a/src/DoublePinyinEditor.cc b/src/DoublePinyinEditor.cc
index 6ad064e..aae4812 100644
--- a/src/DoublePinyinEditor.cc
+++ b/src/DoublePinyinEditor.cc
@@ -473,7 +473,7 @@ DoublePinyinEditor::processKeyEvent (guint keyval, guint keycode, guint modifier
{
/* handle ';' key */
if (G_UNLIKELY (keyval == IBUS_semicolon)) {
- if (CMSHM_FILTER (modifiers) == 0) {
+ if (cmshm_filter (modifiers) == 0) {
if (insert (keyval))
return TRUE;
}
diff --git a/src/FallbackEditor.cc b/src/FallbackEditor.cc
index c93f923..d95ff53 100644
--- a/src/FallbackEditor.cc
+++ b/src/FallbackEditor.cc
@@ -163,7 +163,7 @@ FallbackEditor::processPunctForTraditionalChinese (guint keyval, guint keycode,
inline gboolean
FallbackEditor::processPunct (guint keyval, guint keycode, guint modifiers)
{
- guint cmshm_modifiers = CMSHM_FILTER (modifiers);
+ guint cmshm_modifiers = cmshm_filter (modifiers);
if (G_UNLIKELY (keyval == IBUS_period && cmshm_modifiers == IBUS_CONTROL_MASK)) {
m_props.toggleModeFullPunct ();
diff --git a/src/PhoneticEditor.cc b/src/PhoneticEditor.cc
index f4522ec..d3075aa 100644
--- a/src/PhoneticEditor.cc
+++ b/src/PhoneticEditor.cc
@@ -40,7 +40,7 @@ PhoneticEditor::processSpace (guint keyval, guint keycode, guint modifiers)
{
if (!m_text)
return FALSE;
- if (CMSHM_FILTER (modifiers) != 0)
+ if (cmshm_filter (modifiers) != 0)
return TRUE;
if (m_lookup_table.size () != 0) {
selectCandidate (m_lookup_table.cursorPos ());
@@ -58,7 +58,7 @@ PhoneticEditor::processFunctionKey (guint keyval, guint keycode, guint modifiers
return FALSE;
/* ignore numlock */
- modifiers = CMSHM_FILTER (modifiers);
+ modifiers = cmshm_filter (modifiers);
if (modifiers != 0 && modifiers != IBUS_CONTROL_MASK)
return TRUE;
diff --git a/src/PinyinEditor.cc b/src/PinyinEditor.cc
index fa92282..08c116d 100644
--- a/src/PinyinEditor.cc
+++ b/src/PinyinEditor.cc
@@ -37,7 +37,7 @@ PinyinEditor::PinyinEditor (PinyinProperties & props, Config & config)
inline gboolean
PinyinEditor::processPinyin (guint keyval, guint keycode, guint modifiers)
{
- if (G_UNLIKELY (CMSHM_FILTER (modifiers) != 0))
+ if (G_UNLIKELY (cmshm_filter (modifiers) != 0))
return m_text ? TRUE : FALSE;
return insert (keyval);
@@ -81,7 +81,7 @@ PinyinEditor::processPunct (guint keyval, guint keycode, guint modifiers)
if (m_text.empty ())
return FALSE;
- if (CMSHM_FILTER (modifiers) != 0)
+ if (cmshm_filter (modifiers) != 0)
return TRUE;
switch (keyval) {
@@ -130,7 +130,7 @@ PinyinEditor::processFunctionKey (guint keyval, guint keycode, guint modifiers)
return FALSE;
/* ignore numlock */
- modifiers = CMSHM_FILTER (modifiers);
+ modifiers = cmshm_filter (modifiers);
if (modifiers != 0 && modifiers != IBUS_CONTROL_MASK)
return TRUE;
diff --git a/src/PinyinEngine.cc b/src/PinyinEngine.cc
index 3b07c2d..ee151fc 100644
--- a/src/PinyinEngine.cc
+++ b/src/PinyinEngine.cc
@@ -91,7 +91,7 @@ PinyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers)
}
/* Toggle simp/trad Chinese Mode when hotkey Ctrl + Shift + F pressed */
- if (keyval == IBUS_F && SCMSHM_TEST (modifiers, (IBUS_SHIFT_MASK | IBUS_CONTROL_MASK))) {
+ if (keyval == IBUS_F && scmshm_test (modifiers, (IBUS_SHIFT_MASK | IBUS_CONTROL_MASK))) {
m_props.toggleModeSimp();
m_prev_pressed_key = IBUS_F;
return TRUE;
@@ -99,7 +99,7 @@ PinyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers)
if (m_props.modeChinese ()) {
if (m_input_mode == MODE_INIT &&
- ((CMSHM_FILTER (modifiers)) == 0)) {
+ ((cmshm_filter (modifiers)) == 0)) {
const String & text = m_editors[MODE_INIT]->text ();
if (text.empty ()) {
switch (keyval) {
diff --git a/src/PunctEditor.cc b/src/PunctEditor.cc
index bbe7e39..65c6494 100644
--- a/src/PunctEditor.cc
+++ b/src/PunctEditor.cc
@@ -78,7 +78,7 @@ PunctEditor::processSpace (guint keyval, guint keycode, guint modifiers)
{
if (m_punct_mode != MODE_INIT && m_punct_mode != MODE_NORMAL)
return FALSE;
- if (CMSHM_FILTER (modifiers) != 0)
+ if (cmshm_filter (modifiers) != 0)
return TRUE;
commit ();
return TRUE;
@@ -87,7 +87,7 @@ PunctEditor::processSpace (guint keyval, guint keycode, guint modifiers)
gboolean
PunctEditor::processPunct (guint keyval, guint keycode, guint modifiers)
{
- if (CMSHM_FILTER (modifiers) != 0)
+ if (cmshm_filter (modifiers) != 0)
return TRUE;
if (m_punct_mode == MODE_DISABLE) {
diff --git a/src/Util.h b/src/Util.h
index a0c7cf5..bb3a712 100644
--- a/src/Util.h
+++ b/src/Util.h
@@ -35,34 +35,42 @@
#include <cstdlib>
#include <string>
-namespace PY {
-
-#define CMSHM_MASK \
- (IBUS_CONTROL_MASK | \
- IBUS_MOD1_MASK | \
- IBUS_SUPER_MASK | \
- IBUS_HYPER_MASK | \
- IBUS_META_MASK)
-
-#define SCMSHM_MASK \
- (IBUS_SHIFT_MASK | \
- IBUS_CONTROL_MASK | \
- IBUS_MOD1_MASK | \
- IBUS_SUPER_MASK | \
- IBUS_HYPER_MASK | \
- IBUS_META_MASK)
+#include <ibus.h>
-#define CMSHM_FILTER(modifiers) \
- (modifiers & (CMSHM_MASK))
-
-#define SCMSHM_FILTER(modifiers) \
- (modifiers & (SCMSHM_MASK))
-
-#define CMSHM_TEST(modifiers, mask) \
- (CMSHM_FILTER (modifiers) == (mask))
+namespace PY {
-#define SCMSHM_TEST(modifiers, mask) \
- (SCMSHM_FILTER (modifiers) == (mask))
+// mask for Ctrl, Alt, Super, Hyper, Meta
+const guint CMSHM_MASK = IBUS_CONTROL_MASK |
+ IBUS_MOD1_MASK |
+ IBUS_SUPER_MASK |
+ IBUS_HYPER_MASK |
+ IBUS_META_MASK;
+// mask for Shift, Ctrl, Alt, Super, Hyper, Meta
+const guint SCMSHM_MASK = CMSHM_MASK | IBUS_SHIFT_MASK;
+
+inline guint
+cmshm_filter (guint modifiers)
+{
+ return modifiers & CMSHM_MASK;
+}
+
+inline guint
+scmshm_filter (guint modifiers)
+{
+ return modifiers & SCMSHM_MASK;
+}
+
+inline gboolean
+cmshm_test (guint modifiers, guint mask)
+{
+ return cmshm_filter (modifiers) == mask;
+}
+
+inline gboolean
+scmshm_test (guint modifiers, guint mask)
+{
+ return scmshm_filter (modifiers) == mask;
+}
class UUID {
public: