cscrollingtextbox.hxx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cscrollingtextbox.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_CSCROLLINGTEXTBOX_HXX
  56. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSCROLLINGTEXTBOX_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/cmultilinetextbox.hxx"
  65. #include "graphics/nxwidgets/cwidgeteventhandler.hxx"
  66. #include "graphics/nxwidgets/cwidgetstyle.hxx"
  67. #include "graphics/nxwidgets/cnxstring.hxx"
  68. #include "graphics/nxwidgets/iscrollable.hxx"
  69. /****************************************************************************
  70. * Pre-Processor Definitions
  71. ****************************************************************************/
  72. /****************************************************************************
  73. * Implementation Classes
  74. ****************************************************************************/
  75. #if defined(__cplusplus)
  76. namespace NXWidgets
  77. {
  78. class CScrollbarVertical;
  79. class CNxFont;
  80. /**
  81. * Widget containing a CMultiLineTextBox and a vertical scrollbar. Exposed
  82. * methods are more or less identical to the methods exposed by the
  83. * CMultiLineTextBox to ensure that the two are interchangeable.
  84. */
  85. class CScrollingTextBox : public ITextBox, public CNxWidget,
  86. public IScrollable, public CWidgetEventHandler
  87. {
  88. protected:
  89. CMultiLineTextBox *m_texbox; /**< Pointer to the textbox */
  90. CScrollbarVertical *m_scrollbar; /**< Pointer to the scrollbar */
  91. uint8_t m_scrollbarWidth; /**< Width of the scrollbar */
  92. /**
  93. * Draw the area of this widget that falls within the clipping region.
  94. * Called by the redraw() function to draw all visible regions.
  95. *
  96. * @param port The CGraphicsPort to draw to.
  97. * @see redraw()
  98. */
  99. virtual void drawContents(CGraphicsPort *port);
  100. /**
  101. * Resize the textbox to the new dimensions.
  102. *
  103. * @param width The new width.
  104. * @param height The new height.
  105. */
  106. virtual void onResize(nxgl_coord_t width, nxgl_coord_t height);
  107. /**
  108. * Destructor.
  109. */
  110. virtual inline ~CScrollingTextBox(void) { }
  111. /**
  112. * Copy constructor is protected to prevent usage.
  113. */
  114. inline CScrollingTextBox(const CScrollingTextBox& scrollingTextBox)
  115. : CNxWidget(scrollingTextBox) { }
  116. public:
  117. /**
  118. * Constructor.
  119. *
  120. * @param pWidgetControl The widget control for the display.
  121. * @param x The x coordinate of the text box, relative to its parent.
  122. * @param y The y coordinate of the text box, relative to its parent.
  123. * @param width The width of the textbox.
  124. * @param height The height of the textbox.
  125. * @param text Pointer to a string to display in the textbox.
  126. * @param flags Standard widget flag options.
  127. * @param maxRows The maximum number of rows the textbox can track. Adding
  128. * text beyond this number will cause rows at the start of the text to be
  129. * forgotten; text is essentially stored as a queue, and adding to the back
  130. * of a full queue causes the front items to be popped off. Setting this to
  131. * 0 will make the textbox track only the visible rows.
  132. * @param style The style that the widget should use. If this is not
  133. * specified, the widget will use the values stored in the global
  134. * g_defaultWidgetStyle object. The widget will copy the properties of
  135. * the style into its own internal style object.
  136. */
  137. CScrollingTextBox(CWidgetControl *pWidgetControl,
  138. nxgl_coord_t x, nxgl_coord_t y,
  139. nxgl_coord_t width, nxgl_coord_t height,
  140. const CNxString &text, uint32_t flags,
  141. nxgl_coord_t maxRows = 0,
  142. CWidgetStyle *style = (CWidgetStyle *)NULL);
  143. /**
  144. * Set the horizontal alignment of text within the textbox.
  145. *
  146. * @param alignment The horizontal position of the text.
  147. */
  148. virtual void setTextAlignmentHoriz(CMultiLineTextBox::TextAlignmentHoriz alignment);
  149. /**
  150. * Set the vertical alignment of text within the textbox.
  151. *
  152. * @param alignment The vertical position of the text.
  153. */
  154. virtual void setTextAlignmentVert(CMultiLineTextBox::TextAlignmentVert alignment);
  155. /**
  156. * Returns the number of "pages" that the text spans. A page
  157. * is defined as the amount of text that can be displayed within
  158. * the textbox at one time.
  159. *
  160. * @return The page count.
  161. */
  162. virtual const uint16_t getPageCount(void) const;
  163. /**
  164. * Returns the current page.
  165. *
  166. * @return The current page.
  167. * @see getPageCount().
  168. */
  169. virtual const uint16_t getCurrentPage(void) const;
  170. /**
  171. * Returns a pointer to the Text object that contains the
  172. * wrapped text used in the textbox. It is used as the
  173. * pre-processed data source for the textbox, and should
  174. * not be altered.
  175. *
  176. * @return Pointer to the Text object.
  177. */
  178. virtual const CText *getText(void) const;
  179. /**
  180. * Set the text displayed in the textbox.
  181. *
  182. * @param text String to display.
  183. */
  184. virtual void setText(const CNxString &text);
  185. /**
  186. * Append new text to the end of the current text
  187. * displayed in the textbox.
  188. *
  189. * @param text String to append.
  190. */
  191. virtual void appendText(const CNxString &text);
  192. /**
  193. * Remove all characters from the string from the start index onwards.
  194. *
  195. * @param startIndex Index to remove from.
  196. */
  197. virtual void removeText(const unsigned int startIndex);
  198. /**
  199. * Remove specified number of characters from the string from the
  200. * start index onwards.
  201. *
  202. * @param startIndex Index to remove from.
  203. * @param count Number of characters to remove.
  204. */
  205. virtual void removeText(const unsigned int startIndex, const unsigned int count);
  206. /**
  207. * Set the font used in the textbox.
  208. *
  209. * @param font Pointer to the new font.
  210. */
  211. virtual void setFont(CNxFont *font);
  212. /**
  213. * Get the length of the text string.
  214. *
  215. * @return The length of the text string.
  216. */
  217. virtual const unsigned int getTextLength(void) const;
  218. /**
  219. * Sets the cursor display mode.
  220. *
  221. * @param cursorMode Determines cursor display mode
  222. */
  223. virtual void showCursor(EShowCursor cursorMode);
  224. /**
  225. * Shows the cursor in default mode (only when the TextBox has focus).
  226. */
  227. inline void showCursor(void)
  228. {
  229. showCursor(SHOW_CURSOR_ONFOCUS);
  230. }
  231. /**
  232. * Hides the cursor.
  233. */
  234. inline void hideCursor(void)
  235. {
  236. showCursor(SHOW_CURSOR_NEVER);
  237. }
  238. /**
  239. * Enables/disables cursor wrapping
  240. *
  241. * @param wrap True enables cursor wrapping
  242. */
  243. virtual void wrapCursor(bool wrap);
  244. /**
  245. * Move the cursor to the text position specified. 0 indicates the start
  246. * of the string. If position is greater than the length of the string,
  247. * the cursor is moved to the end of the string.
  248. *
  249. * @param position The new cursor position.
  250. */
  251. virtual void moveCursorToPosition(const int position);
  252. /**
  253. * Get the cursor position. This is the index within the string that
  254. * the cursor is currently positioned over.
  255. *
  256. * @return position The cursor position.
  257. */
  258. virtual const int getCursorPosition(void) const;
  259. /**
  260. * Insert text at the specified index.
  261. *
  262. * @param text The text to insert.
  263. * @param index Index at which to insert the text.
  264. */
  265. virtual void insertText(const CNxString &text, const unsigned int index);
  266. /**
  267. * Insert text at the current cursor position.
  268. *
  269. * @param text The text to insert.
  270. */
  271. virtual void insertTextAtCursor(const CNxString &text);
  272. /**
  273. * Handles events raised by its sub-widgets.
  274. *
  275. * @param e Event arguments.
  276. */
  277. virtual void handleValueChangeEvent(const CWidgetEventArgs &e);
  278. /**
  279. * Handles events raised by its sub-widgets.
  280. *
  281. * @param e Event arguments.
  282. */
  283. virtual void handleScrollEvent(const CWidgetEventArgs &e);
  284. /**
  285. * Gets the x coordinate of the virtual canvas.
  286. *
  287. * @return The x coordinate of the virtual canvas.
  288. */
  289. virtual const int32_t getCanvasX(void) const;
  290. /**
  291. * Gets the y coordinate of the virtual canvas.
  292. *
  293. * @return The y coordinate of the virtual canvas.
  294. */
  295. virtual const int32_t getCanvasY(void) const;
  296. /**
  297. * Gets the width of the virtual canvas.
  298. *
  299. * @return The width of the virtual canvas.
  300. */
  301. virtual const int32_t getCanvasWidth(void) const;
  302. /**
  303. * Gets the height of the virtual canvas.
  304. *
  305. * @return The height of the virtual canvas.
  306. */
  307. virtual const int32_t getCanvasHeight(void) const;
  308. /**
  309. * Scroll the panel by the specified amounts.
  310. *
  311. * @param dx The horizontal distance to scroll.
  312. * @param dy The vertical distance to scroll.
  313. */
  314. virtual void scroll(int32_t dx, int32_t dy);
  315. /**
  316. * Reposition the panel's scrolling region to the specified coordinates.
  317. *
  318. * @param x The new x coordinate of the scrolling region.
  319. * @param y The new y coordinate of the scrolling region.
  320. */
  321. virtual void jump(int32_t x, int32_t y);
  322. /**
  323. * Set whether or not horizontal scrolling is allowed.
  324. *
  325. * @param allow True to allow horizontal scrolling; false to deny it.
  326. */
  327. virtual void setAllowsVerticalScroll(bool allow);
  328. /**
  329. * Set whether or not horizontal scrolling is allowed.
  330. *
  331. * @param allow True to allow horizontal scrolling; false to deny it.
  332. */
  333. virtual void setAllowsHorizontalScroll(bool allow);
  334. /**
  335. * Sets the width of the virtual canvas.
  336. *
  337. * @param width The width of the virtual canvas.
  338. */
  339. virtual void setCanvasWidth(const int32_t width);
  340. /**
  341. * Sets the height of the virtual canvas.
  342. *
  343. * @param height The height of the virtual canvas.
  344. */
  345. virtual void setCanvasHeight(const int32_t height);
  346. /**
  347. * Returns true if vertical scrolling is allowed.
  348. *
  349. * @return True if vertical scrolling is allowed.
  350. */
  351. virtual bool allowsVerticalScroll(void) const;
  352. /**
  353. * Returns true if horizontal scrolling is allowed.
  354. *
  355. * @return True if horizontal scrolling is allowed.
  356. */
  357. virtual bool allowsHorizontalScroll(void) const;
  358. };
  359. }
  360. #endif // __cplusplus
  361. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CSCROLLINGTEXTBOX_HXX