iup_list.e 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. class IUP_LIST
  2. -- Creates an interface element that displays a list of items. The list can be
  3. -- visible or can be dropped down. It also can have an edit box for text input.
  4. -- So it is a 4 in 1 element. In native systems the dropped down case is called
  5. -- Combo Box.
  6. --
  7. -- Text is always left aligned.
  8. --
  9. -- When the list has focus use the arrow keys to move focus from one item to
  10. -- another. When DROPDOWN=Yes use the Alt+Down key combination to show the
  11. -- dropdown list. While the dropdown is shown the arrow key may change the
  12. -- current value depending on the system, on Windows will directly change the
  13. -- current value, on GTK will change the current value only if Enter is pressed.
  14. -- In all systems the dropdown list is closed by using the Alt+Up key
  15. -- combination, or by pressing Enter or Esc keys ( while the dropdown list
  16. -- dropdown list the DEFAULTENTER and DEFAULTESC buttons will not be called
  17. -- (fixed in 3.14)).
  18. --
  19. -- The GETFOCUS_CB and KILLFOCUS_CB callbacks behave differently depending on
  20. -- the list configuration and on the native system:
  21. --
  22. -- If DROPDOWN=NO and EDITBOX=YES, then the list never gets the focus, the
  23. -- callbacks are called only when the edit box is clicked.
  24. -- In Motif if DROPDOWN=YES then when the dropdown button is clicked the list
  25. -- looses its focus and when the dropped list is closed the list regain the
  26. -- focus, also when that happen if the list looses its focus to another control
  27. -- the kill focus callback is not called.
  28. -- In GTK, if DROPDOWN=YES and EDITBOX=NO, both callbacks are called only when
  29. -- navigating with the keyboard (tip: if you need those callbacks with mouse
  30. -- navigation set EDITBOX=YES and READONLY=YES). Also in GTK, if DROPDOWN=YES
  31. -- and EDITBOX=YES then when the dropdown button is clicked the list looses its
  32. -- focus and it gets it back only if the edit box is clicked.
  33. --
  34. -- In Windows, if EDITBOX=YES then the tooltips are shown only when the cursor
  35. -- is near the control border or at the dropdown arrow. Also the selection and
  36. -- caret attributes are not preserved if the list loses its focus, or in other
  37. -- words these attributes are only useful in Windows if the list has the focus.
  38. --
  39. -- IMPORTANT: In Windows when DROPDOWN=Yes the vertical size is controlled by
  40. -- the system, and has the height just right to include the borders and the
  41. -- text. So the User height from RASTERSIZE or SIZE will be always ignored.
  42. --
  43. -- In Windows, list items are limited to 255 pixels height.
  44. --
  45. -- In GTK older than 2.12, the editbox of a dropdown will not follow the list
  46. -- attributes: FONT, BGCOLOR, FGCOLOR and SPACING.
  47. --
  48. -- Clicking and dragging a item: if SHOWDRAGDROP=Yes starts a drag. When mouse
  49. -- is released, the DRAGDROP_CB callback is called. If the callback does not
  50. -- exist or if it returns IUP_CONTINUE then the item is moved to the new
  51. -- position. If Ctrl is pressed then the node is copied instead of moved. In
  52. -- Windows and GTK, drag is performed with the left mouse button. In Motif, the
  53. -- middle mouse button is used to drag. (since 3.7)
  54. inherit
  55. IUP_WIDGET
  56. undefine
  57. execute_dragbegin,
  58. execute_dragdatasize,
  59. execute_dragdata,
  60. execute_dragend,
  61. execute_dropdata,
  62. execute_dropmotion
  63. redefine
  64. execute_map,
  65. execute_unmap,
  66. execute_destroy,
  67. execute_getfocus,
  68. execute_killfocus,
  69. execute_enterwindow,
  70. execute_leavewindow,
  71. execute_k_any,
  72. execute_help,
  73. execute_action_fnsii,
  74. execute_caret,
  75. execute_dblclick,
  76. execute_dragdrop,
  77. execute_dropdown,
  78. execute_edit,
  79. execute_multiselect,
  80. execute_motion,
  81. execute_button,
  82. execute_dropfiles,
  83. execute_valuechanged
  84. end
  85. IUP_WIDGET_TEXT_CARET
  86. IUP_WIDGET_TEXT_COMMON
  87. IUP_WIDGET_TEXT_SELECTION
  88. IUP_WIDGET_BGCOLOR
  89. IUP_WIDGET_FGCOLOR
  90. IUP_WIDGET_SIZE
  91. IUP_WIDGET_ACTIVE
  92. IUP_WIDGET_FONT
  93. IUP_WIDGET_EXPAND
  94. IUP_WIDGET_SCREENPOSITION
  95. IUP_WIDGET_POSITION
  96. IUP_WIDGET_MAXMIN_SIZE
  97. IUP_WIDGET_TIP
  98. IUP_WIDGET_RASTERSIZE
  99. IUP_WIDGET_USERSIZE
  100. IUP_WIDGET_ZORDER
  101. IUP_WIDGET_VISIBLE
  102. IUP_WIDGET_CHILD
  103. IUP_WIDGET_SPACING
  104. redefine
  105. set_spacing
  106. end
  107. IUP_WIDGET_FOCUS
  108. IUP_WIDGET_PROPAGATEFOCUS
  109. IUP_WIDGET_NAME
  110. IUP_DRAG_AND_DROP
  111. IUP_WIDGET_CUSTOM_ATTRIBUTES
  112. create {ANY}
  113. list
  114. feature {ANY}
  115. list
  116. -- Create an empty list.
  117. local
  118. a_list, p: POINTER
  119. do
  120. a_list := int_list(p)
  121. set_widget(a_list)
  122. end
  123. -- Attributes
  124. set_auto_hide (state: BOOLEAN)
  125. -- Scrollbars are shown only if they are necessary. Default: "True".
  126. do
  127. iup_open.set_attribute(Current, "AUTOHIDE", boolean_to_yesno(state))
  128. end
  129. set_auto_redraw (state: BOOLEAN)
  130. -- [Windows] (non inheritable): automatically redraws the list when
  131. -- something has change. Set to False to add many items to the list
  132. -- without updating the display. Default: "True".
  133. do
  134. iup_open.set_attribute(Current, "AUTOREDRAW", boolean_to_yesno(state))
  135. end
  136. set_can_focus (state: BOOLEAN)
  137. -- (creation only) (non inheritable): enables the focus traversal of the
  138. -- control. In Windows the control will still get the focus when clicked.
  139. -- Default: True.
  140. do
  141. iup_open.set_attribute(Current, "CANFOCUS", boolean_to_yesno(state))
  142. end
  143. get_count: INTEGER
  144. -- (read-only) (non inheritable): returns the number of items. Before
  145. -- mapping it counts the number of non NULL items before the first NULL
  146. -- item.
  147. local
  148. str: STRING
  149. do
  150. str := iup_open.get_attribute(Current, "COUNT")
  151. if str.is_integer then
  152. Result := str.to_integer
  153. end
  154. end
  155. set_drag_drop_list (state: BOOLEAN)
  156. -- (non inheritable): enable or disable the drag and drop of items
  157. -- between lists, in the same IUP application. Drag & Drop attributes
  158. -- must be set in order to activate the drag & drop support. On the other
  159. -- hand, it is not necessary to register drag & drop callbacks.
  160. -- Default: False.
  161. do
  162. iup_open.set_attribute(Current, "DRAGDROPLIST", boolean_to_yesno(state))
  163. end
  164. set_drop_files_target (state: BOOLEAN)
  165. -- [Windows and GTK Only] (non inheritable): Enable or disable the drop
  166. -- of files. Default: NO, but if DROPFILES_CB is defined when the element
  167. -- is mapped then it will be automatically enabled.
  168. do
  169. iup_open.set_attribute(Current, "DROPFILESTARGET", boolean_to_yesno(state))
  170. end
  171. set_drop_down (state: BOOLEAN)
  172. -- (creation only): Changes the appearance of the list for the user: only
  173. -- the selected item is shown beside a button with the image of an arrow
  174. -- pointing down. To select another option, the user must press this
  175. -- button, which displays all items in the list. Can be "True" or "False".
  176. -- Default "False".
  177. do
  178. iup_open.set_attribute(Current, "DROPDOWN", boolean_to_yesno(state))
  179. end
  180. set_drop_expand (state: BOOLEAN)
  181. -- [Windows Only]: When DROPDOWN=Yes the size of the dropped list will
  182. -- expand to include the largest text. Can be "YES" or "NO".
  183. -- Default: "True".
  184. do
  185. iup_open.set_attribute(Current, "DROPEXPAND", boolean_to_yesno(state))
  186. end
  187. set_edit_box (state: BOOLEAN)
  188. -- (creation only): Adds an edit box to the list. Can be "True" or
  189. -- "False". Default "False".
  190. do
  191. iup_open.set_attribute(Current, "EDITBOX", boolean_to_yesno(state))
  192. end
  193. set_image_at (imagename: STRING; position: INTEGER)
  194. -- (non inheritable) (write only) [Windows and GTK Only]: image name to
  195. -- be used in the specified item, where position is the specified item
  196. -- starting at 1. The item must already exist. Use set_widget_name
  197. -- to associate an image to a name. See also IupImage. The image is
  198. -- always displayed at the left of the text and only when SHOWIMAGE=Yes.
  199. -- When EDITBOX=Yes the image is not display at the edit box. Images
  200. -- don't need to have the same size. In Windows, list items are limited
  201. -- to 255 pixels height.
  202. require
  203. position > 0
  204. local
  205. str: STRING
  206. do
  207. str := "IMAGE" + position.out
  208. iup_open.set_attribute(Current, str, imagename)
  209. end
  210. set_multiple (state: BOOLEAN)
  211. -- (creation only): Allows selecting several items simultaneously
  212. -- (multiple list). Default: "False". Only valid when EDITBOX=False and
  213. -- DROPDOWN=False.
  214. do
  215. iup_open.set_attribute(Current, "MULTIPLE", boolean_to_yesno(state))
  216. end
  217. set_scroll_bar (state: BOOLEAN)
  218. -- (creation only): Associates automatic scrollbars to the list when
  219. -- DROPDOWN=False. Can be: "True" or "False" (none). Default: "True". For
  220. -- all systems, when SCROLLBAR=True the natural size will always include
  221. -- its size even if the native system hides the scrollbars. If
  222. -- AUTOHIDE=True scrollbars are shown only if they are necessary, by
  223. -- default AUTOHIDE=True. In Motif, SCROLLBAR=False is not supported and
  224. -- if EDITBOX=True the horizontal scrollbar is never shown.
  225. --
  226. -- When DROPDOWN=True the scrollbars are system dependent, and do NOT
  227. -- depend on the SCROLLBAR or AUTOHIDE attributes. Usually the scrollbars
  228. -- are shown if necessary. In GTK, scrollbars are never shown and all
  229. -- items are always visible. In Motif, the horizontal scrollbar is never
  230. -- shown. In Windows, if DROPEXPAND=True then the horizontal scrollbar is
  231. -- never shown.
  232. do
  233. iup_open.set_attribute(Current, "SCROLLBAR", boolean_to_yesno(state))
  234. end
  235. set_show_drag_drop (state: BOOLEAN)
  236. -- (creation only) (non inheritable): enables the internal drag and drop
  237. -- of items, and enables the DRAGDROP_CB callback. Default: "False".
  238. -- Works only if DROPDOWN=False and MULTIPLE=False.ç
  239. do
  240. iup_open.set_attribute(Current, "SHOWDRAGDROP", boolean_to_yesno(state))
  241. end
  242. set_show_drop_down (state: BOOLEAN)
  243. -- (write-only): opens or closes the dropdown list. Can be "True" or
  244. -- "False". Valid only when DROPDOWN=True. Ignored if set before map.
  245. do
  246. iup_open.set_attribute(Current, "SHOWDROPDOWN", boolean_to_yesno(state))
  247. end
  248. set_show_image (state: BOOLEAN)
  249. -- (creation only) [Windows and GTK Only]: enables the use of an image
  250. -- for each item. Can be "True" or "False". Ignored if set before map.
  251. do
  252. iup_open.set_attribute(Current, "SHOWIMAGE", boolean_to_yesno(state))
  253. end
  254. set_sort (state: BOOLEAN)
  255. -- (creation only): force the list to be alphabetically sorted. When
  256. -- using insert_item or append_item the position will be ignored.
  257. do
  258. iup_open.set_attribute(Current, "SORT", boolean_to_yesno(state))
  259. end
  260. set_top_item (item: STRING)
  261. -- (write-only): position the given item at the top of the list or near
  262. -- to make it visible. Valid only when DROPDOWN=False.
  263. do
  264. iup_open.set_attribute(Current, "TOPITEM", item)
  265. end
  266. set_spacing (value: INTEGER)
  267. -- internal padding for each item. Notice that vertically the distance
  268. -- between each item will be actually 2x the spacing. It also affects the
  269. -- horizontal margin of the item. In Windows, the text is aligned at the
  270. -- top left of the item always. Valid only when DROPDOWN=False.
  271. do
  272. Precursor (value)
  273. end
  274. set_value (value: STRING)
  275. -- (non inheritable): Depends on the DROPDOWN+EDITBOX
  276. -- combination:
  277. --
  278. -- EDITBOX=True: Text entered by the user.
  279. -- DROPDOWN=True or MULTIPLE=False: Integer number representing the
  280. -- selected item in the list (begins at 1). It can be zero if there is no
  281. -- selected item. The value can be Void for no item selected (In Motif
  282. -- when DROPDOWN=True there is always an item selected, except only when
  283. -- the list is empty).
  284. -- MULTIPLE=True: Sequence of '+' and '-' symbols indicating the state of
  285. -- each item. When setting this value, the user must provide the same
  286. -- amount of '+' and '-' symbols as the amount of items in the list,
  287. -- otherwise the specified items will be deselected.
  288. --
  289. -- Observations: always returns a non Void value, event if the list is
  290. -- empty or the text box is empty. It can be an empty string when no
  291. -- item selected.
  292. do
  293. iup_open.set_attribute(Current, "VALUE", value)
  294. end
  295. get_value: STRING
  296. -- Return the selected value. See set_value.
  297. do
  298. Result := iup_open.get_attribute(Current, "VALUE")
  299. end
  300. set_value_string (value: STRING)
  301. -- Search for the first item with the same string and select it.
  302. -- Works only when EDITBOX=False and DROPDOWN=True and MULTIPLE=False.
  303. do
  304. iup_open.set_attribute(Current, "VALUESTRING", value)
  305. end
  306. get_value_string (position: INTEGER): STRING
  307. -- Return the selected item.
  308. -- Works only when EDITBOX=False and DROPDOWN=True and MULTIPLE=False.
  309. do
  310. Result := iup_open.get_attribute(Current, "VALUESTRING")
  311. end
  312. set_value_masked (value: STRING)
  313. -- (non inheritable) (write-only): sets VALUE but first checks if it is
  314. -- validated by MASK. If not does nothing. Works only when EDITBOX=True.
  315. do
  316. iup_open.set_attribute(Current, "VALUEMASKED", value)
  317. end
  318. set_visible_items (value: INTEGER)
  319. -- [Windows and Motif Only]: Number of items that are visible when
  320. -- DROPDOWN=True is used for the dropdown list. Default: 5.
  321. require
  322. value > 0
  323. do
  324. iup_open.set_attribute(Current, "VISIBLEITEMS", value.out)
  325. end
  326. set_visible_columns (value: INTEGER)
  327. -- Defines the number of visible columns for the Natural Size, this means
  328. -- that will act also as minimum number of visible columns. It uses a
  329. -- wider character size then the one used for the SIZE attribute so
  330. -- strings will fit better without the need of extra columns. Set this
  331. -- attribute to speed Natural Size computation for very large lists.
  332. require
  333. value > 0
  334. do
  335. iup_open.set_attribute(Current, "VISIBLECOLUMNS", value.out)
  336. end
  337. set_visible_lines (value: INTEGER)
  338. -- When DROPDOWN=False defines the number of visible lines for the
  339. -- Natural Size, this means that will act also as minimum number of
  340. -- visible lines.
  341. require
  342. value > 0
  343. do
  344. iup_open.set_attribute(Current, "VISIBLELINES", value.out)
  345. end
  346. -- SCROLLTO, SCROLLTOPOS: Skip since don't have sense here.
  347. -- Operations
  348. add_item_at (item: STRING; position: INTEGER)
  349. -- Add an item. If "position" is between the first and the last item, the
  350. -- current item is replaced. The effect is the same as removing the old
  351. -- item and inserting a new one at the old position.
  352. -- If "position=COUNT+1" then it is appended after the last item.
  353. require
  354. position > 0
  355. do
  356. iup_open.set_attribute(Current, position.out, item)
  357. end
  358. append_item (item: STRING)
  359. -- (write-only): inserts an item after the last item. Ignored if set
  360. -- before map.
  361. do
  362. iup_open.set_attribute(Current, "APPENDITEM", item)
  363. end
  364. insert_item_at (item: STRING; position: INTEGER)
  365. -- (write-only): inserts an item before the given position. position
  366. -- starts at 1. If position=COUNT+1 then it will append after the last
  367. -- item. Ignored if out of bounds. Ignored if set before map.
  368. require
  369. position > 0
  370. do
  371. iup_open.set_attribute_id(Current, "INSERTITEM", position, item)
  372. end
  373. remove_item_at (position: INTEGER)
  374. -- (write-only): removes the given position. position starts at 1.
  375. -- Ignored if set before map.
  376. do
  377. iup_open.set_attribute(Current, "REMOVEITEM", position.out)
  378. end
  379. remove_all
  380. -- Removes all the items.
  381. do
  382. iup_open.set_attribute(Current, "REMOVEITEM", "ALL")
  383. end
  384. -- Coordination to pos
  385. convert_xt_to_pos (x, y: INTEGER): INTEGER
  386. -- Converts a (x,y) coordinate in an item position.
  387. -- Returns: the position starting at 1. If fails returns -1.
  388. do
  389. Result := iup_open.iup_convert_xy_to_pos (Current, x, y)
  390. end
  391. -- Callbacks
  392. -- Common
  393. set_cb_map (act: detachable FUNCTION[TUPLE[IUP_LIST], STRING])
  394. -- Called right after an element is mapped and its attributes updated.
  395. local
  396. operation: INTEGER
  397. do
  398. cb_map := act
  399. if cb_map /= Void then
  400. operation := 1
  401. else
  402. operation := 0
  403. end
  404. iup_open.set_callback (Current, "MAP_CB", "NONEEDED", operation)
  405. end
  406. set_cb_unmap (act: detachable FUNCTION[TUPLE[IUP_LIST], STRING])
  407. -- Called right before an element is unmapped.
  408. local
  409. operation: INTEGER
  410. do
  411. cb_unmap := act
  412. if cb_unmap /= Void then
  413. operation := 1
  414. else
  415. operation := 0
  416. end
  417. iup_open.set_callback (Current, "UNMAP_CB", "NONEEDED", operation)
  418. end
  419. set_cb_destroy (act: detachable FUNCTION[TUPLE[IUP_LIST], STRING])
  420. -- Called right before an element is destroyed.
  421. local
  422. operation: INTEGER
  423. do
  424. cb_destroy := act
  425. if cb_destroy /= Void then
  426. operation := 1
  427. else
  428. operation := 0
  429. end
  430. iup_open.set_callback (Current, "DESTROY_CB", "NONEEDED", operation)
  431. end
  432. set_cb_get_focus (act: detachable FUNCTION[TUPLE[IUP_LIST], STRING])
  433. -- Action generated when an element is given keyboard focus.
  434. -- This callback is called after the KILLFOCUS_CB of the element
  435. -- that loosed the focus. The {IUP}.get_focus function during the
  436. -- callback returns the element that loosed the focus.
  437. local
  438. operation: INTEGER
  439. do
  440. cb_getfocus := act
  441. if cb_getfocus /= Void then
  442. operation := 1
  443. else
  444. operation := 0
  445. end
  446. iup_open.set_callback (Current, "GETFOCUS_CB", "NONEEDED", operation)
  447. end
  448. set_cb_kill_focus (act: detachable FUNCTION[TUPLE[IUP_LIST], STRING])
  449. -- Action generated when an element loses keyboard focus. This
  450. -- callback is called before the GETFOCUS_CB of the element that
  451. -- gets the focus.
  452. local
  453. operation: INTEGER
  454. do
  455. cb_killfocus := act
  456. if cb_killfocus /= Void then
  457. operation := 1
  458. else
  459. operation := 0
  460. end
  461. iup_open.set_callback (Current, "KILLFOCUS_CB", "NONEEDED", operation)
  462. end
  463. set_cb_enter_window (act: detachable FUNCTION[TUPLE[IUP_LIST], STRING])
  464. -- Action generated when the mouse enters the native element.
  465. local
  466. operation: INTEGER
  467. do
  468. cb_enterwindow := act
  469. if cb_enterwindow /= Void then
  470. operation := 1
  471. else
  472. operation := 0
  473. end
  474. iup_open.set_callback (Current, "ENTERWINDOW_CB", "NONEEDED", operation)
  475. end
  476. set_cb_leave_window (act: detachable FUNCTION[TUPLE[IUP_LIST], STRING])
  477. -- Action generated when the mouse leaves the native element.
  478. local
  479. operation: INTEGER
  480. do
  481. cb_leavewindow := act
  482. if cb_leavewindow /= Void then
  483. operation := 1
  484. else
  485. operation := 0
  486. end
  487. iup_open.set_callback (Current, "LEAVEWINDOW_CB", "NONEEDED", operation)
  488. end
  489. set_cb_k_any (act: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER], STRING])
  490. -- Action generated when a keyboard event occurs.
  491. -- IUP_WIDGET the element that activated the event.
  492. -- INTEGER identifier of typed key. Please refer to the Keyboard
  493. -- Codes table for a list of possible values.
  494. --
  495. -- Returns: If IUP_IGNORE is returned the key is ignored and not
  496. -- processed by the control and not propagated. If returns
  497. -- IUP_CONTINUE, the key will be processed and the event will be
  498. -- propagated to the parent of the element receiving it, this is
  499. -- the default behavior. If returns IUP_DEFAULT the key is processed
  500. -- but it is not propagated. IUP_CLOSE will be processed.
  501. local
  502. operation: INTEGER
  503. do
  504. cb_k_any := act
  505. if cb_k_any /= Void then
  506. operation := 1
  507. else
  508. operation := 0
  509. end
  510. iup_open.set_callback (Current, "K_ANY", "NONEEDED", operation)
  511. end
  512. set_cb_help (act: detachable PROCEDURE[TUPLE[IUP_LIST]])
  513. -- Action generated when the user press F1 at a control. In Motif
  514. -- is also activated by the Help button in some workstations
  515. -- keyboard.
  516. -- Returns: IUP_CLOSE will be processed.
  517. local
  518. operation: INTEGER
  519. do
  520. cb_help := act
  521. if cb_help /= Void then
  522. operation := 1
  523. else
  524. operation := 0
  525. end
  526. iup_open.set_callback (Current, "HELP_CB", "NONEEDED", operation)
  527. end
  528. -- Extra
  529. set_cb_action (act: detachable FUNCTION[TUPLE[IUP_LIST, STRING, INTEGER, INTEGER], STRING])
  530. -- Action generated when the state of an item in the list is changed.
  531. -- Also provides information on the changed item:
  532. -- ih: identifier of the element that activated the event.
  533. -- text: Text of the changed item.
  534. -- item: Number of the changed item starting at 1.
  535. -- state: Equal to 1 if the option was selected or to 0 if the option was
  536. -- deselected.
  537. --
  538. -- The state=0 is simulated internally by IUP in all systems. If you add
  539. -- or remove items to/from the list and you count on the state=0 value,
  540. -- then after adding/removing items set the VALUE attribute to ensure
  541. -- proper state=0 value.
  542. local
  543. operation: INTEGER
  544. do
  545. cb_action := act
  546. if cb_action /= Void then
  547. operation := 1
  548. else
  549. operation := 0
  550. end
  551. iup_open.set_callback (Current, "ACTION", "Fnsii", operation)
  552. end
  553. set_cb_button (act: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING])
  554. -- Action generated when any mouse button is pressed and when it is
  555. -- released. Both calls occur before the ACTION callback when button 1 is
  556. -- being used.
  557. --
  558. -- IUP_BUTTON: identifies the element that activated the event.
  559. -- button: identifies the activated mouse button:
  560. --
  561. -- 1 - left mouse button (button 1);
  562. -- 2 - middle mouse button (button 2);
  563. -- 3 - right mouse button (button 3).
  564. --
  565. -- pressed: indicates the state of the button:
  566. --
  567. -- 0 - mouse button was released;
  568. -- 1 - mouse button was pressed.
  569. --
  570. -- x, y: position in the canvas where the event has occurred, in pixels.
  571. --
  572. -- status: status of the mouse buttons and some keyboard keys at the
  573. -- moment the event is generated. The following IUP features must be used
  574. -- for verification:
  575. --
  576. -- is_shift(status)
  577. -- is_control(status)
  578. -- is_button_1(status)
  579. -- is_button_2(status)
  580. -- is_button_3(status)
  581. -- is_button_4(status)
  582. -- is_button_5(status)
  583. -- is_double(status)
  584. -- is_alt(status)
  585. -- is_sys(status)
  586. --
  587. -- Returns: IUP_CLOSE will be processed. On some controls if IUP_IGNORE
  588. -- is returned the action is ignored (this is system dependent).
  589. local
  590. operation: INTEGER
  591. do
  592. cb_button := act
  593. if cb_button /= Void then
  594. operation := 1
  595. else
  596. operation := 0
  597. end
  598. iup_open.set_callback (Current, "BUTTON_CB", "NONEEDED", operation)
  599. end
  600. set_cb_caret (act: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER, INTEGER, INTEGER], STRING])
  601. -- Action generated when the caret/cursor position is changed. Valid
  602. -- only when EDITBOX=True.
  603. --
  604. -- ih: identifier of the element that activated the event.
  605. -- lin, col: line and column number (start at 1).
  606. -- pos: 0 based character position.
  607. --
  608. -- For lists lin is always 1, and pos is always "col-1".
  609. local
  610. operation: INTEGER
  611. do
  612. cb_caret := act
  613. if cb_caret /= Void then
  614. operation := 1
  615. else
  616. operation := 0
  617. end
  618. iup_open.set_callback (Current, "CARET_CB", "NONEEDED", operation)
  619. end
  620. set_cb_double_click (act: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER, STRING], STRING])
  621. -- Action generated when the user double click an item. Called only when
  622. -- DROPDOWN=False.
  623. -- ih: identifier of the element that activated the event.
  624. -- item: Number of the selected item starting at 1.
  625. -- text: Text of the selected item.
  626. local
  627. operation: INTEGER
  628. do
  629. cb_dblclick := act
  630. if cb_dblclick /= Void then
  631. operation := 1
  632. else
  633. operation := 0
  634. end
  635. iup_open.set_callback (Current, "DBLCLICK_CB", "NONEEDED", operation)
  636. end
  637. set_cb_drag_drop (act: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER, INTEGER, INTEGER, INTEGER], STRING])
  638. -- Action generated when an internal drag and drop is executed. Only
  639. -- active if SHOWDRAGDROP=True.
  640. --
  641. -- ih: identifier of the element that activated the event.
  642. -- drag_id: Identifier of the clicked item where the drag start.
  643. -- drop_id: Identifier of the clicked item where the drop were executed.
  644. -- -1 indicates a drop in a blank area.
  645. -- isshift: flag indicating the shift key state.
  646. -- iscontrol: flag indicating the control key state.
  647. --
  648. -- Returns: if returns IUP_CONTINUE, or if the callback is not defined
  649. -- and SHOWDRAGDROP=True, then the item is moved to the new position. If
  650. -- Ctrl is pressed then the item is copied instead of moved.
  651. local
  652. operation: INTEGER
  653. do
  654. cb_dragdrop := act
  655. if cb_dragdrop /= Void then
  656. operation := 1
  657. else
  658. operation := 0
  659. end
  660. iup_open.set_callback (Current, "DRAGDROP_CB", "NONEEDED", operation)
  661. end
  662. set_cb_drop_down (act: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER], STRING])
  663. -- Action generated when the list of a dropdown is shown or hidden.
  664. -- Called only when DROPDOWN=True.
  665. -- ih: identifier of the element that activated the event.
  666. -- state: state of the list 1=shown, 0=hidden.
  667. local
  668. operation: INTEGER
  669. do
  670. cb_dropdown := act
  671. if cb_dropdown /= Void then
  672. operation := 1
  673. else
  674. operation := 0
  675. end
  676. iup_open.set_callback (Current, "DROPDOWN_CB", "NONEEDED", operation)
  677. end
  678. set_cb_drop_files (act: detachable FUNCTION[TUPLE[IUP_LIST, STRING, INTEGER, INTEGER, INTEGER], STRING])
  679. -- Action called when a file is "dropped" into the control. When several
  680. -- files are dropped at once, the callback is called several times, once
  681. -- for each file.
  682. --
  683. -- If defined after the element is mapped then the attribute
  684. -- DROPFILESTARGET must be set to True. [Windows and GTK Only]
  685. --
  686. -- ih: identifier of the element that activated the event.
  687. -- filename: Name of the dropped file.
  688. -- num: Number index of the dropped file. If several files are dropped,
  689. -- num is the index of the dropped file starting from "total-1" to "0".
  690. -- x: X coordinate of the point where the user released the mouse button.
  691. -- y: Y coordinate of the point where the user released the mouse button.
  692. --
  693. -- Returns: If IUP_IGNORE is returned the callback will NOT be called for
  694. -- the next dropped files, and the processing of dropped files will be
  695. -- interrupted.
  696. local
  697. operation: INTEGER
  698. do
  699. cb_dropfiles := act
  700. if cb_dropfiles /= Void then
  701. operation := 1
  702. else
  703. operation := 0
  704. end
  705. iup_open.set_callback (Current, "DROPFILES_CB", "NONEEDED", operation)
  706. end
  707. set_cb_edit (act: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER, STRING], STRING])
  708. -- Action generated when the text in the text box is manually changed by
  709. -- the user, but before its value is actually updated. Valid only when
  710. -- EDITBOX=True.
  711. --
  712. -- ih: identifier of the element that activated the event.
  713. -- c: valid alphanumeric character or 0.
  714. -- new_value: Represents the new text value.
  715. --
  716. -- Returns: IUP_CLOSE will be processed, but the change will be ignored.
  717. -- If IUP_IGNORE, the system will ignore the new value. If c is valid and
  718. -- returns a valid alpha numeric character, this new character will be
  719. -- used instead. The VALUE attribute can be changed only if IUP_IGNORE is
  720. -- returned.
  721. local
  722. operation: INTEGER
  723. do
  724. cb_edit := act
  725. if cb_edit /= Void then
  726. operation := 1
  727. else
  728. operation := 0
  729. end
  730. iup_open.set_callback (Current, "EDIT_CB", "NONEEDED", operation)
  731. end
  732. set_cb_motion (act: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER, INTEGER, STRING], STRING])
  733. -- Action generated when the mouse moves.
  734. -- ih: identifier of the element that activated the event.
  735. -- x, y: position in the canvas where the event has occurred, in pixels.
  736. -- status: status of mouse buttons and certain keyboard keys at the
  737. -- moment the event was generated. The same macros used for BUTTON_CB can
  738. -- be used for this status.
  739. local
  740. operation: INTEGER
  741. do
  742. cb_motion := act
  743. if cb_motion /= Void then
  744. operation := 1
  745. else
  746. operation := 0
  747. end
  748. iup_open.set_callback (Current, "MOTION_CB", "NONEEDED", operation)
  749. end
  750. set_cb_multi_select (act: detachable FUNCTION[TUPLE[IUP_LIST, STRING], STRING])
  751. -- Action generated when the state of an item in the multiple selection
  752. -- list is changed. But it is called only when the interaction is
  753. -- over.
  754. --
  755. -- ih: identifier of the element that activated the event.
  756. -- value: Similar to the VALUE attribute for a multiple selection list.
  757. -- Items selected are marked with '+', items deselected are marked with
  758. -- '-', and non changed items are marked with an 'x'.
  759. --
  760. -- This callback is called only when MULTIPLE=True. If this callback is
  761. -- defined the CHANGE callback will not be called.
  762. --
  763. -- The non changed items marked with 'x' are simulated internally by IUP
  764. -- in all systems. If you add or remove items to/from the list and you
  765. -- count on the 'x' values, then after adding/removing items set the
  766. -- VALUE attribute to ensure proper 'x' values.
  767. local
  768. operation: INTEGER
  769. do
  770. cb_multiselect := act
  771. if cb_multiselect /= Void then
  772. operation := 1
  773. else
  774. operation := 0
  775. end
  776. iup_open.set_callback (Current, "MULTISELECT_CB", "NONEEDED", operation)
  777. end
  778. set_cb_value_changed (act: detachable FUNCTION[TUPLE[IUP_LIST], STRING])
  779. -- Called after the value was interactively changed by the user.
  780. local
  781. operation: INTEGER
  782. do
  783. cb_valuechanged := act
  784. if cb_valuechanged /= Void then
  785. operation := 1
  786. else
  787. operation := 0
  788. end
  789. iup_open.set_callback (Current, "VALUECHANGED_CB", "NONEEDED", operation)
  790. end
  791. feature {IUP}
  792. execute_map: STRING
  793. do
  794. if attached cb_map as int_cb then
  795. Result := int_cb.item([Current])
  796. else
  797. Result := "IUP_DEFAULT"
  798. end
  799. end
  800. execute_unmap: STRING
  801. do
  802. if attached cb_unmap as int_cb then
  803. Result := int_cb.item([Current])
  804. else
  805. Result := "IUP_DEFAULT"
  806. end
  807. end
  808. execute_destroy: STRING
  809. do
  810. if attached cb_destroy as int_cb then
  811. Result := int_cb.item([Current])
  812. else
  813. Result := "IUP_DEFAULT"
  814. end
  815. end
  816. execute_getfocus: STRING
  817. do
  818. if attached cb_getfocus as int_cb then
  819. Result := int_cb.item([Current])
  820. else
  821. Result := "IUP_DEFAULT"
  822. end
  823. end
  824. execute_killfocus: STRING
  825. do
  826. if attached cb_killfocus as int_cb then
  827. Result := int_cb.item([Current])
  828. else
  829. Result := "IUP_DEFAULT"
  830. end
  831. end
  832. execute_enterwindow: STRING
  833. do
  834. if attached cb_enterwindow as int_cb then
  835. Result := int_cb.item([Current])
  836. else
  837. Result := "IUP_DEFAULT"
  838. end
  839. end
  840. execute_leavewindow: STRING
  841. do
  842. if attached cb_leavewindow as int_cb then
  843. Result := int_cb.item([Current])
  844. else
  845. Result := "IUP_DEFAULT"
  846. end
  847. end
  848. execute_k_any (c: INTEGER): STRING
  849. do
  850. if attached cb_k_any as int_cb then
  851. Result := int_cb.item([Current, c])
  852. else
  853. Result := "IUP_DEFAULT"
  854. end
  855. end
  856. execute_help
  857. do
  858. if attached cb_help as int_cb then
  859. int_cb.call([Current])
  860. end
  861. end
  862. execute_action_fnsii (text: STRING; item, state: INTEGER): STRING
  863. do
  864. if attached cb_action as int_cb then
  865. Result := int_cb.item([Current, text, item, state])
  866. else
  867. Result := "IUP_DEFAULT"
  868. end
  869. end
  870. execute_button (btn, pressed, x, y: INTEGER; status: STRING): STRING
  871. do
  872. if attached cb_button as int_cb then
  873. Result := int_cb.item([Current, btn, pressed, x, y, status])
  874. else
  875. Result := "IUP_DEFAULT"
  876. end
  877. end
  878. execute_caret (lin, col, pos: INTEGER): STRING
  879. do
  880. if attached cb_caret as int_cb then
  881. Result := int_cb.item([Current, lin, col, pos])
  882. else
  883. Result := "IUP_DEFAULT"
  884. end
  885. end
  886. execute_dblclick (item: INTEGER; text: STRING): STRING
  887. do
  888. if attached cb_dblclick as int_cb then
  889. Result := int_cb.item([Current, item, text])
  890. else
  891. Result := "IUP_DEFAULT"
  892. end
  893. end
  894. execute_dragdrop (drag_id, drop_id, isshift, iscontrol: INTEGER): STRING
  895. do
  896. if attached cb_dragdrop as int_cb then
  897. Result := int_cb.item([Current, drag_id, drop_id, isshift, iscontrol])
  898. else
  899. Result := "IUP_DEFAULT"
  900. end
  901. end
  902. execute_dropdown (state: INTEGER): STRING
  903. do
  904. if attached cb_dropdown as int_cb then
  905. Result := int_cb.item([Current, state])
  906. else
  907. Result := "IUP_DEFAULT"
  908. end
  909. end
  910. execute_dropfiles (filename: STRING; num: INTEGER; x: INTEGER; y: INTEGER): STRING
  911. do
  912. if attached cb_dropfiles as int_cb then
  913. Result := int_cb.item([Current, filename, num, x, y])
  914. else
  915. Result := "IUP_DEFAULT"
  916. end
  917. end
  918. execute_edit (c: INTEGER; new_value: STRING): STRING
  919. do
  920. if attached cb_edit as int_cb then
  921. Result := int_cb.item([Current, c, new_value])
  922. else
  923. Result := "IUP_DEFAULT"
  924. end
  925. end
  926. execute_motion (x, y: INTEGER; status: STRING): STRING
  927. do
  928. if attached cb_motion as int_cb then
  929. Result := int_cb.item([Current, x, y, status])
  930. else
  931. Result := "IUP_DEFAULT"
  932. end
  933. end
  934. execute_multiselect (value: STRING): STRING
  935. do
  936. if attached cb_multiselect as int_cb then
  937. Result := int_cb.item([Current, value])
  938. else
  939. Result := "IUP_DEFAULT"
  940. end
  941. end
  942. execute_valuechanged: STRING
  943. do
  944. if attached cb_valuechanged as int_cb then
  945. Result := int_cb.item([Current])
  946. else
  947. Result := "IUP_DEFAULT"
  948. end
  949. end
  950. feature {NONE}
  951. -- For callbacks
  952. cb_map: detachable FUNCTION[TUPLE[IUP_LIST], STRING]
  953. cb_unmap: detachable FUNCTION[TUPLE[IUP_LIST], STRING]
  954. cb_destroy: detachable FUNCTION[TUPLE[IUP_LIST], STRING]
  955. cb_getfocus: detachable FUNCTION[TUPLE[IUP_LIST], STRING]
  956. cb_killfocus: detachable FUNCTION[TUPLE[IUP_LIST], STRING]
  957. cb_enterwindow: detachable FUNCTION[TUPLE[IUP_LIST], STRING]
  958. cb_leavewindow: detachable FUNCTION[TUPLE[IUP_LIST], STRING]
  959. cb_k_any: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER], STRING]
  960. cb_help: detachable PROCEDURE[TUPLE[IUP_LIST]]
  961. cb_action: detachable FUNCTION[TUPLE[IUP_LIST, STRING, INTEGER, INTEGER], STRING]
  962. cb_button: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING]
  963. cb_caret: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER, INTEGER, INTEGER], STRING]
  964. cb_dblclick: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER, STRING], STRING]
  965. cb_dragdrop: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER, INTEGER, INTEGER, INTEGER], STRING]
  966. cb_dropdown: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER], STRING]
  967. cb_dropfiles: detachable FUNCTION[TUPLE[IUP_LIST, STRING, INTEGER, INTEGER, INTEGER], STRING]
  968. cb_edit: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER, STRING], STRING]
  969. cb_motion: detachable FUNCTION[TUPLE[IUP_LIST, INTEGER, INTEGER, STRING], STRING]
  970. cb_multiselect: detachable FUNCTION[TUPLE[IUP_LIST, STRING], STRING]
  971. cb_valuechanged: detachable FUNCTION[TUPLE[IUP_LIST], STRING]
  972. -- Internals
  973. int_list (wgt: POINTER): POINTER
  974. external
  975. "C inline use %"eiffel-iup.h%""
  976. alias
  977. "return IupList ($wgt);"
  978. end
  979. end
  980. -- The MIT License (MIT)
  981. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  982. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  983. -- of this software and associated documentation files (the "Software"), to deal
  984. -- in the Software without restriction, including without limitation the rights
  985. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  986. -- copies of the Software, and to permit persons to whom the Software is
  987. -- furnished to do so, subject to the following conditions:
  988. --
  989. -- The above copyright notice and this permission notice shall be included in
  990. -- all copies or substantial portions of the Software.
  991. --
  992. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  993. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  994. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  995. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  996. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  997. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  998. -- SOFTWARE.