Crazy Eddie's GUI System  0.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
widgets/Editbox.h
1 /***********************************************************************
2  filename: CEGUIEditbox.h
3  created: 13/4/2004
4  author: Paul D Turner
5 
6  purpose: Interface to base class for Editbox widget
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUIEditbox_h_
31 #define _CEGUIEditbox_h_
32 
33 #include "CEGUI/Base.h"
34 #include "CEGUI/Window.h"
35 #include "CEGUI/RegexMatcher.h"
36 
37 #if defined(_MSC_VER)
38 # pragma warning(push)
39 # pragma warning(disable : 4251)
40 #endif
41 
42 // Start of CEGUI namespace section
43 namespace CEGUI
44 {
46 class CEGUIEXPORT EditboxWindowRenderer : public WindowRenderer
47 {
48 public:
50  EditboxWindowRenderer(const String& name);
51 
64  virtual size_t getTextIndexFromPosition(const Vector2f& pt) const = 0;
65 };
66 
67 //----------------------------------------------------------------------------//
68 
70 class CEGUIEXPORT Editbox : public Window
71 {
72 public:
74 
76  static const String EventNamespace;
78  static const String WidgetTypeName;
129  static const String EventCaretMoved;
141  static const String EventEditboxFull;
148  static const String EventTextAccepted;
149 
158  bool hasInputFocus(void) const;
159 
168  bool isReadOnly(void) const
169  {return d_readOnly;}
170 
180  bool isTextMasked(void) const
181  {return d_maskText;}
182 
202  MatchState getTextMatchState() const;
203 
222  const String& getValidationString(void) const
223  {return d_validationString;}
224 
232  size_t getCaretIndex(void) const;
233 
243  size_t getSelectionStartIndex(void) const;
244 
253  size_t getSelectionEndIndex(void) const;
254 
264  size_t getSelectionLength(void) const;
265 
275  String::value_type getMaskCodePoint(void) const
276  { return d_maskCodePoint; }
277 
291  size_t getMaxTextLength(void) const
292  {return d_maxTextLen;}
293 
305  void setReadOnly(bool setting);
306 
319  void setTextMasked(bool setting);
320 
342  void setValidationString(const String& validation_string);
343 
356  void setCaretIndex(size_t caret_pos);
357 
375  void setSelection(size_t start_pos, size_t end_pos);
376 
388  void setSelectionStart(size_t start_pos);
389 
400  void setSelectionLength(size_t length);
401 
414  void setMaskCodePoint(String::value_type code_point);
415 
432  void setMaxTextLength(size_t max_len);
433 
451  void setValidator(RegexMatcher* matcher);
452 
454  virtual bool performCopy(Clipboard& clipboard);
455 
457  virtual bool performCut(Clipboard& clipboard);
458 
460  virtual bool performPaste(Clipboard& clipboard);
461 
463  Editbox(const String& type, const String& name);
464 
466  virtual ~Editbox(void);
467 
468 protected:
481  size_t getTextIndexFromPosition(const Vector2f& pt) const;
482 
484  void clearSelection(void);
485 
494  void eraseSelectedText(bool modify_text = true);
495 
501  MatchState getStringMatchState(const String& str) const;
502 
511  bool handleValidityChangeForString(const String& str);
512 
514  void handleBackspace(void);
515 
517  void handleDelete(void);
518 
520  void handleCharLeft(uint sysKeys);
521 
523  void handleWordLeft(uint sysKeys);
524 
526  void handleCharRight(uint sysKeys);
527 
529  void handleWordRight(uint sysKeys);
530 
532  void handleHome(uint sysKeys);
533 
535  void handleEnd(uint sysKeys);
536 
538  virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
539 
544  virtual void onReadOnlyChanged(WindowEventArgs& e);
545 
551  virtual void onMaskedRenderingModeChanged(WindowEventArgs& e);
552 
558  virtual void onMaskCodePointChanged(WindowEventArgs& e);
559 
564  virtual void onValidationStringChanged(WindowEventArgs& e);
565 
570  virtual void onMaximumTextLengthChanged(WindowEventArgs& e);
571 
577  virtual void onTextValidityChanged(RegexMatchStateEventArgs& e);
578 
583  virtual void onCaretMoved(WindowEventArgs& e);
584 
589  virtual void onTextSelectionChanged(WindowEventArgs& e);
590 
596  virtual void onEditboxFullEvent(WindowEventArgs& e);
597 
603  virtual void onTextAcceptedEvent(WindowEventArgs& e);
604 
605  // Overridden event handlers
606  void onMouseButtonDown(MouseEventArgs& e);
607  void onMouseButtonUp(MouseEventArgs& e);
608  void onMouseDoubleClicked(MouseEventArgs& e);
609  void onMouseTripleClicked(MouseEventArgs& e);
610  void onMouseMove(MouseEventArgs& e);
611  void onCaptureLost(WindowEventArgs& e);
612  void onCharacter(KeyEventArgs& e);
613  void onKeyDown(KeyEventArgs& e);
614  void onTextChanged(WindowEventArgs& e);
615 
623  size_t d_maxTextLen;
625  size_t d_caretPos;
644 
645 private:
646 
647  void addEditboxProperties(void);
648 };
649 
650 } // End of CEGUI namespace section
651 
652 #if defined(_MSC_VER)
653 # pragma warning(pop)
654 #endif
655 
656 #endif // end of guard _CEGUIEditbox_h_