iup_label.e 12 KB

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