iup_calendar.e 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. class IUP_CALENDAR
  2. -- Creates a month calendar interface element, where the user can select a
  3. -- date.
  4. -- GTK and Windows only. NOT available in Motif.
  5. inherit
  6. IUP_WIDGET
  7. redefine
  8. execute_map,
  9. execute_unmap,
  10. execute_destroy,
  11. execute_getfocus,
  12. execute_killfocus,
  13. execute_enterwindow,
  14. execute_leavewindow,
  15. execute_k_any,
  16. execute_help,
  17. execute_valuechanged
  18. end
  19. IUP_WIDGET_INTERNALS
  20. IUP_WIDGET_CHILD
  21. IUP_WIDGET_NAME
  22. IUP_WIDGET_CUSTOM_ATTRIBUTES
  23. create {ANY}
  24. calendar
  25. feature {ANY}
  26. calendar
  27. -- Creates a month calendar interface element.
  28. local
  29. a_calendar: POINTER
  30. do
  31. a_calendar := int_calendar
  32. set_widget(a_calendar)
  33. end
  34. -- Attributes
  35. get_today: TUPLE[INTEGER, INTEGER, INTEGER]
  36. -- (read-only): Returns the date corresponding to today in format
  37. -- [year, month, day]".
  38. do
  39. Result := convert_date_to_tuple(get_string_today)
  40. end
  41. get_string_today: STRING
  42. -- (read-only): Returns the date corresponding to today in
  43. -- format "year/month/day".
  44. do
  45. Result := iup_open.get_attribute(Current, "TODAY")
  46. end
  47. set_value (year, month, day: INTEGER)
  48. -- The current date. Default value is the today date.
  49. require
  50. year >= 0
  51. month >= 1
  52. month <= 12
  53. day >= 1
  54. day <= 31
  55. local
  56. str: STRING
  57. do
  58. str := year.to_string
  59. str.append_string("/")
  60. str.append_string(month.to_string)
  61. str.append_string("/")
  62. str.append_string(day.to_string)
  63. iup_open.set_attribute(Current, "VALUE", str)
  64. end
  65. set_string_value (value: STRING)
  66. -- The current date always in the format "year/month/day".
  67. -- Default value is the today date.
  68. do
  69. iup_open.set_attribute(Current, "VALUE", value)
  70. end
  71. set_today
  72. -- Set value to today date.
  73. do
  74. iup_open.set_attribute(Current, "VALUE", "TODAY")
  75. end
  76. get_value: TUPLE[INTEGER, INTEGER, INTEGER]
  77. -- Return the selected date in format [year, month, day]".
  78. do
  79. Result := convert_date_to_tuple(get_string_value)
  80. end
  81. get_string_value: STRING
  82. -- Return the selected date in format "year/month/day".
  83. do
  84. Result := iup_open.get_attribute(Current, "VALUE")
  85. end
  86. set_week_number (state: BOOLEAN)
  87. -- Shows the number of the week along the year. Default: False.
  88. do
  89. iup_open.set_attribute(Current, "WEEKNUMBERS", boolean_to_yesno(state))
  90. end
  91. -- Callbacks
  92. -- Common
  93. set_cb_map (act: FUNCTION[TUPLE[IUP_CALENDAR], STRING])
  94. -- Called right after an element is mapped and its attributes updated.
  95. local
  96. operation: INTEGER
  97. do
  98. cb_map := act
  99. if cb_map /= Void then
  100. operation := 1
  101. else
  102. operation := 0
  103. end
  104. iup_open.set_callback (Current, "MAP_CB", "NONEEDED", operation)
  105. end
  106. set_cb_unmap (act: FUNCTION[TUPLE[IUP_CALENDAR], STRING])
  107. -- Called right before an element is unmapped.
  108. local
  109. operation: INTEGER
  110. do
  111. cb_unmap := act
  112. if cb_unmap /= Void then
  113. operation := 1
  114. else
  115. operation := 0
  116. end
  117. iup_open.set_callback (Current, "UNMAP_CB", "NONEEDED", operation)
  118. end
  119. set_cb_destroy (act: FUNCTION[TUPLE[IUP_CALENDAR], STRING])
  120. -- Called right before an element is destroyed.
  121. local
  122. operation: INTEGER
  123. do
  124. cb_destroy := act
  125. if cb_destroy /= Void then
  126. operation := 1
  127. else
  128. operation := 0
  129. end
  130. iup_open.set_callback (Current, "DESTROY_CB", "NONEEDED", operation)
  131. end
  132. set_cb_get_focus (act: FUNCTION[TUPLE[IUP_CALENDAR], STRING])
  133. -- Action generated when an element is given keyboard focus.
  134. -- This callback is called after the KILLFOCUS_CB of the element
  135. -- that loosed the focus. The {IUP}.get_focus function during the
  136. -- callback returns the element that loosed the focus.
  137. local
  138. operation: INTEGER
  139. do
  140. cb_getfocus := act
  141. if cb_getfocus /= Void then
  142. operation := 1
  143. else
  144. operation := 0
  145. end
  146. iup_open.set_callback (Current, "GETFOCUS_CB", "NONEEDED", operation)
  147. end
  148. set_cb_kill_focus (act: FUNCTION[TUPLE[IUP_CALENDAR], STRING])
  149. -- Action generated when an element loses keyboard focus. This
  150. -- callback is called before the GETFOCUS_CB of the element that
  151. -- gets the focus.
  152. local
  153. operation: INTEGER
  154. do
  155. cb_killfocus := act
  156. if cb_killfocus /= Void then
  157. operation := 1
  158. else
  159. operation := 0
  160. end
  161. iup_open.set_callback (Current, "KILLFOCUS_CB", "NONEEDED", operation)
  162. end
  163. set_cb_enter_window (act: FUNCTION[TUPLE[IUP_CALENDAR], STRING])
  164. -- Action generated when the mouse enters the native element.
  165. local
  166. operation: INTEGER
  167. do
  168. cb_enterwindow := act
  169. if cb_enterwindow /= Void then
  170. operation := 1
  171. else
  172. operation := 0
  173. end
  174. iup_open.set_callback (Current, "ENTERWINDOW_CB", "NONEEDED", operation)
  175. end
  176. set_cb_leave_window (act: FUNCTION[TUPLE[IUP_CALENDAR], STRING])
  177. -- Action generated when the mouse leaves the native element.
  178. local
  179. operation: INTEGER
  180. do
  181. cb_leavewindow := act
  182. if cb_leavewindow /= Void then
  183. operation := 1
  184. else
  185. operation := 0
  186. end
  187. iup_open.set_callback (Current, "LEAVEWINDOW_CB", "NONEEDED", operation)
  188. end
  189. set_cb_k_any (act: FUNCTION[TUPLE[IUP_CALENDAR, INTEGER], STRING])
  190. -- Action generated when a keyboard event occurs.
  191. -- IUP_WIDGET the element that activated the event.
  192. -- INTEGER identifier of typed key. Please refer to the Keyboard
  193. -- Codes table for a list of possible values.
  194. --
  195. -- Returns: If IUP_IGNORE is returned the key is ignored and not
  196. -- processed by the control and not propagated. If returns
  197. -- IUP_CONTINUE, the key will be processed and the event will be
  198. -- propagated to the parent of the element receiving it, this is
  199. -- the default behavior. If returns IUP_DEFAULT the key is processed
  200. -- but it is not propagated. IUP_CLOSE will be processed.
  201. local
  202. operation: INTEGER
  203. do
  204. cb_k_any := act
  205. if cb_k_any /= Void then
  206. operation := 1
  207. else
  208. operation := 0
  209. end
  210. iup_open.set_callback (Current, "K_ANY", "NONEEDED", operation)
  211. end
  212. set_cb_help (act: PROCEDURE[TUPLE[IUP_CALENDAR]])
  213. -- Action generated when the user press F1 at a control. In Motif
  214. -- is also activated by the Help button in some workstations
  215. -- keyboard.
  216. -- Returns: IUP_CLOSE will be processed.
  217. local
  218. operation: INTEGER
  219. do
  220. cb_help := act
  221. if cb_help /= Void then
  222. operation := 1
  223. else
  224. operation := 0
  225. end
  226. iup_open.set_callback (Current, "HELP_CB", "NONEEDED", operation)
  227. end
  228. -- Extra
  229. set_cb_value_changed (act: FUNCTION[TUPLE[IUP_CALENDAR], STRING])
  230. local
  231. operation: INTEGER
  232. do
  233. cb_valuechanged := act
  234. if cb_valuechanged /= Void then
  235. operation := 1
  236. else
  237. operation := 0
  238. end
  239. iup_open.set_callback (Current, "VALUECHANGED_CB", "NONEEDED", operation)
  240. end
  241. feature {IUP} -- Internal handle of callbacks
  242. -- Common callbacks
  243. execute_map: STRING
  244. do
  245. Result := cb_map.item([Current])
  246. end
  247. execute_unmap: STRING
  248. do
  249. Result := cb_unmap.item([Current])
  250. end
  251. execute_destroy: STRING
  252. do
  253. Result := cb_destroy.item([Current])
  254. end
  255. execute_getfocus: STRING
  256. do
  257. Result := cb_getfocus.item([Current])
  258. end
  259. execute_killfocus: STRING
  260. do
  261. Result := cb_getfocus.item([Current])
  262. end
  263. execute_enterwindow: STRING
  264. do
  265. Result := cb_enterwindow.item([Current])
  266. end
  267. execute_leavewindow: STRING
  268. do
  269. Result := cb_leavewindow.item([Current])
  270. end
  271. execute_k_any (c: INTEGER): STRING
  272. do
  273. Result := cb_k_any.item([Current, c])
  274. end
  275. execute_help
  276. do
  277. cb_help.call([Current])
  278. end
  279. -- Extra
  280. execute_valuechanged: STRING
  281. do
  282. Result := cb_valuechanged.item([Current])
  283. end
  284. feature {}
  285. -- For callbacks
  286. cb_map: FUNCTION[TUPLE[IUP_CALENDAR], STRING]
  287. cb_unmap: FUNCTION[TUPLE[IUP_CALENDAR], STRING]
  288. cb_destroy: FUNCTION[TUPLE[IUP_CALENDAR], STRING]
  289. cb_getfocus: FUNCTION[TUPLE[IUP_CALENDAR], STRING]
  290. cb_killfocus: FUNCTION[TUPLE[IUP_CALENDAR], STRING]
  291. cb_enterwindow: FUNCTION[TUPLE[IUP_CALENDAR], STRING]
  292. cb_leavewindow: FUNCTION[TUPLE[IUP_CALENDAR], STRING]
  293. cb_k_any: FUNCTION[TUPLE[IUP_CALENDAR, INTEGER], STRING]
  294. cb_help: PROCEDURE[TUPLE[IUP_CALENDAR]]
  295. cb_valuechanged: FUNCTION[TUPLE[IUP_CALENDAR], STRING]
  296. -- Internals
  297. int_calendar: POINTER
  298. external "plug_in"
  299. alias "{
  300. location: "${sys}/plugins"
  301. module_name: "iup"
  302. feature_name: "IupCalendar()"
  303. }"
  304. end
  305. end
  306. -- The MIT License (MIT)
  307. -- Copyright (c) 2016, 2017 by German A. Arias
  308. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  309. -- of this software and associated documentation files (the "Software"), to deal
  310. -- in the Software without restriction, including without limitation the rights
  311. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  312. -- copies of the Software, and to permit persons to whom the Software is
  313. -- furnished to do so, subject to the following conditions:
  314. --
  315. -- The above copyright notice and this permission notice shall be included in
  316. -- all copies or substantial portions of the Software.
  317. --
  318. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  319. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  320. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  321. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  322. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  323. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  324. -- SOFTWARE.