Crazy Eddie's GUI System  0.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
widgets/MultiLineEditbox.h
1 /***********************************************************************
2  filename: CEGUIMultiLineEditbox.h
3  created: 30/6/2004
4  author: Paul D Turner
5 
6  purpose: Interface to the Multi-lien edit box base class.
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUIMultiLineEditbox_h_
31 #define _CEGUIMultiLineEditbox_h_
32 
33 #include "../Base.h"
34 #include "../Window.h"
35 #include "../Font.h"
36 
37 #include <vector>
38 
39 #if defined(_MSC_VER)
40 # pragma warning(push)
41 # pragma warning(disable : 4251)
42 #endif
43 
44 
45 // Start of CEGUI namespace section
46 namespace CEGUI
47 {
53 {
54 public:
60 
69  virtual Rectf getTextRenderArea(void) const = 0;
70 
71 protected:
72  // base class overrides
73  void onLookNFeelAssigned();
74 };
75 
80 class CEGUIEXPORT MultiLineEditbox : public Window
81 {
82 public:
83  static const String EventNamespace;
84  static const String WidgetTypeName;
85 
86  /*************************************************************************
87  Constants
88  *************************************************************************/
89  // event names
114  static const String EventCaretMoved;
127  static const String EventEditboxFull;
142 
143  /*************************************************************************
144  Child Widget name constants
145  *************************************************************************/
146  static const String VertScrollbarName;
147  static const String HorzScrollbarName;
148 
149  /*************************************************************************
150  Implementation struct
151  *************************************************************************/
157  struct LineInfo
158  {
159  size_t d_startIdx;
160  size_t d_length;
161  float d_extent;
162  };
163  typedef std::vector<LineInfo
164  CEGUI_VECTOR_ALLOC(LineInfo)> LineList;
165 
166  /*************************************************************************
167  Accessor Functions
168  *************************************************************************/
177  bool hasInputFocus(void) const;
178 
179 
188  bool isReadOnly(void) const {return d_readOnly;}
189 
190 
198  size_t getCaretIndex(void) const {return d_caretPos;}
199 
200 
209  size_t getSelectionStartIndex(void) const;
210 
211 
220  size_t getSelectionEndIndex(void) const;
221 
222 
230  size_t getSelectionLength(void) const;
231 
232 
240  size_t getMaxTextLength(void) const {return d_maxTextLen;}
241 
242 
251  bool isWordWrapped(void) const;
252 
253 
265  Scrollbar* getVertScrollbar() const;
266 
275  bool isVertScrollbarAlwaysShown(void) const;
276 
288  Scrollbar* getHorzScrollbar() const;
289 
290 
299  Rectf getTextRenderArea(void) const;
300 
301  // get d_lines
302  const LineList& getFormattedLines(void) const {return d_lines;}
303 
309  size_t getLineNumberFromIndex(size_t index) const;
310 
311  /*************************************************************************
312  Manipulators
313  *************************************************************************/
324  virtual void initialiseComponents(void);
325 
326 
338  void setReadOnly(bool setting);
339 
340 
352  void setCaretIndex(size_t caret_pos);
353 
354 
370  void setSelection(size_t start_pos, size_t end_pos);
371 
372 
384  void setSelectionStart(size_t start_pos);
385 
396  void setSelectionLength(size_t length);
397 
408  void setMaxTextLength(size_t max_len);
409 
410 
415  void ensureCaretIsVisible(void);
416 
417 
429  void setWordWrapping(bool setting);
430 
442  void setShowVertScrollbar(bool setting);
443 
444  // selection brush image property support
445  void setSelectionBrushImage(const Image* image);
446  const Image* getSelectionBrushImage() const;
447 
449  virtual bool performCopy(Clipboard& clipboard);
450 
452  virtual bool performCut(Clipboard& clipboard);
453 
455  virtual bool performPaste(Clipboard& clipboard);
456 
465  void formatText(const bool update_scrollbars);
466 
467  /*************************************************************************
468  Construction and Destruction
469  *************************************************************************/
474  MultiLineEditbox(const String& type, const String& name);
475 
476 
481  virtual ~MultiLineEditbox(void);
482 
483 
484 protected:
485  /*************************************************************************
486  Implementation Methods (abstract)
487  *************************************************************************/
496  //virtual Rect getTextRenderArea_impl(void) const = 0;
497 
498 
499  /*************************************************************************
500  Implementation Methods
501  *************************************************************************/
508  void formatText(void);
509 
520  size_t getNextTokenLength(const String& text, size_t start_idx) const;
521 
522 
527  void configureScrollbars(void);
528 
529 
540  size_t getTextIndexFromPosition(const Vector2f& pt) const;
541 
542 
547  void clearSelection(void);
548 
549 
557  void eraseSelectedText(bool modify_text = true);
558 
559 
564  void handleBackspace(void);
565 
566 
571  void handleDelete(void);
572 
573 
578  void handleCharLeft(uint sysKeys);
579 
580 
585  void handleWordLeft(uint sysKeys);
586 
587 
592  void handleCharRight(uint sysKeys);
593 
594 
599  void handleWordRight(uint sysKeys);
600 
601 
606  void handleDocHome(uint sysKeys);
607 
608 
613  void handleDocEnd(uint sysKeys);
614 
615 
620  void handleLineHome(uint sysKeys);
621 
622 
627  void handleLineEnd(uint sysKeys);
628 
629 
634  void handleLineUp(uint sysKeys);
635 
636 
641  void handleLineDown(uint sysKeys);
642 
643 
648  void handleNewLine(uint sysKeys);
649 
650 
655  void handlePageUp(uint sysKeys);
656 
657 
662  void handlePageDown(uint sysKeys);
663 
668  bool handle_scrollChange(const EventArgs& args);
669 
670  // handler triggered when vertical scrollbar is shown or hidden
671  bool handle_vertScrollbarVisibilityChanged(const EventArgs&);
672 
673  // validate window renderer
674  virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
675 
676  /*************************************************************************
677  New event handlers
678  *************************************************************************/
683  void onReadOnlyChanged(WindowEventArgs& e);
684 
685 
690  void onWordWrapModeChanged(WindowEventArgs& e);
691 
692 
697  void onMaximumTextLengthChanged(WindowEventArgs& e);
698 
699 
704  void onCaretMoved(WindowEventArgs& e);
705 
706 
711  void onTextSelectionChanged(WindowEventArgs& e);
712 
713 
718  void onEditboxFullEvent(WindowEventArgs& e);
719 
720 
725  void onVertScrollbarModeChanged(WindowEventArgs& e);
726 
727 
732  void onHorzScrollbarModeChanged(WindowEventArgs& e);
733 
734 
735  /*************************************************************************
736  Overridden event handlers
737  *************************************************************************/
738  virtual void onMouseButtonDown(MouseEventArgs& e);
739  virtual void onMouseButtonUp(MouseEventArgs& e);
740  virtual void onMouseDoubleClicked(MouseEventArgs& e);
741  virtual void onMouseTripleClicked(MouseEventArgs& e);
742  virtual void onMouseMove(MouseEventArgs& e);
743  virtual void onCaptureLost(WindowEventArgs& e);
744  virtual void onCharacter(KeyEventArgs& e);
745  virtual void onKeyDown(KeyEventArgs& e);
746  virtual void onTextChanged(WindowEventArgs& e);
747  virtual void onSized(ElementEventArgs& e);
748  virtual void onMouseWheel(MouseEventArgs& e);
749  virtual void onFontChanged(WindowEventArgs& e);
750 
751 
752  /*************************************************************************
753  Implementation data
754  *************************************************************************/
755  bool d_readOnly;
756  size_t d_maxTextLen;
757  size_t d_caretPos;
759  size_t d_selectionEnd;
760  bool d_dragging;
762 
764  bool d_wordWrap;
767 
768  // component widget settings
771 
772  // images
774 
775 
776 private:
777  /*************************************************************************
778  Private methods
779  *************************************************************************/
780  void addMultiLineEditboxProperties(void);
781 };
782 
783 } // End of CEGUI namespace section
784 
785 #if defined(_MSC_VER)
786 # pragma warning(pop)
787 #endif
788 
789 #endif // end of guard _CEGUIMultiLineEditbox_h_