00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _uview_hpp_
00022 #define _uview_hpp_
00023
00024 #include <list>
00025 #include <ubit/ucontrol.hpp>
00026 #include <ubit/uevent.hpp>
00027 #include <ubit/ugeom.hpp>
00028 namespace ubit {
00029
00030 class UFlowView;
00031 class UTableView;
00032 class UPaneView;
00033 class UViewExt;
00034 class UViewLayout;
00035 class UViewUpdate;
00036 class UViewLayoutImpl;
00037 class UViewUpdateImpl;
00038 class UFlowLayoutImpl;
00039 class UFlowUpdateImpl;
00040 class UMultiList;
00041
00042
00045 class UViewStyle : public UMode {
00046 public:
00047 UViewStyle(UView* (*)(UChild*, UView*, UHardWinImpl*), UMask = 0);
00048 virtual ~UViewStyle() {destructs();}
00049
00050 UView* (*createView)(UChild*, UView* parview, UHardWinImpl*);
00052
00053 virtual void addingTo(UChild* self, UGroup *parent);
00054 virtual void removingFrom(UChild* self, UGroup *parent);
00056 };
00057
00058
00059
00067 class UView : public URegion {
00068 public:
00069 UView(UChild*, UView* parview, UHardWinImpl*);
00070 virtual ~UView();
00071
00072 static UViewStyle style;
00074
00075 virtual UViewStyle* getViewStyle() {return &style;}
00077
00078 static UView* createView(UChild*, UView* parview, UHardWinImpl*);
00080
00081 virtual UFlowView* flowCast() {return null;}
00082 virtual UTableView* tableCast() {return null;}
00083 virtual UPaneView* paneCast() {return null;}
00085
00086
00087
00088 bool isShown() const;
00090
00091 bool isRealized() const;
00096 UBox* getBox() const;
00098
00099 UBox* getBoxParent() const;
00100
00101
00102
00103
00104 UView* getParentView() const {return parview;}
00106
00107 UDisp* getDisp() const;
00109
00110 UWin* getWin() const;
00111 UView* getWinView() const;
00113
00114 UHardWinImpl* getHardWinImpl() {return win;}
00115 UNatWin* getNatWin() const;
00116 UNatDisp* getNatDisp() const;
00117
00118
00119 UView* getNext() {return nextview;}
00121
00122 UChild* getChildNode() {return childnode;}
00124
00125 template <typename T> T* getProp(T*& p) {
00126 p = null;
00127 for (UViewProps::iterator i = props.begin(); i != props.end(); ++i)
00128 { if (dynamic_cast<T*>(*i)) {p = (T*)*i; return p;} }
00129 return null;
00130 }
00135 template <typename T> T& obtainProp(T*& p) {
00136 getProp(p); if (!p) {p = new T(); props.push_back(p);} return *p;
00137 }
00142
00143
00144
00145 int getWidth() const {return width;}
00147
00148 int getHeight() const {return height;}
00150
00151 void getSize(int& w, int& h) const {w = width; h = height;}
00153
00154 UDimension getSize() const;
00156
00157 void setSize(int width, int height);
00164
00165
00166
00167 int getX() const;
00169
00170 int getY() const;
00172
00173 void getPos(int& x, int& y) const;
00175
00176 UPoint getPos() const;
00178
00179 void getPosInWin(int& x, int& y) const;
00181
00182 UPoint getPosInWin() const;
00184
00185 void getPosOnScreen(int& x, int& y) const;
00187
00188 UPoint getPosOnScreen() const;
00190
00191 void setPos(int x, int y);
00198 void setAutoPositioning(bool);
00202
00203
00204
00205 static bool convertPos(const UView* to_view, int& to_x, int& to_y,
00206 const UView* from_view, int from_x, int from_y);
00212 int XToXwin(int x_in_view) const {return x_in_view + x;}
00213 int YToYwin(int y_in_view) const {return y_in_view + y;}
00215
00216 int XwinToX(int x_in_win) const {return x_in_win - x;}
00217 int YwinToY(int y_in_win) const {return y_in_win - y;}
00219
00220 int eventToX(const UMouseEvent& e) const {return e.getXwin() - x;}
00221 int eventToY(const UMouseEvent& e) const {return e.getYwin() - y;}
00226 virtual bool caretPosToXY(long caret_pos, int& line, int& col) const;
00227 virtual bool xyToCaretPos(int line, int col, long& caret_pos) const;
00232
00233
00234 enum VMODES {
00237 INITIALIZING = 1<<0,
00238 INITIALIZED = 1<<1,
00239
00241 DAMAGED = 1<<2,
00242
00245 DESTRUCTED = 1<<3,
00246
00248 FIXED_WIDTH = 1<<4,
00249 FIXED_HEIGHT = 1<<5,
00250
00252 REALIZED_CHILDREN = 1<<6,
00253
00254 FORCE_POS = 1<<7,
00255
00258 POS_HAS_CHANGED = 1<<9,
00259 SIZE_HAS_CHANGED = 1<<10,
00260
00261 NO_DOUBLE_BUFFER = 1<< 11
00262 };
00264
00265 int getVModes() const {return vmodes;}
00267
00268 bool hasVMode(int modes) const {return (vmodes & modes) != 0;}
00270
00271 void addVModes(UMask modes) {vmodes |= modes;}
00273
00274 void removeVModes(UMask modes) {vmodes &= ~modes;}
00276
00277
00278
00279 void updatePaint(URegion* view_region = null, int dbf_mode = 0);
00285 void updateWinPaint(const URegion& window_region, int dbf_mode,
00286 bool all_layers, UView* first_layer);
00295 int updateWinData(const URegion& window_region);
00301 virtual bool doLayout(UContext&, UViewLayout&);
00303
00304 virtual void doUpdate(UContext&, URegion r, URegion clip, UViewUpdate&);
00306
00307 void operator delete(void*);
00308
00309
00310 #ifndef NO_DOC
00311 void setParentView(UView* parent_view);
00312 void setNext(UView* v) {nextview = v;}
00313
00314 virtual bool updatePos(UViewUpdateImpl&, UGroup*, UContext& curctx,
00315 URegion& r, URegion& clip, UViewUpdate&);
00316 virtual void beginUpdate3d(UViewUpdateImpl&, UGroup*, UContext& curctx);
00317 virtual void endUpdate3d(UViewUpdateImpl&, UGroup*, UContext& curctx);
00318
00319 virtual bool retrieveProps(UEventProps& );
00320
00321 virtual UView* findInBox(UBox*, UEvent&, const UContext& parent_ctx,
00322 URegion clip, UEventProps);
00323 virtual UView* findInGroup(UGroup*, UEvent&, const UContext& parent_ctx,
00324 URegion clip, UEventProps&);
00325 virtual UView* findInChildren(UGroup*, UEvent&, const UContext& current_ctx,
00326 const URegion& clip, UEventProps&);
00327
00328 protected:
00329 virtual void doLayout2(UViewLayoutImpl&, UGroup*, UContext&, UViewLayout&);
00330 virtual void doUpdate2(UViewUpdateImpl&, UGroup*, UContext&,
00331 URegion& r, URegion& clip, UViewUpdate&);
00332
00333 virtual bool findDataV(UContext&, UChildIter data_it, UChildIter end_it,
00334 const URegion&, UViewUpdate&);
00335 virtual bool findDataH(UContext&, UChildIter data_it, UChildIter end_it,
00336 const URegion&, UViewUpdate&);
00337 virtual bool findDataPtr(UContext&, UChildIter data_it, UChildIter end_it,
00338 const URegion&, UViewUpdate&);
00339 private:
00340 friend class UViewLayoutImpl;
00341 friend class UViewUpdateImpl;
00342 friend class UBox;
00343 friend class UWin;
00344 friend class UChild;
00345 friend class UPlugpane;
00346
00347 UView(const UView&);
00348 UView& operator=(const UView&);
00349
00350 protected:
00351 UView *parview;
00352 UChild *childnode;
00353 UHardWinImpl *win;
00354 UView *nextview;
00355 int vmodes;
00356
00357 public:
00358 int chwidth, chheight;
00359 int edit_shift;
00360 unsigned short hflex_count, vflex_count;
00361 typedef std::list<struct UViewProp*> UViewProps;
00362 UViewProps props;
00363 #endif
00364 };
00365
00366
00369 struct UViewProp {
00370 virtual ~UViewProp() {}
00371 };
00372
00373
00374 struct UViewPrevSizeProp : public UViewProp {
00375 UViewPrevSizeProp() : width(0), height(0) {}
00376 int width, height;
00377 };
00378
00379
00380 struct UViewKeepSizeProp : public UViewProp {
00381 UViewKeepSizeProp() : width(-1), height(-1) {}
00382 int width, height;
00383 };
00384
00385
00386 struct UViewForcePosProp : public UViewProp {
00387 UViewForcePosProp() : x(0), y(0) {}
00388 int x, y;
00389 };
00390
00391
00392 struct UViewBorderProp : public UViewProp, public UMargins {
00393 UViewBorderProp() : UMargins(0,0) {}
00394 };
00395
00396
00397
00398 class UFlowView: public UView {
00399 public:
00400 static UViewStyle style;
00401 virtual UViewStyle* getViewStyle() {return &style;}
00402
00403 UFlowView(UChild*, UView* parview, UHardWinImpl*);
00404 virtual ~UFlowView();
00405
00406 static UView* createView(UChild*, UView* parview, UHardWinImpl*);
00407
00408 virtual UFlowView* flowCast() {return this;}
00410
00411 virtual bool caretPosToXY(long caret_pos, int& x, int& y) const;
00412 virtual bool xyToCaretPos(int x, int y, long& caret_pos) const;
00413
00414
00415 #ifndef NO_DOC
00416 virtual bool doLayout(UContext& parent_context, UViewLayout&);
00417 virtual void doUpdate(UContext& parent_context, URegion r, URegion clip, UViewUpdate&);
00418 int getMaxWidth() const;
00419
00420 private:
00421 friend class UFlowLayoutImpl;
00422 friend class UFlowUpdateImpl;
00423 class UFlowLine* lines;
00424 class UFlowCell* cells;
00425 int line_count, cell_count, lastline_strcell;
00426 int alloc_line_count, alloc_cell_count;
00427
00428
00429
00430 void flowDoLayout(UFlowLayoutImpl&, UGroup*, UContext&, UMultiList&);
00431 void flowDoUpdate(UFlowUpdateImpl&, UContext&, UGroup*, UMultiList&,
00432 const URegion& r, URegion& clip, UViewUpdate&);
00433
00434
00435 bool flowFindDataPos(UContext&, UChildIter data_it, UChildIter end_it,
00436 UFlowCell*, const URegion&, UViewUpdate&);
00437
00438 bool flowFindDataPtr(UContext&, UChildIter data_it, UChildIter end_it,
00439 UFlowCell*, const URegion&, UViewUpdate&);
00440
00441 #endif
00442 };
00443 }
00444 #endif
00445
00446
00447