xref: /haiku/src/apps/deskbar/StatusView.cpp (revision ca9acc20e8829812353a19093c3e9cfa076a06b1)
141281cf3SAxel Dörfler /*
241281cf3SAxel Dörfler Open Tracker License
341281cf3SAxel Dörfler 
441281cf3SAxel Dörfler Terms and Conditions
541281cf3SAxel Dörfler 
641281cf3SAxel Dörfler Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
741281cf3SAxel Dörfler 
841281cf3SAxel Dörfler Permission is hereby granted, free of charge, to any person obtaining a copy of
941281cf3SAxel Dörfler this software and associated documentation files (the "Software"), to deal in
1041281cf3SAxel Dörfler the Software without restriction, including without limitation the rights to
1141281cf3SAxel Dörfler use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
1241281cf3SAxel Dörfler of the Software, and to permit persons to whom the Software is furnished to do
1341281cf3SAxel Dörfler so, subject to the following conditions:
1441281cf3SAxel Dörfler 
1541281cf3SAxel Dörfler The above copyright notice and this permission notice applies to all licensees
1641281cf3SAxel Dörfler and shall be included in all copies or substantial portions of the Software.
1741281cf3SAxel Dörfler 
1841281cf3SAxel Dörfler THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1941281cf3SAxel Dörfler IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
2041281cf3SAxel Dörfler FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2141281cf3SAxel Dörfler BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
2241281cf3SAxel Dörfler AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
2341281cf3SAxel Dörfler WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2441281cf3SAxel Dörfler 
2541281cf3SAxel Dörfler Except as contained in this notice, the name of Be Incorporated shall not be
2641281cf3SAxel Dörfler used in advertising or otherwise to promote the sale, use or other dealings in
2741281cf3SAxel Dörfler this Software without prior written authorization from Be Incorporated.
2841281cf3SAxel Dörfler 
2941281cf3SAxel Dörfler Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
3041281cf3SAxel Dörfler of Be Incorporated in the United States and other countries. Other brand product
3141281cf3SAxel Dörfler names are registered trademarks or trademarks of their respective holders.
3241281cf3SAxel Dörfler All rights reserved.
3341281cf3SAxel Dörfler */
3441281cf3SAxel Dörfler 
3541281cf3SAxel Dörfler #include <Debug.h>
3641281cf3SAxel Dörfler 
3741281cf3SAxel Dörfler #include <errno.h>
3841281cf3SAxel Dörfler #include <stdio.h>
3941281cf3SAxel Dörfler #include <string.h>
4041281cf3SAxel Dörfler #include <time.h>
4141281cf3SAxel Dörfler #include <unistd.h>
4241281cf3SAxel Dörfler #include <algorithm>
4341281cf3SAxel Dörfler 
4441281cf3SAxel Dörfler #include <fs_index.h>
4541281cf3SAxel Dörfler #include <fs_info.h>
4641281cf3SAxel Dörfler 
4741281cf3SAxel Dörfler #include <Application.h>
4841281cf3SAxel Dörfler #include <Beep.h>
49cb6afcb1SStephan Aßmus #include <Bitmap.h>
50ae7a6e3aSAdrien Destugues #include <Catalog.h>
51cb6afcb1SStephan Aßmus #include <ControlLook.h>
5241281cf3SAxel Dörfler #include <Directory.h>
5341281cf3SAxel Dörfler #include <FindDirectory.h>
54ae7a6e3aSAdrien Destugues #include <Locale.h>
5541281cf3SAxel Dörfler #include <MenuItem.h>
5641281cf3SAxel Dörfler #include <NodeInfo.h>
5741281cf3SAxel Dörfler #include <NodeMonitor.h>
5841281cf3SAxel Dörfler #include <Path.h>
5941281cf3SAxel Dörfler #include <PopUpMenu.h>
6041281cf3SAxel Dörfler #include <Roster.h>
6141281cf3SAxel Dörfler #include <Screen.h>
6241281cf3SAxel Dörfler #include <Volume.h>
6341281cf3SAxel Dörfler #include <VolumeRoster.h>
6441281cf3SAxel Dörfler #include <Window.h>
6541281cf3SAxel Dörfler 
66cb6afcb1SStephan Aßmus #include "icons_logo.h"
67cb6afcb1SStephan Aßmus #include "BarApp.h"
6841281cf3SAxel Dörfler #include "DeskBarUtils.h"
69cb6afcb1SStephan Aßmus #include "ResourceSet.h"
7041281cf3SAxel Dörfler #include "StatusView.h"
7141281cf3SAxel Dörfler #include "StatusViewShelf.h"
7241281cf3SAxel Dörfler #include "TimeView.h"
7341281cf3SAxel Dörfler 
746d01b66dSAxel Dörfler using std::max;
7541281cf3SAxel Dörfler 
7641281cf3SAxel Dörfler #ifdef DB_ADDONS
7741281cf3SAxel Dörfler //	Add-on support
7841281cf3SAxel Dörfler //
7941281cf3SAxel Dörfler //	Item - internal item list (node, eref, etc)
8041281cf3SAxel Dörfler //	Icon - physical replicant handed to the DeskbarClass class
8141281cf3SAxel Dörfler //	AddOn - attribute based add-on
8241281cf3SAxel Dörfler 
8341281cf3SAxel Dörfler const char* const kInstantiateItemCFunctionName = "instantiate_deskbar_item";
8441281cf3SAxel Dörfler const char* const kInstantiateEntryCFunctionName = "instantiate_deskbar_entry";
8541281cf3SAxel Dörfler const char* const kDeskbarSecurityCodeFile = "Deskbar_security_code";
8641281cf3SAxel Dörfler const char* const kDeskbarSecurityCodeAttr = "be:deskbar_security_code";
8741281cf3SAxel Dörfler const char* const kStatusPredicate = "be:deskbar_item_status";
8841281cf3SAxel Dörfler const char* const kEnabledPredicate = "be:deskbar_item_status=enabled";
8941281cf3SAxel Dörfler const char* const kDisabledPredicate = "be:deskbar_item_status=disabled";
9041281cf3SAxel Dörfler 
91cb6afcb1SStephan Aßmus float sMinimumWindowWidth = kGutter + kMinimumTrayWidth + kDragRegionWidth;
92cb6afcb1SStephan Aßmus 
9341281cf3SAxel Dörfler 
9441281cf3SAxel Dörfler static void
9541281cf3SAxel Dörfler DumpItem(DeskbarItemInfo* item)
9641281cf3SAxel Dörfler {
9741281cf3SAxel Dörfler 	printf("is addon: %i, id: %li\n", item->isAddOn, item->id);
9866eba86fSAxel Dörfler 	printf("entry_ref:  %ld, %Ld, %s\n", item->entryRef.device,
9966eba86fSAxel Dörfler 		item->entryRef.directory, item->entryRef.name);
10041281cf3SAxel Dörfler 	printf("node_ref:  %ld, %Ld\n", item->nodeRef.device, item->nodeRef.node);
10141281cf3SAxel Dörfler }
10241281cf3SAxel Dörfler 
10341281cf3SAxel Dörfler 
10441281cf3SAxel Dörfler static void
10541281cf3SAxel Dörfler DumpList(BList* itemlist)
10641281cf3SAxel Dörfler {
10741281cf3SAxel Dörfler 	int32 count = itemlist->CountItems() - 1;
10841281cf3SAxel Dörfler 	if (count < 0) {
10941281cf3SAxel Dörfler 		printf("no items in list\n");
11041281cf3SAxel Dörfler 		return;
11141281cf3SAxel Dörfler 	}
11241281cf3SAxel Dörfler 	for (int32 i = count ; i >= 0 ; i--) {
11341281cf3SAxel Dörfler 		DeskbarItemInfo* item = (DeskbarItemInfo*)itemlist->ItemAt(i);
11441281cf3SAxel Dörfler 		if (!item)
11541281cf3SAxel Dörfler 			continue;
11641281cf3SAxel Dörfler 
11741281cf3SAxel Dörfler 		DumpItem(item);
11841281cf3SAxel Dörfler 	}
11941281cf3SAxel Dörfler }
12041281cf3SAxel Dörfler #endif	/* DB_ADDONS */
12141281cf3SAxel Dörfler 
12241281cf3SAxel Dörfler 
1234eb0cbb0SMatt Madia #undef B_TRANSLATE_CONTEXT
1244eb0cbb0SMatt Madia #define B_TRANSLATE_CONTEXT "Tray"
125ae7a6e3aSAdrien Destugues 
1267da06231SAxel Dörfler // don't change the name of this view to anything other than "Status"!
1277da06231SAxel Dörfler 
12841281cf3SAxel Dörfler TReplicantTray::TReplicantTray(TBarView* parent, bool vertical)
12941281cf3SAxel Dörfler 	: BView(BRect(0, 0, 1, 1), "Status", B_FOLLOW_LEFT | B_FOLLOW_TOP,
13041281cf3SAxel Dörfler 			B_WILL_DRAW | B_FRAME_EVENTS),
13141281cf3SAxel Dörfler 	fClock(NULL),
13241281cf3SAxel Dörfler 	fBarView(parent),
13341281cf3SAxel Dörfler 	fShelf(new TReplicantShelf(this)),
13441281cf3SAxel Dörfler 	fMultiRowMode(vertical),
135cb6afcb1SStephan Aßmus 	fMinimumTrayWidth(kMinimumTrayWidth),
13641281cf3SAxel Dörfler 	fAlignmentSupport(false)
13741281cf3SAxel Dörfler {
138cb6afcb1SStephan Aßmus 	// init the minimum window width according to the logo.
139cb6afcb1SStephan Aßmus 	const BBitmap* logoBitmap = AppResSet()->FindBitmap(B_MESSAGE_TYPE,
140cb6afcb1SStephan Aßmus 		R_BeLogoIcon);
141cb6afcb1SStephan Aßmus 	if (logoBitmap != NULL) {
142cb6afcb1SStephan Aßmus 		sMinimumWindowWidth = max_c(sMinimumWindowWidth,
143cb6afcb1SStephan Aßmus 			2 * (logoBitmap->Bounds().Width() + 8));
144cb6afcb1SStephan Aßmus 		fMinimumTrayWidth = sMinimumWindowWidth - kGutter - kDragRegionWidth;
145cb6afcb1SStephan Aßmus 	}
14641281cf3SAxel Dörfler }
14741281cf3SAxel Dörfler 
14841281cf3SAxel Dörfler 
14941281cf3SAxel Dörfler TReplicantTray::~TReplicantTray()
15041281cf3SAxel Dörfler {
15141281cf3SAxel Dörfler 	delete fShelf;
15241281cf3SAxel Dörfler }
15341281cf3SAxel Dörfler 
15441281cf3SAxel Dörfler 
15541281cf3SAxel Dörfler void
15641281cf3SAxel Dörfler TReplicantTray::AttachedToWindow()
15741281cf3SAxel Dörfler {
15841281cf3SAxel Dörfler 	BView::AttachedToWindow();
15941281cf3SAxel Dörfler 
160cb6afcb1SStephan Aßmus 	if (be_control_look != NULL) {
161cb6afcb1SStephan Aßmus 		SetViewColor(Parent()->ViewColor());
162cb6afcb1SStephan Aßmus 	} else {
16366eba86fSAxel Dörfler 		SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
16466eba86fSAxel Dörfler 			B_DARKEN_1_TINT));
165cb6afcb1SStephan Aßmus 	}
16641281cf3SAxel Dörfler 	SetDrawingMode(B_OP_COPY);
16766eba86fSAxel Dörfler 
16841281cf3SAxel Dörfler 	Window()->SetPulseRate(1000000);
16941281cf3SAxel Dörfler 	DealWithClock(fBarView->ShowingClock());
17041281cf3SAxel Dörfler 
171ae7a6e3aSAdrien Destugues 
17241281cf3SAxel Dörfler #ifdef DB_ADDONS
17341281cf3SAxel Dörfler 	// load addons and rehydrate archives
1743a6add49SAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST)
17541281cf3SAxel Dörfler 	InitAddOnSupport();
17641281cf3SAxel Dörfler #endif
1779c910f9eSStephan Aßmus #endif
17841281cf3SAxel Dörfler 	ResizeToPreferred();
17941281cf3SAxel Dörfler }
18041281cf3SAxel Dörfler 
18141281cf3SAxel Dörfler 
18241281cf3SAxel Dörfler void
18341281cf3SAxel Dörfler TReplicantTray::DetachedFromWindow()
18441281cf3SAxel Dörfler {
18541281cf3SAxel Dörfler #ifdef DB_ADDONS
18641281cf3SAxel Dörfler 	// clean up add-on support
187465b54cdSAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST)
18841281cf3SAxel Dörfler 	DeleteAddOnSupport();
18941281cf3SAxel Dörfler #endif
190465b54cdSAxel Dörfler #endif
19141281cf3SAxel Dörfler 	BView::DetachedFromWindow();
19241281cf3SAxel Dörfler }
19341281cf3SAxel Dörfler 
19441281cf3SAxel Dörfler 
19541281cf3SAxel Dörfler void
19641281cf3SAxel Dörfler TReplicantTray::RememberClockSettings()
19741281cf3SAxel Dörfler {
19841281cf3SAxel Dörfler 	if (fClock)	{
19941281cf3SAxel Dörfler 		desk_settings* settings = ((TBarApp*)be_app)->Settings();
20041281cf3SAxel Dörfler 
20141281cf3SAxel Dörfler 		settings->timeShowSeconds = fClock->ShowingSeconds();
20241281cf3SAxel Dörfler 		settings->timeShowMil = fClock->ShowingMilTime();
20341281cf3SAxel Dörfler 		settings->timeShowEuro = fClock->ShowingEuroDate();
20441281cf3SAxel Dörfler 		settings->timeFullDate = fClock->ShowingFullDate();
20541281cf3SAxel Dörfler 	}
20641281cf3SAxel Dörfler }
20741281cf3SAxel Dörfler 
20841281cf3SAxel Dörfler 
20941281cf3SAxel Dörfler bool
21041281cf3SAxel Dörfler TReplicantTray::ShowingSeconds()
21141281cf3SAxel Dörfler {
21241281cf3SAxel Dörfler 	if (fClock)
21341281cf3SAxel Dörfler 		return fClock->ShowingSeconds();
21441281cf3SAxel Dörfler 	return false;
21541281cf3SAxel Dörfler }
21641281cf3SAxel Dörfler 
21741281cf3SAxel Dörfler 
21841281cf3SAxel Dörfler bool
21941281cf3SAxel Dörfler TReplicantTray::ShowingMiltime()
22041281cf3SAxel Dörfler {
22141281cf3SAxel Dörfler 	if (fClock)
22241281cf3SAxel Dörfler 		return fClock->ShowingMilTime();
22341281cf3SAxel Dörfler 	return false;
22441281cf3SAxel Dörfler }
22541281cf3SAxel Dörfler 
22641281cf3SAxel Dörfler 
22741281cf3SAxel Dörfler bool
22841281cf3SAxel Dörfler TReplicantTray::ShowingEuroDate()
22941281cf3SAxel Dörfler {
23041281cf3SAxel Dörfler 	if (fClock)
23141281cf3SAxel Dörfler 		return fClock->ShowingEuroDate();
23241281cf3SAxel Dörfler 	return false;
23341281cf3SAxel Dörfler }
23441281cf3SAxel Dörfler 
23541281cf3SAxel Dörfler 
23641281cf3SAxel Dörfler bool
23741281cf3SAxel Dörfler TReplicantTray::ShowingFullDate()
23841281cf3SAxel Dörfler {
23941281cf3SAxel Dörfler 	if (fClock && CanShowFullDate())
24041281cf3SAxel Dörfler 		return fClock->ShowingFullDate();
24141281cf3SAxel Dörfler 	return false;
24241281cf3SAxel Dörfler }
24341281cf3SAxel Dörfler 
24441281cf3SAxel Dörfler 
24541281cf3SAxel Dörfler bool
24641281cf3SAxel Dörfler TReplicantTray::CanShowFullDate()
24741281cf3SAxel Dörfler {
24841281cf3SAxel Dörfler 	if (fClock)
24941281cf3SAxel Dörfler 		return fClock->CanShowFullDate();
25041281cf3SAxel Dörfler 	return false;
25141281cf3SAxel Dörfler }
25241281cf3SAxel Dörfler 
25341281cf3SAxel Dörfler 
25441281cf3SAxel Dörfler void
25541281cf3SAxel Dörfler TReplicantTray::DealWithClock(bool showClock)
25641281cf3SAxel Dörfler {
25741281cf3SAxel Dörfler 	fBarView->ShowClock(showClock);
25841281cf3SAxel Dörfler 
25941281cf3SAxel Dörfler 	if (showClock) {
26041281cf3SAxel Dörfler 		if (!fClock) {
26141281cf3SAxel Dörfler 			desk_settings* settings = ((TBarApp*)be_app)->Settings();
26241281cf3SAxel Dörfler 
263cb6afcb1SStephan Aßmus 			fClock = new TTimeView(fMinimumTrayWidth, kMaxReplicantHeight - 1.0,
264157cd891SAlexandre Deckner 				settings->timeShowSeconds, settings->timeShowMil,
265157cd891SAlexandre Deckner 				settings->timeFullDate,	settings->timeShowEuro, false);
26641281cf3SAxel Dörfler 			AddChild(fClock);
26741281cf3SAxel Dörfler 
26841281cf3SAxel Dörfler 			fClock->MoveTo(Bounds().right - fClock->Bounds().Width() - 1, 2);
26941281cf3SAxel Dörfler 			fClock->AllowFullDate(!IsMultiRow());
27041281cf3SAxel Dörfler 		}
27141281cf3SAxel Dörfler 	} else {
27241281cf3SAxel Dörfler 		if (fClock) {
27341281cf3SAxel Dörfler 			RememberClockSettings();
27441281cf3SAxel Dörfler 
27541281cf3SAxel Dörfler 			fClock->RemoveSelf();
27641281cf3SAxel Dörfler 			delete fClock;
27741281cf3SAxel Dörfler 			fClock = NULL;
27841281cf3SAxel Dörfler 		}
27941281cf3SAxel Dörfler 	}
28041281cf3SAxel Dörfler }
28141281cf3SAxel Dörfler 
28241281cf3SAxel Dörfler 
28366eba86fSAxel Dörfler /*!
28466eba86fSAxel Dörfler 	Width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth
28566eba86fSAxel Dörfler 	if not in multirowmode and greater than kMinimumReplicantCount
28666eba86fSAxel Dörfler 	the width should be calculated based on the actual
28766eba86fSAxel Dörfler 	replicant widths
28841281cf3SAxel Dörfler */
28941281cf3SAxel Dörfler void
29041281cf3SAxel Dörfler TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight)
29141281cf3SAxel Dörfler {
29241281cf3SAxel Dörfler 	float width = 0, height = kMinimumTrayHeight;
29341281cf3SAxel Dörfler 
29441281cf3SAxel Dörfler 	if (fMultiRowMode) {
2957da06231SAxel Dörfler 		if (fShelf->CountReplicants() > 0)
2967da06231SAxel Dörfler 			height = fRightBottomReplicant.bottom;
29741281cf3SAxel Dörfler 
29841281cf3SAxel Dörfler 		// the height will be uniform for the number of rows
29941281cf3SAxel Dörfler 		// necessary to show all the reps + any gutters
30041281cf3SAxel Dörfler 		// necessary for spacing
30141281cf3SAxel Dörfler 		int32 rowCount = (int32)(height / kMaxReplicantHeight);
30241281cf3SAxel Dörfler 		height = kGutter + (rowCount * kMaxReplicantHeight)
30341281cf3SAxel Dörfler 			+ ((rowCount - 1) * kIconGap) + kGutter;
30441281cf3SAxel Dörfler 		height = max(kMinimumTrayHeight, height);
305cb6afcb1SStephan Aßmus 		width = fMinimumTrayWidth;
30641281cf3SAxel Dörfler 	} else {
30741281cf3SAxel Dörfler 		// if last replicant overruns clock then
30841281cf3SAxel Dörfler 		// resize to accomodate
3097da06231SAxel Dörfler 		if (fShelf->CountReplicants() > 0) {
31041281cf3SAxel Dörfler 			if (fBarView->ShowingClock()
3117da06231SAxel Dörfler 				&& fRightBottomReplicant.right + 6 >= fClock->Frame().left) {
31266eba86fSAxel Dörfler 				width = fRightBottomReplicant.right + 6
31366eba86fSAxel Dörfler 					+ fClock->Frame().Width();
31441281cf3SAxel Dörfler 			} else
3157da06231SAxel Dörfler 				width = fRightBottomReplicant.right + 3;
31641281cf3SAxel Dörfler 		}
31741281cf3SAxel Dörfler 		// this view has a fixed minimum width
318cb6afcb1SStephan Aßmus 		width = max(fMinimumTrayWidth, width);
31941281cf3SAxel Dörfler 	}
32041281cf3SAxel Dörfler 
32141281cf3SAxel Dörfler 	*preferredWidth = width;
32241281cf3SAxel Dörfler 	// add 2 for the border
32341281cf3SAxel Dörfler 	*preferredHeight = height + 1;
32441281cf3SAxel Dörfler }
32541281cf3SAxel Dörfler 
32641281cf3SAxel Dörfler 
32741281cf3SAxel Dörfler void
32841281cf3SAxel Dörfler TReplicantTray::AdjustPlacement()
32941281cf3SAxel Dörfler {
33041281cf3SAxel Dörfler 	// called when an add-on has been added or removed
33141281cf3SAxel Dörfler 	// need to resize the parent of this accordingly
332a5210ab1SAxel Dörfler 
33341281cf3SAxel Dörfler 	BRect bounds = Bounds();
33441281cf3SAxel Dörfler 	float width, height;
33541281cf3SAxel Dörfler 	GetPreferredSize(&width, &height);
33641281cf3SAxel Dörfler 
33741281cf3SAxel Dörfler 	if (width == bounds.Width() && height == bounds.Height()) {
33841281cf3SAxel Dörfler 		// no need to change anything
33941281cf3SAxel Dörfler 		return;
34041281cf3SAxel Dörfler 	}
34141281cf3SAxel Dörfler 
34241281cf3SAxel Dörfler 	Parent()->ResizeToPreferred();
34341281cf3SAxel Dörfler 	fBarView->UpdatePlacement();
34441281cf3SAxel Dörfler 	Parent()->Invalidate();
34541281cf3SAxel Dörfler 	Invalidate();
34641281cf3SAxel Dörfler }
34741281cf3SAxel Dörfler 
34841281cf3SAxel Dörfler 
34941281cf3SAxel Dörfler void
35041281cf3SAxel Dörfler TReplicantTray::Draw(BRect)
35141281cf3SAxel Dörfler {
352cb6afcb1SStephan Aßmus return;
353eaa9af99SStephan Aßmus 	rgb_color menuColor = ViewColor();
35441281cf3SAxel Dörfler 	rgb_color vdark = tint_color(menuColor, B_DARKEN_3_TINT);
35541281cf3SAxel Dörfler 	rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT);
35641281cf3SAxel Dörfler 
35741281cf3SAxel Dörfler 	BRect frame(Bounds());
35841281cf3SAxel Dörfler 
35941281cf3SAxel Dörfler 	SetHighColor(light);
36041281cf3SAxel Dörfler 	StrokeLine(frame.LeftBottom(), frame.RightBottom());
36141281cf3SAxel Dörfler 	StrokeLine(frame.RightBottom(), frame.RightTop());
36241281cf3SAxel Dörfler 
36341281cf3SAxel Dörfler 	SetHighColor(vdark);
36441281cf3SAxel Dörfler 	StrokeLine(frame.RightTop(), frame.LeftTop());
36541281cf3SAxel Dörfler 	StrokeLine(frame.LeftTop(), frame.LeftBottom());
36641281cf3SAxel Dörfler }
36741281cf3SAxel Dörfler 
36841281cf3SAxel Dörfler 
36941281cf3SAxel Dörfler void
37041281cf3SAxel Dörfler TReplicantTray::MessageReceived(BMessage* message)
37141281cf3SAxel Dörfler {
37241281cf3SAxel Dörfler 	switch (message->what) {
37341281cf3SAxel Dörfler 		case 'time':
37441281cf3SAxel Dörfler 			// from context menu in clock and in this view
37541281cf3SAxel Dörfler 			DealWithClock(!fBarView->ShowingClock());
37641281cf3SAxel Dörfler 			RealignReplicants();
37741281cf3SAxel Dörfler 			AdjustPlacement();
37841281cf3SAxel Dörfler 			break;
37941281cf3SAxel Dörfler 
380a5210ab1SAxel Dörfler 		case 'Trfm':
38141281cf3SAxel Dörfler 			// time string reformat -> realign
38241281cf3SAxel Dörfler 			DealWithClock(fBarView->ShowingClock());
38341281cf3SAxel Dörfler 			RealignReplicants();
38441281cf3SAxel Dörfler 			AdjustPlacement();
38541281cf3SAxel Dörfler 			break;
38641281cf3SAxel Dörfler 
38771bd3ba5SJonas Sundström 		case kShowSeconds:
38871bd3ba5SJonas Sundström 		case kMilTime:
38971bd3ba5SJonas Sundström 		case kEuroDate:
39071bd3ba5SJonas Sundström 		case kFullDate:
39141281cf3SAxel Dörfler 			if (fClock != NULL)
39241281cf3SAxel Dörfler 				Window()->PostMessage(message, fClock);
39341281cf3SAxel Dörfler 			break;
39441281cf3SAxel Dörfler 
39541281cf3SAxel Dörfler #ifdef DB_ADDONS
39641281cf3SAxel Dörfler 		case B_NODE_MONITOR:
39741281cf3SAxel Dörfler 		case B_QUERY_UPDATE:
39841281cf3SAxel Dörfler 			HandleEntryUpdate(message);
39941281cf3SAxel Dörfler 			break;
40041281cf3SAxel Dörfler #endif
40141281cf3SAxel Dörfler 
40241281cf3SAxel Dörfler 		default:
40341281cf3SAxel Dörfler 			BView::MessageReceived(message);
40441281cf3SAxel Dörfler 			break;
40541281cf3SAxel Dörfler 	}
40641281cf3SAxel Dörfler }
40741281cf3SAxel Dörfler 
40841281cf3SAxel Dörfler 
40941281cf3SAxel Dörfler void
41041281cf3SAxel Dörfler TReplicantTray::ShowReplicantMenu(BPoint point)
41141281cf3SAxel Dörfler {
41241281cf3SAxel Dörfler 	BPopUpMenu* menu = new BPopUpMenu("", false, false);
41341281cf3SAxel Dörfler 	menu->SetFont(be_plain_font);
41441281cf3SAxel Dörfler 
41541281cf3SAxel Dörfler 	// If the clock is visible, show the extended menu
41641281cf3SAxel Dörfler 	// otheriwse, show "Show Time".
41741281cf3SAxel Dörfler 
41841281cf3SAxel Dörfler 	if (fBarView->ShowingClock())
41941281cf3SAxel Dörfler 		fClock->ShowClockOptions(ConvertToScreen(point));
42041281cf3SAxel Dörfler 	else {
42161863f2cSMatt Madia 		BMenuItem* item = new BMenuItem(B_TRANSLATE("Show Time"),
42261863f2cSMatt Madia 			new BMessage('time'));
42341281cf3SAxel Dörfler 		menu->AddItem(item);
42441281cf3SAxel Dörfler 		menu->SetTargetForItems(this);
42541281cf3SAxel Dörfler 		BPoint where = ConvertToScreen(point);
42641281cf3SAxel Dörfler 		menu->Go(where, true, true, BRect(where - BPoint(4, 4),
42741281cf3SAxel Dörfler 			where + BPoint(4, 4)), true);
42841281cf3SAxel Dörfler 	}
42941281cf3SAxel Dörfler }
43041281cf3SAxel Dörfler 
43141281cf3SAxel Dörfler 
43241281cf3SAxel Dörfler void
43341281cf3SAxel Dörfler TReplicantTray::MouseDown(BPoint where)
43441281cf3SAxel Dörfler {
43541281cf3SAxel Dörfler #ifdef DB_ADDONS
43641281cf3SAxel Dörfler 	if (modifiers() & B_CONTROL_KEY)
43741281cf3SAxel Dörfler 		DumpList(fItemList);
43841281cf3SAxel Dörfler #endif
43941281cf3SAxel Dörfler 
44041281cf3SAxel Dörfler 	uint32	buttons;
44141281cf3SAxel Dörfler 
44241281cf3SAxel Dörfler 	Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
44341281cf3SAxel Dörfler 	if (buttons == B_SECONDARY_MOUSE_BUTTON) {
44441281cf3SAxel Dörfler 		ShowReplicantMenu(where);
44541281cf3SAxel Dörfler 	} else {
44641281cf3SAxel Dörfler 		BPoint save = where;
44741281cf3SAxel Dörfler 		bigtime_t doubleClickSpeed;
44841281cf3SAxel Dörfler 		bigtime_t start = system_time();
44941281cf3SAxel Dörfler 		uint32 buttons;
45041281cf3SAxel Dörfler 
45141281cf3SAxel Dörfler 		get_click_speed(&doubleClickSpeed);
45241281cf3SAxel Dörfler 
45341281cf3SAxel Dörfler 		do {
45441281cf3SAxel Dörfler 			if (fabs(where.x - save.x) > 4 || fabs(where.y - save.y) > 4)
45541281cf3SAxel Dörfler 				// user moved out of bounds of click area
45641281cf3SAxel Dörfler 				break;
45741281cf3SAxel Dörfler 
45841281cf3SAxel Dörfler 			if ((system_time() - start) > (2 * doubleClickSpeed)) {
45941281cf3SAxel Dörfler 				ShowReplicantMenu(where);
46041281cf3SAxel Dörfler 				break;
46141281cf3SAxel Dörfler 			}
46241281cf3SAxel Dörfler 
46341281cf3SAxel Dörfler 			snooze(50000);
46441281cf3SAxel Dörfler 			GetMouse(&where, &buttons);
46541281cf3SAxel Dörfler 		} while (buttons);
46641281cf3SAxel Dörfler 	}
46741281cf3SAxel Dörfler 	BView::MouseDown(where);
46841281cf3SAxel Dörfler }
46941281cf3SAxel Dörfler 
47041281cf3SAxel Dörfler #ifdef DB_ADDONS
47141281cf3SAxel Dörfler 
47241281cf3SAxel Dörfler void
47341281cf3SAxel Dörfler TReplicantTray::InitAddOnSupport()
47441281cf3SAxel Dörfler {
47541281cf3SAxel Dörfler 	// list to maintain refs to each rep added/deleted
47641281cf3SAxel Dörfler 	fItemList = new BList();
47741281cf3SAxel Dörfler 
47841281cf3SAxel Dörfler 	bool haveKey = false;
47941281cf3SAxel Dörfler  	BPath path;
48041281cf3SAxel Dörfler 	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) {
48141281cf3SAxel Dörfler 		path.Append(kDeskbarSecurityCodeFile);
48241281cf3SAxel Dörfler 
48341281cf3SAxel Dörfler 		BFile file(path.Path(),B_READ_ONLY);
48441281cf3SAxel Dörfler 		if (file.InitCheck() == B_OK
48571bd3ba5SJonas Sundström 			&& file.Read(&fDeskbarSecurityCode,	sizeof(fDeskbarSecurityCode))
48671bd3ba5SJonas Sundström 				== sizeof(fDeskbarSecurityCode))
48741281cf3SAxel Dörfler 			haveKey = true;
48841281cf3SAxel Dörfler 	}
48941281cf3SAxel Dörfler 	if (!haveKey) {
49041281cf3SAxel Dörfler 		// create the security code
49141281cf3SAxel Dörfler 		bigtime_t real = real_time_clock_usecs();
49241281cf3SAxel Dörfler 		bigtime_t boot = system_time();
49341281cf3SAxel Dörfler 		// two computers would have to have exactly matching clocks, and launch
49471bd3ba5SJonas Sundström 		// Deskbar at the exact same time into the bootsequence in order for
49571bd3ba5SJonas Sundström 		// their security-ID to be identical
49666eba86fSAxel Dörfler 		fDeskbarSecurityCode = ((real & 0xffffffffULL) << 32)
49766eba86fSAxel Dörfler 			| (boot & 0xffffffffULL);
49841281cf3SAxel Dörfler 
49941281cf3SAxel Dörfler 	if (find_directory (B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) {
50041281cf3SAxel Dörfler 			path.Append(kDeskbarSecurityCodeFile);
50171bd3ba5SJonas Sundström 			BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE
50271bd3ba5SJonas Sundström 				| B_ERASE_FILE);
50341281cf3SAxel Dörfler 			if (file.InitCheck() == B_OK)
50441281cf3SAxel Dörfler 				file.Write(&fDeskbarSecurityCode, sizeof(fDeskbarSecurityCode));
50541281cf3SAxel Dörfler 		}
50641281cf3SAxel Dörfler 	}
50741281cf3SAxel Dörfler 
50841281cf3SAxel Dörfler 	// for each volume currently mounted
50941281cf3SAxel Dörfler 	//		index the volume with our indices
51041281cf3SAxel Dörfler 	BVolumeRoster roster;
51141281cf3SAxel Dörfler 	BVolume volume;
51241281cf3SAxel Dörfler 	while (roster.GetNextVolume(&volume) == B_OK) {
51341281cf3SAxel Dörfler 		fs_create_index(volume.Device(), kStatusPredicate, B_STRING_TYPE, 0);
51441281cf3SAxel Dörfler 		RunAddOnQuery(&volume, kEnabledPredicate);
51541281cf3SAxel Dörfler 	}
51641281cf3SAxel Dörfler 
51741281cf3SAxel Dörfler 	// we also watch for volumes mounted and unmounted
51841281cf3SAxel Dörfler 	watch_node(NULL, B_WATCH_MOUNT | B_WATCH_ATTR, this, Window());
51941281cf3SAxel Dörfler }
52041281cf3SAxel Dörfler 
52141281cf3SAxel Dörfler 
52241281cf3SAxel Dörfler void
52341281cf3SAxel Dörfler TReplicantTray::DeleteAddOnSupport()
52441281cf3SAxel Dörfler {
52541281cf3SAxel Dörfler 	for (int32 i = fItemList->CountItems(); i-- > 0 ;) {
52641281cf3SAxel Dörfler 		DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->RemoveItem(i);
52741281cf3SAxel Dörfler 		if (item) {
52841281cf3SAxel Dörfler 			if (item->isAddOn)
52941281cf3SAxel Dörfler 				watch_node(&(item->nodeRef), B_STOP_WATCHING, this, Window());
53041281cf3SAxel Dörfler 
53141281cf3SAxel Dörfler 			delete item;
53241281cf3SAxel Dörfler 		}
53341281cf3SAxel Dörfler 	}
53441281cf3SAxel Dörfler 	delete fItemList;
53541281cf3SAxel Dörfler 
53641281cf3SAxel Dörfler 	// stop the volume mount/unmount watch
53741281cf3SAxel Dörfler 	stop_watching(this, Window());
53841281cf3SAxel Dörfler }
53941281cf3SAxel Dörfler 
54041281cf3SAxel Dörfler 
54141281cf3SAxel Dörfler void
54241281cf3SAxel Dörfler TReplicantTray::RunAddOnQuery(BVolume* volume, const char* predicate)
54341281cf3SAxel Dörfler {
54441281cf3SAxel Dörfler 	// Since the new BFS supports querying for attributes without
54541281cf3SAxel Dörfler 	// an index, we only run the query if the index exists (for
54641281cf3SAxel Dörfler 	// newly mounted devices only - the Deskbar will automatically
54741281cf3SAxel Dörfler 	// create an index for every device mounted at startup).
54841281cf3SAxel Dörfler 	index_info info;
54966eba86fSAxel Dörfler 	if (!volume->KnowsQuery()
55066eba86fSAxel Dörfler 		|| fs_stat_index(volume->Device(), kStatusPredicate, &info) != 0)
55141281cf3SAxel Dörfler 		return;
55241281cf3SAxel Dörfler 
55341281cf3SAxel Dörfler 	// run a new query on a specific volume
55441281cf3SAxel Dörfler 	// make it live
55541281cf3SAxel Dörfler 	BQuery query;
55641281cf3SAxel Dörfler 	query.SetVolume(volume);
55741281cf3SAxel Dörfler 	query.SetPredicate(predicate);
55841281cf3SAxel Dörfler 	query.Fetch();
55941281cf3SAxel Dörfler 
56041281cf3SAxel Dörfler 	int32 id;
56141281cf3SAxel Dörfler 	BEntry entry;
5627da06231SAxel Dörfler 	while (query.GetNextEntry(&entry) == B_OK) {
56341281cf3SAxel Dörfler 		// scan any entries returned
56441281cf3SAxel Dörfler 		// attempt to load them as add-ons
56541281cf3SAxel Dörfler 		// collisions are handled in LoadAddOn
56641281cf3SAxel Dörfler 		LoadAddOn(&entry, &id);
56741281cf3SAxel Dörfler 	}
5687da06231SAxel Dörfler }
56941281cf3SAxel Dörfler 
57041281cf3SAxel Dörfler 
57141281cf3SAxel Dörfler bool
57241281cf3SAxel Dörfler TReplicantTray::IsAddOn(entry_ref& ref)
57341281cf3SAxel Dörfler {
57441281cf3SAxel Dörfler 	BFile file(&ref, B_READ_ONLY);
57541281cf3SAxel Dörfler 
57641281cf3SAxel Dörfler 	char status[64];
57766eba86fSAxel Dörfler 	ssize_t size = file.ReadAttr(kStatusPredicate, B_STRING_TYPE, 0, &status,
57866eba86fSAxel Dörfler 		sizeof(status));
57941281cf3SAxel Dörfler 	return size > 0;
58041281cf3SAxel Dörfler }
58141281cf3SAxel Dörfler 
58241281cf3SAxel Dörfler 
58341281cf3SAxel Dörfler DeskbarItemInfo*
58441281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(node_ref& nodeRef)
58541281cf3SAxel Dörfler {
58641281cf3SAxel Dörfler 	for (int32 i = fItemList->CountItems(); i-- > 0 ;) {
58766eba86fSAxel Dörfler 		DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i);
58841281cf3SAxel Dörfler 		if (item == NULL)
58941281cf3SAxel Dörfler 			continue;
59041281cf3SAxel Dörfler 
59141281cf3SAxel Dörfler 		if (item->nodeRef == nodeRef)
59241281cf3SAxel Dörfler 			return item;
59341281cf3SAxel Dörfler 	}
59441281cf3SAxel Dörfler 
59541281cf3SAxel Dörfler 	return NULL;
59641281cf3SAxel Dörfler }
59741281cf3SAxel Dörfler 
59841281cf3SAxel Dörfler 
59941281cf3SAxel Dörfler DeskbarItemInfo*
60041281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(int32 id)
60141281cf3SAxel Dörfler {
60241281cf3SAxel Dörfler 	for (int32 i = fItemList->CountItems(); i-- > 0 ;) {
60366eba86fSAxel Dörfler 		DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i);
60441281cf3SAxel Dörfler 		if (item == NULL)
60541281cf3SAxel Dörfler 			continue;
60641281cf3SAxel Dörfler 
60741281cf3SAxel Dörfler 		if (item->id == id)
60841281cf3SAxel Dörfler 			return item;
60941281cf3SAxel Dörfler 	}
61041281cf3SAxel Dörfler 
61141281cf3SAxel Dörfler 	return NULL;
61241281cf3SAxel Dörfler }
61341281cf3SAxel Dörfler 
61441281cf3SAxel Dörfler 
61541281cf3SAxel Dörfler bool
61641281cf3SAxel Dörfler TReplicantTray::NodeExists(node_ref& nodeRef)
61741281cf3SAxel Dörfler {
61841281cf3SAxel Dörfler 	return DeskbarItemFor(nodeRef) != NULL;
61941281cf3SAxel Dörfler }
62041281cf3SAxel Dörfler 
62141281cf3SAxel Dörfler 
62266eba86fSAxel Dörfler /*!	This handles B_NODE_MONITOR & B_QUERY_UPDATE messages received
62366eba86fSAxel Dörfler 	for the registered add-ons.
62441281cf3SAxel Dörfler */
62541281cf3SAxel Dörfler void
62641281cf3SAxel Dörfler TReplicantTray::HandleEntryUpdate(BMessage* message)
62741281cf3SAxel Dörfler {
62841281cf3SAxel Dörfler 	int32 opcode;
62941281cf3SAxel Dörfler 	if (message->FindInt32("opcode", &opcode) != B_OK)
63041281cf3SAxel Dörfler 		return;
63141281cf3SAxel Dörfler 
63241281cf3SAxel Dörfler 	BPath path;
63341281cf3SAxel Dörfler 	switch (opcode) {
63441281cf3SAxel Dörfler 		case B_ENTRY_CREATED:
63541281cf3SAxel Dörfler 		{
63666eba86fSAxel Dörfler 			// entry was just listed, matches live query
63741281cf3SAxel Dörfler 			const char* name;
63841281cf3SAxel Dörfler 			ino_t directory;
63941281cf3SAxel Dörfler 			dev_t device;
64041281cf3SAxel Dörfler 			// received when an app adds a ref to the
64141281cf3SAxel Dörfler 			// Deskbar add-ons folder
64241281cf3SAxel Dörfler 			if (message->FindString("name", &name) == B_OK
64341281cf3SAxel Dörfler 				&& message->FindInt64("directory", &directory) == B_OK
64441281cf3SAxel Dörfler 				&& message->FindInt32("device", &device) == B_OK) {
64541281cf3SAxel Dörfler 				entry_ref ref(device, directory, name);
64641281cf3SAxel Dörfler 				// see if this item has the attribute
64741281cf3SAxel Dörfler 				// that we expect
64841281cf3SAxel Dörfler 				if (IsAddOn(ref)) {
64941281cf3SAxel Dörfler 					int32 id;
65041281cf3SAxel Dörfler 					BEntry entry(&ref);
65141281cf3SAxel Dörfler 					LoadAddOn(&entry, &id);
65241281cf3SAxel Dörfler 				}
65341281cf3SAxel Dörfler 			}
65441281cf3SAxel Dörfler 			break;
65566eba86fSAxel Dörfler 		}
65641281cf3SAxel Dörfler 
65741281cf3SAxel Dörfler 		case B_ATTR_CHANGED:
65866eba86fSAxel Dörfler 		{
65941281cf3SAxel Dörfler 			// from node watch on individual items
66041281cf3SAxel Dörfler 			// (node_watch added in LoadAddOn)
66141281cf3SAxel Dörfler 			node_ref nodeRef;
66241281cf3SAxel Dörfler 			if (message->FindInt32("device", &(nodeRef.device)) == B_OK
66341281cf3SAxel Dörfler 				&& message->FindInt64("node", &(nodeRef.node)) == B_OK) {
66441281cf3SAxel Dörfler 				// get the add-on this is for
66541281cf3SAxel Dörfler 				DeskbarItemInfo* item = DeskbarItemFor(nodeRef);
66641281cf3SAxel Dörfler 				if (item == NULL)
66741281cf3SAxel Dörfler 					break;
66841281cf3SAxel Dörfler 
66941281cf3SAxel Dörfler 				BFile file(&item->entryRef, B_READ_ONLY);
67041281cf3SAxel Dörfler 
67141281cf3SAxel Dörfler 				char status[255];
67241281cf3SAxel Dörfler 				ssize_t size = file.ReadAttr(kStatusPredicate,
67341281cf3SAxel Dörfler 					B_STRING_TYPE, 0, status, sizeof(status) - 1);
67441281cf3SAxel Dörfler 				status[sizeof(status) - 1] = '\0';
67541281cf3SAxel Dörfler 
67641281cf3SAxel Dörfler 				// attribute was removed
67741281cf3SAxel Dörfler 				if (size == B_ENTRY_NOT_FOUND) {
67841281cf3SAxel Dörfler 					// cleans up and removes node_watch
67941281cf3SAxel Dörfler 					UnloadAddOn(&nodeRef, NULL, true, false);
68041281cf3SAxel Dörfler 				} else if (!strcmp(status, "enable")) {
68141281cf3SAxel Dörfler 					int32 id;
68241281cf3SAxel Dörfler 					BEntry entry(&item->entryRef, true);
68341281cf3SAxel Dörfler 					LoadAddOn(&entry, &id);
68441281cf3SAxel Dörfler 				}
68541281cf3SAxel Dörfler 			}
68641281cf3SAxel Dörfler 			break;
68766eba86fSAxel Dörfler 		}
68841281cf3SAxel Dörfler 
68941281cf3SAxel Dörfler 		case B_ENTRY_MOVED:
69041281cf3SAxel Dörfler 		{
69141281cf3SAxel Dörfler 			entry_ref ref;
69241281cf3SAxel Dörfler 			ino_t todirectory;
69341281cf3SAxel Dörfler 			ino_t node;
69441281cf3SAxel Dörfler 			const char* name;
69541281cf3SAxel Dörfler 			if (message->FindString("name", &name) == B_OK
69671bd3ba5SJonas Sundström 				&& message->FindInt64("from directory", &(ref.directory))
69771bd3ba5SJonas Sundström 				== B_OK
69841281cf3SAxel Dörfler 				&& message->FindInt64("to directory", &todirectory) == B_OK
69941281cf3SAxel Dörfler 				&& message->FindInt32("device", &(ref.device)) == B_OK
70041281cf3SAxel Dörfler 				&& message->FindInt64("node", &node) == B_OK ) {
70141281cf3SAxel Dörfler 
70241281cf3SAxel Dörfler 				if (!name)
70341281cf3SAxel Dörfler 					break;
70441281cf3SAxel Dörfler 
70541281cf3SAxel Dörfler 				ref.set_name(name);
70641281cf3SAxel Dörfler 				// change the directory reference to
70741281cf3SAxel Dörfler 				// the new directory
70841281cf3SAxel Dörfler 				MoveItem(&ref, todirectory);
70941281cf3SAxel Dörfler 			}
71041281cf3SAxel Dörfler 			break;
71166eba86fSAxel Dörfler 		}
71241281cf3SAxel Dörfler 
71341281cf3SAxel Dörfler 		case B_ENTRY_REMOVED:
71441281cf3SAxel Dörfler 		{
71541281cf3SAxel Dörfler 			// entry was rm'd from the device
71641281cf3SAxel Dörfler 			node_ref nodeRef;
71741281cf3SAxel Dörfler 			if (message->FindInt32("device", &(nodeRef.device)) == B_OK
71841281cf3SAxel Dörfler 				&& message->FindInt64("node", &(nodeRef.node)) == B_OK) {
71941281cf3SAxel Dörfler 				DeskbarItemInfo* item = DeskbarItemFor(nodeRef);
72041281cf3SAxel Dörfler 				if (item == NULL)
72141281cf3SAxel Dörfler 					break;
72241281cf3SAxel Dörfler 
72341281cf3SAxel Dörfler 				// If there is a team running where the add-on comes from,
72441281cf3SAxel Dörfler 				// we don't want to remove the icon yet.
72541281cf3SAxel Dörfler 				if (be_roster->IsRunning(&item->entryRef))
72641281cf3SAxel Dörfler 					break;
72741281cf3SAxel Dörfler 
72841281cf3SAxel Dörfler 				UnloadAddOn(&nodeRef, NULL, true, false);
72941281cf3SAxel Dörfler 			}
73041281cf3SAxel Dörfler 			break;
73166eba86fSAxel Dörfler 		}
73241281cf3SAxel Dörfler 
73341281cf3SAxel Dörfler 		case B_DEVICE_MOUNTED:
73441281cf3SAxel Dörfler 		{
73541281cf3SAxel Dörfler 			// run a new query on the new device
73641281cf3SAxel Dörfler 			dev_t device;
73741281cf3SAxel Dörfler 			if (message->FindInt32("new device", &device) != B_OK)
73841281cf3SAxel Dörfler 				break;
73941281cf3SAxel Dörfler 
74041281cf3SAxel Dörfler 			RunAddOnQuery(new BVolume(device), kEnabledPredicate);
74141281cf3SAxel Dörfler 			break;
74266eba86fSAxel Dörfler 		}
74366eba86fSAxel Dörfler 
74441281cf3SAxel Dörfler 		case B_DEVICE_UNMOUNTED:
74541281cf3SAxel Dörfler 		{
74641281cf3SAxel Dörfler 			// remove all items associated with the device
74741281cf3SAxel Dörfler 			// unmounted
74841281cf3SAxel Dörfler 			// contrary to what the BeBook says, the item is called "device",
74941281cf3SAxel Dörfler 			// not "new device" like it is for B_DEVICE_MOUNTED
75041281cf3SAxel Dörfler 			dev_t device;
75141281cf3SAxel Dörfler 			if (message->FindInt32("device", &device) != B_OK)
75241281cf3SAxel Dörfler 				break;
75341281cf3SAxel Dörfler 
75441281cf3SAxel Dörfler 			UnloadAddOn(NULL, &device, false, true);
75541281cf3SAxel Dörfler 			break;
75641281cf3SAxel Dörfler 		}
75741281cf3SAxel Dörfler 	}
75866eba86fSAxel Dörfler }
75941281cf3SAxel Dörfler 
76041281cf3SAxel Dörfler 
76166eba86fSAxel Dörfler /*!
76266eba86fSAxel Dörfler 	The add-ons must support the exported C function API
76366eba86fSAxel Dörfler 	if they do, they will be loaded and added to deskbar
76466eba86fSAxel Dörfler 	primary function is the Instantiate function
7657da06231SAxel Dörfler */
76641281cf3SAxel Dörfler status_t
76741281cf3SAxel Dörfler TReplicantTray::LoadAddOn(BEntry* entry, int32* id, bool force)
76841281cf3SAxel Dörfler {
76941281cf3SAxel Dörfler 	if (!entry)
77041281cf3SAxel Dörfler 		return B_ERROR;
77141281cf3SAxel Dörfler 
77241281cf3SAxel Dörfler 	node_ref nodeRef;
77341281cf3SAxel Dörfler 	entry->GetNodeRef(&nodeRef);
77441281cf3SAxel Dörfler 	// no duplicates
77541281cf3SAxel Dörfler 	if (NodeExists(nodeRef))
77641281cf3SAxel Dörfler 		return B_ERROR;
77741281cf3SAxel Dörfler 
77841281cf3SAxel Dörfler 	BNode node(entry);
77941281cf3SAxel Dörfler 	if (!force) {
78041281cf3SAxel Dörfler 		status_t error = node.InitCheck();
78141281cf3SAxel Dörfler 		if (error != B_OK)
78241281cf3SAxel Dörfler 			return error;
78341281cf3SAxel Dörfler 
78441281cf3SAxel Dörfler 		uint64 deskbarID;
78566eba86fSAxel Dörfler 		ssize_t size = node.ReadAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE,
78666eba86fSAxel Dörfler 			0, &deskbarID, sizeof(fDeskbarSecurityCode));
78766eba86fSAxel Dörfler 		if (size != sizeof(fDeskbarSecurityCode)
78866eba86fSAxel Dörfler 			|| deskbarID != fDeskbarSecurityCode) {
78941281cf3SAxel Dörfler 			// no code or code doesn't match
79041281cf3SAxel Dörfler 			return B_ERROR;
79141281cf3SAxel Dörfler 		}
79241281cf3SAxel Dörfler 	}
79341281cf3SAxel Dörfler 
79441281cf3SAxel Dörfler 	BPath path;
79566eba86fSAxel Dörfler 	status_t status = entry->GetPath(&path);
79666eba86fSAxel Dörfler 	if (status < B_OK)
79766eba86fSAxel Dörfler 		return status;
79841281cf3SAxel Dörfler 
79941281cf3SAxel Dörfler 	// load the add-on
80041281cf3SAxel Dörfler 	image_id image = load_add_on(path.Path());
80166eba86fSAxel Dörfler 	if (image < B_OK)
80266eba86fSAxel Dörfler 		return image;
80341281cf3SAxel Dörfler 
80441281cf3SAxel Dörfler 	// get the view loading function symbol
80541281cf3SAxel Dörfler 	//    we first look for a symbol that takes an image_id
80641281cf3SAxel Dörfler 	//    and entry_ref pointer, if not found, go with normal
80741281cf3SAxel Dörfler 	//    instantiate function
80841281cf3SAxel Dörfler 	BView* (*entryFunction)(image_id, const entry_ref*);
80941281cf3SAxel Dörfler 	BView* (*itemFunction)(void);
81041281cf3SAxel Dörfler 	BView* view = NULL;
81141281cf3SAxel Dörfler 
81241281cf3SAxel Dörfler 	entry_ref ref;
81341281cf3SAxel Dörfler 	entry->GetRef(&ref);
81441281cf3SAxel Dörfler 
81541281cf3SAxel Dörfler 	if (get_image_symbol(image, kInstantiateEntryCFunctionName,
81666eba86fSAxel Dörfler 			B_SYMBOL_TYPE_TEXT, (void**)&entryFunction) >= B_OK) {
81741281cf3SAxel Dörfler 		view = (*entryFunction)(image, &ref);
81841281cf3SAxel Dörfler 	} else if (get_image_symbol(image, kInstantiateItemCFunctionName,
81966eba86fSAxel Dörfler 			B_SYMBOL_TYPE_TEXT, (void**)&itemFunction) >= B_OK) {
82041281cf3SAxel Dörfler 		view = (*itemFunction)();
82141281cf3SAxel Dörfler 	} else {
82241281cf3SAxel Dörfler 		unload_add_on(image);
82341281cf3SAxel Dörfler 		return B_ERROR;
82441281cf3SAxel Dörfler 	}
82541281cf3SAxel Dörfler 
82666eba86fSAxel Dörfler 	if (view == NULL || IconExists(view->Name())) {
82741281cf3SAxel Dörfler 		delete view;
82841281cf3SAxel Dörfler 		unload_add_on(image);
82941281cf3SAxel Dörfler 		return B_ERROR;
83041281cf3SAxel Dörfler 	}
83141281cf3SAxel Dörfler 
83241281cf3SAxel Dörfler 	BMessage* data = new BMessage;
83341281cf3SAxel Dörfler 	view->Archive(data);
83441281cf3SAxel Dörfler 	delete view;
83541281cf3SAxel Dörfler 
83641281cf3SAxel Dörfler 	AddIcon(data, id, &ref);
83741281cf3SAxel Dörfler 		// add the rep; adds info to list
83841281cf3SAxel Dörfler 
83941281cf3SAxel Dörfler 	node.WriteAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, 0,
84041281cf3SAxel Dörfler 		&fDeskbarSecurityCode, sizeof(fDeskbarSecurityCode));
84141281cf3SAxel Dörfler 
84241281cf3SAxel Dörfler 	return B_OK;
84341281cf3SAxel Dörfler }
84441281cf3SAxel Dörfler 
84541281cf3SAxel Dörfler 
84641281cf3SAxel Dörfler status_t
84741281cf3SAxel Dörfler TReplicantTray::AddItem(int32 id, node_ref nodeRef, BEntry& entry, bool isAddOn)
84841281cf3SAxel Dörfler {
84941281cf3SAxel Dörfler 	DeskbarItemInfo* item = new DeskbarItemInfo;
85041281cf3SAxel Dörfler 	if (item == NULL)
85141281cf3SAxel Dörfler 		return B_NO_MEMORY;
85241281cf3SAxel Dörfler 
85341281cf3SAxel Dörfler 	item->id = id;
85441281cf3SAxel Dörfler 	item->isAddOn = isAddOn;
85541281cf3SAxel Dörfler 
85641281cf3SAxel Dörfler 	if (entry.GetRef(&item->entryRef) < B_OK) {
85741281cf3SAxel Dörfler 		item->entryRef.device = -1;
85841281cf3SAxel Dörfler 		item->entryRef.directory = -1;
85941281cf3SAxel Dörfler 		item->entryRef.name = NULL;
86041281cf3SAxel Dörfler 	}
86141281cf3SAxel Dörfler 	item->nodeRef = nodeRef;
86241281cf3SAxel Dörfler 
86341281cf3SAxel Dörfler 	fItemList->AddItem(item);
86441281cf3SAxel Dörfler 
86541281cf3SAxel Dörfler 	if (isAddOn)
86641281cf3SAxel Dörfler 		watch_node(&nodeRef, B_WATCH_NAME | B_WATCH_ATTR, this, Window());
86741281cf3SAxel Dörfler 
86841281cf3SAxel Dörfler 	return B_OK;
86941281cf3SAxel Dörfler }
87041281cf3SAxel Dörfler 
87141281cf3SAxel Dörfler 
87241281cf3SAxel Dörfler /**	from entry_removed message, when attribute removed
87341281cf3SAxel Dörfler  *	or when a device is unmounted (use removeall, by device)
87441281cf3SAxel Dörfler  */
87541281cf3SAxel Dörfler 
87641281cf3SAxel Dörfler void
87741281cf3SAxel Dörfler TReplicantTray::UnloadAddOn(node_ref* nodeRef, dev_t* device,
87841281cf3SAxel Dörfler 	bool which, bool removeAll)
87941281cf3SAxel Dörfler {
88041281cf3SAxel Dörfler 	for (int32 i = fItemList->CountItems(); i-- > 0 ;) {
88141281cf3SAxel Dörfler 		DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i);
88241281cf3SAxel Dörfler 		if (!item)
88341281cf3SAxel Dörfler 			continue;
88441281cf3SAxel Dörfler 
88541281cf3SAxel Dörfler 		if ((which && nodeRef && item->nodeRef == *nodeRef)
88641281cf3SAxel Dörfler 			|| (device && item->nodeRef.device == *device)) {
88741281cf3SAxel Dörfler 
88841281cf3SAxel Dörfler 			if (device && be_roster->IsRunning(&item->entryRef))
88941281cf3SAxel Dörfler 				continue;
89041281cf3SAxel Dörfler 
89141281cf3SAxel Dörfler 			RemoveIcon(item->id);
89241281cf3SAxel Dörfler 
89341281cf3SAxel Dörfler 			if (!removeAll)
89441281cf3SAxel Dörfler 				break;
89541281cf3SAxel Dörfler 		}
89641281cf3SAxel Dörfler 	}
89741281cf3SAxel Dörfler }
89841281cf3SAxel Dörfler 
89941281cf3SAxel Dörfler 
90041281cf3SAxel Dörfler void
90141281cf3SAxel Dörfler TReplicantTray::RemoveItem(int32 id)
90241281cf3SAxel Dörfler {
90341281cf3SAxel Dörfler 	DeskbarItemInfo* item = DeskbarItemFor(id);
90441281cf3SAxel Dörfler 	if (item == NULL)
90541281cf3SAxel Dörfler 		return;
90641281cf3SAxel Dörfler 
90741281cf3SAxel Dörfler 	// attribute was added via Deskbar API (AddItem(entry_ref*, int32*)
90841281cf3SAxel Dörfler 	if (item->isAddOn) {
90941281cf3SAxel Dörfler 		BNode node(&item->entryRef);
91041281cf3SAxel Dörfler 		node.RemoveAttr(kStatusPredicate);
91141281cf3SAxel Dörfler 		watch_node(&item->nodeRef, B_STOP_WATCHING, this, Window());
91241281cf3SAxel Dörfler 	}
91341281cf3SAxel Dörfler 
91441281cf3SAxel Dörfler 	fItemList->RemoveItem(item);
91541281cf3SAxel Dörfler 	delete item;
91641281cf3SAxel Dörfler }
91741281cf3SAxel Dörfler 
91841281cf3SAxel Dörfler 
91941281cf3SAxel Dörfler /**	ENTRY_MOVED message, moving only occurs on a device
92041281cf3SAxel Dörfler  *	copying will occur (ENTRY_CREATED) between devices
92141281cf3SAxel Dörfler  */
92241281cf3SAxel Dörfler 
92341281cf3SAxel Dörfler void
92441281cf3SAxel Dörfler TReplicantTray::MoveItem(entry_ref* ref, ino_t toDirectory)
92541281cf3SAxel Dörfler {
92641281cf3SAxel Dörfler 	if (!ref)
92741281cf3SAxel Dörfler 		return;
92841281cf3SAxel Dörfler 
92941281cf3SAxel Dörfler 	// scan for a matching entry_ref and update it
93041281cf3SAxel Dörfler 	//
93141281cf3SAxel Dörfler 	// don't need to change node info as it does not change
93241281cf3SAxel Dörfler 
93341281cf3SAxel Dörfler 	for (int32 i = fItemList->CountItems(); i-- > 0 ;) {
93441281cf3SAxel Dörfler 		DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i);
93541281cf3SAxel Dörfler 		if (!item)
93641281cf3SAxel Dörfler 			continue;
93741281cf3SAxel Dörfler 
93841281cf3SAxel Dörfler 		if (!strcmp(item->entryRef.name, ref->name)
93941281cf3SAxel Dörfler 			&& item->entryRef.device == ref->device
94041281cf3SAxel Dörfler 			&& item->entryRef.directory == ref->directory) {
94141281cf3SAxel Dörfler 			item->entryRef.directory = toDirectory;
94241281cf3SAxel Dörfler 			break;
94341281cf3SAxel Dörfler 		}
94441281cf3SAxel Dörfler 	}
94541281cf3SAxel Dörfler }
94641281cf3SAxel Dörfler 
94741281cf3SAxel Dörfler #endif	//	add-on support
94841281cf3SAxel Dörfler 
94941281cf3SAxel Dörfler //	external add-on API routines
95041281cf3SAxel Dörfler //	called using the new BDeskbar class
95141281cf3SAxel Dörfler 
95241281cf3SAxel Dörfler //	existence of icon/replicant by name or ID
95341281cf3SAxel Dörfler //	returns opposite
95441281cf3SAxel Dörfler //	note: name and id are semi-private limiting
95541281cf3SAxel Dörfler //		the ability of non-host apps to remove
95641281cf3SAxel Dörfler //		icons without a little bit of work
95741281cf3SAxel Dörfler 
95841281cf3SAxel Dörfler /**	for a specific id
95941281cf3SAxel Dörfler  *	return the name of the replicant (name of view)
96041281cf3SAxel Dörfler  */
96141281cf3SAxel Dörfler 
96241281cf3SAxel Dörfler status_t
96341281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 id, const char** name)
96441281cf3SAxel Dörfler {
96541281cf3SAxel Dörfler 	if (id < 0)
96641281cf3SAxel Dörfler 		return B_ERROR;
96741281cf3SAxel Dörfler 
96841281cf3SAxel Dörfler 	int32 index, temp;
96941281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &temp, id, false);
97041281cf3SAxel Dörfler 	if (view) {
97141281cf3SAxel Dörfler 		*name = view->Name();
97241281cf3SAxel Dörfler 		return B_OK;
97341281cf3SAxel Dörfler 	}
97441281cf3SAxel Dörfler 
97541281cf3SAxel Dörfler 	return B_ERROR;
97641281cf3SAxel Dörfler }
97741281cf3SAxel Dörfler 
97841281cf3SAxel Dörfler 
9797da06231SAxel Dörfler /**	for a specific name
9807da06231SAxel Dörfler  *	return the id (internal to Deskbar)
9817da06231SAxel Dörfler  */
9827da06231SAxel Dörfler 
98341281cf3SAxel Dörfler status_t
98441281cf3SAxel Dörfler TReplicantTray::ItemInfo(const char* name, int32* id)
98541281cf3SAxel Dörfler {
98641281cf3SAxel Dörfler 	if (!name || strlen(name) <= 0)
98741281cf3SAxel Dörfler 		return B_ERROR;
98841281cf3SAxel Dörfler 
98941281cf3SAxel Dörfler 	int32 index;
99041281cf3SAxel Dörfler 	BView* view = ViewAt(&index, id, name);
99141281cf3SAxel Dörfler 	if (view)
99241281cf3SAxel Dörfler 		return B_OK;
99341281cf3SAxel Dörfler 
99441281cf3SAxel Dörfler 	return B_ERROR;
99541281cf3SAxel Dörfler }
99641281cf3SAxel Dörfler 
99741281cf3SAxel Dörfler 
9987da06231SAxel Dörfler /**	at a specific index
9997da06231SAxel Dörfler  *	return both the name and the id of the replicant
10007da06231SAxel Dörfler  */
10017da06231SAxel Dörfler 
100241281cf3SAxel Dörfler status_t
100341281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 index, const char** name, int32* id)
100441281cf3SAxel Dörfler {
100541281cf3SAxel Dörfler 	if (index < 0)
100641281cf3SAxel Dörfler 		return B_ERROR;
100741281cf3SAxel Dörfler 
100841281cf3SAxel Dörfler 	BView* view;
100941281cf3SAxel Dörfler 	fShelf->ReplicantAt(index, &view, (uint32*)id, NULL);
101041281cf3SAxel Dörfler 	if (view) {
101141281cf3SAxel Dörfler 		*name = view->Name();
101241281cf3SAxel Dörfler 		return B_OK;
101341281cf3SAxel Dörfler 	}
101441281cf3SAxel Dörfler 
101541281cf3SAxel Dörfler 	return B_ERROR;
101641281cf3SAxel Dörfler }
101741281cf3SAxel Dörfler 
101841281cf3SAxel Dörfler 
10197da06231SAxel Dörfler /**	replicant exists, by id/index */
10207da06231SAxel Dörfler 
102141281cf3SAxel Dörfler bool
102241281cf3SAxel Dörfler TReplicantTray::IconExists(int32 target, bool byIndex)
102341281cf3SAxel Dörfler {
102441281cf3SAxel Dörfler 	int32 index, id;
102541281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &id, target, byIndex);
102641281cf3SAxel Dörfler 
102741281cf3SAxel Dörfler 	return view && index >= 0;
102841281cf3SAxel Dörfler }
102941281cf3SAxel Dörfler 
103041281cf3SAxel Dörfler 
10317da06231SAxel Dörfler /**	replicant exists, by name */
10327da06231SAxel Dörfler 
103341281cf3SAxel Dörfler bool
103441281cf3SAxel Dörfler TReplicantTray::IconExists(const char* name)
103541281cf3SAxel Dörfler {
103641281cf3SAxel Dörfler 	if (!name || strlen(name) == 0)
103741281cf3SAxel Dörfler 		return false;
103841281cf3SAxel Dörfler 
103941281cf3SAxel Dörfler 	int32 index, id;
104041281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &id, name);
104141281cf3SAxel Dörfler 
104241281cf3SAxel Dörfler 	return view && index >= 0;
104341281cf3SAxel Dörfler }
104441281cf3SAxel Dörfler 
104541281cf3SAxel Dörfler 
104641281cf3SAxel Dörfler int32
104741281cf3SAxel Dörfler TReplicantTray::IconCount() const
104841281cf3SAxel Dörfler {
104941281cf3SAxel Dörfler 	return fShelf->CountReplicants();
105041281cf3SAxel Dörfler }
105141281cf3SAxel Dörfler 
105241281cf3SAxel Dörfler 
1053ced3755cSAxel Dörfler /*!	Message must contain an archivable view for later rehydration.
1054ced3755cSAxel Dörfler 	This function takes over ownership of the provided message on success
1055ced3755cSAxel Dörfler 	only.
1056ced3755cSAxel Dörfler 	Returns the current replicant ID.
10577da06231SAxel Dörfler */
105841281cf3SAxel Dörfler status_t
1059ced3755cSAxel Dörfler TReplicantTray::AddIcon(BMessage* archive, int32* id, const entry_ref* addOn)
106041281cf3SAxel Dörfler {
1061ced3755cSAxel Dörfler 	if (archive == NULL || id == NULL)
106241281cf3SAxel Dörfler 		return B_ERROR;
106341281cf3SAxel Dörfler 
10649c50f36eSAxel Dörfler 	// find entry_ref
10659c50f36eSAxel Dörfler 
10669c50f36eSAxel Dörfler 	entry_ref ref;
10679c50f36eSAxel Dörfler 	if (addOn) {
10689c50f36eSAxel Dörfler 		// Use it if we got it
10699c50f36eSAxel Dörfler 		ref = *addOn;
10709c50f36eSAxel Dörfler 	} else {
10719c50f36eSAxel Dörfler 		const char* signature;
1072ced3755cSAxel Dörfler 		status_t status = archive->FindString("add_on", &signature);
10739c50f36eSAxel Dörfler 		if (status == B_OK) {
10749c50f36eSAxel Dörfler 			BRoster roster;
10759c50f36eSAxel Dörfler 			status = roster.FindApp(signature, &ref);
10769c50f36eSAxel Dörfler 		}
10779c50f36eSAxel Dörfler 		if (status < B_OK)
10789c50f36eSAxel Dörfler 			return status;
10799c50f36eSAxel Dörfler 	}
10809c50f36eSAxel Dörfler 
10819c50f36eSAxel Dörfler 	BFile file;
10829c50f36eSAxel Dörfler 	status_t status = file.SetTo(&ref, B_READ_ONLY);
10839c50f36eSAxel Dörfler 	if (status < B_OK)
10849c50f36eSAxel Dörfler 		return status;
10859c50f36eSAxel Dörfler 
10869c50f36eSAxel Dörfler 	node_ref nodeRef;
10879c50f36eSAxel Dörfler 	status = file.GetNodeRef(&nodeRef);
10889c50f36eSAxel Dörfler 	if (status < B_OK)
10899c50f36eSAxel Dörfler 		return status;
10909c50f36eSAxel Dörfler 
10919c50f36eSAxel Dörfler 	BEntry entry(&ref, true);
10929c50f36eSAxel Dörfler 		// ToDo: this resolves an eventual link for the item
10939c50f36eSAxel Dörfler 		// being added - this is okay for now, but in multi-user
10949c50f36eSAxel Dörfler 		// environments, one might want to have links that
10959c50f36eSAxel Dörfler 		// carry the be:deskbar_item_status attribute
10969c50f36eSAxel Dörfler 	status = entry.InitCheck();
10979c50f36eSAxel Dörfler 	if (status != B_OK)
10989c50f36eSAxel Dörfler 		return status;
10999c50f36eSAxel Dörfler 
110041281cf3SAxel Dörfler 	*id = 999;
1101ced3755cSAxel Dörfler 	if (archive->what == B_ARCHIVED_OBJECT)
1102ced3755cSAxel Dörfler 		archive->what = 0;
110341281cf3SAxel Dörfler 
1104ced3755cSAxel Dörfler 	BRect originalBounds = archive->FindRect("_frame");
1105a5210ab1SAxel Dörfler 		// this is a work-around for buggy replicants that change their
1106a5210ab1SAxel Dörfler 		// size in AttachedToWindow() (such as "SVM")
1107a5210ab1SAxel Dörfler 
110841281cf3SAxel Dörfler 	// !! check for name collisions?
1109ced3755cSAxel Dörfler 	status = fShelf->AddReplicant(archive, BPoint(1, 1));
11109c50f36eSAxel Dörfler 	if (status != B_OK)
11119c50f36eSAxel Dörfler 		return status;
111241281cf3SAxel Dörfler 
1113a5210ab1SAxel Dörfler 	int32 count = fShelf->CountReplicants();
1114a5210ab1SAxel Dörfler 	BView* view;
1115a5210ab1SAxel Dörfler 	fShelf->ReplicantAt(count - 1, &view, (uint32*)id, NULL);
1116a5210ab1SAxel Dörfler 
1117a5210ab1SAxel Dörfler 	if (originalBounds != view->Bounds()) {
1118a5210ab1SAxel Dörfler 		// The replicant changed its size when added to the window, so we need
111971bd3ba5SJonas Sundström 		// to recompute all over again (it's already done once via
112071bd3ba5SJonas Sundström 		// BShelf::AddReplicant() and TReplicantShelf::CanAcceptReplicantView())
1121a5210ab1SAxel Dörfler 		RealignReplicants();
1122a5210ab1SAxel Dörfler 	}
1123a5210ab1SAxel Dörfler 
112441281cf3SAxel Dörfler 	float oldWidth = Bounds().Width();
112541281cf3SAxel Dörfler 	float oldHeight = Bounds().Height();
112641281cf3SAxel Dörfler 	float width, height;
112741281cf3SAxel Dörfler 	GetPreferredSize(&width, &height);
112841281cf3SAxel Dörfler 	if (oldWidth != width || oldHeight != height)
112941281cf3SAxel Dörfler 		AdjustPlacement();
113041281cf3SAxel Dörfler 
113141281cf3SAxel Dörfler 	// add the item to the add-on list
113241281cf3SAxel Dörfler 
113341281cf3SAxel Dörfler 	AddItem(*id, nodeRef, entry, addOn != NULL);
113441281cf3SAxel Dörfler  	return B_OK;
113541281cf3SAxel Dörfler }
113641281cf3SAxel Dörfler 
113741281cf3SAxel Dörfler 
113841281cf3SAxel Dörfler void
113941281cf3SAxel Dörfler TReplicantTray::RemoveIcon(int32 target, bool byIndex)
114041281cf3SAxel Dörfler {
114141281cf3SAxel Dörfler 	if (target < 0)
114241281cf3SAxel Dörfler 		return;
114341281cf3SAxel Dörfler 
114441281cf3SAxel Dörfler 	int32 index, id;
114541281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &id, target, byIndex);
114641281cf3SAxel Dörfler 	if (view && index >= 0) {
11477da06231SAxel Dörfler 		// remove the reference from the item list & the shelf
114841281cf3SAxel Dörfler 		RemoveItem(id);
114941281cf3SAxel Dörfler 		fShelf->DeleteReplicant(index);
11507da06231SAxel Dörfler 
115141281cf3SAxel Dörfler 		// force a placement update,  !! need to fix BShelf
115241281cf3SAxel Dörfler 		RealReplicantAdjustment(index);
115341281cf3SAxel Dörfler 	}
115441281cf3SAxel Dörfler }
115541281cf3SAxel Dörfler 
115641281cf3SAxel Dörfler 
115741281cf3SAxel Dörfler void
115841281cf3SAxel Dörfler TReplicantTray::RemoveIcon(const char* name)
115941281cf3SAxel Dörfler {
116041281cf3SAxel Dörfler 	if (!name || strlen(name) <= 0)
116141281cf3SAxel Dörfler 		return;
116241281cf3SAxel Dörfler 
116341281cf3SAxel Dörfler 	int32 id, index;
116441281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &id, name);
116541281cf3SAxel Dörfler 	if (view && index >= 0) {
11667da06231SAxel Dörfler 		// remove the reference from the item list & shelf
116741281cf3SAxel Dörfler 		RemoveItem(id);
116841281cf3SAxel Dörfler 		fShelf->DeleteReplicant(index);
11697da06231SAxel Dörfler 
117041281cf3SAxel Dörfler 		// force a placement update,  !! need to fix BShelf
117141281cf3SAxel Dörfler 		RealReplicantAdjustment(index);
117241281cf3SAxel Dörfler 	}
117341281cf3SAxel Dörfler }
117441281cf3SAxel Dörfler 
117541281cf3SAxel Dörfler 
117641281cf3SAxel Dörfler void
11777da06231SAxel Dörfler TReplicantTray::RealReplicantAdjustment(int32 startIndex)
117841281cf3SAxel Dörfler {
11797da06231SAxel Dörfler 	if (startIndex < 0)
118041281cf3SAxel Dörfler 		return;
11817da06231SAxel Dörfler 
11827da06231SAxel Dörfler 	if (startIndex == fLastReplicant)
11837da06231SAxel Dörfler 		startIndex = 0;
11847da06231SAxel Dörfler 
118541281cf3SAxel Dörfler 	// reset the locations of all replicants after the one deleted
11867da06231SAxel Dörfler 	RealignReplicants(startIndex);
118741281cf3SAxel Dörfler 
118841281cf3SAxel Dörfler 	float oldWidth = Bounds().Width();
118941281cf3SAxel Dörfler 	float oldHeight = Bounds().Height();
119041281cf3SAxel Dörfler 	float width, height;
119141281cf3SAxel Dörfler 	GetPreferredSize(&width, &height);
119241281cf3SAxel Dörfler 	if (oldWidth != width || oldHeight != height) {
119341281cf3SAxel Dörfler 		// resize view to accomodate the replicants
119441281cf3SAxel Dörfler 		// redraw as necessary
119541281cf3SAxel Dörfler 		AdjustPlacement();
119641281cf3SAxel Dörfler 	}
119741281cf3SAxel Dörfler }
119841281cf3SAxel Dörfler 
119941281cf3SAxel Dörfler 
12007da06231SAxel Dörfler /**	looking for a replicant by id/index
12017da06231SAxel Dörfler  *	return the view and index
12027da06231SAxel Dörfler  */
12037da06231SAxel Dörfler 
120441281cf3SAxel Dörfler BView*
120541281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, int32 target, bool byIndex)
120641281cf3SAxel Dörfler {
120741281cf3SAxel Dörfler 	*index = -1;
120841281cf3SAxel Dörfler 
120941281cf3SAxel Dörfler 	BView* view;
121041281cf3SAxel Dörfler 	if (byIndex) {
121141281cf3SAxel Dörfler 		if (fShelf->ReplicantAt(target, &view, (uint32*)id)) {
121241281cf3SAxel Dörfler 			if (view) {
121341281cf3SAxel Dörfler 				*index = target;
121441281cf3SAxel Dörfler 				return view;
121541281cf3SAxel Dörfler 			}
121641281cf3SAxel Dörfler 		}
121741281cf3SAxel Dörfler 	} else {
121841281cf3SAxel Dörfler 		int32 count = fShelf->CountReplicants()-1;
121941281cf3SAxel Dörfler 		int32 localid;
122041281cf3SAxel Dörfler 		for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) {
122141281cf3SAxel Dörfler 			fShelf->ReplicantAt(repIndex, &view, (uint32*)&localid);
122241281cf3SAxel Dörfler 			if (localid == target && view) {
122341281cf3SAxel Dörfler 				*index = repIndex;
122441281cf3SAxel Dörfler 				*id = localid;
122541281cf3SAxel Dörfler 				return view;
122641281cf3SAxel Dörfler 			}
122741281cf3SAxel Dörfler 		}
122841281cf3SAxel Dörfler 	}
122941281cf3SAxel Dörfler 
123041281cf3SAxel Dörfler 	return NULL;
123141281cf3SAxel Dörfler }
123241281cf3SAxel Dörfler 
123341281cf3SAxel Dörfler 
12347da06231SAxel Dörfler /**	looking for a replicant with a view by name
12357da06231SAxel Dörfler  *	return the view, index and the id of the replicant
12367da06231SAxel Dörfler  */
12377da06231SAxel Dörfler 
123841281cf3SAxel Dörfler BView*
123941281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, const char* name)
124041281cf3SAxel Dörfler {
124141281cf3SAxel Dörfler 	*index = -1;
124241281cf3SAxel Dörfler 	*id = -1;
124341281cf3SAxel Dörfler 
124441281cf3SAxel Dörfler 	BView* view;
124541281cf3SAxel Dörfler 	int32 count = fShelf->CountReplicants()-1;
124641281cf3SAxel Dörfler 	for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) {
124741281cf3SAxel Dörfler 		fShelf->ReplicantAt(repIndex, &view, (uint32*)id);
124841281cf3SAxel Dörfler 		if (view && view->Name() && strcmp(name, view->Name()) == 0) {
124941281cf3SAxel Dörfler 			*index = repIndex;
125041281cf3SAxel Dörfler 			return view;
125141281cf3SAxel Dörfler 		}
125241281cf3SAxel Dörfler 	}
125341281cf3SAxel Dörfler 
125441281cf3SAxel Dörfler 	return NULL;
125541281cf3SAxel Dörfler }
125641281cf3SAxel Dörfler 
125741281cf3SAxel Dörfler 
12587da06231SAxel Dörfler /**	Shelf will call to determine where and if
12597da06231SAxel Dörfler  *	the replicant is to be added
12607da06231SAxel Dörfler  */
12617da06231SAxel Dörfler 
126241281cf3SAxel Dörfler bool
126341281cf3SAxel Dörfler TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage* message)
126441281cf3SAxel Dörfler {
126541281cf3SAxel Dörfler 	if (!message)
126641281cf3SAxel Dörfler 		return false;
126741281cf3SAxel Dörfler 
126841281cf3SAxel Dörfler 	if (replicantFrame.Height() > kMaxReplicantHeight)
126941281cf3SAxel Dörfler 		return false;
127041281cf3SAxel Dörfler 
127141281cf3SAxel Dörfler 	alignment align = B_ALIGN_LEFT;
127241281cf3SAxel Dörfler 	if (fAlignmentSupport && message->HasBool("deskbar:dynamic_align")) {
127341281cf3SAxel Dörfler 		if (!fBarView->Vertical())
127441281cf3SAxel Dörfler 			align = B_ALIGN_RIGHT;
127541281cf3SAxel Dörfler 		else
127641281cf3SAxel Dörfler 			align = fBarView->Left() ? B_ALIGN_LEFT : B_ALIGN_RIGHT;
127741281cf3SAxel Dörfler 	} else if (message->HasInt32("deskbar:align"))
127841281cf3SAxel Dörfler 		message->FindInt32("deskbar:align", (int32*)&align);
127941281cf3SAxel Dörfler 
128041281cf3SAxel Dörfler 	if (message->HasInt32("deskbar:private_align"))
128141281cf3SAxel Dörfler 		message->FindInt32("deskbar:private_align", (int32*)&align);
128241281cf3SAxel Dörfler 	else
128341281cf3SAxel Dörfler 		align = B_ALIGN_LEFT;
128441281cf3SAxel Dörfler 
12857da06231SAxel Dörfler 	BPoint loc = LocationForReplicant(fShelf->CountReplicants(),
12867da06231SAxel Dörfler 		replicantFrame.Width());
128741281cf3SAxel Dörfler 
128841281cf3SAxel Dörfler 	message->AddPoint("_pjp_loc", loc);
128941281cf3SAxel Dörfler 	return true;
129041281cf3SAxel Dörfler }
129141281cf3SAxel Dörfler 
129241281cf3SAxel Dörfler 
129341281cf3SAxel Dörfler /**	based on the previous (index - 1) replicant in the list
129441281cf3SAxel Dörfler  *	calculate where the left point should be for this
129541281cf3SAxel Dörfler  *	replicant.  replicant will flow to the right on its own
129641281cf3SAxel Dörfler  */
129741281cf3SAxel Dörfler 
129841281cf3SAxel Dörfler BPoint
12997da06231SAxel Dörfler TReplicantTray::LocationForReplicant(int32 index, float width)
130041281cf3SAxel Dörfler {
130141281cf3SAxel Dörfler 	BPoint loc(kIconGap + 1, kGutter + 1);
130241281cf3SAxel Dörfler 
13037da06231SAxel Dörfler 	if (fMultiRowMode) {
13047da06231SAxel Dörfler 		// try to find free space in every row
13057da06231SAxel Dörfler 		for (int32 row = 0; ; loc.y += kMaxReplicantHeight + kIconGap, row++) {
13067da06231SAxel Dörfler 			// determine free space in this row
130771bd3ba5SJonas Sundström 			BRect rect(loc.x, loc.y, loc.x + fMinimumTrayWidth - kIconGap - 2.0,
130871bd3ba5SJonas Sundström 				loc.y + kMaxReplicantHeight);
13097da06231SAxel Dörfler 			if (row == 0 && fBarView->ShowingClock())
13107da06231SAxel Dörfler 				rect.right -= fClock->Frame().Width() + kIconGap;
13117da06231SAxel Dörfler 
13127da06231SAxel Dörfler 			for (int32 i = 0; i < index; i++) {
13137da06231SAxel Dörfler 				BView* view = NULL;
13147da06231SAxel Dörfler 				fShelf->ReplicantAt(i, &view);
13157da06231SAxel Dörfler 				if (view == NULL || view->Frame().top != rect.top)
13167da06231SAxel Dörfler 					continue;
13177da06231SAxel Dörfler 
13187da06231SAxel Dörfler 				rect.left = view->Frame().right + kIconGap + 1;
13197da06231SAxel Dörfler 			}
13207da06231SAxel Dörfler 
13217da06231SAxel Dörfler 			if (rect.Width() >= width) {
13227da06231SAxel Dörfler 				// the icon fits in this row
13237da06231SAxel Dörfler 				loc = rect.LeftTop();
13247da06231SAxel Dörfler 				break;
13257da06231SAxel Dörfler 			}
13267da06231SAxel Dörfler 		}
13277da06231SAxel Dörfler 	} else {
132841281cf3SAxel Dörfler 		if (index > 0) {
132941281cf3SAxel Dörfler 			// get the last replicant added for placement reference
133041281cf3SAxel Dörfler 			BView* view = NULL;
13317da06231SAxel Dörfler 			fShelf->ReplicantAt(index - 1, &view);
133241281cf3SAxel Dörfler 			if (view) {
133341281cf3SAxel Dörfler 				// push this rep placement past the last one
133441281cf3SAxel Dörfler 				loc.x = view->Frame().right + kIconGap + 1;
133541281cf3SAxel Dörfler 				loc.y = view->Frame().top;
133641281cf3SAxel Dörfler 			}
133741281cf3SAxel Dörfler 		}
13387da06231SAxel Dörfler 	}
133941281cf3SAxel Dörfler 
134071bd3ba5SJonas Sundström 	if ((loc.y == fRightBottomReplicant.top && loc.x
134171bd3ba5SJonas Sundström 		> fRightBottomReplicant.left) || loc.y > fRightBottomReplicant.top) {
134271bd3ba5SJonas Sundström 		fRightBottomReplicant.Set(loc.x, loc.y, loc.x + width, loc.y
134371bd3ba5SJonas Sundström 		+ kMaxReplicantHeight);
13447da06231SAxel Dörfler 		fLastReplicant = index;
134541281cf3SAxel Dörfler 	}
13467da06231SAxel Dörfler 
134741281cf3SAxel Dörfler 	return loc;
134841281cf3SAxel Dörfler }
134941281cf3SAxel Dörfler 
135041281cf3SAxel Dörfler 
135141281cf3SAxel Dörfler BRect
135241281cf3SAxel Dörfler TReplicantTray::IconFrame(int32 target, bool byIndex)
135341281cf3SAxel Dörfler {
135441281cf3SAxel Dörfler 	int32 index, id;
135541281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &id, target, byIndex);
135641281cf3SAxel Dörfler 	if (view)
135741281cf3SAxel Dörfler 		return view->Frame();
135841281cf3SAxel Dörfler 
135941281cf3SAxel Dörfler 	return BRect(0, 0, 0, 0);
136041281cf3SAxel Dörfler }
136141281cf3SAxel Dörfler 
136241281cf3SAxel Dörfler 
136341281cf3SAxel Dörfler BRect
136441281cf3SAxel Dörfler TReplicantTray::IconFrame(const char* name)
136541281cf3SAxel Dörfler {
136641281cf3SAxel Dörfler 	if (!name)
136741281cf3SAxel Dörfler 		return BRect(0, 0, 0, 0);
136841281cf3SAxel Dörfler 
136941281cf3SAxel Dörfler 	int32 id, index;
137041281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &id, name);
137141281cf3SAxel Dörfler 	if (view)
137241281cf3SAxel Dörfler 		return view->Frame();
137341281cf3SAxel Dörfler 
137441281cf3SAxel Dörfler 	return BRect(0, 0, 0, 0);
137541281cf3SAxel Dörfler }
137641281cf3SAxel Dörfler 
137741281cf3SAxel Dörfler 
13787da06231SAxel Dörfler /**	Scan from the startIndex and reset the location
13797da06231SAxel Dörfler  *	as defined in LocationForReplicant()
138041281cf3SAxel Dörfler  */
138141281cf3SAxel Dörfler 
138241281cf3SAxel Dörfler void
138341281cf3SAxel Dörfler TReplicantTray::RealignReplicants(int32 startIndex)
138441281cf3SAxel Dörfler {
138541281cf3SAxel Dörfler 	if (startIndex < 0)
138641281cf3SAxel Dörfler 		startIndex = 0;
138741281cf3SAxel Dörfler 
138841281cf3SAxel Dörfler 	int32 count = fShelf->CountReplicants();
138941281cf3SAxel Dörfler 	if (count <= 0)
139041281cf3SAxel Dörfler 		return;
139141281cf3SAxel Dörfler 
13927da06231SAxel Dörfler 	if (startIndex == 0)
13937da06231SAxel Dörfler 		fRightBottomReplicant.Set(0, 0, 0, 0);
13947da06231SAxel Dörfler 
139541281cf3SAxel Dörfler 	BView* view = NULL;
139641281cf3SAxel Dörfler 	for (int32 i = startIndex ; i < count ; i++) {
139741281cf3SAxel Dörfler 		fShelf->ReplicantAt(i, &view);
13980bec7100SStefano Ceccherini 		if (view != NULL) {
13997da06231SAxel Dörfler 			BPoint loc = LocationForReplicant(i, view->Frame().Width());
14000bec7100SStefano Ceccherini 			if (view->Frame().LeftTop() != loc)
140141281cf3SAxel Dörfler 				view->MoveTo(loc);
140241281cf3SAxel Dörfler 		}
140341281cf3SAxel Dörfler 	}
140441281cf3SAxel Dörfler }
140541281cf3SAxel Dörfler 
140641281cf3SAxel Dörfler 
140741281cf3SAxel Dörfler void
140841281cf3SAxel Dörfler TReplicantTray::SetMultiRow(bool state)
140941281cf3SAxel Dörfler {
141041281cf3SAxel Dörfler 	fMultiRowMode = state;
141141281cf3SAxel Dörfler 
141241281cf3SAxel Dörfler 	// in multi-row state, we only want the short date
141341281cf3SAxel Dörfler 
141441281cf3SAxel Dörfler 	if (fClock != NULL)
141541281cf3SAxel Dörfler 		fClock->AllowFullDate(!state);
141641281cf3SAxel Dörfler }
141741281cf3SAxel Dörfler 
141841281cf3SAxel Dörfler 
141941281cf3SAxel Dörfler //	#pragma mark -
142041281cf3SAxel Dörfler 
142141281cf3SAxel Dörfler 
1422*ca9acc20SAxel Dörfler /*!	Draggable region that is asynchronous so that dragging does not block
1423*ca9acc20SAxel Dörfler 	other activities.
14247da06231SAxel Dörfler */
142541281cf3SAxel Dörfler TDragRegion::TDragRegion(TBarView* parent, BView* child)
1426*ca9acc20SAxel Dörfler 	:
1427*ca9acc20SAxel Dörfler 	BControl(BRect(0, 0, 0, 0), "", "", NULL, B_FOLLOW_NONE,
142841281cf3SAxel Dörfler 		B_WILL_DRAW | B_FRAME_EVENTS),
142941281cf3SAxel Dörfler 	fBarView(parent),
143041281cf3SAxel Dörfler 	fChild(child),
143141281cf3SAxel Dörfler 	fDragLocation(kAutoPlaceDragRegion)
143241281cf3SAxel Dörfler {
143341281cf3SAxel Dörfler }
143441281cf3SAxel Dörfler 
143541281cf3SAxel Dörfler 
143641281cf3SAxel Dörfler void
143741281cf3SAxel Dörfler TDragRegion::AttachedToWindow()
143841281cf3SAxel Dörfler {
143941281cf3SAxel Dörfler 	BView::AttachedToWindow();
1440cb6afcb1SStephan Aßmus 	if (be_control_look != NULL)
1441cb6afcb1SStephan Aßmus 		SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 1.1));
1442cb6afcb1SStephan Aßmus 	else
144341281cf3SAxel Dörfler 		SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
144441281cf3SAxel Dörfler 	ResizeToPreferred();
144541281cf3SAxel Dörfler }
144641281cf3SAxel Dörfler 
144741281cf3SAxel Dörfler 
144841281cf3SAxel Dörfler void
144941281cf3SAxel Dörfler TDragRegion::GetPreferredSize(float* width, float* height)
145041281cf3SAxel Dörfler {
145141281cf3SAxel Dörfler 	fChild->ResizeToPreferred();
145241281cf3SAxel Dörfler 	*width = fChild->Bounds().Width();
145341281cf3SAxel Dörfler 	*height = fChild->Bounds().Height();
145441281cf3SAxel Dörfler 
145541281cf3SAxel Dörfler 	if (fDragLocation != kNoDragRegion)
145641281cf3SAxel Dörfler 		*width += 7;
145741281cf3SAxel Dörfler 	else
145841281cf3SAxel Dörfler 		*width += 6;
145941281cf3SAxel Dörfler 
146041281cf3SAxel Dörfler 	*height += 3;
146141281cf3SAxel Dörfler }
146241281cf3SAxel Dörfler 
146341281cf3SAxel Dörfler 
146441281cf3SAxel Dörfler void
146541281cf3SAxel Dörfler TDragRegion::FrameMoved(BPoint)
146641281cf3SAxel Dörfler {
1467*ca9acc20SAxel Dörfler 	if (fBarView->Left() && fBarView->Vertical()
1468*ca9acc20SAxel Dörfler 		&& fDragLocation != kNoDragRegion)
146941281cf3SAxel Dörfler 		fChild->MoveTo(5, 2);
147041281cf3SAxel Dörfler 	else
147141281cf3SAxel Dörfler 		fChild->MoveTo(2, 2);
147241281cf3SAxel Dörfler }
147341281cf3SAxel Dörfler 
147441281cf3SAxel Dörfler 
147541281cf3SAxel Dörfler void
147641281cf3SAxel Dörfler TDragRegion::Draw(BRect)
147741281cf3SAxel Dörfler {
1478eaa9af99SStephan Aßmus 	rgb_color menuColor = ViewColor();
147941281cf3SAxel Dörfler 	rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT);
1480cb6afcb1SStephan Aßmus 	rgb_color ldark = tint_color(menuColor, 1.02);
1481cb6afcb1SStephan Aßmus 	rgb_color dark = tint_color(menuColor, B_DARKEN_2_TINT);
148241281cf3SAxel Dörfler 	rgb_color vdark = tint_color(menuColor, B_DARKEN_3_TINT);
148341281cf3SAxel Dörfler 	rgb_color vvdark = tint_color(menuColor, B_DARKEN_4_TINT);
148441281cf3SAxel Dörfler 	rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT);
148541281cf3SAxel Dörfler 
148641281cf3SAxel Dörfler 	BRect frame(Bounds());
148741281cf3SAxel Dörfler 	BeginLineArray(4);
148841281cf3SAxel Dörfler 
1489cb6afcb1SStephan Aßmus 	if (be_control_look != NULL) {
1490cb6afcb1SStephan Aßmus 		if (fBarView->Vertical()) {
1491cb6afcb1SStephan Aßmus 			AddLine(frame.LeftTop(), frame.RightTop(), dark);
1492cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.left, frame.top + 1),
1493cb6afcb1SStephan Aßmus 				BPoint(frame.right, frame.top + 1), ldark);
1494cb6afcb1SStephan Aßmus 			AddLine(frame.LeftBottom(), frame.RightBottom(), hilite);
1495cb6afcb1SStephan Aßmus 		} else if (fBarView->AcrossTop() || fBarView->AcrossBottom()) {
1496cb6afcb1SStephan Aßmus 			AddLine(frame.LeftTop(),
1497cb6afcb1SStephan Aßmus 				BPoint(frame.left, frame.bottom), dark);
1498cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.left + 1, frame.top + 1),
1499cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.top + 1), light);
1500cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.right, frame.top + 2),
1501cb6afcb1SStephan Aßmus 				BPoint(frame.right, frame.bottom), hilite);
1502cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.left + 1, frame.bottom),
1503cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.bottom), hilite);
1504cb6afcb1SStephan Aßmus 		}
1505cb6afcb1SStephan Aßmus 	} else {
150641281cf3SAxel Dörfler 		if (fBarView->Vertical()) {
150741281cf3SAxel Dörfler 			AddLine(frame.LeftTop(), frame.RightTop(), light);
150841281cf3SAxel Dörfler 			AddLine(frame.LeftTop(), frame.LeftBottom(), light);
150941281cf3SAxel Dörfler 			AddLine(frame.RightBottom(), frame.RightTop(), hilite);
151041281cf3SAxel Dörfler 		} else if (fBarView->AcrossTop()) {
1511cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.left, frame.top + 1),
1512cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.top + 1), light);
151341281cf3SAxel Dörfler 			AddLine(frame.RightTop(), frame.RightBottom(), vvdark);
1514cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.right - 1, frame.top + 2),
1515cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.bottom - 1), hilite);
1516cb6afcb1SStephan Aßmus 			AddLine(frame.LeftBottom(),
1517cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.bottom), hilite);
151841281cf3SAxel Dörfler 		} else if (fBarView->AcrossBottom()) {
1519cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.left, frame.top + 1),
1520cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.top + 1), light);
152141281cf3SAxel Dörfler 			AddLine(frame.LeftBottom(), frame.RightBottom(), hilite);
152241281cf3SAxel Dörfler 			AddLine(frame.RightTop(), frame.RightBottom(), vvdark);
1523cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.right - 1, frame.top + 1),
1524cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.bottom - 1), hilite);
1525cb6afcb1SStephan Aßmus 		}
152641281cf3SAxel Dörfler 	}
152741281cf3SAxel Dörfler 
152841281cf3SAxel Dörfler 	EndLineArray();
152941281cf3SAxel Dörfler 
153041281cf3SAxel Dörfler 	if (fDragLocation != kDontDrawDragRegion || fDragLocation != kNoDragRegion)
153141281cf3SAxel Dörfler 		DrawDragRegion();
153241281cf3SAxel Dörfler }
153341281cf3SAxel Dörfler 
153441281cf3SAxel Dörfler 
153541281cf3SAxel Dörfler void
153641281cf3SAxel Dörfler TDragRegion::DrawDragRegion()
153741281cf3SAxel Dörfler {
153841281cf3SAxel Dörfler 	BRect dragRegion(DragRegion());
153941281cf3SAxel Dörfler 
1540cb6afcb1SStephan Aßmus 	rgb_color menuColor = ViewColor();
1541cb6afcb1SStephan Aßmus 	rgb_color menuHilite = menuColor;
154241281cf3SAxel Dörfler 	if (IsTracking()) {
1543cb6afcb1SStephan Aßmus 		// Draw drag region highlighted if tracking mouse
1544cb6afcb1SStephan Aßmus 		menuHilite = tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT);
154541281cf3SAxel Dörfler 		SetHighColor(menuHilite);
154641281cf3SAxel Dörfler 		FillRect(dragRegion);
154741281cf3SAxel Dörfler 	}
1548cb6afcb1SStephan Aßmus 	rgb_color vdark = tint_color(menuHilite, B_DARKEN_3_TINT);
1549cb6afcb1SStephan Aßmus 	rgb_color light = tint_color(menuHilite, B_LIGHTEN_2_TINT);
1550cb6afcb1SStephan Aßmus 
1551cb6afcb1SStephan Aßmus 	BeginLineArray(dragRegion.IntegerHeight());
1552cb6afcb1SStephan Aßmus 	BPoint pt;
1553cb6afcb1SStephan Aßmus 	pt.x = floorf((dragRegion.left + dragRegion.right) / 2 + 0.5) - 1;
1554cb6afcb1SStephan Aßmus 	pt.y = dragRegion.top + 2;
1555cb6afcb1SStephan Aßmus 
155641281cf3SAxel Dörfler 	while (pt.y + 1 <= dragRegion.bottom) {
155741281cf3SAxel Dörfler 		AddLine(pt, pt, vdark);
155841281cf3SAxel Dörfler 		AddLine(pt + BPoint(1, 1), pt + BPoint(1, 1), light);
155941281cf3SAxel Dörfler 
156041281cf3SAxel Dörfler 		pt.y += 3;
156141281cf3SAxel Dörfler 	}
156241281cf3SAxel Dörfler 	EndLineArray();
156341281cf3SAxel Dörfler }
156441281cf3SAxel Dörfler 
156541281cf3SAxel Dörfler 
156641281cf3SAxel Dörfler BRect
156741281cf3SAxel Dörfler TDragRegion::DragRegion() const
156841281cf3SAxel Dörfler {
1569cb6afcb1SStephan Aßmus 	float kTopBottomInset = 2;
1570cb6afcb1SStephan Aßmus 	float kLeftRightInset = 1;
1571cb6afcb1SStephan Aßmus 	float kDragWidth = 3;
1572cb6afcb1SStephan Aßmus 	if (be_control_look != NULL) {
1573cb6afcb1SStephan Aßmus 		kTopBottomInset = 1;
1574cb6afcb1SStephan Aßmus 		kLeftRightInset = 0;
1575cb6afcb1SStephan Aßmus 		kDragWidth = 4;
1576cb6afcb1SStephan Aßmus 	}
1577cb6afcb1SStephan Aßmus 
157841281cf3SAxel Dörfler 	BRect dragRegion(Bounds());
1579cb6afcb1SStephan Aßmus 	dragRegion.top += kTopBottomInset;
1580cb6afcb1SStephan Aßmus 	dragRegion.bottom -= kTopBottomInset;
158141281cf3SAxel Dörfler 
158241281cf3SAxel Dörfler 	bool placeOnLeft = false;
158341281cf3SAxel Dörfler 	if (fDragLocation == kAutoPlaceDragRegion) {
158441281cf3SAxel Dörfler 		if (fBarView->Vertical() && fBarView->Left())
158541281cf3SAxel Dörfler 			placeOnLeft = true;
158641281cf3SAxel Dörfler 		else
158741281cf3SAxel Dörfler 			placeOnLeft = false;
158841281cf3SAxel Dörfler 	} else if (fDragLocation == kDragRegionLeft)
158941281cf3SAxel Dörfler 		placeOnLeft = true;
159041281cf3SAxel Dörfler 	else if (fDragLocation == kDragRegionRight)
159141281cf3SAxel Dörfler 		placeOnLeft = false;
159241281cf3SAxel Dörfler 
159341281cf3SAxel Dörfler 	if (placeOnLeft) {
1594cb6afcb1SStephan Aßmus 		dragRegion.left += kLeftRightInset;
1595cb6afcb1SStephan Aßmus 		dragRegion.right = dragRegion.left + kDragWidth;
159641281cf3SAxel Dörfler 	} else {
1597cb6afcb1SStephan Aßmus 		dragRegion.right -= kLeftRightInset;
1598cb6afcb1SStephan Aßmus 		dragRegion.left = dragRegion.right - kDragWidth;
159941281cf3SAxel Dörfler 	}
160041281cf3SAxel Dörfler 
160141281cf3SAxel Dörfler 	return dragRegion;
160241281cf3SAxel Dörfler }
160341281cf3SAxel Dörfler 
160441281cf3SAxel Dörfler 
160541281cf3SAxel Dörfler void
160641281cf3SAxel Dörfler TDragRegion::MouseDown(BPoint thePoint)
160741281cf3SAxel Dörfler {
160841281cf3SAxel Dörfler 	ulong buttons;
160941281cf3SAxel Dörfler 	BPoint where;
161041281cf3SAxel Dörfler 	BRect dragRegion(DragRegion());
161141281cf3SAxel Dörfler 
16127da06231SAxel Dörfler 	dragRegion.InsetBy(-2.0f, -2.0f);
16137da06231SAxel Dörfler 		// DragRegion() is designed for drawing, not clicking
161441281cf3SAxel Dörfler 
161541281cf3SAxel Dörfler 	if (!dragRegion.Contains(thePoint))
161641281cf3SAxel Dörfler 		return;
161741281cf3SAxel Dörfler 
161841281cf3SAxel Dörfler 	while (true) {
161941281cf3SAxel Dörfler 		GetMouse(&where, &buttons);
162041281cf3SAxel Dörfler 		if (!buttons)
162141281cf3SAxel Dörfler 			break;
162241281cf3SAxel Dörfler 
162341281cf3SAxel Dörfler 		if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) != 0) {
162441281cf3SAxel Dörfler 			fPreviousPosition = thePoint;
162541281cf3SAxel Dörfler 			SetTracking(true);
162641281cf3SAxel Dörfler 			SetMouseEventMask(B_POINTER_EVENTS,
162741281cf3SAxel Dörfler 				B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS);
162841281cf3SAxel Dörfler 			Invalidate(DragRegion());
162941281cf3SAxel Dörfler 			break;
163041281cf3SAxel Dörfler 		}
163141281cf3SAxel Dörfler 
163241281cf3SAxel Dörfler 		snooze(25000);
163341281cf3SAxel Dörfler 	}
163441281cf3SAxel Dörfler }
163541281cf3SAxel Dörfler 
163641281cf3SAxel Dörfler 
163741281cf3SAxel Dörfler void
163841281cf3SAxel Dörfler TDragRegion::MouseUp(BPoint pt)
163941281cf3SAxel Dörfler {
164041281cf3SAxel Dörfler 	if (IsTracking()) {
164141281cf3SAxel Dörfler 		SetTracking(false);
164241281cf3SAxel Dörfler 		Invalidate(DragRegion());
164341281cf3SAxel Dörfler 	} else
164441281cf3SAxel Dörfler 		BControl::MouseUp(pt);
164541281cf3SAxel Dörfler }
164641281cf3SAxel Dörfler 
164741281cf3SAxel Dörfler 
164841281cf3SAxel Dörfler bool
164941281cf3SAxel Dörfler TDragRegion::SwitchModeForRect(BPoint mouse, BRect rect,
165041281cf3SAxel Dörfler 	bool newVertical, bool newLeft, bool newTop, int32 newState)
165141281cf3SAxel Dörfler {
165241281cf3SAxel Dörfler 	if (!rect.Contains(mouse))
165341281cf3SAxel Dörfler 		// not our rect
165441281cf3SAxel Dörfler 		return false;
165541281cf3SAxel Dörfler 
165641281cf3SAxel Dörfler 	if (newVertical == fBarView->Vertical()
165741281cf3SAxel Dörfler 		&& newLeft == fBarView->Left()
165841281cf3SAxel Dörfler 		&& newTop == fBarView->Top()
165941281cf3SAxel Dörfler 		&& newState == fBarView->State())
166041281cf3SAxel Dörfler 		// already in the correct mode
166141281cf3SAxel Dörfler 		return true;
166241281cf3SAxel Dörfler 
166341281cf3SAxel Dörfler 	fBarView->ChangeState(newState, newVertical, newLeft, newTop);
166441281cf3SAxel Dörfler 	return true;
166541281cf3SAxel Dörfler }
166641281cf3SAxel Dörfler 
166741281cf3SAxel Dörfler 
166841281cf3SAxel Dörfler void
166941281cf3SAxel Dörfler TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage* message)
167041281cf3SAxel Dörfler {
167141281cf3SAxel Dörfler 	if (IsTracking()) {
167241281cf3SAxel Dörfler 		BScreen screen;
167341281cf3SAxel Dörfler 		BRect frame = screen.Frame();
167441281cf3SAxel Dörfler 
167541281cf3SAxel Dörfler 		float hDivider = frame.Width() / 6;
167671bd3ba5SJonas Sundström 		hDivider = (hDivider < sMinimumWindowWidth + 10.0f)
167771bd3ba5SJonas Sundström 			? sMinimumWindowWidth + 10.0f : hDivider;
167841281cf3SAxel Dörfler 		float miniDivider = frame.top + kMiniHeight + 10.0f;
167941281cf3SAxel Dörfler 		float vDivider = frame.Height() / 2;
168041281cf3SAxel Dörfler #ifdef FULL_MODE
168141281cf3SAxel Dörfler 		float thirdScreen = frame.Height() / 3;
168241281cf3SAxel Dörfler #endif
168371bd3ba5SJonas Sundström 		BRect topLeft(frame.left, frame.top, frame.left + hDivider,
168471bd3ba5SJonas Sundström 			miniDivider);
168571bd3ba5SJonas Sundström 		BRect topMiddle(frame.left + hDivider, frame.top, frame.right
168671bd3ba5SJonas Sundström 			- hDivider, vDivider);
168771bd3ba5SJonas Sundström 		BRect topRight(frame.right - hDivider, frame.top, frame.right,
168871bd3ba5SJonas Sundström 			miniDivider);
168941281cf3SAxel Dörfler 
169041281cf3SAxel Dörfler #ifdef FULL_MODE
169141281cf3SAxel Dörfler 		vDivider = miniDivider + thirdScreen;
169241281cf3SAxel Dörfler #endif
169371bd3ba5SJonas Sundström 		BRect middleLeft(frame.left, miniDivider, frame.left + hDivider,
169471bd3ba5SJonas Sundström 			vDivider);
169571bd3ba5SJonas Sundström 		BRect middleRight(frame.right - hDivider, miniDivider, frame.right,
169671bd3ba5SJonas Sundström 			vDivider);
169741281cf3SAxel Dörfler 
169841281cf3SAxel Dörfler #ifdef FULL_MODE
169971bd3ba5SJonas Sundström 		BRect leftSide(frame.left, vDivider, frame.left + hDivider,
170071bd3ba5SJonas Sundström 			frame.bottom - thirdScreen);
170171bd3ba5SJonas Sundström 		BRect rightSide(frame.right - hDivider, vDivider, frame.right,
170271bd3ba5SJonas Sundström 			frame.bottom - thirdScreen);
170341281cf3SAxel Dörfler 
170441281cf3SAxel Dörfler 		vDivider = frame.bottom - thirdScreen;
170541281cf3SAxel Dörfler #endif
170671bd3ba5SJonas Sundström 		BRect bottomLeft(frame.left, vDivider, frame.left + hDivider,
170771bd3ba5SJonas Sundström 			frame.bottom);
170871bd3ba5SJonas Sundström 		BRect bottomMiddle(frame.left + hDivider, vDivider, frame.right
170971bd3ba5SJonas Sundström 			- hDivider, frame.bottom);
171071bd3ba5SJonas Sundström 		BRect bottomRight(frame.right - hDivider, vDivider, frame.right,
171171bd3ba5SJonas Sundström 			frame.bottom);
171241281cf3SAxel Dörfler 
171341281cf3SAxel Dörfler 		if (where != fPreviousPosition) {
171441281cf3SAxel Dörfler 			fPreviousPosition = where;
171541281cf3SAxel Dörfler 			ConvertToScreen(&where);
171641281cf3SAxel Dörfler 
171741281cf3SAxel Dörfler 			// use short circuit evaluation for convenience
171841281cf3SAxel Dörfler 			if (SwitchModeForRect(where, topLeft, true, true, true, kMiniState)
171971bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, topMiddle, false, true, true,
172071bd3ba5SJonas Sundström 					kExpandoState)
172171bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, topRight, true, false, true,
172271bd3ba5SJonas Sundström 					kMiniState)
172371bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, middleLeft, true, true, true,
172471bd3ba5SJonas Sundström 					kExpandoState)
172571bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, middleRight, true, false, true,
172671bd3ba5SJonas Sundström 					kExpandoState)
172741281cf3SAxel Dörfler 
172841281cf3SAxel Dörfler #ifdef FULL_MODE
172971bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, leftSide, true, true, true,
173071bd3ba5SJonas Sundström 					kFullState)
173171bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, rightSide, true, false, true,
173271bd3ba5SJonas Sundström 					kFullState)
173341281cf3SAxel Dörfler #endif
173471bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, bottomLeft, true, true, false,
173571bd3ba5SJonas Sundström 					kMiniState)
173671bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, bottomMiddle, false, true, false,
173771bd3ba5SJonas Sundström 					kExpandoState)
173871bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, bottomRight, true, false, false,
173971bd3ba5SJonas Sundström 					kMiniState))
174041281cf3SAxel Dörfler 				;
174141281cf3SAxel Dörfler 		}
174241281cf3SAxel Dörfler 	} else
174341281cf3SAxel Dörfler 		BControl::MouseMoved(where, code, message);
174441281cf3SAxel Dörfler }
174541281cf3SAxel Dörfler 
174641281cf3SAxel Dörfler 
174741281cf3SAxel Dörfler int32
174841281cf3SAxel Dörfler TDragRegion::DragRegionLocation() const
174941281cf3SAxel Dörfler {
175041281cf3SAxel Dörfler 	return fDragLocation;
175141281cf3SAxel Dörfler }
175241281cf3SAxel Dörfler 
175341281cf3SAxel Dörfler 
175441281cf3SAxel Dörfler void
175541281cf3SAxel Dörfler TDragRegion::SetDragRegionLocation(int32 location)
175641281cf3SAxel Dörfler {
175741281cf3SAxel Dörfler 	if (location == fDragLocation)
175841281cf3SAxel Dörfler 		return;
175941281cf3SAxel Dörfler 
176041281cf3SAxel Dörfler 	fDragLocation = location;
176141281cf3SAxel Dörfler 	Invalidate();
176241281cf3SAxel Dörfler }
176341281cf3SAxel Dörfler 
1764