141281cf3SAxel Dörfler /* 241281cf3SAxel Dörfler Open Tracker License 341281cf3SAxel Dörfler 441281cf3SAxel Dörfler Terms and Conditions 541281cf3SAxel Dörfler 641281cf3SAxel Dörfler Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 741281cf3SAxel Dörfler 841281cf3SAxel Dörfler Permission is hereby granted, free of charge, to any person obtaining a copy of 941281cf3SAxel Dörfler this software and associated documentation files (the "Software"), to deal in 1041281cf3SAxel Dörfler the Software without restriction, including without limitation the rights to 1141281cf3SAxel Dörfler use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 1241281cf3SAxel Dörfler of the Software, and to permit persons to whom the Software is furnished to do 1341281cf3SAxel Dörfler so, subject to the following conditions: 1441281cf3SAxel Dörfler 1541281cf3SAxel Dörfler The above copyright notice and this permission notice applies to all licensees 1641281cf3SAxel Dörfler and shall be included in all copies or substantial portions of the Software. 1741281cf3SAxel Dörfler 1841281cf3SAxel Dörfler THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1941281cf3SAxel Dörfler IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 2041281cf3SAxel Dörfler FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2141281cf3SAxel Dörfler BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2241281cf3SAxel Dörfler AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 2341281cf3SAxel Dörfler WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2441281cf3SAxel Dörfler 2541281cf3SAxel Dörfler Except as contained in this notice, the name of Be Incorporated shall not be 2641281cf3SAxel Dörfler used in advertising or otherwise to promote the sale, use or other dealings in 2741281cf3SAxel Dörfler this Software without prior written authorization from Be Incorporated. 2841281cf3SAxel Dörfler 291ad8c760SFredrik Holmqvist Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered 301ad8c760SFredrik Holmqvist trademarks of Be Incorporated in the United States and other countries. Other 311ad8c760SFredrik Holmqvist brand product names are registered trademarks or trademarks of their respective 321ad8c760SFredrik Holmqvist holders. 3341281cf3SAxel Dörfler All rights reserved. 3441281cf3SAxel Dörfler */ 3541281cf3SAxel Dörfler 361cd61330SJohn Scipione 371cd61330SJohn Scipione #include "StatusView.h" 3841281cf3SAxel Dörfler 3941281cf3SAxel Dörfler #include <errno.h> 4041281cf3SAxel Dörfler #include <stdio.h> 4141281cf3SAxel Dörfler #include <string.h> 4241281cf3SAxel Dörfler #include <time.h> 4341281cf3SAxel Dörfler #include <unistd.h> 4441281cf3SAxel Dörfler #include <algorithm> 4541281cf3SAxel Dörfler 4641281cf3SAxel Dörfler #include <fs_index.h> 4741281cf3SAxel Dörfler #include <fs_info.h> 4841281cf3SAxel Dörfler 4941281cf3SAxel Dörfler #include <Application.h> 5041281cf3SAxel Dörfler #include <Beep.h> 51cb6afcb1SStephan Aßmus #include <Bitmap.h> 52ae7a6e3aSAdrien Destugues #include <Catalog.h> 53cb6afcb1SStephan Aßmus #include <ControlLook.h> 541cd61330SJohn Scipione #include <Debug.h> 5541281cf3SAxel Dörfler #include <Directory.h> 5641281cf3SAxel Dörfler #include <FindDirectory.h> 57ae7a6e3aSAdrien Destugues #include <Locale.h> 5841281cf3SAxel Dörfler #include <MenuItem.h> 5941281cf3SAxel Dörfler #include <NodeInfo.h> 6041281cf3SAxel Dörfler #include <NodeMonitor.h> 6141281cf3SAxel Dörfler #include <Path.h> 6241281cf3SAxel Dörfler #include <PopUpMenu.h> 6341281cf3SAxel Dörfler #include <Roster.h> 6441281cf3SAxel Dörfler #include <Screen.h> 6541281cf3SAxel Dörfler #include <Volume.h> 6641281cf3SAxel Dörfler #include <VolumeRoster.h> 6741281cf3SAxel Dörfler #include <Window.h> 6841281cf3SAxel Dörfler 69615d572dSJohn Scipione #include "icons.h" 70615d572dSJohn Scipione 71cb6afcb1SStephan Aßmus #include "BarApp.h" 72323b6546SOliver Tappe #include "DeskbarUtils.h" 73*15eb397eSJohn Scipione #include "ExpandoMenuBar.h" 74cb6afcb1SStephan Aßmus #include "ResourceSet.h" 7541281cf3SAxel Dörfler #include "StatusViewShelf.h" 7641281cf3SAxel Dörfler #include "TimeView.h" 7741281cf3SAxel Dörfler 78615d572dSJohn Scipione 7941281cf3SAxel Dörfler #ifdef DB_ADDONS 8041281cf3SAxel Dörfler // Add-on support 8141281cf3SAxel Dörfler // 8241281cf3SAxel Dörfler // Item - internal item list (node, eref, etc) 8341281cf3SAxel Dörfler // Icon - physical replicant handed to the DeskbarClass class 8441281cf3SAxel Dörfler // AddOn - attribute based add-on 8541281cf3SAxel Dörfler 8641281cf3SAxel Dörfler const char* const kInstantiateItemCFunctionName = "instantiate_deskbar_item"; 8741281cf3SAxel Dörfler const char* const kInstantiateEntryCFunctionName = "instantiate_deskbar_entry"; 8826ea7066SIngo Weinhold const char* const kReplicantSettingsFile = "replicants"; 89c0ad1c91SRene Gollent const char* const kReplicantPathField = "replicant_path"; 9041281cf3SAxel Dörfler 91b49e806dSAxel Dörfler float gMinimumWindowWidth = kGutter + kMinimumTrayWidth + kDragRegionWidth; 921bb2e623SJohn Scipione float gMaximumWindowWidth = gMinimumWindowWidth * 2; 9341281cf3SAxel Dörfler 94c3c3360fSJohn Scipione 9541281cf3SAxel Dörfler static void 9641281cf3SAxel Dörfler DumpItem(DeskbarItemInfo* item) 9741281cf3SAxel Dörfler { 98e9632898SAlex Smith printf("is addon: %i, id: %" B_PRId32 "\n", item->isAddOn, item->id); 99e9632898SAlex Smith printf("entry_ref: %" B_PRIdDEV ", %" B_PRIdINO ", %s\n", 100e9632898SAlex Smith item->entryRef.device, item->entryRef.directory, item->entryRef.name); 101e9632898SAlex Smith printf("node_ref: %" B_PRIdDEV ", %" B_PRIdINO "\n", item->nodeRef.device, 102e9632898SAlex Smith item->nodeRef.node); 10341281cf3SAxel Dörfler } 10441281cf3SAxel Dörfler 10541281cf3SAxel Dörfler 10641281cf3SAxel Dörfler static void 10741281cf3SAxel Dörfler DumpList(BList* itemlist) 10841281cf3SAxel Dörfler { 10941281cf3SAxel Dörfler int32 count = itemlist->CountItems() - 1; 11041281cf3SAxel Dörfler if (count < 0) { 11141281cf3SAxel Dörfler printf("no items in list\n"); 11241281cf3SAxel Dörfler return; 11341281cf3SAxel Dörfler } 11441281cf3SAxel Dörfler for (int32 i = count; i >= 0; i--) { 11541281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)itemlist->ItemAt(i); 11641281cf3SAxel Dörfler if (!item) 11741281cf3SAxel Dörfler continue; 11841281cf3SAxel Dörfler 11941281cf3SAxel Dörfler DumpItem(item); 12041281cf3SAxel Dörfler } 12141281cf3SAxel Dörfler } 12241281cf3SAxel Dörfler #endif /* DB_ADDONS */ 12341281cf3SAxel Dörfler 12441281cf3SAxel Dörfler 125546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT 126546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "Tray" 127ae7a6e3aSAdrien Destugues 1287da06231SAxel Dörfler // don't change the name of this view to anything other than "Status"! 1297da06231SAxel Dörfler 13041281cf3SAxel Dörfler TReplicantTray::TReplicantTray(TBarView* parent, bool vertical) 1310d2ac94cSJohn Scipione : 1329ac6fee1SJohn Scipione BView(BRect(0, 0, 1, 1), "Status", B_FOLLOW_LEFT | B_FOLLOW_TOP, 1330d2ac94cSJohn Scipione B_WILL_DRAW | B_FRAME_EVENTS), 134573f748cSJohn Scipione fTime(NULL), 13541281cf3SAxel Dörfler fBarView(parent), 13641281cf3SAxel Dörfler fShelf(new TReplicantShelf(this)), 13741281cf3SAxel Dörfler fMultiRowMode(vertical), 13841281cf3SAxel Dörfler fAlignmentSupport(false) 13941281cf3SAxel Dörfler { 140efafab64SAxel Dörfler fMaxReplicantHeight = std::max(kMinReplicantHeight, 141efafab64SAxel Dörfler floorf(kMinReplicantHeight * be_plain_font->Size() / 12)); 142efafab64SAxel Dörfler // TODO: depends on window size... (so use something like 143efafab64SAxel Dörfler // max(129, height * 3), and restrict the minimum window width for it) 144efafab64SAxel Dörfler fMaxReplicantWidth = 129; 145efafab64SAxel Dörfler 146efafab64SAxel Dörfler fMinTrayHeight = kGutter + fMaxReplicantHeight + kGutter; 147fb956f25SAxel Dörfler if (vertical) 148fb956f25SAxel Dörfler fMinimumTrayWidth = gMinimumWindowWidth - kGutter - kDragRegionWidth; 1491bb2e623SJohn Scipione else 1501bb2e623SJohn Scipione fMinimumTrayWidth = kMinimumTrayWidth; 151573f748cSJohn Scipione 152573f748cSJohn Scipione // Create the time view 153efafab64SAxel Dörfler fTime = new TTimeView(fMinimumTrayWidth, fMaxReplicantHeight - 1.0); 15441281cf3SAxel Dörfler } 15541281cf3SAxel Dörfler 15641281cf3SAxel Dörfler 15741281cf3SAxel Dörfler TReplicantTray::~TReplicantTray() 15841281cf3SAxel Dörfler { 15941281cf3SAxel Dörfler delete fShelf; 160573f748cSJohn Scipione delete fTime; 16141281cf3SAxel Dörfler } 16241281cf3SAxel Dörfler 16341281cf3SAxel Dörfler 16441281cf3SAxel Dörfler void 16541281cf3SAxel Dörfler TReplicantTray::AttachedToWindow() 16641281cf3SAxel Dörfler { 16741281cf3SAxel Dörfler BView::AttachedToWindow(); 16841281cf3SAxel Dörfler 169cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 170cef0a7b2Slooncraz AdoptParentColors(); 171cb6afcb1SStephan Aßmus } else { 17216c10517Slooncraz SetViewUIColor(B_MENU_BACKGROUND_COLOR, B_DARKEN_1_TINT); 173cb6afcb1SStephan Aßmus } 17441281cf3SAxel Dörfler SetDrawingMode(B_OP_COPY); 17566eba86fSAxel Dörfler 17641281cf3SAxel Dörfler Window()->SetPulseRate(1000000); 17741281cf3SAxel Dörfler 1783722e640SJohn Scipione clock_settings* clock = ((TBarApp*)be_app)->ClockSettings(); 1793722e640SJohn Scipione fTime->SetShowSeconds(clock->showSeconds); 1803722e640SJohn Scipione fTime->SetShowDayOfWeek(clock->showDayOfWeek); 1813722e640SJohn Scipione fTime->SetShowTimeZone(clock->showTimeZone); 18231c0024dSJohn Scipione 183573f748cSJohn Scipione AddChild(fTime); 1841bb2e623SJohn Scipione 18570ad5289SJohn Scipione fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - kTrayPadding, 2); 1861dd1976fSJohn Scipione fTime->SetOrientation(fMultiRowMode); 187ae7a6e3aSAdrien Destugues 1883722e640SJohn Scipione if (!((TBarApp*)be_app)->Settings()->showClock) 1893722e640SJohn Scipione fTime->Hide(); 1903722e640SJohn Scipione 19141281cf3SAxel Dörfler #ifdef DB_ADDONS 19241281cf3SAxel Dörfler // load addons and rehydrate archives 1933a6add49SAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 19441281cf3SAxel Dörfler InitAddOnSupport(); 19541281cf3SAxel Dörfler #endif 1969c910f9eSStephan Aßmus #endif 19741281cf3SAxel Dörfler ResizeToPreferred(); 19841281cf3SAxel Dörfler } 19941281cf3SAxel Dörfler 20041281cf3SAxel Dörfler 20141281cf3SAxel Dörfler void 20241281cf3SAxel Dörfler TReplicantTray::DetachedFromWindow() 20341281cf3SAxel Dörfler { 20441281cf3SAxel Dörfler #ifdef DB_ADDONS 20541281cf3SAxel Dörfler // clean up add-on support 206465b54cdSAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 20741281cf3SAxel Dörfler DeleteAddOnSupport(); 20841281cf3SAxel Dörfler #endif 209465b54cdSAxel Dörfler #endif 21041281cf3SAxel Dörfler BView::DetachedFromWindow(); 21141281cf3SAxel Dörfler } 21241281cf3SAxel Dörfler 21341281cf3SAxel Dörfler 2141ad8c760SFredrik Holmqvist /*! Width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth 21566eba86fSAxel Dörfler if not in multirowmode and greater than kMinimumReplicantCount 2162ce9bab8SJohn Scipione the width should be calculated based on the actual replicant widths 21741281cf3SAxel Dörfler */ 21841281cf3SAxel Dörfler void 21941281cf3SAxel Dörfler TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight) 22041281cf3SAxel Dörfler { 2211bb2e623SJohn Scipione float width = 0; 222efafab64SAxel Dörfler float height = fMinTrayHeight; 22341281cf3SAxel Dörfler 22441281cf3SAxel Dörfler if (fMultiRowMode) { 2251bb2e623SJohn Scipione width = static_cast<TBarApp*>(be_app)->Settings()->width 2261bb2e623SJohn Scipione - kDragWidth - kGutter; 227a44504a1SJohn Scipione if (fRightBottomReplicant.IsValid()) 2287da06231SAxel Dörfler height = fRightBottomReplicant.bottom; 229a44504a1SJohn Scipione else if (ReplicantCount() > 0) { 230a44504a1SJohn Scipione // The height will be uniform for the number of rows necessary 231a44504a1SJohn Scipione // to show all the replicants and gutters. 232efafab64SAxel Dörfler int32 rowCount = (int32)(height / fMaxReplicantHeight); 233efafab64SAxel Dörfler height = kGutter + (rowCount * fMaxReplicantHeight) 23441281cf3SAxel Dörfler + ((rowCount - 1) * kIconGap) + kGutter; 235efafab64SAxel Dörfler height = std::max(fMinTrayHeight, height); 236a44504a1SJohn Scipione } else 237efafab64SAxel Dörfler height = fMinTrayHeight; 23841281cf3SAxel Dörfler } else { 2391ad8c760SFredrik Holmqvist // if last replicant overruns clock then resize to accomodate 24032b0035aSJohn Scipione if (ReplicantCount() > 0) { 2411c765f5bSJohn Scipione if (!fTime->IsHidden(fTime) && Bounds().right - kTrayPadding - 2 242c0be5490SJohn Scipione - fTime->Frame().Width() - kClockMargin 2437b7bf68dSJohn Scipione < fRightBottomReplicant.right + kClockMargin) { 2447b7bf68dSJohn Scipione width = fRightBottomReplicant.right + kClockMargin 245c0be5490SJohn Scipione + fTime->Frame().Width() + kTrayPadding + 2; 24641281cf3SAxel Dörfler } else 24770ad5289SJohn Scipione width = fRightBottomReplicant.right + kIconGap + kGutter; 24841281cf3SAxel Dörfler } 2491ad8c760SFredrik Holmqvist 25041281cf3SAxel Dörfler // this view has a fixed minimum width 251efafab64SAxel Dörfler width = std::max(kMinimumTrayWidth, width); 2522ce9bab8SJohn Scipione height = kGutter + static_cast<TBarApp*>(be_app)->IconSize() + kGutter; 25341281cf3SAxel Dörfler } 25441281cf3SAxel Dörfler 25541281cf3SAxel Dörfler *preferredWidth = width; 2561ad8c760SFredrik Holmqvist // add 1 for the border 25741281cf3SAxel Dörfler *preferredHeight = height + 1; 25841281cf3SAxel Dörfler } 25941281cf3SAxel Dörfler 26041281cf3SAxel Dörfler 26141281cf3SAxel Dörfler void 26241281cf3SAxel Dörfler TReplicantTray::AdjustPlacement() 26341281cf3SAxel Dörfler { 26441281cf3SAxel Dörfler // called when an add-on has been added or removed 26541281cf3SAxel Dörfler // need to resize the parent of this accordingly 266a5210ab1SAxel Dörfler 26741281cf3SAxel Dörfler BRect bounds = Bounds(); 26841281cf3SAxel Dörfler float width, height; 26941281cf3SAxel Dörfler GetPreferredSize(&width, &height); 27041281cf3SAxel Dörfler 27141281cf3SAxel Dörfler if (width == bounds.Width() && height == bounds.Height()) { 27241281cf3SAxel Dörfler // no need to change anything 27341281cf3SAxel Dörfler return; 27441281cf3SAxel Dörfler } 27541281cf3SAxel Dörfler 27641281cf3SAxel Dörfler Parent()->ResizeToPreferred(); 27741281cf3SAxel Dörfler fBarView->UpdatePlacement(); 27841281cf3SAxel Dörfler Parent()->Invalidate(); 27941281cf3SAxel Dörfler Invalidate(); 28041281cf3SAxel Dörfler } 28141281cf3SAxel Dörfler 28241281cf3SAxel Dörfler 28341281cf3SAxel Dörfler void 28441281cf3SAxel Dörfler TReplicantTray::MessageReceived(BMessage* message) 28541281cf3SAxel Dörfler { 28641281cf3SAxel Dörfler switch (message->what) { 28730a55802SJohn Scipione case B_LOCALE_CHANGED: 288573f748cSJohn Scipione if (fTime == NULL) 289573f748cSJohn Scipione return; 290573f748cSJohn Scipione 2914c999927SAdrien Destugues fTime->UpdateTimeFormat(); 29231c0024dSJohn Scipione fTime->Update(); 29341281cf3SAxel Dörfler // time string reformat -> realign 294c0dc265cSJohn Scipione goto realignReplicants; 295573f748cSJohn Scipione 29630a55802SJohn Scipione case kShowHideTime: 29730a55802SJohn Scipione // from context menu in clock and in this view 29830a55802SJohn Scipione ShowHideTime(); 29930a55802SJohn Scipione break; 30030a55802SJohn Scipione 3013cf2d117SJohn Scipione case kShowSeconds: 302573f748cSJohn Scipione if (fTime == NULL) 303573f748cSJohn Scipione return; 304573f748cSJohn Scipione 3053cf2d117SJohn Scipione fTime->SetShowSeconds(!fTime->ShowSeconds()); 306573f748cSJohn Scipione 3073cf2d117SJohn Scipione // time string reformat -> realign 308c0dc265cSJohn Scipione goto realignReplicants; 3093cf2d117SJohn Scipione 3103cf2d117SJohn Scipione case kShowDayOfWeek: 3113cf2d117SJohn Scipione if (fTime == NULL) 3123cf2d117SJohn Scipione return; 3133cf2d117SJohn Scipione 3143cf2d117SJohn Scipione fTime->SetShowDayOfWeek(!fTime->ShowDayOfWeek()); 3153cf2d117SJohn Scipione 3163cf2d117SJohn Scipione // time string reformat -> realign 317c0dc265cSJohn Scipione goto realignReplicants; 3183cf2d117SJohn Scipione 31931c0024dSJohn Scipione case kShowTimeZone: 32031c0024dSJohn Scipione if (fTime == NULL) 32131c0024dSJohn Scipione return; 32231c0024dSJohn Scipione 32331c0024dSJohn Scipione fTime->SetShowTimeZone(!fTime->ShowTimeZone()); 32431c0024dSJohn Scipione 32531c0024dSJohn Scipione // time string reformat -> realign 326c0dc265cSJohn Scipione goto realignReplicants; 32731c0024dSJohn Scipione 32831c0024dSJohn Scipione case kGetClockSettings: 32931c0024dSJohn Scipione { 33031c0024dSJohn Scipione if (fTime == NULL) 33131c0024dSJohn Scipione return; 33231c0024dSJohn Scipione 3331c765f5bSJohn Scipione bool showClock = !fTime->IsHidden(fTime); 33431c0024dSJohn Scipione bool showSeconds = fTime->ShowSeconds(); 33531c0024dSJohn Scipione bool showDayOfWeek = fTime->ShowDayOfWeek(); 33631c0024dSJohn Scipione bool showTimeZone = fTime->ShowTimeZone(); 33731c0024dSJohn Scipione 3380fc30d89SDario Casalinuovo BMessage reply(kGetClockSettings); 3390fc30d89SDario Casalinuovo reply.AddBool("showClock", showClock); 3400fc30d89SDario Casalinuovo reply.AddBool("showSeconds", showSeconds); 3410fc30d89SDario Casalinuovo reply.AddBool("showDayOfWeek", showDayOfWeek); 3420fc30d89SDario Casalinuovo reply.AddBool("showTimeZone", showTimeZone); 3430fc30d89SDario Casalinuovo message->SendReply(&reply); 34431c0024dSJohn Scipione break; 34531c0024dSJohn Scipione } 34631c0024dSJohn Scipione 34741281cf3SAxel Dörfler #ifdef DB_ADDONS 34841281cf3SAxel Dörfler case B_NODE_MONITOR: 34941281cf3SAxel Dörfler HandleEntryUpdate(message); 35041281cf3SAxel Dörfler break; 35141281cf3SAxel Dörfler #endif 35241281cf3SAxel Dörfler 353c0dc265cSJohn Scipione case kRealignReplicants: 354c0dc265cSJohn Scipione realignReplicants: 355c0dc265cSJohn Scipione RealignReplicants(); 356c0dc265cSJohn Scipione AdjustPlacement(); 357c0dc265cSJohn Scipione break; 358c0dc265cSJohn Scipione 35941281cf3SAxel Dörfler default: 36041281cf3SAxel Dörfler BView::MessageReceived(message); 36141281cf3SAxel Dörfler break; 36241281cf3SAxel Dörfler } 36341281cf3SAxel Dörfler } 36441281cf3SAxel Dörfler 36541281cf3SAxel Dörfler 36641281cf3SAxel Dörfler void 36741281cf3SAxel Dörfler TReplicantTray::MouseDown(BPoint where) 36841281cf3SAxel Dörfler { 36941281cf3SAxel Dörfler #ifdef DB_ADDONS 37041281cf3SAxel Dörfler if (modifiers() & B_CONTROL_KEY) 37141281cf3SAxel Dörfler DumpList(fItemList); 37241281cf3SAxel Dörfler #endif 37341281cf3SAxel Dörfler 37441281cf3SAxel Dörfler uint32 buttons; 37541281cf3SAxel Dörfler 37641281cf3SAxel Dörfler Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons); 37741281cf3SAxel Dörfler if (buttons == B_SECONDARY_MOUSE_BUTTON) { 37841281cf3SAxel Dörfler ShowReplicantMenu(where); 37941281cf3SAxel Dörfler } else { 38041281cf3SAxel Dörfler BPoint save = where; 38141281cf3SAxel Dörfler bigtime_t doubleClickSpeed; 38241281cf3SAxel Dörfler bigtime_t start = system_time(); 38341281cf3SAxel Dörfler uint32 buttons; 38441281cf3SAxel Dörfler 38541281cf3SAxel Dörfler get_click_speed(&doubleClickSpeed); 38641281cf3SAxel Dörfler 38741281cf3SAxel Dörfler do { 38841281cf3SAxel Dörfler if (fabs(where.x - save.x) > 4 || fabs(where.y - save.y) > 4) 38941281cf3SAxel Dörfler // user moved out of bounds of click area 39041281cf3SAxel Dörfler break; 39141281cf3SAxel Dörfler 39241281cf3SAxel Dörfler if ((system_time() - start) > (2 * doubleClickSpeed)) { 39341281cf3SAxel Dörfler ShowReplicantMenu(where); 39441281cf3SAxel Dörfler break; 39541281cf3SAxel Dörfler } 39641281cf3SAxel Dörfler 39741281cf3SAxel Dörfler snooze(50000); 39841281cf3SAxel Dörfler GetMouse(&where, &buttons); 39941281cf3SAxel Dörfler } while (buttons); 40041281cf3SAxel Dörfler } 40141281cf3SAxel Dörfler BView::MouseDown(where); 40241281cf3SAxel Dörfler } 40341281cf3SAxel Dörfler 4043cf2d117SJohn Scipione 4053cf2d117SJohn Scipione void 4063cf2d117SJohn Scipione TReplicantTray::ShowReplicantMenu(BPoint point) 4073cf2d117SJohn Scipione { 4083cf2d117SJohn Scipione BPopUpMenu* menu = new BPopUpMenu("", false, false); 4093cf2d117SJohn Scipione menu->SetFont(be_plain_font); 4103cf2d117SJohn Scipione 41131c0024dSJohn Scipione // If clock is visible show the extended menu, otherwise show "Show clock" 4123cf2d117SJohn Scipione 4131c765f5bSJohn Scipione if (!fTime->IsHidden(fTime)) 4143cf2d117SJohn Scipione fTime->ShowTimeOptions(ConvertToScreen(point)); 4153cf2d117SJohn Scipione else { 41631c0024dSJohn Scipione BMenuItem* item = new BMenuItem(B_TRANSLATE("Show clock"), 4173cf2d117SJohn Scipione new BMessage(kShowHideTime)); 4183cf2d117SJohn Scipione menu->AddItem(item); 4193cf2d117SJohn Scipione menu->SetTargetForItems(this); 4203cf2d117SJohn Scipione BPoint where = ConvertToScreen(point); 4213cf2d117SJohn Scipione menu->Go(where, true, true, BRect(where - BPoint(4, 4), 4223cf2d117SJohn Scipione where + BPoint(4, 4)), true); 4233cf2d117SJohn Scipione } 4243cf2d117SJohn Scipione } 4253cf2d117SJohn Scipione 4263cf2d117SJohn Scipione 4273cf2d117SJohn Scipione void 4283cf2d117SJohn Scipione TReplicantTray::SetMultiRow(bool state) 4293cf2d117SJohn Scipione { 4303cf2d117SJohn Scipione fMultiRowMode = state; 4313cf2d117SJohn Scipione } 4323cf2d117SJohn Scipione 4333cf2d117SJohn Scipione 4343cf2d117SJohn Scipione void 4353cf2d117SJohn Scipione TReplicantTray::ShowHideTime() 4363cf2d117SJohn Scipione { 4373cf2d117SJohn Scipione if (fTime == NULL) 4383cf2d117SJohn Scipione return; 4393cf2d117SJohn Scipione 4402a5c1f12SJohn Scipione // Check from the point of view of fTime because we need to ignore 4412a5c1f12SJohn Scipione // whether or not the parent window is hidden. 4422a5c1f12SJohn Scipione if (fTime->IsHidden(fTime)) 4433cf2d117SJohn Scipione fTime->Show(); 4443cf2d117SJohn Scipione else 4453cf2d117SJohn Scipione fTime->Hide(); 4463cf2d117SJohn Scipione 4473cf2d117SJohn Scipione RealignReplicants(); 4483cf2d117SJohn Scipione AdjustPlacement(); 44931c0024dSJohn Scipione 4502a5c1f12SJohn Scipione // Check from the point of view of fTime ignoring parent's state. 4512a5c1f12SJohn Scipione bool showClock = !fTime->IsHidden(fTime); 4523722e640SJohn Scipione 4533722e640SJohn Scipione // Update showClock setting that gets saved to disk on quit 4541bb2e623SJohn Scipione static_cast<TBarApp*>(be_app)->Settings()->showClock = showClock; 4553722e640SJohn Scipione 4563722e640SJohn Scipione // Send a message to Time preferences telling it to update 45731c0024dSJohn Scipione BMessenger messenger("application/x-vnd.Haiku-Time"); 4580fc30d89SDario Casalinuovo BMessage message(kShowHideTime); 4590fc30d89SDario Casalinuovo message.AddBool("showClock", showClock); 4600fc30d89SDario Casalinuovo messenger.SendMessage(&message); 4613cf2d117SJohn Scipione } 4623cf2d117SJohn Scipione 4633cf2d117SJohn Scipione 46441281cf3SAxel Dörfler #ifdef DB_ADDONS 46541281cf3SAxel Dörfler 4663cf2d117SJohn Scipione 46741281cf3SAxel Dörfler void 46841281cf3SAxel Dörfler TReplicantTray::InitAddOnSupport() 46941281cf3SAxel Dörfler { 47041281cf3SAxel Dörfler // list to maintain refs to each rep added/deleted 47141281cf3SAxel Dörfler fItemList = new BList(); 47241281cf3SAxel Dörfler BPath path; 4731ad8c760SFredrik Holmqvist 47426ea7066SIngo Weinhold if (GetDeskbarSettingsDirectory(path, true) == B_OK) { 4753e6ff860SRene Gollent path.Append(kReplicantSettingsFile); 47641281cf3SAxel Dörfler 47741281cf3SAxel Dörfler BFile file(path.Path(), B_READ_ONLY); 4783e6ff860SRene Gollent if (file.InitCheck() == B_OK) { 4793e6ff860SRene Gollent status_t result; 4803e6ff860SRene Gollent BEntry entry; 4813e6ff860SRene Gollent int32 id; 482c0ad1c91SRene Gollent BString path; 4833e6ff860SRene Gollent if (fAddOnSettings.Unflatten(&file) == B_OK) { 484c0ad1c91SRene Gollent for (int32 i = 0; fAddOnSettings.FindString(kReplicantPathField, 485c0ad1c91SRene Gollent i, &path) == B_OK; i++) { 486c0ad1c91SRene Gollent if (entry.SetTo(path.String()) == B_OK && entry.Exists()) { 4873e6ff860SRene Gollent result = LoadAddOn(&entry, &id, false); 4883e6ff860SRene Gollent } else 4893e6ff860SRene Gollent result = B_ENTRY_NOT_FOUND; 49041281cf3SAxel Dörfler 4913e6ff860SRene Gollent if (result != B_OK) { 492c0ad1c91SRene Gollent fAddOnSettings.RemoveData(kReplicantPathField, i); 4933e6ff860SRene Gollent --i; 49441281cf3SAxel Dörfler } 49541281cf3SAxel Dörfler } 49641281cf3SAxel Dörfler } 4973e6ff860SRene Gollent } 4983e6ff860SRene Gollent } 49941281cf3SAxel Dörfler } 50041281cf3SAxel Dörfler 50141281cf3SAxel Dörfler 50241281cf3SAxel Dörfler void 50341281cf3SAxel Dörfler TReplicantTray::DeleteAddOnSupport() 50441281cf3SAxel Dörfler { 5057625ce51SRene Gollent _SaveSettings(); 5063e6ff860SRene Gollent 5079f2cce2fSJohn Scipione for (int32 i = fItemList->CountItems() - 1; i >= 0; i--) { 50841281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->RemoveItem(i); 50941281cf3SAxel Dörfler if (item) { 51041281cf3SAxel Dörfler if (item->isAddOn) 51141281cf3SAxel Dörfler watch_node(&(item->nodeRef), B_STOP_WATCHING, this, Window()); 51241281cf3SAxel Dörfler 51341281cf3SAxel Dörfler delete item; 51441281cf3SAxel Dörfler } 51541281cf3SAxel Dörfler } 51641281cf3SAxel Dörfler delete fItemList; 51741281cf3SAxel Dörfler 51841281cf3SAxel Dörfler // stop the volume mount/unmount watch 51941281cf3SAxel Dörfler stop_watching(this, Window()); 52041281cf3SAxel Dörfler } 52141281cf3SAxel Dörfler 52241281cf3SAxel Dörfler 52341281cf3SAxel Dörfler DeskbarItemInfo* 52441281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(node_ref& nodeRef) 52541281cf3SAxel Dörfler { 5269f2cce2fSJohn Scipione for (int32 i = fItemList->CountItems() - 1; i >= 0; i--) { 52766eba86fSAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 52841281cf3SAxel Dörfler if (item == NULL) 52941281cf3SAxel Dörfler continue; 53041281cf3SAxel Dörfler 53141281cf3SAxel Dörfler if (item->nodeRef == nodeRef) 53241281cf3SAxel Dörfler return item; 53341281cf3SAxel Dörfler } 53441281cf3SAxel Dörfler 53541281cf3SAxel Dörfler return NULL; 53641281cf3SAxel Dörfler } 53741281cf3SAxel Dörfler 53841281cf3SAxel Dörfler 53941281cf3SAxel Dörfler DeskbarItemInfo* 54041281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(int32 id) 54141281cf3SAxel Dörfler { 5429f2cce2fSJohn Scipione for (int32 i = fItemList->CountItems() - 1; i >= 0; i--) { 54366eba86fSAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 54441281cf3SAxel Dörfler if (item == NULL) 54541281cf3SAxel Dörfler continue; 54641281cf3SAxel Dörfler 54741281cf3SAxel Dörfler if (item->id == id) 54841281cf3SAxel Dörfler return item; 54941281cf3SAxel Dörfler } 55041281cf3SAxel Dörfler 55141281cf3SAxel Dörfler return NULL; 55241281cf3SAxel Dörfler } 55341281cf3SAxel Dörfler 55441281cf3SAxel Dörfler 55541281cf3SAxel Dörfler bool 55641281cf3SAxel Dörfler TReplicantTray::NodeExists(node_ref& nodeRef) 55741281cf3SAxel Dörfler { 55841281cf3SAxel Dörfler return DeskbarItemFor(nodeRef) != NULL; 55941281cf3SAxel Dörfler } 56041281cf3SAxel Dörfler 56141281cf3SAxel Dörfler 56266eba86fSAxel Dörfler /*! This handles B_NODE_MONITOR & B_QUERY_UPDATE messages received 56366eba86fSAxel Dörfler for the registered add-ons. 56441281cf3SAxel Dörfler */ 56541281cf3SAxel Dörfler void 56641281cf3SAxel Dörfler TReplicantTray::HandleEntryUpdate(BMessage* message) 56741281cf3SAxel Dörfler { 56841281cf3SAxel Dörfler int32 opcode; 56941281cf3SAxel Dörfler if (message->FindInt32("opcode", &opcode) != B_OK) 57041281cf3SAxel Dörfler return; 57141281cf3SAxel Dörfler 57241281cf3SAxel Dörfler BPath path; 57341281cf3SAxel Dörfler switch (opcode) { 57441281cf3SAxel Dörfler case B_ENTRY_MOVED: 57541281cf3SAxel Dörfler { 57641281cf3SAxel Dörfler entry_ref ref; 57741281cf3SAxel Dörfler ino_t todirectory; 57841281cf3SAxel Dörfler ino_t node; 57941281cf3SAxel Dörfler const char* name; 58041281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK 58171bd3ba5SJonas Sundström && message->FindInt64("from directory", &(ref.directory)) 58271bd3ba5SJonas Sundström == B_OK 58341281cf3SAxel Dörfler && message->FindInt64("to directory", &todirectory) == B_OK 58441281cf3SAxel Dörfler && message->FindInt32("device", &(ref.device)) == B_OK 58541281cf3SAxel Dörfler && message->FindInt64("node", &node) == B_OK ) { 58641281cf3SAxel Dörfler 587e4d65fe7SJohn Scipione if (name == NULL) 58841281cf3SAxel Dörfler break; 58941281cf3SAxel Dörfler 59041281cf3SAxel Dörfler ref.set_name(name); 59141281cf3SAxel Dörfler // change the directory reference to 59241281cf3SAxel Dörfler // the new directory 59341281cf3SAxel Dörfler MoveItem(&ref, todirectory); 59441281cf3SAxel Dörfler } 59541281cf3SAxel Dörfler break; 59666eba86fSAxel Dörfler } 59741281cf3SAxel Dörfler 59841281cf3SAxel Dörfler case B_ENTRY_REMOVED: 59941281cf3SAxel Dörfler { 60041281cf3SAxel Dörfler // entry was rm'd from the device 60141281cf3SAxel Dörfler node_ref nodeRef; 60241281cf3SAxel Dörfler if (message->FindInt32("device", &(nodeRef.device)) == B_OK 60341281cf3SAxel Dörfler && message->FindInt64("node", &(nodeRef.node)) == B_OK) { 60441281cf3SAxel Dörfler DeskbarItemInfo* item = DeskbarItemFor(nodeRef); 60541281cf3SAxel Dörfler if (item == NULL) 60641281cf3SAxel Dörfler break; 60741281cf3SAxel Dörfler 60841281cf3SAxel Dörfler // If there is a team running where the add-on comes from, 60941281cf3SAxel Dörfler // we don't want to remove the icon yet. 61041281cf3SAxel Dörfler if (be_roster->IsRunning(&item->entryRef)) 61141281cf3SAxel Dörfler break; 61241281cf3SAxel Dörfler 61341281cf3SAxel Dörfler UnloadAddOn(&nodeRef, NULL, true, false); 61441281cf3SAxel Dörfler } 61541281cf3SAxel Dörfler break; 61666eba86fSAxel Dörfler } 61741281cf3SAxel Dörfler } 61866eba86fSAxel Dörfler } 61941281cf3SAxel Dörfler 62041281cf3SAxel Dörfler 6211ad8c760SFredrik Holmqvist /*! The add-ons must support the exported C function API 62266eba86fSAxel Dörfler if they do, they will be loaded and added to deskbar 62366eba86fSAxel Dörfler primary function is the Instantiate function 6247da06231SAxel Dörfler */ 62541281cf3SAxel Dörfler status_t 6263e6ff860SRene Gollent TReplicantTray::LoadAddOn(BEntry* entry, int32* id, bool addToSettings) 62741281cf3SAxel Dörfler { 628e4d65fe7SJohn Scipione if (entry == NULL) 629a6be6c4dSJohn Scipione return B_BAD_VALUE; 63041281cf3SAxel Dörfler 63141281cf3SAxel Dörfler node_ref nodeRef; 63241281cf3SAxel Dörfler entry->GetNodeRef(&nodeRef); 63341281cf3SAxel Dörfler // no duplicates 63441281cf3SAxel Dörfler if (NodeExists(nodeRef)) 63541281cf3SAxel Dörfler return B_ERROR; 63641281cf3SAxel Dörfler 63741281cf3SAxel Dörfler BNode node(entry); 63841281cf3SAxel Dörfler BPath path; 63966eba86fSAxel Dörfler status_t status = entry->GetPath(&path); 640e4d65fe7SJohn Scipione if (status != B_OK) 64166eba86fSAxel Dörfler return status; 64241281cf3SAxel Dörfler 64341281cf3SAxel Dörfler // load the add-on 64441281cf3SAxel Dörfler image_id image = load_add_on(path.Path()); 64566eba86fSAxel Dörfler if (image < B_OK) 64666eba86fSAxel Dörfler return image; 64741281cf3SAxel Dörfler 64841281cf3SAxel Dörfler // get the view loading function symbol 64941281cf3SAxel Dörfler // we first look for a symbol that takes an image_id 65041281cf3SAxel Dörfler // and entry_ref pointer, if not found, go with normal 65141281cf3SAxel Dörfler // instantiate function 652efafab64SAxel Dörfler BView* (*entryFunction)(image_id, const entry_ref*, float, float); 653efafab64SAxel Dörfler BView* (*itemFunction)(float, float); 65441281cf3SAxel Dörfler BView* view = NULL; 65541281cf3SAxel Dörfler 65641281cf3SAxel Dörfler entry_ref ref; 65741281cf3SAxel Dörfler entry->GetRef(&ref); 65841281cf3SAxel Dörfler 65941281cf3SAxel Dörfler if (get_image_symbol(image, kInstantiateEntryCFunctionName, 66066eba86fSAxel Dörfler B_SYMBOL_TYPE_TEXT, (void**)&entryFunction) >= B_OK) { 661efafab64SAxel Dörfler view = (*entryFunction)(image, &ref, fMaxReplicantWidth, 662efafab64SAxel Dörfler fMaxReplicantHeight); 66341281cf3SAxel Dörfler } else if (get_image_symbol(image, kInstantiateItemCFunctionName, 66466eba86fSAxel Dörfler B_SYMBOL_TYPE_TEXT, (void**)&itemFunction) >= B_OK) { 665efafab64SAxel Dörfler view = (*itemFunction)(fMaxReplicantWidth, fMaxReplicantHeight); 66641281cf3SAxel Dörfler } else { 66741281cf3SAxel Dörfler unload_add_on(image); 66841281cf3SAxel Dörfler return B_ERROR; 66941281cf3SAxel Dörfler } 67041281cf3SAxel Dörfler 67166eba86fSAxel Dörfler if (view == NULL || IconExists(view->Name())) { 67241281cf3SAxel Dörfler delete view; 67341281cf3SAxel Dörfler unload_add_on(image); 67441281cf3SAxel Dörfler return B_ERROR; 67541281cf3SAxel Dörfler } 67641281cf3SAxel Dörfler 67741281cf3SAxel Dörfler BMessage* data = new BMessage; 67841281cf3SAxel Dörfler view->Archive(data); 67941281cf3SAxel Dörfler delete view; 68041281cf3SAxel Dörfler 68141281cf3SAxel Dörfler // add the rep; adds info to list 6820fc30d89SDario Casalinuovo if (AddIcon(data, id, &ref) != B_OK) 6830fc30d89SDario Casalinuovo delete data; 68441281cf3SAxel Dörfler 6853e6ff860SRene Gollent if (addToSettings) { 686c0ad1c91SRene Gollent fAddOnSettings.AddString(kReplicantPathField, path.Path()); 6877625ce51SRene Gollent _SaveSettings(); 6883e6ff860SRene Gollent } 68941281cf3SAxel Dörfler 69041281cf3SAxel Dörfler return B_OK; 69141281cf3SAxel Dörfler } 69241281cf3SAxel Dörfler 69341281cf3SAxel Dörfler 69441281cf3SAxel Dörfler status_t 69541281cf3SAxel Dörfler TReplicantTray::AddItem(int32 id, node_ref nodeRef, BEntry& entry, bool isAddOn) 69641281cf3SAxel Dörfler { 69741281cf3SAxel Dörfler DeskbarItemInfo* item = new DeskbarItemInfo; 69841281cf3SAxel Dörfler if (item == NULL) 69941281cf3SAxel Dörfler return B_NO_MEMORY; 70041281cf3SAxel Dörfler 70141281cf3SAxel Dörfler item->id = id; 70241281cf3SAxel Dörfler item->isAddOn = isAddOn; 70341281cf3SAxel Dörfler 704e4d65fe7SJohn Scipione if (entry.GetRef(&item->entryRef) != B_OK) { 70541281cf3SAxel Dörfler item->entryRef.device = -1; 70641281cf3SAxel Dörfler item->entryRef.directory = -1; 70741281cf3SAxel Dörfler item->entryRef.name = NULL; 70841281cf3SAxel Dörfler } 70941281cf3SAxel Dörfler item->nodeRef = nodeRef; 71041281cf3SAxel Dörfler 71141281cf3SAxel Dörfler fItemList->AddItem(item); 71241281cf3SAxel Dörfler 71341281cf3SAxel Dörfler if (isAddOn) 71441281cf3SAxel Dörfler watch_node(&nodeRef, B_WATCH_NAME | B_WATCH_ATTR, this, Window()); 71541281cf3SAxel Dörfler 71641281cf3SAxel Dörfler return B_OK; 71741281cf3SAxel Dörfler } 71841281cf3SAxel Dörfler 71941281cf3SAxel Dörfler 72041281cf3SAxel Dörfler /** from entry_removed message, when attribute removed 72141281cf3SAxel Dörfler * or when a device is unmounted (use removeall, by device) 72241281cf3SAxel Dörfler */ 72341281cf3SAxel Dörfler 72441281cf3SAxel Dörfler void 725e4d65fe7SJohn Scipione TReplicantTray::UnloadAddOn(node_ref* nodeRef, dev_t* device, bool which, 726e4d65fe7SJohn Scipione bool removeAll) 72741281cf3SAxel Dörfler { 7289f2cce2fSJohn Scipione for (int32 i = fItemList->CountItems() - 1; i >= 0; i--) { 72941281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 730e4d65fe7SJohn Scipione if (item == NULL) 73141281cf3SAxel Dörfler continue; 73241281cf3SAxel Dörfler 733e4d65fe7SJohn Scipione if ((which && nodeRef != NULL && item->nodeRef == *nodeRef) 734e4d65fe7SJohn Scipione || (device != NULL && item->nodeRef.device == *device)) { 73541281cf3SAxel Dörfler 736e4d65fe7SJohn Scipione if (device != NULL && be_roster->IsRunning(&item->entryRef)) 73741281cf3SAxel Dörfler continue; 73841281cf3SAxel Dörfler 73941281cf3SAxel Dörfler RemoveIcon(item->id); 74041281cf3SAxel Dörfler 74141281cf3SAxel Dörfler if (!removeAll) 74241281cf3SAxel Dörfler break; 74341281cf3SAxel Dörfler } 74441281cf3SAxel Dörfler } 74541281cf3SAxel Dörfler } 74641281cf3SAxel Dörfler 74741281cf3SAxel Dörfler 74841281cf3SAxel Dörfler void 74941281cf3SAxel Dörfler TReplicantTray::RemoveItem(int32 id) 75041281cf3SAxel Dörfler { 75141281cf3SAxel Dörfler DeskbarItemInfo* item = DeskbarItemFor(id); 75241281cf3SAxel Dörfler if (item == NULL) 75341281cf3SAxel Dörfler return; 75441281cf3SAxel Dörfler 75541281cf3SAxel Dörfler // attribute was added via Deskbar API (AddItem(entry_ref*, int32*) 75641281cf3SAxel Dörfler if (item->isAddOn) { 7577625ce51SRene Gollent BPath path(&item->entryRef); 7587625ce51SRene Gollent BString storedPath; 7597625ce51SRene Gollent for (int32 i = 0; 7608aab28f1SRene Gollent fAddOnSettings.FindString(kReplicantPathField, i, &storedPath) 7617625ce51SRene Gollent == B_OK; i++) { 7627625ce51SRene Gollent if (storedPath == path.Path()) { 7638aab28f1SRene Gollent fAddOnSettings.RemoveData(kReplicantPathField, i); 7647625ce51SRene Gollent break; 7657625ce51SRene Gollent } 7667625ce51SRene Gollent } 7677625ce51SRene Gollent _SaveSettings(); 7687625ce51SRene Gollent 76941281cf3SAxel Dörfler BNode node(&item->entryRef); 77041281cf3SAxel Dörfler watch_node(&item->nodeRef, B_STOP_WATCHING, this, Window()); 77141281cf3SAxel Dörfler } 77241281cf3SAxel Dörfler 77341281cf3SAxel Dörfler fItemList->RemoveItem(item); 77441281cf3SAxel Dörfler delete item; 77541281cf3SAxel Dörfler } 77641281cf3SAxel Dörfler 77741281cf3SAxel Dörfler 77841281cf3SAxel Dörfler /** ENTRY_MOVED message, moving only occurs on a device 77941281cf3SAxel Dörfler * copying will occur (ENTRY_CREATED) between devices 78041281cf3SAxel Dörfler */ 78141281cf3SAxel Dörfler 78241281cf3SAxel Dörfler void 78341281cf3SAxel Dörfler TReplicantTray::MoveItem(entry_ref* ref, ino_t toDirectory) 78441281cf3SAxel Dörfler { 785e4d65fe7SJohn Scipione if (ref == NULL) 78641281cf3SAxel Dörfler return; 78741281cf3SAxel Dörfler 78841281cf3SAxel Dörfler // scan for a matching entry_ref and update it 78941281cf3SAxel Dörfler // 79041281cf3SAxel Dörfler // don't need to change node info as it does not change 79141281cf3SAxel Dörfler 7929f2cce2fSJohn Scipione for (int32 i = fItemList->CountItems() - 1; i >= 0; i--) { 79341281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 794e4d65fe7SJohn Scipione if (item == NULL) 79541281cf3SAxel Dörfler continue; 79641281cf3SAxel Dörfler 797e4d65fe7SJohn Scipione if (strcmp(item->entryRef.name, ref->name) == 0 79841281cf3SAxel Dörfler && item->entryRef.device == ref->device 79941281cf3SAxel Dörfler && item->entryRef.directory == ref->directory) { 80041281cf3SAxel Dörfler item->entryRef.directory = toDirectory; 80141281cf3SAxel Dörfler break; 80241281cf3SAxel Dörfler } 80341281cf3SAxel Dörfler } 80441281cf3SAxel Dörfler } 80541281cf3SAxel Dörfler 80641281cf3SAxel Dörfler #endif // add-on support 80741281cf3SAxel Dörfler 80841281cf3SAxel Dörfler // external add-on API routines 80941281cf3SAxel Dörfler // called using the new BDeskbar class 81041281cf3SAxel Dörfler 81141281cf3SAxel Dörfler // existence of icon/replicant by name or ID 81241281cf3SAxel Dörfler // returns opposite 81341281cf3SAxel Dörfler // note: name and id are semi-private limiting 81441281cf3SAxel Dörfler // the ability of non-host apps to remove 81541281cf3SAxel Dörfler // icons without a little bit of work 81641281cf3SAxel Dörfler 81741281cf3SAxel Dörfler /** for a specific id 81841281cf3SAxel Dörfler * return the name of the replicant (name of view) 81941281cf3SAxel Dörfler */ 82041281cf3SAxel Dörfler 82141281cf3SAxel Dörfler status_t 82241281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 id, const char** name) 82341281cf3SAxel Dörfler { 82441281cf3SAxel Dörfler if (id < 0) 825a6be6c4dSJohn Scipione return B_BAD_VALUE; 82641281cf3SAxel Dörfler 827e4d65fe7SJohn Scipione int32 index; 828e4d65fe7SJohn Scipione int32 temp; 82941281cf3SAxel Dörfler BView* view = ViewAt(&index, &temp, id, false); 830e4d65fe7SJohn Scipione if (view != NULL) { 83141281cf3SAxel Dörfler *name = view->Name(); 83241281cf3SAxel Dörfler return B_OK; 83341281cf3SAxel Dörfler } 83441281cf3SAxel Dörfler 83541281cf3SAxel Dörfler return B_ERROR; 83641281cf3SAxel Dörfler } 83741281cf3SAxel Dörfler 83841281cf3SAxel Dörfler 8397da06231SAxel Dörfler /** for a specific name 8407da06231SAxel Dörfler * return the id (internal to Deskbar) 8417da06231SAxel Dörfler */ 8427da06231SAxel Dörfler 84341281cf3SAxel Dörfler status_t 84441281cf3SAxel Dörfler TReplicantTray::ItemInfo(const char* name, int32* id) 84541281cf3SAxel Dörfler { 846e4d65fe7SJohn Scipione if (name == NULL || *name == '\0') 847a6be6c4dSJohn Scipione return B_BAD_VALUE; 84841281cf3SAxel Dörfler 84941281cf3SAxel Dörfler int32 index; 85041281cf3SAxel Dörfler BView* view = ViewAt(&index, id, name); 85141281cf3SAxel Dörfler 852378aa08bSJohn Scipione return view != NULL ? B_OK : B_ERROR; 85341281cf3SAxel Dörfler } 85441281cf3SAxel Dörfler 85541281cf3SAxel Dörfler 8567da06231SAxel Dörfler /** at a specific index 8577da06231SAxel Dörfler * return both the name and the id of the replicant 8587da06231SAxel Dörfler */ 8597da06231SAxel Dörfler 86041281cf3SAxel Dörfler status_t 86141281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 index, const char** name, int32* id) 86241281cf3SAxel Dörfler { 86341281cf3SAxel Dörfler if (index < 0) 864a6be6c4dSJohn Scipione return B_BAD_VALUE; 86541281cf3SAxel Dörfler 86641281cf3SAxel Dörfler BView* view; 86741281cf3SAxel Dörfler fShelf->ReplicantAt(index, &view, (uint32*)id, NULL); 868e4d65fe7SJohn Scipione if (view != NULL) { 86941281cf3SAxel Dörfler *name = view->Name(); 87041281cf3SAxel Dörfler return B_OK; 87141281cf3SAxel Dörfler } 87241281cf3SAxel Dörfler 87341281cf3SAxel Dörfler return B_ERROR; 87441281cf3SAxel Dörfler } 87541281cf3SAxel Dörfler 87641281cf3SAxel Dörfler 8777da06231SAxel Dörfler /** replicant exists, by id/index */ 8787da06231SAxel Dörfler 87941281cf3SAxel Dörfler bool 88041281cf3SAxel Dörfler TReplicantTray::IconExists(int32 target, bool byIndex) 88141281cf3SAxel Dörfler { 882e4d65fe7SJohn Scipione int32 index; 883e4d65fe7SJohn Scipione int32 id; 88441281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 88541281cf3SAxel Dörfler 88641281cf3SAxel Dörfler return view && index >= 0; 88741281cf3SAxel Dörfler } 88841281cf3SAxel Dörfler 88941281cf3SAxel Dörfler 8907da06231SAxel Dörfler /** replicant exists, by name */ 8917da06231SAxel Dörfler 89241281cf3SAxel Dörfler bool 89341281cf3SAxel Dörfler TReplicantTray::IconExists(const char* name) 89441281cf3SAxel Dörfler { 895e4d65fe7SJohn Scipione if (name == NULL || *name == '\0') 89641281cf3SAxel Dörfler return false; 89741281cf3SAxel Dörfler 898e4d65fe7SJohn Scipione int32 index; 899e4d65fe7SJohn Scipione int32 id; 90041281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 90141281cf3SAxel Dörfler 902e4d65fe7SJohn Scipione return view != NULL && index >= 0; 90341281cf3SAxel Dörfler } 90441281cf3SAxel Dörfler 90541281cf3SAxel Dörfler 90641281cf3SAxel Dörfler int32 90732b0035aSJohn Scipione TReplicantTray::ReplicantCount() const 90841281cf3SAxel Dörfler { 90941281cf3SAxel Dörfler return fShelf->CountReplicants(); 91041281cf3SAxel Dörfler } 91141281cf3SAxel Dörfler 91241281cf3SAxel Dörfler 913ced3755cSAxel Dörfler /*! Message must contain an archivable view for later rehydration. 914ced3755cSAxel Dörfler This function takes over ownership of the provided message on success 915ced3755cSAxel Dörfler only. 916ced3755cSAxel Dörfler Returns the current replicant ID. 9177da06231SAxel Dörfler */ 91841281cf3SAxel Dörfler status_t 919ced3755cSAxel Dörfler TReplicantTray::AddIcon(BMessage* archive, int32* id, const entry_ref* addOn) 92041281cf3SAxel Dörfler { 921ced3755cSAxel Dörfler if (archive == NULL || id == NULL) 922a6be6c4dSJohn Scipione return B_BAD_VALUE; 92341281cf3SAxel Dörfler 9249c50f36eSAxel Dörfler // find entry_ref 9259c50f36eSAxel Dörfler 9269c50f36eSAxel Dörfler entry_ref ref; 927e4d65fe7SJohn Scipione if (addOn != NULL) { 9289c50f36eSAxel Dörfler // Use it if we got it 9299c50f36eSAxel Dörfler ref = *addOn; 9309c50f36eSAxel Dörfler } else { 9319c50f36eSAxel Dörfler const char* signature; 9321ad8c760SFredrik Holmqvist 933ced3755cSAxel Dörfler status_t status = archive->FindString("add_on", &signature); 9349c50f36eSAxel Dörfler if (status == B_OK) { 9359c50f36eSAxel Dörfler BRoster roster; 9369c50f36eSAxel Dörfler status = roster.FindApp(signature, &ref); 9379c50f36eSAxel Dörfler } 938e4d65fe7SJohn Scipione if (status != B_OK) 9399c50f36eSAxel Dörfler return status; 9409c50f36eSAxel Dörfler } 9419c50f36eSAxel Dörfler 9429c50f36eSAxel Dörfler BFile file; 9439c50f36eSAxel Dörfler status_t status = file.SetTo(&ref, B_READ_ONLY); 944e4d65fe7SJohn Scipione if (status != B_OK) 9459c50f36eSAxel Dörfler return status; 9469c50f36eSAxel Dörfler 9479c50f36eSAxel Dörfler node_ref nodeRef; 9489c50f36eSAxel Dörfler status = file.GetNodeRef(&nodeRef); 949e4d65fe7SJohn Scipione if (status != B_OK) 9509c50f36eSAxel Dörfler return status; 9519c50f36eSAxel Dörfler 9529c50f36eSAxel Dörfler BEntry entry(&ref, true); 9531ad8c760SFredrik Holmqvist // TODO: this resolves an eventual link for the item being added - this 9541ad8c760SFredrik Holmqvist // is okay for now, but in multi-user environments, one might want to 9551ad8c760SFredrik Holmqvist // have links that carry the be:deskbar_item_status attribute 9569c50f36eSAxel Dörfler status = entry.InitCheck(); 9579c50f36eSAxel Dörfler if (status != B_OK) 9589c50f36eSAxel Dörfler return status; 9599c50f36eSAxel Dörfler 96041281cf3SAxel Dörfler *id = 999; 961ced3755cSAxel Dörfler if (archive->what == B_ARCHIVED_OBJECT) 962ced3755cSAxel Dörfler archive->what = 0; 96341281cf3SAxel Dörfler 964ced3755cSAxel Dörfler BRect originalBounds = archive->FindRect("_frame"); 9651ad8c760SFredrik Holmqvist // this is a work-around for buggy replicants that change their size in 9661ad8c760SFredrik Holmqvist // AttachedToWindow() (such as "SVM") 967a5210ab1SAxel Dörfler 9681ad8c760SFredrik Holmqvist // TODO: check for name collisions? 969ced3755cSAxel Dörfler status = fShelf->AddReplicant(archive, BPoint(1, 1)); 9709c50f36eSAxel Dörfler if (status != B_OK) 9719c50f36eSAxel Dörfler return status; 97241281cf3SAxel Dörfler 97332b0035aSJohn Scipione int32 count = ReplicantCount(); 974a5210ab1SAxel Dörfler BView* view; 975a5210ab1SAxel Dörfler fShelf->ReplicantAt(count - 1, &view, (uint32*)id, NULL); 976a5210ab1SAxel Dörfler 977a6be6c4dSJohn Scipione if (view != NULL && originalBounds != view->Bounds()) { 978a5210ab1SAxel Dörfler // The replicant changed its size when added to the window, so we need 97971bd3ba5SJonas Sundström // to recompute all over again (it's already done once via 98071bd3ba5SJonas Sundström // BShelf::AddReplicant() and TReplicantShelf::CanAcceptReplicantView()) 981a5210ab1SAxel Dörfler RealignReplicants(); 982a5210ab1SAxel Dörfler } 983a5210ab1SAxel Dörfler 98441281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 98541281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 98641281cf3SAxel Dörfler float width, height; 98741281cf3SAxel Dörfler GetPreferredSize(&width, &height); 98841281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) 98941281cf3SAxel Dörfler AdjustPlacement(); 99041281cf3SAxel Dörfler 99141281cf3SAxel Dörfler // add the item to the add-on list 99241281cf3SAxel Dörfler 99341281cf3SAxel Dörfler AddItem(*id, nodeRef, entry, addOn != NULL); 99441281cf3SAxel Dörfler return B_OK; 99541281cf3SAxel Dörfler } 99641281cf3SAxel Dörfler 99741281cf3SAxel Dörfler 99841281cf3SAxel Dörfler void 99941281cf3SAxel Dörfler TReplicantTray::RemoveIcon(int32 target, bool byIndex) 100041281cf3SAxel Dörfler { 100141281cf3SAxel Dörfler if (target < 0) 100241281cf3SAxel Dörfler return; 100341281cf3SAxel Dörfler 1004e4d65fe7SJohn Scipione int32 index; 1005e4d65fe7SJohn Scipione int32 id; 100641281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 1007e4d65fe7SJohn Scipione if (view != NULL && index >= 0) { 10087da06231SAxel Dörfler // remove the reference from the item list & the shelf 100941281cf3SAxel Dörfler RemoveItem(id); 101041281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 10117da06231SAxel Dörfler 101241281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 101341281cf3SAxel Dörfler RealReplicantAdjustment(index); 101441281cf3SAxel Dörfler } 101541281cf3SAxel Dörfler } 101641281cf3SAxel Dörfler 101741281cf3SAxel Dörfler 101841281cf3SAxel Dörfler void 101941281cf3SAxel Dörfler TReplicantTray::RemoveIcon(const char* name) 102041281cf3SAxel Dörfler { 1021e4d65fe7SJohn Scipione if (name == NULL || *name == '\0') 102241281cf3SAxel Dörfler return; 102341281cf3SAxel Dörfler 1024378aa08bSJohn Scipione int32 index; 1025378aa08bSJohn Scipione int32 id; 102641281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 1027e4d65fe7SJohn Scipione if (view != NULL && index >= 0) { 10287da06231SAxel Dörfler // remove the reference from the item list & shelf 102941281cf3SAxel Dörfler RemoveItem(id); 103041281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 10317da06231SAxel Dörfler 103241281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 103341281cf3SAxel Dörfler RealReplicantAdjustment(index); 103441281cf3SAxel Dörfler } 103541281cf3SAxel Dörfler } 103641281cf3SAxel Dörfler 103741281cf3SAxel Dörfler 103841281cf3SAxel Dörfler void 10397da06231SAxel Dörfler TReplicantTray::RealReplicantAdjustment(int32 startIndex) 104041281cf3SAxel Dörfler { 10417da06231SAxel Dörfler if (startIndex < 0) 104241281cf3SAxel Dörfler return; 10437da06231SAxel Dörfler 10447da06231SAxel Dörfler if (startIndex == fLastReplicant) 10457da06231SAxel Dörfler startIndex = 0; 10467da06231SAxel Dörfler 104741281cf3SAxel Dörfler // reset the locations of all replicants after the one deleted 10487da06231SAxel Dörfler RealignReplicants(startIndex); 104941281cf3SAxel Dörfler 105041281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 105141281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 105241281cf3SAxel Dörfler float width, height; 105341281cf3SAxel Dörfler GetPreferredSize(&width, &height); 105441281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) { 10551ad8c760SFredrik Holmqvist // resize view to accomodate the replicants, redraw as necessary 105641281cf3SAxel Dörfler AdjustPlacement(); 105741281cf3SAxel Dörfler } 105841281cf3SAxel Dörfler } 105941281cf3SAxel Dörfler 106041281cf3SAxel Dörfler 10617da06231SAxel Dörfler /** looking for a replicant by id/index 10627da06231SAxel Dörfler * return the view and index 10637da06231SAxel Dörfler */ 10647da06231SAxel Dörfler 106541281cf3SAxel Dörfler BView* 106641281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, int32 target, bool byIndex) 106741281cf3SAxel Dörfler { 106841281cf3SAxel Dörfler *index = -1; 106941281cf3SAxel Dörfler 107041281cf3SAxel Dörfler BView* view; 107141281cf3SAxel Dörfler if (byIndex) { 107241281cf3SAxel Dörfler if (fShelf->ReplicantAt(target, &view, (uint32*)id)) { 1073e4d65fe7SJohn Scipione if (view != NULL) { 107441281cf3SAxel Dörfler *index = target; 1075e4d65fe7SJohn Scipione 107641281cf3SAxel Dörfler return view; 107741281cf3SAxel Dörfler } 107841281cf3SAxel Dörfler } 107941281cf3SAxel Dörfler } else { 108032b0035aSJohn Scipione int32 count = ReplicantCount() - 1; 108141281cf3SAxel Dörfler int32 localid; 108241281cf3SAxel Dörfler for (int32 repIndex = count; repIndex >= 0; repIndex--) { 108341281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32*)&localid); 1084e4d65fe7SJohn Scipione if (localid == target && view != NULL) { 108541281cf3SAxel Dörfler *index = repIndex; 108641281cf3SAxel Dörfler *id = localid; 1087e4d65fe7SJohn Scipione 108841281cf3SAxel Dörfler return view; 108941281cf3SAxel Dörfler } 109041281cf3SAxel Dörfler } 109141281cf3SAxel Dörfler } 1092e4d65fe7SJohn Scipione 109341281cf3SAxel Dörfler return NULL; 109441281cf3SAxel Dörfler } 109541281cf3SAxel Dörfler 109641281cf3SAxel Dörfler 10977da06231SAxel Dörfler /** looking for a replicant with a view by name 10987da06231SAxel Dörfler * return the view, index and the id of the replicant 10997da06231SAxel Dörfler */ 11007da06231SAxel Dörfler 110141281cf3SAxel Dörfler BView* 110241281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, const char* name) 110341281cf3SAxel Dörfler { 110441281cf3SAxel Dörfler *index = -1; 110541281cf3SAxel Dörfler *id = -1; 110641281cf3SAxel Dörfler 110741281cf3SAxel Dörfler BView* view; 110832b0035aSJohn Scipione int32 count = ReplicantCount() - 1; 110941281cf3SAxel Dörfler for (int32 repIndex = count; repIndex >= 0; repIndex--) { 111041281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32*)id); 11113641948fSJohn Scipione if (view != NULL && view->Name() != NULL 1112e4d65fe7SJohn Scipione && strcmp(name, view->Name()) == 0) { 111341281cf3SAxel Dörfler *index = repIndex; 1114e4d65fe7SJohn Scipione 111541281cf3SAxel Dörfler return view; 111641281cf3SAxel Dörfler } 111741281cf3SAxel Dörfler } 1118e4d65fe7SJohn Scipione 111941281cf3SAxel Dörfler return NULL; 112041281cf3SAxel Dörfler } 112141281cf3SAxel Dörfler 112241281cf3SAxel Dörfler 11237da06231SAxel Dörfler /** Shelf will call to determine where and if 11247da06231SAxel Dörfler * the replicant is to be added 11257da06231SAxel Dörfler */ 11267da06231SAxel Dörfler 112741281cf3SAxel Dörfler bool 112841281cf3SAxel Dörfler TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage* message) 112941281cf3SAxel Dörfler { 1130e4d65fe7SJohn Scipione if (message == NULL) 113141281cf3SAxel Dörfler return false; 113241281cf3SAxel Dörfler 1133efafab64SAxel Dörfler if (replicantFrame.Height() > fMaxReplicantHeight) 113441281cf3SAxel Dörfler return false; 113541281cf3SAxel Dörfler 113641281cf3SAxel Dörfler alignment align = B_ALIGN_LEFT; 113741281cf3SAxel Dörfler if (fAlignmentSupport && message->HasBool("deskbar:dynamic_align")) { 113841281cf3SAxel Dörfler if (!fBarView->Vertical()) 113941281cf3SAxel Dörfler align = B_ALIGN_RIGHT; 114041281cf3SAxel Dörfler else 114141281cf3SAxel Dörfler align = fBarView->Left() ? B_ALIGN_LEFT : B_ALIGN_RIGHT; 114241281cf3SAxel Dörfler } else if (message->HasInt32("deskbar:align")) 114341281cf3SAxel Dörfler message->FindInt32("deskbar:align", (int32*)&align); 114441281cf3SAxel Dörfler 114541281cf3SAxel Dörfler if (message->HasInt32("deskbar:private_align")) 114641281cf3SAxel Dörfler message->FindInt32("deskbar:private_align", (int32*)&align); 114741281cf3SAxel Dörfler else 114841281cf3SAxel Dörfler align = B_ALIGN_LEFT; 114941281cf3SAxel Dörfler 115032b0035aSJohn Scipione BPoint loc = LocationForReplicant(ReplicantCount(), 11517da06231SAxel Dörfler replicantFrame.Width()); 115241281cf3SAxel Dörfler message->AddPoint("_pjp_loc", loc); 1153e4d65fe7SJohn Scipione 115441281cf3SAxel Dörfler return true; 115541281cf3SAxel Dörfler } 115641281cf3SAxel Dörfler 115741281cf3SAxel Dörfler 115841281cf3SAxel Dörfler /** based on the previous (index - 1) replicant in the list 115941281cf3SAxel Dörfler * calculate where the left point should be for this 116041281cf3SAxel Dörfler * replicant. replicant will flow to the right on its own 116141281cf3SAxel Dörfler */ 116241281cf3SAxel Dörfler 116341281cf3SAxel Dörfler BPoint 116432b0035aSJohn Scipione TReplicantTray::LocationForReplicant(int32 index, float replicantWidth) 116541281cf3SAxel Dörfler { 116670ad5289SJohn Scipione BPoint loc(kTrayPadding, 2); 116770ad5289SJohn Scipione if (fBarView->Vertical()) { 116870ad5289SJohn Scipione if (!fBarView->Left()) 116970ad5289SJohn Scipione loc.x += kDragWidth; // move past dragger 117070ad5289SJohn Scipione } else 117170ad5289SJohn Scipione loc.x += 1; // keeps everything lined up nicely 117241281cf3SAxel Dörfler 11737da06231SAxel Dörfler if (fMultiRowMode) { 11747da06231SAxel Dörfler // try to find free space in every row 1175efafab64SAxel Dörfler for (int32 row = 0; ; loc.y += fMaxReplicantHeight + kIconGap, row++) { 11767da06231SAxel Dörfler // determine free space in this row 1177a44504a1SJohn Scipione BRect rowRect(loc.x, loc.y, 11781bb2e623SJohn Scipione loc.x + static_cast<TBarApp*>(be_app)->Settings()->width 1179015b5dd6SJohn Scipione - (kTrayPadding + kDragWidth + kGutter) * 2, 1180efafab64SAxel Dörfler loc.y + fMaxReplicantHeight); 11811c765f5bSJohn Scipione if (row == 0 && !fTime->IsHidden(fTime)) 1182bc08a7d6SJohn Scipione rowRect.right -= kClockMargin + fTime->Frame().Width(); 11837da06231SAxel Dörfler 1184a44504a1SJohn Scipione BRect replicantRect = rowRect; 11857da06231SAxel Dörfler for (int32 i = 0; i < index; i++) { 11867da06231SAxel Dörfler BView* view = NULL; 11877da06231SAxel Dörfler fShelf->ReplicantAt(i, &view); 1188a44504a1SJohn Scipione if (view == NULL || view->Frame().top != rowRect.top) 11897da06231SAxel Dörfler continue; 11907da06231SAxel Dörfler 1191a44504a1SJohn Scipione // push this replicant placement past the last one 1192a44504a1SJohn Scipione replicantRect.left = view->Frame().right + kIconGap + 1; 11937da06231SAxel Dörfler } 11947da06231SAxel Dörfler 1195*15eb397eSJohn Scipione // calculated left position, add replicantWidth to get the 1196*15eb397eSJohn Scipione // right position 1197bc08a7d6SJohn Scipione replicantRect.right = replicantRect.left + replicantWidth; 1198bc08a7d6SJohn Scipione 1199bc08a7d6SJohn Scipione // check if replicant fits in this row 1200bc08a7d6SJohn Scipione if (replicantRect.right < rowRect.right) { 1201bc08a7d6SJohn Scipione // replicant fits in this row 1202a44504a1SJohn Scipione loc = replicantRect.LeftTop(); 12037da06231SAxel Dörfler break; 12047da06231SAxel Dörfler } 1205bc08a7d6SJohn Scipione 1206bc08a7d6SJohn Scipione // check next row 12077da06231SAxel Dörfler } 1208*15eb397eSJohn Scipione 1209*15eb397eSJohn Scipione fTime->MoveTo(Bounds().right - fTime->Bounds().Width() 1210*15eb397eSJohn Scipione - kTrayPadding, 2); 1211*15eb397eSJohn Scipione } else { 1212*15eb397eSJohn Scipione if (index > 0) { 121341281cf3SAxel Dörfler // get the last replicant added for placement reference 121441281cf3SAxel Dörfler BView* view = NULL; 12157da06231SAxel Dörfler fShelf->ReplicantAt(index - 1, &view); 1216e4d65fe7SJohn Scipione if (view != NULL) { 1217a44504a1SJohn Scipione // push this replicant placement past the last one 121841281cf3SAxel Dörfler loc.x = view->Frame().right + kIconGap + 1; 121941281cf3SAxel Dörfler } 122041281cf3SAxel Dörfler } 122141281cf3SAxel Dörfler 1222*15eb397eSJohn Scipione if (fBarView->Vertical()) { 1223*15eb397eSJohn Scipione // center vertically 1224*15eb397eSJohn Scipione loc.y = floorf((kMenuBarHeight - fMaxReplicantHeight) / 2) - 1; 1225*15eb397eSJohn Scipione } else { 1226*15eb397eSJohn Scipione if (fBarView->Top()) { 1227*15eb397eSJohn Scipione // align top 1228*15eb397eSJohn Scipione loc.y = 3; 1229*15eb397eSJohn Scipione } else { 1230*15eb397eSJohn Scipione // align bottom 1231*15eb397eSJohn Scipione loc.y = fBarView->TeamMenuItemHeight() - fMaxReplicantHeight - 2; 1232*15eb397eSJohn Scipione } 1233*15eb397eSJohn Scipione } 1234*15eb397eSJohn Scipione 1235*15eb397eSJohn Scipione // move time in place next to replicants 1236*15eb397eSJohn Scipione fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - kTrayPadding, 1237*15eb397eSJohn Scipione loc.y + (fMaxReplicantHeight - fTime->Bounds().Height()) / 2); 1238*15eb397eSJohn Scipione } 1239*15eb397eSJohn Scipione 1240e4d65fe7SJohn Scipione if (loc.y > fRightBottomReplicant.top 1241e4d65fe7SJohn Scipione || (loc.y == fRightBottomReplicant.top 1242e4d65fe7SJohn Scipione && loc.x > fRightBottomReplicant.left)) { 1243a44504a1SJohn Scipione fRightBottomReplicant.Set(loc.x, loc.y, loc.x + replicantWidth, 1244efafab64SAxel Dörfler loc.y + fMaxReplicantHeight); 12457da06231SAxel Dörfler fLastReplicant = index; 124641281cf3SAxel Dörfler } 12477da06231SAxel Dörfler 124841281cf3SAxel Dörfler return loc; 124941281cf3SAxel Dörfler } 125041281cf3SAxel Dörfler 125141281cf3SAxel Dörfler 125241281cf3SAxel Dörfler BRect 125341281cf3SAxel Dörfler TReplicantTray::IconFrame(int32 target, bool byIndex) 125441281cf3SAxel Dörfler { 1255378aa08bSJohn Scipione int32 index; 1256378aa08bSJohn Scipione int32 id; 125741281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 125841281cf3SAxel Dörfler 1259378aa08bSJohn Scipione return view != NULL ? view->Frame() : BRect(0, 0, 0, 0); 126041281cf3SAxel Dörfler } 126141281cf3SAxel Dörfler 126241281cf3SAxel Dörfler 126341281cf3SAxel Dörfler BRect 126441281cf3SAxel Dörfler TReplicantTray::IconFrame(const char* name) 126541281cf3SAxel Dörfler { 1266e4d65fe7SJohn Scipione if (name == NULL) 126741281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 126841281cf3SAxel Dörfler 1269378aa08bSJohn Scipione int32 index; 1270378aa08bSJohn Scipione int32 id; 127141281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 127241281cf3SAxel Dörfler 1273378aa08bSJohn Scipione return view != NULL ? view->Frame() : BRect(0, 0, 0, 0); 127441281cf3SAxel Dörfler } 127541281cf3SAxel Dörfler 127641281cf3SAxel Dörfler 12777da06231SAxel Dörfler /** Scan from the startIndex and reset the location 12787da06231SAxel Dörfler * as defined in LocationForReplicant() 127941281cf3SAxel Dörfler */ 128041281cf3SAxel Dörfler 128141281cf3SAxel Dörfler void 128241281cf3SAxel Dörfler TReplicantTray::RealignReplicants(int32 startIndex) 128341281cf3SAxel Dörfler { 128441281cf3SAxel Dörfler if (startIndex < 0) 128541281cf3SAxel Dörfler startIndex = 0; 128641281cf3SAxel Dörfler 128732b0035aSJohn Scipione int32 replicantCount = ReplicantCount(); 128832b0035aSJohn Scipione if (replicantCount <= 0) 128941281cf3SAxel Dörfler return; 129041281cf3SAxel Dörfler 12917da06231SAxel Dörfler if (startIndex == 0) 12927da06231SAxel Dörfler fRightBottomReplicant.Set(0, 0, 0, 0); 12937da06231SAxel Dörfler 129441281cf3SAxel Dörfler BView* view = NULL; 1295a44504a1SJohn Scipione for (int32 index = startIndex; index < replicantCount; index++) { 1296a44504a1SJohn Scipione fShelf->ReplicantAt(index, &view); 1297a44504a1SJohn Scipione if (view == NULL) 1298a44504a1SJohn Scipione continue; 1299a44504a1SJohn Scipione 1300a44504a1SJohn Scipione float replicantWidth = view->Frame().Width(); 1301a44504a1SJohn Scipione BPoint loc = LocationForReplicant(index, replicantWidth); 13020bec7100SStefano Ceccherini if (view->Frame().LeftTop() != loc) 130341281cf3SAxel Dörfler view->MoveTo(loc); 130441281cf3SAxel Dörfler } 130541281cf3SAxel Dörfler } 130641281cf3SAxel Dörfler 130741281cf3SAxel Dörfler 13088aab28f1SRene Gollent status_t 13097625ce51SRene Gollent TReplicantTray::_SaveSettings() 13107625ce51SRene Gollent { 13117625ce51SRene Gollent status_t result; 13127625ce51SRene Gollent BPath path; 131326ea7066SIngo Weinhold if ((result = GetDeskbarSettingsDirectory(path, true)) == B_OK) { 13147625ce51SRene Gollent path.Append(kReplicantSettingsFile); 13157625ce51SRene Gollent 13167625ce51SRene Gollent BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); 13177625ce51SRene Gollent if ((result = file.InitCheck()) == B_OK) 13187625ce51SRene Gollent result = fAddOnSettings.Flatten(&file); 13197625ce51SRene Gollent } 13207625ce51SRene Gollent 13217625ce51SRene Gollent return result; 13227625ce51SRene Gollent } 13237625ce51SRene Gollent 13247625ce51SRene Gollent 13253cf2d117SJohn Scipione void 13263cf2d117SJohn Scipione TReplicantTray::SaveTimeSettings() 13273cf2d117SJohn Scipione { 13283cf2d117SJohn Scipione if (fTime == NULL) 13293cf2d117SJohn Scipione return; 13303cf2d117SJohn Scipione 133131c0024dSJohn Scipione clock_settings* settings = ((TBarApp*)be_app)->ClockSettings(); 13323cf2d117SJohn Scipione settings->showSeconds = fTime->ShowSeconds(); 13333cf2d117SJohn Scipione settings->showDayOfWeek = fTime->ShowDayOfWeek(); 133431c0024dSJohn Scipione settings->showTimeZone = fTime->ShowTimeZone(); 13353cf2d117SJohn Scipione } 13363cf2d117SJohn Scipione 13373cf2d117SJohn Scipione 13381bb2e623SJohn Scipione // #pragma mark - TDragRegion 133941281cf3SAxel Dörfler 134041281cf3SAxel Dörfler 1341ca9acc20SAxel Dörfler /*! Draggable region that is asynchronous so that dragging does not block 1342ca9acc20SAxel Dörfler other activities. 13437da06231SAxel Dörfler */ 134432b0035aSJohn Scipione TDragRegion::TDragRegion(TBarView* parent, BView* replicantTray) 1345ca9acc20SAxel Dörfler : 1346ca9acc20SAxel Dörfler BControl(BRect(0, 0, 0, 0), "", "", NULL, B_FOLLOW_NONE, 134741281cf3SAxel Dörfler B_WILL_DRAW | B_FRAME_EVENTS), 134841281cf3SAxel Dörfler fBarView(parent), 134932b0035aSJohn Scipione fReplicantTray(replicantTray), 135041281cf3SAxel Dörfler fDragLocation(kAutoPlaceDragRegion) 135141281cf3SAxel Dörfler { 135241281cf3SAxel Dörfler } 135341281cf3SAxel Dörfler 135441281cf3SAxel Dörfler 135541281cf3SAxel Dörfler void 135641281cf3SAxel Dörfler TDragRegion::AttachedToWindow() 135741281cf3SAxel Dörfler { 135841281cf3SAxel Dörfler BView::AttachedToWindow(); 1359e4d65fe7SJohn Scipione 1360cb6afcb1SStephan Aßmus if (be_control_look != NULL) 13611bb2e623SJohn Scipione SetViewUIColor(B_MENU_BACKGROUND_COLOR, 1.1); 1362cb6afcb1SStephan Aßmus else 136316c10517Slooncraz SetViewUIColor(B_MENU_BACKGROUND_COLOR); 1364e4d65fe7SJohn Scipione 136541281cf3SAxel Dörfler ResizeToPreferred(); 136641281cf3SAxel Dörfler } 136741281cf3SAxel Dörfler 136841281cf3SAxel Dörfler 136941281cf3SAxel Dörfler void 137041281cf3SAxel Dörfler TDragRegion::GetPreferredSize(float* width, float* height) 137141281cf3SAxel Dörfler { 137232b0035aSJohn Scipione fReplicantTray->ResizeToPreferred(); 137332b0035aSJohn Scipione *width = fReplicantTray->Bounds().Width(); 137432b0035aSJohn Scipione *height = fReplicantTray->Bounds().Height(); 137541281cf3SAxel Dörfler 137641281cf3SAxel Dörfler if (fDragLocation != kNoDragRegion) 13771bb2e623SJohn Scipione *width += kDragWidth + kGutter; 137841281cf3SAxel Dörfler else 137941281cf3SAxel Dörfler *width += 6; 138041281cf3SAxel Dörfler 13811bb2e623SJohn Scipione *height += 2; 138241281cf3SAxel Dörfler } 138341281cf3SAxel Dörfler 138441281cf3SAxel Dörfler 138541281cf3SAxel Dörfler void 138670ad5289SJohn Scipione TDragRegion::Draw(BRect updateRect) 138741281cf3SAxel Dörfler { 1388eaa9af99SStephan Aßmus rgb_color menuColor = ViewColor(); 138941281cf3SAxel Dörfler rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT); 1390cb6afcb1SStephan Aßmus rgb_color ldark = tint_color(menuColor, 1.02); 1391cb6afcb1SStephan Aßmus rgb_color dark = tint_color(menuColor, B_DARKEN_2_TINT); 139241281cf3SAxel Dörfler rgb_color vvdark = tint_color(menuColor, B_DARKEN_4_TINT); 139341281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 139441281cf3SAxel Dörfler 139541281cf3SAxel Dörfler BRect frame(Bounds()); 139641281cf3SAxel Dörfler BeginLineArray(4); 139741281cf3SAxel Dörfler 1398cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 1399cb6afcb1SStephan Aßmus if (fBarView->Vertical()) { 1400cb6afcb1SStephan Aßmus AddLine(frame.LeftTop(), frame.RightTop(), dark); 1401cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1402cb6afcb1SStephan Aßmus BPoint(frame.right, frame.top + 1), ldark); 1403cb6afcb1SStephan Aßmus AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 1404cb6afcb1SStephan Aßmus } else if (fBarView->AcrossTop() || fBarView->AcrossBottom()) { 1405cb6afcb1SStephan Aßmus AddLine(frame.LeftTop(), 1406cb6afcb1SStephan Aßmus BPoint(frame.left, frame.bottom), dark); 1407cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left + 1, frame.top + 1), 1408cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 1409cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right, frame.top + 2), 1410cb6afcb1SStephan Aßmus BPoint(frame.right, frame.bottom), hilite); 1411cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left + 1, frame.bottom), 1412cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom), hilite); 1413cb6afcb1SStephan Aßmus } 1414cb6afcb1SStephan Aßmus } else { 141541281cf3SAxel Dörfler if (fBarView->Vertical()) { 141641281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.RightTop(), light); 141741281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.LeftBottom(), light); 141841281cf3SAxel Dörfler AddLine(frame.RightBottom(), frame.RightTop(), hilite); 141941281cf3SAxel Dörfler } else if (fBarView->AcrossTop()) { 1420cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1421cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 142241281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 1423cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right - 1, frame.top + 2), 1424cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom - 1), hilite); 1425cb6afcb1SStephan Aßmus AddLine(frame.LeftBottom(), 1426cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom), hilite); 142741281cf3SAxel Dörfler } else if (fBarView->AcrossBottom()) { 1428cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1429cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 143041281cf3SAxel Dörfler AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 143141281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 1432cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right - 1, frame.top + 1), 1433cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom - 1), hilite); 1434cb6afcb1SStephan Aßmus } 143541281cf3SAxel Dörfler } 143641281cf3SAxel Dörfler 143741281cf3SAxel Dörfler EndLineArray(); 143841281cf3SAxel Dörfler 143941281cf3SAxel Dörfler if (fDragLocation != kDontDrawDragRegion || fDragLocation != kNoDragRegion) 144041281cf3SAxel Dörfler DrawDragRegion(); 144141281cf3SAxel Dörfler } 144241281cf3SAxel Dörfler 144341281cf3SAxel Dörfler 144441281cf3SAxel Dörfler void 144541281cf3SAxel Dörfler TDragRegion::DrawDragRegion() 144641281cf3SAxel Dörfler { 144741281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 144841281cf3SAxel Dörfler 1449cb6afcb1SStephan Aßmus rgb_color menuColor = ViewColor(); 1450cb6afcb1SStephan Aßmus rgb_color menuHilite = menuColor; 145141281cf3SAxel Dörfler if (IsTracking()) { 14521bb2e623SJohn Scipione // draw drag region highlighted if tracking mouse 1453cb6afcb1SStephan Aßmus menuHilite = tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT); 145441281cf3SAxel Dörfler SetHighColor(menuHilite); 145541281cf3SAxel Dörfler FillRect(dragRegion); 14561bb2e623SJohn Scipione } else { 14571bb2e623SJohn Scipione SetHighColor(menuColor); 14581bb2e623SJohn Scipione FillRect(dragRegion); 145941281cf3SAxel Dörfler } 14601bb2e623SJohn Scipione 1461cb6afcb1SStephan Aßmus rgb_color vdark = tint_color(menuHilite, B_DARKEN_3_TINT); 1462cb6afcb1SStephan Aßmus rgb_color light = tint_color(menuHilite, B_LIGHTEN_2_TINT); 1463cb6afcb1SStephan Aßmus 1464cb6afcb1SStephan Aßmus BeginLineArray(dragRegion.IntegerHeight()); 1465e4d65fe7SJohn Scipione BPoint where; 1466e4d65fe7SJohn Scipione where.x = floorf((dragRegion.left + dragRegion.right) / 2 + 0.5) - 1; 1467e4d65fe7SJohn Scipione where.y = dragRegion.top + 2; 1468cb6afcb1SStephan Aßmus 1469e4d65fe7SJohn Scipione while (where.y + 1 <= dragRegion.bottom) { 1470e4d65fe7SJohn Scipione AddLine(where, where, vdark); 1471e4d65fe7SJohn Scipione AddLine(where + BPoint(1, 1), where + BPoint(1, 1), light); 147241281cf3SAxel Dörfler 1473e4d65fe7SJohn Scipione where.y += 3; 147441281cf3SAxel Dörfler } 147541281cf3SAxel Dörfler EndLineArray(); 147641281cf3SAxel Dörfler } 147741281cf3SAxel Dörfler 147841281cf3SAxel Dörfler 147941281cf3SAxel Dörfler BRect 148041281cf3SAxel Dörfler TDragRegion::DragRegion() const 148141281cf3SAxel Dörfler { 1482cb6afcb1SStephan Aßmus float kTopBottomInset = 2; 1483cb6afcb1SStephan Aßmus float kLeftRightInset = 1; 1484cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 1485cb6afcb1SStephan Aßmus kTopBottomInset = 1; 1486cb6afcb1SStephan Aßmus kLeftRightInset = 0; 1487cb6afcb1SStephan Aßmus } 1488cb6afcb1SStephan Aßmus 148941281cf3SAxel Dörfler BRect dragRegion(Bounds()); 1490cb6afcb1SStephan Aßmus dragRegion.top += kTopBottomInset; 1491cb6afcb1SStephan Aßmus dragRegion.bottom -= kTopBottomInset; 149241281cf3SAxel Dörfler 149341281cf3SAxel Dörfler bool placeOnLeft = false; 149441281cf3SAxel Dörfler if (fDragLocation == kAutoPlaceDragRegion) { 149541281cf3SAxel Dörfler if (fBarView->Vertical() && fBarView->Left()) 149641281cf3SAxel Dörfler placeOnLeft = true; 149741281cf3SAxel Dörfler else 149841281cf3SAxel Dörfler placeOnLeft = false; 14991bb2e623SJohn Scipione } else 15001bb2e623SJohn Scipione placeOnLeft = fDragLocation == kDragRegionLeft; 150141281cf3SAxel Dörfler 150241281cf3SAxel Dörfler if (placeOnLeft) { 1503cb6afcb1SStephan Aßmus dragRegion.left += kLeftRightInset; 1504cb6afcb1SStephan Aßmus dragRegion.right = dragRegion.left + kDragWidth; 150541281cf3SAxel Dörfler } else { 15061bb2e623SJohn Scipione dragRegion.right += kLeftRightInset; 1507cb6afcb1SStephan Aßmus dragRegion.left = dragRegion.right - kDragWidth; 150841281cf3SAxel Dörfler } 150941281cf3SAxel Dörfler 151041281cf3SAxel Dörfler return dragRegion; 151141281cf3SAxel Dörfler } 151241281cf3SAxel Dörfler 151341281cf3SAxel Dörfler 151441281cf3SAxel Dörfler void 1515e4d65fe7SJohn Scipione TDragRegion::MouseDown(BPoint where) 151641281cf3SAxel Dörfler { 1517e9632898SAlex Smith uint32 buttons; 1518e4d65fe7SJohn Scipione BPoint mouseLoc; 151941281cf3SAxel Dörfler 1520e4d65fe7SJohn Scipione BRect dragRegion(DragRegion()); 15211bb2e623SJohn Scipione dragRegion.InsetBy(-2, -2); 15227da06231SAxel Dörfler // DragRegion() is designed for drawing, not clicking 152341281cf3SAxel Dörfler 1524e4d65fe7SJohn Scipione if (!dragRegion.Contains(where)) 152541281cf3SAxel Dörfler return; 152641281cf3SAxel Dörfler 152741281cf3SAxel Dörfler while (true) { 1528e4d65fe7SJohn Scipione GetMouse(&mouseLoc, &buttons); 1529e4d65fe7SJohn Scipione if (buttons == 0) 153041281cf3SAxel Dörfler break; 153141281cf3SAxel Dörfler 153241281cf3SAxel Dörfler if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) != 0) { 1533e4d65fe7SJohn Scipione fPreviousPosition = where; 153441281cf3SAxel Dörfler SetTracking(true); 153541281cf3SAxel Dörfler SetMouseEventMask(B_POINTER_EVENTS, 153641281cf3SAxel Dörfler B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); 153741281cf3SAxel Dörfler Invalidate(DragRegion()); 153841281cf3SAxel Dörfler break; 153941281cf3SAxel Dörfler } 154041281cf3SAxel Dörfler 154141281cf3SAxel Dörfler snooze(25000); 154241281cf3SAxel Dörfler } 154341281cf3SAxel Dörfler } 154441281cf3SAxel Dörfler 154541281cf3SAxel Dörfler 154641281cf3SAxel Dörfler void 1547e4d65fe7SJohn Scipione TDragRegion::MouseUp(BPoint where) 154841281cf3SAxel Dörfler { 154941281cf3SAxel Dörfler if (IsTracking()) { 155041281cf3SAxel Dörfler SetTracking(false); 155141281cf3SAxel Dörfler Invalidate(DragRegion()); 155241281cf3SAxel Dörfler } else 1553e4d65fe7SJohn Scipione BControl::MouseUp(where); 155441281cf3SAxel Dörfler } 155541281cf3SAxel Dörfler 155641281cf3SAxel Dörfler 155741281cf3SAxel Dörfler bool 1558e4d65fe7SJohn Scipione TDragRegion::SwitchModeForRect(BPoint where, BRect rect, 155941281cf3SAxel Dörfler bool newVertical, bool newLeft, bool newTop, int32 newState) 156041281cf3SAxel Dörfler { 1561e4d65fe7SJohn Scipione if (!rect.Contains(where)) { 156241281cf3SAxel Dörfler // not our rect 156341281cf3SAxel Dörfler return false; 15641ad8c760SFredrik Holmqvist } 156541281cf3SAxel Dörfler 15661ad8c760SFredrik Holmqvist if (newVertical == fBarView->Vertical() && newLeft == fBarView->Left() 15671ad8c760SFredrik Holmqvist && newTop == fBarView->Top() && newState == fBarView->State()) { 156841281cf3SAxel Dörfler // already in the correct mode 156941281cf3SAxel Dörfler return true; 15701ad8c760SFredrik Holmqvist } 157141281cf3SAxel Dörfler 1572d7ed9414SRene Gollent fBarView->ChangeState(newState, newVertical, newLeft, newTop, true); 1573e4d65fe7SJohn Scipione 157441281cf3SAxel Dörfler return true; 157541281cf3SAxel Dörfler } 157641281cf3SAxel Dörfler 157741281cf3SAxel Dörfler 157841281cf3SAxel Dörfler void 157941281cf3SAxel Dörfler TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage* message) 158041281cf3SAxel Dörfler { 158141281cf3SAxel Dörfler if (IsTracking()) { 158241281cf3SAxel Dörfler BScreen screen; 158341281cf3SAxel Dörfler BRect frame = screen.Frame(); 158441281cf3SAxel Dörfler 158541281cf3SAxel Dörfler float hDivider = frame.Width() / 6; 15861bb2e623SJohn Scipione hDivider = (hDivider < gMinimumWindowWidth + 10) 15871bb2e623SJohn Scipione ? gMinimumWindowWidth + 10 : hDivider; 15881bb2e623SJohn Scipione float miniDivider = frame.top + kMiniHeight + 10; 158941281cf3SAxel Dörfler float vDivider = frame.Height() / 2; 159041281cf3SAxel Dörfler #ifdef FULL_MODE 159141281cf3SAxel Dörfler float thirdScreen = frame.Height() / 3; 159241281cf3SAxel Dörfler #endif 159371bd3ba5SJonas Sundström BRect topLeft(frame.left, frame.top, frame.left + hDivider, 159471bd3ba5SJonas Sundström miniDivider); 159571bd3ba5SJonas Sundström BRect topMiddle(frame.left + hDivider, frame.top, frame.right 159671bd3ba5SJonas Sundström - hDivider, vDivider); 159771bd3ba5SJonas Sundström BRect topRight(frame.right - hDivider, frame.top, frame.right, 159871bd3ba5SJonas Sundström miniDivider); 159941281cf3SAxel Dörfler 160041281cf3SAxel Dörfler #ifdef FULL_MODE 160141281cf3SAxel Dörfler vDivider = miniDivider + thirdScreen; 160241281cf3SAxel Dörfler #endif 160371bd3ba5SJonas Sundström BRect middleLeft(frame.left, miniDivider, frame.left + hDivider, 160471bd3ba5SJonas Sundström vDivider); 160571bd3ba5SJonas Sundström BRect middleRight(frame.right - hDivider, miniDivider, frame.right, 160671bd3ba5SJonas Sundström vDivider); 160741281cf3SAxel Dörfler 160841281cf3SAxel Dörfler #ifdef FULL_MODE 160971bd3ba5SJonas Sundström BRect leftSide(frame.left, vDivider, frame.left + hDivider, 161071bd3ba5SJonas Sundström frame.bottom - thirdScreen); 161171bd3ba5SJonas Sundström BRect rightSide(frame.right - hDivider, vDivider, frame.right, 161271bd3ba5SJonas Sundström frame.bottom - thirdScreen); 161341281cf3SAxel Dörfler 161441281cf3SAxel Dörfler vDivider = frame.bottom - thirdScreen; 161541281cf3SAxel Dörfler #endif 161671bd3ba5SJonas Sundström BRect bottomLeft(frame.left, vDivider, frame.left + hDivider, 161771bd3ba5SJonas Sundström frame.bottom); 161871bd3ba5SJonas Sundström BRect bottomMiddle(frame.left + hDivider, vDivider, frame.right 161971bd3ba5SJonas Sundström - hDivider, frame.bottom); 162071bd3ba5SJonas Sundström BRect bottomRight(frame.right - hDivider, vDivider, frame.right, 162171bd3ba5SJonas Sundström frame.bottom); 162241281cf3SAxel Dörfler 162341281cf3SAxel Dörfler if (where != fPreviousPosition) { 162441281cf3SAxel Dörfler fPreviousPosition = where; 162541281cf3SAxel Dörfler ConvertToScreen(&where); 162641281cf3SAxel Dörfler 162741281cf3SAxel Dörfler // use short circuit evaluation for convenience 162841281cf3SAxel Dörfler if (SwitchModeForRect(where, topLeft, true, true, true, kMiniState) 162971bd3ba5SJonas Sundström || SwitchModeForRect(where, topMiddle, false, true, true, 163071bd3ba5SJonas Sundström kExpandoState) 163171bd3ba5SJonas Sundström || SwitchModeForRect(where, topRight, true, false, true, 163271bd3ba5SJonas Sundström kMiniState) 163371bd3ba5SJonas Sundström || SwitchModeForRect(where, middleLeft, true, true, true, 163471bd3ba5SJonas Sundström kExpandoState) 163571bd3ba5SJonas Sundström || SwitchModeForRect(where, middleRight, true, false, true, 163671bd3ba5SJonas Sundström kExpandoState) 163741281cf3SAxel Dörfler 163841281cf3SAxel Dörfler #ifdef FULL_MODE 163971bd3ba5SJonas Sundström || SwitchModeForRect(where, leftSide, true, true, true, 164071bd3ba5SJonas Sundström kFullState) 164171bd3ba5SJonas Sundström || SwitchModeForRect(where, rightSide, true, false, true, 164271bd3ba5SJonas Sundström kFullState) 164341281cf3SAxel Dörfler #endif 164471bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomLeft, true, true, false, 164571bd3ba5SJonas Sundström kMiniState) 164671bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomMiddle, false, true, false, 164771bd3ba5SJonas Sundström kExpandoState) 164871bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomRight, true, false, false, 164971bd3ba5SJonas Sundström kMiniState)) 165041281cf3SAxel Dörfler ; 165141281cf3SAxel Dörfler } 165241281cf3SAxel Dörfler } else 165341281cf3SAxel Dörfler BControl::MouseMoved(where, code, message); 165441281cf3SAxel Dörfler } 165541281cf3SAxel Dörfler 165641281cf3SAxel Dörfler 165741281cf3SAxel Dörfler int32 165841281cf3SAxel Dörfler TDragRegion::DragRegionLocation() const 165941281cf3SAxel Dörfler { 166041281cf3SAxel Dörfler return fDragLocation; 166141281cf3SAxel Dörfler } 166241281cf3SAxel Dörfler 166341281cf3SAxel Dörfler 166441281cf3SAxel Dörfler void 166541281cf3SAxel Dörfler TDragRegion::SetDragRegionLocation(int32 location) 166641281cf3SAxel Dörfler { 166741281cf3SAxel Dörfler if (location == fDragLocation) 166841281cf3SAxel Dörfler return; 166941281cf3SAxel Dörfler 167041281cf3SAxel Dörfler fDragLocation = location; 167141281cf3SAxel Dörfler Invalidate(); 167241281cf3SAxel Dörfler } 16731bb2e623SJohn Scipione 16741bb2e623SJohn Scipione 16751bb2e623SJohn Scipione // #pragma mark - TResizeControl 16761bb2e623SJohn Scipione 16771bb2e623SJohn Scipione 16781bb2e623SJohn Scipione /*! Draggable region that is asynchronous so that resizing does not block. 16791bb2e623SJohn Scipione */ 16801bb2e623SJohn Scipione TResizeControl::TResizeControl(TBarView* barView) 16811bb2e623SJohn Scipione : 16821bb2e623SJohn Scipione BControl(BRect(0, kDragWidth, 0, kMenuBarHeight), "", "", NULL, 16831bb2e623SJohn Scipione B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS), 16841bb2e623SJohn Scipione fBarView(barView) 16851bb2e623SJohn Scipione { 16861bb2e623SJohn Scipione } 16871bb2e623SJohn Scipione 16881bb2e623SJohn Scipione 16891bb2e623SJohn Scipione TResizeControl::~TResizeControl() 16901bb2e623SJohn Scipione { 16911bb2e623SJohn Scipione } 16921bb2e623SJohn Scipione 16931bb2e623SJohn Scipione 16941bb2e623SJohn Scipione void 16951bb2e623SJohn Scipione TResizeControl::AttachedToWindow() 16961bb2e623SJohn Scipione { 16971bb2e623SJohn Scipione BView::AttachedToWindow(); 16981bb2e623SJohn Scipione 16991bb2e623SJohn Scipione if (be_control_look != NULL) 17001bb2e623SJohn Scipione SetViewUIColor(B_MENU_BACKGROUND_COLOR, 1.1); 17011bb2e623SJohn Scipione else 17021bb2e623SJohn Scipione SetViewUIColor(B_MENU_BACKGROUND_COLOR); 17031bb2e623SJohn Scipione } 17041bb2e623SJohn Scipione 17051bb2e623SJohn Scipione 17061bb2e623SJohn Scipione void 17071bb2e623SJohn Scipione TResizeControl::Draw(BRect updateRect) 17081bb2e623SJohn Scipione { 17091bb2e623SJohn Scipione if (!fBarView->Vertical()) 17101bb2e623SJohn Scipione return; 17111bb2e623SJohn Scipione 1712092e918bSJohn Scipione BRect dragRegion(Bounds()); 17131bb2e623SJohn Scipione 171400171c6fSJohn Scipione int32 height = dragRegion.IntegerHeight(); 171500171c6fSJohn Scipione if (height <= 0) 171600171c6fSJohn Scipione return; 171700171c6fSJohn Scipione 17181bb2e623SJohn Scipione rgb_color menuColor = ViewColor(); 17191bb2e623SJohn Scipione rgb_color menuHilite = menuColor; 17201bb2e623SJohn Scipione if (IsTracking()) { 17211bb2e623SJohn Scipione // draw drag region highlighted if tracking mouse 17221bb2e623SJohn Scipione menuHilite = tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT); 17231bb2e623SJohn Scipione SetHighColor(menuHilite); 17241bb2e623SJohn Scipione FillRect(dragRegion); 17251bb2e623SJohn Scipione } else { 17261bb2e623SJohn Scipione SetHighColor(menuColor); 17271bb2e623SJohn Scipione FillRect(dragRegion); 17281bb2e623SJohn Scipione } 17291bb2e623SJohn Scipione 17301bb2e623SJohn Scipione rgb_color vdark = tint_color(menuHilite, B_DARKEN_3_TINT); 17311bb2e623SJohn Scipione rgb_color light = tint_color(menuHilite, B_LIGHTEN_2_TINT); 17321bb2e623SJohn Scipione 173300171c6fSJohn Scipione BeginLineArray(height); 17341bb2e623SJohn Scipione BPoint where; 17351bb2e623SJohn Scipione where.x = floorf((dragRegion.left + dragRegion.right) / 2 + 0.5) - 1; 17361bb2e623SJohn Scipione where.y = dragRegion.top + 2; 17371bb2e623SJohn Scipione 17381bb2e623SJohn Scipione while (where.y + 1 <= dragRegion.bottom) { 17391bb2e623SJohn Scipione AddLine(where, where, vdark); 17401bb2e623SJohn Scipione AddLine(where + BPoint(1, 1), where + BPoint(1, 1), light); 17411bb2e623SJohn Scipione 17421bb2e623SJohn Scipione where.y += 3; 17431bb2e623SJohn Scipione } 17441bb2e623SJohn Scipione EndLineArray(); 17451bb2e623SJohn Scipione } 17461bb2e623SJohn Scipione 17471bb2e623SJohn Scipione 17481bb2e623SJohn Scipione void 17491bb2e623SJohn Scipione TResizeControl::MouseDown(BPoint where) 17501bb2e623SJohn Scipione { 17511bb2e623SJohn Scipione uint32 buttons; 17521bb2e623SJohn Scipione BPoint mouseLoc; 17531bb2e623SJohn Scipione 17541bb2e623SJohn Scipione while (true) { 17551bb2e623SJohn Scipione GetMouse(&mouseLoc, &buttons); 17561bb2e623SJohn Scipione if (buttons == 0) 17571bb2e623SJohn Scipione break; 17581bb2e623SJohn Scipione 17591bb2e623SJohn Scipione if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) != 0) { 17601bb2e623SJohn Scipione SetTracking(true); 17611bb2e623SJohn Scipione SetMouseEventMask(B_POINTER_EVENTS, 17621bb2e623SJohn Scipione B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); 17631bb2e623SJohn Scipione Invalidate(); 17641bb2e623SJohn Scipione break; 17651bb2e623SJohn Scipione } 17661bb2e623SJohn Scipione 17671bb2e623SJohn Scipione snooze(25000); 17681bb2e623SJohn Scipione } 17691bb2e623SJohn Scipione } 17701bb2e623SJohn Scipione 17711bb2e623SJohn Scipione 17721bb2e623SJohn Scipione void 17731bb2e623SJohn Scipione TResizeControl::MouseUp(BPoint where) 17741bb2e623SJohn Scipione { 17751bb2e623SJohn Scipione if (IsTracking()) { 17761bb2e623SJohn Scipione SetTracking(false); 17771bb2e623SJohn Scipione Invalidate(); 17781bb2e623SJohn Scipione } else 17791bb2e623SJohn Scipione BControl::MouseUp(where); 17801bb2e623SJohn Scipione } 17811bb2e623SJohn Scipione 17821bb2e623SJohn Scipione 17831bb2e623SJohn Scipione void 17841bb2e623SJohn Scipione TResizeControl::MouseMoved(BPoint where, uint32 code, 17851bb2e623SJohn Scipione const BMessage* dragMessage) 17861bb2e623SJohn Scipione { 17871bb2e623SJohn Scipione if (fBarView->Vertical()) { 17881bb2e623SJohn Scipione if (IsResizing()) { 17891bb2e623SJohn Scipione float windowWidth = Window()->Frame().Width(); 17901bb2e623SJohn Scipione float delta = 0; 17911bb2e623SJohn Scipione BPoint whereScreen = ConvertToScreen(where); 17921bb2e623SJohn Scipione 17931bb2e623SJohn Scipione if (fBarView->Left()) { 17941bb2e623SJohn Scipione delta = whereScreen.x - Window()->Frame().right; 17951bb2e623SJohn Scipione if (delta > 0 && windowWidth >= gMaximumWindowWidth) 17961bb2e623SJohn Scipione ; // do nothing 17971bb2e623SJohn Scipione else if (delta < 0 && windowWidth <= gMinimumWindowWidth) 17981bb2e623SJohn Scipione ; // do nothing 17991bb2e623SJohn Scipione else 18001bb2e623SJohn Scipione Window()->ResizeBy(delta, 0); 18011bb2e623SJohn Scipione } else { 18021bb2e623SJohn Scipione delta = Window()->Frame().left - whereScreen.x; 18031bb2e623SJohn Scipione if (delta > 0 && windowWidth >= gMaximumWindowWidth) 18041bb2e623SJohn Scipione ; // do nothing 18051bb2e623SJohn Scipione else if (delta < 0 && windowWidth <= gMinimumWindowWidth) 18061bb2e623SJohn Scipione ; // do nothing 18071bb2e623SJohn Scipione else { 18081bb2e623SJohn Scipione Window()->MoveBy(delta, 0); 18091bb2e623SJohn Scipione Window()->ResizeBy(delta, 0); 18101bb2e623SJohn Scipione } 18111bb2e623SJohn Scipione } 18121bb2e623SJohn Scipione 18131bb2e623SJohn Scipione windowWidth = Window()->Frame().Width(); 18141bb2e623SJohn Scipione } 18151bb2e623SJohn Scipione } 18161bb2e623SJohn Scipione 18171bb2e623SJohn Scipione BControl::MouseMoved(where, code, dragMessage); 18181bb2e623SJohn Scipione } 1819