- Fix a TODO: get the border width and tab height directly from the decorator and don't use hard coded values. For example, you can tile tab less windows probably together now.

- Only use min size constraints now. If there is a clash between a window with a max size and another window with a min size the max size is ignored and the size is enlarged if needed. When removing this window from a S&T group the old size limit is restored.
Same is done for none resizeable windows.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39432 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler
2010-11-15 02:54:15 +00:00
parent e206972309
commit f1c707c4a2
5 changed files with 132 additions and 30 deletions
@@ -39,8 +39,6 @@ GroupCookie::GroupCookie(SATWindow* satWindow)
fTopConstraint(NULL),
fMinWidthConstraint(NULL),
fMinHeightConstraint(NULL),
fMaxWidthConstraint(NULL),
fMaxHeightConstraint(NULL),
fWidthConstraint(NULL),
fHeightConstraint(NULL)
{
@@ -94,10 +92,10 @@ GroupCookie::DoGroupLayout(SATWindow* triggerWindow)
}
if (result == OPTIMAL) {
fSATGroup->AdjustWindows(triggerWindow);
_UpdateWindowSize(frame);
break;
}
}
_UpdateWindowSize(frame);
// set penalties back to normal
fWidthConstraint->SetPenaltyNeg(kExtentPenalty);
@@ -138,8 +136,6 @@ GroupCookie::SetSizeLimits(int32 minWidth, int32 maxWidth, int32 minHeight,
{
fMinWidthConstraint->SetRightSide(minWidth);
fMinHeightConstraint->SetRightSide(minHeight);
fMaxWidthConstraint->SetRightSide(maxWidth);
fMaxHeightConstraint->SetRightSide(maxHeight);
}
@@ -172,15 +168,12 @@ GroupCookie::Init(SATGroup* group, WindowArea* area)
OperatorType(EQ), frame.top, 1, 1);
int32 minWidth, maxWidth, minHeight, maxHeight;
fSATWindow->GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight);
fSATWindow->GetSizeLimits(&minWidth, &maxWidth, &minHeight,
&maxHeight);
fMinWidthConstraint = linearSpec->AddConstraint(1.0, fRightBorder, -1.0,
fLeftBorder, OperatorType(GE), minWidth);
fMinHeightConstraint = linearSpec->AddConstraint(1.0, fBottomBorder, -1.0,
fTopBorder, OperatorType(GE), minHeight);
fMaxWidthConstraint = linearSpec->AddConstraint(1.0, fRightBorder, -1.0,
fLeftBorder, OperatorType(LE), maxWidth);
fMaxHeightConstraint = linearSpec->AddConstraint(1.0, fBottomBorder, -1.0,
fTopBorder, OperatorType(LE), maxHeight);
// The width and height constraints have higher penalties than the
// position constraints (left, top), so a window will keep its size
@@ -239,16 +232,12 @@ GroupCookie::Uninit()
delete fTopConstraint;
delete fMinWidthConstraint;
delete fMinHeightConstraint;
delete fMaxWidthConstraint;
delete fMaxHeightConstraint;
delete fWidthConstraint;
delete fHeightConstraint;
fLeftConstraint = NULL;
fTopConstraint = NULL;
fMinWidthConstraint = NULL;
fMinHeightConstraint = NULL;
fMaxWidthConstraint = NULL;
fMaxHeightConstraint = NULL;
fWidthConstraint = NULL;
fHeightConstraint = NULL;
@@ -305,6 +294,11 @@ SATWindow::SATWindow(StackAndTile* sat, Window* window)
fSATSnappingBehaviourList.AddItem(&fSATStacking);
fSATSnappingBehaviourList.AddItem(&fSATTiling);
// read initial limit values
fWindow->GetSizeLimits(&fOriginalMinWidth, &fOriginalMaxWidth,
&fOriginalMinHeight, &fOriginalMaxHeight);
Resized();
}
@@ -320,7 +314,7 @@ SATWindow::~SATWindow()
SATDecorator*
SATWindow::GetDecorator()
SATWindow::GetDecorator() const
{
return static_cast<SATDecorator*>(fWindow->Decorator());
}
@@ -386,6 +380,8 @@ SATWindow::AddedToGroup(SATGroup* group, WindowArea* area)
area->UpdateSizeLimits();
if (group->CountItems() == 2)
group->WindowAt(0)->_UpdateSizeLimits();
return true;
}
@@ -396,6 +392,24 @@ SATWindow::RemovedFromGroup(SATGroup* group)
STRACE_SAT("SATWindow::RemovedFromGroup group: %p window %s\n", group,
fWindow->Title());
fWindow->SetSizeLimits(fOriginalMinWidth, fOriginalMaxWidth,
fOriginalMinHeight, fOriginalMaxHeight);
BRect frame = fWindow->Frame();
float x = 0, y = 0;
if (fWindow->Look() == B_MODAL_WINDOW_LOOK
|| fWindow->Look() == B_BORDERED_WINDOW_LOOK
|| fWindow->Look() == B_NO_BORDER_WINDOW_LOOK
|| (fWindow->Flags() & B_NOT_RESIZABLE) != 0) {
x = fOriginalWidth - frame.Width();
y = fOriginalHeight - frame.Height();
} else {
if ((fWindow->Flags() & B_NOT_H_RESIZABLE) != 0)
x = fOriginalWidth - frame.Width();
if ((fWindow->Flags() & B_NOT_V_RESIZABLE) != 0)
y = fOriginalHeight - frame.Height();
}
fDesktop->ResizeWindowBy(fWindow, x, y);
if (fShutdown) {
fGroupCookie->Uninit();
return true;
@@ -495,7 +509,16 @@ void
SATWindow::SetSizeLimits(int32 minWidth, int32 maxWidth, int32 minHeight,
int32 maxHeight)
{
fGroupCookie->SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
_UpdateSizeLimits();
}
void
SATWindow::Resized()
{
BRect frame = fWindow->Frame();
fOriginalWidth = frame.Width();
fOriginalHeight = frame.Height();
}
@@ -510,11 +533,13 @@ SATWindow::CompleteWindowFrame()
frame.OffsetTo(anchor.position);
}
// TODO get this values from the decorator
frame.left -= 5.;
frame.right += 6.;
frame.top -= 27;
frame.bottom += 5;
SATDecorator* decorator = GetDecorator();
if (!decorator)
return frame;
frame.left -= decorator->BorderWidth();
frame.right += decorator->BorderWidth() + 1;
frame.top -= decorator->BorderWidth() + decorator->TabHeight() + 1;
frame.bottom += decorator->BorderWidth();
return frame;
}
@@ -526,11 +551,13 @@ SATWindow::GetSizeLimits(int32* minWidth, int32* maxWidth, int32* minHeight,
{
fWindow->GetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
// TODO get this values from the decorator
*minWidth += 11;
*minHeight += 32;
*maxWidth += 11;
*maxHeight += 32;
SATDecorator* decorator = GetDecorator();
if (!decorator)
return;
*minWidth += 2 * decorator->BorderWidth() + 1;
*minHeight += 2 * decorator->BorderWidth() + decorator->TabHeight() + 1;
*maxWidth += 2 * decorator->BorderWidth() + 1;
*maxHeight += 2 * decorator->BorderWidth() + decorator->TabHeight() + 1;
}
@@ -665,3 +692,49 @@ SATWindow::_InitGroup()
if (!groupRef->AddWindow(this, NULL, NULL, NULL, NULL))
STRACE_SAT("SATWindow::_InitGroup(): adding window to group failed\n");
}
void
SATWindow::_UpdateSizeLimits()
{
int32 minWidth, minHeight;
int32 maxWidth, maxHeight;
fWindow->GetSizeLimits(&fOriginalMinWidth, &maxWidth,
&fOriginalMinHeight, &maxHeight);
minWidth = fOriginalMinWidth;
minHeight = fOriginalMinHeight;
if (maxWidth != B_SIZE_UNLIMITED)
fOriginalMaxWidth = maxWidth;
if (maxHeight != B_SIZE_UNLIMITED)
fOriginalMaxHeight = maxHeight;
SATDecorator* decorator = GetDecorator();
// if no size limit is set but the window is not resizeable choose the
// current size as limit
if (fWindow->Look() == B_MODAL_WINDOW_LOOK
|| fWindow->Look() == B_BORDERED_WINDOW_LOOK
|| fWindow->Look() == B_NO_BORDER_WINDOW_LOOK
|| (fWindow->Flags() & B_NOT_RESIZABLE) != 0
|| (fWindow->Flags() & B_NOT_H_RESIZABLE) != 0
|| (fWindow->Flags() & B_NOT_V_RESIZABLE) != 0) {
int32 minDecorWidth = 1, maxDecorWidth = 1;
int32 minDecorHeight = 1, maxDecorHeight = 1;
if (decorator)
decorator->GetSizeLimits(&minDecorWidth, &minDecorHeight,
&maxDecorWidth, &maxDecorHeight);
BRect frame = fWindow->Frame();
if (fOriginalMinWidth <= minDecorWidth)
minWidth = frame.Width();
if (fOriginalMinHeight <= minDecorHeight)
minHeight = frame.Height();
}
fWindow->SetSizeLimits(minWidth, B_SIZE_UNLIMITED,
minHeight, B_SIZE_UNLIMITED);
if (decorator) {
minWidth += 2 * decorator->BorderWidth();
minHeight += 2 * decorator->BorderWidth() + decorator->TabHeight() + 1;
}
fGroupCookie->SetSizeLimits(minWidth, B_SIZE_UNLIMITED, minHeight,
B_SIZE_UNLIMITED);
}
@@ -65,8 +65,6 @@ private:
Constraint* fTopConstraint;
Constraint* fMinWidthConstraint;
Constraint* fMinHeightConstraint;
Constraint* fMaxWidthConstraint;
Constraint* fMaxHeightConstraint;
Constraint* fWidthConstraint;
Constraint* fHeightConstraint;
};
@@ -78,7 +76,7 @@ public:
~SATWindow();
Window* GetWindow() { return fWindow; }
SATDecorator* GetDecorator();
SATDecorator* GetDecorator() const;
StackAndTile* GetStackAndTile() { return fStackAndTile; }
Desktop* GetDesktop() { return fDesktop; }
//! Can be NULL if memory allocation failed!
@@ -109,6 +107,8 @@ public:
void SetSizeLimits(int32 minWidth, int32 maxWidth,
int32 minHeight, int32 maxHeight);
// hook called when window has been resized form the outside
void Resized();
//! \return the complete window frame including the Decorator
BRect CompleteWindowFrame();
@@ -130,6 +130,7 @@ public:
private:
void _InitGroup();
void _UpdateSizeLimits();
Window* fWindow;
StackAndTile* fStackAndTile;
@@ -149,6 +150,14 @@ private:
SATSnappingBehaviourList fSATSnappingBehaviourList;
bool fShutdown;
int32 fOriginalMinWidth;
int32 fOriginalMaxWidth;
int32 fOriginalMinHeight;
int32 fOriginalMaxHeight;
float fOriginalWidth;
float fOriginalHeight;
};
@@ -189,13 +189,14 @@ StackAndTile::WindowResized(Window* window)
SATWindow* satWindow = GetSATWindow(window);
if (!satWindow)
return;
satWindow->Resized();
if (SATKeyPressed() && fCurrentSATWindow)
satWindow->FindSnappingCandidates();
else {
satWindow->DoGroupLayout();
// Do a window layout for all windows. TODO: mybe do it a bit more
// Do a window layout for all windows. TODO: maybe do it a bit more
// efficient
SATGroup* group = satWindow->GetGroup();
if (!group)
+16
View File
@@ -247,6 +247,22 @@ DefaultDecorator::MouseAction(const BMessage* message, BPoint point,
}
float
DefaultDecorator::BorderWidth()
{
return fBorderWidth;
}
float
DefaultDecorator::TabHeight()
{
if (fTabRect.IsValid())
return fTabRect.Height();
return BorderWidth();
}
void
DefaultDecorator::_DoLayout()
{
+3
View File
@@ -41,6 +41,9 @@ public:
BPoint point, int32 buttons,
int32 modifiers);
float BorderWidth();
float TabHeight();
protected:
virtual void _DoLayout();