vfs: check userland buffers before reading them.
[haiku.git] / src / servers / app / stackandtile / SATDecorator.cpp
blob62796aa2fadda3b641839845b1c9d38890c0958f
1 /*
2 * Copyright 2010-2015, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Clemens Zeidler <haiku@clemens-zeidler.de>
7 * Ingo Weinhold <ingo_weinhold@gmx.de>
8 */
11 #include "SATDecorator.h"
13 #include <new>
15 #include <GradientLinear.h>
16 #include <WindowPrivate.h>
18 #include "DrawingEngine.h"
19 #include "SATWindow.h"
22 //#define DEBUG_SATDECORATOR
23 #ifdef DEBUG_SATDECORATOR
24 # define STRACE(x) debug_printf x
25 #else
26 # define STRACE(x) ;
27 #endif
30 static const float kResizeKnobSize = 18.0;
33 static const rgb_color kFrameColors[4] = {
34 { 152, 152, 152, 255 },
35 { 240, 240, 240, 255 },
36 { 152, 152, 152, 255 },
37 { 108, 108, 108, 255 }
40 static const rgb_color kHighlightFrameColors[6] = {
41 { 52, 52, 52, 255 },
42 { 140, 140, 140, 255 },
43 { 124, 124, 124, 255 },
44 { 108, 108, 108, 255 },
45 { 52, 52, 52, 255 },
46 { 8, 8, 8, 255 }
49 SATDecorator::SATDecorator(DesktopSettings& settings, BRect frame,
50 Desktop* desktop)
52 DefaultDecorator(settings, frame, desktop)
57 void
58 SATDecorator::UpdateColors(DesktopSettings& settings)
60 DefaultDecorator::UpdateColors(settings);
62 // Called during construction, and during any changes
63 fHighlightTabColor = tint_color(fFocusTabColor, B_DARKEN_2_TINT);
64 fHighlightTabColorLight = tint_color(fHighlightTabColor,
65 (B_LIGHTEN_MAX_TINT + B_LIGHTEN_2_TINT) / 2);
66 fHighlightTabColorBevel = tint_color(fHighlightTabColor, B_LIGHTEN_2_TINT);
67 fHighlightTabColorShadow= tint_color(fHighlightTabColor,
68 (B_DARKEN_1_TINT + B_NO_TINT) / 2);
72 void
73 SATDecorator::GetComponentColors(Component component, uint8 highlight,
74 ComponentColors _colors, Decorator::Tab* _tab)
76 DefaultDecorator::Tab* tab = static_cast<DefaultDecorator::Tab*>(_tab);
78 // Get the standard colors from the DefaultDecorator
79 DefaultDecorator::GetComponentColors(component, highlight, _colors, tab);
81 // Now we need to make some changes if the Stack and tile highlight is used
82 if (highlight != HIGHLIGHT_STACK_AND_TILE)
83 return;
85 if (tab && tab->isHighlighted == false
86 && (component == COMPONENT_TAB || component == COMPONENT_CLOSE_BUTTON
87 || component == COMPONENT_ZOOM_BUTTON)) {
88 return;
91 switch (component) {
92 case COMPONENT_TAB:
93 _colors[COLOR_TAB_FRAME_LIGHT] = kFrameColors[0];
94 _colors[COLOR_TAB_FRAME_DARK] = kFrameColors[3];
95 _colors[COLOR_TAB] = fHighlightTabColor;
96 _colors[COLOR_TAB_LIGHT] = fHighlightTabColorLight;
97 _colors[COLOR_TAB_BEVEL] = fHighlightTabColorBevel;
98 _colors[COLOR_TAB_SHADOW] = fHighlightTabColorShadow;
99 _colors[COLOR_TAB_TEXT] = fFocusTextColor;
100 break;
102 case COMPONENT_CLOSE_BUTTON:
103 case COMPONENT_ZOOM_BUTTON:
104 _colors[COLOR_BUTTON] = fHighlightTabColor;
105 _colors[COLOR_BUTTON_LIGHT] = fHighlightTabColorLight;
106 break;
108 case COMPONENT_LEFT_BORDER:
109 case COMPONENT_RIGHT_BORDER:
110 case COMPONENT_TOP_BORDER:
111 case COMPONENT_BOTTOM_BORDER:
112 case COMPONENT_RESIZE_CORNER:
113 default:
114 _colors[0] = kHighlightFrameColors[0];
115 _colors[1] = kHighlightFrameColors[1];
116 _colors[2] = kHighlightFrameColors[2];
117 _colors[3] = kHighlightFrameColors[3];
118 _colors[4] = kHighlightFrameColors[4];
119 _colors[5] = kHighlightFrameColors[5];
120 break;
125 SATWindowBehaviour::SATWindowBehaviour(Window* window, StackAndTile* sat)
127 DefaultWindowBehaviour(window),
129 fStackAndTile(sat)
134 bool
135 SATWindowBehaviour::AlterDeltaForSnap(Window* window, BPoint& delta,
136 bigtime_t now)
138 if (DefaultWindowBehaviour::AlterDeltaForSnap(window, delta, now) == true)
139 return true;
141 SATWindow* satWindow = fStackAndTile->GetSATWindow(window);
142 if (satWindow == NULL)
143 return false;
144 SATGroup* group = satWindow->GetGroup();
145 if (group == NULL)
146 return false;
148 BRect groupFrame = group->WindowAt(0)->CompleteWindowFrame();
149 for (int32 i = 1; i < group->CountItems(); i++)
150 groupFrame = groupFrame | group->WindowAt(i)->CompleteWindowFrame();
152 return fMagneticBorder.AlterDeltaForSnap(window->Screen(),
153 groupFrame, delta, now);