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 "elements/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 
00078 class CEGUIEXPORT MultiLineEditbox : public Window
00079 {
00080 public:
00081         static const String EventNamespace;                             
00082     static const String WidgetTypeName;             
00083 
00084         /*************************************************************************
00085                 Constants
00086         *************************************************************************/
00087         // event names
00088         static const String EventReadOnlyModeChanged;                   
00089         static const String EventWordWrapModeChanged;                   
00090         static const String EventMaximumTextLengthChanged;      
00091         static const String EventCaratMoved;                                    
00092         static const String EventTextSelectionChanged;          
00093         static const String EventEditboxFull;                                   
00094         static const String EventVertScrollbarModeChanged;      
00095         static const String EventHorzScrollbarModeChanged;      
00096 
00097     /*************************************************************************
00098         Child Widget name suffix constants
00099     *************************************************************************/
00100     static const String VertScrollbarNameSuffix;   
00101     static const String HorzScrollbarNameSuffix;   
00102 
00103     /*************************************************************************
00104         Implementation struct
00105     *************************************************************************/
00111     struct LineInfo
00112     {
00113         size_t  d_startIdx;     
00114         size_t  d_length;       
00115         float   d_extent;       
00116     };
00117     typedef std::vector<LineInfo>   LineList;   
00118 
00119         /*************************************************************************
00120                 Accessor Functions
00121         *************************************************************************/
00130         bool    hasInputFocus(void) const;
00131 
00132 
00141         bool    isReadOnly(void) const          {return d_readOnly;}
00142 
00143 
00151         size_t  getCaratIndex(void) const               {return d_caratPos;}
00152 
00153 
00162         size_t  getSelectionStartIndex(void) const;
00163 
00164 
00173         size_t  getSelectionEndIndex(void) const;
00174 
00175         
00183         size_t  getSelectionLength(void) const;
00184 
00185 
00193         size_t  getMaxTextLength(void) const            {return d_maxTextLen;}
00194 
00195 
00204         bool    isWordWrapped(void) const;
00205 
00206 
00218     Scrollbar* getVertScrollbar() const;
00219 
00228         bool    isVertScrollbarAlwaysShown(void) const;
00229 
00241     Scrollbar* getHorzScrollbar() const;
00242 
00243 
00252     Rect    getTextRenderArea(void) const;
00253 
00254     // get d_lines
00255     const LineList& getFormattedLines(void) const   {return d_lines;}
00256 
00262     size_t  getLineNumberFromIndex(size_t index) const;
00263 
00264         /*************************************************************************
00265                 Manipulators
00266         *************************************************************************/
00277         virtual void    initialiseComponents(void);
00278 
00279 
00291         void    setReadOnly(bool setting);
00292 
00293 
00305         void    setCaratIndex(size_t carat_pos);
00306 
00307 
00323         void    setSelection(size_t start_pos, size_t end_pos);
00324         
00325 
00336         void    setMaxTextLength(size_t max_len);
00337 
00338 
00343         void    ensureCaratIsVisible(void);
00344 
00345 
00357         void    setWordWrapping(bool setting);
00358 
00370         void    setShowVertScrollbar(bool setting);
00371 
00372     // selection brush image property support
00373     void setSelectionBrushImage(const Image* image);
00374     const Image* getSelectionBrushImage() const;
00375 
00376         /*************************************************************************
00377                 Construction and Destruction
00378         *************************************************************************/
00383         MultiLineEditbox(const String& type, const String& name);
00384 
00385 
00390         virtual ~MultiLineEditbox(void);
00391 
00392 
00393 protected:
00394         /*************************************************************************
00395                 Implementation Methods (abstract)
00396         *************************************************************************/
00405         //virtual       Rect    getTextRenderArea_impl(void) const              = 0;
00406 
00407 
00408         /*************************************************************************
00409                 Implementation Methods
00410         *************************************************************************/
00415         void    formatText(void);
00416 
00417 
00428         size_t  getNextTokenLength(const String& text, size_t start_idx) const;
00429 
00430 
00435         void    configureScrollbars(void);
00436 
00437 
00448         size_t  getTextIndexFromPosition(const Point& pt) const;
00449 
00450 
00455         void    clearSelection(void);
00456 
00457 
00465         void    eraseSelectedText(bool modify_text = true);
00466 
00467 
00472         void    handleBackspace(void);
00473 
00474 
00479         void    handleDelete(void);
00480 
00481 
00486         void    handleCharLeft(uint sysKeys);
00487 
00488 
00493         void    handleWordLeft(uint sysKeys);
00494 
00495 
00500         void    handleCharRight(uint sysKeys);
00501 
00502 
00507         void    handleWordRight(uint sysKeys);
00508 
00509 
00514         void    handleDocHome(uint sysKeys);
00515 
00516 
00521         void    handleDocEnd(uint sysKeys);
00522 
00523 
00528         void    handleLineHome(uint sysKeys);
00529 
00530 
00535         void    handleLineEnd(uint sysKeys);
00536 
00537 
00542         void    handleLineUp(uint sysKeys);
00543 
00544 
00549         void    handleLineDown(uint sysKeys);
00550 
00551 
00556         void    handleNewLine(uint sysKeys);
00557 
00558 
00563     void    handlePageUp(uint sysKeys);
00564 
00565 
00570     void    handlePageDown(uint sysKeys);
00571 
00572 
00583         virtual bool    testClassName_impl(const String& class_name) const
00584         {
00585                 if ((class_name=="MultiLineEditBox") ||
00586                         (class_name=="MultiLineEditbox"))
00587                 {
00588                         return true;
00589                 }
00590 
00591                 return Window::testClassName_impl(class_name);
00592         }
00593 
00598     bool handle_scrollChange(const EventArgs& args);
00599 
00600     // validate window renderer
00601     virtual bool validateWindowRenderer(const String& name) const
00602     {
00603         return (name == EventNamespace);
00604     }
00605 
00606         /*************************************************************************
00607                 New event handlers
00608         *************************************************************************/
00613         void    onReadOnlyChanged(WindowEventArgs& e);
00614 
00615 
00620         void    onWordWrapModeChanged(WindowEventArgs& e);
00621 
00622 
00627         void    onMaximumTextLengthChanged(WindowEventArgs& e);
00628 
00629 
00634         void    onCaratMoved(WindowEventArgs& e);
00635 
00636 
00641         void    onTextSelectionChanged(WindowEventArgs& e);
00642 
00643 
00648         void    onEditboxFullEvent(WindowEventArgs& e);
00649 
00650 
00655         void    onVertScrollbarModeChanged(WindowEventArgs& e);
00656 
00657 
00662         void    onHorzScrollbarModeChanged(WindowEventArgs& e);
00663 
00664 
00665         /*************************************************************************
00666                 Overridden event handlers
00667         *************************************************************************/
00668         virtual void    onMouseButtonDown(MouseEventArgs& e);
00669         virtual void    onMouseButtonUp(MouseEventArgs& e);
00670         virtual void    onMouseDoubleClicked(MouseEventArgs& e);
00671         virtual void    onMouseTripleClicked(MouseEventArgs& e);
00672         virtual void    onMouseMove(MouseEventArgs& e);
00673         virtual void    onCaptureLost(WindowEventArgs& e);
00674         virtual void    onCharacter(KeyEventArgs& e);
00675         virtual void    onKeyDown(KeyEventArgs& e);
00676         virtual void    onTextChanged(WindowEventArgs& e);
00677         virtual void    onSized(WindowEventArgs& e);
00678         virtual void    onMouseWheel(MouseEventArgs& e);
00679 
00680 
00681         /*************************************************************************
00682                 Implementation data
00683         *************************************************************************/
00684         bool    d_readOnly;                     
00685         size_t  d_maxTextLen;           
00686         size_t  d_caratPos;                     
00687         size_t  d_selectionStart;       
00688         size_t  d_selectionEnd;         
00689         bool    d_dragging;                     
00690         size_t  d_dragAnchorIdx;        
00691 
00692         static String d_lineBreakChars; 
00693         bool            d_wordWrap;                     
00694         LineList        d_lines;                        
00695         float           d_widestExtent;         
00696 
00697         // component widget settings
00698         bool    d_forceVertScroll;              
00699         bool    d_forceHorzScroll;              
00700 
00701         // images
00702         const Image*    d_selectionBrush;       
00703 
00704 
00705 private:
00706         /*************************************************************************
00707                 Static Properties for this class
00708         *************************************************************************/
00709         static MultiLineEditboxProperties::ReadOnly                                     d_readOnlyProperty;
00710         static MultiLineEditboxProperties::WordWrap                                     d_wordWrapProperty;
00711         static MultiLineEditboxProperties::CaratIndex                           d_caratIndexProperty;
00712         static MultiLineEditboxProperties::SelectionStart                       d_selectionStartProperty;
00713         static MultiLineEditboxProperties::SelectionLength                      d_selectionLengthProperty;
00714         static MultiLineEditboxProperties::MaxTextLength                        d_maxTextLengthProperty;
00715     static MultiLineEditboxProperties::SelectionBrushImage      d_selectionBrushProperty;
00716     static MultiLineEditboxProperties::ForceVertScrollbar           d_forceVertProperty;
00717 
00718 
00719         /*************************************************************************
00720                 Private methods
00721         *************************************************************************/
00722         void    addMultiLineEditboxProperties(void);
00723 };
00724 
00725 } // End of  CEGUI namespace section
00726 
00727 #if defined(_MSC_VER)
00728 #       pragma warning(pop)
00729 #endif
00730 
00731 #endif  // end of guard _CEGUIMultiLineEditbox_h_

Generated on Sat Jun 28 14:35:44 2008 for Crazy Eddies GUI System by  doxygen 1.5.4