example5.e 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. class EXAMPLE5
  2. -- This example show how use tabs and many other controls.
  3. inherit
  4. IUP_INTERFACE
  5. IUP_GET_POINTER
  6. create {ANY}
  7. make
  8. feature {ANY}
  9. counter: INTEGER
  10. make
  11. local
  12. gui: IUP
  13. i: STRING
  14. t: IUP_TABS
  15. v1, v2, v3, v4: IUP_VBOX
  16. h1, h2: IUP_HBOX
  17. b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14: IUP_BUTTON
  18. im: IUP_IMAGE
  19. l1, l2, l3, l4, l5: IUP_LABEL
  20. s1: IUP_VAL
  21. lt: IUP_LIST
  22. fl: IUP_FILL
  23. al: IUP_ANIMATED_LABEL
  24. d: IUP_DATE_PICK
  25. c: IUP_CALENDAR
  26. tx1: IUP_TEXT
  27. sb1: IUP_SPIN_BOX
  28. scll: IUP_SCROLL_BOX
  29. frm: IUP_FRAME
  30. ml1: IUP_MULTILINE
  31. sb: IUP_SPLIT
  32. sp: IUP_SPACE
  33. dl: IUP_DIAL
  34. dp: IUP_DROP_BUTTON
  35. cb: IUP_COLOR_BROWSER
  36. gg: IUP_GAUGE
  37. spn: IUP_SPIN
  38. ml: IUP_MULTILINE
  39. pb: IUP_PROGRESS_BAR
  40. w: IUP_DIALOG
  41. do
  42. gui := iup_open
  43. gui.load_images
  44. gui.load_iup_controls
  45. -- Controls at first tab
  46. ---------------------------------
  47. create im.image(10, 10, {ARRAY[INTEGER]} << 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  48. 15, 15, 15, 1, 1, 1, 1, 15, 15, 15,
  49. 15, 15, 15, 1, 15, 15, 15, 15, 15, 15,
  50. 15, 15, 15, 1, 15, 15, 15, 15, 15, 15,
  51. 15, 15, 15, 1, 15, 15, 15, 15, 15, 15,
  52. 15, 15, 15, 1, 1, 1, 15, 15, 15, 15,
  53. 15, 15, 15, 1, 15, 15, 15, 15, 15, 15,
  54. 15, 15, 15, 1, 15, 15, 15, 15, 15, 15,
  55. 15, 15, 15, 1, 15, 15, 15, 15, 15, 15,
  56. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 >>)
  57. im.set_widget_name("my_image")
  58. create b1.button("Launch an alarn")
  59. b1.set_cb_action(agent alarm)
  60. create b2.button("Select a file")
  61. b2.set_cb_action(agent file)
  62. create b3.button("Select a color")
  63. b3.set_cb_action(agent color)
  64. create b4.button("Write a message")
  65. b4.set_cb_action(agent get_message)
  66. create b5.button("Select an option")
  67. b5.set_cb_action(agent list)
  68. create b6.button("Preferences")
  69. b6.set_cb_action(agent param)
  70. create b7.button("Font")
  71. b7.set_image("my_image")
  72. b7.set_cb_action(agent font)
  73. create b8.button("A message")
  74. b8.set_cb_action(agent message)
  75. create b9.button("Color dialog")
  76. b9.set_cb_action(agent color_dialog)
  77. create b10.button("A message dialog")
  78. b10.set_cb_action(agent message_dlg)
  79. create fl.fill
  80. create al.animated_label_empty
  81. al.set_animation("IUP_CircleProgressAnimation")
  82. create ml.multiline
  83. ml.set_name("MULTILINE")
  84. ml.expand_both_directions
  85. create v1.vbox({ARRAY[IUP_WIDGET]} << b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, fl, al >>)
  86. v1.set_alignment("ACENTER")
  87. v1.set_gap(10)
  88. v1.set_margin(10, 10)
  89. v1.normalize_size_horizontal
  90. create h1.hbox({ARRAY[IUP_WIDGET]} << v1, ml >>)
  91. -- Controls at second tab
  92. -----------------------------------------
  93. create l1.label("Age")
  94. create l2.label("City")
  95. create l3.label("Date")
  96. create d.date_pick
  97. create s1.horizontal_val
  98. create lt.list
  99. lt.set_drop_down(True)
  100. lt.set_size(80, 12)
  101. create c.calendar
  102. create v2.vbox({ARRAY[IUP_WIDGET]} << d, l1, s1, l2, lt, l3, c >>)
  103. v2.set_gap(10)
  104. v2.set_margin(10, 10)
  105. create cb.color_browser
  106. create dp.drop_button(cb)
  107. dp.set_title("Color")
  108. create gg.gauge
  109. gg.set_dashed(True)
  110. gg.set_value(0.75)
  111. create spn.spin
  112. spn.set_cb_spin(agent spin)
  113. create l5.label("0")
  114. l5.set_name("L5")
  115. create b13.button("Message Alarm")
  116. b13.set_cb_action(agent alarm_m)
  117. create b14.button("Message Error")
  118. b14.set_cb_action(agent error_m)
  119. create v4.vbox({ARRAY[IUP_WIDGET]} << dp, gg, spn, l5, b13, b14 >>)
  120. v4.set_gap(10)
  121. v4.set_margin(10, 10)
  122. create h2.hbox({ARRAY[IUP_WIDGET]} << v2, v4 >>)
  123. -- Controls at third tab
  124. -----------------------------------------
  125. create tx1.text
  126. tx1.set_value("0")
  127. tx1.set_spin(True)
  128. create l4.label("0")
  129. l4.set_name("L4")
  130. l4.set_size(40, 12)
  131. l4.set_alignment("ACENTER", "ACENTER")
  132. create sb1.spin_box(l4)
  133. sb1.set_cb_spin(agent spin_click)
  134. create frm.frame(sb1)
  135. frm.set_title("Spin-label")
  136. create ml1.multiline
  137. ml1.expand_both_directions
  138. ml1.set_size(550, 350)
  139. create pb.progress_bar
  140. pb.set_name("PROGRESS")
  141. create b11.button("Starts")
  142. b11.set_cb_action(agent progress_bar)
  143. create b12.button("Progress dialog")
  144. create sp.space
  145. sp.set_raster_size(25, 50)
  146. create dl.dial_vertical
  147. b12.set_cb_action(agent progress_dialog)
  148. create scll.scroll_box(ml1)
  149. create v3.vbox({ARRAY[IUP_WIDGET]} << tx1, sb1, pb, b11, b12, sp, dl >>)
  150. v3.set_gap(10)
  151. v3.set_margin(10, 10)
  152. create sb.split(v3, scll)
  153. --sb.set_show_grip("LINES")
  154. sb.set_min_and_max(250, 750)
  155. sb.set_value(500)
  156. -- Create the tabs
  157. -------------------------------
  158. create t.tabs({ARRAY[IUP_WIDGET]} << h1, h2, sb >>)
  159. t.set_tab_n_title("Buttons", 0)
  160. t.set_tab_n_title("List, Slider and Date", 1)
  161. t.set_tab_n_title("Split", 2)
  162. -- Create the window.
  163. -------------------------
  164. create w.dialog(t)
  165. w.set_title("Controls test")
  166. w.set_predefined_size("HALF", "250")
  167. w.set_widget_name("window")
  168. i := w.show
  169. -- Start the animation.
  170. al.start
  171. -- Add items at list.
  172. lt.append_item("London")
  173. lt.append_item("Madrid")
  174. lt.append_item("New York")
  175. lt.append_item("Paris")
  176. lt.append_item("Milan")
  177. lt.append_item("Tokyo")
  178. lt.append_item("Buenos Aires")
  179. lt.set_value_string("Milan")
  180. gui.main_loop
  181. gui.close
  182. end
  183. alarm (widget: IUP_BUTTON): STRING
  184. local
  185. r: INTEGER
  186. al: IUP_ALARM
  187. do
  188. create al.alarm_three_buttons("Alarm", "Select a button", "1",
  189. "2", "3")
  190. r := al.launch
  191. if attached {IUP_MULTILINE} widget.get_dialog_child("MULTILINE") as ml then
  192. if r.is_equal(1) then
  193. ml.append("You selected the first button; %N")
  194. elseif r.is_equal(2) then
  195. ml.append("You selected the second button; %N")
  196. elseif r.is_equal(3) then
  197. ml.append("You selected the third button; %N")
  198. end
  199. end
  200. Result := "IUP_DEFAULT"
  201. end
  202. file (widget: IUP_BUTTON): STRING
  203. local
  204. tup: TUPLE[INTEGER, STRING]
  205. fl: IUP_GET_FILE
  206. do
  207. create fl.get_file("~/", "*.txt")
  208. tup := fl.launch
  209. if tup.integer_32_item(1).is_equal(0) and
  210. attached {STRING} tup.item(2) as st and
  211. attached {IUP_MULTILINE} widget.get_dialog_child("MULTILINE") as ml then
  212. ml.append(st)
  213. ml.append("%N")
  214. end
  215. Result := "IUP_DEFAULT"
  216. end
  217. color (widget: IUP_BUTTON): STRING
  218. local
  219. tup: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  220. gc: IUP_GET_COLOR
  221. do
  222. create gc.get_color_with_initial(0, 0, 0)
  223. tup := gc.launch_predefined_xy("IUP_CENTER", "IUP_CENTER")
  224. if tup.integer_32_item(1).is_equal(1) and
  225. attached {IUP_MULTILINE} widget.get_dialog_child("MULTILINE") as ml then
  226. ml.set_rgb_foreground_color(tup.integer_32_item(2), tup.integer_32_item(3), tup.integer_32_item(4))
  227. end
  228. Result := "IUP_DEFAULT"
  229. end
  230. get_message (widget: IUP_BUTTON): STRING
  231. local
  232. tup: TUPLE[INTEGER, STRING]
  233. gt: IUP_GET_TEXT
  234. do
  235. create gt.get_text_with_initial("Write a message", "...", 40)
  236. tup := gt.launch
  237. if not tup.integer_32_item(1).is_equal(0) and
  238. attached {STRING} tup.item(2) as st and
  239. attached {IUP_MULTILINE} widget.get_dialog_child("MULTILINE") as ml then
  240. ml.append(st)
  241. ml.append("%N")
  242. end
  243. Result := "IUP_DEFAULT"
  244. end
  245. list (widget: IUP_BUTTON): STRING
  246. local
  247. ld: IUP_LIST_DIALOG
  248. a: ARRAY[STRING]
  249. tup: TUPLE[INTEGER, STRING]
  250. do
  251. a := {ARRAY[STRING]} << "Uno", "Dos", "Tres", "Cuatro", "Cinco",
  252. "Seis", "Siete", "Ocho", "Nueve", "Diez" >>
  253. --create ld.list_dialog_simple("Select", a, 1, 1, 1)
  254. create ld.list_dialog_multiple("Select", a, 1, 5)
  255. tup := ld.launch
  256. if attached {STRING} tup.item(2) as st and
  257. attached {IUP_MULTILINE} widget.get_dialog_child("MULTILINE") as ml then
  258. ml.append(st)
  259. ml.append("%N")
  260. end
  261. Result := "IUP_DEFAULT"
  262. end
  263. param (widget: IUP_BUTTON): STRING
  264. local
  265. i: INTEGER
  266. gp: IUP_GET_PARAM
  267. p: POINTER
  268. d1, d2, d3, d4, d5: INTEGER
  269. dr1, dr2, dr3: REAL_32
  270. do
  271. d1 := 1
  272. d2 := 3456
  273. d3 := 192
  274. d4 := 1
  275. d5 := 2
  276. dr1 := 3.543
  277. dr2 := 0.5
  278. dr3 := 90
  279. create gp.get_param ("Preferences", agent preferences, p)
  280. gp.add_buttons_parameter (", MyCancel, Help!")
  281. gp.add_boolean_parameter ("Boolean:", "No,Yes", "", $d1)
  282. gp.add_integer_parameter ("Integer:", "", "", $d2)
  283. gp.add_real_parameter ("Real 1:", "", "", $dr1)
  284. gp.add_separator ("Sep1")
  285. gp.add_integer_parameter ("Integer:", "0,255", "", $d3)
  286. gp.add_real_parameter ("Real 2:", "-1.5,1.5,0.05", "", $dr2)
  287. gp.add_separator ("Sep2")
  288. gp.add_angle_real_parameter ("Angle:", "0,360", "", $dr3)
  289. gp.add_string_parameter ("String:", "", "", get_pointer(("string text").to_c))
  290. gp.add_radio_parameter ("Options:", "item0|item1|item2", "", $d4)
  291. gp.add_list_parameter ("List:", "item0|item1|item2|item3|item4|item5|item6", "", $d5)
  292. gp.add_file_parameter ("File:", "OPEN|*.bmp;*.jpg|CURRENT|NO|NO", "", get_pointer(("test.jpg").to_c))
  293. gp.add_color_parameter ("Color", "", get_pointer(("255 0 128").to_c))
  294. gp.add_font_parameter ("Font", "", get_pointer(("Courier, 24").to_c))
  295. gp.add_separator ("Sep3")
  296. gp.add_multiline_parameter ("Multiline:", "", "", get_pointer(("second text%Nsecond line").to_c))
  297. if attached {IUP_MULTILINE} widget.get_dialog_child("MULTILINE") as ml then
  298. gp.set_attribute_widget("MULTILINE", ml)
  299. end
  300. i := gp.launch
  301. Result := "IUP_DEFAULT"
  302. end
  303. preferences (dialog: IUP_GET_PARAM; index: INTEGER; data: POINTER): INTEGER
  304. local
  305. dat: STRING
  306. do
  307. dat := dialog.get_parameter_value_at(index)
  308. if attached {IUP_MULTILINE} dialog.get_attribute_widget("MULTILINE") as ml then
  309. ml.append("%N" + dat + " at index: " + index.out)
  310. end
  311. Result := 1
  312. end
  313. font (widget: IUP_BUTTON): STRING
  314. local
  315. fd: IUP_FONT_DIALOG
  316. str: STRING
  317. status: INTEGER
  318. do
  319. create fd.font_dialog
  320. str := fd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
  321. status := fd.get_status
  322. if status.is_equal(1) and
  323. attached {IUP_MULTILINE} widget.get_dialog_child("MULTILINE") as ml then
  324. ml.set_font(fd.get_value)
  325. end
  326. fd.destroy
  327. Result := "IUP_DEFAULT"
  328. end
  329. message (widget: IUP_BUTTON): STRING
  330. local
  331. ms: IUP_MESSAGE
  332. do
  333. create ms.message("A message", "Your message")
  334. Result := "IUP_DEFAULT"
  335. end
  336. color_dialog (widget: IUP_BUTTON): STRING
  337. local
  338. cd: IUP_COLOR_DIALOG
  339. rs: STRING
  340. status: INTEGER
  341. tup: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
  342. do
  343. create cd.color_dialog
  344. rs := cd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
  345. status := cd.get_status
  346. if status.is_equal(1) and
  347. attached {IUP_MULTILINE} widget.get_dialog_child("MULTILINE") as ml then
  348. tup := cd.get_value
  349. ml.set_rgb_foreground_color(tup.integer_32_item(1), tup.integer_32_item(2), tup.integer_32_item(3))
  350. end
  351. cd.destroy
  352. Result := "IUP_DEFAULT"
  353. end
  354. message_dlg (widget: IUP_BUTTON): STRING
  355. local
  356. mdlg: IUP_MESSAGE_DIALOG
  357. i: STRING
  358. r: INTEGER
  359. do
  360. create mdlg.message_dialog
  361. mdlg.set_title("A message dialog")
  362. mdlg.set_value("Are you sure?")
  363. mdlg.set_buttons("YESNOCANCEL")
  364. mdlg.set_dialog_type("QUESTION")
  365. mdlg.set_parent_dialog("window")
  366. i := mdlg.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
  367. r := mdlg.get_button_response
  368. mdlg.destroy
  369. if attached {IUP_MULTILINE} widget.get_dialog_child("MULTILINE") as ml then
  370. ml.append(r.out)
  371. ml.append("%N")
  372. end
  373. Result := "IUP_DEFAULT"
  374. end
  375. progress_bar (widget: IUP_BUTTON): STRING
  376. local
  377. cl: INTEGER
  378. pr: REAL_64
  379. ls: STRING
  380. do
  381. from
  382. cl := 0
  383. until
  384. cl > 1000
  385. loop
  386. pr := cl.to_double / (1000).to_double
  387. if attached {IUP_PROGRESS_BAR} widget.get_dialog_child("PROGRESS") as pb then
  388. pb.set_value(pr)
  389. end
  390. ls := iup_open.loop_step
  391. cl := cl + 1
  392. end
  393. Result := "IUP_DEFAULT"
  394. end
  395. progress_dialog (widget: IUP_BUTTON): STRING
  396. local
  397. pdlg: IUP_PROGRESS_DIALOG
  398. cl: INTEGER
  399. ls, i: STRING
  400. do
  401. create pdlg.progress_dialog
  402. pdlg.set_total_count(500)
  403. i := pdlg.show
  404. from
  405. cl := 0
  406. until
  407. cl > 1000
  408. loop
  409. pdlg.increment_one
  410. ls := iup_open.loop_step
  411. cl := cl + 1
  412. end
  413. pdlg.hide
  414. pdlg.destroy
  415. Result := "IUP_DEFAULT"
  416. end
  417. spin_click (wgt: IUP_SPIN_BOX; inc: INTEGER): STRING
  418. local
  419. lint: INTEGER
  420. do
  421. if attached {IUP_LABEL} wgt.get_dialog_child("L4") as l4 then
  422. if l4.get_title.is_integer then
  423. lint := l4.get_title.to_integer + inc
  424. l4.set_title(lint.out)
  425. end
  426. end
  427. Result := "IUP_DEFAULT"
  428. end
  429. spin (wgt: IUP_SPIN; inc: INTEGER): STRING
  430. local
  431. lint: INTEGER
  432. do
  433. if attached {IUP_LABEL} wgt.get_dialog_child("L5") as l5 then
  434. if l5.get_title.is_integer then
  435. lint := l5.get_title.to_integer + inc
  436. l5.set_title(lint.out)
  437. end
  438. end
  439. Result := "IUP_DEFAULT"
  440. end
  441. alarm_m (b: IUP_BUTTON): STRING
  442. local
  443. ma: IUP_MESSAGE_ALARM
  444. ir: INTEGER
  445. do
  446. if attached {IUP_DIALOG} b.get_dialog as w then
  447. create ma.message_alarm_with_parent (w, "Alert", "Are you sure?", "YESNOCANCEL")
  448. ir := ma.launch
  449. end
  450. io.put_string ("Pressed button: ")
  451. io.put_integer(ir)
  452. io.put_new_line
  453. Result := "IUP_DEFAULT"
  454. end
  455. error_m (b: IUP_BUTTON): STRING
  456. local
  457. me: IUP_MESSAGE_ERROR
  458. do
  459. if attached {IUP_DIALOG} b.get_dialog as w then
  460. create me.message_error_with_parent (w, "The configuration file is not found.")
  461. me.launch
  462. end
  463. Result := "IUP_DEFAULT"
  464. end
  465. end -- class EXAMPLE5