IInputWindow.c
上传用户:duwei1288
上传日期:2009-12-27
资源大小:451k
文件大小:10k
源码类别:

BREW编程

开发平台:

Visual C++

  1. #include "IInputWindow.h"
  2. #include "AEEAppGen.h"
  3. #include "WindowStack.h"
  4. #include "MenuList_res.h"
  5. /////////////////////////Static Function//////////////////////
  6. #define INPUT_TEXT_X_START 2
  7. #define INPUT_TEXT_Y_START 0
  8. #define INPUT_TEXT_MAX_SIZE 150
  9. //窗口的控件
  10. typedef enum
  11. {
  12.     INPUT_SOFTKEYCTL=0,
  13.     INPUT_TEXT1CTL,
  14.     INPUT_TEXT2CTL
  15. }TInputCtlType;
  16. //软键控件的ItemId定义
  17. typedef enum
  18. {
  19.   INPUT_SOFTKEY_ITEM = 1,
  20.   INPUT_SOFTKEY_ITEM_INPUT_MODE,
  21.   INPUT_SOFTKEY_ITEM_DONE,
  22.   INPUT_SOFTKEY_ITEM_CANCEL
  23. }TInputMesWinItems;
  24. //按键事件的处理
  25. static boolean IINPUTWINDOW_HandleKeyEvent(IInputWin* pWin,uint16 wParam);
  26. //软键菜单的处理
  27. static boolean IINPUTWINDOW_HandleCommandEvent(IInputWin* pWin,uint16 wParam);
  28. //设置窗口中控件的激活状态
  29. static boolean IINPUTWINDOW_SetActiveCtl(IInputWin* pWin,TInputCtlType nTextCtl);
  30. /////////////////////////Public Function//////////////////////
  31. boolean NewTextInputDialog(
  32. //svoid *pPtr,
  33. InputTextInfo* pTextInfo1,
  34. InputTextInfo* pTextInfo2, 
  35.         TInputDialogResp tpResponseFunction)
  36. {
  37. IInputWin* pWin;
  38. AEERect  Text1Rect;
  39. AEERect  Text2Rect;
  40. AEERect  softkeyRect;
  41. AEEDeviceInfo  di;
  42. uint32         textProps;
  43. AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
  44. if(!pTextInfo1||!tpResponseFunction)
  45. return FALSE;
  46. //分配窗口空间
  47. pWin=MALLOCREC(IInputWin);
  48. if(!pWin) return FALSE;
  49. if(IT_NUMBER==pTextInfo1->m_inputType)
  50. pWin->m_wMode=AEE_TM_NUMBERS;
  51. else
  52. pWin->m_wMode=AEE_TM_LETTERS;
  53. pWin->tpResponseFunction=tpResponseFunction;
  54. //创建软键控件
  55. if(SUCCESS!=ISHELL_CreateInstance(pApp->m_pIShell,AEECLSID_SOFTKEYCTL,
  56. (void **)&(pWin->m_pSoftKeyCtl)))
  57. {
  58. IINPUTWINDOW_Release(pApp->m_pIShell,&pWin);
  59. return FALSE;
  60. }
  61. if(AEE_TM_LETTERS==pWin->m_wMode)
  62. IMENUCTL_AddItem(pWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_INPUTLETTER,INPUT_SOFTKEY_ITEM_INPUT_MODE, NULL, 0);
  63. else
  64. IMENUCTL_AddItem(pWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_INPUTNUMBER,INPUT_SOFTKEY_ITEM_INPUT_MODE, NULL, 0);
  65. IMENUCTL_AddItem(pWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_CANCEL,  INPUT_SOFTKEY_ITEM_CANCEL,     NULL, 0);
  66. IMENUCTL_AddItem(pWin->m_pSoftKeyCtl,MENULIST_RES_FILE, IDS_OK,  INPUT_SOFTKEY_ITEM_DONE,       NULL, 0);
  67. IMENUCTL_GetRect(pWin->m_pSoftKeyCtl, &softkeyRect);
  68. ISHELL_GetDeviceInfo(pApp->m_pIShell, &di);
  69. //创建文本输入控件
  70. if(SUCCESS!=ISHELL_CreateInstance(pApp->m_pIShell,AEECLSID_TEXTCTL,(void **)&(pWin->m_pText1)))
  71. {
  72. IINPUTWINDOW_Release(pApp->m_pIShell,&pWin);
  73. return FALSE;
  74. }
  75. if(pTextInfo2&&SUCCESS!=ISHELL_CreateInstance(pApp->m_pIShell,AEECLSID_TEXTCTL,(void **)&(pWin->m_pText2)))
  76. {
  77. IINPUTWINDOW_Release(pApp->m_pIShell,&pWin);
  78. return FALSE;
  79. }
  80. //Rect
  81. Text1Rect.x = INPUT_TEXT_X_START;
  82. Text1Rect.y = INPUT_TEXT_Y_START;
  83. Text1Rect.dx = di.cxScreen-2*INPUT_TEXT_X_START;
  84. Text1Rect.dy = (int16)(softkeyRect.y -INPUT_TEXT_Y_START-1);
  85. if(pTextInfo2)
  86. {
  87. Text1Rect.dy/=2;
  88. Text2Rect.dx=Text1Rect.dx;
  89. Text2Rect.dy=Text1Rect.dy;
  90. Text2Rect.x=Text1Rect.x;
  91. Text2Rect.y=Text1Rect.y+Text1Rect.dy;
  92. ITEXTCTL_SetRect(pWin->m_pText2, &Text2Rect);
  93. }
  94. ITEXTCTL_SetRect(pWin->m_pText1, &Text1Rect);
  95. //Properties
  96. textProps = ITEXTCTL_GetProperties(pWin->m_pText1);
  97. textProps |= TP_FRAME;
  98. textProps |= TP_MULTILINE;
  99. if (IT_PASSWORD==pTextInfo1->m_inputType)
  100. textProps |= TP_PASSWORD;
  101. else if (IT_NUMBER==pTextInfo1->m_inputType)
  102. textProps |= AEE_TM_NUMBERS;
  103. ITEXTCTL_SetProperties(pWin->m_pText1,textProps);
  104. if(pTextInfo2)
  105. {
  106. textProps = ITEXTCTL_GetProperties(pWin->m_pText2);
  107. textProps |= TP_FRAME;
  108. textProps |= TP_MULTILINE;
  109. if (IT_PASSWORD==pTextInfo2->m_inputType)
  110. textProps |= TP_PASSWORD;
  111. else if (IT_NUMBER==pTextInfo2->m_inputType)
  112. textProps |= AEE_TM_NUMBERS;
  113. ITEXTCTL_SetProperties(pWin->m_pText2,textProps);
  114. }
  115. //Max Size
  116. ITEXTCTL_SetMaxSize(pWin->m_pText1,INPUT_TEXT_MAX_SIZE);
  117. if(pTextInfo2)
  118. ITEXTCTL_SetMaxSize(pWin->m_pText2,INPUT_TEXT_MAX_SIZE);
  119. //Set Text
  120. if(pTextInfo2)
  121. {
  122. ITEXTCTL_SetText(pWin->m_pText2, pTextInfo2->m_pText?pTextInfo2->m_pText:(AECHAR*)"", -1);
  123. ITEXTCTL_SetTitle(pWin->m_pText2,MENULIST_RES_FILE,IDS_INPUTTITLE,pTextInfo2->m_pTitle);
  124. }
  125. ITEXTCTL_SetText(pWin->m_pText1, pTextInfo1->m_pText?pTextInfo1->m_pText:(AECHAR*)"", -1);
  126. ITEXTCTL_SetTitle(pWin->m_pText1,MENULIST_RES_FILE,IDS_INPUTTITLE,pTextInfo1->m_pTitle);
  127. //Set Active
  128. IINPUTWINDOW_SetActiveCtl(pWin,INPUT_SOFTKEYCTL);
  129. //注册窗口
  130. return IWINSTACK_OpenWindow(WAPWINID_INPUT,pWin);
  131. }
  132. void*   IINPUTWINDOW_Create(IShell* pShell,void* pParam)
  133. {
  134. pShell=pShell;
  135. return pParam;
  136. }
  137. boolean IINPUTWINDOW_Release(IShell* pShell,void** pWin)
  138. {
  139. IInputWin* pInputWin=*pWin;
  140. if(pInputWin)
  141. {
  142. if(pInputWin->m_pSoftKeyCtl)
  143. IMENUCTL_Release(pInputWin->m_pSoftKeyCtl);
  144. if(pInputWin->m_pText1)
  145. ITEXTCTL_Release(pInputWin->m_pText1);
  146. if(pInputWin->m_pText2)
  147. ITEXTCTL_Release(pInputWin->m_pText2);
  148. FREEIF(*pWin);
  149. }
  150. return TRUE;
  151. }
  152. boolean IINPUTWINDOW_Redraw(IShell* pShell,void* pWin)
  153. {
  154. IInputWin* pInputWin=pWin;
  155. AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
  156. if(pInputWin&&pApp)
  157. {
  158. IDISPLAY_ClearScreen(pApp->m_pIDisplay);
  159. if(pInputWin->m_pSoftKeyCtl)
  160. IMENUCTL_Redraw(pInputWin->m_pSoftKeyCtl);
  161. if(pInputWin->m_pText1)
  162. ITEXTCTL_Redraw(pInputWin->m_pText1);
  163. if(pInputWin->m_pText2)
  164. ITEXTCTL_Redraw(pInputWin->m_pText2);
  165. IDISPLAY_Update(pApp->m_pIDisplay);
  166. }
  167. return TRUE;
  168. }
  169. boolean IINPUTWINDOW_EventHandle(void* pWin,AEEEvent eCode, uint16 wParam, uint32 dwParam)
  170. {
  171. IInputWin* pInputWin=pWin;
  172. boolean bDispatched = FALSE;
  173. if(NULL==pInputWin) return FALSE;
  174. switch(eCode)
  175. {
  176. case EVT_KEY:
  177. bDispatched=IINPUTWINDOW_HandleKeyEvent(pWin,wParam);
  178. break;
  179. /* case EVT_KEY_HELD://按键长按事件
  180. if(pInputWin->m_pText1&&ITEXTCTL_IsActive(pInputWin->m_pText1))
  181. bDispatched=ITEXTCTL_HandleEvent(pInputWin->m_pText1,eCode,wParam,dwParam);
  182. else if(pInputWin->m_pText2&&ITEXTCTL_IsActive(pInputWin->m_pText2))
  183. bDispatched=ITEXTCTL_HandleEvent(pInputWin->m_pText2,eCode,wParam,dwParam);
  184. break;*/
  185. case EVT_COMMAND:
  186. bDispatched=IINPUTWINDOW_HandleCommandEvent(pWin,wParam);
  187. break;
  188. case EVT_CHAR:
  189. if(pInputWin->m_pText1&&ITEXTCTL_IsActive(pInputWin->m_pText1))
  190. bDispatched=ITEXTCTL_HandleEvent(pInputWin->m_pText1,eCode,wParam,dwParam);
  191. else if(pInputWin->m_pText2&&ITEXTCTL_IsActive(pInputWin->m_pText2))
  192. bDispatched=ITEXTCTL_HandleEvent(pInputWin->m_pText2,eCode,wParam,dwParam);
  193. break;
  194. }
  195. return bDispatched;
  196. }
  197. ///////////////////////////////////////////////////////////////////////////////////
  198. ///////////////////////////////////////////////////////////////////////////////////
  199. static boolean IINPUTWINDOW_HandleKeyEvent(IInputWin* pWin,uint16 wParam)
  200. {
  201. IInputWin* pInputWin=pWin;
  202. boolean bDispatched = FALSE;
  203. if(NULL==pInputWin) return FALSE;
  204. //首先让当前激活的控件处理按键事件
  205. if(pInputWin->m_pText1&&ITEXTCTL_IsActive(pInputWin->m_pText1))
  206. bDispatched=ITEXTCTL_HandleEvent(pInputWin->m_pText1,EVT_KEY,wParam,0);
  207. else if(pInputWin->m_pText2&&ITEXTCTL_IsActive(pInputWin->m_pText2))
  208. bDispatched=ITEXTCTL_HandleEvent(pInputWin->m_pText2,EVT_KEY,wParam,0);
  209. else if(pInputWin->m_pSoftKeyCtl&&IMENUCTL_IsActive(pInputWin->m_pSoftKeyCtl))
  210. bDispatched=IMENUCTL_HandleEvent(pInputWin->m_pSoftKeyCtl,EVT_KEY,wParam,0);
  211. if(bDispatched) return TRUE;
  212. //如果控件对事件不做处理再执行下面操作
  213. switch(wParam) 
  214. {
  215. case AVK_UP:
  216. if(IMENUCTL_IsActive(pWin->m_pSoftKeyCtl))
  217. IINPUTWINDOW_SetActiveCtl(pWin,INPUT_TEXT2CTL);
  218. else if(ITEXTCTL_IsActive(pWin->m_pText1))
  219. IINPUTWINDOW_SetActiveCtl(pWin,INPUT_SOFTKEYCTL);
  220. else
  221. IINPUTWINDOW_SetActiveCtl(pWin,INPUT_TEXT1CTL);
  222. bDispatched = TRUE;
  223. break;
  224. case AVK_DOWN:
  225. if(ITEXTCTL_IsActive(pWin->m_pText1)) 
  226. {
  227. if (pWin->m_pText2)
  228. IINPUTWINDOW_SetActiveCtl(pWin,INPUT_TEXT2CTL);
  229. else
  230. IINPUTWINDOW_SetActiveCtl(pWin,INPUT_SOFTKEYCTL);
  231. }
  232. else if(IMENUCTL_IsActive(pWin->m_pSoftKeyCtl))
  233. IINPUTWINDOW_SetActiveCtl(pWin,INPUT_TEXT1CTL);
  234. else
  235. IINPUTWINDOW_SetActiveCtl(pWin,INPUT_SOFTKEYCTL);
  236. bDispatched = TRUE;
  237. break;
  238. case AVK_CLR://关闭窗口
  239. IWINSTACK_CloseWindow(TRUE);
  240. bDispatched = TRUE;
  241. break;
  242. case AVK_SELECT:
  243. //当软键不在激活状态时按Select会将软键设为激活
  244. IINPUTWINDOW_SetActiveCtl(pWin,INPUT_SOFTKEYCTL);
  245. bDispatched = TRUE;
  246. break;
  247. }
  248. return bDispatched;
  249. }
  250. static boolean IINPUTWINDOW_HandleCommandEvent(IInputWin* pWin,uint16 wParam)
  251. {
  252. AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
  253. IInputWin* pInputWin=pWin;
  254. boolean bDispatched = FALSE;
  255. if(NULL==pInputWin) return FALSE;
  256. //
  257. switch(wParam)
  258. {
  259. case INPUT_SOFTKEY_ITEM_INPUT_MODE:
  260. break;
  261. case INPUT_SOFTKEY_ITEM_DONE:
  262. if(pWin->tpResponseFunction)
  263. {
  264. AECHAR* pText1=NULL;
  265. AECHAR* pText2=NULL;
  266. pText1=ITEXTCTL_GetTextPtr(pWin->m_pText1);
  267. if(pWin->m_pText2)
  268. pText2=ITEXTCTL_GetTextPtr(pWin->m_pText2);
  269. pWin->tpResponseFunction(pText1,pText2, TRUE);
  270. }
  271. IWINSTACK_CloseWindow(TRUE);
  272. break;
  273. default:
  274. IWINSTACK_CloseWindow(TRUE);
  275. }
  276. return TRUE;
  277. }
  278. static boolean IINPUTWINDOW_SetActiveCtl(IInputWin* pWin,TInputCtlType nTextCtl)
  279. {
  280. //当nTextCtl=INPUT_SOFTKEYCTL,不显示任何文本控件
  281. //当text2不存在时,无论nTextCtl的值为多少,都显示text1
  282. //当text2存在时,nTextCtl=INPUT_TEXT1CTL,显示text1,否则显示text2
  283. switch(nTextCtl)
  284. {
  285. case INPUT_SOFTKEYCTL:
  286. ITEXTCTL_SetActive(pWin->m_pText1, FALSE);
  287. if ((pWin->m_pText2) && (ITEXTCTL_IsActive(pWin->m_pText2)))
  288. ITEXTCTL_SetActive(pWin->m_pText2, FALSE);
  289. IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, TRUE);
  290. IMENUCTL_SetSel(pWin->m_pSoftKeyCtl, INPUT_SOFTKEY_ITEM_INPUT_MODE);
  291. break;
  292. case INPUT_TEXT2CTL:
  293. if(pWin->m_pText2)
  294. {
  295. ITEXTCTL_SetInputMode(pWin->m_pText2, pWin->m_wMode);
  296. IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
  297. ITEXTCTL_SetActive(pWin->m_pText1, FALSE);
  298. ITEXTCTL_SetCursorPos(pWin->m_pText2, TC_CURSOREND);
  299. ITEXTCTL_SetActive(pWin->m_pText2, TRUE);
  300. break;
  301. }
  302. default:
  303. ITEXTCTL_SetInputMode(pWin->m_pText1, pWin->m_wMode);
  304. IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
  305. if (pWin->m_pText2)
  306. ITEXTCTL_SetActive(pWin->m_pText2, FALSE);
  307. ITEXTCTL_SetCursorPos(pWin->m_pText1, TC_CURSOREND);
  308. ITEXTCTL_SetActive(pWin->m_pText1, TRUE);
  309. }
  310. return TRUE;
  311. }