NXWidgets: cscrollingtextbox.hxx Source File

NXWidgets 1.19

cscrollingtextbox.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/cscrollingtextbox.hxx
3 *
4 * Copyright (C) 2012 Gregory Nutt. All rights reserved.
5 * Author: Gregory Nutt <gnutt@nuttx.org>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
18 * me be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************
35 *
36 * Portions of this package derive from Woopsi (http://woopsi.org/) and
37 * portions are original efforts. It is difficult to determine at this
38 * point what parts are original efforts and which parts derive from Woopsi.
39 * However, in any event, the work of Antony Dzeryn will be acknowledged
40 * in most NxWidget files. Thanks Antony!
41 *
42 * Copyright (c) 2007-2011, Antony Dzeryn
43 * All rights reserved.
44 *
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions are met:
47 *
48 * * Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * * Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * * Neither the names "Woopsi", "Simian Zombie" nor the
54 * names of its contributors may be used to endorse or promote products
55 * derived from this software without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
58 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
59 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
60 * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
61 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
62 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
63 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
64 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
66 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 *
68 ****************************************************************************/
69
70 #ifndef __INCLUDE_CSCROLLINGTEXTBOX_HXX
71 #define __INCLUDE_CSCROLLINGTEXTBOX_HXX
72
73 /****************************************************************************
74 * Included Files
75 ****************************************************************************/
76
77 #include <nuttx/config.h>
78
79 #include <stdint.h>
80 #include <stdbool.h>
81
82 #include <nuttx/nx/nxglib.h>
83
84 #include "cmultilinetextbox.hxx"
85 #include "cwidgeteventhandler.hxx"
86 #include "cwidgetstyle.hxx"
87 #include "cnxstring.hxx"
88 #include "iscrollable.hxx"
89
90 /****************************************************************************
91 * Pre-Processor Definitions
92 ****************************************************************************/
93
94 /****************************************************************************
95 * Implementation Classes
96 ****************************************************************************/
97
98 #if defined(__cplusplus)
99
100 namespace NXWidgets
101 {
102 class CScrollbarVertical;
103 class CNxFont;
104
105 /**
106 * Widget containing a CMultiLineTextBox and a vertical scrollbar. Exposed
107 * methods are more or less identical to the methods exposed by the
108 * CMultiLineTextBox to ensure that the two are interchangeable.
109 */
110
111 class CScrollingTextBox : public ITextBox, public CNxWidget,
112 public IScrollable, public CWidgetEventHandler
113 {
114 protected:
115 CMultiLineTextBox *m_texbox; /**< Pointer to the textbox */
116 CScrollbarVertical *m_scrollbar; /**< Pointer to the scrollbar */
117 uint8_t m_scrollbarWidth; /**< Width of the scrollbar */
118
119 /**
120 * Draw the area of this widget that falls within the clipping region.
121 * Called by the redraw() function to draw all visible regions.
122 *
123 * @param port The CGraphicsPort to draw to.
124 * @see redraw()
125 */
126
127 virtual void drawContents(CGraphicsPort *port);
128
129 /**
130 * Resize the textbox to the new dimensions.
131 *
132 * @param width The new width.
133 * @param height The new height.
134 */
135
136 virtual void onResize(nxgl_coord_t width, nxgl_coord_t height);
137
138 /**
139 * Destructor.
140 */
141
142 virtual inline ~CScrollingTextBox(void) { }
143
144 /**
145 * Copy constructor is protected to prevent usage.
146 */
147
148 inline CScrollingTextBox(const CScrollingTextBox& scrollingTextBox)
149 : CNxWidget(scrollingTextBox) { }
150
151 public:
152
153 /**
154 * Constructor.
155 *
156 * @param pWidgetControl The widget control for the display.
157 * @param x The x coordinate of the text box, relative to its parent.
158 * @param y The y coordinate of the text box, relative to its parent.
159 * @param width The width of the textbox.
160 * @param height The height of the textbox.
161 * @param text Pointer to a string to display in the textbox.
162 * @param flags Standard widget flag options.
163 * @param maxRows The maximum number of rows the textbox can track. Adding
164 * text beyond this number will cause rows at the start of the text to be
165 * forgotten; text is essentially stored as a queue, and adding to the back
166 * of a full queue causes the front items to be popped off. Setting this to
167 * 0 will make the textbox track only the visible rows.
168 * @param style The style that the widget should use. If this is not
169 * specified, the widget will use the values stored in the global
170 * g_defaultWidgetStyle object. The widget will copy the properties of
171 * the style into its own internal style object.
172 */
173
174 CScrollingTextBox(CWidgetControl *pWidgetControl,
175 nxgl_coord_t x, nxgl_coord_t y,
176 nxgl_coord_t width, nxgl_coord_t height,
177 const CNxString &text, uint32_t flags,
178 nxgl_coord_t maxRows = 0,
179 CWidgetStyle *style = (CWidgetStyle *)NULL);
180
181 /**
182 * Set the horizontal alignment of text within the textbox.
183 *
184 * @param alignment The horizontal position of the text.
185 */
186
187 virtual void setTextAlignmentHoriz(CMultiLineTextBox::TextAlignmentHoriz alignment);
188
189 /**
190 * Set the vertical alignment of text within the textbox.
191 *
192 * @param alignment The vertical position of the text.
193 */
194
195 virtual void setTextAlignmentVert(CMultiLineTextBox::TextAlignmentVert alignment);
196
197 /**
198 * Returns the number of "pages" that the text spans. A page
199 * is defined as the amount of text that can be displayed within
200 * the textbox at one time.
201 *
202 * @return The page count.
203 */
204
205 virtual const uint16_t getPageCount(void) const;
206
207 /**
208 * Returns the current page.
209 *
210 * @return The current page.
211 * @see getPageCount().
212 */
213
214 virtual const uint16_t getCurrentPage(void) const;
215
216 /**
217 * Returns a pointer to the Text object that contains the
218 * wrapped text used in the textbox. It is used as the
219 * pre-processed data source for the textbox, and should
220 * not be altered.
221 *
222 * @return Pointer to the Text object.
223 */
224
225 virtual const CText *getText(void) const;
226
227 /**
228 * Set the text displayed in the textbox.
229 *
230 * @param text String to display.
231 */
232
233 virtual void setText(const CNxString &text);
234
235 /**
236 * Append new text to the end of the current text
237 * displayed in the textbox.
238 *
239 * @param text String to append.
240 */
241
242 virtual void appendText(const CNxString &text);
243
244 /**
245 * Remove all characters from the string from the start index onwards.
246 *
247 * @param startIndex Index to remove from.
248 */
249
250 virtual void removeText(const unsigned int startIndex);
251
252 /**
253 * Remove specified number of characters from the string from the
254 * start index onwards.
255 *
256 * @param startIndex Index to remove from.
257 * @param count Number of characters to remove.
258 */
259
260 virtual void removeText(const unsigned int startIndex, const unsigned int count);
261
262 /**
263 * Set the font used in the textbox.
264 *
265 * @param font Pointer to the new font.
266 */
267
268 virtual void setFont(CNxFont *font);
269
270 /**
271 * Get the length of the text string.
272 *
273 * @return The length of the text string.
274 */
275
276 virtual const unsigned int getTextLength(void) const;
277
278 /**
279 * Sets the cursor display mode.
280 *
281 * @param cursorMode Determines cursor display mode
282 */
283
284 virtual void showCursor(EShowCursor cursorMode);
285
286 /**
287 * Shows the cursor in default mode (only when the TextBox has focus).
288 */
289
290 inline void showCursor(void)
291 {
292 showCursor(SHOW_CURSOR_ONFOCUS);
293 }
294
295 /**
296 * Hides the cursor.
297 */
298
299 inline void hideCursor(void)
300 {
301 showCursor(SHOW_CURSOR_NEVER);
302 }
303
304 /**
305 * Enables/disables cursor wrapping
306 *
307 * @param wrap True enables cursor wrapping
308 */
309
310 virtual void wrapCursor(bool wrap);
311
312 /**
313 * Move the cursor to the text position specified. 0 indicates the start
314 * of the string. If position is greater than the length of the string,
315 * the cursor is moved to the end of the string.
316 *
317 * @param position The new cursor position.
318 */
319
320 virtual void moveCursorToPosition(const int32_t position);
321
322 /**
323 * Get the cursor position. This is the index within the string that
324 * the cursor is currently positioned over.
325 *
326 * @return position The cursor position.
327 */
328
329 virtual const int32_t getCursorPosition(void) const;
330
331 /**
332 * Insert text at the specified index.
333 *
334 * @param text The text to insert.
335 * @param index Index at which to insert the text.
336 */
337
338 virtual void insertText(const CNxString &text, const unsigned int index);
339
340 /**
341 * Insert text at the current cursor position.
342 *
343 * @param text The text to insert.
344 */
345
346 virtual void insertTextAtCursor(const CNxString &text);
347
348 /**
349 * Handles events raised by its sub-widgets.
350 *
351 * @param e Event arguments.
352 */
353
354 virtual void handleValueChangeEvent(const CWidgetEventArgs &e);
355
356 /**
357 * Handles events raised by its sub-widgets.
358 *
359 * @param e Event arguments.
360 */
361
362 virtual void handleScrollEvent(const CWidgetEventArgs &e);
363
364 /**
365 * Gets the x coordinate of the virtual canvas.
366 *
367 * @return The x coordinate of the virtual canvas.
368 */
369
370 virtual const int32_t getCanvasX(void) const;
371
372 /**
373 * Gets the y coordinate of the virtual canvas.
374 *
375 * @return The y coordinate of the virtual canvas.
376 */
377
378 virtual const int32_t getCanvasY(void) const;
379
380 /**
381 * Gets the width of the virtual canvas.
382 *
383 * @return The width of the virtual canvas.
384 */
385
386 virtual const int32_t getCanvasWidth(void) const;
387
388 /**
389 * Gets the height of the virtual canvas.
390 *
391 * @return The height of the virtual canvas.
392 */
393
394 virtual const int32_t getCanvasHeight(void) const;
395
396 /**
397 * Scroll the panel by the specified amounts.
398 *
399 * @param dx The horizontal distance to scroll.
400 * @param dy The vertical distance to scroll.
401 */
402
403 virtual void scroll(int32_t dx, int32_t dy);
404
405 /**
406 * Reposition the panel's scrolling region to the specified coordinates.
407 *
408 * @param x The new x coordinate of the scrolling region.
409 * @param y The new y coordinate of the scrolling region.
410 */
411
412 virtual void jump(int32_t x, int32_t y);
413
414 /**
415 * Set whether or not horizontal scrolling is allowed.
416 *
417 * @param allow True to allow horizontal scrolling; false to deny it.
418 */
419
420 virtual void setAllowsVerticalScroll(bool allow);
421
422 /**
423 * Set whether or not horizontal scrolling is allowed.
424 *
425 * @param allow True to allow horizontal scrolling; false to deny it.
426 */
427
428 virtual void setAllowsHorizontalScroll(bool allow);
429
430 /**
431 * Sets the width of the virtual canvas.
432 *
433 * @param width The width of the virtual canvas.
434 */
435
436 virtual void setCanvasWidth(const int32_t width);
437
438 /**
439 * Sets the height of the virtual canvas.
440 *
441 * @param height The height of the virtual canvas.
442 */
443
444 virtual void setCanvasHeight(const int32_t height);
445
446 /**
447 * Returns true if vertical scrolling is allowed.
448 *
449 * @return True if vertical scrolling is allowed.
450 */
451
452 virtual bool allowsVerticalScroll(void) const;
453
454 /**
455 * Returns true if horizontal scrolling is allowed.
456 *
457 * @return True if horizontal scrolling is allowed.
458 */
459
460 virtual bool allowsHorizontalScroll(void) const;
461 };
462 }
463
464 #endif // __cplusplus
465
466 #endif // __INCLUDE_CSCROLLINGTEXTBOX_HXX
467
NXWidgets::CScrollingTextBox::getCanvasY
virtual const int32_t getCanvasY(void) const
Definition: cscrollingtextbox.cxx:430
NXWidgets::CNxWidget
Definition: cnxwidget.hxx:121
NXWidgets::CScrollingTextBox::appendText
virtual void appendText(const CNxString &text)
Definition: cscrollingtextbox.cxx:228
NXWidgets::CScrollingTextBox::getCanvasHeight
virtual const int32_t getCanvasHeight(void) const
Definition: cscrollingtextbox.cxx:452
cmultilinetextbox.hxx
NXWidgets::CWidgetStyle
Definition: cwidgetstyle.hxx:125
NXWidgets::CScrollingTextBox::setTextAlignmentVert
virtual void setTextAlignmentVert(CMultiLineTextBox::TextAlignmentVert alignment)
Definition: cscrollingtextbox.cxx:165
NXWidgets::CWidgetEventHandler
Definition: cwidgeteventhandler.hxx:103
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CScrollingTextBox::insertText
virtual void insertText(const CNxString &text, const unsigned int index)
Definition: cscrollingtextbox.cxx:340
iscrollable.hxx
NXWidgets::CScrollingTextBox::getText
virtual const CText * getText(void) const
Definition: cscrollingtextbox.cxx:204
NXWidgets::CScrollingTextBox::setCanvasWidth
virtual void setCanvasWidth(const int32_t width)
Definition: cscrollingtextbox.cxx:509
NXWidgets::CMultiLineTextBox::TextAlignmentHoriz
TextAlignmentHoriz
Definition: cmultilinetextbox.hxx:123
cwidgetstyle.hxx
NXWidgets::CScrollingTextBox::getCanvasX
virtual const int32_t getCanvasX(void) const
Definition: cscrollingtextbox.cxx:419
NXWidgets::EShowCursor
EShowCursor
Definition: itextbox.hxx:104
NXWidgets::IScrollable
Definition: iscrollable.hxx:102
NXWidgets::CScrollingTextBox::showCursor
void showCursor(void)
Definition: cscrollingtextbox.hxx:290
NXWidgets::CScrollingTextBox::insertTextAtCursor
virtual void insertTextAtCursor(const CNxString &text)
Definition: cscrollingtextbox.cxx:353
NXWidgets::CScrollingTextBox::getCanvasWidth
virtual const int32_t getCanvasWidth(void) const
Definition: cscrollingtextbox.cxx:441
NXWidgets::CScrollingTextBox::scroll
virtual void scroll(int32_t dx, int32_t dy)
Definition: cscrollingtextbox.cxx:464
NXWidgets::CScrollingTextBox::allowsVerticalScroll
virtual bool allowsVerticalScroll(void) const
Definition: cscrollingtextbox.cxx:531
NXWidgets::CScrollingTextBox::handleScrollEvent
virtual void handleScrollEvent(const CWidgetEventArgs &e)
Definition: cscrollingtextbox.cxx:397
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CScrollingTextBox::wrapCursor
virtual void wrapCursor(bool wrap)
Definition: cscrollingtextbox.cxx:302
NXWidgets::CScrollingTextBox::removeText
virtual void removeText(const unsigned int startIndex)
Definition: cscrollingtextbox.cxx:240
NXWidgets::CScrollingTextBox::getCursorPosition
virtual const int32_t getCursorPosition(void) const
Definition: cscrollingtextbox.cxx:328
NXWidgets::CScrollingTextBox::setCanvasHeight
virtual void setCanvasHeight(const int32_t height)
Definition: cscrollingtextbox.cxx:520
NXWidgets::SHOW_CURSOR_ONFOCUS
Definition: itextbox.hxx:106
NXWidgets::CNxFont
Definition: cnxfont.hxx:70
NXWidgets::CScrollingTextBox::m_scrollbarWidth
uint8_t m_scrollbarWidth
Definition: cscrollingtextbox.hxx:117
NXWidgets::CScrollingTextBox::hideCursor
void hideCursor(void)
Definition: cscrollingtextbox.hxx:299
NXWidgets::CScrollingTextBox::allowsHorizontalScroll
virtual bool allowsHorizontalScroll(void) const
Definition: cscrollingtextbox.cxx:542
NXWidgets::CText
Definition: ctext.hxx:108
NXWidgets::CScrollingTextBox::drawContents
virtual void drawContents(CGraphicsPort *port)
Definition: cscrollingtextbox.cxx:555
NXWidgets::CScrollingTextBox::setAllowsHorizontalScroll
virtual void setAllowsHorizontalScroll(bool allow)
Definition: cscrollingtextbox.cxx:498
NXWidgets::CScrollingTextBox::getPageCount
virtual const uint16_t getPageCount(void) const
Definition: cscrollingtextbox.cxx:178
NXWidgets::CScrollingTextBox::setFont
virtual void setFont(CNxFont *font)
Definition: cscrollingtextbox.cxx:267
NXWidgets::CScrollingTextBox::m_scrollbar
CScrollbarVertical * m_scrollbar
Definition: cscrollingtextbox.hxx:116
NXWidgets::CScrollingTextBox::~CScrollingTextBox
virtual ~CScrollingTextBox(void)
Definition: cscrollingtextbox.hxx:142
NXWidgets::CScrollingTextBox::m_texbox
CMultiLineTextBox * m_texbox
Definition: cscrollingtextbox.hxx:115
NXWidgets::CWidgetEventArgs
Definition: cwidgeteventargs.hxx:127
NXWidgets::CScrollingTextBox::setText
virtual void setText(const CNxString &text)
Definition: cscrollingtextbox.cxx:215
NXWidgets::CScrollingTextBox::moveCursorToPosition
virtual void moveCursorToPosition(const int32_t position)
Definition: cscrollingtextbox.cxx:315
NXWidgets::CScrollingTextBox::CScrollingTextBox
CScrollingTextBox(const CScrollingTextBox &scrollingTextBox)
Definition: cscrollingtextbox.hxx:148
NXWidgets::CMultiLineTextBox::TextAlignmentVert
TextAlignmentVert
Definition: cmultilinetextbox.hxx:134
NXWidgets::CNxString
Definition: cnxstring.hxx:121
NXWidgets::CScrollingTextBox::onResize
virtual void onResize(nxgl_coord_t width, nxgl_coord_t height)
Definition: cscrollingtextbox.cxx:567
NXWidgets::CScrollingTextBox::handleValueChangeEvent
virtual void handleValueChangeEvent(const CWidgetEventArgs &e)
Definition: cscrollingtextbox.cxx:365
NXWidgets::CScrollingTextBox::setAllowsVerticalScroll
virtual void setAllowsVerticalScroll(bool allow)
Definition: cscrollingtextbox.cxx:487
NXWidgets::CScrollingTextBox::setTextAlignmentHoriz
virtual void setTextAlignmentHoriz(CMultiLineTextBox::TextAlignmentHoriz alignment)
Definition: cscrollingtextbox.cxx:154
NXWidgets::CScrollingTextBox
Definition: cscrollingtextbox.hxx:111
NXWidgets::CMultiLineTextBox
Definition: cmultilinetextbox.hxx:114
cnxstring.hxx
NXWidgets::CScrollbarVertical
Definition: cscrollbarvertical.hxx:113
NXWidgets::CScrollingTextBox::getCurrentPage
virtual const uint16_t getCurrentPage(void) const
Definition: cscrollingtextbox.cxx:190
NXWidgets::ITextBox
Definition: itextbox.hxx:115
NXWidgets::CScrollingTextBox::getTextLength
virtual const unsigned int getTextLength(void) const
Definition: cscrollingtextbox.cxx:280
NXWidgets::SHOW_CURSOR_NEVER
Definition: itextbox.hxx:107
cwidgeteventhandler.hxx
NXWidgets::CScrollingTextBox::jump
virtual void jump(int32_t x, int32_t y)
Definition: cscrollingtextbox.cxx:476
NXWidgets::CGraphicsPort
Definition: cgraphicsport.hxx:106