From 14fb2b690b730b18aaec3aa798134d71e540ca74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 7 Mar 2006 15:23:35 +0000 Subject: [PATCH] * A double click on the window border now minimizes the window - has a fixed double click time, though. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16631 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/DefaultDecorator.cpp | 56 +++++++++------ src/servers/app/DefaultDecorator.h | 103 ++++++++++++++------------- src/servers/app/WindowLayer.cpp | 41 +++++------ 3 files changed, 105 insertions(+), 95 deletions(-) diff --git a/src/servers/app/DefaultDecorator.cpp b/src/servers/app/DefaultDecorator.cpp index 3e73ee5f56..fe4f65da19 100644 --- a/src/servers/app/DefaultDecorator.cpp +++ b/src/servers/app/DefaultDecorator.cpp @@ -39,8 +39,9 @@ DefaultDecorator::DefaultDecorator(DesktopSettings& settings, BRect rect, - window_look look, uint32 flags) - : Decorator(settings, rect, look, flags) + window_look look, uint32 flags) + : Decorator(settings, rect, look, flags), + fLastClicked(0) { DefaultDecorator::SetLook(settings, look); @@ -358,6 +359,13 @@ DefaultDecorator::Clicked(BPoint pt, int32 buttons, int32 modifiers) printf("\tButtons: %ld, Modifiers: 0x%lx\n", buttons, modifiers); #endif // DEBUG_DECORATOR + // TODO: have a real double-click mechanism, ie. take user settings into account + bigtime_t now = system_time(); + if (buttons != 0) { + fWasDoubleClick = now - fLastClicked < 200000; + fLastClicked = now; + } + // In checking for hit test stuff, we start with the smallest rectangles the user might // be clicking on and gradually work our way out into larger rectangles. if (!(fFlags & B_NOT_CLOSABLE) && _closerect.Contains(pt)) @@ -369,20 +377,19 @@ DefaultDecorator::Clicked(BPoint pt, int32 buttons, int32 modifiers) if (fLook == B_DOCUMENT_WINDOW_LOOK && _resizerect.Contains(pt)) return DEC_RESIZE; + bool clicked = false; + // 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) return DEC_SLIDETAB; - // Here's part of our window management stuff - if (buttons == B_SECONDARY_MOUSE_BUTTON) - return DEC_MOVETOBACK; - return DEC_DRAG; - } - // We got this far, so user is clicking on the border? - if (fLeftBorder.Contains(pt) || fRightBorder.Contains(pt) + clicked = true; + } else if (fLeftBorder.Contains(pt) || fRightBorder.Contains(pt) || fTopBorder.Contains(pt) || fBottomBorder.Contains(pt)) { + // Clicked on border + // check resize area if (!(fFlags & B_NOT_RESIZABLE) && (fLook == B_TITLED_WINDOW_LOOK @@ -394,11 +401,18 @@ DefaultDecorator::Clicked(BPoint pt, int32 buttons, int32 modifiers) return DEC_RESIZE; } - // NOTE: On R5, windows are not moved to back if clicked inside the resize area with - // the second mouse button. So we check this after the check above + clicked = true; + } + + if (clicked) { + // NOTE: On R5, windows are not moved to back if clicked inside the resize area + // with the second mouse button. So we check this after the check above if (buttons == B_SECONDARY_MOUSE_BUTTON) return DEC_MOVETOBACK; + if (fWasDoubleClick) + return DEC_MINIMIZE; + return DEC_DRAG; } @@ -750,7 +764,7 @@ DefaultDecorator::_DrawClose(BRect r) { STRACE(("_DrawClose(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom)); // Just like DrawZoom, but for a close button - _DrawBlendedRect( r, GetClose()); + _DrawBlendedRect(r, GetClose()); } // _DrawTitle @@ -835,14 +849,14 @@ DefaultDecorator::_SetColors() _SetFocus(); } -// _DrawBlendedRect + +/*! + \brief Draws a framed rectangle with a gradient. + \param down The rectangle should be drawn recessed or not +*/ void DefaultDecorator::_DrawBlendedRect(BRect r, bool down) { - // This bad boy is used to draw a rectangle with a gradient. - // Note that it is not part of the Decorator API - it's specific - // to just the BeDecorator. Called by DrawZoom and DrawClose - // Actually just draws a blended square int32 w = r.IntegerWidth(); int32 h = r.IntegerHeight(); @@ -854,11 +868,11 @@ DefaultDecorator::_DrawBlendedRect(BRect r, bool down) int steps = (w < h) ? w : h; if (down) { - startcol = fButtonLowColor.GetColor32(); - endcol = fButtonHighColor.GetColor32(); + startcol = fButtonLowColor.GetColor32(); + endcol = fButtonHighColor.GetColor32(); } else { - startcol = fButtonHighColor.GetColor32(); - endcol = fButtonLowColor.GetColor32(); + startcol = fButtonHighColor.GetColor32(); + endcol = fButtonLowColor.GetColor32(); } halfcol = MakeBlendColor(startcol,endcol,0.5); diff --git a/src/servers/app/DefaultDecorator.h b/src/servers/app/DefaultDecorator.h index 46f6c8fbf4..2d9cadbbc3 100644 --- a/src/servers/app/DefaultDecorator.h +++ b/src/servers/app/DefaultDecorator.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005, Haiku. + * Copyright 2001-2006, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -17,72 +17,75 @@ class Desktop; class DefaultDecorator: public Decorator { -public: - DefaultDecorator(DesktopSettings& settings, BRect frame, - window_look look, uint32 flags); - virtual ~DefaultDecorator(); + public: + DefaultDecorator(DesktopSettings& settings, BRect frame, + window_look look, uint32 flags); + virtual ~DefaultDecorator(); - virtual void SetTitle(const char* string, BRegion* updateRegion = NULL); - virtual void SetLook(DesktopSettings& settings, - window_look look, BRegion* updateRegion = NULL); - virtual void SetFlags(uint32 flags, BRegion* updateRegion = NULL); + virtual void SetTitle(const char* string, BRegion* updateRegion = NULL); + virtual void SetLook(DesktopSettings& settings, + window_look look, BRegion* updateRegion = NULL); + virtual void SetFlags(uint32 flags, BRegion* updateRegion = NULL); - virtual void MoveBy(BPoint pt); - virtual void ResizeBy(BPoint pt, BRegion* dirty); + virtual void MoveBy(BPoint pt); + virtual void ResizeBy(BPoint pt, BRegion* dirty); - virtual void Draw(BRect r); - virtual void Draw(); + virtual void Draw(BRect r); + virtual void Draw(); - virtual void GetSizeLimits(int32* minWidth, int32* minHeight, - int32* maxWidth, int32* maxHeight) const; + virtual void GetSizeLimits(int32* minWidth, int32* minHeight, + int32* maxWidth, int32* maxHeight) const; - virtual void GetFootprint(BRegion *region); + virtual void GetFootprint(BRegion *region); - virtual click_type Clicked(BPoint pt, int32 buttons, - int32 modifiers); + virtual click_type Clicked(BPoint pt, int32 buttons, + int32 modifiers); -protected: - virtual void _DoLayout(); + protected: + virtual void _DoLayout(); - virtual void _DrawFrame(BRect r); - virtual void _DrawTab(BRect r); + virtual void _DrawFrame(BRect r); + virtual void _DrawTab(BRect r); - virtual void _DrawClose(BRect r); - virtual void _DrawTitle(BRect r); - virtual void _DrawZoom(BRect r); + virtual void _DrawClose(BRect r); + virtual void _DrawTitle(BRect r); + virtual void _DrawZoom(BRect r); - virtual void _SetFocus(); - virtual void _SetColors(); + virtual void _SetFocus(); + virtual void _SetColors(); -private: - void _DrawBlendedRect(BRect r, bool down); - void _GetButtonSizeAndOffset(const BRect& tabRect, + private: + void _DrawBlendedRect(BRect r, bool down); + void _GetButtonSizeAndOffset(const BRect& tabRect, float* offset, float*size) const; - void _LayoutTabItems(const BRect& tabRect); + void _LayoutTabItems(const BRect& tabRect); - RGBColor fButtonHighColor; - RGBColor fButtonLowColor; - RGBColor fTextColor; - RGBColor fTabColor; + RGBColor fButtonHighColor; + RGBColor fButtonLowColor; + RGBColor fTextColor; + RGBColor fTabColor; - RGBColor* fFrameColors; - - // Individual rects for handling window frame - // rendering the proper way - BRect fRightBorder; - BRect fLeftBorder; - BRect fTopBorder; - BRect fBottomBorder; + RGBColor* fFrameColors; - int32 fBorderWidth; + // Individual rects for handling window frame + // rendering the proper way + BRect fRightBorder; + BRect fLeftBorder; + BRect fTopBorder; + BRect fBottomBorder; - uint32 fTabOffset; - float fTextOffset; + int32 fBorderWidth; - float fMinTabWidth; - float fMaxTabWidth; - BString fTruncatedTitle; - int32 fTruncatedTitleLength; + uint32 fTabOffset; + float fTextOffset; + + float fMinTabWidth; + float fMaxTabWidth; + BString fTruncatedTitle; + int32 fTruncatedTitleLength; + + bigtime_t fLastClicked; + bool fWasDoubleClick; }; #endif /* DEFAULT_DECORATOR_H */ diff --git a/src/servers/app/WindowLayer.cpp b/src/servers/app/WindowLayer.cpp index 07d9ff14c8..06832cdf98 100644 --- a/src/servers/app/WindowLayer.cpp +++ b/src/servers/app/WindowLayer.cpp @@ -756,19 +756,16 @@ WindowLayer::MouseDown(BMessage* message, BPoint where, int32* _viewToken) switch (action) { case DEC_CLOSE: fIsClosing = true; - fDecorator->SetClose(true); STRACE_CLICK(("===> DEC_CLOSE\n")); break; case DEC_ZOOM: fIsZooming = true; - fDecorator->SetZoom(true); STRACE_CLICK(("===> DEC_ZOOM\n")); break; case DEC_MINIMIZE: fIsMinimizing = true; - fDecorator->SetMinimize(true); STRACE_CLICK(("===> DEC_MINIMIZE\n")); break; @@ -794,7 +791,7 @@ WindowLayer::MouseDown(BMessage* message, BPoint where, int32* _viewToken) break; } - // redraw decoratpr + // redraw decorator BRegion visibleBorder; GetBorderRegion(&visibleBorder); visibleBorder.IntersectWith(&VisibleRegion()); @@ -805,7 +802,7 @@ WindowLayer::MouseDown(BMessage* message, BPoint where, int32* _viewToken) if (fIsZooming) { fDecorator->SetZoom(true); } else if (fIsClosing) { - fDecorator->SetClose(true); + //fDecorator->SetClose(true); } else if (fIsMinimizing) { fDecorator->SetMinimize(true); } @@ -855,7 +852,7 @@ WindowLayer::MouseUp(BMessage* msg, BPoint where, int32* _viewToken) if (fDecorator) { click_type action = _ActionFor(msg); - // redraw decoratpr + // redraw decorator BRegion visibleBorder; GetBorderRegion(&visibleBorder); visibleBorder.IntersectWith(&VisibleRegion()); @@ -863,14 +860,6 @@ WindowLayer::MouseUp(BMessage* msg, BPoint where, int32* _viewToken) fDrawingEngine->Lock(); fDrawingEngine->ConstrainClippingRegion(&visibleBorder); - if (fIsZooming) { - fDecorator->SetZoom(true); - } else if (fIsClosing) { - fDecorator->SetClose(true); - } else if (fIsMinimizing) { - fDecorator->SetMinimize(true); - } - if (fIsZooming) { fIsZooming = false; fDecorator->SetZoom(false); @@ -1853,21 +1842,25 @@ WindowLayer::_UpdateContentRegion() click_type WindowLayer::_ActionFor(const BMessage* msg) const { - BPoint where(0, 0); - int32 buttons = 0; - int32 modifiers = 0; + if (fDecorator == NULL) + return DEC_NONE; - msg->FindPoint("where", &where); - msg->FindInt32("buttons", &buttons); - msg->FindInt32("modifiers", &modifiers); + BPoint where; + if (msg->FindPoint("where", &where) != B_OK) + return DEC_NONE; - if (fDecorator) - return fDecorator->Clicked(where, buttons, modifiers); + int32 buttons; + if (msg->FindInt32("buttons", &buttons) != B_OK) + buttons = 0; - return DEC_NONE; + int32 modifiers; + if (msg->FindInt32("modifiers", &modifiers) != B_OK) + modifiers = 0; + + return fDecorator->Clicked(where, buttons, modifiers); } -// _ObeySizeLimits + void WindowLayer::_ObeySizeLimits() {