vfs: check userland buffers before reading them.
[haiku.git] / src / servers / app / decorator / Decorator.h
blob44440a83cafb69add5af3f0860a30fb754dfd524
1 /*
2 * Copyright 2001-2015 Haiku, Inc.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus, superstippi@gmx.de
7 * DarkWyrm, bpmagic@columbus.rr.com
8 * John Scipione, jscipione@gmail.com
9 * Ingo Weinhold, ingo_weinhold@gmx.de
10 * Clemens Zeidler, haiku@clemens-zeidler.de
11 * Joseph Groover <looncraz@looncraz.net>
13 #ifndef DECORATOR_H
14 #define DECORATOR_H
17 #include <Rect.h>
18 #include <Region.h>
19 #include <String.h>
20 #include <Window.h>
22 #include "DrawState.h"
24 class Desktop;
25 class DesktopSettings;
26 class DrawingEngine;
27 class ServerBitmap;
28 class ServerFont;
29 class BRegion;
32 class Decorator {
33 public:
34 struct Tab {
35 Tab();
36 virtual ~Tab() {}
38 BRect tabRect;
40 BRect zoomRect;
41 BRect closeRect;
42 BRect minimizeRect;
44 bool closePressed : 1;
45 bool zoomPressed : 1;
46 bool minimizePressed : 1;
48 window_look look;
49 uint32 flags;
50 bool isFocused : 1;
52 BString title;
54 uint32 tabOffset;
55 float tabLocation;
56 float textOffset;
58 BString truncatedTitle;
59 int32 truncatedTitleLength;
61 bool buttonFocus : 1;
63 bool isHighlighted : 1;
65 float minTabSize;
66 float maxTabSize;
68 ServerBitmap* closeBitmaps[4];
69 ServerBitmap* minimizeBitmaps[4];
70 ServerBitmap* zoomBitmaps[4];
73 enum Region {
74 REGION_NONE,
76 REGION_TAB,
78 REGION_CLOSE_BUTTON,
79 REGION_ZOOM_BUTTON,
80 REGION_MINIMIZE_BUTTON,
82 REGION_LEFT_BORDER,
83 REGION_RIGHT_BORDER,
84 REGION_TOP_BORDER,
85 REGION_BOTTOM_BORDER,
87 REGION_LEFT_TOP_CORNER,
88 REGION_LEFT_BOTTOM_CORNER,
89 REGION_RIGHT_TOP_CORNER,
90 REGION_RIGHT_BOTTOM_CORNER,
92 REGION_COUNT
95 enum {
96 HIGHLIGHT_NONE,
97 HIGHLIGHT_RESIZE_BORDER,
99 HIGHLIGHT_USER_DEFINED
102 Decorator(DesktopSettings& settings,
103 BRect frame,
104 Desktop* desktop);
105 virtual ~Decorator();
107 virtual Decorator::Tab* AddTab(DesktopSettings& settings,
108 const char* title, window_look look,
109 uint32 flags, int32 index = -1,
110 BRegion* updateRegion = NULL);
111 virtual bool RemoveTab(int32 index,
112 BRegion* updateRegion = NULL);
113 virtual bool MoveTab(int32 from, int32 to, bool isMoving,
114 BRegion* updateRegion = NULL);
116 virtual int32 TabAt(const BPoint& where) const;
117 Decorator::Tab* TabAt(int32 index) const
118 { return fTabList.ItemAt(index); }
119 int32 CountTabs() const
120 { return fTabList.CountItems(); }
121 void SetTopTab(int32 tab);
123 void SetDrawingEngine(DrawingEngine *driver);
124 inline DrawingEngine* GetDrawingEngine() const
125 { return fDrawingEngine; }
127 void FontsChanged(DesktopSettings& settings,
128 BRegion* updateRegion = NULL);
129 void ColorsChanged(DesktopSettings& settings,
130 BRegion* updateRegion = NULL);
132 virtual void UpdateColors(DesktopSettings& settings) = 0;
134 void SetLook(int32 tab, DesktopSettings& settings,
135 window_look look,
136 BRegion* updateRegion = NULL);
137 void SetFlags(int32 tab, uint32 flags,
138 BRegion* updateRegion = NULL);
140 window_look Look(int32 tab) const;
141 uint32 Flags(int32 tab) const;
143 BRect BorderRect() const;
144 BRect TitleBarRect() const;
145 BRect TabRect(int32 tab) const;
146 BRect TabRect(Decorator::Tab* tab) const;
148 void SetClose(int32 tab, bool pressed);
149 void SetMinimize(int32 tab, bool pressed);
150 void SetZoom(int32 tab, bool pressed);
152 const char* Title(int32 tab) const;
153 const char* Title(Decorator::Tab* tab) const;
154 void SetTitle(int32 tab, const char* string,
155 BRegion* updateRegion = NULL);
157 void SetFocus(int32 tab, bool focussed);
158 bool IsFocus(int32 tab) const;
159 bool IsFocus(Decorator::Tab* tab) const;
161 virtual float TabLocation(int32 tab) const;
162 bool SetTabLocation(int32 tab, float location,
163 bool isShifting,
164 BRegion* updateRegion = NULL);
165 /*! \return true if tab location updated, false if out of
166 bounds or unsupported */
168 virtual Region RegionAt(BPoint where, int32& tab) const;
170 const BRegion& GetFootprint();
171 ::Desktop* GetDesktop();
173 void MoveBy(float x, float y);
174 void MoveBy(BPoint offset);
175 void ResizeBy(float x, float y, BRegion* dirty);
176 void ResizeBy(BPoint offset, BRegion* dirty);
178 virtual bool SetRegionHighlight(Region region,
179 uint8 highlight, BRegion* dirty,
180 int32 tab = -1);
181 inline uint8 RegionHighlight(Region region,
182 int32 tab = -1) const;
184 bool SetSettings(const BMessage& settings,
185 BRegion* updateRegion = NULL);
186 virtual bool GetSettings(BMessage* settings) const;
188 virtual void GetSizeLimits(int32* minWidth, int32* minHeight,
189 int32* maxWidth, int32* maxHeight) const;
190 virtual void ExtendDirtyRegion(Region region, BRegion& dirty);
192 virtual void Draw(BRect updateRect) = 0;
193 virtual void Draw() = 0;
195 virtual void DrawTab(int32 tab);
196 virtual void DrawTitle(int32 tab);
198 virtual void DrawClose(int32 tab);
199 virtual void DrawMinimize(int32 tab);
200 virtual void DrawZoom(int32 tab);
202 rgb_color UIColor(color_which which);
204 float BorderWidth();
205 float TabHeight();
207 protected:
208 virtual Decorator::Tab* _AllocateNewTab();
210 virtual void _DoLayout() = 0;
211 //! method for calculating layout for the decorator
213 virtual void _DrawFrame(BRect rect) = 0;
214 virtual void _DrawTabs(BRect rect);
216 virtual void _DrawTab(Decorator::Tab* tab, BRect rect) = 0;
217 virtual void _DrawTitle(Decorator::Tab* tab,
218 BRect rect) = 0;
220 virtual void _DrawButtons(Decorator::Tab* tab,
221 const BRect& invalid) = 0;
222 virtual void _DrawClose(Decorator::Tab* tab, bool direct,
223 BRect rect) = 0;
224 virtual void _DrawMinimize(Decorator::Tab* tab, bool direct,
225 BRect rect) = 0;
226 virtual void _DrawZoom(Decorator::Tab* tab, bool direct,
227 BRect rect) = 0;
229 virtual void _SetTitle(Decorator::Tab* tab,
230 const char* string,
231 BRegion* updateRegion = NULL) = 0;
232 int32 _TitleWidth(Decorator::Tab* tab) const
233 { return tab->title.CountChars(); }
235 virtual void _SetFocus(Decorator::Tab* tab);
236 virtual bool _SetTabLocation(Decorator::Tab* tab,
237 float location, bool isShifting,
238 BRegion* updateRegion = NULL);
240 virtual Decorator::Tab* _TabAt(int32 index) const;
242 virtual void _FontsChanged(DesktopSettings& settings,
243 BRegion* updateRegion = NULL);
244 virtual void _UpdateFont(DesktopSettings& settings) = 0;
246 virtual void _SetLook(Decorator::Tab* tab,
247 DesktopSettings& settings,
248 window_look look,
249 BRegion* updateRegion = NULL);
250 virtual void _SetFlags(Decorator::Tab* tab, uint32 flags,
251 BRegion* updateRegion = NULL);
253 virtual void _MoveBy(BPoint offset);
254 virtual void _ResizeBy(BPoint offset, BRegion* dirty) = 0;
256 virtual bool _SetSettings(const BMessage& settings,
257 BRegion* updateRegion = NULL);
259 virtual bool _AddTab(DesktopSettings& settings,
260 int32 index = -1,
261 BRegion* updateRegion = NULL) = 0;
262 virtual bool _RemoveTab(int32 index,
263 BRegion* updateRegion = NULL) = 0;
264 virtual bool _MoveTab(int32 from, int32 to, bool isMoving,
265 BRegion* updateRegion = NULL) = 0;
267 virtual void _GetFootprint(BRegion *region);
268 void _InvalidateFootprint();
270 void _InvalidateBitmaps();
272 DrawingEngine* fDrawingEngine;
273 DrawState fDrawState;
275 // Individual rects for handling window frame
276 // rendering the proper way
277 BRect fTitleBarRect;
278 BRect fFrame;
279 BRect fResizeRect;
280 BRect fBorderRect;
282 BRect fLeftBorder;
283 BRect fTopBorder;
284 BRect fBottomBorder;
285 BRect fRightBorder;
287 int32 fBorderWidth;
289 Decorator::Tab* fTopTab;
290 BObjectList<Decorator::Tab> fTabList;
292 private:
293 Desktop* fDesktop;
294 BRegion fFootprint;
295 bool fFootprintValid : 1;
297 uint8 fRegionHighlights[REGION_COUNT - 1];
301 uint8
302 Decorator::RegionHighlight(Region region, int32 tab) const
304 int32 index = (int32)region - 1;
305 return index >= 0 && index < REGION_COUNT - 1
306 ? fRegionHighlights[index] : 0;
310 #endif // DECORATOR_H