iup_widget_internals.e 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. deferred class IUP_WIDGET_INTERNALS
  2. -- Internals commands.
  3. inherit
  4. IUP_WIDGET
  5. undefine
  6. execute_map,
  7. execute_unmap,
  8. execute_destroy,
  9. execute_getfocus,
  10. execute_killfocus,
  11. execute_enterwindow,
  12. execute_leavewindow,
  13. execute_k_any,
  14. execute_help,
  15. execute_action,
  16. execute_close,
  17. execute_copydata,
  18. execute_dropfiles,
  19. execute_mdiactivate,
  20. execute_move,
  21. execute_resize,
  22. execute_show,
  23. execute_trayclick,
  24. execute_file,
  25. execute_colorupdate,
  26. execute_cancel,
  27. execute_button,
  28. execute_valuechanged,
  29. execute_action_fnff,
  30. execute_focus,
  31. execute_motion,
  32. execute_keypress,
  33. execute_scroll,
  34. execute_wheel,
  35. execute_detached,
  36. execute_restored,
  37. execute_openclose,
  38. execute_extrabutton,
  39. execute_click,
  40. execute_action_fnsii,
  41. execute_caret,
  42. execute_dblclick,
  43. execute_dragdrop,
  44. execute_dropdown,
  45. execute_edit,
  46. execute_multiselect,
  47. execute_spin,
  48. execute_tabchange,
  49. execute_tabchangepos,
  50. execute_tabclose,
  51. execute_rightclick,
  52. execute_action_fnis,
  53. execute_maskfail,
  54. execute_action_fni,
  55. execute_selection,
  56. execute_multiselection,
  57. execute_multiunselection,
  58. execute_branchopen,
  59. execute_branchclose,
  60. execute_executeleaf,
  61. execute_showrename,
  62. execute_rename,
  63. execute_noderemoved,
  64. execute_togglevalue,
  65. execute_highlight,
  66. execute_open,
  67. execute_menuclose,
  68. execute_dragbegin,
  69. execute_dragdatasize,
  70. execute_dragdata,
  71. execute_dragend,
  72. execute_dropdata,
  73. execute_dropmotion,
  74. execute_recent,
  75. execute_param,
  76. execute_flat_action,
  77. execute_flat_button,
  78. execute_flat_focus,
  79. execute_flat_enterwindow,
  80. execute_flat_leavewindow,
  81. execute_draw,
  82. execute_height,
  83. execute_hspan,
  84. execute_mouseclick,
  85. execute_mousemotion,
  86. execute_ncols,
  87. execute_nlines,
  88. execute_scrolling,
  89. execute_vspan,
  90. execute_width,
  91. execute_cell,
  92. execute_extended,
  93. execute_select,
  94. execute_switch,
  95. execute_action_fniiiis,
  96. execute_click_fniis,
  97. execute_colresize,
  98. execute_release,
  99. execute_resizematrix,
  100. execute_mousemove,
  101. execute_enteritem,
  102. execute_leaveitem,
  103. execute_scrolltop,
  104. execute_bgcolor,
  105. execute_fgcolor,
  106. execute_font,
  107. execute_type,
  108. execute_dropcheck,
  109. execute_translatevalue,
  110. execute_togglevalue_fniii,
  111. execute_drop,
  112. execute_menudrop,
  113. execute_dropselect,
  114. execute_edition,
  115. execute_value,
  116. execute_value_edit,
  117. execute_mark,
  118. execute_markedit,
  119. execute_flat_motion,
  120. execute_dropshow,
  121. execute_button_press,
  122. execute_button_release,
  123. execute_mousemove_fnd,
  124. execute_change,
  125. execute_drag
  126. end
  127. feature {ANY}
  128. is_yes_no (value: STRING): BOOLEAN
  129. do
  130. if value.is_equal("YES") or value.is_equal("NO") then
  131. Result := True
  132. else
  133. Result := False
  134. end
  135. end
  136. is_yes_no_ignore (value: STRING): BOOLEAN
  137. do
  138. if is_yes_no(value) or value.is_equal("IGNORE") then
  139. Result := True
  140. else
  141. Result := False
  142. end
  143. end
  144. is_valid_expand (value: STRING): BOOLEAN
  145. do
  146. if is_yes_no(value) or value.is_equal("HORIZONTAL") or
  147. value.is_equal("HORIZONTALFREE") or
  148. value.is_equal("VERTICAL") or
  149. value.is_equal("VERTICALFREE") then
  150. Result := True
  151. else
  152. Result := False
  153. end
  154. end
  155. is_valid_rgb_string (color: STRING): BOOLEAN
  156. local
  157. r, g, b: INTEGER
  158. v: LIST[STRING]
  159. do
  160. v := color.split(' ')
  161. if v.count.is_equal(3) then
  162. if v.at(1).is_integer and
  163. v.at(2).is_integer and
  164. v.at(3).is_integer then
  165. r := v.at(1).to_integer
  166. g := v.at(2).to_integer
  167. b := v.at(3).to_integer
  168. if r >= 0 and r <= 255 and
  169. g >= 0 and g <= 255 and
  170. b >= 0 and b <= 255 then
  171. Result := True
  172. end
  173. end
  174. end
  175. end
  176. is_valid_hexadecimal (value: STRING): BOOLEAN
  177. require
  178. sharp: value.starts_with("#")
  179. number_of_colors: value.count.is_equal(7)
  180. local
  181. x, y: INTEGER
  182. do
  183. value.remove_head(1)
  184. from
  185. x := 1
  186. y := 0
  187. until
  188. x <= value.count
  189. loop
  190. if value.character_32_item(x).is_hexa_digit then
  191. y := y + 1
  192. end
  193. x := x + 1
  194. end
  195. if y.is_equal(value.count) then
  196. Result := True
  197. else
  198. Result := False
  199. end
  200. end
  201. is_valid_string_date (value: STRING): BOOLEAN
  202. local
  203. str: STRING
  204. y, m, d: INTEGER
  205. v: LIST[STRING]
  206. do
  207. create str.make_from_string(value)
  208. if str.occurrences('/').is_equal(2) then
  209. v := str.split('/')
  210. if v.count.is_equal(3) then
  211. if v.at(1).is_integer and
  212. v.at(2).is_integer and
  213. v.at(3).is_integer then
  214. y := v.at(1).to_integer
  215. m := v.at(2).to_integer
  216. d := v.at(3).to_integer
  217. if y >= 0 and
  218. m >= 1 and m <= 12 and
  219. d >= 1 and d <= 31 then
  220. Result := True
  221. else
  222. Result := False
  223. end
  224. else
  225. Result := False
  226. end
  227. else
  228. Result := False
  229. end
  230. else
  231. Result := False
  232. end
  233. end
  234. feature {NONE}
  235. yesno_to_boolean (value: STRING): BOOLEAN
  236. do
  237. if value.is_equal("YES") then
  238. Result := True
  239. else
  240. Result := False
  241. end
  242. end
  243. boolean_to_yesno (value: BOOLEAN): STRING
  244. do
  245. if value then
  246. Result := "YES"
  247. else
  248. Result := "NO"
  249. end
  250. end
  251. rgb_to_string (red, green, blue: INTEGER): STRING
  252. require
  253. red >= 0
  254. red <= 255
  255. green >= 0
  256. green <= 255
  257. blue >= 0
  258. blue <= 255
  259. local
  260. color: STRING
  261. do
  262. color := red.out
  263. color.append_string(" ")
  264. color.append_string(green.out)
  265. color.append_string(" ")
  266. color.append_string(blue.out)
  267. Result := color
  268. end
  269. rgba_to_string (red, green, blue, alpha: INTEGER): STRING
  270. require
  271. alpha >= 0
  272. alpha <= 255
  273. local
  274. color: STRING
  275. do
  276. color := rgb_to_string(red, green, blue)
  277. color.append_string(" ")
  278. color.append_string(alpha.out)
  279. Result := color
  280. end
  281. hsi_to_string (h, s, i: INTEGER): STRING
  282. require
  283. h >= 0
  284. h <= 359
  285. s >= 0
  286. s <= 100
  287. i >= 0
  288. i <= 100
  289. local
  290. color: STRING
  291. do
  292. color := h.out
  293. color.append_string(" ")
  294. color.append_string(s.out)
  295. color.append_string(" ")
  296. color.append_string(i.out)
  297. Result := color
  298. end
  299. hsi_real_to_string (h, s, i: REAL_64): STRING
  300. require
  301. h >= 0
  302. h <= 360
  303. s >= 0
  304. s <= 1
  305. i >= 0
  306. i <= 1
  307. local
  308. color: STRING
  309. do
  310. color := h.out
  311. color.append_string(" ")
  312. color.append_string(s.out)
  313. color.append_string(" ")
  314. color.append_string(i.out)
  315. Result := color
  316. end
  317. rgb_to_hexadecimal (red, green, blue: INTEGER): STRING
  318. require
  319. red >= 0
  320. red <= 255
  321. green >= 0
  322. green <= 255
  323. blue >= 0
  324. blue <= 255
  325. local
  326. c: INTEGER
  327. color, rs, gs, bs: STRING
  328. do
  329. color := "#"
  330. rs := red.to_hex_string
  331. gs := green.to_hex_string
  332. bs := blue.to_hex_string
  333. c := rs.count
  334. if c > 2 then
  335. rs.remove_head(c - 2)
  336. end
  337. c := gs.count
  338. if c > 2 then
  339. gs.remove_head(c - 2)
  340. end
  341. c := bs.count
  342. if c > 2 then
  343. bs.remove_head(c - 2)
  344. end
  345. color.append_string(rs)
  346. color.append_string(gs)
  347. color.append_string(bs)
  348. Result := color
  349. end
  350. hexadecimal_to_rgb (color: STRING): TUPLE[INTEGER, INTEGER, INTEGER]
  351. require
  352. valid_color: is_valid_hexadecimal(color)
  353. local
  354. r, g, b, base: INTEGER
  355. tup: TUPLE[INTEGER, INTEGER, INTEGER]
  356. do
  357. base := 16
  358. r := color.character_32_item(1).out.to_integer_32 * base +
  359. color.character_32_item(2).out.to_integer
  360. g := color.character_32_item(3).out.to_integer_32 * base +
  361. color.character_32_item(4).out.to_integer
  362. b := color.character_32_item(5).out.to_integer_32 * base +
  363. color.character_32_item(6).out.to_integer
  364. tup := [r, g, b]
  365. Result := tup
  366. end
  367. string_to_rgb (color: STRING): TUPLE[INTEGER, INTEGER, INTEGER]
  368. local
  369. tup: TUPLE[INTEGER, INTEGER, INTEGER]
  370. v: LIST[STRING]
  371. do
  372. v := color.split(' ')
  373. if v.count.is_equal(3) and
  374. v.at(1).out.is_integer and
  375. v.at(2).out.is_integer and
  376. v.at(3).out.is_integer then
  377. tup := [v.at(1).out.to_integer, v.at(2).out.to_integer,
  378. v.at(3).out.to_integer]
  379. Result := tup
  380. else
  381. io.put_string("Something goes wrong %N")
  382. Result := [0, 0, 0]
  383. end
  384. end
  385. components_of (size: STRING; separator: CHARACTER): TUPLE[INTEGER, INTEGER]
  386. local
  387. i, c: INTEGER
  388. str, width, height: STRING
  389. tup: TUPLE[INTEGER, INTEGER]
  390. do
  391. create str.make_from_string(size)
  392. if str.has(separator) then
  393. i := str.index_of(separator, 1)
  394. c := str.count
  395. --io.put_string(size)
  396. --io.put_integer(i)
  397. --io.put_integer(c)
  398. if not i.is_equal(1) then
  399. width := str.substring(1, i - 1)
  400. else
  401. width := "0"
  402. end
  403. if not i.is_equal(c) then
  404. height := str.substring(i + 1, c)
  405. else
  406. height := "0"
  407. end
  408. --io.put_string(width)
  409. --io.put_string(height)
  410. tup := [width.to_integer, height.to_integer]
  411. Result := tup
  412. else
  413. io.put_string("Unable to get the components %N")
  414. Result := [0, 0]
  415. end
  416. end
  417. components_of_size (size: STRING): TUPLE[INTEGER, INTEGER]
  418. do
  419. Result := components_of (size, 'x')
  420. end
  421. components_of_position (size: STRING): TUPLE[INTEGER, INTEGER]
  422. do
  423. Result := components_of (size, ',')
  424. end
  425. components_of_minmax (size: STRING): TUPLE[INTEGER, INTEGER]
  426. do
  427. Result := components_of (size, ':')
  428. end
  429. components_of_limits (limits: STRING): TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  430. local
  431. i, c: INTEGER
  432. xmin, xmax, ymin, ymax: STRING
  433. tup: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  434. do
  435. i := limits.index_of(':', 1)
  436. c := limits.count
  437. if not i.is_equal(1) then
  438. xmin := limits.substring(1, i - 1)
  439. limits.remove_substring(1, i)
  440. else
  441. xmin := "0"
  442. limits.remove_head(1)
  443. end
  444. i := limits.index_of(':', 1)
  445. if not i.is_equal(1) then
  446. xmax := limits.substring(1, i - 1)
  447. limits.remove_substring(1, i)
  448. else
  449. xmax := "0"
  450. limits.remove_head(1)
  451. end
  452. i := limits.index_of(':', 1)
  453. if not i.is_equal(1) then
  454. ymin := limits.substring(1, i - 1)
  455. limits.remove_substring(1, i)
  456. else
  457. ymin := "0"
  458. limits.remove_head(1)
  459. end
  460. ymax := limits
  461. tup := [xmin.to_integer, xmax.to_integer,
  462. ymin.to_integer, ymax.to_integer]
  463. Result := tup
  464. end
  465. convert_date_to_tuple (value: STRING): TUPLE[INTEGER, INTEGER, INTEGER]
  466. local
  467. str: STRING
  468. v: LIST[STRING]
  469. do
  470. create str.make_from_string(value)
  471. v := str.split('/')
  472. if v.count.is_equal(3) and
  473. v.at(1).out.is_integer and
  474. v.at(2).out.is_integer and
  475. v.at(3).out.is_integer then
  476. Result := [v.at(1).out.to_integer,
  477. v.at(2).out.to_integer,
  478. v.at(3).out.to_integer]
  479. else
  480. io.put_string("Something goes wrong %N")
  481. Result := [0, 0, 0]
  482. end
  483. end
  484. end
  485. -- The MIT License (MIT)
  486. -- Copyright (c) 2016, 2017, 2019 by German A. Arias
  487. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  488. -- of this software and associated documentation files (the "Software"), to deal
  489. -- in the Software without restriction, including without limitation the rights
  490. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  491. -- copies of the Software, and to permit persons to whom the Software is
  492. -- furnished to do so, subject to the following conditions:
  493. --
  494. -- The above copyright notice and this permission notice shall be included in
  495. -- all copies or substantial portions of the Software.
  496. --
  497. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  498. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  499. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  500. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  501. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  502. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  503. -- SOFTWARE.