iup_list.e 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  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_TEXT_CARET
  86. IUP_TEXT_COMMON
  87. IUP_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_attribute_handle
  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.to_string
  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.to_string)
  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.to_string)
  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.to_string)
  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.to_string, 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.to_string)
  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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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. Result := cb_map.item([Current])
  795. end
  796. execute_unmap: STRING
  797. do
  798. Result := cb_unmap.item([Current])
  799. end
  800. execute_destroy: STRING
  801. do
  802. Result := cb_destroy.item([Current])
  803. end
  804. execute_getfocus: STRING
  805. do
  806. Result := cb_getfocus.item([Current])
  807. end
  808. execute_killfocus: STRING
  809. do
  810. Result := cb_getfocus.item([Current])
  811. end
  812. execute_enterwindow: STRING
  813. do
  814. Result := cb_enterwindow.item([Current])
  815. end
  816. execute_leavewindow: STRING
  817. do
  818. Result := cb_leavewindow.item([Current])
  819. end
  820. execute_k_any (c: INTEGER): STRING
  821. do
  822. Result := cb_k_any.item([Current, c])
  823. end
  824. execute_help
  825. do
  826. cb_help.call([Current])
  827. end
  828. execute_action_fnsii (text: STRING; item, state: INTEGER): STRING
  829. do
  830. Result := cb_action.item([Current, text, item, state])
  831. end
  832. execute_button (btn, pressed, x, y: INTEGER; status: STRING): STRING
  833. do
  834. Result := cb_button.item([Current, btn, pressed, x, y, status])
  835. end
  836. execute_caret (lin, col, pos: INTEGER): STRING
  837. do
  838. Result := cb_caret.item([Current, lin, col, pos])
  839. end
  840. execute_dblclick (item: INTEGER; text: STRING): STRING
  841. do
  842. Result := cb_dblclick.item([Current, item, text])
  843. end
  844. execute_dragdrop (drag_id, drop_id, isshift, iscontrol: INTEGER): STRING
  845. do
  846. Result := cb_dragdrop.item([Current, drag_id, drop_id, isshift, iscontrol])
  847. end
  848. execute_dropdown (state: INTEGER): STRING
  849. do
  850. Result := cb_dropdown.item([Current, state])
  851. end
  852. execute_dropfiles (filename: STRING; num: INTEGER; x: INTEGER; y: INTEGER): STRING
  853. do
  854. Result := cb_dropfiles.item([Current, filename, num, x, y])
  855. end
  856. execute_edit (c: INTEGER; new_value: STRING): STRING
  857. do
  858. Result := cb_edit.item([Current, c, new_value])
  859. end
  860. execute_motion (x, y: INTEGER; status: STRING): STRING
  861. do
  862. Result := cb_motion.item([Current, x, y, status])
  863. end
  864. execute_multiselect (value: STRING): STRING
  865. do
  866. Result := cb_multiselect.item([Current, value])
  867. end
  868. execute_valuechanged: STRING
  869. do
  870. Result := cb_valuechanged.item([Current])
  871. end
  872. feature {}
  873. -- For callbacks
  874. cb_map: FUNCTION[TUPLE[IUP_LIST], STRING]
  875. cb_unmap: FUNCTION[TUPLE[IUP_LIST], STRING]
  876. cb_destroy: FUNCTION[TUPLE[IUP_LIST], STRING]
  877. cb_getfocus: FUNCTION[TUPLE[IUP_LIST], STRING]
  878. cb_killfocus: FUNCTION[TUPLE[IUP_LIST], STRING]
  879. cb_enterwindow: FUNCTION[TUPLE[IUP_LIST], STRING]
  880. cb_leavewindow: FUNCTION[TUPLE[IUP_LIST], STRING]
  881. cb_k_any: FUNCTION[TUPLE[IUP_LIST, INTEGER], STRING]
  882. cb_help: PROCEDURE[TUPLE[IUP_LIST]]
  883. cb_action: FUNCTION[TUPLE[IUP_LIST, STRING, INTEGER, INTEGER], STRING]
  884. cb_button: FUNCTION[TUPLE[IUP_LIST, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING]
  885. cb_caret: FUNCTION[TUPLE[IUP_LIST, INTEGER, INTEGER, INTEGER], STRING]
  886. cb_dblclick: FUNCTION[TUPLE[IUP_LIST, INTEGER, STRING], STRING]
  887. cb_dragdrop: FUNCTION[TUPLE[IUP_LIST, INTEGER, INTEGER, INTEGER, INTEGER], STRING]
  888. cb_dropdown: FUNCTION[TUPLE[IUP_LIST, INTEGER], STRING]
  889. cb_dropfiles: FUNCTION[TUPLE[IUP_LIST, STRING, INTEGER, INTEGER, INTEGER], STRING]
  890. cb_edit: FUNCTION[TUPLE[IUP_LIST, INTEGER, STRING], STRING]
  891. cb_motion: FUNCTION[TUPLE[IUP_LIST, INTEGER, INTEGER, STRING], STRING]
  892. cb_multiselect: FUNCTION[TUPLE[IUP_LIST, STRING], STRING]
  893. cb_valuechanged: FUNCTION[TUPLE[IUP_LIST], STRING]
  894. -- Internals
  895. int_list (wgt: POINTER): POINTER
  896. external "plug_in"
  897. alias "{
  898. location: "${sys}/plugins"
  899. module_name: "iup"
  900. feature_name: "IupList"
  901. }"
  902. end
  903. end
  904. -- The MIT License (MIT)
  905. -- Copyright (c) 2016, 2017 by German A. Arias
  906. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  907. -- of this software and associated documentation files (the "Software"), to deal
  908. -- in the Software without restriction, including without limitation the rights
  909. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  910. -- copies of the Software, and to permit persons to whom the Software is
  911. -- furnished to do so, subject to the following conditions:
  912. --
  913. -- The above copyright notice and this permission notice shall be included in
  914. -- all copies or substantial portions of the Software.
  915. --
  916. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  917. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  918. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  919. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  920. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  921. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  922. -- SOFTWARE.