Crazy Eddies GUI System  0.7.9
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
CEGUIMultiLineEditbox.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 "../CEGUIBase.h"
34 #include "../CEGUIWindow.h"
35 #include "../CEGUIFont.h"
36 #include "CEGUIMultiLineEditboxProperties.h"
37 
38 #include <vector>
39 
40 
41 #if defined(_MSC_VER)
42 # pragma warning(push)
43 # pragma warning(disable : 4251)
44 #endif
45 
46 
47 // Start of CEGUI namespace section
48 namespace CEGUI
49 {
55 {
56 public:
62 
71  virtual Rect getTextRenderArea(void) const = 0;
72 
73 protected:
74  // base class overrides
75  void onLookNFeelAssigned();
76 };
77 
82 class CEGUIEXPORT MultiLineEditbox : public Window
83 {
84 public:
85  static const String EventNamespace;
86  static const String WidgetTypeName;
87 
88  /*************************************************************************
89  Constants
90  *************************************************************************/
91  // event names
116  static const String EventCaratMoved;
129  static const String EventEditboxFull;
144 
145  /*************************************************************************
146  Child Widget name suffix constants
147  *************************************************************************/
150 
151  /*************************************************************************
152  Implementation struct
153  *************************************************************************/
159  struct LineInfo
160  {
161  size_t d_startIdx;
162  size_t d_length;
163  float d_extent;
164  };
165  typedef std::vector<LineInfo> LineList;
166 
167  /*************************************************************************
168  Accessor Functions
169  *************************************************************************/
178  bool hasInputFocus(void) const;
179 
180 
189  bool isReadOnly(void) const {return d_readOnly;}
190 
191 
199  size_t getCaratIndex(void) const {return d_caratPos;}
200 
201 
210  size_t getSelectionStartIndex(void) const;
211 
212 
221  size_t getSelectionEndIndex(void) const;
222 
223 
231  size_t getSelectionLength(void) const;
232 
233 
241  size_t getMaxTextLength(void) const {return d_maxTextLen;}
242 
243 
252  bool isWordWrapped(void) const;
253 
254 
266  Scrollbar* getVertScrollbar() const;
267 
276  bool isVertScrollbarAlwaysShown(void) const;
277 
289  Scrollbar* getHorzScrollbar() const;
290 
291 
300  Rect getTextRenderArea(void) const;
301 
302  // get d_lines
303  const LineList& getFormattedLines(void) const {return d_lines;}
304 
310  size_t getLineNumberFromIndex(size_t index) const;
311 
312  /*************************************************************************
313  Manipulators
314  *************************************************************************/
325  virtual void initialiseComponents(void);
326 
327 
339  void setReadOnly(bool setting);
340 
341 
353  void setCaratIndex(size_t carat_pos);
354 
355 
371  void setSelection(size_t start_pos, size_t end_pos);
372 
373 
384  void setMaxTextLength(size_t max_len);
385 
386 
391  void ensureCaratIsVisible(void);
392 
393 
405  void setWordWrapping(bool setting);
406 
418  void setShowVertScrollbar(bool setting);
419 
420  // selection brush image property support
421  void setSelectionBrushImage(const Image* image);
422  const Image* getSelectionBrushImage() const;
423 
424  /*************************************************************************
425  Construction and Destruction
426  *************************************************************************/
431  MultiLineEditbox(const String& type, const String& name);
432 
433 
438  virtual ~MultiLineEditbox(void);
439 
440 
441 protected:
442  /*************************************************************************
443  Implementation Methods (abstract)
444  *************************************************************************/
453  //virtual Rect getTextRenderArea_impl(void) const = 0;
454 
455 
456  /*************************************************************************
457  Implementation Methods
458  *************************************************************************/
465  void formatText(void);
466 
475  void formatText(const bool update_scrollbars);
476 
487  size_t getNextTokenLength(const String& text, size_t start_idx) const;
488 
489 
494  void configureScrollbars(void);
495 
496 
507  size_t getTextIndexFromPosition(const Point& pt) const;
508 
509 
514  void clearSelection(void);
515 
516 
524  void eraseSelectedText(bool modify_text = true);
525 
526 
531  void handleBackspace(void);
532 
533 
538  void handleDelete(void);
539 
540 
545  void handleCharLeft(uint sysKeys);
546 
547 
552  void handleWordLeft(uint sysKeys);
553 
554 
559  void handleCharRight(uint sysKeys);
560 
561 
566  void handleWordRight(uint sysKeys);
567 
568 
573  void handleDocHome(uint sysKeys);
574 
575 
580  void handleDocEnd(uint sysKeys);
581 
582 
587  void handleLineHome(uint sysKeys);
588 
589 
594  void handleLineEnd(uint sysKeys);
595 
596 
601  void handleLineUp(uint sysKeys);
602 
603 
608  void handleLineDown(uint sysKeys);
609 
610 
615  void handleNewLine(uint sysKeys);
616 
617 
622  void handlePageUp(uint sysKeys);
623 
624 
629  void handlePageDown(uint sysKeys);
630 
631 
642  virtual bool testClassName_impl(const String& class_name) const
643  {
644  if ((class_name=="MultiLineEditBox") ||
645  (class_name=="MultiLineEditbox"))
646  {
647  return true;
648  }
649 
650  return Window::testClassName_impl(class_name);
651  }
652 
657  bool handle_scrollChange(const EventArgs& args);
658 
659  // handler triggered when vertical scrollbar is shown or hidden
660  bool handle_vertScrollbarVisibilityChanged(const EventArgs&);
661 
662  // validate window renderer
663  virtual bool validateWindowRenderer(const String& name) const
664  {
665  return (name == EventNamespace);
666  }
667 
668  /*************************************************************************
669  New event handlers
670  *************************************************************************/
675  void onReadOnlyChanged(WindowEventArgs& e);
676 
677 
682  void onWordWrapModeChanged(WindowEventArgs& e);
683 
684 
689  void onMaximumTextLengthChanged(WindowEventArgs& e);
690 
691 
696  void onCaratMoved(WindowEventArgs& e);
697 
698 
703  void onTextSelectionChanged(WindowEventArgs& e);
704 
705 
710  void onEditboxFullEvent(WindowEventArgs& e);
711 
712 
717  void onVertScrollbarModeChanged(WindowEventArgs& e);
718 
719 
724  void onHorzScrollbarModeChanged(WindowEventArgs& e);
725 
726 
727  /*************************************************************************
728  Overridden event handlers
729  *************************************************************************/
730  virtual void onMouseButtonDown(MouseEventArgs& e);
731  virtual void onMouseButtonUp(MouseEventArgs& e);
732  virtual void onMouseDoubleClicked(MouseEventArgs& e);
733  virtual void onMouseTripleClicked(MouseEventArgs& e);
734  virtual void onMouseMove(MouseEventArgs& e);
735  virtual void onCaptureLost(WindowEventArgs& e);
736  virtual void onCharacter(KeyEventArgs& e);
737  virtual void onKeyDown(KeyEventArgs& e);
738  virtual void onTextChanged(WindowEventArgs& e);
739  virtual void onSized(WindowEventArgs& e);
740  virtual void onMouseWheel(MouseEventArgs& e);
741 
742 
743  /*************************************************************************
744  Implementation data
745  *************************************************************************/
746  bool d_readOnly;
747  size_t d_maxTextLen;
748  size_t d_caratPos;
750  size_t d_selectionEnd;
751  bool d_dragging;
753 
755  bool d_wordWrap;
758 
759  // component widget settings
762 
763  // images
765 
766 
767 private:
768  /*************************************************************************
769  Static Properties for this class
770  *************************************************************************/
771  static MultiLineEditboxProperties::ReadOnly d_readOnlyProperty;
772  static MultiLineEditboxProperties::WordWrap d_wordWrapProperty;
773  static MultiLineEditboxProperties::CaratIndex d_caratIndexProperty;
774  static MultiLineEditboxProperties::SelectionStart d_selectionStartProperty;
775  static MultiLineEditboxProperties::SelectionLength d_selectionLengthProperty;
776  static MultiLineEditboxProperties::MaxTextLength d_maxTextLengthProperty;
777  static MultiLineEditboxProperties::SelectionBrushImage d_selectionBrushProperty;
778  static MultiLineEditboxProperties::ForceVertScrollbar d_forceVertProperty;
779 
780 
781  /*************************************************************************
782  Private methods
783  *************************************************************************/
784  void addMultiLineEditboxProperties(void);
785 };
786 
787 } // End of CEGUI namespace section
788 
789 #if defined(_MSC_VER)
790 # pragma warning(pop)
791 #endif
792 
793 #endif // end of guard _CEGUIMultiLineEditbox_h_