Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
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:
49  EditboxWindowRenderer(const String& name);
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 
201  MatchState getTextMatchState() const;
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 
274  String::value_type getMaskCodePoint(void) const
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 
413  void setMaskCodePoint(String::value_type code_point);
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 
500  MatchState getStringMatchState(const String& str) const;
501 
510  bool handleValidityChangeForString(const String& str);
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 
543  virtual void onReadOnlyChanged(WindowEventArgs& e);
544 
550  virtual void onMaskedRenderingModeChanged(WindowEventArgs& e);
551 
557  virtual void onMaskCodePointChanged(WindowEventArgs& e);
558 
563  virtual void onValidationStringChanged(WindowEventArgs& e);
564 
569  virtual void onMaximumTextLengthChanged(WindowEventArgs& e);
570 
576  virtual void onTextValidityChanged(RegexMatchStateEventArgs& e);
577 
582  virtual void onCaretMoved(WindowEventArgs& e);
583 
588  virtual void onTextSelectionChanged(WindowEventArgs& e);
589 
595  virtual void onEditboxFullEvent(WindowEventArgs& e);
596 
602  virtual void onTextAcceptedEvent(WindowEventArgs& e);
603 
604  // Overridden event handlers
605  void onMouseButtonDown(MouseEventArgs& e);
606  void onMouseButtonUp(MouseEventArgs& e);
607  void onMouseDoubleClicked(MouseEventArgs& e);
608  void onMouseTripleClicked(MouseEventArgs& e);
609  void onMouseMove(MouseEventArgs& e);
610  void onCaptureLost(WindowEventArgs& e);
611  void onCharacter(KeyEventArgs& e);
612  void onKeyDown(KeyEventArgs& e);
613  void onTextChanged(WindowEventArgs& e);
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_