ubit
uedit.hpp
1 /************************************************************************
2  *
3  * uedit.cpp: Text Edition Attribute
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef _uedit_hpp_
18 #define _uedit_hpp_ 1
19 #include <ubit/uattr.hpp>
20 namespace ubit {
21 
30  class UEdit : public UAttr {
31  public:
32  UCLASS(UEdit)
33 
34  UEdit();
36 
37  virtual ~UEdit(); // NOTE: removingFrom() requires a destructor.
38 
39  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40 
41  bool isEditable() const;
42  UEdit& setEditable(bool = true);
44 
45  bool isCaretVisible() const;
46  UEdit& setCaretVisible(bool = true);
48 
49  UColor* getCaretColor() const;
55  long getCaretPos() const;
60  UEdit& setCaretPos(long pos);
65  long getCaretPos(UElem& container) const;
66  UEdit& setCaretPos(long pos, UElem& container);
73  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74 
75  UStr* getCaretStr() const;
76  UStr* getCaretStr(int& pos_in_str) const;
85  UEdit& setCaretStr(UStr* str);
86  UEdit& setCaretStr(UStr* str, int pos_in_str);
97  static UStr* getPreviousStr(UStr* from, UElem& container);
98  static UStr* getNextStr(UStr* from, UElem& container);
104  static UStr* getParagraphFirstStr(UStr* from, int& pos, UElem& container);
105  static UStr* getParagraphLastStr(UStr* from, int& pos, UElem& container);
113  // - - - impl - - - - -- - - - - - - - - - - - - - - - - - - - - - - -
114 
115  USelection* getSelection(UInputEvent& e, UStr& sel_text);
116  void deleteSelection(USelection* sel, UStr& sel_text, UElem& container);
117  void deletePreviousChar(UElem& container, UView* view);
118  void deleteChar(UElem& container, UView* view);
119  bool nextChar(UElem& container, UView* view);
120  bool previousChar(UElem& container, UView* view);
121 
122  void beginningOfLine(UElem& container, UView* view);
123  void endOfLine(UElem& container, UView* view);
124  void previousLine(UElem& container, UView* view);
125  void nextLine(UElem& container, UView* view);
127 
128  virtual void update();
129 
130 #ifndef NO_DOC
131  virtual void putProp(UUpdateContext*, UElem&);
132  virtual void addingTo(UChild&, UElem& parent);
133  virtual void removingFrom(UChild&, UElem& parent);
134  // NOTE: removingFrom() requires a destructor.
135 
136  void setCaretStr(UStr*, int pos_in_str, bool update, UView* view);
137 
138  // prototypes for non-warped text (UView)
139  virtual float getXpos(UUpdateContext&, const URect& r) const;
140  virtual void paint(UGraph&, UUpdateContext&, const URect &r) const;
141 
142  // prototypes for warped text (UFlowview)
143  virtual float getXpos(UUpdateContext&, const URect&, int offset, int cellen) const;
144  virtual void paint(UGraph&, UUpdateContext&, const URect&, int offset, int cellen) const;
145 
146  private:
147  uptr<UCall> calls; // callback object
148  uptr<UCall> calls2; // callback object
149  uptr<UColor> caret_color; // specific color for displaying the caret (if any)
150  uptr<UStr> caret_str; // the string that contains the caret (if any)
151  long caret_pos; // the position of the caret in 'caret_str'
152  bool is_editable, is_visible;
153  mutable bool repainted;
154  virtual void inputCB(UInputEvent&);
155  virtual void kpressed(UKeyEvent&);
156  virtual void mpressed(UMouseEvent&);
157  virtual void mreleased(UMouseEvent&);
158  virtual void callbacks2(UMouseEvent&);
159 #endif
160  };
161 
162  inline UEdit& uedit() {return *new UEdit();}
164 
165 }
166 #endif
167 /* ==================================================== [TheEnd] ======= */
Base class for attributes.
Definition: uattr.hpp:97
keyboard events
Definition: uevent.hpp:316
text selection.
Definition: uselection.hpp:25
long getCaretPos() const
returns the caret position.
Definition: uedit.cpp:152
UEdit()
creates a new UEdit property;
Definition: uedit.cpp:39
class for drawing on widgets.
Definition: ugraph.hpp:44
2D Rectangle.
Definition: ugeom.hpp:165
Text editing and caret controller.
Definition: uedit.hpp:30
Color attribute of an element or a widget.
Definition: ucolor.hpp:73
UEdit & setCaretPos(long pos)
changes the caret position.
Definition: uedit.cpp:172
static UStr * getNextStr(UStr *from, UElem &container)
[unstable] returns the string before/after &#39;from&#39; in this &#39;container&#39;.
Definition: uedit.cpp:309
UEdit & setCaretVisible(bool=true)
get/set caret visibility.
Definition: uedit.cpp:59
UEdit & setCaretColor(UColor *)
get/set the color used to render the caret.
Definition: uedit.cpp:60
lightweight general purpose container.
Definition: uelem.hpp:44
static UStr * getParagraphLastStr(UStr *from, int &pos, UElem &container)
[unstable] returns the first/last string in the same paragraph than &#39;from&#39;.
Definition: uedit.cpp:363
Smart Pointer for UObject instances (.
Definition: uobject.hpp:365
static UStr * getParagraphFirstStr(UStr *from, int &pos, UElem &container)
Definition: uedit.cpp:317
virtual void addingTo(UChild &, UElem &parent)
called when this object is added to a parent.
Definition: uedit.cpp:64
void previousLine(UElem &container, UView *view)
Definition: uedit.cpp:500
Box View.
Definition: uview.hpp:65
virtual void removingFrom(UChild &, UElem &parent)
called when this object is removed from a parent (SEE DETAILS IF YOU REDEFINE THIS METHOD)...
Definition: uedit.cpp:90
Definition: uupdatecontext.hpp:32
Definition: uhardfont.hpp:31
virtual void update()
updates parents graphics.
Definition: uedit.cpp:118
Base class for UMouseEvent and UKeyEvent Note that this class inherits from class UModifier that defi...
Definition: uevent.hpp:75
virtual void putProp(UUpdateContext *, UElem &)
[impl] changes corresponding value in the UUpdateContext
Definition: uedit.cpp:107
void nextLine(UElem &container, UView *view)
[impl] moves the caret in the expected way.
Definition: uedit.cpp:516
UEdit & setEditable(bool=true)
get/set text editing mode
Definition: uedit.cpp:58
Ubit String.
Definition: ustr.hpp:72
mouse events
Definition: uevent.hpp:172
[impl] Internal implementation of a child node.
Definition: uchild.hpp:23