Crazy Eddies GUI System: CEGUIEditbox.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

# 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     Crazy Eddie's GUI System (http://www.cegui.org.uk)
    00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
    00011
    00012     This library is free software; you can redistribute it and/or
    00013     modify it under the terms of the GNU Lesser General Public
    00014     License as published by the Free Software Foundation; either
    00015     version 2.1 of the License, or (at your option) any later version.
    00016
    00017     This library is distributed in the hope that it will be useful,
    00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00020     Lesser General Public License for more details.
    00021
    00022     You should have received a copy of the GNU Lesser General Public
    00023     License along with this library; if not, write to the Free Software
    00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00025 *************************************************************************/
    00026 #ifndef _CEGUIEditbox_h_
    00027 #define _CEGUIEditbox_h_
    00028
    00029 #include "CEGUIBase.h"
    00030 #include "CEGUIWindow.h"
    00031 #include "elements/CEGUIEditboxProperties.h"
    00032
    00033
    00034 #if defined(_MSC_VER)
    00035 #       pragma warning(push)
    00036 #       pragma warning(disable : 4251)
    00037 #endif
    00038
    00039
    00040 // Start of CEGUI namespace section
    00041 namespace CEGUI
    00042 {
    00043 // forward declare implementation data type
    00044 struct RegexValidator;
    00045
    00046
    00051 class CEGUIEXPORT Editbox : public Window
    00052 {
    00053 public:
    00054         static const String EventNamespace;
    00055
    00056
    00057         /*************************************************************************
    00058                 Constants
    00059         *************************************************************************/
    00060         // default colours
    00061         static const argb_t     DefaultNormalTextColour;
    00062         static const argb_t     DefaultSelectedTextColour;
    00063         static const argb_t     DefaultNormalSelectionColour;
    00064         static const argb_t     DefaultInactiveSelectionColour;
    00065
    00066
    00067         /*************************************************************************
    00068                 Event name constants
    00069         *************************************************************************/
    00070         static const String EventReadOnlyModeChanged;
    00071         static const String EventMaskedRenderingModeChanged;
    00072         static const String EventMaskCodePointChanged;
    00073         static const String EventValidationStringChanged;
    00074         static const String EventMaximumTextLengthChanged;
    00075         static const String EventTextInvalidated;
    00076         static const String EventInvalidEntryAttempted;
    00077         static const String EventCaratMoved;
    00078         static const String EventTextSelectionChanged;
    00079         static const String EventEditboxFull;
    00080         static const String EventTextAccepted;
    00081
    00082
    00083         /*************************************************************************
    00084                 Accessor Functions
    00085         *************************************************************************/
    00093         bool    hasInputFocus(void) const;
    00094
    00095
    00104         bool    isReadOnly(void) const          {return d_readOnly;}
    00105
    00106
    00115         bool    isTextMasked(void) const        {return d_maskText;}
    00116
    00117
    00134         bool    isTextValid(void) const;
    00135
    00136
    00148         const String&   getValidationString(void) const         {return d_validationString;}
    00149
    00150
    00158         size_t  getCaratIndex(void) const               {return d_caratPos;}
    00159
    00160
    00169         size_t  getSelectionStartIndex(void) const;
    00170
    00171
    00180         size_t  getSelectionEndIndex(void) const;
    00181
    00182
    00190         size_t  getSelectionLength(void) const;
    00191
    00192
    00201         utf32   getMaskCodePoint(void) const            {return d_maskCodePoint;}
    00202
    00203
    00215         size_t  getMaxTextLength(void) const            {return d_maxTextLen;}
    00216
    00217
    00226         colour  getNormalTextColour(void) const                         {return d_normalTextColour;}
    00227
    00228
    00237         colour  getSelectedTextColour(void) const                       {return d_selectTextColour;}
    00238
    00239
    00248         colour  getNormalSelectBrushColour(void) const          {return d_selectBrushColour;}
    00249
    00250
    00259         colour  getInactiveSelectBrushColour(void) const        {return d_inactiveSelectBrushColour;}
    00260
    00261
    00262         /*************************************************************************
    00263                 Manipulators
    00264         *************************************************************************/
    00276         void    setReadOnly(bool setting);
    00277
    00278
    00290         void    setTextMasked(bool setting);
    00291
    00292
    00307         void    setValidationString(const String& validation_string);
    00308
    00309
    00321         void    setCaratIndex(size_t carat_pos);
    00322
    00323
    00339         void    setSelection(size_t start_pos, size_t end_pos);
    00340
    00341
    00353         void    setMaskCodePoint(utf32 code_point);
    00354
    00355
    00370         void    setMaxTextLength(size_t max_len);
    00371
    00372
    00383         void    setNormalTextColour(const colour& col);
    00384
    00385
    00394         void    setSelectedTextColour(const colour& col);
    00395
    00396
    00408         void    setNormalSelectBrushColour(const colour& col);
    00409
    00410
    00422         void    setInactiveSelectBrushColour(const colour& col);
    00423
    00424
    00425         /*************************************************************************
    00426                 Construction / Destruction
    00427         *************************************************************************/
    00432         Editbox(const String& type, const String& name);
    00433
    00434
    00439         virtual ~Editbox(void);
    00440
    00441
    00442 protected:
    00443         /*************************************************************************
    00444                 Implementation functions
    00445         *************************************************************************/
    00450         void    addEditboxEvents(void);
    00451
    00452
    00463         virtual size_t  getTextIndexFromPosition(const Point& pt) const         = 0;
    00464
    00465
    00470         void    clearSelection(void);
    00471
    00472
    00480         void    eraseSelectedText(bool modify_text = true);
    00481
    00482
    00487         bool    isStringValid(const String& str) const;
    00488
    00489
    00490
    00495         void    handleBackspace(void);
    00496
    00497
    00502         void    handleDelete(void);
    00503
    00504
    00509         void    handleCharLeft(uint sysKeys);
    00510
    00511
    00516         void    handleWordLeft(uint sysKeys);
    00517
    00518
    00523         void    handleCharRight(uint sysKeys);
    00524
    00525
    00530         void    handleWordRight(uint sysKeys);
    00531
    00532
    00537         void    handleHome(uint sysKeys);
    00538
    00539
    00544         void    handleEnd(uint sysKeys);
    00545
    00546
    00557         virtual bool    testClassName_impl(const String& class_name) const
    00558         {
    00559                 if (class_name==(const utf8*)"Editbox") return true;
    00560                 return Window::testClassName_impl(class_name);
    00561         }
    00562
    00563
    00564         /*************************************************************************
    00565                 New event handlers
    00566         *************************************************************************/
    00571         virtual void    onReadOnlyChanged(WindowEventArgs& e);
    00572
    00573
    00578         virtual void    onMaskedRenderingModeChanged(WindowEventArgs& e);
    00579
    00580
    00585         virtual void    onMaskCodePointChanged(WindowEventArgs& e);
    00586
    00587
    00592         virtual void    onValidationStringChanged(WindowEventArgs& e);
    00593
    00594
    00599         virtual void    onMaximumTextLengthChanged(WindowEventArgs& e);
    00600
    00601
    00609         virtual void    onTextInvalidatedEvent(WindowEventArgs& e);
    00610
    00611
    00617         virtual void    onInvalidEntryAttempted(WindowEventArgs& e);
    00618
    00619
    00624         virtual void    onCaratMoved(WindowEventArgs& e);
    00625
    00626
    00631         virtual void    onTextSelectionChanged(WindowEventArgs& e);
    00632
    00633
    00638         virtual void    onEditboxFullEvent(WindowEventArgs& e);
    00639
    00640
    00645         virtual void    onTextAcceptedEvent(WindowEventArgs& e);
    00646
    00647
    00648         /*************************************************************************
    00649                 Overridden event handlers
    00650         *************************************************************************/
    00651         virtual void    onMouseButtonDown(MouseEventArgs& e);
    00652         virtual void    onMouseButtonUp(MouseEventArgs& e);
    00653         virtual void    onMouseDoubleClicked(MouseEventArgs& e);
    00654         virtual void    onMouseTripleClicked(MouseEventArgs& e);
    00655         virtual void    onMouseMove(MouseEventArgs& e);
    00656         virtual void    onCaptureLost(WindowEventArgs& e);
    00657         virtual void    onCharacter(KeyEventArgs& e);
    00658         virtual void    onKeyDown(KeyEventArgs& e);
    00659         virtual void    onTextChanged(WindowEventArgs& e);
    00660
    00661
    00662         /*************************************************************************
    00663                 Implementation data
    00664         *************************************************************************/
    00665         bool    d_readOnly;
    00666         bool    d_maskText;
    00667         utf32   d_maskCodePoint;
    00668         size_t  d_maxTextLen;
    00669         size_t  d_caratPos;
    00670         size_t  d_selectionStart;
    00671         size_t  d_selectionEnd;
    00672         String  d_validationString;
    00673         RegexValidator* d_validator;
    00674         bool    d_dragging;
    00675         size_t  d_dragAnchorIdx;
    00676
    00677         // basic rendering colours
    00678         colour  d_normalTextColour;
    00679         colour  d_selectTextColour;
    00680         colour  d_selectBrushColour;
    00681         colour  d_inactiveSelectBrushColour;
    00682
    00683
    00684 private:
    00685         /*************************************************************************
    00686                 Static Properties for this class
    00687         *************************************************************************/
    00688         static EditboxProperties::ReadOnly                                      d_readOnlyProperty;
    00689         static EditboxProperties::MaskText                                      d_maskTextProperty;
    00690         static EditboxProperties::MaskCodepoint                         d_maskCodepointProperty;
    00691         static EditboxProperties::ValidationString                      d_validationStringProperty;
    00692         static EditboxProperties::CaratIndex                            d_caratIndexProperty;
    00693         static EditboxProperties::SelectionStart                        d_selectionStartProperty;
    00694         static EditboxProperties::SelectionLength                       d_selectionLengthProperty;
    00695         static EditboxProperties::MaxTextLength                         d_maxTextLengthProperty;
    00696         static EditboxProperties::NormalTextColour                      d_normalTextColourProperty;
    00697         static EditboxProperties::SelectedTextColour            d_selectedTextColourProperty;
    00698         static EditboxProperties::ActiveSelectionColour         d_activeSelectionColourProperty;
    00699         static EditboxProperties::InactiveSelectionColour       d_inactiveSelectionColourProperty;
    00700
    00701
    00702         /*************************************************************************
    00703                 Private methods
    00704         *************************************************************************/
    00705         void    addEditboxProperties(void);
    00706 };
    00707
    00708 } // End of  CEGUI namespace section
    00709
    00710
    00711 #if defined(_MSC_VER)
    00712 #       pragma warning(pop)
    00713 #endif
    00714
    00715 #endif  // end of guard _CEGUIEditbox_h_