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 147*3a6add49SAxel 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 16041281cf3SAxel Dörfler DeleteAddOnSupport(); 16141281cf3SAxel Dörfler #endif 16241281cf3SAxel Dörfler BView::DetachedFromWindow(); 16341281cf3SAxel Dörfler } 16441281cf3SAxel Dörfler 16541281cf3SAxel Dörfler 16641281cf3SAxel Dörfler void 16741281cf3SAxel Dörfler TReplicantTray::RememberClockSettings() 16841281cf3SAxel Dörfler { 16941281cf3SAxel Dörfler if (fClock) { 17041281cf3SAxel Dörfler desk_settings *settings = ((TBarApp *)be_app)->Settings(); 17141281cf3SAxel Dörfler 17241281cf3SAxel Dörfler settings->timeShowSeconds = fClock->ShowingSeconds(); 17341281cf3SAxel Dörfler settings->timeShowMil = fClock->ShowingMilTime(); 17441281cf3SAxel Dörfler settings->timeShowEuro = fClock->ShowingEuroDate(); 17541281cf3SAxel Dörfler settings->timeFullDate = fClock->ShowingFullDate(); 17641281cf3SAxel Dörfler } 17741281cf3SAxel Dörfler } 17841281cf3SAxel Dörfler 17941281cf3SAxel Dörfler 18041281cf3SAxel Dörfler bool 18141281cf3SAxel Dörfler TReplicantTray::ShowingSeconds() 18241281cf3SAxel Dörfler { 18341281cf3SAxel Dörfler if (fClock) 18441281cf3SAxel Dörfler return fClock->ShowingSeconds(); 18541281cf3SAxel Dörfler return false; 18641281cf3SAxel Dörfler } 18741281cf3SAxel Dörfler 18841281cf3SAxel Dörfler 18941281cf3SAxel Dörfler bool 19041281cf3SAxel Dörfler TReplicantTray::ShowingMiltime() 19141281cf3SAxel Dörfler { 19241281cf3SAxel Dörfler if (fClock) 19341281cf3SAxel Dörfler return fClock->ShowingMilTime(); 19441281cf3SAxel Dörfler return false; 19541281cf3SAxel Dörfler } 19641281cf3SAxel Dörfler 19741281cf3SAxel Dörfler 19841281cf3SAxel Dörfler bool 19941281cf3SAxel Dörfler TReplicantTray::ShowingEuroDate() 20041281cf3SAxel Dörfler { 20141281cf3SAxel Dörfler if (fClock) 20241281cf3SAxel Dörfler return fClock->ShowingEuroDate(); 20341281cf3SAxel Dörfler return false; 20441281cf3SAxel Dörfler } 20541281cf3SAxel Dörfler 20641281cf3SAxel Dörfler 20741281cf3SAxel Dörfler bool 20841281cf3SAxel Dörfler TReplicantTray::ShowingFullDate() 20941281cf3SAxel Dörfler { 21041281cf3SAxel Dörfler if (fClock && CanShowFullDate()) 21141281cf3SAxel Dörfler return fClock->ShowingFullDate(); 21241281cf3SAxel Dörfler return false; 21341281cf3SAxel Dörfler } 21441281cf3SAxel Dörfler 21541281cf3SAxel Dörfler 21641281cf3SAxel Dörfler bool 21741281cf3SAxel Dörfler TReplicantTray::CanShowFullDate() 21841281cf3SAxel Dörfler { 21941281cf3SAxel Dörfler if (fClock) 22041281cf3SAxel Dörfler return fClock->CanShowFullDate(); 22141281cf3SAxel Dörfler return false; 22241281cf3SAxel Dörfler } 22341281cf3SAxel Dörfler 22441281cf3SAxel Dörfler 22541281cf3SAxel Dörfler void 22641281cf3SAxel Dörfler TReplicantTray::DealWithClock(bool showClock) 22741281cf3SAxel Dörfler { 22841281cf3SAxel Dörfler fBarView->ShowClock(showClock); 22941281cf3SAxel Dörfler 23041281cf3SAxel Dörfler if (showClock) { 23141281cf3SAxel Dörfler if (!fClock) { 23241281cf3SAxel Dörfler desk_settings *settings = ((TBarApp *)be_app)->Settings(); 23341281cf3SAxel Dörfler 23441281cf3SAxel Dörfler fClock = new TTimeView(settings->timeShowSeconds, settings->timeShowMil, 23541281cf3SAxel Dörfler settings->timeFullDate, settings->timeShowEuro, false); 23641281cf3SAxel Dörfler AddChild(fClock); 23741281cf3SAxel Dörfler 23841281cf3SAxel Dörfler fClock->MoveTo(Bounds().right - fClock->Bounds().Width() - 1, 2); 23941281cf3SAxel Dörfler fClock->AllowFullDate(!IsMultiRow()); 24041281cf3SAxel Dörfler } 24141281cf3SAxel Dörfler } else { 24241281cf3SAxel Dörfler if (fClock) { 24341281cf3SAxel Dörfler RememberClockSettings(); 24441281cf3SAxel Dörfler 24541281cf3SAxel Dörfler fClock->RemoveSelf(); 24641281cf3SAxel Dörfler delete fClock; 24741281cf3SAxel Dörfler fClock = NULL; 24841281cf3SAxel Dörfler } 24941281cf3SAxel Dörfler } 25041281cf3SAxel Dörfler } 25141281cf3SAxel Dörfler 25241281cf3SAxel Dörfler 25341281cf3SAxel Dörfler /** width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth 25441281cf3SAxel Dörfler * if not in multirowmode and greater than kMinimumReplicantCount 25541281cf3SAxel Dörfler * the width should be calculated based on the actual 25641281cf3SAxel Dörfler * replicant widths 25741281cf3SAxel Dörfler */ 25841281cf3SAxel Dörfler 25941281cf3SAxel Dörfler void 26041281cf3SAxel Dörfler TReplicantTray::GetPreferredSize(float *preferredWidth, float *preferredHeight) 26141281cf3SAxel Dörfler { 26241281cf3SAxel Dörfler float width = 0, height = kMinimumTrayHeight; 26341281cf3SAxel Dörfler 26441281cf3SAxel Dörfler if (fMultiRowMode) { 2657da06231SAxel Dörfler if (fShelf->CountReplicants() > 0) 2667da06231SAxel Dörfler height = fRightBottomReplicant.bottom; 26741281cf3SAxel Dörfler 26841281cf3SAxel Dörfler // the height will be uniform for the number of rows 26941281cf3SAxel Dörfler // necessary to show all the reps + any gutters 27041281cf3SAxel Dörfler // necessary for spacing 27141281cf3SAxel Dörfler int32 rowCount = (int32)(height / kMaxReplicantHeight); 27241281cf3SAxel Dörfler height = kGutter + (rowCount * kMaxReplicantHeight) 27341281cf3SAxel Dörfler + ((rowCount - 1) * kIconGap) + kGutter; 27441281cf3SAxel Dörfler height = max(kMinimumTrayHeight, height); 27541281cf3SAxel Dörfler width = kMinimumTrayWidth; 27641281cf3SAxel Dörfler } else { 27741281cf3SAxel Dörfler // if last replicant overruns clock then 27841281cf3SAxel Dörfler // resize to accomodate 2797da06231SAxel Dörfler if (fShelf->CountReplicants() > 0) { 28041281cf3SAxel Dörfler if (fBarView->ShowingClock() 2817da06231SAxel Dörfler && fRightBottomReplicant.right + 6 >= fClock->Frame().left) { 2827da06231SAxel Dörfler width = fRightBottomReplicant.right + 6 + fClock->Frame().Width(); 28341281cf3SAxel Dörfler } else 2847da06231SAxel Dörfler width = fRightBottomReplicant.right + 3; 28541281cf3SAxel Dörfler } 28641281cf3SAxel Dörfler // this view has a fixed minimum width 28741281cf3SAxel Dörfler width = max(kMinimumTrayWidth, width); 28841281cf3SAxel Dörfler } 28941281cf3SAxel Dörfler 29041281cf3SAxel Dörfler *preferredWidth = width; 29141281cf3SAxel Dörfler // add 2 for the border 29241281cf3SAxel Dörfler *preferredHeight = height + 1; 29341281cf3SAxel Dörfler } 29441281cf3SAxel Dörfler 29541281cf3SAxel Dörfler 29641281cf3SAxel Dörfler void 29741281cf3SAxel Dörfler TReplicantTray::AdjustPlacement() 29841281cf3SAxel Dörfler { 29941281cf3SAxel Dörfler // called when an add-on has been added or removed 30041281cf3SAxel Dörfler // need to resize the parent of this accordingly 30141281cf3SAxel Dörfler // 30241281cf3SAxel Dörfler // call to Parent will call ResizeToPreferred 30341281cf3SAxel Dörfler BRect bounds = Bounds(); 30441281cf3SAxel Dörfler float width, height; 30541281cf3SAxel Dörfler GetPreferredSize(&width, &height); 30641281cf3SAxel Dörfler 30741281cf3SAxel Dörfler if (width == bounds.Width() && height == bounds.Height()) { 30841281cf3SAxel Dörfler // no need to change anything 30941281cf3SAxel Dörfler return; 31041281cf3SAxel Dörfler } 31141281cf3SAxel Dörfler 31241281cf3SAxel Dörfler Parent()->ResizeToPreferred(); 31341281cf3SAxel Dörfler fBarView->UpdatePlacement(); 31441281cf3SAxel Dörfler Parent()->Invalidate(); 31541281cf3SAxel Dörfler Invalidate(); 31641281cf3SAxel Dörfler } 31741281cf3SAxel Dörfler 31841281cf3SAxel Dörfler 31941281cf3SAxel Dörfler void 32041281cf3SAxel Dörfler TReplicantTray::Draw(BRect) 32141281cf3SAxel Dörfler { 32241281cf3SAxel Dörfler rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR); 32341281cf3SAxel Dörfler rgb_color vdark = tint_color(menuColor, B_DARKEN_3_TINT); 32441281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 32541281cf3SAxel Dörfler 32641281cf3SAxel Dörfler BRect frame(Bounds()); 32741281cf3SAxel Dörfler 32841281cf3SAxel Dörfler SetHighColor(light); 32941281cf3SAxel Dörfler StrokeLine(frame.LeftBottom(), frame.RightBottom()); 33041281cf3SAxel Dörfler StrokeLine(frame.RightBottom(), frame.RightTop()); 33141281cf3SAxel Dörfler 33241281cf3SAxel Dörfler SetHighColor(vdark); 33341281cf3SAxel Dörfler StrokeLine(frame.RightTop(), frame.LeftTop()); 33441281cf3SAxel Dörfler StrokeLine(frame.LeftTop(), frame.LeftBottom()); 33541281cf3SAxel Dörfler } 33641281cf3SAxel Dörfler 33741281cf3SAxel Dörfler 33841281cf3SAxel Dörfler void 33941281cf3SAxel Dörfler TReplicantTray::MessageReceived(BMessage *message) 34041281cf3SAxel Dörfler { 34141281cf3SAxel Dörfler switch (message->what) { 34241281cf3SAxel Dörfler case 'time': 34341281cf3SAxel Dörfler // from context menu in clock and in this view 34441281cf3SAxel Dörfler DealWithClock(!fBarView->ShowingClock()); 34541281cf3SAxel Dörfler RealignReplicants(); 34641281cf3SAxel Dörfler AdjustPlacement(); 34741281cf3SAxel Dörfler break; 34841281cf3SAxel Dörfler 34941281cf3SAxel Dörfler case 'trfm': 35041281cf3SAxel Dörfler // time string reformat -> realign 35141281cf3SAxel Dörfler DealWithClock(fBarView->ShowingClock()); 35241281cf3SAxel Dörfler RealignReplicants(); 35341281cf3SAxel Dörfler AdjustPlacement(); 35441281cf3SAxel Dörfler break; 35541281cf3SAxel Dörfler 35641281cf3SAxel Dörfler case kMsgShowSeconds: 35741281cf3SAxel Dörfler case kMsgMilTime: 35841281cf3SAxel Dörfler case kMsgEuroDate: 35941281cf3SAxel Dörfler case kMsgFullDate: 36041281cf3SAxel Dörfler if (fClock != NULL) 36141281cf3SAxel Dörfler Window()->PostMessage(message, fClock); 36241281cf3SAxel Dörfler break; 36341281cf3SAxel Dörfler 36441281cf3SAxel Dörfler #ifdef DB_ADDONS 36541281cf3SAxel Dörfler case B_NODE_MONITOR: 36641281cf3SAxel Dörfler case B_QUERY_UPDATE: 36741281cf3SAxel Dörfler HandleEntryUpdate(message); 36841281cf3SAxel Dörfler break; 36941281cf3SAxel Dörfler #endif 37041281cf3SAxel Dörfler 37141281cf3SAxel Dörfler default: 37241281cf3SAxel Dörfler BView::MessageReceived(message); 37341281cf3SAxel Dörfler break; 37441281cf3SAxel Dörfler } 37541281cf3SAxel Dörfler } 37641281cf3SAxel Dörfler 37741281cf3SAxel Dörfler 37841281cf3SAxel Dörfler void 37941281cf3SAxel Dörfler TReplicantTray::ShowReplicantMenu(BPoint point) 38041281cf3SAxel Dörfler { 38141281cf3SAxel Dörfler BPopUpMenu *menu = new BPopUpMenu("", false, false); 38241281cf3SAxel Dörfler menu->SetFont(be_plain_font); 38341281cf3SAxel Dörfler 38441281cf3SAxel Dörfler // If the clock is visible, show the extended menu 38541281cf3SAxel Dörfler // otheriwse, show "Show Time". 38641281cf3SAxel Dörfler 38741281cf3SAxel Dörfler if (fBarView->ShowingClock()) 38841281cf3SAxel Dörfler fClock->ShowClockOptions(ConvertToScreen(point)); 38941281cf3SAxel Dörfler else { 39041281cf3SAxel Dörfler BMenuItem *item = new BMenuItem("Show Time", new BMessage('time')); 39141281cf3SAxel Dörfler menu->AddItem(item); 39241281cf3SAxel Dörfler menu->SetTargetForItems(this); 39341281cf3SAxel Dörfler BPoint where = ConvertToScreen(point); 39441281cf3SAxel Dörfler menu->Go(where, true, true, BRect(where - BPoint(4, 4), 39541281cf3SAxel Dörfler where + BPoint(4, 4)), true); 39641281cf3SAxel Dörfler } 39741281cf3SAxel Dörfler } 39841281cf3SAxel Dörfler 39941281cf3SAxel Dörfler 40041281cf3SAxel Dörfler void 40141281cf3SAxel Dörfler TReplicantTray::MouseDown(BPoint where) 40241281cf3SAxel Dörfler { 40341281cf3SAxel Dörfler #ifdef DB_ADDONS 40441281cf3SAxel Dörfler if (modifiers() & B_CONTROL_KEY) 40541281cf3SAxel Dörfler DumpList(fItemList); 40641281cf3SAxel Dörfler #endif 40741281cf3SAxel Dörfler 40841281cf3SAxel Dörfler uint32 buttons; 40941281cf3SAxel Dörfler 41041281cf3SAxel Dörfler Window()->CurrentMessage()->FindInt32("buttons", (int32 *)&buttons); 41141281cf3SAxel Dörfler if (buttons == B_SECONDARY_MOUSE_BUTTON) { 41241281cf3SAxel Dörfler ShowReplicantMenu(where); 41341281cf3SAxel Dörfler } else { 41441281cf3SAxel Dörfler BPoint save = where; 41541281cf3SAxel Dörfler bigtime_t doubleClickSpeed; 41641281cf3SAxel Dörfler bigtime_t start = system_time(); 41741281cf3SAxel Dörfler uint32 buttons; 41841281cf3SAxel Dörfler 41941281cf3SAxel Dörfler get_click_speed(&doubleClickSpeed); 42041281cf3SAxel Dörfler 42141281cf3SAxel Dörfler do { 42241281cf3SAxel Dörfler if (fabs(where.x - save.x) > 4 || fabs(where.y - save.y) > 4) 42341281cf3SAxel Dörfler // user moved out of bounds of click area 42441281cf3SAxel Dörfler break; 42541281cf3SAxel Dörfler 42641281cf3SAxel Dörfler if ((system_time() - start) > (2 * doubleClickSpeed)) { 42741281cf3SAxel Dörfler ShowReplicantMenu(where); 42841281cf3SAxel Dörfler break; 42941281cf3SAxel Dörfler } 43041281cf3SAxel Dörfler 43141281cf3SAxel Dörfler snooze(50000); 43241281cf3SAxel Dörfler GetMouse(&where, &buttons); 43341281cf3SAxel Dörfler } while (buttons); 43441281cf3SAxel Dörfler } 43541281cf3SAxel Dörfler BView::MouseDown(where); 43641281cf3SAxel Dörfler } 43741281cf3SAxel Dörfler 43841281cf3SAxel Dörfler #ifdef DB_ADDONS 43941281cf3SAxel Dörfler 44041281cf3SAxel Dörfler void 44141281cf3SAxel Dörfler TReplicantTray::InitAddOnSupport() 44241281cf3SAxel Dörfler { 44341281cf3SAxel Dörfler // list to maintain refs to each rep added/deleted 44441281cf3SAxel Dörfler fItemList = new BList(); 44541281cf3SAxel Dörfler 44641281cf3SAxel Dörfler bool haveKey = false; 44741281cf3SAxel Dörfler BPath path; 44841281cf3SAxel Dörfler if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) { 44941281cf3SAxel Dörfler path.Append(kDeskbarSecurityCodeFile); 45041281cf3SAxel Dörfler 45141281cf3SAxel Dörfler BFile file(path.Path(),B_READ_ONLY); 45241281cf3SAxel Dörfler if (file.InitCheck() == B_OK 45341281cf3SAxel Dörfler && file.Read(&fDeskbarSecurityCode, 45441281cf3SAxel Dörfler sizeof(fDeskbarSecurityCode)) == sizeof(fDeskbarSecurityCode)) 45541281cf3SAxel Dörfler haveKey = true; 45641281cf3SAxel Dörfler } 45741281cf3SAxel Dörfler if (!haveKey) { 45841281cf3SAxel Dörfler // create the security code 45941281cf3SAxel Dörfler bigtime_t real = real_time_clock_usecs(); 46041281cf3SAxel Dörfler bigtime_t boot = system_time(); 46141281cf3SAxel Dörfler // two computers would have to have exactly matching clocks, and launch 46241281cf3SAxel Dörfler // Deskbar at the exact same time into the bootsequence in order for their 46341281cf3SAxel Dörfler // security-ID to be identical 46441281cf3SAxel Dörfler fDeskbarSecurityCode = ((real&0xffffffffULL)<<32)|(boot&0xffffffffULL); 46541281cf3SAxel Dörfler 46641281cf3SAxel Dörfler if (find_directory (B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) { 46741281cf3SAxel Dörfler path.Append(kDeskbarSecurityCodeFile); 46841281cf3SAxel Dörfler BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); 46941281cf3SAxel Dörfler if (file.InitCheck() == B_OK) 47041281cf3SAxel Dörfler file.Write(&fDeskbarSecurityCode, sizeof(fDeskbarSecurityCode)); 47141281cf3SAxel Dörfler } 47241281cf3SAxel Dörfler } 47341281cf3SAxel Dörfler 47441281cf3SAxel Dörfler // for each volume currently mounted 47541281cf3SAxel Dörfler // index the volume with our indices 47641281cf3SAxel Dörfler BVolumeRoster roster; 47741281cf3SAxel Dörfler BVolume volume; 47841281cf3SAxel Dörfler while (roster.GetNextVolume(&volume) == B_OK) { 47941281cf3SAxel Dörfler fs_create_index(volume.Device(), kStatusPredicate, B_STRING_TYPE, 0); 48041281cf3SAxel Dörfler RunAddOnQuery(&volume, kEnabledPredicate); 48141281cf3SAxel Dörfler } 48241281cf3SAxel Dörfler 48341281cf3SAxel Dörfler // we also watch for volumes mounted and unmounted 48441281cf3SAxel Dörfler watch_node(NULL, B_WATCH_MOUNT | B_WATCH_ATTR, this, Window()); 48541281cf3SAxel Dörfler } 48641281cf3SAxel Dörfler 48741281cf3SAxel Dörfler 48841281cf3SAxel Dörfler void 48941281cf3SAxel Dörfler TReplicantTray::DeleteAddOnSupport() 49041281cf3SAxel Dörfler { 49141281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 49241281cf3SAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo *)fItemList->RemoveItem(i); 49341281cf3SAxel Dörfler if (item) { 49441281cf3SAxel Dörfler if (item->isAddOn) 49541281cf3SAxel Dörfler watch_node(&(item->nodeRef), B_STOP_WATCHING, this, Window()); 49641281cf3SAxel Dörfler 49741281cf3SAxel Dörfler delete item; 49841281cf3SAxel Dörfler } 49941281cf3SAxel Dörfler } 50041281cf3SAxel Dörfler delete fItemList; 50141281cf3SAxel Dörfler 50241281cf3SAxel Dörfler // stop the volume mount/unmount watch 50341281cf3SAxel Dörfler stop_watching(this, Window()); 50441281cf3SAxel Dörfler } 50541281cf3SAxel Dörfler 50641281cf3SAxel Dörfler 50741281cf3SAxel Dörfler void 50841281cf3SAxel Dörfler TReplicantTray::RunAddOnQuery(BVolume *volume, const char *predicate) 50941281cf3SAxel Dörfler { 51041281cf3SAxel Dörfler // Since the new BFS supports querying for attributes without 51141281cf3SAxel Dörfler // an index, we only run the query if the index exists (for 51241281cf3SAxel Dörfler // newly mounted devices only - the Deskbar will automatically 51341281cf3SAxel Dörfler // create an index for every device mounted at startup). 51441281cf3SAxel Dörfler index_info info; 51541281cf3SAxel Dörfler if (!volume->KnowsQuery() || fs_stat_index(volume->Device(),kStatusPredicate,&info) != 0) 51641281cf3SAxel Dörfler return; 51741281cf3SAxel Dörfler 51841281cf3SAxel Dörfler // run a new query on a specific volume 51941281cf3SAxel Dörfler // make it live 52041281cf3SAxel Dörfler BQuery query; 52141281cf3SAxel Dörfler query.SetVolume(volume); 52241281cf3SAxel Dörfler query.SetPredicate(predicate); 52341281cf3SAxel Dörfler query.Fetch(); 52441281cf3SAxel Dörfler 52541281cf3SAxel Dörfler int32 id; 52641281cf3SAxel Dörfler BEntry entry; 5277da06231SAxel Dörfler while (query.GetNextEntry(&entry) == B_OK) { 52841281cf3SAxel Dörfler // scan any entries returned 52941281cf3SAxel Dörfler // attempt to load them as add-ons 53041281cf3SAxel Dörfler // collisions are handled in LoadAddOn 53141281cf3SAxel Dörfler LoadAddOn(&entry, &id); 53241281cf3SAxel Dörfler } 5337da06231SAxel Dörfler } 53441281cf3SAxel Dörfler 53541281cf3SAxel Dörfler 53641281cf3SAxel Dörfler bool 53741281cf3SAxel Dörfler TReplicantTray::IsAddOn(entry_ref &ref) 53841281cf3SAxel Dörfler { 53941281cf3SAxel Dörfler BFile file(&ref, B_READ_ONLY); 54041281cf3SAxel Dörfler 54141281cf3SAxel Dörfler char status[64]; 54241281cf3SAxel Dörfler ssize_t size = file.ReadAttr(kStatusPredicate, B_STRING_TYPE, 0, &status, 64); 54341281cf3SAxel Dörfler return size > 0; 54441281cf3SAxel Dörfler } 54541281cf3SAxel Dörfler 54641281cf3SAxel Dörfler 54741281cf3SAxel Dörfler DeskbarItemInfo * 54841281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(node_ref &nodeRef) 54941281cf3SAxel Dörfler { 55041281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 55141281cf3SAxel Dörfler DeskbarItemInfo *item = static_cast<DeskbarItemInfo *>(fItemList->ItemAt(i)); 55241281cf3SAxel Dörfler if (item == NULL) 55341281cf3SAxel Dörfler continue; 55441281cf3SAxel Dörfler 55541281cf3SAxel Dörfler if (item->nodeRef == nodeRef) 55641281cf3SAxel Dörfler return item; 55741281cf3SAxel Dörfler } 55841281cf3SAxel Dörfler 55941281cf3SAxel Dörfler return NULL; 56041281cf3SAxel Dörfler } 56141281cf3SAxel Dörfler 56241281cf3SAxel Dörfler 56341281cf3SAxel Dörfler DeskbarItemInfo * 56441281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(int32 id) 56541281cf3SAxel Dörfler { 56641281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 56741281cf3SAxel Dörfler DeskbarItemInfo *item = static_cast<DeskbarItemInfo *>(fItemList->ItemAt(i)); 56841281cf3SAxel Dörfler if (item == NULL) 56941281cf3SAxel Dörfler continue; 57041281cf3SAxel Dörfler 57141281cf3SAxel Dörfler if (item->id == id) 57241281cf3SAxel Dörfler return item; 57341281cf3SAxel Dörfler } 57441281cf3SAxel Dörfler 57541281cf3SAxel Dörfler return NULL; 57641281cf3SAxel Dörfler } 57741281cf3SAxel Dörfler 57841281cf3SAxel Dörfler 57941281cf3SAxel Dörfler bool 58041281cf3SAxel Dörfler TReplicantTray::NodeExists(node_ref &nodeRef) 58141281cf3SAxel Dörfler { 58241281cf3SAxel Dörfler return DeskbarItemFor(nodeRef) != NULL; 58341281cf3SAxel Dörfler } 58441281cf3SAxel Dörfler 58541281cf3SAxel Dörfler 58641281cf3SAxel Dörfler /** This handles B_NODE_MONITOR & B_QUERY_UPDATE messages received 58741281cf3SAxel Dörfler * for the registered add-ons. 58841281cf3SAxel Dörfler */ 58941281cf3SAxel Dörfler 59041281cf3SAxel Dörfler void 59141281cf3SAxel Dörfler TReplicantTray::HandleEntryUpdate(BMessage *message) 59241281cf3SAxel Dörfler { 59341281cf3SAxel Dörfler int32 opcode; 59441281cf3SAxel Dörfler if (message->FindInt32("opcode", &opcode) != B_OK) 59541281cf3SAxel Dörfler return; 59641281cf3SAxel Dörfler 59741281cf3SAxel Dörfler BPath path; 59841281cf3SAxel Dörfler switch (opcode) { 59941281cf3SAxel Dörfler case B_ENTRY_CREATED: 60041281cf3SAxel Dörfler // entry was just listed, matches live query 60141281cf3SAxel Dörfler { 60241281cf3SAxel Dörfler const char *name; 60341281cf3SAxel Dörfler ino_t directory; 60441281cf3SAxel Dörfler dev_t device; 60541281cf3SAxel Dörfler // received when an app adds a ref to the 60641281cf3SAxel Dörfler // Deskbar add-ons folder 60741281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK 60841281cf3SAxel Dörfler && message->FindInt64("directory", &directory) == B_OK 60941281cf3SAxel Dörfler && message->FindInt32("device", &device) == B_OK) { 61041281cf3SAxel Dörfler entry_ref ref(device, directory, name); 61141281cf3SAxel Dörfler // see if this item has the attribute 61241281cf3SAxel Dörfler // that we expect 61341281cf3SAxel Dörfler if (IsAddOn(ref)) { 61441281cf3SAxel Dörfler int32 id; 61541281cf3SAxel Dörfler BEntry entry(&ref); 61641281cf3SAxel Dörfler LoadAddOn(&entry, &id); 61741281cf3SAxel Dörfler } 61841281cf3SAxel Dörfler } 61941281cf3SAxel Dörfler } 62041281cf3SAxel Dörfler break; 62141281cf3SAxel Dörfler 62241281cf3SAxel Dörfler case B_ATTR_CHANGED: 62341281cf3SAxel Dörfler // from node watch on individual items 62441281cf3SAxel Dörfler // (node_watch added in LoadAddOn) 62541281cf3SAxel Dörfler { 62641281cf3SAxel Dörfler node_ref nodeRef; 62741281cf3SAxel Dörfler if (message->FindInt32("device", &(nodeRef.device)) == B_OK 62841281cf3SAxel Dörfler && message->FindInt64("node", &(nodeRef.node)) == B_OK) { 62941281cf3SAxel Dörfler // get the add-on this is for 63041281cf3SAxel Dörfler DeskbarItemInfo *item = DeskbarItemFor(nodeRef); 63141281cf3SAxel Dörfler if (item == NULL) 63241281cf3SAxel Dörfler break; 63341281cf3SAxel Dörfler 63441281cf3SAxel Dörfler BFile file(&item->entryRef, B_READ_ONLY); 63541281cf3SAxel Dörfler 63641281cf3SAxel Dörfler char status[255]; 63741281cf3SAxel Dörfler ssize_t size = file.ReadAttr(kStatusPredicate, 63841281cf3SAxel Dörfler B_STRING_TYPE, 0, status, sizeof(status) - 1); 63941281cf3SAxel Dörfler status[sizeof(status) - 1] = '\0'; 64041281cf3SAxel Dörfler 64141281cf3SAxel Dörfler // attribute was removed 64241281cf3SAxel Dörfler if (size == B_ENTRY_NOT_FOUND) { 64341281cf3SAxel Dörfler // cleans up and removes node_watch 64441281cf3SAxel Dörfler UnloadAddOn(&nodeRef, NULL, true, false); 64541281cf3SAxel Dörfler } else if (!strcmp(status, "enable")) { 64641281cf3SAxel Dörfler int32 id; 64741281cf3SAxel Dörfler BEntry entry(&item->entryRef, true); 64841281cf3SAxel Dörfler LoadAddOn(&entry, &id); 64941281cf3SAxel Dörfler } 65041281cf3SAxel Dörfler } 65141281cf3SAxel Dörfler } 65241281cf3SAxel Dörfler break; 65341281cf3SAxel Dörfler 65441281cf3SAxel Dörfler case B_ENTRY_MOVED: 65541281cf3SAxel Dörfler { 65641281cf3SAxel Dörfler entry_ref ref; 65741281cf3SAxel Dörfler ino_t todirectory; 65841281cf3SAxel Dörfler ino_t node; 65941281cf3SAxel Dörfler const char *name; 66041281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK 66141281cf3SAxel Dörfler && message->FindInt64("from directory", &(ref.directory)) == B_OK 66241281cf3SAxel Dörfler && message->FindInt64("to directory", &todirectory) == B_OK 66341281cf3SAxel Dörfler && message->FindInt32("device", &(ref.device)) == B_OK 66441281cf3SAxel Dörfler && message->FindInt64("node", &node) == B_OK ) { 66541281cf3SAxel Dörfler 66641281cf3SAxel Dörfler if (!name) 66741281cf3SAxel Dörfler break; 66841281cf3SAxel Dörfler 66941281cf3SAxel Dörfler ref.set_name(name); 67041281cf3SAxel Dörfler // change the directory reference to 67141281cf3SAxel Dörfler // the new directory 67241281cf3SAxel Dörfler MoveItem(&ref, todirectory); 67341281cf3SAxel Dörfler } 67441281cf3SAxel Dörfler } 67541281cf3SAxel Dörfler break; 67641281cf3SAxel Dörfler 67741281cf3SAxel Dörfler case B_ENTRY_REMOVED: 67841281cf3SAxel Dörfler { 67941281cf3SAxel Dörfler // entry was rm'd from the device 68041281cf3SAxel Dörfler node_ref nodeRef; 68141281cf3SAxel Dörfler if (message->FindInt32("device", &(nodeRef.device)) == B_OK 68241281cf3SAxel Dörfler && message->FindInt64("node", &(nodeRef.node)) == B_OK) { 68341281cf3SAxel Dörfler DeskbarItemInfo *item = DeskbarItemFor(nodeRef); 68441281cf3SAxel Dörfler if (item == NULL) 68541281cf3SAxel Dörfler break; 68641281cf3SAxel Dörfler 68741281cf3SAxel Dörfler // If there is a team running where the add-on comes from, 68841281cf3SAxel Dörfler // we don't want to remove the icon yet. 68941281cf3SAxel Dörfler if (be_roster->IsRunning(&item->entryRef)) 69041281cf3SAxel Dörfler break; 69141281cf3SAxel Dörfler 69241281cf3SAxel Dörfler UnloadAddOn(&nodeRef, NULL, true, false); 69341281cf3SAxel Dörfler } 69441281cf3SAxel Dörfler } 69541281cf3SAxel Dörfler break; 69641281cf3SAxel Dörfler 69741281cf3SAxel Dörfler case B_DEVICE_MOUNTED: 69841281cf3SAxel Dörfler { 69941281cf3SAxel Dörfler // run a new query on the new device 70041281cf3SAxel Dörfler dev_t device; 70141281cf3SAxel Dörfler if (message->FindInt32("new device", &device) != B_OK) 70241281cf3SAxel Dörfler break; 70341281cf3SAxel Dörfler 70441281cf3SAxel Dörfler RunAddOnQuery(new BVolume(device), kEnabledPredicate); 70541281cf3SAxel Dörfler } 70641281cf3SAxel Dörfler break; 70741281cf3SAxel Dörfler case B_DEVICE_UNMOUNTED: 70841281cf3SAxel Dörfler { 70941281cf3SAxel Dörfler // remove all items associated with the device 71041281cf3SAxel Dörfler // unmounted 71141281cf3SAxel Dörfler // contrary to what the BeBook says, the item is called "device", 71241281cf3SAxel Dörfler // not "new device" like it is for B_DEVICE_MOUNTED 71341281cf3SAxel Dörfler dev_t device; 71441281cf3SAxel Dörfler if (message->FindInt32("device", &device) != B_OK) 71541281cf3SAxel Dörfler break; 71641281cf3SAxel Dörfler 71741281cf3SAxel Dörfler UnloadAddOn(NULL, &device, false, true); 71841281cf3SAxel Dörfler } 71941281cf3SAxel Dörfler break; 72041281cf3SAxel Dörfler } 72141281cf3SAxel Dörfler } 72241281cf3SAxel Dörfler 72341281cf3SAxel Dörfler 7247da06231SAxel Dörfler /** The add-ons must support the exported C function API 7257da06231SAxel Dörfler * if they do, they will be loaded and added to deskbar 7267da06231SAxel Dörfler * primary function is the Instantiate function 7277da06231SAxel Dörfler */ 72841281cf3SAxel Dörfler 72941281cf3SAxel Dörfler status_t 73041281cf3SAxel Dörfler TReplicantTray::LoadAddOn(BEntry *entry, int32 *id, bool force) 73141281cf3SAxel Dörfler { 73241281cf3SAxel Dörfler if (!entry) 73341281cf3SAxel Dörfler return B_ERROR; 73441281cf3SAxel Dörfler 73541281cf3SAxel Dörfler node_ref nodeRef; 73641281cf3SAxel Dörfler entry->GetNodeRef(&nodeRef); 73741281cf3SAxel Dörfler // no duplicates 73841281cf3SAxel Dörfler if (NodeExists(nodeRef)) 73941281cf3SAxel Dörfler return B_ERROR; 74041281cf3SAxel Dörfler 74141281cf3SAxel Dörfler BNode node(entry); 74241281cf3SAxel Dörfler if (!force) { 74341281cf3SAxel Dörfler status_t error = node.InitCheck(); 74441281cf3SAxel Dörfler if (error != B_OK) 74541281cf3SAxel Dörfler return error; 74641281cf3SAxel Dörfler 74741281cf3SAxel Dörfler uint64 deskbarID; 74841281cf3SAxel Dörfler ssize_t size = node.ReadAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, 0, 74941281cf3SAxel Dörfler &deskbarID, sizeof(fDeskbarSecurityCode)); 75041281cf3SAxel Dörfler if (size != sizeof(fDeskbarSecurityCode) || deskbarID != fDeskbarSecurityCode) { 75141281cf3SAxel Dörfler // no code or code doesn't match 75241281cf3SAxel Dörfler return B_ERROR; 75341281cf3SAxel Dörfler } 75441281cf3SAxel Dörfler } 75541281cf3SAxel Dörfler 75641281cf3SAxel Dörfler BPath path; 75741281cf3SAxel Dörfler entry->GetPath(&path); 75841281cf3SAxel Dörfler 75941281cf3SAxel Dörfler // load the add-on 76041281cf3SAxel Dörfler image_id image = load_add_on(path.Path()); 76141281cf3SAxel Dörfler if (image < 0) 76241281cf3SAxel Dörfler return (status_t)image; 76341281cf3SAxel Dörfler 76441281cf3SAxel Dörfler // get the view loading function symbol 76541281cf3SAxel Dörfler // we first look for a symbol that takes an image_id 76641281cf3SAxel Dörfler // and entry_ref pointer, if not found, go with normal 76741281cf3SAxel Dörfler // instantiate function 76841281cf3SAxel Dörfler BView *(*entryFunction)(image_id, const entry_ref *); 76941281cf3SAxel Dörfler BView *(*itemFunction)(void); 77041281cf3SAxel Dörfler BView *view = NULL; 77141281cf3SAxel Dörfler 77241281cf3SAxel Dörfler entry_ref ref; 77341281cf3SAxel Dörfler entry->GetRef(&ref); 77441281cf3SAxel Dörfler 77541281cf3SAxel Dörfler if (get_image_symbol(image, kInstantiateEntryCFunctionName, 77641281cf3SAxel Dörfler B_SYMBOL_TYPE_TEXT, (void **)&entryFunction) >= 0) { 77741281cf3SAxel Dörfler 77841281cf3SAxel Dörfler view = (*entryFunction)(image, &ref); 77941281cf3SAxel Dörfler } else if (get_image_symbol(image, kInstantiateItemCFunctionName, 78041281cf3SAxel Dörfler B_SYMBOL_TYPE_TEXT, (void **)&itemFunction) >= 0) { 78141281cf3SAxel Dörfler 78241281cf3SAxel Dörfler view = (*itemFunction)(); 78341281cf3SAxel Dörfler } else { 78441281cf3SAxel Dörfler unload_add_on(image); 78541281cf3SAxel Dörfler return B_ERROR; 78641281cf3SAxel Dörfler } 78741281cf3SAxel Dörfler 78841281cf3SAxel Dörfler if (!view || IconExists(view->Name())) { 78941281cf3SAxel Dörfler delete view; 79041281cf3SAxel Dörfler unload_add_on(image); 79141281cf3SAxel Dörfler return B_ERROR; 79241281cf3SAxel Dörfler } 79341281cf3SAxel Dörfler 79441281cf3SAxel Dörfler BMessage *data = new BMessage; 79541281cf3SAxel Dörfler view->Archive(data); 79641281cf3SAxel Dörfler delete view; 79741281cf3SAxel Dörfler 79841281cf3SAxel Dörfler AddIcon(data, id, &ref); 79941281cf3SAxel Dörfler // add the rep; adds info to list 80041281cf3SAxel Dörfler 80141281cf3SAxel Dörfler node.WriteAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, 0, 80241281cf3SAxel Dörfler &fDeskbarSecurityCode, sizeof(fDeskbarSecurityCode)); 80341281cf3SAxel Dörfler 80441281cf3SAxel Dörfler return B_OK; 80541281cf3SAxel Dörfler } 80641281cf3SAxel Dörfler 80741281cf3SAxel Dörfler 80841281cf3SAxel Dörfler status_t 80941281cf3SAxel Dörfler TReplicantTray::AddItem(int32 id, node_ref nodeRef, BEntry &entry, bool isAddOn) 81041281cf3SAxel Dörfler { 81141281cf3SAxel Dörfler DeskbarItemInfo *item = new DeskbarItemInfo; 81241281cf3SAxel Dörfler if (item == NULL) 81341281cf3SAxel Dörfler return B_NO_MEMORY; 81441281cf3SAxel Dörfler 81541281cf3SAxel Dörfler item->id = id; 81641281cf3SAxel Dörfler item->isAddOn = isAddOn; 81741281cf3SAxel Dörfler 81841281cf3SAxel Dörfler if (entry.GetRef(&item->entryRef) < B_OK) { 81941281cf3SAxel Dörfler item->entryRef.device = -1; 82041281cf3SAxel Dörfler item->entryRef.directory = -1; 82141281cf3SAxel Dörfler item->entryRef.name = NULL; 82241281cf3SAxel Dörfler } 82341281cf3SAxel Dörfler item->nodeRef = nodeRef; 82441281cf3SAxel Dörfler 82541281cf3SAxel Dörfler fItemList->AddItem(item); 82641281cf3SAxel Dörfler 82741281cf3SAxel Dörfler if (isAddOn) 82841281cf3SAxel Dörfler watch_node(&nodeRef, B_WATCH_NAME | B_WATCH_ATTR, this, Window()); 82941281cf3SAxel Dörfler 83041281cf3SAxel Dörfler return B_OK; 83141281cf3SAxel Dörfler } 83241281cf3SAxel Dörfler 83341281cf3SAxel Dörfler 83441281cf3SAxel Dörfler /** from entry_removed message, when attribute removed 83541281cf3SAxel Dörfler * or when a device is unmounted (use removeall, by device) 83641281cf3SAxel Dörfler */ 83741281cf3SAxel Dörfler 83841281cf3SAxel Dörfler void 83941281cf3SAxel Dörfler TReplicantTray::UnloadAddOn(node_ref *nodeRef, dev_t *device, 84041281cf3SAxel Dörfler bool which, bool removeAll) 84141281cf3SAxel Dörfler { 84241281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 84341281cf3SAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo*)fItemList->ItemAt(i); 84441281cf3SAxel Dörfler if (!item) 84541281cf3SAxel Dörfler continue; 84641281cf3SAxel Dörfler 84741281cf3SAxel Dörfler if ((which && nodeRef && item->nodeRef == *nodeRef) 84841281cf3SAxel Dörfler || (device && item->nodeRef.device == *device)) { 84941281cf3SAxel Dörfler 85041281cf3SAxel Dörfler if (device && be_roster->IsRunning(&item->entryRef)) 85141281cf3SAxel Dörfler continue; 85241281cf3SAxel Dörfler 85341281cf3SAxel Dörfler RemoveIcon(item->id); 85441281cf3SAxel Dörfler 85541281cf3SAxel Dörfler if (!removeAll) 85641281cf3SAxel Dörfler break; 85741281cf3SAxel Dörfler } 85841281cf3SAxel Dörfler } 85941281cf3SAxel Dörfler } 86041281cf3SAxel Dörfler 86141281cf3SAxel Dörfler 86241281cf3SAxel Dörfler void 86341281cf3SAxel Dörfler TReplicantTray::RemoveItem(int32 id) 86441281cf3SAxel Dörfler { 86541281cf3SAxel Dörfler DeskbarItemInfo *item = DeskbarItemFor(id); 86641281cf3SAxel Dörfler if (item == NULL) 86741281cf3SAxel Dörfler return; 86841281cf3SAxel Dörfler 86941281cf3SAxel Dörfler // attribute was added via Deskbar API (AddItem(entry_ref *, int32 *) 87041281cf3SAxel Dörfler if (item->isAddOn) { 87141281cf3SAxel Dörfler BNode node(&item->entryRef); 87241281cf3SAxel Dörfler node.RemoveAttr(kStatusPredicate); 87341281cf3SAxel Dörfler watch_node(&item->nodeRef, B_STOP_WATCHING, this, Window()); 87441281cf3SAxel Dörfler } 87541281cf3SAxel Dörfler 87641281cf3SAxel Dörfler fItemList->RemoveItem(item); 87741281cf3SAxel Dörfler delete item; 87841281cf3SAxel Dörfler } 87941281cf3SAxel Dörfler 88041281cf3SAxel Dörfler 88141281cf3SAxel Dörfler /** ENTRY_MOVED message, moving only occurs on a device 88241281cf3SAxel Dörfler * copying will occur (ENTRY_CREATED) between devices 88341281cf3SAxel Dörfler */ 88441281cf3SAxel Dörfler 88541281cf3SAxel Dörfler void 88641281cf3SAxel Dörfler TReplicantTray::MoveItem(entry_ref *ref, ino_t toDirectory) 88741281cf3SAxel Dörfler { 88841281cf3SAxel Dörfler if (!ref) 88941281cf3SAxel Dörfler return; 89041281cf3SAxel Dörfler 89141281cf3SAxel Dörfler // scan for a matching entry_ref and update it 89241281cf3SAxel Dörfler // 89341281cf3SAxel Dörfler // don't need to change node info as it does not change 89441281cf3SAxel Dörfler 89541281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 89641281cf3SAxel Dörfler DeskbarItemInfo *item = (DeskbarItemInfo *)fItemList->ItemAt(i); 89741281cf3SAxel Dörfler if (!item) 89841281cf3SAxel Dörfler continue; 89941281cf3SAxel Dörfler 90041281cf3SAxel Dörfler if (!strcmp(item->entryRef.name, ref->name) 90141281cf3SAxel Dörfler && item->entryRef.device == ref->device 90241281cf3SAxel Dörfler && item->entryRef.directory == ref->directory) { 90341281cf3SAxel Dörfler item->entryRef.directory = toDirectory; 90441281cf3SAxel Dörfler break; 90541281cf3SAxel Dörfler } 90641281cf3SAxel Dörfler } 90741281cf3SAxel Dörfler } 90841281cf3SAxel Dörfler 90941281cf3SAxel Dörfler #endif // add-on support 91041281cf3SAxel Dörfler 91141281cf3SAxel Dörfler // external add-on API routines 91241281cf3SAxel Dörfler // called using the new BDeskbar class 91341281cf3SAxel Dörfler 91441281cf3SAxel Dörfler // existence of icon/replicant by name or ID 91541281cf3SAxel Dörfler // returns opposite 91641281cf3SAxel Dörfler // note: name and id are semi-private limiting 91741281cf3SAxel Dörfler // the ability of non-host apps to remove 91841281cf3SAxel Dörfler // icons without a little bit of work 91941281cf3SAxel Dörfler 92041281cf3SAxel Dörfler /** for a specific id 92141281cf3SAxel Dörfler * return the name of the replicant (name of view) 92241281cf3SAxel Dörfler */ 92341281cf3SAxel Dörfler 92441281cf3SAxel Dörfler status_t 92541281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 id, const char **name) 92641281cf3SAxel Dörfler { 92741281cf3SAxel Dörfler if (id < 0) 92841281cf3SAxel Dörfler return B_ERROR; 92941281cf3SAxel Dörfler 93041281cf3SAxel Dörfler int32 index, temp; 93141281cf3SAxel Dörfler BView *view = ViewAt(&index, &temp, id, false); 93241281cf3SAxel Dörfler if (view) { 93341281cf3SAxel Dörfler *name = view->Name(); 93441281cf3SAxel Dörfler return B_OK; 93541281cf3SAxel Dörfler } 93641281cf3SAxel Dörfler 93741281cf3SAxel Dörfler return B_ERROR; 93841281cf3SAxel Dörfler } 93941281cf3SAxel Dörfler 94041281cf3SAxel Dörfler 9417da06231SAxel Dörfler /** for a specific name 9427da06231SAxel Dörfler * return the id (internal to Deskbar) 9437da06231SAxel Dörfler */ 9447da06231SAxel Dörfler 94541281cf3SAxel Dörfler status_t 94641281cf3SAxel Dörfler TReplicantTray::ItemInfo(const char *name, int32 *id) 94741281cf3SAxel Dörfler { 94841281cf3SAxel Dörfler if (!name || strlen(name) <= 0) 94941281cf3SAxel Dörfler return B_ERROR; 95041281cf3SAxel Dörfler 95141281cf3SAxel Dörfler int32 index; 95241281cf3SAxel Dörfler BView *view = ViewAt(&index, id, name); 95341281cf3SAxel Dörfler if (view) 95441281cf3SAxel Dörfler return B_OK; 95541281cf3SAxel Dörfler 95641281cf3SAxel Dörfler return B_ERROR; 95741281cf3SAxel Dörfler } 95841281cf3SAxel Dörfler 95941281cf3SAxel Dörfler 9607da06231SAxel Dörfler /** at a specific index 9617da06231SAxel Dörfler * return both the name and the id of the replicant 9627da06231SAxel Dörfler */ 9637da06231SAxel Dörfler 96441281cf3SAxel Dörfler status_t 96541281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 index, const char **name, int32 *id) 96641281cf3SAxel Dörfler { 96741281cf3SAxel Dörfler if (index < 0) 96841281cf3SAxel Dörfler return B_ERROR; 96941281cf3SAxel Dörfler 97041281cf3SAxel Dörfler BView *view; 97141281cf3SAxel Dörfler fShelf->ReplicantAt(index, &view, (uint32 *)id, NULL); 97241281cf3SAxel Dörfler if (view) { 97341281cf3SAxel Dörfler *name = view->Name(); 97441281cf3SAxel Dörfler return B_OK; 97541281cf3SAxel Dörfler } 97641281cf3SAxel Dörfler 97741281cf3SAxel Dörfler return B_ERROR; 97841281cf3SAxel Dörfler } 97941281cf3SAxel Dörfler 98041281cf3SAxel Dörfler 9817da06231SAxel Dörfler /** replicant exists, by id/index */ 9827da06231SAxel Dörfler 98341281cf3SAxel Dörfler bool 98441281cf3SAxel Dörfler TReplicantTray::IconExists(int32 target, bool byIndex) 98541281cf3SAxel Dörfler { 98641281cf3SAxel Dörfler int32 index, id; 98741281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, target, byIndex); 98841281cf3SAxel Dörfler 98941281cf3SAxel Dörfler return view && index >= 0; 99041281cf3SAxel Dörfler } 99141281cf3SAxel Dörfler 99241281cf3SAxel Dörfler 9937da06231SAxel Dörfler /** replicant exists, by name */ 9947da06231SAxel Dörfler 99541281cf3SAxel Dörfler bool 99641281cf3SAxel Dörfler TReplicantTray::IconExists(const char *name) 99741281cf3SAxel Dörfler { 99841281cf3SAxel Dörfler if (!name || strlen(name) == 0) 99941281cf3SAxel Dörfler return false; 100041281cf3SAxel Dörfler 100141281cf3SAxel Dörfler int32 index, id; 100241281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, name); 100341281cf3SAxel Dörfler 100441281cf3SAxel Dörfler return view && index >= 0; 100541281cf3SAxel Dörfler } 100641281cf3SAxel Dörfler 100741281cf3SAxel Dörfler 100841281cf3SAxel Dörfler int32 100941281cf3SAxel Dörfler TReplicantTray::IconCount() const 101041281cf3SAxel Dörfler { 101141281cf3SAxel Dörfler return fShelf->CountReplicants(); 101241281cf3SAxel Dörfler } 101341281cf3SAxel Dörfler 101441281cf3SAxel Dörfler 10157da06231SAxel Dörfler /** message must contain an archivable view 10167da06231SAxel Dörfler * in the Archives folder for later rehydration 10177da06231SAxel Dörfler * returns the current boot id 10187da06231SAxel Dörfler */ 10197da06231SAxel Dörfler 102041281cf3SAxel Dörfler status_t 102141281cf3SAxel Dörfler TReplicantTray::AddIcon(BMessage *icon, int32 *id, const entry_ref *addOn) 102241281cf3SAxel Dörfler { 102341281cf3SAxel Dörfler if (!icon || !id) 102441281cf3SAxel Dörfler return B_ERROR; 102541281cf3SAxel Dörfler 102641281cf3SAxel Dörfler *id = 999; 102741281cf3SAxel Dörfler if (icon->what == B_ARCHIVED_OBJECT) 102841281cf3SAxel Dörfler icon->what = 0; 102941281cf3SAxel Dörfler 103041281cf3SAxel Dörfler // !! check for name collisions? 103141281cf3SAxel Dörfler status_t err = fShelf->AddReplicant(icon, BPoint(1, 1)); 103241281cf3SAxel Dörfler if (err != B_OK) 103341281cf3SAxel Dörfler return err; 103441281cf3SAxel Dörfler 103541281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 103641281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 103741281cf3SAxel Dörfler float width, height; 103841281cf3SAxel Dörfler GetPreferredSize(&width, &height); 103941281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) 104041281cf3SAxel Dörfler AdjustPlacement(); 104141281cf3SAxel Dörfler 104241281cf3SAxel Dörfler int32 count = fShelf->CountReplicants(); 104341281cf3SAxel Dörfler BView *view; 104441281cf3SAxel Dörfler fShelf->ReplicantAt(count-1, &view, (uint32 *)id, NULL); 104541281cf3SAxel Dörfler 104641281cf3SAxel Dörfler // add the item to the add-on list 104741281cf3SAxel Dörfler entry_ref ref; 10487da06231SAxel Dörfler if (addOn) { 10497da06231SAxel Dörfler // Use it if we got it 105041281cf3SAxel Dörfler ref = *addOn; 10517da06231SAxel Dörfler } else { 105241281cf3SAxel Dörfler const char *appsig; 105341281cf3SAxel Dörfler icon->FindString("add_on", &appsig); 105441281cf3SAxel Dörfler BRoster roster; 105541281cf3SAxel Dörfler roster.FindApp(appsig, &ref); 105641281cf3SAxel Dörfler } 105741281cf3SAxel Dörfler 105841281cf3SAxel Dörfler BFile file(&ref, B_READ_ONLY); 105941281cf3SAxel Dörfler node_ref nodeRef; 106041281cf3SAxel Dörfler file.GetNodeRef(&nodeRef); 106141281cf3SAxel Dörfler BEntry entry(&ref, true); 106241281cf3SAxel Dörfler // ToDo: this resolves an eventual link for the item 106341281cf3SAxel Dörfler // being added - this is okay for now, but in multi-user 106441281cf3SAxel Dörfler // environments, one might want to have links that 106541281cf3SAxel Dörfler // carry the be:deskbar_item_status attribute 106641281cf3SAxel Dörfler AddItem(*id, nodeRef, entry, addOn != NULL); 106741281cf3SAxel Dörfler 106841281cf3SAxel Dörfler return B_OK; 106941281cf3SAxel Dörfler } 107041281cf3SAxel Dörfler 107141281cf3SAxel Dörfler 107241281cf3SAxel Dörfler void 107341281cf3SAxel Dörfler TReplicantTray::RemoveIcon(int32 target, bool byIndex) 107441281cf3SAxel Dörfler { 107541281cf3SAxel Dörfler if (target < 0) 107641281cf3SAxel Dörfler return; 107741281cf3SAxel Dörfler 107841281cf3SAxel Dörfler int32 index, id; 107941281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, target, byIndex); 108041281cf3SAxel Dörfler if (view && index >= 0) { 10817da06231SAxel Dörfler // remove the reference from the item list & the shelf 108241281cf3SAxel Dörfler RemoveItem(id); 108341281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 10847da06231SAxel Dörfler 108541281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 108641281cf3SAxel Dörfler RealReplicantAdjustment(index); 108741281cf3SAxel Dörfler } 108841281cf3SAxel Dörfler } 108941281cf3SAxel Dörfler 109041281cf3SAxel Dörfler 109141281cf3SAxel Dörfler void 109241281cf3SAxel Dörfler TReplicantTray::RemoveIcon(const char *name) 109341281cf3SAxel Dörfler { 109441281cf3SAxel Dörfler if (!name || strlen(name) <= 0) 109541281cf3SAxel Dörfler return; 109641281cf3SAxel Dörfler 109741281cf3SAxel Dörfler int32 id, index; 109841281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, name); 109941281cf3SAxel Dörfler if (view && index >= 0) { 11007da06231SAxel Dörfler // remove the reference from the item list & 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 11117da06231SAxel Dörfler TReplicantTray::RealReplicantAdjustment(int32 startIndex) 111241281cf3SAxel Dörfler { 11137da06231SAxel Dörfler if (startIndex < 0) 111441281cf3SAxel Dörfler return; 11157da06231SAxel Dörfler 11167da06231SAxel Dörfler if (startIndex == fLastReplicant) 11177da06231SAxel Dörfler startIndex = 0; 11187da06231SAxel Dörfler 111941281cf3SAxel Dörfler // reset the locations of all replicants after the one deleted 11207da06231SAxel Dörfler RealignReplicants(startIndex); 112141281cf3SAxel Dörfler 112241281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 112341281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 112441281cf3SAxel Dörfler float width, height; 112541281cf3SAxel Dörfler GetPreferredSize(&width, &height); 112641281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) { 112741281cf3SAxel Dörfler // resize view to accomodate the replicants 112841281cf3SAxel Dörfler // redraw as necessary 112941281cf3SAxel Dörfler AdjustPlacement(); 113041281cf3SAxel Dörfler } 113141281cf3SAxel Dörfler } 113241281cf3SAxel Dörfler 113341281cf3SAxel Dörfler 11347da06231SAxel Dörfler /** looking for a replicant by id/index 11357da06231SAxel Dörfler * return the view and index 11367da06231SAxel Dörfler */ 11377da06231SAxel Dörfler 113841281cf3SAxel Dörfler BView * 113941281cf3SAxel Dörfler TReplicantTray::ViewAt(int32 *index, int32 *id, int32 target, bool byIndex) 114041281cf3SAxel Dörfler { 114141281cf3SAxel Dörfler *index = -1; 114241281cf3SAxel Dörfler 114341281cf3SAxel Dörfler BView *view; 114441281cf3SAxel Dörfler if (byIndex){ 114541281cf3SAxel Dörfler if (fShelf->ReplicantAt(target, &view, (uint32 *)id)) { 114641281cf3SAxel Dörfler if (view) { 114741281cf3SAxel Dörfler *index = target; 114841281cf3SAxel Dörfler return view; 114941281cf3SAxel Dörfler } 115041281cf3SAxel Dörfler } 115141281cf3SAxel Dörfler } else { 115241281cf3SAxel Dörfler int32 count = fShelf->CountReplicants()-1; 115341281cf3SAxel Dörfler int32 localid; 115441281cf3SAxel Dörfler for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { 115541281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32 *)&localid); 115641281cf3SAxel Dörfler if (localid == target && view) { 115741281cf3SAxel Dörfler *index = repIndex; 115841281cf3SAxel Dörfler *id = localid; 115941281cf3SAxel Dörfler return view; 116041281cf3SAxel Dörfler } 116141281cf3SAxel Dörfler } 116241281cf3SAxel Dörfler } 116341281cf3SAxel Dörfler 116441281cf3SAxel Dörfler return NULL; 116541281cf3SAxel Dörfler } 116641281cf3SAxel Dörfler 116741281cf3SAxel Dörfler 11687da06231SAxel Dörfler /** looking for a replicant with a view by name 11697da06231SAxel Dörfler * return the view, index and the id of the replicant 11707da06231SAxel Dörfler */ 11717da06231SAxel Dörfler 117241281cf3SAxel Dörfler BView * 117341281cf3SAxel Dörfler TReplicantTray::ViewAt(int32 *index, int32 *id, const char *name) 117441281cf3SAxel Dörfler { 117541281cf3SAxel Dörfler *index = -1; 117641281cf3SAxel Dörfler *id = -1; 117741281cf3SAxel Dörfler 117841281cf3SAxel Dörfler BView *view; 117941281cf3SAxel Dörfler int32 count = fShelf->CountReplicants()-1; 118041281cf3SAxel Dörfler for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { 118141281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32 *)id); 118241281cf3SAxel Dörfler if (view && view->Name() && strcmp(name, view->Name()) == 0) { 118341281cf3SAxel Dörfler *index = repIndex; 118441281cf3SAxel Dörfler return view; 118541281cf3SAxel Dörfler } 118641281cf3SAxel Dörfler } 118741281cf3SAxel Dörfler 118841281cf3SAxel Dörfler return NULL; 118941281cf3SAxel Dörfler } 119041281cf3SAxel Dörfler 119141281cf3SAxel Dörfler 11927da06231SAxel Dörfler /** Shelf will call to determine where and if 11937da06231SAxel Dörfler * the replicant is to be added 11947da06231SAxel Dörfler */ 11957da06231SAxel Dörfler 119641281cf3SAxel Dörfler bool 119741281cf3SAxel Dörfler TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage *message) 119841281cf3SAxel Dörfler { 119941281cf3SAxel Dörfler if (!message) 120041281cf3SAxel Dörfler return false; 120141281cf3SAxel Dörfler 120241281cf3SAxel Dörfler if (replicantFrame.Height() > kMaxReplicantHeight) 120341281cf3SAxel Dörfler return false; 120441281cf3SAxel Dörfler 120541281cf3SAxel Dörfler alignment align = B_ALIGN_LEFT; 120641281cf3SAxel Dörfler if (fAlignmentSupport && message->HasBool("deskbar:dynamic_align")) { 120741281cf3SAxel Dörfler if (!fBarView->Vertical()) 120841281cf3SAxel Dörfler align = B_ALIGN_RIGHT; 120941281cf3SAxel Dörfler else 121041281cf3SAxel Dörfler align = fBarView->Left() ? B_ALIGN_LEFT : B_ALIGN_RIGHT; 121141281cf3SAxel Dörfler } else if (message->HasInt32("deskbar:align")) 121241281cf3SAxel Dörfler message->FindInt32("deskbar:align", (int32 *)&align); 121341281cf3SAxel Dörfler 121441281cf3SAxel Dörfler if (message->HasInt32("deskbar:private_align")) 121541281cf3SAxel Dörfler message->FindInt32("deskbar:private_align", (int32 *)&align); 121641281cf3SAxel Dörfler else 121741281cf3SAxel Dörfler align = B_ALIGN_LEFT; 121841281cf3SAxel Dörfler 12197da06231SAxel Dörfler BPoint loc = LocationForReplicant(fShelf->CountReplicants(), 12207da06231SAxel Dörfler replicantFrame.Width()); 122141281cf3SAxel Dörfler 122241281cf3SAxel Dörfler message->AddPoint("_pjp_loc", loc); 122341281cf3SAxel Dörfler return true; 122441281cf3SAxel Dörfler } 122541281cf3SAxel Dörfler 122641281cf3SAxel Dörfler 122741281cf3SAxel Dörfler /** based on the previous (index - 1) replicant in the list 122841281cf3SAxel Dörfler * calculate where the left point should be for this 122941281cf3SAxel Dörfler * replicant. replicant will flow to the right on its own 123041281cf3SAxel Dörfler */ 123141281cf3SAxel Dörfler 123241281cf3SAxel Dörfler BPoint 12337da06231SAxel Dörfler TReplicantTray::LocationForReplicant(int32 index, float width) 123441281cf3SAxel Dörfler { 123541281cf3SAxel Dörfler BPoint loc(kIconGap + 1, kGutter + 1); 123641281cf3SAxel Dörfler 12377da06231SAxel Dörfler if (fMultiRowMode) { 12387da06231SAxel Dörfler // try to find free space in every row 12397da06231SAxel Dörfler for (int32 row = 0; ; loc.y += kMaxReplicantHeight + kIconGap, row++) { 12407da06231SAxel Dörfler // determine free space in this row 12417da06231SAxel Dörfler BRect rect(loc.x, loc.y, loc.x + kMinimumTrayWidth + 2, kMaxReplicantHeight); 12427da06231SAxel Dörfler if (row == 0 && fBarView->ShowingClock()) 12437da06231SAxel Dörfler rect.right -= fClock->Frame().Width() + kIconGap; 12447da06231SAxel Dörfler 12457da06231SAxel Dörfler for (int32 i = 0; i < index; i++) { 12467da06231SAxel Dörfler BView *view = NULL; 12477da06231SAxel Dörfler fShelf->ReplicantAt(i, &view); 12487da06231SAxel Dörfler if (view == NULL || view->Frame().top != rect.top) 12497da06231SAxel Dörfler continue; 12507da06231SAxel Dörfler 12517da06231SAxel Dörfler rect.left = view->Frame().right + kIconGap + 1; 12527da06231SAxel Dörfler } 12537da06231SAxel Dörfler 12547da06231SAxel Dörfler if (rect.Width() >= width) { 12557da06231SAxel Dörfler // the icon fits in this row 12567da06231SAxel Dörfler loc = rect.LeftTop(); 12577da06231SAxel Dörfler break; 12587da06231SAxel Dörfler } 12597da06231SAxel Dörfler } 12607da06231SAxel Dörfler } else { 126141281cf3SAxel Dörfler if (index > 0) { 126241281cf3SAxel Dörfler // get the last replicant added for placement reference 126341281cf3SAxel Dörfler BView *view = NULL; 12647da06231SAxel Dörfler fShelf->ReplicantAt(index - 1, &view); 126541281cf3SAxel Dörfler if (view) { 126641281cf3SAxel Dörfler // push this rep placement past the last one 126741281cf3SAxel Dörfler loc.x = view->Frame().right + kIconGap + 1; 126841281cf3SAxel Dörfler loc.y = view->Frame().top; 126941281cf3SAxel Dörfler } 127041281cf3SAxel Dörfler } 12717da06231SAxel Dörfler } 127241281cf3SAxel Dörfler 12737da06231SAxel Dörfler if ((loc.y == fRightBottomReplicant.top && loc.x > fRightBottomReplicant.left) 12747da06231SAxel Dörfler || loc.y > fRightBottomReplicant.top) { 12757da06231SAxel Dörfler fRightBottomReplicant.Set(loc.x, loc.y, loc.x + width, loc.y + kMaxReplicantHeight); 12767da06231SAxel Dörfler fLastReplicant = index; 127741281cf3SAxel Dörfler } 12787da06231SAxel Dörfler 127941281cf3SAxel Dörfler return loc; 128041281cf3SAxel Dörfler } 128141281cf3SAxel Dörfler 128241281cf3SAxel Dörfler 128341281cf3SAxel Dörfler BRect 128441281cf3SAxel Dörfler TReplicantTray::IconFrame(int32 target, bool byIndex) 128541281cf3SAxel Dörfler { 128641281cf3SAxel Dörfler int32 index, id; 128741281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, target, byIndex); 128841281cf3SAxel Dörfler if (view) 128941281cf3SAxel Dörfler return view->Frame(); 129041281cf3SAxel Dörfler 129141281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 129241281cf3SAxel Dörfler } 129341281cf3SAxel Dörfler 129441281cf3SAxel Dörfler 129541281cf3SAxel Dörfler BRect 129641281cf3SAxel Dörfler TReplicantTray::IconFrame(const char *name) 129741281cf3SAxel Dörfler { 129841281cf3SAxel Dörfler if (!name) 129941281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 130041281cf3SAxel Dörfler 130141281cf3SAxel Dörfler int32 id, index; 130241281cf3SAxel Dörfler BView *view = ViewAt(&index, &id, name); 130341281cf3SAxel Dörfler if (view) 130441281cf3SAxel Dörfler return view->Frame(); 130541281cf3SAxel Dörfler 130641281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 130741281cf3SAxel Dörfler } 130841281cf3SAxel Dörfler 130941281cf3SAxel Dörfler 13107da06231SAxel Dörfler /** Scan from the startIndex and reset the location 13117da06231SAxel Dörfler * as defined in LocationForReplicant() 131241281cf3SAxel Dörfler */ 131341281cf3SAxel Dörfler 131441281cf3SAxel Dörfler void 131541281cf3SAxel Dörfler TReplicantTray::RealignReplicants(int32 startIndex) 131641281cf3SAxel Dörfler { 131741281cf3SAxel Dörfler if (startIndex < 0) 131841281cf3SAxel Dörfler startIndex = 0; 131941281cf3SAxel Dörfler 132041281cf3SAxel Dörfler int32 count = fShelf->CountReplicants(); 132141281cf3SAxel Dörfler if (count <= 0) 132241281cf3SAxel Dörfler return; 132341281cf3SAxel Dörfler 13247da06231SAxel Dörfler if (startIndex == 0) 13257da06231SAxel Dörfler fRightBottomReplicant.Set(0, 0, 0, 0); 13267da06231SAxel Dörfler 132741281cf3SAxel Dörfler BView *view = NULL; 132841281cf3SAxel Dörfler for (int32 i = startIndex ; i < count ; i++){ 132941281cf3SAxel Dörfler fShelf->ReplicantAt(i, &view); 13307da06231SAxel Dörfler BPoint loc = LocationForReplicant(i, view->Frame().Width()); 133141281cf3SAxel Dörfler if (view && (view->Frame().LeftTop() != loc)) { 133241281cf3SAxel Dörfler view->MoveTo(loc); 133341281cf3SAxel Dörfler } 133441281cf3SAxel Dörfler } 133541281cf3SAxel Dörfler } 133641281cf3SAxel Dörfler 133741281cf3SAxel Dörfler 133841281cf3SAxel Dörfler void 133941281cf3SAxel Dörfler TReplicantTray::SetMultiRow(bool state) 134041281cf3SAxel Dörfler { 134141281cf3SAxel Dörfler fMultiRowMode = state; 134241281cf3SAxel Dörfler 134341281cf3SAxel Dörfler // in multi-row state, we only want the short date 134441281cf3SAxel Dörfler 134541281cf3SAxel Dörfler if (fClock != NULL) 134641281cf3SAxel Dörfler fClock->AllowFullDate(!state); 134741281cf3SAxel Dörfler } 134841281cf3SAxel Dörfler 134941281cf3SAxel Dörfler 135041281cf3SAxel Dörfler // #pragma mark - 135141281cf3SAxel Dörfler 135241281cf3SAxel Dörfler 13537da06231SAxel Dörfler /** draggable region that is asynchronous so that 13547da06231SAxel Dörfler * dragging does not block other activities 13557da06231SAxel Dörfler */ 13567da06231SAxel Dörfler 135741281cf3SAxel Dörfler TDragRegion::TDragRegion(TBarView *parent, BView *child) 135841281cf3SAxel Dörfler : BControl(BRect(0, 0, 0, 0), "", "", NULL, B_FOLLOW_NONE, 135941281cf3SAxel Dörfler B_WILL_DRAW | B_FRAME_EVENTS), 136041281cf3SAxel Dörfler fBarView(parent), 136141281cf3SAxel Dörfler fChild(child), 136241281cf3SAxel Dörfler fDragLocation(kAutoPlaceDragRegion) 136341281cf3SAxel Dörfler { 136441281cf3SAxel Dörfler } 136541281cf3SAxel Dörfler 136641281cf3SAxel Dörfler 136741281cf3SAxel Dörfler void 136841281cf3SAxel Dörfler TDragRegion::AttachedToWindow() 136941281cf3SAxel Dörfler { 137041281cf3SAxel Dörfler BView::AttachedToWindow(); 137141281cf3SAxel Dörfler SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); 137241281cf3SAxel Dörfler ResizeToPreferred(); 137341281cf3SAxel Dörfler } 137441281cf3SAxel Dörfler 137541281cf3SAxel Dörfler 137641281cf3SAxel Dörfler void 137741281cf3SAxel Dörfler TDragRegion::GetPreferredSize(float *width, float *height) 137841281cf3SAxel Dörfler { 137941281cf3SAxel Dörfler fChild->ResizeToPreferred(); 138041281cf3SAxel Dörfler *width = fChild->Bounds().Width(); 138141281cf3SAxel Dörfler *height = fChild->Bounds().Height(); 138241281cf3SAxel Dörfler 138341281cf3SAxel Dörfler if (fDragLocation != kNoDragRegion) 138441281cf3SAxel Dörfler *width += 7; 138541281cf3SAxel Dörfler else 138641281cf3SAxel Dörfler *width += 6; 138741281cf3SAxel Dörfler 138841281cf3SAxel Dörfler *height += 3; 138941281cf3SAxel Dörfler } 139041281cf3SAxel Dörfler 139141281cf3SAxel Dörfler 139241281cf3SAxel Dörfler void 139341281cf3SAxel Dörfler TDragRegion::FrameMoved(BPoint) 139441281cf3SAxel Dörfler { 139541281cf3SAxel Dörfler if (fBarView->Left() && fBarView->Vertical() && fDragLocation != kNoDragRegion) 139641281cf3SAxel Dörfler fChild->MoveTo(5,2); 139741281cf3SAxel Dörfler else 139841281cf3SAxel Dörfler fChild->MoveTo(2,2); 139941281cf3SAxel Dörfler } 140041281cf3SAxel Dörfler 140141281cf3SAxel Dörfler 140241281cf3SAxel Dörfler void 140341281cf3SAxel Dörfler TDragRegion::Draw(BRect) 140441281cf3SAxel Dörfler { 140541281cf3SAxel Dörfler rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR); 140641281cf3SAxel Dörfler rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT); 140741281cf3SAxel Dörfler rgb_color vdark = tint_color(menuColor, B_DARKEN_3_TINT); 140841281cf3SAxel Dörfler rgb_color vvdark = tint_color(menuColor, B_DARKEN_4_TINT); 140941281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 141041281cf3SAxel Dörfler 141141281cf3SAxel Dörfler BRect frame(Bounds()); 141241281cf3SAxel Dörfler BeginLineArray(4); 141341281cf3SAxel Dörfler 141441281cf3SAxel Dörfler if (fBarView->Vertical()) { 141541281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.RightTop(), light); 141641281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.LeftBottom(), light); 141741281cf3SAxel Dörfler AddLine(frame.RightBottom(), frame.RightTop(), hilite); 141841281cf3SAxel Dörfler } else if (fBarView->AcrossTop()) { 141941281cf3SAxel Dörfler AddLine(frame.LeftTop()+BPoint(0, 1), frame.RightTop()+BPoint(-1, 1), 142041281cf3SAxel Dörfler light); 142141281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 142241281cf3SAxel Dörfler AddLine(frame.RightTop()+BPoint(-1, 2),frame.RightBottom()+BPoint(-1, -1), 142341281cf3SAxel Dörfler hilite); 142441281cf3SAxel Dörfler AddLine(frame.LeftBottom(), frame.RightBottom()+BPoint(-1, 0), hilite); 142541281cf3SAxel Dörfler } else if (fBarView->AcrossBottom()) { 142641281cf3SAxel Dörfler AddLine(frame.LeftTop()+BPoint(0, 1), frame.RightTop()+BPoint(-1, 1), light); 142741281cf3SAxel Dörfler AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 142841281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 142941281cf3SAxel Dörfler AddLine(frame.RightTop()+BPoint(-1, 1),frame.RightBottom()+BPoint(-1, -1), 143041281cf3SAxel Dörfler hilite); 143141281cf3SAxel Dörfler } 143241281cf3SAxel Dörfler 143341281cf3SAxel Dörfler EndLineArray(); 143441281cf3SAxel Dörfler 143541281cf3SAxel Dörfler if (fDragLocation != kDontDrawDragRegion || fDragLocation != kNoDragRegion) 143641281cf3SAxel Dörfler DrawDragRegion(); 143741281cf3SAxel Dörfler } 143841281cf3SAxel Dörfler 143941281cf3SAxel Dörfler 144041281cf3SAxel Dörfler void 144141281cf3SAxel Dörfler TDragRegion::DrawDragRegion() 144241281cf3SAxel Dörfler { 144341281cf3SAxel Dörfler rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR); 144441281cf3SAxel Dörfler rgb_color menuHilite = tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT); 144541281cf3SAxel Dörfler rgb_color vdark = tint_color(menuColor, B_DARKEN_3_TINT); 144641281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 144741281cf3SAxel Dörfler 144841281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 144941281cf3SAxel Dörfler 145041281cf3SAxel Dörfler BeginLineArray(dragRegion.IntegerHeight()); 145141281cf3SAxel Dörfler BPoint pt = dragRegion.LeftTop() + BPoint(1,1); 145241281cf3SAxel Dörfler 145341281cf3SAxel Dörfler // Draw drag region highlighted if tracking mouse 145441281cf3SAxel Dörfler if (IsTracking()) { 145541281cf3SAxel Dörfler SetHighColor(menuHilite); 145641281cf3SAxel Dörfler FillRect(dragRegion); 145741281cf3SAxel Dörfler while (pt.y + 1 <= dragRegion.bottom) { 145841281cf3SAxel Dörfler AddLine(pt, pt, light); 145941281cf3SAxel Dörfler AddLine(pt+BPoint(1,1), pt+BPoint(1,1), vdark); 146041281cf3SAxel Dörfler 146141281cf3SAxel Dörfler pt.y += 3; 146241281cf3SAxel Dörfler } 146341281cf3SAxel Dörfler } else { 146441281cf3SAxel Dörfler while (pt.y + 1 <= dragRegion.bottom) { 146541281cf3SAxel Dörfler AddLine(pt, pt, vdark); 146641281cf3SAxel Dörfler AddLine(pt+BPoint(1,1), pt+BPoint(1,1), light); 146741281cf3SAxel Dörfler 146841281cf3SAxel Dörfler pt.y += 3; 146941281cf3SAxel Dörfler } 147041281cf3SAxel Dörfler } 147141281cf3SAxel Dörfler EndLineArray(); 147241281cf3SAxel Dörfler } 147341281cf3SAxel Dörfler 147441281cf3SAxel Dörfler 147541281cf3SAxel Dörfler BRect 147641281cf3SAxel Dörfler TDragRegion::DragRegion() const 147741281cf3SAxel Dörfler { 147841281cf3SAxel Dörfler BRect dragRegion(Bounds()); 147941281cf3SAxel Dörfler dragRegion.top += 2; 148041281cf3SAxel Dörfler dragRegion.bottom -= 2; 148141281cf3SAxel Dörfler 148241281cf3SAxel Dörfler bool placeOnLeft=false; 148341281cf3SAxel Dörfler if (fDragLocation == kAutoPlaceDragRegion) { 148441281cf3SAxel Dörfler if (fBarView->Vertical() && fBarView->Left()) 148541281cf3SAxel Dörfler placeOnLeft = true; 148641281cf3SAxel Dörfler else 148741281cf3SAxel Dörfler placeOnLeft = false; 148841281cf3SAxel Dörfler } else if (fDragLocation == kDragRegionLeft) 148941281cf3SAxel Dörfler placeOnLeft = true; 149041281cf3SAxel Dörfler else if (fDragLocation == kDragRegionRight) 149141281cf3SAxel Dörfler placeOnLeft = false; 149241281cf3SAxel Dörfler 149341281cf3SAxel Dörfler if (placeOnLeft) { 149441281cf3SAxel Dörfler dragRegion.left += 1; 149541281cf3SAxel Dörfler dragRegion.right = dragRegion.left + 3; 149641281cf3SAxel Dörfler } else { 149741281cf3SAxel Dörfler dragRegion.right -= 1; 149841281cf3SAxel Dörfler dragRegion.left = dragRegion.right - 3; 149941281cf3SAxel Dörfler } 150041281cf3SAxel Dörfler 150141281cf3SAxel Dörfler return dragRegion; 150241281cf3SAxel Dörfler } 150341281cf3SAxel Dörfler 150441281cf3SAxel Dörfler 150541281cf3SAxel Dörfler void 150641281cf3SAxel Dörfler TDragRegion::MouseDown(BPoint thePoint) 150741281cf3SAxel Dörfler { 150841281cf3SAxel Dörfler ulong buttons; 150941281cf3SAxel Dörfler BPoint where; 151041281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 151141281cf3SAxel Dörfler 15127da06231SAxel Dörfler dragRegion.InsetBy(-2.0f, -2.0f); 15137da06231SAxel Dörfler // DragRegion() is designed for drawing, not clicking 151441281cf3SAxel Dörfler 151541281cf3SAxel Dörfler if (!dragRegion.Contains(thePoint)) 151641281cf3SAxel Dörfler return; 151741281cf3SAxel Dörfler 151841281cf3SAxel Dörfler while(true) { 151941281cf3SAxel Dörfler GetMouse(&where, &buttons); 152041281cf3SAxel Dörfler if (!buttons) 152141281cf3SAxel Dörfler break; 152241281cf3SAxel Dörfler 152341281cf3SAxel Dörfler if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) != 0) { 152441281cf3SAxel Dörfler fPreviousPosition = thePoint; 152541281cf3SAxel Dörfler SetTracking(true); 152641281cf3SAxel Dörfler SetMouseEventMask(B_POINTER_EVENTS, 152741281cf3SAxel Dörfler B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); 152841281cf3SAxel Dörfler Invalidate(DragRegion()); 152941281cf3SAxel Dörfler break; 153041281cf3SAxel Dörfler } 153141281cf3SAxel Dörfler 153241281cf3SAxel Dörfler snooze(25000); 153341281cf3SAxel Dörfler } 153441281cf3SAxel Dörfler } 153541281cf3SAxel Dörfler 153641281cf3SAxel Dörfler 153741281cf3SAxel Dörfler void 153841281cf3SAxel Dörfler TDragRegion::MouseUp(BPoint pt) 153941281cf3SAxel Dörfler { 154041281cf3SAxel Dörfler if (IsTracking()) { 154141281cf3SAxel Dörfler SetTracking(false); 154241281cf3SAxel Dörfler Invalidate(DragRegion()); 154341281cf3SAxel Dörfler } else 154441281cf3SAxel Dörfler BControl::MouseUp(pt); 154541281cf3SAxel Dörfler } 154641281cf3SAxel Dörfler 154741281cf3SAxel Dörfler 154841281cf3SAxel Dörfler bool 154941281cf3SAxel Dörfler TDragRegion::SwitchModeForRect(BPoint mouse, BRect rect, 155041281cf3SAxel Dörfler bool newVertical, bool newLeft, bool newTop, int32 newState) 155141281cf3SAxel Dörfler { 155241281cf3SAxel Dörfler if (!rect.Contains(mouse)) 155341281cf3SAxel Dörfler // not our rect 155441281cf3SAxel Dörfler return false; 155541281cf3SAxel Dörfler 155641281cf3SAxel Dörfler if (newVertical == fBarView->Vertical() 155741281cf3SAxel Dörfler && newLeft == fBarView->Left() 155841281cf3SAxel Dörfler && newTop == fBarView->Top() 155941281cf3SAxel Dörfler && newState == fBarView->State()) 156041281cf3SAxel Dörfler // already in the correct mode 156141281cf3SAxel Dörfler return true; 156241281cf3SAxel Dörfler 156341281cf3SAxel Dörfler fBarView->ChangeState(newState, newVertical, newLeft, newTop); 156441281cf3SAxel Dörfler return true; 156541281cf3SAxel Dörfler } 156641281cf3SAxel Dörfler 156741281cf3SAxel Dörfler 156841281cf3SAxel Dörfler void 156941281cf3SAxel Dörfler TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage *message) 157041281cf3SAxel Dörfler { 157141281cf3SAxel Dörfler if (IsTracking()) { 157241281cf3SAxel Dörfler BScreen screen; 157341281cf3SAxel Dörfler BRect frame = screen.Frame(); 157441281cf3SAxel Dörfler 157541281cf3SAxel Dörfler float hDivider = frame.Width() / 6; 157641281cf3SAxel Dörfler hDivider = (hDivider < kMinimumWindowWidth + 10.0f) ? kMinimumWindowWidth + 10.0f : hDivider; 157741281cf3SAxel Dörfler float miniDivider = frame.top + kMiniHeight + 10.0f; 157841281cf3SAxel Dörfler float vDivider = frame.Height() / 2; 157941281cf3SAxel Dörfler #ifdef FULL_MODE 158041281cf3SAxel Dörfler float thirdScreen = frame.Height() / 3; 158141281cf3SAxel Dörfler #endif 158241281cf3SAxel Dörfler BRect topLeft(frame.left, frame.top, frame.left + hDivider, miniDivider); 158341281cf3SAxel Dörfler BRect topMiddle(frame.left + hDivider, frame.top, frame.right - hDivider, vDivider); 158441281cf3SAxel Dörfler BRect topRight(frame.right - hDivider, frame.top, frame.right, miniDivider); 158541281cf3SAxel Dörfler 158641281cf3SAxel Dörfler #ifdef FULL_MODE 158741281cf3SAxel Dörfler vDivider = miniDivider + thirdScreen; 158841281cf3SAxel Dörfler #endif 158941281cf3SAxel Dörfler BRect middleLeft(frame.left, miniDivider, frame.left + hDivider, vDivider); 159041281cf3SAxel Dörfler BRect middleRight(frame.right - hDivider, miniDivider, frame.right, vDivider); 159141281cf3SAxel Dörfler 159241281cf3SAxel Dörfler #ifdef FULL_MODE 159341281cf3SAxel Dörfler BRect leftSide(frame.left, vDivider, frame.left + hDivider, frame.bottom - thirdScreen); 159441281cf3SAxel Dörfler BRect rightSide(frame.right - hDivider, vDivider, frame.right, frame.bottom - thirdScreen); 159541281cf3SAxel Dörfler 159641281cf3SAxel Dörfler vDivider = frame.bottom - thirdScreen; 159741281cf3SAxel Dörfler #endif 159841281cf3SAxel Dörfler BRect bottomLeft(frame.left, vDivider, frame.left + hDivider, frame.bottom); 159941281cf3SAxel Dörfler BRect bottomMiddle(frame.left + hDivider, vDivider, frame.right - hDivider, frame.bottom); 160041281cf3SAxel Dörfler BRect bottomRight(frame.right - hDivider, vDivider, frame.right, frame.bottom); 160141281cf3SAxel Dörfler 160241281cf3SAxel Dörfler if (where != fPreviousPosition) { 160341281cf3SAxel Dörfler fPreviousPosition = where; 160441281cf3SAxel Dörfler ConvertToScreen(&where); 160541281cf3SAxel Dörfler 160641281cf3SAxel Dörfler // use short circuit evaluation for convenience 160741281cf3SAxel Dörfler if (SwitchModeForRect(where, topLeft, true, true, true, kMiniState) 160841281cf3SAxel Dörfler || SwitchModeForRect(where, topMiddle, false, true, true, kExpandoState) 160941281cf3SAxel Dörfler || SwitchModeForRect(where, topRight, true, false, true, kMiniState) 161041281cf3SAxel Dörfler 161141281cf3SAxel Dörfler || SwitchModeForRect(where, middleLeft, true, true, true, kExpandoState) 161241281cf3SAxel Dörfler || SwitchModeForRect(where, middleRight, true, false, true, kExpandoState) 161341281cf3SAxel Dörfler 161441281cf3SAxel Dörfler #ifdef FULL_MODE 161541281cf3SAxel Dörfler || SwitchModeForRect(where, leftSide, true, true, true, kFullState) 161641281cf3SAxel Dörfler || SwitchModeForRect(where, rightSide, true, false, true, kFullState) 161741281cf3SAxel Dörfler #endif 161841281cf3SAxel Dörfler || SwitchModeForRect(where, bottomLeft, true, true, false, kMiniState) 161941281cf3SAxel Dörfler || SwitchModeForRect(where, bottomMiddle, false, true, false, kExpandoState) 16207da06231SAxel Dörfler || SwitchModeForRect(where, bottomRight, true, false, false, kMiniState)) 162141281cf3SAxel Dörfler ; 162241281cf3SAxel Dörfler } 162341281cf3SAxel Dörfler } else 162441281cf3SAxel Dörfler BControl::MouseMoved(where, code, message); 162541281cf3SAxel Dörfler } 162641281cf3SAxel Dörfler 162741281cf3SAxel Dörfler 162841281cf3SAxel Dörfler int32 162941281cf3SAxel Dörfler TDragRegion::DragRegionLocation() const 163041281cf3SAxel Dörfler { 163141281cf3SAxel Dörfler return fDragLocation; 163241281cf3SAxel Dörfler } 163341281cf3SAxel Dörfler 163441281cf3SAxel Dörfler 163541281cf3SAxel Dörfler void 163641281cf3SAxel Dörfler TDragRegion::SetDragRegionLocation(int32 location) 163741281cf3SAxel Dörfler { 163841281cf3SAxel Dörfler if (location == fDragLocation) 163941281cf3SAxel Dörfler return; 164041281cf3SAxel Dörfler 164141281cf3SAxel Dörfler fDragLocation = location; 164241281cf3SAxel Dörfler Invalidate(); 164341281cf3SAxel Dörfler } 164441281cf3SAxel Dörfler 1645