Crazy Eddies GUI System  0.7.1
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
95  static const String EventCaratMoved;
97  static const String EventEditboxFull;
100 
101  /*************************************************************************
102  Child Widget name suffix constants
103  *************************************************************************/
106 
107  /*************************************************************************
108  Implementation struct
109  *************************************************************************/
115  struct LineInfo
116  {
117  size_t d_startIdx;
118  size_t d_length;
119  float d_extent;
120  };
121  typedef std::vector<LineInfo> LineList;
122 
123  /*************************************************************************
124  Accessor Functions
125  *************************************************************************/
134  bool hasInputFocus(void) const;
135 
136 
145  bool isReadOnly(void) const {return d_readOnly;}
146 
147 
155  size_t getCaratIndex(void) const {return d_caratPos;}
156 
157 
166  size_t getSelectionStartIndex(void) const;
167 
168 
177  size_t getSelectionEndIndex(void) const;
178 
179 
187  size_t getSelectionLength(void) const;
188 
189 
197  size_t getMaxTextLength(void) const {return d_maxTextLen;}
198 
199 
208  bool isWordWrapped(void) const;
209 
210 
222  Scrollbar* getVertScrollbar() const;
223 
232  bool isVertScrollbarAlwaysShown(void) const;
233 
245  Scrollbar* getHorzScrollbar() const;
246 
247 
256  Rect getTextRenderArea(void) const;
257 
258  // get d_lines
259  const LineList& getFormattedLines(void) const {return d_lines;}
260 
266  size_t getLineNumberFromIndex(size_t index) const;
267 
268  /*************************************************************************
269  Manipulators
270  *************************************************************************/
281  virtual void initialiseComponents(void);
282 
283 
295  void setReadOnly(bool setting);
296 
297 
309  void setCaratIndex(size_t carat_pos);
310 
311 
327  void setSelection(size_t start_pos, size_t end_pos);
328 
329 
340  void setMaxTextLength(size_t max_len);
341 
342 
347  void ensureCaratIsVisible(void);
348 
349 
361  void setWordWrapping(bool setting);
362 
374  void setShowVertScrollbar(bool setting);
375 
376  // selection brush image property support
377  void setSelectionBrushImage(const Image* image);
378  const Image* getSelectionBrushImage() const;
379 
380  /*************************************************************************
381  Construction and Destruction
382  *************************************************************************/
387  MultiLineEditbox(const String& type, const String& name);
388 
389 
394  virtual ~MultiLineEditbox(void);
395 
396 
397 protected:
398  /*************************************************************************
399  Implementation Methods (abstract)
400  *************************************************************************/
409  //virtual Rect getTextRenderArea_impl(void) const = 0;
410 
411 
412  /*************************************************************************
413  Implementation Methods
414  *************************************************************************/
419  void formatText(void);
420 
421 
432  size_t getNextTokenLength(const String& text, size_t start_idx) const;
433 
434 
439  void configureScrollbars(void);
440 
441 
452  size_t getTextIndexFromPosition(const Point& pt) const;
453 
454 
459  void clearSelection(void);
460 
461 
469  void eraseSelectedText(bool modify_text = true);
470 
471 
476  void handleBackspace(void);
477 
478 
483  void handleDelete(void);
484 
485 
490  void handleCharLeft(uint sysKeys);
491 
492 
497  void handleWordLeft(uint sysKeys);
498 
499 
504  void handleCharRight(uint sysKeys);
505 
506 
511  void handleWordRight(uint sysKeys);
512 
513 
518  void handleDocHome(uint sysKeys);
519 
520 
525  void handleDocEnd(uint sysKeys);
526 
527 
532  void handleLineHome(uint sysKeys);
533 
534 
539  void handleLineEnd(uint sysKeys);
540 
541 
546  void handleLineUp(uint sysKeys);
547 
548 
553  void handleLineDown(uint sysKeys);
554 
555 
560  void handleNewLine(uint sysKeys);
561 
562 
567  void handlePageUp(uint sysKeys);
568 
569 
574  void handlePageDown(uint sysKeys);
575 
576 
587  virtual bool testClassName_impl(const String& class_name) const
588  {
589  if ((class_name=="MultiLineEditBox") ||
590  (class_name=="MultiLineEditbox"))
591  {
592  return true;
593  }
594 
595  return Window::testClassName_impl(class_name);
596  }
597 
602  bool handle_scrollChange(const EventArgs& args);
603 
604  // validate window renderer
605  virtual bool validateWindowRenderer(const String& name) const
606  {
607  return (name == EventNamespace);
608  }
609 
610  /*************************************************************************
611  New event handlers
612  *************************************************************************/
617  void onReadOnlyChanged(WindowEventArgs& e);
618 
619 
624  void onWordWrapModeChanged(WindowEventArgs& e);
625 
626 
631  void onMaximumTextLengthChanged(WindowEventArgs& e);
632 
633 
638  void onCaratMoved(WindowEventArgs& e);
639 
640 
645  void onTextSelectionChanged(WindowEventArgs& e);
646 
647 
652  void onEditboxFullEvent(WindowEventArgs& e);
653 
654 
659  void onVertScrollbarModeChanged(WindowEventArgs& e);
660 
661 
666  void onHorzScrollbarModeChanged(WindowEventArgs& e);
667 
668 
669  /*************************************************************************
670  Overridden event handlers
671  *************************************************************************/
672  virtual void onMouseButtonDown(MouseEventArgs& e);
673  virtual void onMouseButtonUp(MouseEventArgs& e);
674  virtual void onMouseDoubleClicked(MouseEventArgs& e);
675  virtual void onMouseTripleClicked(MouseEventArgs& e);
676  virtual void onMouseMove(MouseEventArgs& e);
677  virtual void onCaptureLost(WindowEventArgs& e);
678  virtual void onCharacter(KeyEventArgs& e);
679  virtual void onKeyDown(KeyEventArgs& e);
680  virtual void onTextChanged(WindowEventArgs& e);
681  virtual void onSized(WindowEventArgs& e);
682  virtual void onMouseWheel(MouseEventArgs& e);
683 
684 
685  /*************************************************************************
686  Implementation data
687  *************************************************************************/
688  bool d_readOnly;
689  size_t d_maxTextLen;
690  size_t d_caratPos;
692  size_t d_selectionEnd;
693  bool d_dragging;
695 
697  bool d_wordWrap;
700 
701  // component widget settings
704 
705  // images
707 
708 
709 private:
710  /*************************************************************************
711  Static Properties for this class
712  *************************************************************************/
713  static MultiLineEditboxProperties::ReadOnly d_readOnlyProperty;
714  static MultiLineEditboxProperties::WordWrap d_wordWrapProperty;
715  static MultiLineEditboxProperties::CaratIndex d_caratIndexProperty;
716  static MultiLineEditboxProperties::SelectionStart d_selectionStartProperty;
717  static MultiLineEditboxProperties::SelectionLength d_selectionLengthProperty;
718  static MultiLineEditboxProperties::MaxTextLength d_maxTextLengthProperty;
719  static MultiLineEditboxProperties::SelectionBrushImage d_selectionBrushProperty;
720  static MultiLineEditboxProperties::ForceVertScrollbar d_forceVertProperty;
721 
722 
723  /*************************************************************************
724  Private methods
725  *************************************************************************/
726  void addMultiLineEditboxProperties(void);
727 };
728 
729 } // End of CEGUI namespace section
730 
731 #if defined(_MSC_VER)
732 # pragma warning(pop)
733 #endif
734 
735 #endif // end of guard _CEGUIMultiLineEditbox_h_