Crazy Eddies GUI System  0.6.2
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 - 2006 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 "elements/CEGUIEditboxProperties.h"
36 
37 
38 #if defined(_MSC_VER)
39 # pragma warning(push)
40 # pragma warning(disable : 4251)
41 #endif
42 
43 
44 // Start of CEGUI namespace section
45 namespace CEGUI
46 {
47 // forward declare implementation data type
48 struct RegexValidator;
49 
54 class CEGUIEXPORT EditboxWindowRenderer : public WindowRenderer
55 {
56 public:
61  EditboxWindowRenderer(const String& name);
62 
73  virtual size_t getTextIndexFromPosition(const Point& pt) const = 0;
74 };
75 
76 
81 class CEGUIEXPORT Editbox : public Window
82 {
83 public:
84  static const String EventNamespace;
85  static const String WidgetTypeName;
86 
87  /*************************************************************************
88  Event name constants
89  *************************************************************************/
97  static const String EventCaratMoved;
99  static const String EventEditboxFull;
100  static const String EventTextAccepted;
101 
102 
103  /*************************************************************************
104  Accessor Functions
105  *************************************************************************/
113  bool hasInputFocus(void) const;
114 
115 
124  bool isReadOnly(void) const {return d_readOnly;}
125 
126 
135  bool isTextMasked(void) const {return d_maskText;}
136 
137 
154  bool isTextValid(void) const;
155 
156 
168  const String& getValidationString(void) const {return d_validationString;}
169 
170 
178  size_t getCaratIndex(void) const {return d_caratPos;}
179 
180 
189  size_t getSelectionStartIndex(void) const;
190 
191 
200  size_t getSelectionEndIndex(void) const;
201 
202 
210  size_t getSelectionLength(void) const;
211 
212 
221  utf32 getMaskCodePoint(void) const {return d_maskCodePoint;}
222 
223 
235  size_t getMaxTextLength(void) const {return d_maxTextLen;}
236 
237 
238  /*************************************************************************
239  Manipulators
240  *************************************************************************/
252  void setReadOnly(bool setting);
253 
254 
266  void setTextMasked(bool setting);
267 
268 
283  void setValidationString(const String& validation_string);
284 
285 
297  void setCaratIndex(size_t carat_pos);
298 
299 
315  void setSelection(size_t start_pos, size_t end_pos);
316 
317 
329  void setMaskCodePoint(utf32 code_point);
330 
331 
346  void setMaxTextLength(size_t max_len);
347 
348 
349  /*************************************************************************
350  Construction / Destruction
351  *************************************************************************/
356  Editbox(const String& type, const String& name);
357 
358 
363  virtual ~Editbox(void);
364 
365 
366 protected:
367  /*************************************************************************
368  Implementation functions
369  *************************************************************************/
380  size_t getTextIndexFromPosition(const Point& pt) const;
381 
382 
393  //virtual size_t getTextIndexFromPosition_impl(const Point& pt) const = 0;
394 
395 
400  void clearSelection(void);
401 
402 
410  void eraseSelectedText(bool modify_text = true);
411 
412 
417  bool isStringValid(const String& str) const;
418 
419 
420 
425  void handleBackspace(void);
426 
427 
432  void handleDelete(void);
433 
434 
439  void handleCharLeft(uint sysKeys);
440 
441 
446  void handleWordLeft(uint sysKeys);
447 
448 
453  void handleCharRight(uint sysKeys);
454 
455 
460  void handleWordRight(uint sysKeys);
461 
462 
467  void handleHome(uint sysKeys);
468 
469 
474  void handleEnd(uint sysKeys);
475 
476 
487  virtual bool testClassName_impl(const String& class_name) const
488  {
489  if (class_name=="Editbox") return true;
490  return Window::testClassName_impl(class_name);
491  }
492 
493  // validate window renderer
494  virtual bool validateWindowRenderer(const String& name) const
495  {
496  return (name == "Editbox");
497  }
498 
499  /*************************************************************************
500  New event handlers
501  *************************************************************************/
506  virtual void onReadOnlyChanged(WindowEventArgs& e);
507 
508 
513  virtual void onMaskedRenderingModeChanged(WindowEventArgs& e);
514 
515 
520  virtual void onMaskCodePointChanged(WindowEventArgs& e);
521 
522 
527  virtual void onValidationStringChanged(WindowEventArgs& e);
528 
529 
534  virtual void onMaximumTextLengthChanged(WindowEventArgs& e);
535 
536 
544  virtual void onTextInvalidatedEvent(WindowEventArgs& e);
545 
546 
552  virtual void onInvalidEntryAttempted(WindowEventArgs& e);
553 
554 
559  virtual void onCaratMoved(WindowEventArgs& e);
560 
561 
566  virtual void onTextSelectionChanged(WindowEventArgs& e);
567 
568 
573  virtual void onEditboxFullEvent(WindowEventArgs& e);
574 
575 
580  virtual void onTextAcceptedEvent(WindowEventArgs& e);
581 
582 
583  /*************************************************************************
584  Overridden event handlers
585  *************************************************************************/
586  virtual void onMouseButtonDown(MouseEventArgs& e);
587  virtual void onMouseButtonUp(MouseEventArgs& e);
588  virtual void onMouseDoubleClicked(MouseEventArgs& e);
589  virtual void onMouseTripleClicked(MouseEventArgs& e);
590  virtual void onMouseMove(MouseEventArgs& e);
591  virtual void onCaptureLost(WindowEventArgs& e);
592  virtual void onCharacter(KeyEventArgs& e);
593  virtual void onKeyDown(KeyEventArgs& e);
594  virtual void onTextChanged(WindowEventArgs& e);
595 
596 
597  /*************************************************************************
598  Implementation data
599  *************************************************************************/
600  bool d_readOnly;
601  bool d_maskText;
603  size_t d_maxTextLen;
604  size_t d_caratPos;
606  size_t d_selectionEnd;
609  bool d_dragging;
611 
612 private:
613  /*************************************************************************
614  Static Properties for this class
615  *************************************************************************/
616  static EditboxProperties::ReadOnly d_readOnlyProperty;
617  static EditboxProperties::MaskText d_maskTextProperty;
618  static EditboxProperties::MaskCodepoint d_maskCodepointProperty;
619  static EditboxProperties::ValidationString d_validationStringProperty;
620  static EditboxProperties::CaratIndex d_caratIndexProperty;
621  static EditboxProperties::SelectionStart d_selectionStartProperty;
622  static EditboxProperties::SelectionLength d_selectionLengthProperty;
623  static EditboxProperties::MaxTextLength d_maxTextLengthProperty;
624 
625  /*************************************************************************
626  Private methods
627  *************************************************************************/
628  void addEditboxProperties(void);
629 };
630 
631 } // End of CEGUI namespace section
632 
633 
634 #if defined(_MSC_VER)
635 # pragma warning(pop)
636 #endif
637 
638 #endif // end of guard _CEGUIEditbox_h_