From f247113640c6b692023a316913c73a89b04c3a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 31 Mar 2009 13:34:16 +0000 Subject: [PATCH] Added DecoratorFrame() method, which returns the outer frame of the window on screen (ie including the decorator border and tab). Plus the necessary refactoring as well as some TODO notes about windows with the tab on the left side. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29820 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/Window.h | 4 +++ src/kits/interface/Window.cpp | 63 +++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/headers/os/interface/Window.h b/headers/os/interface/Window.h index 572f97efdc..be48b49685 100644 --- a/headers/os/interface/Window.h +++ b/headers/os/interface/Window.h @@ -186,6 +186,7 @@ public: BRect Bounds() const; BRect Frame() const; + BRect DecoratorFrame() const; const char* Title() const; void SetTitle(const char* title); bool IsFront() const; @@ -331,6 +332,9 @@ private: bool _HandleKeyDown(BMessage* event); void _KeyboardNavigation(); + void _GetDecoratorSize(float* _borderWidth, + float* _tabHeight) const; + private: char* fTitle; int32 _unused0; diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index f45d2a49f8..a5b4176cad 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -1532,16 +1532,9 @@ BWindow::Zoom() the smallest of three rectangles: */ - // fallback in case retrieving the decorator settings fails (highly unlikely) - float borderWidth = 5.0; - float tabHeight = 21.0; - BMessage settings; - if (GetDecoratorSettings(&settings) == B_OK) { - BRect tabRect; - if (settings.FindRect("tab frame", &tabRect) == B_OK) - tabHeight = tabRect.Height(); - settings.FindFloat("border width", &borderWidth); - } + float borderWidth; + float tabHeight; + _GetDecoratorSize(&borderWidth, &tabHeight); // 1) the rectangle defined by SetZoomLimits(), float zoomedWidth = fMaxZoomWidth; @@ -1555,6 +1548,7 @@ BWindow::Zoom() // 3) the screen rectangle BScreen screen(this); + // TODO: Broken for tab on left side windows... float screenWidth = screen.Frame().Width() - 2 * borderWidth; float screenHeight = screen.Frame().Height() - (2 * borderWidth + tabHeight); if (screenWidth < zoomedWidth) @@ -1562,7 +1556,8 @@ BWindow::Zoom() if (screenHeight < zoomedHeight) zoomedHeight = screenHeight; - BPoint zoomedLeftTop = screen.Frame().LeftTop() + BPoint(borderWidth, tabHeight + borderWidth); + BPoint zoomedLeftTop = screen.Frame().LeftTop() + BPoint(borderWidth, + tabHeight + borderWidth); // UN-ZOOM: if (fPreviousFrame.IsValid() @@ -1914,6 +1909,22 @@ BWindow::Frame() const } +BRect +BWindow::DecoratorFrame() const +{ + BRect decortatorFrame(Frame()); + float borderWidth; + float tabHeight; + _GetDecoratorSize(&borderWidth, &tabHeight); + // TODO: Broken for tab on left window side windows... + decortatorFrame.top -= tabHeight; + decortatorFrame.left -= borderWidth; + decortatorFrame.right += borderWidth; + decortatorFrame.bottom += borderWidth; + return decortatorFrame; +} + + const char * BWindow::Title() const { @@ -3686,6 +3697,36 @@ BWindow::IsFilePanel() const } +void +BWindow::_GetDecoratorSize(float* _borderWidth, float* _tabHeight) const +{ + // fallback in case retrieving the decorator settings fails + // (highly unlikely) + float borderWidth = 5.0; + float tabHeight = 21.0; + + BMessage settings; + if (GetDecoratorSettings(&settings) == B_OK) { + BRect tabRect; + if (settings.FindRect("tab frame", &tabRect) == B_OK) + tabHeight = tabRect.Height(); + settings.FindFloat("border width", &borderWidth); + } else { + // probably no-border window look + if (fLook == B_NO_BORDER_WINDOW_LOOK) { + borderWidth = 0.0; + tabHeight = 0.0; + } + // else use fall-back values from above + } + + if (_borderWidth != NULL) + *_borderWidth = borderWidth; + if (_tabHeight != NULL) + *_tabHeight = tabHeight; +} + + // #pragma mark - C++ binary compatibility kludge