PageRenderTime 757ms CodeModel.GetById 614ms app.highlight 10ms RepoModel.GetById 131ms app.codeStats 0ms

/src/os/iphone/ftk_input_method_iphone.c

http://ftk.googlecode.com/
C | 151 lines | 114 code | 36 blank | 1 comment | 14 complexity | 765df34fc29fb1d29c6ba8f40a68d3cb MD5 | raw file
  1
  2#include "ftk_log.h"
  3#include "ftk_event.h"
  4#include "ftk_globals.h"
  5#include "ftk_input_method_iphone.h"
  6
  7typedef struct _PrivInfo
  8{
  9	FtkWidget* editor;
 10	FtkInputType input_type;
 11}PrivInfo;
 12
 13static Ret  ftk_input_method_iphone_handle_event(FtkInputMethod* thiz, FtkEvent* event);
 14
 15static Ret  ftk_input_method_iphone_init(FtkInputMethod* thiz)
 16{
 17	return RET_OK;
 18}
 19
 20static Ret  ftk_input_method_iphone_reset(FtkInputMethod* thiz)
 21{
 22	return RET_OK;
 23}
 24
 25static Ret  ftk_input_method_iphone_activate(FtkInputMethod* thiz)
 26{
 27	ftk_input_method_iphone_init(thiz);
 28
 29	ftk_wnd_manager_add_global_listener(ftk_default_wnd_manager(),
 30		(FtkListener)ftk_input_method_iphone_handle_event, thiz);
 31
 32	ftk_logd("%s\n", __func__);
 33
 34	return RET_OK;
 35}
 36
 37static Ret  ftk_input_method_iphone_deactivate(FtkInputMethod* thiz)
 38{
 39	ftk_input_method_iphone_reset(thiz);
 40
 41	ftk_wnd_manager_remove_global_listener(ftk_default_wnd_manager(), 
 42		(FtkListener)ftk_input_method_iphone_handle_event, thiz);
 43
 44	ftk_logd("%s\n", __func__);
 45
 46	return RET_OK;
 47}
 48
 49static Ret  ftk_input_method_iphone_focus_in(FtkInputMethod* thiz, FtkWidget* editor)
 50{
 51	DECL_PRIV(thiz, priv);
 52	return_val_if_fail(priv != NULL && editor != NULL, RET_FAIL);
 53
 54	ftk_logd("%s:%d ftk_input_method_iphone_focus_in\n", __FILE__, __LINE__);
 55
 56	priv->editor = editor;
 57
 58	ftk_display_iphone_show_keyboard(ftk_display_get_real_display(ftk_default_display()));
 59
 60	return ftk_input_method_iphone_activate(thiz);
 61}
 62
 63static Ret  ftk_input_method_iphone_focus_out(FtkInputMethod* thiz)
 64{
 65	DECL_PRIV(thiz, priv);
 66	return_val_if_fail(priv != NULL, RET_FAIL);
 67
 68	ftk_logd("%s:%d ftk_input_method_iphone_focus_out\n", __FILE__, __LINE__);
 69
 70	ftk_display_iphone_hide_keyboard(ftk_display_get_real_display(ftk_default_display()));
 71
 72	priv->editor = NULL;
 73
 74	return ftk_input_method_iphone_deactivate(thiz);
 75}
 76
 77static Ret  ftk_input_method_iphone_set_type(FtkInputMethod* thiz, FtkInputType input_type)
 78{
 79	DECL_PRIV(thiz, priv);
 80	return_val_if_fail(priv != NULL, RET_FAIL);
 81
 82	priv->input_type = input_type;
 83
 84	return RET_OK;
 85}
 86
 87static Ret  ftk_input_method_iphone_handle_event(FtkInputMethod* thiz, FtkEvent* event)
 88{
 89	Ret ret = RET_OK;
 90	DECL_PRIV(thiz, priv);
 91	return_val_if_fail(priv != NULL && event != NULL, RET_FAIL);
 92
 93	switch(event->type)
 94	{
 95		case FTK_EVT_OS_IM_COMMIT:
 96		{
 97			FtkEvent evt = {0};
 98			if(priv->editor == NULL)
 99			{
100				FTK_FREE(event->u.extra);
101				ret = RET_REMOVE;
102				break;
103			}
104
105			/* TODO: priv->input_type */
106
107			evt.type = FTK_EVT_IM_COMMIT;
108			evt.u.extra = event->u.extra;
109			evt.widget = priv->editor;
110			ftk_widget_event(priv->editor, &evt);
111
112			FTK_FREE(event->u.extra);
113			ret = RET_REMOVE;
114			break;
115		}
116		case FTK_EVT_IM_ACT_COMMIT:
117		{
118			break;
119		}
120		default:break;
121	}
122
123	return ret;
124}
125
126static void ftk_input_method_iphone_destroy(FtkInputMethod* thiz)
127{
128	if(thiz != NULL)
129	{
130		DECL_PRIV(thiz, priv);
131		FTK_ZFREE(thiz, sizeof(FtkInputMethod) + sizeof(PrivInfo));
132	}
133}
134
135FtkInputMethod* ftk_input_method_iphone_create(void)
136{
137	FtkInputMethod* thiz = FTK_ZALLOC(sizeof(FtkInputMethod) + sizeof(PrivInfo));
138
139	if(thiz != NULL)
140	{
141		thiz->ref  = 1;
142		thiz->name = "iphone ime";
143		thiz->set_type     = ftk_input_method_iphone_set_type;
144		thiz->focus_in     = ftk_input_method_iphone_focus_in;
145		thiz->focus_out    = ftk_input_method_iphone_focus_out;
146		thiz->handle_event = ftk_input_method_iphone_handle_event;
147		thiz->destroy      = ftk_input_method_iphone_destroy;
148	}
149
150	return thiz;
151}