1 /* 2 * Copyright (c) 2001-2008, Haiku, Inc. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * DarkWyrm <bpmagic@columbus.rr.com> 7 * Adi Oanca <adioanca@gmail.com> 8 * Axel Dörfler, axeld@pinc-software.de 9 * Stephan Aßmus <superstippi@gmx.de> 10 * Marcus Overhagen <marcus@overhagen.de> 11 */ 12 #ifndef VIEW_H 13 #define VIEW_H 14 15 16 #include "IntRect.h" 17 18 #include <GraphicsDefs.h> 19 #include <ObjectList.h> 20 #include <Region.h> 21 #include <String.h> 22 23 class BList; 24 class BMessage; 25 26 namespace BPrivate { 27 class PortLink; 28 }; 29 30 class DrawState; 31 class DrawingEngine; 32 class Overlay; 33 class Window; 34 class ServerBitmap; 35 class ServerCursor; 36 class ServerPicture; 37 class BGradient; 38 39 class View { 40 public: 41 View(IntRect frame, IntPoint scrollingOffset, 42 const char* name, int32 token, 43 uint32 resizeMode, uint32 flags); 44 virtual ~View(); 45 46 int32 Token() const 47 { return fToken; } 48 49 IntRect Frame() const 50 { return fFrame; } 51 IntRect Bounds() const; 52 53 void SetResizeMode(uint32 resizeMode) 54 { fResizeMode = resizeMode; } 55 56 void SetName(const char* string); 57 const char* Name() const 58 { return fName.String(); } 59 60 void SetFlags(uint32 flags); 61 uint32 Flags() const 62 { return fFlags; } 63 64 inline IntPoint ScrollingOffset() const 65 { return fScrollingOffset; } 66 67 void SetDrawingOrigin(BPoint origin); 68 BPoint DrawingOrigin() const; 69 70 void SetScale(float scale); 71 float Scale() const; 72 73 void SetUserClipping(const BRegion* region); 74 // region is expected in view coordinates 75 76 // converts the given frame up the view hierarchy and 77 // clips to each views bounds 78 void ConvertToVisibleInTopView(IntRect* bounds) const; 79 80 virtual void AttachedToWindow(::Window* window); 81 virtual void DetachedFromWindow(); 82 ::Window* Window() const { return fWindow; } 83 84 // tree stuff 85 void AddChild(View* view); 86 bool RemoveChild(View* view); 87 88 inline View* Parent() const 89 { return fParent; } 90 91 inline View* FirstChild() const 92 { return fFirstChild; } 93 inline View* LastChild() const 94 { return fLastChild; } 95 inline View* PreviousSibling() const 96 { return fPreviousSibling; } 97 inline View* NextSibling() const 98 { return fNextSibling; } 99 100 View* TopView(); 101 102 uint32 CountChildren(bool deep = false) const; 103 void CollectTokensForChildren(BList* tokenMap) const; 104 void FindViews(uint32 flags, BObjectList<View>& list, 105 int32& left); 106 107 View* ViewAt(const BPoint& where); 108 109 // coordinate conversion 110 void ConvertToParent(BPoint* point) const; 111 void ConvertToParent(IntPoint* point) const; 112 void ConvertToParent(BRect* rect) const; 113 void ConvertToParent(IntRect* rect) const; 114 void ConvertToParent(BRegion* region) const; 115 116 void ConvertFromParent(BPoint* point) const; 117 void ConvertFromParent(IntPoint* point) const; 118 void ConvertFromParent(BRect* rect) const; 119 void ConvertFromParent(IntRect* rect) const; 120 void ConvertFromParent(BRegion* region) const; 121 122 void ConvertToScreen(BPoint* point) const; 123 void ConvertToScreen(IntPoint* point) const; 124 void ConvertToScreen(BRect* rect) const; 125 void ConvertToScreen(IntRect* rect) const; 126 void ConvertToScreen(BRegion* region) const; 127 128 void ConvertFromScreen(BPoint* point) const; 129 void ConvertFromScreen(IntPoint* point) const; 130 void ConvertFromScreen(BRect* rect) const; 131 void ConvertFromScreen(IntRect* rect) const; 132 void ConvertFromScreen(BRegion* region) const; 133 134 void ConvertToScreenForDrawing(BPoint* point) const; 135 void ConvertToScreenForDrawing(BRect* rect) const; 136 void ConvertToScreenForDrawing(BRegion* region) const; 137 void ConvertToScreenForDrawing(BGradient* gradient) const; 138 139 void ConvertToScreenForDrawing(BPoint* dst, const BPoint* src, int32 num) const; 140 void ConvertToScreenForDrawing(BRect* dst, const BRect* src, int32 num) const; 141 void ConvertToScreenForDrawing(BRegion* dst, const BRegion* src, int32 num) const; 142 143 void ConvertFromScreenForDrawing(BPoint* point) const; 144 // used when updating the pen position 145 146 void MoveBy(int32 dx, int32 dy, 147 BRegion* dirtyRegion); 148 149 void ResizeBy(int32 dx, int32 dy, 150 BRegion* dirtyRegion); 151 152 void ScrollBy(int32 dx, int32 dy, 153 BRegion* dirtyRegion); 154 155 void ParentResized(int32 dx, int32 dy, 156 BRegion* dirtyRegion); 157 158 void CopyBits(IntRect src, IntRect dst, 159 BRegion& windowContentClipping); 160 161 const BRegion& LocalClipping() const { return fLocalClipping; } 162 163 const rgb_color& ViewColor() const 164 { return fViewColor; } 165 void SetViewColor(const rgb_color& color) 166 { fViewColor = color; } 167 168 ServerBitmap* ViewBitmap() const 169 { return fViewBitmap; } 170 void SetViewBitmap(ServerBitmap* bitmap, 171 IntRect sourceRect, IntRect destRect, 172 int32 resizingMode, int32 options); 173 174 void PushState(); 175 void PopState(); 176 DrawState* CurrentState() const { return fDrawState; } 177 178 void SetEventMask(uint32 eventMask, uint32 options); 179 uint32 EventMask() const 180 { return fEventMask; } 181 uint32 EventOptions() const 182 { return fEventOptions; } 183 184 void SetCursor(ServerCursor* cursor); 185 ServerCursor* Cursor() const { return fCursor; } 186 187 void SetPicture(ServerPicture* picture); 188 ServerPicture* Picture() const 189 { return fPicture; } 190 191 // for background clearing 192 virtual void Draw(DrawingEngine* drawingEngine, 193 BRegion* effectiveClipping, 194 BRegion* windowContentClipping, 195 bool deep = false); 196 197 virtual void MouseDown(BMessage* message, BPoint where); 198 virtual void MouseUp(BMessage* message, BPoint where); 199 virtual void MouseMoved(BMessage* message, BPoint where); 200 201 void SetHidden(bool hidden); 202 bool IsHidden() const; 203 204 // takes into account parent views hidden status 205 bool IsVisible() const 206 { return fVisible; } 207 // update visible status for this view and all children 208 // according to the parents visibility 209 void UpdateVisibleDeep(bool parentVisible); 210 211 void UpdateOverlay(); 212 213 void MarkBackgroundDirty(); 214 bool IsBackgroundDirty() const 215 { return fBackgroundDirty; } 216 217 bool IsDesktopBackground() const 218 { return fIsDesktopBackground; } 219 220 void AddTokensForViewsInRegion(BPrivate::PortLink& link, 221 BRegion& region, 222 BRegion* windowContentClipping); 223 224 // clipping 225 void RebuildClipping(bool deep); 226 BRegion& ScreenAndUserClipping( 227 BRegion* windowContentClipping, 228 bool force = false) const; 229 void InvalidateScreenClipping(); 230 inline bool IsScreenClippingValid() const 231 { 232 return fScreenClippingValid 233 && (fUserClipping == NULL 234 || (fUserClipping != NULL 235 && fScreenAndUserClipping != NULL)); 236 } 237 238 // debugging 239 void PrintToStream() const; 240 #if 0 241 bool MarkAt(DrawingEngine* engine, const BPoint& where, 242 int32 level = 0); 243 #endif 244 245 protected: 246 BRegion& _ScreenClipping(BRegion* windowContentClipping, 247 bool force = false) const; 248 void _MoveScreenClipping(int32 x, int32 y, 249 bool deep); 250 Overlay* _Overlay() const; 251 void _UpdateOverlayView() const; 252 253 BString fName; 254 int32 fToken; 255 // area within parent coordinate space 256 IntRect fFrame; 257 // offset of the local area (bounds) 258 IntPoint fScrollingOffset; 259 260 rgb_color fViewColor; 261 DrawState* fDrawState; 262 ServerBitmap* fViewBitmap; 263 IntRect fBitmapSource; 264 IntRect fBitmapDestination; 265 int32 fBitmapResizingMode; 266 int32 fBitmapOptions; 267 268 uint32 fResizeMode; 269 uint32 fFlags; 270 bool fHidden : 1; 271 bool fVisible : 1; 272 bool fBackgroundDirty : 1; 273 bool fIsDesktopBackground : 1; 274 275 uint32 fEventMask; 276 uint32 fEventOptions; 277 278 ::Window* fWindow; 279 View* fParent; 280 281 View* fFirstChild; 282 View* fPreviousSibling; 283 View* fNextSibling; 284 View* fLastChild; 285 286 ServerCursor* fCursor; 287 ServerPicture* fPicture; 288 289 // clipping 290 BRegion fLocalClipping; 291 292 mutable BRegion fScreenClipping; 293 mutable bool fScreenClippingValid; 294 295 BRegion* fUserClipping; 296 mutable BRegion* fScreenAndUserClipping; 297 }; 298 299 #endif // VIEW_H 300