iup_widget_text_common.e 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. deferred class IUP_WIDGET_TEXT_COMMON
  2. -- Common attributes related with text controls.
  3. inherit
  4. IUP_WIDGET_INTERNALS
  5. IUP_WIDGET_PADDING
  6. feature {ANY}
  7. clipboard (option: STRING)
  8. -- (write-only): clear, cut, copy or paste the selection to or from the
  9. -- clipboard. Values: "CLEAR", "CUT", "COPY" or "PASTE". In Windows UNDO
  10. -- is also available, and REDO is available when FORMATTING=True.
  11. require
  12. is_valid_option(option)
  13. do
  14. iup_open.set_attribute(Current, "CLIPBOARD", option)
  15. end
  16. set_cue_banner (txt: STRING)
  17. -- [Windows and GTK Only] (non inheritable): a text that is displayed
  18. -- when there is no text at the control. It works as a textual cue, or
  19. -- tip to prompt the user for input. Valid only for MULTILINE=False, and
  20. -- works only when Visual Styles are enabled. (since 3.0) [GTK 3.2] (GTK
  21. -- support added in IUP 3.20).
  22. do
  23. iup_open.set_attribute(Current, "CUEBANNER", txt)
  24. end
  25. set_filter (filter: STRING)
  26. -- [Windows Only] (non inheritable): allows a custom filter to process
  27. -- the characters: Can be LOWERCASE, UPPERCASE or NUMBER (only numbers
  28. -- allowed).
  29. require
  30. is_valid_filter(filter)
  31. do
  32. iup_open.set_attribute(Current, "FILTER", filter)
  33. end
  34. set_mask (mask: STRING)
  35. -- (non inheritable): Defines a mask that will filter interactive text
  36. -- input. Use "REMOVE" to remove the mask.
  37. --
  38. -- Since the validation process is performed key by key when the user is
  39. -- typing, an intermediate value cannot be typed if it does not follow
  40. -- the mask rules.
  41. --
  42. -- If you set the VALUE attribute any text can be used. To set a value
  43. -- that is validated by the current MASK use VALUEMASKED.
  44. --
  45. -- Pre-Defined Masks
  46. --
  47. -- Definition Value Description
  48. -- IUP_MASK_INT "[+/-]?/d+" integer number
  49. -- IUP_MASK_UINT "/d+" unsigned integer number
  50. -- IUP_MASK_FLOAT "[+/-]?(/d+/.?/d*|/./d+)" floating point number
  51. -- IUP_MASK_UFLOAT "(/d+/.?/d*|/./d+)" unsigned floating point number
  52. -- IUP_MASK_EFLOAT "[+/-]?(/d+/.?/d*|/./d+)([eE][+/-]?/d+)?" floating
  53. -- point number with exponential notation
  54. -- IUP_MASK_FLOATCOMMA "[+/-]?(/d+/,?/d*|/,/d+)" floating point number
  55. -- IUP_MASK_UFLOATCOMMA "(/d+/,?/d*|/,/d+)" unsigned floating point number
  56. --
  57. -- For more information see:
  58. -- http://webserver2.tecgraf.puc-rio.br/iup/en/attrib/iup_mask.html
  59. do
  60. if mask.is_equal("REMOVE") then
  61. iup_open.set_attribute_null(Current, "MASK")
  62. elseif mask.is_equal("IUP_MASK_FLOAT") then
  63. iup_open.set_attribute(Current, "MASK", "[+/-]?(/d+/.?/d*|/./d+)")
  64. elseif mask.is_equal("IUP_MASK_UFLOAT") then
  65. iup_open.set_attribute(Current, "MASK", "(/d+/.?/d*|/./d+)")
  66. elseif mask.is_equal("IUP_MASK_EFLOAT") then
  67. iup_open.set_attribute(Current, "MASK", "[+/-]?(/d+/.?/d*|/./d+)([eE][+/-]?/d+)?")
  68. elseif mask.is_equal("IUP_MASK_FLOATCOMMA") then
  69. iup_open.set_attribute(Current, "MASK", "[+/-]?(/d+/,?/d*|/,/d+)")
  70. elseif mask.is_equal("IUP_MASK_UFLOATCOMMA") then
  71. iup_open.set_attribute(Current, "MASK", "(/d+/,?/d*|/,/d+)")
  72. elseif mask.is_equal("IUP_MASK_INT") then
  73. iup_open.set_attribute(Current, "MASK", "[+/-]?/d+")
  74. elseif mask.is_equal("IUP_MASK_UINT") then
  75. iup_open.set_attribute(Current, "MASK", "/d+")
  76. else
  77. iup_open.set_attribute(Current, "MASK", mask)
  78. end
  79. end
  80. set_mask_case_insesitive (state: BOOLEAN)
  81. -- If True, will turn the filter case insensitive. Default: False.
  82. do
  83. iup_open.set_attribute(Current, "MASKCASEI", boolean_to_yesno(state))
  84. end
  85. set_mask_no_empty (state: BOOLEAN)
  86. -- If True, value can NOT be Void or empty. Default: False (can be
  87. -- empty or Void).
  88. do
  89. iup_open.set_attribute(Current, "MASKNOEMPTY", boolean_to_yesno(state))
  90. end
  91. set_mask_decimal_symbol (value: STRING)
  92. -- The decimal symbol for string/float conversion. Can be "." or ",".
  93. -- Must be set before MASKFLOAT.
  94. require
  95. is_valid_symbol (value)
  96. do
  97. iup_open.set_attribute(Current, "MASKDECIMALSYMBOL", value)
  98. end
  99. set_mask_integer (min, max: INTEGER)
  100. -- Defines an integer mask with limits "min-max". It will replace MASK
  101. -- using one of the pre-defined masks.
  102. local
  103. str: STRING
  104. do
  105. str := min.out
  106. str.append_string(":")
  107. str.append_string(max.out)
  108. iup_open.set_attribute(Current, "MASKINT", str)
  109. end
  110. set_mask_float (min, max: REAL_64)
  111. -- Defines a floating point mask with limits "min:max". It will replace
  112. -- MASK using one of the pre-defined masks.
  113. local
  114. str: STRING
  115. do
  116. str := min.out
  117. str.append_string(":")
  118. str.append_string(max.out)
  119. iup_open.set_attribute(Current, "MASKFLOAT", str)
  120. end
  121. set_number_of_characters (num: INTEGER)
  122. -- Maximum number of characters allowed for keyboard input, larger text
  123. -- can still be set using attributes. The maximum value is the limit of
  124. -- the VALUE attribute. The "0" value don't impose a limit. Default: "0".
  125. require
  126. num >= 0
  127. do
  128. iup_open.set_attribute(Current, "NC", num.out)
  129. end
  130. set_readonly (state: BOOLEAN)
  131. -- Allows the user only to read the contents, without changing it.
  132. -- Restricts keyboard input only, text value can still be changed using
  133. -- attributes. Navigation keys are still available. Possible values:
  134. -- "True", "False". Default: False.
  135. do
  136. iup_open.set_attribute(Current, "READONLY", boolean_to_yesno(state))
  137. end
  138. set_selected_text (value: STRING)
  139. -- Replaces the current selection. Similar to INSERT, but does nothing if
  140. -- there is no selection.
  141. do
  142. iup_open.set_attribute(Current, "SELECTEDTEXT", value)
  143. end
  144. get_selected_text: STRING
  145. -- Selected text. Returns "" if there is no selection.
  146. local
  147. str: STRING
  148. do
  149. str := iup_open.get_attribute(Current, "SELECTEDTEXT")
  150. if str /= Void then
  151. Result := str
  152. else
  153. Result := ""
  154. end
  155. end
  156. select_all
  157. -- Select all the text.
  158. do
  159. iup_open.set_attribute(Current, "SELECTION", "ALL")
  160. end
  161. deselect_all
  162. -- Deselect.
  163. do
  164. iup_open.set_attribute(Current, "SELECTION", "NONE")
  165. end
  166. -- Changes
  167. append (txt: STRING)
  168. -- Inserts a text at the end of the current text.
  169. do
  170. iup_open.set_attribute(Current, "APPEND", txt)
  171. end
  172. insert (txt: STRING)
  173. -- (write-only): Inserts a text in the caret's position, also replaces
  174. -- the current selection if any. Ignored if set before map.
  175. do
  176. iup_open.set_attribute(Current, "INSERT", txt)
  177. end
  178. -- Internals
  179. is_valid_option (value: STRING): BOOLEAN
  180. do
  181. if value.is_equal("CLEAR") or
  182. value.is_equal("CUT") or
  183. value.is_equal("COPY") or
  184. value.is_equal("PASTE") or
  185. value.is_equal("UNDO") or
  186. value.is_equal("REDO") then
  187. Result := True
  188. else
  189. Result := False
  190. end
  191. end
  192. is_valid_filter (value: STRING): BOOLEAN
  193. do
  194. if value.is_equal("LOWERCASE") or
  195. value.is_equal("UPPERCASE") or
  196. value.is_equal("NUMBER") then
  197. Result := True
  198. else
  199. Result := False
  200. end
  201. end
  202. is_valid_symbol (value: STRING): BOOLEAN
  203. do
  204. if value.is_equal(".") or
  205. value.is_equal(",") then
  206. Result := True
  207. else
  208. Result := False
  209. end
  210. end
  211. end
  212. -- The MIT License (MIT)
  213. -- Copyright (c) 2016, 2017, 2018, 2019 by German A. Arias
  214. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  215. -- of this software and associated documentation files (the "Software"), to deal
  216. -- in the Software without restriction, including without limitation the rights
  217. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  218. -- copies of the Software, and to permit persons to whom the Software is
  219. -- furnished to do so, subject to the following conditions:
  220. --
  221. -- The above copyright notice and this permission notice shall be included in
  222. -- all copies or substantial portions of the Software.
  223. --
  224. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  225. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  226. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  227. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  228. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  229. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  230. -- SOFTWARE.