Ticket #7051: Deskbar Persist Expanded State 8.diff
File Deskbar Persist Expanded State 8.diff, 7.2 KB (added by , 13 years ago) |
---|
-
src/apps/deskbar/BarApp.cpp
diff --git src/apps/deskbar/BarApp.cpp src/apps/deskbar/BarApp.cpp index 58664f7..9f42ca3 100644
TBarApp::TBarApp() 95 95 InitSettings(); 96 96 InitIconPreloader(); 97 97 98 fBarWindow = new TBarWindow(); 99 98 100 be_roster->StartWatching(this); 99 101 100 102 gLocalizedNamePreferred … … TBarApp::TBarApp() 119 121 120 122 fSwitcherMessenger = BMessenger(new TSwitchManager(fSettings.switcherLoc)); 121 123 122 fBarWindow = new TBarWindow();123 124 fBarWindow->Show(); 124 125 126 // Call UpdatePlacement() after the window is shown because expanded apps 127 // need to resize the window. 128 if (fBarWindow->Lock()) { 129 BarView()->UpdatePlacement(); 130 fBarWindow->Unlock(); 131 } 132 125 133 // this messenger now targets the barview instead of the 126 134 // statusview so that all additions to the tray 127 135 // follow the same path … … TBarApp::AddTeam(team_id team, uint32 flags, const char* sig, entry_ref* ref) 645 653 646 654 sBarTeamInfoList.AddItem(barInfo); 647 655 656 if (fSettings.expandNewTeams) 657 BarView()->AddExpandedItem(sig); 658 648 659 int32 subsCount = sSubscribers.CountItems(); 649 660 if (subsCount > 0) { 650 661 for (int32 i = 0; i < subsCount; i++) { -
src/apps/deskbar/BarView.cpp
diff --git src/apps/deskbar/BarView.cpp src/apps/deskbar/BarView.cpp index 6e71956..e6d9f39 100644
const int32 kDefaultRecentAppCount = 10; 68 68 69 69 const int32 kMenuTrackMargin = 20; 70 70 71 71 72 TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, 72 73 bool showInterval, uint32 state, float, bool showTime) 73 74 : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), … … TBarView::~TBarView() 99 100 { 100 101 delete fDragMessage; 101 102 delete fCachedTypesList; 103 104 RemoveExpandedItems(); 102 105 } 103 106 104 107 … … TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height) 405 408 windowHeight = screenFrame.bottom; 406 409 windowWidth = fBarMenuBar->Frame().Width(); 407 410 } else if (fState == kExpandoState) { 408 if (fVertical) 411 if (fVertical) { 409 412 // top left or right 410 413 windowHeight = fExpando->Frame().bottom; 411 else {414 } else { 412 415 // top or bottom, full 413 416 fExpando->CheckItemSizes(0); 414 417 windowHeight = kHModeHeight; … … TBarView::ChangeState(int32 state, bool vertical, bool left, bool top) 528 531 PlaceBeMenu(); 529 532 PlaceTray(vertSwap, leftSwap, screenFrame); 530 533 531 // We need to keep track of what apps are expanded. 532 BList expandedItems; 533 BString* signature = NULL; 534 if (fVertical && Expando() 535 && static_cast<TBarApp*>(be_app)->Settings()->superExpando) { 536 // Get a list of the signatures of expanded apps. Can't use 537 // team_id because there can be more than one team per application 538 if (fVertical && Expando() && vertical && fExpando) { 539 for (int index = 0; index < fExpando->CountItems(); index++) { 540 TTeamMenuItem* item 541 = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(index)); 542 if (item != NULL && item->IsExpanded()) { 543 signature = new BString(item->Signature()); 544 expandedItems.AddItem((void*)signature); 545 } 546 } 547 } 548 } 534 // Keep track of which apps are expanded 535 SaveExpandedItems(); 549 536 550 537 PlaceApplicationBar(screenFrame); 551 538 SizeWindow(screenFrame); 552 539 PositionWindow(screenFrame); 553 540 Window()->UpdateIfNeeded(); 554 541 555 // Re-expand those apps. 556 if (expandedItems.CountItems() > 0) { 557 for (int sigIndex = expandedItems.CountItems(); sigIndex-- > 0;) { 558 signature = static_cast<BString*>(expandedItems.ItemAt(sigIndex)); 559 if (signature == NULL) 560 continue; 561 562 // Start at the 'bottom' of the list working up. 563 // Prevents being thrown off by expanding items. 564 for (int teamIndex = fExpando->CountItems(); teamIndex-- > 0;) { 565 TTeamMenuItem* item 566 = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex)); 567 if (item != NULL && !signature->Compare(item->Signature())) { 568 item->ToggleExpandState(false); 542 // Re-expand apps 543 ExpandItems(); 544 Invalidate(); 545 } 546 547 548 void 549 TBarView::SaveExpandedItems() 550 { 551 if (fExpando == NULL || fExpando->CountItems() <= 0) 552 return; 553 554 // Get a list of the signatures of expanded apps. Can't use 555 // team_id because there can be more than one team per application 556 for (int32 i = 0; i < fExpando->CountItems(); i++) { 557 TTeamMenuItem* teamItem 558 = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(i)); 559 560 if (teamItem != NULL && teamItem->IsExpanded()) 561 AddExpandedItem(teamItem->Signature()); 562 } 563 } 564 565 566 void 567 TBarView::RemoveExpandedItems() 568 { 569 while (!fExpandedItems.IsEmpty()) 570 delete static_cast<BString*>(fExpandedItems.RemoveItem((int32)0)); 571 fExpandedItems.MakeEmpty(); 572 } 573 574 575 void 576 TBarView::ExpandItems() 577 { 578 if (fExpando == NULL || !fVertical || !Expando() 579 || !static_cast<TBarApp*>(be_app)->Settings()->superExpando 580 || fExpandedItems.CountItems() <= 0) 581 return; 582 583 // Start at the 'bottom' of the list working up. 584 // Prevents being thrown off by expanding items. 585 for (int32 i = fExpando->CountItems() - 1; i >= 0; i--) { 586 TTeamMenuItem* teamItem 587 = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(i)); 588 589 if (teamItem != NULL) { 590 // Start at the 'bottom' of the fExpandedItems list working up 591 // matching the order of the fExpando list in the outer loop. 592 for (int32 j = fExpandedItems.CountItems() - 1; j >= 0; j--) { 593 BString* itemSig = 594 static_cast<BString*>(fExpandedItems.ItemAt(j)); 595 596 if (itemSig->Compare(teamItem->Signature()) == 0) { 597 // Found it, expand the item and delete signature from 598 // the list so that we don't consider it for later items. 599 teamItem->ToggleExpandState(false); 600 fExpandedItems.RemoveItem(j); 601 delete itemSig; 569 602 break; 570 603 } 571 604 } 572 605 } 606 } 573 607 574 // Clean up expanded signature list. 575 while (!expandedItems.IsEmpty()) { 576 delete static_cast<BString*>(expandedItems.RemoveItem((int32)0)); 577 } 608 // Clean up the expanded items list 609 RemoveExpandedItems(); 578 610 579 fExpando->SizeWindow(); 611 fExpando->SizeWindow(); 612 } 613 614 615 void 616 TBarView::AddExpandedItem(const char* signature) 617 { 618 bool shouldAdd = true; 619 620 for (int32 i = 0; i < fExpandedItems.CountItems(); i++) { 621 BString *itemSig = static_cast<BString*>(fExpandedItems.ItemAt(i)); 622 if (itemSig->Compare(signature) == 0) { 623 // already in the list, don't add the signature 624 shouldAdd = false; 625 break; 626 } 580 627 } 581 628 582 Invalidate(); 629 if (shouldAdd) 630 fExpandedItems.AddItem(static_cast<void*>(new BString(signature))); 583 631 } 584 632 585 633 -
src/apps/deskbar/BarView.h
diff --git src/apps/deskbar/BarView.h src/apps/deskbar/BarView.h index 9e165cb..5939a65 100644
class TBarView : public BView { 141 141 TExpandoMenuBar* ExpandoMenuBar() const; 142 142 TBarMenuBar* BarMenuBar() const; 143 143 TDragRegion* DragRegion() const { return fDragRegion; } 144 144 void AddExpandedItem(const char* signature); 145 145 146 private: 146 147 friend class TBeMenu; 147 148 friend class PreferencesWindow; … … class TBarView : public BView { 151 152 void PlaceBeMenu(); 152 153 void PlaceTray(bool vertSwap, bool leftSwap, BRect screenFrame); 153 154 void PlaceApplicationBar(BRect screenFrame); 155 void SaveExpandedItems(); 156 void RemoveExpandedItems(); 157 void ExpandItems(); 154 158 155 159 TBarMenuBar* fBarMenuBar; 156 160 TExpandoMenuBar* fExpando; … … class TBarView : public BView { 177 181 uint32 fMaxRecentApps; 178 182 179 183 TTeamMenuItem* fLastDragItem; 184 BList fExpandedItems; 180 185 }; 181 186 182 187