Responder.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // Core.cs: The core engine for gui.cs
  3. //
  4. // Authors:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. // Pending:
  8. // - Check for NeedDisplay on the hierarchy and repaint
  9. // - Layout support
  10. // - "Colors" type or "Attributes" type?
  11. // - What to surface as "BackgroundCOlor" when clearing a window, an attribute or colors?
  12. //
  13. // Optimziations
  14. // - Add rendering limitation to the exposed area
  15. namespace Terminal.Gui {
  16. /// <summary>
  17. /// Responder base class implemented by objects that want to participate on keyboard and mouse input.
  18. /// </summary>
  19. public class Responder {
  20. /// <summary>
  21. /// Gets or sets a value indicating whether this <see cref="Responder"/> can focus.
  22. /// </summary>
  23. /// <value><c>true</c> if can focus; otherwise, <c>false</c>.</value>
  24. public virtual bool CanFocus { get; set; }
  25. internal bool hasFocus;
  26. /// <summary>
  27. /// Gets or sets a value indicating whether this <see cref="Responder"/> has focus.
  28. /// </summary>
  29. /// <value><c>true</c> if has focus; otherwise, <c>false</c>.</value>
  30. public virtual bool HasFocus { get { return hasFocus; } }
  31. // Key handling
  32. /// <summary>
  33. /// This method can be overwritten by view that
  34. /// want to provide accelerator functionality
  35. /// (Alt-key for example).
  36. /// </summary>
  37. /// <remarks>
  38. /// <para>
  39. /// Before keys are sent to the subview on the
  40. /// current view, all the views are
  41. /// processed and the key is passed to the widgets
  42. /// to allow some of them to process the keystroke
  43. /// as a hot-key. </para>
  44. /// <para>
  45. /// For example, if you implement a button that
  46. /// has a hotkey ok "o", you would catch the
  47. /// combination Alt-o here. If the event is
  48. /// caught, you must return true to stop the
  49. /// keystroke from being dispatched to other
  50. /// views.
  51. /// </para>
  52. /// </remarks>
  53. public virtual bool ProcessHotKey (KeyEvent kb)
  54. {
  55. return false;
  56. }
  57. /// <summary>
  58. /// If the view is focused, gives the view a
  59. /// chance to process the keystroke.
  60. /// </summary>
  61. /// <remarks>
  62. /// <para>
  63. /// Views can override this method if they are
  64. /// interested in processing the given keystroke.
  65. /// If they consume the keystroke, they must
  66. /// return true to stop the keystroke from being
  67. /// processed by other widgets or consumed by the
  68. /// widget engine. If they return false, the
  69. /// keystroke will be passed using the ProcessColdKey
  70. /// method to other views to process.
  71. /// </para>
  72. /// <para>
  73. /// The View implementation does nothing but return false,
  74. /// so it is not necessary to call base.ProcessKey if you
  75. /// derive directly from View, but you should if you derive
  76. /// other View subclasses.
  77. /// </para>
  78. /// </remarks>
  79. /// <param name="keyEvent">Contains the details about the key that produced the event.</param>
  80. public virtual bool ProcessKey (KeyEvent keyEvent)
  81. {
  82. return false;
  83. }
  84. /// <summary>
  85. /// This method can be overwritten by views that
  86. /// want to provide accelerator functionality
  87. /// (Alt-key for example), but without
  88. /// interefering with normal ProcessKey behavior.
  89. /// </summary>
  90. /// <remarks>
  91. /// <para>
  92. /// After keys are sent to the subviews on the
  93. /// current view, all the view are
  94. /// processed and the key is passed to the views
  95. /// to allow some of them to process the keystroke
  96. /// as a cold-key. </para>
  97. /// <para>
  98. /// This functionality is used, for example, by
  99. /// default buttons to act on the enter key.
  100. /// Processing this as a hot-key would prevent
  101. /// non-default buttons from consuming the enter
  102. /// keypress when they have the focus.
  103. /// </para>
  104. /// </remarks>
  105. /// <param name="keyEvent">Contains the details about the key that produced the event.</param>
  106. public virtual bool ProcessColdKey (KeyEvent keyEvent)
  107. {
  108. return false;
  109. }
  110. /// <summary>
  111. /// Method invoked when a key is pressed.
  112. /// </summary>
  113. /// <param name="keyEvent">Contains the details about the key that produced the event.</param>
  114. /// <returns>true if the event was handled</returns>
  115. public virtual bool OnKeyDown (KeyEvent keyEvent)
  116. {
  117. return false;
  118. }
  119. /// <summary>
  120. /// Method invoked when a key is released.
  121. /// </summary>
  122. /// <param name="keyEvent">Contains the details about the key that produced the event.</param>
  123. /// <returns>true if the event was handled</returns>
  124. public virtual bool OnKeyUp (KeyEvent keyEvent)
  125. {
  126. return false;
  127. }
  128. /// <summary>
  129. /// Method invoked when a mouse event is generated
  130. /// </summary>
  131. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  132. /// <param name="mouseEvent">Contains the details about the mouse event.</param>
  133. public virtual bool MouseEvent (MouseEvent mouseEvent)
  134. {
  135. return false;
  136. }
  137. /// <summary>
  138. /// Method invoked when a mouse event is generated for the first time.
  139. /// </summary>
  140. /// <param name="mouseEvent"></param>
  141. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  142. public virtual bool OnMouseEnter (MouseEvent mouseEvent)
  143. {
  144. return false;
  145. }
  146. /// <summary>
  147. /// Method invoked when a mouse event is generated for the last time.
  148. /// </summary>
  149. /// <param name="mouseEvent"></param>
  150. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  151. public virtual bool OnMouseLeave (MouseEvent mouseEvent)
  152. {
  153. return false;
  154. }
  155. /// <summary>
  156. /// Method invoked when a view gets focus.
  157. /// </summary>
  158. /// <param name="view">The view that is losing focus.</param>
  159. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  160. public virtual bool OnEnter (View view)
  161. {
  162. return false;
  163. }
  164. /// <summary>
  165. /// Method invoked when a view loses focus.
  166. /// </summary>
  167. /// <param name="view">The view that is getting focus.</param>
  168. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  169. public virtual bool OnLeave (View view)
  170. {
  171. return false;
  172. }
  173. }
  174. }