iup_grid_box.e 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. class IUP_GRID_BOX
  2. -- Creates a void container for composing elements in a regular grid. It is a
  3. -- box that arranges the elements it contains from top to bottom and from left
  4. -- to right, but can distribute the elements in lines or in columns.
  5. --
  6. -- The child elements are added to the control just like a vbox and hbox,
  7. -- sequentially. Then they are distributed accordingly the attributes
  8. -- ORIENTATION and NUMDIV. When ORIENTATION=HORIZONTAL children are distributed
  9. -- from left to right on the first line until NUMDIV, then on the second line,
  10. -- and so on. When ORIENTATION=VERTICAL children are distributed from top to
  11. -- bottom on the first column until NUMDIV, then on the second column, and so
  12. -- on. The number of lines and the number of columns can be easily obtained
  13. -- from the combination of these attributes.
  14. --
  15. -- Notice that the total number of spaces can be larger than the number of
  16. -- actual children, the last line or column can be incomplete.
  17. --
  18. -- The column sizes will be based only on the width of the children of the
  19. -- reference line, usually line 0. The line sizes will be based only on the
  20. -- height of the children of the reference column, usually column 0.
  21. inherit
  22. IUP_CONTAINER
  23. IUP_WIDGET_EXPAND
  24. IUP_WIDGET_WID
  25. IUP_WIDGET_SIZE
  26. IUP_WIDGET_RASTERSIZE
  27. IUP_WIDGET_USERSIZE
  28. IUP_WIDGET_FONT
  29. IUP_WIDGET_CLIENTSIZE
  30. IUP_WIDGET_CLIENTOFFSET
  31. IUP_WIDGET_POSITION
  32. IUP_WIDGET_MAXMIN_SIZE
  33. IUP_WIDGET_CHILD
  34. IUP_WIDGET_NAME
  35. IUP_WIDGET_CUSTOM_ATTRIBUTES
  36. IUP_WIDGET_NORMALIZE_SIZE
  37. redefine
  38. set_normalize_size
  39. end
  40. create {ANY}
  41. grid_box_empty,
  42. grid_box
  43. feature {ANY}
  44. grid_box_empty
  45. -- Create an empty grid box.
  46. local
  47. p, a_grid_box: POINTER
  48. do
  49. a_grid_box := int_grid_box_empty (p)
  50. set_widget(a_grid_box)
  51. end
  52. grid_box (col: ARRAY[IUP_WIDGET])
  53. -- Create a new grid box containing the list of widgets.
  54. local
  55. i: INTEGER; arg: ARRAY[POINTER]; s: IUP_WIDGET; a_grid_box: POINTER
  56. do
  57. i := col.count
  58. create arg.make_filled(default_pointer, 1, i + 1)
  59. i := 0
  60. across
  61. col as ic
  62. loop
  63. i := i + 1
  64. s := ic.item
  65. arg.put(s.widget, i)
  66. end
  67. a_grid_box := int_grid_box (get_pointer(arg.to_c))
  68. set_widget(a_grid_box)
  69. end
  70. -- Commands to handle attributes.
  71. set_alignment_line (value: STRING)
  72. -- Vertically aligns the elements within each line. Possible values:
  73. -- "ATOP", "ACENTER", "ABOTTOM". Default: "ATOP".
  74. -- (non inheritable)
  75. require
  76. valid_lin: is_valid_alignment_lin(value)
  77. do
  78. iup_open.set_attribute(Current, "ALIGNMENTLIN", value)
  79. end
  80. get_alignment_line: STRING
  81. -- Return the vertical align of the elements within each line.
  82. do
  83. Result := iup_open.get_attribute(Current, "ALIGNMENTLIN")
  84. end
  85. set_alignment_for_line (value: STRING; line: INTEGER)
  86. -- Set the alignment of a single line.
  87. require
  88. valid_lin: is_valid_alignment_lin(value)
  89. line >= 0
  90. local
  91. str: STRING
  92. do
  93. str := "ALIGNMENTLIN" + line.out
  94. iup_open.set_attribute(Current, str, value)
  95. end
  96. get_alignment_for_line (line: INTEGER): STRING
  97. -- Return the alignment used at the line.
  98. require
  99. line >= 0
  100. local
  101. str: STRING
  102. do
  103. str := "ALIGNMENTLIN" + line.out
  104. Result := iup_open.get_attribute(Current, str)
  105. end
  106. set_alignment_column (value: STRING)
  107. -- Horizontally aligns the elements within each column. Possible values:
  108. -- "ALEFT", "ACENTER", "ARIGHT". Default: "ALEFT".
  109. -- (non inheritable)
  110. require
  111. valid_col: is_valid_alignment_col(value)
  112. do
  113. iup_open.set_attribute(Current, "ALIGNMENTCOL", value)
  114. end
  115. get_alignment_column: STRING
  116. -- Return the horizontal align of the elements within each line.
  117. do
  118. Result := iup_open.get_attribute(Current, "ALIGNMENTCOL")
  119. end
  120. set_alignment_for_column (value: STRING; col: INTEGER)
  121. -- Set the alignment of a single column.
  122. require
  123. valid_col: is_valid_alignment_col(value)
  124. col >= 0
  125. local
  126. str: STRING
  127. do
  128. str := "ALIGNMENTCOL" + col.out
  129. iup_open.set_attribute(Current, str, value)
  130. end
  131. get_alignment_for_column (col: INTEGER): STRING
  132. -- Return the alignment used at the column.
  133. require
  134. col >= 0
  135. local
  136. str: STRING
  137. do
  138. str := "ALIGNMENTCOL" + col.out
  139. Result := iup_open.get_attribute(Current, str)
  140. end
  141. set_expand_children (value: STRING)
  142. -- Forces all children to expand in the given direction and to fully
  143. -- occupy its space available inside the box. Can be YES (both
  144. -- directions), HORIZONTAL, VERTICAL or NO. Default: "NO". This has the
  145. -- same effect as setting EXPAND on each child.
  146. -- (non inheritable).
  147. require
  148. valid_expand_children: is_valid_expand_children(value)
  149. do
  150. iup_open.set_attribute(Current, "EXPANDCHILDREN", value)
  151. end
  152. get_expand_children: STRING
  153. -- Return the value of the used expand children.
  154. do
  155. Result := iup_open.get_attribute(Current, "EXPANDCHILDREN")
  156. end
  157. set_fit_to_children_at_line (line: INTEGER)
  158. -- (write-only) Set the RASTERSIZE attribute of the reference element in
  159. -- the given line, so that it will fit the highest element in the line.
  160. -- Can only be set after the layout of the dialog has been calculated at
  161. -- least 1 time. If FITMAXWIDTHn or FITMAXHEIGHTn are set for the line
  162. -- they are used as maximum limit for the size.
  163. require
  164. line > 0
  165. local
  166. str: STRING
  167. do
  168. str := "L" + line.out
  169. iup_open.set_attribute(Current, "FITTOCHILDREN", str)
  170. end
  171. set_fit_to_children_at_column (column: INTEGER)
  172. -- (write-only) Set the RASTERSIZE attribute of the reference element in
  173. -- the given column, so that it will fit the largest element in the
  174. -- column. Can only be set after the layout of the dialog has been
  175. -- calculated at least 1 time. If FITMAXWIDTHn or FITMAXHEIGHTn are set
  176. -- for the column they are used as maximum limit for the size.
  177. require
  178. column > 0
  179. local
  180. str: STRING
  181. do
  182. str := "C" + column.out
  183. iup_open.set_attribute(Current, "FITTOCHILDREN", str)
  184. end
  185. set_gaplin (space: INTEGER)
  186. -- Defines a vertical space in pixels between lines. Default: "0".
  187. require
  188. space >= 0
  189. do
  190. iup_open.set_attribute(Current, "GAPLIN", space.out)
  191. end
  192. get_gaplin: INTEGER
  193. -- Return the vertical space between lines.
  194. local
  195. value: STRING
  196. do
  197. value := iup_open.get_attribute(Current, "GAPLIN")
  198. Result := value.to_integer
  199. end
  200. set_cgaplin (space: INTEGER)
  201. -- Defines a vertical space between lines in the same units of the SIZE
  202. -- attribute for the height. Default: "0".
  203. require
  204. space >= 0
  205. do
  206. iup_open.set_attribute(Current, "CGAPLIN", space.out)
  207. end
  208. get_cgaplin: INTEGER
  209. -- Return the value of the attribute cgaplin.
  210. local
  211. value: STRING
  212. do
  213. value := iup_open.get_attribute(Current, "CGAPLIN")
  214. Result := value.to_integer
  215. end
  216. set_gapcol (space: INTEGER)
  217. -- Defines an horizontal space in pixels between columns. Default: "0".
  218. require
  219. space >= 0
  220. do
  221. iup_open.set_attribute(Current, "GAPCOL", space.out)
  222. end
  223. get_gapcol: INTEGER
  224. -- Return the horizontal space between columns.
  225. local
  226. value: STRING
  227. do
  228. value := iup_open.get_attribute(Current, "GAPCOL")
  229. Result := value.to_integer
  230. end
  231. set_cgapcol (space: INTEGER)
  232. -- Defines an horizontal space between columns in the same units of the
  233. -- SIZE attribute for the height. Default: "0".
  234. require
  235. space >= 0
  236. do
  237. iup_open.set_attribute(Current, "CGAPCOL", space.out)
  238. end
  239. get_cgapcol: INTEGER
  240. -- Return the value of the attribute cgapcol.
  241. local
  242. value: STRING
  243. do
  244. value := iup_open.get_attribute(Current, "CGAPCOL")
  245. Result := value.to_integer
  246. end
  247. set_ngaplin (space: INTEGER)
  248. -- Same as *GAPLIN* but non inheritable.
  249. require
  250. space >= 0
  251. do
  252. iup_open.set_attribute(Current, "NGAPLIN", space.out)
  253. end
  254. get_ngaplin: INTEGER
  255. -- Return the value of *NGAPLIN* attribute.
  256. local
  257. value: STRING
  258. do
  259. value := iup_open.get_attribute(Current, "NGAPLIN")
  260. Result := value.to_integer
  261. end
  262. set_ncgaplin (space: INTEGER)
  263. -- Same as *CGAPLIN* but non inheritable.
  264. require
  265. space >= 0
  266. do
  267. iup_open.set_attribute(Current, "NCGAPLIN", space.out)
  268. end
  269. get_ncgaplin: INTEGER
  270. -- Return the value of *NCGAPLIN* attribute.
  271. local
  272. value: STRING
  273. do
  274. value := iup_open.get_attribute(Current, "NCGAPLIN")
  275. Result := value.to_integer
  276. end
  277. set_ngapcol (space: INTEGER)
  278. -- Same as *GAPCOL* but non inheritable.
  279. require
  280. space >= 0
  281. do
  282. iup_open.set_attribute(Current, "NGAPCOL", space.out)
  283. end
  284. get_ngapcol: INTEGER
  285. -- Return the value of *NGAPCOL* attribute.
  286. local
  287. value: STRING
  288. do
  289. value := iup_open.get_attribute(Current, "NGAPCOL")
  290. Result := value.to_integer
  291. end
  292. set_ncgapcol (space: INTEGER)
  293. -- Same as *CGAPCOL* but non inheritable.
  294. require
  295. space >= 0
  296. do
  297. iup_open.set_attribute(Current, "NCGAPCOL", space.out)
  298. end
  299. get_ncgapcol: INTEGER
  300. -- Return the value of *NCGAPCOL* attribute.
  301. local
  302. value: STRING
  303. do
  304. value := iup_open.get_attribute(Current, "NCGAPCOL")
  305. Result := value.to_integer
  306. end
  307. set_homogeneous_lines (state: BOOLEAN)
  308. -- (non inheritable): forces all lines to have the same vertical space,
  309. -- or height. The line height will be based on the highest child of the
  310. -- reference column (See set_sizecol). Default: "NO". Notice that this
  311. -- does not changes the children size, only the available space for each
  312. -- one of them to expand.
  313. do
  314. iup_open.set_attribute(Current, "HOMOGENEOUSLIN", boolean_to_yesno(state))
  315. end
  316. is_homogeneous_lines: BOOLEAN
  317. -- Return the state of homogeneouslin.
  318. local
  319. str: STRING
  320. do
  321. str := iup_open.get_attribute(Current, "HOMOGENEOUSLIN")
  322. Result := yesno_to_boolean(str)
  323. end
  324. set_homogeneous_columns (state: BOOLEAN)
  325. -- (non inheritable): forces all columns to have the same horizontal
  326. -- space, or width. The column width will be based on the largest child
  327. -- of the reference line (See set_sizelin). Default: "NO". Notice that
  328. -- this does not changes the children size, only the available space for
  329. -- each one of them to expand.
  330. do
  331. iup_open.set_attribute(Current, "HOMOGENEOUSCOL", boolean_to_yesno(state))
  332. end
  333. is_homogeneous_columns: BOOLEAN
  334. -- Return the state of homogeneouscol.
  335. local
  336. str: STRING
  337. do
  338. str := iup_open.get_attribute(Current, "HOMOGENEOUSCOL")
  339. Result := yesno_to_boolean(str)
  340. end
  341. set_margin (horizontal, vertical: INTEGER)
  342. -- Defines a margin in pixels. Default: "0x0" (no margin).
  343. require
  344. horizontal >= 0
  345. vertical >= 0
  346. local
  347. margin: STRING
  348. do
  349. margin := horizontal.out
  350. margin.append_string("x")
  351. margin.append_string(vertical.out)
  352. iup_open.set_attribute(Current, "MARGIN", margin)
  353. end
  354. get_margin: TUPLE[INTEGER, INTEGER]
  355. -- Return the value of the margins.
  356. local
  357. margin: STRING
  358. do
  359. margin := iup_open.get_attribute(Current, "MARGIN")
  360. Result := components_of_size(margin)
  361. end
  362. set_cmargin (horizontal, vertical: INTEGER)
  363. -- Defines a margin in the same units of the SIZE attribute.
  364. -- Default: "0x0" (no margin).
  365. require
  366. horizontal >= 0
  367. vertical >= 0
  368. local
  369. margin: STRING
  370. do
  371. margin := horizontal.out
  372. margin.append_string("x")
  373. margin.append_string(vertical.out)
  374. iup_open.set_attribute(Current, "CMARGIN", margin)
  375. end
  376. get_cmargin: TUPLE[INTEGER, INTEGER]
  377. -- Return the value of the CMARGIN.
  378. local
  379. margin: STRING
  380. do
  381. margin := iup_open.get_attribute(Current, "CMARGIN")
  382. Result := components_of_size(margin)
  383. end
  384. set_nmargin (horizontal, vertical: INTEGER)
  385. -- (non inheritable): Same as MARGIN but are non inheritable.
  386. require
  387. horizontal >= 0
  388. vertical >= 0
  389. local
  390. margin: STRING
  391. do
  392. margin := horizontal.out
  393. margin.append_string("x")
  394. margin.append_string(vertical.out)
  395. iup_open.set_attribute(Current, "NMARGIN", margin)
  396. end
  397. get_nmargin: TUPLE[INTEGER, INTEGER]
  398. -- Return the value of the nmargin.
  399. local
  400. margin: STRING
  401. do
  402. margin := iup_open.get_attribute(Current, "NMARGIN")
  403. Result := components_of_size(margin)
  404. end
  405. set_ncmargin (horizontal, vertical: INTEGER)
  406. -- (non inheritable): Same as CMARGIN but are non inheritable.
  407. require
  408. horizontal >= 0
  409. vertical >= 0
  410. local
  411. margin: STRING
  412. do
  413. margin := horizontal.out
  414. margin.append_string("x")
  415. margin.append_string(vertical.out)
  416. iup_open.set_attribute(Current, "NCMARGIN", margin)
  417. end
  418. get_ncmargin: TUPLE[INTEGER, INTEGER]
  419. -- Return the value of NCMARGIN.
  420. local
  421. margin: STRING
  422. do
  423. margin := iup_open.get_attribute(Current, "NCMARGIN")
  424. Result := components_of_size(margin)
  425. end
  426. set_numdiv (num: INTEGER)
  427. -- Controls the number of divisions along the distribution according to
  428. -- ORIENTATION. When ORIENTATION=HORIZONTAL, NUMDIV is the number of
  429. -- columns, when ORIENTATION=VERTICAL, NUMDIV is the number of lines.
  430. -- When value is 0, its actual value will be calculated to fit the
  431. -- maximum number of elements in the orientation direction. Default: 0.
  432. require
  433. num >= 0
  434. local
  435. str: STRING
  436. do
  437. if num.is_equal(0) then
  438. str := "AUTO"
  439. else
  440. str := num.out
  441. end
  442. iup_open.set_attribute(Current, "NUMDIV", str)
  443. end
  444. get_numdiv: INTEGER
  445. -- Return the number of divisions.
  446. local
  447. str: STRING
  448. do
  449. str := iup_open.get_attribute(Current, "NUMDIV")
  450. if str.is_equal("AUTO") then
  451. Result := 0
  452. else
  453. Result := str.to_integer
  454. end
  455. end
  456. get_lines: INTEGER
  457. -- (read-only): returns the number of lines.
  458. local
  459. str: STRING
  460. do
  461. str := iup_open.get_attribute(Current, "NUMLIN")
  462. Result := str.to_integer
  463. end
  464. get_columns: INTEGER
  465. -- (read-only): returns the number of columns.
  466. local
  467. str: STRING
  468. do
  469. str := iup_open.get_attribute(Current, "NUMCOL")
  470. Result := str.to_integer
  471. end
  472. set_normalize_size (value: STRING)
  473. -- (non inheritable): normalizes all children natural size to be the
  474. -- biggest natural size among the reference line and/or the reference
  475. -- column. All natural width will be set to the biggest width, and all
  476. -- natural height will be set to the biggest height according to is
  477. -- value. Can be NO, HORIZONTAL (width only), VERTICAL (height only) or
  478. -- BOTH. Default: "NO". Same as using IUP_NORMALIZER. Notice that this is
  479. -- different from the HOMOGENEOUS* attributes in the sense that the
  480. -- children will have their sizes changed.
  481. do
  482. Precursor (value)
  483. end
  484. set_horizontal_orientation
  485. -- (non inheritable): controls the distribution of the children in
  486. -- columns. This is the default value.
  487. do
  488. iup_open.set_attribute(Current, "ORIENTATION", "HORIZONTAL")
  489. end
  490. set_vertical_orientation
  491. -- (non inheritable): controls the distribution of the children in
  492. -- lines.
  493. do
  494. iup_open.set_attribute(Current, "ORIENTATION", "VERTICAL")
  495. end
  496. is_horizontal: BOOLEAN
  497. local
  498. str: STRING
  499. do
  500. str := iup_open.get_attribute(Current, "ORIENTATION")
  501. if str.is_equal("HORIZONTAL") then
  502. Result := True
  503. else
  504. Result := False
  505. end
  506. end
  507. is_vertical: BOOLEAN
  508. local
  509. str: STRING
  510. do
  511. str := iup_open.get_attribute(Current, "ORIENTATION")
  512. if str.is_equal("VERTICAL") then
  513. Result := True
  514. else
  515. Result := False
  516. end
  517. end
  518. set_reference_column (col: INTEGER)
  519. -- (non inheritable): index of the column that will be used as reference
  520. -- when calculating the height of the lines. Default: 0.
  521. require
  522. col >= 0
  523. do
  524. iup_open.set_attribute(Current, "SIZECOL", col.out)
  525. end
  526. get_reference_column: INTEGER
  527. -- Return the index of the column used as reference.
  528. local
  529. str: STRING
  530. do
  531. str := iup_open.get_attribute(Current, "SIZECOL")
  532. Result := str.to_integer
  533. end
  534. set_reference_line (line: INTEGER)
  535. -- (non inheritable): index of the line that will be used as reference
  536. -- when calculating the width of the columns. Default: 0.
  537. require
  538. line >= 0
  539. do
  540. iup_open.set_attribute(Current, "SIZELIN", line.out)
  541. end
  542. get_reference_line: INTEGER
  543. -- Return the index of the line used as reference.
  544. local
  545. str: STRING
  546. do
  547. str := iup_open.get_attribute(Current, "SIZELIN")
  548. Result := str.to_integer
  549. end
  550. -- Validations
  551. is_valid_alignment_lin (value: STRING): BOOLEAN
  552. do
  553. if value.is_equal("ATOP") or
  554. value.is_equal("ACENTER") or
  555. value.is_equal("ABOTTOM") then
  556. Result := True
  557. else
  558. Result := False
  559. end
  560. end
  561. is_valid_alignment_col (value: STRING): BOOLEAN
  562. do
  563. if value.is_equal("ALEFT") or
  564. value.is_equal("ACENTER") or
  565. value.is_equal("ARIGHT") then
  566. Result := True
  567. else
  568. Result := False
  569. end
  570. end
  571. is_valid_expand_children (value: STRING): BOOLEAN
  572. do
  573. if value.is_equal("YES") or
  574. value.is_equal("HORIZONTAL") or
  575. value.is_equal("VERTICAL") or
  576. value.is_equal("NO") then
  577. Result := True
  578. else
  579. Result := False
  580. end
  581. end
  582. feature {NONE}
  583. -- Internals
  584. int_grid_box_empty (arguments: POINTER): POINTER
  585. external
  586. "C inline use %"eiffel-iup.h%""
  587. alias
  588. "return IupGridBox ($arguments);"
  589. end
  590. int_grid_box (arguments: POINTER): POINTER
  591. external
  592. "C inline use %"eiffel-iup.h%""
  593. alias
  594. "return IupGridBoxv ($arguments);"
  595. end
  596. end -- class IUP_GRID_BOX
  597. -- The MIT License (MIT)
  598. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  599. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  600. -- of this software and associated documentation files (the "Software"), to deal
  601. -- in the Software without restriction, including without limitation the rights
  602. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  603. -- copies of the Software, and to permit persons to whom the Software is
  604. -- furnished to do so, subject to the following conditions:
  605. --
  606. -- The above copyright notice and this permission notice shall be included in
  607. -- all copies or substantial portions of the Software.
  608. --
  609. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  610. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  611. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  612. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  613. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  614. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  615. -- SOFTWARE.