# 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     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") ||
    00626                         (class_name==(const utf8*)"MultiLineEditbox"))
    00627                 {
    00628                         return true;
    00629                 }
    00630
    00631                 return Window::testClassName_impl(class_name);
    00632         }
    00633
    00638     bool handle_scrollChange(const EventArgs& args);
    00639
    00640
    00641         /*************************************************************************
    00642                 New event handlers
    00643         *************************************************************************/
    00648         void    onReadOnlyChanged(WindowEventArgs& e);
    00649
    00650
    00655         void    onWordWrapModeChanged(WindowEventArgs& e);
    00656
    00657
    00662         void    onMaximumTextLengthChanged(WindowEventArgs& e);
    00663
    00664
    00669         void    onCaratMoved(WindowEventArgs& e);
    00670
    00671
    00676         void    onTextSelectionChanged(WindowEventArgs& e);
    00677
    00678
    00683         void    onEditboxFullEvent(WindowEventArgs& e);
    00684
    00685
    00690         void    onVertScrollbarModeChanged(WindowEventArgs& e);
    00691
    00692
    00697         void    onHorzScrollbarModeChanged(WindowEventArgs& e);
    00698
    00699
    00700         /*************************************************************************
    00701                 Overridden event handlers
    00702         *************************************************************************/
    00703         virtual void    onMouseButtonDown(MouseEventArgs& e);
    00704         virtual void    onMouseButtonUp(MouseEventArgs& e);
    00705         virtual void    onMouseDoubleClicked(MouseEventArgs& e);
    00706         virtual void    onMouseTripleClicked(MouseEventArgs& e);
    00707         virtual void    onMouseMove(MouseEventArgs& e);
    00708         virtual void    onCaptureLost(WindowEventArgs& e);
    00709         virtual void    onCharacter(KeyEventArgs& e);
    00710         virtual void    onKeyDown(KeyEventArgs& e);
    00711         virtual void    onTextChanged(WindowEventArgs& e);
    00712         virtual void    onSized(WindowEventArgs& e);
    00713         virtual void    onMouseWheel(MouseEventArgs& e);
    00714
    00715
    00716         /*************************************************************************
    00717                 Implementation struct
    00718         *************************************************************************/
    00724         struct LineInfo
    00725         {
    00726                 size_t  d_startIdx;
    00727                 size_t  d_length;
    00728                 float   d_extent;
    00729         };
    00730
    00731
    00732         /*************************************************************************
    00733                 Implementation data
    00734         *************************************************************************/
    00735         bool    d_readOnly;
    00736         size_t  d_maxTextLen;
    00737         size_t  d_caratPos;
    00738         size_t  d_selectionStart;
    00739         size_t  d_selectionEnd;
    00740         bool    d_dragging;
    00741         size_t  d_dragAnchorIdx;
    00742
    00743         typedef std::vector<LineInfo>   LineList;
    00744         static String d_lineBreakChars;
    00745         bool            d_wordWrap;
    00746         LineList        d_lines;
    00747         float           d_widestExtent;
    00748
    00749         // component widgets
    00750         Scrollbar*      d_vertScrollbar;
    00751         Scrollbar*      d_horzScrollbar;
    00752         bool    d_forceVertScroll;
    00753         bool    d_forceHorzScroll;
    00754
    00755         // images
    00756         const Image*    d_selectionBrush;
    00757
    00758         // basic rendering colours
    00759         colour  d_normalTextColour;
    00760         colour  d_selectTextColour;
    00761         colour  d_selectBrushColour;
    00762         colour  d_inactiveSelectBrushColour;
    00763
    00764
    00765 private:
    00766         /*************************************************************************
    00767                 Static Properties for this class
    00768         *************************************************************************/
    00769         static MultiLineEditboxProperties::ReadOnly                                     d_readOnlyProperty;
    00770         static MultiLineEditboxProperties::WordWrap                                     d_wordWrapProperty;
    00771         static MultiLineEditboxProperties::CaratIndex                           d_caratIndexProperty;
    00772         static MultiLineEditboxProperties::SelectionStart                       d_selectionStartProperty;
    00773         static MultiLineEditboxProperties::SelectionLength                      d_selectionLengthProperty;
    00774         static MultiLineEditboxProperties::MaxTextLength                        d_maxTextLengthProperty;
    00775         static MultiLineEditboxProperties::NormalTextColour                     d_normalTextColourProperty;
    00776         static MultiLineEditboxProperties::SelectedTextColour           d_selectedTextColourProperty;
    00777         static MultiLineEditboxProperties::ActiveSelectionColour        d_activeSelectionColourProperty;
    00778         static MultiLineEditboxProperties::InactiveSelectionColour      d_inactiveSelectionColourProperty;
    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_