xref: /haiku/src/apps/deskbar/StatusView.cpp (revision 8aab28f19b8361c9eebdd81c7ae645ba3d10096e)
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 
291ad8c760SFredrik Holmqvist Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered
301ad8c760SFredrik Holmqvist trademarks of Be Incorporated in the United States and other countries. Other
311ad8c760SFredrik Holmqvist brand product names are registered trademarks or trademarks of their respective
321ad8c760SFredrik Holmqvist holders.
3341281cf3SAxel Dörfler All rights reserved.
3441281cf3SAxel Dörfler */
3541281cf3SAxel Dörfler 
3641281cf3SAxel Dörfler #include <Debug.h>
3741281cf3SAxel Dörfler 
3841281cf3SAxel Dörfler #include <errno.h>
3941281cf3SAxel Dörfler #include <stdio.h>
4041281cf3SAxel Dörfler #include <string.h>
4141281cf3SAxel Dörfler #include <time.h>
4241281cf3SAxel Dörfler #include <unistd.h>
4341281cf3SAxel Dörfler #include <algorithm>
4441281cf3SAxel Dörfler 
4541281cf3SAxel Dörfler #include <fs_index.h>
4641281cf3SAxel Dörfler #include <fs_info.h>
4741281cf3SAxel Dörfler 
4841281cf3SAxel Dörfler #include <Application.h>
4941281cf3SAxel Dörfler #include <Beep.h>
50cb6afcb1SStephan Aßmus #include <Bitmap.h>
51ae7a6e3aSAdrien Destugues #include <Catalog.h>
52cb6afcb1SStephan Aßmus #include <ControlLook.h>
5341281cf3SAxel Dörfler #include <Directory.h>
5441281cf3SAxel Dörfler #include <FindDirectory.h>
55ae7a6e3aSAdrien Destugues #include <Locale.h>
5641281cf3SAxel Dörfler #include <MenuItem.h>
5741281cf3SAxel Dörfler #include <NodeInfo.h>
5841281cf3SAxel Dörfler #include <NodeMonitor.h>
5941281cf3SAxel Dörfler #include <Path.h>
6041281cf3SAxel Dörfler #include <PopUpMenu.h>
6141281cf3SAxel Dörfler #include <Roster.h>
6241281cf3SAxel Dörfler #include <Screen.h>
6341281cf3SAxel Dörfler #include <Volume.h>
6441281cf3SAxel Dörfler #include <VolumeRoster.h>
6541281cf3SAxel Dörfler #include <Window.h>
6641281cf3SAxel Dörfler 
67cb6afcb1SStephan Aßmus #include "icons_logo.h"
68cb6afcb1SStephan Aßmus #include "BarApp.h"
6941281cf3SAxel Dörfler #include "DeskBarUtils.h"
70cb6afcb1SStephan Aßmus #include "ResourceSet.h"
7141281cf3SAxel Dörfler #include "StatusView.h"
7241281cf3SAxel Dörfler #include "StatusViewShelf.h"
7341281cf3SAxel Dörfler #include "TimeView.h"
7441281cf3SAxel Dörfler 
756d01b66dSAxel Dörfler using std::max;
7641281cf3SAxel Dörfler 
7741281cf3SAxel Dörfler #ifdef DB_ADDONS
7841281cf3SAxel Dörfler // Add-on support
7941281cf3SAxel Dörfler //
8041281cf3SAxel Dörfler // Item - internal item list (node, eref, etc)
8141281cf3SAxel Dörfler // Icon - physical replicant handed to the DeskbarClass class
8241281cf3SAxel Dörfler // AddOn - attribute based add-on
8341281cf3SAxel Dörfler 
8441281cf3SAxel Dörfler const char* const kInstantiateItemCFunctionName = "instantiate_deskbar_item";
8541281cf3SAxel Dörfler const char* const kInstantiateEntryCFunctionName = "instantiate_deskbar_entry";
863e6ff860SRene Gollent const char* const kReplicantSettingsFile = "Deskbar_replicants";
87c0ad1c91SRene Gollent const char* const kReplicantPathField = "replicant_path";
8841281cf3SAxel Dörfler 
89cb6afcb1SStephan Aßmus float sMinimumWindowWidth = kGutter + kMinimumTrayWidth + kDragRegionWidth;
90cb6afcb1SStephan Aßmus 
9141281cf3SAxel Dörfler 
9241281cf3SAxel Dörfler static void
9341281cf3SAxel Dörfler DumpItem(DeskbarItemInfo* item)
9441281cf3SAxel Dörfler {
9541281cf3SAxel Dörfler 	printf("is addon: %i, id: %li\n", item->isAddOn, item->id);
9666eba86fSAxel Dörfler 	printf("entry_ref:  %ld, %Ld, %s\n", item->entryRef.device,
9766eba86fSAxel Dörfler 		item->entryRef.directory, item->entryRef.name);
9841281cf3SAxel Dörfler 	printf("node_ref:  %ld, %Ld\n", item->nodeRef.device, item->nodeRef.node);
9941281cf3SAxel Dörfler }
10041281cf3SAxel Dörfler 
10141281cf3SAxel Dörfler 
10241281cf3SAxel Dörfler static void
10341281cf3SAxel Dörfler DumpList(BList* itemlist)
10441281cf3SAxel Dörfler {
10541281cf3SAxel Dörfler 	int32 count = itemlist->CountItems() - 1;
10641281cf3SAxel Dörfler 	if (count < 0) {
10741281cf3SAxel Dörfler 		printf("no items in list\n");
10841281cf3SAxel Dörfler 		return;
10941281cf3SAxel Dörfler 	}
11041281cf3SAxel Dörfler 	for (int32 i = count ; i >= 0 ; i--) {
11141281cf3SAxel Dörfler 		DeskbarItemInfo* item = (DeskbarItemInfo*)itemlist->ItemAt(i);
11241281cf3SAxel Dörfler 		if (!item)
11341281cf3SAxel Dörfler 			continue;
11441281cf3SAxel Dörfler 
11541281cf3SAxel Dörfler 		DumpItem(item);
11641281cf3SAxel Dörfler 	}
11741281cf3SAxel Dörfler }
11841281cf3SAxel Dörfler #endif	/* DB_ADDONS */
11941281cf3SAxel Dörfler 
12041281cf3SAxel Dörfler 
1214eb0cbb0SMatt Madia #undef B_TRANSLATE_CONTEXT
1224eb0cbb0SMatt Madia #define B_TRANSLATE_CONTEXT "Tray"
123ae7a6e3aSAdrien Destugues 
1247da06231SAxel Dörfler // don't change the name of this view to anything other than "Status"!
1257da06231SAxel Dörfler 
12641281cf3SAxel Dörfler TReplicantTray::TReplicantTray(TBarView* parent, bool vertical)
12741281cf3SAxel Dörfler 	: BView(BRect(0, 0, 1, 1), "Status", B_FOLLOW_LEFT | B_FOLLOW_TOP,
12841281cf3SAxel Dörfler 			B_WILL_DRAW | B_FRAME_EVENTS),
12941281cf3SAxel Dörfler 	fClock(NULL),
13041281cf3SAxel Dörfler 	fBarView(parent),
13141281cf3SAxel Dörfler 	fShelf(new TReplicantShelf(this)),
13241281cf3SAxel Dörfler 	fMultiRowMode(vertical),
133cb6afcb1SStephan Aßmus 	fMinimumTrayWidth(kMinimumTrayWidth),
13441281cf3SAxel Dörfler 	fAlignmentSupport(false)
13541281cf3SAxel Dörfler {
136cb6afcb1SStephan Aßmus 	// init the minimum window width according to the logo.
137cb6afcb1SStephan Aßmus 	const BBitmap* logoBitmap = AppResSet()->FindBitmap(B_MESSAGE_TYPE,
1389e8a970bSJonas Sundström 		R_LeafLogoBitmap);
139cb6afcb1SStephan Aßmus 	if (logoBitmap != NULL) {
140cb6afcb1SStephan Aßmus 		sMinimumWindowWidth = max_c(sMinimumWindowWidth,
141cb6afcb1SStephan Aßmus 			2 * (logoBitmap->Bounds().Width() + 8));
142cb6afcb1SStephan Aßmus 		fMinimumTrayWidth = sMinimumWindowWidth - kGutter - kDragRegionWidth;
143cb6afcb1SStephan Aßmus 	}
14441281cf3SAxel Dörfler }
14541281cf3SAxel Dörfler 
14641281cf3SAxel Dörfler 
14741281cf3SAxel Dörfler TReplicantTray::~TReplicantTray()
14841281cf3SAxel Dörfler {
14941281cf3SAxel Dörfler 	delete fShelf;
15041281cf3SAxel Dörfler }
15141281cf3SAxel Dörfler 
15241281cf3SAxel Dörfler 
15341281cf3SAxel Dörfler void
15441281cf3SAxel Dörfler TReplicantTray::AttachedToWindow()
15541281cf3SAxel Dörfler {
15641281cf3SAxel Dörfler 	BView::AttachedToWindow();
15741281cf3SAxel Dörfler 
158cb6afcb1SStephan Aßmus 	if (be_control_look != NULL) {
159cb6afcb1SStephan Aßmus 		SetViewColor(Parent()->ViewColor());
160cb6afcb1SStephan Aßmus 	} else {
16166eba86fSAxel Dörfler 		SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
16266eba86fSAxel Dörfler 			B_DARKEN_1_TINT));
163cb6afcb1SStephan Aßmus 	}
16441281cf3SAxel Dörfler 	SetDrawingMode(B_OP_COPY);
16566eba86fSAxel Dörfler 
16641281cf3SAxel Dörfler 	Window()->SetPulseRate(1000000);
16741281cf3SAxel Dörfler 	DealWithClock(fBarView->ShowingClock());
16841281cf3SAxel Dörfler 
169ae7a6e3aSAdrien Destugues 
17041281cf3SAxel Dörfler #ifdef DB_ADDONS
17141281cf3SAxel Dörfler 	// load addons and rehydrate archives
1723a6add49SAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST)
17341281cf3SAxel Dörfler 	InitAddOnSupport();
17441281cf3SAxel Dörfler #endif
1759c910f9eSStephan Aßmus #endif
17641281cf3SAxel Dörfler 	ResizeToPreferred();
17741281cf3SAxel Dörfler }
17841281cf3SAxel Dörfler 
17941281cf3SAxel Dörfler 
18041281cf3SAxel Dörfler void
18141281cf3SAxel Dörfler TReplicantTray::DetachedFromWindow()
18241281cf3SAxel Dörfler {
18341281cf3SAxel Dörfler #ifdef DB_ADDONS
18441281cf3SAxel Dörfler 	// clean up add-on support
185465b54cdSAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST)
18641281cf3SAxel Dörfler 	DeleteAddOnSupport();
18741281cf3SAxel Dörfler #endif
188465b54cdSAxel Dörfler #endif
18941281cf3SAxel Dörfler 	BView::DetachedFromWindow();
19041281cf3SAxel Dörfler }
19141281cf3SAxel Dörfler 
19241281cf3SAxel Dörfler 
19341281cf3SAxel Dörfler void
19441281cf3SAxel Dörfler TReplicantTray::RememberClockSettings()
19541281cf3SAxel Dörfler {
19641281cf3SAxel Dörfler 	if (fClock)	{
19741281cf3SAxel Dörfler 		desk_settings* settings = ((TBarApp*)be_app)->Settings();
19841281cf3SAxel Dörfler 
19941281cf3SAxel Dörfler 		settings->timeShowSeconds = fClock->ShowingSeconds();
20041281cf3SAxel Dörfler 	}
20141281cf3SAxel Dörfler }
20241281cf3SAxel Dörfler 
20341281cf3SAxel Dörfler 
20441281cf3SAxel Dörfler bool
20541281cf3SAxel Dörfler TReplicantTray::ShowingSeconds()
20641281cf3SAxel Dörfler {
20741281cf3SAxel Dörfler 	if (fClock)
20841281cf3SAxel Dörfler 		return fClock->ShowingSeconds();
20941281cf3SAxel Dörfler 	return false;
21041281cf3SAxel Dörfler }
21141281cf3SAxel Dörfler 
21241281cf3SAxel Dörfler 
21341281cf3SAxel Dörfler void
21441281cf3SAxel Dörfler TReplicantTray::DealWithClock(bool showClock)
21541281cf3SAxel Dörfler {
21641281cf3SAxel Dörfler 	fBarView->ShowClock(showClock);
21741281cf3SAxel Dörfler 
21841281cf3SAxel Dörfler 	if (showClock) {
21941281cf3SAxel Dörfler 		if (!fClock) {
22041281cf3SAxel Dörfler 			desk_settings* settings = ((TBarApp*)be_app)->Settings();
22141281cf3SAxel Dörfler 
222cb6afcb1SStephan Aßmus 			fClock = new TTimeView(fMinimumTrayWidth, kMaxReplicantHeight - 1.0,
2239e9c8091SRene Gollent 				settings->timeShowSeconds,
2242f0eb7b1SAdrien Destugues 				false);
22541281cf3SAxel Dörfler 			AddChild(fClock);
22641281cf3SAxel Dörfler 
22741281cf3SAxel Dörfler 			fClock->MoveTo(Bounds().right - fClock->Bounds().Width() - 1, 2);
22841281cf3SAxel Dörfler 		}
22941281cf3SAxel Dörfler 	} else {
23041281cf3SAxel Dörfler 		if (fClock) {
23141281cf3SAxel Dörfler 			RememberClockSettings();
23241281cf3SAxel Dörfler 
23341281cf3SAxel Dörfler 			fClock->RemoveSelf();
23441281cf3SAxel Dörfler 			delete fClock;
23541281cf3SAxel Dörfler 			fClock = NULL;
23641281cf3SAxel Dörfler 		}
23741281cf3SAxel Dörfler 	}
23841281cf3SAxel Dörfler }
23941281cf3SAxel Dörfler 
24041281cf3SAxel Dörfler 
2411ad8c760SFredrik Holmqvist /*! Width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth
24266eba86fSAxel Dörfler 	if not in multirowmode and greater than kMinimumReplicantCount
24366eba86fSAxel Dörfler 	the width should be calculated based on the actual
24466eba86fSAxel Dörfler 	replicant widths
24541281cf3SAxel Dörfler */
24641281cf3SAxel Dörfler void
24741281cf3SAxel Dörfler TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight)
24841281cf3SAxel Dörfler {
24941281cf3SAxel Dörfler 	float width = 0, height = kMinimumTrayHeight;
25041281cf3SAxel Dörfler 
25141281cf3SAxel Dörfler 	if (fMultiRowMode) {
2527da06231SAxel Dörfler 		if (fShelf->CountReplicants() > 0)
2537da06231SAxel Dörfler 			height = fRightBottomReplicant.bottom;
25441281cf3SAxel Dörfler 
2551ad8c760SFredrik Holmqvist 		// the height will be uniform for the number of rows necessary to show
2561ad8c760SFredrik Holmqvist 		// all the reps + any gutters necessary for spacing
25741281cf3SAxel Dörfler 		int32 rowCount = (int32)(height / kMaxReplicantHeight);
25841281cf3SAxel Dörfler 		height = kGutter + (rowCount * kMaxReplicantHeight)
25941281cf3SAxel Dörfler 			+ ((rowCount - 1) * kIconGap) + kGutter;
26041281cf3SAxel Dörfler 		height = max(kMinimumTrayHeight, height);
261cb6afcb1SStephan Aßmus 		width = fMinimumTrayWidth;
26241281cf3SAxel Dörfler 	} else {
2631ad8c760SFredrik Holmqvist 		// if last replicant overruns clock then resize to accomodate
2647da06231SAxel Dörfler 		if (fShelf->CountReplicants() > 0) {
26541281cf3SAxel Dörfler 			if (fBarView->ShowingClock()
2667da06231SAxel Dörfler 				&& fRightBottomReplicant.right + 6 >= fClock->Frame().left) {
26766eba86fSAxel Dörfler 				width = fRightBottomReplicant.right + 6
26866eba86fSAxel Dörfler 					+ fClock->Frame().Width();
26941281cf3SAxel Dörfler 			} else
2707da06231SAxel Dörfler 				width = fRightBottomReplicant.right + 3;
27141281cf3SAxel Dörfler 		}
2721ad8c760SFredrik Holmqvist 
27341281cf3SAxel Dörfler 		// this view has a fixed minimum width
274cb6afcb1SStephan Aßmus 		width = max(fMinimumTrayWidth, width);
27541281cf3SAxel Dörfler 	}
27641281cf3SAxel Dörfler 
27741281cf3SAxel Dörfler 	*preferredWidth = width;
2781ad8c760SFredrik Holmqvist 	// add 1 for the border
27941281cf3SAxel Dörfler 	*preferredHeight = height + 1;
28041281cf3SAxel Dörfler }
28141281cf3SAxel Dörfler 
28241281cf3SAxel Dörfler 
28341281cf3SAxel Dörfler void
28441281cf3SAxel Dörfler TReplicantTray::AdjustPlacement()
28541281cf3SAxel Dörfler {
28641281cf3SAxel Dörfler 	// called when an add-on has been added or removed
28741281cf3SAxel Dörfler 	// need to resize the parent of this accordingly
288a5210ab1SAxel Dörfler 
28941281cf3SAxel Dörfler 	BRect bounds = Bounds();
29041281cf3SAxel Dörfler 	float width, height;
29141281cf3SAxel Dörfler 	GetPreferredSize(&width, &height);
29241281cf3SAxel Dörfler 
29341281cf3SAxel Dörfler 	if (width == bounds.Width() && height == bounds.Height()) {
29441281cf3SAxel Dörfler 		// no need to change anything
29541281cf3SAxel Dörfler 		return;
29641281cf3SAxel Dörfler 	}
29741281cf3SAxel Dörfler 
29841281cf3SAxel Dörfler 	Parent()->ResizeToPreferred();
29941281cf3SAxel Dörfler 	fBarView->UpdatePlacement();
30041281cf3SAxel Dörfler 	Parent()->Invalidate();
30141281cf3SAxel Dörfler 	Invalidate();
30241281cf3SAxel Dörfler }
30341281cf3SAxel Dörfler 
30441281cf3SAxel Dörfler 
30541281cf3SAxel Dörfler void
30641281cf3SAxel Dörfler TReplicantTray::MessageReceived(BMessage* message)
30741281cf3SAxel Dörfler {
30841281cf3SAxel Dörfler 	switch (message->what) {
30941281cf3SAxel Dörfler 		case 'time':
31041281cf3SAxel Dörfler 			// from context menu in clock and in this view
31141281cf3SAxel Dörfler 			DealWithClock(!fBarView->ShowingClock());
31241281cf3SAxel Dörfler 			RealignReplicants();
31341281cf3SAxel Dörfler 			AdjustPlacement();
31441281cf3SAxel Dörfler 			break;
31541281cf3SAxel Dörfler 
316a5210ab1SAxel Dörfler 		case 'Trfm':
31741281cf3SAxel Dörfler 			// time string reformat -> realign
31841281cf3SAxel Dörfler 			DealWithClock(fBarView->ShowingClock());
31941281cf3SAxel Dörfler 			RealignReplicants();
32041281cf3SAxel Dörfler 			AdjustPlacement();
32141281cf3SAxel Dörfler 			break;
32241281cf3SAxel Dörfler 
32371bd3ba5SJonas Sundström 		case kShowSeconds:
32471bd3ba5SJonas Sundström 		case kFullDate:
32541281cf3SAxel Dörfler 			if (fClock != NULL)
32641281cf3SAxel Dörfler 				Window()->PostMessage(message, fClock);
32741281cf3SAxel Dörfler 			break;
32841281cf3SAxel Dörfler 
32941281cf3SAxel Dörfler #ifdef DB_ADDONS
33041281cf3SAxel Dörfler 		case B_NODE_MONITOR:
33141281cf3SAxel Dörfler 			HandleEntryUpdate(message);
33241281cf3SAxel Dörfler 			break;
33341281cf3SAxel Dörfler #endif
33441281cf3SAxel Dörfler 
33541281cf3SAxel Dörfler 		default:
33641281cf3SAxel Dörfler 			BView::MessageReceived(message);
33741281cf3SAxel Dörfler 			break;
33841281cf3SAxel Dörfler 	}
33941281cf3SAxel Dörfler }
34041281cf3SAxel Dörfler 
34141281cf3SAxel Dörfler 
34241281cf3SAxel Dörfler void
34341281cf3SAxel Dörfler TReplicantTray::ShowReplicantMenu(BPoint point)
34441281cf3SAxel Dörfler {
34541281cf3SAxel Dörfler 	BPopUpMenu* menu = new BPopUpMenu("", false, false);
34641281cf3SAxel Dörfler 	menu->SetFont(be_plain_font);
34741281cf3SAxel Dörfler 
3481ad8c760SFredrik Holmqvist 	// If clock is visible show the extended menu, otherwise show "Show Time"
34941281cf3SAxel Dörfler 
35041281cf3SAxel Dörfler 	if (fBarView->ShowingClock())
35141281cf3SAxel Dörfler 		fClock->ShowClockOptions(ConvertToScreen(point));
35241281cf3SAxel Dörfler 	else {
35361863f2cSMatt Madia 		BMenuItem* item = new BMenuItem(B_TRANSLATE("Show Time"),
35461863f2cSMatt Madia 			new BMessage('time'));
35541281cf3SAxel Dörfler 		menu->AddItem(item);
35641281cf3SAxel Dörfler 		menu->SetTargetForItems(this);
35741281cf3SAxel Dörfler 		BPoint where = ConvertToScreen(point);
35841281cf3SAxel Dörfler 		menu->Go(where, true, true, BRect(where - BPoint(4, 4),
35941281cf3SAxel Dörfler 			where + BPoint(4, 4)), true);
36041281cf3SAxel Dörfler 	}
36141281cf3SAxel Dörfler }
36241281cf3SAxel Dörfler 
36341281cf3SAxel Dörfler 
36441281cf3SAxel Dörfler void
36541281cf3SAxel Dörfler TReplicantTray::MouseDown(BPoint where)
36641281cf3SAxel Dörfler {
36741281cf3SAxel Dörfler #ifdef DB_ADDONS
36841281cf3SAxel Dörfler 	if (modifiers() & B_CONTROL_KEY)
36941281cf3SAxel Dörfler 		DumpList(fItemList);
37041281cf3SAxel Dörfler #endif
37141281cf3SAxel Dörfler 
37241281cf3SAxel Dörfler 	uint32 buttons;
37341281cf3SAxel Dörfler 
37441281cf3SAxel Dörfler 	Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
37541281cf3SAxel Dörfler 	if (buttons == B_SECONDARY_MOUSE_BUTTON) {
37641281cf3SAxel Dörfler 		ShowReplicantMenu(where);
37741281cf3SAxel Dörfler 	} else {
37841281cf3SAxel Dörfler 		BPoint save = where;
37941281cf3SAxel Dörfler 		bigtime_t doubleClickSpeed;
38041281cf3SAxel Dörfler 		bigtime_t start = system_time();
38141281cf3SAxel Dörfler 		uint32 buttons;
38241281cf3SAxel Dörfler 
38341281cf3SAxel Dörfler 		get_click_speed(&doubleClickSpeed);
38441281cf3SAxel Dörfler 
38541281cf3SAxel Dörfler 		do {
38641281cf3SAxel Dörfler 			if (fabs(where.x - save.x) > 4 || fabs(where.y - save.y) > 4)
38741281cf3SAxel Dörfler 				// user moved out of bounds of click area
38841281cf3SAxel Dörfler 				break;
38941281cf3SAxel Dörfler 
39041281cf3SAxel Dörfler 			if ((system_time() - start) > (2 * doubleClickSpeed)) {
39141281cf3SAxel Dörfler 				ShowReplicantMenu(where);
39241281cf3SAxel Dörfler 				break;
39341281cf3SAxel Dörfler 			}
39441281cf3SAxel Dörfler 
39541281cf3SAxel Dörfler 			snooze(50000);
39641281cf3SAxel Dörfler 			GetMouse(&where, &buttons);
39741281cf3SAxel Dörfler 		} while (buttons);
39841281cf3SAxel Dörfler 	}
39941281cf3SAxel Dörfler 	BView::MouseDown(where);
40041281cf3SAxel Dörfler }
40141281cf3SAxel Dörfler 
40241281cf3SAxel Dörfler #ifdef DB_ADDONS
40341281cf3SAxel Dörfler 
40441281cf3SAxel Dörfler void
40541281cf3SAxel Dörfler TReplicantTray::InitAddOnSupport()
40641281cf3SAxel Dörfler {
40741281cf3SAxel Dörfler 	// list to maintain refs to each rep added/deleted
40841281cf3SAxel Dörfler 	fItemList = new BList();
40941281cf3SAxel Dörfler 	BPath path;
4101ad8c760SFredrik Holmqvist 
41141281cf3SAxel Dörfler 	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) {
4123e6ff860SRene Gollent 		path.Append(kReplicantSettingsFile);
41341281cf3SAxel Dörfler 
41441281cf3SAxel Dörfler 		BFile file(path.Path(), B_READ_ONLY);
4153e6ff860SRene Gollent 		if (file.InitCheck() == B_OK) {
4163e6ff860SRene Gollent 			status_t result;
4173e6ff860SRene Gollent 			BEntry entry;
4183e6ff860SRene Gollent 			int32 id;
419c0ad1c91SRene Gollent 			BString path;
4203e6ff860SRene Gollent 			if (fAddOnSettings.Unflatten(&file) == B_OK) {
421c0ad1c91SRene Gollent 				for (int32 i = 0; fAddOnSettings.FindString(kReplicantPathField,
422c0ad1c91SRene Gollent 					i, &path) == B_OK; i++) {
423c0ad1c91SRene Gollent 					if (entry.SetTo(path.String()) == B_OK && entry.Exists()) {
4243e6ff860SRene Gollent 						result = LoadAddOn(&entry, &id, false);
4253e6ff860SRene Gollent 					} else
4263e6ff860SRene Gollent 						result = B_ENTRY_NOT_FOUND;
42741281cf3SAxel Dörfler 
4283e6ff860SRene Gollent 					if (result != B_OK) {
429c0ad1c91SRene Gollent 						fAddOnSettings.RemoveData(kReplicantPathField, i);
4303e6ff860SRene Gollent 						--i;
43141281cf3SAxel Dörfler 					}
43241281cf3SAxel Dörfler 				}
43341281cf3SAxel Dörfler 			}
4343e6ff860SRene Gollent 		}
4353e6ff860SRene Gollent 	}
43641281cf3SAxel Dörfler }
43741281cf3SAxel Dörfler 
43841281cf3SAxel Dörfler 
43941281cf3SAxel Dörfler void
44041281cf3SAxel Dörfler TReplicantTray::DeleteAddOnSupport()
44141281cf3SAxel Dörfler {
4427625ce51SRene Gollent 	_SaveSettings();
4433e6ff860SRene Gollent 
44441281cf3SAxel Dörfler 	for (int32 i = fItemList->CountItems(); i-- > 0 ;) {
44541281cf3SAxel Dörfler 		DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->RemoveItem(i);
44641281cf3SAxel Dörfler 		if (item) {
44741281cf3SAxel Dörfler 			if (item->isAddOn)
44841281cf3SAxel Dörfler 				watch_node(&(item->nodeRef), B_STOP_WATCHING, this, Window());
44941281cf3SAxel Dörfler 
45041281cf3SAxel Dörfler 			delete item;
45141281cf3SAxel Dörfler 		}
45241281cf3SAxel Dörfler 	}
45341281cf3SAxel Dörfler 	delete fItemList;
45441281cf3SAxel Dörfler 
45541281cf3SAxel Dörfler 	// stop the volume mount/unmount watch
45641281cf3SAxel Dörfler 	stop_watching(this, Window());
45741281cf3SAxel Dörfler }
45841281cf3SAxel Dörfler 
45941281cf3SAxel Dörfler 
46041281cf3SAxel Dörfler DeskbarItemInfo*
46141281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(node_ref& nodeRef)
46241281cf3SAxel Dörfler {
46341281cf3SAxel Dörfler 	for (int32 i = fItemList->CountItems(); i-- > 0 ;) {
46466eba86fSAxel Dörfler 		DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i);
46541281cf3SAxel Dörfler 		if (item == NULL)
46641281cf3SAxel Dörfler 			continue;
46741281cf3SAxel Dörfler 
46841281cf3SAxel Dörfler 		if (item->nodeRef == nodeRef)
46941281cf3SAxel Dörfler 			return item;
47041281cf3SAxel Dörfler 	}
47141281cf3SAxel Dörfler 
47241281cf3SAxel Dörfler 	return NULL;
47341281cf3SAxel Dörfler }
47441281cf3SAxel Dörfler 
47541281cf3SAxel Dörfler 
47641281cf3SAxel Dörfler DeskbarItemInfo*
47741281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(int32 id)
47841281cf3SAxel Dörfler {
47941281cf3SAxel Dörfler 	for (int32 i = fItemList->CountItems(); i-- > 0 ;) {
48066eba86fSAxel Dörfler 		DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i);
48141281cf3SAxel Dörfler 		if (item == NULL)
48241281cf3SAxel Dörfler 			continue;
48341281cf3SAxel Dörfler 
48441281cf3SAxel Dörfler 		if (item->id == id)
48541281cf3SAxel Dörfler 			return item;
48641281cf3SAxel Dörfler 	}
48741281cf3SAxel Dörfler 
48841281cf3SAxel Dörfler 	return NULL;
48941281cf3SAxel Dörfler }
49041281cf3SAxel Dörfler 
49141281cf3SAxel Dörfler 
49241281cf3SAxel Dörfler bool
49341281cf3SAxel Dörfler TReplicantTray::NodeExists(node_ref& nodeRef)
49441281cf3SAxel Dörfler {
49541281cf3SAxel Dörfler 	return DeskbarItemFor(nodeRef) != NULL;
49641281cf3SAxel Dörfler }
49741281cf3SAxel Dörfler 
49841281cf3SAxel Dörfler 
49966eba86fSAxel Dörfler /*! This handles B_NODE_MONITOR & B_QUERY_UPDATE messages received
50066eba86fSAxel Dörfler 	for the registered add-ons.
50141281cf3SAxel Dörfler */
50241281cf3SAxel Dörfler void
50341281cf3SAxel Dörfler TReplicantTray::HandleEntryUpdate(BMessage* message)
50441281cf3SAxel Dörfler {
50541281cf3SAxel Dörfler 	int32 opcode;
50641281cf3SAxel Dörfler 	if (message->FindInt32("opcode", &opcode) != B_OK)
50741281cf3SAxel Dörfler 		return;
50841281cf3SAxel Dörfler 
50941281cf3SAxel Dörfler 	BPath path;
51041281cf3SAxel Dörfler 	switch (opcode) {
51141281cf3SAxel Dörfler 		case B_ENTRY_MOVED:
51241281cf3SAxel Dörfler 		{
51341281cf3SAxel Dörfler 			entry_ref ref;
51441281cf3SAxel Dörfler 			ino_t todirectory;
51541281cf3SAxel Dörfler 			ino_t node;
51641281cf3SAxel Dörfler 			const char* name;
51741281cf3SAxel Dörfler 			if (message->FindString("name", &name) == B_OK
51871bd3ba5SJonas Sundström 				&& message->FindInt64("from directory", &(ref.directory))
51971bd3ba5SJonas Sundström 				== B_OK
52041281cf3SAxel Dörfler 				&& message->FindInt64("to directory", &todirectory) == B_OK
52141281cf3SAxel Dörfler 				&& message->FindInt32("device", &(ref.device)) == B_OK
52241281cf3SAxel Dörfler 				&& message->FindInt64("node", &node) == B_OK ) {
52341281cf3SAxel Dörfler 
52441281cf3SAxel Dörfler 				if (!name)
52541281cf3SAxel Dörfler 					break;
52641281cf3SAxel Dörfler 
52741281cf3SAxel Dörfler 				ref.set_name(name);
52841281cf3SAxel Dörfler 				// change the directory reference to
52941281cf3SAxel Dörfler 				// the new directory
53041281cf3SAxel Dörfler 				MoveItem(&ref, todirectory);
53141281cf3SAxel Dörfler 			}
53241281cf3SAxel Dörfler 			break;
53366eba86fSAxel Dörfler 		}
53441281cf3SAxel Dörfler 
53541281cf3SAxel Dörfler 		case B_ENTRY_REMOVED:
53641281cf3SAxel Dörfler 		{
53741281cf3SAxel Dörfler 			// entry was rm'd from the device
53841281cf3SAxel Dörfler 			node_ref nodeRef;
53941281cf3SAxel Dörfler 			if (message->FindInt32("device", &(nodeRef.device)) == B_OK
54041281cf3SAxel Dörfler 				&& message->FindInt64("node", &(nodeRef.node)) == B_OK) {
54141281cf3SAxel Dörfler 				DeskbarItemInfo* item = DeskbarItemFor(nodeRef);
54241281cf3SAxel Dörfler 				if (item == NULL)
54341281cf3SAxel Dörfler 					break;
54441281cf3SAxel Dörfler 
54541281cf3SAxel Dörfler 				// If there is a team running where the add-on comes from,
54641281cf3SAxel Dörfler 				// we don't want to remove the icon yet.
54741281cf3SAxel Dörfler 				if (be_roster->IsRunning(&item->entryRef))
54841281cf3SAxel Dörfler 					break;
54941281cf3SAxel Dörfler 
55041281cf3SAxel Dörfler 				UnloadAddOn(&nodeRef, NULL, true, false);
55141281cf3SAxel Dörfler 			}
55241281cf3SAxel Dörfler 			break;
55366eba86fSAxel Dörfler 		}
55441281cf3SAxel Dörfler 	}
55566eba86fSAxel Dörfler }
55641281cf3SAxel Dörfler 
55741281cf3SAxel Dörfler 
5581ad8c760SFredrik Holmqvist /*! The add-ons must support the exported C function API
55966eba86fSAxel Dörfler 	if they do, they will be loaded and added to deskbar
56066eba86fSAxel Dörfler 	primary function is the Instantiate function
5617da06231SAxel Dörfler */
56241281cf3SAxel Dörfler status_t
5633e6ff860SRene Gollent TReplicantTray::LoadAddOn(BEntry* entry, int32* id, bool addToSettings)
56441281cf3SAxel Dörfler {
56541281cf3SAxel Dörfler 	if (!entry)
56641281cf3SAxel Dörfler 		return B_ERROR;
56741281cf3SAxel Dörfler 
56841281cf3SAxel Dörfler 	node_ref nodeRef;
56941281cf3SAxel Dörfler 	entry->GetNodeRef(&nodeRef);
57041281cf3SAxel Dörfler 	// no duplicates
57141281cf3SAxel Dörfler 	if (NodeExists(nodeRef))
57241281cf3SAxel Dörfler 		return B_ERROR;
57341281cf3SAxel Dörfler 
57441281cf3SAxel Dörfler 	BNode node(entry);
57541281cf3SAxel Dörfler 	BPath path;
57666eba86fSAxel Dörfler 	status_t status = entry->GetPath(&path);
57766eba86fSAxel Dörfler 	if (status < B_OK)
57866eba86fSAxel Dörfler 		return status;
57941281cf3SAxel Dörfler 
58041281cf3SAxel Dörfler 	// load the add-on
58141281cf3SAxel Dörfler 	image_id image = load_add_on(path.Path());
58266eba86fSAxel Dörfler 	if (image < B_OK)
58366eba86fSAxel Dörfler 		return image;
58441281cf3SAxel Dörfler 
58541281cf3SAxel Dörfler 	// get the view loading function symbol
58641281cf3SAxel Dörfler 	//    we first look for a symbol that takes an image_id
58741281cf3SAxel Dörfler 	//    and entry_ref pointer, if not found, go with normal
58841281cf3SAxel Dörfler 	//    instantiate function
58941281cf3SAxel Dörfler 	BView* (*entryFunction)(image_id, const entry_ref*);
59041281cf3SAxel Dörfler 	BView* (*itemFunction)(void);
59141281cf3SAxel Dörfler 	BView* view = NULL;
59241281cf3SAxel Dörfler 
59341281cf3SAxel Dörfler 	entry_ref ref;
59441281cf3SAxel Dörfler 	entry->GetRef(&ref);
59541281cf3SAxel Dörfler 
59641281cf3SAxel Dörfler 	if (get_image_symbol(image, kInstantiateEntryCFunctionName,
59766eba86fSAxel Dörfler 			B_SYMBOL_TYPE_TEXT, (void**)&entryFunction) >= B_OK) {
59841281cf3SAxel Dörfler 		view = (*entryFunction)(image, &ref);
59941281cf3SAxel Dörfler 	} else if (get_image_symbol(image, kInstantiateItemCFunctionName,
60066eba86fSAxel Dörfler 			B_SYMBOL_TYPE_TEXT, (void**)&itemFunction) >= B_OK) {
60141281cf3SAxel Dörfler 		view = (*itemFunction)();
60241281cf3SAxel Dörfler 	} else {
60341281cf3SAxel Dörfler 		unload_add_on(image);
60441281cf3SAxel Dörfler 		return B_ERROR;
60541281cf3SAxel Dörfler 	}
60641281cf3SAxel Dörfler 
60766eba86fSAxel Dörfler 	if (view == NULL || IconExists(view->Name())) {
60841281cf3SAxel Dörfler 		delete view;
60941281cf3SAxel Dörfler 		unload_add_on(image);
61041281cf3SAxel Dörfler 		return B_ERROR;
61141281cf3SAxel Dörfler 	}
61241281cf3SAxel Dörfler 
61341281cf3SAxel Dörfler 	BMessage* data = new BMessage;
61441281cf3SAxel Dörfler 	view->Archive(data);
61541281cf3SAxel Dörfler 	delete view;
61641281cf3SAxel Dörfler 
61741281cf3SAxel Dörfler 	AddIcon(data, id, &ref);
61841281cf3SAxel Dörfler 		// add the rep; adds info to list
61941281cf3SAxel Dörfler 
6203e6ff860SRene Gollent 	if (addToSettings) {
621c0ad1c91SRene Gollent 		fAddOnSettings.AddString(kReplicantPathField, path.Path());
6227625ce51SRene Gollent 		_SaveSettings();
6233e6ff860SRene Gollent 	}
62441281cf3SAxel Dörfler 
62541281cf3SAxel Dörfler 	return B_OK;
62641281cf3SAxel Dörfler }
62741281cf3SAxel Dörfler 
62841281cf3SAxel Dörfler 
62941281cf3SAxel Dörfler status_t
63041281cf3SAxel Dörfler TReplicantTray::AddItem(int32 id, node_ref nodeRef, BEntry& entry, bool isAddOn)
63141281cf3SAxel Dörfler {
63241281cf3SAxel Dörfler 	DeskbarItemInfo* item = new DeskbarItemInfo;
63341281cf3SAxel Dörfler 	if (item == NULL)
63441281cf3SAxel Dörfler 		return B_NO_MEMORY;
63541281cf3SAxel Dörfler 
63641281cf3SAxel Dörfler 	item->id = id;
63741281cf3SAxel Dörfler 	item->isAddOn = isAddOn;
63841281cf3SAxel Dörfler 
63941281cf3SAxel Dörfler 	if (entry.GetRef(&item->entryRef) < B_OK) {
64041281cf3SAxel Dörfler 		item->entryRef.device = -1;
64141281cf3SAxel Dörfler 		item->entryRef.directory = -1;
64241281cf3SAxel Dörfler 		item->entryRef.name = NULL;
64341281cf3SAxel Dörfler 	}
64441281cf3SAxel Dörfler 	item->nodeRef = nodeRef;
64541281cf3SAxel Dörfler 
64641281cf3SAxel Dörfler 	fItemList->AddItem(item);
64741281cf3SAxel Dörfler 
64841281cf3SAxel Dörfler 	if (isAddOn)
64941281cf3SAxel Dörfler 		watch_node(&nodeRef, B_WATCH_NAME | B_WATCH_ATTR, this, Window());
65041281cf3SAxel Dörfler 
65141281cf3SAxel Dörfler 	return B_OK;
65241281cf3SAxel Dörfler }
65341281cf3SAxel Dörfler 
65441281cf3SAxel Dörfler 
65541281cf3SAxel Dörfler /**	from entry_removed message, when attribute removed
65641281cf3SAxel Dörfler  *	or when a device is unmounted (use removeall, by device)
65741281cf3SAxel Dörfler  */
65841281cf3SAxel Dörfler 
65941281cf3SAxel Dörfler void
66041281cf3SAxel Dörfler TReplicantTray::UnloadAddOn(node_ref* nodeRef, dev_t* device,
66141281cf3SAxel Dörfler 	bool which, bool removeAll)
66241281cf3SAxel Dörfler {
66341281cf3SAxel Dörfler 	for (int32 i = fItemList->CountItems(); i-- > 0 ;) {
66441281cf3SAxel Dörfler 		DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i);
66541281cf3SAxel Dörfler 		if (!item)
66641281cf3SAxel Dörfler 			continue;
66741281cf3SAxel Dörfler 
66841281cf3SAxel Dörfler 		if ((which && nodeRef && item->nodeRef == *nodeRef)
66941281cf3SAxel Dörfler 			|| (device && item->nodeRef.device == *device)) {
67041281cf3SAxel Dörfler 
67141281cf3SAxel Dörfler 			if (device && be_roster->IsRunning(&item->entryRef))
67241281cf3SAxel Dörfler 				continue;
67341281cf3SAxel Dörfler 
67441281cf3SAxel Dörfler 			RemoveIcon(item->id);
67541281cf3SAxel Dörfler 
67641281cf3SAxel Dörfler 			if (!removeAll)
67741281cf3SAxel Dörfler 				break;
67841281cf3SAxel Dörfler 		}
67941281cf3SAxel Dörfler 	}
68041281cf3SAxel Dörfler }
68141281cf3SAxel Dörfler 
68241281cf3SAxel Dörfler 
68341281cf3SAxel Dörfler void
68441281cf3SAxel Dörfler TReplicantTray::RemoveItem(int32 id)
68541281cf3SAxel Dörfler {
68641281cf3SAxel Dörfler 	DeskbarItemInfo* item = DeskbarItemFor(id);
68741281cf3SAxel Dörfler 	if (item == NULL)
68841281cf3SAxel Dörfler 		return;
68941281cf3SAxel Dörfler 
69041281cf3SAxel Dörfler 	// attribute was added via Deskbar API (AddItem(entry_ref*, int32*)
69141281cf3SAxel Dörfler 	if (item->isAddOn) {
6927625ce51SRene Gollent 		BPath path(&item->entryRef);
6937625ce51SRene Gollent 		BString storedPath;
6947625ce51SRene Gollent 		for (int32 i = 0;
695*8aab28f1SRene Gollent 			fAddOnSettings.FindString(kReplicantPathField, i, &storedPath)
6967625ce51SRene Gollent 				== B_OK; i++) {
6977625ce51SRene Gollent 			if (storedPath == path.Path()) {
698*8aab28f1SRene Gollent 				fAddOnSettings.RemoveData(kReplicantPathField, i);
6997625ce51SRene Gollent 				break;
7007625ce51SRene Gollent 			}
7017625ce51SRene Gollent 		}
7027625ce51SRene Gollent 		_SaveSettings();
7037625ce51SRene Gollent 
70441281cf3SAxel Dörfler 		BNode node(&item->entryRef);
70541281cf3SAxel Dörfler 		watch_node(&item->nodeRef, B_STOP_WATCHING, this, Window());
70641281cf3SAxel Dörfler 	}
70741281cf3SAxel Dörfler 
70841281cf3SAxel Dörfler 	fItemList->RemoveItem(item);
70941281cf3SAxel Dörfler 	delete item;
71041281cf3SAxel Dörfler }
71141281cf3SAxel Dörfler 
71241281cf3SAxel Dörfler 
71341281cf3SAxel Dörfler /**	ENTRY_MOVED message, moving only occurs on a device
71441281cf3SAxel Dörfler  *	copying will occur (ENTRY_CREATED) between devices
71541281cf3SAxel Dörfler  */
71641281cf3SAxel Dörfler 
71741281cf3SAxel Dörfler void
71841281cf3SAxel Dörfler TReplicantTray::MoveItem(entry_ref* ref, ino_t toDirectory)
71941281cf3SAxel Dörfler {
72041281cf3SAxel Dörfler 	if (!ref)
72141281cf3SAxel Dörfler 		return;
72241281cf3SAxel Dörfler 
72341281cf3SAxel Dörfler 	// scan for a matching entry_ref and update it
72441281cf3SAxel Dörfler 	//
72541281cf3SAxel Dörfler 	// don't need to change node info as it does not change
72641281cf3SAxel Dörfler 
72741281cf3SAxel Dörfler 	for (int32 i = fItemList->CountItems(); i-- > 0 ;) {
72841281cf3SAxel Dörfler 		DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i);
72941281cf3SAxel Dörfler 		if (!item)
73041281cf3SAxel Dörfler 			continue;
73141281cf3SAxel Dörfler 
73241281cf3SAxel Dörfler 		if (!strcmp(item->entryRef.name, ref->name)
73341281cf3SAxel Dörfler 			&& item->entryRef.device == ref->device
73441281cf3SAxel Dörfler 			&& item->entryRef.directory == ref->directory) {
73541281cf3SAxel Dörfler 			item->entryRef.directory = toDirectory;
73641281cf3SAxel Dörfler 			break;
73741281cf3SAxel Dörfler 		}
73841281cf3SAxel Dörfler 	}
73941281cf3SAxel Dörfler }
74041281cf3SAxel Dörfler 
74141281cf3SAxel Dörfler #endif // add-on support
74241281cf3SAxel Dörfler 
74341281cf3SAxel Dörfler //	external add-on API routines
74441281cf3SAxel Dörfler //	called using the new BDeskbar class
74541281cf3SAxel Dörfler 
74641281cf3SAxel Dörfler //	existence of icon/replicant by name or ID
74741281cf3SAxel Dörfler //	returns opposite
74841281cf3SAxel Dörfler //	note: name and id are semi-private limiting
74941281cf3SAxel Dörfler //		the ability of non-host apps to remove
75041281cf3SAxel Dörfler //		icons without a little bit of work
75141281cf3SAxel Dörfler 
75241281cf3SAxel Dörfler /**	for a specific id
75341281cf3SAxel Dörfler  *	return the name of the replicant (name of view)
75441281cf3SAxel Dörfler  */
75541281cf3SAxel Dörfler 
75641281cf3SAxel Dörfler status_t
75741281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 id, const char** name)
75841281cf3SAxel Dörfler {
75941281cf3SAxel Dörfler 	if (id < 0)
76041281cf3SAxel Dörfler 		return B_ERROR;
76141281cf3SAxel Dörfler 
76241281cf3SAxel Dörfler 	int32 index, temp;
76341281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &temp, id, false);
76441281cf3SAxel Dörfler 	if (view) {
76541281cf3SAxel Dörfler 		*name = view->Name();
76641281cf3SAxel Dörfler 		return B_OK;
76741281cf3SAxel Dörfler 	}
76841281cf3SAxel Dörfler 
76941281cf3SAxel Dörfler 	return B_ERROR;
77041281cf3SAxel Dörfler }
77141281cf3SAxel Dörfler 
77241281cf3SAxel Dörfler 
7737da06231SAxel Dörfler /**	for a specific name
7747da06231SAxel Dörfler  *	return the id (internal to Deskbar)
7757da06231SAxel Dörfler  */
7767da06231SAxel Dörfler 
77741281cf3SAxel Dörfler status_t
77841281cf3SAxel Dörfler TReplicantTray::ItemInfo(const char* name, int32* id)
77941281cf3SAxel Dörfler {
78041281cf3SAxel Dörfler 	if (!name || strlen(name) <= 0)
78141281cf3SAxel Dörfler 		return B_ERROR;
78241281cf3SAxel Dörfler 
78341281cf3SAxel Dörfler 	int32 index;
78441281cf3SAxel Dörfler 	BView* view = ViewAt(&index, id, name);
78541281cf3SAxel Dörfler 	if (view)
78641281cf3SAxel Dörfler 		return B_OK;
78741281cf3SAxel Dörfler 
78841281cf3SAxel Dörfler 	return B_ERROR;
78941281cf3SAxel Dörfler }
79041281cf3SAxel Dörfler 
79141281cf3SAxel Dörfler 
7927da06231SAxel Dörfler /**	at a specific index
7937da06231SAxel Dörfler  *	return both the name and the id of the replicant
7947da06231SAxel Dörfler  */
7957da06231SAxel Dörfler 
79641281cf3SAxel Dörfler status_t
79741281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 index, const char** name, int32* id)
79841281cf3SAxel Dörfler {
79941281cf3SAxel Dörfler 	if (index < 0)
80041281cf3SAxel Dörfler 		return B_ERROR;
80141281cf3SAxel Dörfler 
80241281cf3SAxel Dörfler 	BView* view;
80341281cf3SAxel Dörfler 	fShelf->ReplicantAt(index, &view, (uint32*)id, NULL);
80441281cf3SAxel Dörfler 	if (view) {
80541281cf3SAxel Dörfler 		*name = view->Name();
80641281cf3SAxel Dörfler 		return B_OK;
80741281cf3SAxel Dörfler 	}
80841281cf3SAxel Dörfler 
80941281cf3SAxel Dörfler 	return B_ERROR;
81041281cf3SAxel Dörfler }
81141281cf3SAxel Dörfler 
81241281cf3SAxel Dörfler 
8137da06231SAxel Dörfler /**	replicant exists, by id/index */
8147da06231SAxel Dörfler 
81541281cf3SAxel Dörfler bool
81641281cf3SAxel Dörfler TReplicantTray::IconExists(int32 target, bool byIndex)
81741281cf3SAxel Dörfler {
81841281cf3SAxel Dörfler 	int32 index, id;
81941281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &id, target, byIndex);
82041281cf3SAxel Dörfler 
82141281cf3SAxel Dörfler 	return view && index >= 0;
82241281cf3SAxel Dörfler }
82341281cf3SAxel Dörfler 
82441281cf3SAxel Dörfler 
8257da06231SAxel Dörfler /**	replicant exists, by name */
8267da06231SAxel Dörfler 
82741281cf3SAxel Dörfler bool
82841281cf3SAxel Dörfler TReplicantTray::IconExists(const char* name)
82941281cf3SAxel Dörfler {
83041281cf3SAxel Dörfler 	if (!name || strlen(name) == 0)
83141281cf3SAxel Dörfler 		return false;
83241281cf3SAxel Dörfler 
83341281cf3SAxel Dörfler 	int32 index, id;
83441281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &id, name);
83541281cf3SAxel Dörfler 
83641281cf3SAxel Dörfler 	return view && index >= 0;
83741281cf3SAxel Dörfler }
83841281cf3SAxel Dörfler 
83941281cf3SAxel Dörfler 
84041281cf3SAxel Dörfler int32
84141281cf3SAxel Dörfler TReplicantTray::IconCount() const
84241281cf3SAxel Dörfler {
84341281cf3SAxel Dörfler 	return fShelf->CountReplicants();
84441281cf3SAxel Dörfler }
84541281cf3SAxel Dörfler 
84641281cf3SAxel Dörfler 
847ced3755cSAxel Dörfler /*! Message must contain an archivable view for later rehydration.
848ced3755cSAxel Dörfler 	This function takes over ownership of the provided message on success
849ced3755cSAxel Dörfler 	only.
850ced3755cSAxel Dörfler 	Returns the current replicant ID.
8517da06231SAxel Dörfler */
85241281cf3SAxel Dörfler status_t
853ced3755cSAxel Dörfler TReplicantTray::AddIcon(BMessage* archive, int32* id, const entry_ref* addOn)
85441281cf3SAxel Dörfler {
855ced3755cSAxel Dörfler 	if (archive == NULL || id == NULL)
85641281cf3SAxel Dörfler 		return B_ERROR;
85741281cf3SAxel Dörfler 
8589c50f36eSAxel Dörfler 	// find entry_ref
8599c50f36eSAxel Dörfler 
8609c50f36eSAxel Dörfler 	entry_ref ref;
8619c50f36eSAxel Dörfler 	if (addOn) {
8629c50f36eSAxel Dörfler 		// Use it if we got it
8639c50f36eSAxel Dörfler 		ref = *addOn;
8649c50f36eSAxel Dörfler 	} else {
8659c50f36eSAxel Dörfler 		const char* signature;
8661ad8c760SFredrik Holmqvist 
867ced3755cSAxel Dörfler 		status_t status = archive->FindString("add_on", &signature);
8689c50f36eSAxel Dörfler 		if (status == B_OK) {
8699c50f36eSAxel Dörfler 			BRoster roster;
8709c50f36eSAxel Dörfler 			status = roster.FindApp(signature, &ref);
8719c50f36eSAxel Dörfler 		}
8729c50f36eSAxel Dörfler 		if (status < B_OK)
8739c50f36eSAxel Dörfler 			return status;
8749c50f36eSAxel Dörfler 	}
8759c50f36eSAxel Dörfler 
8769c50f36eSAxel Dörfler 	BFile file;
8779c50f36eSAxel Dörfler 	status_t status = file.SetTo(&ref, B_READ_ONLY);
8789c50f36eSAxel Dörfler 	if (status < B_OK)
8799c50f36eSAxel Dörfler 		return status;
8809c50f36eSAxel Dörfler 
8819c50f36eSAxel Dörfler 	node_ref nodeRef;
8829c50f36eSAxel Dörfler 	status = file.GetNodeRef(&nodeRef);
8839c50f36eSAxel Dörfler 	if (status < B_OK)
8849c50f36eSAxel Dörfler 		return status;
8859c50f36eSAxel Dörfler 
8869c50f36eSAxel Dörfler 	BEntry entry(&ref, true);
8871ad8c760SFredrik Holmqvist 		// TODO: this resolves an eventual link for the item being added - this
8881ad8c760SFredrik Holmqvist 		// is okay for now, but in multi-user environments, one might want to
8891ad8c760SFredrik Holmqvist 		// have links that carry the be:deskbar_item_status attribute
8909c50f36eSAxel Dörfler 	status = entry.InitCheck();
8919c50f36eSAxel Dörfler 	if (status != B_OK)
8929c50f36eSAxel Dörfler 		return status;
8939c50f36eSAxel Dörfler 
89441281cf3SAxel Dörfler 	*id = 999;
895ced3755cSAxel Dörfler 	if (archive->what == B_ARCHIVED_OBJECT)
896ced3755cSAxel Dörfler 		archive->what = 0;
89741281cf3SAxel Dörfler 
898ced3755cSAxel Dörfler 	BRect originalBounds = archive->FindRect("_frame");
8991ad8c760SFredrik Holmqvist 		// this is a work-around for buggy replicants that change their size in
9001ad8c760SFredrik Holmqvist 		// AttachedToWindow() (such as "SVM")
901a5210ab1SAxel Dörfler 
9021ad8c760SFredrik Holmqvist 	// TODO: check for name collisions?
903ced3755cSAxel Dörfler 	status = fShelf->AddReplicant(archive, BPoint(1, 1));
9049c50f36eSAxel Dörfler 	if (status != B_OK)
9059c50f36eSAxel Dörfler 		return status;
90641281cf3SAxel Dörfler 
907a5210ab1SAxel Dörfler 	int32 count = fShelf->CountReplicants();
908a5210ab1SAxel Dörfler 	BView* view;
909a5210ab1SAxel Dörfler 	fShelf->ReplicantAt(count - 1, &view, (uint32*)id, NULL);
910a5210ab1SAxel Dörfler 
911a5210ab1SAxel Dörfler 	if (originalBounds != view->Bounds()) {
912a5210ab1SAxel Dörfler 		// The replicant changed its size when added to the window, so we need
91371bd3ba5SJonas Sundström 		// to recompute all over again (it's already done once via
91471bd3ba5SJonas Sundström 		// BShelf::AddReplicant() and TReplicantShelf::CanAcceptReplicantView())
915a5210ab1SAxel Dörfler 		RealignReplicants();
916a5210ab1SAxel Dörfler 	}
917a5210ab1SAxel Dörfler 
91841281cf3SAxel Dörfler 	float oldWidth = Bounds().Width();
91941281cf3SAxel Dörfler 	float oldHeight = Bounds().Height();
92041281cf3SAxel Dörfler 	float width, height;
92141281cf3SAxel Dörfler 	GetPreferredSize(&width, &height);
92241281cf3SAxel Dörfler 	if (oldWidth != width || oldHeight != height)
92341281cf3SAxel Dörfler 		AdjustPlacement();
92441281cf3SAxel Dörfler 
92541281cf3SAxel Dörfler 	// add the item to the add-on list
92641281cf3SAxel Dörfler 
92741281cf3SAxel Dörfler 	AddItem(*id, nodeRef, entry, addOn != NULL);
92841281cf3SAxel Dörfler 	return B_OK;
92941281cf3SAxel Dörfler }
93041281cf3SAxel Dörfler 
93141281cf3SAxel Dörfler 
93241281cf3SAxel Dörfler void
93341281cf3SAxel Dörfler TReplicantTray::RemoveIcon(int32 target, bool byIndex)
93441281cf3SAxel Dörfler {
93541281cf3SAxel Dörfler 	if (target < 0)
93641281cf3SAxel Dörfler 		return;
93741281cf3SAxel Dörfler 
93841281cf3SAxel Dörfler 	int32 index, id;
93941281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &id, target, byIndex);
94041281cf3SAxel Dörfler 	if (view && index >= 0) {
9417da06231SAxel Dörfler 		// remove the reference from the item list & the shelf
94241281cf3SAxel Dörfler 		RemoveItem(id);
94341281cf3SAxel Dörfler 		fShelf->DeleteReplicant(index);
9447da06231SAxel Dörfler 
94541281cf3SAxel Dörfler 		// force a placement update,  !! need to fix BShelf
94641281cf3SAxel Dörfler 		RealReplicantAdjustment(index);
94741281cf3SAxel Dörfler 	}
94841281cf3SAxel Dörfler }
94941281cf3SAxel Dörfler 
95041281cf3SAxel Dörfler 
95141281cf3SAxel Dörfler void
95241281cf3SAxel Dörfler TReplicantTray::RemoveIcon(const char* name)
95341281cf3SAxel Dörfler {
95441281cf3SAxel Dörfler 	if (!name || strlen(name) <= 0)
95541281cf3SAxel Dörfler 		return;
95641281cf3SAxel Dörfler 
95741281cf3SAxel Dörfler 	int32 id, index;
95841281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &id, name);
95941281cf3SAxel Dörfler 	if (view && index >= 0) {
9607da06231SAxel Dörfler 		// remove the reference from the item list & shelf
96141281cf3SAxel Dörfler 		RemoveItem(id);
96241281cf3SAxel Dörfler 		fShelf->DeleteReplicant(index);
9637da06231SAxel Dörfler 
96441281cf3SAxel Dörfler 		// force a placement update,  !! need to fix BShelf
96541281cf3SAxel Dörfler 		RealReplicantAdjustment(index);
96641281cf3SAxel Dörfler 	}
96741281cf3SAxel Dörfler }
96841281cf3SAxel Dörfler 
96941281cf3SAxel Dörfler 
97041281cf3SAxel Dörfler void
9717da06231SAxel Dörfler TReplicantTray::RealReplicantAdjustment(int32 startIndex)
97241281cf3SAxel Dörfler {
9737da06231SAxel Dörfler 	if (startIndex < 0)
97441281cf3SAxel Dörfler 		return;
9757da06231SAxel Dörfler 
9767da06231SAxel Dörfler 	if (startIndex == fLastReplicant)
9777da06231SAxel Dörfler 		startIndex = 0;
9787da06231SAxel Dörfler 
97941281cf3SAxel Dörfler 	// reset the locations of all replicants after the one deleted
9807da06231SAxel Dörfler 	RealignReplicants(startIndex);
98141281cf3SAxel Dörfler 
98241281cf3SAxel Dörfler 	float oldWidth = Bounds().Width();
98341281cf3SAxel Dörfler 	float oldHeight = Bounds().Height();
98441281cf3SAxel Dörfler 	float width, height;
98541281cf3SAxel Dörfler 	GetPreferredSize(&width, &height);
98641281cf3SAxel Dörfler 	if (oldWidth != width || oldHeight != height) {
9871ad8c760SFredrik Holmqvist 		// resize view to accomodate the replicants, redraw as necessary
98841281cf3SAxel Dörfler 		AdjustPlacement();
98941281cf3SAxel Dörfler 	}
99041281cf3SAxel Dörfler }
99141281cf3SAxel Dörfler 
99241281cf3SAxel Dörfler 
9937da06231SAxel Dörfler /**	looking for a replicant by id/index
9947da06231SAxel Dörfler  *	return the view and index
9957da06231SAxel Dörfler  */
9967da06231SAxel Dörfler 
99741281cf3SAxel Dörfler BView*
99841281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, int32 target, bool byIndex)
99941281cf3SAxel Dörfler {
100041281cf3SAxel Dörfler 	*index = -1;
100141281cf3SAxel Dörfler 
100241281cf3SAxel Dörfler 	BView* view;
100341281cf3SAxel Dörfler 	if (byIndex) {
100441281cf3SAxel Dörfler 		if (fShelf->ReplicantAt(target, &view, (uint32*)id)) {
100541281cf3SAxel Dörfler 			if (view) {
100641281cf3SAxel Dörfler 				*index = target;
100741281cf3SAxel Dörfler 				return view;
100841281cf3SAxel Dörfler 			}
100941281cf3SAxel Dörfler 		}
101041281cf3SAxel Dörfler 	} else {
101141281cf3SAxel Dörfler 		int32 count = fShelf->CountReplicants() - 1;
101241281cf3SAxel Dörfler 		int32 localid;
101341281cf3SAxel Dörfler 		for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) {
101441281cf3SAxel Dörfler 			fShelf->ReplicantAt(repIndex, &view, (uint32*)&localid);
101541281cf3SAxel Dörfler 			if (localid == target && view) {
101641281cf3SAxel Dörfler 				*index = repIndex;
101741281cf3SAxel Dörfler 				*id = localid;
101841281cf3SAxel Dörfler 				return view;
101941281cf3SAxel Dörfler 			}
102041281cf3SAxel Dörfler 		}
102141281cf3SAxel Dörfler 	}
102241281cf3SAxel Dörfler 	return NULL;
102341281cf3SAxel Dörfler }
102441281cf3SAxel Dörfler 
102541281cf3SAxel Dörfler 
10267da06231SAxel Dörfler /**	looking for a replicant with a view by name
10277da06231SAxel Dörfler  *	return the view, index and the id of the replicant
10287da06231SAxel Dörfler  */
10297da06231SAxel Dörfler 
103041281cf3SAxel Dörfler BView*
103141281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, const char* name)
103241281cf3SAxel Dörfler {
103341281cf3SAxel Dörfler 	*index = -1;
103441281cf3SAxel Dörfler 	*id = -1;
103541281cf3SAxel Dörfler 
103641281cf3SAxel Dörfler 	BView* view;
103741281cf3SAxel Dörfler 	int32 count = fShelf->CountReplicants()-1;
103841281cf3SAxel Dörfler 	for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) {
103941281cf3SAxel Dörfler 		fShelf->ReplicantAt(repIndex, &view, (uint32*)id);
104041281cf3SAxel Dörfler 		if (view && view->Name() && strcmp(name, view->Name()) == 0) {
104141281cf3SAxel Dörfler 			*index = repIndex;
104241281cf3SAxel Dörfler 			return view;
104341281cf3SAxel Dörfler 		}
104441281cf3SAxel Dörfler 	}
104541281cf3SAxel Dörfler 	return NULL;
104641281cf3SAxel Dörfler }
104741281cf3SAxel Dörfler 
104841281cf3SAxel Dörfler 
10497da06231SAxel Dörfler /**	Shelf will call to determine where and if
10507da06231SAxel Dörfler  *	the replicant is to be added
10517da06231SAxel Dörfler  */
10527da06231SAxel Dörfler 
105341281cf3SAxel Dörfler bool
105441281cf3SAxel Dörfler TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage* message)
105541281cf3SAxel Dörfler {
105641281cf3SAxel Dörfler 	if (!message)
105741281cf3SAxel Dörfler 		return false;
105841281cf3SAxel Dörfler 
105941281cf3SAxel Dörfler 	if (replicantFrame.Height() > kMaxReplicantHeight)
106041281cf3SAxel Dörfler 		return false;
106141281cf3SAxel Dörfler 
106241281cf3SAxel Dörfler 	alignment align = B_ALIGN_LEFT;
106341281cf3SAxel Dörfler 	if (fAlignmentSupport && message->HasBool("deskbar:dynamic_align")) {
106441281cf3SAxel Dörfler 		if (!fBarView->Vertical())
106541281cf3SAxel Dörfler 			align = B_ALIGN_RIGHT;
106641281cf3SAxel Dörfler 		else
106741281cf3SAxel Dörfler 			align = fBarView->Left() ? B_ALIGN_LEFT : B_ALIGN_RIGHT;
106841281cf3SAxel Dörfler 	} else if (message->HasInt32("deskbar:align"))
106941281cf3SAxel Dörfler 		message->FindInt32("deskbar:align", (int32*)&align);
107041281cf3SAxel Dörfler 
107141281cf3SAxel Dörfler 	if (message->HasInt32("deskbar:private_align"))
107241281cf3SAxel Dörfler 		message->FindInt32("deskbar:private_align", (int32*)&align);
107341281cf3SAxel Dörfler 	else
107441281cf3SAxel Dörfler 		align = B_ALIGN_LEFT;
107541281cf3SAxel Dörfler 
10767da06231SAxel Dörfler 	BPoint loc = LocationForReplicant(fShelf->CountReplicants(),
10777da06231SAxel Dörfler 		replicantFrame.Width());
107841281cf3SAxel Dörfler 
107941281cf3SAxel Dörfler 	message->AddPoint("_pjp_loc", loc);
108041281cf3SAxel Dörfler 	return true;
108141281cf3SAxel Dörfler }
108241281cf3SAxel Dörfler 
108341281cf3SAxel Dörfler 
108441281cf3SAxel Dörfler /**	based on the previous (index - 1) replicant in the list
108541281cf3SAxel Dörfler  *	calculate where the left point should be for this
108641281cf3SAxel Dörfler  *	replicant.  replicant will flow to the right on its own
108741281cf3SAxel Dörfler  */
108841281cf3SAxel Dörfler 
108941281cf3SAxel Dörfler BPoint
10907da06231SAxel Dörfler TReplicantTray::LocationForReplicant(int32 index, float width)
109141281cf3SAxel Dörfler {
109241281cf3SAxel Dörfler 	BPoint loc(kIconGap + 1, kGutter + 1);
109341281cf3SAxel Dörfler 
10947da06231SAxel Dörfler 	if (fMultiRowMode) {
10957da06231SAxel Dörfler 		// try to find free space in every row
10967da06231SAxel Dörfler 		for (int32 row = 0; ; loc.y += kMaxReplicantHeight + kIconGap, row++) {
10977da06231SAxel Dörfler 			// determine free space in this row
109871bd3ba5SJonas Sundström 			BRect rect(loc.x, loc.y, loc.x + fMinimumTrayWidth - kIconGap - 2.0,
109971bd3ba5SJonas Sundström 				loc.y + kMaxReplicantHeight);
11007da06231SAxel Dörfler 			if (row == 0 && fBarView->ShowingClock())
11017da06231SAxel Dörfler 				rect.right -= fClock->Frame().Width() + kIconGap;
11027da06231SAxel Dörfler 
11037da06231SAxel Dörfler 			for (int32 i = 0; i < index; i++) {
11047da06231SAxel Dörfler 				BView* view = NULL;
11057da06231SAxel Dörfler 				fShelf->ReplicantAt(i, &view);
11067da06231SAxel Dörfler 				if (view == NULL || view->Frame().top != rect.top)
11077da06231SAxel Dörfler 					continue;
11087da06231SAxel Dörfler 
11097da06231SAxel Dörfler 				rect.left = view->Frame().right + kIconGap + 1;
11107da06231SAxel Dörfler 			}
11117da06231SAxel Dörfler 
11127da06231SAxel Dörfler 			if (rect.Width() >= width) {
11137da06231SAxel Dörfler 				// the icon fits in this row
11147da06231SAxel Dörfler 				loc = rect.LeftTop();
11157da06231SAxel Dörfler 				break;
11167da06231SAxel Dörfler 			}
11177da06231SAxel Dörfler 		}
11187da06231SAxel Dörfler 	} else {
111941281cf3SAxel Dörfler 		if (index > 0) {
112041281cf3SAxel Dörfler 			// get the last replicant added for placement reference
112141281cf3SAxel Dörfler 			BView* view = NULL;
11227da06231SAxel Dörfler 			fShelf->ReplicantAt(index - 1, &view);
112341281cf3SAxel Dörfler 			if (view) {
112441281cf3SAxel Dörfler 				// push this rep placement past the last one
112541281cf3SAxel Dörfler 				loc.x = view->Frame().right + kIconGap + 1;
112641281cf3SAxel Dörfler 				loc.y = view->Frame().top;
112741281cf3SAxel Dörfler 			}
112841281cf3SAxel Dörfler 		}
11297da06231SAxel Dörfler 	}
113041281cf3SAxel Dörfler 
113171bd3ba5SJonas Sundström 	if ((loc.y == fRightBottomReplicant.top && loc.x
113271bd3ba5SJonas Sundström 		> fRightBottomReplicant.left) || loc.y > fRightBottomReplicant.top) {
113371bd3ba5SJonas Sundström 		fRightBottomReplicant.Set(loc.x, loc.y, loc.x + width, loc.y
113471bd3ba5SJonas Sundström 		+ kMaxReplicantHeight);
11357da06231SAxel Dörfler 		fLastReplicant = index;
113641281cf3SAxel Dörfler 	}
11377da06231SAxel Dörfler 
113841281cf3SAxel Dörfler 	return loc;
113941281cf3SAxel Dörfler }
114041281cf3SAxel Dörfler 
114141281cf3SAxel Dörfler 
114241281cf3SAxel Dörfler BRect
114341281cf3SAxel Dörfler TReplicantTray::IconFrame(int32 target, bool byIndex)
114441281cf3SAxel Dörfler {
114541281cf3SAxel Dörfler 	int32 index, id;
114641281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &id, target, byIndex);
114741281cf3SAxel Dörfler 	if (view)
114841281cf3SAxel Dörfler 		return view->Frame();
114941281cf3SAxel Dörfler 
115041281cf3SAxel Dörfler 	return BRect(0, 0, 0, 0);
115141281cf3SAxel Dörfler }
115241281cf3SAxel Dörfler 
115341281cf3SAxel Dörfler 
115441281cf3SAxel Dörfler BRect
115541281cf3SAxel Dörfler TReplicantTray::IconFrame(const char* name)
115641281cf3SAxel Dörfler {
115741281cf3SAxel Dörfler 	if (!name)
115841281cf3SAxel Dörfler 		return BRect(0, 0, 0, 0);
115941281cf3SAxel Dörfler 
116041281cf3SAxel Dörfler 	int32 id, index;
116141281cf3SAxel Dörfler 	BView* view = ViewAt(&index, &id, name);
116241281cf3SAxel Dörfler 	if (view)
116341281cf3SAxel Dörfler 		return view->Frame();
116441281cf3SAxel Dörfler 
116541281cf3SAxel Dörfler 	return BRect(0, 0, 0, 0);
116641281cf3SAxel Dörfler }
116741281cf3SAxel Dörfler 
116841281cf3SAxel Dörfler 
11697da06231SAxel Dörfler /**	Scan from the startIndex and reset the location
11707da06231SAxel Dörfler  *	as defined in LocationForReplicant()
117141281cf3SAxel Dörfler  */
117241281cf3SAxel Dörfler 
117341281cf3SAxel Dörfler void
117441281cf3SAxel Dörfler TReplicantTray::RealignReplicants(int32 startIndex)
117541281cf3SAxel Dörfler {
117641281cf3SAxel Dörfler 	if (startIndex < 0)
117741281cf3SAxel Dörfler 		startIndex = 0;
117841281cf3SAxel Dörfler 
117941281cf3SAxel Dörfler 	int32 count = fShelf->CountReplicants();
118041281cf3SAxel Dörfler 	if (count <= 0)
118141281cf3SAxel Dörfler 		return;
118241281cf3SAxel Dörfler 
11837da06231SAxel Dörfler 	if (startIndex == 0)
11847da06231SAxel Dörfler 		fRightBottomReplicant.Set(0, 0, 0, 0);
11857da06231SAxel Dörfler 
118641281cf3SAxel Dörfler 	BView* view = NULL;
118741281cf3SAxel Dörfler 	for (int32 i = startIndex ; i < count ; i++) {
118841281cf3SAxel Dörfler 		fShelf->ReplicantAt(i, &view);
11890bec7100SStefano Ceccherini 		if (view != NULL) {
11907da06231SAxel Dörfler 			BPoint loc = LocationForReplicant(i, view->Frame().Width());
11910bec7100SStefano Ceccherini 			if (view->Frame().LeftTop() != loc)
119241281cf3SAxel Dörfler 				view->MoveTo(loc);
119341281cf3SAxel Dörfler 		}
119441281cf3SAxel Dörfler 	}
119541281cf3SAxel Dörfler }
119641281cf3SAxel Dörfler 
119741281cf3SAxel Dörfler 
119841281cf3SAxel Dörfler void
119941281cf3SAxel Dörfler TReplicantTray::SetMultiRow(bool state)
120041281cf3SAxel Dörfler {
120141281cf3SAxel Dörfler 	fMultiRowMode = state;
120241281cf3SAxel Dörfler }
120341281cf3SAxel Dörfler 
120441281cf3SAxel Dörfler 
1205*8aab28f1SRene Gollent status_t
12067625ce51SRene Gollent TReplicantTray::_SaveSettings()
12077625ce51SRene Gollent {
12087625ce51SRene Gollent 	status_t result;
12097625ce51SRene Gollent 	BPath path;
12107625ce51SRene Gollent 	if ((result = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true))
12117625ce51SRene Gollent 		 == B_OK) {
12127625ce51SRene Gollent 		path.Append(kReplicantSettingsFile);
12137625ce51SRene Gollent 
12147625ce51SRene Gollent 		BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
12157625ce51SRene Gollent 		if ((result = file.InitCheck()) == B_OK)
12167625ce51SRene Gollent 			result = fAddOnSettings.Flatten(&file);
12177625ce51SRene Gollent 	}
12187625ce51SRene Gollent 
12197625ce51SRene Gollent 	return result;
12207625ce51SRene Gollent }
12217625ce51SRene Gollent 
12227625ce51SRene Gollent 
122341281cf3SAxel Dörfler //	#pragma mark -
122441281cf3SAxel Dörfler 
122541281cf3SAxel Dörfler 
1226ca9acc20SAxel Dörfler /*! Draggable region that is asynchronous so that dragging does not block
1227ca9acc20SAxel Dörfler 	other activities.
12287da06231SAxel Dörfler */
122941281cf3SAxel Dörfler TDragRegion::TDragRegion(TBarView* parent, BView* child)
1230ca9acc20SAxel Dörfler 	:
1231ca9acc20SAxel Dörfler 	BControl(BRect(0, 0, 0, 0), "", "", NULL, B_FOLLOW_NONE,
123241281cf3SAxel Dörfler 		B_WILL_DRAW | B_FRAME_EVENTS),
123341281cf3SAxel Dörfler 	fBarView(parent),
123441281cf3SAxel Dörfler 	fChild(child),
123541281cf3SAxel Dörfler 	fDragLocation(kAutoPlaceDragRegion)
123641281cf3SAxel Dörfler {
123741281cf3SAxel Dörfler }
123841281cf3SAxel Dörfler 
123941281cf3SAxel Dörfler 
124041281cf3SAxel Dörfler void
124141281cf3SAxel Dörfler TDragRegion::AttachedToWindow()
124241281cf3SAxel Dörfler {
124341281cf3SAxel Dörfler 	BView::AttachedToWindow();
1244cb6afcb1SStephan Aßmus 	if (be_control_look != NULL)
1245cb6afcb1SStephan Aßmus 		SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 1.1));
1246cb6afcb1SStephan Aßmus 	else
124741281cf3SAxel Dörfler 		SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
124841281cf3SAxel Dörfler 	ResizeToPreferred();
124941281cf3SAxel Dörfler }
125041281cf3SAxel Dörfler 
125141281cf3SAxel Dörfler 
125241281cf3SAxel Dörfler void
125341281cf3SAxel Dörfler TDragRegion::GetPreferredSize(float* width, float* height)
125441281cf3SAxel Dörfler {
125541281cf3SAxel Dörfler 	fChild->ResizeToPreferred();
125641281cf3SAxel Dörfler 	*width = fChild->Bounds().Width();
125741281cf3SAxel Dörfler 	*height = fChild->Bounds().Height();
125841281cf3SAxel Dörfler 
125941281cf3SAxel Dörfler 	if (fDragLocation != kNoDragRegion)
126041281cf3SAxel Dörfler 		*width += 7;
126141281cf3SAxel Dörfler 	else
126241281cf3SAxel Dörfler 		*width += 6;
126341281cf3SAxel Dörfler 
126441281cf3SAxel Dörfler 	*height += 3;
126541281cf3SAxel Dörfler }
126641281cf3SAxel Dörfler 
126741281cf3SAxel Dörfler 
126841281cf3SAxel Dörfler void
126941281cf3SAxel Dörfler TDragRegion::FrameMoved(BPoint)
127041281cf3SAxel Dörfler {
1271ca9acc20SAxel Dörfler 	if (fBarView->Left() && fBarView->Vertical()
1272ca9acc20SAxel Dörfler 		&& fDragLocation != kNoDragRegion)
127341281cf3SAxel Dörfler 		fChild->MoveTo(5, 2);
127441281cf3SAxel Dörfler 	else
127541281cf3SAxel Dörfler 		fChild->MoveTo(2, 2);
127641281cf3SAxel Dörfler }
127741281cf3SAxel Dörfler 
127841281cf3SAxel Dörfler 
127941281cf3SAxel Dörfler void
128041281cf3SAxel Dörfler TDragRegion::Draw(BRect)
128141281cf3SAxel Dörfler {
1282eaa9af99SStephan Aßmus 	rgb_color menuColor = ViewColor();
128341281cf3SAxel Dörfler 	rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT);
1284cb6afcb1SStephan Aßmus 	rgb_color ldark = tint_color(menuColor, 1.02);
1285cb6afcb1SStephan Aßmus 	rgb_color dark = tint_color(menuColor, B_DARKEN_2_TINT);
128641281cf3SAxel Dörfler 	rgb_color vdark = tint_color(menuColor, B_DARKEN_3_TINT);
128741281cf3SAxel Dörfler 	rgb_color vvdark = tint_color(menuColor, B_DARKEN_4_TINT);
128841281cf3SAxel Dörfler 	rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT);
128941281cf3SAxel Dörfler 
129041281cf3SAxel Dörfler 	BRect frame(Bounds());
129141281cf3SAxel Dörfler 	BeginLineArray(4);
129241281cf3SAxel Dörfler 
1293cb6afcb1SStephan Aßmus 	if (be_control_look != NULL) {
1294cb6afcb1SStephan Aßmus 		if (fBarView->Vertical()) {
1295cb6afcb1SStephan Aßmus 			AddLine(frame.LeftTop(), frame.RightTop(), dark);
1296cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.left, frame.top + 1),
1297cb6afcb1SStephan Aßmus 				BPoint(frame.right, frame.top + 1), ldark);
1298cb6afcb1SStephan Aßmus 			AddLine(frame.LeftBottom(), frame.RightBottom(), hilite);
1299cb6afcb1SStephan Aßmus 		} else if (fBarView->AcrossTop() || fBarView->AcrossBottom()) {
1300cb6afcb1SStephan Aßmus 			AddLine(frame.LeftTop(),
1301cb6afcb1SStephan Aßmus 				BPoint(frame.left, frame.bottom), dark);
1302cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.left + 1, frame.top + 1),
1303cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.top + 1), light);
1304cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.right, frame.top + 2),
1305cb6afcb1SStephan Aßmus 				BPoint(frame.right, frame.bottom), hilite);
1306cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.left + 1, frame.bottom),
1307cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.bottom), hilite);
1308cb6afcb1SStephan Aßmus 		}
1309cb6afcb1SStephan Aßmus 	} else {
131041281cf3SAxel Dörfler 		if (fBarView->Vertical()) {
131141281cf3SAxel Dörfler 			AddLine(frame.LeftTop(), frame.RightTop(), light);
131241281cf3SAxel Dörfler 			AddLine(frame.LeftTop(), frame.LeftBottom(), light);
131341281cf3SAxel Dörfler 			AddLine(frame.RightBottom(), frame.RightTop(), hilite);
131441281cf3SAxel Dörfler 		} else if (fBarView->AcrossTop()) {
1315cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.left, frame.top + 1),
1316cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.top + 1), light);
131741281cf3SAxel Dörfler 			AddLine(frame.RightTop(), frame.RightBottom(), vvdark);
1318cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.right - 1, frame.top + 2),
1319cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.bottom - 1), hilite);
1320cb6afcb1SStephan Aßmus 			AddLine(frame.LeftBottom(),
1321cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.bottom), hilite);
132241281cf3SAxel Dörfler 		} else if (fBarView->AcrossBottom()) {
1323cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.left, frame.top + 1),
1324cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.top + 1), light);
132541281cf3SAxel Dörfler 			AddLine(frame.LeftBottom(), frame.RightBottom(), hilite);
132641281cf3SAxel Dörfler 			AddLine(frame.RightTop(), frame.RightBottom(), vvdark);
1327cb6afcb1SStephan Aßmus 			AddLine(BPoint(frame.right - 1, frame.top + 1),
1328cb6afcb1SStephan Aßmus 				BPoint(frame.right - 1, frame.bottom - 1), hilite);
1329cb6afcb1SStephan Aßmus 		}
133041281cf3SAxel Dörfler 	}
133141281cf3SAxel Dörfler 
133241281cf3SAxel Dörfler 	EndLineArray();
133341281cf3SAxel Dörfler 
133441281cf3SAxel Dörfler 	if (fDragLocation != kDontDrawDragRegion || fDragLocation != kNoDragRegion)
133541281cf3SAxel Dörfler 		DrawDragRegion();
133641281cf3SAxel Dörfler }
133741281cf3SAxel Dörfler 
133841281cf3SAxel Dörfler 
133941281cf3SAxel Dörfler void
134041281cf3SAxel Dörfler TDragRegion::DrawDragRegion()
134141281cf3SAxel Dörfler {
134241281cf3SAxel Dörfler 	BRect dragRegion(DragRegion());
134341281cf3SAxel Dörfler 
1344cb6afcb1SStephan Aßmus 	rgb_color menuColor = ViewColor();
1345cb6afcb1SStephan Aßmus 	rgb_color menuHilite = menuColor;
134641281cf3SAxel Dörfler 	if (IsTracking()) {
1347cb6afcb1SStephan Aßmus 		// Draw drag region highlighted if tracking mouse
1348cb6afcb1SStephan Aßmus 		menuHilite = tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT);
134941281cf3SAxel Dörfler 		SetHighColor(menuHilite);
135041281cf3SAxel Dörfler 		FillRect(dragRegion);
135141281cf3SAxel Dörfler 	}
1352cb6afcb1SStephan Aßmus 	rgb_color vdark = tint_color(menuHilite, B_DARKEN_3_TINT);
1353cb6afcb1SStephan Aßmus 	rgb_color light = tint_color(menuHilite, B_LIGHTEN_2_TINT);
1354cb6afcb1SStephan Aßmus 
1355cb6afcb1SStephan Aßmus 	BeginLineArray(dragRegion.IntegerHeight());
1356cb6afcb1SStephan Aßmus 	BPoint pt;
1357cb6afcb1SStephan Aßmus 	pt.x = floorf((dragRegion.left + dragRegion.right) / 2 + 0.5) - 1;
1358cb6afcb1SStephan Aßmus 	pt.y = dragRegion.top + 2;
1359cb6afcb1SStephan Aßmus 
136041281cf3SAxel Dörfler 	while (pt.y + 1 <= dragRegion.bottom) {
136141281cf3SAxel Dörfler 		AddLine(pt, pt, vdark);
136241281cf3SAxel Dörfler 		AddLine(pt + BPoint(1, 1), pt + BPoint(1, 1), light);
136341281cf3SAxel Dörfler 
136441281cf3SAxel Dörfler 		pt.y += 3;
136541281cf3SAxel Dörfler 	}
136641281cf3SAxel Dörfler 	EndLineArray();
136741281cf3SAxel Dörfler }
136841281cf3SAxel Dörfler 
136941281cf3SAxel Dörfler 
137041281cf3SAxel Dörfler BRect
137141281cf3SAxel Dörfler TDragRegion::DragRegion() const
137241281cf3SAxel Dörfler {
1373cb6afcb1SStephan Aßmus 	float kTopBottomInset = 2;
1374cb6afcb1SStephan Aßmus 	float kLeftRightInset = 1;
1375cb6afcb1SStephan Aßmus 	float kDragWidth = 3;
1376cb6afcb1SStephan Aßmus 	if (be_control_look != NULL) {
1377cb6afcb1SStephan Aßmus 		kTopBottomInset = 1;
1378cb6afcb1SStephan Aßmus 		kLeftRightInset = 0;
1379cb6afcb1SStephan Aßmus 		kDragWidth = 4;
1380cb6afcb1SStephan Aßmus 	}
1381cb6afcb1SStephan Aßmus 
138241281cf3SAxel Dörfler 	BRect dragRegion(Bounds());
1383cb6afcb1SStephan Aßmus 	dragRegion.top += kTopBottomInset;
1384cb6afcb1SStephan Aßmus 	dragRegion.bottom -= kTopBottomInset;
138541281cf3SAxel Dörfler 
138641281cf3SAxel Dörfler 	bool placeOnLeft = false;
138741281cf3SAxel Dörfler 	if (fDragLocation == kAutoPlaceDragRegion) {
138841281cf3SAxel Dörfler 		if (fBarView->Vertical() && fBarView->Left())
138941281cf3SAxel Dörfler 			placeOnLeft = true;
139041281cf3SAxel Dörfler 		else
139141281cf3SAxel Dörfler 			placeOnLeft = false;
139241281cf3SAxel Dörfler 	} else if (fDragLocation == kDragRegionLeft)
139341281cf3SAxel Dörfler 		placeOnLeft = true;
139441281cf3SAxel Dörfler 	else if (fDragLocation == kDragRegionRight)
139541281cf3SAxel Dörfler 		placeOnLeft = false;
139641281cf3SAxel Dörfler 
139741281cf3SAxel Dörfler 	if (placeOnLeft) {
1398cb6afcb1SStephan Aßmus 		dragRegion.left += kLeftRightInset;
1399cb6afcb1SStephan Aßmus 		dragRegion.right = dragRegion.left + kDragWidth;
140041281cf3SAxel Dörfler 	} else {
1401cb6afcb1SStephan Aßmus 		dragRegion.right -= kLeftRightInset;
1402cb6afcb1SStephan Aßmus 		dragRegion.left = dragRegion.right - kDragWidth;
140341281cf3SAxel Dörfler 	}
140441281cf3SAxel Dörfler 
140541281cf3SAxel Dörfler 	return dragRegion;
140641281cf3SAxel Dörfler }
140741281cf3SAxel Dörfler 
140841281cf3SAxel Dörfler 
140941281cf3SAxel Dörfler void
141041281cf3SAxel Dörfler TDragRegion::MouseDown(BPoint thePoint)
141141281cf3SAxel Dörfler {
141241281cf3SAxel Dörfler 	ulong buttons;
141341281cf3SAxel Dörfler 	BPoint where;
141441281cf3SAxel Dörfler 	BRect dragRegion(DragRegion());
141541281cf3SAxel Dörfler 
14167da06231SAxel Dörfler 	dragRegion.InsetBy(-2.0f, -2.0f);
14177da06231SAxel Dörfler 		// DragRegion() is designed for drawing, not clicking
141841281cf3SAxel Dörfler 
141941281cf3SAxel Dörfler 	if (!dragRegion.Contains(thePoint))
142041281cf3SAxel Dörfler 		return;
142141281cf3SAxel Dörfler 
142241281cf3SAxel Dörfler 	while (true) {
142341281cf3SAxel Dörfler 		GetMouse(&where, &buttons);
142441281cf3SAxel Dörfler 		if (!buttons)
142541281cf3SAxel Dörfler 			break;
142641281cf3SAxel Dörfler 
142741281cf3SAxel Dörfler 		if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) != 0) {
142841281cf3SAxel Dörfler 			fPreviousPosition = thePoint;
142941281cf3SAxel Dörfler 			SetTracking(true);
143041281cf3SAxel Dörfler 			SetMouseEventMask(B_POINTER_EVENTS,
143141281cf3SAxel Dörfler 				B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS);
143241281cf3SAxel Dörfler 			Invalidate(DragRegion());
143341281cf3SAxel Dörfler 			break;
143441281cf3SAxel Dörfler 		}
143541281cf3SAxel Dörfler 
143641281cf3SAxel Dörfler 		snooze(25000);
143741281cf3SAxel Dörfler 	}
143841281cf3SAxel Dörfler }
143941281cf3SAxel Dörfler 
144041281cf3SAxel Dörfler 
144141281cf3SAxel Dörfler void
144241281cf3SAxel Dörfler TDragRegion::MouseUp(BPoint pt)
144341281cf3SAxel Dörfler {
144441281cf3SAxel Dörfler 	if (IsTracking()) {
144541281cf3SAxel Dörfler 		SetTracking(false);
144641281cf3SAxel Dörfler 		Invalidate(DragRegion());
144741281cf3SAxel Dörfler 	} else
144841281cf3SAxel Dörfler 		BControl::MouseUp(pt);
144941281cf3SAxel Dörfler }
145041281cf3SAxel Dörfler 
145141281cf3SAxel Dörfler 
145241281cf3SAxel Dörfler bool
145341281cf3SAxel Dörfler TDragRegion::SwitchModeForRect(BPoint mouse, BRect rect,
145441281cf3SAxel Dörfler 	bool newVertical, bool newLeft, bool newTop, int32 newState)
145541281cf3SAxel Dörfler {
14561ad8c760SFredrik Holmqvist 	if (!rect.Contains(mouse)) {
145741281cf3SAxel Dörfler 		// not our rect
145841281cf3SAxel Dörfler 		return false;
14591ad8c760SFredrik Holmqvist 	}
146041281cf3SAxel Dörfler 
14611ad8c760SFredrik Holmqvist 	if (newVertical == fBarView->Vertical() && newLeft == fBarView->Left()
14621ad8c760SFredrik Holmqvist 		&& newTop == fBarView->Top() && newState == fBarView->State()) {
146341281cf3SAxel Dörfler 		// already in the correct mode
146441281cf3SAxel Dörfler 		return true;
14651ad8c760SFredrik Holmqvist 	}
146641281cf3SAxel Dörfler 
146741281cf3SAxel Dörfler 	fBarView->ChangeState(newState, newVertical, newLeft, newTop);
146841281cf3SAxel Dörfler 	return true;
146941281cf3SAxel Dörfler }
147041281cf3SAxel Dörfler 
147141281cf3SAxel Dörfler 
147241281cf3SAxel Dörfler void
147341281cf3SAxel Dörfler TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage* message)
147441281cf3SAxel Dörfler {
147541281cf3SAxel Dörfler 	if (IsTracking()) {
147641281cf3SAxel Dörfler 		BScreen screen;
147741281cf3SAxel Dörfler 		BRect frame = screen.Frame();
147841281cf3SAxel Dörfler 
147941281cf3SAxel Dörfler 		float hDivider = frame.Width() / 6;
148071bd3ba5SJonas Sundström 		hDivider = (hDivider < sMinimumWindowWidth + 10.0f)
148171bd3ba5SJonas Sundström 			? sMinimumWindowWidth + 10.0f : hDivider;
148241281cf3SAxel Dörfler 		float miniDivider = frame.top + kMiniHeight + 10.0f;
148341281cf3SAxel Dörfler 		float vDivider = frame.Height() / 2;
148441281cf3SAxel Dörfler #ifdef FULL_MODE
148541281cf3SAxel Dörfler 		float thirdScreen = frame.Height() / 3;
148641281cf3SAxel Dörfler #endif
148771bd3ba5SJonas Sundström 		BRect topLeft(frame.left, frame.top, frame.left + hDivider,
148871bd3ba5SJonas Sundström 			miniDivider);
148971bd3ba5SJonas Sundström 		BRect topMiddle(frame.left + hDivider, frame.top, frame.right
149071bd3ba5SJonas Sundström 			- hDivider, vDivider);
149171bd3ba5SJonas Sundström 		BRect topRight(frame.right - hDivider, frame.top, frame.right,
149271bd3ba5SJonas Sundström 			miniDivider);
149341281cf3SAxel Dörfler 
149441281cf3SAxel Dörfler #ifdef FULL_MODE
149541281cf3SAxel Dörfler 		vDivider = miniDivider + thirdScreen;
149641281cf3SAxel Dörfler #endif
149771bd3ba5SJonas Sundström 		BRect middleLeft(frame.left, miniDivider, frame.left + hDivider,
149871bd3ba5SJonas Sundström 			vDivider);
149971bd3ba5SJonas Sundström 		BRect middleRight(frame.right - hDivider, miniDivider, frame.right,
150071bd3ba5SJonas Sundström 			vDivider);
150141281cf3SAxel Dörfler 
150241281cf3SAxel Dörfler #ifdef FULL_MODE
150371bd3ba5SJonas Sundström 		BRect leftSide(frame.left, vDivider, frame.left + hDivider,
150471bd3ba5SJonas Sundström 			frame.bottom - thirdScreen);
150571bd3ba5SJonas Sundström 		BRect rightSide(frame.right - hDivider, vDivider, frame.right,
150671bd3ba5SJonas Sundström 			frame.bottom - thirdScreen);
150741281cf3SAxel Dörfler 
150841281cf3SAxel Dörfler 		vDivider = frame.bottom - thirdScreen;
150941281cf3SAxel Dörfler #endif
151071bd3ba5SJonas Sundström 		BRect bottomLeft(frame.left, vDivider, frame.left + hDivider,
151171bd3ba5SJonas Sundström 			frame.bottom);
151271bd3ba5SJonas Sundström 		BRect bottomMiddle(frame.left + hDivider, vDivider, frame.right
151371bd3ba5SJonas Sundström 			- hDivider, frame.bottom);
151471bd3ba5SJonas Sundström 		BRect bottomRight(frame.right - hDivider, vDivider, frame.right,
151571bd3ba5SJonas Sundström 			frame.bottom);
151641281cf3SAxel Dörfler 
151741281cf3SAxel Dörfler 		if (where != fPreviousPosition) {
151841281cf3SAxel Dörfler 			fPreviousPosition = where;
151941281cf3SAxel Dörfler 			ConvertToScreen(&where);
152041281cf3SAxel Dörfler 
152141281cf3SAxel Dörfler 			// use short circuit evaluation for convenience
152241281cf3SAxel Dörfler 			if (SwitchModeForRect(where, topLeft, true, true, true, kMiniState)
152371bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, topMiddle, false, true, true,
152471bd3ba5SJonas Sundström 					kExpandoState)
152571bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, topRight, true, false, true,
152671bd3ba5SJonas Sundström 					kMiniState)
152771bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, middleLeft, true, true, true,
152871bd3ba5SJonas Sundström 					kExpandoState)
152971bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, middleRight, true, false, true,
153071bd3ba5SJonas Sundström 					kExpandoState)
153141281cf3SAxel Dörfler 
153241281cf3SAxel Dörfler #ifdef FULL_MODE
153371bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, leftSide, true, true, true,
153471bd3ba5SJonas Sundström 					kFullState)
153571bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, rightSide, true, false, true,
153671bd3ba5SJonas Sundström 					kFullState)
153741281cf3SAxel Dörfler #endif
153871bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, bottomLeft, true, true, false,
153971bd3ba5SJonas Sundström 					kMiniState)
154071bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, bottomMiddle, false, true, false,
154171bd3ba5SJonas Sundström 					kExpandoState)
154271bd3ba5SJonas Sundström 				|| SwitchModeForRect(where, bottomRight, true, false, false,
154371bd3ba5SJonas Sundström 					kMiniState))
154441281cf3SAxel Dörfler 				;
154541281cf3SAxel Dörfler 		}
154641281cf3SAxel Dörfler 	} else
154741281cf3SAxel Dörfler 		BControl::MouseMoved(where, code, message);
154841281cf3SAxel Dörfler }
154941281cf3SAxel Dörfler 
155041281cf3SAxel Dörfler 
155141281cf3SAxel Dörfler int32
155241281cf3SAxel Dörfler TDragRegion::DragRegionLocation() const
155341281cf3SAxel Dörfler {
155441281cf3SAxel Dörfler 	return fDragLocation;
155541281cf3SAxel Dörfler }
155641281cf3SAxel Dörfler 
155741281cf3SAxel Dörfler 
155841281cf3SAxel Dörfler void
155941281cf3SAxel Dörfler TDragRegion::SetDragRegionLocation(int32 location)
156041281cf3SAxel Dörfler {
156141281cf3SAxel Dörfler 	if (location == fDragLocation)
156241281cf3SAxel Dörfler 		return;
156341281cf3SAxel Dörfler 
156441281cf3SAxel Dörfler 	fDragLocation = location;
156541281cf3SAxel Dörfler 	Invalidate();
156641281cf3SAxel Dörfler }
156741281cf3SAxel Dörfler 
1568