iup_flat_frame.e 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. class IUP_FLAT_FRAME
  2. -- Creates a native container, which draws a frame with a title around its
  3. -- child. The decorations are manually drawn. The control inherits from
  4. -- IUP_BACKGROUND_BOX. Inherits all attributes and callbacks of the IUP_CANVAS,
  5. -- but redefines a few attributes.
  6. inherit
  7. IUP_BACKGROUND_BOX
  8. rename
  9. background_box_empty as flat_frame_empty,
  10. background_box as flat_frame
  11. redefine
  12. flat_frame_empty,
  13. flat_frame,
  14. set_rgb_background_color,
  15. set_decoration
  16. end
  17. IUP_WIDGET_TITLE
  18. IUP_WIDGET_FLAT_TEXT
  19. create {ANY}
  20. flat_frame_empty,
  21. flat_frame
  22. feature {ANY}
  23. flat_frame_empty
  24. -- Create an empty flat frame.
  25. local
  26. a_flat_frame, p: POINTER
  27. do
  28. a_flat_frame := int_flat_frame (p)
  29. set_widget(a_flat_frame)
  30. end
  31. flat_frame (child: IUP_WIDGET)
  32. -- Create a flat frame with the child.
  33. --
  34. -- child: Identifier of an interface element which will receive the frame
  35. -- around.
  36. local
  37. a_flat_frame: POINTER
  38. do
  39. a_flat_frame := int_flat_frame (child.widget)
  40. set_widget(a_flat_frame)
  41. end
  42. -- Attributes
  43. set_decoration (state: BOOLEAN)
  44. -- Does nothing since the frame always have a decoration.
  45. do
  46. end
  47. set_rgb_background_color (red: INTEGER; green: INTEGER; blue: INTEGER)
  48. -- Background color of the child area. If not defined it will use the
  49. -- background color of the native parent.
  50. do
  51. Precursor (red, green, blue)
  52. end
  53. disable_frame
  54. -- (non inheritable): Disables the frame line.
  55. do
  56. iup_open.set_attribute(Current, "FRAME", "NO")
  57. end
  58. set_frame_line
  59. -- (non inheritable): Enables the frame line.
  60. do
  61. iup_open.set_attribute(Current, "FRAME", "YES")
  62. end
  63. set_frame_cross_title
  64. -- (non inheritable): Enables the frame cross title.
  65. do
  66. iup_open.set_attribute(Current, "FRAME", "CROSSTITLE")
  67. end
  68. get_frame_value: STRING
  69. local
  70. str: STRING
  71. do
  72. str := iup_open.get_attribute(Current, "FRAME")
  73. Result := str
  74. end
  75. set_rgb_frame_color (red: INTEGER; green: INTEGER; blue: INTEGER)
  76. -- (non inheritable): frame line color. Default: "160 160 160"
  77. do
  78. iup_open.set_attribute(Current, "FRAMECOLOR", rgb_to_string(red, green, blue))
  79. end
  80. get_rgb_frame_color: TUPLE[INTEGER, INTEGER, INTEGER]
  81. do
  82. Result := iup_open.get_rgb(Current, "FRAMECOLOR")
  83. end
  84. set_frame_width (value: INTEGER)
  85. -- (non inheritable): frame line width. Default: 1.
  86. require
  87. value > 0
  88. do
  89. iup_open.set_attribute(Current, "FRAMEWIDTH", value.out)
  90. end
  91. get_frame_width: INTEGER
  92. local
  93. str: STRING
  94. do
  95. str := iup_open.get_attribute(Current, "FRAMEWIDTH")
  96. Result := str.to_integer
  97. end
  98. set_frame_space (value: INTEGER)
  99. -- (non inheritable): spacing between frame line and child area. Used
  100. -- only when FRAME=True. Default: 2.
  101. require
  102. value >= 0
  103. do
  104. iup_open.set_attribute(Current, "FRAMESPACE", value.out)
  105. end
  106. get_frame_space: INTEGER
  107. local
  108. str: STRING
  109. do
  110. str := iup_open.get_attribute(Current, "FRAMESPACE")
  111. Result := str.to_integer
  112. end
  113. set_rgb_title_color (red: INTEGER; green: INTEGER; blue: INTEGER)
  114. -- (non inheritable): title text color. Default: the global attribute
  115. -- DLGFGCOLOR.
  116. do
  117. iup_open.set_attribute(Current, "TITLECOLOR", rgb_to_string(red, green, blue))
  118. end
  119. get_rgb_title_color: TUPLE[INTEGER, INTEGER, INTEGER]
  120. do
  121. Result := iup_open.get_rgb(Current, "TITLECOLOR")
  122. end
  123. set_rgb_title_background_color (red: INTEGER; green: INTEGER; blue: INTEGER)
  124. -- (non inheritable): background color of the title area. Default: the
  125. -- global attribute DLGBGCOLOR.
  126. do
  127. iup_open.set_attribute(Current, "TITLEBGCOLOR", rgb_to_string(red, green, blue))
  128. end
  129. get_rgb_title_background_color: TUPLE[INTEGER, INTEGER, INTEGER]
  130. do
  131. Result := iup_open.get_rgb(Current, "TITLEBGCOLOR")
  132. end
  133. set_title_line (state: BOOLEAN)
  134. -- (non inheritable): enables the title line. Horizontal line that
  135. -- separates the title area from the child area. Default: True.
  136. do
  137. iup_open.set_attribute(Current, "TITLELINE", boolean_to_yesno(state))
  138. end
  139. has_title_line: BOOLEAN
  140. local
  141. str: STRING
  142. do
  143. str := iup_open.get_attribute(Current, "TITLELINE")
  144. Result := yesno_to_boolean(str)
  145. end
  146. set_rgb_title_line_color (red: INTEGER; green: INTEGER; blue: INTEGER)
  147. -- (non inheritable): title line color. Default: the global attribute
  148. -- DLGFGCOLOR.
  149. do
  150. iup_open.set_attribute(Current, "TITLELINECOLOR", rgb_to_string(red, green, blue))
  151. end
  152. get_rgb_title_line_color: TUPLE[INTEGER, INTEGER, INTEGER]
  153. do
  154. Result := iup_open.get_rgb(Current, "TITLELINECOLOR")
  155. end
  156. set_title_line_width (value: INTEGER)
  157. -- (non inheritable): title line width. Default: 1.
  158. require
  159. value > 0
  160. do
  161. iup_open.set_attribute(Current, "TITLELINEWIDTH", value.out)
  162. end
  163. get_title_line_width: INTEGER
  164. local
  165. str: STRING
  166. do
  167. str := iup_open.get_attribute(Current, "TITLELINEWIDTH")
  168. Result := str.to_integer
  169. end
  170. set_title_image (imagename: STRING)
  171. -- (non inheritable): image name to be used in title. Use
  172. -- set_widget_name to associate an image to a name.
  173. -- See also IUP_IMAGE.
  174. do
  175. iup_open.set_attribute(Current, "TITLEIMAGE", imagename)
  176. end
  177. get_title_image: STRING
  178. do
  179. Result := iup_open.get_attribute(Current, "TITLEIMAGE")
  180. end
  181. set_title_image_inactive (imagename: STRING)
  182. -- (non inheritable): image used in title when inactive. If it is not
  183. -- defined then the TITLEIMAGE is used and its colors will be replaced by
  184. -- a modified version creating the disabled effect.
  185. do
  186. iup_open.set_attribute(Current, "TITLEIMAGEINACTIVE", imagename)
  187. end
  188. get_title_image_inactive: STRING
  189. do
  190. Result := iup_open.get_attribute(Current, "TITLEIMAGEINACTIVE")
  191. end
  192. set_title_image_position (position: STRING)
  193. -- (non inheritable): position of the image relative to the text when
  194. -- both are displayed. Can be: LEFT, RIGHT, TOP, BOTTOM. Default: LEFT.
  195. require
  196. is_valid_position(position)
  197. do
  198. iup_open.set_attribute(Current, "TITLEIMAGEPOSITION", position)
  199. end
  200. get_title_image_position: STRING
  201. do
  202. Result := iup_open.get_attribute(Current, "TITLEIMAGEPOSITION")
  203. end
  204. set_title_image_spacing (value: INTEGER)
  205. -- (non inheritable): spacing between the image and the text.
  206. -- Default: "2".
  207. require
  208. value >= 0
  209. do
  210. iup_open.set_attribute(Current, "TITLEIMAGESPACING", value.out)
  211. end
  212. get_title_image_spacing: INTEGER
  213. local
  214. str: STRING
  215. do
  216. str := iup_open.get_attribute(Current, "TITLEIMAGESPACING")
  217. Result := str.to_integer
  218. end
  219. set_title_alignment (value: STRING)
  220. -- (non inheritable): horizontal alignment. Possible values: "ALEFT",
  221. -- "ACENTER" and "ARIGHT". Default: "ACENTER".
  222. require
  223. is_valid_horizontal_alignment(value)
  224. do
  225. iup_open.set_attribute(Current, "TITLEALIGNMENT", value)
  226. end
  227. get_title_alignment: STRING
  228. do
  229. Result := iup_open.get_attribute(Current, "TITLEALIGNMENT")
  230. end
  231. set_title_text_alignment (value: STRING)
  232. -- (non inheritable): horizontal text alignment for multiple lines. Can
  233. -- be: ALEFT, ARIGHT or ACENTER. Default: ALEFT.
  234. require
  235. is_valid_horizontal_alignment(value)
  236. do
  237. iup_open.set_attribute(Current, "TITLETEXTALIGNMENT", value)
  238. end
  239. get_title_text_alignment: STRING
  240. do
  241. Result := iup_open.get_attribute(Current, "TITLETEXTALIGNMENT")
  242. end
  243. set_title_padding (horizontal, vertical: INTEGER)
  244. -- (non inheritable): title internal margin. Default value: "0x0".
  245. local
  246. str: STRING
  247. do
  248. create str.make_from_string(horizontal.out)
  249. str.append_string("x")
  250. str.append_string(vertical.out)
  251. iup_open.set_attribute(Current, "TITLEPADDING", str)
  252. end
  253. get_title_padding: TUPLE[INTEGER, INTEGER]
  254. local
  255. str: STRING
  256. do
  257. str := iup_open.get_attribute(Current, "TITLEPADDING")
  258. Result := components_of (str, 'x')
  259. end
  260. -- Validations
  261. is_valid_position (value: STRING): BOOLEAN
  262. do
  263. if value.is_equal("LEFT") or
  264. value.is_equal("RIGHT") or
  265. value.is_equal("TOP") or
  266. value.is_equal("BOTTON") then
  267. Result := True
  268. else
  269. Result := False
  270. end
  271. end
  272. feature {NONE}
  273. -- Internals
  274. int_flat_frame (arguments: POINTER): POINTER
  275. external
  276. "C inline use %"eiffel-iup.h%""
  277. alias
  278. "return IupFlatFrame ($arguments);"
  279. end
  280. end
  281. -- The MIT License (MIT)
  282. -- Copyright (c) 2017, 2018, 2019, 2022 by German A. Arias
  283. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  284. -- of this software and associated documentation files (the "Software"), to deal
  285. -- in the Software without restriction, including without limitation the rights
  286. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  287. -- copies of the Software, and to permit persons to whom the Software is
  288. -- furnished to do so, subject to the following conditions:
  289. --
  290. -- The above copyright notice and this permission notice shall be included in
  291. -- all copies or substantial portions of the Software.
  292. --
  293. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  294. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  295. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  296. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  297. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  298. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  299. -- SOFTWARE.