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 
00220 
00232     Scrollbar* getHorzScrollbar() const;
00233 
00234 
00243     Rect    getTextRenderArea(void) const;
00244 
00245     // get d_lines
00246     const LineList& getFormattedLines(void) const   {return d_lines;}
00247 
00253     size_t  getLineNumberFromIndex(size_t index) const;
00254 
00255         /*************************************************************************
00256                 Manipulators
00257         *************************************************************************/
00268         virtual void    initialiseComponents(void);
00269 
00270 
00282         void    setReadOnly(bool setting);
00283 
00284 
00296         void    setCaratIndex(size_t carat_pos);
00297 
00298 
00314         void    setSelection(size_t start_pos, size_t end_pos);
00315         
00316 
00327         void    setMaxTextLength(size_t max_len);
00328 
00329 
00334         void    ensureCaratIsVisible(void);
00335 
00336 
00348         void    setWordWrapping(bool setting);
00349 
00350     // selection brush image property support
00351     void setSelectionBrushImage(const Image* image);
00352     const Image* getSelectionBrushImage() const;
00353 
00354         /*************************************************************************
00355                 Construction and Destruction
00356         *************************************************************************/
00361         MultiLineEditbox(const String& type, const String& name);
00362 
00363 
00368         virtual ~MultiLineEditbox(void);
00369 
00370 
00371 protected:
00372         /*************************************************************************
00373                 Implementation Methods (abstract)
00374         *************************************************************************/
00383         //virtual       Rect    getTextRenderArea_impl(void) const              = 0;
00384 
00385 
00386         /*************************************************************************
00387                 Implementation Methods
00388         *************************************************************************/
00393         void    formatText(void);
00394 
00395 
00406         size_t  getNextTokenLength(const String& text, size_t start_idx) const;
00407 
00408 
00413         void    configureScrollbars(void);
00414 
00415 
00426         size_t  getTextIndexFromPosition(const Point& pt) const;
00427 
00428 
00433         void    clearSelection(void);
00434 
00435 
00443         void    eraseSelectedText(bool modify_text = true);
00444 
00445 
00450         void    handleBackspace(void);
00451 
00452 
00457         void    handleDelete(void);
00458 
00459 
00464         void    handleCharLeft(uint sysKeys);
00465 
00466 
00471         void    handleWordLeft(uint sysKeys);
00472 
00473 
00478         void    handleCharRight(uint sysKeys);
00479 
00480 
00485         void    handleWordRight(uint sysKeys);
00486 
00487 
00492         void    handleDocHome(uint sysKeys);
00493 
00494 
00499         void    handleDocEnd(uint sysKeys);
00500 
00501 
00506         void    handleLineHome(uint sysKeys);
00507 
00508 
00513         void    handleLineEnd(uint sysKeys);
00514 
00515 
00520         void    handleLineUp(uint sysKeys);
00521 
00522 
00527         void    handleLineDown(uint sysKeys);
00528 
00529 
00534         void    handleNewLine(uint sysKeys);
00535 
00536 
00541     void    handlePageUp(uint sysKeys);
00542 
00543 
00548     void    handlePageDown(uint sysKeys);
00549 
00550 
00561         virtual bool    testClassName_impl(const String& class_name) const
00562         {
00563                 if ((class_name=="MultiLineEditBox") ||
00564                         (class_name=="MultiLineEditbox"))
00565                 {
00566                         return true;
00567                 }
00568 
00569                 return Window::testClassName_impl(class_name);
00570         }
00571 
00576     bool handle_scrollChange(const EventArgs& args);
00577 
00578     // validate window renderer
00579     virtual bool validateWindowRenderer(const String& name) const
00580     {
00581         return (name == EventNamespace);
00582     }
00583 
00584         /*************************************************************************
00585                 New event handlers
00586         *************************************************************************/
00591         void    onReadOnlyChanged(WindowEventArgs& e);
00592 
00593 
00598         void    onWordWrapModeChanged(WindowEventArgs& e);
00599 
00600 
00605         void    onMaximumTextLengthChanged(WindowEventArgs& e);
00606 
00607 
00612         void    onCaratMoved(WindowEventArgs& e);
00613 
00614 
00619         void    onTextSelectionChanged(WindowEventArgs& e);
00620 
00621 
00626         void    onEditboxFullEvent(WindowEventArgs& e);
00627 
00628 
00633         void    onVertScrollbarModeChanged(WindowEventArgs& e);
00634 
00635 
00640         void    onHorzScrollbarModeChanged(WindowEventArgs& e);
00641 
00642 
00643         /*************************************************************************
00644                 Overridden event handlers
00645         *************************************************************************/
00646         virtual void    onMouseButtonDown(MouseEventArgs& e);
00647         virtual void    onMouseButtonUp(MouseEventArgs& e);
00648         virtual void    onMouseDoubleClicked(MouseEventArgs& e);
00649         virtual void    onMouseTripleClicked(MouseEventArgs& e);
00650         virtual void    onMouseMove(MouseEventArgs& e);
00651         virtual void    onCaptureLost(WindowEventArgs& e);
00652         virtual void    onCharacter(KeyEventArgs& e);
00653         virtual void    onKeyDown(KeyEventArgs& e);
00654         virtual void    onTextChanged(WindowEventArgs& e);
00655         virtual void    onSized(WindowEventArgs& e);
00656         virtual void    onMouseWheel(MouseEventArgs& e);
00657 
00658 
00659         /*************************************************************************
00660                 Implementation data
00661         *************************************************************************/
00662         bool    d_readOnly;                     
00663         size_t  d_maxTextLen;           
00664         size_t  d_caratPos;                     
00665         size_t  d_selectionStart;       
00666         size_t  d_selectionEnd;         
00667         bool    d_dragging;                     
00668         size_t  d_dragAnchorIdx;        
00669 
00670         static String d_lineBreakChars; 
00671         bool            d_wordWrap;                     
00672         LineList        d_lines;                        
00673         float           d_widestExtent;         
00674 
00675         // component widget settings
00676         bool    d_forceVertScroll;              
00677         bool    d_forceHorzScroll;              
00678 
00679         // images
00680         const Image*    d_selectionBrush;       
00681 
00682 
00683 private:
00684         /*************************************************************************
00685                 Static Properties for this class
00686         *************************************************************************/
00687         static MultiLineEditboxProperties::ReadOnly                                     d_readOnlyProperty;
00688         static MultiLineEditboxProperties::WordWrap                                     d_wordWrapProperty;
00689         static MultiLineEditboxProperties::CaratIndex                           d_caratIndexProperty;
00690         static MultiLineEditboxProperties::SelectionStart                       d_selectionStartProperty;
00691         static MultiLineEditboxProperties::SelectionLength                      d_selectionLengthProperty;
00692         static MultiLineEditboxProperties::MaxTextLength                        d_maxTextLengthProperty;
00693     static MultiLineEditboxProperties::SelectionBrushImage      d_selectionBrushProperty;
00694 
00695 
00696         /*************************************************************************
00697                 Private methods
00698         *************************************************************************/
00699         void    addMultiLineEditboxProperties(void);
00700 };
00701 
00702 } // End of  CEGUI namespace section
00703 
00704 #if defined(_MSC_VER)
00705 #       pragma warning(pop)
00706 #endif
00707 
00708 #endif  // end of guard _CEGUIMultiLineEditbox_h_

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