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