Crazy Eddies GUI System  0.6.2
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 "elements/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 
78 class CEGUIEXPORT MultiLineEditbox : public Window
79 {
80 public:
81  static const String EventNamespace;
82  static const String WidgetTypeName;
83 
84  /*************************************************************************
85  Constants
86  *************************************************************************/
87  // event names
91  static const String EventCaratMoved;
93  static const String EventEditboxFull;
96 
97  /*************************************************************************
98  Child Widget name suffix constants
99  *************************************************************************/
102 
103  /*************************************************************************
104  Implementation struct
105  *************************************************************************/
111  struct LineInfo
112  {
113  size_t d_startIdx;
114  size_t d_length;
115  float d_extent;
116  };
117  typedef std::vector<LineInfo> LineList;
118 
119  /*************************************************************************
120  Accessor Functions
121  *************************************************************************/
130  bool hasInputFocus(void) const;
131 
132 
141  bool isReadOnly(void) const {return d_readOnly;}
142 
143 
151  size_t getCaratIndex(void) const {return d_caratPos;}
152 
153 
162  size_t getSelectionStartIndex(void) const;
163 
164 
173  size_t getSelectionEndIndex(void) const;
174 
175 
183  size_t getSelectionLength(void) const;
184 
185 
193  size_t getMaxTextLength(void) const {return d_maxTextLen;}
194 
195 
204  bool isWordWrapped(void) const;
205 
206 
218  Scrollbar* getVertScrollbar() const;
219 
228  bool isVertScrollbarAlwaysShown(void) const;
229 
241  Scrollbar* getHorzScrollbar() const;
242 
243 
252  Rect getTextRenderArea(void) const;
253 
254  // get d_lines
255  const LineList& getFormattedLines(void) const {return d_lines;}
256 
262  size_t getLineNumberFromIndex(size_t index) const;
263 
264  /*************************************************************************
265  Manipulators
266  *************************************************************************/
277  virtual void initialiseComponents(void);
278 
279 
291  void setReadOnly(bool setting);
292 
293 
305  void setCaratIndex(size_t carat_pos);
306 
307 
323  void setSelection(size_t start_pos, size_t end_pos);
324 
325 
336  void setMaxTextLength(size_t max_len);
337 
338 
343  void ensureCaratIsVisible(void);
344 
345 
357  void setWordWrapping(bool setting);
358 
370  void setShowVertScrollbar(bool setting);
371 
372  // selection brush image property support
373  void setSelectionBrushImage(const Image* image);
374  const Image* getSelectionBrushImage() const;
375 
376  /*************************************************************************
377  Construction and Destruction
378  *************************************************************************/
383  MultiLineEditbox(const String& type, const String& name);
384 
385 
390  virtual ~MultiLineEditbox(void);
391 
392 
393 protected:
394  /*************************************************************************
395  Implementation Methods (abstract)
396  *************************************************************************/
405  //virtual Rect getTextRenderArea_impl(void) const = 0;
406 
407 
408  /*************************************************************************
409  Implementation Methods
410  *************************************************************************/
415  void formatText(void);
416 
417 
428  size_t getNextTokenLength(const String& text, size_t start_idx) const;
429 
430 
435  void configureScrollbars(void);
436 
437 
448  size_t getTextIndexFromPosition(const Point& pt) const;
449 
450 
455  void clearSelection(void);
456 
457 
465  void eraseSelectedText(bool modify_text = true);
466 
467 
472  void handleBackspace(void);
473 
474 
479  void handleDelete(void);
480 
481 
486  void handleCharLeft(uint sysKeys);
487 
488 
493  void handleWordLeft(uint sysKeys);
494 
495 
500  void handleCharRight(uint sysKeys);
501 
502 
507  void handleWordRight(uint sysKeys);
508 
509 
514  void handleDocHome(uint sysKeys);
515 
516 
521  void handleDocEnd(uint sysKeys);
522 
523 
528  void handleLineHome(uint sysKeys);
529 
530 
535  void handleLineEnd(uint sysKeys);
536 
537 
542  void handleLineUp(uint sysKeys);
543 
544 
549  void handleLineDown(uint sysKeys);
550 
551 
556  void handleNewLine(uint sysKeys);
557 
558 
563  void handlePageUp(uint sysKeys);
564 
565 
570  void handlePageDown(uint sysKeys);
571 
572 
583  virtual bool testClassName_impl(const String& class_name) const
584  {
585  if ((class_name=="MultiLineEditBox") ||
586  (class_name=="MultiLineEditbox"))
587  {
588  return true;
589  }
590 
591  return Window::testClassName_impl(class_name);
592  }
593 
598  bool handle_scrollChange(const EventArgs& args);
599 
600  // validate window renderer
601  virtual bool validateWindowRenderer(const String& name) const
602  {
603  return (name == EventNamespace);
604  }
605 
606  /*************************************************************************
607  New event handlers
608  *************************************************************************/
613  void onReadOnlyChanged(WindowEventArgs& e);
614 
615 
620  void onWordWrapModeChanged(WindowEventArgs& e);
621 
622 
627  void onMaximumTextLengthChanged(WindowEventArgs& e);
628 
629 
634  void onCaratMoved(WindowEventArgs& e);
635 
636 
641  void onTextSelectionChanged(WindowEventArgs& e);
642 
643 
648  void onEditboxFullEvent(WindowEventArgs& e);
649 
650 
655  void onVertScrollbarModeChanged(WindowEventArgs& e);
656 
657 
662  void onHorzScrollbarModeChanged(WindowEventArgs& e);
663 
664 
665  /*************************************************************************
666  Overridden event handlers
667  *************************************************************************/
668  virtual void onMouseButtonDown(MouseEventArgs& e);
669  virtual void onMouseButtonUp(MouseEventArgs& e);
670  virtual void onMouseDoubleClicked(MouseEventArgs& e);
671  virtual void onMouseTripleClicked(MouseEventArgs& e);
672  virtual void onMouseMove(MouseEventArgs& e);
673  virtual void onCaptureLost(WindowEventArgs& e);
674  virtual void onCharacter(KeyEventArgs& e);
675  virtual void onKeyDown(KeyEventArgs& e);
676  virtual void onTextChanged(WindowEventArgs& e);
677  virtual void onSized(WindowEventArgs& e);
678  virtual void onMouseWheel(MouseEventArgs& e);
679 
680 
681  /*************************************************************************
682  Implementation data
683  *************************************************************************/
684  bool d_readOnly;
685  size_t d_maxTextLen;
686  size_t d_caratPos;
688  size_t d_selectionEnd;
689  bool d_dragging;
691 
693  bool d_wordWrap;
696 
697  // component widget settings
700 
701  // images
703 
704 
705 private:
706  /*************************************************************************
707  Static Properties for this class
708  *************************************************************************/
709  static MultiLineEditboxProperties::ReadOnly d_readOnlyProperty;
710  static MultiLineEditboxProperties::WordWrap d_wordWrapProperty;
711  static MultiLineEditboxProperties::CaratIndex d_caratIndexProperty;
712  static MultiLineEditboxProperties::SelectionStart d_selectionStartProperty;
713  static MultiLineEditboxProperties::SelectionLength d_selectionLengthProperty;
714  static MultiLineEditboxProperties::MaxTextLength d_maxTextLengthProperty;
715  static MultiLineEditboxProperties::SelectionBrushImage d_selectionBrushProperty;
716  static MultiLineEditboxProperties::ForceVertScrollbar d_forceVertProperty;
717 
718 
719  /*************************************************************************
720  Private methods
721  *************************************************************************/
722  void addMultiLineEditboxProperties(void);
723 };
724 
725 } // End of CEGUI namespace section
726 
727 #if defined(_MSC_VER)
728 # pragma warning(pop)
729 #endif
730 
731 #endif // end of guard _CEGUIMultiLineEditbox_h_