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 <Debug.h> 4841281cf3SAxel Dörfler #include <Application.h> 4941281cf3SAxel Dörfler #include <Beep.h> 5041281cf3SAxel Dörfler #include <Directory.h> 5141281cf3SAxel Dörfler #include <FindDirectory.h> 5241281cf3SAxel Dörfler #include <MenuItem.h> 5341281cf3SAxel Dörfler #include <NodeInfo.h> 5441281cf3SAxel Dörfler #include <NodeMonitor.h> 5541281cf3SAxel Dörfler #include <Path.h> 5641281cf3SAxel Dörfler #include <PopUpMenu.h> 5741281cf3SAxel Dörfler #include <Roster.h> 5841281cf3SAxel Dörfler #include <Screen.h> 5941281cf3SAxel Dörfler #include <Volume.h> 6041281cf3SAxel Dörfler #include <VolumeRoster.h> 6141281cf3SAxel Dörfler #include <Window.h> 6241281cf3SAxel Dörfler 6341281cf3SAxel Dörfler #include "DeskBarUtils.h" 6441281cf3SAxel Dörfler #include "StatusView.h" 6541281cf3SAxel Dörfler #include "StatusViewShelf.h" 6641281cf3SAxel Dörfler #include "TimeView.h" 6741281cf3SAxel Dörfler #include "BarApp.h" 6841281cf3SAxel Dörfler 696d01b66dSAxel Dörfler using std::max; 7041281cf3SAxel Dörfler 7141281cf3SAxel Dörfler #ifdef DB_ADDONS 7241281cf3SAxel Dörfler // Add-on support 7341281cf3SAxel Dörfler // 7441281cf3SAxel Dörfler // Item - internal item list (node, eref, etc) 7541281cf3SAxel Dörfler // Icon - physical replicant handed to the DeskbarClass class 7641281cf3SAxel Dörfler // AddOn - attribute based add-on 7741281cf3SAxel Dörfler 7841281cf3SAxel Dörfler const char *const kInstantiateItemCFunctionName = "instantiate_deskbar_item"; 7941281cf3SAxel Dörfler const char *const kInstantiateEntryCFunctionName = "instantiate_deskbar_entry"; 8041281cf3SAxel Dörfler const char *const kDeskbarSecurityCodeFile = "Deskbar_security_code"; 8141281cf3SAxel Dörfler const char *const kDeskbarSecurityCodeAttr = "be:deskbar_security_code"; 8241281cf3SAxel Dörfler const char *const kStatusPredicate = "be:deskbar_item_status"; 8341281cf3SAxel Dörfler const char *const kEnabledPredicate = "be:deskbar_item_status=enabled"; 8441281cf3SAxel Dörfler const char *const kDisabledPredicate = "be:deskbar_item_status=disabled"; 8541281cf3SAxel Dörfler 8641281cf3SAxel Dörfler 8741281cf3SAxel Dörfler static void 8841281cf3SAxel Dörfler DumpItem(DeskbarItemInfo *item) 8941281cf3SAxel Dörfler { 9041281cf3SAxel Dörfler printf("is addon: %i, id: %li\n", item->isAddOn, item->id); 9141281cf3SAxel Dörfler printf("entry_ref: %ld, %Ld, %s\n", item->entryRef.device, item->entryRef.directory, item->entryRef.name); 9241281cf3SAxel Dörfler printf("node_ref: %ld, %Ld\n", item->nodeRef.device, item->nodeRef.node); 9341281cf3SAxel Dörfler } 9441281cf3SAxel Dörfler 9541281cf3SAxel Dörfler 9641281cf3SAxel Dörfler static void 9741281cf3SAxel Dörfler DumpList(BList *itemlist) 9841281cf3SAxel Dörfler { 9941281cf3SAxel Dörfler int32 count = itemlist->CountItems() - 1; 10041281cf3SAxel Dörfler if (count < 0) { 10141281cf3SAxel Dörfler printf("no items in list\n"); 10241281cf3SAxel Dörfler return; 10341281cf3SAxel Dörfler } 10441281cf3SAxel Dörfler for (int32 i = count ; i >= 0 ; i--) { 10541281cf3SAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo*)itemlist->ItemAt(i); 10641281cf3SAxel Dörfler if (!item) 10741281cf3SAxel Dörfler continue; 10841281cf3SAxel Dörfler 10941281cf3SAxel Dörfler DumpItem(item); 11041281cf3SAxel Dörfler } 11141281cf3SAxel Dörfler } 11241281cf3SAxel Dörfler #endif /* DB_ADDONS */ 11341281cf3SAxel Dörfler 11441281cf3SAxel Dörfler 1157da06231SAxel Dörfler // don't change the name of this view to anything other than "Status"! 1167da06231SAxel Dörfler 11741281cf3SAxel Dörfler TReplicantTray::TReplicantTray(TBarView *parent, bool vertical) 11841281cf3SAxel Dörfler : BView(BRect(0, 0, 1, 1), "Status", B_FOLLOW_LEFT | B_FOLLOW_TOP, 11941281cf3SAxel Dörfler B_WILL_DRAW | B_FRAME_EVENTS), 12041281cf3SAxel Dörfler fClock(NULL), 12141281cf3SAxel Dörfler fBarView(parent), 12241281cf3SAxel Dörfler fShelf(new TReplicantShelf(this)), 12341281cf3SAxel Dörfler fMultiRowMode(vertical), 12441281cf3SAxel Dörfler fAlignmentSupport(false) 12541281cf3SAxel Dörfler { 12641281cf3SAxel Dörfler } 12741281cf3SAxel Dörfler 12841281cf3SAxel Dörfler 12941281cf3SAxel Dörfler TReplicantTray::~TReplicantTray() 13041281cf3SAxel Dörfler { 13141281cf3SAxel Dörfler delete fShelf; 13241281cf3SAxel Dörfler } 13341281cf3SAxel Dörfler 13441281cf3SAxel Dörfler 13541281cf3SAxel Dörfler void 13641281cf3SAxel Dörfler TReplicantTray::AttachedToWindow() 13741281cf3SAxel Dörfler { 13841281cf3SAxel Dörfler BView::AttachedToWindow(); 13941281cf3SAxel Dörfler 14041281cf3SAxel Dörfler SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); 14141281cf3SAxel Dörfler SetDrawingMode(B_OP_COPY); 14241281cf3SAxel Dörfler Window()->SetPulseRate(1000000); 14341281cf3SAxel Dörfler DealWithClock(fBarView->ShowingClock()); 14441281cf3SAxel Dörfler 14541281cf3SAxel Dörfler #ifdef DB_ADDONS 14641281cf3SAxel Dörfler // load addons and rehydrate archives 1473a6add49SAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 14841281cf3SAxel Dörfler InitAddOnSupport(); 14941281cf3SAxel Dörfler #endif 1509c910f9eSStephan Aßmus #endif 15141281cf3SAxel Dörfler ResizeToPreferred(); 15241281cf3SAxel Dörfler } 15341281cf3SAxel Dörfler 15441281cf3SAxel Dörfler 15541281cf3SAxel Dörfler void 15641281cf3SAxel Dörfler TReplicantTray::DetachedFromWindow() 15741281cf3SAxel Dörfler { 15841281cf3SAxel Dörfler #ifdef DB_ADDONS 15941281cf3SAxel Dörfler // clean up add-on support 160465b54cdSAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 16141281cf3SAxel Dörfler DeleteAddOnSupport(); 16241281cf3SAxel Dörfler #endif 163465b54cdSAxel Dörfler #endif 16441281cf3SAxel Dörfler BView::DetachedFromWindow(); 16541281cf3SAxel Dörfler } 16641281cf3SAxel Dörfler 16741281cf3SAxel Dörfler 16841281cf3SAxel Dörfler void 16941281cf3SAxel Dörfler TReplicantTray::RememberClockSettings() 17041281cf3SAxel Dörfler { 17141281cf3SAxel Dörfler if (fClock) { 17241281cf3SAxel Dörfler desk_settings *settings = ((TBarApp *)be_app)->Settings(); 17341281cf3SAxel Dörfler 17441281cf3SAxel Dörfler settings->timeShowSeconds = fClock->ShowingSeconds(); 17541281cf3SAxel Dörfler settings->timeShowMil = fClock->ShowingMilTime(); 17641281cf3SAxel Dörfler settings->timeShowEuro = fClock->ShowingEuroDate(); 17741281cf3SAxel Dörfler settings->timeFullDate = fClock->ShowingFullDate(); 17841281cf3SAxel Dörfler } 17941281cf3SAxel Dörfler } 18041281cf3SAxel Dörfler 18141281cf3SAxel Dörfler 18241281cf3SAxel Dörfler bool 18341281cf3SAxel Dörfler TReplicantTray::ShowingSeconds() 18441281cf3SAxel Dörfler { 18541281cf3SAxel Dörfler if (fClock) 18641281cf3SAxel Dörfler return fClock->ShowingSeconds(); 18741281cf3SAxel Dörfler return false; 18841281cf3SAxel Dörfler } 18941281cf3SAxel Dörfler 19041281cf3SAxel Dörfler 19141281cf3SAxel Dörfler bool 19241281cf3SAxel Dörfler TReplicantTray::ShowingMiltime() 19341281cf3SAxel Dörfler { 19441281cf3SAxel Dörfler if (fClock) 19541281cf3SAxel Dörfler return fClock->ShowingMilTime(); 19641281cf3SAxel Dörfler return false; 19741281cf3SAxel Dörfler } 19841281cf3SAxel Dörfler 19941281cf3SAxel Dörfler 20041281cf3SAxel Dörfler bool 20141281cf3SAxel Dörfler TReplicantTray::ShowingEuroDate() 20241281cf3SAxel Dörfler { 20341281cf3SAxel Dörfler if (fClock) 20441281cf3SAxel Dörfler return fClock->ShowingEuroDate(); 20541281cf3SAxel Dörfler return false; 20641281cf3SAxel Dörfler } 20741281cf3SAxel Dörfler 20841281cf3SAxel Dörfler 20941281cf3SAxel Dörfler bool 21041281cf3SAxel Dörfler TReplicantTray::ShowingFullDate() 21141281cf3SAxel Dörfler { 21241281cf3SAxel Dörfler if (fClock && CanShowFullDate()) 21341281cf3SAxel Dörfler return fClock->ShowingFullDate(); 21441281cf3SAxel Dörfler return false; 21541281cf3SAxel Dörfler } 21641281cf3SAxel Dörfler 21741281cf3SAxel Dörfler 21841281cf3SAxel Dörfler bool 21941281cf3SAxel Dörfler TReplicantTray::CanShowFullDate() 22041281cf3SAxel Dörfler { 22141281cf3SAxel Dörfler if (fClock) 22241281cf3SAxel Dörfler return fClock->CanShowFullDate(); 22341281cf3SAxel Dörfler return false; 22441281cf3SAxel Dörfler } 22541281cf3SAxel Dörfler 22641281cf3SAxel Dörfler 22741281cf3SAxel Dörfler void 22841281cf3SAxel Dörfler TReplicantTray::DealWithClock(bool showClock) 22941281cf3SAxel Dörfler { 23041281cf3SAxel Dörfler fBarView->ShowClock(showClock); 23141281cf3SAxel Dörfler 23241281cf3SAxel Dörfler if (showClock) { 23341281cf3SAxel Dörfler if (!fClock) { 23441281cf3SAxel Dörfler desk_settings *settings = ((TBarApp *)be_app)->Settings(); 23541281cf3SAxel Dörfler 23641281cf3SAxel Dörfler fClock = new TTimeView(settings->timeShowSeconds, settings->timeShowMil, 23741281cf3SAxel Dörfler settings->timeFullDate, settings->timeShowEuro, false); 23841281cf3SAxel Dörfler AddChild(fClock); 23941281cf3SAxel Dörfler 24041281cf3SAxel Dörfler fClock->MoveTo(Bounds().right - fClock->Bounds().Width() - 1, 2); 24141281cf3SAxel Dörfler fClock->AllowFullDate(!IsMultiRow()); 24241281cf3SAxel Dörfler } 24341281cf3SAxel Dörfler } else { 24441281cf3SAxel Dörfler if (fClock) { 24541281cf3SAxel Dörfler RememberClockSettings(); 24641281cf3SAxel Dörfler 24741281cf3SAxel Dörfler fClock->RemoveSelf(); 24841281cf3SAxel Dörfler delete fClock; 24941281cf3SAxel Dörfler fClock = NULL; 25041281cf3SAxel Dörfler } 25141281cf3SAxel Dörfler } 25241281cf3SAxel Dörfler } 25341281cf3SAxel Dörfler 25441281cf3SAxel Dörfler 25541281cf3SAxel Dörfler /** width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth 25641281cf3SAxel Dörfler * if not in multirowmode and greater than kMinimumReplicantCount 25741281cf3SAxel Dörfler * the width should be calculated based on the actual 25841281cf3SAxel Dörfler * replicant widths 25941281cf3SAxel Dörfler */ 26041281cf3SAxel Dörfler 26141281cf3SAxel Dörfler void 26241281cf3SAxel Dörfler TReplicantTray::GetPreferredSize(float *preferredWidth, float *preferredHeight) 26341281cf3SAxel Dörfler { 26441281cf3SAxel Dörfler float width = 0, height = kMinimumTrayHeight; 26541281cf3SAxel Dörfler 26641281cf3SAxel Dörfler if (fMultiRowMode) { 2677da06231SAxel Dörfler if (fShelf->CountReplicants() > 0) 2687da06231SAxel Dörfler height = fRightBottomReplicant.bottom; 26941281cf3SAxel Dörfler 27041281cf3SAxel Dörfler // the height will be uniform for the number of rows 27141281cf3SAxel Dörfler // necessary to show all the reps + any gutters 27241281cf3SAxel Dörfler // necessary for spacing 27341281cf3SAxel Dörfler int32 rowCount = (int32)(height / kMaxReplicantHeight); 27441281cf3SAxel Dörfler height = kGutter + (rowCount * kMaxReplicantHeight) 27541281cf3SAxel Dörfler + ((rowCount - 1) * kIconGap) + kGutter; 27641281cf3SAxel Dörfler height = max(kMinimumTrayHeight, height); 27741281cf3SAxel Dörfler width = kMinimumTrayWidth; 27841281cf3SAxel Dörfler } else { 27941281cf3SAxel Dörfler // if last replicant overruns clock then 28041281cf3SAxel Dörfler // resize to accomodate 2817da06231SAxel Dörfler if (fShelf->CountReplicants() > 0) { 28241281cf3SAxel Dörfler if (fBarView->ShowingClock() 2837da06231SAxel Dörfler && fRightBottomReplicant.right + 6 >= fClock->Frame().left) { 2847da06231SAxel Dörfler width = fRightBottomReplicant.right + 6 + fClock->Frame().Width(); 28541281cf3SAxel Dörfler } else 2867da06231SAxel Dörfler width = fRightBottomReplicant.right + 3; 28741281cf3SAxel Dörfler } 28841281cf3SAxel Dörfler // this view has a fixed minimum width 28941281cf3SAxel Dörfler width = max(kMinimumTrayWidth, width); 29041281cf3SAxel Dörfler } 29141281cf3SAxel Dörfler 29241281cf3SAxel Dörfler *preferredWidth = width; 29341281cf3SAxel Dörfler // add 2 for the border 29441281cf3SAxel Dörfler *preferredHeight = height + 1; 29541281cf3SAxel Dörfler } 29641281cf3SAxel Dörfler 29741281cf3SAxel Dörfler 29841281cf3SAxel Dörfler void 29941281cf3SAxel Dörfler TReplicantTray::AdjustPlacement() 30041281cf3SAxel Dörfler { 30141281cf3SAxel Dörfler // called when an add-on has been added or removed 30241281cf3SAxel Dörfler // need to resize the parent of this accordingly 30341281cf3SAxel Dörfler // 30441281cf3SAxel Dörfler // call to Parent will call ResizeToPreferred 30541281cf3SAxel Dörfler BRect bounds = Bounds(); 30641281cf3SAxel Dörfler float width, height; 30741281cf3SAxel Dörfler GetPreferredSize(&width, &height); 30841281cf3SAxel Dörfler 30941281cf3SAxel Dörfler if (width == bounds.Width() && height == bounds.Height()) { 31041281cf3SAxel Dörfler // no need to change anything 31141281cf3SAxel Dörfler return; 31241281cf3SAxel Dörfler } 31341281cf3SAxel Dörfler 31441281cf3SAxel Dörfler Parent()->ResizeToPreferred(); 31541281cf3SAxel Dörfler fBarView->UpdatePlacement(); 31641281cf3SAxel Dörfler Parent()->Invalidate(); 31741281cf3SAxel Dörfler Invalidate(); 31841281cf3SAxel Dörfler } 31941281cf3SAxel Dörfler 32041281cf3SAxel Dörfler 32141281cf3SAxel Dörfler void 32241281cf3SAxel Dörfler TReplicantTray::Draw(BRect) 32341281cf3SAxel Dörfler { 32441281cf3SAxel Dörfler rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR); 32541281cf3SAxel Dörfler rgb_color vdark = tint_color(menuColor, B_DARKEN_3_TINT); 32641281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 32741281cf3SAxel Dörfler 32841281cf3SAxel Dörfler BRect frame(Bounds()); 32941281cf3SAxel Dörfler 33041281cf3SAxel Dörfler SetHighColor(light); 33141281cf3SAxel Dörfler StrokeLine(frame.LeftBottom(), frame.RightBottom()); 33241281cf3SAxel Dörfler StrokeLine(frame.RightBottom(), frame.RightTop()); 33341281cf3SAxel Dörfler 33441281cf3SAxel Dörfler SetHighColor(vdark); 33541281cf3SAxel Dörfler StrokeLine(frame.RightTop(), frame.LeftTop()); 33641281cf3SAxel Dörfler StrokeLine(frame.LeftTop(), frame.LeftBottom()); 33741281cf3SAxel Dörfler } 33841281cf3SAxel Dörfler 33941281cf3SAxel Dörfler 34041281cf3SAxel Dörfler void 34141281cf3SAxel Dörfler TReplicantTray::MessageReceived(BMessage *message) 34241281cf3SAxel Dörfler { 34341281cf3SAxel Dörfler switch (message->what) { 34441281cf3SAxel Dörfler case 'time': 34541281cf3SAxel Dörfler // from context menu in clock and in this view 34641281cf3SAxel Dörfler DealWithClock(!fBarView->ShowingClock()); 34741281cf3SAxel Dörfler RealignReplicants(); 34841281cf3SAxel Dörfler AdjustPlacement(); 34941281cf3SAxel Dörfler break; 35041281cf3SAxel Dörfler 35141281cf3SAxel Dörfler case 'trfm': 35241281cf3SAxel Dörfler // time string reformat -> realign 35341281cf3SAxel Dörfler DealWithClock(fBarView->ShowingClock()); 35441281cf3SAxel Dörfler RealignReplicants(); 35541281cf3SAxel Dörfler AdjustPlacement(); 35641281cf3SAxel Dörfler break; 35741281cf3SAxel Dörfler 35841281cf3SAxel Dörfler case kMsgShowSeconds: 35941281cf3SAxel Dörfler case kMsgMilTime: 36041281cf3SAxel Dörfler case kMsgEuroDate: 36141281cf3SAxel Dörfler case kMsgFullDate: 36241281cf3SAxel Dörfler if (fClock != NULL) 36341281cf3SAxel Dörfler Window()->PostMessage(message, fClock); 36441281cf3SAxel Dörfler break; 36541281cf3SAxel Dörfler 36641281cf3SAxel Dörfler #ifdef DB_ADDONS 36741281cf3SAxel Dörfler case B_NODE_MONITOR: 36841281cf3SAxel Dörfler case B_QUERY_UPDATE: 36941281cf3SAxel Dörfler HandleEntryUpdate(message); 37041281cf3SAxel Dörfler break; 37141281cf3SAxel Dörfler #endif 37241281cf3SAxel Dörfler 37341281cf3SAxel Dörfler default: 37441281cf3SAxel Dörfler BView::MessageReceived(message); 37541281cf3SAxel Dörfler break; 37641281cf3SAxel Dörfler } 37741281cf3SAxel Dörfler } 37841281cf3SAxel Dörfler 37941281cf3SAxel Dörfler 38041281cf3SAxel Dörfler void 38141281cf3SAxel Dörfler TReplicantTray::ShowReplicantMenu(BPoint point) 38241281cf3SAxel Dörfler { 38341281cf3SAxel Dörfler BPopUpMenu *menu = new BPopUpMenu("", false, false); 38441281cf3SAxel Dörfler menu->SetFont(be_plain_font); 38541281cf3SAxel Dörfler 38641281cf3SAxel Dörfler // If the clock is visible, show the extended menu 38741281cf3SAxel Dörfler // otheriwse, show "Show Time". 38841281cf3SAxel Dörfler 38941281cf3SAxel Dörfler if (fBarView->ShowingClock()) 39041281cf3SAxel Dörfler fClock->ShowClockOptions(ConvertToScreen(point)); 39141281cf3SAxel Dörfler else { 39241281cf3SAxel Dörfler BMenuItem *item = new BMenuItem("Show Time", new BMessage('time')); 39341281cf3SAxel Dörfler menu->AddItem(item); 39441281cf3SAxel Dörfler menu->SetTargetForItems(this); 39541281cf3SAxel Dörfler BPoint where = ConvertToScreen(point); 39641281cf3SAxel Dörfler menu->Go(where, true, true, BRect(where - BPoint(4, 4), 39741281cf3SAxel Dörfler where + BPoint(4, 4)), true); 39841281cf3SAxel Dörfler } 39941281cf3SAxel Dörfler } 40041281cf3SAxel Dörfler 40141281cf3SAxel Dörfler 40241281cf3SAxel Dörfler void 40341281cf3SAxel Dörfler TReplicantTray::MouseDown(BPoint where) 40441281cf3SAxel Dörfler { 40541281cf3SAxel Dörfler #ifdef DB_ADDONS 40641281cf3SAxel Dörfler if (modifiers() & B_CONTROL_KEY) 40741281cf3SAxel Dörfler DumpList(fItemList); 40841281cf3SAxel Dörfler #endif 40941281cf3SAxel Dörfler 41041281cf3SAxel Dörfler uint32 buttons; 41141281cf3SAxel Dörfler 41241281cf3SAxel Dörfler Window()->CurrentMessage()->FindInt32("buttons", (int32 *)&buttons); 41341281cf3SAxel Dörfler if (buttons == B_SECONDARY_MOUSE_BUTTON) { 41441281cf3SAxel Dörfler ShowReplicantMenu(where); 41541281cf3SAxel Dörfler } else { 41641281cf3SAxel Dörfler BPoint save = where; 41741281cf3SAxel Dörfler bigtime_t doubleClickSpeed; 41841281cf3SAxel Dörfler bigtime_t start = system_time(); 41941281cf3SAxel Dörfler uint32 buttons; 42041281cf3SAxel Dörfler 42141281cf3SAxel Dörfler get_click_speed(&doubleClickSpeed); 42241281cf3SAxel Dörfler 42341281cf3SAxel Dörfler do { 42441281cf3SAxel Dörfler if (fabs(where.x - save.x) > 4 || fabs(where.y - save.y) > 4) 42541281cf3SAxel Dörfler // user moved out of bounds of click area 42641281cf3SAxel Dörfler break; 42741281cf3SAxel Dörfler 42841281cf3SAxel Dörfler if ((system_time() - start) > (2 * doubleClickSpeed)) { 42941281cf3SAxel Dörfler ShowReplicantMenu(where); 43041281cf3SAxel Dörfler break; 43141281cf3SAxel Dörfler } 43241281cf3SAxel Dörfler 43341281cf3SAxel Dörfler snooze(50000); 43441281cf3SAxel Dörfler GetMouse(&where, &buttons); 43541281cf3SAxel Dörfler } while (buttons); 43641281cf3SAxel Dörfler } 43741281cf3SAxel Dörfler BView::MouseDown(where); 43841281cf3SAxel Dörfler } 43941281cf3SAxel Dörfler 44041281cf3SAxel Dörfler #ifdef DB_ADDONS 44141281cf3SAxel Dörfler 44241281cf3SAxel Dörfler void 44341281cf3SAxel Dörfler TReplicantTray::InitAddOnSupport() 44441281cf3SAxel Dörfler { 44541281cf3SAxel Dörfler // list to maintain refs to each rep added/deleted 44641281cf3SAxel Dörfler fItemList = new BList(); 44741281cf3SAxel Dörfler 44841281cf3SAxel Dörfler bool haveKey = false; 44941281cf3SAxel Dörfler BPath path; 45041281cf3SAxel Dörfler if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) { 45141281cf3SAxel Dörfler path.Append(kDeskbarSecurityCodeFile); 45241281cf3SAxel Dörfler 45341281cf3SAxel Dörfler BFile file(path.Path(),B_READ_ONLY); 45441281cf3SAxel Dörfler if (file.InitCheck() == B_OK 45541281cf3SAxel Dörfler && file.Read(&fDeskbarSecurityCode, 45641281cf3SAxel Dörfler sizeof(fDeskbarSecurityCode)) == sizeof(fDeskbarSecurityCode)) 45741281cf3SAxel Dörfler haveKey = true; 45841281cf3SAxel Dörfler } 45941281cf3SAxel Dörfler if (!haveKey) { 46041281cf3SAxel Dörfler // create the security code 46141281cf3SAxel Dörfler bigtime_t real = real_time_clock_usecs(); 46241281cf3SAxel Dörfler bigtime_t boot = system_time(); 46341281cf3SAxel Dörfler // two computers would have to have exactly matching clocks, and launch 46441281cf3SAxel Dörfler // Deskbar at the exact same time into the bootsequence in order for their 46541281cf3SAxel Dörfler // security-ID to be identical 46641281cf3SAxel Dörfler fDeskbarSecurityCode = ((real&0xffffffffULL)<<32)|(boot&0xffffffffULL); 46741281cf3SAxel Dörfler 46841281cf3SAxel Dörfler if (find_directory (B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) { 46941281cf3SAxel Dörfler path.Append(kDeskbarSecurityCodeFile); 47041281cf3SAxel Dörfler BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); 47141281cf3SAxel Dörfler if (file.InitCheck() == B_OK) 47241281cf3SAxel Dörfler file.Write(&fDeskbarSecurityCode, sizeof(fDeskbarSecurityCode)); 47341281cf3SAxel Dörfler } 47441281cf3SAxel Dörfler } 47541281cf3SAxel Dörfler 47641281cf3SAxel Dörfler // for each volume currently mounted 47741281cf3SAxel Dörfler // index the volume with our indices 47841281cf3SAxel Dörfler BVolumeRoster roster; 47941281cf3SAxel Dörfler BVolume volume; 48041281cf3SAxel Dörfler while (roster.GetNextVolume(&volume) == B_OK) { 48141281cf3SAxel Dörfler fs_create_index(volume.Device(), kStatusPredicate, B_STRING_TYPE, 0); 48241281cf3SAxel Dörfler RunAddOnQuery(&volume, kEnabledPredicate); 48341281cf3SAxel Dörfler } 48441281cf3SAxel Dörfler 48541281cf3SAxel Dörfler // we also watch for volumes mounted and unmounted 48641281cf3SAxel Dörfler watch_node(NULL, B_WATCH_MOUNT | B_WATCH_ATTR, this, Window()); 48741281cf3SAxel Dörfler } 48841281cf3SAxel Dörfler 48941281cf3SAxel Dörfler 49041281cf3SAxel Dörfler void 49141281cf3SAxel Dörfler TReplicantTray::DeleteAddOnSupport() 49241281cf3SAxel Dörfler { 49341281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 49441281cf3SAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo *)fItemList->RemoveItem(i); 49541281cf3SAxel Dörfler if (item) { 49641281cf3SAxel Dörfler if (item->isAddOn) 49741281cf3SAxel Dörfler watch_node(&(item->nodeRef), B_STOP_WATCHING, this, Window()); 49841281cf3SAxel Dörfler 49941281cf3SAxel Dörfler delete item; 50041281cf3SAxel Dörfler } 50141281cf3SAxel Dörfler } 50241281cf3SAxel Dörfler delete fItemList; 50341281cf3SAxel Dörfler 50441281cf3SAxel Dörfler // stop the volume mount/unmount watch 50541281cf3SAxel Dörfler stop_watching(this, Window()); 50641281cf3SAxel Dörfler } 50741281cf3SAxel Dörfler 50841281cf3SAxel Dörfler 50941281cf3SAxel Dörfler void 51041281cf3SAxel Dörfler TReplicantTray::RunAddOnQuery(BVolume *volume, const char *predicate) 51141281cf3SAxel Dörfler { 51241281cf3SAxel Dörfler // Since the new BFS supports querying for attributes without 51341281cf3SAxel Dörfler // an index, we only run the query if the index exists (for 51441281cf3SAxel Dörfler // newly mounted devices only - the Deskbar will automatically 51541281cf3SAxel Dörfler // create an index for every device mounted at startup). 51641281cf3SAxel Dörfler index_info info; 51741281cf3SAxel Dörfler if (!volume->KnowsQuery() || fs_stat_index(volume->Device(),kStatusPredicate,&info) != 0) 51841281cf3SAxel Dörfler return; 51941281cf3SAxel Dörfler 52041281cf3SAxel Dörfler // run a new query on a specific volume 52141281cf3SAxel Dörfler // make it live 52241281cf3SAxel Dörfler BQuery query; 52341281cf3SAxel Dörfler query.SetVolume(volume); 52441281cf3SAxel Dörfler query.SetPredicate(predicate); 52541281cf3SAxel Dörfler query.Fetch(); 52641281cf3SAxel Dörfler 52741281cf3SAxel Dörfler int32 id; 52841281cf3SAxel Dörfler BEntry entry; 5297da06231SAxel Dörfler while (query.GetNextEntry(&entry) == B_OK) { 53041281cf3SAxel Dörfler // scan any entries returned 53141281cf3SAxel Dörfler // attempt to load them as add-ons 53241281cf3SAxel Dörfler // collisions are handled in LoadAddOn 53341281cf3SAxel Dörfler LoadAddOn(&entry, &id); 53441281cf3SAxel Dörfler } 5357da06231SAxel Dörfler } 53641281cf3SAxel Dörfler 53741281cf3SAxel Dörfler 53841281cf3SAxel Dörfler bool 53941281cf3SAxel Dörfler TReplicantTray::IsAddOn(entry_ref &ref) 54041281cf3SAxel Dörfler { 54141281cf3SAxel Dörfler BFile file(&ref, B_READ_ONLY); 54241281cf3SAxel Dörfler 54341281cf3SAxel Dörfler char status[64]; 54441281cf3SAxel Dörfler ssize_t size = file.ReadAttr(kStatusPredicate, B_STRING_TYPE, 0, &status, 64); 54541281cf3SAxel Dörfler return size > 0; 54641281cf3SAxel Dörfler } 54741281cf3SAxel Dörfler 54841281cf3SAxel Dörfler 54941281cf3SAxel Dörfler DeskbarItemInfo * 55041281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(node_ref &nodeRef) 55141281cf3SAxel Dörfler { 55241281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 55341281cf3SAxel Dörfler DeskbarItemInfo *item = static_cast<DeskbarItemInfo *>(fItemList->ItemAt(i)); 55441281cf3SAxel Dörfler if (item == NULL) 55541281cf3SAxel Dörfler continue; 55641281cf3SAxel Dörfler 55741281cf3SAxel Dörfler if (item->nodeRef == nodeRef) 55841281cf3SAxel Dörfler return item; 55941281cf3SAxel Dörfler } 56041281cf3SAxel Dörfler 56141281cf3SAxel Dörfler return NULL; 56241281cf3SAxel Dörfler } 56341281cf3SAxel Dörfler 56441281cf3SAxel Dörfler 56541281cf3SAxel Dörfler DeskbarItemInfo * 56641281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(int32 id) 56741281cf3SAxel Dörfler { 56841281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 56941281cf3SAxel Dörfler DeskbarItemInfo *item = static_cast<DeskbarItemInfo *>(fItemList->ItemAt(i)); 57041281cf3SAxel Dörfler if (item == NULL) 57141281cf3SAxel Dörfler continue; 57241281cf3SAxel Dörfler 57341281cf3SAxel Dörfler if (item->id == id) 57441281cf3SAxel Dörfler return item; 57541281cf3SAxel Dörfler } 57641281cf3SAxel Dörfler 57741281cf3SAxel Dörfler return NULL; 57841281cf3SAxel Dörfler } 57941281cf3SAxel Dörfler 58041281cf3SAxel Dörfler 58141281cf3SAxel Dörfler bool 58241281cf3SAxel Dörfler TReplicantTray::NodeExists(node_ref &nodeRef) 58341281cf3SAxel Dörfler { 58441281cf3SAxel Dörfler return DeskbarItemFor(nodeRef) != NULL; 58541281cf3SAxel Dörfler } 58641281cf3SAxel Dörfler 58741281cf3SAxel Dörfler 58841281cf3SAxel Dörfler /** This handles B_NODE_MONITOR & B_QUERY_UPDATE messages received 58941281cf3SAxel Dörfler * for the registered add-ons. 59041281cf3SAxel Dörfler */ 59141281cf3SAxel Dörfler 59241281cf3SAxel Dörfler void 59341281cf3SAxel Dörfler TReplicantTray::HandleEntryUpdate(BMessage *message) 59441281cf3SAxel Dörfler { 59541281cf3SAxel Dörfler int32 opcode; 59641281cf3SAxel Dörfler if (message->FindInt32("opcode", &opcode) != B_OK) 59741281cf3SAxel Dörfler return; 59841281cf3SAxel Dörfler 59941281cf3SAxel Dörfler BPath path; 60041281cf3SAxel Dörfler switch (opcode) { 60141281cf3SAxel Dörfler case B_ENTRY_CREATED: 60241281cf3SAxel Dörfler // entry was just listed, matches live query 60341281cf3SAxel Dörfler { 60441281cf3SAxel Dörfler const char *name; 60541281cf3SAxel Dörfler ino_t directory; 60641281cf3SAxel Dörfler dev_t device; 60741281cf3SAxel Dörfler // received when an app adds a ref to the 60841281cf3SAxel Dörfler // Deskbar add-ons folder 60941281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK 61041281cf3SAxel Dörfler && message->FindInt64("directory", &directory) == B_OK 61141281cf3SAxel Dörfler && message->FindInt32("device", &device) == B_OK) { 61241281cf3SAxel Dörfler entry_ref ref(device, directory, name); 61341281cf3SAxel Dörfler // see if this item has the attribute 61441281cf3SAxel Dörfler // that we expect 61541281cf3SAxel Dörfler if (IsAddOn(ref)) { 61641281cf3SAxel Dörfler int32 id; 61741281cf3SAxel Dörfler BEntry entry(&ref); 61841281cf3SAxel Dörfler LoadAddOn(&entry, &id); 61941281cf3SAxel Dörfler } 62041281cf3SAxel Dörfler } 62141281cf3SAxel Dörfler } 62241281cf3SAxel Dörfler break; 62341281cf3SAxel Dörfler 62441281cf3SAxel Dörfler case B_ATTR_CHANGED: 62541281cf3SAxel Dörfler // from node watch on individual items 62641281cf3SAxel Dörfler // (node_watch added in LoadAddOn) 62741281cf3SAxel Dörfler { 62841281cf3SAxel Dörfler node_ref nodeRef; 62941281cf3SAxel Dörfler if (message->FindInt32("device", &(nodeRef.device)) == B_OK 63041281cf3SAxel Dörfler && message->FindInt64("node", &(nodeRef.node)) == B_OK) { 63141281cf3SAxel Dörfler // get the add-on this is for 63241281cf3SAxel Dörfler DeskbarItemInfo *item = DeskbarItemFor(nodeRef); 63341281cf3SAxel Dörfler if (item == NULL) 63441281cf3SAxel Dörfler break; 63541281cf3SAxel Dörfler 63641281cf3SAxel Dörfler BFile file(&item->entryRef, B_READ_ONLY); 63741281cf3SAxel Dörfler 63841281cf3SAxel Dörfler char status[255]; 63941281cf3SAxel Dörfler ssize_t size = file.ReadAttr(kStatusPredicate, 64041281cf3SAxel Dörfler B_STRING_TYPE, 0, status, sizeof(status) - 1); 64141281cf3SAxel Dörfler status[sizeof(status) - 1] = '\0'; 64241281cf3SAxel Dörfler 64341281cf3SAxel Dörfler // attribute was removed 64441281cf3SAxel Dörfler if (size == B_ENTRY_NOT_FOUND) { 64541281cf3SAxel Dörfler // cleans up and removes node_watch 64641281cf3SAxel Dörfler UnloadAddOn(&nodeRef, NULL, true, false); 64741281cf3SAxel Dörfler } else if (!strcmp(status, "enable")) { 64841281cf3SAxel Dörfler int32 id; 64941281cf3SAxel Dörfler BEntry entry(&item->entryRef, true); 65041281cf3SAxel Dörfler LoadAddOn(&entry, &id); 65141281cf3SAxel Dörfler } 65241281cf3SAxel Dörfler } 65341281cf3SAxel Dörfler } 65441281cf3SAxel Dörfler break; 65541281cf3SAxel Dörfler 65641281cf3SAxel Dörfler case B_ENTRY_MOVED: 65741281cf3SAxel Dörfler { 65841281cf3SAxel Dörfler entry_ref ref; 65941281cf3SAxel Dörfler ino_t todirectory; 66041281cf3SAxel Dörfler ino_t node; 66141281cf3SAxel Dörfler const char *name; 66241281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK 66341281cf3SAxel Dörfler && message->FindInt64("from directory", &(ref.directory)) == B_OK 66441281cf3SAxel Dörfler && message->FindInt64("to directory", &todirectory) == B_OK 66541281cf3SAxel Dörfler && message->FindInt32("device", &(ref.device)) == B_OK 66641281cf3SAxel Dörfler && message->FindInt64("node", &node) == B_OK ) { 66741281cf3SAxel Dörfler 66841281cf3SAxel Dörfler if (!name) 66941281cf3SAxel Dörfler break; 67041281cf3SAxel Dörfler 67141281cf3SAxel Dörfler ref.set_name(name); 67241281cf3SAxel Dörfler // change the directory reference to 67341281cf3SAxel Dörfler // the new directory 67441281cf3SAxel Dörfler MoveItem(&ref, todirectory); 67541281cf3SAxel Dörfler } 67641281cf3SAxel Dörfler } 67741281cf3SAxel Dörfler break; 67841281cf3SAxel Dörfler 67941281cf3SAxel Dörfler case B_ENTRY_REMOVED: 68041281cf3SAxel Dörfler { 68141281cf3SAxel Dörfler // entry was rm'd from the device 68241281cf3SAxel Dörfler node_ref nodeRef; 68341281cf3SAxel Dörfler if (message->FindInt32("device", &(nodeRef.device)) == B_OK 68441281cf3SAxel Dörfler && message->FindInt64("node", &(nodeRef.node)) == B_OK) { 68541281cf3SAxel Dörfler DeskbarItemInfo *item = DeskbarItemFor(nodeRef); 68641281cf3SAxel Dörfler if (item == NULL) 68741281cf3SAxel Dörfler break; 68841281cf3SAxel Dörfler 68941281cf3SAxel Dörfler // If there is a team running where the add-on comes from, 69041281cf3SAxel Dörfler // we don't want to remove the icon yet. 69141281cf3SAxel Dörfler if (be_roster->IsRunning(&item->entryRef)) 69241281cf3SAxel Dörfler break; 69341281cf3SAxel Dörfler 69441281cf3SAxel Dörfler UnloadAddOn(&nodeRef, NULL, true, false); 69541281cf3SAxel Dörfler } 69641281cf3SAxel Dörfler } 69741281cf3SAxel Dörfler break; 69841281cf3SAxel Dörfler 69941281cf3SAxel Dörfler case B_DEVICE_MOUNTED: 70041281cf3SAxel Dörfler { 70141281cf3SAxel Dörfler // run a new query on the new device 70241281cf3SAxel Dörfler dev_t device; 70341281cf3SAxel Dörfler if (message->FindInt32("new device", &device) != B_OK) 70441281cf3SAxel Dörfler break; 70541281cf3SAxel Dörfler 70641281cf3SAxel Dörfler RunAddOnQuery(new BVolume(device), kEnabledPredicate); 70741281cf3SAxel Dörfler } 70841281cf3SAxel Dörfler break; 70941281cf3SAxel Dörfler case B_DEVICE_UNMOUNTED: 71041281cf3SAxel Dörfler { 71141281cf3SAxel Dörfler // remove all items associated with the device 71241281cf3SAxel Dörfler // unmounted 71341281cf3SAxel Dörfler // contrary to what the BeBook says, the item is called "device", 71441281cf3SAxel Dörfler // not "new device" like it is for B_DEVICE_MOUNTED 71541281cf3SAxel Dörfler dev_t device; 71641281cf3SAxel Dörfler if (message->FindInt32("device", &device) != B_OK) 71741281cf3SAxel Dörfler break; 71841281cf3SAxel Dörfler 71941281cf3SAxel Dörfler UnloadAddOn(NULL, &device, false, true); 72041281cf3SAxel Dörfler } 72141281cf3SAxel Dörfler break; 72241281cf3SAxel Dörfler } 72341281cf3SAxel Dörfler } 72441281cf3SAxel Dörfler 72541281cf3SAxel Dörfler 7267da06231SAxel Dörfler /** The add-ons must support the exported C function API 7277da06231SAxel Dörfler * if they do, they will be loaded and added to deskbar 7287da06231SAxel Dörfler * primary function is the Instantiate function 7297da06231SAxel Dörfler */ 73041281cf3SAxel Dörfler 73141281cf3SAxel Dörfler status_t 73241281cf3SAxel Dörfler TReplicantTray::LoadAddOn(BEntry *entry, int32 *id, bool force) 73341281cf3SAxel Dörfler { 73441281cf3SAxel Dörfler if (!entry) 73541281cf3SAxel Dörfler return B_ERROR; 73641281cf3SAxel Dörfler 73741281cf3SAxel Dörfler node_ref nodeRef; 73841281cf3SAxel Dörfler entry->GetNodeRef(&nodeRef); 73941281cf3SAxel Dörfler // no duplicates 74041281cf3SAxel Dörfler if (NodeExists(nodeRef)) 74141281cf3SAxel Dörfler return B_ERROR; 74241281cf3SAxel Dörfler 74341281cf3SAxel Dörfler BNode node(entry); 74441281cf3SAxel Dörfler if (!force) { 74541281cf3SAxel Dörfler status_t error = node.InitCheck(); 74641281cf3SAxel Dörfler if (error != B_OK) 74741281cf3SAxel Dörfler return error; 74841281cf3SAxel Dörfler 74941281cf3SAxel Dörfler uint64 deskbarID; 75041281cf3SAxel Dörfler ssize_t size = node.ReadAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, 0, 75141281cf3SAxel Dörfler &deskbarID, sizeof(fDeskbarSecurityCode)); 75241281cf3SAxel Dörfler if (size != sizeof(fDeskbarSecurityCode) || deskbarID != fDeskbarSecurityCode) { 75341281cf3SAxel Dörfler // no code or code doesn't match 75441281cf3SAxel Dörfler return B_ERROR; 75541281cf3SAxel Dörfler } 75641281cf3SAxel Dörfler } 75741281cf3SAxel Dörfler 75841281cf3SAxel Dörfler BPath path; 75941281cf3SAxel Dörfler entry->GetPath(&path); 76041281cf3SAxel Dörfler 76141281cf3SAxel Dörfler // load the add-on 76241281cf3SAxel Dörfler image_id image = load_add_on(path.Path()); 76341281cf3SAxel Dörfler if (image < 0) 76441281cf3SAxel Dörfler return (status_t)image; 76541281cf3SAxel Dörfler 76641281cf3SAxel Dörfler // get the view loading function symbol 76741281cf3SAxel Dörfler // we first look for a symbol that takes an image_id 76841281cf3SAxel Dörfler // and entry_ref pointer, if not found, go with normal 76941281cf3SAxel Dörfler // instantiate function 77041281cf3SAxel Dörfler BView *(*entryFunction)(image_id, const entry_ref *); 77141281cf3SAxel Dörfler BView *(*itemFunction)(void); 77241281cf3SAxel Dörfler BView *view = NULL; 77341281cf3SAxel Dörfler 77441281cf3SAxel Dörfler entry_ref ref; 77541281cf3SAxel Dörfler entry->GetRef(&ref); 77641281cf3SAxel Dörfler 77741281cf3SAxel Dörfler if (get_image_symbol(image, kInstantiateEntryCFunctionName, 77841281cf3SAxel Dörfler B_SYMBOL_TYPE_TEXT, (void **)&entryFunction) >= 0) { 77941281cf3SAxel Dörfler 78041281cf3SAxel Dörfler view = (*entryFunction)(image, &ref); 78141281cf3SAxel Dörfler } else if (get_image_symbol(image, kInstantiateItemCFunctionName, 78241281cf3SAxel Dörfler B_SYMBOL_TYPE_TEXT, (void **)&itemFunction) >= 0) { 78341281cf3SAxel Dörfler 78441281cf3SAxel Dörfler view = (*itemFunction)(); 78541281cf3SAxel Dörfler } else { 78641281cf3SAxel Dörfler unload_add_on(image); 78741281cf3SAxel Dörfler return B_ERROR; 78841281cf3SAxel Dörfler } 78941281cf3SAxel Dörfler 79041281cf3SAxel Dörfler if (!view || IconExists(view->Name())) { 79141281cf3SAxel Dörfler delete view; 79241281cf3SAxel Dörfler unload_add_on(image); 79341281cf3SAxel Dörfler return B_ERROR; 79441281cf3SAxel Dörfler } 79541281cf3SAxel Dörfler 79641281cf3SAxel Dörfler BMessage *data = new BMessage; 79741281cf3SAxel Dörfler view->Archive(data); 79841281cf3SAxel Dörfler delete view; 79941281cf3SAxel Dörfler 80041281cf3SAxel Dörfler AddIcon(data, id, &ref); 80141281cf3SAxel Dörfler // add the rep; adds info to list 80241281cf3SAxel Dörfler 80341281cf3SAxel Dörfler node.WriteAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, 0, 80441281cf3SAxel Dörfler &fDeskbarSecurityCode, sizeof(fDeskbarSecurityCode)); 80541281cf3SAxel Dörfler 80641281cf3SAxel Dörfler return B_OK; 80741281cf3SAxel Dörfler } 80841281cf3SAxel Dörfler 80941281cf3SAxel Dörfler 81041281cf3SAxel Dörfler status_t 81141281cf3SAxel Dörfler TReplicantTray::AddItem(int32 id, node_ref nodeRef, BEntry &entry, bool isAddOn) 81241281cf3SAxel Dörfler { 81341281cf3SAxel Dörfler DeskbarItemInfo *item = new DeskbarItemInfo; 81441281cf3SAxel Dörfler if (item == NULL) 81541281cf3SAxel Dörfler return B_NO_MEMORY; 81641281cf3SAxel Dörfler 81741281cf3SAxel Dörfler item->id = id; 81841281cf3SAxel Dörfler item->isAddOn = isAddOn; 81941281cf3SAxel Dörfler 82041281cf3SAxel Dörfler if (entry.GetRef(&item->entryRef) < B_OK) { 82141281cf3SAxel Dörfler item->entryRef.device = -1; 82241281cf3SAxel Dörfler item->entryRef.directory = -1; 82341281cf3SAxel Dörfler item->entryRef.name = NULL; 82441281cf3SAxel Dörfler } 82541281cf3SAxel Dörfler item->nodeRef = nodeRef; 82641281cf3SAxel Dörfler 82741281cf3SAxel Dörfler fItemList->AddItem(item); 82841281cf3SAxel Dörfler 82941281cf3SAxel Dörfler if (isAddOn) 83041281cf3SAxel Dörfler watch_node(&nodeRef, B_WATCH_NAME | B_WATCH_ATTR, this, Window()); 83141281cf3SAxel Dörfler 83241281cf3SAxel Dörfler return B_OK; 83341281cf3SAxel Dörfler } 83441281cf3SAxel Dörfler 83541281cf3SAxel Dörfler 83641281cf3SAxel Dörfler /** from entry_removed message, when attribute removed 83741281cf3SAxel Dörfler * or when a device is unmounted (use removeall, by device) 83841281cf3SAxel Dörfler */ 83941281cf3SAxel Dörfler 84041281cf3SAxel Dörfler void 84141281cf3SAxel Dörfler TReplicantTray::UnloadAddOn(node_ref *nodeRef, dev_t *device, 84241281cf3SAxel Dörfler bool which, bool removeAll) 84341281cf3SAxel Dörfler { 84441281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 84541281cf3SAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo*)fItemList->ItemAt(i); 84641281cf3SAxel Dörfler if (!item) 84741281cf3SAxel Dörfler continue; 84841281cf3SAxel Dörfler 84941281cf3SAxel Dörfler if ((which && nodeRef && item->nodeRef == *nodeRef) 85041281cf3SAxel Dörfler || (device && item->nodeRef.device == *device)) { 85141281cf3SAxel Dörfler 85241281cf3SAxel Dörfler if (device && be_roster->IsRunning(&item->entryRef)) 85341281cf3SAxel Dörfler continue; 85441281cf3SAxel Dörfler 85541281cf3SAxel Dörfler RemoveIcon(item->id); 85641281cf3SAxel Dörfler 85741281cf3SAxel Dörfler if (!removeAll) 85841281cf3SAxel Dörfler break; 85941281cf3SAxel Dörfler } 86041281cf3SAxel Dörfler } 86141281cf3SAxel Dörfler } 86241281cf3SAxel Dörfler 86341281cf3SAxel Dörfler 86441281cf3SAxel Dörfler void 86541281cf3SAxel Dörfler TReplicantTray::RemoveItem(int32 id) 86641281cf3SAxel Dörfler { 86741281cf3SAxel Dörfler DeskbarItemInfo *item = DeskbarItemFor(id); 86841281cf3SAxel Dörfler if (item == NULL) 86941281cf3SAxel Dörfler return; 87041281cf3SAxel Dörfler 87141281cf3SAxel Dörfler // attribute was added via Deskbar API (AddItem(entry_ref *, int32 *) 87241281cf3SAxel Dörfler if (item->isAddOn) { 87341281cf3SAxel Dörfler BNode node(&item->entryRef); 87441281cf3SAxel Dörfler node.RemoveAttr(kStatusPredicate); 87541281cf3SAxel Dörfler watch_node(&item->nodeRef, B_STOP_WATCHING, this, Window()); 87641281cf3SAxel Dörfler } 87741281cf3SAxel Dörfler 87841281cf3SAxel Dörfler fItemList->RemoveItem(item); 87941281cf3SAxel Dörfler delete item; 88041281cf3SAxel Dörfler } 88141281cf3SAxel Dörfler 88241281cf3SAxel Dörfler 88341281cf3SAxel Dörfler /** ENTRY_MOVED message, moving only occurs on a device 88441281cf3SAxel Dörfler * copying will occur (ENTRY_CREATED) between devices 88541281cf3SAxel Dörfler */ 88641281cf3SAxel Dörfler 88741281cf3SAxel Dörfler void 88841281cf3SAxel Dörfler TReplicantTray::MoveItem(entry_ref *ref, ino_t toDirectory) 88941281cf3SAxel Dörfler { 89041281cf3SAxel Dörfler if (!ref) 89141281cf3SAxel Dörfler return; 89241281cf3SAxel Dörfler 89341281cf3SAxel Dörfler // scan for a matching entry_ref and update it 89441281cf3SAxel Dörfler // 89541281cf3SAxel Dörfler // don't need to change node info as it does not change 89641281cf3SAxel Dörfler 89741281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 89841281cf3SAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo *)fItemList->ItemAt(i); 89941281cf3SAxel Dörfler if (!item) 90041281cf3SAxel Dörfler continue; 90141281cf3SAxel Dörfler 90241281cf3SAxel Dörfler if (!strcmp(item->entryRef.name, ref->name) 90341281cf3SAxel Dörfler && item->entryRef.device == ref->device 90441281cf3SAxel Dörfler && item->entryRef.directory == ref->directory) { 90541281cf3SAxel Dörfler item->entryRef.directory = toDirectory; 90641281cf3SAxel Dörfler break; 90741281cf3SAxel Dörfler } 90841281cf3SAxel Dörfler } 90941281cf3SAxel Dörfler } 91041281cf3SAxel Dörfler 91141281cf3SAxel Dörfler #endif // add-on support 91241281cf3SAxel Dörfler 91341281cf3SAxel Dörfler // external add-on API routines 91441281cf3SAxel Dörfler // called using the new BDeskbar class 91541281cf3SAxel Dörfler 91641281cf3SAxel Dörfler // existence of icon/replicant by name or ID 91741281cf3SAxel Dörfler // returns opposite 91841281cf3SAxel Dörfler // note: name and id are semi-private limiting 91941281cf3SAxel Dörfler // the ability of non-host apps to remove 92041281cf3SAxel Dörfler // icons without a little bit of work 92141281cf3SAxel Dörfler 92241281cf3SAxel Dörfler /** for a specific id 92341281cf3SAxel Dörfler * return the name of the replicant (name of view) 92441281cf3SAxel Dörfler */ 92541281cf3SAxel Dörfler 92641281cf3SAxel Dörfler status_t 92741281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 id, const char **name) 92841281cf3SAxel Dörfler { 92941281cf3SAxel Dörfler if (id < 0) 93041281cf3SAxel Dörfler return B_ERROR; 93141281cf3SAxel Dörfler 93241281cf3SAxel Dörfler int32 index, temp; 93341281cf3SAxel Dörfler BView *view = ViewAt(&index, &temp, id, false); 93441281cf3SAxel Dörfler if (view) { 93541281cf3SAxel Dörfler *name = view->Name(); 93641281cf3SAxel Dörfler return B_OK; 93741281cf3SAxel Dörfler } 93841281cf3SAxel Dörfler 93941281cf3SAxel Dörfler return B_ERROR; 94041281cf3SAxel Dörfler } 94141281cf3SAxel Dörfler 94241281cf3SAxel Dörfler 9437da06231SAxel Dörfler /** for a specific name 9447da06231SAxel Dörfler * return the id (internal to Deskbar) 9457da06231SAxel Dörfler */ 9467da06231SAxel Dörfler 94741281cf3SAxel Dörfler status_t 94841281cf3SAxel Dörfler TReplicantTray::ItemInfo(const char *name, int32 *id) 94941281cf3SAxel Dörfler { 95041281cf3SAxel Dörfler if (!name || strlen(name) <= 0) 95141281cf3SAxel Dörfler return B_ERROR; 95241281cf3SAxel Dörfler 95341281cf3SAxel Dörfler int32 index; 95441281cf3SAxel Dörfler BView *view = ViewAt(&index, id, name); 95541281cf3SAxel Dörfler if (view) 95641281cf3SAxel Dörfler return B_OK; 95741281cf3SAxel Dörfler 95841281cf3SAxel Dörfler return B_ERROR; 95941281cf3SAxel Dörfler } 96041281cf3SAxel Dörfler 96141281cf3SAxel Dörfler 9627da06231SAxel Dörfler /** at a specific index 9637da06231SAxel Dörfler * return both the name and the id of the replicant 9647da06231SAxel Dörfler */ 9657da06231SAxel Dörfler 96641281cf3SAxel Dörfler status_t 96741281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 index, const char **name, int32 *id) 96841281cf3SAxel Dörfler { 96941281cf3SAxel Dörfler if (index < 0) 97041281cf3SAxel Dörfler return B_ERROR; 97141281cf3SAxel Dörfler 97241281cf3SAxel Dörfler BView *view; 97341281cf3SAxel Dörfler fShelf->ReplicantAt(index, &view, (uint32 *)id, NULL); 97441281cf3SAxel Dörfler if (view) { 97541281cf3SAxel Dörfler *name = view->Name(); 97641281cf3SAxel Dörfler return B_OK; 97741281cf3SAxel Dörfler } 97841281cf3SAxel Dörfler 97941281cf3SAxel Dörfler return B_ERROR; 98041281cf3SAxel Dörfler } 98141281cf3SAxel Dörfler 98241281cf3SAxel Dörfler 9837da06231SAxel Dörfler /** replicant exists, by id/index */ 9847da06231SAxel Dörfler 98541281cf3SAxel Dörfler bool 98641281cf3SAxel Dörfler TReplicantTray::IconExists(int32 target, bool byIndex) 98741281cf3SAxel Dörfler { 98841281cf3SAxel Dörfler int32 index, id; 98941281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, target, byIndex); 99041281cf3SAxel Dörfler 99141281cf3SAxel Dörfler return view && index >= 0; 99241281cf3SAxel Dörfler } 99341281cf3SAxel Dörfler 99441281cf3SAxel Dörfler 9957da06231SAxel Dörfler /** replicant exists, by name */ 9967da06231SAxel Dörfler 99741281cf3SAxel Dörfler bool 99841281cf3SAxel Dörfler TReplicantTray::IconExists(const char *name) 99941281cf3SAxel Dörfler { 100041281cf3SAxel Dörfler if (!name || strlen(name) == 0) 100141281cf3SAxel Dörfler return false; 100241281cf3SAxel Dörfler 100341281cf3SAxel Dörfler int32 index, id; 100441281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, name); 100541281cf3SAxel Dörfler 100641281cf3SAxel Dörfler return view && index >= 0; 100741281cf3SAxel Dörfler } 100841281cf3SAxel Dörfler 100941281cf3SAxel Dörfler 101041281cf3SAxel Dörfler int32 101141281cf3SAxel Dörfler TReplicantTray::IconCount() const 101241281cf3SAxel Dörfler { 101341281cf3SAxel Dörfler return fShelf->CountReplicants(); 101441281cf3SAxel Dörfler } 101541281cf3SAxel Dörfler 101641281cf3SAxel Dörfler 1017*9c50f36eSAxel Dörfler /** Message must contain an archivable view 10187da06231SAxel Dörfler * in the Archives folder for later rehydration 10197da06231SAxel Dörfler * returns the current boot id 10207da06231SAxel Dörfler */ 10217da06231SAxel Dörfler 102241281cf3SAxel Dörfler status_t 102341281cf3SAxel Dörfler TReplicantTray::AddIcon(BMessage *icon, int32 *id, const entry_ref *addOn) 102441281cf3SAxel Dörfler { 102541281cf3SAxel Dörfler if (!icon || !id) 102641281cf3SAxel Dörfler return B_ERROR; 102741281cf3SAxel Dörfler 1028*9c50f36eSAxel Dörfler // find entry_ref 1029*9c50f36eSAxel Dörfler 1030*9c50f36eSAxel Dörfler entry_ref ref; 1031*9c50f36eSAxel Dörfler if (addOn) { 1032*9c50f36eSAxel Dörfler // Use it if we got it 1033*9c50f36eSAxel Dörfler ref = *addOn; 1034*9c50f36eSAxel Dörfler } else { 1035*9c50f36eSAxel Dörfler const char *signature; 1036*9c50f36eSAxel Dörfler status_t status = icon->FindString("add_on", &signature); 1037*9c50f36eSAxel Dörfler if (status == B_OK) { 1038*9c50f36eSAxel Dörfler BRoster roster; 1039*9c50f36eSAxel Dörfler status = roster.FindApp(signature, &ref); 1040*9c50f36eSAxel Dörfler } 1041*9c50f36eSAxel Dörfler if (status < B_OK) 1042*9c50f36eSAxel Dörfler return status; 1043*9c50f36eSAxel Dörfler } 1044*9c50f36eSAxel Dörfler 1045*9c50f36eSAxel Dörfler BFile file; 1046*9c50f36eSAxel Dörfler status_t status = file.SetTo(&ref, B_READ_ONLY); 1047*9c50f36eSAxel Dörfler if (status < B_OK) 1048*9c50f36eSAxel Dörfler return status; 1049*9c50f36eSAxel Dörfler 1050*9c50f36eSAxel Dörfler node_ref nodeRef; 1051*9c50f36eSAxel Dörfler status = file.GetNodeRef(&nodeRef); 1052*9c50f36eSAxel Dörfler if (status < B_OK) 1053*9c50f36eSAxel Dörfler return status; 1054*9c50f36eSAxel Dörfler 1055*9c50f36eSAxel Dörfler BEntry entry(&ref, true); 1056*9c50f36eSAxel Dörfler // ToDo: this resolves an eventual link for the item 1057*9c50f36eSAxel Dörfler // being added - this is okay for now, but in multi-user 1058*9c50f36eSAxel Dörfler // environments, one might want to have links that 1059*9c50f36eSAxel Dörfler // carry the be:deskbar_item_status attribute 1060*9c50f36eSAxel Dörfler status = entry.InitCheck(); 1061*9c50f36eSAxel Dörfler if (status != B_OK) 1062*9c50f36eSAxel Dörfler return status; 1063*9c50f36eSAxel Dörfler 106441281cf3SAxel Dörfler *id = 999; 106541281cf3SAxel Dörfler if (icon->what == B_ARCHIVED_OBJECT) 106641281cf3SAxel Dörfler icon->what = 0; 106741281cf3SAxel Dörfler 106841281cf3SAxel Dörfler // !! check for name collisions? 1069*9c50f36eSAxel Dörfler status = fShelf->AddReplicant(icon, BPoint(1, 1)); 1070*9c50f36eSAxel Dörfler if (status != B_OK) 1071*9c50f36eSAxel Dörfler return status; 107241281cf3SAxel Dörfler 107341281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 107441281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 107541281cf3SAxel Dörfler float width, height; 107641281cf3SAxel Dörfler GetPreferredSize(&width, &height); 107741281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) 107841281cf3SAxel Dörfler AdjustPlacement(); 107941281cf3SAxel Dörfler 108041281cf3SAxel Dörfler int32 count = fShelf->CountReplicants(); 108141281cf3SAxel Dörfler BView *view; 108241281cf3SAxel Dörfler fShelf->ReplicantAt(count-1, &view, (uint32 *)id, NULL); 108341281cf3SAxel Dörfler 108441281cf3SAxel Dörfler // add the item to the add-on list 108541281cf3SAxel Dörfler 108641281cf3SAxel Dörfler AddItem(*id, nodeRef, entry, addOn != NULL); 108741281cf3SAxel Dörfler return B_OK; 108841281cf3SAxel Dörfler } 108941281cf3SAxel Dörfler 109041281cf3SAxel Dörfler 109141281cf3SAxel Dörfler void 109241281cf3SAxel Dörfler TReplicantTray::RemoveIcon(int32 target, bool byIndex) 109341281cf3SAxel Dörfler { 109441281cf3SAxel Dörfler if (target < 0) 109541281cf3SAxel Dörfler return; 109641281cf3SAxel Dörfler 109741281cf3SAxel Dörfler int32 index, id; 109841281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, target, byIndex); 109941281cf3SAxel Dörfler if (view && index >= 0) { 11007da06231SAxel Dörfler // remove the reference from the item list & the shelf 110141281cf3SAxel Dörfler RemoveItem(id); 110241281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 11037da06231SAxel Dörfler 110441281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 110541281cf3SAxel Dörfler RealReplicantAdjustment(index); 110641281cf3SAxel Dörfler } 110741281cf3SAxel Dörfler } 110841281cf3SAxel Dörfler 110941281cf3SAxel Dörfler 111041281cf3SAxel Dörfler void 111141281cf3SAxel Dörfler TReplicantTray::RemoveIcon(const char *name) 111241281cf3SAxel Dörfler { 111341281cf3SAxel Dörfler if (!name || strlen(name) <= 0) 111441281cf3SAxel Dörfler return; 111541281cf3SAxel Dörfler 111641281cf3SAxel Dörfler int32 id, index; 111741281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, name); 111841281cf3SAxel Dörfler if (view && index >= 0) { 11197da06231SAxel Dörfler // remove the reference from the item list & shelf 112041281cf3SAxel Dörfler RemoveItem(id); 112141281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 11227da06231SAxel Dörfler 112341281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 112441281cf3SAxel Dörfler RealReplicantAdjustment(index); 112541281cf3SAxel Dörfler } 112641281cf3SAxel Dörfler } 112741281cf3SAxel Dörfler 112841281cf3SAxel Dörfler 112941281cf3SAxel Dörfler void 11307da06231SAxel Dörfler TReplicantTray::RealReplicantAdjustment(int32 startIndex) 113141281cf3SAxel Dörfler { 11327da06231SAxel Dörfler if (startIndex < 0) 113341281cf3SAxel Dörfler return; 11347da06231SAxel Dörfler 11357da06231SAxel Dörfler if (startIndex == fLastReplicant) 11367da06231SAxel Dörfler startIndex = 0; 11377da06231SAxel Dörfler 113841281cf3SAxel Dörfler // reset the locations of all replicants after the one deleted 11397da06231SAxel Dörfler RealignReplicants(startIndex); 114041281cf3SAxel Dörfler 114141281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 114241281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 114341281cf3SAxel Dörfler float width, height; 114441281cf3SAxel Dörfler GetPreferredSize(&width, &height); 114541281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) { 114641281cf3SAxel Dörfler // resize view to accomodate the replicants 114741281cf3SAxel Dörfler // redraw as necessary 114841281cf3SAxel Dörfler AdjustPlacement(); 114941281cf3SAxel Dörfler } 115041281cf3SAxel Dörfler } 115141281cf3SAxel Dörfler 115241281cf3SAxel Dörfler 11537da06231SAxel Dörfler /** looking for a replicant by id/index 11547da06231SAxel Dörfler * return the view and index 11557da06231SAxel Dörfler */ 11567da06231SAxel Dörfler 115741281cf3SAxel Dörfler BView * 115841281cf3SAxel Dörfler TReplicantTray::ViewAt(int32 *index, int32 *id, int32 target, bool byIndex) 115941281cf3SAxel Dörfler { 116041281cf3SAxel Dörfler *index = -1; 116141281cf3SAxel Dörfler 116241281cf3SAxel Dörfler BView *view; 116341281cf3SAxel Dörfler if (byIndex){ 116441281cf3SAxel Dörfler if (fShelf->ReplicantAt(target, &view, (uint32 *)id)) { 116541281cf3SAxel Dörfler if (view) { 116641281cf3SAxel Dörfler *index = target; 116741281cf3SAxel Dörfler return view; 116841281cf3SAxel Dörfler } 116941281cf3SAxel Dörfler } 117041281cf3SAxel Dörfler } else { 117141281cf3SAxel Dörfler int32 count = fShelf->CountReplicants()-1; 117241281cf3SAxel Dörfler int32 localid; 117341281cf3SAxel Dörfler for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { 117441281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32 *)&localid); 117541281cf3SAxel Dörfler if (localid == target && view) { 117641281cf3SAxel Dörfler *index = repIndex; 117741281cf3SAxel Dörfler *id = localid; 117841281cf3SAxel Dörfler return view; 117941281cf3SAxel Dörfler } 118041281cf3SAxel Dörfler } 118141281cf3SAxel Dörfler } 118241281cf3SAxel Dörfler 118341281cf3SAxel Dörfler return NULL; 118441281cf3SAxel Dörfler } 118541281cf3SAxel Dörfler 118641281cf3SAxel Dörfler 11877da06231SAxel Dörfler /** looking for a replicant with a view by name 11887da06231SAxel Dörfler * return the view, index and the id of the replicant 11897da06231SAxel Dörfler */ 11907da06231SAxel Dörfler 119141281cf3SAxel Dörfler BView * 119241281cf3SAxel Dörfler TReplicantTray::ViewAt(int32 *index, int32 *id, const char *name) 119341281cf3SAxel Dörfler { 119441281cf3SAxel Dörfler *index = -1; 119541281cf3SAxel Dörfler *id = -1; 119641281cf3SAxel Dörfler 119741281cf3SAxel Dörfler BView *view; 119841281cf3SAxel Dörfler int32 count = fShelf->CountReplicants()-1; 119941281cf3SAxel Dörfler for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { 120041281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32 *)id); 120141281cf3SAxel Dörfler if (view && view->Name() && strcmp(name, view->Name()) == 0) { 120241281cf3SAxel Dörfler *index = repIndex; 120341281cf3SAxel Dörfler return view; 120441281cf3SAxel Dörfler } 120541281cf3SAxel Dörfler } 120641281cf3SAxel Dörfler 120741281cf3SAxel Dörfler return NULL; 120841281cf3SAxel Dörfler } 120941281cf3SAxel Dörfler 121041281cf3SAxel Dörfler 12117da06231SAxel Dörfler /** Shelf will call to determine where and if 12127da06231SAxel Dörfler * the replicant is to be added 12137da06231SAxel Dörfler */ 12147da06231SAxel Dörfler 121541281cf3SAxel Dörfler bool 121641281cf3SAxel Dörfler TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage *message) 121741281cf3SAxel Dörfler { 121841281cf3SAxel Dörfler if (!message) 121941281cf3SAxel Dörfler return false; 122041281cf3SAxel Dörfler 122141281cf3SAxel Dörfler if (replicantFrame.Height() > kMaxReplicantHeight) 122241281cf3SAxel Dörfler return false; 122341281cf3SAxel Dörfler 122441281cf3SAxel Dörfler alignment align = B_ALIGN_LEFT; 122541281cf3SAxel Dörfler if (fAlignmentSupport && message->HasBool("deskbar:dynamic_align")) { 122641281cf3SAxel Dörfler if (!fBarView->Vertical()) 122741281cf3SAxel Dörfler align = B_ALIGN_RIGHT; 122841281cf3SAxel Dörfler else 122941281cf3SAxel Dörfler align = fBarView->Left() ? B_ALIGN_LEFT : B_ALIGN_RIGHT; 123041281cf3SAxel Dörfler } else if (message->HasInt32("deskbar:align")) 123141281cf3SAxel Dörfler message->FindInt32("deskbar:align", (int32 *)&align); 123241281cf3SAxel Dörfler 123341281cf3SAxel Dörfler if (message->HasInt32("deskbar:private_align")) 123441281cf3SAxel Dörfler message->FindInt32("deskbar:private_align", (int32 *)&align); 123541281cf3SAxel Dörfler else 123641281cf3SAxel Dörfler align = B_ALIGN_LEFT; 123741281cf3SAxel Dörfler 12387da06231SAxel Dörfler BPoint loc = LocationForReplicant(fShelf->CountReplicants(), 12397da06231SAxel Dörfler replicantFrame.Width()); 124041281cf3SAxel Dörfler 124141281cf3SAxel Dörfler message->AddPoint("_pjp_loc", loc); 124241281cf3SAxel Dörfler return true; 124341281cf3SAxel Dörfler } 124441281cf3SAxel Dörfler 124541281cf3SAxel Dörfler 124641281cf3SAxel Dörfler /** based on the previous (index - 1) replicant in the list 124741281cf3SAxel Dörfler * calculate where the left point should be for this 124841281cf3SAxel Dörfler * replicant. replicant will flow to the right on its own 124941281cf3SAxel Dörfler */ 125041281cf3SAxel Dörfler 125141281cf3SAxel Dörfler BPoint 12527da06231SAxel Dörfler TReplicantTray::LocationForReplicant(int32 index, float width) 125341281cf3SAxel Dörfler { 125441281cf3SAxel Dörfler BPoint loc(kIconGap + 1, kGutter + 1); 125541281cf3SAxel Dörfler 12567da06231SAxel Dörfler if (fMultiRowMode) { 12577da06231SAxel Dörfler // try to find free space in every row 12587da06231SAxel Dörfler for (int32 row = 0; ; loc.y += kMaxReplicantHeight + kIconGap, row++) { 12597da06231SAxel Dörfler // determine free space in this row 12607da06231SAxel Dörfler BRect rect(loc.x, loc.y, loc.x + kMinimumTrayWidth + 2, kMaxReplicantHeight); 12617da06231SAxel Dörfler if (row == 0 && fBarView->ShowingClock()) 12627da06231SAxel Dörfler rect.right -= fClock->Frame().Width() + kIconGap; 12637da06231SAxel Dörfler 12647da06231SAxel Dörfler for (int32 i = 0; i < index; i++) { 12657da06231SAxel Dörfler BView *view = NULL; 12667da06231SAxel Dörfler fShelf->ReplicantAt(i, &view); 12677da06231SAxel Dörfler if (view == NULL || view->Frame().top != rect.top) 12687da06231SAxel Dörfler continue; 12697da06231SAxel Dörfler 12707da06231SAxel Dörfler rect.left = view->Frame().right + kIconGap + 1; 12717da06231SAxel Dörfler } 12727da06231SAxel Dörfler 12737da06231SAxel Dörfler if (rect.Width() >= width) { 12747da06231SAxel Dörfler // the icon fits in this row 12757da06231SAxel Dörfler loc = rect.LeftTop(); 12767da06231SAxel Dörfler break; 12777da06231SAxel Dörfler } 12787da06231SAxel Dörfler } 12797da06231SAxel Dörfler } else { 128041281cf3SAxel Dörfler if (index > 0) { 128141281cf3SAxel Dörfler // get the last replicant added for placement reference 128241281cf3SAxel Dörfler BView *view = NULL; 12837da06231SAxel Dörfler fShelf->ReplicantAt(index - 1, &view); 128441281cf3SAxel Dörfler if (view) { 128541281cf3SAxel Dörfler // push this rep placement past the last one 128641281cf3SAxel Dörfler loc.x = view->Frame().right + kIconGap + 1; 128741281cf3SAxel Dörfler loc.y = view->Frame().top; 128841281cf3SAxel Dörfler } 128941281cf3SAxel Dörfler } 12907da06231SAxel Dörfler } 129141281cf3SAxel Dörfler 12927da06231SAxel Dörfler if ((loc.y == fRightBottomReplicant.top && loc.x > fRightBottomReplicant.left) 12937da06231SAxel Dörfler || loc.y > fRightBottomReplicant.top) { 12947da06231SAxel Dörfler fRightBottomReplicant.Set(loc.x, loc.y, loc.x + width, loc.y + kMaxReplicantHeight); 12957da06231SAxel Dörfler fLastReplicant = index; 129641281cf3SAxel Dörfler } 12977da06231SAxel Dörfler 129841281cf3SAxel Dörfler return loc; 129941281cf3SAxel Dörfler } 130041281cf3SAxel Dörfler 130141281cf3SAxel Dörfler 130241281cf3SAxel Dörfler BRect 130341281cf3SAxel Dörfler TReplicantTray::IconFrame(int32 target, bool byIndex) 130441281cf3SAxel Dörfler { 130541281cf3SAxel Dörfler int32 index, id; 130641281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, target, byIndex); 130741281cf3SAxel Dörfler if (view) 130841281cf3SAxel Dörfler return view->Frame(); 130941281cf3SAxel Dörfler 131041281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 131141281cf3SAxel Dörfler } 131241281cf3SAxel Dörfler 131341281cf3SAxel Dörfler 131441281cf3SAxel Dörfler BRect 131541281cf3SAxel Dörfler TReplicantTray::IconFrame(const char *name) 131641281cf3SAxel Dörfler { 131741281cf3SAxel Dörfler if (!name) 131841281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 131941281cf3SAxel Dörfler 132041281cf3SAxel Dörfler int32 id, index; 132141281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, name); 132241281cf3SAxel Dörfler if (view) 132341281cf3SAxel Dörfler return view->Frame(); 132441281cf3SAxel Dörfler 132541281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 132641281cf3SAxel Dörfler } 132741281cf3SAxel Dörfler 132841281cf3SAxel Dörfler 13297da06231SAxel Dörfler /** Scan from the startIndex and reset the location 13307da06231SAxel Dörfler * as defined in LocationForReplicant() 133141281cf3SAxel Dörfler */ 133241281cf3SAxel Dörfler 133341281cf3SAxel Dörfler void 133441281cf3SAxel Dörfler TReplicantTray::RealignReplicants(int32 startIndex) 133541281cf3SAxel Dörfler { 133641281cf3SAxel Dörfler if (startIndex < 0) 133741281cf3SAxel Dörfler startIndex = 0; 133841281cf3SAxel Dörfler 133941281cf3SAxel Dörfler int32 count = fShelf->CountReplicants(); 134041281cf3SAxel Dörfler if (count <= 0) 134141281cf3SAxel Dörfler return; 134241281cf3SAxel Dörfler 13437da06231SAxel Dörfler if (startIndex == 0) 13447da06231SAxel Dörfler fRightBottomReplicant.Set(0, 0, 0, 0); 13457da06231SAxel Dörfler 134641281cf3SAxel Dörfler BView *view = NULL; 134741281cf3SAxel Dörfler for (int32 i = startIndex ; i < count ; i++){ 134841281cf3SAxel Dörfler fShelf->ReplicantAt(i, &view); 13497da06231SAxel Dörfler BPoint loc = LocationForReplicant(i, view->Frame().Width()); 135041281cf3SAxel Dörfler if (view && (view->Frame().LeftTop() != loc)) { 135141281cf3SAxel Dörfler view->MoveTo(loc); 135241281cf3SAxel Dörfler } 135341281cf3SAxel Dörfler } 135441281cf3SAxel Dörfler } 135541281cf3SAxel Dörfler 135641281cf3SAxel Dörfler 135741281cf3SAxel Dörfler void 135841281cf3SAxel Dörfler TReplicantTray::SetMultiRow(bool state) 135941281cf3SAxel Dörfler { 136041281cf3SAxel Dörfler fMultiRowMode = state; 136141281cf3SAxel Dörfler 136241281cf3SAxel Dörfler // in multi-row state, we only want the short date 136341281cf3SAxel Dörfler 136441281cf3SAxel Dörfler if (fClock != NULL) 136541281cf3SAxel Dörfler fClock->AllowFullDate(!state); 136641281cf3SAxel Dörfler } 136741281cf3SAxel Dörfler 136841281cf3SAxel Dörfler 136941281cf3SAxel Dörfler // #pragma mark - 137041281cf3SAxel Dörfler 137141281cf3SAxel Dörfler 13727da06231SAxel Dörfler /** draggable region that is asynchronous so that 13737da06231SAxel Dörfler * dragging does not block other activities 13747da06231SAxel Dörfler */ 13757da06231SAxel Dörfler 137641281cf3SAxel Dörfler TDragRegion::TDragRegion(TBarView *parent, BView *child) 137741281cf3SAxel Dörfler : BControl(BRect(0, 0, 0, 0), "", "", NULL, B_FOLLOW_NONE, 137841281cf3SAxel Dörfler B_WILL_DRAW | B_FRAME_EVENTS), 137941281cf3SAxel Dörfler fBarView(parent), 138041281cf3SAxel Dörfler fChild(child), 138141281cf3SAxel Dörfler fDragLocation(kAutoPlaceDragRegion) 138241281cf3SAxel Dörfler { 138341281cf3SAxel Dörfler } 138441281cf3SAxel Dörfler 138541281cf3SAxel Dörfler 138641281cf3SAxel Dörfler void 138741281cf3SAxel Dörfler TDragRegion::AttachedToWindow() 138841281cf3SAxel Dörfler { 138941281cf3SAxel Dörfler BView::AttachedToWindow(); 139041281cf3SAxel Dörfler SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); 139141281cf3SAxel Dörfler ResizeToPreferred(); 139241281cf3SAxel Dörfler } 139341281cf3SAxel Dörfler 139441281cf3SAxel Dörfler 139541281cf3SAxel Dörfler void 139641281cf3SAxel Dörfler TDragRegion::GetPreferredSize(float *width, float *height) 139741281cf3SAxel Dörfler { 139841281cf3SAxel Dörfler fChild->ResizeToPreferred(); 139941281cf3SAxel Dörfler *width = fChild->Bounds().Width(); 140041281cf3SAxel Dörfler *height = fChild->Bounds().Height(); 140141281cf3SAxel Dörfler 140241281cf3SAxel Dörfler if (fDragLocation != kNoDragRegion) 140341281cf3SAxel Dörfler *width += 7; 140441281cf3SAxel Dörfler else 140541281cf3SAxel Dörfler *width += 6; 140641281cf3SAxel Dörfler 140741281cf3SAxel Dörfler *height += 3; 140841281cf3SAxel Dörfler } 140941281cf3SAxel Dörfler 141041281cf3SAxel Dörfler 141141281cf3SAxel Dörfler void 141241281cf3SAxel Dörfler TDragRegion::FrameMoved(BPoint) 141341281cf3SAxel Dörfler { 141441281cf3SAxel Dörfler if (fBarView->Left() && fBarView->Vertical() && fDragLocation != kNoDragRegion) 141541281cf3SAxel Dörfler fChild->MoveTo(5,2); 141641281cf3SAxel Dörfler else 141741281cf3SAxel Dörfler fChild->MoveTo(2,2); 141841281cf3SAxel Dörfler } 141941281cf3SAxel Dörfler 142041281cf3SAxel Dörfler 142141281cf3SAxel Dörfler void 142241281cf3SAxel Dörfler TDragRegion::Draw(BRect) 142341281cf3SAxel Dörfler { 142441281cf3SAxel Dörfler rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR); 142541281cf3SAxel Dörfler rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT); 142641281cf3SAxel Dörfler rgb_color vdark = tint_color(menuColor, B_DARKEN_3_TINT); 142741281cf3SAxel Dörfler rgb_color vvdark = tint_color(menuColor, B_DARKEN_4_TINT); 142841281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 142941281cf3SAxel Dörfler 143041281cf3SAxel Dörfler BRect frame(Bounds()); 143141281cf3SAxel Dörfler BeginLineArray(4); 143241281cf3SAxel Dörfler 143341281cf3SAxel Dörfler if (fBarView->Vertical()) { 143441281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.RightTop(), light); 143541281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.LeftBottom(), light); 143641281cf3SAxel Dörfler AddLine(frame.RightBottom(), frame.RightTop(), hilite); 143741281cf3SAxel Dörfler } else if (fBarView->AcrossTop()) { 143841281cf3SAxel Dörfler AddLine(frame.LeftTop()+BPoint(0, 1), frame.RightTop()+BPoint(-1, 1), 143941281cf3SAxel Dörfler light); 144041281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 144141281cf3SAxel Dörfler AddLine(frame.RightTop()+BPoint(-1, 2),frame.RightBottom()+BPoint(-1, -1), 144241281cf3SAxel Dörfler hilite); 144341281cf3SAxel Dörfler AddLine(frame.LeftBottom(), frame.RightBottom()+BPoint(-1, 0), hilite); 144441281cf3SAxel Dörfler } else if (fBarView->AcrossBottom()) { 144541281cf3SAxel Dörfler AddLine(frame.LeftTop()+BPoint(0, 1), frame.RightTop()+BPoint(-1, 1), light); 144641281cf3SAxel Dörfler AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 144741281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 144841281cf3SAxel Dörfler AddLine(frame.RightTop()+BPoint(-1, 1),frame.RightBottom()+BPoint(-1, -1), 144941281cf3SAxel Dörfler hilite); 145041281cf3SAxel Dörfler } 145141281cf3SAxel Dörfler 145241281cf3SAxel Dörfler EndLineArray(); 145341281cf3SAxel Dörfler 145441281cf3SAxel Dörfler if (fDragLocation != kDontDrawDragRegion || fDragLocation != kNoDragRegion) 145541281cf3SAxel Dörfler DrawDragRegion(); 145641281cf3SAxel Dörfler } 145741281cf3SAxel Dörfler 145841281cf3SAxel Dörfler 145941281cf3SAxel Dörfler void 146041281cf3SAxel Dörfler TDragRegion::DrawDragRegion() 146141281cf3SAxel Dörfler { 146241281cf3SAxel Dörfler rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR); 146341281cf3SAxel Dörfler rgb_color menuHilite = tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT); 146441281cf3SAxel Dörfler rgb_color vdark = tint_color(menuColor, B_DARKEN_3_TINT); 146541281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 146641281cf3SAxel Dörfler 146741281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 146841281cf3SAxel Dörfler 146941281cf3SAxel Dörfler BeginLineArray(dragRegion.IntegerHeight()); 147041281cf3SAxel Dörfler BPoint pt = dragRegion.LeftTop() + BPoint(1,1); 147141281cf3SAxel Dörfler 147241281cf3SAxel Dörfler // Draw drag region highlighted if tracking mouse 147341281cf3SAxel Dörfler if (IsTracking()) { 147441281cf3SAxel Dörfler SetHighColor(menuHilite); 147541281cf3SAxel Dörfler FillRect(dragRegion); 147641281cf3SAxel Dörfler while (pt.y + 1 <= dragRegion.bottom) { 147741281cf3SAxel Dörfler AddLine(pt, pt, light); 147841281cf3SAxel Dörfler AddLine(pt+BPoint(1,1), pt+BPoint(1,1), vdark); 147941281cf3SAxel Dörfler 148041281cf3SAxel Dörfler pt.y += 3; 148141281cf3SAxel Dörfler } 148241281cf3SAxel Dörfler } else { 148341281cf3SAxel Dörfler while (pt.y + 1 <= dragRegion.bottom) { 148441281cf3SAxel Dörfler AddLine(pt, pt, vdark); 148541281cf3SAxel Dörfler AddLine(pt+BPoint(1,1), pt+BPoint(1,1), light); 148641281cf3SAxel Dörfler 148741281cf3SAxel Dörfler pt.y += 3; 148841281cf3SAxel Dörfler } 148941281cf3SAxel Dörfler } 149041281cf3SAxel Dörfler EndLineArray(); 149141281cf3SAxel Dörfler } 149241281cf3SAxel Dörfler 149341281cf3SAxel Dörfler 149441281cf3SAxel Dörfler BRect 149541281cf3SAxel Dörfler TDragRegion::DragRegion() const 149641281cf3SAxel Dörfler { 149741281cf3SAxel Dörfler BRect dragRegion(Bounds()); 149841281cf3SAxel Dörfler dragRegion.top += 2; 149941281cf3SAxel Dörfler dragRegion.bottom -= 2; 150041281cf3SAxel Dörfler 150141281cf3SAxel Dörfler bool placeOnLeft=false; 150241281cf3SAxel Dörfler if (fDragLocation == kAutoPlaceDragRegion) { 150341281cf3SAxel Dörfler if (fBarView->Vertical() && fBarView->Left()) 150441281cf3SAxel Dörfler placeOnLeft = true; 150541281cf3SAxel Dörfler else 150641281cf3SAxel Dörfler placeOnLeft = false; 150741281cf3SAxel Dörfler } else if (fDragLocation == kDragRegionLeft) 150841281cf3SAxel Dörfler placeOnLeft = true; 150941281cf3SAxel Dörfler else if (fDragLocation == kDragRegionRight) 151041281cf3SAxel Dörfler placeOnLeft = false; 151141281cf3SAxel Dörfler 151241281cf3SAxel Dörfler if (placeOnLeft) { 151341281cf3SAxel Dörfler dragRegion.left += 1; 151441281cf3SAxel Dörfler dragRegion.right = dragRegion.left + 3; 151541281cf3SAxel Dörfler } else { 151641281cf3SAxel Dörfler dragRegion.right -= 1; 151741281cf3SAxel Dörfler dragRegion.left = dragRegion.right - 3; 151841281cf3SAxel Dörfler } 151941281cf3SAxel Dörfler 152041281cf3SAxel Dörfler return dragRegion; 152141281cf3SAxel Dörfler } 152241281cf3SAxel Dörfler 152341281cf3SAxel Dörfler 152441281cf3SAxel Dörfler void 152541281cf3SAxel Dörfler TDragRegion::MouseDown(BPoint thePoint) 152641281cf3SAxel Dörfler { 152741281cf3SAxel Dörfler ulong buttons; 152841281cf3SAxel Dörfler BPoint where; 152941281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 153041281cf3SAxel Dörfler 15317da06231SAxel Dörfler dragRegion.InsetBy(-2.0f, -2.0f); 15327da06231SAxel Dörfler // DragRegion() is designed for drawing, not clicking 153341281cf3SAxel Dörfler 153441281cf3SAxel Dörfler if (!dragRegion.Contains(thePoint)) 153541281cf3SAxel Dörfler return; 153641281cf3SAxel Dörfler 153741281cf3SAxel Dörfler while(true) { 153841281cf3SAxel Dörfler GetMouse(&where, &buttons); 153941281cf3SAxel Dörfler if (!buttons) 154041281cf3SAxel Dörfler break; 154141281cf3SAxel Dörfler 154241281cf3SAxel Dörfler if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) != 0) { 154341281cf3SAxel Dörfler fPreviousPosition = thePoint; 154441281cf3SAxel Dörfler SetTracking(true); 154541281cf3SAxel Dörfler SetMouseEventMask(B_POINTER_EVENTS, 154641281cf3SAxel Dörfler B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); 154741281cf3SAxel Dörfler Invalidate(DragRegion()); 154841281cf3SAxel Dörfler break; 154941281cf3SAxel Dörfler } 155041281cf3SAxel Dörfler 155141281cf3SAxel Dörfler snooze(25000); 155241281cf3SAxel Dörfler } 155341281cf3SAxel Dörfler } 155441281cf3SAxel Dörfler 155541281cf3SAxel Dörfler 155641281cf3SAxel Dörfler void 155741281cf3SAxel Dörfler TDragRegion::MouseUp(BPoint pt) 155841281cf3SAxel Dörfler { 155941281cf3SAxel Dörfler if (IsTracking()) { 156041281cf3SAxel Dörfler SetTracking(false); 156141281cf3SAxel Dörfler Invalidate(DragRegion()); 156241281cf3SAxel Dörfler } else 156341281cf3SAxel Dörfler BControl::MouseUp(pt); 156441281cf3SAxel Dörfler } 156541281cf3SAxel Dörfler 156641281cf3SAxel Dörfler 156741281cf3SAxel Dörfler bool 156841281cf3SAxel Dörfler TDragRegion::SwitchModeForRect(BPoint mouse, BRect rect, 156941281cf3SAxel Dörfler bool newVertical, bool newLeft, bool newTop, int32 newState) 157041281cf3SAxel Dörfler { 157141281cf3SAxel Dörfler if (!rect.Contains(mouse)) 157241281cf3SAxel Dörfler // not our rect 157341281cf3SAxel Dörfler return false; 157441281cf3SAxel Dörfler 157541281cf3SAxel Dörfler if (newVertical == fBarView->Vertical() 157641281cf3SAxel Dörfler && newLeft == fBarView->Left() 157741281cf3SAxel Dörfler && newTop == fBarView->Top() 157841281cf3SAxel Dörfler && newState == fBarView->State()) 157941281cf3SAxel Dörfler // already in the correct mode 158041281cf3SAxel Dörfler return true; 158141281cf3SAxel Dörfler 158241281cf3SAxel Dörfler fBarView->ChangeState(newState, newVertical, newLeft, newTop); 158341281cf3SAxel Dörfler return true; 158441281cf3SAxel Dörfler } 158541281cf3SAxel Dörfler 158641281cf3SAxel Dörfler 158741281cf3SAxel Dörfler void 158841281cf3SAxel Dörfler TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage *message) 158941281cf3SAxel Dörfler { 159041281cf3SAxel Dörfler if (IsTracking()) { 159141281cf3SAxel Dörfler BScreen screen; 159241281cf3SAxel Dörfler BRect frame = screen.Frame(); 159341281cf3SAxel Dörfler 159441281cf3SAxel Dörfler float hDivider = frame.Width() / 6; 159541281cf3SAxel Dörfler hDivider = (hDivider < kMinimumWindowWidth + 10.0f) ? kMinimumWindowWidth + 10.0f : hDivider; 159641281cf3SAxel Dörfler float miniDivider = frame.top + kMiniHeight + 10.0f; 159741281cf3SAxel Dörfler float vDivider = frame.Height() / 2; 159841281cf3SAxel Dörfler #ifdef FULL_MODE 159941281cf3SAxel Dörfler float thirdScreen = frame.Height() / 3; 160041281cf3SAxel Dörfler #endif 160141281cf3SAxel Dörfler BRect topLeft(frame.left, frame.top, frame.left + hDivider, miniDivider); 160241281cf3SAxel Dörfler BRect topMiddle(frame.left + hDivider, frame.top, frame.right - hDivider, vDivider); 160341281cf3SAxel Dörfler BRect topRight(frame.right - hDivider, frame.top, frame.right, miniDivider); 160441281cf3SAxel Dörfler 160541281cf3SAxel Dörfler #ifdef FULL_MODE 160641281cf3SAxel Dörfler vDivider = miniDivider + thirdScreen; 160741281cf3SAxel Dörfler #endif 160841281cf3SAxel Dörfler BRect middleLeft(frame.left, miniDivider, frame.left + hDivider, vDivider); 160941281cf3SAxel Dörfler BRect middleRight(frame.right - hDivider, miniDivider, frame.right, vDivider); 161041281cf3SAxel Dörfler 161141281cf3SAxel Dörfler #ifdef FULL_MODE 161241281cf3SAxel Dörfler BRect leftSide(frame.left, vDivider, frame.left + hDivider, frame.bottom - thirdScreen); 161341281cf3SAxel Dörfler BRect rightSide(frame.right - hDivider, vDivider, frame.right, frame.bottom - thirdScreen); 161441281cf3SAxel Dörfler 161541281cf3SAxel Dörfler vDivider = frame.bottom - thirdScreen; 161641281cf3SAxel Dörfler #endif 161741281cf3SAxel Dörfler BRect bottomLeft(frame.left, vDivider, frame.left + hDivider, frame.bottom); 161841281cf3SAxel Dörfler BRect bottomMiddle(frame.left + hDivider, vDivider, frame.right - hDivider, frame.bottom); 161941281cf3SAxel Dörfler BRect bottomRight(frame.right - hDivider, vDivider, frame.right, frame.bottom); 162041281cf3SAxel Dörfler 162141281cf3SAxel Dörfler if (where != fPreviousPosition) { 162241281cf3SAxel Dörfler fPreviousPosition = where; 162341281cf3SAxel Dörfler ConvertToScreen(&where); 162441281cf3SAxel Dörfler 162541281cf3SAxel Dörfler // use short circuit evaluation for convenience 162641281cf3SAxel Dörfler if (SwitchModeForRect(where, topLeft, true, true, true, kMiniState) 162741281cf3SAxel Dörfler || SwitchModeForRect(where, topMiddle, false, true, true, kExpandoState) 162841281cf3SAxel Dörfler || SwitchModeForRect(where, topRight, true, false, true, kMiniState) 162941281cf3SAxel Dörfler 163041281cf3SAxel Dörfler || SwitchModeForRect(where, middleLeft, true, true, true, kExpandoState) 163141281cf3SAxel Dörfler || SwitchModeForRect(where, middleRight, true, false, true, kExpandoState) 163241281cf3SAxel Dörfler 163341281cf3SAxel Dörfler #ifdef FULL_MODE 163441281cf3SAxel Dörfler || SwitchModeForRect(where, leftSide, true, true, true, kFullState) 163541281cf3SAxel Dörfler || SwitchModeForRect(where, rightSide, true, false, true, kFullState) 163641281cf3SAxel Dörfler #endif 163741281cf3SAxel Dörfler || SwitchModeForRect(where, bottomLeft, true, true, false, kMiniState) 163841281cf3SAxel Dörfler || SwitchModeForRect(where, bottomMiddle, false, true, false, kExpandoState) 16397da06231SAxel Dörfler || SwitchModeForRect(where, bottomRight, true, false, false, kMiniState)) 164041281cf3SAxel Dörfler ; 164141281cf3SAxel Dörfler } 164241281cf3SAxel Dörfler } else 164341281cf3SAxel Dörfler BControl::MouseMoved(where, code, message); 164441281cf3SAxel Dörfler } 164541281cf3SAxel Dörfler 164641281cf3SAxel Dörfler 164741281cf3SAxel Dörfler int32 164841281cf3SAxel Dörfler TDragRegion::DragRegionLocation() const 164941281cf3SAxel Dörfler { 165041281cf3SAxel Dörfler return fDragLocation; 165141281cf3SAxel Dörfler } 165241281cf3SAxel Dörfler 165341281cf3SAxel Dörfler 165441281cf3SAxel Dörfler void 165541281cf3SAxel Dörfler TDragRegion::SetDragRegionLocation(int32 location) 165641281cf3SAxel Dörfler { 165741281cf3SAxel Dörfler if (location == fDragLocation) 165841281cf3SAxel Dörfler return; 165941281cf3SAxel Dörfler 166041281cf3SAxel Dörfler fDragLocation = location; 166141281cf3SAxel Dörfler Invalidate(); 166241281cf3SAxel Dörfler } 166341281cf3SAxel Dörfler 1664