Crazy Eddies GUI System  0.7.0
CEGUIEditbox.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 "../CEGUIBase.h"
34 #include "../CEGUIWindow.h"
35 #include "CEGUIEditboxProperties.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 Point& pt) const = 0;
65 };
66 
67 //----------------------------------------------------------------------------//
68 
70 class CEGUIEXPORT Editbox : public Window
71 {
72 public:
74  static const String EventNamespace;
76  static const String WidgetTypeName;
92  static const String EventCaratMoved;
96  static const String EventEditboxFull;
98  static const String EventTextAccepted;
99 
108  bool hasInputFocus(void) const;
109 
118  bool isReadOnly(void) const
119  {return d_readOnly;}
120 
130  bool isTextMasked(void) const
131  {return d_maskText;}
132 
153  bool isTextValid(void) const;
154 
167  const String& getValidationString(void) const
168  {return d_validationString;}
169 
177  size_t getCaratIndex(void) const;
178 
188  size_t getSelectionStartIndex(void) const;
189 
198  size_t getSelectionEndIndex(void) const;
199 
209  size_t getSelectionLength(void) const;
210 
219  utf32 getMaskCodePoint(void) const
220  {return d_maskCodePoint;}
221 
235  size_t getMaxTextLength(void) const
236  {return d_maxTextLen;}
237 
249  void setReadOnly(bool setting);
250 
263  void setTextMasked(bool setting);
264 
280  void setValidationString(const String& validation_string);
281 
294  void setCaratIndex(size_t carat_pos);
295 
313  void setSelection(size_t start_pos, size_t end_pos);
314 
326  void setMaskCodePoint(utf32 code_point);
327 
344  void setMaxTextLength(size_t max_len);
345 
347  Editbox(const String& type, const String& name);
348 
350  virtual ~Editbox(void);
351 
352 protected:
365  size_t getTextIndexFromPosition(const Point& pt) const;
366 
368  void clearSelection(void);
369 
378  void eraseSelectedText(bool modify_text = true);
379 
385  bool isStringValid(const String& str) const;
386 
388  void handleBackspace(void);
389 
391  void handleDelete(void);
392 
394  void handleCharLeft(uint sysKeys);
395 
397  void handleWordLeft(uint sysKeys);
398 
400  void handleCharRight(uint sysKeys);
401 
403  void handleWordRight(uint sysKeys);
404 
406  void handleHome(uint sysKeys);
407 
409  void handleEnd(uint sysKeys);
410 
423  virtual bool testClassName_impl(const String& class_name) const
424  {
425  if (class_name=="Editbox") return true;
426  return Window::testClassName_impl(class_name);
427  }
428 
430  virtual bool validateWindowRenderer(const String& name) const
431  {
432  return (name == "Editbox");
433  }
434 
439  virtual void onReadOnlyChanged(WindowEventArgs& e);
440 
446  virtual void onMaskedRenderingModeChanged(WindowEventArgs& e);
447 
453  virtual void onMaskCodePointChanged(WindowEventArgs& e);
454 
459  virtual void onValidationStringChanged(WindowEventArgs& e);
460 
465  virtual void onMaximumTextLengthChanged(WindowEventArgs& e);
466 
475  virtual void onTextInvalidatedEvent(WindowEventArgs& e);
476 
482  virtual void onInvalidEntryAttempted(WindowEventArgs& e);
483 
488  virtual void onCaratMoved(WindowEventArgs& e);
489 
494  virtual void onTextSelectionChanged(WindowEventArgs& e);
495 
501  virtual void onEditboxFullEvent(WindowEventArgs& e);
502 
508  virtual void onTextAcceptedEvent(WindowEventArgs& e);
509 
510  // Overridden event handlers
511  void onMouseButtonDown(MouseEventArgs& e);
512  void onMouseButtonUp(MouseEventArgs& e);
513  void onMouseDoubleClicked(MouseEventArgs& e);
514  void onMouseTripleClicked(MouseEventArgs& e);
515  void onMouseMove(MouseEventArgs& e);
516  void onCaptureLost(WindowEventArgs& e);
517  void onCharacter(KeyEventArgs& e);
518  void onKeyDown(KeyEventArgs& e);
519  void onTextChanged(WindowEventArgs& e);
520 
528  size_t d_maxTextLen;
530  size_t d_caratPos;
543 
544 private:
545  static EditboxProperties::ReadOnly d_readOnlyProperty;
546  static EditboxProperties::MaskText d_maskTextProperty;
547  static EditboxProperties::MaskCodepoint d_maskCodepointProperty;
548  static EditboxProperties::ValidationString d_validationStringProperty;
549  static EditboxProperties::CaratIndex d_caratIndexProperty;
550  static EditboxProperties::SelectionStart d_selectionStartProperty;
551  static EditboxProperties::SelectionLength d_selectionLengthProperty;
552  static EditboxProperties::MaxTextLength d_maxTextLengthProperty;
553 
554  void addEditboxProperties(void);
555 };
556 
557 } // End of CEGUI namespace section
558 
559 #if defined(_MSC_VER)
560 # pragma warning(pop)
561 #endif
562 
563 #endif // end of guard _CEGUIEditbox_h_