Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUIMultiLineEditbox.h

Go to the documentation of this file.
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     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 _CEGUIMultiLineEditbox_h_
00027 #define _CEGUIMultiLineEditbox_h_
00028 
00029 #include "CEGUIBase.h"
00030 #include "CEGUIWindow.h"
00031 #include "CEGUIFont.h"
00032 #include "elements/CEGUIMultiLineEditboxProperties.h"
00033 
00034 #include <vector>
00035 
00036 
00037 #if defined(_MSC_VER)
00038 #       pragma warning(push)
00039 #       pragma warning(disable : 4251)
00040 #endif
00041 
00042 
00043 // Start of CEGUI namespace section
00044 namespace CEGUI
00045 {
00050 class CEGUIEXPORT MultiLineEditbox : public Window
00051 {
00052 public:
00053         static const String EventNamespace;                             
00054 
00055 
00056         /*************************************************************************
00057                 Constants
00058         *************************************************************************/
00059         // event names
00060         static const String EventReadOnlyModeChanged;                   
00061         static const String EventWordWrapModeChanged;                   
00062         static const String EventMaximumTextLengthChanged;      
00063         static const String EventCaratMoved;                                    
00064         static const String EventTextSelectionChanged;          
00065         static const String EventEditboxFull;                                   
00066         static const String EventVertScrollbarModeChanged;      
00067         static const String EventHorzScrollbarModeChanged;      
00068 
00069         // default colours
00070         static const argb_t     DefaultNormalTextColour;                        
00071         static const argb_t     DefaultSelectedTextColour;                      
00072         static const argb_t     DefaultNormalSelectionColour;           
00073         static const argb_t     DefaultInactiveSelectionColour;         
00074 
00075 
00076         /*************************************************************************
00077                 Accessor Functions
00078         *************************************************************************/
00087         bool    hasInputFocus(void) const;
00088 
00089 
00098         bool    isReadOnly(void) const          {return d_readOnly;}
00099 
00100 
00108         size_t  getCaratIndex(void) const               {return d_caratPos;}
00109 
00110 
00119         size_t  getSelectionStartIndex(void) const;
00120 
00121 
00130         size_t  getSelectionEndIndex(void) const;
00131 
00132         
00140         size_t  getSelectionLength(void) const;
00141 
00142 
00150         size_t  getMaxTextLength(void) const            {return d_maxTextLen;}
00151 
00152 
00161         colour  getNormalTextColour(void) const                         {return d_normalTextColour;}
00162 
00163 
00172         colour  getSelectedTextColour(void) const                       {return d_selectTextColour;}
00173 
00174 
00183         colour  getNormalSelectBrushColour(void) const          {return d_selectBrushColour;}
00184 
00185 
00194         colour  getInactiveSelectBrushColour(void) const        {return d_inactiveSelectBrushColour;}
00195 
00196 
00205         bool    isWordWrapped(void) const;
00206 
00207 
00208         /*************************************************************************
00209                 Manipulators
00210         *************************************************************************/
00221         virtual void    initialise(void);
00222 
00223 
00235         void    setReadOnly(bool setting);
00236 
00237 
00249         void    setCaratIndex(size_t carat_pos);
00250 
00251 
00267         void    setSelection(size_t start_pos, size_t end_pos);
00268         
00269 
00280         void    setMaxTextLength(size_t max_len);
00281 
00282 
00293         void    setNormalTextColour(const colour& col);
00294 
00295 
00304         void    setSelectedTextColour(const colour& col);
00305 
00306 
00318         void    setNormalSelectBrushColour(const colour& col);
00319 
00320 
00332         void    setInactiveSelectBrushColour(const colour& col);
00333 
00334 
00339         void    ensureCaratIsVisible(void);
00340 
00341 
00353         void    setWordWrapping(bool setting);
00354 
00355 
00356         /*************************************************************************
00357                 Construction and Destruction
00358         *************************************************************************/
00363         MultiLineEditbox(const String& type, const String& name);
00364 
00365 
00370         virtual ~MultiLineEditbox(void);
00371 
00372 
00373 protected:
00374         /*************************************************************************
00375                 Implementation Methods (abstract)
00376         *************************************************************************/
00385         virtual Rect    getTextRenderArea(void) const           = 0;
00386 
00387 
00398         virtual Scrollbar*      createVertScrollbar(const String& name) const           = 0;
00399  
00400 
00411         virtual Scrollbar*      createHorzScrollbar(const String& name) const           = 0;
00412 
00413 
00424         virtual void    cacheEditboxBaseImagery()               = 0;
00425 
00426 
00434         virtual void    cacheCaratImagery(const Rect& textArea) = 0;
00435 
00436 
00437         /*************************************************************************
00438                 Implementation Methods
00439         *************************************************************************/
00444         void    addMultiLineEditboxEvents(void);
00445 
00446 
00451         void    cacheTextLines(const Rect& dest_area);
00452 
00453 
00458         void    formatText(void);
00459 
00460 
00471         size_t  getNextTokenLength(const String& text, size_t start_idx) const;
00472 
00473 
00474         virtual void populateRenderCache();
00475 
00476 
00481         void    configureScrollbars(void);
00482 
00483 
00494         size_t  getTextIndexFromPosition(const Point& pt) const;
00495 
00496 
00502         size_t  getLineNumberFromIndex(size_t index) const;
00503 
00504 
00509         void    clearSelection(void);
00510 
00511 
00519         void    eraseSelectedText(bool modify_text = true);
00520 
00521 
00526         void    handleBackspace(void);
00527 
00528 
00533         void    handleDelete(void);
00534 
00535 
00540         void    handleCharLeft(uint sysKeys);
00541 
00542 
00547         void    handleWordLeft(uint sysKeys);
00548 
00549 
00554         void    handleCharRight(uint sysKeys);
00555 
00556 
00561         void    handleWordRight(uint sysKeys);
00562 
00563 
00568         void    handleDocHome(uint sysKeys);
00569 
00570 
00575         void    handleDocEnd(uint sysKeys);
00576 
00577 
00582         void    handleLineHome(uint sysKeys);
00583 
00584 
00589         void    handleLineEnd(uint sysKeys);
00590 
00591 
00596         void    handleLineUp(uint sysKeys);
00597 
00598 
00603         void    handleLineDown(uint sysKeys);
00604 
00605 
00610         void    handleNewLine(uint sysKeys);
00611 
00612 
00623         virtual bool    testClassName_impl(const String& class_name) const
00624         {
00625                 if (class_name==(const utf8*)"MultiLineEditBox")        return true;
00626                 return Window::testClassName_impl(class_name);
00627         }
00628 
00633     bool handle_scrollChange(const EventArgs& args);
00634 
00635 
00636         /*************************************************************************
00637                 New event handlers
00638         *************************************************************************/
00643         void    onReadOnlyChanged(WindowEventArgs& e);
00644 
00645 
00650         void    onWordWrapModeChanged(WindowEventArgs& e);
00651 
00652 
00657         void    onMaximumTextLengthChanged(WindowEventArgs& e);
00658 
00659 
00664         void    onCaratMoved(WindowEventArgs& e);
00665 
00666 
00671         void    onTextSelectionChanged(WindowEventArgs& e);
00672 
00673 
00678         void    onEditboxFullEvent(WindowEventArgs& e);
00679 
00680 
00685         void    onVertScrollbarModeChanged(WindowEventArgs& e);
00686 
00687 
00692         void    onHorzScrollbarModeChanged(WindowEventArgs& e);
00693 
00694 
00695         /*************************************************************************
00696                 Overridden event handlers
00697         *************************************************************************/
00698         virtual void    onMouseButtonDown(MouseEventArgs& e);
00699         virtual void    onMouseButtonUp(MouseEventArgs& e);
00700         virtual void    onMouseDoubleClicked(MouseEventArgs& e);
00701         virtual void    onMouseTripleClicked(MouseEventArgs& e);
00702         virtual void    onMouseMove(MouseEventArgs& e);
00703         virtual void    onCaptureLost(WindowEventArgs& e);
00704         virtual void    onCharacter(KeyEventArgs& e);
00705         virtual void    onKeyDown(KeyEventArgs& e);
00706         virtual void    onTextChanged(WindowEventArgs& e);
00707         virtual void    onSized(WindowEventArgs& e);
00708         virtual void    onMouseWheel(MouseEventArgs& e);
00709 
00710 
00711         /*************************************************************************
00712                 Implementation struct
00713         *************************************************************************/
00719         struct LineInfo
00720         {
00721                 size_t  d_startIdx;             
00722                 size_t  d_length;               
00723                 float   d_extent;               
00724         };
00725 
00726 
00727         /*************************************************************************
00728                 Implementation data
00729         *************************************************************************/
00730         bool    d_readOnly;                     
00731         size_t  d_maxTextLen;           
00732         size_t  d_caratPos;                     
00733         size_t  d_selectionStart;       
00734         size_t  d_selectionEnd;         
00735         bool    d_dragging;                     
00736         size_t  d_dragAnchorIdx;        
00737 
00738         typedef std::vector<LineInfo>   LineList;       
00739         static String d_lineBreakChars; 
00740         bool            d_wordWrap;                     
00741         LineList        d_lines;                        
00742         float           d_widestExtent;         
00743 
00744         // component widgets
00745         Scrollbar*      d_vertScrollbar;        
00746         Scrollbar*      d_horzScrollbar;        
00747         bool    d_forceVertScroll;              
00748         bool    d_forceHorzScroll;              
00749 
00750         // images
00751         const Image*    d_selectionBrush;       
00752 
00753         // basic rendering colours
00754         colour  d_normalTextColour;                             
00755         colour  d_selectTextColour;                             
00756         colour  d_selectBrushColour;                    
00757         colour  d_inactiveSelectBrushColour;    
00758 
00759 
00760 private:
00761         /*************************************************************************
00762                 Static Properties for this class
00763         *************************************************************************/
00764         static MultiLineEditboxProperties::ReadOnly                                     d_readOnlyProperty;
00765         static MultiLineEditboxProperties::WordWrap                                     d_wordWrapProperty;
00766         static MultiLineEditboxProperties::CaratIndex                           d_caratIndexProperty;
00767         static MultiLineEditboxProperties::SelectionStart                       d_selectionStartProperty;
00768         static MultiLineEditboxProperties::SelectionLength                      d_selectionLengthProperty;
00769         static MultiLineEditboxProperties::MaxTextLength                        d_maxTextLengthProperty;
00770         static MultiLineEditboxProperties::NormalTextColour                     d_normalTextColourProperty;
00771         static MultiLineEditboxProperties::SelectedTextColour           d_selectedTextColourProperty;
00772         static MultiLineEditboxProperties::ActiveSelectionColour        d_activeSelectionColourProperty;
00773         static MultiLineEditboxProperties::InactiveSelectionColour      d_inactiveSelectionColourProperty;
00774 
00775 
00776         /*************************************************************************
00777                 Private methods
00778         *************************************************************************/
00779         void    addMultiLineEditboxProperties(void);
00780 };
00781 
00782 } // End of  CEGUI namespace section
00783 
00784 #if defined(_MSC_VER)
00785 #       pragma warning(pop)
00786 #endif
00787 
00788 #endif  // end of guard _CEGUIMultiLineEditbox_h_

Generated on Wed Sep 7 09:56:32 2005 for Crazy Eddies GUI System by  doxygen 1.4.3