/src/os/wince/ftk_input_method_wince.c

http://ftk.googlecode.com/ · C · 172 lines · 122 code · 42 blank · 8 comment · 16 complexity · 9622583d877fee95b567e16e2629283d MD5 · raw file

  1. #include "ftk_log.h"
  2. #include "ftk_event.h"
  3. #include "ftk_globals.h"
  4. #include "ftk_input_method_wince.h"
  5. #include <sipapi.h>
  6. typedef struct _PrivInfo
  7. {
  8. FtkWidget* editor;
  9. FtkInputType input_type;
  10. }PrivInfo;
  11. static Ret ftk_input_method_wince_handle_event(FtkInputMethod* thiz, FtkEvent* event);
  12. static Ret ftk_input_method_wince_init(FtkInputMethod* thiz)
  13. {
  14. return RET_OK;
  15. }
  16. static Ret ftk_input_method_wince_reset(FtkInputMethod* thiz)
  17. {
  18. return RET_OK;
  19. }
  20. static Ret ftk_input_method_wince_activate(FtkInputMethod* thiz)
  21. {
  22. ftk_input_method_wince_init(thiz);
  23. ftk_wnd_manager_add_global_listener(ftk_default_wnd_manager(),
  24. (FtkListener)ftk_input_method_wince_handle_event, thiz);
  25. ftk_logd("%s\n", __func__);
  26. return RET_OK;
  27. }
  28. static Ret ftk_input_method_wince_deactivate(FtkInputMethod* thiz)
  29. {
  30. ftk_input_method_wince_reset(thiz);
  31. ftk_wnd_manager_remove_global_listener(ftk_default_wnd_manager(),
  32. (FtkListener)ftk_input_method_wince_handle_event, thiz);
  33. ftk_logd("%s\n", __func__);
  34. return RET_OK;
  35. }
  36. static Ret ftk_input_method_wince_focus_in(FtkInputMethod* thiz, FtkWidget* editor)
  37. {
  38. DECL_PRIV(thiz, priv);
  39. return_val_if_fail(priv != NULL && editor != NULL, RET_FAIL);
  40. ftk_logd("%s:%d ftk_input_method_wince_focus_in\n", __FILE__, __LINE__);
  41. priv->editor = editor;
  42. //SipEnumIM();
  43. //SipSetCurrentIM();
  44. //MzOpenSip();
  45. //MzCloseSip();
  46. SipShowIM(SIPF_ON);
  47. //SHSipPreference(hWnd, SIP_UP);
  48. return ftk_input_method_wince_activate(thiz);
  49. }
  50. static Ret ftk_input_method_wince_focus_out(FtkInputMethod* thiz)
  51. {
  52. DECL_PRIV(thiz, priv);
  53. return_val_if_fail(priv != NULL, RET_FAIL);
  54. ftk_logd("%s:%d ftk_input_method_wince_focus_out\n", __FILE__, __LINE__);
  55. SipShowIM(SIPF_OFF);
  56. //SHSipPreference(hWnd, SIP_FORCEDOWN);
  57. //SHSipPreference(m_hwnd, SIP_DOWN);
  58. priv->editor = NULL;
  59. return ftk_input_method_wince_deactivate(thiz);
  60. }
  61. static Ret ftk_input_method_wince_set_type(FtkInputMethod* thiz, FtkInputType input_type)
  62. {
  63. DECL_PRIV(thiz, priv);
  64. return_val_if_fail(priv != NULL, RET_FAIL);
  65. priv->input_type = input_type;
  66. return RET_OK;
  67. }
  68. static Ret ftk_input_method_wince_handle_event(FtkInputMethod* thiz, FtkEvent* event)
  69. {
  70. Ret ret = RET_OK;
  71. DECL_PRIV(thiz, priv);
  72. return_val_if_fail(priv != NULL && event != NULL, RET_FAIL);
  73. switch(event->type)
  74. {
  75. case FTK_EVT_OS_IM_COMMIT:
  76. {
  77. FtkEvent evt = {0};
  78. ftk_logd("%s:%d FTK_EVT_OS_IM_COMMIT:%s\n", __FILE__, __LINE__, event->u.extra);
  79. if(priv->editor == NULL)
  80. {
  81. FTK_FREE(event->u.extra);
  82. ret = RET_REMOVE;
  83. break;
  84. }
  85. /* TODO: priv->input_type */
  86. evt.type = FTK_EVT_IM_COMMIT;
  87. evt.u.extra = event->u.extra;
  88. evt.widget = priv->editor;
  89. ftk_widget_event(priv->editor, &evt);
  90. FTK_FREE(event->u.extra);
  91. ret = RET_REMOVE;
  92. break;
  93. }
  94. case FTK_EVT_IM_ACT_COMMIT:
  95. {
  96. break;
  97. }
  98. default:break;
  99. }
  100. return ret;
  101. }
  102. static void ftk_input_method_wince_destroy(FtkInputMethod* thiz)
  103. {
  104. if(thiz != NULL)
  105. {
  106. DECL_PRIV(thiz, priv);
  107. FTK_ZFREE(thiz, sizeof(FtkInputMethod) + sizeof(PrivInfo));
  108. }
  109. }
  110. FtkInputMethod* ftk_input_method_wince_create(void)
  111. {
  112. FtkInputMethod* thiz = FTK_ZALLOC(sizeof(FtkInputMethod) + sizeof(PrivInfo));
  113. if(thiz != NULL)
  114. {
  115. thiz->ref = 1;
  116. thiz->name = "wince ime";
  117. thiz->set_type = ftk_input_method_wince_set_type;
  118. thiz->focus_in = ftk_input_method_wince_focus_in;
  119. thiz->focus_out = ftk_input_method_wince_focus_out;
  120. thiz->handle_event = ftk_input_method_wince_handle_event;
  121. thiz->destroy = ftk_input_method_wince_destroy;
  122. }
  123. return thiz;
  124. }
  125. FtkWidget* ftk_input_method_wince_get_editor(FtkInputMethod* thiz)
  126. {
  127. DECL_PRIV(thiz, priv);
  128. return_val_if_fail(priv != NULL, NULL);
  129. return priv->editor;
  130. }