iup_get_param.e 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. class IUP_GET_PARAM
  2. -- Shows a modal dialog for capturing parameter values using several types of
  3. -- controls. After create the dialog with "get_param" you can add any
  4. -- amout of parameters with features "add_xxxx_parameter". The first
  5. -- argument in these features are the label of the parameter, you can
  6. -- add any number of characters %T at the label to indent the parameter entry.
  7. -- The argument "tip" is a string that is displayed as a tool-tip for the main
  8. -- control of the parameter. To add break lines in tool-tip string
  9. -- add the characters "%%r". You can pass an empty string if don't want a
  10. -- tool-tip. You can also add "separators" to organize the parameters.
  11. -- The dialog is resizable if it contains a string, a multiline string or a
  12. -- number with a valuator. All the multiline strings will increase size equally
  13. -- in both directions.
  14. --
  15. -- The dialog is resizable if it contains a string, a multiline string or a
  16. -- number with a valuator. All the multiline strings will increase size equally
  17. -- in both directions.
  18. --
  19. -- The dialog uses a global attribute called "PARENTDIALOG" as the parent
  20. -- dialog if it is defined. It also uses a global attribute called "ICON" as
  21. -- the dialog icon if it is defined.
  22. inherit
  23. IUP_WIDGET
  24. redefine
  25. execute_param
  26. end
  27. create {ANY}
  28. get_param
  29. feature {ANY}
  30. get_param (title: STRING;
  31. act: FUNCTION[TUPLE[IUP_GET_PARAM, INTEGER, POINTER], INTEGER];
  32. user_data: POINTER)
  33. -- Create the dialog.
  34. --
  35. -- title: dialog title.
  36. -- act: user callback to be called whenever a parameter value was
  37. -- changed, and when the user pressed the OK button.
  38. -- user_data: user pointer passed to the user callback.
  39. --
  40. -- The callback receive three arguments:
  41. --
  42. -- dialog: the IUP_GET_PARAM object
  43. -- param_index: current parameter being changed. Can have negative values
  44. -- to indicate specific situations:
  45. -- -1 = if the user pressed the button 1.
  46. -- -2 = after the dialog is mapped and just before it is shown.
  47. -- -3 = if the user pressed the button 2.
  48. -- -4 = if the user pressed the button 3, if any.
  49. -- -5 = if the user clicked on the dialog close button.
  50. -- user_data: a user pointer that is passed in the function call.
  51. --
  52. -- Returns: You can reject the change or the button action by returning 0
  53. -- in the callback, otherwise you must return 1. By default button 1 and
  54. -- button 2 will close the dialog.
  55. --
  56. -- You should not programmatically change the current parameter value
  57. -- during the callback. On the other hand you can freely change the value
  58. -- of other parameters.
  59. do
  60. t := title
  61. cb_param := act
  62. ud := user_data
  63. pe := 0
  64. create f.make_empty
  65. create pd.default_create
  66. end
  67. launch: INTEGER
  68. -- Show the dialog, return 1 if the button 1 was pressed, 0 if the button
  69. -- 2 was pressed or if an error occurred.
  70. do
  71. iup_open.set_get_param (Current)
  72. Result := int_get_param (t.to_external, ud,
  73. f.to_external, pd.count, pe,
  74. pd.to_external)
  75. end
  76. -- Set parameters
  77. add_boolean_parameter (label, extra_data, tip: STRING; def: POINTER)
  78. -- Add an entry for a boolean parameter, it shows a True/False toggle.
  79. -- The "extra_data" parameter are optional strings, in the form
  80. -- "false_title,true_title" for boolean types to be displayed after the
  81. -- toggle. The strings can not have commas ',', nor brackets '[' or ']'.
  82. -- The "def" parameter should be a pointer to a integer with
  83. -- the initial value (0 for False and 1 to True).
  84. do
  85. f.append_string(label)
  86. f.append_string("%%b")
  87. if not extra_data.is_empty then
  88. f.append_string("[")
  89. f.append_string(extra_data)
  90. f.append_string("]")
  91. end
  92. if not tip.is_empty then
  93. f.append_string("{")
  94. f.append_string(tip)
  95. f.append_string("}")
  96. end
  97. f.append_string("%N")
  98. pd.add_last(def)
  99. end
  100. add_integer_parameter (label, extra_data, tip: STRING; def: POINTER)
  101. -- A field to a C integer value. The "extra_data" parameter is a
  102. -- string of the form "min,max,step". The "max" and "step" values can be
  103. -- omitted. When "min" and "max" are specified a valuator will also be
  104. -- added to change the value. To specify "step", "max" must be also
  105. -- specified. "step" is the size of the increment. The "def" parameter
  106. -- should be a pointer to a INTEGER with the initial value.
  107. -- A integer parameter always has a spin attached to the text to
  108. -- increment and decrement the value.
  109. do
  110. f.append_string(label)
  111. f.append_string("%%i")
  112. if not extra_data.is_empty then
  113. f.append_string("[")
  114. f.append_string(extra_data)
  115. f.append_string("]")
  116. end
  117. if not tip.is_empty then
  118. f.append_string("{")
  119. f.append_string(tip)
  120. f.append_string("}")
  121. end
  122. f.append_string("%N")
  123. pd.add_last(def)
  124. end
  125. add_real_parameter (label, extra_data, tip: STRING; def: POINTER)
  126. -- A field to a C real value. The "extra_data" parameter is a
  127. -- string of the form "min,max,step". The "max" and "step" values can be
  128. -- omitted. When "min" and "max" are specified a valuator will also be
  129. -- added to change the value. To specify "step", "max" must be also
  130. -- specified. "step" is the size of the increment. The "def" parameter
  131. -- should be a pointer to a REAL_32 with the initial value.
  132. -- A real parameter only has a spin in a full interval is defined (min
  133. -- and max), in this case the default step is (max-min)/20.
  134. do
  135. f.append_string(label)
  136. f.append_string("%%r")
  137. if not extra_data.is_empty then
  138. f.append_string("[")
  139. f.append_string(extra_data)
  140. f.append_string("]")
  141. end
  142. if not tip.is_empty then
  143. f.append_string("{")
  144. f.append_string(tip)
  145. f.append_string("}")
  146. end
  147. f.append_string("%N")
  148. pd.add_last(def)
  149. end
  150. add_double_parameter (label, extra_data, tip: STRING; def: POINTER)
  151. -- A field to a C double value. The "extra_data" parameter is a
  152. -- string of the form "min,max,step". The "max" and "step" values can be
  153. -- omitted. When "min" and "max" are specified a valuator will also be
  154. -- added to change the value. To specify "step", "max" must be also
  155. -- specified. "step" is the size of the increment. The "def" parameter
  156. -- should be a pointer to a REAL_64 with the initial value.
  157. -- A double parameter only has a spin in a full interval is defined (min
  158. -- and max), in this case the default step is (max-min)/20.
  159. do
  160. f.append_string(label)
  161. f.append_string("%%R")
  162. if not extra_data.is_empty then
  163. f.append_string("[")
  164. f.append_string(extra_data)
  165. f.append_string("]")
  166. end
  167. if not tip.is_empty then
  168. f.append_string("{")
  169. f.append_string(tip)
  170. f.append_string("}")
  171. end
  172. f.append_string("%N")
  173. pd.add_last(def)
  174. end
  175. add_angle_real_parameter (label, extra_data, tip: STRING; def: POINTER)
  176. -- A field to a C real value. The "extra_data" parameter is a
  177. -- string of the form "min,max,step". The "max" and "step" values can be
  178. -- omitted. When "min" and "max" are specified a dial will also be
  179. -- added to change the value (only if "load_iup_controls" is
  180. -- called on IUP). To specify "step", "max" must be also
  181. -- specified. "step" is the size of the increment. The "def" parameter
  182. -- should be a pointer to a REAL_32 with the initial value.
  183. do
  184. f.append_string(label)
  185. f.append_string("%%a")
  186. if not extra_data.is_empty then
  187. f.append_string("[")
  188. f.append_string(extra_data)
  189. f.append_string("]")
  190. end
  191. if not tip.is_empty then
  192. f.append_string("{")
  193. f.append_string(tip)
  194. f.append_string("}")
  195. end
  196. f.append_string("%N")
  197. pd.add_last(def)
  198. end
  199. add_angle_double_parameter (label, extra_data, tip: STRING; def: POINTER)
  200. -- A field to an C double value. The "extra_data" parameter is a
  201. -- string of the form "min,max,step". The "max" and "step" values can be
  202. -- omitted. When "min" and "max" are specified a dial will also be
  203. -- added to change the value (only if "load_iup_controls" is
  204. -- called on IUP). To specify "step", "max" must be also
  205. -- specified. "step" is the size of the increment. The "def" parameter
  206. -- should be a pointer to a REAL_64 with the initial value.
  207. do
  208. f.append_string(label)
  209. f.append_string("%%A")
  210. if not extra_data.is_empty then
  211. f.append_string("[")
  212. f.append_string(extra_data)
  213. f.append_string("]")
  214. end
  215. if not tip.is_empty then
  216. f.append_string("{")
  217. f.append_string(tip)
  218. f.append_string("}")
  219. end
  220. f.append_string("%N")
  221. pd.add_last(def)
  222. end
  223. add_string_parameter (label, extra_data, tip: STRING; def: POINTER)
  224. -- A field to a string value. The "extra_data" parameter is an optional
  225. -- mask for the string. The maks have the same format used in IUP_TEXT.
  226. -- For more information see:
  227. -- http://webserver2.tecgraf.puc-rio.br/iup/en/attrib/iup_mask.html
  228. -- Pass an empty string if don't want a mask.
  229. -- The "def" parameter should be a pointer to a STRING with the initial
  230. -- value (if any) and with enough space for the user entry.
  231. do
  232. f.append_string(label)
  233. f.append_string("%%s")
  234. if not extra_data.is_empty then
  235. f.append_string("[")
  236. f.append_string(extra_data)
  237. f.append_string("]")
  238. end
  239. if not tip.is_empty then
  240. f.append_string("{")
  241. f.append_string(tip)
  242. f.append_string("}")
  243. end
  244. f.append_string("%N")
  245. pd.add_last(def)
  246. end
  247. add_multiline_parameter (label, extra_data, tip: STRING; def: POINTER)
  248. -- A field to a multiline string value. The "extra_data" parameter is an
  249. -- optional mask for the string. The maks have the same format used in
  250. -- IUP_TEXT. For more information see:
  251. -- http://webserver2.tecgraf.puc-rio.br/iup/en/attrib/iup_mask.html
  252. -- Pass an empty string if don't want a mask.
  253. -- The "def" parameter should be a pointer to a STRING with the initial
  254. -- value (if any) and with enough space for the user entry.
  255. do
  256. f.append_string(label)
  257. f.append_string("%%m")
  258. if not extra_data.is_empty then
  259. f.append_string("[")
  260. f.append_string(extra_data)
  261. f.append_string("]")
  262. end
  263. if not tip.is_empty then
  264. f.append_string("{")
  265. f.append_string(tip)
  266. f.append_string("}")
  267. end
  268. f.append_string("%N")
  269. pd.add_last(def)
  270. end
  271. add_list_parameter (label, extra_data, tip: STRING; def: POINTER)
  272. -- A dropdown list box. The "extra_data" parameter is a string of the
  273. -- form "item0|item1|item2|...|itemN" with the titles of the items in the
  274. -- list. At least one item must exist. Items index are zero based start.
  275. -- The "def" parameter should be a pointer to an INTEGER with
  276. -- the initial value (the selected item).
  277. do
  278. f.append_string(label)
  279. f.append_string("%%l")
  280. if not extra_data.is_empty then
  281. f.append_string("|")
  282. f.append_string(extra_data)
  283. f.append_string("|")
  284. end
  285. if not tip.is_empty then
  286. f.append_string("{")
  287. f.append_string(tip)
  288. f.append_string("}")
  289. end
  290. f.append_string("%N")
  291. pd.add_last(def)
  292. end
  293. add_radio_parameter (label, extra_data, tip: STRING; def: POINTER)
  294. -- A list of toggles inside a radio. The "extra_data" parameter is a
  295. -- string of the form "item0|item1|item2|...|itemN" with
  296. -- the titles of the items in the list. At least one item must exist.
  297. -- Items index are zero based start. The "def" parameter should be a
  298. -- pointer to an INTEGER with the initial value (the selected item).
  299. do
  300. f.append_string(label)
  301. f.append_string("%%o")
  302. if not extra_data.is_empty then
  303. f.append_string("|")
  304. f.append_string(extra_data)
  305. f.append_string("|")
  306. end
  307. if not tip.is_empty then
  308. f.append_string("{")
  309. f.append_string(tip)
  310. f.append_string("}")
  311. end
  312. f.append_string("%N")
  313. pd.add_last(def)
  314. end
  315. add_separator (label: STRING)
  316. -- Separator. Shows a horizontal line separator label, in this case text
  317. -- can be an empty string.
  318. do
  319. f.append_string(label)
  320. f.append_string("%%t")
  321. f.append_string("%N")
  322. pe := pe + 1
  323. end
  324. add_date_parameter (label, extra_data, tip: STRING; def: POINTER)
  325. -- A string parameter, but the interface uses a IUP_DATE_PICK element to
  326. -- select a date. The "extra_data" parameter are simply IUP_DATE_PICK
  327. -- attributes in a single string. The "def" parameter should be a pointer
  328. -- to a string with the initial value and with enough space for the user
  329. -- entry.
  330. do
  331. f.append_string(label)
  332. f.append_string("%%d")
  333. if not extra_data.is_empty then
  334. f.append_string("|")
  335. f.append_string(extra_data)
  336. f.append_string("|")
  337. end
  338. if not tip.is_empty then
  339. f.append_string("{")
  340. f.append_string(tip)
  341. f.append_string("}")
  342. end
  343. f.append_string("%N")
  344. pd.add_last(def)
  345. end
  346. add_file_parameter (label, extra_data, tip: STRING; def: POINTER)
  347. -- A string parameter with a button to open a file selection dialog box.
  348. -- The "estra_data" is a string of the form
  349. -- "dialogtype|filter|directory|nochangedir|nooverwriteprompt"
  350. -- with the respective attribute values passed to the IUP_FILE_DIALOG
  351. -- control when activated. All '|' must exist, but you can let empty
  352. -- values to use the default values.
  353. -- The "def" parameter should be a pointer to a string with the
  354. -- initial value and with enough space for the user entry.
  355. do
  356. f.append_string(label)
  357. f.append_string("%%f")
  358. if not tip.is_empty then
  359. f.append_string("{")
  360. f.append_string(tip)
  361. f.append_string("}")
  362. end
  363. f.append_string("%N")
  364. pd.add_last(def)
  365. end
  366. add_color_parameter (label, tip: STRING; def: POINTER)
  367. -- A string parameter with a color button to open a color selection
  368. -- dialog box. The "def" parameter should be a pointer to a string
  369. -- with the initial value and with enough space for the user entry.
  370. do
  371. f.append_string(label)
  372. f.append_string("%%c")
  373. if not tip.is_empty then
  374. f.append_string("{")
  375. f.append_string(tip)
  376. f.append_string("}")
  377. end
  378. f.append_string("%N")
  379. pd.add_last(def)
  380. end
  381. add_font_parameter (label, tip: STRING; def: POINTER)
  382. -- A string parameter with a font button to open a font selection
  383. -- dialog box. The "def" parameter should be a pointer to a string
  384. -- with the initial value and with enough space for the user entry.
  385. do
  386. f.append_string(label)
  387. f.append_string("%%n")
  388. if not tip.is_empty then
  389. f.append_string("{")
  390. f.append_string(tip)
  391. f.append_string("}")
  392. end
  393. f.append_string("%N")
  394. pd.add_last(def)
  395. end
  396. add_widget_parameter (label: STRING; wgt: IUP_WIDGET)
  397. -- Add a widget that will be managed by the application, it will be
  398. -- placed after the parameters and before the buttons
  399. do
  400. f.append_string(label)
  401. f.append_string("%%h")
  402. f.append_string("%N")
  403. pd.add_last(wgt.widget)
  404. end
  405. add_buttons_parameter (titles: STRING)
  406. -- Buttons titles. Allow to redefine the default button titles (OK and
  407. -- Cancel), and to add a third button. Use "button1,button2,button3".
  408. -- Can omit one of them, it will use the default name.
  409. do
  410. f.append_string("Bt %%u")
  411. f.append_string("[")
  412. f.append_string(titles)
  413. f.append_string("]")
  414. f.append_string("%N")
  415. pe := pe + 1
  416. end
  417. -- Attributes
  418. set_precision (decimals: INTEGER)
  419. -- The default number of decimal places used in floating point output by
  420. -- some controls.
  421. --
  422. -- The default precision for real value display is given by the global
  423. -- attribute DEFAULTPRECISION. But inside the callback the application
  424. -- can use this feature to use another value. It will work only during
  425. -- interactive changes. The decimal symbol will used the
  426. -- DEFAULTDECIMALSYMBOL global attribute. Local attributes may overwrite
  427. -- the default. Default: 2.
  428. require
  429. decimals >= 0
  430. do
  431. iup_open.set_attribute (Current, "PRECISION", decimals.to_string)
  432. end
  433. get_button (number: INTEGER): IUP_BUTTON
  434. -- Returns the button 1, 2 or 3 (if any).
  435. require
  436. number >= 1
  437. number <= 3
  438. local
  439. p: POINTER
  440. b: IUP_BUTTON
  441. do
  442. if number.is_equal(1) then
  443. p := iup_open.get_attribute_ihandle(Current, "BUTTON1")
  444. elseif number.is_equal(2) then
  445. p := iup_open.get_attribute_ihandle(Current, "BUTTON2")
  446. elseif number.is_equal(3) then
  447. p := iup_open.get_attribute_ihandle(Current, "BUTTON3")
  448. end
  449. create b.button_widget(p)
  450. Result := b
  451. end
  452. --get_parameter_label_at (number: INTEGER): IUP_LABEL
  453. -- local
  454. -- str: STRING
  455. -- a_label: IUP_LABEL
  456. -- p1, p2: POINTER
  457. -- do
  458. -- str := "PARAM"
  459. -- str.append_string(number.to_string)
  460. -- p1 := iup_open.get_attribute_ihandle(Current, str)
  461. -- p2 := iup_open.get_attribute_ihandle_from_handle(p1, str)
  462. --
  463. -- create a_label.label_widget(p2)
  464. -- Result := a_label
  465. -- end
  466. get_parameter_value_at (index: INTEGER): STRING
  467. -- Get the value, as string, that the user writes in the parameter at
  468. -- provided index.
  469. local
  470. str: STRING
  471. p: POINTER
  472. do
  473. str := "PARAM"
  474. str.append_string(index.to_string)
  475. p := iup_open.get_attribute_ihandle(Current, str)
  476. if p.is_not_null then
  477. Result := iup_open.get_attribute_from_handle(p, "VALUE")
  478. else
  479. Result := ""
  480. end
  481. end
  482. set_parameter_value_at (value: STRING; index: INTEGER)
  483. -- Set the value, passed as string, in the parameter at provided index.
  484. -- This set the value at the control and at the auxiliary
  485. -- control (if any).
  486. local
  487. str: STRING
  488. p1, p2: POINTER
  489. do
  490. str := "PARAM"
  491. str.append_string(index.to_string)
  492. p1 := iup_open.get_attribute_ihandle(Current, str)
  493. if p1.is_not_null then
  494. iup_open.set_attribute_in_handle(p1, "VALUE", value)
  495. end
  496. p2 := iup_open.get_attribute_ihandle_from_handle(p1, "AUXCONTROL")
  497. if p2.is_not_null then
  498. iup_open.set_attribute_in_handle(p2, "VALUE", value)
  499. end
  500. end
  501. set_parameter_visible_columns_at (value, index: INTEGER)
  502. -- Set the visible columns in string parameters (those
  503. -- added with "add_string_parameter").
  504. local
  505. str: STRING
  506. p: POINTER
  507. do
  508. str := "PARAM"
  509. str.append_string(index.to_string)
  510. p := iup_open.get_attribute_ihandle(Current, str)
  511. if p.is_not_null then
  512. iup_open.set_attribute_in_handle(p, "VISIBLECOLUMNS",
  513. value.to_string)
  514. end
  515. end
  516. get_spinning: INTEGER
  517. -- A integer parameter always has a spin attached to the text to
  518. -- increment and decrement the value. A real parameter only has a spin in
  519. -- a full interval is defined (min and max), in this case the default
  520. -- step is (max-min)/20. When the callback is called because a spin was
  521. -- activated then this feature return a non zero value.
  522. local
  523. str: STRING
  524. do
  525. str := iup_open.get_attribute (Current, "SPINNING")
  526. if str /= Void then
  527. if str.is_integer then
  528. Result := str.to_integer
  529. end
  530. end
  531. end
  532. feature {IUP}
  533. execute_param (handle: POINTER; param_index: INTEGER; user_data: POINTER): INTEGER
  534. do
  535. widget := handle
  536. Result := cb_param.item([Current, param_index, user_data])
  537. end
  538. feature {}
  539. cb_param: FUNCTION[TUPLE[IUP_GET_PARAM, INTEGER, POINTER], INTEGER]
  540. t, f: STRING
  541. ud: POINTER
  542. pe: INTEGER
  543. pd: ARRAY[POINTER]
  544. -- Internals
  545. int_get_param (title, user_data, format: POINTER; param_count, param_extra: INTEGER; param_data: POINTER): INTEGER
  546. external "plug_in"
  547. alias "{
  548. location: "${sys}/plugins"
  549. module_name: "iup"
  550. feature_name: "get_param_dialog"
  551. }"
  552. end
  553. end -- end class
  554. -- The MIT License (MIT)
  555. -- Copyright (c) 2016, 2017 by German A. Arias
  556. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  557. -- of this software and associated documentation files (the "Software"), to deal
  558. -- in the Software without restriction, including without limitation the rights
  559. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  560. -- copies of the Software, and to permit persons to whom the Software is
  561. -- furnished to do so, subject to the following conditions:
  562. --
  563. -- The above copyright notice and this permission notice shall be included in
  564. -- all copies or substantial portions of the Software.
  565. --
  566. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  567. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  568. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  569. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  570. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  571. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  572. -- SOFTWARE.