iup_expander.e 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. class IUP_EXPANDER
  2. -- Creates a void container that can interactively show or hide its
  3. -- child.
  4. inherit
  5. IUP_CONTAINER
  6. redefine
  7. execute_action,
  8. execute_openclose,
  9. execute_extrabutton
  10. end
  11. IUP_WIDGET_EXPAND
  12. IUP_WIDGET_TITLE
  13. IUP_WIDGET_WID
  14. IUP_WIDGET_FONT
  15. IUP_WIDGET_SIZE
  16. IUP_WIDGET_RASTERSIZE
  17. IUP_WIDGET_USERSIZE
  18. IUP_WIDGET_CLIENTSIZE
  19. IUP_WIDGET_CLIENTOFFSET
  20. IUP_WIDGET_POSITION
  21. IUP_WIDGET_MAXMIN_SIZE
  22. IUP_WIDGET_CHILD
  23. IUP_WIDGET_NAME
  24. IUP_WIDGET_CUSTOM_ATTRIBUTES
  25. create {ANY}
  26. expander_empty,
  27. expander
  28. feature {ANY}
  29. expander_empty
  30. -- Create an empty expander.
  31. local
  32. p, a_expander: POINTER
  33. do
  34. a_expander := int_expander (p)
  35. set_widget(a_expander)
  36. end
  37. expander (child: IUP_WIDGET)
  38. -- Create a new expander containing the widget.
  39. local
  40. a_expander: POINTER
  41. do
  42. a_expander := int_expander (child.widget)
  43. set_widget(a_expander)
  44. end
  45. -- Commands to handle attributes
  46. set_autoshow (state: BOOLEAN)
  47. -- (non inheritable): enables the automatic show of the child when mouse
  48. -- is over the handler for more than 1 second. Default: No.
  49. do
  50. iup_open.set_attribute(Current, "AUTOSHOW", boolean_to_yesno(state))
  51. end
  52. is_autoshow: BOOLEAN
  53. -- Return the state of the autoshow.
  54. local
  55. str: STRING
  56. do
  57. str := iup_open.get_attribute(Current, "AUTOSHOW")
  58. Result := yesno_to_boolean(str)
  59. end
  60. set_animation (value: STRING)
  61. -- (non inheritable): enable animation during open/close. Works only for
  62. -- BARPOSITION=TOP and does not works for AUTOSHOW. Also the child must
  63. -- be a native container like IUP_TABS, IUP_FRAME, IUP_BACKGROUNBOX, or
  64. -- IUP_SCROLLBOX, or it will not work accordantly. Values can be SLIDE
  65. -- (child controls slide down), CURTAIN (child controls appears as if a
  66. -- curtain is being pulled) or NO. Default: NO.
  67. require
  68. is_valid_animation(value)
  69. do
  70. iup_open.set_attribute(Current, "ANIMATION", value)
  71. end
  72. get_animation: STRING
  73. -- Return the type of animation.
  74. do
  75. Result := iup_open.get_attribute(Current, "ANIMATION")
  76. end
  77. set_number_of_frames (num: INTEGER)
  78. -- Control the number of frames used for the animation, the default value
  79. -- is 10 frames.
  80. require
  81. non_negative: num >= 0
  82. do
  83. iup_open.set_attribute(Current, "NUMFRAMES", num.out)
  84. end
  85. get_number_of_frames: INTEGER
  86. -- Return the number of frames for the animation.
  87. local
  88. num: STRING
  89. do
  90. num := iup_open.get_attribute(Current, "NUMFRAMES")
  91. Result := num.to_integer
  92. end
  93. set_frame_time (time: INTEGER)
  94. -- Time between frames, the default value is 30ms (milliseconds). If the
  95. -- dialog has lots of controls and its layout computation takes longer
  96. -- than FRAMETIME, then a frame is lost, but the total animation time
  97. -- (numframes*frametime) is always the same.
  98. require
  99. non_negative: time >= 0
  100. do
  101. iup_open.set_attribute(Current, "FRAMETIME", time.out)
  102. end
  103. get_frame_time: INTEGER
  104. -- Return the frame time.
  105. local
  106. time: STRING
  107. do
  108. time := iup_open.get_attribute(Current, "FRAMETIME")
  109. Result := time.to_integer
  110. end
  111. set_rgb_back_color (red, green, blue: INTEGER)
  112. -- (non inheritable): background color of the bar handler. If not defined
  113. -- it will use the background color of the native parent.
  114. do
  115. iup_open.set_attribute(Current, "BACKCOLOR", rgb_to_string(red, green, blue))
  116. end
  117. get_rgb_back_color: TUPLE[INTEGER, INTEGER, INTEGER]
  118. -- Return the RGB values of the back color.
  119. do
  120. Result := iup_open.get_rgb(Current, "BACKCOLOR")
  121. end
  122. set_bar_position (value: STRING)
  123. -- (creation only): indicates the bar handler position. Possible values
  124. -- are "TOP", "BOTTOM", "LEFT" or "RIGHT". Default: "TOP".
  125. require
  126. is_valid_barposition(value)
  127. do
  128. iup_open.set_attribute(Current, "BARPOSITION", value)
  129. end
  130. get_bar_position: STRING
  131. -- Return the bar position.
  132. do
  133. Result := iup_open.get_attribute(Current, "BARPOSITION")
  134. end
  135. set_bar_size (size: INTEGER)
  136. -- (non inheritable): controls the size of the bar handler. Default: the
  137. -- height or width that fits all its internal elements according to
  138. -- BARPOSITION.
  139. require
  140. non_negative: size >= 0
  141. do
  142. iup_open.set_attribute(Current, "BARSIZE", size.out)
  143. end
  144. get_bar_size: INTEGER
  145. -- Return the bar size.
  146. local
  147. size: STRING
  148. do
  149. size := iup_open.get_attribute(Current, "BARSIZE")
  150. Result := size.to_integer
  151. end
  152. set_extra_buttons (n: INTEGER)
  153. -- (non inheritable) (creation only): sets the number of extra image
  154. -- buttons at right when BARPOSITION=TOP. The maximum number of buttons
  155. -- is 3. See the EXTRABUTTON_CB callback. Default: 0.
  156. require
  157. n >= 0
  158. n <= 3
  159. do
  160. iup_open.set_attribute(Current, "EXTRABUTTONS", n.out)
  161. end
  162. get_extra_buttons: INTEGER
  163. -- Return the number of extrabuttons.
  164. local
  165. n: STRING
  166. do
  167. n := iup_open.get_attribute(Current, "EXTRABUTTONS")
  168. Result := n.to_integer
  169. end
  170. set_extra_button_id_image (imagename: STRING; id: INTEGER)
  171. -- Set the image name used for the button. id can be 1, 2 or 3. 1 is the
  172. -- rightmost button, and count from right to left.
  173. require
  174. id >= 0
  175. id <= 3
  176. local
  177. str: STRING
  178. do
  179. str := "IMAGEEXTRA" + id.out
  180. iup_open.set_attribute(Current, str, imagename)
  181. end
  182. get_extra_button_id_image (id: INTEGER): STRING
  183. -- Return the name for the image at button number id.
  184. require
  185. id >= 0
  186. id <= 3
  187. local
  188. str: STRING
  189. do
  190. str := "IMAGEEXTRA" + id.out
  191. Result := iup_open.get_attribute(Current, str)
  192. end
  193. set_extra_button_id_image_press (imagename: STRING; id: INTEGER)
  194. -- Set the image name used for the button when pressed. id can be 1, 2
  195. -- or 3. 1 is the rightmost button, and count from right to left.
  196. require
  197. id >= 0
  198. id <= 3
  199. local
  200. str: STRING
  201. do
  202. str := "IMAGEEXTRAPRESS" + id.out
  203. iup_open.set_attribute(Current, str, imagename)
  204. end
  205. get_extra_button_id_image_press (id: INTEGER): STRING
  206. -- Return the name for the image at button number id when pressed.
  207. require
  208. id >= 0
  209. id <= 3
  210. local
  211. str: STRING
  212. do
  213. str := "IMAGEEXTRAPRESS" + id.out
  214. Result := iup_open.get_attribute(Current, str)
  215. end
  216. set_extra_button_id_image_highlight (imagename: STRING; id: INTEGER)
  217. -- Set the image name for the button used when mouse is over the button
  218. -- area. id can be 1, 2 or 3. 1 is the rightmost button, and count from
  219. -- right to left.
  220. require
  221. id >= 0
  222. id <= 3
  223. local
  224. str: STRING
  225. do
  226. str := "IMAGEEXTRAHIGHLIGHT" + id.out
  227. iup_open.set_attribute(Current, str, imagename)
  228. end
  229. get_extra_button_id_image_highlight (id: INTEGER): STRING
  230. -- Return the image name for the button number id, used when mouse is
  231. -- over the button area.
  232. require
  233. id >= 0
  234. id <= 3
  235. local
  236. str: STRING
  237. do
  238. str := "IMAGEEXTRAHIGHLIGHT" + id.out
  239. Result := iup_open.get_attribute(Current, str)
  240. end
  241. set_rgb_fore_color (red, green, blue: INTEGER)
  242. -- (non inheritable): title text color. Default: the global attribute
  243. -- DLGFGCOLOR.
  244. do
  245. iup_open.set_attribute(Current, "FORECOLOR", rgb_to_string(red, green, blue))
  246. end
  247. get_rgb_fore_color: TUPLE[INTEGER, INTEGER, INTEGER]
  248. -- Return the RGB values of the fore color.
  249. do
  250. Result := iup_open.get_rgb(Current, "FORECOLOR")
  251. end
  252. set_rgb_open_color (red, green, blue: INTEGER)
  253. -- (non inheritable): title text color when STATE=OPEN. Defaults to the
  254. -- FORECOLOR if not defined.
  255. do
  256. iup_open.set_attribute(Current, "OPENCOLOR", rgb_to_string(red, green, blue))
  257. end
  258. get_rgb_open_color: TUPLE[INTEGER, INTEGER, INTEGER]
  259. -- Return the RGB values of the open color.
  260. do
  261. Result := iup_open.get_rgb(Current, "OPENCOLOR")
  262. end
  263. set_rgb_high_color (red, green, blue: INTEGER)
  264. -- (non inheritable): title text color when highlighted. Works only when
  265. -- TITLEEXPAND=Yes. Defaults to the FORECOLOR if not defined.
  266. do
  267. iup_open.set_attribute(Current, "HIGHCOLOR", rgb_to_string(red, green, blue))
  268. end
  269. get_rgb_high_color: TUPLE[INTEGER, INTEGER, INTEGER]
  270. -- Return the RGB values of the high color.
  271. do
  272. Result := iup_open.get_rgb(Current, "HIGHCOLOR")
  273. end
  274. set_image (imagename: STRING)
  275. -- (non inheritable): image name to replace the arrow image by a custom
  276. -- image when STATE=CLOSE. Works only when BARPOSITION=TOP. Use
  277. -- set_widget_name to associate an image to a name. See also
  278. -- IUP_IMAGE.
  279. do
  280. iup_open.set_attribute(Current, "IMAGE", imagename)
  281. end
  282. get_image: STRING
  283. -- Return the name of the image when STATE=CLOSE.
  284. do
  285. Result := iup_open.get_attribute(Current, "IMAGE")
  286. end
  287. set_image_open (imagename: STRING)
  288. -- Set the image name used when STATE=OPEN.
  289. do
  290. iup_open.set_attribute(Current, "IMAGEOPEN", imagename)
  291. end
  292. get_image_open: STRING
  293. -- Return the image name used when STATE=OPEN.
  294. do
  295. Result := iup_open.get_attribute(Current, "IMAGEOPEN")
  296. end
  297. set_image_highlight (imagename: STRING)
  298. -- Set image name used when mouse is over the bar handler and STATE=CLOSE.
  299. do
  300. iup_open.set_attribute(Current, "IMAGEHIGHLIGHT", imagename)
  301. end
  302. get_image_highlight: STRING
  303. -- Return the image name used when mouse is over the bar handler and
  304. -- STATE=CLOSE.
  305. do
  306. Result := iup_open.get_attribute(Current, "IMAGEHIGHLIGHT")
  307. end
  308. set_image_open_highlight (imagename: STRING)
  309. -- Set the image name used when mouse is over the bar handler and
  310. -- STATE=OPEN.
  311. do
  312. iup_open.set_attribute(Current, "IMAGEOPENHIGHLIGHT", imagename)
  313. end
  314. get_image_open_highlight: STRING
  315. -- Return the image name used when mouse is over the bar handler and
  316. -- STATE=OPEN.
  317. do
  318. Result := iup_open.get_attribute(Current, "IMAGEOPENHIGHLIGHT")
  319. end
  320. set_expanded
  321. -- Show the container elements.
  322. -- Setting this attribute will automatically change the layout of the
  323. -- entire dialog so the child can be recomposed.
  324. do
  325. iup_open.set_attribute(Current, "STATE", "OPEN")
  326. end
  327. set_collapsed
  328. -- Hide the container elements.
  329. -- Setting this attribute will automatically change the layout of the
  330. -- entire dialog so the child can be recomposed.
  331. do
  332. iup_open.set_attribute(Current, "STATE", "CLOSE")
  333. end
  334. is_expanded: BOOLEAN
  335. -- Return True if expanded.
  336. local
  337. str: STRING
  338. do
  339. str := iup_open.get_attribute(Current, "STATE")
  340. if str.is_equal("OPEN") then
  341. Result := True
  342. else
  343. Result := False
  344. end
  345. end
  346. set_state_refresh (state: BOOLEAN)
  347. -- (non inheritable): when state is changed "refresh" is automatically
  348. -- called. Default: "True".
  349. do
  350. iup_open.set_attribute(Current, "STATEREFRESH", boolean_to_yesno(state))
  351. end
  352. is_state_refresh: BOOLEAN
  353. -- Return the value of staterefresh.
  354. local
  355. str: STRING
  356. do
  357. str := iup_open.get_attribute(Current, "STATEREFRESH")
  358. Result := yesno_to_boolean(str)
  359. end
  360. set_title_image (imagename: STRING)
  361. -- (non inheritable): title image, shown in the bar handler near the
  362. -- expand/collapse button. When set it will reset TITLE (image and text
  363. -- title are mutually exclusive). Shown only when BARPOSITION=TOP.
  364. do
  365. iup_open.set_attribute(Current, "TITLEIMAGE", imagename)
  366. end
  367. get_title_image: STRING
  368. -- Return the name of the title image.
  369. do
  370. Result := iup_open.get_attribute(Current, "TITLEIMAGE")
  371. end
  372. set_title_image_open (imagename: STRING)
  373. -- Set the title image name used when STATE=OPEN.
  374. do
  375. iup_open.set_attribute(Current, "TITLEIMAGEOPEN", imagename)
  376. end
  377. get_title_image_open: STRING
  378. -- Return the title image name used when STATE=OPEN.
  379. do
  380. Result := iup_open.get_attribute(Current, "TITLEIMAGEOPEN")
  381. end
  382. set_title_image_highlight (imagename: STRING)
  383. -- Set image name used when mouse is over the title image and STATE=CLOSE.
  384. do
  385. iup_open.set_attribute(Current, "TITLEIMAGEHIGHLIGHT", imagename)
  386. end
  387. get_title_image_highlight: STRING
  388. -- Return the image name used when mouse is over the title image and
  389. -- STATE=CLOSE.
  390. do
  391. Result := iup_open.get_attribute(Current, "TITLEIMAGEHIGHLIGHT")
  392. end
  393. set_title_image_open_highlight (imagename: STRING)
  394. -- Set the image name used when mouse is over the title image and
  395. -- STATE=OPEN.
  396. do
  397. iup_open.set_attribute(Current, "TITLEIMAGEOPENHIGHLIGHT", imagename)
  398. end
  399. get_title_image_open_highlight: STRING
  400. -- Return the image name used when mouse is over the title image and
  401. -- STATE=OPEN.
  402. do
  403. Result := iup_open.get_attribute(Current, "TITLEIMAGEOPENHIGHLIGHT")
  404. end
  405. set_title_expand (state: BOOLEAN)
  406. -- (non inheritable): enable the expand/collapse action also at the
  407. -- tile. Default: False.
  408. do
  409. iup_open.set_attribute(Current, "TITLEEXPAND", boolean_to_yesno(state))
  410. end
  411. is_title_expand: BOOLEAN
  412. -- Return the value of TITLEEXPAND.
  413. local
  414. str: STRING
  415. do
  416. str := iup_open.get_attribute(Current, "TITLEEXPAND")
  417. Result := yesno_to_boolean(str)
  418. end
  419. -- Callbacks
  420. -- Common
  421. set_cb_action (act: detachable FUNCTION[TUPLE[IUP_EXPANDER], STRING])
  422. -- Action generated when the element is activated. Affects each
  423. -- element differently.
  424. local
  425. operation: INTEGER
  426. do
  427. cb_action := act
  428. if cb_action /= Void then
  429. operation := 1
  430. else
  431. operation := 0
  432. end
  433. iup_open.set_callback (Current, "ACTION", "Fn", operation)
  434. end
  435. -- Extra
  436. set_cb_open_close (act: detachable FUNCTION[TUPLE[IUP_EXPANDER, INTEGER], STRING])
  437. -- Action generated before the expander state is interactively
  438. -- changed.
  439. -- ih: identifier of the element that activated the event.
  440. -- state: new state to be applied.
  441. --
  442. -- Returns: if return IUP_IGNORE the new state is ignored.
  443. local
  444. operation: INTEGER
  445. do
  446. cb_openclose := act
  447. if cb_openclose /= Void then
  448. operation := 1
  449. else
  450. operation := 0
  451. end
  452. iup_open.set_callback (Current, "OPENCLOSE_CB", "NONEEDED", operation)
  453. end
  454. set_cb_extra_button (act: detachable FUNCTION[TUPLE[IUP_EXPANDER, INTEGER, INTEGER], STRING])
  455. -- Action generated when any mouse button is pressed or
  456. -- released.
  457. -- ih: identifies the element that activated the event.
  458. -- button: identifies the extra button. can be 1, 2 or 3. (this is not
  459. -- the same as BUTTON_CB)
  460. -- pressed: indicates the state of the button:
  461. -- 0 - mouse button was released;
  462. -- 1 - mouse button was pressed.
  463. local
  464. operation: INTEGER
  465. do
  466. cb_extrabutton := act
  467. if cb_extrabutton /= Void then
  468. operation := 1
  469. else
  470. operation := 0
  471. end
  472. iup_open.set_callback (Current, "EXTRABUTTON_CB", "NONEEDED", operation)
  473. end
  474. -- Validations
  475. is_valid_animation (value: STRING): BOOLEAN
  476. do
  477. if value.is_equal("SLIDE") or
  478. value.is_equal("CURTAIN") or
  479. value.is_equal("NO") then
  480. Result := True
  481. else
  482. Result := False
  483. end
  484. end
  485. is_valid_barposition (value: STRING): BOOLEAN
  486. do
  487. if value.is_equal("TOP") or
  488. value.is_equal("BOTTOM") or
  489. value.is_equal("LEFT") or
  490. value.is_equal("RIGHT") then
  491. Result := True
  492. else
  493. Result := False
  494. end
  495. end
  496. feature {IUP}
  497. -- Internal handle of callbacks
  498. execute_action: STRING
  499. do
  500. if attached cb_action as int_cb then
  501. Result := int_cb.item([Current])
  502. else
  503. Result := "IUP_DEFAULT"
  504. end
  505. end
  506. execute_openclose (state: INTEGER): STRING
  507. do
  508. if attached cb_openclose as int_cb then
  509. Result := int_cb.item([Current, state])
  510. else
  511. Result := "IUP_DEFAULT"
  512. end
  513. end
  514. execute_extrabutton (button, pressed: INTEGER): STRING
  515. do
  516. if attached cb_extrabutton as int_cb then
  517. Result := int_cb.item([Current, button, pressed])
  518. else
  519. Result := "IUP_DEFAULT"
  520. end
  521. end
  522. feature {NONE}
  523. -- For callbacks
  524. cb_action: detachable FUNCTION[TUPLE[IUP_EXPANDER], STRING]
  525. cb_openclose: detachable FUNCTION[TUPLE[IUP_EXPANDER, INTEGER], STRING]
  526. cb_extrabutton: detachable FUNCTION[TUPLE[IUP_EXPANDER, INTEGER, INTEGER], STRING]
  527. -- Internals
  528. int_expander (child: POINTER): POINTER
  529. external
  530. "C inline use %"eiffel-iup.h%""
  531. alias
  532. "return IupExpander ($child);"
  533. end
  534. end
  535. -- The MIT License (MIT)
  536. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  537. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  538. -- of this software and associated documentation files (the "Software"), to deal
  539. -- in the Software without restriction, including without limitation the rights
  540. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  541. -- copies of the Software, and to permit persons to whom the Software is
  542. -- furnished to do so, subject to the following conditions:
  543. --
  544. -- The above copyright notice and this permission notice shall be included in
  545. -- all copies or substantial portions of the Software.
  546. --
  547. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  548. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  549. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  550. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  551. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  552. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  553. -- SOFTWARE.