Crazy Eddie's GUI System  0.8.7
widgets/Editbox.h
1 /***********************************************************************
2  created: 13/4/2004
3  author: Paul D Turner
4 
5  purpose: Interface to base class for Editbox widget
6 *************************************************************************/
7 /***************************************************************************
8  * Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining
11  * a copy of this software and associated documentation files (the
12  * "Software"), to deal in the Software without restriction, including
13  * without limitation the rights to use, copy, modify, merge, publish,
14  * distribute, sublicense, and/or sell copies of the Software, and to
15  * permit persons to whom the Software is furnished to do so, subject to
16  * the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  ***************************************************************************/
29 #ifndef _CEGUIEditbox_h_
30 #define _CEGUIEditbox_h_
31 
32 #include "CEGUI/Base.h"
33 #include "CEGUI/Window.h"
34 #include "CEGUI/RegexMatcher.h"
35 
36 #if defined(_MSC_VER)
37 # pragma warning(push)
38 # pragma warning(disable : 4251)
39 #endif
40 
41 // Start of CEGUI namespace section
42 namespace CEGUI
43 {
45 class CEGUIEXPORT EditboxWindowRenderer : public WindowRenderer
46 {
47 public:
50 
63  virtual size_t getTextIndexFromPosition(const Vector2f& pt) const = 0;
64 };
65 
66 //----------------------------------------------------------------------------//
67 
69 class CEGUIEXPORT Editbox : public Window
70 {
71 public:
73 
75  static const String EventNamespace;
77  static const String WidgetTypeName;
128  static const String EventCaretMoved;
140  static const String EventEditboxFull;
147  static const String EventTextAccepted;
148 
157  bool hasInputFocus(void) const;
158 
167  bool isReadOnly(void) const
168  {return d_readOnly;}
169 
179  bool isTextMasked(void) const
180  {return d_maskText;}
181 
202 
221  const String& getValidationString(void) const
222  {return d_validationString;}
223 
231  size_t getCaretIndex(void) const;
232 
242  size_t getSelectionStartIndex(void) const;
243 
252  size_t getSelectionEndIndex(void) const;
253 
263  size_t getSelectionLength(void) const;
264 
275  { return d_maskCodePoint; }
276 
290  size_t getMaxTextLength(void) const
291  {return d_maxTextLen;}
292 
304  void setReadOnly(bool setting);
305 
318  void setTextMasked(bool setting);
319 
341  void setValidationString(const String& validation_string);
342 
355  void setCaretIndex(size_t caret_pos);
356 
374  void setSelection(size_t start_pos, size_t end_pos);
375 
387  void setSelectionStart(size_t start_pos);
388 
399  void setSelectionLength(size_t length);
400 
414 
431  void setMaxTextLength(size_t max_len);
432 
450  void setValidator(RegexMatcher* matcher);
451 
453  virtual bool performCopy(Clipboard& clipboard);
454 
456  virtual bool performCut(Clipboard& clipboard);
457 
459  virtual bool performPaste(Clipboard& clipboard);
460 
462  Editbox(const String& type, const String& name);
463 
465  virtual ~Editbox(void);
466 
467 protected:
480  size_t getTextIndexFromPosition(const Vector2f& pt) const;
481 
483  void clearSelection(void);
484 
493  void eraseSelectedText(bool modify_text = true);
494 
501 
511 
513  void handleBackspace(void);
514 
516  void handleDelete(void);
517 
519  void handleCharLeft(uint sysKeys);
520 
522  void handleWordLeft(uint sysKeys);
523 
525  void handleCharRight(uint sysKeys);
526 
528  void handleWordRight(uint sysKeys);
529 
531  void handleHome(uint sysKeys);
532 
534  void handleEnd(uint sysKeys);
535 
537  virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
538 
544 
551 
558 
564 
570 
577 
582  virtual void onCaretMoved(WindowEventArgs& e);
583 
589 
596 
603 
604  // Overridden event handlers
614 
622  size_t d_maxTextLen;
624  size_t d_caretPos;
643 
644 private:
645 
646  void addEditboxProperties(void);
647 };
648 
649 } // End of CEGUI namespace section
650 
651 #if defined(_MSC_VER)
652 # pragma warning(pop)
653 #endif
654 
655 #endif // end of guard _CEGUIEditbox_h_
Defines a clipboard handling class.
Definition: Clipboard.h:84
Base class for the EditboxWindowRenderer class.
Definition: widgets/Editbox.h:46
virtual size_t getTextIndexFromPosition(const Vector2f &pt) const =0
Return the text code point index that is rendered closest to screen position pt.
EditboxWindowRenderer(const String &name)
Constructor.
Base class for an Editbox widget.
Definition: widgets/Editbox.h:70
bool d_previousValidityChangeResponse
Previous match state change response.
Definition: widgets/Editbox.h:642
void setValidationString(const String &validation_string)
Set the text validation string.
bool handleValidityChangeForString(const String &str)
size_t d_maxTextLen
Maximum number of characters for this Editbox.
Definition: widgets/Editbox.h:622
static const String WidgetTypeName
Window factory name.
Definition: widgets/Editbox.h:77
size_t getSelectionEndIndex(void) const
return the current selection end point.
virtual void onTextSelectionChanged(WindowEventArgs &e)
Handler called when the current text selection changes.
virtual void onMaskedRenderingModeChanged(WindowEventArgs &e)
Handler called when the masked rendering mode (password mode) has been changed.
bool d_readOnly
True if the editbox is in read-only mode.
Definition: widgets/Editbox.h:616
void onMouseButtonUp(MouseEventArgs &e)
Handler called when a mouse button has been released within this window's area.
void setReadOnly(bool setting)
Specify whether the Editbox is read-only.
virtual void onMaximumTextLengthChanged(WindowEventArgs &e)
Handler called when the maximum text length for the edit box is changed.
virtual void onCaretMoved(WindowEventArgs &e)
Handler called when the caret (insert point) position changes.
size_t d_selectionEnd
End of selection area.
Definition: widgets/Editbox.h:628
void onCaptureLost(WindowEventArgs &e)
Handler called when this window loses capture of mouse inputs.
void setMaskCodePoint(String::value_type code_point)
set the code point used when rendering masked text.
static const String EventNamespace
Namespace for global events.
Definition: widgets/Editbox.h:75
static const String EventCaretMoved
Definition: widgets/Editbox.h:128
void handleCharLeft(uint sysKeys)
Processing to move caret one character left.
virtual void onValidationStringChanged(WindowEventArgs &e)
Event fired internally when the validation string is changed.
bool d_maskText
True if the editbox text should be rendered masked.
Definition: widgets/Editbox.h:618
void handleWordLeft(uint sysKeys)
Processing to move caret one word left.
void onMouseMove(MouseEventArgs &e)
Handler called when the mouse cursor has been moved within this window's area.
void onMouseTripleClicked(MouseEventArgs &e)
Handler called when a mouse button has been triple-clicked within this window's area.
static const String EventMaskedRenderingModeChanged
Definition: widgets/Editbox.h:89
void clearSelection(void)
Clear the currently defined selection (just the region, not the text).
void eraseSelectedText(bool modify_text=true)
Erase the currently selected text.
void setCaretIndex(size_t caret_pos)
Set the current position of the caret.
size_t d_caretPos
Position of the caret / insert-point.
Definition: widgets/Editbox.h:624
virtual void onTextValidityChanged(RegexMatchStateEventArgs &e)
Handler called when something has caused the validity state of the current text to change.
static const String EventTextAccepted
Definition: widgets/Editbox.h:147
virtual ~Editbox(void)
Destructor for Editbox class.
virtual bool performCopy(Clipboard &clipboard)
Asks the widget to perform a clipboard copy to the provided clipboard.
static const String EventReadOnlyModeChanged
Definition: widgets/Editbox.h:83
void handleBackspace(void)
Processing for backspace key.
String d_validationString
Copy of validation reg-ex string.
Definition: widgets/Editbox.h:630
size_t getTextIndexFromPosition(const Vector2f &pt) const
Return the text code point index that is rendered closest to screen position pt.
virtual void onMaskCodePointChanged(WindowEventArgs &e)
Handler called when the code point to use for masked rendering has been changed.
void onMouseDoubleClicked(MouseEventArgs &e)
Handler called when a mouse button has been double-clicked within this window's area.
size_t getSelectionLength(void) const
return the length of the current selection (in code points / characters).
String::value_type getMaskCodePoint(void) const
return the code point used when rendering masked text.
Definition: widgets/Editbox.h:274
size_t d_selectionStart
Start of selection area.
Definition: widgets/Editbox.h:626
size_t getSelectionStartIndex(void) const
return the current selection start point.
static const String EventEditboxFull
Definition: widgets/Editbox.h:140
void onMouseButtonDown(MouseEventArgs &e)
Handler called when a mouse button has been depressed within this window's area.
const String & getValidationString(void) const
return the currently set validation string
Definition: widgets/Editbox.h:221
virtual bool performCut(Clipboard &clipboard)
Asks the widget to perform a clipboard cut to the provided clipboard.
void handleWordRight(uint sysKeys)
Processing to move caret one word right.
bool d_dragging
true when a selection is being dragged.
Definition: widgets/Editbox.h:636
virtual void onReadOnlyChanged(WindowEventArgs &e)
Handler called when the read only state of the Editbox has been changed.
virtual void onTextAcceptedEvent(WindowEventArgs &e)
Handler called when the user accepts the edit box text by pressing Return, Enter, or Tab.
size_t getCaretIndex(void) const
return the current position of the caret.
RegexMatcher * d_validator
Pointer to class used for validation of text.
Definition: widgets/Editbox.h:632
bool hasInputFocus(void) const
return true if the Editbox has input focus.
size_t d_dragAnchorIdx
Selection index for drag selection anchor point.
Definition: widgets/Editbox.h:638
void setMaxTextLength(size_t max_len)
set the maximum text length for this Editbox.
static const String EventValidationStringChanged
Definition: widgets/Editbox.h:102
void handleEnd(uint sysKeys)
Processing to move caret to the end of the text.
virtual bool performPaste(Clipboard &clipboard)
Asks the widget to perform a clipboard paste from the provided clipboard.
static const String EventTextSelectionChanged
Definition: widgets/Editbox.h:134
size_t getMaxTextLength(void) const
return the maximum text length set for this Editbox.
Definition: widgets/Editbox.h:290
virtual void onEditboxFullEvent(WindowEventArgs &e)
Handler called when the edit box text has reached the set maximum length.
virtual bool validateWindowRenderer(const WindowRenderer *renderer) const
validate window renderer
void onCharacter(KeyEventArgs &e)
Handler called when a character-key has been pressed while this window has input focus.
void handleCharRight(uint sysKeys)
Processing to move caret one character right.
void handleDelete(void)
Processing for Delete key.
MatchState d_validatorMatchState
Current match state of EditboxText.
Definition: widgets/Editbox.h:640
void setSelectionStart(size_t start_pos)
Define the current selection start for the Editbox.
Editbox(const String &type, const String &name)
Constructor for Editbox class.
static const String EventTextValidityChanged
Definition: widgets/Editbox.h:122
bool isReadOnly(void) const
return true if the Editbox is read-only.
Definition: widgets/Editbox.h:167
MatchState getStringMatchState(const String &str) const
return the match state of the given string for the validation regular expression.
bool d_weOwnValidator
specifies whether validator was created by us, or supplied by user.
Definition: widgets/Editbox.h:634
String::value_type d_maskCodePoint
Code point to use when rendering masked text.
Definition: widgets/Editbox.h:620
MatchState getTextMatchState() const
return the validation MatchState for the current Editbox text, given the currently set validation str...
static const String EventMaximumTextLengthChanged
Definition: widgets/Editbox.h:108
void setSelection(size_t start_pos, size_t end_pos)
Define the current selection for the Editbox.
void setValidator(RegexMatcher *matcher)
Set the RegexMatcher based validator for this Editbox.
void onTextChanged(WindowEventArgs &e)
Handler called when the window's text is changed.
void setSelectionLength(size_t length)
Define the current selection for the Editbox.
void handleHome(uint sysKeys)
Processing to move caret to the start of the text.
bool isTextMasked(void) const
return true if the text for the Editbox will be rendered masked.
Definition: widgets/Editbox.h:179
static const String EventMaskCodePointChanged
Definition: widgets/Editbox.h:96
void onKeyDown(KeyEventArgs &e)
Handler called when a key as been depressed while this window has input focus.
void setTextMasked(bool setting)
Specify whether the text for the Editbox will be rendered masked.
EventArgs based class that is used for objects passed to input event handlers concerning keyboard inp...
Definition: InputEvent.h:315
EventArgs based class that is used for objects passed to input event handlers concerning mouse input.
Definition: InputEvent.h:281
Definition: RegexMatcher.h:70
Interface for Regex matching support classes.
Definition: RegexMatcher.h:41
MatchState
Enumeration of possible states when cosidering a regex match.
Definition: RegexMatcher.h:45
String class used within the GUI system.
Definition: String.h:64
utf32 value_type
Basic 'code point' type used for String (utf32)
Definition: String.h:69
EventArgs based class that is used for objects passed to handlers triggered for events concerning som...
Definition: InputEvent.h:252
Base-class for the assignable WindowRenderer object.
Definition: WindowRenderer.h:52
An abstract base class providing common functionality and specifying the required interface for deriv...
Definition: Window.h:151
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1