From 382084bd0a8da947a5b8f7b738b43d688cfc2345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 24 May 2006 00:42:34 +0000 Subject: [PATCH] The return of the long awaited for Sliding Tabs, that even Linux users envy! Needs some cleanup, passed values should be inside [0:1]. Need to make sure changing the title doesn't reset the tab to left. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17571 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/Decorator.h | 4 +++- src/servers/app/DefaultDecorator.cpp | 28 +++++++++++++++++++++++++++- src/servers/app/DefaultDecorator.h | 2 ++ src/servers/app/Desktop.cpp | 20 ++++++++++++++++++++ src/servers/app/Desktop.h | 1 + src/servers/app/WindowLayer.cpp | 19 ++++++++++++++----- src/servers/app/WindowLayer.h | 2 +- 7 files changed, 68 insertions(+), 8 deletions(-) diff --git a/src/servers/app/Decorator.h b/src/servers/app/Decorator.h index a353561259..ccb4066208 100644 --- a/src/servers/app/Decorator.h +++ b/src/servers/app/Decorator.h @@ -95,7 +95,9 @@ class Decorator { void ResizeBy(float x, float y, BRegion* dirty); virtual void ResizeBy(BPoint pt, BRegion* dirty) = 0; - virtual void SetTabLocation(float location) {} + /*! \return true if tab location updated, false if out of bounds or unsupported */ + virtual bool SetTabLocation(float location, BRegion* updateRegion = NULL) + { (void)updateRegion; return false; } virtual float TabLocation() const { return 0.0; } diff --git a/src/servers/app/DefaultDecorator.cpp b/src/servers/app/DefaultDecorator.cpp index 907bdb7d27..760e462d53 100644 --- a/src/servers/app/DefaultDecorator.cpp +++ b/src/servers/app/DefaultDecorator.cpp @@ -337,6 +337,31 @@ DefaultDecorator::ResizeBy(BPoint pt, BRegion* dirty) } } +bool +DefaultDecorator::SetTabLocation(float location, BRegion* updateRegion) +{ + STRACE(("DefaultDecorator: Set Tab Location(%.1f)\n", location)); + if (!_tabrect.IsValid()) + return false; + if (location < 0) + location = 0; + if (location > (fRightBorder.right - fLeftBorder.left - _tabrect.Width())) + location = (fRightBorder.right - fLeftBorder.left - _tabrect.Width()); + float delta = location - fTabOffset; + // redraw old rect (1 pix on the border also must be updated) + BRect trect(_tabrect); + trect.bottom++; + updateRegion->Include(trect); + _tabrect.OffsetBy(delta, 0); + fTabOffset = (int32)location; + _LayoutTabItems(_tabrect); + // redraw new rect as well + trect = _tabrect; + trect.bottom++; + updateRegion->Include(trect); + return true; +} + // Draw void DefaultDecorator::Draw(BRect update) @@ -439,7 +464,8 @@ DefaultDecorator::Clicked(BPoint pt, int32 buttons, int32 modifiers) // Clicking in the tab? if (_tabrect.Contains(pt)) { // tab sliding in any case if either shift key is held down - if (modifiers & B_SHIFT_KEY) + // except sliding up-down by moving mouse left-right would look strange + if ((modifiers & B_SHIFT_KEY) && (fLook != kLeftTitledWindowLook)) return DEC_SLIDETAB; clicked = true; diff --git a/src/servers/app/DefaultDecorator.h b/src/servers/app/DefaultDecorator.h index 0e7222739e..116bb2fdcc 100644 --- a/src/servers/app/DefaultDecorator.h +++ b/src/servers/app/DefaultDecorator.h @@ -29,6 +29,8 @@ class DefaultDecorator: public Decorator { virtual void MoveBy(BPoint pt); virtual void ResizeBy(BPoint pt, BRegion* dirty); + virtual bool SetTabLocation(float location, BRegion* updateRegion = NULL); + virtual float TabLocation() const { return (float)fTabOffset;; } virtual void Draw(BRect r); virtual void Draw(); diff --git a/src/servers/app/Desktop.cpp b/src/servers/app/Desktop.cpp index fdc9603eff..b409839794 100644 --- a/src/servers/app/Desktop.cpp +++ b/src/servers/app/Desktop.cpp @@ -1575,6 +1575,26 @@ Desktop::ResizeWindowBy(WindowLayer* window, float x, float y) UnlockAllWindows(); } +void +Desktop::SetWindowTabLocation(WindowLayer* window, float location) +{ + if (!LockAllWindows()) + return; + + BRegion dirty; + window->SetTabLocation(location, dirty); + + if (window->IsVisible() && dirty.CountRects() > 0) { + BRegion stillAvailableOnScreen; + _RebuildClippingForAllWindows(stillAvailableOnScreen); + _SetBackground(stillAvailableOnScreen); + + _TriggerWindowRedrawing(dirty); + } + + UnlockAllWindows(); +} + /*! Updates the workspaces of all subset windows with regard to the diff --git a/src/servers/app/Desktop.h b/src/servers/app/Desktop.h index 63ea1c8e11..10a7d550f6 100644 --- a/src/servers/app/Desktop.h +++ b/src/servers/app/Desktop.h @@ -111,6 +111,7 @@ class Desktop : public MessageLooper, public ScreenOwner { void MoveWindowBy(WindowLayer* window, float x, float y, int32 workspace = -1); void ResizeWindowBy(WindowLayer* window, float x, float y); + void SetWindowTabLocation(WindowLayer* window, float location); void SetWindowWorkspaces(WindowLayer* window, uint32 workspaces); diff --git a/src/servers/app/WindowLayer.cpp b/src/servers/app/WindowLayer.cpp index 0e60db14b3..bd9ab0793a 100644 --- a/src/servers/app/WindowLayer.cpp +++ b/src/servers/app/WindowLayer.cpp @@ -1006,7 +1006,11 @@ WindowLayer::MouseMoved(BMessage *message, BPoint where, int32* _viewToken, } // sliding tab if (fIsSlidingTab) { - // TODO: implement + float loc = TabLocation(); + // TODO: change to [0:1] + loc += delta.x; + fDesktop->SetWindowTabLocation(this, loc); + delta.y = 0; } // NOTE: fLastMousePosition is currently only @@ -1200,11 +1204,16 @@ WindowLayer::GetSizeLimits(int32* minWidth, int32* maxWidth, } -void -WindowLayer::SetTabLocation(float location) +bool +WindowLayer::SetTabLocation(float location, BRegion& dirty) { - if (fDecorator) - fDecorator->SetTabLocation(location); + bool ret = false; + if (fDecorator) { + ret = fDecorator->SetTabLocation(location, &dirty); + fBorderRegionValid = false; + // the border very likely changed + } + return ret; } diff --git a/src/servers/app/WindowLayer.h b/src/servers/app/WindowLayer.h index 13a25f87b2..c04f7a1a84 100644 --- a/src/servers/app/WindowLayer.h +++ b/src/servers/app/WindowLayer.h @@ -169,7 +169,7 @@ class WindowLayer { int32* minHeight, int32* maxHeight) const; // 0.0 -> left .... 1.0 -> right - void SetTabLocation(float location); + bool SetTabLocation(float location, BRegion& dirty); float TabLocation() const; void HighlightDecorator(bool active);