ubit
uviewImpl.hpp
1 /************************************************************************
2  *
3  * uviewImpl.hpp : internal implementation of UView
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 _uviewImpl_hpp_
18 #define _uviewImpl_hpp_ 1
19 #include <ubit/uevent.hpp>
20 #include <ubit/uborder.hpp>
21 #include <ubit/uupdatecontext.hpp>
22 namespace ubit {
23 
24  class U3DcanvasView;
25  class U3Dpos;
26 
27  // ==================================================== ===== =======
28  // [Impl] Object behaviors.
29 
30  class UBehavior {
31  public:
32  enum InputType {MOUSE=0, BROWSE=1, KEY=2};
33 
34  UBehavior(InputType = MOUSE);
35 
36  InputType intype;
39  const UCursor* cursor;
40  UElem* browsing_group;
41  UBox* event_observer;
42  };
43 
44  // ==================================================== ===== =======
45  // [Impl] UViewProp: view property.
46 
47  class UViewProp {
48  public:
49  virtual ~UViewProp() {}
50  };
51 
52  // used by motion/resize callbacks to check if pos/size has changed.
54  UPoint pos;
55  UDimension size;
56  };
57 
58  // used by the keep size mode of USize
59  struct UViewKeepSizeProp : public UViewProp {
60  UViewKeepSizeProp() : width(-1), height(-1) {}
61  float width, height;
62  };
63 
64  // border padding of this view.
65  struct UViewBorderProp : public UViewProp, public UPaddingSpec {
66  UViewBorderProp() : UPaddingSpec(0,0) {}
67  };
68 
69  // used by to force position.
70  //struct UViewForcePosProp : public UViewProp {
71  // UViewForcePosProp() : x(0), y(0) {}
72  // float x, y;
73  //};
74 
75  // ==================================================== ===== =======
76  // [Impl] UViewContext: struct used to retrieve the view context.
77 
78  class UViewContext {
79  public:
80  UViewContext();
81  ~UViewContext();
82  UView::FindMode find_mode;
83  bool is_clip_set; // is clip valid ?
84  URect clip;
85  UUpdateContext* upd_context; // set if get_upd_context is true
86  UView* layout_view; // layout should take place from this view.
87  };
88 
89  // ==================================================== ===== =======
90  // [Impl] UViewFind: struct used to find event sources.
91 
92  class UViewFind {
93  public:
94  UViewFind(UView* win_view, const UPoint pos_in_win,
95  UBehavior::InputType intype, unsigned char catch_mask);
96  void updateProps(UView*, UElem*, const UUpdateContext& cur_ctx);
97 
98  UView* ref_view; // window or 3Dwidget view (if canvas_view != null)
99  UPoint ref_pos; // pos in ref_view (whatever it is)
100  U3DcanvasView* canvas_view; // != null if the source is in a 3Dwidget
101  U3Dpos* refpos_in_canvas; // 3Dpos of the 3Dwidget in canvas_view (if it is != null)
102 
103  UWinUpdateContext win_ctx;
104  UUpdateContext found_ctx;
105  unsigned char CATCH_MASK;
106  UBox* catched;
107  UBox* uncatchable;
108  UBehavior bp;
109  };
110 
111  // ==================================================== ===== =======
112  // [Impl] UViewLayout: struct used to layout widget views.
113 
114  class UViewLayout {
115  public:
116  enum Strategy {BOXVIEW, GET_HINTS, IMPOSE_WIDTH, NESTED} strategy;
117  UDimension dim;
118  float spec_w, min_w, max_w;
119  float spec_h, min_h, max_h;
120  UViewLayout() : strategy(BOXVIEW) {}
121  };
122 
124  public:
126  void computeWidth(const UUpdateContext& curp, const UPaddingSpec&,
127  UViewLayout&, bool minmax_defined);
128  void computeHeight(const UUpdateContext& curp, const UPaddingSpec&,
129  UViewLayout&, bool minmax_defined);
130 
131  UView* view;
132  int visibleElemCount; // UBox or UData (not UElem, not a PosBox)
133  float chwidth, pos_chwidth, chheight, pos_chheight; // ex int
134  unsigned char orient;
135  bool mustLayoutAgain;
136  };
137 
138  // ==================================================== ===== =======
139  // [Impl] UViewUpdate: struct used to update widget views.
140 
141  class UViewUpdate {
142  public:
143  // !BEWARE: order is MEANINGFUL: all ITEM operations must be > ITEM_OPS
144  enum Mode {
145  PAINT_ALL, // Paint all objects in clipping area
146  PAINT_DAMAGED, // Just paint damaged objects and their children,
147  //MAIS AUSSI toutes les vues soeurs qui suivent (a cause des vues
148  //evntuellement superposees, voir note dans UViewUpdateData ci-dessous)
149  //PAINT_CHANGED, // Just paint objects whose size or pos has changed
150  UPDATE_DATA, // Just update data, do not paint
151  FIND_DATA_POS, // Locate an UData from its pos - do NOT paint it
152  FIND_DATA_PTR // Locate an UData from a link or a pointer
153  };
154 
155  Mode mode;
156  UDataContext* datactx; // optional, used when searching UDatas
157  // when applicable (mode PAINT_DAMAGED) : 0 before drawing any damaged,
158  // > 0 No (depth) of the damaged view, < 0 after painting the first damaged
159  int damaged_level;
160  // true when one or several damaged views have been processed
161  bool after_damaged;
162  // number of views to repaint above damaged objects
163  int above_damaged_count;
164 
165  UViewUpdate(Mode _mode) {
166  mode = _mode;
167  datactx = null;
168  damaged_level = 0;
169  after_damaged = false;
170  above_damaged_count = 0;
171  }
172 
173  void setMode(Mode _mode) {mode = _mode;}
174  Mode getMode() {return mode;}
175  };
176 
177 
178  class UViewUpdateImpl : public URect {
179  public:
180  UViewUpdateImpl(UView*, const URect& r, UViewUpdate&);
181  virtual ~UViewUpdateImpl();
182 
183  virtual void updateBackground(UGraph&, UUpdateContext&,
184  const URect &r, const URect& clip);
185  virtual void setPadding(UGraph&, const UUpdateContext&,
186  const URect &r, bool add_frame_and_paddind);
187  virtual void callPaintCallbacks(UElem&, UUpdateContext&);
188  virtual void callMoveResizeCallbacks(UElem&, UUpdateContext&);
189 
190  UView* view;
191  UPaddingSpec pad;
192  URect chr, chclip;
193  float vflex_space, hflex_space;
194  bool can_paint;
195  unsigned char orient;
196  UViewUpdate& upmode;
197  class UTableView* tabview;
198  class UEdit* edit;
199  };
200 
201  // ==================================================== ===== =======
202 
203  class UMultiList {
204  public:
205  static const int MAXCOUNT = 2;
206 
207  // parses the child list of grp, finds the 1st visible element (UData or UElem)
208  // and adds it (and its followers) as a sublist
209  // also checks HARDWIN and SOFTWIN_LIST
211 
212  UChildIter begin() {return sublists[current = 0].begin;}
213  UChildIter end() {return sublists[current].end;}
214  // att: end() doit etre celui de current car cette valeur est utilisee ds le code.
215 
216  void next(UChildIter& c);
217  void addChildList(UChildIter begin, UChildIter end);
218 
219  //private:
220  struct SubList {UChildIter begin, end;};
221  SubList sublists[MAXCOUNT];
222  int card, current;
223  bool in_softwin_list;
224  };
225 
226 }
227 #endif
228 
information on UData objects that are being retrieved by UEvent::getData() or UEvent::getStr().
Definition: uevent.hpp:524
2D Dimension.
Definition: ugeom.hpp:55
Definition: utable.hpp:108
Definition: uviewImpl.hpp:92
Definition: uviewImpl.hpp:47
Box container.
Definition: ubox.hpp:64
2D Point.
Definition: ugeom.hpp:25
Definition: uviewImpl.hpp:30
class for drawing on widgets.
Definition: ugraph.hpp:44
2D Rectangle.
Definition: ugeom.hpp:165
Definition: uviewImpl.hpp:141
Definition: uupdatecontext.hpp:98
Text editing and caret controller.
Definition: uedit.hpp:30
bool DONT_CLOSE_MENU
the source does not close menus.
Definition: uviewImpl.hpp:38
Definition: uviewImpl.hpp:59
Definition: uviewImpl.hpp:65
lightweight general purpose container.
Definition: uelem.hpp:44
Definition: uviewImpl.hpp:178
[Instable/OpenGL] 3D position.
Definition: u3d.hpp:129
Box padding.
Definition: ulength.hpp:150
Definition: uviewImpl.hpp:203
Box View.
Definition: uview.hpp:65
Definition: uupdatecontext.hpp:32
Definition: u3d.hpp:173
Definition: uhardfont.hpp:31
bool SOURCE_IN_MENU
is the source (indirectly) included in a menu?.
Definition: uviewImpl.hpp:37
Definition: uviewImpl.hpp:114
Definition: uviewImpl.hpp:123
Definition: uviewImpl.hpp:78
Mouse cursor property.
Definition: ucursor.hpp:31
Definition: uviewImpl.hpp:220
Definition: uviewImpl.hpp:53