2
0

Responder.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. /// <summary>
  26. /// Gets or sets a value indicating whether this <see cref="Responder"/> has focus.
  27. /// </summary>
  28. /// <value><c>true</c> if has focus; otherwise, <c>false</c>.</value>
  29. public virtual bool HasFocus { get; }
  30. // Key handling
  31. /// <summary>
  32. /// This method can be overwritten by view that
  33. /// want to provide accelerator functionality
  34. /// (Alt-key for example).
  35. /// </summary>
  36. /// <remarks>
  37. /// <para>
  38. /// Before keys are sent to the subview on the
  39. /// current view, all the views are
  40. /// processed and the key is passed to the widgets
  41. /// to allow some of them to process the keystroke
  42. /// as a hot-key. </para>
  43. /// <para>
  44. /// For example, if you implement a button that
  45. /// has a hotkey ok "o", you would catch the
  46. /// combination Alt-o here. If the event is
  47. /// caught, you must return true to stop the
  48. /// keystroke from being dispatched to other
  49. /// views.
  50. /// </para>
  51. /// </remarks>
  52. public virtual bool ProcessHotKey (KeyEvent kb)
  53. {
  54. return false;
  55. }
  56. /// <summary>
  57. /// If the view is focused, gives the view a
  58. /// chance to process the keystroke.
  59. /// </summary>
  60. /// <remarks>
  61. /// <para>
  62. /// Views can override this method if they are
  63. /// interested in processing the given keystroke.
  64. /// If they consume the keystroke, they must
  65. /// return true to stop the keystroke from being
  66. /// processed by other widgets or consumed by the
  67. /// widget engine. If they return false, the
  68. /// keystroke will be passed using the ProcessColdKey
  69. /// method to other views to process.
  70. /// </para>
  71. /// <para>
  72. /// The View implementation does nothing but return false,
  73. /// so it is not necessary to call base.ProcessKey if you
  74. /// derive directly from View, but you should if you derive
  75. /// other View subclasses.
  76. /// </para>
  77. /// </remarks>
  78. /// <param name="keyEvent">Contains the details about the key that produced the event.</param>
  79. public virtual bool ProcessKey (KeyEvent keyEvent)
  80. {
  81. return false;
  82. }
  83. /// <summary>
  84. /// This method can be overwritten by views that
  85. /// want to provide accelerator functionality
  86. /// (Alt-key for example), but without
  87. /// interefering with normal ProcessKey behavior.
  88. /// </summary>
  89. /// <remarks>
  90. /// <para>
  91. /// After keys are sent to the subviews on the
  92. /// current view, all the view are
  93. /// processed and the key is passed to the views
  94. /// to allow some of them to process the keystroke
  95. /// as a cold-key. </para>
  96. /// <para>
  97. /// This functionality is used, for example, by
  98. /// default buttons to act on the enter key.
  99. /// Processing this as a hot-key would prevent
  100. /// non-default buttons from consuming the enter
  101. /// keypress when they have the focus.
  102. /// </para>
  103. /// </remarks>
  104. /// <param name="keyEvent">Contains the details about the key that produced the event.</param>
  105. public virtual bool ProcessColdKey (KeyEvent keyEvent)
  106. {
  107. return false;
  108. }
  109. /// <summary>
  110. /// Method invoked when a key is pressed.
  111. /// </summary>
  112. /// <param name="keyEvent">Contains the details about the key that produced the event.</param>
  113. /// <returns>true if the event was handled</returns>
  114. public virtual bool OnKeyDown (KeyEvent keyEvent)
  115. {
  116. return false;
  117. }
  118. /// <summary>
  119. /// Method invoked when a key is released.
  120. /// </summary>
  121. /// <param name="keyEvent">Contains the details about the key that produced the event.</param>
  122. /// <returns>true if the event was handled</returns>
  123. public virtual bool OnKeyUp (KeyEvent keyEvent)
  124. {
  125. return false;
  126. }
  127. /// <summary>
  128. /// Method invoked when a mouse event is generated
  129. /// </summary>
  130. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  131. /// <param name="mouseEvent">Contains the details about the mouse event.</param>
  132. public virtual bool MouseEvent (MouseEvent mouseEvent)
  133. {
  134. return false;
  135. }
  136. /// <summary>
  137. /// Method invoked when a mouse event is generated for the first time.
  138. /// </summary>
  139. /// <param name="mouseEvent"></param>
  140. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  141. public virtual bool OnMouseEnter (MouseEvent mouseEvent)
  142. {
  143. return false;
  144. }
  145. /// <summary>
  146. /// Method invoked when a mouse event is generated for the last time.
  147. /// </summary>
  148. /// <param name="mouseEvent"></param>
  149. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  150. public virtual bool OnMouseLeave (MouseEvent mouseEvent)
  151. {
  152. return false;
  153. }
  154. /// <summary>
  155. /// Method invoked when a view is added.
  156. /// </summary>
  157. /// <param name="view">The view added.</param>
  158. public virtual void OnAddedView (View view) { }
  159. /// <summary>
  160. /// Method invoked when a view being removing.
  161. /// </summary>
  162. /// <param name="view">The view being removing.</param>
  163. public virtual void OnRemovingView (View view) { }
  164. /// <summary>
  165. /// Method invoked when a view gets focus.
  166. /// </summary>
  167. /// <param name="view">The view that is losing focus.</param>
  168. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  169. public virtual bool OnEnter (View view)
  170. {
  171. return false;
  172. }
  173. /// <summary>
  174. /// Method invoked when a view loses focus.
  175. /// </summary>
  176. /// <param name="view">The view that is getting focus.</param>
  177. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  178. public virtual bool OnLeave (View view)
  179. {
  180. return false;
  181. }
  182. }
  183. }