141281cf3SAxel Dörfler/*
241281cf3SAxel DörflerOpen Tracker License
341281cf3SAxel Dörfler
441281cf3SAxel DörflerTerms and Conditions
541281cf3SAxel Dörfler
641281cf3SAxel DörflerCopyright (c) 1991-2000, Be Incorporated. All rights reserved.
741281cf3SAxel Dörfler
841281cf3SAxel DörflerPermission is hereby granted, free of charge, to any person obtaining a copy of
941281cf3SAxel Dörflerthis software and associated documentation files (the "Software"), to deal in
1041281cf3SAxel Dörflerthe Software without restriction, including without limitation the rights to
1141281cf3SAxel Dörfleruse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
1241281cf3SAxel Dörflerof the Software, and to permit persons to whom the Software is furnished to do
1341281cf3SAxel Dörflerso, subject to the following conditions:
1441281cf3SAxel Dörfler
1541281cf3SAxel DörflerThe above copyright notice and this permission notice applies to all licensees
1641281cf3SAxel Dörflerand shall be included in all copies or substantial portions of the Software.
1741281cf3SAxel Dörfler
1841281cf3SAxel DörflerTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1941281cf3SAxel DörflerIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
2041281cf3SAxel DörflerFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2141281cf3SAxel DörflerBE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
2241281cf3SAxel DörflerAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
2341281cf3SAxel DörflerWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2441281cf3SAxel Dörfler
2541281cf3SAxel DörflerExcept as contained in this notice, the name of Be Incorporated shall not be
2641281cf3SAxel Dörflerused in advertising or otherwise to promote the sale, use or other dealings in
2741281cf3SAxel Dörflerthis Software without prior written authorization from Be Incorporated.
2841281cf3SAxel Dörfler
294ec67d2bSFredrik HolmqvistTracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered
304ec67d2bSFredrik Holmqvisttrademarks of Be Incorporated in the United States and other countries. Other
314ec67d2bSFredrik Holmqvistbrand product names are registered trademarks or trademarks of their respective
324ec67d2bSFredrik Holmqvistholders.
3341281cf3SAxel DörflerAll rights reserved.
3441281cf3SAxel Dörfler*/
3541281cf3SAxel Dörfler
361cf94bf9SStephan Aßmus
371cf94bf9SStephan Aßmus#include "BarView.h"
381cf94bf9SStephan Aßmus
3941281cf3SAxel Dörfler#include <AppFileInfo.h>
4041281cf3SAxel Dörfler#include <Bitmap.h>
411cd61330SJohn Scipione#include <Debug.h>
4241281cf3SAxel Dörfler#include <Directory.h>
439ac6fee1SJohn Scipione#include <LocaleRoster.h>
4441281cf3SAxel Dörfler#include <NodeInfo.h>
4541281cf3SAxel Dörfler#include <Roster.h>
4641281cf3SAxel Dörfler#include <Screen.h>
4741281cf3SAxel Dörfler#include <String.h>
4841281cf3SAxel Dörfler
4941281cf3SAxel Dörfler#include "icons.h"
5041281cf3SAxel Dörfler#include "BarApp.h"
5141281cf3SAxel Dörfler#include "BarMenuBar.h"
5241281cf3SAxel Dörfler#include "BarWindow.h"
53323b6546SOliver Tappe#include "DeskbarMenu.h"
54323b6546SOliver Tappe#include "DeskbarUtils.h"
5541281cf3SAxel Dörfler#include "ExpandoMenuBar.h"
5641281cf3SAxel Dörfler#include "FSUtils.h"
5732f840b7SJohn Scipione#include "InlineScrollView.h"
5841281cf3SAxel Dörfler#include "ResourceSet.h"
5941281cf3SAxel Dörfler#include "StatusView.h"
6041281cf3SAxel Dörfler#include "TeamMenuItem.h"
6141281cf3SAxel Dörfler
6241281cf3SAxel Dörfler
6341281cf3SAxel Dörflerconst int32 kDefaultRecentDocCount = 10;
6441281cf3SAxel Dörflerconst int32 kDefaultRecentAppCount = 10;
6541281cf3SAxel Dörfler
6641281cf3SAxel Dörflerconst int32 kMenuTrackMargin = 20;
6741281cf3SAxel Dörfler
68d7ed9414SRene Gollentconst uint32 kUpdateOrientation = 'UpOr';
69c07e6ff2SJohn Scipioneconst float kSepItemWidth = 5.0f;
70d7ed9414SRene Gollent
71001f3799SJohn Scipione
7222812ba2SRene Gollentclass BarViewMessageFilter : public BMessageFilter
7322812ba2SRene Gollent{
7422812ba2SRene Gollent	public:
7522812ba2SRene Gollent		BarViewMessageFilter(TBarView* barView);
7622812ba2SRene Gollent		virtual ~BarViewMessageFilter();
7722812ba2SRene Gollent
7822812ba2SRene Gollent		virtual filter_result Filter(BMessage* message, BHandler** target);
7922812ba2SRene Gollent
8022812ba2SRene Gollent	private:
8122812ba2SRene Gollent		TBarView* fBarView;
8222812ba2SRene Gollent};
8322812ba2SRene Gollent
8422812ba2SRene Gollent
8522812ba2SRene GollentBarViewMessageFilter::BarViewMessageFilter(TBarView* barView)
8622812ba2SRene Gollent	:
8722812ba2SRene Gollent	BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE),
8822812ba2SRene Gollent	fBarView(barView)
8922812ba2SRene Gollent{
9022812ba2SRene Gollent}
9122812ba2SRene Gollent
9222812ba2SRene Gollent
9322812ba2SRene GollentBarViewMessageFilter::~BarViewMessageFilter()
9422812ba2SRene Gollent{
9522812ba2SRene Gollent}
9622812ba2SRene Gollent
9722812ba2SRene Gollent
9822812ba2SRene Gollentfilter_result
9922812ba2SRene GollentBarViewMessageFilter::Filter(BMessage* message, BHandler** target)
10022812ba2SRene Gollent{
10122812ba2SRene Gollent	if (message->what == B_MOUSE_DOWN || message->what == B_MOUSE_MOVED) {
10222812ba2SRene Gollent		BPoint where = message->FindPoint("be:view_where");
10322812ba2SRene Gollent		uint32 transit = message->FindInt32("be:transit");
104d7ed9414SRene Gollent		BMessage* dragMessage = NULL;
10522812ba2SRene Gollent		if (message->HasMessage("be:drag_message")) {
10622812ba2SRene Gollent			dragMessage = new BMessage();
10722812ba2SRene Gollent			message->FindMessage("be:drag_message", dragMessage);
10822812ba2SRene Gollent		}
10995aae4aeSRene Gollent
11095aae4aeSRene Gollent		switch (message->what) {
11122812ba2SRene Gollent			case B_MOUSE_DOWN:
11222812ba2SRene Gollent				fBarView->MouseDown(where);
1138f29b6e6SJohn Scipione				break;
11422812ba2SRene Gollent
11522812ba2SRene Gollent			case B_MOUSE_MOVED:
11622812ba2SRene Gollent				fBarView->MouseMoved(where, transit, dragMessage);
1178f29b6e6SJohn Scipione				break;
11822812ba2SRene Gollent		}
11922812ba2SRene Gollent
1208cf6d28fSJohn Scipione		delete dragMessage;
12122812ba2SRene Gollent	}
12222812ba2SRene Gollent
12322812ba2SRene Gollent	return B_DISPATCH_MESSAGE;
12422812ba2SRene Gollent}
12522812ba2SRene Gollent
12622812ba2SRene Gollent
1279f339a00SJohn Scipione//	#pragma mark - TBarView
1289f339a00SJohn Scipione
1299f339a00SJohn Scipione
13041281cf3SAxel DörflerTBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
131ee78e4deSJohn Scipione	int32 state, float)
13253ec5d1fSJohn Scipione	:
13353ec5d1fSJohn Scipione	BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
134ee78e4deSJohn Scipione	fBarApp(static_cast<TBarApp*>(be_app)),
13532f840b7SJohn Scipione	fInlineScrollView(NULL),
136f4a73641SAxel Dörfler	fBarMenuBar(NULL),
13753ec5d1fSJohn Scipione	fExpandoMenuBar(NULL),
138f4a73641SAxel Dörfler	fTrayLocation(1),
139f4a73641SAxel Dörfler	fVertical(vertical),
140f4a73641SAxel Dörfler	fTop(top),
141f4a73641SAxel Dörfler	fLeft(left),
142ee78e4deSJohn Scipione	fState(state),
143f4a73641SAxel Dörfler	fRefsRcvdOnly(true),
144f4a73641SAxel Dörfler	fDragMessage(NULL),
145f4a73641SAxel Dörfler	fCachedTypesList(NULL),
146f4a73641SAxel Dörfler	fMaxRecentDocs(kDefaultRecentDocCount),
147f4a73641SAxel Dörfler	fMaxRecentApps(kDefaultRecentAppCount),
148d7ed9414SRene Gollent	fLastDragItem(NULL),
149d7ed9414SRene Gollent	fMouseFilter(NULL)
150cb6afcb1SStephan Aßmus{
151777fffe8SJohn Scipione	// determine the initial Be menu size
152777fffe8SJohn Scipione	BRect menuFrame(frame);
153777fffe8SJohn Scipione	if (fVertical)
154777fffe8SJohn Scipione		menuFrame.bottom = menuFrame.top + kMenuBarHeight;
155777fffe8SJohn Scipione	else
156777fffe8SJohn Scipione		menuFrame.bottom = menuFrame.top + fBarApp->IconSize() + 4;
157777fffe8SJohn Scipione
158777fffe8SJohn Scipione	// create and add the Be menu
159777fffe8SJohn Scipione	fBarMenuBar = new TBarMenuBar(menuFrame, "BarMenuBar", this);
160777fffe8SJohn Scipione	AddChild(fBarMenuBar);
161777fffe8SJohn Scipione
16270ad5289SJohn Scipione	// create the status tray
1630dd68c86SAxel Dörfler	fReplicantTray = new TReplicantTray(this, fVertical);
16470ad5289SJohn Scipione
16570ad5289SJohn Scipione	// create the resize control
16670ad5289SJohn Scipione	fResizeControl = new TResizeControl(this);
16770ad5289SJohn Scipione
16870ad5289SJohn Scipione	// create the drag region and add the resize control
16970ad5289SJohn Scipione	// and replicant tray to it
1700dd68c86SAxel Dörfler	fDragRegion = new TDragRegion(this, fReplicantTray);
17170ad5289SJohn Scipione	fDragRegion->AddChild(fResizeControl);
1720dd68c86SAxel Dörfler	fDragRegion->AddChild(fReplicantTray);
17370ad5289SJohn Scipione
17470ad5289SJohn Scipione	// Add the drag region
1750dd68c86SAxel Dörfler	if (fTrayLocation != 0)
1760dd68c86SAxel Dörfler		AddChild(fDragRegion);
17753ec5d1fSJohn Scipione
178777fffe8SJohn Scipione	// create and add the application menubar
1794f4cab95SJohn Scipione	fExpandoMenuBar = new TExpandoMenuBar(this, fVertical);
180deaae5fcSJohn Scipione	fInlineScrollView = new TInlineScrollView(fExpandoMenuBar,
181deaae5fcSJohn Scipione		fVertical ? B_VERTICAL : B_HORIZONTAL);
18253ec5d1fSJohn Scipione	AddChild(fInlineScrollView);
18353ec5d1fSJohn Scipione
184777fffe8SJohn Scipione	// If mini mode, hide the application menubar
1858f0935acSJohn Scipione	if (state == kMiniState)
18653ec5d1fSJohn Scipione		fInlineScrollView->Hide();
18741281cf3SAxel Dörfler}
18841281cf3SAxel Dörfler
18941281cf3SAxel Dörfler
19041281cf3SAxel DörflerTBarView::~TBarView()
19141281cf3SAxel Dörfler{
19241281cf3SAxel Dörfler	delete fDragMessage;
19341281cf3SAxel Dörfler	delete fCachedTypesList;
194c6bc755dSJohn Scipione	delete fBarMenuBar;
19541281cf3SAxel Dörfler}
19641281cf3SAxel Dörfler
19741281cf3SAxel Dörfler
19841281cf3SAxel Dörflervoid
19941281cf3SAxel DörflerTBarView::AttachedToWindow()
20041281cf3SAxel Dörfler{
20141281cf3SAxel Dörfler	BView::AttachedToWindow();
20241281cf3SAxel Dörfler
20316c10517Slooncraz	SetViewUIColor(B_MENU_BACKGROUND_COLOR);
20441281cf3SAxel Dörfler	SetFont(be_plain_font);
2057da06231SAxel Dörfler
206d7ed9414SRene Gollent	fMouseFilter = new BarViewMessageFilter(this);
207d7ed9414SRene Gollent	Window()->AddCommonFilter(fMouseFilter);
20822812ba2SRene Gollent
20941281cf3SAxel Dörfler	fTrackingHookData.fTrackingHook = MenuTrackingHook;
21041281cf3SAxel Dörfler	fTrackingHookData.fTarget = BMessenger(this);
21141281cf3SAxel Dörfler	fTrackingHookData.fDragMessage = new BMessage(B_REFS_RECEIVED);
21241281cf3SAxel Dörfler}
21341281cf3SAxel Dörfler
21441281cf3SAxel Dörfler
215cb6afcb1SStephan Aßmusvoid
216cb6afcb1SStephan AßmusTBarView::DetachedFromWindow()
217cb6afcb1SStephan Aßmus{
218d7ed9414SRene Gollent	Window()->RemoveCommonFilter(fMouseFilter);
219d7ed9414SRene Gollent	delete fMouseFilter;
220d7ed9414SRene Gollent	fMouseFilter = NULL;
221cb6afcb1SStephan Aßmus	delete fTrackingHookData.fDragMessage;
222cb6afcb1SStephan Aßmus	fTrackingHookData.fDragMessage = NULL;
223cb6afcb1SStephan Aßmus}
224cb6afcb1SStephan Aßmus
225cb6afcb1SStephan Aßmus
22641281cf3SAxel Dörflervoid
22741281cf3SAxel DörflerTBarView::Draw(BRect)
22841281cf3SAxel Dörfler{
22941281cf3SAxel Dörfler	BRect bounds(Bounds());
23038bda653SFredrik Holmqvist
231eaa9af99SStephan Aßmus	rgb_color hilite = tint_color(ViewColor(), B_DARKEN_1_TINT);
23238bda653SFredrik Holmqvist
23341281cf3SAxel Dörfler	SetHighColor(hilite);
2344ec67d2bSFredrik Holmqvist	if (AcrossTop())
23541281cf3SAxel Dörfler		StrokeLine(bounds.LeftBottom(), bounds.RightBottom());
2364ec67d2bSFredrik Holmqvist	else if (AcrossBottom())
23741281cf3SAxel Dörfler		StrokeLine(bounds.LeftTop(), bounds.RightTop());
23841281cf3SAxel Dörfler
239d0a49328SJohn Scipione	if (fVertical && fState == kExpandoState) {
24041281cf3SAxel Dörfler		SetHighColor(hilite);
24153ec5d1fSJohn Scipione		BRect frame(fExpandoMenuBar->Frame());
2421cf94bf9SStephan Aßmus		StrokeLine(BPoint(frame.left, frame.top - 1),
2431cf94bf9SStephan Aßmus			BPoint(frame.right, frame.top -1));
24441281cf3SAxel Dörfler	}
24541281cf3SAxel Dörfler}
24641281cf3SAxel Dörfler
24741281cf3SAxel Dörfler
24841281cf3SAxel Dörflervoid
249290c9039SJonas SundströmTBarView::MessageReceived(BMessage* message)
25041281cf3SAxel Dörfler{
251f4a73641SAxel Dörfler	switch (message->what) {
2529ac6fee1SJohn Scipione		case B_LOCALE_CHANGED:
253c0dc265cSJohn Scipione		case kRealignReplicants:
25431c0024dSJohn Scipione		case kShowHideTime:
25531c0024dSJohn Scipione		case kShowSeconds:
25631c0024dSJohn Scipione		case kShowDayOfWeek:
25731c0024dSJohn Scipione		case kShowTimeZone:
25831c0024dSJohn Scipione		case kGetClockSettings:
2599ac6fee1SJohn Scipione			fReplicantTray->MessageReceived(message);
2609ac6fee1SJohn Scipione			break;
2619ac6fee1SJohn Scipione
26241281cf3SAxel Dörfler		case B_REFS_RECEIVED:
263f4a73641SAxel Dörfler			// received when an item is selected during DnD
264f4a73641SAxel Dörfler			// message is targeted here from Be menu
265323b6546SOliver Tappe			HandleDeskbarMenu(message);
26641281cf3SAxel Dörfler			break;
26741281cf3SAxel Dörfler
26841281cf3SAxel Dörfler		case B_ARCHIVED_OBJECT:
269f4a73641SAxel Dörfler		{
270f4a73641SAxel Dörfler			// this message has been retargeted to here
271f4a73641SAxel Dörfler			// instead of directly to the replicant tray
272f4a73641SAxel Dörfler			// so that I can follow the common pathway
273f4a73641SAxel Dörfler			// for adding icons to the tray
274f4a73641SAxel Dörfler			int32 id;
2750fc30d89SDario Casalinuovo			if (AddItem(message, B_DESKBAR_TRAY, &id) == B_OK)
2760fc30d89SDario Casalinuovo				Looper()->DetachCurrentMessage();
27741281cf3SAxel Dörfler			break;
278f4a73641SAxel Dörfler		}
279f4a73641SAxel Dörfler
280d7ed9414SRene Gollent		case kUpdateOrientation:
281d7ed9414SRene Gollent		{
282d7ed9414SRene Gollent			_ChangeState(message);
283d7ed9414SRene Gollent			break;
284d7ed9414SRene Gollent		}
285d7ed9414SRene Gollent
28641281cf3SAxel Dörfler		default:
28741281cf3SAxel Dörfler			BView::MessageReceived(message);
28841281cf3SAxel Dörfler	}
28941281cf3SAxel Dörfler}
29041281cf3SAxel Dörfler
29141281cf3SAxel Dörfler
292dc69d5e2SAxel Dörflervoid
293dc69d5e2SAxel DörflerTBarView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
294dc69d5e2SAxel Dörfler{
29547a394ecSJohn Scipione	if (fDragRegion->IsDragging()) {
29647a394ecSJohn Scipione		fDragRegion->MouseMoved(where, transit, dragMessage);
297e2700599SAxel Dörfler		return;
298ec3fd171SRene Gollent	}
299ec3fd171SRene Gollent
300ec3fd171SRene Gollent	if (transit == B_ENTERED_VIEW && EventMask() == 0)
301ec3fd171SRene Gollent		SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
302e2700599SAxel Dörfler
3031bb2e623SJohn Scipione	BPoint whereScreen = ConvertToScreen(where);
3041bb2e623SJohn Scipione
305777fffe8SJohn Scipione	desk_settings* settings = fBarApp->Settings();
30647a394ecSJohn Scipione	bool alwaysOnTop = settings->alwaysOnTop;
30747a394ecSJohn Scipione	bool autoRaise = settings->autoRaise;
30847a394ecSJohn Scipione	bool autoHide = settings->autoHide;
30947a394ecSJohn Scipione
310ec3fd171SRene Gollent	if (!autoRaise && !autoHide) {
311ec3fd171SRene Gollent		if (transit == B_EXITED_VIEW || transit == B_OUTSIDE_VIEW)
312ec3fd171SRene Gollent			SetEventMask(0);
313e2700599SAxel Dörfler		return;
314ec3fd171SRene Gollent	}
315e2700599SAxel Dörfler
316e2700599SAxel Dörfler	bool isTopMost = Window()->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
317dc69d5e2SAxel Dörfler
318e2700599SAxel Dörfler	// Auto-Raise
319d0a49328SJohn Scipione	BRect screenFrame = (BScreen(Window())).Frame();
3201bb2e623SJohn Scipione	if ((whereScreen.x == screenFrame.left
3211bb2e623SJohn Scipione			|| whereScreen.x == screenFrame.right
3221bb2e623SJohn Scipione			|| whereScreen.y == screenFrame.top
3231bb2e623SJohn Scipione			|| whereScreen.y == screenFrame.bottom)
3241bb2e623SJohn Scipione		&& Window()->Frame().Contains(whereScreen)) {
325e2700599SAxel Dörfler		// cursor is on a screen edge within the window frame
326e2700599SAxel Dörfler
327ec3fd171SRene Gollent		if (!alwaysOnTop && autoRaise && !isTopMost)
328e2700599SAxel Dörfler			RaiseDeskbar(true);
329e2700599SAxel Dörfler
330e2700599SAxel Dörfler		if (autoHide && IsHidden())
331e2700599SAxel Dörfler			HideDeskbar(false);
332e2700599SAxel Dörfler	} else {
33322812ba2SRene Gollent		TBarWindow* window = (TBarWindow*)Window();
33422812ba2SRene Gollent		if (window->IsShowingMenu())
33522812ba2SRene Gollent			return;
33622812ba2SRene Gollent
337e2700599SAxel Dörfler		// cursor is not on screen edge
338e2700599SAxel Dörfler		BRect preventHideArea = Window()->Frame().InsetByCopy(
339e2700599SAxel Dörfler			-kMaxPreventHidingDist, -kMaxPreventHidingDist);
340e2700599SAxel Dörfler
3411bb2e623SJohn Scipione		if (preventHideArea.Contains(whereScreen))
342e2700599SAxel Dörfler			return;
343e2700599SAxel Dörfler
344e2700599SAxel Dörfler		// cursor to bar distance above threshold
34522812ba2SRene Gollent		if (!alwaysOnTop && autoRaise && isTopMost) {
346e2700599SAxel Dörfler			RaiseDeskbar(false);
34722812ba2SRene Gollent			SetEventMask(0);
34822812ba2SRene Gollent		}
349e2700599SAxel Dörfler
350e2700599SAxel Dörfler		if (autoHide && !IsHidden())
351e2700599SAxel Dörfler			HideDeskbar(true);
352e2700599SAxel Dörfler	}
353e2700599SAxel Dörfler}
354e2700599SAxel Dörfler
355e2700599SAxel Dörfler
356e2700599SAxel Dörflervoid
357e2700599SAxel DörflerTBarView::MouseDown(BPoint where)
358e2700599SAxel Dörfler{
3591bb2e623SJohn Scipione	BPoint whereScreen = ConvertToScreen(where);
360e2700599SAxel Dörfler
3611bb2e623SJohn Scipione	if (Window()->Frame().Contains(whereScreen)) {
362e2700599SAxel Dörfler		Window()->Activate();
363e2700599SAxel Dörfler
364e2700599SAxel Dörfler		if ((modifiers() & (B_CONTROL_KEY | B_COMMAND_KEY | B_OPTION_KEY
3651bb2e623SJohn Scipione				| B_SHIFT_KEY)) == (B_CONTROL_KEY | B_COMMAND_KEY)) {
366e2700599SAxel Dörfler			// The window key was pressed - enter dragging code
36747a394ecSJohn Scipione			fDragRegion->MouseDown(fDragRegion->DragRegion().LeftTop());
368e2700599SAxel Dörfler			return;
369e2700599SAxel Dörfler		}
370e2700599SAxel Dörfler	} else {
371e2700599SAxel Dörfler		// hide deskbar if required
372777fffe8SJohn Scipione		desk_settings* settings = fBarApp->Settings();
373e2700599SAxel Dörfler		bool alwaysOnTop = settings->alwaysOnTop;
374e2700599SAxel Dörfler		bool autoRaise = settings->autoRaise;
375e2700599SAxel Dörfler		bool autoHide = settings->autoHide;
376e2700599SAxel Dörfler		bool isTopMost = Window()->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
377e2700599SAxel Dörfler
378e2700599SAxel Dörfler		if (!alwaysOnTop && autoRaise && isTopMost)
379e2700599SAxel Dörfler			RaiseDeskbar(false);
380e2700599SAxel Dörfler
381e2700599SAxel Dörfler		if (autoHide && !IsHidden())
382e2700599SAxel Dörfler			HideDeskbar(true);
383dc69d5e2SAxel Dörfler	}
384dc69d5e2SAxel Dörfler}
385dc69d5e2SAxel Dörfler
386dc69d5e2SAxel Dörfler
38741281cf3SAxel Dörflervoid
388323b6546SOliver TappeTBarView::PlaceDeskbarMenu()
38941281cf3SAxel Dörfler{
3901bb2e623SJohn Scipione	float width = 0;
3911bb2e623SJohn Scipione	float height = 0;
39241281cf3SAxel Dörfler
3931bb2e623SJohn Scipione	// Calculate the size of the deskbar menu
3941bb2e623SJohn Scipione	BRect menuFrame(Bounds());
3951bb2e623SJohn Scipione	if (fVertical) {
3961bb2e623SJohn Scipione		width = static_cast<TBarApp*>(be_app)->Settings()->width;
397419bc0a2SAxel Dörfler		height = 4 + fReplicantTray->MaxReplicantHeight();
3981bb2e623SJohn Scipione		menuFrame.bottom = menuFrame.top + height;
3991bb2e623SJohn Scipione	} else {
4001bb2e623SJohn Scipione		width = gMinimumWindowWidth;
4011bb2e623SJohn Scipione		height = fBarApp->IconSize() + 4;
4021bb2e623SJohn Scipione		menuFrame.bottom = menuFrame.top + height;
4031bb2e623SJohn Scipione	}
4041bb2e623SJohn Scipione
4051bb2e623SJohn Scipione	if (fBarMenuBar == NULL) {
4061bb2e623SJohn Scipione		// create the Be menu
4071bb2e623SJohn Scipione		fBarMenuBar = new TBarMenuBar(menuFrame, "BarMenuBar", this);
4081bb2e623SJohn Scipione		AddChild(fBarMenuBar);
4091bb2e623SJohn Scipione	} else
4101bb2e623SJohn Scipione		fBarMenuBar->SmartResize(-1, -1);
411cb55ef9fSJohn Scipione
4121bb2e623SJohn Scipione	BPoint loc(B_ORIGIN);
41341281cf3SAxel Dörfler	if (fState == kFullState) {
41441281cf3SAxel Dörfler		fBarMenuBar->RemoveTeamMenu();
415c07e6ff2SJohn Scipione		fBarMenuBar->RemoveSeperatorItem();
41641281cf3SAxel Dörfler		loc = Bounds().LeftTop();
417f4a73641SAxel Dörfler	} else if (fState == kExpandoState) {
41841281cf3SAxel Dörfler		fBarMenuBar->RemoveTeamMenu();
419c07e6ff2SJohn Scipione		if (fVertical) {
420c07e6ff2SJohn Scipione			// shows apps below tray
421c07e6ff2SJohn Scipione			fBarMenuBar->RemoveSeperatorItem();
42241281cf3SAxel Dörfler			width += 1;
423c07e6ff2SJohn Scipione		} else {
424c07e6ff2SJohn Scipione			// shows apps to the right of bemenu
4254ae3e542SJohn Scipione			fBarMenuBar->AddSeparatorItem();
426b1967b10SJohn Scipione			width = floorf(width) / 2 + kSepItemWidth;
427c07e6ff2SJohn Scipione		}
42841281cf3SAxel Dörfler		loc = Bounds().LeftTop();
4294ec67d2bSFredrik Holmqvist	} else {
430323b6546SOliver Tappe		// mini mode, DeskbarMenu next to team menu
431c07e6ff2SJohn Scipione		fBarMenuBar->RemoveSeperatorItem();
432dec421b1SJohn Scipione		fBarMenuBar->AddTeamMenu();
4334ec67d2bSFredrik Holmqvist	}
43441281cf3SAxel Dörfler
435777fffe8SJohn Scipione	fBarMenuBar->SmartResize(width, height);
43641281cf3SAxel Dörfler	fBarMenuBar->MoveTo(loc);
43741281cf3SAxel Dörfler}
43841281cf3SAxel Dörfler
43941281cf3SAxel Dörfler
44041281cf3SAxel Dörflervoid
441363a49a6SJohn ScipioneTBarView::PlaceTray(bool vertSwap, bool leftSwap)
44241281cf3SAxel Dörfler{
443f4a73641SAxel Dörfler	BPoint statusLoc;
44441281cf3SAxel Dörfler	if (fState == kFullState) {
44541281cf3SAxel Dörfler		fDragRegion->ResizeTo(fBarMenuBar->Frame().Width(), kMenuBarHeight);
44641281cf3SAxel Dörfler		statusLoc.y = fBarMenuBar->Frame().bottom + 1;
44741281cf3SAxel Dörfler		statusLoc.x = 0;
44841281cf3SAxel Dörfler		fDragRegion->MoveTo(statusLoc);
4491bb2e623SJohn Scipione		fDragRegion->Invalidate();
450f4a73641SAxel Dörfler
45141281cf3SAxel Dörfler		if (!fReplicantTray->IsHidden())
4524ec67d2bSFredrik Holmqvist			fReplicantTray->Hide();
4537da06231SAxel Dörfler
45441281cf3SAxel Dörfler		return;
45541281cf3SAxel Dörfler	}
456f4a73641SAxel Dörfler
45741281cf3SAxel Dörfler	if (fReplicantTray->IsHidden())
4584ec67d2bSFredrik Holmqvist		fReplicantTray->Show();
459f4a73641SAxel Dörfler
46041281cf3SAxel Dörfler	if (fTrayLocation != 0) {
46141281cf3SAxel Dörfler		fReplicantTray->SetMultiRow(fVertical);
46241281cf3SAxel Dörfler		fReplicantTray->RealignReplicants();
46341281cf3SAxel Dörfler		fDragRegion->ResizeToPreferred();
46470ad5289SJohn Scipione			// also resizes replicant tray
46541281cf3SAxel Dörfler
46670ad5289SJohn Scipione		fResizeControl->ResizeTo(kDragWidth, fDragRegion->Bounds().Height()
46770ad5289SJohn Scipione			- 2); // make room for top and bottom border
4681bb2e623SJohn Scipione
46941281cf3SAxel Dörfler		if (fVertical) {
4701bb2e623SJohn Scipione			if (fResizeControl->IsHidden())
4711bb2e623SJohn Scipione				fResizeControl->Show();
47270ad5289SJohn Scipione
47370ad5289SJohn Scipione			if (fLeft) {
47470ad5289SJohn Scipione				// move replicant tray past dragger width on left
47570ad5289SJohn Scipione				// also down 1px so it won't cover the border
47670ad5289SJohn Scipione				fReplicantTray->MoveTo(kDragWidth + kGutter, kGutter);
47770ad5289SJohn Scipione
47870ad5289SJohn Scipione				// shrink width by same amount
47970ad5289SJohn Scipione				fReplicantTray->ResizeBy(-(kDragWidth + kGutter), 0);
48070ad5289SJohn Scipione			} else {
48170ad5289SJohn Scipione				// move replicant tray down 1px so it won't cover the border
48270ad5289SJohn Scipione				fReplicantTray->MoveTo(0, kGutter);
48370ad5289SJohn Scipione			}
48470ad5289SJohn Scipione
48541281cf3SAxel Dörfler			statusLoc.x = 0;
4861bb2e623SJohn Scipione			statusLoc.y = fBarMenuBar->Frame().bottom + 1;
48741281cf3SAxel Dörfler		} else {
4881bb2e623SJohn Scipione			if (!fResizeControl->IsHidden())
4891bb2e623SJohn Scipione				fResizeControl->Hide();
49032b0035aSJohn Scipione
4916123d2ddSJohn Scipione			// move right and down to not cover border then resize to fit
4926123d2ddSJohn Scipione			fReplicantTray->MoveTo(kGutter, kGutter);
4936123d2ddSJohn Scipione			fReplicantTray->ResizeBy(-kGutter, -kGutter);
494363a49a6SJohn Scipione			BRect screenFrame = (BScreen(Window())).Frame();
495cb6afcb1SStephan Aßmus			statusLoc.x = screenFrame.right - fDragRegion->Bounds().Width();
49641281cf3SAxel Dörfler			statusLoc.y = -1;
49741281cf3SAxel Dörfler		}
49841281cf3SAxel Dörfler
49941281cf3SAxel Dörfler		fDragRegion->MoveTo(statusLoc);
5001bb2e623SJohn Scipione		fDragRegion->Invalidate();
5011bb2e623SJohn Scipione
5021bb2e623SJohn Scipione		if (fVertical && fLeft)
50370ad5289SJohn Scipione			fResizeControl->MoveTo(fDragRegion->Bounds().right - kDragWidth, 1);
5041bb2e623SJohn Scipione		else
50570ad5289SJohn Scipione			fResizeControl->MoveTo(0, 1);
5061bb2e623SJohn Scipione
5071bb2e623SJohn Scipione		fResizeControl->Invalidate();
50841281cf3SAxel Dörfler	}
50941281cf3SAxel Dörfler}
51041281cf3SAxel Dörfler
51141281cf3SAxel Dörfler
51241281cf3SAxel Dörflervoid
513363a49a6SJohn ScipioneTBarView::PlaceApplicationBar()
51441281cf3SAxel Dörfler{
5157ee3b479SJohn Scipione	BRect screenFrame = (BScreen(Window())).Frame();
5167ee3b479SJohn Scipione	if (fState == kMiniState) {
51753ec5d1fSJohn Scipione		if (!fInlineScrollView->IsHidden())
51853ec5d1fSJohn Scipione			fInlineScrollView->Hide();
5197ee3b479SJohn Scipione		SizeWindow(screenFrame);
5207ee3b479SJohn Scipione		PositionWindow(screenFrame);
5217ee3b479SJohn Scipione		Window()->UpdateIfNeeded();
5227ee3b479SJohn Scipione		Invalidate();
52341281cf3SAxel Dörfler		return;
5247ee3b479SJohn Scipione	}
525f4a73641SAxel Dörfler
52653ec5d1fSJohn Scipione	if (fInlineScrollView->IsHidden())
52753ec5d1fSJohn Scipione		fInlineScrollView->Show();
52853ec5d1fSJohn Scipione
52941281cf3SAxel Dörfler	BRect expandoFrame(0, 0, 0, 0);
53041281cf3SAxel Dörfler	if (fVertical) {
53153ec5d1fSJohn Scipione		// left or right
5323b8cb300SJohn Scipione		expandoFrame.left = fDragRegion->Frame().left;
5333b8cb300SJohn Scipione		expandoFrame.top = fTrayLocation != 0 ? fDragRegion->Frame().bottom + 1
5343b8cb300SJohn Scipione			: fBarMenuBar->Frame().bottom + 1;
5353b8cb300SJohn Scipione		expandoFrame.right = fBarMenuBar->Frame().right;
5363b8cb300SJohn Scipione		expandoFrame.bottom = fState == kFullState ? screenFrame.bottom
5373b8cb300SJohn Scipione			: Frame().bottom;
53841281cf3SAxel Dörfler	} else {
53941281cf3SAxel Dörfler		// top or bottom
540cb6afcb1SStephan Aßmus		expandoFrame.top = 0;
541777fffe8SJohn Scipione		expandoFrame.bottom = fBarApp->IconSize() + 4;
542c07e6ff2SJohn Scipione
543c07e6ff2SJohn Scipione		if (fBarMenuBar != NULL)
544777fffe8SJohn Scipione			expandoFrame.left = fBarMenuBar->Frame().Width() + 1;
545c07e6ff2SJohn Scipione
546652a115cSJohn Scipione		if (fTrayLocation != 0 && fDragRegion != NULL) {
547652a115cSJohn Scipione			expandoFrame.right = screenFrame.Width()
548652a115cSJohn Scipione				- fDragRegion->Frame().Width() - 1;
549652a115cSJohn Scipione		} else
55041281cf3SAxel Dörfler			expandoFrame.right = screenFrame.Width();
55141281cf3SAxel Dörfler	}
552