dropdownlist.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. #ifndef __DROPDOWNLIST_H
  2. #define __DROPDOWNLIST_H
  3. #include <api/wnd/popexitcb.h>
  4. #include <api/wnd/wndclass/embeddedxui.h>
  5. #include <api/script/objects/c_script/h_guiobject.h>
  6. #include <api/script/objects/c_script/h_button.h>
  7. #include <api/skin/feeds/feedwatch.h>
  8. #include <api/script/objcontroller.h>
  9. #define DROPDOWNLIST_PARENT EmbeddedXuiObject
  10. class DDLClicksCallback;
  11. class DDLKeyCallback;
  12. class svc_textFeed;
  13. /**
  14. Class
  15. @short
  16. @author Nullsoft
  17. @ver 1.0
  18. @see
  19. */
  20. class DDLEntry {
  21. public:
  22. /**
  23. Method
  24. @see
  25. @ret
  26. @param
  27. */
  28. DDLEntry(const wchar_t *txt) : text(txt), id(id_gen++) { }
  29. const wchar_t *getText() { return text; }
  30. /**
  31. Method
  32. @see
  33. @ret
  34. @param
  35. */
  36. int getId() { return id; }
  37. private:
  38. StringW text;
  39. int id;
  40. static int id_gen;
  41. };
  42. /**
  43. Class
  44. @short
  45. @author Nullsoft
  46. @ver 1.0
  47. @see
  48. */
  49. class SortDDLEntries{
  50. public:
  51. static int compareItem(DDLEntry *p1, DDLEntry *p2) {
  52. return WCSICMP(p1->getText(), p2->getText());
  53. }
  54. static int compareAttrib(const wchar_t *attrib, DDLEntry *item)
  55. {
  56. return WCSICMP(attrib, item->getText());
  57. }
  58. };
  59. /**
  60. Class
  61. @short
  62. @author Nullsoft
  63. @ver 1.0
  64. @see
  65. */
  66. class DropDownList : public DROPDOWNLIST_PARENT, public PopupExitCallbackI, public FeedWatcher, public DependentViewerI {
  67. public:
  68. /**
  69. Method
  70. @see
  71. @ret
  72. @param
  73. */
  74. DropDownList();
  75. /**
  76. Method
  77. @see
  78. @ret
  79. @param
  80. */
  81. virtual ~DropDownList();
  82. /**
  83. Method
  84. @see
  85. @ret
  86. @param
  87. */
  88. virtual int onInit();
  89. /**
  90. Method
  91. @see
  92. @ret
  93. @param
  94. */
  95. void clickCallback();
  96. void escapeCallback();
  97. /**
  98. Method
  99. @see
  100. @ret
  101. @param
  102. */
  103. #ifdef WASABI_COMPILE_CONFIG
  104. virtual int onReloadConfig();
  105. #endif
  106. /**
  107. Method
  108. @see
  109. @ret
  110. @param
  111. */
  112. virtual void abstract_onNewContent();
  113. /**
  114. Method
  115. @see
  116. @ret
  117. @param
  118. */
  119. virtual void setListHeight(int h) { height = h; }
  120. /**
  121. Method
  122. @see
  123. @ret
  124. @param
  125. */
  126. virtual int popupexitcb_onExitPopup();
  127. virtual api_dependent *popupexit_getDependencyPtr() { return rootwnd_getDependencyPtr(); }
  128. /**
  129. Method
  130. @see
  131. @ret
  132. @param
  133. */
  134. void openList();
  135. /**
  136. Method
  137. @see
  138. @ret
  139. @param
  140. */
  141. void closeList();
  142. void setItems(const wchar_t *lotsofitems);
  143. int addItem(const wchar_t *text);
  144. /**
  145. Method
  146. @see
  147. @ret
  148. @param
  149. */
  150. void delItem(int id);
  151. int findItem(const wchar_t *text);
  152. int getNumItems() { return items.getNumItems(); }
  153. DDLEntry *enumItem(int i) { return items.enumItem(i); }
  154. /**
  155. Method
  156. @see
  157. @ret
  158. @param
  159. */
  160. void selectItem(int id, int hover=0);
  161. const wchar_t *getItemText(int id);
  162. int getSelected() { return selected; }
  163. const wchar_t *getSelectedText() { int a = getSelected(); if (a == -1) return getCustomText(); return getItemText(a); }
  164. virtual const wchar_t *getCustomText() { return noitemtext; }
  165. /**
  166. Method
  167. @see
  168. @ret
  169. @param
  170. */
  171. virtual void deleteAllItems();
  172. /**
  173. Method
  174. @see
  175. @ret
  176. @param
  177. */
  178. virtual void onSelect(int id, int hover=0);
  179. virtual void setNoItemText(const wchar_t *txt);
  180. /**
  181. Method
  182. @see
  183. @ret
  184. @param
  185. */
  186. virtual int childNotify(ifc_window *child, int msg, intptr_t param1=0, intptr_t param2=0);
  187. /**
  188. Method
  189. @see
  190. @ret
  191. @param
  192. */
  193. virtual int onDeferredCallback(intptr_t p1, intptr_t p2);
  194. /**
  195. Method
  196. @see
  197. @ret
  198. @param
  199. */
  200. virtual int viewer_onItemDeleted(api_dependent *item);
  201. virtual void feedwatcher_onSetFeed(svc_textFeed *svc);
  202. virtual void feedwatcher_onFeedChange(const wchar_t *data);
  203. virtual int onAction(const wchar_t *action, const wchar_t *param=NULL, int x=-1, int y=-1, intptr_t p1=0, intptr_t p2=0, void *data=NULL, size_t datalen=0, ifc_window *source=NULL);
  204. /**
  205. Method
  206. @see
  207. @ret
  208. @param
  209. */
  210. virtual void selectDefault();
  211. virtual void setMaxItems(int _maxitems) { maxitems = _maxitems; }
  212. virtual int getMaxItems() { return maxitems; }
  213. virtual int wantTrapButton() { return 1; }
  214. virtual int wantTrapText() { return 1; }
  215. virtual int wantFocus() { return 1; }
  216. virtual const wchar_t *dropdownlist_getMainGroupId() { return L"wasabi.dropdownlist.main.group"; }
  217. virtual const wchar_t *dropdownlist_getListGroupId() { return L"wasabi.dropdownlist.list.group"; }
  218. virtual const wchar_t *dropdownlist_getTextId() { return L"dropdownlist.text"; }
  219. virtual const wchar_t *dropdownlist_getButtonId() { return L"dropdownlist.button"; }
  220. virtual const wchar_t *dropdownlist_getListId() { return L"dropdownlist.list"; }
  221. virtual void updateTextInControl(const wchar_t *txt);
  222. virtual int setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value);
  223. virtual const wchar_t *embeddedxui_getContentId() { return dropdownlist_getMainGroupId(); }
  224. virtual const wchar_t *embeddedxui_getEmbeddedObjectId() { return dropdownlist_getTextId(); }
  225. int isListOpen() { return list_group != NULL; };
  226. virtual int wantAutoSort() { return 1; }
  227. virtual void dropdownlist_onCloseList();
  228. virtual void dropdownlist_onOpenList();
  229. virtual void dropdownlist_onConfigureList(GuiObject *o);
  230. virtual int onKeyDown(int keyCode);
  231. virtual int onKeyUp(int keyCode);
  232. virtual int onAcceleratorEvent(const wchar_t *name);
  233. virtual void onPreCloseList() {}
  234. virtual void onPreOpenList() {}
  235. protected:
  236. /*static */void CreateXMLParameters(int master_handle);
  237. private:
  238. enum {
  239. DROPDOWNLIST_SETITEMS = 0,
  240. DROPDOWNLIST_SETFEED,
  241. DROPDOWNLIST_SELECT,
  242. DROPDOWNLIST_LISTHEIGHT,
  243. DROPDOWNLIST_MAXITEMS,
  244. DROPDOWNLIST_SETLISTANTIALIAS,
  245. };
  246. int myxuihandle;
  247. static XMLParamPair params[];
  248. private:
  249. #ifdef WASABI_COMPILE_CONFIG
  250. void updateTextFromConfig();
  251. #endif
  252. /**
  253. Method
  254. @see
  255. @ret
  256. @param
  257. */
  258. void trapControls();
  259. /**
  260. Method
  261. @see
  262. @ret
  263. @param
  264. */
  265. void setListParams();
  266. /**
  267. Method
  268. @see
  269. @ret
  270. @param
  271. */
  272. void doCloseList(int cb=1);
  273. DDLClicksCallback *clicks_button;
  274. DDLClicksCallback *clicks_text;
  275. DDLKeyCallback *list_key;
  276. ifc_window *list_group;
  277. PtrListInsertSorted<DDLEntry, SortDDLEntries> items;
  278. int selected;
  279. int height;
  280. int maxitems;
  281. StringW noitemtext;
  282. int trap_click;
  283. api_dependent *group_dep;
  284. ifc_window *action_list;
  285. int disable_cfg_event;
  286. ifc_window *listif;
  287. int listAntialias;
  288. };
  289. /**
  290. Class
  291. @short
  292. @author Nullsoft
  293. @ver 1.0
  294. @see
  295. */
  296. class DDLClicksCallback : public H_GuiObject {
  297. public:
  298. /**
  299. Method
  300. @see
  301. @ret
  302. @param
  303. */
  304. DDLClicksCallback(ScriptObject *trap, DropDownList *_callback) :
  305. /**
  306. Method
  307. @see
  308. @ret
  309. @param
  310. */
  311. callback(_callback), H_GuiObject(trap) {
  312. }
  313. /**
  314. Method
  315. @see
  316. @ret
  317. @param
  318. */
  319. virtual void hook_onLeftButtonDown(int x, int y) {
  320. callback->clickCallback();
  321. }
  322. virtual void hook_onChar(wchar_t c)
  323. {
  324. #ifdef _WIN32
  325. if (c == VK_SPACE || c == VK_RETURN)
  326. callback->clickCallback();
  327. #else
  328. #warning port me
  329. #endif
  330. }
  331. private:
  332. DropDownList *callback;
  333. };
  334. class DDLKeyCallback : public H_GuiObject {
  335. public:
  336. /**
  337. Method
  338. @see
  339. @ret
  340. @param
  341. */
  342. DDLKeyCallback(ScriptObject *trap, DropDownList *_callback) :
  343. /**
  344. Method
  345. @see
  346. @ret
  347. @param
  348. */
  349. callback(_callback), H_GuiObject(trap) {
  350. }
  351. /**
  352. Method
  353. @see
  354. @ret
  355. @param
  356. */
  357. virtual void hook_onChar(wchar_t c)
  358. {
  359. #ifdef _WIN32
  360. if (c == VK_ESCAPE)
  361. callback->escapeCallback();
  362. #else
  363. #warning port me
  364. #endif
  365. }
  366. private:
  367. DropDownList *callback;
  368. };
  369. // -----------------------------------------------------------------------
  370. class DropDownListScriptController: public ScriptObjectControllerI {
  371. public:
  372. virtual const wchar_t *getClassName() { return L"DropDownList"; }
  373. virtual const wchar_t *getAncestorClassName() { return L"ObjectEmbedder"; }
  374. virtual ScriptObjectController *getAncestorController() { return WASABI_API_MAKI->maki_getController(embeddedXuiGuid); }
  375. virtual int getNumFunctions();
  376. virtual const function_descriptor_struct *getExportedFunctions();
  377. virtual GUID getClassGuid() { return dropDownListGuid; }
  378. virtual ScriptObject *instantiate();
  379. virtual void destroy(ScriptObject *o);
  380. virtual void *encapsulate(ScriptObject *o);
  381. virtual void deencapsulate(void *o);
  382. // public cause it's called by the xui object.
  383. static scriptVar DropDownList_onSelect(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar id, scriptVar hover);
  384. private:
  385. static function_descriptor_struct exportedFunction[];
  386. static scriptVar DropDownList_getItemSelected(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  387. static /*void*/ scriptVar DropDownList_setListHeight(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*int*/ scriptVar h);
  388. static /*void*/ scriptVar DropDownList_openList(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  389. static /*void*/ scriptVar DropDownList_closeList(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  390. static /*void*/ scriptVar DropDownList_setItems(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*String*/ scriptVar lotsofitems);
  391. static /*int*/ scriptVar DropDownList_addItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*String*/ scriptVar text);
  392. static /*void*/ scriptVar DropDownList_delItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*int*/ scriptVar id);
  393. static /*int*/ scriptVar DropDownList_findItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*String*/ scriptVar text);
  394. static /*int*/ scriptVar DropDownList_getNumItems(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  395. static /*void*/ scriptVar DropDownList_selectItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*int*/ scriptVar id, /*int*/ scriptVar hover);
  396. static /*String*/ scriptVar DropDownList_getItemText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*int*/ scriptVar id);
  397. static /*int*/ scriptVar DropDownList_getSelected(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  398. static /*String*/ scriptVar DropDownList_getSelectedText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  399. static /*String*/ scriptVar DropDownList_getCustomText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  400. static /*void*/ scriptVar DropDownList_deleteAllItems(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  401. static /*void*/ scriptVar DropDownList_setNoItemText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*String*/ scriptVar txt);
  402. };
  403. extern COMEXP DropDownListScriptController *dropDownListController;
  404. #endif