Deskbar: Don't keep state in TBarView
... get/set from/to the app settings instead. This synchronises bar view state and app settings state. Set state in the app settings when TBarView::ChangeState() is called. This updates the in-memory settings, they get saved on quit (reboot). Change order of ChangeState() to be same as settings: vertical, left, top, state. Pass kExpandoState or kMiniState instead of a true or false. kFullState is deprecated and unused. Change-Id: I907e381396d99bd6d81cac8986dd6769735b6cd6 Reviewed-on: https://review.haiku-os.org/c/haiku/+/10834 Reviewed-by: John Scipione <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
@@ -142,10 +142,6 @@ TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
|
||||
fTrayLocation(1),
|
||||
fIsRaised(false),
|
||||
fMouseDownOutside(false),
|
||||
fVertical(vertical),
|
||||
fTop(top),
|
||||
fLeft(left),
|
||||
fState(state),
|
||||
fRefsRcvdOnly(true),
|
||||
fDragMessage(NULL),
|
||||
fCachedTypesList(NULL),
|
||||
@@ -171,7 +167,7 @@ TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
|
||||
// determine the initial Be menu size
|
||||
// (will be updated later)
|
||||
BRect menuFrame(frame);
|
||||
if (fVertical)
|
||||
if (Vertical())
|
||||
menuFrame.bottom = menuFrame.top + fTabHeight - 1;
|
||||
else
|
||||
menuFrame.bottom = menuFrame.top + TeamMenuItemHeight();
|
||||
@@ -198,9 +194,9 @@ TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
|
||||
|
||||
// create and add the expando menu bar
|
||||
fExpandoMenuBar = new TExpandoMenuBar(
|
||||
fVertical ? B_ITEMS_IN_COLUMN : B_ITEMS_IN_ROW, this);
|
||||
Vertical() ? B_ITEMS_IN_COLUMN : B_ITEMS_IN_ROW, this);
|
||||
fInlineScrollView = new TInlineScrollView(fExpandoMenuBar,
|
||||
fVertical ? B_VERTICAL : B_HORIZONTAL);
|
||||
Vertical() ? B_VERTICAL : B_HORIZONTAL);
|
||||
AddChild(fInlineScrollView);
|
||||
|
||||
// hide the expando menu bar in mini-mode
|
||||
@@ -238,7 +234,7 @@ TBarView::AttachedToWindow()
|
||||
fTrackingHookData.fTarget = BMessenger(this);
|
||||
fTrackingHookData.fDragMessage = new BMessage(B_REFS_RECEIVED);
|
||||
|
||||
if (!fVertical)
|
||||
if (!Vertical())
|
||||
UpdatePlacement(); // update MenuBarHeight
|
||||
}
|
||||
|
||||
@@ -267,7 +263,7 @@ TBarView::Draw(BRect)
|
||||
else if (AcrossBottom())
|
||||
StrokeLine(bounds.LeftTop(), bounds.RightTop());
|
||||
|
||||
if (fVertical && fState == kExpandoState) {
|
||||
if (Vertical() && State() == kExpandoState) {
|
||||
SetHighColor(hilite);
|
||||
BRect frame(fExpandoMenuBar->Frame());
|
||||
StrokeLine(BPoint(frame.left, frame.top - 1),
|
||||
@@ -464,12 +460,12 @@ TBarView::PlaceDeskbarMenu()
|
||||
|
||||
// Calculate the size of the deskbar menu
|
||||
BRect menuFrame(Bounds());
|
||||
if (fVertical) {
|
||||
width = static_cast<TBarApp*>(be_app)->Settings()->width;
|
||||
if (Vertical()) {
|
||||
width = fBarApp->Settings()->width;
|
||||
height = fTabHeight;
|
||||
} else {
|
||||
// horizontal
|
||||
if (fState == kMiniState) {
|
||||
if (State() == kMiniState) {
|
||||
width = gMinimumWindowWidth;
|
||||
height = std::max(fTabHeight,
|
||||
kGutter + fReplicantTray->MaxReplicantHeight() + kGutter);
|
||||
@@ -489,11 +485,11 @@ TBarView::PlaceDeskbarMenu()
|
||||
} else
|
||||
fBarMenuBar->SmartResize(-1, -1);
|
||||
|
||||
if (fState == kMiniState) {
|
||||
if (State() == kMiniState) {
|
||||
// vertical or horizontal mini
|
||||
fBarMenuBar->RemoveSeperatorItem();
|
||||
fBarMenuBar->AddTeamMenu();
|
||||
} else if (fVertical) {
|
||||
} else if (Vertical()) {
|
||||
fBarMenuBar->RemoveSeperatorItem();
|
||||
fBarMenuBar->RemoveTeamMenu();
|
||||
} else {
|
||||
@@ -522,11 +518,11 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap)
|
||||
fDragRegion->ResizeToPreferred();
|
||||
// also resizes replicant tray
|
||||
|
||||
if (fVertical) {
|
||||
if (Vertical()) {
|
||||
if (fResizeControl->IsHidden())
|
||||
fResizeControl->Show();
|
||||
|
||||
if (fLeft) {
|
||||
if (Left()) {
|
||||
// move replicant tray past dragger width on left
|
||||
// also down 1px so it won't cover the border
|
||||
fReplicantTray->MoveTo(gDragWidth + kGutter, kGutter);
|
||||
@@ -542,14 +538,14 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap)
|
||||
statusLoc.y = fBarMenuBar->Frame().bottom + 1;
|
||||
} else {
|
||||
// horizontal
|
||||
if (fState == kMiniState) {
|
||||
if (State() == kMiniState) {
|
||||
// horizontal mini
|
||||
statusLoc.x = fLeft ? fBarMenuBar->Frame().right + 1 : 0;
|
||||
statusLoc.x = Left() ? fBarMenuBar->Frame().right + 1 : 0;
|
||||
statusLoc.y = 0;
|
||||
|
||||
// move past dragger and top border
|
||||
// and make room for the top and bottom borders
|
||||
fReplicantTray->MoveTo(fLeft ? gDragWidth : 0, kGutter);
|
||||
fReplicantTray->MoveTo(Left() ? gDragWidth : 0, kGutter);
|
||||
fReplicantTray->ResizeBy(0, -4);
|
||||
} else {
|
||||
// move tray right and down to not cover border, resize by same
|
||||
@@ -566,10 +562,10 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap)
|
||||
// make room for top and bottom border
|
||||
fResizeControl->ResizeTo(gDragWidth, fDragRegion->Bounds().Height() - 2);
|
||||
|
||||
if (fVertical) {
|
||||
if (Vertical()) {
|
||||
// move resize control into place based on width setting
|
||||
fResizeControl->MoveTo(
|
||||
fLeft ? fBarApp->Settings()->width - gDragWidth : 0, 1);
|
||||
Left() ? fBarApp->Settings()->width - gDragWidth : 0, 1);
|
||||
if (fResizeControl->IsHidden())
|
||||
fResizeControl->Show();
|
||||
} else {
|
||||
@@ -586,17 +582,17 @@ void
|
||||
TBarView::PlaceApplicationBar()
|
||||
{
|
||||
BRect screenFrame = (BScreen(Window())).Frame();
|
||||
if (fState == kMiniState) {
|
||||
if (State() == kMiniState) {
|
||||
if (!fInlineScrollView->IsHidden())
|
||||
fInlineScrollView->Hide();
|
||||
|
||||
SizeWindow(screenFrame);
|
||||
PositionWindow(screenFrame);
|
||||
Window()->UpdateIfNeeded();
|
||||
if (!fVertical) {
|
||||
if (!Vertical()) {
|
||||
// move the menu bar into place after the window has been resized
|
||||
// based on replicant tray
|
||||
fBarMenuBar->MoveTo(fLeft ? 0 : fDragRegion->Bounds().right + 1,
|
||||
fBarMenuBar->MoveTo(Left() ? 0 : fDragRegion->Bounds().right + 1,
|
||||
0);
|
||||
}
|
||||
Invalidate();
|
||||
@@ -607,13 +603,13 @@ TBarView::PlaceApplicationBar()
|
||||
fInlineScrollView->Show();
|
||||
|
||||
BRect expandoFrame(0, 0, 0, 0);
|
||||
if (fVertical) {
|
||||
if (Vertical()) {
|
||||
// left or right
|
||||
expandoFrame.left = fDragRegion->Frame().left;
|
||||
expandoFrame.top = fTrayLocation != 0 ? fDragRegion->Frame().bottom + 1
|
||||
: fBarMenuBar->Frame().bottom + 1;
|
||||
expandoFrame.right = fBarApp->Settings()->width;
|
||||
expandoFrame.bottom = fState == kFullState ? screenFrame.bottom
|
||||
expandoFrame.bottom = State() == kFullState ? screenFrame.bottom
|
||||
: Frame().bottom;
|
||||
} else {
|
||||
// top or bottom
|
||||
@@ -625,7 +621,7 @@ TBarView::PlaceApplicationBar()
|
||||
|
||||
fInlineScrollView->DetachScrollers();
|
||||
fInlineScrollView->MoveTo(expandoFrame.LeftTop());
|
||||
fInlineScrollView->ResizeTo(expandoFrame.Width(), fVertical
|
||||
fInlineScrollView->ResizeTo(expandoFrame.Width(), Vertical()
|
||||
? screenFrame.bottom - expandoFrame.top : expandoFrame.bottom);
|
||||
fExpandoMenuBar->ResizeTo(expandoFrame.Width(), expandoFrame.Height());
|
||||
fExpandoMenuBar->MoveTo(0, 0);
|
||||
@@ -646,13 +642,13 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width,
|
||||
if (setToHiddenSize) {
|
||||
windowHeight = kHiddenDimension;
|
||||
|
||||
if (fState == kExpandoState && !fVertical) {
|
||||
if (State() == kExpandoState && !Vertical()) {
|
||||
// top or bottom, full
|
||||
windowWidth = screenFrame.Width();
|
||||
} else
|
||||
windowWidth = kHiddenDimension;
|
||||
} else if (fVertical) {
|
||||
if (fState == kFullState) {
|
||||
} else if (Vertical()) {
|
||||
if (State() == kFullState) {
|
||||
// full state has minimum screen window height
|
||||
windowHeight = std::max(screenFrame.bottom, windowHeight);
|
||||
} else {
|
||||
@@ -662,7 +658,7 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width,
|
||||
else
|
||||
windowHeight = fBarMenuBar->Frame().bottom;
|
||||
|
||||
if (fState == kExpandoState && fExpandoMenuBar != NULL) {
|
||||
if (State() == kExpandoState && fExpandoMenuBar != NULL) {
|
||||
// top left or right
|
||||
windowHeight += fExpandoMenuBar->Bounds().Height();
|
||||
// use Height() here, not bottom so view can be scrolled
|
||||
@@ -672,7 +668,7 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width,
|
||||
windowWidth = fBarApp->Settings()->width;
|
||||
} else {
|
||||
// horizontal
|
||||
if (fState == kMiniState) {
|
||||
if (State() == kMiniState) {
|
||||
// four corners horizontal
|
||||
windowHeight = fBarMenuBar->Frame().Height();
|
||||
windowWidth = fDragRegion->Frame().Width()
|
||||
@@ -710,11 +706,11 @@ TBarView::PositionWindow(BRect screenFrame)
|
||||
|
||||
BPoint moveLoc(0, 0);
|
||||
// right, expanded, mini, or full
|
||||
if (!fLeft && (fVertical || fState == kMiniState))
|
||||
if (!Left() && (Vertical() || State() == kMiniState))
|
||||
moveLoc.x = screenFrame.right - windowWidth;
|
||||
|
||||
// bottom, full
|
||||
if (!fTop)
|
||||
if (!Top())
|
||||
moveLoc.y = screenFrame.bottom - windowHeight;
|
||||
|
||||
Window()->MoveTo(moveLoc);
|
||||
@@ -737,13 +733,6 @@ TBarView::CheckForScrolling()
|
||||
void
|
||||
TBarView::SaveSettings()
|
||||
{
|
||||
desk_settings* settings = fBarApp->Settings();
|
||||
|
||||
settings->vertical = fVertical;
|
||||
settings->left = fLeft;
|
||||
settings->top = fTop;
|
||||
settings->state = fState;
|
||||
|
||||
fReplicantTray->SaveTimeSettings();
|
||||
}
|
||||
|
||||
@@ -751,19 +740,18 @@ TBarView::SaveSettings()
|
||||
void
|
||||
TBarView::UpdatePlacement()
|
||||
{
|
||||
ChangeState(fState, fVertical, fLeft, fTop);
|
||||
ChangeState(Vertical(), Left(), Top(), State());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TBarView::ChangeState(int32 state, bool vertical, bool left, bool top,
|
||||
bool async)
|
||||
TBarView::ChangeState(bool vertical, bool left, bool top, int32 state, bool async)
|
||||
{
|
||||
BMessage message(kUpdateOrientation);
|
||||
message.AddInt32("state", state);
|
||||
message.AddBool("vertical", vertical);
|
||||
message.AddBool("left", left);
|
||||
message.AddBool("top", top);
|
||||
message.AddInt32("state", state);
|
||||
|
||||
if (async)
|
||||
BMessenger(this).SendMessage(&message);
|
||||
@@ -775,19 +763,19 @@ TBarView::ChangeState(int32 state, bool vertical, bool left, bool top,
|
||||
void
|
||||
TBarView::_ChangeState(BMessage* message)
|
||||
{
|
||||
int32 state = message->FindInt32("state");
|
||||
bool vertical = message->FindBool("vertical");
|
||||
bool left = message->FindBool("left");
|
||||
bool top = message->FindBool("top");
|
||||
int32 state = message->FindInt32("state");
|
||||
|
||||
bool vertSwap = (fVertical != vertical);
|
||||
bool leftSwap = (fLeft != left);
|
||||
bool stateChanged = (fState != state);
|
||||
bool vertSwap = (Vertical() != vertical);
|
||||
bool leftSwap = (Left() != left);
|
||||
bool stateChanged = (State() != state);
|
||||
|
||||
fState = state;
|
||||
fVertical = vertical;
|
||||
fLeft = left;
|
||||
fTop = top;
|
||||
fBarApp->Settings()->vertical = vertical;
|
||||
fBarApp->Settings()->left = left;
|
||||
fBarApp->Settings()->top = top;
|
||||
fBarApp->Settings()->state = state;
|
||||
|
||||
if (stateChanged || vertSwap) {
|
||||
be_app->PostMessage(kStateChanged);
|
||||
@@ -799,7 +787,7 @@ TBarView::_ChangeState(BMessage* message)
|
||||
barWindow->SetSizeLimits();
|
||||
|
||||
if (vertSwap && fExpandoMenuBar != NULL) {
|
||||
if (fVertical) {
|
||||
if (Vertical()) {
|
||||
fInlineScrollView->SetOrientation(B_VERTICAL);
|
||||
fExpandoMenuBar->SetMenuLayout(B_ITEMS_IN_COLUMN);
|
||||
fExpandoMenuBar->StartMonitoringWindows();
|
||||
@@ -854,6 +842,48 @@ TBarView::HideDeskbar(bool hide)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TBarView::Vertical() const
|
||||
{
|
||||
return fBarApp->Settings()->vertical;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TBarView::Left() const
|
||||
{
|
||||
return fBarApp->Settings()->left;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TBarView::Top() const {
|
||||
return fBarApp->Settings()->top;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
TBarView::State() const
|
||||
{
|
||||
return fBarApp->Settings()->state;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TBarView::AcrossTop() const
|
||||
{
|
||||
return Top() && !Vertical() && State() != kMiniState;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TBarView::AcrossBottom() const
|
||||
{
|
||||
return !Top() && !Vertical() && State() != kMiniState;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// #pragma mark - Drag and Drop
|
||||
|
||||
|
||||
@@ -1117,7 +1147,7 @@ TBarView::HandleDeskbarMenu(BMessage* messagewithdestination)
|
||||
return;
|
||||
|
||||
// in mini-mode
|
||||
if (fVertical && fState != kExpandoState) {
|
||||
if (Vertical() && State() != kExpandoState) {
|
||||
// if drop is in the team menu, bail
|
||||
if (fBarMenuBar->CountItems() >= 2) {
|
||||
uint32 buttons;
|
||||
@@ -1282,11 +1312,11 @@ TBarView::TeamMenuItemHeight() const
|
||||
if (fBarApp->Settings()->hideLabels && iconSize > B_MINI_ICON) {
|
||||
// height is determined based solely on icon size
|
||||
return iconOnlyHeight;
|
||||
} else if (!fVertical || (fVertical && iconSize <= large)) {
|
||||
} else if (!Vertical() || (Vertical() && iconSize <= large)) {
|
||||
// horizontal or vertical with label on same row as icon:
|
||||
// height based on icon size or font size, whichever is bigger
|
||||
return std::max(iconOnlyHeight, labelHeight);
|
||||
} else if (fVertical && iconSize > large) {
|
||||
} else if (Vertical() && iconSize > large) {
|
||||
// vertical with label below icon: height based on icon and label
|
||||
return ceilf(iconOnlyHeight + labelHeight);
|
||||
} else {
|
||||
|
||||
+11
-19
@@ -96,27 +96,24 @@ public:
|
||||
void SaveSettings();
|
||||
|
||||
void UpdatePlacement();
|
||||
void ChangeState(int32 state, bool vertical, bool left,
|
||||
bool top, bool aSync = false);
|
||||
void ChangeState(bool vertical, bool left, bool top, int32 state,
|
||||
bool aSync = false);
|
||||
|
||||
void RaiseDeskbar(bool raise);
|
||||
void HideDeskbar(bool hide);
|
||||
|
||||
// window placement methods
|
||||
bool Vertical() const { return fVertical; };
|
||||
bool Left() const { return fLeft; };
|
||||
bool Top() const { return fTop; };
|
||||
bool AcrossTop() const { return fTop && !fVertical
|
||||
&& fState != kMiniState; };
|
||||
bool AcrossBottom() const { return !fTop && !fVertical
|
||||
&& fState != kMiniState; };
|
||||
bool Vertical() const;
|
||||
bool Left() const;
|
||||
bool Top() const;
|
||||
bool AcrossTop() const;
|
||||
bool AcrossBottom() const;
|
||||
|
||||
// window state methods
|
||||
bool ExpandoState() const
|
||||
{ return fState == kExpandoState; };
|
||||
bool FullState() const { return fState == kFullState; };
|
||||
bool MiniState() const { return fState == kMiniState; };
|
||||
int32 State() const { return fState; };
|
||||
bool ExpandoState() const { return State() == kExpandoState; };
|
||||
bool FullState() const { return State() == kFullState; };
|
||||
bool MiniState() const { return State() == kMiniState; };
|
||||
int32 State() const;
|
||||
|
||||
// drag and drop methods
|
||||
void CacheDragData(const BMessage* incoming);
|
||||
@@ -201,11 +198,6 @@ private:
|
||||
bool fIsRaised : 1;
|
||||
bool fMouseDownOutside : 1;
|
||||
|
||||
bool fVertical : 1;
|
||||
bool fTop : 1;
|
||||
bool fLeft : 1;
|
||||
int32 fState;
|
||||
|
||||
bigtime_t fPulseRate;
|
||||
bool fRefsRcvdOnly;
|
||||
BMessage* fDragMessage;
|
||||
|
||||
@@ -462,7 +462,7 @@ TBarWindow::SetDeskbarLocation(deskbar_location location, bool newExpandState)
|
||||
break;
|
||||
}
|
||||
|
||||
fBarView->ChangeState(expand, vertical, left, top);
|
||||
fBarView->ChangeState(vertical, left, top, expand ? kExpandoState : kMiniState);
|
||||
}
|
||||
|
||||
|
||||
@@ -494,7 +494,7 @@ TBarWindow::Expand(BMessage* message)
|
||||
bool vertical = fBarView->Vertical();
|
||||
bool left = fBarView->Left();
|
||||
bool top = fBarView->Top();
|
||||
fBarView->ChangeState(expand, vertical, left, top);
|
||||
fBarView->ChangeState(vertical, left, top, expand ? kExpandoState : kMiniState);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1560,7 +1560,7 @@ TDragRegion::SwitchModeForRegion(BPoint where, BRegion region,
|
||||
return true;
|
||||
}
|
||||
|
||||
fBarView->ChangeState(newState, newVertical, newLeft, newTop, true);
|
||||
fBarView->ChangeState(newVertical, newLeft, newTop, newState, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user