iup_alarm.e 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. class IUP_ALARM
  2. -- Shows a modal dialog containing a message and up to three buttons.
  3. --
  4. -- This function shows a dialog centralized on the screen, with the message and
  5. -- the buttons. The ‘%N’ character can be added to the message to indicate line
  6. -- change.
  7. --
  8. -- Button 1 is set as the "DEFAULTENTER" and "DEFAULTESC". If Button 2 exists
  9. -- it is set as the "DEFAULTESC". If Button 3 exists it is set as the
  10. -- "DEFAULTESC".
  11. --
  12. -- The dialog uses a global attribute called "PARENTDIALOG" as the parent
  13. -- dialog if it is defined. It also uses a global attribute called "ICON" as
  14. -- the dialog icon if it is defined.
  15. inherit
  16. IUP_WIDGET
  17. create {ANY}
  18. alarm_one_button,
  19. alarm_two_buttons,
  20. alarm_three_buttons
  21. feature {ANY}
  22. alarm_one_button (title: STRING; message: STRING; text_button_1: STRING)
  23. -- Create an alarm dialog with title, a message and one button.
  24. do
  25. t := title
  26. m := message
  27. bt1 := text_button_1
  28. type := 1
  29. end
  30. alarm_two_buttons (title, message, text_button_1, text_button_2: STRING)
  31. -- Create an alarm dialog with title, a message and two buttons.
  32. do
  33. t := title
  34. m := message
  35. bt1 := text_button_1
  36. bt2 := text_button_2
  37. type := 2
  38. end
  39. alarm_three_buttons (title, message, text_button_1,
  40. text_button_2, text_button_3: STRING)
  41. -- Create an alarm dialog with title, a message and three buttons.
  42. do
  43. t := title
  44. m := message
  45. bt1 := text_button_1
  46. bt2 := text_button_2
  47. bt3 := text_button_3
  48. type := 3
  49. end
  50. launch: INTEGER
  51. -- Returns the number of the button selected by the user (1, 2 or 3) , or
  52. -- 0 if failed. It fails only if button 1 is not defined.
  53. local
  54. p: POINTER
  55. do
  56. if type.is_equal(1) then
  57. Result := int_alarm (get_pointer(t.to_c), get_pointer(m.to_c),
  58. get_pointer(bt1.to_c), p, p)
  59. elseif type.is_equal(2) and
  60. attached bt2 as button_2 then
  61. Result := int_alarm (get_pointer(t.to_c), get_pointer(m.to_c),
  62. get_pointer(bt1.to_c),
  63. get_pointer(button_2.to_c), p)
  64. elseif type.is_equal(3) and
  65. attached bt2 as button_2 and
  66. attached bt3 as button_3 then
  67. Result := int_alarm (get_pointer(t.to_c), get_pointer(m.to_c),
  68. get_pointer(bt1.to_c),
  69. get_pointer(button_2.to_c),
  70. get_pointer(button_3.to_c))
  71. else
  72. Result := 0
  73. end
  74. end
  75. feature {NONE}
  76. t, m, bt1: STRING
  77. bt2, bt3: detachable STRING
  78. type: INTEGER
  79. -- Internal
  80. int_alarm (title: POINTER; message: POINTER; b1, b2, b3: POINTER): INTEGER
  81. external
  82. "C inline use %"eiffel-iup.h%""
  83. alias
  84. "return IupAlarm ($title, $message, $b1, $b2, $b3);"
  85. end
  86. end -- class IUP_ALARM
  87. -- The MIT License (MIT)
  88. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  89. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  90. -- of this software and associated documentation files (the "Software"), to deal
  91. -- in the Software without restriction, including without limitation the rights
  92. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  93. -- copies of the Software, and to permit persons to whom the Software is
  94. -- furnished to do so, subject to the following conditions:
  95. --
  96. -- The above copyright notice and this permission notice shall be included in
  97. -- all copies or substantial portions of the Software.
  98. --
  99. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  100. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  101. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  102. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  103. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  104. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  105. -- SOFTWARE.