iup_label.e 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. class IUP_LABEL
  2. -- Creates a label interface element, which displays a separator, a text or an
  3. -- image. Labels with images, texts or line separator can not change its
  4. -- behavior after mapped. But after map the image can be changed for another
  5. -- image, and the text for another text.
  6. inherit
  7. IUP_WIDGET
  8. undefine
  9. execute_dragbegin,
  10. execute_dragdatasize,
  11. execute_dragdata,
  12. execute_dragend,
  13. execute_dropdata,
  14. execute_dropmotion
  15. redefine
  16. execute_map,
  17. execute_unmap,
  18. execute_destroy,
  19. execute_enterwindow,
  20. execute_leavewindow,
  21. execute_button,
  22. execute_motion,
  23. execute_dropfiles
  24. end
  25. IUP_WIDGET_ACTIVE
  26. IUP_WIDGET_BGCOLOR
  27. IUP_WIDGET_FGCOLOR
  28. IUP_WIDGET_TITLE
  29. IUP_WIDGET_FONT
  30. IUP_WIDGET_EXPAND
  31. IUP_WIDGET_SCREENPOSITION
  32. IUP_WIDGET_POSITION
  33. IUP_WIDGET_MAXMIN_SIZE
  34. IUP_WIDGET_TIP
  35. IUP_WIDGET_SIZE
  36. IUP_WIDGET_RASTERSIZE
  37. IUP_WIDGET_USERSIZE
  38. IUP_WIDGET_ZORDER
  39. IUP_WIDGET_VISIBLE
  40. IUP_WIDGET_CHILD
  41. IUP_WIDGET_NAME
  42. IUP_DRAG_AND_DROP
  43. IUP_WIDGET_CUSTOM_ATTRIBUTES
  44. IUP_WIDGET_PADDING
  45. create {ANY}
  46. label_empty,
  47. label
  48. feature {ANY}
  49. label_empty
  50. -- A new empty label.
  51. local
  52. a_label, p: POINTER
  53. do
  54. a_label := int_label (p)
  55. set_widget(a_label)
  56. end
  57. label (text: STRING)
  58. -- A new label with the provided text
  59. local
  60. a_label: POINTER
  61. do
  62. a_label := int_label (get_pointer(text.to_c))
  63. set_widget(a_label)
  64. end
  65. -- Attributes
  66. set_alignment (horizontal, vertical: STRING)
  67. -- (non inheritable): horizontal and vertical alignment. Possible values:
  68. -- "ALEFT", "ACENTER" and "ARIGHT", combined to "ATOP", "ACENTER" and
  69. -- "ABOTTOM". Default: "ALEFT:ACENTER". In Motif, vertical alignment is
  70. -- restricted to "ACENTER".
  71. require
  72. is_valid_alignment(horizontal, vertical)
  73. local
  74. str: STRING
  75. do
  76. create str.make_from_string(horizontal)
  77. str.append_string(":")
  78. str.append_string(vertical)
  79. iup_open.set_attribute(Current, "ALIGNMENT", str)
  80. end
  81. set_as_drop_files_target (state: BOOLEAN)
  82. -- [Windows and GTK Only] (non inheritable): Enable or disable the drop
  83. -- of files. Default: False, but if DROPFILES_CB is defined when the
  84. -- element is mapped then it will be automatically enabled.
  85. do
  86. iup_open.set_attribute(Current, "DROPFILESTARGET", boolean_to_yesno(state))
  87. end
  88. set_ellipsis (state: BOOLEAN)
  89. -- [Windows and GTK only]: add an ellipsis: "..." to the text if there
  90. -- is not enough space to render the entire string. Can be "YES" or "NO".
  91. -- Default: "False".
  92. do
  93. iup_open.set_attribute(Current, "ELLIPSIS", boolean_to_yesno(state))
  94. end
  95. set_image (name: STRING)
  96. -- (non inheritable): Image name. If set before map defines the behavior
  97. -- of the button to contain an image. The natural size will be size of
  98. -- the image in pixels. Use set_widget_name to associate an image to
  99. -- a name. See also IUP_IMAGE.
  100. do
  101. iup_open.set_attribute(Current, "IMAGE", name)
  102. end
  103. set_image_inactive (name: STRING)
  104. -- (non inheritable) [GTK and Motif only]: Image name of the element when
  105. -- inactive. If it is not defined then the IMAGE is used and the colors
  106. -- will be replaced by a modified version of the background color
  107. -- creating the disabled effect. GTK will also change the inactive image
  108. -- to look like other inactive objects.
  109. do
  110. iup_open.set_attribute(Current, "IMINACTIVE", name)
  111. end
  112. set_markup (state: BOOLEAN)
  113. -- [GTK only]: allows the title string to contains pango markup
  114. -- commands. Works only if a mnemonic is NOT defined in the title. Can
  115. -- be "True" or "False". Default: "False".
  116. do
  117. iup_open.set_attribute(Current, "MARKUP", boolean_to_yesno(state))
  118. end
  119. set_horizontal_separator
  120. -- (creation only) (non inheritable): Turns the label into a horizontal
  121. -- line separator. When changed before mapping the EXPAND attribute is
  122. -- set to "HORIZONTALFREE". (Since 3.11 changed to FREE based expand)
  123. do
  124. iup_open.set_attribute(Current, "SEPARATOR", "HORIZONTAL")
  125. end
  126. set_vertical_separator
  127. -- (creation only) (non inheritable): Turns the label into a vertical line
  128. -- separator. When changed before mapping the EXPAND attribute is set to
  129. -- "VERTICALFREE" accordingly. (Since 3.11 changed to FREE based expand)
  130. do
  131. iup_open.set_attribute(Current, "SEPARATOR", "VERTICAL")
  132. end
  133. set_word_wrap (state: BOOLEAN)
  134. -- [Windows and GTK only]: enables or disable the wrapping of lines that
  135. -- does not fits in the label. Can be "YES" or "NO". Default: "NO". Can
  136. -- only set WORDWRAP=YES if ALIGNMENT=ALEFT.
  137. do
  138. iup_open.set_attribute(Current, "WORDWRAP", boolean_to_yesno(state))
  139. end
  140. -- Validations
  141. is_valid_alignment (horizontal, vertical: STRING): BOOLEAN
  142. local
  143. h, v: BOOLEAN
  144. do
  145. if horizontal.is_equal("ALEFT") or
  146. horizontal.is_equal("ACENTER") or
  147. horizontal.is_equal("ARIGHT") then
  148. h := True
  149. else
  150. h := False
  151. end
  152. if vertical.is_equal("ATOP") or
  153. vertical.is_equal("ACENTER") or
  154. vertical.is_equal("ABOTTOM") then
  155. v := True
  156. else
  157. v := False
  158. end
  159. if h and v then
  160. Result := True
  161. else
  162. Result := False
  163. end
  164. end
  165. -- Callbacks
  166. -- Common
  167. set_cb_map (act: detachable FUNCTION[TUPLE[IUP_LABEL], STRING])
  168. -- Called right after an element is mapped and its attributes updated.
  169. local
  170. operation: INTEGER
  171. do
  172. cb_map := act
  173. if cb_map /= Void then
  174. operation := 1
  175. else
  176. operation := 0
  177. end
  178. iup_open.set_callback (Current, "MAP_CB", "NONEEDED", operation)
  179. end
  180. set_cb_unmap (act: detachable FUNCTION[TUPLE[IUP_LABEL], STRING])
  181. -- Called right before an element is unmapped.
  182. local
  183. operation: INTEGER
  184. do
  185. cb_unmap := act
  186. if cb_unmap /= Void then
  187. operation := 1
  188. else
  189. operation := 0
  190. end
  191. iup_open.set_callback (Current, "UNMAP_CB", "NONEEDED", operation)
  192. end
  193. set_cb_destroy (act: detachable FUNCTION[TUPLE[IUP_LABEL], STRING])
  194. -- Called right before an element is destroyed.
  195. local
  196. operation: INTEGER
  197. do
  198. cb_destroy := act
  199. if cb_destroy /= Void then
  200. operation := 1
  201. else
  202. operation := 0
  203. end
  204. iup_open.set_callback (Current, "DESTROY_CB", "NONEEDED", operation)
  205. end
  206. set_cb_enter_window (act: detachable FUNCTION[TUPLE[IUP_LABEL], STRING])
  207. -- Action generated when the mouse enters the native element.
  208. local
  209. operation: INTEGER
  210. do
  211. cb_enterwindow := act
  212. if cb_enterwindow /= Void then
  213. operation := 1
  214. else
  215. operation := 0
  216. end
  217. iup_open.set_callback (Current, "ENTERWINDOW_CB", "NONEEDED", operation)
  218. end
  219. set_cb_leave_window (act: detachable FUNCTION[TUPLE[IUP_LABEL], STRING])
  220. -- Action generated when the mouse leaves the native element.
  221. local
  222. operation: INTEGER
  223. do
  224. cb_leavewindow := act
  225. if cb_leavewindow /= Void then
  226. operation := 1
  227. else
  228. operation := 0
  229. end
  230. iup_open.set_callback (Current, "LEAVEWINDOW_CB", "NONEEDED", operation)
  231. end
  232. -- Extra
  233. set_cb_button (act: detachable FUNCTION[TUPLE[IUP_LABEL, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING])
  234. -- Action generated when any mouse button is pressed and when it is
  235. -- released. Both calls occur before the ACTION callback when button 1 is
  236. -- being used.
  237. --
  238. -- IUP_BUTTON: identifies the element that activated the event.
  239. -- button: identifies the activated mouse button:
  240. --
  241. -- 1 - left mouse button (button 1);
  242. -- 2 - middle mouse button (button 2);
  243. -- 3 - right mouse button (button 3).
  244. --
  245. -- pressed: indicates the state of the button:
  246. --
  247. -- 0 - mouse button was released;
  248. -- 1 - mouse button was pressed.
  249. --
  250. -- x, y: position in the canvas where the event has occurred, in pixels.
  251. --
  252. -- status: status of the mouse buttons and some keyboard keys at the
  253. -- moment the event is generated. The following IUP features must be used
  254. -- for verification:
  255. --
  256. -- is_shift(status)
  257. -- is_control(status)
  258. -- is_button_1(status)
  259. -- is_button_2(status)
  260. -- is_button_3(status)
  261. -- is_button_4(status)
  262. -- is_button_5(status)
  263. -- is_double(status)
  264. -- is_alt(status)
  265. -- is_sys(status)
  266. --
  267. -- Returns: IUP_CLOSE will be processed. On some controls if IUP_IGNORE
  268. -- is returned the action is ignored (this is system dependent).
  269. local
  270. operation: INTEGER
  271. do
  272. cb_button := act
  273. if cb_button /= Void then
  274. operation := 1
  275. else
  276. operation := 0
  277. end
  278. iup_open.set_callback (Current, "BUTTON_CB", "NONEEDED", operation)
  279. end
  280. set_cb_motion (act: detachable FUNCTION[TUPLE[IUP_LABEL, INTEGER, INTEGER, STRING], STRING])
  281. -- Action generated when the mouse moves.
  282. -- ih: identifier of the element that activated the event.
  283. -- x, y: position in the canvas where the event has occurred, in pixels.
  284. -- status: status of mouse buttons and certain keyboard keys at the
  285. -- moment the event was generated. The same macros used for BUTTON_CB can
  286. -- be used for this status.
  287. local
  288. operation: INTEGER
  289. do
  290. cb_motion := act
  291. if cb_motion /= Void then
  292. operation := 1
  293. else
  294. operation := 0
  295. end
  296. iup_open.set_callback (Current, "MOTION_CB", "NONEEDED", operation)
  297. end
  298. set_cb_drop_files (act: detachable FUNCTION[TUPLE[IUP_LABEL, STRING, INTEGER, INTEGER, INTEGER], STRING])
  299. local
  300. operation: INTEGER
  301. do
  302. cb_dropfiles := act
  303. if cb_dropfiles /= Void then
  304. operation := 1
  305. else
  306. operation := 0
  307. end
  308. iup_open.set_callback (Current, "DROPFILES_CB", "NONEEDED", operation)
  309. end
  310. feature {IUP}
  311. execute_map: STRING
  312. do
  313. if attached cb_map as int_cb then
  314. Result := int_cb.item([Current])
  315. else
  316. Result := "IUP_DEFAULT"
  317. end
  318. end
  319. execute_unmap: STRING
  320. do
  321. if attached cb_unmap as int_cb then
  322. Result := int_cb.item([Current])
  323. else
  324. Result := "IUP_DEFAULT"
  325. end
  326. end
  327. execute_destroy: STRING
  328. do
  329. if attached cb_destroy as int_cb then
  330. Result := int_cb.item([Current])
  331. else
  332. Result := "IUP_DEFAULT"
  333. end
  334. end
  335. execute_enterwindow: STRING
  336. do
  337. if attached cb_enterwindow as int_cb then
  338. Result := int_cb.item([Current])
  339. else
  340. Result := "IUP_DEFAULT"
  341. end
  342. end
  343. execute_leavewindow: STRING
  344. do
  345. if attached cb_leavewindow as int_cb then
  346. Result := int_cb.item([Current])
  347. else
  348. Result := "IUP_DEFAULT"
  349. end
  350. end
  351. execute_button (btn, pressed, x, y: INTEGER; status: STRING): STRING
  352. do
  353. if attached cb_button as int_cb then
  354. Result := int_cb.item([Current, btn, pressed, x, y, status])
  355. else
  356. Result := "IUP_DEFAULT"
  357. end
  358. end
  359. execute_motion (x, y: INTEGER; status: STRING): STRING
  360. do
  361. if attached cb_motion as int_cb then
  362. Result := int_cb.item([Current, x, y, status])
  363. else
  364. Result := "IUP_DEFAULT"
  365. end
  366. end
  367. execute_dropfiles (filename: STRING; num: INTEGER; x: INTEGER; y: INTEGER): STRING
  368. do
  369. if attached cb_dropfiles as int_cb then
  370. Result := int_cb.item([Current, filename, num, x, y])
  371. else
  372. Result := "IUP_DEFAULT"
  373. end
  374. end
  375. feature {NONE}
  376. -- For callbacks
  377. cb_map: detachable FUNCTION[TUPLE[IUP_LABEL], STRING]
  378. cb_unmap: detachable FUNCTION[TUPLE[IUP_LABEL], STRING]
  379. cb_destroy: detachable FUNCTION[TUPLE[IUP_LABEL], STRING]
  380. cb_enterwindow: detachable FUNCTION[TUPLE[IUP_LABEL], STRING]
  381. cb_leavewindow: detachable FUNCTION[TUPLE[IUP_LABEL], STRING]
  382. cb_button: detachable FUNCTION[TUPLE[IUP_LABEL, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING]
  383. cb_motion: detachable FUNCTION[TUPLE[IUP_LABEL, INTEGER, INTEGER, STRING], STRING]
  384. cb_dropfiles: detachable FUNCTION[TUPLE[IUP_LABEL, STRING, INTEGER, INTEGER, INTEGER], STRING]
  385. -- Internals
  386. int_label (text: POINTER): POINTER
  387. external
  388. "C inline use %"eiffel-iup.h%""
  389. alias
  390. "return IupLabel ($text);"
  391. end
  392. end -- class IUP_LABEL
  393. -- The MIT License (MIT)
  394. -- Copyright (c) 2016, 2017, 2018, 2019, 2020 by German A. Arias
  395. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  396. -- of this software and associated documentation files (the "Software"), to deal
  397. -- in the Software without restriction, including without limitation the rights
  398. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  399. -- copies of the Software, and to permit persons to whom the Software is
  400. -- furnished to do so, subject to the following conditions:
  401. --
  402. -- The above copyright notice and this permission notice shall be included in
  403. -- all copies or substantial portions of the Software.
  404. --
  405. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  406. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  407. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  408. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  409. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  410. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  411. -- SOFTWARE.