Crazy Eddies GUI System: CEGUIMultiLineEditbox.h Source File

Crazy Eddies GUI System 0.7.6

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

- File List

CEGUIMultiLineEditbox.h

    00001 /***********************************************************************
    00002         filename:       CEGUIMultiLineEditbox.h
    00003         created:        30/6/2004
    00004         author:         Paul D Turner
    00005
    00006         purpose:        Interface to the Multi-lien edit box base class.
    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 _CEGUIMultiLineEditbox_h_
    00031 #define _CEGUIMultiLineEditbox_h_
    00032
    00033 #include "../CEGUIBase.h"
    00034 #include "../CEGUIWindow.h"
    00035 #include "../CEGUIFont.h"
    00036 #include "CEGUIMultiLineEditboxProperties.h"
    00037
    00038 #include <vector>
    00039
    00040
    00041 #if defined(_MSC_VER)
    00042 #       pragma warning(push)
    00043 #       pragma warning(disable : 4251)
    00044 #endif
    00045
    00046
    00047 // Start of CEGUI namespace section
    00048 namespace CEGUI
    00049 {
    00054 class CEGUIEXPORT MultiLineEditboxWindowRenderer : public WindowRenderer
    00055 {
    00056 public:
    00061     MultiLineEditboxWindowRenderer(const String& name);
    00062
    00071     virtual Rect getTextRenderArea(void) const = 0;
    00072
    00073 protected:
    00074     // base class overrides
    00075     void onLookNFeelAssigned();
    00076 };
    00077
    00082 class CEGUIEXPORT MultiLineEditbox : public Window
    00083 {
    00084 public:
    00085         static const String EventNamespace;
    00086     static const String WidgetTypeName;
    00087
    00088         /*************************************************************************
    00089                 Constants
    00090         *************************************************************************/
    00091         // event names
    00097         static const String EventReadOnlyModeChanged;
    00103         static const String EventWordWrapModeChanged;
    00110         static const String EventMaximumTextLengthChanged;
    00116         static const String EventCaratMoved;
    00122         static const String EventTextSelectionChanged;
    00129         static const String EventEditboxFull;
    00136         static const String EventVertScrollbarModeChanged;
    00143         static const String EventHorzScrollbarModeChanged;
    00144
    00145     /*************************************************************************
    00146         Child Widget name suffix constants
    00147     *************************************************************************/
    00148     static const String VertScrollbarNameSuffix;
    00149     static const String HorzScrollbarNameSuffix;
    00150
    00151     /*************************************************************************
    00152         Implementation struct
    00153     *************************************************************************/
    00159     struct LineInfo
    00160     {
    00161         size_t  d_startIdx;
    00162         size_t  d_length;
    00163         float   d_extent;
    00164     };
    00165     typedef std::vector<LineInfo>   LineList;
    00166
    00167         /*************************************************************************
    00168                 Accessor Functions
    00169         *************************************************************************/
    00178         bool    hasInputFocus(void) const;
    00179
    00180
    00189         bool    isReadOnly(void) const          {return d_readOnly;}
    00190
    00191
    00199         size_t  getCaratIndex(void) const               {return d_caratPos;}
    00200
    00201
    00210         size_t  getSelectionStartIndex(void) const;
    00211
    00212
    00221         size_t  getSelectionEndIndex(void) const;
    00222
    00223
    00231         size_t  getSelectionLength(void) const;
    00232
    00233
    00241         size_t  getMaxTextLength(void) const            {return d_maxTextLen;}
    00242
    00243
    00252         bool    isWordWrapped(void) const;
    00253
    00254
    00266     Scrollbar* getVertScrollbar() const;
    00267
    00276         bool    isVertScrollbarAlwaysShown(void) const;
    00277
    00289     Scrollbar* getHorzScrollbar() const;
    00290
    00291
    00300     Rect    getTextRenderArea(void) const;
    00301
    00302     // get d_lines
    00303     const LineList& getFormattedLines(void) const   {return d_lines;}
    00304
    00310     size_t  getLineNumberFromIndex(size_t index) const;
    00311
    00312         /*************************************************************************
    00313                 Manipulators
    00314         *************************************************************************/
    00325         virtual void    initialiseComponents(void);
    00326
    00327
    00339         void    setReadOnly(bool setting);
    00340
    00341
    00353         void    setCaratIndex(size_t carat_pos);
    00354
    00355
    00371         void    setSelection(size_t start_pos, size_t end_pos);
    00372
    00373
    00384         void    setMaxTextLength(size_t max_len);
    00385
    00386
    00391         void    ensureCaratIsVisible(void);
    00392
    00393
    00405         void    setWordWrapping(bool setting);
    00406
    00418         void    setShowVertScrollbar(bool setting);
    00419
    00420     // selection brush image property support
    00421     void setSelectionBrushImage(const Image* image);
    00422     const Image* getSelectionBrushImage() const;
    00423
    00424         /*************************************************************************
    00425                 Construction and Destruction
    00426         *************************************************************************/
    00431         MultiLineEditbox(const String& type, const String& name);
    00432
    00433
    00438         virtual ~MultiLineEditbox(void);
    00439
    00440
    00441 protected:
    00442         /*************************************************************************
    00443                 Implementation Methods (abstract)
    00444         *************************************************************************/
    00453         //virtual       Rect    getTextRenderArea_impl(void) const              = 0;
    00454
    00455
    00456         /*************************************************************************
    00457                 Implementation Methods
    00458         *************************************************************************/
    00465         void    formatText(void);
    00466
    00475     void formatText(const bool update_scrollbars);
    00476
    00487         size_t  getNextTokenLength(const String& text, size_t start_idx) const;
    00488
    00489
    00494         void    configureScrollbars(void);
    00495
    00496
    00507         size_t  getTextIndexFromPosition(const Point& pt) const;
    00508
    00509
    00514         void    clearSelection(void);
    00515
    00516
    00524         void    eraseSelectedText(bool modify_text = true);
    00525
    00526
    00531         void    handleBackspace(void);
    00532
    00533
    00538         void    handleDelete(void);
    00539
    00540
    00545         void    handleCharLeft(uint sysKeys);
    00546
    00547
    00552         void    handleWordLeft(uint sysKeys);
    00553
    00554
    00559         void    handleCharRight(uint sysKeys);
    00560
    00561
    00566         void    handleWordRight(uint sysKeys);
    00567
    00568
    00573         void    handleDocHome(uint sysKeys);
    00574
    00575
    00580         void    handleDocEnd(uint sysKeys);
    00581
    00582
    00587         void    handleLineHome(uint sysKeys);
    00588
    00589
    00594         void    handleLineEnd(uint sysKeys);
    00595
    00596
    00601         void    handleLineUp(uint sysKeys);
    00602
    00603
    00608         void    handleLineDown(uint sysKeys);
    00609
    00610
    00615         void    handleNewLine(uint sysKeys);
    00616
    00617
    00622     void    handlePageUp(uint sysKeys);
    00623
    00624
    00629     void    handlePageDown(uint sysKeys);
    00630
    00631
    00642         virtual bool    testClassName_impl(const String& class_name) const
    00643         {
    00644                 if ((class_name=="MultiLineEditBox") ||
    00645                         (class_name=="MultiLineEditbox"))
    00646                 {
    00647                         return true;
    00648                 }
    00649
    00650                 return Window::testClassName_impl(class_name);
    00651         }
    00652
    00657     bool handle_scrollChange(const EventArgs& args);
    00658
    00659     // handler triggered when vertical scrollbar is shown or hidden
    00660     bool handle_vertScrollbarVisibilityChanged(const EventArgs&);
    00661
    00662     // validate window renderer
    00663     virtual bool validateWindowRenderer(const String& name) const
    00664     {
    00665         return (name == EventNamespace);
    00666     }
    00667
    00668         /*************************************************************************
    00669                 New event handlers
    00670         *************************************************************************/
    00675         void    onReadOnlyChanged(WindowEventArgs& e);
    00676
    00677
    00682         void    onWordWrapModeChanged(WindowEventArgs& e);
    00683
    00684
    00689         void    onMaximumTextLengthChanged(WindowEventArgs& e);
    00690
    00691
    00696         void    onCaratMoved(WindowEventArgs& e);
    00697
    00698
    00703         void    onTextSelectionChanged(WindowEventArgs& e);
    00704
    00705
    00710         void    onEditboxFullEvent(WindowEventArgs& e);
    00711
    00712
    00717         void    onVertScrollbarModeChanged(WindowEventArgs& e);
    00718
    00719
    00724         void    onHorzScrollbarModeChanged(WindowEventArgs& e);
    00725
    00726
    00727         /*************************************************************************
    00728                 Overridden event handlers
    00729         *************************************************************************/
    00730         virtual void    onMouseButtonDown(MouseEventArgs& e);
    00731         virtual void    onMouseButtonUp(MouseEventArgs& e);
    00732         virtual void    onMouseDoubleClicked(MouseEventArgs& e);
    00733         virtual void    onMouseTripleClicked(MouseEventArgs& e);
    00734         virtual void    onMouseMove(MouseEventArgs& e);
    00735         virtual void    onCaptureLost(WindowEventArgs& e);
    00736         virtual void    onCharacter(KeyEventArgs& e);
    00737         virtual void    onKeyDown(KeyEventArgs& e);
    00738         virtual void    onTextChanged(WindowEventArgs& e);
    00739         virtual void    onSized(WindowEventArgs& e);
    00740         virtual void    onMouseWheel(MouseEventArgs& e);
    00741
    00742
    00743         /*************************************************************************
    00744                 Implementation data
    00745         *************************************************************************/
    00746         bool    d_readOnly;
    00747         size_t  d_maxTextLen;
    00748         size_t  d_caratPos;
    00749         size_t  d_selectionStart;
    00750         size_t  d_selectionEnd;
    00751         bool    d_dragging;
    00752         size_t  d_dragAnchorIdx;
    00753
    00754         static String d_lineBreakChars;
    00755         bool            d_wordWrap;
    00756         LineList        d_lines;
    00757         float           d_widestExtent;
    00758
    00759         // component widget settings
    00760         bool    d_forceVertScroll;
    00761         bool    d_forceHorzScroll;
    00762
    00763         // images
    00764         const Image*    d_selectionBrush;
    00765
    00766
    00767 private:
    00768         /*************************************************************************
    00769                 Static Properties for this class
    00770         *************************************************************************/
    00771         static MultiLineEditboxProperties::ReadOnly                                     d_readOnlyProperty;
    00772         static MultiLineEditboxProperties::WordWrap                                     d_wordWrapProperty;
    00773         static MultiLineEditboxProperties::CaratIndex                           d_caratIndexProperty;
    00774         static MultiLineEditboxProperties::SelectionStart                       d_selectionStartProperty;
    00775         static MultiLineEditboxProperties::SelectionLength                      d_selectionLengthProperty;
    00776         static MultiLineEditboxProperties::MaxTextLength                        d_maxTextLengthProperty;
    00777     static MultiLineEditboxProperties::SelectionBrushImage      d_selectionBrushProperty;
    00778     static MultiLineEditboxProperties::ForceVertScrollbar           d_forceVertProperty;
    00779
    00780
    00781         /*************************************************************************
    00782                 Private methods
    00783         *************************************************************************/
    00784         void    addMultiLineEditboxProperties(void);
    00785 };
    00786
    00787 } // End of  CEGUI namespace section
    00788
    00789 #if defined(_MSC_VER)
    00790 #       pragma warning(pop)
    00791 #endif
    00792
    00793 #endif  // end of guard _CEGUIMultiLineEditbox_h_