iup_flat_frame.e 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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: the global attribute
  77. -- DLGFGCOLOR.
  78. do
  79. iup_open.set_attribute(Current, "FRAMECOLOR", rgb_to_string(red, green, blue))
  80. end
  81. get_rgb_frame_color: TUPLE[INTEGER, INTEGER, INTEGER]
  82. do
  83. Result := iup_open.get_rgb(Current, "FRAMECOLOR")
  84. end
  85. set_frame_width (value: INTEGER)
  86. -- (non inheritable): frame line width. Default: 1.
  87. require
  88. value > 0
  89. do
  90. iup_open.set_attribute(Current, "FRAMEWIDTH", value.to_string)
  91. end
  92. get_frame_width: INTEGER
  93. local
  94. str: STRING
  95. do
  96. str := iup_open.get_attribute(Current, "FRAMEWIDTH")
  97. Result := str.to_integer
  98. end
  99. set_frame_space (value: INTEGER)
  100. -- (non inheritable): spacing between frame line and child area. Used
  101. -- only when FRAME=True. Default: 2.
  102. require
  103. value >= 0
  104. do
  105. iup_open.set_attribute(Current, "FRAMESPACE", value.to_string)
  106. end
  107. get_frame_space: INTEGER
  108. local
  109. str: STRING
  110. do
  111. str := iup_open.get_attribute(Current, "FRAMESPACE")
  112. Result := str.to_integer
  113. end
  114. set_rgb_title_color (red: INTEGER; green: INTEGER; blue: INTEGER)
  115. -- (non inheritable): title text color. Default: the global attribute
  116. -- DLGFGCOLOR.
  117. do
  118. iup_open.set_attribute(Current, "TITLECOLOR", rgb_to_string(red, green, blue))
  119. end
  120. get_rgb_title_color: TUPLE[INTEGER, INTEGER, INTEGER]
  121. do
  122. Result := iup_open.get_rgb(Current, "TITLECOLOR")
  123. end
  124. set_rgb_title_background_color (red: INTEGER; green: INTEGER; blue: INTEGER)
  125. -- (non inheritable): background color of the title area. Default: the
  126. -- global attribute DLGBGCOLOR.
  127. do
  128. iup_open.set_attribute(Current, "TITLEBGCOLOR", rgb_to_string(red, green, blue))
  129. end
  130. get_rgb_title_background_color: TUPLE[INTEGER, INTEGER, INTEGER]
  131. do
  132. Result := iup_open.get_rgb(Current, "TITLEBGCOLOR")
  133. end
  134. set_title_line (state: BOOLEAN)
  135. -- (non inheritable): enables the title line. Horizontal line that
  136. -- separates the title area from the child area. Default: True.
  137. do
  138. iup_open.set_attribute(Current, "TITLELINE", boolean_to_yesno(state))
  139. end
  140. has_title_line: BOOLEAN
  141. local
  142. str: STRING
  143. do
  144. str := iup_open.get_attribute(Current, "TITLELINE")
  145. Result := yesno_to_boolean(str)
  146. end
  147. set_rgb_title_line_color (red: INTEGER; green: INTEGER; blue: INTEGER)
  148. -- (non inheritable): title line color. Default: the global attribute
  149. -- DLGFGCOLOR.
  150. do
  151. iup_open.set_attribute(Current, "TITLELINECOLOR", rgb_to_string(red, green, blue))
  152. end
  153. get_rgb_title_line_color: TUPLE[INTEGER, INTEGER, INTEGER]
  154. do
  155. Result := iup_open.get_rgb(Current, "TITLELINECOLOR")
  156. end
  157. set_title_line_width (value: INTEGER)
  158. -- (non inheritable): title line width. Default: 1.
  159. require
  160. value > 0
  161. do
  162. iup_open.set_attribute(Current, "TITLELINEWIDTH", value.to_string)
  163. end
  164. get_title_line_width: INTEGER
  165. local
  166. str: STRING
  167. do
  168. str := iup_open.get_attribute(Current, "TITLELINEWIDTH")
  169. Result := str.to_integer
  170. end
  171. set_title_image (imagename: STRING)
  172. -- (non inheritable): image name to be used in title. Use
  173. -- set_attribute_handle to associate an image to a name.
  174. -- See also IUP_IMAGE.
  175. do
  176. iup_open.set_attribute(Current, "TITLEIMAGE", imagename)
  177. end
  178. get_title_image: STRING
  179. do
  180. Result := iup_open.get_attribute(Current, "TITLEIMAGE")
  181. end
  182. set_title_image_inactive (imagename: STRING)
  183. -- (non inheritable): image used in title when inactive. If it is not
  184. -- defined then the TITLEIMAGE is used and its colors will be replaced by
  185. -- a modified version creating the disabled effect.
  186. do
  187. iup_open.set_attribute(Current, "TITLEIMAGEINACTIVE", imagename)
  188. end
  189. get_title_image_inactive: STRING
  190. do
  191. Result := iup_open.get_attribute(Current, "TITLEIMAGEINACTIVE")
  192. end
  193. set_title_image_position (position: STRING)
  194. -- (non inheritable): position of the image relative to the text when
  195. -- both are displayed. Can be: LEFT, RIGHT, TOP, BOTTOM. Default: LEFT.
  196. require
  197. is_valid_position(position)
  198. do
  199. iup_open.set_attribute(Current, "TITLEIMAGEPOSITION", position)
  200. end
  201. get_title_image_position: STRING
  202. do
  203. Result := iup_open.get_attribute(Current, "TITLEIMAGEPOSITION")
  204. end
  205. set_title_image_spacing (value: INTEGER)
  206. -- (non inheritable): spacing between the image and the text.
  207. -- Default: "2".
  208. require
  209. value >= 0
  210. do
  211. iup_open.set_attribute(Current, "TITLEIMAGESPACING", value.to_string)
  212. end
  213. get_title_image_spacing: INTEGER
  214. local
  215. str: STRING
  216. do
  217. str := iup_open.get_attribute(Current, "TITLEIMAGESPACING")
  218. Result := str.to_integer
  219. end
  220. set_title_alignment (value: STRING)
  221. -- (non inheritable): horizontal alignment. Possible values: "ALEFT",
  222. -- "ACENTER" and "ARIGHT". Default: "ACENTER".
  223. require
  224. is_valid_horizontal_alignment(value)
  225. do
  226. iup_open.set_attribute(Current, "TITLEALIGNMENT", value)
  227. end
  228. get_title_alignment: STRING
  229. do
  230. Result := iup_open.get_attribute(Current, "TITLEALIGNMENT")
  231. end
  232. set_title_text_alignment (value: STRING)
  233. -- (non inheritable): horizontal text alignment for multiple lines. Can
  234. -- be: ALEFT, ARIGHT or ACENTER. Default: ALEFT.
  235. require
  236. is_valid_horizontal_alignment(value)
  237. do
  238. iup_open.set_attribute(Current, "TITLETEXTALIGNMENT", value)
  239. end
  240. get_title_text_alignment: STRING
  241. do
  242. Result := iup_open.get_attribute(Current, "TITLETEXTALIGNMENT")
  243. end
  244. set_title_padding (horizontal, vertical: INTEGER)
  245. -- (non inheritable): title internal margin. Default value: "0x0".
  246. local
  247. str: STRING
  248. do
  249. create str.copy(horizontal.to_string)
  250. str.append_string("x")
  251. str.append_string(vertical.to_string)
  252. iup_open.set_attribute(Current, "TITLEPADDING", str)
  253. end
  254. get_title_padding: TUPLE[INTEGER, INTEGER]
  255. local
  256. str: STRING
  257. do
  258. str := iup_open.get_attribute(Current, "TITLEPADDING")
  259. Result := components_of (str, 'x')
  260. end
  261. feature {}
  262. -- Internals
  263. int_flat_frame_empty (arguments: POINTER): POINTER
  264. external "plug_in"
  265. alias "{
  266. location: "${sys}/plugins"
  267. module_name: "iup"
  268. feature_name: "IupFlatFrame"
  269. }"
  270. end
  271. int_flat_frame (arguments: POINTER): POINTER
  272. external "plug_in"
  273. alias "{
  274. location: "${sys}/plugins"
  275. module_name: "iup"
  276. feature_name: "IupFlatFrame"
  277. }"
  278. end
  279. -- Validations
  280. is_valid_position (value: STRING): BOOLEAN
  281. do
  282. if value.is_equal("LEFT") or
  283. value.is_equal("RIGHT") or
  284. value.is_equal("TOP") or
  285. value.is_equal("BOTTON") then
  286. Result := True
  287. else
  288. Result := False
  289. end
  290. end
  291. end
  292. -- The MIT License (MIT)
  293. -- Copyright (c) 2017, 2018, 2019 by German A. Arias
  294. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  295. -- of this software and associated documentation files (the "Software"), to deal
  296. -- in the Software without restriction, including without limitation the rights
  297. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  298. -- copies of the Software, and to permit persons to whom the Software is
  299. -- furnished to do so, subject to the following conditions:
  300. --
  301. -- The above copyright notice and this permission notice shall be included in
  302. -- all copies or substantial portions of the Software.
  303. --
  304. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  305. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  306. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  307. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  308. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  309. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  310. -- SOFTWARE.