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