dropdownlist.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. #include <precomp.h>
  2. #include "dropdownlist.h"
  3. #include <api/wnd/wndclass/listwnd.h>
  4. #include <api/script/objects/guiobject.h>
  5. #include <api/script/scriptguid.h>
  6. #include <api/script/objects/c_script/c_text.h>
  7. #include <api/wnd/popexitcb.h>
  8. #include <api/wnd/notifmsg.h>
  9. #include <api/service/svc_enum.h>
  10. #include <bfc/parse/paramparser.h>
  11. #include <api/service/svcs/svc_textfeed.h>
  12. #define DDL_CLOSELISTCB 0x0721
  13. XMLParamPair DropDownList::params[] =
  14. {
  15. {DROPDOWNLIST_SETFEED, L"FEED"},
  16. {DROPDOWNLIST_SETITEMS, L"ITEMS"},
  17. {DROPDOWNLIST_LISTHEIGHT, L"LISTHEIGHT"},
  18. {DROPDOWNLIST_MAXITEMS, L"MAXITEMS"},
  19. {DROPDOWNLIST_SELECT, L"SELECT"},
  20. {DROPDOWNLIST_SETLISTANTIALIAS, L"ANTIALIAS"},
  21. };
  22. // -----------------------------------------------------------------------
  23. DropDownList::DropDownList() {
  24. selected = -1;
  25. //abstract_setAllowDeferredContent(1);
  26. clicks_button = NULL;
  27. clicks_text = NULL;
  28. list_key = NULL;
  29. height = 128;
  30. maxitems = 0;
  31. noitemtext = L"";
  32. list_group = NULL;
  33. trap_click = 0;
  34. disable_cfg_event = 0;
  35. GuiObjectWnd::getScriptObject()->vcpu_setInterface(dropDownListGuid, (void *)static_cast<DropDownList *>(this));
  36. GuiObjectWnd::getScriptObject()->vcpu_setClassName(L"DropDownList"); // this is the script class name
  37. GuiObjectWnd::getScriptObject()->vcpu_setController(dropDownListController);
  38. myxuihandle = newXuiHandle();
  39. CreateXMLParameters(myxuihandle);
  40. registerAcceleratorSection(L"popup", 1);
  41. }
  42. void DropDownList::CreateXMLParameters(int master_handle)
  43. {
  44. //DROPDOWNLIST_PARENT::CreateXMLParameters(master_handle);
  45. int numParams = sizeof(params) / sizeof(params[0]);
  46. hintNumberOfParams(myxuihandle, numParams);
  47. for (int i = 0;i < numParams;i++)
  48. addParam(myxuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  49. }
  50. // -----------------------------------------------------------------------
  51. DropDownList::~DropDownList() {
  52. doCloseList(0);
  53. delete clicks_text;
  54. delete clicks_button;
  55. delete list_key;
  56. }
  57. // -----------------------------------------------------------------------
  58. int DropDownList::onAcceleratorEvent(const wchar_t *name) {
  59. int r = DROPDOWNLIST_PARENT::onAcceleratorEvent(name);
  60. if (WCSCASEEQLSAFE(name, L"exit")) {
  61. escapeCallback();
  62. return 1;
  63. }
  64. return r;
  65. }
  66. // -----------------------------------------------------------------------
  67. int DropDownList::setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value) {
  68. if (xuihandle != myxuihandle)
  69. return DROPDOWNLIST_PARENT::setXuiParam(xuihandle, xmlattributeid, xmlattributename, value);
  70. switch (xmlattributeid) {
  71. case DROPDOWNLIST_SETITEMS:
  72. setItems(value);
  73. break;
  74. case DROPDOWNLIST_SETFEED:
  75. setFeed(value);
  76. break;
  77. case DROPDOWNLIST_SELECT:
  78. selectItem(findItem(value));
  79. break;
  80. case DROPDOWNLIST_LISTHEIGHT:
  81. setListHeight(WTOI(value));
  82. break;
  83. case DROPDOWNLIST_MAXITEMS:
  84. setMaxItems(WTOI(value));
  85. break;
  86. case DROPDOWNLIST_SETLISTANTIALIAS:
  87. listAntialias = WTOI(value);
  88. break;
  89. default:
  90. return 0;
  91. }
  92. return 1;
  93. }
  94. // -----------------------------------------------------------------------
  95. int DropDownList::onInit()
  96. {
  97. int rt = DROPDOWNLIST_PARENT::onInit();
  98. abstract_setContent(dropdownlist_getMainGroupId());
  99. return rt;
  100. }
  101. // -----------------------------------------------------------------------
  102. void DropDownList::abstract_onNewContent() {
  103. DROPDOWNLIST_PARENT::abstract_onNewContent();
  104. trapControls();
  105. updateTextInControl(getSelectedText());
  106. }
  107. #ifdef WASABI_COMPILE_CONFIG
  108. // -----------------------------------------------------------------------
  109. int DropDownList::onReloadConfig() {
  110. int r = DROPDOWNLIST_PARENT::onReloadConfig();
  111. disable_cfg_event = 1;
  112. updateTextFromConfig(); // triggers onSelect
  113. disable_cfg_event = 0;
  114. return r;
  115. }
  116. // -----------------------------------------------------------------------
  117. void DropDownList::updateTextFromConfig() {
  118. const wchar_t *val = getGuiObject()->guiobject_getCfgString();
  119. const wchar_t *old = getSelectedText();
  120. if (old && val && !_wcsicmp(val, old)) return;
  121. if (val != NULL) {
  122. int id = findItem(val);
  123. if (id != -1)
  124. selectItem(id);
  125. }
  126. }
  127. #endif
  128. // -----------------------------------------------------------------------
  129. void DropDownList::trapControls() {
  130. delete clicks_button;
  131. delete clicks_text;
  132. clicks_button = NULL;
  133. clicks_text = NULL;
  134. if (wantTrapText()) {
  135. GuiObject *textGuiObj = getGuiObject()->guiobject_findObject(dropdownlist_getTextId());
  136. if (textGuiObj) clicks_text = new DDLClicksCallback(*textGuiObj, this);
  137. }
  138. if (wantTrapButton()) {
  139. GuiObject *butGuiObj = getGuiObject()->guiobject_findObject(dropdownlist_getButtonId());
  140. if (butGuiObj) clicks_button = new DDLClicksCallback(*butGuiObj, this);
  141. }
  142. }
  143. // -----------------------------------------------------------------------
  144. void DropDownList::clickCallback() {
  145. if (list_group != NULL)
  146. closeList();
  147. else
  148. openList();
  149. }
  150. // -----------------------------------------------------------------------
  151. void DropDownList::escapeCallback() {
  152. if (isListOpen())
  153. closeList();
  154. }
  155. // -----------------------------------------------------------------------
  156. void DropDownList::openList() {
  157. onPreOpenList();
  158. WASABI_API_WND->appdeactivation_push_disallow(this);
  159. #ifdef WASABI_COMPILE_WNDMGR
  160. list_group = WASABI_API_SKIN->group_create_layout(dropdownlist_getListGroupId());
  161. #else
  162. list_group = WASABI_API_SKIN->group_create(dropdownlist_getListGroupId());
  163. #endif
  164. group_dep = list_group->getDependencyPtr();
  165. viewer_addViewItem(group_dep);
  166. if (list_group == NULL) return;
  167. list_group->setStartHidden(1);
  168. list_group->setParent(WASABI_API_WND->main_getRootWnd());
  169. trap_click = 0;
  170. list_group->init(this, TRUE);
  171. setListParams();
  172. // At this point, the list should be good. Calc for max-items size
  173. int calc_height = 0;
  174. if (maxitems) {
  175. ifc_window *listroot = list_group->findWindowByInterface(listGuid);
  176. ListWnd *listwnd = static_cast<ListWnd *>(listroot->getInterface(guilistGuid));
  177. GuiObject *listobj = listroot->getGuiObject();
  178. if (listwnd) {
  179. int numitems = 0;
  180. if (maxitems == -1) {
  181. numitems = listwnd->getNumItems();
  182. } else {
  183. numitems = MIN(maxitems, listwnd->getNumItems());
  184. }
  185. int offset_h = 0;
  186. if (listobj) {
  187. const wchar_t *y_param = listobj->guiobject_getXmlParam(L"y");
  188. const wchar_t *h_param = listobj->guiobject_getXmlParam(L"h");
  189. const wchar_t *ry_param = listobj->guiobject_getXmlParam(L"relaty");
  190. const wchar_t *rh_param = listobj->guiobject_getXmlParam(L"relath");
  191. int h_val = (h_param)?WTOI(h_param):0;
  192. int y_val = (y_param)?WTOI(y_param):0;
  193. if (ry_param && (wcscmp(ry_param, L"1") == 0)) {
  194. if (y_val < 0) y_val = -y_val;
  195. else y_val = 0;
  196. }
  197. if (rh_param && (wcscmp(rh_param, L"1") == 0)) {
  198. if (h_val < 0) h_val = -h_val;
  199. }
  200. offset_h = h_val + y_val;
  201. }
  202. calc_height = (numitems * listwnd->getItemHeight()) + offset_h;
  203. }
  204. } else {
  205. calc_height = height;
  206. }
  207. RECT r;
  208. getWindowRect(&r);
  209. r.top = r.bottom;
  210. r.bottom = r.top + calc_height;
  211. divRatio(&r);
  212. list_group->resize(r.left, r.top, r.right-r.left, r.bottom-r.top);
  213. list_group->setVisible(1);
  214. WASABI_API_WND->popupexit_register(this, list_group); // this will call us back whenever someone clicks outside us
  215. trap_click = 1;
  216. listif = list_group->findWindowByInterface(listGuid);
  217. if (listif != NULL)
  218. list_key = new DDLKeyCallback(listif->getGuiObject()->guiobject_getScriptObject(), this);
  219. dropdownlist_onOpenList();
  220. }
  221. // -----------------------------------------------------------------------
  222. void DropDownList::dropdownlist_onOpenList()
  223. {
  224. #ifdef _WIN32
  225. SetCapture(NULL); // NONPORTABLE, the goal is to cancel any capture some of our content guiobject might have so as to let the click down + slide in list transfer mouse capture
  226. #else
  227. #warning port me?
  228. #endif
  229. setFocus();
  230. }
  231. // -----------------------------------------------------------------------
  232. void DropDownList::dropdownlist_onCloseList() {
  233. }
  234. // -----------------------------------------------------------------------
  235. void DropDownList::closeList() {
  236. if (list_group != NULL) {
  237. onPreCloseList();
  238. postDeferredCallback(DDL_CLOSELISTCB, 0);
  239. }
  240. }
  241. // -----------------------------------------------------------------------
  242. void DropDownList::doCloseList(int cb) {
  243. if (cb) dropdownlist_onCloseList();
  244. if (list_group) {
  245. trap_click = 0;
  246. WASABI_API_WND->popupexit_deregister(this);
  247. WASABI_API_SKIN->group_destroy(list_group);
  248. list_group = NULL;
  249. group_dep = NULL;
  250. action_list = NULL;
  251. delete list_key;
  252. list_key = NULL;
  253. WASABI_API_WND->appdeactivation_pop_disallow(this);
  254. }
  255. }
  256. // -----------------------------------------------------------------------
  257. void DropDownList::setListParams() {
  258. ASSERT(list_group != NULL);
  259. GuiObject *go = static_cast<GuiObject *>(list_group->getInterface(guiObjectGuid));
  260. if (go != NULL) {
  261. dropdownlist_onConfigureList(go);
  262. }
  263. }
  264. // -----------------------------------------------------------------------
  265. void DropDownList::dropdownlist_onConfigureList(GuiObject *go) {
  266. XmlObject *o = NULL;
  267. if (go != NULL) {
  268. GuiObject *list = go->guiobject_findObject(dropdownlist_getListId());
  269. if (list != NULL) {
  270. action_list = list->guiobject_getRootWnd();
  271. o = static_cast<XmlObject *>(list->guiobject_getScriptObject()->vcpu_getInterface(xmlObjectGuid));
  272. }
  273. }
  274. StringW s;
  275. foreach(items)
  276. if (foreach_index > 0)
  277. s += L";";
  278. s += items.getfor()->getText();
  279. endfor;
  280. o->setXmlParam(L"multiselect", L"0");
  281. o->setXmlParam(L"hoverselect", L"1");
  282. o->setXmlParam(L"selectonupdown", L"0");
  283. o->setXmlParam(L"sort", StringPrintfW(L"%d", wantAutoSort()));
  284. o->setXmlParam(L"items", s);
  285. o->setXmlParam(L"antialias", listAntialias ? L"1" : L"0");
  286. if (selected != -1)
  287. o->setXmlParam(L"select", getSelectedText());
  288. }
  289. // -----------------------------------------------------------------------
  290. int DropDownList::onAction(const wchar_t *action, const wchar_t *param, int x, int y, intptr_t p1, intptr_t p2, void *data, size_t datalen, ifc_window *source) {
  291. if (WCSCASEEQLSAFE(action, L"set_selection")) {
  292. int p = findItem(param);
  293. selectItem(p);
  294. return p;
  295. }
  296. if (WCSCASEEQLSAFE(action, L"get_selection")) {
  297. if (source)
  298. sendAction(source, L"set_selection", getSelectedText());
  299. }
  300. return DROPDOWNLIST_PARENT::onAction(action, param, x, y, p1, p2, data, datalen, source);
  301. }
  302. // -----------------------------------------------------------------------
  303. int DropDownList::addItem(const wchar_t *text) {
  304. DDLEntry *e = new DDLEntry(text);
  305. items.setSorted(wantAutoSort());
  306. items.addItem(e);
  307. return e->getId();
  308. }
  309. // -----------------------------------------------------------------------
  310. void DropDownList::selectDefault() {
  311. #ifdef WASABI_COMPILE_CONFIG
  312. onReloadConfig();
  313. #endif
  314. }
  315. // -----------------------------------------------------------------------
  316. void DropDownList::delItem(int id) {
  317. foreach(items)
  318. if (items.getfor()->getId() == id) {
  319. delete items.getfor();
  320. items.removeByPos(foreach_index);
  321. break;
  322. }
  323. endfor;
  324. if (list_group != NULL)
  325. setListParams();
  326. }
  327. // -----------------------------------------------------------------------
  328. void DropDownList::selectItem(int id, int hover) {
  329. //FG> DO NOT PUT THIS TEST BACK: if (selected == id) return;
  330. selected = id;
  331. onSelect(selected, hover);
  332. }
  333. // -----------------------------------------------------------------------
  334. void DropDownList::onSelect(int id, int hover) {
  335. updateTextInControl(getSelectedText());
  336. if (!disable_cfg_event && !hover) {
  337. #ifdef WASABI_COMPILE_CONFIG
  338. if (selected == -1)
  339. getGuiObject()->guiobject_setCfgString(L"");
  340. else
  341. getGuiObject()->guiobject_setCfgString(getSelectedText());
  342. #endif
  343. }
  344. // Let the script have the callback, too.
  345. DropDownListScriptController::DropDownList_onSelect(SCRIPT_CALL, GuiObjectWnd::getScriptObject(), MAKE_SCRIPT_INT(id), MAKE_SCRIPT_INT(hover));
  346. }
  347. // -----------------------------------------------------------------------
  348. const wchar_t *DropDownList::getItemText(int id) {
  349. foreach(items)
  350. if (items.getfor()->getId() == id)
  351. return items.getfor()->getText();
  352. endfor;
  353. return NULL;
  354. }
  355. // -----------------------------------------------------------------------
  356. int DropDownList::findItem(const wchar_t *text) {
  357. int pos=-1;
  358. items.findItem(text, &pos);
  359. if (pos < 0) return -1;
  360. return items[pos]->getId();
  361. }
  362. // -----------------------------------------------------------------------
  363. void DropDownList::updateTextInControl(const wchar_t *txt)
  364. {
  365. GuiObject *content = getContent();
  366. if (content != NULL) {
  367. if (wantTrapText()) {
  368. GuiObject *text = content->guiobject_findObject(dropdownlist_getTextId());
  369. if (text != NULL) {
  370. C_Text t(*text);
  371. t.setText(txt);
  372. }
  373. }
  374. }
  375. }
  376. // -----------------------------------------------------------------------
  377. void DropDownList::setNoItemText(const wchar_t *txt)
  378. {
  379. noitemtext = txt;
  380. if (selected == -1)
  381. updateTextInControl(getSelectedText());
  382. }
  383. // -----------------------------------------------------------------------
  384. int DropDownList::popupexitcb_onExitPopup() {
  385. closeList();
  386. return 1;
  387. }
  388. // -----------------------------------------------------------------------
  389. int DropDownList::childNotify(ifc_window *child, int msg, intptr_t param1, intptr_t param2) {
  390. if (msg == ChildNotify::LISTWND_ITEMSELCHANGED && param2 && trap_click) {
  391. sendAction(action_list, L"get_selection");
  392. closeList();
  393. }
  394. return DROPDOWNLIST_PARENT::childNotify(child, msg, param1, param2);
  395. }
  396. // -----------------------------------------------------------------------
  397. int DropDownList::onDeferredCallback(intptr_t p1, intptr_t p2) {
  398. if (p1 == DDL_CLOSELISTCB)
  399. doCloseList();
  400. return DROPDOWNLIST_PARENT::onDeferredCallback(p1, p2);
  401. }
  402. // -----------------------------------------------------------------------
  403. int DropDownList::viewer_onItemDeleted(ifc_dependent *item) {
  404. if (item == group_dep) {
  405. WASABI_API_WND->popupexit_deregister(this);
  406. trap_click = 0;
  407. list_group = NULL;
  408. group_dep = NULL;
  409. action_list = NULL;
  410. }
  411. return 1;
  412. }
  413. // -----------------------------------------------------------------------
  414. void DropDownList::feedwatcher_onSetFeed(svc_textFeed *svc)
  415. {
  416. StringW a = getRootWndName();
  417. if (a.isempty())
  418. setName(svc->getFeedDescription(getFeedId()));
  419. }
  420. void DropDownList::feedwatcher_onFeedChange(const wchar_t *data)
  421. {
  422. setItems(data);
  423. }
  424. // -----------------------------------------------------------------------
  425. void DropDownList::deleteAllItems() {
  426. items.deleteAll();
  427. selected = -1;
  428. }
  429. // -----------------------------------------------------------------------
  430. int DropDownList::onKeyDown(int keyCode) {
  431. #ifdef _WIN32
  432. if (isListOpen()) {
  433. switch (keyCode) {
  434. case VK_ESCAPE:
  435. closeList();
  436. break;
  437. }
  438. if (listif != NULL) {
  439. listif->onKeyDown(keyCode);
  440. }
  441. } else {
  442. switch (keyCode) {
  443. case VK_SPACE:
  444. case VK_RETURN:
  445. openList();
  446. break;
  447. }
  448. }
  449. #else
  450. #warning port me
  451. #endif
  452. return DROPDOWNLIST_PARENT::onKeyDown(keyCode);
  453. }
  454. // -----------------------------------------------------------------------
  455. int DropDownList::onKeyUp(int keyCode) {
  456. if (isListOpen()) {
  457. if (listif != NULL) {
  458. listif->onKeyUp(keyCode);
  459. return 1;
  460. }
  461. }
  462. return DROPDOWNLIST_PARENT::onKeyDown(keyCode);
  463. }
  464. // -----------------------------------------------------------------------
  465. void DropDownList::setItems(const wchar_t *value) {
  466. deleteAllItems();
  467. ParamParser pp(value);
  468. for (int i=0;i<pp.getNumItems();i++) {
  469. addItem(pp.enumItem(i));
  470. }
  471. selectDefault();
  472. }
  473. // -----------------------------------------------------------------------
  474. int DDLEntry::id_gen=0;
  475. // -----------------------------------------------------------------------
  476. // Script Object
  477. DropDownListScriptController _dropDownListController;
  478. DropDownListScriptController *dropDownListController = &_dropDownListController;
  479. // -- Functions table -------------------------------------
  480. function_descriptor_struct DropDownListScriptController::exportedFunction[] = {
  481. {L"getItemSelected", 0, (void*)DropDownListScriptController::DropDownList_getItemSelected},
  482. {L"onSelect", 2, (void*)DropDownListScriptController::DropDownList_onSelect},
  483. {L"setListHeight", 1, (void*)DropDownListScriptController::DropDownList_setListHeight},
  484. {L"openList", 0, (void*)DropDownListScriptController::DropDownList_openList},
  485. {L"closeList", 0, (void*)DropDownListScriptController::DropDownList_closeList},
  486. {L"setItems", 1, (void*)DropDownListScriptController::DropDownList_setItems},
  487. {L"addItem", 1, (void*)DropDownListScriptController::DropDownList_addItem},
  488. {L"delItem", 1, (void*)DropDownListScriptController::DropDownList_delItem},
  489. {L"findItem", 1, (void*)DropDownListScriptController::DropDownList_findItem},
  490. {L"getNumItems", 0, (void*)DropDownListScriptController::DropDownList_getNumItems},
  491. {L"selectItem", 2, (void*)DropDownListScriptController::DropDownList_selectItem},
  492. {L"getItemText", 1, (void*)DropDownListScriptController::DropDownList_getItemText},
  493. {L"getSelected", 0, (void*)DropDownListScriptController::DropDownList_getSelected},
  494. {L"getSelectedText", 0, (void*)DropDownListScriptController::DropDownList_getSelectedText},
  495. {L"getCustomText", 0, (void*)DropDownListScriptController::DropDownList_getCustomText},
  496. {L"deleteAllItems", 0, (void*)DropDownListScriptController::DropDownList_deleteAllItems},
  497. {L"setNoItemText", 1, (void*)DropDownListScriptController::DropDownList_setNoItemText},
  498. };
  499. ScriptObject *DropDownListScriptController::instantiate() {
  500. DropDownList *ddl = new DropDownList;
  501. ASSERT(ddl != NULL);
  502. return ddl->GuiObjectWnd::getScriptObject();
  503. }
  504. void DropDownListScriptController::destroy(ScriptObject *o) {
  505. DropDownList *ddl= static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  506. ASSERT(ddl != NULL);
  507. delete ddl;
  508. }
  509. void *DropDownListScriptController::encapsulate(ScriptObject *o) {
  510. return NULL; // no encapsulation for DropDownlist yet
  511. }
  512. void DropDownListScriptController::deencapsulate(void *o) {
  513. }
  514. int DropDownListScriptController::getNumFunctions() {
  515. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  516. }
  517. const function_descriptor_struct *DropDownListScriptController::getExportedFunctions() {
  518. return exportedFunction;
  519. }
  520. scriptVar DropDownListScriptController::DropDownList_getItemSelected(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  521. SCRIPT_FUNCTION_INIT
  522. DropDownList *ddl = static_cast<DropDownList*>(o->vcpu_getInterface(dropDownListGuid));
  523. const wchar_t *p=L"";
  524. if (ddl) p = ddl->getSelectedText();
  525. return MAKE_SCRIPT_STRING(p);
  526. }
  527. scriptVar DropDownListScriptController::DropDownList_onSelect(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar id, scriptVar hover) {
  528. SCRIPT_FUNCTION_INIT
  529. PROCESS_HOOKS2(o, dropDownListController, id, hover);
  530. SCRIPT_FUNCTION_CHECKABORTEVENT;
  531. SCRIPT_EXEC_EVENT2(o, id, hover);
  532. }
  533. /*void*/ scriptVar DropDownListScriptController::DropDownList_setListHeight(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*int*/ scriptVar h) {
  534. SCRIPT_FUNCTION_INIT
  535. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  536. if (ddl) {
  537. ddl->setListHeight(GET_SCRIPT_INT(h));
  538. }
  539. RETURN_SCRIPT_VOID;
  540. }
  541. /*void*/ scriptVar DropDownListScriptController::DropDownList_openList(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  542. SCRIPT_FUNCTION_INIT
  543. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  544. if (ddl) {
  545. ddl->openList();
  546. }
  547. RETURN_SCRIPT_VOID;
  548. }
  549. /*void*/ scriptVar DropDownListScriptController::DropDownList_closeList(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  550. SCRIPT_FUNCTION_INIT
  551. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  552. if (ddl) {
  553. ddl->closeList();
  554. }
  555. RETURN_SCRIPT_VOID;
  556. }
  557. /*void*/ scriptVar DropDownListScriptController::DropDownList_setItems(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*String*/ scriptVar lotsofitems) {
  558. SCRIPT_FUNCTION_INIT
  559. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  560. if (ddl) {
  561. ddl->setItems(GET_SCRIPT_STRING(lotsofitems));
  562. }
  563. RETURN_SCRIPT_VOID;
  564. }
  565. /*int*/ scriptVar DropDownListScriptController::DropDownList_addItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*String*/ scriptVar text) {
  566. SCRIPT_FUNCTION_INIT
  567. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  568. int retval = 0;
  569. if (ddl)
  570. {
  571. retval = ddl->addItem(GET_SCRIPT_STRING(text));
  572. }
  573. return MAKE_SCRIPT_INT(retval);
  574. }
  575. /*void*/ scriptVar DropDownListScriptController::DropDownList_delItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*int*/ scriptVar id) {
  576. SCRIPT_FUNCTION_INIT
  577. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  578. if (ddl) {
  579. ddl->delItem(GET_SCRIPT_INT(id));
  580. }
  581. RETURN_SCRIPT_VOID;
  582. }
  583. /*int*/ scriptVar DropDownListScriptController::DropDownList_findItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*String*/ scriptVar text) {
  584. SCRIPT_FUNCTION_INIT
  585. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  586. int retval = 0;
  587. if (ddl) {
  588. retval = ddl->findItem(GET_SCRIPT_STRING(text));
  589. }
  590. return MAKE_SCRIPT_INT(retval);
  591. }
  592. /*int*/ scriptVar DropDownListScriptController::DropDownList_getNumItems(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  593. SCRIPT_FUNCTION_INIT
  594. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  595. int retval = 0;
  596. if (ddl) {
  597. retval = ddl->getNumItems();
  598. }
  599. return MAKE_SCRIPT_INT(retval);
  600. }
  601. /*void*/ scriptVar DropDownListScriptController::DropDownList_selectItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*int*/ scriptVar id, /*int*/ scriptVar hover) {
  602. SCRIPT_FUNCTION_INIT
  603. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  604. if (ddl) {
  605. ddl->selectItem(GET_SCRIPT_INT(id), GET_SCRIPT_INT(hover));
  606. }
  607. RETURN_SCRIPT_VOID;
  608. }
  609. /*String*/ scriptVar DropDownListScriptController::DropDownList_getItemText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*int*/ scriptVar id) {
  610. SCRIPT_FUNCTION_INIT
  611. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  612. const wchar_t *retval = L"";
  613. if (ddl) {
  614. retval = ddl->getItemText(GET_SCRIPT_INT(id));
  615. }
  616. return MAKE_SCRIPT_STRING(retval);
  617. }
  618. /*int*/ scriptVar DropDownListScriptController::DropDownList_getSelected(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  619. SCRIPT_FUNCTION_INIT
  620. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  621. int retval = 0;
  622. if (ddl) {
  623. retval = ddl->getSelected();
  624. }
  625. return MAKE_SCRIPT_INT(retval);
  626. }
  627. /*String*/ scriptVar DropDownListScriptController::DropDownList_getSelectedText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  628. SCRIPT_FUNCTION_INIT
  629. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  630. const wchar_t *retval = L"";
  631. if (ddl) {
  632. retval = ddl->getSelectedText();
  633. }
  634. return MAKE_SCRIPT_STRING(retval);
  635. }
  636. /*String*/ scriptVar DropDownListScriptController::DropDownList_getCustomText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  637. SCRIPT_FUNCTION_INIT
  638. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  639. const wchar_t *retval=L"";
  640. if (ddl) {
  641. retval = ddl->getCustomText();
  642. }
  643. return MAKE_SCRIPT_STRING(retval);
  644. }
  645. /*void*/ scriptVar DropDownListScriptController::DropDownList_deleteAllItems(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  646. SCRIPT_FUNCTION_INIT
  647. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  648. if (ddl) {
  649. ddl->deleteAllItems();
  650. }
  651. RETURN_SCRIPT_VOID;
  652. }
  653. /*void*/ scriptVar DropDownListScriptController::DropDownList_setNoItemText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*String*/ scriptVar txt) {
  654. SCRIPT_FUNCTION_INIT
  655. DropDownList *ddl = static_cast<DropDownList *>(o->vcpu_getInterface(dropDownListGuid));
  656. if (ddl) {
  657. ddl->setNoItemText(GET_SCRIPT_STRING(txt));
  658. }
  659. RETURN_SCRIPT_VOID;
  660. }