diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index 66397046a9..b3308c4099 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -74,7 +74,6 @@ const uint32 kShowDeskbarMenu = 'BeMn'; const uint32 kShowTeamMenu = 'TmMn'; -const BRect kIconRect(0.0f, 0.0f, 15.0f, 15.0f); static const color_space kIconFormat = B_RGBA32; @@ -215,6 +214,8 @@ TBarApp::SaveSettings() storedSettings.AddBool("sortRunningApps", fSettings.sortRunningApps); storedSettings.AddBool("superExpando", fSettings.superExpando); storedSettings.AddBool("expandNewTeams", fSettings.expandNewTeams); + storedSettings.AddBool("hideLabels", fSettings.hideLabels); + storedSettings.AddInt32("iconSize", fSettings.iconSize); storedSettings.AddBool("autoRaise", fSettings.autoRaise); storedSettings.AddBool("autoHide", fSettings.autoHide); storedSettings.AddBool("recentAppsEnabled", @@ -251,6 +252,8 @@ TBarApp::InitSettings() settings.sortRunningApps = false; settings.superExpando = false; settings.expandNewTeams = false; + settings.hideLabels = false; + settings.iconSize = kMinimumIconSize; settings.autoRaise = false; settings.autoHide = false; settings.recentAppsEnabled = true; @@ -301,6 +304,8 @@ TBarApp::InitSettings() &settings.sortRunningApps); storedSettings.FindBool("superExpando", &settings.superExpando); storedSettings.FindBool("expandNewTeams", &settings.expandNewTeams); + storedSettings.FindBool("hideLabels", &settings.hideLabels); + storedSettings.FindInt32("iconSize", (int32*)&settings.iconSize); storedSettings.FindBool("autoRaise", &settings.autoRaise); storedSettings.FindBool("autoHide", &settings.autoHide); storedSettings.FindBool("recentAppsEnabled", @@ -484,6 +489,36 @@ TBarApp::MessageReceived(BMessage* message) fBarWindow->Unlock(); break; + case kHideLabels: + fSettings.hideLabels = !fSettings.hideLabels; + + fBarWindow->Lock(); + BarView()->UpdatePlacement(); + fBarWindow->Unlock(); + break; + + case kResizeTeamIcons: + { + int32 iconSize; + + if (message->FindInt32("be:value", &iconSize) < B_OK) + break; + + fSettings.iconSize = iconSize * kIconSizeInterval; + + if (fSettings.iconSize < kMinimumIconSize) + fSettings.iconSize = kMinimumIconSize; + else if (fSettings.iconSize > kMaximumIconSize) + fSettings.iconSize = kMaximumIconSize; + + ResizeTeamIcons(); + + fBarWindow->Lock(); + BarView()->UpdatePlacement(); + fBarWindow->Unlock(); + break; + } + case 'TASK': fSwitcherMessenger.SendMessage(message); break; @@ -647,11 +682,13 @@ TBarApp::AddTeam(team_id team, uint32 flags, const char* sig, entry_ref* ref) name = ref->name; BarTeamInfo* barInfo = new BarTeamInfo(new BList(), flags, strdup(sig), - new BBitmap(kIconRect, kIconFormat), strdup(name.String())); + new BBitmap(IconRect(), kIconFormat), strdup(ref->name)); + + if ((barInfo->flags & B_BACKGROUND_APP) == 0 + && strcasecmp(barInfo->sig, kDeskbarSignature) != 0) + FetchAppIcon(barInfo->sig, barInfo->icon); barInfo->teams->AddItem((void*)team); - if (appMime.GetIcon(barInfo->icon, B_MINI_ICON) != B_OK) - appMime.GetTrackerIcon(barInfo->icon, B_MINI_ICON); sBarTeamInfoList.AddItem(barInfo); @@ -715,6 +752,27 @@ TBarApp::RemoveTeam(team_id team) } +void +TBarApp::ResizeTeamIcons() +{ + for (int32 i = 0; i < sBarTeamInfoList.CountItems(); i++) { + BarTeamInfo* barInfo = (BarTeamInfo*)sBarTeamInfoList.ItemAt(i); + if ((barInfo->flags & B_BACKGROUND_APP) == 0 + && strcasecmp(barInfo->sig, kDeskbarSignature) != 0) { + barInfo->icon = new BBitmap(IconRect(), kIconFormat); + FetchAppIcon(barInfo->sig, barInfo->icon); + } + } +} + + +int32 +TBarApp::IconSize() +{ + return fSettings.iconSize; +} + + void TBarApp::ShowPreferencesWindow() { @@ -727,6 +785,31 @@ TBarApp::ShowPreferencesWindow() } +void +TBarApp::FetchAppIcon(const char* signature, BBitmap* icon) +{ + app_info appInfo; + + if (be_roster->GetAppInfo(signature, &appInfo) == B_OK) { + BFile file(&appInfo.ref, B_READ_ONLY); + BAppFileInfo appMime(&file); + icon_size size = icon->Bounds().IntegerHeight() >= 32 + ? B_LARGE_ICON : B_MINI_ICON; + + if (appMime.GetIcon(icon, size) != B_OK) + appMime.GetTrackerIcon(icon, size); + } +} + + +BRect +TBarApp::IconRect() +{ + int32 iconSize = IconSize(); + return BRect(0, 0, iconSize - 1, iconSize - 1); +} + + // #pragma mark - @@ -758,4 +841,3 @@ BarTeamInfo::~BarTeamInfo() delete icon; free(name); } - diff --git a/src/apps/deskbar/BarApp.h b/src/apps/deskbar/BarApp.h index 736e638a0a..693fd88324 100644 --- a/src/apps/deskbar/BarApp.h +++ b/src/apps/deskbar/BarApp.h @@ -80,6 +80,8 @@ const uint32 kTrackerFirst = 'TkFt'; const uint32 kSortRunningApps = 'SAps'; const uint32 kSuperExpando = 'SprE'; const uint32 kExpandNewTeams = 'ExTm'; +const uint32 kHideLabels = 'hLbs'; +const uint32 kResizeTeamIcons = 'RTIs'; const uint32 kAutoRaise = 'AtRs'; const uint32 kAutoHide = 'AtHd'; const uint32 kRestartTracker = 'Trak'; @@ -89,6 +91,11 @@ const uint32 kShutdownSystem = 301; const uint32 kRebootSystem = 302; const uint32 kSuspendSystem = 304; +// icon size constants +const int32 kMinimumIconSize = 16; +const int32 kMaximumIconSize = 96; +const int32 kIconSizeInterval = 8; + /* --------------------------------------------- */ struct desk_settings { @@ -110,6 +117,8 @@ struct desk_settings { bool sortRunningApps; bool superExpando; bool expandNewTeams; + bool hideLabels; + int32 iconSize; bool autoRaise; bool autoHide; bool recentAppsEnabled; @@ -128,7 +137,7 @@ class TBarApp : public BApplication { TBarApp(); virtual ~TBarApp(); - virtual bool QuitRequested(); + virtual bool QuitRequested(); virtual void MessageReceived(BMessage* message); virtual void RefsReceived(BMessage* refs); @@ -141,6 +150,7 @@ class TBarApp : public BApplication { static void Subscribe(const BMessenger &subscriber, BList*); static void Unsubscribe(const BMessenger &subscriber); + int32 IconSize(); private: void AddTeam(team_id team, uint32 flags, const char* sig, entry_ref*); @@ -150,6 +160,9 @@ class TBarApp : public BApplication { void SaveSettings(); void ShowPreferencesWindow(); + void ResizeTeamIcons(); + void FetchAppIcon(const char* signature, BBitmap* icon); + BRect IconRect(); TBarWindow* fBarWindow; BMessenger fSwitcherMessenger; diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 7c39e9f151..c588b2c0b2 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -293,6 +293,7 @@ TBarView::PlaceDeskbarMenu() BRect menuFrame(fBarMenuBar->Frame()); if (fState == kFullState) { fBarMenuBar->RemoveTeamMenu(); + // TODO: Magic constants need explanation width = 8 + 16 + 8; loc = Bounds().LeftTop(); } else if (fState == kExpandoState) { @@ -381,15 +382,18 @@ TBarView::PlaceApplicationBar(BRect screenFrame) } else { // top or bottom expandoFrame.top = 0; - expandoFrame.bottom = kHModeHeight; + int32 iconSize = static_cast(be_app)->IconSize(); + expandoFrame.bottom = iconSize + 4; if (fTrayLocation != 0) expandoFrame.right = fDragRegion->Frame().left - 1; else expandoFrame.right = screenFrame.Width(); } + bool hideLabels = ((TBarApp*)be_app)->Settings()->hideLabels; + fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", - fVertical, fState != kFullState); + fVertical, !hideLabels && fState != kFullState); AddChild(fExpando); } @@ -401,6 +405,7 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height) float windowWidth = sMinimumWindowWidth; bool calcHiddenSize = ((TBarApp*)be_app)->Settings()->autoHide && IsHidden() && !DragRegion()->IsDragging(); + int32 iconSize = static_cast(be_app)->IconSize(); if (!calcHiddenSize) { if (fState == kFullState) { @@ -413,7 +418,7 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height) } else { // top or bottom, full fExpando->CheckItemSizes(0); - windowHeight = kHModeHeight; + windowHeight = iconSize + 4; windowWidth = screenFrame.Width(); } } else { @@ -429,6 +434,7 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height) if (fState == kExpandoState && !fVertical) { // top or bottom, full fExpando->CheckItemSizes(0); + windowHeight = iconSize + 4; windowWidth = screenFrame.Width(); } else windowWidth = kHModeHiddenHeight; @@ -1100,6 +1106,7 @@ BRect TBarView::OffsetIconFrame(BRect rect) const { BRect frame(Frame()); + frame.left += fDragRegion->Frame().left + fReplicantTray->Frame().left + rect.left; frame.top += fDragRegion->Frame().top + fReplicantTray->Frame().top diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h index c24d5ae593..f222c18877 100644 --- a/src/apps/deskbar/BarView.h +++ b/src/apps/deskbar/BarView.h @@ -138,11 +138,12 @@ class TBarView : public BView { float* height); void SizeWindow(BRect screenFrame); void PositionWindow(BRect screenFrame); + void AddExpandedItem(const char* signature); TExpandoMenuBar* ExpandoMenuBar() const; TBarMenuBar* BarMenuBar() const; TDragRegion* DragRegion() const { return fDragRegion; } - void AddExpandedItem(const char* signature); + TReplicantTray* ReplicantTray() const { return fReplicantTray; } private: friend class TDeskbarMenu; diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index eb5e18f921..5a6cba86b5 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -61,6 +61,7 @@ All rights reserved. const float kDefaultDeskbarMenuWidth = 50.0f; const float kSepItemWidth = 5.0f; +const float kIconPadding = 8.0f; const uint32 kMinimizeTeam = 'mntm'; const uint32 kBringTeamToFront = 'bftm'; @@ -90,7 +91,15 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* bar, BRect frame, const char* name, { SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f); SetFont(be_plain_font); - SetMaxContentWidth(sMinimumWindowWidth); + if (fVertical) + SetMaxContentWidth(sMinimumWindowWidth); + else { + // Make more room for the icon in horizontal mode + int32 iconSize = static_cast(be_app)->IconSize(); + float maxContentWidth = sMinimumWindowWidth + iconSize + - kMinimumIconSize; + SetMaxContentWidth(maxContentWidth); + } } @@ -108,8 +117,20 @@ TExpandoMenuBar::AttachedToWindow() BMessenger self(this); BList teamList; TBarApp::Subscribe(self, &teamList); - float width = fVertical ? Frame().Width() : sMinimumWindowWidth; - float height = -1.0f; + int32 iconSize = static_cast(be_app)->IconSize(); + desk_settings* settings = static_cast(be_app)->Settings(); + + float itemWidth = -0.1f; + if (fVertical) { + itemWidth = Frame().Width(); + } else { + itemWidth = iconSize; + if (fDrawLabel) + itemWidth += sMinimumWindowWidth - kMinimumIconSize; + else + itemWidth += kIconPadding * 2; + } + float itemHeight = -1.0f; // top or bottom mode, add deskbar menu and sep for menubar tracking // consistency @@ -124,7 +145,7 @@ TExpandoMenuBar::AttachedToWindow() logoBitmap, beMenu, true); AddItem(fDeskbarMenuItem); - fSeparatorItem = new TTeamMenuItem(kSepItemWidth, height, fVertical); + fSeparatorItem = new TTeamMenuItem(kSepItemWidth, itemHeight, fVertical); AddItem(fSeparatorItem); fSeparatorItem->SetEnabled(false); fFirstApp = 2; @@ -133,8 +154,6 @@ TExpandoMenuBar::AttachedToWindow() fSeparatorItem = NULL; } - desk_settings* settings = ((TBarApp*)be_app)->Settings(); - if (settings->sortRunningApps) teamList.SortItems(CompareByName); @@ -146,11 +165,11 @@ TExpandoMenuBar::AttachedToWindow() if (settings->trackerAlwaysFirst && !strcmp(barInfo->sig, kTrackerSignature)) { AddItem(new TTeamMenuItem(barInfo->teams, barInfo->icon, - barInfo->name, barInfo->sig, width, height, + barInfo->name, barInfo->sig, itemWidth, itemHeight, fDrawLabel, fVertical), fFirstApp); } else { AddItem(new TTeamMenuItem(barInfo->teams, barInfo->icon, - barInfo->name, barInfo->sig, width, height, + barInfo->name, barInfo->sig, itemWidth, itemHeight, fDrawLabel, fVertical)); } @@ -168,7 +187,7 @@ TExpandoMenuBar::AttachedToWindow() if (CountItems() == 0) { // If we're empty, BMenuBar::AttachedToWindow() resizes us to some // weird value - we just override it again - ResizeTo(width, 0); + ResizeTo(itemWidth, 0); } if (fVertical) { @@ -500,11 +519,21 @@ void TExpandoMenuBar::AddTeam(BList* team, BBitmap* icon, char* name, char* signature) { - float itemWidth = fVertical ? fBarView->Bounds().Width() - : sMinimumWindowWidth; + desk_settings* settings = static_cast(be_app)->Settings(); + int32 iconSize = static_cast(be_app)->IconSize(); + + float itemWidth = -1.0f; + if (fVertical) { + itemWidth = fBarView->Bounds().Width(); + } else { + itemWidth = iconSize; + if (fDrawLabel) + itemWidth += sMinimumWindowWidth - kMinimumIconSize; + else + itemWidth += kIconPadding * 2; + } float itemHeight = -1.0f; - desk_settings* settings = ((TBarApp*)be_app)->Settings(); TTeamMenuItem* item = new TTeamMenuItem(team, icon, name, signature, itemWidth, itemHeight, fDrawLabel, fVertical); @@ -558,7 +587,6 @@ TExpandoMenuBar::AddTeam(team_id team, const char* signature) if (strcasecmp(item->Signature(), signature) == 0) { if (!(item->Teams()->HasItem((void*)team))) item->Teams()->AddItem((void*)team); - break; } } @@ -607,39 +635,48 @@ TExpandoMenuBar::RemoveTeam(team_id team, bool partial) void TExpandoMenuBar::CheckItemSizes(int32 delta) { - float width = Frame().Width(); - int32 count = CountItems(); + if (fBarView->Vertical()) + return; + + int32 iconSize = static_cast(be_app)->IconSize(); + float maxContentWidth = sMinimumWindowWidth + iconSize - kMinimumIconSize; + + // There are 2 extra items: + // The Be Menu + // The little separator item + int32 count = CountItems() - 2; + float maxWidth = Frame().Width() - fDeskbarMenuWidth - kSepItemWidth * 2; + float fullWidth = maxContentWidth * count + fDeskbarMenuWidth + + kSepItemWidth; + float iconOnlyWidth = kIconPadding + iconSize + kIconPadding; + bool reset = false; - float newWidth = 0; - float fullWidth = (sMinimumWindowWidth * count); + float newWidth = 0.0f; - if (!fBarView->Vertical()) { - // in this case there are 2 extra items: - // - The Be Menu - // - The little separator item - fullWidth = fullWidth - (sMinimumWindowWidth * 2) - + (fDeskbarMenuWidth + kSepItemWidth); - width -= (fDeskbarMenuWidth + kSepItemWidth); - count -= 2; - } - - if (delta >= 0 && fullWidth > width) { + if (delta >= 0 && fullWidth > maxWidth) { fOverflow = true; reset = true; - newWidth = floorf(width / count); + if (fDrawLabel) + newWidth = floorf(maxWidth / count); + else + newWidth = iconOnlyWidth; } else if (delta < 0 && fOverflow) { reset = true; - if (fullWidth > width) - newWidth = floorf(width / count); - else - newWidth = sMinimumWindowWidth; + if (fullWidth > maxWidth) { + if (fDrawLabel) + newWidth = floorf(maxWidth / count); + else + newWidth = iconOnlyWidth; + } else + newWidth = maxContentWidth; } - if (newWidth > sMinimumWindowWidth) - newWidth = sMinimumWindowWidth; + + if (newWidth > maxContentWidth) + newWidth = maxContentWidth; if (reset) { SetMaxContentWidth(newWidth); - if (newWidth == sMinimumWindowWidth) + if (newWidth == maxContentWidth) fOverflow = false; InvalidateLayout(); @@ -647,7 +684,12 @@ TExpandoMenuBar::CheckItemSizes(int32 delta) TTeamMenuItem* item = (TTeamMenuItem*)ItemAt(index); if (!item) break; - item->SetOverrideWidth(newWidth); + + if (!fDrawLabel && newWidth > iconOnlyWidth) { + item->SetOverrideWidth(iconOnlyWidth); + } else { + item->SetOverrideWidth(newWidth); + } } Invalidate(); diff --git a/src/apps/deskbar/PreferencesWindow.cpp b/src/apps/deskbar/PreferencesWindow.cpp index ebc4077f25..8140a872fd 100644 --- a/src/apps/deskbar/PreferencesWindow.cpp +++ b/src/apps/deskbar/PreferencesWindow.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -55,6 +56,17 @@ PreferencesWindow::PreferencesWindow(BRect frame) new BMessage(kSuperExpando)); fAppsExpandNew = new BCheckBox(B_TRANSLATE("Expand new applications"), new BMessage(kExpandNewTeams)); + fAppsHideLabels = new BCheckBox(B_TRANSLATE("Hide application names"), + new BMessage(kHideLabels)); + fAppsIconSizeSlider = new BSlider("icon_size", B_TRANSLATE("Icon size"), + NULL, kMinimumIconSize / kIconSizeInterval, + kMaximumIconSize / kIconSizeInterval, B_HORIZONTAL); + fAppsIconSizeSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); + fAppsIconSizeSlider->SetHashMarkCount((kMaximumIconSize - kMinimumIconSize) + / kIconSizeInterval + 1); + fAppsIconSizeSlider->SetLimitLabels(B_TRANSLATE("Small"), + B_TRANSLATE("Large")); + fAppsIconSizeSlider->SetModificationMessage(new BMessage(kResizeTeamIcons)); fClockSeconds = new BCheckBox(B_TRANSLATE("Show seconds"), new BMessage(kShowSeconds)); @@ -89,6 +101,8 @@ PreferencesWindow::PreferencesWindow(BRect frame) fAppsSortTrackerFirst->SetValue(appSettings->trackerAlwaysFirst); fAppsShowExpanders->SetValue(appSettings->superExpando); fAppsExpandNew->SetValue(appSettings->expandNewTeams); + fAppsHideLabels->SetValue(appSettings->hideLabels); + fAppsIconSizeSlider->SetValue(appSettings->iconSize / kIconSizeInterval); int32 docCount = appSettings->recentDocsCount; int32 appCount = appSettings->recentAppsCount; @@ -132,6 +146,8 @@ PreferencesWindow::PreferencesWindow(BRect frame) fAppsSort->SetTarget(be_app); fAppsSortTrackerFirst->SetTarget(be_app); fAppsExpandNew->SetTarget(be_app); + fAppsHideLabels->SetTarget(be_app); + fAppsIconSizeSlider->SetTarget(be_app); fClockSeconds->SetTarget(replicantTray); @@ -181,6 +197,8 @@ PreferencesWindow::PreferencesWindow(BRect frame) .SetInsets(20, 0, 0, 0) .Add(fAppsExpandNew) .End() + .Add(fAppsIconSizeSlider) + .Add(fAppsHideLabels) .AddGlue() .SetInsets(10, 10, 10, 10) .End() diff --git a/src/apps/deskbar/PreferencesWindow.h b/src/apps/deskbar/PreferencesWindow.h index df50663558..4f1891f1d3 100644 --- a/src/apps/deskbar/PreferencesWindow.h +++ b/src/apps/deskbar/PreferencesWindow.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -52,6 +53,8 @@ private: BCheckBox* fAppsSortTrackerFirst; BCheckBox* fAppsShowExpanders; BCheckBox* fAppsExpandNew; + BCheckBox* fAppsHideLabels; + BSlider* fAppsIconSizeSlider; BCheckBox* fClockSeconds; diff --git a/src/apps/deskbar/StatusView.cpp b/src/apps/deskbar/StatusView.cpp index bead5e5a32..dbac254282 100644 --- a/src/apps/deskbar/StatusView.cpp +++ b/src/apps/deskbar/StatusView.cpp @@ -107,7 +107,7 @@ DumpList(BList* itemlist) printf("no items in list\n"); return; } - for (int32 i = count ; i >= 0 ; i--) { + for (int32 i = count; i >= 0; i--) { DeskbarItemInfo* item = (DeskbarItemInfo*)itemlist->ItemAt(i); if (!item) continue; @@ -193,7 +193,7 @@ TReplicantTray::DetachedFromWindow() void TReplicantTray::RememberClockSettings() { - if (fClock) { + if (fClock) { desk_settings* settings = ((TBarApp*)be_app)->Settings(); settings->timeShowSeconds = fClock->ShowingSeconds(); @@ -240,8 +240,7 @@ TReplicantTray::DealWithClock(bool showClock) /*! Width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth if not in multirowmode and greater than kMinimumReplicantCount - the width should be calculated based on the actual - replicant widths + the width should be calculated based on the actual replicant widths */ void TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight) @@ -262,8 +261,8 @@ TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight) } else { // if last replicant overruns clock then resize to accomodate if (fShelf->CountReplicants() > 0) { - if (fBarView->ShowingClock() - && fRightBottomReplicant.right + 6 >= fClock->Frame().left) { + if (fBarView->ShowingClock() && fRightBottomReplicant.right + 6 + >= fClock->Frame().left) { width = fRightBottomReplicant.right + 6 + fClock->Frame().Width(); } else @@ -272,6 +271,7 @@ TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight) // this view has a fixed minimum width width = max(fMinimumTrayWidth, width); + height = kGutter + static_cast(be_app)->IconSize() + kGutter; } *preferredWidth = width; @@ -1095,8 +1095,8 @@ TReplicantTray::LocationForReplicant(int32 index, float width) // try to find free space in every row for (int32 row = 0; ; loc.y += kMaxReplicantHeight + kIconGap, row++) { // determine free space in this row - BRect rect(loc.x, loc.y, loc.x + fMinimumTrayWidth - kIconGap - 2.0, - loc.y + kMaxReplicantHeight); + BRect rect(loc.x, loc.y, loc.x + fMinimumTrayWidth - kIconGap + - 2.0, loc.y + kMaxReplicantHeight); if (row == 0 && fBarView->ShowingClock()) rect.right -= fClock->Frame().Width() + kIconGap; diff --git a/src/apps/deskbar/StatusView.h b/src/apps/deskbar/StatusView.h index fbfc6c4720..138114dc73 100644 --- a/src/apps/deskbar/StatusView.h +++ b/src/apps/deskbar/StatusView.h @@ -48,15 +48,16 @@ All rights reserved. const float kMaxReplicantHeight = 16.0f; const float kMaxReplicantWidth = 16.0f; const int32 kMinimumReplicantCount = 6; -const int32 kIconGap = 2; +const int32 kIconGap = 2; const int32 kGutter = 1; const int32 kDragRegionWidth = 6; -// 1 pixel left gutter +// 1 pixel for left gutter // space for replicant tray (6 items) // 6 pixel drag region -const float kMinimumTrayWidth = kIconGap + (kMinimumReplicantCount * kIconGap) - + (kMinimumReplicantCount * kMaxReplicantWidth) + kGutter; +const float kMinimumTrayWidth = kIconGap + + (kMinimumReplicantCount * kIconGap) + + (kMinimumReplicantCount * kMaxReplicantWidth) + kGutter; const float kMinimumTrayHeight = kGutter + kMaxReplicantHeight + kGutter; extern float sMinimumWindowWidth; diff --git a/src/apps/deskbar/TeamMenu.cpp b/src/apps/deskbar/TeamMenu.cpp index e22c83eb61..fcf3400d0d 100644 --- a/src/apps/deskbar/TeamMenu.cpp +++ b/src/apps/deskbar/TeamMenu.cpp @@ -86,7 +86,8 @@ TTeamMenu::AttachedToWindow() if (((barInfo->flags & B_BACKGROUND_APP) == 0) && (strcasecmp(barInfo->sig, kDeskbarSignature) != 0)) { TTeamMenuItem* item = new TTeamMenuItem(barInfo->teams, - barInfo->icon, barInfo->name, barInfo->sig, -1, -1, true, true); + barInfo->icon, barInfo->name, barInfo->sig, -1, -1, + !settings->hideLabels, true); if ((settings->trackerAlwaysFirst) && (strcmp(barInfo->sig, kTrackerSignature) == 0)) diff --git a/src/apps/deskbar/TeamMenuItem.cpp b/src/apps/deskbar/TeamMenuItem.cpp index a3f361953a..982d19d552 100644 --- a/src/apps/deskbar/TeamMenuItem.cpp +++ b/src/apps/deskbar/TeamMenuItem.cpp @@ -107,8 +107,8 @@ TTeamMenuItem::InitData(BList* team, BBitmap* icon, char* name, char* sig, fOverrideHeight = height; fOverriddenSelected = false; - fDrawLabel = drawLabel; fVertical = vertical; + fDrawLabel = drawLabel; fExpanded = false; } @@ -127,21 +127,21 @@ status_t TTeamMenuItem::Invoke(BMessage* message) { if ((static_cast(be_app))->BarView()->InvokeItem(Signature())) - // handles drop on application + // handles drop on application return B_OK; - // if the app could not handle the drag message - // and we were dragging, then kill the drag - // should never get here, disabled item will not invoke - TBarView* barview = (static_cast(be_app))->BarView(); - if (barview && barview->Dragging()) - barview->DragStop(); + // if the app could not handle the drag message + // and we were dragging, then kill the drag + // should never get here, disabled item will not invoke + TBarView* barView = (static_cast(be_app))->BarView(); + if (barView && barView->Dragging()) + barView->DragStop(); // bring to front or minimize shortcuts uint32 mods = modifiers(); if (mods & B_CONTROL_KEY) { TShowHideMenuItem::TeamShowHideCommon((mods & B_SHIFT_KEY) - ? B_MINIMIZE_WINDOW : B_BRING_TO_FRONT, Teams()); + ? B_MINIMIZE_WINDOW : B_BRING_TO_FRONT, Teams()); } return BMenuItem::Invoke(message); @@ -170,6 +170,13 @@ TTeamMenuItem::SetOverrideSelected(bool selected) } +void +TTeamMenuItem::SetDrawLabel(bool drawLabel) +{ + fDrawLabel = drawLabel; +} + + float TTeamMenuItem::LabelWidth() const { @@ -206,24 +213,28 @@ TTeamMenuItem::GetContentSize(float* width, float* height) if (fIcon) iconBounds = fIcon->Bounds(); else - iconBounds = BRect(0, 0, 15, 15); + iconBounds = BRect(0, 0, kMinimumIconSize - 1, kMinimumIconSize - 1); BMenuItem::GetContentSize(width, height); if (fOverrideWidth != -1.0f) *width = fOverrideWidth; - else - *width = kHPad + iconBounds.Width() + kLabelOffset + fLabelWidth + kHPad - + 20; + else { + *width = kHPad + iconBounds.Width() + kHPad; + if (iconBounds.Width() <= 32 && fDrawLabel) + *width += LabelWidth() + kHPad; + } if (fOverrideHeight != -1.0f) *height = fOverrideHeight; else { - *height = iconBounds.Height(); - float labelHeight = fLabelAscent + fLabelDescent; - if (labelHeight > *height) - *height = labelHeight; - *height += (kVPad * 2) + 2; + if (fVertical) { + *height = iconBounds.Height() + kVPad * 4; + if (fDrawLabel && iconBounds.Width() > 32) + *height += fLabelAscent + fLabelDescent; + } else { + *height = iconBounds.Height() - kVPad * 8; + } } *height += 2; } @@ -236,10 +247,10 @@ TTeamMenuItem::Draw() BMenu* menu = Menu(); menu->PushState(); rgb_color menuColor = menu->LowColor(); - TBarView* barview = (static_cast(be_app))->BarView(); + TBarView* barView = (static_cast(be_app))->BarView(); - bool canHandle = !barview->Dragging() - || barview->AppCanHandleTypes(Signature()); + bool canHandle = !barView->Dragging() + || barView->AppCanHandleTypes(Signature()); if (be_control_look != NULL) { uint32 flags = 0; @@ -275,7 +286,7 @@ TTeamMenuItem::Draw() return; } - // if not selected or being tracked on, fill with gray + // if not selected or being tracked on, fill with gray if ((!_IsSelected() && !menu->IsRedrawAfterSticky()) || !canHandle || !IsEnabled()) { frame.InsetBy(1, 1); @@ -283,7 +294,7 @@ TTeamMenuItem::Draw() menu->FillRect(frame); } - // draw the gray, unselected item, border + // draw the gray, unselected item, border if (!_IsSelected() || !IsEnabled()) { rgb_color shadow = tint_color(menuColor, B_DARKEN_1_TINT); rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); @@ -308,7 +319,7 @@ TTeamMenuItem::Draw() menu->StrokeLine(frame.LeftTop(), frame.LeftBottom()); } - // if selected or being tracked on, fill with the hilite gray color + // if selected or being tracked on, fill with the hilite gray color if (IsEnabled() && _IsSelected() && !menu->IsRedrawAfterSticky() && canHandle) { // fill @@ -337,7 +348,7 @@ void TTeamMenuItem::DrawContent() { BMenu* menu = Menu(); - if (fIcon) { + if (fIcon != NULL) { if (fIcon->ColorSpace() == B_RGBA32) { menu->SetDrawingMode(B_OP_ALPHA); menu->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); @@ -347,17 +358,33 @@ TTeamMenuItem::DrawContent() BRect frame(Frame()); BRect iconBounds(fIcon->Bounds()); BRect dstRect(iconBounds); - float extra = fVertical ? 0.0f : 1.0f; + float extra = fVertical ? 0.0f : -1.0f; BPoint contLoc = ContentLocation(); - - dstRect.OffsetTo(BPoint(contLoc.x + kHPad, contLoc.y + - ((frame.Height() - iconBounds.Height()) / 2) + extra)); - menu->DrawBitmapAsync(fIcon, dstRect); - - float labelHeight = fLabelAscent + fLabelDescent; BPoint drawLoc = contLoc + BPoint(kHPad, kVPad); - drawLoc.x += iconBounds.Width() + kLabelOffset; - drawLoc.y = frame.top + ((frame.Height() - labelHeight) / 2) + 1.0f; + + if (!fDrawLabel || (fVertical && iconBounds.Width() > 32)) { + float offsetx = contLoc.x + + ((frame.Width() - iconBounds.Width()) / 2) + extra; + float offsety = contLoc.y + 3.0f + extra; + + dstRect.OffsetTo(BPoint(offsetx, offsety)); + menu->DrawBitmapAsync(fIcon, dstRect); + + drawLoc.x = ((frame.Width() - LabelWidth()) / 2); + drawLoc.y = frame.top + iconBounds.Height() + 4.0f; + } else { + float offsetx = contLoc.x + kHPad; + float offsety = contLoc.y + + ((frame.Height() - iconBounds.Height()) / 2) + extra; + + dstRect.OffsetTo(BPoint(offsetx, offsety)); + menu->DrawBitmapAsync(fIcon, dstRect); + + float labelHeight = fLabelAscent + fLabelDescent; + drawLoc.x += iconBounds.Width() + kLabelOffset; + drawLoc.y = frame.top + ((frame.Height() - labelHeight) / 2) + extra; + } + menu->MovePenTo(drawLoc); } @@ -449,10 +476,10 @@ TTeamMenuItem::DrawContentLabel() char* truncLabel = NULL; float max = 0; - if (static_cast(be_app)->Settings()->superExpando && fVertical) + if (fVertical && static_cast(be_app)->Settings()->superExpando) max = menu->MaxContentWidth() - kSwitchWidth; else - max = menu->MaxContentWidth(); + max = menu->MaxContentWidth() - 4.0f; if (max > 0) { BPoint penloc = menu->PenLocation(); diff --git a/src/apps/deskbar/TeamMenuItem.h b/src/apps/deskbar/TeamMenuItem.h index 9bfd28bb24..851d0299b1 100644 --- a/src/apps/deskbar/TeamMenuItem.h +++ b/src/apps/deskbar/TeamMenuItem.h @@ -62,6 +62,7 @@ class TTeamMenuItem : public BMenuItem { void SetOverrideWidth(float width); void SetOverrideHeight(float height); void SetOverrideSelected(bool selected); + void SetDrawLabel(bool drawLabel); bool IsExpanded(); void ToggleExpandState(bool resizeWindow); diff --git a/src/apps/deskbar/TimeView.cpp b/src/apps/deskbar/TimeView.cpp index f6d50bba31..96a79365b3 100644 --- a/src/apps/deskbar/TimeView.cpp +++ b/src/apps/deskbar/TimeView.cpp @@ -332,13 +332,8 @@ TTimeView::Pulse() Update(); strlcpy(fLastTimeStr, fTimeStr, sizeof(fLastTimeStr)); - fNeedToUpdate = true; - } - - // Update the tooltip if the date has changed - if (strcmp(fDateStr, fLastDateStr) != 0) { strlcpy(fLastDateStr, fDateStr, sizeof(fLastDateStr)); - SetToolTip(fDateStr); + fNeedToUpdate = true; } if (fNeedToUpdate) {