ubit
uview.hpp
1 /************************************************************************
2  *
3  * uview.hpp : UBox views
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 _uview_hpp_
18 #define _uview_hpp_ 1
19 #include <list>
20 #include <ubit/uelem.hpp>
21 #include <ubit/uevent.hpp>
22 #include <ubit/ugeom.hpp>
23 namespace ubit {
24 
25  class UFlowView;
26  class UTableView;
27  class UPaneView;
28  class UViewFind;
29  class UViewLayout;
30  class UViewUpdate;
31  class UViewLayoutImpl;
32  class UViewUpdateImpl;
33  class UFlowLayoutImpl;
34  class UFlowUpdateImpl;
35  class UMultiList;
36  class UViewProp;
37  //struct UViewContext;
38 
39  /* ==================================================== ===== ======= */
42  class UViewStyle : public UAttr {
43  public:
44  UCLASSDEF("UViewStyle", UViewStyle, null)
45 
47  virtual ~UViewStyle() {destructs();}
48 
49  UView* (*createView)(UBox*, UView* parview, UHardwinImpl*);
51 
52  virtual void addingTo(UChild&, UElem& parent);
53  virtual void removingFrom(UChild&, UElem& parent);
55  };
56 
57  /* ==================================================== ===== ======= */
65  class UView : public URect {
66  public:
67  UCLASSDEF("UView", UView, null)
68 
69  static UViewStyle style;
70 
71  UView(UBox*, UView* parview, UHardwinImpl*);
72  virtual ~UView();
73 
74  virtual UFlowView* toFlowView() {return null;}
75  virtual UTableView* toTableView() {return null;}
76  virtual UPaneView* toPaneView() {return null;}
77 
78  bool isShown() const;
80 
81  bool isRealized() const;
83 
84  float getWidth() const {return width;}
86 
87  float getHeight() const {return height;}
89 
90  UDimension getSize() const;
92 
93  void setSize(const UDimension&);
100  static UPoint convertPosTo(const UView& to, const UView& from, const UPoint& pos_in_from);
105  float getX() const;
107 
108  float getY() const;
110 
111  UPoint getPos() const;
113 
114  UPoint getPosIn(UView& ref_view) const;
116 
117  UPoint getScreenPos() const;
119 
120  UPoint getGLPos() const;
126  UPoint getHardwinPos() const;
134  float getScale() const {return scale;}
136 
137 
138  virtual bool caretPosToXY(long caret_pos, int& xcol, int& yline) const;
143  virtual bool xyToCaretPos(int line, int col, long& caret_pos) const;
148  UBox* getBox() const {return box;}
150 
151  UBox* getBoxParent() const;
153 
154  UView* getParentView() const {return parview;}
156 
157  UDisp* getDisp() const;
159 
160  UWin* getWin() const;
162 
163  UView* getWinView() const;
165 
166  UHardwinImpl* getHardwin() const {return hardwin;}
168 
169  bool isChildOf(const std::vector<UView*>& parent_views);
170 
171  // - - - Impl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
172 
173  virtual bool containsWC(const UPoint& pos_in_win);
175 
176  virtual void updateLayout(const UDimension* force_size, bool upd_paint_data = true);
178 
179  virtual void updatePaintData(const URect* region = null);
185  virtual void updatePaint(const URect* region = null);
190  virtual UView* findSource(UViewFind&, UPoint& pos_in_src);
192 
193  virtual UView* findSourceNext(UViewFind&, UPoint& pos_in_src);
195 
196  enum FindMode {FIND_CLIP, FIND_VIEW_CONTEXT, FIND_PARENT_CONTEXT};
197 
198  virtual bool findContext(UViewContext&, FindMode);
200 
201  virtual UData* findData(UDataContext&, const UPoint& pos,
202  const UData* searched_data, int strpos1, int strpos2);
204 
205 #ifndef NO_DOC
206  enum VMODES {
207  // INITIALIZING is set at the 1st update, INITIALIZED at the 2nd update
208  // (a combination of layout+update+layout is necessary for correct init)
209  INITIALIZING = 1<<0,
210  INITIALIZED = 1<<1,
211  DAMAGED = 1<<2, // this view has been damaged and must be repaint
212  // this viewobject has been fully destructed (by all its destructors)
213  // but the memory has not yet been freed (operator delete being redefined)
214  DESTRUCTED = 1<<3,
215  FIXED_WIDTH = 1<<4, // this view has a fixed width.
216  FIXED_HEIGHT = 1<<5, // this view has a fixed height.
217  REALIZED_CHILDREN = 1<<6, // the children of this view have been realized (for win views only)
218  POS_HAS_CHANGED = 1<<9, // position has changed => geometry must be updated
219  SIZE_HAS_CHANGED = 1<<10, // size has changed => geometry must be updated
220  NO_DOUBLE_BUFFER = 1<< 11
221  // !BEWARE: no comma after last item!
222  };
223 
224  typedef std::list<UViewProp*> UViewProps;
225 
226  static UView* createView(UBox*, UView* parview, UHardwinImpl*);
227  // createView() is a static constructor used by UViewStyle to make a new view.
228 
229  void operator delete(void*);
230  // requests view deletion.
231 
232  int getVModes() const {return vmodes;}
233  // returns the current V-Modes bitmask.
234 
235  bool hasVMode(int modes) const {return (vmodes & modes) != 0;}
236  // true if ONE of these V-Modes is verified.
237 
238  void addVModes(long modes) {vmodes |= modes;}
239  // add these modes to the V-Modes bitmask.
240 
241  void removeVModes(long modes) {vmodes &= ~modes;}
242  // remove these modes from the V-Modes bitmask.
243 
244  virtual UViewStyle* getViewStyle() {return &style;}
245  // returns the default view style.
246 
247  UView* getNext() {return next;}
248  // returns the next view in the list (if any, null otherwise).
249 
250  template <typename T> T* getProp(T*& p) {
251  p = null;
252  for (UViewProps::iterator i = props.begin(); i != props.end(); ++i)
253  { if (dynamic_cast<T*>(*i)) {p = (T*)*i; return p;} }
254  return null;
255  }
256  // returns the corresponding View Property; null if this property does not belong to the view.
257 
258  template <typename T> T& obtainProp(T*& p) {
259  getProp(p); if (!p) {p = new T(); props.push_back(p);} return *p;
260  }
261  // returns or creates the corresponding View Property: creates and adds this property if it does not belong to the view.
262 
263  void incrHFlexCount() {++hflex_count;}
264  void incrVFlexCount() {++vflex_count;}
265  void setScale(float s) {scale = s;}
266 
267  virtual bool doLayout(UUpdateContext&, UViewLayout&);
268  virtual void doUpdate(UUpdateContext&, URect r, URect clip, UViewUpdate&);
269 
270  protected:
271  int vmodes; // modes of this view
272  float scale;
273  float chwidth, chheight; // size occupied by children
274  float edit_shift; // for UEdit
275  unsigned short hflex_count, vflex_count; // number of horiz and vert flexible children
276  UView* parview; // parent view
277  UBox* box; // corresponding UBox
278  UHardwinImpl* hardwin; // hard window
279  UView* next; // next view
280  UViewProps props;
281 
282  void setParentView(UView* parent_view);
283  void setNext(UView* v) {next = v;}
284 
285  virtual void doLayout2(UViewLayoutImpl&, UElem&, UUpdateContext&, UViewLayout&);
286 
287  virtual void doUpdate2(UViewUpdateImpl&, UElem&, UUpdateContext&,
288  URect& r, URect& clip, UViewUpdate&);
289 
290  virtual bool updatePos(UViewUpdateImpl&, UElem&, UUpdateContext& curctx,
291  URect& r, URect& clip, UViewUpdate&);
292 
293  virtual void beginUpdate3d(UViewUpdateImpl&, UElem&, UUpdateContext& curctx);
294  virtual void endUpdate3d(UViewUpdateImpl&, UElem&, UUpdateContext& curctx);
295 
296  virtual UView* findInBox(UBox*, const UPoint& winpos, const UUpdateContext&, UViewFind&);
297  virtual UView* findInGroup(UElem*, const UPoint& winpos, const UUpdateContext&, UViewFind&);
298  virtual UView* findInChildren(UElem*, const UPoint& winpos, const UUpdateContext&, UViewFind&);
299 
300  virtual bool findDataV(UUpdateContext&, UChildIter data_iter, UChildIter end_iter,
301  const URect&, UViewUpdate&);
302  virtual bool findDataH(UUpdateContext&, UChildIter data_iter, UChildIter end_iter,
303  const URect&, UViewUpdate&);
304  virtual bool findDataPtr(UUpdateContext&, UChildIter data_iter, UChildIter end_iter,
305  const URect&, UViewUpdate&);
306 
307  static void initLayoutH(UViewUpdateImpl& vd, const UUpdateContext& curp, const URect& r);
308  static void initLayoutV(UViewUpdateImpl& vd, const UUpdateContext& curp, const URect& r);
309  static void initLayoutViewport(UViewUpdateImpl& vd, const UUpdateContext& curp, const URect& r);
310  static void layoutH(UViewUpdateImpl& vd, const UUpdateContext& curp, UChildIter link,
311  const UDimension& dim, UElem* chgrp, UView* chview);
312  static void layoutV(UViewUpdateImpl& vd, const UUpdateContext& curp, UChildIter link,
313  const UDimension& dim, UElem* chgrp, UView* chview);
314  static void layoutViewport(UViewUpdateImpl& vd, const UUpdateContext& curp,
315  UChildIter link, const UDimension& dim, UView* chview);
316 #endif
317  private:
318  friend class UBox;
319  friend class UWin;
320  friend class UHardwinImpl;
321  friend class USubwin;
322  friend class UChild;
323  friend class UViewLayoutImpl;
324  friend class UViewUpdateImpl;
325  friend class UAppliImpl;
326  friend class UInputEvent;
327  friend class UEventFlow;
328  friend class U3DcanvasView;
329  UView(const UView&);
330  UView& operator=(const UView&); // assigment is forbidden
331  };
332 
333  // ==================================================== ===== ======= //
334 
335  class UFlowView: public UView {
336  public:
337  UCLASSDEF("UFlowView", UFlowView, null)
338 
339  static UViewStyle style; // renderer
340  virtual UViewStyle* getViewStyle() {return &style;}
341 
342  UFlowView(UBox*, UView* parview, UHardwinImpl*);
343  virtual ~UFlowView();
344 
345  static UView* createView(UBox*, UView* parview, UHardwinImpl*);
346 
347  virtual UFlowView* toFlowView() {return this;}
349 
350  virtual bool caretPosToXY(long caret_pos, int& xcol, int& yline) const; // ex int
351  virtual bool xyToCaretPos(int xcol, int yline, long& caret_pos) const;
352 
353  virtual bool doLayout(UUpdateContext& parent_context, UViewLayout&);
354  virtual void doUpdate(UUpdateContext& parent_context, URect r, URect clip, UViewUpdate&);
355 
356  float getMaxWidth() const;
357 
358  // - - - Impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
359  private:
360  friend class UFlowLayoutImpl;
361  friend class UFlowUpdateImpl;
362  class UFlowLine* lines;
363  class UFlowCell* cells;
364  int line_count, cell_count, lastline_strcell;
365  int alloc_line_count, alloc_cell_count;
366 
367  //NB: pour des raiason historiquesflowview utilise des fonctions differentes
368  // de sa superclasse UView
369  void flowDoLayout(UFlowLayoutImpl&, UElem&, UUpdateContext&, UMultiList&);
370  void flowDoUpdate(UFlowUpdateImpl&, UUpdateContext&, UElem&, UMultiList&,
371  const URect& r, URect& clip, UViewUpdate&);
372 
373  //NB: NOT virtual: these functions are used instead of findDataV, findDataH, findDataPtr
374  bool flowFindDataPos(UUpdateContext&, UChildIter data_it, UChildIter end_it,
375  UFlowCell*, const URect&, UViewUpdate&);
376 
377  bool flowFindDataPtr(UUpdateContext&, UChildIter data_it, UChildIter end_it,
378  UFlowCell*, const URect&, UViewUpdate&);
379  };
380 
381 
382 }
383 #endif
information on UData objects that are being retrieved by UEvent::getData() or UEvent::getStr().
Definition: uevent.hpp:524
Base class for attributes.
Definition: uattr.hpp:97
2D Dimension.
Definition: ugeom.hpp:55
Definition: utable.hpp:108
Definition: uviewImpl.hpp:92
Definition: uobject.hpp:282
Box container.
Definition: ubox.hpp:64
2D Point.
Definition: ugeom.hpp:25
UView *(* createView)(UBox *, UView *parview, UHardwinImpl *)
pointer to the corresponding UView::createView static constructor.
Definition: uview.hpp:49
Definition: uappliImpl.hpp:40
Definition: uviewflow.cpp:38
2D Rectangle.
Definition: ugeom.hpp:165
Display Context.
Definition: udisp.hpp:44
float getWidth() const
returns the width of the view.
Definition: uview.hpp:84
Definition: uviewImpl.hpp:141
Definition: uviewflow.cpp:491
float getHeight() const
returns the height of the view.
Definition: uview.hpp:87
Base class for Viewable Objects.
Definition: udata.hpp:31
Definition: uviewflow.cpp:46
lightweight general purpose container.
Definition: uelem.hpp:44
UBox * getBox() const
returns the widget that controls this view.
Definition: uview.hpp:148
Definition: uviewImpl.hpp:178
UView * getParentView() const
returns the parent view (if any, null for window views).
Definition: uview.hpp:154
float getScale() const
returns the scaling factor applied to this view.
Definition: uview.hpp:134
Definition: uviewImpl.hpp:203
Definition: uview.hpp:335
virtual void addingTo(UChild &, UElem &parent)
called when this object is added to a parent.
Definition: uview.cpp:39
UHardwinImpl * getHardwin() const
returns the hard window that contains this view.
Definition: uview.hpp:166
Event Flow.
Definition: ueventflow.hpp:34
virtual void destructs()
unlinks the object from its parents and destroys its children.
Definition: unode.cpp:56
Box View.
Definition: uview.hpp:65
Specifies the View Style of an UBox.
Definition: uview.hpp:42
Definition: uupdatecontext.hpp:32
Definition: uviewflow.cpp:139
Definition: u3d.hpp:173
Definition: uhardfont.hpp:31
Base class for UMouseEvent and UKeyEvent Note that this class inherits from class UModifier that defi...
Definition: uevent.hpp:75
virtual void removingFrom(UChild &, UElem &parent)
NOTE that this function require a specific destructor.
Definition: uview.cpp:47
Definition: uwinImpl.hpp:84
virtual bool isChildOf(const UElem &parent, bool indirect=true) const
returns true if this object a child of &#39;parent&#39;.
Definition: unode.cpp:249
Definition: uviewImpl.hpp:114
Base class for windows and menus.
Definition: uwin.hpp:47
Definition: uviewImpl.hpp:123
Definition: uviewImpl.hpp:78
Subwindow: a hard window that is embedded inside another window.
Definition: usubwin.hpp:33
[Impl] UPane View.
Definition: uscrollpane.hpp:127
[impl] Internal implementation of a child node.
Definition: uchild.hpp:23
virtual UFlowView * toFlowView()
pseudo dynamic cast: returns this object if it a a UFlowView.
Definition: uview.hpp:347