Responder.cs 5.8 KB

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