CEGUIEditbox.h

00001 /***********************************************************************
00002         filename:       CEGUIEditbox.h
00003         created:        13/4/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Interface to base class for Editbox widget
00007 *************************************************************************/
00008 /***************************************************************************
00009  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00010  *
00011  *   Permission is hereby granted, free of charge, to any person obtaining
00012  *   a copy of this software and associated documentation files (the
00013  *   "Software"), to deal in the Software without restriction, including
00014  *   without limitation the rights to use, copy, modify, merge, publish,
00015  *   distribute, sublicense, and/or sell copies of the Software, and to
00016  *   permit persons to whom the Software is furnished to do so, subject to
00017  *   the following conditions:
00018  *
00019  *   The above copyright notice and this permission notice shall be
00020  *   included in all copies or substantial portions of the Software.
00021  *
00022  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00023  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00024  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00025  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00026  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00027  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00028  *   OTHER DEALINGS IN THE SOFTWARE.
00029  ***************************************************************************/
00030 #ifndef _CEGUIEditbox_h_
00031 #define _CEGUIEditbox_h_
00032 
00033 #include "CEGUIBase.h"
00034 #include "CEGUIWindow.h"
00035 #include "elements/CEGUIEditboxProperties.h"
00036 
00037 
00038 #if defined(_MSC_VER)
00039 #       pragma warning(push)
00040 #       pragma warning(disable : 4251)
00041 #endif
00042 
00043 
00044 // Start of CEGUI namespace section
00045 namespace CEGUI
00046 {
00047 // forward declare implementation data type
00048 struct RegexValidator;
00049 
00054 class CEGUIEXPORT EditboxWindowRenderer : public WindowRenderer
00055 {
00056 public:
00061     EditboxWindowRenderer(const String& name);
00062 
00073     virtual size_t getTextIndexFromPosition(const Point& pt) const = 0;
00074 };
00075 
00076 
00081 class CEGUIEXPORT Editbox : public Window
00082 {
00083 public:
00084         static const String EventNamespace;                             
00085     static const String WidgetTypeName;             
00086 
00087         /*************************************************************************
00088                 Event name constants
00089         *************************************************************************/
00090         static const String EventReadOnlyModeChanged;                   
00091         static const String EventMaskedRenderingModeChanged;    
00092         static const String EventMaskCodePointChanged;          
00093         static const String EventValidationStringChanged;               
00094         static const String EventMaximumTextLengthChanged;      
00095         static const String EventTextInvalidated;                               
00096         static const String EventInvalidEntryAttempted;         
00097         static const String EventCaratMoved;                                    
00098         static const String EventTextSelectionChanged;          
00099         static const String EventEditboxFull;                                   
00100         static const String EventTextAccepted;                          
00101 
00102 
00103         /*************************************************************************
00104                 Accessor Functions
00105         *************************************************************************/
00113         bool    hasInputFocus(void) const;
00114 
00115 
00124         bool    isReadOnly(void) const          {return d_readOnly;}
00125 
00126 
00135         bool    isTextMasked(void) const        {return d_maskText;}
00136 
00137 
00154         bool    isTextValid(void) const;
00155 
00156 
00168         const String&   getValidationString(void) const         {return d_validationString;}
00169 
00170 
00178         size_t  getCaratIndex(void) const               {return d_caratPos;}
00179 
00180 
00189         size_t  getSelectionStartIndex(void) const;
00190 
00191 
00200         size_t  getSelectionEndIndex(void) const;
00201 
00202         
00210         size_t  getSelectionLength(void) const;
00211 
00212 
00221         utf32   getMaskCodePoint(void) const            {return d_maskCodePoint;}
00222 
00223 
00235         size_t  getMaxTextLength(void) const            {return d_maxTextLen;}
00236 
00237 
00238         /*************************************************************************
00239                 Manipulators
00240         *************************************************************************/
00252         void    setReadOnly(bool setting);
00253 
00254 
00266         void    setTextMasked(bool setting);
00267 
00268 
00283         void    setValidationString(const String& validation_string);
00284 
00285 
00297         void    setCaratIndex(size_t carat_pos);
00298 
00299 
00315         void    setSelection(size_t start_pos, size_t end_pos);
00316         
00317 
00329         void    setMaskCodePoint(utf32 code_point);
00330 
00331 
00346         void    setMaxTextLength(size_t max_len);
00347 
00348 
00349         /*************************************************************************
00350                 Construction / Destruction
00351         *************************************************************************/
00356         Editbox(const String& type, const String& name);
00357 
00358 
00363         virtual ~Editbox(void);
00364 
00365 
00366 protected:
00367         /*************************************************************************
00368                 Implementation functions
00369         *************************************************************************/
00380         size_t  getTextIndexFromPosition(const Point& pt) const;
00381 
00382 
00393     //virtual size_t  getTextIndexFromPosition_impl(const Point& pt) const = 0;
00394 
00395 
00400         void    clearSelection(void);
00401 
00402 
00410         void    eraseSelectedText(bool modify_text = true);
00411 
00412 
00417         bool    isStringValid(const String& str) const;
00418 
00419 
00420 
00425         void    handleBackspace(void);
00426 
00427 
00432         void    handleDelete(void);
00433 
00434 
00439         void    handleCharLeft(uint sysKeys);
00440 
00441 
00446         void    handleWordLeft(uint sysKeys);
00447 
00448 
00453         void    handleCharRight(uint sysKeys);
00454 
00455 
00460         void    handleWordRight(uint sysKeys);
00461 
00462 
00467         void    handleHome(uint sysKeys);
00468 
00469 
00474         void    handleEnd(uint sysKeys);
00475 
00476 
00487         virtual bool    testClassName_impl(const String& class_name) const
00488         {
00489                 if (class_name=="Editbox")      return true;
00490                 return Window::testClassName_impl(class_name);
00491         }
00492     
00493     // validate window renderer
00494     virtual bool    validateWindowRenderer(const String& name) const
00495     {
00496         return (name == "Editbox");
00497     }
00498 
00499         /*************************************************************************
00500                 New event handlers
00501         *************************************************************************/
00506         virtual void    onReadOnlyChanged(WindowEventArgs& e);
00507 
00508 
00513         virtual void    onMaskedRenderingModeChanged(WindowEventArgs& e);
00514 
00515 
00520         virtual void    onMaskCodePointChanged(WindowEventArgs& e);
00521 
00522 
00527         virtual void    onValidationStringChanged(WindowEventArgs& e);
00528 
00529 
00534         virtual void    onMaximumTextLengthChanged(WindowEventArgs& e);
00535 
00536 
00544         virtual void    onTextInvalidatedEvent(WindowEventArgs& e);
00545 
00546 
00552         virtual void    onInvalidEntryAttempted(WindowEventArgs& e);
00553 
00554 
00559         virtual void    onCaratMoved(WindowEventArgs& e);
00560 
00561 
00566         virtual void    onTextSelectionChanged(WindowEventArgs& e);
00567 
00568 
00573         virtual void    onEditboxFullEvent(WindowEventArgs& e);
00574 
00575 
00580         virtual void    onTextAcceptedEvent(WindowEventArgs& e);
00581 
00582         
00583         /*************************************************************************
00584                 Overridden event handlers
00585         *************************************************************************/
00586         virtual void    onMouseButtonDown(MouseEventArgs& e);
00587         virtual void    onMouseButtonUp(MouseEventArgs& e);
00588         virtual void    onMouseDoubleClicked(MouseEventArgs& e);
00589         virtual void    onMouseTripleClicked(MouseEventArgs& e);
00590         virtual void    onMouseMove(MouseEventArgs& e);
00591         virtual void    onCaptureLost(WindowEventArgs& e);
00592         virtual void    onCharacter(KeyEventArgs& e);
00593         virtual void    onKeyDown(KeyEventArgs& e);
00594         virtual void    onTextChanged(WindowEventArgs& e);
00595 
00596 
00597         /*************************************************************************
00598                 Implementation data
00599         *************************************************************************/
00600         bool    d_readOnly;                     
00601         bool    d_maskText;                     
00602         utf32   d_maskCodePoint;        
00603         size_t  d_maxTextLen;           
00604         size_t  d_caratPos;                     
00605         size_t  d_selectionStart;       
00606         size_t  d_selectionEnd;         
00607         String  d_validationString;     
00608         RegexValidator* d_validator;            
00609         bool    d_dragging;                     
00610         size_t  d_dragAnchorIdx;        
00611 
00612 private:
00613         /*************************************************************************
00614                 Static Properties for this class
00615         *************************************************************************/
00616         static EditboxProperties::ReadOnly                                      d_readOnlyProperty;
00617         static EditboxProperties::MaskText                                      d_maskTextProperty;
00618         static EditboxProperties::MaskCodepoint                         d_maskCodepointProperty;
00619         static EditboxProperties::ValidationString                      d_validationStringProperty;
00620         static EditboxProperties::CaratIndex                            d_caratIndexProperty;
00621         static EditboxProperties::SelectionStart                        d_selectionStartProperty;
00622         static EditboxProperties::SelectionLength                       d_selectionLengthProperty;
00623         static EditboxProperties::MaxTextLength                         d_maxTextLengthProperty;
00624 
00625         /*************************************************************************
00626                 Private methods
00627         *************************************************************************/
00628         void    addEditboxProperties(void);
00629 };
00630 
00631 } // End of  CEGUI namespace section
00632 
00633 
00634 #if defined(_MSC_VER)
00635 #       pragma warning(pop)
00636 #endif
00637 
00638 #endif  // end of guard _CEGUIEditbox_h_

Generated on Sun Nov 5 14:35:28 2006 for Crazy Eddies GUI System by  doxygen 1.4.7