1
0

combobox.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #include <precomp.h>
  2. #include "combobox.h"
  3. #include <api/script/objects/c_script/c_edit.h>
  4. #include <api/skin/xmlobject.h>
  5. ComboBox::ComboBox() {
  6. keys_edit = NULL;
  7. lastlist = NULL;
  8. disable_getselection = 0;
  9. savedidle = 0;
  10. savedautoenter = 0;
  11. }
  12. ComboBox::~ComboBox() {
  13. delete keys_edit;
  14. }
  15. void ComboBox::abstract_onNewContent() {
  16. COMBOBOX_PARENT::abstract_onNewContent();
  17. trapControls();
  18. }
  19. void ComboBox::trapControls() {
  20. delete keys_edit;
  21. keys_edit = NULL;
  22. if (wantTrapEdit()) {
  23. GuiObject *editGuiObj = getGuiObject()->guiobject_findObject(combobox_getEditId());
  24. if (editGuiObj) keys_edit = new HEBKeysCallback(*editGuiObj, this);
  25. }
  26. }
  27. void ComboBox::updateTextInControl(const wchar_t *txt)
  28. {
  29. if (txt == NULL) return;
  30. if (WCSCASEEQLSAFE(getText(), txt)) return;
  31. GuiObject *content = getContent();
  32. if (content != NULL) {
  33. if (wantTrapEdit()) {
  34. GuiObject *text = content->guiobject_findObject(combobox_getEditId());
  35. if (text != NULL) {
  36. C_Edit t(*text);
  37. t.setText(txt);
  38. curtxt = txt;
  39. }
  40. }
  41. }
  42. }
  43. void ComboBox::dropdownlist_onCloseList() {
  44. COMBOBOX_PARENT::dropdownlist_onCloseList();
  45. if (wantTrapEdit()) {
  46. GuiObject *o = embeddedxui_getEmbeddedObject();
  47. if (o != NULL) {
  48. o->guiobject_getRootWnd()->setFocus();
  49. GuiObject *edit = o->guiobject_findObjectByInterface(editGuid);
  50. if (edit != NULL) {
  51. C_Edit e(*edit);
  52. e.setAutoEnter(savedautoenter);
  53. e.setIdleEnabled(savedidle);
  54. }
  55. }
  56. }
  57. if (wantEnterOnSelect())
  58. enter();
  59. disable_getselection = 0;
  60. }
  61. void ComboBox::dropdownlist_onOpenList() {
  62. COMBOBOX_PARENT::dropdownlist_onOpenList();
  63. if (wantTrapEdit()) {
  64. GuiObject *o = embeddedxui_getEmbeddedObject();
  65. if (o != NULL) {
  66. o->guiobject_getRootWnd()->setFocus();
  67. GuiObject *edit = o->guiobject_findObjectByInterface(editGuid);
  68. if (edit != NULL) {
  69. C_Edit e(*edit);
  70. savedidle = e.getIdleEnabled();
  71. savedautoenter = e.getAutoEnter();
  72. e.setIdleEnabled(0);
  73. e.setAutoEnter(0);
  74. }
  75. }
  76. }
  77. }
  78. void ComboBox::setText(const wchar_t *text, int hover) {
  79. updateTextInControl(text);
  80. selectItem(-1, hover);
  81. selectEditor();
  82. }
  83. const wchar_t *ComboBox::getText(int fromcontrol)
  84. {
  85. if (!fromcontrol)
  86. return curtxt;
  87. const wchar_t *c = NULL;
  88. GuiObject *content = getContent();
  89. if (content != NULL) {
  90. if (wantTrapEdit()) {
  91. GuiObject *text = content->guiobject_findObject(combobox_getEditId());
  92. if (text != NULL) {
  93. C_Edit t(*text);
  94. c = t.getText();
  95. }
  96. }
  97. }
  98. curtxt = c;
  99. return c;
  100. }
  101. void ComboBox::dropdownlist_onConfigureList(GuiObject *o) {
  102. COMBOBOX_PARENT::dropdownlist_onConfigureList(o);
  103. ifc_window *w = o->guiobject_getRootWnd()->findWindowByInterface(listGuid);
  104. sendAction(w, L"register_tempselectnotify");
  105. //w->getGuiObject()->guiobject_setXmlParam("select", getCustomText());
  106. lastlist = w->getGuiObject();
  107. }
  108. void ComboBox::onSelect(int id, int hover) {
  109. COMBOBOX_PARENT::onSelect(id, hover);
  110. if (!hover) {
  111. selectEditor();
  112. if (wantEnterOnSelect())
  113. enter();
  114. }
  115. }
  116. void ComboBox::enter() {
  117. GuiObject *content = getContent();
  118. if (content != NULL) {
  119. if (wantTrapEdit()) {
  120. GuiObject *text = content->guiobject_findObject(combobox_getEditId());
  121. if (text != NULL) {
  122. C_Edit t(*text);
  123. t.enter();
  124. }
  125. }
  126. }
  127. }
  128. void ComboBox::selectEditor() {
  129. GuiObject *content = getContent();
  130. if (content != NULL) {
  131. if (wantTrapEdit()) {
  132. GuiObject *text = content->guiobject_findObject(combobox_getEditId());
  133. if (text != NULL) {
  134. C_Edit t(*text);
  135. t.selectAll();
  136. }
  137. }
  138. }
  139. }
  140. int ComboBox::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) {
  141. int r = COMBOBOX_PARENT::onAction(action, param, x, y, p1, p2, data, datalen, source);
  142. if (WCSCASEEQLSAFE(action, L"tempselectnotify")) {
  143. if (!disable_getselection)
  144. setText(param, 1);
  145. }
  146. return r;
  147. }
  148. void ComboBox::onEditKeyDown(int vk) {
  149. if (Std::keyDown(VK_CONTROL)) return;
  150. if (vk == VK_DOWN) {
  151. if (wantDownOpenList()) {
  152. if (!isListOpen())
  153. openList();
  154. else {
  155. if (wantTransferDownToList())
  156. listDown();
  157. }
  158. }
  159. } else if (vk == VK_UP) {
  160. if (wantTransferUpToList())
  161. listUp();
  162. } else if (vk == VK_HOME) {
  163. if (wantTransferHomeToList())
  164. listHome();
  165. } else if (vk == VK_END) {
  166. if (wantTransferEndToList())
  167. listEnd();
  168. } else if (vk == VK_PRIOR) {
  169. if (wantTransferPgUpToList())
  170. listPageUp();
  171. } else if (vk == VK_NEXT) {
  172. if (wantTransferPgDnToList())
  173. listPageDown();
  174. } else if (vk == VK_ESCAPE) {
  175. if (isListOpen())
  176. closeList();
  177. } else if (vk == VK_BACK || vk == VK_DELETE || vk == VK_LEFT || vk == VK_RIGHT) {
  178. if (wantCloseListOnChar()) {
  179. if (isListOpen())
  180. closeList();
  181. }
  182. }
  183. }
  184. void ComboBox::onEditKeyUp(int vk)
  185. {
  186. curtxt = getText(1);
  187. }
  188. void ComboBox::onEditEnter(const wchar_t *txt)
  189. {
  190. if (isListOpen()) {
  191. if (wantTransferEnterToList())
  192. listSelect();
  193. }
  194. }
  195. void ComboBox::onEditChar(int c) {
  196. if (wantCloseListOnChar()) {
  197. if (isListOpen())
  198. closeList();
  199. }
  200. }
  201. void ComboBox::listUp() {
  202. if (lastlist != NULL && isListOpen()) {
  203. sendAction(lastlist->guiobject_getRootWnd(), L"up");
  204. }
  205. }
  206. void ComboBox::listDown() {
  207. if (lastlist != NULL && isListOpen()) {
  208. sendAction(lastlist->guiobject_getRootWnd(), L"down");
  209. }
  210. }
  211. void ComboBox::listHome() {
  212. if (lastlist != NULL && isListOpen()) {
  213. sendAction(lastlist->guiobject_getRootWnd(), L"home");
  214. }
  215. }
  216. void ComboBox::listEnd() {
  217. if (lastlist != NULL && isListOpen()) {
  218. sendAction(lastlist->guiobject_getRootWnd(), L"end");
  219. }
  220. }
  221. void ComboBox::listPageUp() {
  222. if (lastlist != NULL && isListOpen()) {
  223. sendAction(lastlist->guiobject_getRootWnd(), L"pageup");
  224. }
  225. }
  226. void ComboBox::listPageDown() {
  227. if (lastlist != NULL && isListOpen()) {
  228. sendAction(lastlist->guiobject_getRootWnd(), L"pagedown");
  229. }
  230. }
  231. void ComboBox::listSelect() {
  232. if (lastlist != NULL && isListOpen()) {
  233. sendAction(lastlist->guiobject_getRootWnd(), L"select_current");
  234. }
  235. }
  236. void ComboBox::onPreCloseList() {
  237. disable_getselection = 1;
  238. }