Build the fBarMenu object in the BarView constructor

... then resize it and move it to the desired size and location on update.

* Create an fBarApp pointer and use it, this is easier than having to keep casting to TBarApp.
This commit is contained in:
John Scipione
2013-04-14 02:49:37 -04:00
parent 541decfaab
commit 777fffe8f7
2 changed files with 31 additions and 29 deletions
+29 -29
View File
@@ -146,19 +146,33 @@ TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
fLastDragItem(NULL), fLastDragItem(NULL),
fMouseFilter(NULL) fMouseFilter(NULL)
{ {
// determine the initial Be menu size
BRect menuFrame(frame);
if (fVertical)
menuFrame.bottom = menuFrame.top + kMenuBarHeight;
else
menuFrame.bottom = menuFrame.top + fBarApp->IconSize() + 4;
// create and add the Be menu
fBarMenuBar = new TBarMenuBar(menuFrame, "BarMenuBar", this);
AddChild(fBarMenuBar);
// create and add the status tray
fReplicantTray = new TReplicantTray(this, fVertical); fReplicantTray = new TReplicantTray(this, fVertical);
fDragRegion = new TDragRegion(this, fReplicantTray); fDragRegion = new TDragRegion(this, fReplicantTray);
fDragRegion->AddChild(fReplicantTray); fDragRegion->AddChild(fReplicantTray);
if (fTrayLocation != 0) if (fTrayLocation != 0)
AddChild(fDragRegion); AddChild(fDragRegion);
// create and add the application menubar
fExpandoMenuBar = new TExpandoMenuBar(BRect(0, 0, 0, 0), fExpandoMenuBar = new TExpandoMenuBar(BRect(0, 0, 0, 0),
"ExpandoMenuBar", this, fVertical); "ExpandoMenuBar", this, fVertical);
fInlineScrollView = new TInlineScrollView(BRect(0, 0, 0, 0), fInlineScrollView = new TInlineScrollView(BRect(0, 0, 0, 0),
fExpandoMenuBar, fVertical ? B_VERTICAL : B_HORIZONTAL); fExpandoMenuBar, fVertical ? B_VERTICAL : B_HORIZONTAL);
AddChild(fInlineScrollView); AddChild(fInlineScrollView);
if (state == kMiniState) // If mini mode, hide the application menubar
if (state != kMiniState)
fInlineScrollView->Hide(); fInlineScrollView->Hide();
} }
@@ -276,7 +290,7 @@ TBarView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
if (transit == B_ENTERED_VIEW && EventMask() == 0) if (transit == B_ENTERED_VIEW && EventMask() == 0)
SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY); SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
desk_settings* settings = ((TBarApp*)be_app)->Settings(); desk_settings* settings = fBarApp->Settings();
bool alwaysOnTop = settings->alwaysOnTop; bool alwaysOnTop = settings->alwaysOnTop;
bool autoRaise = settings->autoRaise; bool autoRaise = settings->autoRaise;
bool autoHide = settings->autoHide; bool autoHide = settings->autoHide;
@@ -343,7 +357,7 @@ TBarView::MouseDown(BPoint where)
} }
} else { } else {
// hide deskbar if required // hide deskbar if required
desk_settings* settings = ((TBarApp*)be_app)->Settings(); desk_settings* settings = fBarApp->Settings();
bool alwaysOnTop = settings->alwaysOnTop; bool alwaysOnTop = settings->alwaysOnTop;
bool autoRaise = settings->autoRaise; bool autoRaise = settings->autoRaise;
bool autoHide = settings->autoHide; bool autoHide = settings->autoHide;
@@ -361,21 +375,8 @@ TBarView::MouseDown(BPoint where)
void void
TBarView::PlaceDeskbarMenu() TBarView::PlaceDeskbarMenu()
{ {
// Calculate the size of the deskbar menu float height;
BRect menuFrame(Bounds()); height = fVertical ? kMenuBarHeight : fBarApp->IconSize() + 4;
if (fVertical)
menuFrame.bottom = menuFrame.top + kMenuBarHeight;
else {
menuFrame.bottom = menuFrame.top
+ static_cast<TBarApp*>(be_app)->IconSize() + 4;
}
if (fBarMenuBar == NULL) {
// create the Be menu
fBarMenuBar = new TBarMenuBar(this, menuFrame, "BarMenuBar");
AddChild(fBarMenuBar);
} else
fBarMenuBar->SmartResize(-1, -1);
BPoint loc(B_ORIGIN); BPoint loc(B_ORIGIN);
float width = sMinimumWindowWidth; float width = sMinimumWindowWidth;
@@ -402,7 +403,7 @@ TBarView::PlaceDeskbarMenu()
fBarMenuBar->AddTeamMenu(); fBarMenuBar->AddTeamMenu();
} }
fBarMenuBar->SmartResize(width, menuFrame.Height()); fBarMenuBar->SmartResize(width, height);
fBarMenuBar->MoveTo(loc); fBarMenuBar->MoveTo(loc);
} }
@@ -485,11 +486,10 @@ TBarView::PlaceApplicationBar()
} else { } else {
// top or bottom // top or bottom
expandoFrame.top = 0; expandoFrame.top = 0;
int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize(); expandoFrame.bottom = fBarApp->IconSize() + 4;
expandoFrame.bottom = iconSize + 4;
if (fBarMenuBar != NULL) if (fBarMenuBar != NULL)
expandoFrame.left = fBarMenuBar->Frame().Width(); expandoFrame.left = fBarMenuBar->Frame().Width() + 1;
if (fTrayLocation != 0 && fDragRegion != NULL) { if (fTrayLocation != 0 && fDragRegion != NULL) {
expandoFrame.right = screenFrame.Width() expandoFrame.right = screenFrame.Width()
@@ -530,9 +530,8 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height)
{ {
float windowHeight = 0; float windowHeight = 0;
float windowWidth = sMinimumWindowWidth; float windowWidth = sMinimumWindowWidth;
bool setToHiddenSize = ((TBarApp*)be_app)->Settings()->autoHide bool setToHiddenSize = fBarApp->Settings()->autoHide && IsHidden()
&& IsHidden() && !fDragRegion->IsDragging(); && !fDragRegion->IsDragging();
int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
if (setToHiddenSize) { if (setToHiddenSize) {
windowHeight = kHiddenDimension; windowHeight = kHiddenDimension;
@@ -559,7 +558,7 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height)
} else { } else {
// top or bottom, full // top or bottom, full
fExpandoMenuBar->CheckItemSizes(0); fExpandoMenuBar->CheckItemSizes(0);
windowHeight = iconSize + 4; windowHeight = fBarApp->IconSize() + 4;
windowWidth = screenFrame.Width(); windowWidth = screenFrame.Width();
} }
} else { } else {
@@ -623,7 +622,7 @@ TBarView::CheckForScrolling()
void void
TBarView::SaveSettings() TBarView::SaveSettings()
{ {
desk_settings* settings = ((TBarApp*)be_app)->Settings(); desk_settings* settings = fBarApp->Settings();
settings->vertical = fVertical; settings->vertical = fVertical;
settings->left = fLeft; settings->left = fLeft;
@@ -691,9 +690,10 @@ void
TBarView::ExpandItems() TBarView::ExpandItems()
{ {
if (fExpandoMenuBar == NULL || !fVertical || fState != kExpandoState if (fExpandoMenuBar == NULL || !fVertical || fState != kExpandoState
|| !static_cast<TBarApp*>(be_app)->Settings()->superExpando || !fBarApp->Settings()->superExpando
|| fExpandedItems.CountItems() <= 0) || fExpandedItems.CountItems() <= 0) {
return; return;
}
// Start at the 'bottom' of the list working up. // Start at the 'bottom' of the list working up.
// Prevents being thrown off by expanding items. // Prevents being thrown off by expanding items.
+2
View File
@@ -66,6 +66,7 @@ const float kHiddenDimension = 1.0f;
const float kMaxPreventHidingDist = 80.0f; const float kMaxPreventHidingDist = 80.0f;
class BShelf; class BShelf;
class TBarApp;
class TBarMenuBar; class TBarMenuBar;
class TExpandoMenuBar; class TExpandoMenuBar;
class TReplicantTray; class TReplicantTray;
@@ -170,6 +171,7 @@ class TBarView : public BView {
void ExpandItems(); void ExpandItems();
void _ChangeState(BMessage* message); void _ChangeState(BMessage* message);
TBarApp* fBarApp;
TInlineScrollView* fInlineScrollView; TInlineScrollView* fInlineScrollView;
TBarMenuBar* fBarMenuBar; TBarMenuBar* fBarMenuBar;
TExpandoMenuBar* fExpandoMenuBar; TExpandoMenuBar* fExpandoMenuBar;