Show frequency symbols in lookup table 77/49777/3
authorLi Zhang <li2012.zhang@samsung.com>
Tue, 20 Oct 2015 07:09:25 +0000 (15:09 +0800)
committerLi Zhang <li2012.zhang@samsung.com>
Tue, 20 Oct 2015 09:08:30 +0000 (17:08 +0800)
Change-Id: I4add088fdc3bbf5e845c3480c211f49f0acaafe1

src/scim_anthy_imengine.cpp
src/scim_anthy_imengine.h

index c7f66a4..9e8956f 100755 (executable)
@@ -90,6 +90,8 @@
 #define UTF8_MIDDLE_DOT           "\xE3\x83\xBB"
 #define UTF8_SLASH_WIDE           "\xEF\xBC\x8F"
 
+static char g_common_symbol[]={'#','$','%','^','&','*','@'};
+
 AnthyInstance::AnthyInstance (AnthyFactory   *factory,
                               const String   &encoding,
                               int             id)
@@ -99,6 +101,7 @@ AnthyInstance::AnthyInstance (AnthyFactory   *factory,
       m_preedit                (*this),
       m_preedit_string_visible (false),
       m_lookup_table_visible   (false),
+      m_common_lookup_table    (0),
       m_n_conv_key_pressed     (0),
       m_prev_input_mode        (SCIM_ANTHY_MODE_HIRAGANA),
       m_conv_mode              (SCIM_ANTHY_CONVERSION_MULTI_SEGMENT),
@@ -107,10 +110,14 @@ AnthyInstance::AnthyInstance (AnthyFactory   *factory,
       m_layout                 (ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL)
 {
     SCIM_DEBUG_IMENGINE(1) << "Create Anthy Instance : ";
-
     reload_config (m_factory->m_config);
     m_factory->append_config_listener (this);
     m_on_init = false;
+    m_common_lookup_table = new CommonLookupTable();
+    for(int i = 0;i < sizeof(g_common_symbol)/sizeof(char);i++) {
+        char _str[2]={g_common_symbol[i],0};
+        m_common_lookup_table->append_candidate (utf8_mbstowcs ((const char*)_str));
+    }
 }
 
 AnthyInstance::~AnthyInstance ()
@@ -119,6 +126,7 @@ AnthyInstance::~AnthyInstance ()
         stop_helper (String (SCIM_ANTHY_HELPER_UUID));
 
     m_factory->remove_config_listener (this);
+    delete m_common_lookup_table;
 }
 
 // FIXME!
@@ -152,7 +160,7 @@ AnthyInstance::process_key_event_input (const KeyEvent &key)
             update_lookup_table (table);
             show_lookup_table ();
         } else {
-            hide_lookup_table ();
+            show_symbols_lookup_table ();
         }
     }
 
@@ -321,7 +329,7 @@ AnthyInstance::process_key_event (const KeyEvent& key)
         if (process_key_event_input (key))
             return true;
     }
-
+    show_symbols_lookup_table ();
     if (m_preedit.is_preediting ())
         return true;
     else
@@ -363,6 +371,18 @@ void
 AnthyInstance::select_candidate (unsigned int item)
 {
     SCIM_DEBUG_IMENGINE(2) << "select_candidate.\n";
+    if (!(m_lookup_table_visible && is_selecting_candidates ())) {
+        if (m_preedit.get_length () > 0) {
+            commit_string (m_preedit.get_string ());
+            flush ();
+            return;
+        }
+        if (item < sizeof (g_common_symbol)/sizeof (char)) {
+            char _str[2] = {g_common_symbol[item], 0};
+            commit_string (utf8_mbstowcs (_str));
+            return;
+        }
+    }
 
     select_candidate_no_direct (item);
 
@@ -466,7 +486,7 @@ AnthyInstance::focus_in ()
         show_lookup_table ();
     } else {
         hide_aux_string ();
-        hide_lookup_table ();
+        show_symbols_lookup_table ();
     }
 
     install_properties ();
@@ -564,7 +584,7 @@ AnthyInstance::set_lookup_table (void)
             show_aux_string ();
         }
     } else if (!m_lookup_table_visible) {
-        hide_lookup_table ();
+        show_symbols_lookup_table ();
     }
 }
 
@@ -572,7 +592,8 @@ void
 AnthyInstance::unset_lookup_table (void)
 {
     m_lookup_table.clear ();
-    hide_lookup_table ();
+    show_symbols_lookup_table ();
+
     m_lookup_table_visible = false;
     m_n_conv_key_pressed = 0;
 
@@ -2385,6 +2406,21 @@ AnthyInstance::is_realtime_conversion (void)
         return false;
 }
 
+void
+AnthyInstance::show_symbols_lookup_table (void)
+{
+    if (!(m_lookup_table_visible && is_selecting_candidates ()))  {
+        if (m_preedit.get_length () > 0) {
+            CommonLookupTable     lookup_table;
+            lookup_table.append_candidate (m_preedit.get_string());
+            update_lookup_table (lookup_table);
+        }
+        else
+            update_lookup_table (*m_common_lookup_table);
+        show_lookup_table ();
+    }
+}
+
 int
 AnthyInstance::get_pseudo_ascii_mode (void)
 {
index a4937cf..fc80e78 100755 (executable)
@@ -237,6 +237,7 @@ private:
 
     bool   is_single_segment                  (void);
     bool   is_realtime_conversion             (void);
+    void   show_symbols_lookup_table          (void);
 
 private: // FIXME!
     bool   is_nicola_thumb_shift_key          (const KeyEvent &key);
@@ -253,6 +254,7 @@ private:
     /* for candidates window */
     CommonLookupTable     m_lookup_table;
     bool                  m_lookup_table_visible;
+    CommonLookupTable    *m_common_lookup_table;
     unsigned int          m_n_conv_key_pressed;
 
     /* for toggling latin and wide latin */