iup_message_alarm.e 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. class IUP_MESSAGE_ALARM
  2. -- Shows a modal dialog containing a question message, similar
  3. -- to IUP_ALARM.
  4. inherit
  5. IUP_GET_POINTER
  6. create {ANY}
  7. message_alarm_with_parent,
  8. message_alarm
  9. feature {ANY}
  10. message_alarm_with_parent (parent: IUP_DIALOG; title, message, buttons: STRING)
  11. -- hows a modal dialog containing a question message, similar to
  12. -- IUP_ALARM.
  13. --
  14. -- parent: parent dialog.
  15. -- title: dialog’s title. It can be a language pre-defined string
  16. -- without the "_@" prefix.
  17. -- message: text message contents. It can be a language pre-defined
  18. -- string without the "_@" prefix.
  19. -- buttons: list of buttons. Can have values: "OK", "OKCANCEL",
  20. -- "RETRYCANCEL", "YESNO", or "YESNOCANCEL".
  21. --
  22. -- The dialog is shown centered relative to its parent.
  23. require
  24. is_valid_buttons(buttons)
  25. do
  26. int_parent := parent.widget
  27. int_tittle := title
  28. int_message := message
  29. int_buttons := buttons
  30. end
  31. message_alarm (title, message, buttons: STRING)
  32. -- The title defaults to "Attention!" and tries the global attribute
  33. -- "PARENTDIALOG" as the parent dialog.
  34. require
  35. is_valid_buttons(buttons)
  36. do
  37. int_tittle := title
  38. int_message := message
  39. int_buttons := buttons
  40. end
  41. launch: INTEGER
  42. -- Launch the message alarm.
  43. --
  44. -- Returns: the number of the button selected by the user (1, 2 or 3).
  45. do
  46. Result := int_message_alarm (int_parent, get_pointer(int_tittle.to_c),
  47. get_pointer(int_message.to_c), get_pointer(int_buttons.to_c))
  48. end
  49. -- Validations
  50. is_valid_buttons (value: STRING): BOOLEAN
  51. do
  52. if value.is_equal ("OK") or
  53. value.is_equal ("OKCANCEL") or
  54. value.is_equal ("RETRYCANCEL") or
  55. value.is_equal ("YESNO") or
  56. value.is_equal ("YESNOCANCEL") then
  57. Result := True
  58. else
  59. Result := False
  60. end
  61. end
  62. feature {NONE}
  63. -- Internal
  64. int_parent: POINTER
  65. int_tittle, int_message, int_buttons: STRING
  66. int_message_alarm (wgt, t, m, b: POINTER): INTEGER
  67. external
  68. "C inline use %"eiffel-iup.h%""
  69. alias
  70. "return IupMessageAlarm ($wgt, $t, $m, $b);"
  71. end
  72. end -- class IUP_MESSAGE_ALARM
  73. -- The MIT License (MIT)
  74. -- Copyright (c) 2017, 2019 by German A. Arias
  75. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  76. -- of this software and associated documentation files (the "Software"), to deal
  77. -- in the Software without restriction, including without limitation the rights
  78. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  79. -- copies of the Software, and to permit persons to whom the Software is
  80. -- furnished to do so, subject to the following conditions:
  81. --
  82. -- The above copyright notice and this permission notice shall be included in
  83. -- all copies or substantial portions of the Software.
  84. --
  85. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  86. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  87. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  88. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  89. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  90. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  91. -- SOFTWARE.