diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index c795a92d24..4189654acd 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -126,13 +126,11 @@ TBarApp::TBarApp() } sSubscribers.MakeEmpty(); - fSwitcherMessenger = BMessenger(new TSwitchManager(fSettings.switcherLoc)); - fBarWindow->Show(); - // Call UpdatePlacement() after the window is shown because expanded apps - // need to resize the window. + // Call UpdatePlacement() after the window is shown because expanded + // apps need to resize the window. if (fBarWindow->Lock()) { fBarView->UpdatePlacement(); fBarWindow->Unlock(); @@ -578,11 +576,13 @@ TBarApp::MessageReceived(BMessage* message) break; fBarWindow->Lock(); - if (fBarView->Vertical()) - fBarView->PlaceApplicationBar(); - else - fBarView->UpdatePlacement(); - + if (!fBarView->Vertical()) { + // Must also resize the Deskbar menu and replicant tray in + // horizontal mode + fBarView->PlaceDeskbarMenu(); + fBarView->PlaceTray(false, false); + } + fBarView->PlaceApplicationBar(); fBarWindow->Unlock(); if (fPreferencesWindow != NULL) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 2c0fb4f97e..67ef95f309 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -130,11 +130,12 @@ BarViewMessageFilter::Filter(BMessage* message, BHandler** target) TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, - uint32 state, float) - : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), + uint32 state, float) + : + BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), fInlineScrollView(NULL), fBarMenuBar(NULL), - fExpando(NULL), + fExpandoMenuBar(NULL), fTrayLocation(1), fVertical(vertical), fTop(top), @@ -153,6 +154,15 @@ TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, fDragRegion->AddChild(fReplicantTray); if (fTrayLocation != 0) AddChild(fDragRegion); + + fExpandoMenuBar = new TExpandoMenuBar(BRect(0, 0, 0, 0), + "ExpandoMenuBar", fVertical); + fInlineScrollView = new TInlineScrollView(BRect(0, 0, 0, 0), + fExpandoMenuBar, fVertical ? B_VERTICAL : B_HORIZONTAL); + AddChild(fInlineScrollView); + + if (state == kMiniState) + fInlineScrollView->Hide(); } @@ -177,8 +187,6 @@ TBarView::AttachedToWindow() fMouseFilter = new BarViewMessageFilter(this); Window()->AddCommonFilter(fMouseFilter); - UpdatePlacement(); - fTrackingHookData.fTrackingHook = MenuTrackingHook; fTrackingHookData.fTarget = BMessenger(this); fTrackingHookData.fDragMessage = new BMessage(B_REFS_RECEIVED); @@ -211,7 +219,7 @@ TBarView::Draw(BRect) if (fVertical && fState == kExpandoState) { SetHighColor(hilite); - BRect frame(fExpando->Frame()); + BRect frame(fExpandoMenuBar->Frame()); StrokeLine(BPoint(frame.left, frame.top - 1), BPoint(frame.right, frame.top -1)); } @@ -450,22 +458,10 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap) void TBarView::PlaceApplicationBar() { - SaveExpandedItems(); - - if (fInlineScrollView != NULL) { - fInlineScrollView->DetachScrollers(); - fInlineScrollView->RemoveSelf(); - delete fInlineScrollView; - fInlineScrollView = NULL; - } - - if (fExpando != NULL) { - delete fExpando; - fExpando = NULL; - } - BRect screenFrame = (BScreen(Window())).Frame(); if (fState == kMiniState) { + if (!fInlineScrollView->IsHidden()) + fInlineScrollView->Hide(); SizeWindow(screenFrame); PositionWindow(screenFrame); Window()->UpdateIfNeeded(); @@ -473,23 +469,25 @@ TBarView::PlaceApplicationBar() return; } + if (fInlineScrollView->IsHidden()) + fInlineScrollView->Show(); + BRect expandoFrame(0, 0, 0, 0); - BRect menuScrollFrame(0, 0, 0, 0); if (fVertical) { - // top left/right - if (fTrayLocation != 0) + // left or right + if (fTrayLocation != 0) { expandoFrame.top = fDragRegion->Frame().bottom + 1; - else + expandoFrame.left = fDragRegion->Frame().left; + } else { expandoFrame.top = fBarMenuBar->Frame().bottom + 1; + expandoFrame.left = fDragRegion->Frame().left; + } - expandoFrame.bottom = expandoFrame.top + 1; + expandoFrame.right = expandoFrame.left + sMinimumWindowWidth; if (fState == kFullState) - expandoFrame.right = fBarMenuBar->Frame().Width(); + expandoFrame.bottom = screenFrame.bottom; else - expandoFrame.right = sMinimumWindowWidth; - - menuScrollFrame = expandoFrame; - menuScrollFrame.bottom = screenFrame.bottom; + expandoFrame.bottom = expandoFrame.top + 1; } else { // top or bottom expandoFrame.top = 0; @@ -504,28 +502,25 @@ TBarView::PlaceApplicationBar() - fDragRegion->Frame().Width() - 1; } else expandoFrame.right = screenFrame.Width(); - - menuScrollFrame = expandoFrame; } - bool hideLabels = ((TBarApp*)be_app)->Settings()->hideLabels; - - fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", - fVertical, !hideLabels && fState != kFullState); - - fInlineScrollView = new TInlineScrollView(menuScrollFrame, fExpando, - fVertical ? B_VERTICAL : B_HORIZONTAL); - AddChild(fInlineScrollView); + fInlineScrollView->DetachScrollers(); + fInlineScrollView->MoveTo(expandoFrame.LeftTop()); + fInlineScrollView->ResizeTo(expandoFrame.Width(), fVertical + ? screenFrame.bottom - expandoFrame.top + : expandoFrame.Height()); + fExpandoMenuBar->MoveTo(0, 0); + fExpandoMenuBar->ResizeTo(expandoFrame.Width(), expandoFrame.Height()); + fExpandoMenuBar->BuildItems(); if (fVertical) ExpandItems(); SizeWindow(screenFrame); PositionWindow(screenFrame); - fExpando->DoLayout(); + fExpandoMenuBar->DoLayout(); // force menu to autosize CheckForScrolling(); - Window()->UpdateIfNeeded(); Invalidate(); } @@ -545,7 +540,7 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height) if (fState == kExpandoState && !fVertical) { // top or bottom, full - fExpando->CheckItemSizes(0); + fExpandoMenuBar->CheckItemSizes(0); windowWidth = screenFrame.Width(); } else windowWidth = kHiddenDimension; @@ -561,10 +556,10 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height) else windowHeight = fBarMenuBar->Frame().bottom + 1; - windowHeight += fExpando->Bounds().Height(); + windowHeight += fExpandoMenuBar->Bounds().Height(); } else { // top or bottom, full - fExpando->CheckItemSizes(0); + fExpandoMenuBar->CheckItemSizes(0); windowHeight = iconSize + 4; windowWidth = screenFrame.Width(); } @@ -617,8 +612,8 @@ TBarView::PositionWindow(BRect screenFrame) void TBarView::CheckForScrolling() { - if (fInlineScrollView != NULL && fExpando != NULL) { - if (fExpando->CheckForSizeOverrun()) + if (fInlineScrollView != NULL && fExpandoMenuBar != NULL) { + if (fExpandoMenuBar->CheckForSizeOverrun()) fInlineScrollView->AttachScrollers(); else fInlineScrollView->DetachScrollers(); @@ -668,14 +663,14 @@ TBarView::ChangeState(int32 state, bool vertical, bool left, bool top, void TBarView::SaveExpandedItems() { - if (fExpando == NULL || fExpando->CountItems() <= 0) + if (fExpandoMenuBar == NULL || fExpandoMenuBar->CountItems() <= 0) return; // Get a list of the signatures of expanded apps. Can't use // team_id because there can be more than one team per application - for (int32 i = 0; i < fExpando->CountItems(); i++) { + for (int32 i = 0; i < fExpandoMenuBar->CountItems(); i++) { TTeamMenuItem* teamItem - = dynamic_cast(fExpando->ItemAt(i)); + = dynamic_cast(fExpandoMenuBar->ItemAt(i)); if (teamItem != NULL && teamItem->IsExpanded()) AddExpandedItem(teamItem->Signature()); @@ -695,20 +690,20 @@ TBarView::RemoveExpandedItems() void TBarView::ExpandItems() { - if (fExpando == NULL || !fVertical || fState != kExpandoState + if (fExpandoMenuBar == NULL || !fVertical || fState != kExpandoState || !static_cast(be_app)->Settings()->superExpando || fExpandedItems.CountItems() <= 0) return; // Start at the 'bottom' of the list working up. // Prevents being thrown off by expanding items. - for (int32 i = fExpando->CountItems() - 1; i >= 0; i--) { + for (int32 i = fExpandoMenuBar->CountItems() - 1; i >= 0; i--) { TTeamMenuItem* teamItem - = dynamic_cast(fExpando->ItemAt(i)); + = dynamic_cast(fExpandoMenuBar->ItemAt(i)); if (teamItem != NULL) { // Start at the 'bottom' of the fExpandedItems list working up - // matching the order of the fExpando list in the outer loop. + // matching the order of the fExpandoMenuBar list in the outer loop. for (int32 j = fExpandedItems.CountItems() - 1; j >= 0; j--) { BString* itemSig = static_cast(fExpandedItems.ItemAt(j)); @@ -747,10 +742,33 @@ TBarView::_ChangeState(BMessage* message) fLeft = left; fTop = top; - // Send a message to the preferences window to let it know to enable - // or disable preference items - if (stateChanged || vertSwap) + SaveExpandedItems(); + + if (stateChanged || vertSwap) { be_app->PostMessage(kStateChanged); + // Send a message to the preferences window to let it know to + // enable or disable preference items. + + // If switching to expando state, rebuild expando menu bar. + if (fState == kExpandoState) { + if (fInlineScrollView != NULL) { + fInlineScrollView->DetachScrollers(); + fInlineScrollView->RemoveSelf(); + delete fInlineScrollView; + fInlineScrollView = NULL; + } + if (fExpandoMenuBar != NULL) { + delete fExpandoMenuBar; + fExpandoMenuBar = NULL; + } + + fExpandoMenuBar = new TExpandoMenuBar(BRect(0, 0, 0, 0), + "ExpandoMenuBar", fVertical); + fInlineScrollView = new TInlineScrollView(BRect(0, 0, 0, 0), + fExpandoMenuBar, fVertical ? B_VERTICAL : B_HORIZONTAL); + AddChild(fInlineScrollView); + } + } PlaceDeskbarMenu(); PlaceTray(vertSwap, leftSwap); @@ -847,10 +865,10 @@ TBarView::DragStart() uint32 buttons; GetMouse(&loc, &buttons); - if (fExpando && fExpando->Frame().Contains(loc)) { + if (fExpandoMenuBar && fExpandoMenuBar->Frame().Contains(loc)) { ConvertToScreen(&loc); - BPoint expandoLocation = fExpando->ConvertFromScreen(loc); - TTeamMenuItem* item = fExpando->TeamItemAtPoint(expandoLocation); + BPoint expandoLocation = fExpandoMenuBar->ConvertFromScreen(loc); + TTeamMenuItem* item = fExpandoMenuBar->TeamItemAtPoint(expandoLocation); if (fLastDragItem) init_tracking_hook(fLastDragItem, NULL, NULL); @@ -940,8 +958,8 @@ TBarView::DragStop(bool full) if (!Dragging()) return; - if (fExpando) { - if (fLastDragItem) { + if (fExpandoMenuBar != NULL) { + if (fLastDragItem != NULL) { init_tracking_hook(fLastDragItem, NULL, NULL); fLastDragItem = NULL; } diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h index d04586775e..3f9b1445b6 100644 --- a/src/apps/deskbar/BarView.h +++ b/src/apps/deskbar/BarView.h @@ -172,7 +172,7 @@ class TBarView : public BView { TInlineScrollView* fInlineScrollView; TBarMenuBar* fBarMenuBar; - TExpandoMenuBar* fExpando; + TExpandoMenuBar* fExpandoMenuBar; int32 fTrayLocation; TDragRegion* fDragRegion; @@ -202,7 +202,7 @@ class TBarView : public BView { inline TExpandoMenuBar* TBarView::ExpandoMenuBar() const { - return fExpando; + return fExpandoMenuBar; } diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index 6c23498f6e..3bfa307fb4 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -45,6 +45,7 @@ All rights reserved. #include #include #include +#include #include "icons.h" @@ -75,18 +76,17 @@ thread_id TExpandoMenuBar::sMonThread = B_ERROR; BLocker TExpandoMenuBar::sMonLocker("expando monitor"); -TExpandoMenuBar::TExpandoMenuBar(TBarView* bar, BRect frame, const char* name, - bool vertical, bool drawLabel) +TExpandoMenuBar::TExpandoMenuBar(BRect frame, const char* name, bool vertical) : BMenuBar(frame, name, B_FOLLOW_NONE, vertical ? B_ITEMS_IN_COLUMN : B_ITEMS_IN_ROW), fVertical(vertical), fOverflow(false), - fDrawLabel(drawLabel), + fDrawLabel(!static_cast(be_app)->Settings()->hideLabels), fShowTeamExpander(static_cast(be_app)->Settings()->superExpando), fExpandNewTeams(static_cast(be_app)->Settings()->expandNewTeams), fDeskbarMenuWidth(kMinMenuItemWidth), - fBarView(bar), + fBarView(NULL), fPreviousDragTargetItem(NULL), fLastClickItem(NULL) { @@ -101,6 +101,13 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* bar, BRect frame, const char* name, - kMinimumIconSize; SetMaxContentWidth(maxContentWidth); } + + // top or bottom mode, add deskbar menu and sep for menubar tracking + // consistency + const BBitmap* logoBitmap = AppResSet()->FindBitmap(B_MESSAGE_TYPE, + R_LeafLogoBitmap); + if (logoBitmap != NULL) + fDeskbarMenuWidth = logoBitmap->Bounds().Width() + 16; } @@ -115,68 +122,10 @@ TExpandoMenuBar::CompareByName(const void* first, const void* second) void TExpandoMenuBar::AttachedToWindow() { - BMessenger self(this); - BList teamList; - TBarApp::Subscribe(self, &teamList); - 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 - if (!fVertical) { - const BBitmap* logoBitmap = AppResSet()->FindBitmap(B_MESSAGE_TYPE, - R_LeafLogoBitmap); - if (logoBitmap != NULL) - fDeskbarMenuWidth = logoBitmap->Bounds().Width() + 16; - } - - if (settings->sortRunningApps) - teamList.SortItems(CompareByName); - - int32 count = teamList.CountItems(); - for (int32 i = 0; i < count; i++) { - BarTeamInfo* barInfo = (BarTeamInfo*)teamList.ItemAt(i); - if ((barInfo->flags & B_BACKGROUND_APP) == 0 - && strcasecmp(barInfo->sig, kDeskbarSignature) != 0) { - if (settings->trackerAlwaysFirst - && !strcmp(barInfo->sig, kTrackerSignature)) { - AddItem(new TTeamMenuItem(barInfo->teams, barInfo->icon, - barInfo->name, barInfo->sig, itemWidth, itemHeight, - fDrawLabel, fVertical), 0); - } else { - AddItem(new TTeamMenuItem(barInfo->teams, barInfo->icon, - barInfo->name, barInfo->sig, itemWidth, itemHeight, - fDrawLabel, fVertical)); - } - - barInfo->teams = NULL; - barInfo->icon = NULL; - barInfo->name = NULL; - barInfo->sig = NULL; - } - - delete barInfo; - } - BMenuBar::AttachedToWindow(); - if (CountItems() == 0) { - // If we're empty, BMenuBar::AttachedToWindow() resizes us to some - // weird value - we just override it again - ResizeTo(itemWidth, 0); - } + fBarView = static_cast(Window())->BarView(); + fTeamList.MakeEmpty(); if (fVertical) { sDoMonitor = true; @@ -525,6 +474,70 @@ TExpandoMenuBar::MouseUp(BPoint where) } +void +TExpandoMenuBar::BuildItems() +{ + BMessenger self(this); + TBarApp::Subscribe(self, &fTeamList); + + int32 iconSize = static_cast(be_app)->IconSize(); + desk_settings* settings = static_cast(be_app)->Settings(); + fDrawLabel = !settings->hideLabels; + fShowTeamExpander = settings->superExpando; + fExpandNewTeams = settings->expandNewTeams; + + 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; + + RemoveItems(0, CountItems(), true); + // remove all items + + if (settings->sortRunningApps) + fTeamList.SortItems(CompareByName); + + int32 count = fTeamList.CountItems(); + for (int32 i = 0; i < count; i++) { + // add them again + BarTeamInfo* barInfo = (BarTeamInfo*)fTeamList.ItemAt(i); + if ((barInfo->flags & B_BACKGROUND_APP) == 0 + && strcasecmp(barInfo->sig, kDeskbarSignature) != 0) { + if (settings->trackerAlwaysFirst + && !strcmp(barInfo->sig, kTrackerSignature)) { + AddItem(new TTeamMenuItem(barInfo->teams, barInfo->icon, + barInfo->name, barInfo->sig, itemWidth, itemHeight, + fDrawLabel, fVertical), 0); + } else { + AddItem(new TTeamMenuItem(barInfo->teams, barInfo->icon, + barInfo->name, barInfo->sig, itemWidth, itemHeight, + fDrawLabel, fVertical)); + } + + barInfo->teams = NULL; + barInfo->icon = NULL; + barInfo->name = NULL; + barInfo->sig = NULL; + } + + delete barInfo; + } + + if (CountItems() == 0) { + // If we're empty, BMenuBar::AttachedToWindow() resizes us to some + // weird value - we just override it again + ResizeTo(itemWidth, 0); + } +} + + bool TExpandoMenuBar::InDeskbarMenu(BPoint loc) const { @@ -636,7 +649,6 @@ TExpandoMenuBar::AddTeam(BList* team, BBitmap* icon, char* name, } SizeWindow(1); - Window()->UpdateIfNeeded(); } @@ -676,11 +688,8 @@ TExpandoMenuBar::RemoveTeam(team_id team, bool partial) #endif RemoveItem(i); - SizeWindow(-1); - Window()->UpdateIfNeeded(); - delete item; return; } diff --git a/src/apps/deskbar/ExpandoMenuBar.h b/src/apps/deskbar/ExpandoMenuBar.h index b50a085d08..f23af5dc68 100644 --- a/src/apps/deskbar/ExpandoMenuBar.h +++ b/src/apps/deskbar/ExpandoMenuBar.h @@ -61,18 +61,21 @@ enum drag_and_drop_selection { class TExpandoMenuBar : public BMenuBar { public: - TExpandoMenuBar(TBarView* bar, BRect frame, const char* name, - bool vertical, bool drawLabel = true); + TExpandoMenuBar(BRect frame, const char* name, bool vertical); virtual void AttachedToWindow(); virtual void DetachedFromWindow(); + + virtual void Draw(BRect update); + virtual void DrawBackground(BRect update); + virtual void MessageReceived(BMessage* message); + virtual void MouseDown(BPoint where); virtual void MouseMoved(BPoint where, uint32 code, const BMessage*); virtual void MouseUp(BPoint where); - virtual void Draw(BRect update); - virtual void DrawBackground(BRect update); + void BuildItems(); TTeamMenuItem* TeamItemAtPoint(BPoint location, BMenuItem** _item = NULL); @@ -109,6 +112,7 @@ class TExpandoMenuBar : public BMenuBar { BMenuItem* fLastMousedOverItem; BMenuItem* fLastClickItem; + BList fTeamList; static bool sDoMonitor; static thread_id sMonThread;