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