PageRenderTime 33ms CodeModel.GetById 23ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/os/wince/ftk_input_method_wince.c

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