[haiku-commits] haiku: hrev53890 - src/apps/deskbar

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 19 Feb 2020 11:20:07 -0500 (EST)

hrev53890 adds 2 changesets to branch 'master'
old head: cce89fa82f071528e533a87c9b6790c705d6cffc
new head: 15eb397e32ec5483964f787ecec46358d06173fd
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=15eb397e32ec+%5Ecce89fa82f07

----------------------------------------------------------------------------

1c765f5b6282: Deskbar: Set window limits to hidden dimension in auto-hide mode.
  
  This fixes a bug where the window size limits were not set correctly
  causing the window not to be hidden properly in some cases while
  Deskbar is in auto-hide mode. This bug was introduced in hrev53585:
  Update window resize size limits.
  
  A couple of other auto-hide related bugs were also fixed:
  
  Hide TBarView in constructor if auto-hide is on. This is needed to
  size and position the window correctly on Deskbar startup in auto-
  hide mode.
  
  Always Check fTime->IsHidden() from the perspective of fTime instead
  of the parent view because we were getting false positives that the
  clock was hidden in auto-hide mode which caused the replicants not to
  realign themselves around the clock on Deskbar startup. The clock
  thought it was hidden because the parent view was hidden but that's
  not what is needed here.
  
  Bail out of BarView::MouseMoved if resizing. This fixes a bug where
  if you resized the window in auto-hide mode once the window had become
  as wide as possible dragging beyond the window hidden area slop limit
  would confusingly cause the window to hide itself in the middle of your
  resize operation.
  
  Fixes #15067 better. Fixes problems related to #8641 and #9469.
  
  Change-Id: I58de02e0cdd4e4cdccc15594992f11bf8c7f3a26
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/2252
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

15eb397e32ec: Deskbar: Adjust team menu items with font size.
  
  The Deskbar team menu should look the same at 12pt but much better
  at larger (and smaller) font sizes.
  
  Determine team menu item height in TBarView instead of
  TTeamMenuItem::GetContentSize() because it is needed earlier in the
  process, and also call method in GetContentSize().
  
  The clock is centered horizontally in the first replicant row and the
  width can grow to push the replicant icons better at larger font sizes.
  
  The replicant tray and clock go to the bottom in horizontal bottom mode
  and go to the top in horizontal top mode for Fitt's Law convinience and
  go in the center of the first row in vertical mode.
  
  Grow horizontal team item widths with font size, and shrink them
  down to 1/2 of full width to fit more, or 1/2 padding for icon-only.
  
  In horizontal mode the menu item size increases so that you can fit
  approximate the same amount of label text based on icon and font size.
  hit the width limit the items shrink and the label gets truncated
  (like before.)
  
  Scale team menu with font size. Reduce to half width for hide labels.
  
  Change-Id: I93ecc8acded274b994728e7247768455862e31c5
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/345
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

----------------------------------------------------------------------------

11 files changed, 244 insertions(+), 174 deletions(-)
src/apps/deskbar/BarView.cpp             |  72 ++++++++++++---
src/apps/deskbar/BarView.h               |   2 +
src/apps/deskbar/BarWindow.cpp           |  22 +++--
src/apps/deskbar/ExpandoMenuBar.cpp      | 127 ++++++++++-----------------
src/apps/deskbar/ExpandoMenuBar.h        |   7 +-
src/apps/deskbar/StatusView.cpp          |  49 ++++++++---
src/apps/deskbar/TeamMenuItem.cpp        | 111 ++++++++++++-----------
src/apps/deskbar/TeamMenuItem.h          |   4 +
src/apps/deskbar/TimeView.cpp            |  22 +++--
src/apps/deskbar/TimeView.h              |   1 -
src/apps/deskbar/TruncatableMenuItem.cpp |   1 -

############################################################################

Commit:      1c765f5b62820d833dfa2acca312336f5b3065e4
URL:         https://git.haiku-os.org/haiku/commit/?id=1c765f5b6282
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Feb 18 07:03:58 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Wed Feb 19 16:20:01 2020 UTC

Ticket:      https://dev.haiku-os.org/ticket/8641
Ticket:      https://dev.haiku-os.org/ticket/9469
Ticket:      https://dev.haiku-os.org/ticket/15067

Deskbar: Set window limits to hidden dimension in auto-hide mode.

This fixes a bug where the window size limits were not set correctly
causing the window not to be hidden properly in some cases while
Deskbar is in auto-hide mode. This bug was introduced in hrev53585:
Update window resize size limits.

A couple of other auto-hide related bugs were also fixed:

Hide TBarView in constructor if auto-hide is on. This is needed to
size and position the window correctly on Deskbar startup in auto-
hide mode.

Always Check fTime->IsHidden() from the perspective of fTime instead
of the parent view because we were getting false positives that the
clock was hidden in auto-hide mode which caused the replicants not to
realign themselves around the clock on Deskbar startup. The clock
thought it was hidden because the parent view was hidden but that's
not what is needed here.

Bail out of BarView::MouseMoved if resizing. This fixes a bug where
if you resized the window in auto-hide mode once the window had become
as wide as possible dragging beyond the window hidden area slop limit
would confusingly cause the window to hide itself in the middle of your
resize operation.

Fixes #15067 better. Fixes problems related to #8641 and #9469.

Change-Id: I58de02e0cdd4e4cdccc15594992f11bf8c7f3a26
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2252
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp
index 6d8fd6ba44..dcea99ed31 100644
--- a/src/apps/deskbar/BarView.cpp
+++ b/src/apps/deskbar/BarView.cpp
@@ -184,6 +184,9 @@ TBarView::TBarView(BRect frame, bool vertical, bool left, 
bool top,
        // If mini mode, hide the application menubar
        if (state == kMiniState)
                fInlineScrollView->Hide();
+
+       if (fBarApp->Settings()->autoHide && !IsHidden())
+               Hide();
 }
 
 
@@ -292,10 +295,10 @@ TBarView::MessageReceived(BMessage* message)
 void
 TBarView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
 {
-       if (fDragRegion->IsDragging()) {
-               fDragRegion->MouseMoved(where, transit, dragMessage);
-               return;
-       }
+       if (fDragRegion->IsDragging())
+               return fDragRegion->MouseMoved(where, transit, dragMessage);
+       else if (fResizeControl->IsResizing())
+               return BView::MouseMoved(where, transit, dragMessage);
 
        desk_settings* settings = fBarApp->Settings();
        bool alwaysOnTop = settings->alwaysOnTop;
@@ -805,13 +808,20 @@ void
 TBarView::HideDeskbar(bool hide)
 {
        BRect screenFrame = (BScreen(Window())).Frame();
+       TBarWindow* barWindow = dynamic_cast<TBarWindow*>(Window());
 
        if (hide) {
                Hide();
+               if (barWindow != NULL)
+                       barWindow->SetSizeLimits();
+
                PositionWindow(screenFrame);
                SizeWindow(screenFrame);
        } else {
                Show();
+               if (barWindow != NULL)
+                       barWindow->SetSizeLimits();
+
                SizeWindow(screenFrame);
                PositionWindow(screenFrame);
        }
diff --git a/src/apps/deskbar/BarWindow.cpp b/src/apps/deskbar/BarWindow.cpp
index 388846bf5c..db65d94e13 100644
--- a/src/apps/deskbar/BarWindow.cpp
+++ b/src/apps/deskbar/BarWindow.cpp
@@ -654,12 +654,24 @@ void
 TBarWindow::SetSizeLimits()
 {
        BRect screenFrame = (BScreen(this)).Frame();
-       if (fBarView->Vertical()) {
-               BWindow::SetSizeLimits(gMinimumWindowWidth, gMaximumWindowWidth,
-                       kMenuBarHeight - 1, screenFrame.Height());
+       bool setToHiddenSize = 
static_cast<TBarApp*>(be_app)->Settings()->autoHide
+               && fBarView->IsHidden() && 
!fBarView->DragRegion()->IsDragging();
+
+       if (setToHiddenSize) {
+               if (fBarView->Vertical())
+                       BWindow::SetSizeLimits(0, kHiddenDimension, 0, 
kHiddenDimension);
+               else {
+                       BWindow::SetSizeLimits(screenFrame.Width(), 
screenFrame.Width(),
+                               0, kHiddenDimension);
+               }
        } else {
-               BWindow::SetSizeLimits(screenFrame.Width(), screenFrame.Width(),
-                       kMenuBarHeight - 1, kMaximumIconSize + 4);
+               if (fBarView->Vertical()) {
+                       BWindow::SetSizeLimits(gMinimumWindowWidth, 
gMaximumWindowWidth,
+                               kMenuBarHeight - 1, screenFrame.Height());
+               } else {
+                       BWindow::SetSizeLimits(screenFrame.Width(), 
screenFrame.Width(),
+                               kMenuBarHeight - 1, kMaximumIconSize + 4);
+               }
        }
 }
 
diff --git a/src/apps/deskbar/StatusView.cpp b/src/apps/deskbar/StatusView.cpp
index 5ff13b4d58..35d8ed5ebb 100644
--- a/src/apps/deskbar/StatusView.cpp
+++ b/src/apps/deskbar/StatusView.cpp
@@ -237,7 +237,7 @@ TReplicantTray::GetPreferredSize(float* preferredWidth, 
float* preferredHeight)
        } else {
                // if last replicant overruns clock then resize to accomodate
                if (ReplicantCount() > 0) {
-                       if (!fTime->IsHidden() && Bounds().right - kTrayPadding 
- 2
+                       if (!fTime->IsHidden(fTime) && Bounds().right - 
kTrayPadding - 2
                                                - fTime->Frame().Width() - 
kClockMargin
                                        < fRightBottomReplicant.right + 
kClockMargin) {
                                width = fRightBottomReplicant.right + 
kClockMargin
@@ -329,7 +329,7 @@ TReplicantTray::MessageReceived(BMessage* message)
                        if (fTime == NULL)
                                return;
 
-                       bool showClock = !fTime->IsHidden();
+                       bool showClock = !fTime->IsHidden(fTime);
                        bool showSeconds = fTime->ShowSeconds();
                        bool showDayOfWeek = fTime->ShowDayOfWeek();
                        bool showTimeZone = fTime->ShowTimeZone();
@@ -409,7 +409,7 @@ TReplicantTray::ShowReplicantMenu(BPoint point)
 
        // If clock is visible show the extended menu, otherwise show "Show 
clock"
 
-       if (!fTime->IsHidden())
+       if (!fTime->IsHidden(fTime))
                fTime->ShowTimeOptions(ConvertToScreen(point));
        else {
                BMenuItem* item = new BMenuItem(B_TRANSLATE("Show clock"),
@@ -1177,7 +1177,7 @@ TReplicantTray::LocationForReplicant(int32 index, float 
replicantWidth)
                                loc.x + 
static_cast<TBarApp*>(be_app)->Settings()->width
                                        - (kTrayPadding + kDragWidth + kGutter) 
* 2,
                                loc.y + fMaxReplicantHeight);
-                       if (row == 0 && !fTime->IsHidden())
+                       if (row == 0 && !fTime->IsHidden(fTime))
                                rowRect.right -= kClockMargin + 
fTime->Frame().Width();
 
                        BRect replicantRect = rowRect;

############################################################################

Revision:    hrev53890
Commit:      15eb397e32ec5483964f787ecec46358d06173fd
URL:         https://git.haiku-os.org/haiku/commit/?id=15eb397e32ec
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Fri Jul 20 05:33:25 2018 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Wed Feb 19 16:20:01 2020 UTC

Deskbar: Adjust team menu items with font size.

The Deskbar team menu should look the same at 12pt but much better
at larger (and smaller) font sizes.

Determine team menu item height in TBarView instead of
TTeamMenuItem::GetContentSize() because it is needed earlier in the
process, and also call method in GetContentSize().

The clock is centered horizontally in the first replicant row and the
width can grow to push the replicant icons better at larger font sizes.

The replicant tray and clock go to the bottom in horizontal bottom mode
and go to the top in horizontal top mode for Fitt's Law convinience and
go in the center of the first row in vertical mode.

Grow horizontal team item widths with font size, and shrink them
down to 1/2 of full width to fit more, or 1/2 padding for icon-only.

In horizontal mode the menu item size increases so that you can fit
approximate the same amount of label text based on icon and font size.
hit the width limit the items shrink and the label gets truncated
(like before.)

Scale team menu with font size. Reduce to half width for hide labels.

Change-Id: I93ecc8acded274b994728e7247768455862e31c5
Reviewed-on: https://review.haiku-os.org/c/haiku/+/345
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp
index dcea99ed31..b6ebf8632d 100644
--- a/src/apps/deskbar/BarView.cpp
+++ b/src/apps/deskbar/BarView.cpp
@@ -64,9 +64,10 @@ const int32 kDefaultRecentDocCount = 10;
 const int32 kDefaultRecentAppCount = 10;
 
 const int32 kMenuTrackMargin = 20;
+const float kMinTeamItemHeight = 20.0f;
+const float kVPad = 2.0f;
 
 const uint32 kUpdateOrientation = 'UpOr';
-const float kSepItemWidth = 5.0f;
 
 
 class BarViewMessageFilter : public BMessageFilter
@@ -149,6 +150,7 @@ TBarView::TBarView(BRect frame, bool vertical, bool left, 
bool top,
        fMouseFilter(NULL)
 {
        // determine the initial Be menu size
+       // (will be updated later)
        BRect menuFrame(frame);
        if (fVertical)
                menuFrame.bottom = menuFrame.top + kMenuBarHeight;
@@ -212,6 +214,9 @@ TBarView::AttachedToWindow()
        fTrackingHookData.fTrackingHook = MenuTrackingHook;
        fTrackingHookData.fTarget = BMessenger(this);
        fTrackingHookData.fDragMessage = new BMessage(B_REFS_RECEIVED);
+
+       if (!fVertical)
+               UpdatePlacement(); // update MenuBarHeight
 }
 
 
@@ -434,7 +439,8 @@ TBarView::PlaceDeskbarMenu()
                menuFrame.bottom = menuFrame.top + height;
        } else {
                width = gMinimumWindowWidth;
-               height = fBarApp->IconSize() + 4;
+               height = std::max(TeamMenuItemHeight(),
+                       kGutter + fReplicantTray->MaxReplicantHeight() + 
kGutter);
                menuFrame.bottom = menuFrame.top + height;
        }
 
@@ -574,7 +580,7 @@ TBarView::PlaceApplicationBar()
        } else {
                // top or bottom
                expandoFrame.top = 0;
-               expandoFrame.bottom = fBarApp->IconSize() + 4;
+               expandoFrame.bottom = TeamMenuItemHeight();
 
                if (fBarMenuBar != NULL)
                        expandoFrame.left = fBarMenuBar->Frame().Width() + 1;
@@ -594,11 +600,6 @@ TBarView::PlaceApplicationBar()
        fExpandoMenuBar->MoveTo(0, 0);
        fExpandoMenuBar->ResizeTo(expandoFrame.Width(), expandoFrame.Height());
 
-       if (!fVertical) {
-               // Set the max item width based on icon size
-               fExpandoMenuBar->SetMaxItemWidth();
-       }
-
        if (fState == kExpandoState)
                fExpandoMenuBar->BuildItems();
 
@@ -645,7 +646,8 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* 
width, float* height)
                        } else {
                                // top or bottom, full
                                fExpandoMenuBar->CheckItemSizes(0);
-                               windowHeight = fBarApp->IconSize() + 4;
+                               windowHeight = std::max(TeamMenuItemHeight(),
+                                       kGutter + 
fReplicantTray->MaxReplicantHeight() + kGutter);
                                windowWidth = screenFrame.Width();
                        }
                } else {
@@ -1230,3 +1232,37 @@ TBarView::IconFrame(const char* name) const
 {
        return OffsetIconFrame(fReplicantTray->IconFrame(name));
 }
+
+
+float
+TBarView::TeamMenuItemHeight() const
+{
+       const int32 iconSize = fBarApp->IconSize();
+       float iconSizePadded = kVPad + iconSize + kVPad;
+
+       font_height fontHeight;
+       if (fExpandoMenuBar != NULL)
+               fExpandoMenuBar->GetFontHeight(&fontHeight);
+       else
+               GetFontHeight(&fontHeight);
+
+       float labelHeight = fontHeight.ascent + fontHeight.descent;
+       labelHeight = labelHeight < kMinTeamItemHeight ? kMinTeamItemHeight
+               : ceilf(labelHeight * 1.1f);
+
+       bool hideLabels = static_cast<TBarApp*>(be_app)->Settings()->hideLabels;
+       if (hideLabels && iconSize > B_MINI_ICON) {
+               // height is determined based solely on icon size
+               return iconSizePadded;
+       } else if (!fVertical || fVertical && iconSize <= B_LARGE_ICON) {
+               // horizontal or vertical with label on same row as icon:
+               // height based on icon size or font size, whichever is bigger
+               return std::max(iconSizePadded, labelHeight);
+       } else if (fVertical && iconSize > B_LARGE_ICON) {
+               // vertical with label below icon: height based on icon and 
label
+               return ceilf(iconSizePadded + labelHeight);
+       } else {
+               // height is determined based solely on label height
+               return labelHeight;
+       }
+}
diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h
index 6ed2b6eb87..b1da59f7bd 100644
--- a/src/apps/deskbar/BarView.h
+++ b/src/apps/deskbar/BarView.h
@@ -169,6 +169,8 @@ public:
                        TDragRegion*            DragRegion() const { return 
fDragRegion; }
                        TReplicantTray*         ReplicantTray() const { return 
fReplicantTray; }
 
+                       float                   TeamMenuItemHeight() const;
+
 private:
        friend class TBarApp;
        friend class TDeskbarMenu;
diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp 
b/src/apps/deskbar/ExpandoMenuBar.cpp
index 36fac162c7..f1d9536fdc 100644
--- a/src/apps/deskbar/ExpandoMenuBar.cpp
+++ b/src/apps/deskbar/ExpandoMenuBar.cpp
@@ -71,7 +71,6 @@ All rights reserved.
 
 
 const float kMinMenuItemWidth = 50.0f;
-const float kSepItemWidth = 5.0f;
 const float kIconPadding = 8.0f;
 
 const uint32 kMinimizeTeam = 'mntm';
@@ -95,14 +94,13 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* barView, bool 
vertical)
        fVertical(vertical),
        fOverflow(false),
        fFirstBuild(true),
-       fDeskbarMenuWidth(kMinMenuItemWidth),
+       fDeskbarMenuWidth(gMinimumWindowWidth),
        fPreviousDragTargetItem(NULL),
        fLastMousedOverItem(NULL),
        fLastClickedItem(NULL)
 {
        SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f);
        SetFont(be_plain_font);
-       SetMaxItemWidth();
 
        // top or bottom mode, add deskbar menu and sep for menubar tracking
        // consistency
@@ -468,21 +466,12 @@ TExpandoMenuBar::BuildItems()
        BMessenger self(this);
        TBarApp::Subscribe(self, &fTeamList);
 
-       int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
-       desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();
-
        float itemWidth = -1.0f;
        if (fVertical) {
                itemWidth = Frame().Width();
                SetMaxContentWidth(itemWidth);
-       } else {
-               itemWidth = iconSize;
-               if (!settings->hideLabels)
-                       itemWidth += gMinimumWindowWidth - kMinimumIconSize;
-               else
-                       itemWidth += kIconPadding * 2;
-       }
-       float itemHeight = -1.0f;
+       } else
+               CheckItemSizes(0, true); // force reset
 
        TeamMenuItemMap items;
        int32 itemCount = CountItems();
@@ -495,6 +484,7 @@ TExpandoMenuBar::BuildItems()
                        items[BString(item->Signature()).ToLower()] = item;
        }
 
+       desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();
        if (settings->sortRunningApps)
                fTeamList.SortItems(TTeamMenu::CompareByName);
 
@@ -506,8 +496,7 @@ TExpandoMenuBar::BuildItems()
                if (iter == items.end()) {
                        // new team
                        TTeamMenuItem* item = new TTeamMenuItem(barInfo->teams,
-                               barInfo->icon, barInfo->name, barInfo->sig, 
itemWidth,
-                               itemHeight);
+                               barInfo->icon, barInfo->name, barInfo->sig, 
itemWidth);
 
                        if (settings->trackerAlwaysFirst
                                && strcasecmp(barInfo->sig, kTrackerSignature) 
== 0) {
@@ -522,7 +511,6 @@ TExpandoMenuBar::BuildItems()
                        TTeamMenuItem* item = iter->second;
                        item->SetIcon(barInfo->icon);
                        item->SetOverrideWidth(itemWidth);
-                       item->SetOverrideHeight(itemHeight);
 
                        if (settings->trackerAlwaysFirst
                                && strcasecmp(barInfo->sig, kTrackerSignature) 
== 0) {
@@ -560,7 +548,7 @@ TExpandoMenuBar::BuildItems()
        if (CountItems() == 0) {
                // If we're empty, BMenuBar::AttachedToWindow() resizes us to 
some
                // weird value - we just override it again
-               ResizeTo(itemWidth, 0);
+               ResizeTo(gMinimumWindowWidth, 0);
        }
 
        fFirstBuild = false;
@@ -624,24 +612,9 @@ void
 TExpandoMenuBar::AddTeam(BList* team, BBitmap* icon, char* name,
        char* signature)
 {
-       int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
-       desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();
-
-       float itemWidth = -1.0f;
-       if (fVertical)
-               itemWidth = fBarView->Bounds().Width();
-       else {
-               itemWidth = iconSize;
-               if (!settings->hideLabels)
-                       itemWidth += gMinimumWindowWidth - kMinimumIconSize;
-               else
-                       itemWidth += kIconPadding * 2;
-       }
-       float itemHeight = -1.0f;
-
-       TTeamMenuItem* item = new TTeamMenuItem(team, icon, name, signature,
-               itemWidth, itemHeight);
+       TTeamMenuItem* item = new TTeamMenuItem(team, icon, name, signature);
 
+       desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();
        if (settings->trackerAlwaysFirst
                && strcasecmp(signature, kTrackerSignature) == 0) {
                AddItem(item, 0);
@@ -746,34 +719,44 @@ TExpandoMenuBar::RemoveTeam(team_id team, bool partial)
 
 
 void
-TExpandoMenuBar::CheckItemSizes(int32 delta)
+TExpandoMenuBar::CheckItemSizes(int32 delta, bool reset)
 {
-       if (fBarView->Vertical())
+       if (fVertical)
                return;
 
-       bool drawLabels = 
!static_cast<TBarApp*>(be_app)->Settings()->hideLabels;
+       int32 itemCount = CountItems();
+       TTeamMenuItem* item = static_cast<TTeamMenuItem*>(ItemAt(0));
+       if (itemCount < 1 || item == NULL)
+               return;
 
-       float maxWidth = fBarView->DragRegion()->Frame().left
-               - fDeskbarMenuWidth - kSepItemWidth;
        int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
        float iconOnlyWidth = kIconPadding + iconSize + kIconPadding;
-       float minItemWidth = drawLabels
-               ? iconOnlyWidth + kMinMenuItemWidth
-               : iconOnlyWidth - kIconPadding;
-       float maxItemWidth = drawLabels
-               ? gMinimumWindowWidth + iconSize - kMinimumIconSize
-               : iconOnlyWidth;
-       float menuWidth = maxItemWidth * CountItems() + fDeskbarMenuWidth
-               + kSepItemWidth;
-
-       bool reset = false;
+
+       float maxItemWidth;
+       float minItemWidth;
+       if (static_cast<TBarApp*>(be_app)->Settings()->hideLabels) {
+               maxItemWidth = iconOnlyWidth;
+               minItemWidth = iconOnlyWidth - kIconPadding * 3 / 4;
+       } else {
+               float labelWidth = gMinimumWindowWidth;
+               labelWidth += (be_plain_font->Size() - 12) * 4 + iconSize
+                       - kMinimumIconSize;
+               maxItemWidth = iconOnlyWidth + labelWidth;
+               minItemWidth = iconOnlyWidth + floorf(labelWidth / 4);
+       }
+
+       float menuWidth = fDeskbarMenuWidth + kSepItemWidth
+               + maxItemWidth * itemCount;
+       float maxWidth = fBarView->DragRegion()->Frame().left - 1
+               - fDeskbarMenuWidth - kSepItemWidth;
+
        float newWidth = -1.0f;
 
        if (delta >= 0 && menuWidth > maxWidth) {
                fOverflow = true;
                reset = true;
                newWidth = floorf(maxWidth / CountItems());
-       } else if (delta < 0 && fOverflow) {
+       } else if (reset || (delta < 0 && fOverflow)) {
                reset = true;
                if (menuWidth > maxWidth)
                        newWidth = floorf(maxWidth / CountItems());
@@ -820,8 +803,7 @@ TExpandoMenuBar::SetMenuLayout(menu_layout layout)
 {
        fVertical = layout == B_ITEMS_IN_COLUMN;
        BPrivate::MenuPrivate(this).SetLayout(layout);
-       SetMaxItemWidth();
-               // when the menu layout changes, make sure to set the max width
+       InvalidateLayout();
 }
 
 
@@ -884,35 +866,19 @@ TExpandoMenuBar::CheckForSizeOverrun()
        }
 
        // horizontal
-       int32 count = CountItems() - 1;
-       if (count < 0)
+       int32 itemCount = CountItems();
+       TTeamMenuItem* item = static_cast<TTeamMenuItem*>(ItemAt(0));
+       if (itemCount < 1 || item == NULL)
                return false;
 
-       int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
-       float iconOnlyWidth = kIconPadding + iconSize + kIconPadding;
-       float minItemWidth = 
!static_cast<TBarApp*>(be_app)->Settings()->hideLabels
-               ? iconOnlyWidth + kMinMenuItemWidth
-               : iconOnlyWidth - kIconPadding;
-       float menuWidth = minItemWidth * CountItems() + fDeskbarMenuWidth
-               + kSepItemWidth;
-       float maxWidth = fBarView->DragRegion()->Frame().left
-               - fDeskbarMenuWidth - kSepItemWidth;
-
-       return menuWidth > maxWidth;
-}
+       float itemWidth = item->Frame().Width();
+       if (itemWidth <= 0)
+               return false;
 
+       float menuWidth = fDeskbarMenuWidth + kSepItemWidth + itemWidth * 
itemCount;
+       float maxWidth = fBarView->DragRegion()->Frame().left - 1;
 
-void
-TExpandoMenuBar::SetMaxItemWidth()
-{
-       if (fVertical)
-               
SetMaxContentWidth(static_cast<TBarApp*>(be_app)->Settings()->width);
-       else {
-               // Make more room for the icon in horizontal mode
-               int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
-               SetMaxContentWidth(gMinimumWindowWidth + iconSize
-                       - kMinimumIconSize);
-       }
+       return menuWidth > maxWidth;
 }
 
 
@@ -1029,9 +995,10 @@ TExpandoMenuBar::monitor_team_windows(void* arg)
                                                                                
((1 << current_workspace())
                                                                                
        & wInfo->workspaces) != 0);
 
-                                                                       if 
(strcasecmp(item->Label(), windowName) > 0)
+                                                                       if 
(strcasecmp(item->Label(), windowName)
+                                                                               
        > 0) {
                                                                                
item->SetLabel(windowName);
-
+                                                                       }
                                                                        if 
(item->Modified())
                                                                                
itemModified = true;
                                                                } else if 
(teamItem->IsExpanded()) {
diff --git a/src/apps/deskbar/ExpandoMenuBar.h 
b/src/apps/deskbar/ExpandoMenuBar.h
index 1aa2e86533..ffb1e518aa 100644
--- a/src/apps/deskbar/ExpandoMenuBar.h
+++ b/src/apps/deskbar/ExpandoMenuBar.h
@@ -45,6 +45,9 @@ All rights reserved.
 #include <Locker.h>
 
 
+const float kSepItemWidth = 5.0f;
+
+
 enum drag_and_drop_selection {
        kNoSelection,
        kDeskbarMenuSelection,
@@ -83,13 +86,11 @@ public:
                                                                BMenuItem** 
_item = NULL);
                        bool                    InDeskbarMenu(BPoint) const;
 
-                       void                    CheckItemSizes(int32 delta);
+                       void                    CheckItemSizes(int32 delta, 
bool reset = false);
 
                        menu_layout             MenuLayout() const;
                        void                    SetMenuLayout(menu_layout 
layout);
 
-                       void                    SetMaxItemWidth();
-
                        void                    SizeWindow(int32 delta);
                        bool                    CheckForSizeOverrun();
 
diff --git a/src/apps/deskbar/StatusView.cpp b/src/apps/deskbar/StatusView.cpp
index 35d8ed5ebb..871f87ceda 100644
--- a/src/apps/deskbar/StatusView.cpp
+++ b/src/apps/deskbar/StatusView.cpp
@@ -70,6 +70,7 @@ All rights reserved.
 
 #include "BarApp.h"
 #include "DeskbarUtils.h"
+#include "ExpandoMenuBar.h"
 #include "ResourceSet.h"
 #include "StatusViewShelf.h"
 #include "TimeView.h"
@@ -1191,7 +1192,8 @@ TReplicantTray::LocationForReplicant(int32 index, float 
replicantWidth)
                                replicantRect.left = view->Frame().right + 
kIconGap + 1;
                        }
 
-                       // calculated left position, add replicantWidth to get 
right position
+                       // calculated left position, add replicantWidth to get 
the
+                       // right position
                        replicantRect.right = replicantRect.left + 
replicantWidth;
 
                        // check if replicant fits in this row
@@ -1203,15 +1205,36 @@ TReplicantTray::LocationForReplicant(int32 index, float 
replicantWidth)
 
                        // check next row
                }
-       } else if (index > 0) {
-               // get the last replicant added for placement reference
-               BView* view = NULL;
-               fShelf->ReplicantAt(index - 1, &view);
-               if (view != NULL) {
-                       // push this replicant placement past the last one
-                       loc.x = view->Frame().right + kIconGap + 1;
-                       loc.y = view->Frame().top;
+
+               fTime->MoveTo(Bounds().right - fTime->Bounds().Width()
+                       - kTrayPadding, 2);
+       } else {
+               if (index > 0) {
+                       // get the last replicant added for placement reference
+                       BView* view = NULL;
+                       fShelf->ReplicantAt(index - 1, &view);
+                       if (view != NULL) {
+                               // push this replicant placement past the last 
one
+                               loc.x = view->Frame().right + kIconGap + 1;
+                       }
                }
+
+               if (fBarView->Vertical()) {
+                       // center vertically
+                       loc.y = floorf((kMenuBarHeight - fMaxReplicantHeight) / 
2) - 1;
+               } else {
+                       if (fBarView->Top()) {
+                               // align top
+                               loc.y = 3;
+                       } else {
+                               // align bottom
+                               loc.y = fBarView->TeamMenuItemHeight() - 
fMaxReplicantHeight - 2;
+                       }
+               }
+
+               // move time in place next to replicants
+               fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - 
kTrayPadding,
+                       loc.y + (fMaxReplicantHeight - 
fTime->Bounds().Height()) / 2);
        }
 
        if (loc.y > fRightBottomReplicant.top
diff --git a/src/apps/deskbar/TeamMenuItem.cpp 
b/src/apps/deskbar/TeamMenuItem.cpp
index 1c1fd1f740..fd9bf4e8b1 100644
--- a/src/apps/deskbar/TeamMenuItem.cpp
+++ b/src/apps/deskbar/TeamMenuItem.cpp
@@ -40,10 +40,13 @@ All rights reserved.
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <algorithm>
+
 #include <Bitmap.h>
 #include <ControlLook.h>
 #include <Debug.h>
 #include <Font.h>
+#include <Mime.h>
 #include <Region.h>
 #include <Roster.h>
 #include <Resources.h>
@@ -54,6 +57,7 @@ All rights reserved.
 #include "ExpandoMenuBar.h"
 #include "ResourceSet.h"
 #include "ShowHideMenuItem.h"
+#include "StatusView.h"
 #include "TeamMenu.h"
 #include "WindowMenu.h"
 #include "WindowMenuItem.h"
@@ -62,7 +66,7 @@ All rights reserved.
 const float kHPad = 8.0f;
 const float kVPad = 2.0f;
 const float kLabelOffset = 8.0f;
-const float kSwitchWidth = 12.0f;
+const float kIconPadding = 8.0f;
 
 
 //     #pragma mark - TTeamMenuItem
@@ -138,39 +142,39 @@ TTeamMenuItem::SetIcon(BBitmap* icon) {
 void
 TTeamMenuItem::GetContentSize(float* width, float* height)
 {
-       BRect iconBounds;
-
-       if (fIcon != NULL)
-               iconBounds = fIcon->Bounds();
-       else
-               iconBounds = BRect(0, 0, kMinimumIconSize - 1, kMinimumIconSize 
- 1);
-
        BMenuItem::GetContentSize(width, height);
 
        if (fOverrideWidth != -1.0f)
                *width = fOverrideWidth;
        else {
-               *width = kHPad + iconBounds.Width() + kHPad;
-               if (iconBounds.Width() <= 32
-                       && 
!static_cast<TBarApp*>(be_app)->Settings()->hideLabels) {
-                       *width += LabelWidth() + kHPad;
-               }
+               bool hideLabels = 
static_cast<TBarApp*>(be_app)->Settings()->hideLabels;
+               float iconSize = static_cast<TBarApp*>(be_app)->IconSize();
+               float iconOnlyWidth = kIconPadding + iconSize + kIconPadding;
+
+               if (fBarView->MiniState()) {
+                       if (hideLabels)
+                               *width = iconOnlyWidth;
+                       else
+                               *width = gMinimumWindowWidth - 
(kDragRegionWidth + kGutter) * 2;
+               } else if (!fBarView->Vertical()) {
+                       if (hideLabels)
+                               *width = iconOnlyWidth;
+                       else {
+                               float labelWidth = gMinimumWindowWidth;
+                               BFont font;
+                               Menu()->GetFont(&font);
+                               labelWidth += (font.Size() - 12) * 4 + iconSize 
- 16;
+                                       // do font and icon scaling
+                               *width = iconOnlyWidth + labelWidth;
+                       }
+               } else
+                       *width = 
static_cast<TBarApp*>(be_app)->Settings()->width;
        }
 
        if (fOverrideHeight != -1.0f)
                *height = fOverrideHeight;
-       else {
-               if (fBarView->Vertical()) {
-                       *height = iconBounds.Height() + kVPad * 2;
-                       if 
(!static_cast<TBarApp*>(be_app)->Settings()->hideLabels
-                               && iconBounds.Width() > 32) {
-                               *height += fLabelAscent + fLabelDescent;
-                       }
-               } else {
-                       *height = iconBounds.Height() + kVPad * 2;
-               }
-       }
-       *height += 2;
+       else
+               *height = fBarView->TeamMenuItemHeight();
 }
 
 
@@ -223,6 +227,8 @@ void
 TTeamMenuItem::DrawContent()
 {
        BMenu* menu = Menu();
+       BRect frame = Frame();
+
        if (fIcon != NULL) {
                if (fIcon->ColorSpace() == B_RGBA32) {
                        menu->SetDrawingMode(B_OP_ALPHA);
@@ -230,48 +236,50 @@ TTeamMenuItem::DrawContent()
                } else
                        menu->SetDrawingMode(B_OP_OVER);
 
-               BRect frame = Frame();
-               BRect iconBounds = fIcon->Bounds();
+               BRect iconBounds = fIcon != NULL ? fIcon->Bounds()
+                       : BRect(0, 0, kMinimumIconSize - 1, kMinimumIconSize - 
1);
                BRect updateRect = iconBounds;
-               float extra = fBarView->Vertical() ? 0.0f : -1.0f;
                BPoint contentLocation = ContentLocation();
                BPoint drawLocation = contentLocation + BPoint(kHPad, kVPad);
 
                if (static_cast<TBarApp*>(be_app)->Settings()->hideLabels
                        || (fBarView->Vertical() && iconBounds.Width() > 32)) {
+                       // determine icon location (centered horizontally)
                        float offsetx = contentLocation.x
-                               + ((frame.Width() - iconBounds.Width()) / 2) + 
extra;
-                       float offsety = contentLocation.y + 3.0f + extra;
+                               + floorf((frame.Width() - iconBounds.Width()) / 
2);
+                       float offsety = contentLocation.y + kVPad + kGutter;
 
+                       // draw icon
                        updateRect.OffsetTo(BPoint(offsetx, offsety));
                        menu->DrawBitmapAsync(fIcon, updateRect);
 
-                       drawLocation.x = ((frame.Width() - LabelWidth()) / 2);
-                       drawLocation.y = frame.top + iconBounds.Height() + 
kVPad * 2;
+                       // determine label position (below icon)
+                       drawLocation.x = floorf((frame.Width() - fLabelWidth) / 
2);
+                       drawLocation.y = frame.top + kVPad + 
iconBounds.Height() + kVPad;
                } else {
+                       // determine icon location (centered vertically)
                        float offsetx = contentLocation.x + kHPad;
                        float offsety = contentLocation.y +
-                               ((frame.Height() - iconBounds.Height()) / 2) + 
extra;
+                               floorf((frame.Height() - iconBounds.Height()) / 
2);
 
+                       // draw icon
                        updateRect.OffsetTo(BPoint(offsetx, offsety));
                        menu->DrawBitmapAsync(fIcon, updateRect);
 
-                       float labelHeight = fLabelAscent + fLabelDescent;
+                       // determine label position (centered vertically)
                        drawLocation.x += iconBounds.Width() + kLabelOffset;
-                       drawLocation.y = frame.top + ((frame.Height() - 
labelHeight) / 2)
-                               + extra;
+                       drawLocation.y = frame.top
+                               + ceilf((frame.Height() - fLabelHeight) / 2);
                }
 
                menu->MovePenTo(drawLocation);
        }
 
-       menu->SetDrawingMode(B_OP_OVER);
-       menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
-
        // override the drawing of the content when the item is disabled
        // the wrong lowcolor is used when the item is disabled since the
        // text color does not change
-       menu->MovePenBy(0, fLabelAscent);
+       menu->SetDrawingMode(B_OP_OVER);
+       menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
 
        bool canHandle = !fBarView->Dragging()
                || fBarView->AppCanHandleTypes(Signature());
@@ -286,13 +294,18 @@ TTeamMenuItem::DrawContent()
        else
                menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
 
+       menu->MovePenBy(0, fLabelAscent);
+
+       // draw label
        if (!static_cast<TBarApp*>(be_app)->Settings()->hideLabels) {
                float labelWidth = menu->StringWidth(Label());
                BPoint penLocation = menu->PenLocation();
-               float offset = penLocation.x - Frame().left;
+               // truncate to max width
+               float offset = penLocation.x - frame.left;
                menu->DrawString(Label(labelWidth + offset));
        }
 
+       // draw expander arrow
        if (fBarView->Vertical()
                && static_cast<TBarApp*>(be_app)->Settings()->superExpando
                && fBarView->ExpandoState()) {
@@ -304,23 +317,18 @@ TTeamMenuItem::DrawContent()
 void
 TTeamMenuItem::DrawExpanderArrow()
 {
-       BMenu* menu = Menu();
        BRect frame = Frame();
        BRect rect(0.0f, 0.0f, kSwitchWidth, kHPad + 2.0f);
-
        rect.OffsetTo(BPoint(frame.right - rect.Width(),
                ContentLocation().y + ((frame.Height() - rect.Height()) / 2)));
 
        float colorTint = B_DARKEN_3_TINT;
-
        rgb_color bgColor = ui_color(B_MENU_BACKGROUND_COLOR);
-       if (bgColor.red + bgColor.green + bgColor.blue <= 128 * 3) {
+       if (bgColor.red + bgColor.green + bgColor.blue <= 128 * 3)
                colorTint = B_LIGHTEN_2_TINT;
-       }
 
-       be_control_look->DrawArrowShape(menu, rect, rect,
-               bgColor, fArrowDirection, 0,
-               colorTint);
+       be_control_look->DrawArrowShape(Menu(), rect, Menu()->Frame(),
+               bgColor, fArrowDirection, 0, colorTint);
 }
 
 
@@ -372,8 +380,8 @@ TTeamMenuItem::ToggleExpandState(bool resizeWindow)
                        int32 childIndex = parent->IndexOf(this) + 1;
                        while (parent->SubmenuAt(childIndex) == NULL
                                && childIndex < parent->CountItems()) {
-                               windowItem
-                                       = 
static_cast<TWindowMenuItem*>(parent->RemoveItem(childIndex));
+                               windowItem = static_cast<TWindowMenuItem*>(
+                                       parent->RemoveItem(childIndex));
                                sub->AddItem(windowItem, 0);
                                windowItem->SetExpanded(false);
                        }
@@ -449,6 +457,7 @@ TTeamMenuItem::_Init(BList* team, BBitmap* icon, char* 
name, char* signature,
        font.GetHeight(&fontHeight);
        fLabelAscent = ceilf(fontHeight.ascent);
        fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading);
+       fLabelHeight = fLabelAscent + fLabelDescent;
 
        fOverriddenSelected = false;
 
diff --git a/src/apps/deskbar/TeamMenuItem.h b/src/apps/deskbar/TeamMenuItem.h
index e8f770eabd..011fa7c849 100644
--- a/src/apps/deskbar/TeamMenuItem.h
+++ b/src/apps/deskbar/TeamMenuItem.h
@@ -44,6 +44,9 @@ All rights reserved.
 #include "TruncatableMenuItem.h"
 
 
+const float kSwitchWidth = 12.0f;
+
+
 class BBitmap;
 class TBarView;
 class TWindowMenuItem;
@@ -108,6 +111,7 @@ private:
                        float                           fLabelWidth;
                        float                           fLabelAscent;
                        float                           fLabelDescent;
+                       float                           fLabelHeight;
 
                        bool                            fOverriddenSelected;
 
diff --git a/src/apps/deskbar/TimeView.cpp b/src/apps/deskbar/TimeView.cpp
index ce462fd2fc..05c9aec551 100644
--- a/src/apps/deskbar/TimeView.cpp
+++ b/src/apps/deskbar/TimeView.cpp
@@ -52,6 +52,9 @@ All rights reserved.
 #include <Window.h>
 
 #include "BarApp.h"
+#include "BarView.h"
+#include "BarWindow.h"
+#include "StatusView.h"
 #include "CalendarMenuWindow.h"
 #include "StatusView.h"
 
@@ -185,16 +188,21 @@ TTimeView::FrameMoved(BPoint)
 void
 TTimeView::GetPreferredSize(float* width, float* height)
 {
-       *height = fHeight;
-
        float timeWidth = StringWidth(fCurrentTimeStr);
 
-       if (fOrientation) {
+       // set the height based on the font size
+       font_height fontHeight;
+       GetFontHeight(&fontHeight);
+       fHeight = fontHeight.ascent + fontHeight.descent;
+
+       if (Vertical()) {
                float appWidth = 
static_cast<TBarApp*>(be_app)->Settings()->width;
                *width = fMaxWidth
                        = std::min(appWidth - (kDragRegionWidth + kHMargin) * 
2, timeWidth);
        } else
                *width = fMaxWidth = timeWidth;
+
+       *height = fHeight;
 }
 
 
@@ -418,7 +426,8 @@ TTimeView::UpdateTimeFormat()
 
        delete fTimeFormat;
        fTimeFormat = new BDateTimeFormat(BLocale::Default());
-       fTimeFormat->SetDateTimeFormat(B_SHORT_DATE_FORMAT, 
B_SHORT_TIME_FORMAT, fields);
+       fTimeFormat->SetDateTimeFormat(B_SHORT_DATE_FORMAT, B_SHORT_TIME_FORMAT,
+               fields);
 
        delete fDateFormat;
        fDateFormat = new BDateFormat(BLocale::Default());
@@ -454,8 +463,6 @@ TTimeView::GetCurrentDate()
 void
 TTimeView::CalculateTextPlacement()
 {
-       BRect bounds(Bounds());
-
        fDateLocation.x = 0.0;
        fTimeLocation.x = 0.0;
 
@@ -469,7 +476,8 @@ TTimeView::CalculateTextPlacement()
        font.GetBoundingBoxesForStrings(stringArray, 1, B_SCREEN_METRIC, &delta,
                rectArray);
 
-       fTimeLocation.y = fDateLocation.y = ceilf((bounds.Height()
+       // center vertically
+       fTimeLocation.y = fDateLocation.y = ceilf((Bounds().Height()
                - rectArray[0].Height() + 1.0) / 2.0 - rectArray[0].top);
 
        if (fOrientation) {
diff --git a/src/apps/deskbar/TimeView.h b/src/apps/deskbar/TimeView.h
index db269519c5..4f01976ee4 100644
--- a/src/apps/deskbar/TimeView.h
+++ b/src/apps/deskbar/TimeView.h
@@ -66,7 +66,6 @@ const uint32 kShowTimeZone = 'SwTz';
 const uint32 kGetClockSettings = 'GCkS';
 
 
-
 class BCountry;
 class BMessageRunner;
 class CalendarMenuWindow;
diff --git a/src/apps/deskbar/TruncatableMenuItem.cpp 
b/src/apps/deskbar/TruncatableMenuItem.cpp
index 542b4d013c..c9a5420731 100644
--- a/src/apps/deskbar/TruncatableMenuItem.cpp
+++ b/src/apps/deskbar/TruncatableMenuItem.cpp
@@ -47,7 +47,6 @@ All rights reserved.
 
 
 const float kVPad = 2.0f;
-const float kSwitchWidth = 12.0f;
 
 
 //     #pragma mark - TTruncatableMenuItem



Other related posts:

  • » [haiku-commits] haiku: hrev53890 - src/apps/deskbar - waddlesplash