iup_message_dialog.e 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. class IUP_MESSAGE_DIALOG
  2. -- Creates the Message Dialog element. It is a predefined dialog for displaying
  3. -- a message. The dialog can be shown with the IupPopup function only.
  4. --
  5. -- The IupMessageDlg is a native pre-defined dialog not altered by
  6. -- IupSetLanguage.
  7. --
  8. -- In Windows the position (x,y) used in popup is ignored and the dialog is
  9. -- always centered on screen.
  10. --
  11. -- The IUP_MESSAGE function simply creates and popup a IUP_MESSAGE_DIALOG.
  12. --
  13. -- In Windows each different dialog type is always associated with a different
  14. -- beep sound.
  15. --
  16. -- In Windows, if PARENTDIALOG is specified then it will be modal relative only
  17. -- to its parent.
  18. inherit
  19. IUP_WIDGET
  20. redefine
  21. execute_help
  22. end
  23. IUP_WIDGET_TITLE
  24. IUP_WIDGET_POPUP
  25. IUP_WIDGET_ICON
  26. IUP_WIDGET_PARENT_DIALOG
  27. create {ANY}
  28. message_dialog
  29. feature {ANY}
  30. message_dialog
  31. -- New message dialog.
  32. local
  33. a_message_dialog: POINTER
  34. do
  35. a_message_dialog := int_message_dialog
  36. set_widget(a_message_dialog)
  37. end
  38. -- Attributes
  39. set_default_button (id: INTEGER)
  40. -- Number of the default button. Can be "1", "2" or "3". "2" is valid
  41. -- only for "RETRYCANCEL", "OKCANCEL" and "YESNO" button configurations.
  42. -- "3" is valid only for "YESNOCANCEL". Default: "1".
  43. require
  44. id >= 1
  45. id <= 3
  46. do
  47. iup_open.set_attribute(Current, "BUTTONDEFAULT", id.out)
  48. end
  49. set_buttons (buttons: STRING)
  50. -- Buttons configuration. Can have values: "OK", "OKCANCEL",
  51. -- "RETRYCANCEL", "YESNO", or "YESNOCANCEL". Default: "OK". Additionally
  52. -- the "Help" button is displayed if the HELP_CB callback is defined.
  53. require
  54. are_valid_buttons(buttons)
  55. do
  56. iup_open.set_attribute(Current, "BUTTONS", buttons)
  57. end
  58. set_dialog_type (type: STRING)
  59. -- Type of dialog defines which icon will be displayed besides the
  60. -- message text. Can have values: "MESSAGE" (No Icon), "ERROR"
  61. -- (Stop-sign), "WARNING" (Exclamation-point), "QUESTION"
  62. -- (Question-mark) or "INFORMATION" (Letter "i"). Default: "MESSAGE".
  63. require
  64. is_valid_type(type)
  65. do
  66. iup_open.set_attribute(Current, "DIALOGTYPE", type)
  67. end
  68. set_value (text: STRING)
  69. -- Message text.
  70. do
  71. iup_open.set_attribute(Current, "VALUE", text)
  72. end
  73. get_button_response: INTEGER
  74. -- Number of the pressed button. Can be "1", "2" or "3". Default: "1".
  75. local
  76. str: STRING
  77. do
  78. str := iup_open.get_attribute(Current, "BUTTONRESPONSE")
  79. if str.is_integer then
  80. Result := str.to_integer
  81. end
  82. end
  83. -- Callbacks
  84. set_cb_help (act: detachable PROCEDURE[TUPLE[IUP_MESSAGE_DIALOG]])
  85. -- Action generated when the user press F1 at a control. In Motif
  86. -- is also activated by the Help button in some workstations
  87. -- keyboard.
  88. -- Returns: IUP_CLOSE will be processed.
  89. local
  90. operation: INTEGER
  91. do
  92. cb_help := act
  93. if cb_help /= Void then
  94. operation := 1
  95. else
  96. operation := 0
  97. end
  98. iup_open.set_callback (Current, "HELP_CB", "NONEEDED", operation)
  99. end
  100. -- Validations
  101. are_valid_buttons(buttons: STRING): BOOLEAN
  102. do
  103. if buttons.is_equal("OK") or
  104. buttons.is_equal("OKCANCEL") or
  105. buttons.is_equal("RETRYCANCEL") or
  106. buttons.is_equal("YESNO") or
  107. buttons.is_equal("YESNOCANCEL") then
  108. Result := True
  109. else
  110. Result := False
  111. end
  112. end
  113. is_valid_type(type: STRING): BOOLEAN
  114. do
  115. if type.is_equal("MESSAGE") or
  116. type.is_equal("ERROR") or
  117. type.is_equal("WARNING") or
  118. type.is_equal("QUESTION") or
  119. type.is_equal("INFORMATION") then
  120. Result := True
  121. else
  122. Result := False
  123. end
  124. end
  125. feature {IUP}
  126. -- Common callbacks
  127. execute_help
  128. do
  129. if attached cb_help as int_cb then
  130. int_cb.call([Current])
  131. end
  132. end
  133. feature {NONE}
  134. -- For callback
  135. cb_help: detachable PROCEDURE[TUPLE[IUP_MESSAGE_DIALOG]]
  136. -- Internals
  137. int_message_dialog: POINTER
  138. external
  139. "C inline use %"eiffel-iup.h%""
  140. alias
  141. "return IupMessageDlg();"
  142. end
  143. end
  144. -- The MIT License (MIT)
  145. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  146. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  147. -- of this software and associated documentation files (the "Software"), to deal
  148. -- in the Software without restriction, including without limitation the rights
  149. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  150. -- copies of the Software, and to permit persons to whom the Software is
  151. -- furnished to do so, subject to the following conditions:
  152. --
  153. -- The above copyright notice and this permission notice shall be included in
  154. -- all copies or substantial portions of the Software.
  155. --
  156. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  157. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  158. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  159. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  160. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  161. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  162. -- SOFTWARE.