itextbox.hxx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/itextbox.hxx
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. *
  22. * Portions of this package derive from Woopsi (http://woopsi.org/) and
  23. * portions are original efforts. It is difficult to determine at this
  24. * point what parts are original efforts and which parts derive from Woopsi.
  25. * However, in any event, the work of Antony Dzeryn will be acknowledged
  26. * in most NxWidget files. Thanks Antony!
  27. *
  28. * Copyright (c) 2007-2011, Antony Dzeryn
  29. * All rights reserved.
  30. *
  31. * Redistribution and use in source and binary forms, with or without
  32. * modification, are permitted provided that the following conditions are met:
  33. *
  34. * * Redistributions of source code must retain the above copyright
  35. * notice, this list of conditions and the following disclaimer.
  36. * * Redistributions in binary form must reproduce the above copyright
  37. * notice, this list of conditions and the following disclaimer in the
  38. * documentation and/or other materials provided with the distribution.
  39. * * Neither the names "Woopsi", "Simian Zombie" nor the
  40. * names of its contributors may be used to endorse or promote products
  41. * derived from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
  44. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  45. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  46. * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
  47. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  48. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  49. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  50. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  51. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  52. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  53. *
  54. ****************************************************************************/
  55. #ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_ITEXTBOX_HXX
  56. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_ITEXTBOX_HXX
  57. /****************************************************************************
  58. * Included Files
  59. ****************************************************************************/
  60. #include <nuttx/config.h>
  61. #include <stdint.h>
  62. #include <stdbool.h>
  63. #include <nuttx/nx/nxglib.h>
  64. #include "graphics/nxwidgets/cnxstring.hxx"
  65. #include "graphics/nxwidgets/cwidgetstyle.hxx"
  66. #include "graphics/nxwidgets/cwidgeteventargs.hxx"
  67. /****************************************************************************
  68. * Pre-Processor Definitions
  69. ****************************************************************************/
  70. /****************************************************************************
  71. * Abstract Base Classes
  72. ****************************************************************************/
  73. #if defined(__cplusplus)
  74. namespace NXWidgets
  75. {
  76. /**
  77. * Cursor display options.
  78. */
  79. typedef enum
  80. {
  81. SHOW_CURSOR_ONFOCUS = 0, /**< Show the cursor only if the widget has focus */
  82. SHOW_CURSOR_NEVER, /**< The cursor is never displayed */
  83. SHOW_CURSOR_ALWAYS /**< Always show the cursor */
  84. } EShowCursor;
  85. /**
  86. * Defines the interface that textbox-like classes should implement.
  87. */
  88. class ITextBox
  89. {
  90. public:
  91. /**
  92. * A virtual destructor is required in order to override the ITextBox
  93. * destructor. We do this because if we delete ITextBox, we want the
  94. * destructor of the class that inherits from ITextBox to run, not this
  95. * one.
  96. */
  97. virtual ~ITextBox(void) { }
  98. /**
  99. * Sets the cursor display mode.
  100. *
  101. *@param cursorMode Determines cursor display mode
  102. */
  103. virtual void showCursor(EShowCursor cursorMode) = 0;
  104. /**
  105. * Enables/disables cursor wrapping
  106. *
  107. * @param wrap True enables cursor wrapping
  108. */
  109. virtual void wrapCursor(bool wrap) = 0;
  110. /**
  111. * Set the text displayed in the label.
  112. *
  113. * @param text String to display.
  114. */
  115. virtual void setText(const CNxString &text) = 0;
  116. /**
  117. * Append new text to the end of the current text displayed in the
  118. * label.
  119. *
  120. * @param text String to append.
  121. */
  122. virtual void appendText(const CNxString &text) = 0;
  123. /**
  124. * Remove all characters from the string from the start index onwards.
  125. *
  126. * @param startIndex Index to remove from.
  127. */
  128. virtual void removeText(const unsigned int startIndex) = 0;
  129. /**
  130. * Remove specified number of characters from the string from the
  131. * start index onwards.
  132. *
  133. * @param startIndex Index to remove from.
  134. * @param count Number of characters to remove.
  135. */
  136. virtual void removeText(const unsigned int startIndex, const unsigned int count) = 0;
  137. /**
  138. * Insert text at the specified index.
  139. *
  140. * @param text The text to insert.
  141. * @param index Index at which to insert the text.
  142. */
  143. virtual void insertText(const CNxString &text, const unsigned int index) = 0;
  144. /**
  145. * Insert text at the current cursor position.
  146. *
  147. * @param text The text to insert.
  148. */
  149. virtual void insertTextAtCursor(const CNxString &text) = 0;
  150. /**
  151. * Move the cursor to the text position specified. 0 indicates the
  152. * start of the string. If position is greater than the length of the
  153. * string, the cursor is moved to the end of the string.
  154. *
  155. * @param position The new cursor position.
  156. */
  157. virtual void moveCursorToPosition(const int position) = 0;
  158. /**
  159. * Get the cursor position. This is the index within the string that
  160. * the cursor is currently positioned over.
  161. * @return position The cursor position.
  162. */
  163. virtual const int getCursorPosition(void) const = 0;
  164. };
  165. }
  166. #endif // __cplusplus
  167. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_ITEXTBOX_HXX