Crazy Eddies GUI System  0.7.9
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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;
126  static const String EventCaratMoved;
138  static const String EventEditboxFull;
145  static const String EventTextAccepted;
146 
155  bool hasInputFocus(void) const;
156 
165  bool isReadOnly(void) const
166  {return d_readOnly;}
167 
177  bool isTextMasked(void) const
178  {return d_maskText;}
179 
200  bool isTextValid(void) const;
201 
214  const String& getValidationString(void) const
215  {return d_validationString;}
216 
224  size_t getCaratIndex(void) const;
225 
235  size_t getSelectionStartIndex(void) const;
236 
245  size_t getSelectionEndIndex(void) const;
246 
256  size_t getSelectionLength(void) const;
257 
266  utf32 getMaskCodePoint(void) const
267  {return d_maskCodePoint;}
268 
282  size_t getMaxTextLength(void) const
283  {return d_maxTextLen;}
284 
296  void setReadOnly(bool setting);
297 
310  void setTextMasked(bool setting);
311 
327  void setValidationString(const String& validation_string);
328 
341  void setCaratIndex(size_t carat_pos);
342 
360  void setSelection(size_t start_pos, size_t end_pos);
361 
373  void setMaskCodePoint(utf32 code_point);
374 
391  void setMaxTextLength(size_t max_len);
392 
394  Editbox(const String& type, const String& name);
395 
397  virtual ~Editbox(void);
398 
399 protected:
412  size_t getTextIndexFromPosition(const Point& pt) const;
413 
415  void clearSelection(void);
416 
425  void eraseSelectedText(bool modify_text = true);
426 
432  bool isStringValid(const String& str) const;
433 
435  void handleBackspace(void);
436 
438  void handleDelete(void);
439 
441  void handleCharLeft(uint sysKeys);
442 
444  void handleWordLeft(uint sysKeys);
445 
447  void handleCharRight(uint sysKeys);
448 
450  void handleWordRight(uint sysKeys);
451 
453  void handleHome(uint sysKeys);
454 
456  void handleEnd(uint sysKeys);
457 
470  virtual bool testClassName_impl(const String& class_name) const
471  {
472  if (class_name=="Editbox") return true;
473  return Window::testClassName_impl(class_name);
474  }
475 
477  virtual bool validateWindowRenderer(const String& name) const
478  {
479  return (name == "Editbox");
480  }
481 
486  virtual void onReadOnlyChanged(WindowEventArgs& e);
487 
493  virtual void onMaskedRenderingModeChanged(WindowEventArgs& e);
494 
500  virtual void onMaskCodePointChanged(WindowEventArgs& e);
501 
506  virtual void onValidationStringChanged(WindowEventArgs& e);
507 
512  virtual void onMaximumTextLengthChanged(WindowEventArgs& e);
513 
522  virtual void onTextInvalidatedEvent(WindowEventArgs& e);
523 
529  virtual void onInvalidEntryAttempted(WindowEventArgs& e);
530 
535  virtual void onCaratMoved(WindowEventArgs& e);
536 
541  virtual void onTextSelectionChanged(WindowEventArgs& e);
542 
548  virtual void onEditboxFullEvent(WindowEventArgs& e);
549 
555  virtual void onTextAcceptedEvent(WindowEventArgs& e);
556 
557  // Overridden event handlers
558  void onMouseButtonDown(MouseEventArgs& e);
559  void onMouseButtonUp(MouseEventArgs& e);
560  void onMouseDoubleClicked(MouseEventArgs& e);
561  void onMouseTripleClicked(MouseEventArgs& e);
562  void onMouseMove(MouseEventArgs& e);
563  void onCaptureLost(WindowEventArgs& e);
564  void onCharacter(KeyEventArgs& e);
565  void onKeyDown(KeyEventArgs& e);
566  void onTextChanged(WindowEventArgs& e);
567 
575  size_t d_maxTextLen;
577  size_t d_caratPos;
590 
591 private:
592  static EditboxProperties::ReadOnly d_readOnlyProperty;
593  static EditboxProperties::MaskText d_maskTextProperty;
594  static EditboxProperties::MaskCodepoint d_maskCodepointProperty;
595  static EditboxProperties::ValidationString d_validationStringProperty;
596  static EditboxProperties::CaratIndex d_caratIndexProperty;
597  static EditboxProperties::SelectionStart d_selectionStartProperty;
598  static EditboxProperties::SelectionLength d_selectionLengthProperty;
599  static EditboxProperties::MaxTextLength d_maxTextLengthProperty;
600 
601  void addEditboxProperties(void);
602 };
603 
604 } // End of CEGUI namespace section
605 
606 #if defined(_MSC_VER)
607 # pragma warning(pop)
608 #endif
609 
610 #endif // end of guard _CEGUIEditbox_h_