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); 9166eba86fSAxel Dörfler printf("entry_ref: %ld, %Ld, %s\n", item->entryRef.device, 9266eba86fSAxel Dörfler item->entryRef.directory, item->entryRef.name); 9341281cf3SAxel Dörfler printf("node_ref: %ld, %Ld\n", item->nodeRef.device, item->nodeRef.node); 9441281cf3SAxel Dörfler } 9541281cf3SAxel Dörfler 9641281cf3SAxel Dörfler 9741281cf3SAxel Dörfler static void 9841281cf3SAxel Dörfler DumpList(BList *itemlist) 9941281cf3SAxel Dörfler { 10041281cf3SAxel Dörfler int32 count = itemlist->CountItems() - 1; 10141281cf3SAxel Dörfler if (count < 0) { 10241281cf3SAxel Dörfler printf("no items in list\n"); 10341281cf3SAxel Dörfler return; 10441281cf3SAxel Dörfler } 10541281cf3SAxel Dörfler for (int32 i = count ; i >= 0 ; i--) { 10641281cf3SAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo*)itemlist->ItemAt(i); 10741281cf3SAxel Dörfler if (!item) 10841281cf3SAxel Dörfler continue; 10941281cf3SAxel Dörfler 11041281cf3SAxel Dörfler DumpItem(item); 11141281cf3SAxel Dörfler } 11241281cf3SAxel Dörfler } 11341281cf3SAxel Dörfler #endif /* DB_ADDONS */ 11441281cf3SAxel Dörfler 11541281cf3SAxel Dörfler 1167da06231SAxel Dörfler // don't change the name of this view to anything other than "Status"! 1177da06231SAxel Dörfler 11841281cf3SAxel Dörfler TReplicantTray::TReplicantTray(TBarView *parent, bool vertical) 11941281cf3SAxel Dörfler : BView(BRect(0, 0, 1, 1), "Status", B_FOLLOW_LEFT | B_FOLLOW_TOP, 12041281cf3SAxel Dörfler B_WILL_DRAW | B_FRAME_EVENTS), 12141281cf3SAxel Dörfler fClock(NULL), 12241281cf3SAxel Dörfler fBarView(parent), 12341281cf3SAxel Dörfler fShelf(new TReplicantShelf(this)), 12441281cf3SAxel Dörfler fMultiRowMode(vertical), 12541281cf3SAxel Dörfler fAlignmentSupport(false) 12641281cf3SAxel Dörfler { 12741281cf3SAxel Dörfler } 12841281cf3SAxel Dörfler 12941281cf3SAxel Dörfler 13041281cf3SAxel Dörfler TReplicantTray::~TReplicantTray() 13141281cf3SAxel Dörfler { 13241281cf3SAxel Dörfler delete fShelf; 13341281cf3SAxel Dörfler } 13441281cf3SAxel Dörfler 13541281cf3SAxel Dörfler 13641281cf3SAxel Dörfler void 13741281cf3SAxel Dörfler TReplicantTray::AttachedToWindow() 13841281cf3SAxel Dörfler { 13941281cf3SAxel Dörfler BView::AttachedToWindow(); 14041281cf3SAxel Dörfler 14166eba86fSAxel Dörfler SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 14266eba86fSAxel Dörfler B_DARKEN_1_TINT)); 14341281cf3SAxel Dörfler SetDrawingMode(B_OP_COPY); 14466eba86fSAxel Dörfler 14541281cf3SAxel Dörfler Window()->SetPulseRate(1000000); 14641281cf3SAxel Dörfler DealWithClock(fBarView->ShowingClock()); 14741281cf3SAxel Dörfler 14841281cf3SAxel Dörfler #ifdef DB_ADDONS 14941281cf3SAxel Dörfler // load addons and rehydrate archives 1503a6add49SAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 15141281cf3SAxel Dörfler InitAddOnSupport(); 15241281cf3SAxel Dörfler #endif 1539c910f9eSStephan Aßmus #endif 15441281cf3SAxel Dörfler ResizeToPreferred(); 15541281cf3SAxel Dörfler } 15641281cf3SAxel Dörfler 15741281cf3SAxel Dörfler 15841281cf3SAxel Dörfler void 15941281cf3SAxel Dörfler TReplicantTray::DetachedFromWindow() 16041281cf3SAxel Dörfler { 16141281cf3SAxel Dörfler #ifdef DB_ADDONS 16241281cf3SAxel Dörfler // clean up add-on support 163465b54cdSAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 16441281cf3SAxel Dörfler DeleteAddOnSupport(); 16541281cf3SAxel Dörfler #endif 166465b54cdSAxel Dörfler #endif 16741281cf3SAxel Dörfler BView::DetachedFromWindow(); 16841281cf3SAxel Dörfler } 16941281cf3SAxel Dörfler 17041281cf3SAxel Dörfler 17141281cf3SAxel Dörfler void 17241281cf3SAxel Dörfler TReplicantTray::RememberClockSettings() 17341281cf3SAxel Dörfler { 17441281cf3SAxel Dörfler if (fClock) { 17541281cf3SAxel Dörfler desk_settings *settings = ((TBarApp *)be_app)->Settings(); 17641281cf3SAxel Dörfler 17741281cf3SAxel Dörfler settings->timeShowSeconds = fClock->ShowingSeconds(); 17841281cf3SAxel Dörfler settings->timeShowMil = fClock->ShowingMilTime(); 17941281cf3SAxel Dörfler settings->timeShowEuro = fClock->ShowingEuroDate(); 18041281cf3SAxel Dörfler settings->timeFullDate = fClock->ShowingFullDate(); 18141281cf3SAxel Dörfler } 18241281cf3SAxel Dörfler } 18341281cf3SAxel Dörfler 18441281cf3SAxel Dörfler 18541281cf3SAxel Dörfler bool 18641281cf3SAxel Dörfler TReplicantTray::ShowingSeconds() 18741281cf3SAxel Dörfler { 18841281cf3SAxel Dörfler if (fClock) 18941281cf3SAxel Dörfler return fClock->ShowingSeconds(); 19041281cf3SAxel Dörfler return false; 19141281cf3SAxel Dörfler } 19241281cf3SAxel Dörfler 19341281cf3SAxel Dörfler 19441281cf3SAxel Dörfler bool 19541281cf3SAxel Dörfler TReplicantTray::ShowingMiltime() 19641281cf3SAxel Dörfler { 19741281cf3SAxel Dörfler if (fClock) 19841281cf3SAxel Dörfler return fClock->ShowingMilTime(); 19941281cf3SAxel Dörfler return false; 20041281cf3SAxel Dörfler } 20141281cf3SAxel Dörfler 20241281cf3SAxel Dörfler 20341281cf3SAxel Dörfler bool 20441281cf3SAxel Dörfler TReplicantTray::ShowingEuroDate() 20541281cf3SAxel Dörfler { 20641281cf3SAxel Dörfler if (fClock) 20741281cf3SAxel Dörfler return fClock->ShowingEuroDate(); 20841281cf3SAxel Dörfler return false; 20941281cf3SAxel Dörfler } 21041281cf3SAxel Dörfler 21141281cf3SAxel Dörfler 21241281cf3SAxel Dörfler bool 21341281cf3SAxel Dörfler TReplicantTray::ShowingFullDate() 21441281cf3SAxel Dörfler { 21541281cf3SAxel Dörfler if (fClock && CanShowFullDate()) 21641281cf3SAxel Dörfler return fClock->ShowingFullDate(); 21741281cf3SAxel Dörfler return false; 21841281cf3SAxel Dörfler } 21941281cf3SAxel Dörfler 22041281cf3SAxel Dörfler 22141281cf3SAxel Dörfler bool 22241281cf3SAxel Dörfler TReplicantTray::CanShowFullDate() 22341281cf3SAxel Dörfler { 22441281cf3SAxel Dörfler if (fClock) 22541281cf3SAxel Dörfler return fClock->CanShowFullDate(); 22641281cf3SAxel Dörfler return false; 22741281cf3SAxel Dörfler } 22841281cf3SAxel Dörfler 22941281cf3SAxel Dörfler 23041281cf3SAxel Dörfler void 23141281cf3SAxel Dörfler TReplicantTray::DealWithClock(bool showClock) 23241281cf3SAxel Dörfler { 23341281cf3SAxel Dörfler fBarView->ShowClock(showClock); 23441281cf3SAxel Dörfler 23541281cf3SAxel Dörfler if (showClock) { 23641281cf3SAxel Dörfler if (!fClock) { 23741281cf3SAxel Dörfler desk_settings *settings = ((TBarApp *)be_app)->Settings(); 23841281cf3SAxel Dörfler 239157cd891SAlexandre Deckner fClock = new TTimeView(kMinimumTrayWidth, kMaxReplicantHeight - 1.0, 240157cd891SAlexandre Deckner settings->timeShowSeconds, settings->timeShowMil, 241157cd891SAlexandre Deckner settings->timeFullDate, settings->timeShowEuro, false); 24241281cf3SAxel Dörfler AddChild(fClock); 24341281cf3SAxel Dörfler 24441281cf3SAxel Dörfler fClock->MoveTo(Bounds().right - fClock->Bounds().Width() - 1, 2); 24541281cf3SAxel Dörfler fClock->AllowFullDate(!IsMultiRow()); 24641281cf3SAxel Dörfler } 24741281cf3SAxel Dörfler } else { 24841281cf3SAxel Dörfler if (fClock) { 24941281cf3SAxel Dörfler RememberClockSettings(); 25041281cf3SAxel Dörfler 25141281cf3SAxel Dörfler fClock->RemoveSelf(); 25241281cf3SAxel Dörfler delete fClock; 25341281cf3SAxel Dörfler fClock = NULL; 25441281cf3SAxel Dörfler } 25541281cf3SAxel Dörfler } 25641281cf3SAxel Dörfler } 25741281cf3SAxel Dörfler 25841281cf3SAxel Dörfler 25966eba86fSAxel Dörfler /*! 26066eba86fSAxel Dörfler Width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth 26166eba86fSAxel Dörfler if not in multirowmode and greater than kMinimumReplicantCount 26266eba86fSAxel Dörfler the width should be calculated based on the actual 26366eba86fSAxel Dörfler replicant widths 26441281cf3SAxel Dörfler */ 26541281cf3SAxel Dörfler void 26641281cf3SAxel Dörfler TReplicantTray::GetPreferredSize(float *preferredWidth, float *preferredHeight) 26741281cf3SAxel Dörfler { 26841281cf3SAxel Dörfler float width = 0, height = kMinimumTrayHeight; 26941281cf3SAxel Dörfler 27041281cf3SAxel Dörfler if (fMultiRowMode) { 2717da06231SAxel Dörfler if (fShelf->CountReplicants() > 0) 2727da06231SAxel Dörfler height = fRightBottomReplicant.bottom; 27341281cf3SAxel Dörfler 27441281cf3SAxel Dörfler // the height will be uniform for the number of rows 27541281cf3SAxel Dörfler // necessary to show all the reps + any gutters 27641281cf3SAxel Dörfler // necessary for spacing 27741281cf3SAxel Dörfler int32 rowCount = (int32)(height / kMaxReplicantHeight); 27841281cf3SAxel Dörfler height = kGutter + (rowCount * kMaxReplicantHeight) 27941281cf3SAxel Dörfler + ((rowCount - 1) * kIconGap) + kGutter; 28041281cf3SAxel Dörfler height = max(kMinimumTrayHeight, height); 28141281cf3SAxel Dörfler width = kMinimumTrayWidth; 28241281cf3SAxel Dörfler } else { 28341281cf3SAxel Dörfler // if last replicant overruns clock then 28441281cf3SAxel Dörfler // resize to accomodate 2857da06231SAxel Dörfler if (fShelf->CountReplicants() > 0) { 28641281cf3SAxel Dörfler if (fBarView->ShowingClock() 2877da06231SAxel Dörfler && fRightBottomReplicant.right + 6 >= fClock->Frame().left) { 28866eba86fSAxel Dörfler width = fRightBottomReplicant.right + 6 28966eba86fSAxel Dörfler + fClock->Frame().Width(); 29041281cf3SAxel Dörfler } else 2917da06231SAxel Dörfler width = fRightBottomReplicant.right + 3; 29241281cf3SAxel Dörfler } 29341281cf3SAxel Dörfler // this view has a fixed minimum width 29441281cf3SAxel Dörfler width = max(kMinimumTrayWidth, width); 29541281cf3SAxel Dörfler } 29641281cf3SAxel Dörfler 29741281cf3SAxel Dörfler *preferredWidth = width; 29841281cf3SAxel Dörfler // add 2 for the border 29941281cf3SAxel Dörfler *preferredHeight = height + 1; 30041281cf3SAxel Dörfler } 30141281cf3SAxel Dörfler 30241281cf3SAxel Dörfler 30341281cf3SAxel Dörfler void 30441281cf3SAxel Dörfler TReplicantTray::AdjustPlacement() 30541281cf3SAxel Dörfler { 30641281cf3SAxel Dörfler // called when an add-on has been added or removed 30741281cf3SAxel Dörfler // need to resize the parent of this accordingly 308a5210ab1SAxel Dörfler 30941281cf3SAxel Dörfler BRect bounds = Bounds(); 31041281cf3SAxel Dörfler float width, height; 31141281cf3SAxel Dörfler GetPreferredSize(&width, &height); 31241281cf3SAxel Dörfler 31341281cf3SAxel Dörfler if (width == bounds.Width() && height == bounds.Height()) { 31441281cf3SAxel Dörfler // no need to change anything 31541281cf3SAxel Dörfler return; 31641281cf3SAxel Dörfler } 31741281cf3SAxel Dörfler 31841281cf3SAxel Dörfler Parent()->ResizeToPreferred(); 31941281cf3SAxel Dörfler fBarView->UpdatePlacement(); 32041281cf3SAxel Dörfler Parent()->Invalidate(); 32141281cf3SAxel Dörfler Invalidate(); 32241281cf3SAxel Dörfler } 32341281cf3SAxel Dörfler 32441281cf3SAxel Dörfler 32541281cf3SAxel Dörfler void 32641281cf3SAxel Dörfler TReplicantTray::Draw(BRect) 32741281cf3SAxel Dörfler { 32841281cf3SAxel Dörfler rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR); 32941281cf3SAxel Dörfler rgb_color vdark = tint_color(menuColor, B_DARKEN_3_TINT); 33041281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 33141281cf3SAxel Dörfler 33241281cf3SAxel Dörfler BRect frame(Bounds()); 33341281cf3SAxel Dörfler 33441281cf3SAxel Dörfler SetHighColor(light); 33541281cf3SAxel Dörfler StrokeLine(frame.LeftBottom(), frame.RightBottom()); 33641281cf3SAxel Dörfler StrokeLine(frame.RightBottom(), frame.RightTop()); 33741281cf3SAxel Dörfler 33841281cf3SAxel Dörfler SetHighColor(vdark); 33941281cf3SAxel Dörfler StrokeLine(frame.RightTop(), frame.LeftTop()); 34041281cf3SAxel Dörfler StrokeLine(frame.LeftTop(), frame.LeftBottom()); 34141281cf3SAxel Dörfler } 34241281cf3SAxel Dörfler 34341281cf3SAxel Dörfler 34441281cf3SAxel Dörfler void 34541281cf3SAxel Dörfler TReplicantTray::MessageReceived(BMessage *message) 34641281cf3SAxel Dörfler { 34741281cf3SAxel Dörfler switch (message->what) { 34841281cf3SAxel Dörfler case 'time': 34941281cf3SAxel Dörfler // from context menu in clock and in this view 35041281cf3SAxel Dörfler DealWithClock(!fBarView->ShowingClock()); 35141281cf3SAxel Dörfler RealignReplicants(); 35241281cf3SAxel Dörfler AdjustPlacement(); 35341281cf3SAxel Dörfler break; 35441281cf3SAxel Dörfler 355a5210ab1SAxel Dörfler case 'Trfm': 35641281cf3SAxel Dörfler // time string reformat -> realign 35741281cf3SAxel Dörfler DealWithClock(fBarView->ShowingClock()); 35841281cf3SAxel Dörfler RealignReplicants(); 35941281cf3SAxel Dörfler AdjustPlacement(); 36041281cf3SAxel Dörfler break; 36141281cf3SAxel Dörfler 36241281cf3SAxel Dörfler case kMsgShowSeconds: 36341281cf3SAxel Dörfler case kMsgMilTime: 36441281cf3SAxel Dörfler case kMsgEuroDate: 36541281cf3SAxel Dörfler case kMsgFullDate: 36641281cf3SAxel Dörfler if (fClock != NULL) 36741281cf3SAxel Dörfler Window()->PostMessage(message, fClock); 36841281cf3SAxel Dörfler break; 36941281cf3SAxel Dörfler 37041281cf3SAxel Dörfler #ifdef DB_ADDONS 37141281cf3SAxel Dörfler case B_NODE_MONITOR: 37241281cf3SAxel Dörfler case B_QUERY_UPDATE: 37341281cf3SAxel Dörfler HandleEntryUpdate(message); 37441281cf3SAxel Dörfler break; 37541281cf3SAxel Dörfler #endif 37641281cf3SAxel Dörfler 37741281cf3SAxel Dörfler default: 37841281cf3SAxel Dörfler BView::MessageReceived(message); 37941281cf3SAxel Dörfler break; 38041281cf3SAxel Dörfler } 38141281cf3SAxel Dörfler } 38241281cf3SAxel Dörfler 38341281cf3SAxel Dörfler 38441281cf3SAxel Dörfler void 38541281cf3SAxel Dörfler TReplicantTray::ShowReplicantMenu(BPoint point) 38641281cf3SAxel Dörfler { 38741281cf3SAxel Dörfler BPopUpMenu *menu = new BPopUpMenu("", false, false); 38841281cf3SAxel Dörfler menu->SetFont(be_plain_font); 38941281cf3SAxel Dörfler 39041281cf3SAxel Dörfler // If the clock is visible, show the extended menu 39141281cf3SAxel Dörfler // otheriwse, show "Show Time". 39241281cf3SAxel Dörfler 39341281cf3SAxel Dörfler if (fBarView->ShowingClock()) 39441281cf3SAxel Dörfler fClock->ShowClockOptions(ConvertToScreen(point)); 39541281cf3SAxel Dörfler else { 39641281cf3SAxel Dörfler BMenuItem *item = new BMenuItem("Show Time", new BMessage('time')); 39741281cf3SAxel Dörfler menu->AddItem(item); 39841281cf3SAxel Dörfler menu->SetTargetForItems(this); 39941281cf3SAxel Dörfler BPoint where = ConvertToScreen(point); 40041281cf3SAxel Dörfler menu->Go(where, true, true, BRect(where - BPoint(4, 4), 40141281cf3SAxel Dörfler where + BPoint(4, 4)), true); 40241281cf3SAxel Dörfler } 40341281cf3SAxel Dörfler } 40441281cf3SAxel Dörfler 40541281cf3SAxel Dörfler 40641281cf3SAxel Dörfler void 40741281cf3SAxel Dörfler TReplicantTray::MouseDown(BPoint where) 40841281cf3SAxel Dörfler { 40941281cf3SAxel Dörfler #ifdef DB_ADDONS 41041281cf3SAxel Dörfler if (modifiers() & B_CONTROL_KEY) 41141281cf3SAxel Dörfler DumpList(fItemList); 41241281cf3SAxel Dörfler #endif 41341281cf3SAxel Dörfler 41441281cf3SAxel Dörfler uint32 buttons; 41541281cf3SAxel Dörfler 41641281cf3SAxel Dörfler Window()->CurrentMessage()->FindInt32("buttons", (int32 *)&buttons); 41741281cf3SAxel Dörfler if (buttons == B_SECONDARY_MOUSE_BUTTON) { 41841281cf3SAxel Dörfler ShowReplicantMenu(where); 41941281cf3SAxel Dörfler } else { 42041281cf3SAxel Dörfler BPoint save = where; 42141281cf3SAxel Dörfler bigtime_t doubleClickSpeed; 42241281cf3SAxel Dörfler bigtime_t start = system_time(); 42341281cf3SAxel Dörfler uint32 buttons; 42441281cf3SAxel Dörfler 42541281cf3SAxel Dörfler get_click_speed(&doubleClickSpeed); 42641281cf3SAxel Dörfler 42741281cf3SAxel Dörfler do { 42841281cf3SAxel Dörfler if (fabs(where.x - save.x) > 4 || fabs(where.y - save.y) > 4) 42941281cf3SAxel Dörfler // user moved out of bounds of click area 43041281cf3SAxel Dörfler break; 43141281cf3SAxel Dörfler 43241281cf3SAxel Dörfler if ((system_time() - start) > (2 * doubleClickSpeed)) { 43341281cf3SAxel Dörfler ShowReplicantMenu(where); 43441281cf3SAxel Dörfler break; 43541281cf3SAxel Dörfler } 43641281cf3SAxel Dörfler 43741281cf3SAxel Dörfler snooze(50000); 43841281cf3SAxel Dörfler GetMouse(&where, &buttons); 43941281cf3SAxel Dörfler } while (buttons); 44041281cf3SAxel Dörfler } 44141281cf3SAxel Dörfler BView::MouseDown(where); 44241281cf3SAxel Dörfler } 44341281cf3SAxel Dörfler 44441281cf3SAxel Dörfler #ifdef DB_ADDONS 44541281cf3SAxel Dörfler 44641281cf3SAxel Dörfler void 44741281cf3SAxel Dörfler TReplicantTray::InitAddOnSupport() 44841281cf3SAxel Dörfler { 44941281cf3SAxel Dörfler // list to maintain refs to each rep added/deleted 45041281cf3SAxel Dörfler fItemList = new BList(); 45141281cf3SAxel Dörfler 45241281cf3SAxel Dörfler bool haveKey = false; 45341281cf3SAxel Dörfler BPath path; 45441281cf3SAxel Dörfler if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) { 45541281cf3SAxel Dörfler path.Append(kDeskbarSecurityCodeFile); 45641281cf3SAxel Dörfler 45741281cf3SAxel Dörfler BFile file(path.Path(),B_READ_ONLY); 45841281cf3SAxel Dörfler if (file.InitCheck() == B_OK 45941281cf3SAxel Dörfler && file.Read(&fDeskbarSecurityCode, 46041281cf3SAxel Dörfler sizeof(fDeskbarSecurityCode)) == sizeof(fDeskbarSecurityCode)) 46141281cf3SAxel Dörfler haveKey = true; 46241281cf3SAxel Dörfler } 46341281cf3SAxel Dörfler if (!haveKey) { 46441281cf3SAxel Dörfler // create the security code 46541281cf3SAxel Dörfler bigtime_t real = real_time_clock_usecs(); 46641281cf3SAxel Dörfler bigtime_t boot = system_time(); 46741281cf3SAxel Dörfler // two computers would have to have exactly matching clocks, and launch 46841281cf3SAxel Dörfler // Deskbar at the exact same time into the bootsequence in order for their 46941281cf3SAxel Dörfler // security-ID to be identical 47066eba86fSAxel Dörfler fDeskbarSecurityCode = ((real & 0xffffffffULL) << 32) 47166eba86fSAxel Dörfler | (boot & 0xffffffffULL); 47241281cf3SAxel Dörfler 47341281cf3SAxel Dörfler if (find_directory (B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) { 47441281cf3SAxel Dörfler path.Append(kDeskbarSecurityCodeFile); 47541281cf3SAxel Dörfler BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); 47641281cf3SAxel Dörfler if (file.InitCheck() == B_OK) 47741281cf3SAxel Dörfler file.Write(&fDeskbarSecurityCode, sizeof(fDeskbarSecurityCode)); 47841281cf3SAxel Dörfler } 47941281cf3SAxel Dörfler } 48041281cf3SAxel Dörfler 48141281cf3SAxel Dörfler // for each volume currently mounted 48241281cf3SAxel Dörfler // index the volume with our indices 48341281cf3SAxel Dörfler BVolumeRoster roster; 48441281cf3SAxel Dörfler BVolume volume; 48541281cf3SAxel Dörfler while (roster.GetNextVolume(&volume) == B_OK) { 48641281cf3SAxel Dörfler fs_create_index(volume.Device(), kStatusPredicate, B_STRING_TYPE, 0); 48741281cf3SAxel Dörfler RunAddOnQuery(&volume, kEnabledPredicate); 48841281cf3SAxel Dörfler } 48941281cf3SAxel Dörfler 49041281cf3SAxel Dörfler // we also watch for volumes mounted and unmounted 49141281cf3SAxel Dörfler watch_node(NULL, B_WATCH_MOUNT | B_WATCH_ATTR, this, Window()); 49241281cf3SAxel Dörfler } 49341281cf3SAxel Dörfler 49441281cf3SAxel Dörfler 49541281cf3SAxel Dörfler void 49641281cf3SAxel Dörfler TReplicantTray::DeleteAddOnSupport() 49741281cf3SAxel Dörfler { 49841281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 49941281cf3SAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo *)fItemList->RemoveItem(i); 50041281cf3SAxel Dörfler if (item) { 50141281cf3SAxel Dörfler if (item->isAddOn) 50241281cf3SAxel Dörfler watch_node(&(item->nodeRef), B_STOP_WATCHING, this, Window()); 50341281cf3SAxel Dörfler 50441281cf3SAxel Dörfler delete item; 50541281cf3SAxel Dörfler } 50641281cf3SAxel Dörfler } 50741281cf3SAxel Dörfler delete fItemList; 50841281cf3SAxel Dörfler 50941281cf3SAxel Dörfler // stop the volume mount/unmount watch 51041281cf3SAxel Dörfler stop_watching(this, Window()); 51141281cf3SAxel Dörfler } 51241281cf3SAxel Dörfler 51341281cf3SAxel Dörfler 51441281cf3SAxel Dörfler void 51541281cf3SAxel Dörfler TReplicantTray::RunAddOnQuery(BVolume *volume, const char *predicate) 51641281cf3SAxel Dörfler { 51741281cf3SAxel Dörfler // Since the new BFS supports querying for attributes without 51841281cf3SAxel Dörfler // an index, we only run the query if the index exists (for 51941281cf3SAxel Dörfler // newly mounted devices only - the Deskbar will automatically 52041281cf3SAxel Dörfler // create an index for every device mounted at startup). 52141281cf3SAxel Dörfler index_info info; 52266eba86fSAxel Dörfler if (!volume->KnowsQuery() 52366eba86fSAxel Dörfler || fs_stat_index(volume->Device(), kStatusPredicate, &info) != 0) 52441281cf3SAxel Dörfler return; 52541281cf3SAxel Dörfler 52641281cf3SAxel Dörfler // run a new query on a specific volume 52741281cf3SAxel Dörfler // make it live 52841281cf3SAxel Dörfler BQuery query; 52941281cf3SAxel Dörfler query.SetVolume(volume); 53041281cf3SAxel Dörfler query.SetPredicate(predicate); 53141281cf3SAxel Dörfler query.Fetch(); 53241281cf3SAxel Dörfler 53341281cf3SAxel Dörfler int32 id; 53441281cf3SAxel Dörfler BEntry entry; 5357da06231SAxel Dörfler while (query.GetNextEntry(&entry) == B_OK) { 53641281cf3SAxel Dörfler // scan any entries returned 53741281cf3SAxel Dörfler // attempt to load them as add-ons 53841281cf3SAxel Dörfler // collisions are handled in LoadAddOn 53941281cf3SAxel Dörfler LoadAddOn(&entry, &id); 54041281cf3SAxel Dörfler } 5417da06231SAxel Dörfler } 54241281cf3SAxel Dörfler 54341281cf3SAxel Dörfler 54441281cf3SAxel Dörfler bool 54541281cf3SAxel Dörfler TReplicantTray::IsAddOn(entry_ref &ref) 54641281cf3SAxel Dörfler { 54741281cf3SAxel Dörfler BFile file(&ref, B_READ_ONLY); 54841281cf3SAxel Dörfler 54941281cf3SAxel Dörfler char status[64]; 55066eba86fSAxel Dörfler ssize_t size = file.ReadAttr(kStatusPredicate, B_STRING_TYPE, 0, &status, 55166eba86fSAxel Dörfler sizeof(status)); 55241281cf3SAxel Dörfler return size > 0; 55341281cf3SAxel Dörfler } 55441281cf3SAxel Dörfler 55541281cf3SAxel Dörfler 55641281cf3SAxel Dörfler DeskbarItemInfo * 55741281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(node_ref &nodeRef) 55841281cf3SAxel Dörfler { 55941281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 56066eba86fSAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo *)fItemList->ItemAt(i); 56141281cf3SAxel Dörfler if (item == NULL) 56241281cf3SAxel Dörfler continue; 56341281cf3SAxel Dörfler 56441281cf3SAxel Dörfler if (item->nodeRef == nodeRef) 56541281cf3SAxel Dörfler return item; 56641281cf3SAxel Dörfler } 56741281cf3SAxel Dörfler 56841281cf3SAxel Dörfler return NULL; 56941281cf3SAxel Dörfler } 57041281cf3SAxel Dörfler 57141281cf3SAxel Dörfler 57241281cf3SAxel Dörfler DeskbarItemInfo * 57341281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(int32 id) 57441281cf3SAxel Dörfler { 57541281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 57666eba86fSAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo *)fItemList->ItemAt(i); 57741281cf3SAxel Dörfler if (item == NULL) 57841281cf3SAxel Dörfler continue; 57941281cf3SAxel Dörfler 58041281cf3SAxel Dörfler if (item->id == id) 58141281cf3SAxel Dörfler return item; 58241281cf3SAxel Dörfler } 58341281cf3SAxel Dörfler 58441281cf3SAxel Dörfler return NULL; 58541281cf3SAxel Dörfler } 58641281cf3SAxel Dörfler 58741281cf3SAxel Dörfler 58841281cf3SAxel Dörfler bool 58941281cf3SAxel Dörfler TReplicantTray::NodeExists(node_ref &nodeRef) 59041281cf3SAxel Dörfler { 59141281cf3SAxel Dörfler return DeskbarItemFor(nodeRef) != NULL; 59241281cf3SAxel Dörfler } 59341281cf3SAxel Dörfler 59441281cf3SAxel Dörfler 59566eba86fSAxel Dörfler /*! This handles B_NODE_MONITOR & B_QUERY_UPDATE messages received 59666eba86fSAxel Dörfler for the registered add-ons. 59741281cf3SAxel Dörfler */ 59841281cf3SAxel Dörfler void 59941281cf3SAxel Dörfler TReplicantTray::HandleEntryUpdate(BMessage *message) 60041281cf3SAxel Dörfler { 60141281cf3SAxel Dörfler int32 opcode; 60241281cf3SAxel Dörfler if (message->FindInt32("opcode", &opcode) != B_OK) 60341281cf3SAxel Dörfler return; 60441281cf3SAxel Dörfler 60541281cf3SAxel Dörfler BPath path; 60641281cf3SAxel Dörfler switch (opcode) { 60741281cf3SAxel Dörfler case B_ENTRY_CREATED: 60841281cf3SAxel Dörfler { 60966eba86fSAxel Dörfler // entry was just listed, matches live query 61041281cf3SAxel Dörfler const char *name; 61141281cf3SAxel Dörfler ino_t directory; 61241281cf3SAxel Dörfler dev_t device; 61341281cf3SAxel Dörfler // received when an app adds a ref to the 61441281cf3SAxel Dörfler // Deskbar add-ons folder 61541281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK 61641281cf3SAxel Dörfler && message->FindInt64("directory", &directory) == B_OK 61741281cf3SAxel Dörfler && message->FindInt32("device", &device) == B_OK) { 61841281cf3SAxel Dörfler entry_ref ref(device, directory, name); 61941281cf3SAxel Dörfler // see if this item has the attribute 62041281cf3SAxel Dörfler // that we expect 62141281cf3SAxel Dörfler if (IsAddOn(ref)) { 62241281cf3SAxel Dörfler int32 id; 62341281cf3SAxel Dörfler BEntry entry(&ref); 62441281cf3SAxel Dörfler LoadAddOn(&entry, &id); 62541281cf3SAxel Dörfler } 62641281cf3SAxel Dörfler } 62741281cf3SAxel Dörfler break; 62866eba86fSAxel Dörfler } 62941281cf3SAxel Dörfler 63041281cf3SAxel Dörfler case B_ATTR_CHANGED: 63166eba86fSAxel Dörfler { 63241281cf3SAxel Dörfler // from node watch on individual items 63341281cf3SAxel Dörfler // (node_watch added in LoadAddOn) 63441281cf3SAxel Dörfler node_ref nodeRef; 63541281cf3SAxel Dörfler if (message->FindInt32("device", &(nodeRef.device)) == B_OK 63641281cf3SAxel Dörfler && message->FindInt64("node", &(nodeRef.node)) == B_OK) { 63741281cf3SAxel Dörfler // get the add-on this is for 63841281cf3SAxel Dörfler DeskbarItemInfo *item = DeskbarItemFor(nodeRef); 63941281cf3SAxel Dörfler if (item == NULL) 64041281cf3SAxel Dörfler break; 64141281cf3SAxel Dörfler 64241281cf3SAxel Dörfler BFile file(&item->entryRef, B_READ_ONLY); 64341281cf3SAxel Dörfler 64441281cf3SAxel Dörfler char status[255]; 64541281cf3SAxel Dörfler ssize_t size = file.ReadAttr(kStatusPredicate, 64641281cf3SAxel Dörfler B_STRING_TYPE, 0, status, sizeof(status) - 1); 64741281cf3SAxel Dörfler status[sizeof(status) - 1] = '\0'; 64841281cf3SAxel Dörfler 64941281cf3SAxel Dörfler // attribute was removed 65041281cf3SAxel Dörfler if (size == B_ENTRY_NOT_FOUND) { 65141281cf3SAxel Dörfler // cleans up and removes node_watch 65241281cf3SAxel Dörfler UnloadAddOn(&nodeRef, NULL, true, false); 65341281cf3SAxel Dörfler } else if (!strcmp(status, "enable")) { 65441281cf3SAxel Dörfler int32 id; 65541281cf3SAxel Dörfler BEntry entry(&item->entryRef, true); 65641281cf3SAxel Dörfler LoadAddOn(&entry, &id); 65741281cf3SAxel Dörfler } 65841281cf3SAxel Dörfler } 65941281cf3SAxel Dörfler break; 66066eba86fSAxel Dörfler } 66141281cf3SAxel Dörfler 66241281cf3SAxel Dörfler case B_ENTRY_MOVED: 66341281cf3SAxel Dörfler { 66441281cf3SAxel Dörfler entry_ref ref; 66541281cf3SAxel Dörfler ino_t todirectory; 66641281cf3SAxel Dörfler ino_t node; 66741281cf3SAxel Dörfler const char *name; 66841281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK 66941281cf3SAxel Dörfler && message->FindInt64("from directory", &(ref.directory)) == B_OK 67041281cf3SAxel Dörfler && message->FindInt64("to directory", &todirectory) == B_OK 67141281cf3SAxel Dörfler && message->FindInt32("device", &(ref.device)) == B_OK 67241281cf3SAxel Dörfler && message->FindInt64("node", &node) == B_OK ) { 67341281cf3SAxel Dörfler 67441281cf3SAxel Dörfler if (!name) 67541281cf3SAxel Dörfler break; 67641281cf3SAxel Dörfler 67741281cf3SAxel Dörfler ref.set_name(name); 67841281cf3SAxel Dörfler // change the directory reference to 67941281cf3SAxel Dörfler // the new directory 68041281cf3SAxel Dörfler MoveItem(&ref, todirectory); 68141281cf3SAxel Dörfler } 68241281cf3SAxel Dörfler break; 68366eba86fSAxel Dörfler } 68441281cf3SAxel Dörfler 68541281cf3SAxel Dörfler case B_ENTRY_REMOVED: 68641281cf3SAxel Dörfler { 68741281cf3SAxel Dörfler // entry was rm'd from the device 68841281cf3SAxel Dörfler node_ref nodeRef; 68941281cf3SAxel Dörfler if (message->FindInt32("device", &(nodeRef.device)) == B_OK 69041281cf3SAxel Dörfler && message->FindInt64("node", &(nodeRef.node)) == B_OK) { 69141281cf3SAxel Dörfler DeskbarItemInfo *item = DeskbarItemFor(nodeRef); 69241281cf3SAxel Dörfler if (item == NULL) 69341281cf3SAxel Dörfler break; 69441281cf3SAxel Dörfler 69541281cf3SAxel Dörfler // If there is a team running where the add-on comes from, 69641281cf3SAxel Dörfler // we don't want to remove the icon yet. 69741281cf3SAxel Dörfler if (be_roster->IsRunning(&item->entryRef)) 69841281cf3SAxel Dörfler break; 69941281cf3SAxel Dörfler 70041281cf3SAxel Dörfler UnloadAddOn(&nodeRef, NULL, true, false); 70141281cf3SAxel Dörfler } 70241281cf3SAxel Dörfler break; 70366eba86fSAxel Dörfler } 70441281cf3SAxel Dörfler 70541281cf3SAxel Dörfler case B_DEVICE_MOUNTED: 70641281cf3SAxel Dörfler { 70741281cf3SAxel Dörfler // run a new query on the new device 70841281cf3SAxel Dörfler dev_t device; 70941281cf3SAxel Dörfler if (message->FindInt32("new device", &device) != B_OK) 71041281cf3SAxel Dörfler break; 71141281cf3SAxel Dörfler 71241281cf3SAxel Dörfler RunAddOnQuery(new BVolume(device), kEnabledPredicate); 71341281cf3SAxel Dörfler break; 71466eba86fSAxel Dörfler } 71566eba86fSAxel Dörfler 71641281cf3SAxel Dörfler case B_DEVICE_UNMOUNTED: 71741281cf3SAxel Dörfler { 71841281cf3SAxel Dörfler // remove all items associated with the device 71941281cf3SAxel Dörfler // unmounted 72041281cf3SAxel Dörfler // contrary to what the BeBook says, the item is called "device", 72141281cf3SAxel Dörfler // not "new device" like it is for B_DEVICE_MOUNTED 72241281cf3SAxel Dörfler dev_t device; 72341281cf3SAxel Dörfler if (message->FindInt32("device", &device) != B_OK) 72441281cf3SAxel Dörfler break; 72541281cf3SAxel Dörfler 72641281cf3SAxel Dörfler UnloadAddOn(NULL, &device, false, true); 72741281cf3SAxel Dörfler break; 72841281cf3SAxel Dörfler } 72941281cf3SAxel Dörfler } 73066eba86fSAxel Dörfler } 73141281cf3SAxel Dörfler 73241281cf3SAxel Dörfler 73366eba86fSAxel Dörfler /*! 73466eba86fSAxel Dörfler The add-ons must support the exported C function API 73566eba86fSAxel Dörfler if they do, they will be loaded and added to deskbar 73666eba86fSAxel Dörfler primary function is the Instantiate function 7377da06231SAxel Dörfler */ 73841281cf3SAxel Dörfler status_t 73941281cf3SAxel Dörfler TReplicantTray::LoadAddOn(BEntry *entry, int32 *id, bool force) 74041281cf3SAxel Dörfler { 74141281cf3SAxel Dörfler if (!entry) 74241281cf3SAxel Dörfler return B_ERROR; 74341281cf3SAxel Dörfler 74441281cf3SAxel Dörfler node_ref nodeRef; 74541281cf3SAxel Dörfler entry->GetNodeRef(&nodeRef); 74641281cf3SAxel Dörfler // no duplicates 74741281cf3SAxel Dörfler if (NodeExists(nodeRef)) 74841281cf3SAxel Dörfler return B_ERROR; 74941281cf3SAxel Dörfler 75041281cf3SAxel Dörfler BNode node(entry); 75141281cf3SAxel Dörfler if (!force) { 75241281cf3SAxel Dörfler status_t error = node.InitCheck(); 75341281cf3SAxel Dörfler if (error != B_OK) 75441281cf3SAxel Dörfler return error; 75541281cf3SAxel Dörfler 75641281cf3SAxel Dörfler uint64 deskbarID; 75766eba86fSAxel Dörfler ssize_t size = node.ReadAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, 75866eba86fSAxel Dörfler 0, &deskbarID, sizeof(fDeskbarSecurityCode)); 75966eba86fSAxel Dörfler if (size != sizeof(fDeskbarSecurityCode) 76066eba86fSAxel Dörfler || deskbarID != fDeskbarSecurityCode) { 76141281cf3SAxel Dörfler // no code or code doesn't match 76241281cf3SAxel Dörfler return B_ERROR; 76341281cf3SAxel Dörfler } 76441281cf3SAxel Dörfler } 76541281cf3SAxel Dörfler 76641281cf3SAxel Dörfler BPath path; 76766eba86fSAxel Dörfler status_t status = entry->GetPath(&path); 76866eba86fSAxel Dörfler if (status < B_OK) 76966eba86fSAxel Dörfler return status; 77041281cf3SAxel Dörfler 77141281cf3SAxel Dörfler // load the add-on 77241281cf3SAxel Dörfler image_id image = load_add_on(path.Path()); 77366eba86fSAxel Dörfler if (image < B_OK) 77466eba86fSAxel Dörfler return image; 77541281cf3SAxel Dörfler 77641281cf3SAxel Dörfler // get the view loading function symbol 77741281cf3SAxel Dörfler // we first look for a symbol that takes an image_id 77841281cf3SAxel Dörfler // and entry_ref pointer, if not found, go with normal 77941281cf3SAxel Dörfler // instantiate function 78041281cf3SAxel Dörfler BView *(*entryFunction)(image_id, const entry_ref *); 78141281cf3SAxel Dörfler BView *(*itemFunction)(void); 78241281cf3SAxel Dörfler BView *view = NULL; 78341281cf3SAxel Dörfler 78441281cf3SAxel Dörfler entry_ref ref; 78541281cf3SAxel Dörfler entry->GetRef(&ref); 78641281cf3SAxel Dörfler 78741281cf3SAxel Dörfler if (get_image_symbol(image, kInstantiateEntryCFunctionName, 78866eba86fSAxel Dörfler B_SYMBOL_TYPE_TEXT, (void **)&entryFunction) >= B_OK) { 78941281cf3SAxel Dörfler view = (*entryFunction)(image, &ref); 79041281cf3SAxel Dörfler } else if (get_image_symbol(image, kInstantiateItemCFunctionName, 79166eba86fSAxel Dörfler B_SYMBOL_TYPE_TEXT, (void **)&itemFunction) >= B_OK) { 79241281cf3SAxel Dörfler view = (*itemFunction)(); 79341281cf3SAxel Dörfler } else { 79441281cf3SAxel Dörfler unload_add_on(image); 79541281cf3SAxel Dörfler return B_ERROR; 79641281cf3SAxel Dörfler } 79741281cf3SAxel Dörfler 79866eba86fSAxel Dörfler if (view == NULL || IconExists(view->Name())) { 79941281cf3SAxel Dörfler delete view; 80041281cf3SAxel Dörfler unload_add_on(image); 80141281cf3SAxel Dörfler return B_ERROR; 80241281cf3SAxel Dörfler } 80341281cf3SAxel Dörfler 80441281cf3SAxel Dörfler BMessage *data = new BMessage; 80541281cf3SAxel Dörfler view->Archive(data); 80641281cf3SAxel Dörfler delete view; 80741281cf3SAxel Dörfler 80841281cf3SAxel Dörfler AddIcon(data, id, &ref); 80941281cf3SAxel Dörfler // add the rep; adds info to list 81041281cf3SAxel Dörfler 81141281cf3SAxel Dörfler node.WriteAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, 0, 81241281cf3SAxel Dörfler &fDeskbarSecurityCode, sizeof(fDeskbarSecurityCode)); 81341281cf3SAxel Dörfler 81441281cf3SAxel Dörfler return B_OK; 81541281cf3SAxel Dörfler } 81641281cf3SAxel Dörfler 81741281cf3SAxel Dörfler 81841281cf3SAxel Dörfler status_t 81941281cf3SAxel Dörfler TReplicantTray::AddItem(int32 id, node_ref nodeRef, BEntry &entry, bool isAddOn) 82041281cf3SAxel Dörfler { 82141281cf3SAxel Dörfler DeskbarItemInfo *item = new DeskbarItemInfo; 82241281cf3SAxel Dörfler if (item == NULL) 82341281cf3SAxel Dörfler return B_NO_MEMORY; 82441281cf3SAxel Dörfler 82541281cf3SAxel Dörfler item->id = id; 82641281cf3SAxel Dörfler item->isAddOn = isAddOn; 82741281cf3SAxel Dörfler 82841281cf3SAxel Dörfler if (entry.GetRef(&item->entryRef) < B_OK) { 82941281cf3SAxel Dörfler item->entryRef.device = -1; 83041281cf3SAxel Dörfler item->entryRef.directory = -1; 83141281cf3SAxel Dörfler item->entryRef.name = NULL; 83241281cf3SAxel Dörfler } 83341281cf3SAxel Dörfler item->nodeRef = nodeRef; 83441281cf3SAxel Dörfler 83541281cf3SAxel Dörfler fItemList->AddItem(item); 83641281cf3SAxel Dörfler 83741281cf3SAxel Dörfler if (isAddOn) 83841281cf3SAxel Dörfler watch_node(&nodeRef, B_WATCH_NAME | B_WATCH_ATTR, this, Window()); 83941281cf3SAxel Dörfler 84041281cf3SAxel Dörfler return B_OK; 84141281cf3SAxel Dörfler } 84241281cf3SAxel Dörfler 84341281cf3SAxel Dörfler 84441281cf3SAxel Dörfler /** from entry_removed message, when attribute removed 84541281cf3SAxel Dörfler * or when a device is unmounted (use removeall, by device) 84641281cf3SAxel Dörfler */ 84741281cf3SAxel Dörfler 84841281cf3SAxel Dörfler void 84941281cf3SAxel Dörfler TReplicantTray::UnloadAddOn(node_ref *nodeRef, dev_t *device, 85041281cf3SAxel Dörfler bool which, bool removeAll) 85141281cf3SAxel Dörfler { 85241281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 85341281cf3SAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo*)fItemList->ItemAt(i); 85441281cf3SAxel Dörfler if (!item) 85541281cf3SAxel Dörfler continue; 85641281cf3SAxel Dörfler 85741281cf3SAxel Dörfler if ((which && nodeRef && item->nodeRef == *nodeRef) 85841281cf3SAxel Dörfler || (device && item->nodeRef.device == *device)) { 85941281cf3SAxel Dörfler 86041281cf3SAxel Dörfler if (device && be_roster->IsRunning(&item->entryRef)) 86141281cf3SAxel Dörfler continue; 86241281cf3SAxel Dörfler 86341281cf3SAxel Dörfler RemoveIcon(item->id); 86441281cf3SAxel Dörfler 86541281cf3SAxel Dörfler if (!removeAll) 86641281cf3SAxel Dörfler break; 86741281cf3SAxel Dörfler } 86841281cf3SAxel Dörfler } 86941281cf3SAxel Dörfler } 87041281cf3SAxel Dörfler 87141281cf3SAxel Dörfler 87241281cf3SAxel Dörfler void 87341281cf3SAxel Dörfler TReplicantTray::RemoveItem(int32 id) 87441281cf3SAxel Dörfler { 87541281cf3SAxel Dörfler DeskbarItemInfo *item = DeskbarItemFor(id); 87641281cf3SAxel Dörfler if (item == NULL) 87741281cf3SAxel Dörfler return; 87841281cf3SAxel Dörfler 87941281cf3SAxel Dörfler // attribute was added via Deskbar API (AddItem(entry_ref *, int32 *) 88041281cf3SAxel Dörfler if (item->isAddOn) { 88141281cf3SAxel Dörfler BNode node(&item->entryRef); 88241281cf3SAxel Dörfler node.RemoveAttr(kStatusPredicate); 88341281cf3SAxel Dörfler watch_node(&item->nodeRef, B_STOP_WATCHING, this, Window()); 88441281cf3SAxel Dörfler } 88541281cf3SAxel Dörfler 88641281cf3SAxel Dörfler fItemList->RemoveItem(item); 88741281cf3SAxel Dörfler delete item; 88841281cf3SAxel Dörfler } 88941281cf3SAxel Dörfler 89041281cf3SAxel Dörfler 89141281cf3SAxel Dörfler /** ENTRY_MOVED message, moving only occurs on a device 89241281cf3SAxel Dörfler * copying will occur (ENTRY_CREATED) between devices 89341281cf3SAxel Dörfler */ 89441281cf3SAxel Dörfler 89541281cf3SAxel Dörfler void 89641281cf3SAxel Dörfler TReplicantTray::MoveItem(entry_ref *ref, ino_t toDirectory) 89741281cf3SAxel Dörfler { 89841281cf3SAxel Dörfler if (!ref) 89941281cf3SAxel Dörfler return; 90041281cf3SAxel Dörfler 90141281cf3SAxel Dörfler // scan for a matching entry_ref and update it 90241281cf3SAxel Dörfler // 90341281cf3SAxel Dörfler // don't need to change node info as it does not change 90441281cf3SAxel Dörfler 90541281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 90641281cf3SAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo *)fItemList->ItemAt(i); 90741281cf3SAxel Dörfler if (!item) 90841281cf3SAxel Dörfler continue; 90941281cf3SAxel Dörfler 91041281cf3SAxel Dörfler if (!strcmp(item->entryRef.name, ref->name) 91141281cf3SAxel Dörfler && item->entryRef.device == ref->device 91241281cf3SAxel Dörfler && item->entryRef.directory == ref->directory) { 91341281cf3SAxel Dörfler item->entryRef.directory = toDirectory; 91441281cf3SAxel Dörfler break; 91541281cf3SAxel Dörfler } 91641281cf3SAxel Dörfler } 91741281cf3SAxel Dörfler } 91841281cf3SAxel Dörfler 91941281cf3SAxel Dörfler #endif // add-on support 92041281cf3SAxel Dörfler 92141281cf3SAxel Dörfler // external add-on API routines 92241281cf3SAxel Dörfler // called using the new BDeskbar class 92341281cf3SAxel Dörfler 92441281cf3SAxel Dörfler // existence of icon/replicant by name or ID 92541281cf3SAxel Dörfler // returns opposite 92641281cf3SAxel Dörfler // note: name and id are semi-private limiting 92741281cf3SAxel Dörfler // the ability of non-host apps to remove 92841281cf3SAxel Dörfler // icons without a little bit of work 92941281cf3SAxel Dörfler 93041281cf3SAxel Dörfler /** for a specific id 93141281cf3SAxel Dörfler * return the name of the replicant (name of view) 93241281cf3SAxel Dörfler */ 93341281cf3SAxel Dörfler 93441281cf3SAxel Dörfler status_t 93541281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 id, const char **name) 93641281cf3SAxel Dörfler { 93741281cf3SAxel Dörfler if (id < 0) 93841281cf3SAxel Dörfler return B_ERROR; 93941281cf3SAxel Dörfler 94041281cf3SAxel Dörfler int32 index, temp; 94141281cf3SAxel Dörfler BView *view = ViewAt(&index, &temp, id, false); 94241281cf3SAxel Dörfler if (view) { 94341281cf3SAxel Dörfler *name = view->Name(); 94441281cf3SAxel Dörfler return B_OK; 94541281cf3SAxel Dörfler } 94641281cf3SAxel Dörfler 94741281cf3SAxel Dörfler return B_ERROR; 94841281cf3SAxel Dörfler } 94941281cf3SAxel Dörfler 95041281cf3SAxel Dörfler 9517da06231SAxel Dörfler /** for a specific name 9527da06231SAxel Dörfler * return the id (internal to Deskbar) 9537da06231SAxel Dörfler */ 9547da06231SAxel Dörfler 95541281cf3SAxel Dörfler status_t 95641281cf3SAxel Dörfler TReplicantTray::ItemInfo(const char *name, int32 *id) 95741281cf3SAxel Dörfler { 95841281cf3SAxel Dörfler if (!name || strlen(name) <= 0) 95941281cf3SAxel Dörfler return B_ERROR; 96041281cf3SAxel Dörfler 96141281cf3SAxel Dörfler int32 index; 96241281cf3SAxel Dörfler BView *view = ViewAt(&index, id, name); 96341281cf3SAxel Dörfler if (view) 96441281cf3SAxel Dörfler return B_OK; 96541281cf3SAxel Dörfler 96641281cf3SAxel Dörfler return B_ERROR; 96741281cf3SAxel Dörfler } 96841281cf3SAxel Dörfler 96941281cf3SAxel Dörfler 9707da06231SAxel Dörfler /** at a specific index 9717da06231SAxel Dörfler * return both the name and the id of the replicant 9727da06231SAxel Dörfler */ 9737da06231SAxel Dörfler 97441281cf3SAxel Dörfler status_t 97541281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 index, const char **name, int32 *id) 97641281cf3SAxel Dörfler { 97741281cf3SAxel Dörfler if (index < 0) 97841281cf3SAxel Dörfler return B_ERROR; 97941281cf3SAxel Dörfler 98041281cf3SAxel Dörfler BView *view; 98141281cf3SAxel Dörfler fShelf->ReplicantAt(index, &view, (uint32 *)id, NULL); 98241281cf3SAxel Dörfler if (view) { 98341281cf3SAxel Dörfler *name = view->Name(); 98441281cf3SAxel Dörfler return B_OK; 98541281cf3SAxel Dörfler } 98641281cf3SAxel Dörfler 98741281cf3SAxel Dörfler return B_ERROR; 98841281cf3SAxel Dörfler } 98941281cf3SAxel Dörfler 99041281cf3SAxel Dörfler 9917da06231SAxel Dörfler /** replicant exists, by id/index */ 9927da06231SAxel Dörfler 99341281cf3SAxel Dörfler bool 99441281cf3SAxel Dörfler TReplicantTray::IconExists(int32 target, bool byIndex) 99541281cf3SAxel Dörfler { 99641281cf3SAxel Dörfler int32 index, id; 99741281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, target, byIndex); 99841281cf3SAxel Dörfler 99941281cf3SAxel Dörfler return view && index >= 0; 100041281cf3SAxel Dörfler } 100141281cf3SAxel Dörfler 100241281cf3SAxel Dörfler 10037da06231SAxel Dörfler /** replicant exists, by name */ 10047da06231SAxel Dörfler 100541281cf3SAxel Dörfler bool 100641281cf3SAxel Dörfler TReplicantTray::IconExists(const char *name) 100741281cf3SAxel Dörfler { 100841281cf3SAxel Dörfler if (!name || strlen(name) == 0) 100941281cf3SAxel Dörfler return false; 101041281cf3SAxel Dörfler 101141281cf3SAxel Dörfler int32 index, id; 101241281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, name); 101341281cf3SAxel Dörfler 101441281cf3SAxel Dörfler return view && index >= 0; 101541281cf3SAxel Dörfler } 101641281cf3SAxel Dörfler 101741281cf3SAxel Dörfler 101841281cf3SAxel Dörfler int32 101941281cf3SAxel Dörfler TReplicantTray::IconCount() const 102041281cf3SAxel Dörfler { 102141281cf3SAxel Dörfler return fShelf->CountReplicants(); 102241281cf3SAxel Dörfler } 102341281cf3SAxel Dörfler 102441281cf3SAxel Dörfler 1025ced3755cSAxel Dörfler /*! Message must contain an archivable view for later rehydration. 1026ced3755cSAxel Dörfler This function takes over ownership of the provided message on success 1027ced3755cSAxel Dörfler only. 1028ced3755cSAxel Dörfler Returns the current replicant ID. 10297da06231SAxel Dörfler */ 103041281cf3SAxel Dörfler status_t 1031ced3755cSAxel Dörfler TReplicantTray::AddIcon(BMessage *archive, int32 *id, const entry_ref *addOn) 103241281cf3SAxel Dörfler { 1033ced3755cSAxel Dörfler if (archive == NULL || id == NULL) 103441281cf3SAxel Dörfler return B_ERROR; 103541281cf3SAxel Dörfler 10369c50f36eSAxel Dörfler // find entry_ref 10379c50f36eSAxel Dörfler 10389c50f36eSAxel Dörfler entry_ref ref; 10399c50f36eSAxel Dörfler if (addOn) { 10409c50f36eSAxel Dörfler // Use it if we got it 10419c50f36eSAxel Dörfler ref = *addOn; 10429c50f36eSAxel Dörfler } else { 10439c50f36eSAxel Dörfler const char *signature; 1044ced3755cSAxel Dörfler status_t status = archive->FindString("add_on", &signature); 10459c50f36eSAxel Dörfler if (status == B_OK) { 10469c50f36eSAxel Dörfler BRoster roster; 10479c50f36eSAxel Dörfler status = roster.FindApp(signature, &ref); 10489c50f36eSAxel Dörfler } 10499c50f36eSAxel Dörfler if (status < B_OK) 10509c50f36eSAxel Dörfler return status; 10519c50f36eSAxel Dörfler } 10529c50f36eSAxel Dörfler 10539c50f36eSAxel Dörfler BFile file; 10549c50f36eSAxel Dörfler status_t status = file.SetTo(&ref, B_READ_ONLY); 10559c50f36eSAxel Dörfler if (status < B_OK) 10569c50f36eSAxel Dörfler return status; 10579c50f36eSAxel Dörfler 10589c50f36eSAxel Dörfler node_ref nodeRef; 10599c50f36eSAxel Dörfler status = file.GetNodeRef(&nodeRef); 10609c50f36eSAxel Dörfler if (status < B_OK) 10619c50f36eSAxel Dörfler return status; 10629c50f36eSAxel Dörfler 10639c50f36eSAxel Dörfler BEntry entry(&ref, true); 10649c50f36eSAxel Dörfler // ToDo: this resolves an eventual link for the item 10659c50f36eSAxel Dörfler // being added - this is okay for now, but in multi-user 10669c50f36eSAxel Dörfler // environments, one might want to have links that 10679c50f36eSAxel Dörfler // carry the be:deskbar_item_status attribute 10689c50f36eSAxel Dörfler status = entry.InitCheck(); 10699c50f36eSAxel Dörfler if (status != B_OK) 10709c50f36eSAxel Dörfler return status; 10719c50f36eSAxel Dörfler 107241281cf3SAxel Dörfler *id = 999; 1073ced3755cSAxel Dörfler if (archive->what == B_ARCHIVED_OBJECT) 1074ced3755cSAxel Dörfler archive->what = 0; 107541281cf3SAxel Dörfler 1076ced3755cSAxel Dörfler BRect originalBounds = archive->FindRect("_frame"); 1077a5210ab1SAxel Dörfler // this is a work-around for buggy replicants that change their 1078a5210ab1SAxel Dörfler // size in AttachedToWindow() (such as "SVM") 1079a5210ab1SAxel Dörfler 108041281cf3SAxel Dörfler // !! check for name collisions? 1081ced3755cSAxel Dörfler status = fShelf->AddReplicant(archive, BPoint(1, 1)); 10829c50f36eSAxel Dörfler if (status != B_OK) 10839c50f36eSAxel Dörfler return status; 108441281cf3SAxel Dörfler 1085a5210ab1SAxel Dörfler int32 count = fShelf->CountReplicants(); 1086a5210ab1SAxel Dörfler BView *view; 1087a5210ab1SAxel Dörfler fShelf->ReplicantAt(count - 1, &view, (uint32 *)id, NULL); 1088a5210ab1SAxel Dörfler 1089a5210ab1SAxel Dörfler if (originalBounds != view->Bounds()) { 1090a5210ab1SAxel Dörfler // The replicant changed its size when added to the window, so we need 1091a5210ab1SAxel Dörfler // to recompute all over again (it's already done once via BShelf::AddReplicant() 1092a5210ab1SAxel Dörfler // and TReplicantShelf::CanAcceptReplicantView()) 1093a5210ab1SAxel Dörfler RealignReplicants(); 1094a5210ab1SAxel Dörfler } 1095a5210ab1SAxel Dörfler 109641281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 109741281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 109841281cf3SAxel Dörfler float width, height; 109941281cf3SAxel Dörfler GetPreferredSize(&width, &height); 110041281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) 110141281cf3SAxel Dörfler AdjustPlacement(); 110241281cf3SAxel Dörfler 110341281cf3SAxel Dörfler // add the item to the add-on list 110441281cf3SAxel Dörfler 110541281cf3SAxel Dörfler AddItem(*id, nodeRef, entry, addOn != NULL); 110641281cf3SAxel Dörfler return B_OK; 110741281cf3SAxel Dörfler } 110841281cf3SAxel Dörfler 110941281cf3SAxel Dörfler 111041281cf3SAxel Dörfler void 111141281cf3SAxel Dörfler TReplicantTray::RemoveIcon(int32 target, bool byIndex) 111241281cf3SAxel Dörfler { 111341281cf3SAxel Dörfler if (target < 0) 111441281cf3SAxel Dörfler return; 111541281cf3SAxel Dörfler 111641281cf3SAxel Dörfler int32 index, id; 111741281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, target, byIndex); 111841281cf3SAxel Dörfler if (view && index >= 0) { 11197da06231SAxel Dörfler // remove the reference from the item list & the 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 113041281cf3SAxel Dörfler TReplicantTray::RemoveIcon(const char *name) 113141281cf3SAxel Dörfler { 113241281cf3SAxel Dörfler if (!name || strlen(name) <= 0) 113341281cf3SAxel Dörfler return; 113441281cf3SAxel Dörfler 113541281cf3SAxel Dörfler int32 id, index; 113641281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, name); 113741281cf3SAxel Dörfler if (view && index >= 0) { 11387da06231SAxel Dörfler // remove the reference from the item list & shelf 113941281cf3SAxel Dörfler RemoveItem(id); 114041281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 11417da06231SAxel Dörfler 114241281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 114341281cf3SAxel Dörfler RealReplicantAdjustment(index); 114441281cf3SAxel Dörfler } 114541281cf3SAxel Dörfler } 114641281cf3SAxel Dörfler 114741281cf3SAxel Dörfler 114841281cf3SAxel Dörfler void 11497da06231SAxel Dörfler TReplicantTray::RealReplicantAdjustment(int32 startIndex) 115041281cf3SAxel Dörfler { 11517da06231SAxel Dörfler if (startIndex < 0) 115241281cf3SAxel Dörfler return; 11537da06231SAxel Dörfler 11547da06231SAxel Dörfler if (startIndex == fLastReplicant) 11557da06231SAxel Dörfler startIndex = 0; 11567da06231SAxel Dörfler 115741281cf3SAxel Dörfler // reset the locations of all replicants after the one deleted 11587da06231SAxel Dörfler RealignReplicants(startIndex); 115941281cf3SAxel Dörfler 116041281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 116141281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 116241281cf3SAxel Dörfler float width, height; 116341281cf3SAxel Dörfler GetPreferredSize(&width, &height); 116441281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) { 116541281cf3SAxel Dörfler // resize view to accomodate the replicants 116641281cf3SAxel Dörfler // redraw as necessary 116741281cf3SAxel Dörfler AdjustPlacement(); 116841281cf3SAxel Dörfler } 116941281cf3SAxel Dörfler } 117041281cf3SAxel Dörfler 117141281cf3SAxel Dörfler 11727da06231SAxel Dörfler /** looking for a replicant by id/index 11737da06231SAxel Dörfler * return the view and index 11747da06231SAxel Dörfler */ 11757da06231SAxel Dörfler 117641281cf3SAxel Dörfler BView * 117741281cf3SAxel Dörfler TReplicantTray::ViewAt(int32 *index, int32 *id, int32 target, bool byIndex) 117841281cf3SAxel Dörfler { 117941281cf3SAxel Dörfler *index = -1; 118041281cf3SAxel Dörfler 118141281cf3SAxel Dörfler BView *view; 118241281cf3SAxel Dörfler if (byIndex){ 118341281cf3SAxel Dörfler if (fShelf->ReplicantAt(target, &view, (uint32 *)id)) { 118441281cf3SAxel Dörfler if (view) { 118541281cf3SAxel Dörfler *index = target; 118641281cf3SAxel Dörfler return view; 118741281cf3SAxel Dörfler } 118841281cf3SAxel Dörfler } 118941281cf3SAxel Dörfler } else { 119041281cf3SAxel Dörfler int32 count = fShelf->CountReplicants()-1; 119141281cf3SAxel Dörfler int32 localid; 119241281cf3SAxel Dörfler for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { 119341281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32 *)&localid); 119441281cf3SAxel Dörfler if (localid == target && view) { 119541281cf3SAxel Dörfler *index = repIndex; 119641281cf3SAxel Dörfler *id = localid; 119741281cf3SAxel Dörfler return view; 119841281cf3SAxel Dörfler } 119941281cf3SAxel Dörfler } 120041281cf3SAxel Dörfler } 120141281cf3SAxel Dörfler 120241281cf3SAxel Dörfler return NULL; 120341281cf3SAxel Dörfler } 120441281cf3SAxel Dörfler 120541281cf3SAxel Dörfler 12067da06231SAxel Dörfler /** looking for a replicant with a view by name 12077da06231SAxel Dörfler * return the view, index and the id of the replicant 12087da06231SAxel Dörfler */ 12097da06231SAxel Dörfler 121041281cf3SAxel Dörfler BView * 121141281cf3SAxel Dörfler TReplicantTray::ViewAt(int32 *index, int32 *id, const char *name) 121241281cf3SAxel Dörfler { 121341281cf3SAxel Dörfler *index = -1; 121441281cf3SAxel Dörfler *id = -1; 121541281cf3SAxel Dörfler 121641281cf3SAxel Dörfler BView *view; 121741281cf3SAxel Dörfler int32 count = fShelf->CountReplicants()-1; 121841281cf3SAxel Dörfler for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { 121941281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32 *)id); 122041281cf3SAxel Dörfler if (view && view->Name() && strcmp(name, view->Name()) == 0) { 122141281cf3SAxel Dörfler *index = repIndex; 122241281cf3SAxel Dörfler return view; 122341281cf3SAxel Dörfler } 122441281cf3SAxel Dörfler } 122541281cf3SAxel Dörfler 122641281cf3SAxel Dörfler return NULL; 122741281cf3SAxel Dörfler } 122841281cf3SAxel Dörfler 122941281cf3SAxel Dörfler 12307da06231SAxel Dörfler /** Shelf will call to determine where and if 12317da06231SAxel Dörfler * the replicant is to be added 12327da06231SAxel Dörfler */ 12337da06231SAxel Dörfler 123441281cf3SAxel Dörfler bool 123541281cf3SAxel Dörfler TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage *message) 123641281cf3SAxel Dörfler { 123741281cf3SAxel Dörfler if (!message) 123841281cf3SAxel Dörfler return false; 123941281cf3SAxel Dörfler 124041281cf3SAxel Dörfler if (replicantFrame.Height() > kMaxReplicantHeight) 124141281cf3SAxel Dörfler return false; 124241281cf3SAxel Dörfler 124341281cf3SAxel Dörfler alignment align = B_ALIGN_LEFT; 124441281cf3SAxel Dörfler if (fAlignmentSupport && message->HasBool("deskbar:dynamic_align")) { 124541281cf3SAxel Dörfler if (!fBarView->Vertical()) 124641281cf3SAxel Dörfler align = B_ALIGN_RIGHT; 124741281cf3SAxel Dörfler else 124841281cf3SAxel Dörfler align = fBarView->Left() ? B_ALIGN_LEFT : B_ALIGN_RIGHT; 124941281cf3SAxel Dörfler } else if (message->HasInt32("deskbar:align")) 125041281cf3SAxel Dörfler message->FindInt32("deskbar:align", (int32 *)&align); 125141281cf3SAxel Dörfler 125241281cf3SAxel Dörfler if (message->HasInt32("deskbar:private_align")) 125341281cf3SAxel Dörfler message->FindInt32("deskbar:private_align", (int32 *)&align); 125441281cf3SAxel Dörfler else 125541281cf3SAxel Dörfler align = B_ALIGN_LEFT; 125641281cf3SAxel Dörfler 12577da06231SAxel Dörfler BPoint loc = LocationForReplicant(fShelf->CountReplicants(), 12587da06231SAxel Dörfler replicantFrame.Width()); 125941281cf3SAxel Dörfler 126041281cf3SAxel Dörfler message->AddPoint("_pjp_loc", loc); 126141281cf3SAxel Dörfler return true; 126241281cf3SAxel Dörfler } 126341281cf3SAxel Dörfler 126441281cf3SAxel Dörfler 126541281cf3SAxel Dörfler /** based on the previous (index - 1) replicant in the list 126641281cf3SAxel Dörfler * calculate where the left point should be for this 126741281cf3SAxel Dörfler * replicant. replicant will flow to the right on its own 126841281cf3SAxel Dörfler */ 126941281cf3SAxel Dörfler 127041281cf3SAxel Dörfler BPoint 12717da06231SAxel Dörfler TReplicantTray::LocationForReplicant(int32 index, float width) 127241281cf3SAxel Dörfler { 127341281cf3SAxel Dörfler BPoint loc(kIconGap + 1, kGutter + 1); 127441281cf3SAxel Dörfler 12757da06231SAxel Dörfler if (fMultiRowMode) { 12767da06231SAxel Dörfler // try to find free space in every row 12777da06231SAxel Dörfler for (int32 row = 0; ; loc.y += kMaxReplicantHeight + kIconGap, row++) { 12787da06231SAxel Dörfler // determine free space in this row 1279157cd891SAlexandre Deckner BRect rect(loc.x, loc.y, loc.x + kMinimumTrayWidth - kIconGap - 2.0, loc.y + kMaxReplicantHeight); 12807da06231SAxel Dörfler if (row == 0 && fBarView->ShowingClock()) 12817da06231SAxel Dörfler rect.right -= fClock->Frame().Width() + kIconGap; 12827da06231SAxel Dörfler 12837da06231SAxel Dörfler for (int32 i = 0; i < index; i++) { 12847da06231SAxel Dörfler BView *view = NULL; 12857da06231SAxel Dörfler fShelf->ReplicantAt(i, &view); 12867da06231SAxel Dörfler if (view == NULL || view->Frame().top != rect.top) 12877da06231SAxel Dörfler continue; 12887da06231SAxel Dörfler 12897da06231SAxel Dörfler rect.left = view->Frame().right + kIconGap + 1; 12907da06231SAxel Dörfler } 12917da06231SAxel Dörfler 12927da06231SAxel Dörfler if (rect.Width() >= width) { 12937da06231SAxel Dörfler // the icon fits in this row 12947da06231SAxel Dörfler loc = rect.LeftTop(); 12957da06231SAxel Dörfler break; 12967da06231SAxel Dörfler } 12977da06231SAxel Dörfler } 12987da06231SAxel Dörfler } else { 129941281cf3SAxel Dörfler if (index > 0) { 130041281cf3SAxel Dörfler // get the last replicant added for placement reference 130141281cf3SAxel Dörfler BView *view = NULL; 13027da06231SAxel Dörfler fShelf->ReplicantAt(index - 1, &view); 130341281cf3SAxel Dörfler if (view) { 130441281cf3SAxel Dörfler // push this rep placement past the last one 130541281cf3SAxel Dörfler loc.x = view->Frame().right + kIconGap + 1; 130641281cf3SAxel Dörfler loc.y = view->Frame().top; 130741281cf3SAxel Dörfler } 130841281cf3SAxel Dörfler } 13097da06231SAxel Dörfler } 131041281cf3SAxel Dörfler 13117da06231SAxel Dörfler if ((loc.y == fRightBottomReplicant.top && loc.x > fRightBottomReplicant.left) 13127da06231SAxel Dörfler || loc.y > fRightBottomReplicant.top) { 13137da06231SAxel Dörfler fRightBottomReplicant.Set(loc.x, loc.y, loc.x + width, loc.y + kMaxReplicantHeight); 13147da06231SAxel Dörfler fLastReplicant = index; 131541281cf3SAxel Dörfler } 13167da06231SAxel Dörfler 131741281cf3SAxel Dörfler return loc; 131841281cf3SAxel Dörfler } 131941281cf3SAxel Dörfler 132041281cf3SAxel Dörfler 132141281cf3SAxel Dörfler BRect 132241281cf3SAxel Dörfler TReplicantTray::IconFrame(int32 target, bool byIndex) 132341281cf3SAxel Dörfler { 132441281cf3SAxel Dörfler int32 index, id; 132541281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, target, byIndex); 132641281cf3SAxel Dörfler if (view) 132741281cf3SAxel Dörfler return view->Frame(); 132841281cf3SAxel Dörfler 132941281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 133041281cf3SAxel Dörfler } 133141281cf3SAxel Dörfler 133241281cf3SAxel Dörfler 133341281cf3SAxel Dörfler BRect 133441281cf3SAxel Dörfler TReplicantTray::IconFrame(const char *name) 133541281cf3SAxel Dörfler { 133641281cf3SAxel Dörfler if (!name) 133741281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 133841281cf3SAxel Dörfler 133941281cf3SAxel Dörfler int32 id, index; 134041281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, name); 134141281cf3SAxel Dörfler if (view) 134241281cf3SAxel Dörfler return view->Frame(); 134341281cf3SAxel Dörfler 134441281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 134541281cf3SAxel Dörfler } 134641281cf3SAxel Dörfler 134741281cf3SAxel Dörfler 13487da06231SAxel Dörfler /** Scan from the startIndex and reset the location 13497da06231SAxel Dörfler * as defined in LocationForReplicant() 135041281cf3SAxel Dörfler */ 135141281cf3SAxel Dörfler 135241281cf3SAxel Dörfler void 135341281cf3SAxel Dörfler TReplicantTray::RealignReplicants(int32 startIndex) 135441281cf3SAxel Dörfler { 135541281cf3SAxel Dörfler if (startIndex < 0) 135641281cf3SAxel Dörfler startIndex = 0; 135741281cf3SAxel Dörfler 135841281cf3SAxel Dörfler int32 count = fShelf->CountReplicants(); 135941281cf3SAxel Dörfler if (count <= 0) 136041281cf3SAxel Dörfler return; 136141281cf3SAxel Dörfler 13627da06231SAxel Dörfler if (startIndex == 0) 13637da06231SAxel Dörfler fRightBottomReplicant.Set(0, 0, 0, 0); 13647da06231SAxel Dörfler 136541281cf3SAxel Dörfler BView *view = NULL; 136641281cf3SAxel Dörfler for (int32 i = startIndex ; i < count ; i++){ 136741281cf3SAxel Dörfler fShelf->ReplicantAt(i, &view); 1368*0bec7100SStefano Ceccherini if (view != NULL) { 13697da06231SAxel Dörfler BPoint loc = LocationForReplicant(i, view->Frame().Width()); 1370*0bec7100SStefano Ceccherini if (view->Frame().LeftTop() != loc) 137141281cf3SAxel Dörfler view->MoveTo(loc); 137241281cf3SAxel Dörfler } 137341281cf3SAxel Dörfler } 137441281cf3SAxel Dörfler } 137541281cf3SAxel Dörfler 137641281cf3SAxel Dörfler 137741281cf3SAxel Dörfler void 137841281cf3SAxel Dörfler TReplicantTray::SetMultiRow(bool state) 137941281cf3SAxel Dörfler { 138041281cf3SAxel Dörfler fMultiRowMode = state; 138141281cf3SAxel Dörfler 138241281cf3SAxel Dörfler // in multi-row state, we only want the short date 138341281cf3SAxel Dörfler 138441281cf3SAxel Dörfler if (fClock != NULL) 138541281cf3SAxel Dörfler fClock->AllowFullDate(!state); 138641281cf3SAxel Dörfler } 138741281cf3SAxel Dörfler 138841281cf3SAxel Dörfler 138941281cf3SAxel Dörfler // #pragma mark - 139041281cf3SAxel Dörfler 139141281cf3SAxel Dörfler 13927da06231SAxel Dörfler /** draggable region that is asynchronous so that 13937da06231SAxel Dörfler * dragging does not block other activities 13947da06231SAxel Dörfler */ 13957da06231SAxel Dörfler 139641281cf3SAxel Dörfler TDragRegion::TDragRegion(TBarView *parent, BView *child) 139741281cf3SAxel Dörfler : BControl(BRect(0, 0, 0, 0), "", "", NULL, B_FOLLOW_NONE, 139841281cf3SAxel Dörfler B_WILL_DRAW | B_FRAME_EVENTS), 139941281cf3SAxel Dörfler fBarView(parent), 140041281cf3SAxel Dörfler fChild(child), 140141281cf3SAxel Dörfler fDragLocation(kAutoPlaceDragRegion) 140241281cf3SAxel Dörfler { 140341281cf3SAxel Dörfler } 140441281cf3SAxel Dörfler 140541281cf3SAxel Dörfler 140641281cf3SAxel Dörfler void 140741281cf3SAxel Dörfler TDragRegion::AttachedToWindow() 140841281cf3SAxel Dörfler { 140941281cf3SAxel Dörfler BView::AttachedToWindow(); 141041281cf3SAxel Dörfler SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); 141141281cf3SAxel Dörfler ResizeToPreferred(); 141241281cf3SAxel Dörfler } 141341281cf3SAxel Dörfler 141441281cf3SAxel Dörfler 141541281cf3SAxel Dörfler void 141641281cf3SAxel Dörfler TDragRegion::GetPreferredSize(float *width, float *height) 141741281cf3SAxel Dörfler { 141841281cf3SAxel Dörfler fChild->ResizeToPreferred(); 141941281cf3SAxel Dörfler *width = fChild->Bounds().Width(); 142041281cf3SAxel Dörfler *height = fChild->Bounds().Height(); 142141281cf3SAxel Dörfler 142241281cf3SAxel Dörfler if (fDragLocation != kNoDragRegion) 142341281cf3SAxel Dörfler *width += 7; 142441281cf3SAxel Dörfler else 142541281cf3SAxel Dörfler *width += 6; 142641281cf3SAxel Dörfler 142741281cf3SAxel Dörfler *height += 3; 142841281cf3SAxel Dörfler } 142941281cf3SAxel Dörfler 143041281cf3SAxel Dörfler 143141281cf3SAxel Dörfler void 143241281cf3SAxel Dörfler TDragRegion::FrameMoved(BPoint) 143341281cf3SAxel Dörfler { 143441281cf3SAxel Dörfler if (fBarView->Left() && fBarView->Vertical() && fDragLocation != kNoDragRegion) 143541281cf3SAxel Dörfler fChild->MoveTo(5,2); 143641281cf3SAxel Dörfler else 143741281cf3SAxel Dörfler fChild->MoveTo(2,2); 143841281cf3SAxel Dörfler } 143941281cf3SAxel Dörfler 144041281cf3SAxel Dörfler 144141281cf3SAxel Dörfler void 144241281cf3SAxel Dörfler TDragRegion::Draw(BRect) 144341281cf3SAxel Dörfler { 144441281cf3SAxel Dörfler rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR); 144541281cf3SAxel Dörfler rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT); 144641281cf3SAxel Dörfler rgb_color vdark = tint_color(menuColor, B_DARKEN_3_TINT); 144741281cf3SAxel Dörfler rgb_color vvdark = tint_color(menuColor, B_DARKEN_4_TINT); 144841281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 144941281cf3SAxel Dörfler 145041281cf3SAxel Dörfler BRect frame(Bounds()); 145141281cf3SAxel Dörfler BeginLineArray(4); 145241281cf3SAxel Dörfler 145341281cf3SAxel Dörfler if (fBarView->Vertical()) { 145441281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.RightTop(), light); 145541281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.LeftBottom(), light); 145641281cf3SAxel Dörfler AddLine(frame.RightBottom(), frame.RightTop(), hilite); 145741281cf3SAxel Dörfler } else if (fBarView->AcrossTop()) { 145841281cf3SAxel Dörfler AddLine(frame.LeftTop()+BPoint(0, 1), frame.RightTop()+BPoint(-1, 1), 145941281cf3SAxel Dörfler light); 146041281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 146141281cf3SAxel Dörfler AddLine(frame.RightTop()+BPoint(-1, 2),frame.RightBottom()+BPoint(-1, -1), 146241281cf3SAxel Dörfler hilite); 146341281cf3SAxel Dörfler AddLine(frame.LeftBottom(), frame.RightBottom()+BPoint(-1, 0), hilite); 146441281cf3SAxel Dörfler } else if (fBarView->AcrossBottom()) { 146541281cf3SAxel Dörfler AddLine(frame.LeftTop()+BPoint(0, 1), frame.RightTop()+BPoint(-1, 1), light); 146641281cf3SAxel Dörfler AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 146741281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 146841281cf3SAxel Dörfler AddLine(frame.RightTop()+BPoint(-1, 1),frame.RightBottom()+BPoint(-1, -1), 146941281cf3SAxel Dörfler hilite); 147041281cf3SAxel Dörfler } 147141281cf3SAxel Dörfler 147241281cf3SAxel Dörfler EndLineArray(); 147341281cf3SAxel Dörfler 147441281cf3SAxel Dörfler if (fDragLocation != kDontDrawDragRegion || fDragLocation != kNoDragRegion) 147541281cf3SAxel Dörfler DrawDragRegion(); 147641281cf3SAxel Dörfler } 147741281cf3SAxel Dörfler 147841281cf3SAxel Dörfler 147941281cf3SAxel Dörfler void 148041281cf3SAxel Dörfler TDragRegion::DrawDragRegion() 148141281cf3SAxel Dörfler { 148241281cf3SAxel Dörfler rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR); 148341281cf3SAxel Dörfler rgb_color menuHilite = tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT); 148441281cf3SAxel Dörfler rgb_color vdark = tint_color(menuColor, B_DARKEN_3_TINT); 148541281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 148641281cf3SAxel Dörfler 148741281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 148841281cf3SAxel Dörfler 148941281cf3SAxel Dörfler BeginLineArray(dragRegion.IntegerHeight()); 149041281cf3SAxel Dörfler BPoint pt = dragRegion.LeftTop() + BPoint(1,1); 149141281cf3SAxel Dörfler 149241281cf3SAxel Dörfler // Draw drag region highlighted if tracking mouse 149341281cf3SAxel Dörfler if (IsTracking()) { 149441281cf3SAxel Dörfler SetHighColor(menuHilite); 149541281cf3SAxel Dörfler FillRect(dragRegion); 149641281cf3SAxel Dörfler while (pt.y + 1 <= dragRegion.bottom) { 149741281cf3SAxel Dörfler AddLine(pt, pt, light); 149841281cf3SAxel Dörfler AddLine(pt+BPoint(1,1), pt+BPoint(1,1), vdark); 149941281cf3SAxel Dörfler 150041281cf3SAxel Dörfler pt.y += 3; 150141281cf3SAxel Dörfler } 150241281cf3SAxel Dörfler } else { 150341281cf3SAxel Dörfler while (pt.y + 1 <= dragRegion.bottom) { 150441281cf3SAxel Dörfler AddLine(pt, pt, vdark); 150541281cf3SAxel Dörfler AddLine(pt+BPoint(1,1), pt+BPoint(1,1), light); 150641281cf3SAxel Dörfler 150741281cf3SAxel Dörfler pt.y += 3; 150841281cf3SAxel Dörfler } 150941281cf3SAxel Dörfler } 151041281cf3SAxel Dörfler EndLineArray(); 151141281cf3SAxel Dörfler } 151241281cf3SAxel Dörfler 151341281cf3SAxel Dörfler 151441281cf3SAxel Dörfler BRect 151541281cf3SAxel Dörfler TDragRegion::DragRegion() const 151641281cf3SAxel Dörfler { 151741281cf3SAxel Dörfler BRect dragRegion(Bounds()); 151841281cf3SAxel Dörfler dragRegion.top += 2; 151941281cf3SAxel Dörfler dragRegion.bottom -= 2; 152041281cf3SAxel Dörfler 152141281cf3SAxel Dörfler bool placeOnLeft=false; 152241281cf3SAxel Dörfler if (fDragLocation == kAutoPlaceDragRegion) { 152341281cf3SAxel Dörfler if (fBarView->Vertical() && fBarView->Left()) 152441281cf3SAxel Dörfler placeOnLeft = true; 152541281cf3SAxel Dörfler else 152641281cf3SAxel Dörfler placeOnLeft = false; 152741281cf3SAxel Dörfler } else if (fDragLocation == kDragRegionLeft) 152841281cf3SAxel Dörfler placeOnLeft = true; 152941281cf3SAxel Dörfler else if (fDragLocation == kDragRegionRight) 153041281cf3SAxel Dörfler placeOnLeft = false; 153141281cf3SAxel Dörfler 153241281cf3SAxel Dörfler if (placeOnLeft) { 153341281cf3SAxel Dörfler dragRegion.left += 1; 153441281cf3SAxel Dörfler dragRegion.right = dragRegion.left + 3; 153541281cf3SAxel Dörfler } else { 153641281cf3SAxel Dörfler dragRegion.right -= 1; 153741281cf3SAxel Dörfler dragRegion.left = dragRegion.right - 3; 153841281cf3SAxel Dörfler } 153941281cf3SAxel Dörfler 154041281cf3SAxel Dörfler return dragRegion; 154141281cf3SAxel Dörfler } 154241281cf3SAxel Dörfler 154341281cf3SAxel Dörfler 154441281cf3SAxel Dörfler void 154541281cf3SAxel Dörfler TDragRegion::MouseDown(BPoint thePoint) 154641281cf3SAxel Dörfler { 154741281cf3SAxel Dörfler ulong buttons; 154841281cf3SAxel Dörfler BPoint where; 154941281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 155041281cf3SAxel Dörfler 15517da06231SAxel Dörfler dragRegion.InsetBy(-2.0f, -2.0f); 15527da06231SAxel Dörfler // DragRegion() is designed for drawing, not clicking 155341281cf3SAxel Dörfler 155441281cf3SAxel Dörfler if (!dragRegion.Contains(thePoint)) 155541281cf3SAxel Dörfler return; 155641281cf3SAxel Dörfler 155741281cf3SAxel Dörfler while(true) { 155841281cf3SAxel Dörfler GetMouse(&where, &buttons); 155941281cf3SAxel Dörfler if (!buttons) 156041281cf3SAxel Dörfler break; 156141281cf3SAxel Dörfler 156241281cf3SAxel Dörfler if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) != 0) { 156341281cf3SAxel Dörfler fPreviousPosition = thePoint; 156441281cf3SAxel Dörfler SetTracking(true); 156541281cf3SAxel Dörfler SetMouseEventMask(B_POINTER_EVENTS, 156641281cf3SAxel Dörfler B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); 156741281cf3SAxel Dörfler Invalidate(DragRegion()); 156841281cf3SAxel Dörfler break; 156941281cf3SAxel Dörfler } 157041281cf3SAxel Dörfler 157141281cf3SAxel Dörfler snooze(25000); 157241281cf3SAxel Dörfler } 157341281cf3SAxel Dörfler } 157441281cf3SAxel Dörfler 157541281cf3SAxel Dörfler 157641281cf3SAxel Dörfler void 157741281cf3SAxel Dörfler TDragRegion::MouseUp(BPoint pt) 157841281cf3SAxel Dörfler { 157941281cf3SAxel Dörfler if (IsTracking()) { 158041281cf3SAxel Dörfler SetTracking(false); 158141281cf3SAxel Dörfler Invalidate(DragRegion()); 158241281cf3SAxel Dörfler } else 158341281cf3SAxel Dörfler BControl::MouseUp(pt); 158441281cf3SAxel Dörfler } 158541281cf3SAxel Dörfler 158641281cf3SAxel Dörfler 158741281cf3SAxel Dörfler bool 158841281cf3SAxel Dörfler TDragRegion::SwitchModeForRect(BPoint mouse, BRect rect, 158941281cf3SAxel Dörfler bool newVertical, bool newLeft, bool newTop, int32 newState) 159041281cf3SAxel Dörfler { 159141281cf3SAxel Dörfler if (!rect.Contains(mouse)) 159241281cf3SAxel Dörfler // not our rect 159341281cf3SAxel Dörfler return false; 159441281cf3SAxel Dörfler 159541281cf3SAxel Dörfler if (newVertical == fBarView->Vertical() 159641281cf3SAxel Dörfler && newLeft == fBarView->Left() 159741281cf3SAxel Dörfler && newTop == fBarView->Top() 159841281cf3SAxel Dörfler && newState == fBarView->State()) 159941281cf3SAxel Dörfler // already in the correct mode 160041281cf3SAxel Dörfler return true; 160141281cf3SAxel Dörfler 160241281cf3SAxel Dörfler fBarView->ChangeState(newState, newVertical, newLeft, newTop); 160341281cf3SAxel Dörfler return true; 160441281cf3SAxel Dörfler } 160541281cf3SAxel Dörfler 160641281cf3SAxel Dörfler 160741281cf3SAxel Dörfler void 160841281cf3SAxel Dörfler TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage *message) 160941281cf3SAxel Dörfler { 161041281cf3SAxel Dörfler if (IsTracking()) { 161141281cf3SAxel Dörfler BScreen screen; 161241281cf3SAxel Dörfler BRect frame = screen.Frame(); 161341281cf3SAxel Dörfler 161441281cf3SAxel Dörfler float hDivider = frame.Width() / 6; 161541281cf3SAxel Dörfler hDivider = (hDivider < kMinimumWindowWidth + 10.0f) ? kMinimumWindowWidth + 10.0f : hDivider; 161641281cf3SAxel Dörfler float miniDivider = frame.top + kMiniHeight + 10.0f; 161741281cf3SAxel Dörfler float vDivider = frame.Height() / 2; 161841281cf3SAxel Dörfler #ifdef FULL_MODE 161941281cf3SAxel Dörfler float thirdScreen = frame.Height() / 3; 162041281cf3SAxel Dörfler #endif 162141281cf3SAxel Dörfler BRect topLeft(frame.left, frame.top, frame.left + hDivider, miniDivider); 162241281cf3SAxel Dörfler BRect topMiddle(frame.left + hDivider, frame.top, frame.right - hDivider, vDivider); 162341281cf3SAxel Dörfler BRect topRight(frame.right - hDivider, frame.top, frame.right, miniDivider); 162441281cf3SAxel Dörfler 162541281cf3SAxel Dörfler #ifdef FULL_MODE 162641281cf3SAxel Dörfler vDivider = miniDivider + thirdScreen; 162741281cf3SAxel Dörfler #endif 162841281cf3SAxel Dörfler BRect middleLeft(frame.left, miniDivider, frame.left + hDivider, vDivider); 162941281cf3SAxel Dörfler BRect middleRight(frame.right - hDivider, miniDivider, frame.right, vDivider); 163041281cf3SAxel Dörfler 163141281cf3SAxel Dörfler #ifdef FULL_MODE 163241281cf3SAxel Dörfler BRect leftSide(frame.left, vDivider, frame.left + hDivider, frame.bottom - thirdScreen); 163341281cf3SAxel Dörfler BRect rightSide(frame.right - hDivider, vDivider, frame.right, frame.bottom - thirdScreen); 163441281cf3SAxel Dörfler 163541281cf3SAxel Dörfler vDivider = frame.bottom - thirdScreen; 163641281cf3SAxel Dörfler #endif 163741281cf3SAxel Dörfler BRect bottomLeft(frame.left, vDivider, frame.left + hDivider, frame.bottom); 163841281cf3SAxel Dörfler BRect bottomMiddle(frame.left + hDivider, vDivider, frame.right - hDivider, frame.bottom); 163941281cf3SAxel Dörfler BRect bottomRight(frame.right - hDivider, vDivider, frame.right, frame.bottom); 164041281cf3SAxel Dörfler 164141281cf3SAxel Dörfler if (where != fPreviousPosition) { 164241281cf3SAxel Dörfler fPreviousPosition = where; 164341281cf3SAxel Dörfler ConvertToScreen(&where); 164441281cf3SAxel Dörfler 164541281cf3SAxel Dörfler // use short circuit evaluation for convenience 164641281cf3SAxel Dörfler if (SwitchModeForRect(where, topLeft, true, true, true, kMiniState) 164741281cf3SAxel Dörfler || SwitchModeForRect(where, topMiddle, false, true, true, kExpandoState) 164841281cf3SAxel Dörfler || SwitchModeForRect(where, topRight, true, false, true, kMiniState) 164941281cf3SAxel Dörfler 165041281cf3SAxel Dörfler || SwitchModeForRect(where, middleLeft, true, true, true, kExpandoState) 165141281cf3SAxel Dörfler || SwitchModeForRect(where, middleRight, true, false, true, kExpandoState) 165241281cf3SAxel Dörfler 165341281cf3SAxel Dörfler #ifdef FULL_MODE 165441281cf3SAxel Dörfler || SwitchModeForRect(where, leftSide, true, true, true, kFullState) 165541281cf3SAxel Dörfler || SwitchModeForRect(where, rightSide, true, false, true, kFullState) 165641281cf3SAxel Dörfler #endif 165741281cf3SAxel Dörfler || SwitchModeForRect(where, bottomLeft, true, true, false, kMiniState) 165841281cf3SAxel Dörfler || SwitchModeForRect(where, bottomMiddle, false, true, false, kExpandoState) 16597da06231SAxel Dörfler || SwitchModeForRect(where, bottomRight, true, false, false, kMiniState)) 166041281cf3SAxel Dörfler ; 166141281cf3SAxel Dörfler } 166241281cf3SAxel Dörfler } else 166341281cf3SAxel Dörfler BControl::MouseMoved(where, code, message); 166441281cf3SAxel Dörfler } 166541281cf3SAxel Dörfler 166641281cf3SAxel Dörfler 166741281cf3SAxel Dörfler int32 166841281cf3SAxel Dörfler TDragRegion::DragRegionLocation() const 166941281cf3SAxel Dörfler { 167041281cf3SAxel Dörfler return fDragLocation; 167141281cf3SAxel Dörfler } 167241281cf3SAxel Dörfler 167341281cf3SAxel Dörfler 167441281cf3SAxel Dörfler void 167541281cf3SAxel Dörfler TDragRegion::SetDragRegionLocation(int32 location) 167641281cf3SAxel Dörfler { 167741281cf3SAxel Dörfler if (location == fDragLocation) 167841281cf3SAxel Dörfler return; 167941281cf3SAxel Dörfler 168041281cf3SAxel Dörfler fDragLocation = location; 168141281cf3SAxel Dörfler Invalidate(); 168241281cf3SAxel Dörfler } 168341281cf3SAxel Dörfler 1684