iup_widget_show.e 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. deferred class IUP_WIDGET_SHOW
  2. -- Commands to show dialogs.
  3. inherit
  4. IUP_WIDGET_INTERNALS
  5. feature {ANY}
  6. show : STRING
  7. -- Show the dialog at screen, return IUP_NOERROR if successful.
  8. -- If there was an error returns IUP_ERROR.
  9. local
  10. r: INTEGER
  11. do
  12. r := int_show(widget)
  13. if r.is_equal(0) then
  14. Result := "IUP_NOERROR"
  15. else
  16. Result := "IUP_ERROR"
  17. end
  18. end
  19. show_predefined_xy (x, y: STRING): STRING
  20. -- Displays a dialog in a given position on the screen using predefined
  21. -- values. However you can combine a predefined value with an integer (as
  22. -- string). If there was an error returns IUP_ERROR.
  23. --
  24. -- x: The following predefined values can be used:
  25. --
  26. -- IUP_LEFT: Positions the dialog on the left corner of the main screen
  27. -- IUP_CENTER: Horizontally centralizes the dialog on the main screen
  28. -- IUP_RIGHT: Positions the dialog on the right corner of the main screen
  29. -- IUP_MOUSEPOS: Positions the dialog on the mouse position
  30. -- IUP_CENTERPARENT: Horizontally centralizes the dialog relative to its
  31. -- parent
  32. -- IUP_CURRENT: use the current position of the dialog.
  33. --
  34. -- y: The following predefined calues can be used:
  35. --
  36. -- IUP_TOP: Positions the dialog on the top of the main screen
  37. -- IUP_CENTER: Vertically centralizes the dialog on the main screen
  38. -- IUP_BOTTOM: Positions the dialog on the base of the main screen
  39. -- IUP_MOUSEPOS: Positions the dialog on the mouse position
  40. -- IUP_CENTERPARENT: Vertically centralizes the dialog relative to its
  41. -- parent
  42. -- IUP_CURRENT: use the current position of the dialog.
  43. require
  44. is_valid_position(x, y)
  45. do
  46. Result := show_xy(iup_open.position_to_integer(x),
  47. iup_open.position_to_integer(y))
  48. end
  49. show_xy (x, y: INTEGER): STRING
  50. -- Displays a dialog in a given position on the screen. If there was an
  51. -- error returns IUP_ERROR.
  52. --
  53. -- x: horizontal position of the top left corner of the window, relative
  54. -- to the origin of the main screen.
  55. --
  56. -- y: vertical position of the top left corner of the window, relative to
  57. -- the origin of the main screen.
  58. require
  59. x >= 0
  60. y >= 0
  61. local
  62. r: INTEGER
  63. do
  64. r := int_show_xy(widget, x, y)
  65. if r.is_equal(-1) then
  66. Result := "IUP_INVALID"
  67. elseif r.is_equal(0) then
  68. Result := "IUP_NOERROR"
  69. else
  70. Result := "IUP_ERROR"
  71. end
  72. end
  73. -- Validations
  74. is_valid_position (x, y: STRING): BOOLEAN
  75. local
  76. xs, ys: BOOLEAN
  77. do
  78. if x.is_equal("IUP_LEFT") or
  79. x.is_equal("IUP_CENTER") or
  80. x.is_equal("IUP_RIGHT") or
  81. x.is_equal("IUP_MOUSEPOS") or
  82. x.is_equal("IUP_CENTERPARENT") or
  83. x.is_equal("IUP_CURRENT") then
  84. xs := True
  85. elseif x.is_integer and x.to_integer >= 0 then
  86. xs := True
  87. else
  88. xs := False
  89. end
  90. if y.is_equal("IUP_TOP") or
  91. y.is_equal("IUP_CENTER") or
  92. y.is_equal("IUP_BOTTOM") or
  93. y.is_equal("IUP_MOUSEPOS") or
  94. y.is_equal("IUP_CENTERPARENT") or
  95. y.is_equal("IUP_CURRENT") then
  96. ys := True
  97. elseif y.is_integer and y.to_integer >= 0 then
  98. ys := True
  99. else
  100. ys := False
  101. end
  102. if xs and ys then
  103. Result := True
  104. else
  105. Result := False
  106. end
  107. end
  108. feature {NONE}
  109. -- Internals
  110. int_show (dlg: POINTER): INTEGER
  111. external
  112. "C inline use %"eiffel-iup.h%""
  113. alias
  114. "return IupShow ($dlg);"
  115. end
  116. int_show_xy (wgt: POINTER; x, y: INTEGER): INTEGER
  117. external
  118. "C inline use %"eiffel-iup.h%""
  119. alias
  120. "return IupShowXY ($wgt, $x, $y);"
  121. end
  122. end
  123. -- The MIT License (MIT)
  124. -- Copyright (c) 2016, 2017, 2019 by German A. Arias
  125. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  126. -- of this software and associated documentation files (the "Software"), to deal
  127. -- in the Software without restriction, including without limitation the rights
  128. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  129. -- copies of the Software, and to permit persons to whom the Software is
  130. -- furnished to do so, subject to the following conditions:
  131. --
  132. -- The above copyright notice and this permission notice shall be included in
  133. -- all copies or substantial portions of the Software.
  134. --
  135. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  136. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  137. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  138. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  139. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  140. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  141. -- SOFTWARE.