diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index 6a480c1188..303afcfe6e 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -118,15 +118,15 @@ TBarApp::TBarApp() sSubscribers.MakeEmpty(); - fSwitcherMess = BMessenger(new TSwitchMgr(fSettings.switcherLoc)); + fSwitcherMessenger = BMessenger(new TSwitchManager(fSettings.switcherLoc)); fBarWindow = new TBarWindow(); fBarWindow->Show(); - // this messenger now targets the barview instead of the - // statusview so that all additions to the tray - // follow the same path - fStatusViewMess = BMessenger(fBarWindow->FindView("BarView")); + // this messenger now targets the barview instead of the + // statusview so that all additions to the tray + // follow the same path + fStatusViewMessenger = BMessenger(fBarWindow->FindView("BarView")); } @@ -372,8 +372,9 @@ TBarApp::MessageReceived(BMessage *message) } case B_ARCHIVED_OBJECT: + // TODO: what's this??? message->AddString("special", "Alex Osadzinski"); - fStatusViewMess.SendMessage(message); + fStatusViewMessenger.SendMessage(message); break; case msg_Be: @@ -459,7 +460,7 @@ TBarApp::MessageReceived(BMessage *message) } case 'TASK': - fSwitcherMess.SendMessage(message); + fSwitcherMessenger.SendMessage(message); break; #if __HAIKU__ diff --git a/src/apps/deskbar/BarApp.h b/src/apps/deskbar/BarApp.h index d0adcd68b1..3e262b9771 100644 --- a/src/apps/deskbar/BarApp.h +++ b/src/apps/deskbar/BarApp.h @@ -31,14 +31,15 @@ of Be Incorporated in the United States and other countries. Other brand product names are registered trademarks or trademarks of their respective holders. All rights reserved. */ - #ifndef BAR_APP_H #define BAR_APP_H + #include #include #include "BarWindow.h" + /* ------------------------------------ */ // Private app_server defines that I need to use @@ -46,6 +47,7 @@ All rights reserved. #define _FLOATER_W_TYPE_ 4 #define _STD_W_TYPE_ 0 + class BarTeamInfo { public: BarTeamInfo(BList *teams, uint32 flags, char *sig, BBitmap *icon, @@ -86,7 +88,7 @@ const uint32 CMD_SUSPEND_SYSTEM = 304; // if you want to extend this structure, maintain the // constants below (used in TBarApp::InitSettings()) -struct desk_settings { +struct desk_settings { bool vertical; // version 1 bool left; bool top; @@ -126,53 +128,49 @@ class TBarView; class BFile; namespace BPrivate { - -class TFavoritesConfigWindow; - + class TFavoritesConfigWindow; } using namespace BPrivate; class TBarApp : public BApplication { -public: - TBarApp(); - virtual ~TBarApp(); + public: + TBarApp(); + virtual ~TBarApp(); - virtual bool QuitRequested(); - virtual void MessageReceived(BMessage *); + virtual bool QuitRequested(); + virtual void MessageReceived(BMessage *); - desk_settings *Settings() - { return &fSettings; }; - TBarView *BarView() const - { return fBarWindow->BarView(); }; - - static void Subscribe(const BMessenger &subscriber, BList *); - static void Unsubscribe(const BMessenger &subscriber); - -private: - void AddTeam(team_id team, uint32 flags, const char *sig, entry_ref *); - void RemoveTeam(team_id); + desk_settings *Settings() + { return &fSettings; } + TBarView *BarView() const + { return fBarWindow->BarView(); } + TBarWindow *BarWindow() const + { return fBarWindow; } - void InitSettings(); - void SaveSettings(); - - void ShowConfigWindow(); + static void Subscribe(const BMessenger &subscriber, BList *); + static void Unsubscribe(const BMessenger &subscriber); -#if __HAIKU__ - static int32 _shutdown(void* cookie); -#endif + private: + void AddTeam(team_id team, uint32 flags, const char *sig, entry_ref *); + void RemoveTeam(team_id); - TBarWindow *fBarWindow; - BMessenger fSwitcherMess; - BMessenger fStatusViewMess; - BFile *fSettingsFile; - desk_settings fSettings; - - TFavoritesConfigWindow *fConfigWindow; - - static BLocker sSubscriberLock; - static BList sBarTeamInfoList; - static BList sSubscribers; + void InitSettings(); + void SaveSettings(); + + void ShowConfigWindow(); + + TBarWindow *fBarWindow; + BMessenger fSwitcherMessenger; + BMessenger fStatusViewMessenger; + BFile *fSettingsFile; + desk_settings fSettings; + + TFavoritesConfigWindow *fConfigWindow; + + static BLocker sSubscriberLock; + static BList sBarTeamInfoList; + static BList sSubscribers; }; #endif diff --git a/src/apps/deskbar/BarMenuBar.cpp b/src/apps/deskbar/BarMenuBar.cpp index 64a49534de..65e13f758d 100644 --- a/src/apps/deskbar/BarMenuBar.cpp +++ b/src/apps/deskbar/BarMenuBar.cpp @@ -48,15 +48,15 @@ All rights reserved. TBarMenuBar::TBarMenuBar(TBarView *bar, BRect frame, const char *name) - : BMenuBar(frame, name, B_FOLLOW_NONE, B_ITEMS_IN_ROW, false), - fBarView(bar), - fAppListMenuItem(NULL) + : BMenuBar(frame, name, B_FOLLOW_NONE, B_ITEMS_IN_ROW, false), + fBarView(bar), + fAppListMenuItem(NULL) { SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f); - + TBeMenu *beMenu = new TBeMenu(bar); TBarWindow::SetBeMenu(beMenu); - + fBeMenuItem = new TBarMenuTitle(frame.Width(), frame.Height(), AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_BeLogoIcon), beMenu); AddItem(fBeMenuItem); @@ -71,14 +71,13 @@ TBarMenuBar::~TBarMenuBar() void TBarMenuBar::SmartResize(float width, float height) { - if ((width == -1.0f) && (height == -1.0f)) { + if (width == -1.0f && height == -1.0f) { BRect frame = Frame(); width = frame.Width(); height = frame.Height(); } else ResizeTo(width, height); - width -= 1; int32 count = CountItems(); @@ -99,7 +98,7 @@ TBarMenuBar::AddTeamMenu() BRect frame(Frame()); delete fAppListMenuItem; - + fAppListMenuItem = new TBarMenuTitle(0.0f, 0.0f, AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_TeamIcon), new TTeamMenu()); AddItem(fAppListMenuItem); @@ -118,7 +117,7 @@ TBarMenuBar::RemoveTeamMenu() delete fAppListMenuItem; fAppListMenuItem = NULL; } - + BRect frame = Frame(); SmartResize(frame.Width(), frame.Height()); } @@ -139,50 +138,53 @@ TBarMenuBar::DrawBackground(BRect rect) } -// the following code parallels that in ExpandoMenuBar for DnD tracking void TBarMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage *message) { + // the following code parallels that in ExpandoMenuBar for DnD tracking + if (!message) { - // force a cleanup + // force a cleanup fBarView->DragStop(true); BMenuBar::MouseMoved(where, code, message); return; } - + switch (code) { case B_ENTERED_VIEW: - { - BPoint loc; - uint32 buttons; - GetMouse(&loc, &buttons); - // attempt to start Dnd tracking - if (message && buttons != 0) { - fBarView->CacheDragData(const_cast(message)); - MouseDown(loc); - } + { + BPoint loc; + uint32 buttons; + GetMouse(&loc, &buttons); + // attempt to start DnD tracking + if (message && buttons != 0) { + fBarView->CacheDragData(const_cast(message)); + MouseDown(loc); } break; + } } BMenuBar::MouseMoved(where, code, message); } static void -init_tracking_hook(BMenuItem *item,bool (*hookfunction)(BMenu *, void *), void *state) +init_tracking_hook(BMenuItem *item, bool (*hookFunction)(BMenu *, void *), + void *state) { if (!item) return; - - BMenu *windowmenu = item->Submenu(); - if (windowmenu) + + BMenu *windowMenu = item->Submenu(); + if (windowMenu) // have a menu, set the tracking hook - windowmenu->SetTrackingHook(hookfunction, state); + windowMenu->SetTrackingHook(hookFunction, state); } void -TBarMenuBar::InitTrackingHook(bool (*hookfunction)(BMenu *, void *), void *state, bool both) +TBarMenuBar::InitTrackingHook(bool (*hookFunction)(BMenu *, void *), + void *state, bool both) { BPoint loc; uint32 buttons; @@ -191,8 +193,8 @@ TBarMenuBar::InitTrackingHook(bool (*hookfunction)(BMenu *, void *), void *state // will always have the be menu // may have the app menu as well (mini mode) if (fBeMenuItem->Frame().Contains(loc) || both) - init_tracking_hook(fBeMenuItem, hookfunction, state); + init_tracking_hook(fBeMenuItem, hookFunction, state); if (fAppListMenuItem && (fAppListMenuItem->Frame().Contains(loc) || both)) - init_tracking_hook(fAppListMenuItem, hookfunction, state); + init_tracking_hook(fAppListMenuItem, hookFunction, state); } diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 59765a988c..503dda0c95 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -110,13 +110,7 @@ TBarView::AttachedToWindow() SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); SetFont(be_plain_font); - -#if SA_CLOCK - fClock = new TTimeView(this, false, false, false, false, fShowInterval); - if (fShowClock) - AddChild(fClock); -#endif - + fReplicantTray = new TReplicantTray(this, fVertical); fDragRegion = new TDragRegion(this, fReplicantTray); fDragRegion->AddChild(fReplicantTray); @@ -241,7 +235,7 @@ TBarView::PlaceTray(bool, bool, BRect screenFrame) if (!fReplicantTray->IsHidden()) fReplicantTray->Hide(); - + return; } @@ -254,12 +248,7 @@ TBarView::PlaceTray(bool, bool, BRect screenFrame) fDragRegion->ResizeToPreferred(); if (fVertical) { -#if SA_CLOCK - if (fShowClock) - statusLoc.y = fClock->Frame().bottom + 1; - else -#endif - statusLoc.y = fBarMenuBar->Frame().bottom + 1; + statusLoc.y = fBarMenuBar->Frame().bottom + 1; statusLoc.x = 0; if (Left() && Vertical()) fReplicantTray->MoveTo(5, 2); @@ -275,38 +264,6 @@ TBarView::PlaceTray(bool, bool, BRect screenFrame) } -#if SA_CLOCK -void -TBarView::PlaceClock() -{ - if (fState == kFullState) { - if (!fClock->IsHidden()) - fClock->Hide(); - return; - } - - if (fShowClock) { - fClock->SetOrientation(fVertical); - - BPoint loc; - if (fVertical) { - fClock->ResizeTo(kMinimumWindowWidth, kMenuBarHeight); - loc.x = 0; - loc.y = fBarMenuBar->Frame().bottom + 1; - } else { - float width, height; - fClock->GetPreferredSize(&width, &height); - fClock->ResizeTo(width, kMenuBarHeight); - loc = fDragRegion->Frame().LeftTop(); - loc.x -= fClock->Frame().Width(); - loc.y = 0; - } - fClock->MoveTo(loc); - } -} -#endif - - void TBarView::PlaceApplicationBar(BRect screenFrame) { @@ -324,12 +281,7 @@ TBarView::PlaceApplicationBar(BRect screenFrame) if (fTrayLocation != 0) expandoFrame.top = fDragRegion->Frame().bottom + 2; else { -#if SA_CLOCK - if (fShowClock) - expandoFrame.top = fClock->Frame().bottom + 2; - else -#endif - expandoFrame.top = fBarMenuBar->Frame().bottom + 2; + expandoFrame.top = fBarMenuBar->Frame().bottom + 2; } expandoFrame.bottom = expandoFrame.top + 1; @@ -342,12 +294,7 @@ TBarView::PlaceApplicationBar(BRect screenFrame) expandoFrame.top = -1; expandoFrame.bottom = kHModeHeight; if (fTrayLocation != 0) { -#if SA_CLOCK - if (fShowClock) - expandoFrame.right = fClock->Frame().left; - else -#endif - expandoFrame.right = fDragRegion->Frame().left; + expandoFrame.right = fDragRegion->Frame().left; } else expandoFrame.right = screenFrame.Width(); @@ -463,17 +410,7 @@ TBarView::ChangeState(int32 state, bool vertical, bool left, bool top) BRect screenFrame = (BScreen(Window())).Frame(); PlaceBeMenu(); - if (fVertical){ -#if SA_CLOCK - PlaceClock(); // tray dependent on clock location -#endif - PlaceTray(vertSwap, leftSwap, screenFrame); - } else { - PlaceTray(vertSwap, leftSwap, screenFrame); -#if SA_CLOCK - PlaceClock(); // clock is dependent on tray location -#endif - } + PlaceTray(vertSwap, leftSwap, screenFrame); // We need to keep track of what apps are expanded. BList expandedItems; @@ -601,25 +538,7 @@ TBarView::ShowingClock() const } -#if SA_CLOCK -void -TBarView::ToggleClock() -{ - fShowClock = !fShowClock; - -#if SA_CLOCK - if (fShowClock) - AddChild(fClock); - else - fClock->RemoveSelf(); -#endif - - UpdatePlacement(); -} -#endif - - -// Drag and Drop +// #pragma mark - Drag and Drop void TBarView::CacheDragData(BMessage *incoming) @@ -920,7 +839,7 @@ TBarView::HandleBeMenu(BMessage *messagewithdestination) } -// Add-on convenience functions +// #pragma mark - Add-ons // shelf is ignored for now, // it exists in anticipation of having other 'shelves' for diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h index 956da1ffdb..50474124e4 100644 --- a/src/apps/deskbar/BarView.h +++ b/src/apps/deskbar/BarView.h @@ -57,16 +57,11 @@ const float kHModeHeight = 21.0f; const float kMenuBarHeight = 21.0f; const float kStatusHeight = 22.0f; -#define SA_CLOCK 0 - class BShelf; class TBarMenuBar; class TExpandoMenuBar; class TReplicantTray; class TDragRegion; -#if SA_CLOCK -class TTimeView; -#endif class TTeamMenuItem; @@ -95,9 +90,6 @@ class TBarView : public BView { bool MilTime() const; void ShowClock(bool); bool ShowingClock() const; - #if SA_CLOCK - void ToggleClock(); - #endif void CacheDragData(BMessage *incoming); status_t DragStart(); @@ -144,9 +136,6 @@ class TBarView : public BView { void PlaceBeMenu(); void PlaceTray(bool vertSwap, bool leftSwap, BRect screenFrame); - #if SA_CLOCK - void PlaceClock(); - #endif void PlaceApplicationBar(BRect screenFrame); TBarMenuBar *fBarMenuBar; @@ -158,9 +147,6 @@ class TBarView : public BView { bool fShowInterval; bool fShowClock; - #if SA_CLOCK - TTimeView *fClock; - #endif bool fVertical; bool fTop; bool fLeft; diff --git a/src/apps/deskbar/BarWindow.cpp b/src/apps/deskbar/BarWindow.cpp index 18db86b4d2..cb84662778 100644 --- a/src/apps/deskbar/BarWindow.cpp +++ b/src/apps/deskbar/BarWindow.cpp @@ -86,9 +86,6 @@ TBarWindow::TBarWindow() AddChild(fBarView); AddShortcut('F', B_COMMAND_KEY, new BMessage(kFindButton)); -#if SA_CLOCK - AddShortcut('H', B_COMMAND_KEY, new BMessage('clok')); -#endif } @@ -164,12 +161,6 @@ TBarWindow::MessageReceived(BMessage *message) break; } -#if SA_CLOCK - case 'clok': - fBarView->ToggleClock(); - break; -#endif - case 'gloc': GetLocation(message); break; diff --git a/src/apps/deskbar/BeMenu.cpp b/src/apps/deskbar/BeMenu.cpp index a1ad1358a8..2ec13a1db0 100644 --- a/src/apps/deskbar/BeMenu.cpp +++ b/src/apps/deskbar/BeMenu.cpp @@ -88,8 +88,8 @@ using namespace BPrivate; TBeMenu::TBeMenu(TBarView *barview) : BNavMenu("BeMenu", B_REFS_RECEIVED, BMessenger(kTrackerSignature)), - fAddState(kStart), - fBarView(barview) + fAddState(kStart), + fBarView(barview) { } @@ -128,10 +128,8 @@ TBeMenu::DetachedFromWindow() } } - // - // don't call BNavMenu::DetachedFromWindow - // it sets the TypesList to NULL - // + // don't call BNavMenu::DetachedFromWindow + // it sets the TypesList to NULL BMenu::DetachedFromWindow(); } @@ -185,7 +183,7 @@ TBeMenu::AddNextItem() } if (count > 0) { AddSeparatorItem(); - + for (int i = 0;i < recentTypes;i++) { if (!recentItem[i]) continue; @@ -207,10 +205,10 @@ TBeMenu::AddNextItem() fAddState = kAddingBeMenu; return true; } - + if (fAddState == kAddingBeMenu) { - // keep reentering and adding items - // until this returns false + // keep reentering and adding items + // until this returns false bool done = BNavMenu::AddNextItem(); BMenuItem *item = ItemAt(CountItems() - 1); if (item) { @@ -228,7 +226,7 @@ TBeMenu::AddNextItem() fAddState = kDone; return done; } - + return false; } @@ -236,9 +234,10 @@ TBeMenu::AddNextItem() bool TBeMenu::AddStandardBeMenuItems() { - bool dragging=false; + bool dragging = false; if (fBarView) dragging = fBarView->Dragging(); + #ifdef __HAIKU__ BMenuItem* item = new BMenuItem("About Haiku", new BMessage(kShowSplash)); #else @@ -246,7 +245,7 @@ TBeMenu::AddStandardBeMenuItems() #endif item->SetEnabled(!dragging); AddItem(item); - + #ifdef SHOW_RECENT_FIND_ITEMS item = new BMenuItem(TrackerBuildRecentFindItemsMenu("Find"B_UTF8_ELLIPSIS), new BMessage(kFindButton)); @@ -278,21 +277,22 @@ TBeMenu::AddStandardBeMenuItems() item = new BMenuItem("Always on Top", new BMessage(msg_AlwaysTop)); item->SetTarget(be_app); // set checkbox based on current state of Deskbar's main window feel - item->SetMarked((be_app->WindowAt(1)->Feel() & B_FLOATING_ALL_WINDOW_FEEL) != 0); + if (BWindow *window = static_cast(be_app)->BarWindow()) + item->SetMarked((window->Feel() & B_FLOATING_ALL_WINDOW_FEEL) != 0); subMenu->AddItem(item); item = new BMenuItem("Sort Running Applications", new BMessage(msg_sortRunningApps)); item->SetTarget(be_app); - item->SetMarked( static_cast(be_app)->Settings()->sortRunningApps); + item->SetMarked(static_cast(be_app)->Settings()->sortRunningApps); subMenu->AddItem(item); item = new BMenuItem("Tracker Always First", new BMessage(msg_trackerFirst)); item->SetTarget(be_app); - item->SetMarked( static_cast(be_app)->Settings()->trackerAlwaysFirst); + item->SetMarked(static_cast(be_app)->Settings()->trackerAlwaysFirst); subMenu->AddItem(item); subMenu->AddSeparatorItem(); - + TReplicantTray *replicantTray = ((TBarApp *)be_app)->BarView()->fReplicantTray; item = new BMenuItem("24 Hour Clock", new BMessage(kMsgMilTime)); @@ -323,17 +323,17 @@ TBeMenu::AddStandardBeMenuItems() item = new BMenuItem("Show Application Expander", new BMessage(msg_superExpando)); item->SetTarget(be_app); - item->SetMarked( static_cast(be_app)->Settings()->superExpando); + item->SetMarked(static_cast(be_app)->Settings()->superExpando); subMenu->AddItem(item); item = new BMenuItem("Expand New Applications", new BMessage(msg_expandNewTeams)); item->SetTarget(be_app); - item->SetMarked( static_cast(be_app)->Settings()->expandNewTeams); + item->SetMarked(static_cast(be_app)->Settings()->expandNewTeams); item->SetEnabled(static_cast(be_app)->Settings()->superExpando); subMenu->AddItem(item); - - subMenu->SetFont(be_plain_font); - AddItem(subMenu); + + subMenu->SetFont(be_plain_font); + AddItem(subMenu); if ((modifiers() & (B_LEFT_SHIFT_KEY|B_LEFT_CONTROL_KEY|B_LEFT_COMMAND_KEY)) == (B_LEFT_SHIFT_KEY|B_LEFT_CONTROL_KEY|B_LEFT_COMMAND_KEY)) { diff --git a/src/apps/deskbar/CalendarMenuItem.cpp b/src/apps/deskbar/CalendarMenuItem.cpp index 5424708ef7..838209e017 100644 --- a/src/apps/deskbar/CalendarMenuItem.cpp +++ b/src/apps/deskbar/CalendarMenuItem.cpp @@ -156,12 +156,12 @@ CalendarMenuItem::GetContentSize(float *_width, float *_height) font.SetSize(kTitleFontSize); font_height fontHeight; font.GetHeight(&fontHeight); - fTitleHeight = ceil(fontHeight.ascent + fontHeight.descent + fontHeight.leading); + fTitleHeight = ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading); font = be_plain_font; font.GetHeight(&fontHeight); - fRowHeight = ceil(fontHeight.ascent + fontHeight.descent + fontHeight.leading + kRowGap); - fFontHeight = ceil(fontHeight.ascent); + fRowHeight = ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading + kRowGap); + fFontHeight = ceilf(fontHeight.ascent); fColumnWidth = font.StringWidth("99") + kColumnGap; fFirstWeekday = first_weekday_of_month(tm); diff --git a/src/apps/deskbar/StatusView.cpp b/src/apps/deskbar/StatusView.cpp index 332f1b5b28..2b70badf4f 100644 --- a/src/apps/deskbar/StatusView.cpp +++ b/src/apps/deskbar/StatusView.cpp @@ -112,8 +112,8 @@ DumpList(BList *itemlist) #endif /* DB_ADDONS */ -// don't change the name of this view to anything other than -// Status +// don't change the name of this view to anything other than "Status"! + TReplicantTray::TReplicantTray(TBarView *parent, bool vertical) : BView(BRect(0, 0, 1, 1), "Status", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS), @@ -136,16 +136,17 @@ void TReplicantTray::AttachedToWindow() { BView::AttachedToWindow(); - + SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); SetDrawingMode(B_OP_COPY); Window()->SetPulseRate(1000000); - DealWithClock(fBarView->ShowingClock()); + DealWithClock(fBarView->ShowingClock()); -#ifdef DB_ADDONS - // load addons and rehydrate archives +#ifdef DB_ADDONS + // load addons and rehydrate archives #if !defined(__HAIKU__) && !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) - InitAddOnSupport(); +// TODO: fix me! + InitAddOnSupport(); #endif #endif ResizeToPreferred(); @@ -156,9 +157,9 @@ void TReplicantTray::DetachedFromWindow() { #ifdef DB_ADDONS - // clean up add-on support + // clean up add-on support DeleteAddOnSupport(); -#endif +#endif BView::DetachedFromWindow(); } @@ -261,43 +262,34 @@ TReplicantTray::GetPreferredSize(float *preferredWidth, float *preferredHeight) { float width = 0, height = kMinimumTrayHeight; - uint32 id; - BView *view; - fShelf->ReplicantAt(IconCount() - 1, &view, &id); if (fMultiRowMode) { - if (view) - height = view->Frame().bottom; - - // the height will be uniform for the number of rows - // necessary to show all the reps + any gutters - // necessary for spacing + if (fShelf->CountReplicants() > 0) + height = fRightBottomReplicant.bottom; + + // the height will be uniform for the number of rows + // necessary to show all the reps + any gutters + // necessary for spacing int32 rowCount = (int32)(height / kMaxReplicantHeight); height = kGutter + (rowCount * kMaxReplicantHeight) + ((rowCount - 1) * kIconGap) + kGutter; - // if new replicant budges into clock's area on clock row, add a row - if (view && fBarView->ShowingClock() - && view->Frame().right >= fClock->Frame().left - && view->Frame().top == fClock->Frame().top) - height += kMaxReplicantHeight; - height = max (kMinimumTrayHeight, height); + height = max(kMinimumTrayHeight, height); width = kMinimumTrayWidth; } else { // if last replicant overruns clock then // resize to accomodate - if (view) { - BRect viewFrame(view->Frame()); + if (fShelf->CountReplicants() > 0) { if (fBarView->ShowingClock() - && viewFrame.right + 6 >= fClock->Frame().left) { - width = viewFrame.right + 6 + fClock->Frame().Width(); + && fRightBottomReplicant.right + 6 >= fClock->Frame().left) { + width = fRightBottomReplicant.right + 6 + fClock->Frame().Width(); } else - width = viewFrame.right + 3; + width = fRightBottomReplicant.right + 3; } - // this view has a fixed minimum width + // this view has a fixed minimum width width = max(kMinimumTrayWidth, width); } *preferredWidth = width; - // add 2 for the border + // add 2 for the border *preferredHeight = height + 1; } @@ -305,10 +297,10 @@ TReplicantTray::GetPreferredSize(float *preferredWidth, float *preferredHeight) void TReplicantTray::AdjustPlacement() { - // called when an add-on has been added or removed - // need to resize the parent of this accordingly + // called when an add-on has been added or removed + // need to resize the parent of this accordingly // - // call to Parent will call ResizeToPreferred + // call to Parent will call ResizeToPreferred BRect bounds = Bounds(); float width, height; GetPreferredSize(&width, &height); @@ -429,14 +421,14 @@ TReplicantTray::MouseDown(BPoint where) do { if (fabs(where.x - save.x) > 4 || fabs(where.y - save.y) > 4) - // user moved out of bounds of click area + // user moved out of bounds of click area break; - + if ((system_time() - start) > (2 * doubleClickSpeed)) { ShowReplicantMenu(where); break; } - + snooze(50000); GetMouse(&where, &buttons); } while (buttons); @@ -479,8 +471,8 @@ TReplicantTray::InitAddOnSupport() file.Write(&fDeskbarSecurityCode, sizeof(fDeskbarSecurityCode)); } } - - // for each volume currently mounted + + // for each volume currently mounted // index the volume with our indices BVolumeRoster roster; BVolume volume; @@ -489,7 +481,7 @@ TReplicantTray::InitAddOnSupport() RunAddOnQuery(&volume, kEnabledPredicate); } - // we also watch for volumes mounted and unmounted + // we also watch for volumes mounted and unmounted watch_node(NULL, B_WATCH_MOUNT | B_WATCH_ATTR, this, Window()); } @@ -508,7 +500,7 @@ TReplicantTray::DeleteAddOnSupport() } delete fItemList; - // stop the volume mount/unmount watch + // stop the volume mount/unmount watch stop_watching(this, Window()); } @@ -533,11 +525,12 @@ TReplicantTray::RunAddOnQuery(BVolume *volume, const char *predicate) int32 id; BEntry entry; - while (query.GetNextEntry(&entry) == B_OK) - // scan any entries returned - // attempt to load them as add-ons - // collisions are handled in LoadAddOn + while (query.GetNextEntry(&entry) == B_OK) { + // scan any entries returned + // attempt to load them as add-ons + // collisions are handled in LoadAddOn LoadAddOn(&entry, &id); + } } @@ -605,19 +598,19 @@ TReplicantTray::HandleEntryUpdate(BMessage *message) BPath path; switch (opcode) { case B_ENTRY_CREATED: - // entry was just listed, matches live query + // entry was just listed, matches live query { const char *name; ino_t directory; dev_t device; - // received when an app adds a ref to the - // Deskbar add-ons folder + // received when an app adds a ref to the + // Deskbar add-ons folder if (message->FindString("name", &name) == B_OK && message->FindInt64("directory", &directory) == B_OK && message->FindInt32("device", &device) == B_OK) { entry_ref ref(device, directory, name); - // see if this item has the attribute - // that we expect + // see if this item has the attribute + // that we expect if (IsAddOn(ref)) { int32 id; BEntry entry(&ref); @@ -628,8 +621,8 @@ TReplicantTray::HandleEntryUpdate(BMessage *message) break; case B_ATTR_CHANGED: - // from node watch on individual items - // (node_watch added in LoadAddOn) + // from node watch on individual items + // (node_watch added in LoadAddOn) { node_ref nodeRef; if (message->FindInt32("device", &(nodeRef.device)) == B_OK @@ -675,8 +668,8 @@ TReplicantTray::HandleEntryUpdate(BMessage *message) break; ref.set_name(name); - // change the directory reference to - // the new directory + // change the directory reference to + // the new directory MoveItem(&ref, todirectory); } } @@ -684,7 +677,7 @@ TReplicantTray::HandleEntryUpdate(BMessage *message) case B_ENTRY_REMOVED: { - // entry was rm'd from the device + // entry was rm'd from the device node_ref nodeRef; if (message->FindInt32("device", &(nodeRef.device)) == B_OK && message->FindInt64("node", &(nodeRef.node)) == B_OK) { @@ -704,7 +697,7 @@ TReplicantTray::HandleEntryUpdate(BMessage *message) case B_DEVICE_MOUNTED: { - // run a new query on the new device + // run a new query on the new device dev_t device; if (message->FindInt32("new device", &device) != B_OK) break; @@ -714,10 +707,10 @@ TReplicantTray::HandleEntryUpdate(BMessage *message) break; case B_DEVICE_UNMOUNTED: { - // remove all items associated with the device - // unmounted - // contrary to what the BeBook says, the item is called "device", - // not "new device" like it is for B_DEVICE_MOUNTED + // remove all items associated with the device + // unmounted + // contrary to what the BeBook says, the item is called "device", + // not "new device" like it is for B_DEVICE_MOUNTED dev_t device; if (message->FindInt32("device", &device) != B_OK) break; @@ -729,9 +722,10 @@ TReplicantTray::HandleEntryUpdate(BMessage *message) } -// the add-ons must support the exported C function API -// if they do, they will be loaded and added to deskbar -// primary function is the Instantiate function +/** The add-ons must support the exported C function API + * if they do, they will be loaded and added to deskbar + * primary function is the Instantiate function + */ status_t TReplicantTray::LoadAddOn(BEntry *entry, int32 *id, bool force) @@ -741,7 +735,7 @@ TReplicantTray::LoadAddOn(BEntry *entry, int32 *id, bool force) node_ref nodeRef; entry->GetNodeRef(&nodeRef); - // no duplicates + // no duplicates if (NodeExists(nodeRef)) return B_ERROR; @@ -763,12 +757,12 @@ TReplicantTray::LoadAddOn(BEntry *entry, int32 *id, bool force) BPath path; entry->GetPath(&path); - // load the add-on + // load the add-on image_id image = load_add_on(path.Path()); if (image < 0) return (status_t)image; - // get the view loading function symbol + // get the view loading function symbol // we first look for a symbol that takes an image_id // and entry_ref pointer, if not found, go with normal // instantiate function @@ -895,9 +889,9 @@ TReplicantTray::MoveItem(entry_ref *ref, ino_t toDirectory) if (!ref) return; - // scan for a matching entry_ref and update it + // scan for a matching entry_ref and update it // - // don't need to change node info as it does not change + // don't need to change node info as it does not change for (int32 i = fItemList->CountItems(); i-- > 0 ;) { DeskbarItemInfo *item = (DeskbarItemInfo *)fItemList->ItemAt(i); @@ -945,8 +939,10 @@ TReplicantTray::ItemInfo(int32 id, const char **name) } -// for a specific name -// return the id (internal to Deskbar) +/** for a specific name + * return the id (internal to Deskbar) + */ + status_t TReplicantTray::ItemInfo(const char *name, int32 *id) { @@ -962,8 +958,10 @@ TReplicantTray::ItemInfo(const char *name, int32 *id) } -// at a specific index -// return both the name and the id of the replicant +/** at a specific index + * return both the name and the id of the replicant + */ + status_t TReplicantTray::ItemInfo(int32 index, const char **name, int32 *id) { @@ -981,7 +979,8 @@ TReplicantTray::ItemInfo(int32 index, const char **name, int32 *id) } -// replicant exists, by id/index +/** replicant exists, by id/index */ + bool TReplicantTray::IconExists(int32 target, bool byIndex) { @@ -992,7 +991,8 @@ TReplicantTray::IconExists(int32 target, bool byIndex) } -// replicant exists, by name +/** replicant exists, by name */ + bool TReplicantTray::IconExists(const char *name) { @@ -1013,9 +1013,11 @@ TReplicantTray::IconCount() const } -// message must contain an archivable view -// in the Archives folder for later rehydration -// returns the current boot id +/** message must contain an archivable view + * in the Archives folder for later rehydration + * returns the current boot id + */ + status_t TReplicantTray::AddIcon(BMessage *icon, int32 *id, const entry_ref *addOn) { @@ -1026,27 +1028,28 @@ TReplicantTray::AddIcon(BMessage *icon, int32 *id, const entry_ref *addOn) if (icon->what == B_ARCHIVED_OBJECT) icon->what = 0; - // !! check for name collisions? + // !! check for name collisions? status_t err = fShelf->AddReplicant(icon, BPoint(1, 1)); if (err != B_OK) return err; - + float oldWidth = Bounds().Width(); float oldHeight = Bounds().Height(); float width, height; GetPreferredSize(&width, &height); if (oldWidth != width || oldHeight != height) AdjustPlacement(); - + int32 count = fShelf->CountReplicants(); BView *view; fShelf->ReplicantAt(count-1, &view, (uint32 *)id, NULL); - // add the item to the add-on list + // add the item to the add-on list entry_ref ref; - if (addOn) // Use it if we got it + if (addOn) { + // Use it if we got it ref = *addOn; - else { + } else { const char *appsig; icon->FindString("add_on", &appsig); BRoster roster; @@ -1076,11 +1079,11 @@ TReplicantTray::RemoveIcon(int32 target, bool byIndex) int32 index, id; BView *view = ViewAt(&index, &id, target, byIndex); if (view && index >= 0) { - // remove the reference from the item list + // remove the reference from the item list & the shelf RemoveItem(id); - // remove the replicant from the shelf fShelf->DeleteReplicant(index); - // force a placement update, !! need to fix BShelf + + // force a placement update, !! need to fix BShelf RealReplicantAdjustment(index); } } @@ -1095,38 +1098,44 @@ TReplicantTray::RemoveIcon(const char *name) int32 id, index; BView *view = ViewAt(&index, &id, name); if (view && index >= 0) { - // remove the reference from the item list + // remove the reference from the item list & shelf RemoveItem(id); - // remove the replicant from the shelf fShelf->DeleteReplicant(index); - // force a placement update, !! need to fix BShelf + + // force a placement update, !! need to fix BShelf RealReplicantAdjustment(index); } } void -TReplicantTray::RealReplicantAdjustment(int32 startindex) +TReplicantTray::RealReplicantAdjustment(int32 startIndex) { - if (startindex < 0) + if (startIndex < 0) return; - // reset the locations of all replicants after the one deleted - RealignReplicants(startindex); + + if (startIndex == fLastReplicant) + startIndex = 0; + + // reset the locations of all replicants after the one deleted + RealignReplicants(startIndex); float oldWidth = Bounds().Width(); float oldHeight = Bounds().Height(); float width, height; GetPreferredSize(&width, &height); if (oldWidth != width || oldHeight != height) { - // resize view to accomodate the replicants - // redraw as necessary + // resize view to accomodate the replicants + // redraw as necessary AdjustPlacement(); } } -// looking for a replicant by id/index -// return the view and index +/** looking for a replicant by id/index + * return the view and index + */ + BView * TReplicantTray::ViewAt(int32 *index, int32 *id, int32 target, bool byIndex) { @@ -1157,8 +1166,10 @@ TReplicantTray::ViewAt(int32 *index, int32 *id, int32 target, bool byIndex) } -// looking for a replicant with a view by name -// return the view, index and the id of the replicant +/** looking for a replicant with a view by name + * return the view, index and the id of the replicant + */ + BView * TReplicantTray::ViewAt(int32 *index, int32 *id, const char *name) { @@ -1179,14 +1190,16 @@ TReplicantTray::ViewAt(int32 *index, int32 *id, const char *name) } -// Shelf will call to determine where and if -// the replicant is to be added +/** Shelf will call to determine where and if + * the replicant is to be added + */ + bool TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage *message) { if (!message) return false; - + if (replicantFrame.Height() > kMaxReplicantHeight) return false; @@ -1203,12 +1216,11 @@ TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage *message) message->FindInt32("deskbar:private_align", (int32 *)&align); else align = B_ALIGN_LEFT; - - int32 count = fShelf->CountReplicants(); - BPoint loc = LocForReplicant(count+1, count, replicantFrame.Width()); - - message->AddPoint("_pjp_loc", loc); + BPoint loc = LocationForReplicant(fShelf->CountReplicants(), + replicantFrame.Width()); + + message->AddPoint("_pjp_loc", loc); return true; } @@ -1219,35 +1231,52 @@ TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage *message) */ BPoint -TReplicantTray::LocForReplicant(int32, int32 index, float width) +TReplicantTray::LocationForReplicant(int32 index, float width) { BPoint loc(kIconGap + 1, kGutter + 1); - if (index > 0) { - // get the last replicant added for placement reference - BView *view = NULL; - fShelf->ReplicantAt((index-1), &view); - if (view) { - // push this rep placement past the last one - loc.x = view->Frame().right + kIconGap+1; - loc.y = view->Frame().top; + if (fMultiRowMode) { + // 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 + kMinimumTrayWidth + 2, kMaxReplicantHeight); + if (row == 0 && fBarView->ShowingClock()) + rect.right -= fClock->Frame().Width() + kIconGap; + + for (int32 i = 0; i < index; i++) { + BView *view = NULL; + fShelf->ReplicantAt(i, &view); + if (view == NULL || view->Frame().top != rect.top) + continue; + + rect.left = view->Frame().right + kIconGap + 1; + } + + if (rect.Width() >= width) { + // the icon fits in this row + loc = rect.LeftTop(); + break; + } + } + } else { + if (index > 0) { + // get the last replicant added for placement reference + BView *view = NULL; + fShelf->ReplicantAt(index - 1, &view); + if (view) { + // push this rep placement past the last one + loc.x = view->Frame().right + kIconGap + 1; + loc.y = view->Frame().top; + } } } - if (fMultiRowMode) { - // if on first row, don't cover the clock - // if on any other row, don't go past right edge - if ((loc.x + width + 2 >= kMinimumTrayWidth) - || (fBarView->ShowingClock() - && (loc.x + width + 6 >= kMinimumTrayWidth - fClock->Frame().Width()) - && (loc.y == kGutter + 1))) { - // make the vertical placement uniform - // based on the maximum height provided for each - // replicant - loc.y += kMaxReplicantHeight + kIconGap; - loc.x = kIconGap + 1; - } + if ((loc.y == fRightBottomReplicant.top && loc.x > fRightBottomReplicant.left) + || loc.y > fRightBottomReplicant.top) { + fRightBottomReplicant.Set(loc.x, loc.y, loc.x + width, loc.y + kMaxReplicantHeight); + fLastReplicant = index; } + return loc; } @@ -1269,18 +1298,18 @@ TReplicantTray::IconFrame(const char *name) { if (!name) return BRect(0, 0, 0, 0); - + int32 id, index; BView *view = ViewAt(&index, &id, name); if (view) return view->Frame(); - + return BRect(0, 0, 0, 0); } -/** scan from the startIndex and reset the location - * as defined in LocForReplicant +/** Scan from the startIndex and reset the location + * as defined in LocationForReplicant() */ void @@ -1288,15 +1317,18 @@ TReplicantTray::RealignReplicants(int32 startIndex) { if (startIndex < 0) startIndex = 0; - + int32 count = fShelf->CountReplicants(); if (count <= 0) return; + if (startIndex == 0) + fRightBottomReplicant.Set(0, 0, 0, 0); + BView *view = NULL; for (int32 i = startIndex ; i < count ; i++){ fShelf->ReplicantAt(i, &view); - BPoint loc = LocForReplicant(count, i, view->Frame().Width()); + BPoint loc = LocationForReplicant(i, view->Frame().Width()); if (view && (view->Frame().LeftTop() != loc)) { view->MoveTo(loc); } @@ -1319,8 +1351,10 @@ TReplicantTray::SetMultiRow(bool state) // #pragma mark - -// draggable region that is asynchronous so that -// dragging does not block other activities +/** draggable region that is asynchronous so that + * dragging does not block other activities + */ + TDragRegion::TDragRegion(TBarView *parent, BView *child) : BControl(BRect(0, 0, 0, 0), "", "", NULL, B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS), @@ -1475,12 +1509,13 @@ TDragRegion::MouseDown(BPoint thePoint) ulong buttons; BPoint where; BRect dragRegion(DragRegion()); - - dragRegion.InsetBy(-2.0f, -2.0f); // DragRegion() is designed for drawing, not clicking - + + dragRegion.InsetBy(-2.0f, -2.0f); + // DragRegion() is designed for drawing, not clicking + if (!dragRegion.Contains(thePoint)) return; - + while(true) { GetMouse(&where, &buttons); if (!buttons) @@ -1525,9 +1560,8 @@ TDragRegion::SwitchModeForRect(BPoint mouse, BRect rect, && newState == fBarView->State()) // already in the correct mode return true; - + fBarView->ChangeState(newState, newVertical, newLeft, newTop); - return true; } @@ -1549,7 +1583,7 @@ TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage *message) BRect topLeft(frame.left, frame.top, frame.left + hDivider, miniDivider); BRect topMiddle(frame.left + hDivider, frame.top, frame.right - hDivider, vDivider); BRect topRight(frame.right - hDivider, frame.top, frame.right, miniDivider); - + #ifdef FULL_MODE vDivider = miniDivider + thirdScreen; #endif @@ -1559,7 +1593,7 @@ TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage *message) #ifdef FULL_MODE BRect leftSide(frame.left, vDivider, frame.left + hDivider, frame.bottom - thirdScreen); BRect rightSide(frame.right - hDivider, vDivider, frame.right, frame.bottom - thirdScreen); - + vDivider = frame.bottom - thirdScreen; #endif BRect bottomLeft(frame.left, vDivider, frame.left + hDivider, frame.bottom); @@ -1584,11 +1618,9 @@ TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage *message) #endif || SwitchModeForRect(where, bottomLeft, true, true, false, kMiniState) || SwitchModeForRect(where, bottomMiddle, false, true, false, kExpandoState) - || SwitchModeForRect(where, bottomRight, true, false, false, kMiniState) - ) + || SwitchModeForRect(where, bottomRight, true, false, false, kMiniState)) ; } - } else BControl::MouseMoved(where, code, message); } diff --git a/src/apps/deskbar/StatusView.h b/src/apps/deskbar/StatusView.h index 1622d63233..5e81f6b37a 100644 --- a/src/apps/deskbar/StatusView.h +++ b/src/apps/deskbar/StatusView.h @@ -149,17 +149,19 @@ private: void MoveItem(entry_ref *, ino_t toDirectory); #endif - BPoint LocForReplicant(int32 replicantCount, int32 index, float width); + BPoint LocationForReplicant(int32 index, float width); BShelf *Shelf() const; - + friend class TReplicantShelf; TTimeView *fClock; TBarView *fBarView; TReplicantShelf *fShelf; - + BRect fRightBottomReplicant; + int32 fLastReplicant; + bool fMultiRowMode; - + bool fAlignmentSupport; #ifdef DB_ADDONS BList *fItemList; diff --git a/src/apps/deskbar/Switcher.cpp b/src/apps/deskbar/Switcher.cpp index e195c0d8d8..a6dd043c11 100644 --- a/src/apps/deskbar/Switcher.cpp +++ b/src/apps/deskbar/Switcher.cpp @@ -61,7 +61,25 @@ static bool IsWindowOK(const window_info *); static int SmartStrcmp(const char *s1, const char *s2); -inline bool IsVisibleInCurrentWorkspace(const window_info *windowInfo) +static int32 +LowBitIndex(uint32 value) +{ + int32 result = 0; + int32 bitMask = 1; + + if (value == 0) + return -1; + + while (result < 32 && (value & bitMask) == 0) { + result++; + bitMask = bitMask << 1; + } + return result; +} + + +inline bool +IsVisibleInCurrentWorkspace(const window_info *windowInfo) { /* The window list is always ordered from the top @@ -77,33 +95,37 @@ inline bool IsVisibleInCurrentWorkspace(const window_info *windowInfo) } +// #pragma mark - + + TTeamGroup::TTeamGroup() - : fTeams(NULL), - fFlags(0), - fName(NULL), - fSmallIcon(NULL), - fLargeIcon(NULL) - + : + fTeams(NULL), + fFlags(0), + fName(NULL), + fSmallIcon(NULL), + fLargeIcon(NULL) { - fSig[0] = '\0'; + fSignature[0] = '\0'; } TTeamGroup::TTeamGroup(BList *teams, uint32 flags, char *name, - const char *sig) - : fTeams(teams), - fFlags(flags), - fName(name), - fSmallIcon(NULL), - fLargeIcon(NULL) + const char *signature) + : + fTeams(teams), + fFlags(flags), + fName(name), + fSmallIcon(NULL), + fLargeIcon(NULL) { - strcpy(fSig, sig); + strcpy(fSignature, signature); fSmallIcon = new BBitmap(BRect(0,0,15,15), B_COLOR_8_BIT); fLargeIcon = new BBitmap(BRect(0,0,31,31), B_COLOR_8_BIT); app_info appInfo; - if (be_roster->GetAppInfo(sig, &appInfo) == B_OK) { + if (be_roster->GetAppInfo(signature, &appInfo) == B_OK) { BNode node(&(appInfo.ref)); if (node.InitCheck() == B_OK) { BNodeInfo nodeInfo(&node); @@ -156,16 +178,16 @@ const int32 kScrollStep = kSlotSize / 2; const int32 kNumSlots = 7; const int32 kCenterSlot = 3; -TSwitchMgr::TSwitchMgr(BPoint point) - : BHandler("SwitchMgr"), - fMainMonitor(create_sem(1, "main_monitor")), - fBlock(false), - fSkipUntil(0), - fGroupList(10), - fCurIndex(0), - fCurSlot(0), - fWindowID(-1), - fLastActivity(0) +TSwitchManager::TSwitchManager(BPoint point) + : BHandler("SwitchManager"), + fMainMonitor(create_sem(1, "main_monitor")), + fBlock(false), + fSkipUntil(0), + fGroupList(10), + fCurrentIndex(0), + fCurrentSlot(0), + fWindowID(-1), + fLastActivity(0) { BRect rect(point.x, point.y, point.x + (kSlotSize * kNumSlots) - 1 + (2 * kHorizontalMargin), @@ -197,7 +219,7 @@ TSwitchMgr::TSwitchMgr(BPoint point) } -TSwitchMgr::~TSwitchMgr() +TSwitchManager::~TSwitchManager() { for (int32 i = fGroupList.CountItems(); i-- > 0;) { TTeamGroup *teamInfo = static_cast(fGroupList.ItemAt(i)); @@ -207,137 +229,138 @@ TSwitchMgr::~TSwitchMgr() void -TSwitchMgr::MessageReceived(BMessage *message) +TSwitchManager::MessageReceived(BMessage *message) { status_t err; switch (message->what) { case B_SOME_APP_QUIT: - { - // This is only sent when last team of a matching set quits - team_id teamID; - int i = 0; - TTeamGroup *tinfo; - message->FindInt32("team", &teamID); - while ((tinfo = (TTeamGroup *) fGroupList.ItemAt(i)) != NULL) { - if (tinfo->TeamList()->HasItem((void *)teamID)) { - fGroupList.RemoveItem(i); - - if (OKToUse(tinfo)) { - fWindow->Redraw(i); - if (i <= fCurIndex) { - fCurIndex--; - CycleApp(true); - } + { + // This is only sent when last team of a matching set quits + team_id teamID; + int i = 0; + TTeamGroup *tinfo; + message->FindInt32("team", &teamID); + while ((tinfo = (TTeamGroup *) fGroupList.ItemAt(i)) != NULL) { + if (tinfo->TeamList()->HasItem((void *)teamID)) { + fGroupList.RemoveItem(i); + + if (OKToUse(tinfo)) { + fWindow->Redraw(i); + if (i <= fCurrentIndex) { + fCurrentIndex--; + CycleApp(true); } - delete tinfo; - break; } - i++; + delete tinfo; + break; } - break; + i++; } + break; + } case B_SOME_APP_LAUNCHED: - { - BList *teams; - const char *name; - BBitmap *smallIcon; - uint32 flags; - const char *sig; - - if (message->FindPointer("teams", (void **)&teams) != B_OK) - break; + { + BList *teams; + const char *name; + BBitmap *smallIcon; + uint32 flags; + const char *signature; - if (message->FindPointer("icon", (void **)&smallIcon) != B_OK) { - delete teams; - break; - } - delete smallIcon; - if (message->FindString("sig", &sig) != B_OK) { - delete teams; - break; - } - if (message->FindInt32("flags", (int32 *)&flags) != B_OK) { - delete teams; - break; - } - if (message->FindString("name", &name) != B_OK) { - delete teams; - break; - } - - TTeamGroup *tinfo = new TTeamGroup(teams, flags, strdup(name), sig); - - fGroupList.AddItem(tinfo); - if (OKToUse(tinfo)) - fWindow->Redraw(fGroupList.CountItems() - 1); + if (message->FindPointer("teams", (void **)&teams) != B_OK) + break; + if (message->FindPointer("icon", (void **)&smallIcon) != B_OK) { + delete teams; break; } + delete smallIcon; + if (message->FindString("sig", &signature) != B_OK) { + delete teams; + break; + } + if (message->FindInt32("flags", (int32 *)&flags) != B_OK) { + delete teams; + break; + } + if (message->FindString("name", &name) != B_OK) { + delete teams; + break; + } + + TTeamGroup *tinfo = new TTeamGroup(teams, flags, strdup(name), signature); + + fGroupList.AddItem(tinfo); + if (OKToUse(tinfo)) + fWindow->Redraw(fGroupList.CountItems() - 1); + + break; + } + case msg_AddTeam: - { - const char *sig = message->FindString("sig"); - team_id team = message->FindInt32("team"); - - int32 numItems = fGroupList.CountItems(); - for (int32 i = 0; i < numItems; i++) { - TTeamGroup *tinfo = (TTeamGroup *)fGroupList.ItemAt(i); - if (strcasecmp(tinfo->Sig(), sig) == 0) { - if (!(tinfo->TeamList()->HasItem((void *)team))) - tinfo->TeamList()->AddItem((void *)team); - break; - } - } - break; - } + { + const char *signature = message->FindString("sig"); + team_id team = message->FindInt32("team"); + + int32 numItems = fGroupList.CountItems(); + for (int32 i = 0; i < numItems; i++) { + TTeamGroup *tinfo = (TTeamGroup *)fGroupList.ItemAt(i); + if (strcasecmp(tinfo->Signature(), signature) == 0) { + if (!(tinfo->TeamList()->HasItem((void *)team))) + tinfo->TeamList()->AddItem((void *)team); + break; + } + } + break; + } + case msg_RemoveTeam: - { - team_id team = message->FindInt32("team"); - - int32 numItems = fGroupList.CountItems(); - for (int32 i = 0; i < numItems; i++) { - TTeamGroup *tinfo = (TTeamGroup *)fGroupList.ItemAt(i); - if (tinfo->TeamList()->HasItem((void *)team)) { - tinfo->TeamList()->RemoveItem((void *)team); - break; - } - } - break; - } + { + team_id team = message->FindInt32("team"); + + int32 numItems = fGroupList.CountItems(); + for (int32 i = 0; i < numItems; i++) { + TTeamGroup *tinfo = (TTeamGroup *)fGroupList.ItemAt(i); + if (tinfo->TeamList()->HasItem((void *)team)) { + tinfo->TeamList()->RemoveItem((void *)team); + break; + } + } + break; + } case 'TASK': - { - - // The first TASK message calls MainEntry. Subsequent ones - // call Process(). - bigtime_t time; - message->FindInt64("when", (int64 *)&time); - - // The fSkipUntil stuff can be removed once the new input_server - // starts differentiating initial key_downs from KeyDowns generated - // by auto-repeat. Until then the fSkipUntil stuff helps, but it - // isn't perfect. - - if (time < fSkipUntil) - break; + { + // The first TASK message calls MainEntry. Subsequent ones + // call Process(). + bigtime_t time; + message->FindInt64("when", (int64 *)&time); - err = acquire_sem_etc(fMainMonitor, 1, B_TIMEOUT, 0); - if (err != B_OK) { - if (!fWindow->IsHidden() && !fBlock) { - // Want to skip TASK msgs posted before the window - // was made visible. Better UI feel if we do this. - if (time > fSkipUntil) { - uint32 mods; - message->FindInt32("modifiers", (int32 *)&mods); - Process((mods & B_SHIFT_KEY) == 0, (mods & B_OPTION_KEY) != 0); - } - } - } else - MainEntry(message); + // The fSkipUntil stuff can be removed once the new input_server + // starts differentiating initial key_downs from KeyDowns generated + // by auto-repeat. Until then the fSkipUntil stuff helps, but it + // isn't perfect. + if (time < fSkipUntil) break; - } + + err = acquire_sem_etc(fMainMonitor, 1, B_TIMEOUT, 0); + if (err != B_OK) { + if (!fWindow->IsHidden() && !fBlock) { + // Want to skip TASK msgs posted before the window + // was made visible. Better UI feel if we do this. + if (time > fSkipUntil) { + uint32 mods; + message->FindInt32("modifiers", (int32 *)&mods); + Process((mods & B_SHIFT_KEY) == 0, (mods & B_OPTION_KEY) != 0); + } + } + } else + MainEntry(message); + + break; + } default: break; @@ -346,7 +369,7 @@ TSwitchMgr::MessageReceived(BMessage *message) void -TSwitchMgr::MainEntry(BMessage *message) +TSwitchManager::MainEntry(BMessage *message) { bigtime_t keyRepeatRate; get_key_repeat_delay(&keyRepeatRate); @@ -360,7 +383,7 @@ TSwitchMgr::MainEntry(BMessage *message) be_roster->GetActiveAppInfo(&appInfo); int32 index; - fCurIndex = (FindTeam(appInfo.team, &index) != NULL) ? index : 0; + fCurrentIndex = (FindTeam(appInfo.team, &index) != NULL) ? index : 0; int32 key; message->FindInt32("key", (int32 *)&key); @@ -384,7 +407,7 @@ TSwitchMgr::MainEntry(BMessage *message) void -TSwitchMgr::Stop(bool do_action, uint32 ) +TSwitchManager::Stop(bool do_action, uint32) { fWindow->Hide(); if (do_action) @@ -395,7 +418,7 @@ TSwitchMgr::Stop(bool do_action, uint32 ) TTeamGroup * -TSwitchMgr::FindTeam(team_id teamID, int32 *index) +TSwitchManager::FindTeam(team_id teamID, int32 *index) { int i = 0; TTeamGroup *tinfo; @@ -412,7 +435,7 @@ TSwitchMgr::FindTeam(team_id teamID, int32 *index) void -TSwitchMgr::Process(bool forward, bool byWindow) +TSwitchManager::Process(bool forward, bool byWindow) { bool hidden = false; if (fWindow->Lock()) { @@ -423,7 +446,7 @@ TSwitchMgr::Process(bool forward, bool byWindow) if (byWindow) { // If hidden we need to get things started by switching to correct app if (hidden) - SwitchToApp(fCurIndex, fCurIndex, forward); + SwitchToApp(fCurrentIndex, fCurrentIndex, forward); CycleWindow(forward, false); } else CycleApp(forward, false); @@ -457,14 +480,13 @@ TSwitchMgr::Process(bool forward, bool byWindow) void -TSwitchMgr::QuickSwitch(BMessage *message) +TSwitchManager::QuickSwitch(BMessage *message) { uint32 modifiers = 0; message->FindInt32("modifiers", (int32 *) &modifiers); team_id team; if (message->FindInt32("team", &team) == B_OK) { - bool forward = ((modifiers & B_SHIFT_KEY) == 0); if ((modifiers & B_OPTION_KEY) != 0) @@ -478,7 +500,7 @@ TSwitchMgr::QuickSwitch(BMessage *message) int32 -TSwitchMgr::CountVisibleGroups() +TSwitchManager::CountVisibleGroups() { int32 result = 0; @@ -494,11 +516,11 @@ TSwitchMgr::CountVisibleGroups() void -TSwitchMgr::CycleWindow(bool forward, bool wrap) +TSwitchManager::CycleWindow(bool forward, bool wrap) { - int32 max = CountWindows(fCurIndex); - int32 prev = fCurWindow; - int32 next = fCurWindow; + int32 max = CountWindows(fCurrentIndex); + int32 prev = fCurrentWindow; + int32 next = fCurrentWindow; if (forward) { next++; @@ -515,40 +537,39 @@ TSwitchMgr::CycleWindow(bool forward, bool wrap) next = max - 1; } } - fCurWindow = next; + fCurrentWindow = next; - if (fCurWindow != prev) - fWindow->WindowView()->ShowIndex(fCurWindow); + if (fCurrentWindow != prev) + fWindow->WindowView()->ShowIndex(fCurrentWindow); } void -TSwitchMgr::CycleApp(bool forward, bool activateNow) +TSwitchManager::CycleApp(bool forward, bool activateNow) { - int32 startIndex = fCurIndex; + int32 startIndex = fCurrentIndex; int32 max = fGroupList.CountItems(); for (;;) { if (forward) { - fCurIndex++; - if (fCurIndex >= max) - fCurIndex = 0; + fCurrentIndex++; + if (fCurrentIndex >= max) + fCurrentIndex = 0; } else { - fCurIndex--; - if (fCurIndex < 0) - fCurIndex = max - 1; + fCurrentIndex--; + if (fCurrentIndex < 0) + fCurrentIndex = max - 1; } - if ((fCurIndex == startIndex)) + if ((fCurrentIndex == startIndex)) // we've gone completely through the list without finding - // an good app. Oh well. + // a good app. Oh well. return; - - if (!OKToUse((TTeamGroup *)fGroupList.ItemAt(fCurIndex))) + if (!OKToUse((TTeamGroup *)fGroupList.ItemAt(fCurrentIndex))) continue; // if we're here then we found a good one - SwitchToApp(startIndex, fCurIndex, forward); + SwitchToApp(startIndex, fCurrentIndex, forward); if (!activateNow) break; @@ -560,55 +581,37 @@ TSwitchMgr::CycleApp(bool forward, bool activateNow) void -TSwitchMgr::SwitchToApp(int32 previousIndex, int32 newIndex, bool forward) +TSwitchManager::SwitchToApp(int32 previousIndex, int32 newIndex, bool forward) { - int32 previousSlot = fCurSlot; + int32 previousSlot = fCurrentSlot; - fCurIndex = newIndex; - fCurSlot = fWindow->SlotOf(fCurIndex); - fCurWindow = 0; + fCurrentIndex = newIndex; + fCurrentSlot = fWindow->SlotOf(fCurrentIndex); + fCurrentWindow = 0; - fWindow->Update(previousIndex, fCurIndex, previousSlot, fCurSlot, forward); -} - - -static int32 -LowBitIndex(uint32 value) -{ - int32 result = 0; - int32 bitMask = 1; - - if (value == 0) - return -1; - - while (result < 32 && (value & bitMask) == 0) { - result++; - bitMask = bitMask << 1; - } - return result; + fWindow->Update(previousIndex, fCurrentIndex, previousSlot, fCurrentSlot, forward); } bool -TSwitchMgr::ActivateApp(bool forceShow, bool allowWorkspaceSwitch) +TSwitchManager::ActivateApp(bool forceShow, bool allowWorkspaceSwitch) { - // Let's get the info about the selected window. If it doesn't exist // anymore then get info about first window. If that doesn't exist then // do nothing. - window_info *windowInfo = WindowInfo(fCurIndex, fCurWindow); + window_info *windowInfo = WindowInfo(fCurrentIndex, fCurrentWindow); if (!windowInfo) { - windowInfo = WindowInfo(fCurIndex, 0); + windowInfo = WindowInfo(fCurrentIndex, 0); if (!windowInfo) return false; } - + int32 currentWorkspace = current_workspace(); - TTeamGroup *teamGroup = (TTeamGroup *) fGroupList.ItemAt(fCurIndex); + TTeamGroup *teamGroup = (TTeamGroup *)fGroupList.ItemAt(fCurrentIndex); // Let's handle the easy case first: There's only 1 team in the group if (teamGroup->TeamList()->CountItems() == 1) { bool result; - if (forceShow && (fCurWindow != 0 || windowInfo->is_mini)) + if (forceShow && (fCurrentWindow != 0 || windowInfo->is_mini)) do_window_action(windowInfo->id, B_BRING_TO_FRONT, BRect(0, 0, 0, 0), false); @@ -622,7 +625,7 @@ TSwitchMgr::ActivateApp(bool forceShow, bool allowWorkspaceSwitch) result = false; else { result = true; - be_roster->ActivateApp((team_id) teamGroup->TeamList()->ItemAt(0)); + be_roster->ActivateApp((team_id)teamGroup->TeamList()->ItemAt(0)); } ASSERT(windowInfo); @@ -631,7 +634,7 @@ TSwitchMgr::ActivateApp(bool forceShow, bool allowWorkspaceSwitch) } // Now the trickier case. We're trying to Bring to the Front a group - // of teams. The current window (defined by fCurWindow) will define + // of teams. The current window (defined by fCurrentWindow) will define // which workspace we're going to. Then, once that is determined we // want to bring to the front every window of the group of teams that // lives in that workspace. @@ -644,13 +647,13 @@ TSwitchMgr::ActivateApp(bool forceShow, bool allowWorkspaceSwitch) free(windowInfo); return false; } - int32 dest_ws = LowBitIndex(windowInfo->workspaces); + int32 destWorkspace = LowBitIndex(windowInfo->workspaces); // now switch to that workspace - activate_workspace(dest_ws); + activate_workspace(destWorkspace); } if (!forceShow && windowInfo->is_mini) { - // If the first window in the list is hiddenm then no windows in + // If the first window in the list is hidden then no windows in // this group are visible. So we can't switch to this app. ASSERT(windowInfo); free(windowInfo); @@ -671,17 +674,18 @@ TSwitchMgr::ActivateApp(bool forceShow, bool allowWorkspaceSwitch) // As we hit member teams we build the "activate" list. for (int32 i = 0; i < tokenCount; i++) { window_info *matchWindowInfo = get_window_info(tokens[i]); - if (!matchWindowInfo) + if (!matchWindowInfo) { // That window probably closed. Just go to the next one. continue; + } if (!IsVisibleInCurrentWorkspace(matchWindowInfo)) { // first non-visible in workspace window means we're done. free(matchWindowInfo); break; } - if ((matchWindowInfo->id != windowInfo->id) + if (matchWindowInfo->id != windowInfo->id && teamGroup->TeamList()->HasItem((void *)matchWindowInfo->team)) - windowsToActivate.AddItem((void *)matchWindowInfo->id); + windowsToActivate.AddItem((void *)matchWindowInfo->id); free(matchWindowInfo); } @@ -704,10 +708,52 @@ TSwitchMgr::ActivateApp(bool forceShow, bool allowWorkspaceSwitch) } -window_info * -TSwitchMgr::WindowInfo(int32 groupIndex, int32 windowIndex) +void +TSwitchManager::QuitApp() { + // check if we're in the last slot already (the last usable team group) + TTeamGroup *teamGroup; + int32 count = 0; + for (int32 i = fCurrentIndex + 1; i < fGroupList.CountItems(); i++) { + teamGroup = (TTeamGroup *)fGroupList.ItemAt(i); + + if (!OKToUse(teamGroup)) + continue; + + count++; + } + + teamGroup = (TTeamGroup *)fGroupList.ItemAt(fCurrentIndex); + + if (count == 0) { + // switch to previous app in the list so that we don't jump to + // the start of the list (try to keep the same position when + // the apps at the current index go away) + CycleApp(false, false); + } + + // send the quit request to all teams in this group + + for (int32 i = teamGroup->TeamList()->CountItems(); i-- > 0;) { + team_id team = (team_id)teamGroup->TeamList()->ItemAt(i); + app_info info; + if (be_roster->GetRunningAppInfo(team, &info) == B_OK) { + if (!strcasecmp(info.signature, kTrackerSignature)) { + // Tracker can't be quit this way + continue; + } + + BMessenger messenger(NULL, team); + messenger.SendMessage(B_QUIT_REQUESTED); + } + } +} + + +window_info * +TSwitchManager::WindowInfo(int32 groupIndex, int32 windowIndex) +{ TTeamGroup *teamGroup = (TTeamGroup *) fGroupList.ItemAt(groupIndex); if (!teamGroup) return NULL; @@ -751,7 +797,7 @@ TSwitchMgr::WindowInfo(int32 groupIndex, int32 windowIndex) int32 -TSwitchMgr::CountWindows(int32 groupIndex, bool ) +TSwitchManager::CountWindows(int32 groupIndex, bool ) { TTeamGroup *teamGroup = (TTeamGroup *)fGroupList.ItemAt(groupIndex); if (!teamGroup) @@ -785,7 +831,7 @@ TSwitchMgr::CountWindows(int32 groupIndex, bool ) void -TSwitchMgr::ActivateWindow(int32 windowID) +TSwitchManager::ActivateWindow(int32 windowID) { if (windowID == -1) windowID = fWindowID; @@ -795,7 +841,7 @@ TSwitchMgr::ActivateWindow(int32 windowID) void -TSwitchMgr::SwitchWindow(team_id team, bool, bool activate) +TSwitchManager::SwitchWindow(team_id team, bool, bool activate) { // Find the _last_ window in the current workspace that belongs // to the group. This is the window to activate. @@ -825,7 +871,7 @@ TSwitchMgr::SwitchWindow(team_id team, bool, bool activate) void -TSwitchMgr::Unblock() +TSwitchManager::Unblock() { fBlock = false; fSkipUntil = system_time(); @@ -833,35 +879,35 @@ TSwitchMgr::Unblock() int32 -TSwitchMgr::CurIndex() +TSwitchManager::CurrentIndex() { - return fCurIndex; + return fCurrentIndex; } int32 -TSwitchMgr::CurWindow() +TSwitchManager::CurrentWindow() { - return fCurWindow; + return fCurrentWindow; } int32 -TSwitchMgr::CurSlot() +TSwitchManager::CurrentSlot() { - return fCurSlot; + return fCurrentSlot; } BList * -TSwitchMgr::GroupList() +TSwitchManager::GroupList() { return &fGroupList; } bigtime_t -TSwitchMgr::IdleTime() +TSwitchManager::IdleTime() { return system_time() - fLastActivity; } @@ -870,13 +916,14 @@ TSwitchMgr::IdleTime() // #pragma mark - -TBox::TBox(BRect bounds, TSwitchMgr *mgr, TSwitcherWindow *window, TIconView *iview) - : BBox(bounds, "top", B_FOLLOW_NONE, B_WILL_DRAW, B_PLAIN_BORDER), - fMgr(mgr), - fWindow(window), - fIconView(iview), - fLeftScroller(false), - fRightScroller(false) +TBox::TBox(BRect bounds, TSwitchManager *manager, TSwitcherWindow *window, + TIconView *iview) + : BBox(bounds, "top", B_FOLLOW_NONE, B_WILL_DRAW, B_PLAIN_BORDER), + fManager(manager), + fWindow(window), + fIconView(iview), + fLeftScroller(false), + fRightScroller(false) { } @@ -911,14 +958,14 @@ TBox::MouseDown(BPoint where) BRect lhit(0, frame.top, frame.left, frame.bottom); if (lhit.Contains(where)) { // Want to scroll by NUMSLOTS-1 slots - int32 previousIndex = fMgr->CurIndex(); - int32 previousSlot = fMgr->CurSlot(); + int32 previousIndex = fManager->CurrentIndex(); + int32 previousSlot = fManager->CurrentSlot(); int32 newSlot = previousSlot - (kNumSlots - 1); if (newSlot < 0) newSlot = 0; int32 newIndex = fIconView->IndexAt(newSlot); - fMgr->SwitchToApp(previousIndex, newIndex, false); + fManager->SwitchToApp(previousIndex, newIndex, false); } } @@ -926,17 +973,17 @@ TBox::MouseDown(BPoint where) BRect rhit(frame.right, frame.top, bounds.right, frame.bottom); if (rhit.Contains(where)) { // Want to scroll by NUMSLOTS-1 slots - int32 previousIndex = fMgr->CurIndex(); - int32 previousSlot = fMgr->CurSlot(); + int32 previousIndex = fManager->CurrentIndex(); + int32 previousSlot = fManager->CurrentSlot(); int32 newSlot = previousSlot + (kNumSlots-1); int32 newIndex = fIconView->IndexAt(newSlot); if (newIndex < 0) { // don't have a page full to scroll - int32 valid = fMgr->CountVisibleGroups(); + int32 valid = fManager->CountVisibleGroups(); newIndex = fIconView->IndexAt(valid-1); } - fMgr->SwitchToApp(previousIndex, newIndex, true); + fManager->SwitchToApp(previousIndex, newIndex, true); } } @@ -946,7 +993,7 @@ TBox::MouseDown(BPoint where) BRect hit2(frame.right, frame.top, frame.right + 10, (frame.top+frame.bottom)/2); if (hit1.Contains(where) || hit2.Contains(where)) { // Want to scroll up 1 window - fMgr->CycleWindow(false, false); + fManager->CycleWindow(false, false); } } @@ -955,7 +1002,7 @@ TBox::MouseDown(BPoint where) BRect hit2(frame.right, (frame.top+frame.bottom) / 2, frame.right + 10, frame.bottom); if (hit1.Contains(where) || hit2.Contains(where)) { // Want to scroll down 1 window - fMgr->CycleWindow(true, false); + fManager->CycleWindow(true, false); } } } @@ -977,12 +1024,12 @@ TBox::Draw(BRect update) BRect box(3, 3, bounds.right - 3, 3 + height + kChildInset * 2); rgb_color white = {255,255,255,255}; - rgb_color standardGray = {216, 216, 216, 255}; + rgb_color standardGray = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color veryDarkGray = {128, 128, 128, 255}; - rgb_color darkGray = {184, 184, 184, 255}; + rgb_color darkGray = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT); // Fill the area with dark gray - SetHighColor(184,184,184); + SetHighColor(darkGray); box.InsetBy(1,1); FillRect(box); @@ -1062,8 +1109,8 @@ TBox::DrawIconScrollers(bool force) bool updateRight = false; rgb_color leftc; rgb_color rightc; - rgb_color bkg = {184, 184, 184, 255}; - rgb_color dark = {0, 96, 96, 255}; + rgb_color bkg = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT); + rgb_color dark = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_4_TINT); BRect rect = fIconView->Bounds(); if (rect.left > (kSlotSize * kCenterSlot)) { @@ -1078,7 +1125,7 @@ TBox::DrawIconScrollers(bool force) } } - int32 maxIndex = fMgr->GroupList()->CountItems() - 1; + int32 maxIndex = fManager->GroupList()->CountItems() - 1; // last_frame is in fIconView coordinate space BRect lastFrame = fIconView->FrameOf(maxIndex); @@ -1125,8 +1172,8 @@ TBox::DrawWindowScrollers(bool force) bool updateDown = false; rgb_color upColor; rgb_color downColor; - rgb_color bkg = {216,216,216,255}; - rgb_color dark = {96,96,96,255}; + rgb_color bkg = ui_color(B_PANEL_BACKGROUND_COLOR); + rgb_color dark = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_4_TINT); BRect rect = fWindow->WindowView()->Bounds(); if (rect.top != 0) { @@ -1141,8 +1188,8 @@ TBox::DrawWindowScrollers(bool force) } } - int32 groupIndex = fMgr->CurIndex(); - int32 maxIndex = fMgr->CountWindows(groupIndex) - 1; + int32 groupIndex = fManager->CurrentIndex(); + int32 maxIndex = fManager->CountWindows(groupIndex) - 1; BRect lastFrame(0, 0, 0, 0); if (maxIndex >= 0) { @@ -1200,12 +1247,12 @@ TBox::DrawWindowScrollers(bool force) // #pragma mark - -TSwitcherWindow::TSwitcherWindow(BRect frame, TSwitchMgr *mgr) - : BWindow(frame, "Twitcher", B_MODAL_WINDOW_LOOK, +TSwitcherWindow::TSwitcherWindow(BRect frame, TSwitchManager *manager) + : BWindow(frame, "Twitcher", B_MODAL_WINDOW_LOOK, B_MODAL_ALL_WINDOW_FEEL, B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE, B_ALL_WORKSPACES), - fMgr(mgr), - fHairTrigger(true) + fManager(manager), + fHairTrigger(true) { BRect rect = frame; rect.OffsetTo(B_ORIGIN); @@ -1213,15 +1260,15 @@ TSwitcherWindow::TSwitcherWindow(BRect frame, TSwitchMgr *mgr) rect.top = kVerticalMargin; rect.bottom = rect.top + kSlotSize - 1; - fIconView = new TIconView(rect, mgr, this); + fIconView = new TIconView(rect, manager, this); rect.top = rect.bottom + (kVerticalMargin * 1 + 4); rect.InsetBy(9, 0); - fWindowView = new TWindowView(rect, mgr, this); + fWindowView = new TWindowView(rect, manager, this); fWindowView->ResizeToPreferred(); - fTopView = new TBox(Bounds(), fMgr, this, fIconView); + fTopView = new TBox(Bounds(), fManager, this, fIconView); AddChild(fTopView); SetPulseRate(0); @@ -1241,12 +1288,12 @@ TSwitcherWindow::DispatchMessage(BMessage *message, BHandler *handler) { if (message->what == B_KEY_DOWN) { // large timeout - effective kills key repeats - if (fMgr->IdleTime() < 10000000) { + if (fManager->IdleTime() < 10000000) return; - } - fMgr->Touch(); + + fManager->Touch(); } else if (message->what == B_KEY_UP) - fMgr->Touch(true); + fManager->Touch(true); BWindow::DispatchMessage(message, handler); } @@ -1257,12 +1304,14 @@ TSwitcherWindow::MessageReceived(BMessage *message) { switch (message->what) { case B_KEY_DOWN: - uint32 ch; + { + uint32 rawChar; uint32 modifiers; - message->FindInt32("raw_char", 0, (int32 *)&ch); + message->FindInt32("raw_char", 0, (int32 *)&rawChar); message->FindInt32("modifiers", 0, (int32 *)&modifiers); - DoKey(ch, modifiers); + DoKey(rawChar, modifiers); break; + } default: BWindow::MessageReceived(message); @@ -1285,12 +1334,40 @@ TSwitcherWindow::DoKey(uint32 key, uint32 modifiers) bool forward = ((modifiers & B_SHIFT_KEY) == 0); switch (key) { - case '~': - fMgr->CycleWindow(false, false); + case B_RIGHT_ARROW: + case '`': + fManager->CycleApp(true, false); break; - case '`': - fMgr->CycleWindow(true, false); + case B_LEFT_ARROW: + case '~': + fManager->CycleApp(false, false); + break; + + case B_UP_ARROW: + fManager->CycleWindow(false, false); + break; + + case B_DOWN_ARROW: + fManager->CycleWindow(true, false); + break; + + case B_TAB: + fManager->CycleApp(forward, false); + break; + + case B_ESCAPE: + fManager->Stop(false, 0); + break; + + case B_SPACE: + case B_ENTER: + fManager->Stop(true, modifiers); + break; + + case 'q': + case 'Q': + fManager->QuitApp(); break; #if _ALLOW_STICKY_ @@ -1305,35 +1382,6 @@ TSwitcherWindow::DoKey(uint32 key, uint32 modifiers) } break; #endif - case B_RIGHT_ARROW: - fMgr->CycleApp(true, false); - break; - - case B_LEFT_ARROW: - fMgr->CycleApp(false, false); - break; - - case B_UP_ARROW: - fMgr->CycleWindow(false, false); - break; - - case B_DOWN_ARROW: - fMgr->CycleWindow(true, false); - break; - - case B_TAB: - fMgr->CycleApp(forward, false); - break; - - case B_ESCAPE: - fMgr->Stop(false, 0); - break; - - case B_SPACE: - case B_ENTER: - fMgr->Stop(true, modifiers); - break; - } } @@ -1342,7 +1390,7 @@ bool TSwitcherWindow::QuitRequested() { ((TBarApp *) be_app)->Settings()->switcherLoc = Frame().LeftTop(); - fMgr->Stop(false, 0); + fManager->Stop(false, 0); return false; } @@ -1351,20 +1399,20 @@ void TSwitcherWindow::WindowActivated(bool state) { if (state) - fMgr->Unblock(); + fManager->Unblock(); } void -TSwitcherWindow::Update(int32 prev, int32 cur, int32 previousSlot, +TSwitcherWindow::Update(int32 prev, int32 current, int32 previousSlot, int32 currentSlot, bool forward) { if (!IsHidden()) - fIconView->Update(prev, cur, previousSlot, currentSlot, forward); + fIconView->Update(prev, current, previousSlot, currentSlot, forward); else - fIconView->CenterOn(cur); + fIconView->CenterOn(current); - fWindowView->UpdateGroup(cur, 0); + fWindowView->UpdateGroup(current, 0); } @@ -1383,7 +1431,7 @@ TSwitcherWindow::Show() fHairTrigger = true; fIconView->Showing(); SetPulseRate(100000); - fMgr->Touch(); + fManager->Touch(); SetLook(B_MODAL_WINDOW_LOOK); BWindow::Show(); } @@ -1406,32 +1454,33 @@ TSwitcherWindow::HairTrigger() // #pragma mark - -TIconView::TIconView(BRect frame, TSwitchMgr *mgr, TSwitcherWindow *switcherWindow) - : BView(frame, "main_view", B_FOLLOW_NONE, +TIconView::TIconView(BRect frame, TSwitchManager *manager, TSwitcherWindow *switcherWindow) + : BView(frame, "main_view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED), - fAutoScrolling(false), - fSwitcher(switcherWindow), - fMgr(mgr) + fAutoScrolling(false), + fSwitcher(switcherWindow), + fManager(manager) { BRect rect(0, 0, kSlotSize - 1, kSlotSize - 1); + rgb_color color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT); fOffView = new BView(rect, "off_view", B_FOLLOW_NONE, B_WILL_DRAW); - fOffView->SetHighColor(184, 184, 184); - fOffBitmap = new BBitmap(rect, B_COLOR_8_BIT, true); + fOffView->SetHighColor(color); + fOffBitmap = new BBitmap(rect, B_RGB32, true); fOffBitmap->AddChild(fOffView); - fCurSmall = new BBitmap(BRect(0, 0, 15, 15), B_COLOR_8_BIT); - fCurLarge = new BBitmap(BRect(0, 0, 31, 31), B_COLOR_8_BIT); - - SetViewColor(184, 184, 184); - SetLowColor(184, 184, 184); + fCurrentSmall = new BBitmap(BRect(0, 0, 15, 15), B_COLOR_8_BIT); + fCurrentLarge = new BBitmap(BRect(0, 0, 31, 31), B_COLOR_8_BIT); + + SetViewColor(color); + SetLowColor(color); } TIconView::~TIconView() { - delete fCurSmall; - delete fCurLarge; + delete fCurrentSmall; + delete fCurrentLarge; delete fOffBitmap; } @@ -1447,12 +1496,12 @@ TIconView::CacheIcons(TTeamGroup *teamGroup) { const BBitmap *bitmap = teamGroup->SmallIcon(); ASSERT(bitmap); - fCurSmall->SetBits(bitmap->Bits(), bitmap->BitsLength(), 0, + fCurrentSmall->SetBits(bitmap->Bits(), bitmap->BitsLength(), 0, B_COLOR_8_BIT); bitmap = teamGroup->LargeIcon(); ASSERT(bitmap); - fCurLarge->SetBits(bitmap->Bits(), bitmap->BitsLength(), 0, + fCurrentLarge->SetBits(bitmap->Bits(), bitmap->BitsLength(), 0, B_COLOR_8_BIT); } @@ -1467,10 +1516,9 @@ TIconView::AnimateIcon(BBitmap *startIcon, BBitmap *endIcon) float width = startIconBounds.Width(); int32 amount = (width < 20) ? -2 : 2; - // center the starting icon inside of centerRect float off = (centerRect.Width() - width) / 2; - startIconBounds.OffsetTo(BPoint(off,off)); + startIconBounds.OffsetTo(BPoint(off, off)); // scroll the centerRect to correct location centerRect.OffsetBy(bounds.left, 0); @@ -1480,7 +1528,7 @@ TIconView::AnimateIcon(BBitmap *startIcon, BBitmap *endIcon) destRect.OffsetTo(centerRect.left, 0); // center the destRect inside of centerRect. off = (centerRect.Width() - destRect.Width()) / 2; - destRect.OffsetBy(BPoint(off,off)); + destRect.OffsetBy(BPoint(off, off)); fOffBitmap->Lock(); fOffView->SetDrawingMode(B_OP_OVER); @@ -1507,12 +1555,12 @@ TIconView::AnimateIcon(BBitmap *startIcon, BBitmap *endIcon) void -TIconView::Update(int32, int32 cur, int32 previousSlot, int32 currentSlot, +TIconView::Update(int32, int32 current, int32 previousSlot, int32 currentSlot, bool forward) { // Animate the shrinking of the currently centered icon. - AnimateIcon(fCurLarge, fCurSmall); - + AnimateIcon(fCurrentLarge, fCurrentSmall); + int32 nslots = abs(previousSlot - currentSlot); int32 stepSize = kScrollStep; @@ -1520,14 +1568,13 @@ TIconView::Update(int32, int32 cur, int32 previousSlot, int32 currentSlot, // we were at the end of the list and we just moved to the start forward = false; if (previousSlot - currentSlot > 4) - stepSize = stepSize*2; - + stepSize *= 2; } else if (!forward && (currentSlot > previousSlot)) { // we're are moving backwards and we just hit start of list and // we wrapped to the end. forward = true; if (currentSlot - previousSlot > 4) - stepSize = stepSize*2; + stepSize *= 2; } int32 scrollValue = forward ? stepSize : -stepSize; @@ -1542,12 +1589,12 @@ TIconView::Update(int32, int32 cur, int32 previousSlot, int32 currentSlot, } fAutoScrolling = false; - TTeamGroup *teamGroup = (TTeamGroup *)fMgr->GroupList()->ItemAt(cur); + TTeamGroup *teamGroup = (TTeamGroup *)fManager->GroupList()->ItemAt(current); ASSERT(teamGroup); CacheIcons(teamGroup); // Animate the expansion of the currently centered icon - AnimateIcon(fCurSmall, fCurLarge); + AnimateIcon(fCurrentSmall, fCurrentLarge); } @@ -1570,7 +1617,7 @@ TIconView::ItemAtPoint(BPoint point) const for (int32 i = 0, verticalIndex = 0; ; i++) { - TTeamGroup *teamGroup = (TTeamGroup *)fMgr->GroupList()->ItemAt(i); + TTeamGroup *teamGroup = (TTeamGroup *)fManager->GroupList()->ItemAt(i); if (teamGroup == NULL) break; @@ -1597,7 +1644,7 @@ TIconView::ScrollTo(BPoint where) int32 TIconView::IndexAt(int32 slot) const { - BList *list = fMgr->GroupList(); + BList *list = fManager->GroupList(); int32 count = list->CountItems(); int32 slotIndex = 0; @@ -1627,29 +1674,29 @@ TIconView::SlotOf(int32 index) const BRect TIconView::FrameOf(int32 index) const { - BList *list = fMgr->GroupList(); - int32 visi = kCenterSlot - 1; + BList *list = fManager->GroupList(); + int32 visible = kCenterSlot - 1; // first few slots in view are empty TTeamGroup *teamGroup; for (int32 i = 0; i <= index; i++) { - teamGroup = (TTeamGroup *) list->ItemAt(i); + teamGroup = (TTeamGroup *)list->ItemAt(i); if (!OKToUse(teamGroup)) continue; - visi++; + visible++; } - return BRect(visi * kSlotSize, 0, (visi + 1) * kSlotSize - 1, kSlotSize - 1); + return BRect(visible * kSlotSize, 0, (visible + 1) * kSlotSize - 1, kSlotSize - 1); } void TIconView::DrawTeams(BRect update) { - int32 mainIndex = fMgr->CurIndex(); - BList *list = fMgr->GroupList(); + int32 mainIndex = fManager->CurrentIndex(); + BList *list = fManager->GroupList(); int32 count = list->CountItems(); BRect rect(kCenterSlot * kSlotSize, 0, @@ -1663,7 +1710,7 @@ TIconView::DrawTeams(BRect update) if (rect.Intersects(update) && teamGroup) { SetDrawingMode(B_OP_OVER); - + teamGroup->Draw(this, rect, !fAutoScrolling && (i == mainIndex)); if (i == mainIndex) @@ -1688,10 +1735,10 @@ TIconView::MouseDown(BPoint where) { int32 index = ItemAtPoint(where); if (index >= 0) { - int32 previousIndex = fMgr->CurIndex(); - int32 previousSlot = fMgr->CurSlot(); + int32 previousIndex = fManager->CurrentIndex(); + int32 previousSlot = fManager->CurrentSlot(); int32 currentSlot = SlotOf(index); - fMgr->SwitchToApp(previousIndex, index, (currentSlot > previousSlot)); + fManager->SwitchToApp(previousIndex, index, (currentSlot > previousSlot)); } } @@ -1701,7 +1748,7 @@ TIconView::Pulse() { uint32 modifiersKeys = modifiers(); if (fSwitcher->HairTrigger() && (modifiersKeys & B_CONTROL_KEY) == 0) { - fMgr->Stop(true, modifiersKeys); + fManager->Stop(true, modifiersKeys); return; } @@ -1712,7 +1759,7 @@ TIconView::Pulse() if (buttons != 0) { point = ConvertToScreen(point); if (!Window()->Frame().Contains(point)) - fMgr->Stop(false, 0); + fManager->Stop(false, 0); } } } @@ -1734,17 +1781,26 @@ TIconView::Hiding() // #pragma mark - -TWindowView::TWindowView(BRect rect, TSwitchMgr *mgr, TSwitcherWindow *window) - : BView(rect, "wlist_view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED), - fCurToken(-1), - fSwitcher(window), - fMgr(mgr) +TWindowView::TWindowView(BRect rect, TSwitchManager *manager, TSwitcherWindow *window) + : BView(rect, "wlist_view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED), + fCurrentToken(-1), + fSwitcher(window), + fManager(manager) { - SetViewColor(216,216,216); SetFont(be_plain_font); } +void +TWindowView::AttachedToWindow() +{ + if (Parent()) + SetViewColor(Parent()->ViewColor()); + else + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); +} + + void TWindowView::ScrollTo(BPoint where) { @@ -1764,7 +1820,7 @@ TWindowView::FrameOf(int32 index) const const int32 kWindowScrollSteps = 3; void -TWindowView::GetPreferredSize(float *w, float *h) +TWindowView::GetPreferredSize(float *_width, float *_height) { font_height fh; be_plain_font->GetHeight(&fh); @@ -1774,13 +1830,13 @@ TWindowView::GetPreferredSize(float *w, float *h) fItemHeight = fItemHeight + 3 + 3; // want fItemHeight to be divisible by kWindowScrollSteps. - fItemHeight = ((((int) fItemHeight) + kWindowScrollSteps) / kWindowScrollSteps) * - kWindowScrollSteps; + fItemHeight = ((((int) fItemHeight) + kWindowScrollSteps) / kWindowScrollSteps) + * kWindowScrollSteps; - *h = fItemHeight; + *_height = fItemHeight; // leave width alone - *w = Bounds().Width(); + *_width = Bounds().Width(); } @@ -1791,16 +1847,16 @@ TWindowView::ShowIndex(int32 newIndex) BPoint point(0, newIndex * fItemHeight); BRect bounds = Bounds(); - int32 groupIndex = fMgr->CurIndex(); - TTeamGroup *teamGroup = (TTeamGroup *)fMgr->GroupList()->ItemAt(groupIndex); + int32 groupIndex = fManager->CurrentIndex(); + TTeamGroup *teamGroup = (TTeamGroup *)fManager->GroupList()->ItemAt(groupIndex); if (!teamGroup) return; - window_info *windowInfo = fMgr->WindowInfo(groupIndex, newIndex); + window_info *windowInfo = fManager->WindowInfo(groupIndex, newIndex); if (windowInfo == NULL) return; - fCurToken = windowInfo->id; + fCurrentToken = windowInfo->id; free(windowInfo); if (bounds.top == point.y) @@ -1825,11 +1881,11 @@ TWindowView::ShowIndex(int32 newIndex) void TWindowView::Draw(BRect update) { - int32 groupIndex = fMgr->CurIndex(); - TTeamGroup *teamGroup = (TTeamGroup *) fMgr->GroupList()->ItemAt(groupIndex); + int32 groupIndex = fManager->CurrentIndex(); + TTeamGroup *teamGroup = (TTeamGroup *) fManager->GroupList()->ItemAt(groupIndex); if (!teamGroup) return; - + BRect bounds = Bounds(); int32 windowIndex = (int32) (bounds.top / fItemHeight); BRect windowRect = bounds; @@ -1843,20 +1899,20 @@ TWindowView::Draw(BRect update) windowRect.OffsetBy(0, fItemHeight); continue; } - - bool local = true; // is window in cur workspace? + // is window in current workspace? + + bool local = true; bool minimized = false; BString title; - window_info *windowInfo = fMgr->WindowInfo(groupIndex, windowIndex); + window_info *windowInfo = fManager->WindowInfo(groupIndex, windowIndex); if (windowInfo != NULL) { - if (SmartStrcmp(windowInfo->name, teamGroup->Name()) != 0) title << teamGroup->Name() << ": " << windowInfo->name; else title = teamGroup->Name(); - + int32 currentWorkspace = current_workspace(); if ((windowInfo->workspaces & (1 << currentWorkspace)) == 0) local = false; @@ -1887,7 +1943,7 @@ TWindowView::Draw(BRect update) DrawBitmap(bitmap, p); if (!local) { - SetHighColor(96, 96, 96); + SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_4_TINT)); p.x -= 8; p.y += 4; StrokeLine(p + BPoint(2, 2), p + BPoint(2, 2)); @@ -1926,7 +1982,7 @@ void TWindowView::Pulse() { // If selected window went away then reset to first window - window_info *windowInfo = get_window_info(fCurToken); + window_info *windowInfo = get_window_info(fCurrentToken); if (windowInfo == NULL) { Invalidate(); ShowIndex(0); @@ -1935,6 +1991,7 @@ TWindowView::Pulse() } +// #pragma mark - bool @@ -1964,7 +2021,7 @@ IsWindowOK(const window_info *windowInfo) if (windowInfo->is_mini) return true; - + return windowInfo->show_hide_level <= 0; } @@ -1980,7 +2037,7 @@ OKToUse(const TTeamGroup *teamGroup) return false; // skip the Deakbar itself - if (strcasecmp(teamGroup->Sig(), kDeskbarSignature) == 0) + if (strcasecmp(teamGroup->Signature(), kDeskbarSignature) == 0) return false; return true; @@ -2020,5 +2077,3 @@ SmartStrcmp(const char *s1, const char *s2) } - - diff --git a/src/apps/deskbar/Switcher.h b/src/apps/deskbar/Switcher.h index 5eb2c25ce0..870c088d8f 100644 --- a/src/apps/deskbar/Switcher.h +++ b/src/apps/deskbar/Switcher.h @@ -31,8 +31,6 @@ of Be Incorporated in the United States and other countries. Other brand product names are registered trademarks or trademarks of their respective holders. All rights reserved. */ - - #ifndef SWITCHER_H #define SWITCHER_H @@ -42,35 +40,35 @@ All rights reserved. #include #include + class TTeamGroup { -public: - TTeamGroup(); - TTeamGroup(BList *teams, uint32 flags, char *name, const char *sig); - virtual ~TTeamGroup(); + public: + TTeamGroup(); + TTeamGroup(BList *teams, uint32 flags, char *name, const char *sig); + virtual ~TTeamGroup(); - void Draw(BView *, BRect bounds, bool main); + void Draw(BView *, BRect bounds, bool main); - BList *TeamList() const - { return fTeams; } - const char *Name() const - { return fName; } - const char *Sig() const - { return fSig; } - uint32 Flags() const - { return fFlags; } - const BBitmap *SmallIcon() const - { return fSmallIcon; } - const BBitmap *LargeIcon() const - { return fLargeIcon; } + BList *TeamList() const + { return fTeams; } + const char *Name() const + { return fName; } + const char *Signature() const + { return fSignature; } + uint32 Flags() const + { return fFlags; } + const BBitmap *SmallIcon() const + { return fSmallIcon; } + const BBitmap *LargeIcon() const + { return fLargeIcon; } - -private: - BList *fTeams; - uint32 fFlags; - char fSig[B_MIME_TYPE_LENGTH]; - char *fName; - BBitmap *fSmallIcon; - BBitmap *fLargeIcon; + private: + BList *fTeams; + uint32 fFlags; + char fSignature[B_MIME_TYPE_LENGTH]; + char *fName; + BBitmap *fSmallIcon; + BBitmap *fLargeIcon; }; class TIconView; @@ -79,175 +77,190 @@ class TWindowView; class TSwitcherWindow; struct window_info; -class TSwitchMgr : public BHandler { -public: - TSwitchMgr(BPoint where); - virtual ~TSwitchMgr(); +class TSwitchManager : public BHandler { + public: + TSwitchManager(BPoint where); + virtual ~TSwitchManager(); - virtual void MessageReceived(BMessage *); + virtual void MessageReceived(BMessage *message); - void Stop(bool doAction, uint32 mods); - void Unblock(); - int32 CurIndex(); - int32 CurWindow(); - int32 CurSlot(); - BList *GroupList(); - int32 CountVisibleGroups(); - void CycleApp(bool forward, bool activate = false); - void CycleWindow(bool forward, bool wrap = true); - void SwitchToApp(int32 prevIndex, int32 newIndex, bool forward); - void Touch(bool zero = false); - bigtime_t IdleTime(); + void Stop(bool doAction, uint32 mods); + void Unblock(); + int32 CurrentIndex(); + int32 CurrentWindow(); + int32 CurrentSlot(); + BList *GroupList(); + int32 CountVisibleGroups(); - window_info *WindowInfo(int32 groupIndex, int32 wdIndex); - int32 CountWindows(int32 groupIndex, bool inCurrentWorkspace = false); - TTeamGroup *FindTeam(team_id, int32 *index); - -private: - void MainEntry(BMessage *); - void Process(bool forward, bool byWindow = false); - void QuickSwitch(BMessage *); - void SwitchWindow(team_id , bool forward, bool activate); - bool ActivateApp(bool forceShow, bool allowWorkspaceSwitch); - void ActivateWindow(int32 windowID = -1); + void QuitApp(); + void CycleApp(bool forward, bool activate = false); + void CycleWindow(bool forward, bool wrap = true); + void SwitchToApp(int32 prevIndex, int32 newIndex, bool forward); - TSwitcherWindow *fWindow; - sem_id fMainMonitor; - bool fBlock; - bigtime_t fSkipUntil; - BList fGroupList; - int32 fCurIndex; - int32 fCurWindow; - int32 fCurSlot; - int32 fWindowID; - bigtime_t fLastActivity; + void Touch(bool zero = false); + bigtime_t IdleTime(); + + window_info *WindowInfo(int32 groupIndex, int32 wdIndex); + int32 CountWindows(int32 groupIndex, bool inCurrentWorkspace = false); + TTeamGroup *FindTeam(team_id, int32 *index); + + private: + void MainEntry(BMessage *message); + void Process(bool forward, bool byWindow = false); + void QuickSwitch(BMessage *message); + void SwitchWindow(team_id team, bool forward, bool activate); + bool ActivateApp(bool forceShow, bool allowWorkspaceSwitch); + void ActivateWindow(int32 windowID = -1); + + TSwitcherWindow *fWindow; + sem_id fMainMonitor; + bool fBlock; + bigtime_t fSkipUntil; + BList fGroupList; + int32 fCurrentIndex; + int32 fCurrentWindow; + int32 fCurrentSlot; + int32 fWindowID; + bigtime_t fLastActivity; }; class TSwitcherWindow : public BWindow { -public: - TSwitcherWindow(BRect frame, TSwitchMgr *mgr); - virtual ~TSwitcherWindow(); + public: + TSwitcherWindow(BRect frame, TSwitchManager *mgr); + virtual ~TSwitcherWindow(); - virtual bool QuitRequested(); - virtual void DispatchMessage(BMessage *, BHandler *); - virtual void MessageReceived(BMessage *); - virtual void Show(); - virtual void Hide(); - virtual void WindowActivated(bool state); + virtual bool QuitRequested(); + virtual void DispatchMessage(BMessage *message, BHandler *target); + virtual void MessageReceived(BMessage *message); + virtual void Show(); + virtual void Hide(); + virtual void WindowActivated(bool state); - void DoKey(uint32 key, uint32 mods); - TIconView *IconView(); - TWindowView *WindowView(); - TBox *TopView(); - bool HairTrigger(); - void Update(int32 prev, int32 cur, int32 prevSlot, int32 curSlot, bool forward); - int32 SlotOf(int32); - void Redraw(int32 index); + void DoKey(uint32 key, uint32 mods); + TIconView *IconView(); + TWindowView *WindowView(); + TBox *TopView(); + bool HairTrigger(); + void Update(int32 previous, int32 current, int32 prevSlot, + int32 currentSlot, bool forward); + int32 SlotOf(int32); + void Redraw(int32 index); -private: - - TSwitchMgr *fMgr; - TIconView *fIconView; - TBox *fTopView; - TWindowView *fWindowView; - bool fHairTrigger; + private: + TSwitchManager *fManager; + TIconView *fIconView; + TBox *fTopView; + TWindowView *fWindowView; + bool fHairTrigger; }; class TWindowView : public BView { -public: - TWindowView(BRect, TSwitchMgr *, TSwitcherWindow *); + public: + TWindowView(BRect frame, TSwitchManager *manager, TSwitcherWindow *switcher); - void UpdateGroup(int32 groupIndex, int32 windowIndex); + void UpdateGroup(int32 groupIndex, int32 windowIndex); - virtual void Draw(BRect update); - virtual void Pulse(); - virtual void GetPreferredSize(float *w, float *h); - void ScrollTo(float x, float y) - { ScrollTo(BPoint(x,y)); } - virtual void ScrollTo(BPoint where); + virtual void AttachedToWindow(); + virtual void Draw(BRect update); + virtual void Pulse(); + virtual void GetPreferredSize(float *w, float *h); + void ScrollTo(float x, float y) + { ScrollTo(BPoint(x,y)); } + virtual void ScrollTo(BPoint where); - void ShowIndex(int32 windex); - BRect FrameOf(int32 index) const; + void ShowIndex(int32 windex); + BRect FrameOf(int32 index) const; -private: - - int32 fCurToken; - float fItemHeight; - TSwitcherWindow *fSwitcher; - TSwitchMgr *fMgr; - bool fLocal; + private: + int32 fCurrentToken; + float fItemHeight; + TSwitcherWindow *fSwitcher; + TSwitchManager *fManager; + bool fLocal; }; class TIconView : public BView { -public: - TIconView(BRect , TSwitchMgr *, TSwitcherWindow *); - ~TIconView(); + public: + TIconView(BRect frame, TSwitchManager *manager, TSwitcherWindow *switcher); + ~TIconView(); - void Showing(); - void Hiding(); + void Showing(); + void Hiding(); - virtual void KeyDown(const char *bytes, int32 numBytes); - virtual void Pulse(); - virtual void MouseDown(BPoint ); - virtual void Draw(BRect ); - - void ScrollTo(float x, float y) - { ScrollTo(BPoint(x,y)); } - virtual void ScrollTo(BPoint where); - void Update(int32 prev, int32 cur, int32 prevSlot, int32 curSlot, bool forward); - void DrawTeams(BRect update); - int32 SlotOf(int32) const; - BRect FrameOf(int32) const; - int32 ItemAtPoint(BPoint) const; - int32 IndexAt(int32 slot) const; - void CenterOn(int32 index); + virtual void KeyDown(const char *bytes, int32 numBytes); + virtual void Pulse(); + virtual void MouseDown(BPoint ); + virtual void Draw(BRect ); -private: - - void CacheIcons(TTeamGroup *); - void AnimateIcon(BBitmap *startIcon, BBitmap *endIcon); + void ScrollTo(float x, float y) + { ScrollTo(BPoint(x,y)); } + virtual void ScrollTo(BPoint where); + void Update(int32 previous, int32 current, int32 previousSlot, + int32 currentSlot, bool forward); + void DrawTeams(BRect update); + int32 SlotOf(int32) const; + BRect FrameOf(int32) const; + int32 ItemAtPoint(BPoint) const; + int32 IndexAt(int32 slot) const; + void CenterOn(int32 index); - bool fAutoScrolling; - bool fCapsState; - TSwitcherWindow *fSwitcher; - TSwitchMgr *fMgr; - BBitmap *fOffBitmap; - BView *fOffView; - BBitmap *fCurSmall; - BBitmap *fCurLarge; + private: + void CacheIcons(TTeamGroup *); + void AnimateIcon(BBitmap *startIcon, BBitmap *endIcon); + + bool fAutoScrolling; + bool fCapsState; + TSwitcherWindow *fSwitcher; + TSwitchManager *fManager; + BBitmap *fOffBitmap; + BView *fOffView; + BBitmap *fCurrentSmall; + BBitmap *fCurrentLarge; }; class TBox : public BBox { -public: - TBox(BRect bounds, TSwitchMgr *manager, TSwitcherWindow *, TIconView *iconView); + public: + TBox(BRect bounds, TSwitchManager *manager, TSwitcherWindow *, TIconView *iconView); - virtual void Draw(BRect update); - virtual void AllAttached(); - virtual void DrawIconScrollers(bool force); - virtual void DrawWindowScrollers(bool force); - virtual void MouseDown(BPoint where); + virtual void Draw(BRect update); + virtual void AllAttached(); + virtual void DrawIconScrollers(bool force); + virtual void DrawWindowScrollers(bool force); + virtual void MouseDown(BPoint where); -private: - TSwitchMgr *fMgr; - TSwitcherWindow *fWindow; - TIconView *fIconView; - BRect fCenter; - bool fLeftScroller; - bool fRightScroller; - bool fUpScroller; - bool fDownScroller; + private: + TSwitchManager *fManager; + TSwitcherWindow *fWindow; + TIconView *fIconView; + BRect fCenter; + bool fLeftScroller; + bool fRightScroller; + bool fUpScroller; + bool fDownScroller; }; -inline int32 TSwitcherWindow::SlotOf(int32 i) - { return fIconView->SlotOf(i); } +inline int32 +TSwitcherWindow::SlotOf(int32 i) +{ + return fIconView->SlotOf(i); +} -inline TIconView *TSwitcherWindow::IconView() - { return fIconView; } +inline TIconView * +TSwitcherWindow::IconView() +{ + return fIconView; +} -inline TWindowView *TSwitcherWindow::WindowView() - { return fWindowView; } +inline TWindowView * +TSwitcherWindow::WindowView() +{ + return fWindowView; +} -inline void TSwitchMgr::Touch(bool zero) - { fLastActivity = zero ? 0 : system_time(); } +inline void +TSwitchManager::Touch(bool zero) +{ + fLastActivity = zero ? 0 : system_time(); +} -#endif +#endif /* SWITCHER_H */ diff --git a/src/apps/deskbar/TimeView.cpp b/src/apps/deskbar/TimeView.cpp index f57b00f2d4..e6ebdcb34f 100644 --- a/src/apps/deskbar/TimeView.cpp +++ b/src/apps/deskbar/TimeView.cpp @@ -335,9 +335,6 @@ TTimeView::MouseDown(BPoint point) Pulse(); #ifdef _SHOW_CALENDAR_MENU_ITEM - if (!fShowingDate) - return; - // see if the user holds down the button long enough to show him the calendar bigtime_t startTime = system_time(); diff --git a/src/apps/deskbar/WindowMenuItem.cpp b/src/apps/deskbar/WindowMenuItem.cpp index d39585dd05..03d0927eb5 100644 --- a/src/apps/deskbar/WindowMenuItem.cpp +++ b/src/apps/deskbar/WindowMenuItem.cpp @@ -61,7 +61,8 @@ TWindowMenuItem::TWindowMenuItem(const char *title, int32 id, fDragging(dragging), fExpanded(false), fRequireUpdate(false), - fModified(false) + fModified(false), + fFullTitle("") { Initialize(title); } @@ -111,6 +112,25 @@ TWindowMenuItem::ChangedState() } +void +TWindowMenuItem::SetLabel(const char* string) +{ + fFullTitle = string; + BString truncatedTitle = fFullTitle; + + if (fExpanded && Menu()) { + BPoint contLoc = ContentLocation() + BPoint(kHPad, kVPad); + contLoc.x += kIconRect.Width() + kLabelOffset; + + be_plain_font->TruncateString(&truncatedTitle, B_TRUNCATE_MIDDLE, + Frame().Width() - contLoc.x - 3.0f); + } + + if (strcmp(Label(), truncatedTitle.String()) != 0) + BMenuItem::SetLabel(truncatedTitle.String()); +} + + int32 TWindowMenuItem::ID() { @@ -126,10 +146,12 @@ TWindowMenuItem::GetContentSize(float *width, float *height) if (fID >= 0) *width += fBitmap->Bounds().Width() + kLabelOffset; } else - *width = Frame().Width() - kHPad; + *width = Frame().Width()/* - kHPad*/; - // ToDo: label width is not correct yet - the text label is - // always written completely, if it fits or not! + // Note: when the item is in "expanded mode", ie embedded into + // the Deskbar itself, then a truncated label is used in SetLabel() + // The code here is ignorant of this fact, but it doesn't seem to + // hurt anything. *height = (fID >= 0) ? fBitmap->Bounds().Height() : 0.0f; float labelHeight = fTitleAscent + fTitleDescent; @@ -155,7 +177,7 @@ TWindowMenuItem::Draw() menu->FillRect(frame); if (fExpanded) { - rgb_color shadow = tint_color(menuColor, B_DARKEN_1_TINT); + rgb_color shadow = tint_color(menuColor, (B_NO_TINT + B_DARKEN_1_TINT) / 2.0f); menu->SetHighColor(shadow); frame.right = frame.left + kHPad / 2; menu->FillRect(frame); @@ -169,7 +191,6 @@ TWindowMenuItem::Draw() } else menu->SetLowColor(menuColor); - menu->MovePenTo(ContentLocation()); DrawContent(); menu->PopState(); } @@ -185,8 +206,8 @@ TWindowMenuItem::DrawContent() BRect frame(Frame()); BPoint contLoc = ContentLocation() + BPoint(kHPad, kVPad); - if (fExpanded) - contLoc.x += kHPad; +// if (fExpanded) +// contLoc.x += kHPad; menu->SetDrawingMode(B_OP_COPY); if (fID >= 0) { @@ -213,6 +234,7 @@ TWindowMenuItem::DrawContent() menu->MovePenTo(contLoc); // Set the pen color so that the label is always visible. menu->SetHighColor(0, 0, 0); + BMenuItem::DrawContent(); } @@ -249,7 +271,10 @@ TWindowMenuItem::Invoke(BMessage *) void TWindowMenuItem::ExpandedItem(bool status) { - fExpanded = status; + if (fExpanded != status) { + fExpanded = status; + SetLabel(fFullTitle.String()); + } } diff --git a/src/apps/deskbar/WindowMenuItem.h b/src/apps/deskbar/WindowMenuItem.h index a5f1015296..1621c0ac8b 100644 --- a/src/apps/deskbar/WindowMenuItem.h +++ b/src/apps/deskbar/WindowMenuItem.h @@ -59,6 +59,8 @@ class TWindowMenuItem : public BMenuItem { bool RequiresUpdate(); bool ChangedState(); + virtual void SetLabel(const char* string); + protected: void Initialize(const char *title); virtual void GetContentSize(float *width, float *height); @@ -67,17 +69,18 @@ class TWindowMenuItem : public BMenuItem { virtual void Draw(); private: - int32 fID; - bool fMini; - bool fCurrentWorkSpace; - const BBitmap *fBitmap; - float fTitleWidth; - float fTitleAscent; - float fTitleDescent; - bool fDragging; - bool fExpanded; - bool fRequireUpdate; - bool fModified; + int32 fID; + bool fMini; + bool fCurrentWorkSpace; + const BBitmap* fBitmap; + float fTitleWidth; + float fTitleAscent; + float fTitleDescent; + bool fDragging; + bool fExpanded; + bool fRequireUpdate; + bool fModified; + BString fFullTitle; }; /****************************************************************************