1
0

edit.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #include <precomp.h>
  2. #include <bfc/wasabi_std.h>
  3. #include <api/skin/skinparse.h>
  4. #include "edit.h"
  5. #include <api/script/scriptmgr.h>
  6. #include <api/skin/widgets/mb/xuibrowser.h>
  7. #include <api/skin/widgets/mb/mainminibrowser.h>
  8. #define BUFSIZE 0x7ffe
  9. const wchar_t editXuiObjectStr[] = L"Edit"; // This is the xml tag
  10. char editXuiSvcName[] = "Edit xui object"; // this is the name of the xuiservice
  11. EditScriptController _editController;
  12. EditScriptController *editController = &_editController;
  13. // -- Functions table -------------------------------------
  14. function_descriptor_struct EditScriptController::exportedFunction[] = {
  15. {L"setText", 1, (void*)Edit::script_vcpu_setText },
  16. {L"setAutoEnter", 1, (void*)Edit::script_vcpu_setAutoEnter },
  17. {L"getAutoEnter", 0, (void*)Edit::script_vcpu_getAutoEnter },
  18. {L"getText", 0, (void*)Edit::script_vcpu_getText },
  19. {L"onEnter", 0, (void*)Edit::script_vcpu_onEnter },
  20. {L"onAbort", 0, (void*)Edit::script_vcpu_onAbort },
  21. {L"onIdleEditUpdate", 0, (void*)Edit::script_vcpu_onIdleEditUpdate },
  22. {L"onEditUpdate", 0, (void*)Edit::script_vcpu_onEditUpdate },
  23. {L"selectAll", 0, (void*)Edit::script_vcpu_selectAll },
  24. {L"enter", 0, (void*)Edit::script_vcpu_enter },
  25. {L"setIdleEnabled", 1, (void*)Edit::script_vcpu_setIdleEnabled},
  26. {L"getIdleEnabled", 0, (void*)Edit::script_vcpu_getIdleEnabled},
  27. };
  28. // --------------------------------------------------------
  29. const wchar_t *EditScriptController::getClassName()
  30. {
  31. return L"Edit";
  32. }
  33. const wchar_t *EditScriptController::getAncestorClassName()
  34. {
  35. return L"GuiObject";
  36. }
  37. ScriptObject *EditScriptController::instantiate()
  38. {
  39. Edit *e = new Edit;
  40. ASSERT(e != NULL);
  41. return e->getScriptObject();
  42. }
  43. void EditScriptController::destroy(ScriptObject *o)
  44. {
  45. Edit *e = static_cast<Edit *>(o->vcpu_getInterface(editGuid));
  46. ASSERT(e != NULL);
  47. delete e;
  48. }
  49. void *EditScriptController::encapsulate(ScriptObject *o)
  50. {
  51. return NULL; // no encapsulation for edit yet
  52. }
  53. void EditScriptController::deencapsulate(void *o)
  54. {}
  55. int EditScriptController::getNumFunctions()
  56. {
  57. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  58. }
  59. const function_descriptor_struct *EditScriptController::getExportedFunctions()
  60. {
  61. return exportedFunction;
  62. }
  63. GUID EditScriptController::getClassGuid()
  64. {
  65. return editGuid;
  66. }
  67. // -----------------------------------------------------------------------------
  68. XMLParamPair Edit::params[] = {
  69. {EDIT_ACTION, L"ACTION"},
  70. {EDIT_AUTOENTER, L"AUTOENTER"},
  71. {EDIT_AUTOHSCROLL, L"AUTOHSCROLL"},
  72. {EDIT_AUTOSELECT, L"AUTOSELECT"},
  73. {EDIT_MULTILINE, L"MULTILINE"},
  74. {EDIT_PASSWORD, L"PASSWORD"},
  75. {EDIT_TEXT, L"TEXT"},
  76. {EDIT_VSCROLL, L"VSCROLL"},
  77. };
  78. Edit::Edit()
  79. {
  80. getScriptObject()->vcpu_setInterface(editGuid, (void *)static_cast<Edit *>(this));
  81. getScriptObject()->vcpu_setClassName(L"Edit");
  82. getScriptObject()->vcpu_setController(editController);
  83. my_buffer = WMALLOC(BUFSIZE);
  84. *my_buffer = 0;
  85. autourl = 0;
  86. xuihandle = newXuiHandle();
  87. CreateXMLParameters(xuihandle);
  88. }
  89. void Edit::CreateXMLParameters(int master_handle)
  90. {
  91. //EDIT_PARENT::CreateXMLParameters(master_handle);
  92. int numParams = sizeof(params) / sizeof(params[0]);
  93. hintNumberOfParams(xuihandle, numParams);
  94. for (int i = 0;i < numParams;i++)
  95. addParam(xuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  96. }
  97. Edit::~Edit()
  98. {
  99. FREE(my_buffer);
  100. }
  101. int Edit::setXuiParam(int _xuihandle, int xmlattrid, const wchar_t *name, const wchar_t *value)
  102. {
  103. if (xuihandle == _xuihandle)
  104. {
  105. switch (xmlattrid)
  106. {
  107. case EDIT_TEXT: setText(value); return 1;
  108. case EDIT_ACTION: if (SkinParser::getAction(value) == ACTION_MB_URL) setAutoUrl(1); return 1;
  109. case EDIT_MULTILINE: setMultiline(WTOI(value)); return 1;
  110. case EDIT_VSCROLL: setVScroll(WTOI(value)); return 1;
  111. case EDIT_AUTOHSCROLL: setAutoHScroll(WTOI(value)); return 1;
  112. case EDIT_AUTOENTER: setAutoEnter(WTOI(value)); return 1;
  113. case EDIT_PASSWORD: setPassword(WTOI(value)); return 1;
  114. case EDIT_AUTOSELECT: setAutoSelect(WTOI(value)); return 1;
  115. }
  116. }
  117. return EDIT_PARENT::setXuiParam(_xuihandle, xmlattrid, name, value);
  118. }
  119. int Edit::onInit()
  120. {
  121. int r = EDIT_PARENT::onInit();
  122. setBuffer(my_buffer, BUFSIZE - 1);
  123. my_buffer[BUFSIZE - 1] = 0;
  124. return r;
  125. }
  126. void Edit::onEditUpdate()
  127. {
  128. EDIT_PARENT::onEditUpdate();
  129. script_vcpu_onEditUpdate(SCRIPT_CALL, getScriptObject());
  130. }
  131. void Edit::onIdleEditUpdate()
  132. {
  133. EDIT_PARENT::onIdleEditUpdate();
  134. script_vcpu_onIdleEditUpdate(SCRIPT_CALL, getScriptObject());
  135. }
  136. int Edit::onEnter()
  137. {
  138. if (autourl)
  139. {
  140. MainMiniBrowser::navigateUrl(my_buffer);
  141. }
  142. #ifdef WASABI_COMPILE_CONFIG
  143. getGuiObject()->guiobject_setCfgString(my_buffer);
  144. #endif
  145. int r = EDIT_PARENT::onEnter();
  146. #ifdef WASABI_COMPILE_CONFIG
  147. script_vcpu_onEnter(SCRIPT_CALL, getScriptObject());
  148. #endif
  149. return r;
  150. }
  151. #ifdef WASABI_COMPILE_CONFIG
  152. int Edit::onReloadConfig()
  153. {
  154. EDIT_PARENT::onReloadConfig();
  155. setText(getGuiObject()->guiobject_getCfgString());
  156. return 1;
  157. }
  158. #endif
  159. int Edit::onAbort()
  160. {
  161. if (autourl)
  162. {
  163. ScriptObject *so = MainMiniBrowser::getScriptObject();
  164. if (so)
  165. {
  166. ScriptBrowserWnd *sbw = static_cast<ScriptBrowserWnd *>(so->vcpu_getInterface(browserGuid));
  167. if (sbw)
  168. setText(sbw->getCurrentUrl());
  169. }
  170. }
  171. int r = EDIT_PARENT::onAbort();
  172. script_vcpu_onAbort(SCRIPT_CALL, getScriptObject());
  173. return r;
  174. }
  175. void Edit::setText(const wchar_t *t)
  176. {
  177. wcsncpy(my_buffer, t, BUFSIZE - 1);
  178. setBuffer(my_buffer, BUFSIZE - 1);
  179. my_buffer[BUFSIZE - 1] = 0;
  180. }
  181. void Edit::setAutoUrl(int a)
  182. {
  183. autourl = a;
  184. }
  185. // -----------------------------------------------------------------------------
  186. scriptVar Edit::script_vcpu_setText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar t)
  187. {
  188. SCRIPT_FUNCTION_INIT
  189. ASSERT(t.type == SCRIPT_STRING);
  190. Edit *e = static_cast<Edit *>(o->vcpu_getInterface(editGuid));
  191. if (e) e->setText(t.data.sdata);
  192. RETURN_SCRIPT_VOID;
  193. }
  194. scriptVar Edit::script_vcpu_setAutoEnter(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar t)
  195. {
  196. SCRIPT_FUNCTION_INIT
  197. Edit *e = static_cast<Edit *>(o->vcpu_getInterface(editGuid));
  198. if (e) e->setAutoEnter(t.data.idata);
  199. RETURN_SCRIPT_VOID;
  200. }
  201. scriptVar Edit::script_vcpu_getAutoEnter(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  202. {
  203. SCRIPT_FUNCTION_INIT
  204. int a = 0;
  205. Edit *e = static_cast<Edit *>(o->vcpu_getInterface(editGuid));
  206. if (e) a = e->getAutoEnter();
  207. return MAKE_SCRIPT_INT(a);
  208. }
  209. scriptVar Edit::script_vcpu_setIdleEnabled(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar t)
  210. {
  211. SCRIPT_FUNCTION_INIT
  212. Edit *e = static_cast<Edit *>(o->vcpu_getInterface(editGuid));
  213. if (e) e->setIdleEnabled(t.data.idata);
  214. RETURN_SCRIPT_VOID;
  215. }
  216. scriptVar Edit::script_vcpu_getIdleEnabled(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  217. {
  218. SCRIPT_FUNCTION_INIT
  219. int a = 0;
  220. Edit *e = static_cast<Edit *>(o->vcpu_getInterface(editGuid));
  221. if (e) a = e->getIdleEnabled();
  222. return MAKE_SCRIPT_INT(a);
  223. }
  224. scriptVar Edit::script_vcpu_getText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  225. {
  226. SCRIPT_FUNCTION_INIT
  227. Edit *e = static_cast<Edit *>(o->vcpu_getInterface(editGuid));
  228. if (e) return MAKE_SCRIPT_STRING(e->getBufferPtr());
  229. return MAKE_SCRIPT_STRING(L"");
  230. }
  231. scriptVar Edit::script_vcpu_selectAll(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  232. {
  233. SCRIPT_FUNCTION_INIT
  234. Edit *e = static_cast<Edit *>(o->vcpu_getInterface(editGuid));
  235. if (e) e->selectAll();
  236. RETURN_SCRIPT_VOID;
  237. }
  238. scriptVar Edit::script_vcpu_enter(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  239. {
  240. SCRIPT_FUNCTION_INIT
  241. Edit *e = static_cast<Edit *>(o->vcpu_getInterface(editGuid));
  242. if (e) e->enter();
  243. RETURN_SCRIPT_VOID;
  244. }
  245. scriptVar Edit::script_vcpu_onEnter(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  246. {
  247. SCRIPT_FUNCTION_INIT;
  248. PROCESS_HOOKS0(o, editController);
  249. SCRIPT_FUNCTION_CHECKABORTEVENT;
  250. SCRIPT_EXEC_EVENT0(o);
  251. }
  252. scriptVar Edit::script_vcpu_onIdleEditUpdate(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  253. {
  254. SCRIPT_FUNCTION_INIT;
  255. PROCESS_HOOKS0(o, editController);
  256. SCRIPT_FUNCTION_CHECKABORTEVENT;
  257. SCRIPT_EXEC_EVENT0(o);
  258. }
  259. scriptVar Edit::script_vcpu_onEditUpdate(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  260. {
  261. SCRIPT_FUNCTION_INIT;
  262. PROCESS_HOOKS0(o, editController);
  263. SCRIPT_FUNCTION_CHECKABORTEVENT;
  264. SCRIPT_EXEC_EVENT0(o);
  265. }
  266. scriptVar Edit::script_vcpu_onAbort(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  267. {
  268. SCRIPT_FUNCTION_INIT;
  269. PROCESS_HOOKS0(o, editController);
  270. SCRIPT_FUNCTION_CHECKABORTEVENT;
  271. SCRIPT_EXEC_EVENT0(o);
  272. }