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" 73cb6afcb1SStephan Aßmus #include "ResourceSet.h" 7441281cf3SAxel Dörfler #include "StatusViewShelf.h" 7541281cf3SAxel Dörfler #include "TimeView.h" 7641281cf3SAxel Dörfler 77615d572dSJohn Scipione 7841281cf3SAxel Dörfler #ifdef DB_ADDONS 7941281cf3SAxel Dörfler // Add-on support 8041281cf3SAxel Dörfler // 8141281cf3SAxel Dörfler // Item - internal item list (node, eref, etc) 8241281cf3SAxel Dörfler // Icon - physical replicant handed to the DeskbarClass class 8341281cf3SAxel Dörfler // AddOn - attribute based add-on 8441281cf3SAxel Dörfler 8541281cf3SAxel Dörfler const char* const kInstantiateItemCFunctionName = "instantiate_deskbar_item"; 8641281cf3SAxel Dörfler const char* const kInstantiateEntryCFunctionName = "instantiate_deskbar_entry"; 8726ea7066SIngo Weinhold const char* const kReplicantSettingsFile = "replicants"; 88c0ad1c91SRene Gollent const char* const kReplicantPathField = "replicant_path"; 8941281cf3SAxel Dörfler 90b49e806dSAxel Dörfler float gMinimumWindowWidth = kGutter + kMinimumTrayWidth + kDragRegionWidth; 911bb2e623SJohn Scipione float gMaximumWindowWidth = gMinimumWindowWidth * 2; 9241281cf3SAxel Dörfler 93c3c3360fSJohn Scipione 9441281cf3SAxel Dörfler static void 9541281cf3SAxel Dörfler DumpItem(DeskbarItemInfo* item) 9641281cf3SAxel Dörfler { 97e9632898SAlex Smith printf("is addon: %i, id: %" B_PRId32 "\n", item->isAddOn, item->id); 98e9632898SAlex Smith printf("entry_ref: %" B_PRIdDEV ", %" B_PRIdINO ", %s\n", 99e9632898SAlex Smith item->entryRef.device, item->entryRef.directory, item->entryRef.name); 100e9632898SAlex Smith printf("node_ref: %" B_PRIdDEV ", %" B_PRIdINO "\n", item->nodeRef.device, 101e9632898SAlex Smith item->nodeRef.node); 10241281cf3SAxel Dörfler } 10341281cf3SAxel Dörfler 10441281cf3SAxel Dörfler 10541281cf3SAxel Dörfler static void 10641281cf3SAxel Dörfler DumpList(BList* itemlist) 10741281cf3SAxel Dörfler { 10841281cf3SAxel Dörfler int32 count = itemlist->CountItems() - 1; 10941281cf3SAxel Dörfler if (count < 0) { 11041281cf3SAxel Dörfler printf("no items in list\n"); 11141281cf3SAxel Dörfler return; 11241281cf3SAxel Dörfler } 11341281cf3SAxel Dörfler for (int32 i = count; i >= 0; i--) { 11441281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)itemlist->ItemAt(i); 11541281cf3SAxel Dörfler if (!item) 11641281cf3SAxel Dörfler continue; 11741281cf3SAxel Dörfler 11841281cf3SAxel Dörfler DumpItem(item); 11941281cf3SAxel Dörfler } 12041281cf3SAxel Dörfler } 12141281cf3SAxel Dörfler #endif /* DB_ADDONS */ 12241281cf3SAxel Dörfler 12341281cf3SAxel Dörfler 124546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT 125546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "Tray" 126ae7a6e3aSAdrien Destugues 1277da06231SAxel Dörfler // don't change the name of this view to anything other than "Status"! 1287da06231SAxel Dörfler 12941281cf3SAxel Dörfler TReplicantTray::TReplicantTray(TBarView* parent, bool vertical) 1300d2ac94cSJohn Scipione : 1319ac6fee1SJohn Scipione BView(BRect(0, 0, 1, 1), "Status", B_FOLLOW_LEFT | B_FOLLOW_TOP, 1320d2ac94cSJohn Scipione B_WILL_DRAW | B_FRAME_EVENTS), 133573f748cSJohn Scipione fTime(NULL), 13441281cf3SAxel Dörfler fBarView(parent), 13541281cf3SAxel Dörfler fShelf(new TReplicantShelf(this)), 13641281cf3SAxel Dörfler fMultiRowMode(vertical), 13741281cf3SAxel Dörfler fAlignmentSupport(false) 13841281cf3SAxel Dörfler { 139fb956f25SAxel Dörfler if (vertical) 140fb956f25SAxel Dörfler fMinimumTrayWidth = gMinimumWindowWidth - kGutter - kDragRegionWidth; 1411bb2e623SJohn Scipione else 1421bb2e623SJohn Scipione fMinimumTrayWidth = kMinimumTrayWidth; 143573f748cSJohn Scipione 144573f748cSJohn Scipione // Create the time view 14531c0024dSJohn Scipione fTime = new TTimeView(fMinimumTrayWidth, kMaxReplicantHeight - 1.0); 14641281cf3SAxel Dörfler } 14741281cf3SAxel Dörfler 14841281cf3SAxel Dörfler 14941281cf3SAxel Dörfler TReplicantTray::~TReplicantTray() 15041281cf3SAxel Dörfler { 15141281cf3SAxel Dörfler delete fShelf; 152573f748cSJohn Scipione delete fTime; 15341281cf3SAxel Dörfler } 15441281cf3SAxel Dörfler 15541281cf3SAxel Dörfler 15641281cf3SAxel Dörfler void 15741281cf3SAxel Dörfler TReplicantTray::AttachedToWindow() 15841281cf3SAxel Dörfler { 15941281cf3SAxel Dörfler BView::AttachedToWindow(); 16041281cf3SAxel Dörfler 161cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 162cef0a7b2Slooncraz AdoptParentColors(); 163cb6afcb1SStephan Aßmus } else { 16416c10517Slooncraz SetViewUIColor(B_MENU_BACKGROUND_COLOR, B_DARKEN_1_TINT); 165cb6afcb1SStephan Aßmus } 16641281cf3SAxel Dörfler SetDrawingMode(B_OP_COPY); 16766eba86fSAxel Dörfler 16841281cf3SAxel Dörfler Window()->SetPulseRate(1000000); 16941281cf3SAxel Dörfler 1703722e640SJohn Scipione clock_settings* clock = ((TBarApp*)be_app)->ClockSettings(); 1713722e640SJohn Scipione fTime->SetShowSeconds(clock->showSeconds); 1723722e640SJohn Scipione fTime->SetShowDayOfWeek(clock->showDayOfWeek); 1733722e640SJohn Scipione fTime->SetShowTimeZone(clock->showTimeZone); 17431c0024dSJohn Scipione 175573f748cSJohn Scipione AddChild(fTime); 1761bb2e623SJohn Scipione 17770ad5289SJohn Scipione fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - kTrayPadding, 2); 178ae7a6e3aSAdrien Destugues 1793722e640SJohn Scipione if (!((TBarApp*)be_app)->Settings()->showClock) 1803722e640SJohn Scipione fTime->Hide(); 1813722e640SJohn Scipione 18241281cf3SAxel Dörfler #ifdef DB_ADDONS 18341281cf3SAxel Dörfler // load addons and rehydrate archives 1843a6add49SAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 18541281cf3SAxel Dörfler InitAddOnSupport(); 18641281cf3SAxel Dörfler #endif 1879c910f9eSStephan Aßmus #endif 18841281cf3SAxel Dörfler ResizeToPreferred(); 18941281cf3SAxel Dörfler } 19041281cf3SAxel Dörfler 19141281cf3SAxel Dörfler 19241281cf3SAxel Dörfler void 19341281cf3SAxel Dörfler TReplicantTray::DetachedFromWindow() 19441281cf3SAxel Dörfler { 19541281cf3SAxel Dörfler #ifdef DB_ADDONS 19641281cf3SAxel Dörfler // clean up add-on support 197465b54cdSAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 19841281cf3SAxel Dörfler DeleteAddOnSupport(); 19941281cf3SAxel Dörfler #endif 200465b54cdSAxel Dörfler #endif 20141281cf3SAxel Dörfler BView::DetachedFromWindow(); 20241281cf3SAxel Dörfler } 20341281cf3SAxel Dörfler 20441281cf3SAxel Dörfler 2051ad8c760SFredrik Holmqvist /*! Width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth 20666eba86fSAxel Dörfler if not in multirowmode and greater than kMinimumReplicantCount 2072ce9bab8SJohn Scipione the width should be calculated based on the actual replicant widths 20841281cf3SAxel Dörfler */ 20941281cf3SAxel Dörfler void 21041281cf3SAxel Dörfler TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight) 21141281cf3SAxel Dörfler { 2121bb2e623SJohn Scipione float width = 0; 213e4d65fe7SJohn Scipione float height = kMinimumTrayHeight; 21441281cf3SAxel Dörfler 21541281cf3SAxel Dörfler if (fMultiRowMode) { 2161bb2e623SJohn Scipione width = static_cast<TBarApp*>(be_app)->Settings()->width 2171bb2e623SJohn Scipione - kDragWidth - kGutter; 218a44504a1SJohn Scipione if (fRightBottomReplicant.IsValid()) 2197da06231SAxel Dörfler height = fRightBottomReplicant.bottom; 220a44504a1SJohn Scipione else if (ReplicantCount() > 0) { 221a44504a1SJohn Scipione // The height will be uniform for the number of rows necessary 222a44504a1SJohn Scipione // to show all the replicants and gutters. 22341281cf3SAxel Dörfler int32 rowCount = (int32)(height / kMaxReplicantHeight); 22441281cf3SAxel Dörfler height = kGutter + (rowCount * kMaxReplicantHeight) 22541281cf3SAxel Dörfler + ((rowCount - 1) * kIconGap) + kGutter; 2261bb2e623SJohn Scipione height = std::max(kMinimumTrayHeight, height); 227a44504a1SJohn Scipione } else 228a44504a1SJohn Scipione height = kMinimumTrayHeight; 22941281cf3SAxel Dörfler } else { 2301ad8c760SFredrik Holmqvist // if last replicant overruns clock then resize to accomodate 23132b0035aSJohn Scipione if (ReplicantCount() > 0) { 232c0be5490SJohn Scipione if (!fTime->IsHidden() && Bounds().right - kTrayPadding - 2 233c0be5490SJohn Scipione - fTime->Frame().Width() - kClockMargin 2347b7bf68dSJohn Scipione < fRightBottomReplicant.right + kClockMargin) { 2357b7bf68dSJohn Scipione width = fRightBottomReplicant.right + kClockMargin 236c0be5490SJohn Scipione + fTime->Frame().Width() + kTrayPadding + 2; 23741281cf3SAxel Dörfler } else 23870ad5289SJohn Scipione width = fRightBottomReplicant.right + kIconGap + kGutter; 23941281cf3SAxel Dörfler } 2401ad8c760SFredrik Holmqvist 24141281cf3SAxel Dörfler // this view has a fixed minimum width 2421bb2e623SJohn Scipione width = std::max(fMinimumTrayWidth, width); 2432ce9bab8SJohn Scipione height = kGutter + static_cast<TBarApp*>(be_app)->IconSize() + kGutter; 24441281cf3SAxel Dörfler } 24541281cf3SAxel Dörfler 24641281cf3SAxel Dörfler *preferredWidth = width; 2471ad8c760SFredrik Holmqvist // add 1 for the border 24841281cf3SAxel Dörfler *preferredHeight = height + 1; 24941281cf3SAxel Dörfler } 25041281cf3SAxel Dörfler 25141281cf3SAxel Dörfler 25241281cf3SAxel Dörfler void 25341281cf3SAxel Dörfler TReplicantTray::AdjustPlacement() 25441281cf3SAxel Dörfler { 25541281cf3SAxel Dörfler // called when an add-on has been added or removed 25641281cf3SAxel Dörfler // need to resize the parent of this accordingly 257a5210ab1SAxel Dörfler 25841281cf3SAxel Dörfler BRect bounds = Bounds(); 25941281cf3SAxel Dörfler float width, height; 26041281cf3SAxel Dörfler GetPreferredSize(&width, &height); 26141281cf3SAxel Dörfler 26241281cf3SAxel Dörfler if (width == bounds.Width() && height == bounds.Height()) { 26341281cf3SAxel Dörfler // no need to change anything 26441281cf3SAxel Dörfler return; 26541281cf3SAxel Dörfler } 26641281cf3SAxel Dörfler 26741281cf3SAxel Dörfler Parent()->ResizeToPreferred(); 26841281cf3SAxel Dörfler fBarView->UpdatePlacement(); 26941281cf3SAxel Dörfler Parent()->Invalidate(); 27041281cf3SAxel Dörfler Invalidate(); 27141281cf3SAxel Dörfler } 27241281cf3SAxel Dörfler 27341281cf3SAxel Dörfler 27441281cf3SAxel Dörfler void 27541281cf3SAxel Dörfler TReplicantTray::MessageReceived(BMessage* message) 27641281cf3SAxel Dörfler { 27741281cf3SAxel Dörfler switch (message->what) { 27830a55802SJohn Scipione case B_LOCALE_CHANGED: 279573f748cSJohn Scipione if (fTime == NULL) 280573f748cSJohn Scipione return; 281573f748cSJohn Scipione 282*4c999927SAdrien Destugues fTime->UpdateTimeFormat(); 28331c0024dSJohn Scipione fTime->Update(); 28441281cf3SAxel Dörfler // time string reformat -> realign 285c0dc265cSJohn Scipione goto realignReplicants; 286573f748cSJohn Scipione 28730a55802SJohn Scipione case kShowHideTime: 28830a55802SJohn Scipione // from context menu in clock and in this view 28930a55802SJohn Scipione ShowHideTime(); 29030a55802SJohn Scipione break; 29130a55802SJohn Scipione 2923cf2d117SJohn Scipione case kShowSeconds: 293573f748cSJohn Scipione if (fTime == NULL) 294573f748cSJohn Scipione return; 295573f748cSJohn Scipione 2963cf2d117SJohn Scipione fTime->SetShowSeconds(!fTime->ShowSeconds()); 297573f748cSJohn Scipione 2983cf2d117SJohn Scipione // time string reformat -> realign 299c0dc265cSJohn Scipione goto realignReplicants; 3003cf2d117SJohn Scipione 3013cf2d117SJohn Scipione case kShowDayOfWeek: 3023cf2d117SJohn Scipione if (fTime == NULL) 3033cf2d117SJohn Scipione return; 3043cf2d117SJohn Scipione 3053cf2d117SJohn Scipione fTime->SetShowDayOfWeek(!fTime->ShowDayOfWeek()); 3063cf2d117SJohn Scipione 3073cf2d117SJohn Scipione // time string reformat -> realign 308c0dc265cSJohn Scipione goto realignReplicants; 3093cf2d117SJohn Scipione 31031c0024dSJohn Scipione case kShowTimeZone: 31131c0024dSJohn Scipione if (fTime == NULL) 31231c0024dSJohn Scipione return; 31331c0024dSJohn Scipione 31431c0024dSJohn Scipione fTime->SetShowTimeZone(!fTime->ShowTimeZone()); 31531c0024dSJohn Scipione 31631c0024dSJohn Scipione // time string reformat -> realign 317c0dc265cSJohn Scipione goto realignReplicants; 31831c0024dSJohn Scipione 31931c0024dSJohn Scipione case kGetClockSettings: 32031c0024dSJohn Scipione { 32131c0024dSJohn Scipione if (fTime == NULL) 32231c0024dSJohn Scipione return; 32331c0024dSJohn Scipione 32431c0024dSJohn Scipione bool showClock = !fTime->IsHidden(); 32531c0024dSJohn Scipione bool showSeconds = fTime->ShowSeconds(); 32631c0024dSJohn Scipione bool showDayOfWeek = fTime->ShowDayOfWeek(); 32731c0024dSJohn Scipione bool showTimeZone = fTime->ShowTimeZone(); 32831c0024dSJohn Scipione 3290fc30d89SDario Casalinuovo BMessage reply(kGetClockSettings); 3300fc30d89SDario Casalinuovo reply.AddBool("showClock", showClock); 3310fc30d89SDario Casalinuovo reply.AddBool("showSeconds", showSeconds); 3320fc30d89SDario Casalinuovo reply.AddBool("showDayOfWeek", showDayOfWeek); 3330fc30d89SDario Casalinuovo reply.AddBool("showTimeZone", showTimeZone); 3340fc30d89SDario Casalinuovo message->SendReply(&reply); 33531c0024dSJohn Scipione break; 33631c0024dSJohn Scipione } 33731c0024dSJohn Scipione 33841281cf3SAxel Dörfler #ifdef DB_ADDONS 33941281cf3SAxel Dörfler case B_NODE_MONITOR: 34041281cf3SAxel Dörfler HandleEntryUpdate(message); 34141281cf3SAxel Dörfler break; 34241281cf3SAxel Dörfler #endif 34341281cf3SAxel Dörfler 344c0dc265cSJohn Scipione case kRealignReplicants: 345c0dc265cSJohn Scipione realignReplicants: 346c0dc265cSJohn Scipione RealignReplicants(); 347c0dc265cSJohn Scipione AdjustPlacement(); 348c0dc265cSJohn Scipione break; 349c0dc265cSJohn Scipione 35041281cf3SAxel Dörfler default: 35141281cf3SAxel Dörfler BView::MessageReceived(message); 35241281cf3SAxel Dörfler break; 35341281cf3SAxel Dörfler } 35441281cf3SAxel Dörfler } 35541281cf3SAxel Dörfler 35641281cf3SAxel Dörfler 35741281cf3SAxel Dörfler void 35841281cf3SAxel Dörfler TReplicantTray::MouseDown(BPoint where) 35941281cf3SAxel Dörfler { 36041281cf3SAxel Dörfler #ifdef DB_ADDONS 36141281cf3SAxel Dörfler if (modifiers() & B_CONTROL_KEY) 36241281cf3SAxel Dörfler DumpList(fItemList); 36341281cf3SAxel Dörfler #endif 36441281cf3SAxel Dörfler 36541281cf3SAxel Dörfler uint32 buttons; 36641281cf3SAxel Dörfler 36741281cf3SAxel Dörfler Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons); 36841281cf3SAxel Dörfler if (buttons == B_SECONDARY_MOUSE_BUTTON) { 36941281cf3SAxel Dörfler ShowReplicantMenu(where); 37041281cf3SAxel Dörfler } else { 37141281cf3SAxel Dörfler BPoint save = where; 37241281cf3SAxel Dörfler bigtime_t doubleClickSpeed; 37341281cf3SAxel Dörfler bigtime_t start = system_time(); 37441281cf3SAxel Dörfler uint32 buttons; 37541281cf3SAxel Dörfler 37641281cf3SAxel Dörfler get_click_speed(&doubleClickSpeed); 37741281cf3SAxel Dörfler 37841281cf3SAxel Dörfler do { 37941281cf3SAxel Dörfler if (fabs(where.x - save.x) > 4 || fabs(where.y - save.y) > 4) 38041281cf3SAxel Dörfler // user moved out of bounds of click area 38141281cf3SAxel Dörfler break; 38241281cf3SAxel Dörfler 38341281cf3SAxel Dörfler if ((system_time() - start) > (2 * doubleClickSpeed)) { 38441281cf3SAxel Dörfler ShowReplicantMenu(where); 38541281cf3SAxel Dörfler break; 38641281cf3SAxel Dörfler } 38741281cf3SAxel Dörfler 38841281cf3SAxel Dörfler snooze(50000); 38941281cf3SAxel Dörfler GetMouse(&where, &buttons); 39041281cf3SAxel Dörfler } while (buttons); 39141281cf3SAxel Dörfler } 39241281cf3SAxel Dörfler BView::MouseDown(where); 39341281cf3SAxel Dörfler } 39441281cf3SAxel Dörfler 3953cf2d117SJohn Scipione 3963cf2d117SJohn Scipione void 3973cf2d117SJohn Scipione TReplicantTray::ShowReplicantMenu(BPoint point) 3983cf2d117SJohn Scipione { 3993cf2d117SJohn Scipione BPopUpMenu* menu = new BPopUpMenu("", false, false); 4003cf2d117SJohn Scipione menu->SetFont(be_plain_font); 4013cf2d117SJohn Scipione 40231c0024dSJohn Scipione // If clock is visible show the extended menu, otherwise show "Show clock" 4033cf2d117SJohn Scipione 4043cf2d117SJohn Scipione if (!fTime->IsHidden()) 4053cf2d117SJohn Scipione fTime->ShowTimeOptions(ConvertToScreen(point)); 4063cf2d117SJohn Scipione else { 40731c0024dSJohn Scipione BMenuItem* item = new BMenuItem(B_TRANSLATE("Show clock"), 4083cf2d117SJohn Scipione new BMessage(kShowHideTime)); 4093cf2d117SJohn Scipione menu->AddItem(item); 4103cf2d117SJohn Scipione menu->SetTargetForItems(this); 4113cf2d117SJohn Scipione BPoint where = ConvertToScreen(point); 4123cf2d117SJohn Scipione menu->Go(where, true, true, BRect(where - BPoint(4, 4), 4133cf2d117SJohn Scipione where + BPoint(4, 4)), true); 4143cf2d117SJohn Scipione } 4153cf2d117SJohn Scipione } 4163cf2d117SJohn Scipione 4173cf2d117SJohn Scipione 4183cf2d117SJohn Scipione void 4193cf2d117SJohn Scipione TReplicantTray::SetMultiRow(bool state) 4203cf2d117SJohn Scipione { 4213cf2d117SJohn Scipione fMultiRowMode = state; 4223cf2d117SJohn Scipione } 4233cf2d117SJohn Scipione 4243cf2d117SJohn Scipione 4253cf2d117SJohn Scipione void 4263cf2d117SJohn Scipione TReplicantTray::ShowHideTime() 4273cf2d117SJohn Scipione { 4283cf2d117SJohn Scipione if (fTime == NULL) 4293cf2d117SJohn Scipione return; 4303cf2d117SJohn Scipione 4312a5c1f12SJohn Scipione // Check from the point of view of fTime because we need to ignore 4322a5c1f12SJohn Scipione // whether or not the parent window is hidden. 4332a5c1f12SJohn Scipione if (fTime->IsHidden(fTime)) 4343cf2d117SJohn Scipione fTime->Show(); 4353cf2d117SJohn Scipione else 4363cf2d117SJohn Scipione fTime->Hide(); 4373cf2d117SJohn Scipione 4383cf2d117SJohn Scipione RealignReplicants(); 4393cf2d117SJohn Scipione AdjustPlacement(); 44031c0024dSJohn Scipione 4412a5c1f12SJohn Scipione // Check from the point of view of fTime ignoring parent's state. 4422a5c1f12SJohn Scipione bool showClock = !fTime->IsHidden(fTime); 4433722e640SJohn Scipione 4443722e640SJohn Scipione // Update showClock setting that gets saved to disk on quit 4451bb2e623SJohn Scipione static_cast<TBarApp*>(be_app)->Settings()->showClock = showClock; 4463722e640SJohn Scipione 4473722e640SJohn Scipione // Send a message to Time preferences telling it to update 44831c0024dSJohn Scipione BMessenger messenger("application/x-vnd.Haiku-Time"); 4490fc30d89SDario Casalinuovo BMessage message(kShowHideTime); 4500fc30d89SDario Casalinuovo message.AddBool("showClock", showClock); 4510fc30d89SDario Casalinuovo messenger.SendMessage(&message); 4523cf2d117SJohn Scipione } 4533cf2d117SJohn Scipione 4543cf2d117SJohn Scipione 45541281cf3SAxel Dörfler #ifdef DB_ADDONS 45641281cf3SAxel Dörfler 4573cf2d117SJohn Scipione 45841281cf3SAxel Dörfler void 45941281cf3SAxel Dörfler TReplicantTray::InitAddOnSupport() 46041281cf3SAxel Dörfler { 46141281cf3SAxel Dörfler // list to maintain refs to each rep added/deleted 46241281cf3SAxel Dörfler fItemList = new BList(); 46341281cf3SAxel Dörfler BPath path; 4641ad8c760SFredrik Holmqvist 46526ea7066SIngo Weinhold if (GetDeskbarSettingsDirectory(path, true) == B_OK) { 4663e6ff860SRene Gollent path.Append(kReplicantSettingsFile); 46741281cf3SAxel Dörfler 46841281cf3SAxel Dörfler BFile file(path.Path(), B_READ_ONLY); 4693e6ff860SRene Gollent if (file.InitCheck() == B_OK) { 4703e6ff860SRene Gollent status_t result; 4713e6ff860SRene Gollent BEntry entry; 4723e6ff860SRene Gollent int32 id; 473c0ad1c91SRene Gollent BString path; 4743e6ff860SRene Gollent if (fAddOnSettings.Unflatten(&file) == B_OK) { 475c0ad1c91SRene Gollent for (int32 i = 0; fAddOnSettings.FindString(kReplicantPathField, 476c0ad1c91SRene Gollent i, &path) == B_OK; i++) { 477c0ad1c91SRene Gollent if (entry.SetTo(path.String()) == B_OK && entry.Exists()) { 4783e6ff860SRene Gollent result = LoadAddOn(&entry, &id, false); 4793e6ff860SRene Gollent } else 4803e6ff860SRene Gollent result = B_ENTRY_NOT_FOUND; 48141281cf3SAxel Dörfler 4823e6ff860SRene Gollent if (result != B_OK) { 483c0ad1c91SRene Gollent fAddOnSettings.RemoveData(kReplicantPathField, i); 4843e6ff860SRene Gollent --i; 48541281cf3SAxel Dörfler } 48641281cf3SAxel Dörfler } 48741281cf3SAxel Dörfler } 4883e6ff860SRene Gollent } 4893e6ff860SRene Gollent } 49041281cf3SAxel Dörfler } 49141281cf3SAxel Dörfler 49241281cf3SAxel Dörfler 49341281cf3SAxel Dörfler void 49441281cf3SAxel Dörfler TReplicantTray::DeleteAddOnSupport() 49541281cf3SAxel Dörfler { 4967625ce51SRene Gollent _SaveSettings(); 4973e6ff860SRene Gollent 4989f2cce2fSJohn Scipione for (int32 i = fItemList->CountItems() - 1; i >= 0; i--) { 49941281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->RemoveItem(i); 50041281cf3SAxel Dörfler if (item) { 50141281cf3SAxel Dörfler if (item->isAddOn) 50241281cf3SAxel Dörfler watch_node(&(item->nodeRef), B_STOP_WATCHING, this, Window()); 50341281cf3SAxel Dörfler 50441281cf3SAxel Dörfler delete item; 50541281cf3SAxel Dörfler } 50641281cf3SAxel Dörfler } 50741281cf3SAxel Dörfler delete fItemList; 50841281cf3SAxel Dörfler 50941281cf3SAxel Dörfler // stop the volume mount/unmount watch 51041281cf3SAxel Dörfler stop_watching(this, Window()); 51141281cf3SAxel Dörfler } 51241281cf3SAxel Dörfler 51341281cf3SAxel Dörfler 51441281cf3SAxel Dörfler DeskbarItemInfo* 51541281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(node_ref& nodeRef) 51641281cf3SAxel Dörfler { 5179f2cce2fSJohn Scipione for (int32 i = fItemList->CountItems() - 1; i >= 0; i--) { 51866eba86fSAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 51941281cf3SAxel Dörfler if (item == NULL) 52041281cf3SAxel Dörfler continue; 52141281cf3SAxel Dörfler 52241281cf3SAxel Dörfler if (item->nodeRef == nodeRef) 52341281cf3SAxel Dörfler return item; 52441281cf3SAxel Dörfler } 52541281cf3SAxel Dörfler 52641281cf3SAxel Dörfler return NULL; 52741281cf3SAxel Dörfler } 52841281cf3SAxel Dörfler 52941281cf3SAxel Dörfler 53041281cf3SAxel Dörfler DeskbarItemInfo* 53141281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(int32 id) 53241281cf3SAxel Dörfler { 5339f2cce2fSJohn Scipione for (int32 i = fItemList->CountItems() - 1; i >= 0; i--) { 53466eba86fSAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 53541281cf3SAxel Dörfler if (item == NULL) 53641281cf3SAxel Dörfler continue; 53741281cf3SAxel Dörfler 53841281cf3SAxel Dörfler if (item->id == id) 53941281cf3SAxel Dörfler return item; 54041281cf3SAxel Dörfler } 54141281cf3SAxel Dörfler 54241281cf3SAxel Dörfler return NULL; 54341281cf3SAxel Dörfler } 54441281cf3SAxel Dörfler 54541281cf3SAxel Dörfler 54641281cf3SAxel Dörfler bool 54741281cf3SAxel Dörfler TReplicantTray::NodeExists(node_ref& nodeRef) 54841281cf3SAxel Dörfler { 54941281cf3SAxel Dörfler return DeskbarItemFor(nodeRef) != NULL; 55041281cf3SAxel Dörfler } 55141281cf3SAxel Dörfler 55241281cf3SAxel Dörfler 55366eba86fSAxel Dörfler /*! This handles B_NODE_MONITOR & B_QUERY_UPDATE messages received 55466eba86fSAxel Dörfler for the registered add-ons. 55541281cf3SAxel Dörfler */ 55641281cf3SAxel Dörfler void 55741281cf3SAxel Dörfler TReplicantTray::HandleEntryUpdate(BMessage* message) 55841281cf3SAxel Dörfler { 55941281cf3SAxel Dörfler int32 opcode; 56041281cf3SAxel Dörfler if (message->FindInt32("opcode", &opcode) != B_OK) 56141281cf3SAxel Dörfler return; 56241281cf3SAxel Dörfler 56341281cf3SAxel Dörfler BPath path; 56441281cf3SAxel Dörfler switch (opcode) { 56541281cf3SAxel Dörfler case B_ENTRY_MOVED: 56641281cf3SAxel Dörfler { 56741281cf3SAxel Dörfler entry_ref ref; 56841281cf3SAxel Dörfler ino_t todirectory; 56941281cf3SAxel Dörfler ino_t node; 57041281cf3SAxel Dörfler const char* name; 57141281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK 57271bd3ba5SJonas Sundström && message->FindInt64("from directory", &(ref.directory)) 57371bd3ba5SJonas Sundström == B_OK 57441281cf3SAxel Dörfler && message->FindInt64("to directory", &todirectory) == B_OK 57541281cf3SAxel Dörfler && message->FindInt32("device", &(ref.device)) == B_OK 57641281cf3SAxel Dörfler && message->FindInt64("node", &node) == B_OK ) { 57741281cf3SAxel Dörfler 578e4d65fe7SJohn Scipione if (name == NULL) 57941281cf3SAxel Dörfler break; 58041281cf3SAxel Dörfler 58141281cf3SAxel Dörfler ref.set_name(name); 58241281cf3SAxel Dörfler // change the directory reference to 58341281cf3SAxel Dörfler // the new directory 58441281cf3SAxel Dörfler MoveItem(&ref, todirectory); 58541281cf3SAxel Dörfler } 58641281cf3SAxel Dörfler break; 58766eba86fSAxel Dörfler } 58841281cf3SAxel Dörfler 58941281cf3SAxel Dörfler case B_ENTRY_REMOVED: 59041281cf3SAxel Dörfler { 59141281cf3SAxel Dörfler // entry was rm'd from the device 59241281cf3SAxel Dörfler node_ref nodeRef; 59341281cf3SAxel Dörfler if (message->FindInt32("device", &(nodeRef.device)) == B_OK 59441281cf3SAxel Dörfler && message->FindInt64("node", &(nodeRef.node)) == B_OK) { 59541281cf3SAxel Dörfler DeskbarItemInfo* item = DeskbarItemFor(nodeRef); 59641281cf3SAxel Dörfler if (item == NULL) 59741281cf3SAxel Dörfler break; 59841281cf3SAxel Dörfler 59941281cf3SAxel Dörfler // If there is a team running where the add-on comes from, 60041281cf3SAxel Dörfler // we don't want to remove the icon yet. 60141281cf3SAxel Dörfler if (be_roster->IsRunning(&item->entryRef)) 60241281cf3SAxel Dörfler break; 60341281cf3SAxel Dörfler 60441281cf3SAxel Dörfler UnloadAddOn(&nodeRef, NULL, true, false); 60541281cf3SAxel Dörfler } 60641281cf3SAxel Dörfler break; 60766eba86fSAxel Dörfler } 60841281cf3SAxel Dörfler } 60966eba86fSAxel Dörfler } 61041281cf3SAxel Dörfler 61141281cf3SAxel Dörfler 6121ad8c760SFredrik Holmqvist /*! The add-ons must support the exported C function API 61366eba86fSAxel Dörfler if they do, they will be loaded and added to deskbar 61466eba86fSAxel Dörfler primary function is the Instantiate function 6157da06231SAxel Dörfler */ 61641281cf3SAxel Dörfler status_t 6173e6ff860SRene Gollent TReplicantTray::LoadAddOn(BEntry* entry, int32* id, bool addToSettings) 61841281cf3SAxel Dörfler { 619e4d65fe7SJohn Scipione if (entry == NULL) 620a6be6c4dSJohn Scipione return B_BAD_VALUE; 62141281cf3SAxel Dörfler 62241281cf3SAxel Dörfler node_ref nodeRef; 62341281cf3SAxel Dörfler entry->GetNodeRef(&nodeRef); 62441281cf3SAxel Dörfler // no duplicates 62541281cf3SAxel Dörfler if (NodeExists(nodeRef)) 62641281cf3SAxel Dörfler return B_ERROR; 62741281cf3SAxel Dörfler 62841281cf3SAxel Dörfler BNode node(entry); 62941281cf3SAxel Dörfler BPath path; 63066eba86fSAxel Dörfler status_t status = entry->GetPath(&path); 631e4d65fe7SJohn Scipione if (status != B_OK) 63266eba86fSAxel Dörfler return status; 63341281cf3SAxel Dörfler 63441281cf3SAxel Dörfler // load the add-on 63541281cf3SAxel Dörfler image_id image = load_add_on(path.Path()); 63666eba86fSAxel Dörfler if (image < B_OK) 63766eba86fSAxel Dörfler return image; 63841281cf3SAxel Dörfler 63941281cf3SAxel Dörfler // get the view loading function symbol 64041281cf3SAxel Dörfler // we first look for a symbol that takes an image_id 64141281cf3SAxel Dörfler // and entry_ref pointer, if not found, go with normal 64241281cf3SAxel Dörfler // instantiate function 64341281cf3SAxel Dörfler BView* (*entryFunction)(image_id, const entry_ref*); 64441281cf3SAxel Dörfler BView* (*itemFunction)(void); 64541281cf3SAxel Dörfler BView* view = NULL; 64641281cf3SAxel Dörfler 64741281cf3SAxel Dörfler entry_ref ref; 64841281cf3SAxel Dörfler entry->GetRef(&ref); 64941281cf3SAxel Dörfler 65041281cf3SAxel Dörfler if (get_image_symbol(image, kInstantiateEntryCFunctionName, 65166eba86fSAxel Dörfler B_SYMBOL_TYPE_TEXT, (void**)&entryFunction) >= B_OK) { 65241281cf3SAxel Dörfler view = (*entryFunction)(image, &ref); 65341281cf3SAxel Dörfler } else if (get_image_symbol(image, kInstantiateItemCFunctionName, 65466eba86fSAxel Dörfler B_SYMBOL_TYPE_TEXT, (void**)&itemFunction) >= B_OK) { 65541281cf3SAxel Dörfler view = (*itemFunction)(); 65641281cf3SAxel Dörfler } else { 65741281cf3SAxel Dörfler unload_add_on(image); 65841281cf3SAxel Dörfler return B_ERROR; 65941281cf3SAxel Dörfler } 66041281cf3SAxel Dörfler 66166eba86fSAxel Dörfler if (view == NULL || IconExists(view->Name())) { 66241281cf3SAxel Dörfler delete view; 66341281cf3SAxel Dörfler unload_add_on(image); 66441281cf3SAxel Dörfler return B_ERROR; 66541281cf3SAxel Dörfler } 66641281cf3SAxel Dörfler 66741281cf3SAxel Dörfler BMessage* data = new BMessage; 66841281cf3SAxel Dörfler view->Archive(data); 66941281cf3SAxel Dörfler delete view; 67041281cf3SAxel Dörfler 67141281cf3SAxel Dörfler // add the rep; adds info to list 6720fc30d89SDario Casalinuovo if (AddIcon(data, id, &ref) != B_OK) 6730fc30d89SDario Casalinuovo delete data; 67441281cf3SAxel Dörfler 6753e6ff860SRene Gollent if (addToSettings) { 676c0ad1c91SRene Gollent fAddOnSettings.AddString(kReplicantPathField, path.Path()); 6777625ce51SRene Gollent _SaveSettings(); 6783e6ff860SRene Gollent } 67941281cf3SAxel Dörfler 68041281cf3SAxel Dörfler return B_OK; 68141281cf3SAxel Dörfler } 68241281cf3SAxel Dörfler 68341281cf3SAxel Dörfler 68441281cf3SAxel Dörfler status_t 68541281cf3SAxel Dörfler TReplicantTray::AddItem(int32 id, node_ref nodeRef, BEntry& entry, bool isAddOn) 68641281cf3SAxel Dörfler { 68741281cf3SAxel Dörfler DeskbarItemInfo* item = new DeskbarItemInfo; 68841281cf3SAxel Dörfler if (item == NULL) 68941281cf3SAxel Dörfler return B_NO_MEMORY; 69041281cf3SAxel Dörfler 69141281cf3SAxel Dörfler item->id = id; 69241281cf3SAxel Dörfler item->isAddOn = isAddOn; 69341281cf3SAxel Dörfler 694e4d65fe7SJohn Scipione if (entry.GetRef(&item->entryRef) != B_OK) { 69541281cf3SAxel Dörfler item->entryRef.device = -1; 69641281cf3SAxel Dörfler item->entryRef.directory = -1; 69741281cf3SAxel Dörfler item->entryRef.name = NULL; 69841281cf3SAxel Dörfler } 69941281cf3SAxel Dörfler item->nodeRef = nodeRef; 70041281cf3SAxel Dörfler 70141281cf3SAxel Dörfler fItemList->AddItem(item); 70241281cf3SAxel Dörfler 70341281cf3SAxel Dörfler if (isAddOn) 70441281cf3SAxel Dörfler watch_node(&nodeRef, B_WATCH_NAME | B_WATCH_ATTR, this, Window()); 70541281cf3SAxel Dörfler 70641281cf3SAxel Dörfler return B_OK; 70741281cf3SAxel Dörfler } 70841281cf3SAxel Dörfler 70941281cf3SAxel Dörfler 71041281cf3SAxel Dörfler /** from entry_removed message, when attribute removed 71141281cf3SAxel Dörfler * or when a device is unmounted (use removeall, by device) 71241281cf3SAxel Dörfler */ 71341281cf3SAxel Dörfler 71441281cf3SAxel Dörfler void 715e4d65fe7SJohn Scipione TReplicantTray::UnloadAddOn(node_ref* nodeRef, dev_t* device, bool which, 716e4d65fe7SJohn Scipione bool removeAll) 71741281cf3SAxel Dörfler { 7189f2cce2fSJohn Scipione for (int32 i = fItemList->CountItems() - 1; i >= 0; i--) { 71941281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 720e4d65fe7SJohn Scipione if (item == NULL) 72141281cf3SAxel Dörfler continue; 72241281cf3SAxel Dörfler 723e4d65fe7SJohn Scipione if ((which && nodeRef != NULL && item->nodeRef == *nodeRef) 724e4d65fe7SJohn Scipione || (device != NULL && item->nodeRef.device == *device)) { 72541281cf3SAxel Dörfler 726e4d65fe7SJohn Scipione if (device != NULL && be_roster->IsRunning(&item->entryRef)) 72741281cf3SAxel Dörfler continue; 72841281cf3SAxel Dörfler 72941281cf3SAxel Dörfler RemoveIcon(item->id); 73041281cf3SAxel Dörfler 73141281cf3SAxel Dörfler if (!removeAll) 73241281cf3SAxel Dörfler break; 73341281cf3SAxel Dörfler } 73441281cf3SAxel Dörfler } 73541281cf3SAxel Dörfler } 73641281cf3SAxel Dörfler 73741281cf3SAxel Dörfler 73841281cf3SAxel Dörfler void 73941281cf3SAxel Dörfler TReplicantTray::RemoveItem(int32 id) 74041281cf3SAxel Dörfler { 74141281cf3SAxel Dörfler DeskbarItemInfo* item = DeskbarItemFor(id); 74241281cf3SAxel Dörfler if (item == NULL) 74341281cf3SAxel Dörfler return; 74441281cf3SAxel Dörfler 74541281cf3SAxel Dörfler // attribute was added via Deskbar API (AddItem(entry_ref*, int32*) 74641281cf3SAxel Dörfler if (item->isAddOn) { 7477625ce51SRene Gollent BPath path(&item->entryRef); 7487625ce51SRene Gollent BString storedPath; 7497625ce51SRene Gollent for (int32 i = 0; 7508aab28f1SRene Gollent fAddOnSettings.FindString(kReplicantPathField, i, &storedPath) 7517625ce51SRene Gollent == B_OK; i++) { 7527625ce51SRene Gollent if (storedPath == path.Path()) { 7538aab28f1SRene Gollent fAddOnSettings.RemoveData(kReplicantPathField, i); 7547625ce51SRene Gollent break; 7557625ce51SRene Gollent } 7567625ce51SRene Gollent } 7577625ce51SRene Gollent _SaveSettings(); 7587625ce51SRene Gollent 75941281cf3SAxel Dörfler BNode node(&item->entryRef); 76041281cf3SAxel Dörfler watch_node(&item->nodeRef, B_STOP_WATCHING, this, Window()); 76141281cf3SAxel Dörfler } 76241281cf3SAxel Dörfler 76341281cf3SAxel Dörfler fItemList->RemoveItem(item); 76441281cf3SAxel Dörfler delete item; 76541281cf3SAxel Dörfler } 76641281cf3SAxel Dörfler 76741281cf3SAxel Dörfler 76841281cf3SAxel Dörfler /** ENTRY_MOVED message, moving only occurs on a device 76941281cf3SAxel Dörfler * copying will occur (ENTRY_CREATED) between devices 77041281cf3SAxel Dörfler */ 77141281cf3SAxel Dörfler 77241281cf3SAxel Dörfler void 77341281cf3SAxel Dörfler TReplicantTray::MoveItem(entry_ref* ref, ino_t toDirectory) 77441281cf3SAxel Dörfler { 775e4d65fe7SJohn Scipione if (ref == NULL) 77641281cf3SAxel Dörfler return; 77741281cf3SAxel Dörfler 77841281cf3SAxel Dörfler // scan for a matching entry_ref and update it 77941281cf3SAxel Dörfler // 78041281cf3SAxel Dörfler // don't need to change node info as it does not change 78141281cf3SAxel Dörfler 7829f2cce2fSJohn Scipione for (int32 i = fItemList->CountItems() - 1; i >= 0; i--) { 78341281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 784e4d65fe7SJohn Scipione if (item == NULL) 78541281cf3SAxel Dörfler continue; 78641281cf3SAxel Dörfler 787e4d65fe7SJohn Scipione if (strcmp(item->entryRef.name, ref->name) == 0 78841281cf3SAxel Dörfler && item->entryRef.device == ref->device 78941281cf3SAxel Dörfler && item->entryRef.directory == ref->directory) { 79041281cf3SAxel Dörfler item->entryRef.directory = toDirectory; 79141281cf3SAxel Dörfler break; 79241281cf3SAxel Dörfler } 79341281cf3SAxel Dörfler } 79441281cf3SAxel Dörfler } 79541281cf3SAxel Dörfler 79641281cf3SAxel Dörfler #endif // add-on support 79741281cf3SAxel Dörfler 79841281cf3SAxel Dörfler // external add-on API routines 79941281cf3SAxel Dörfler // called using the new BDeskbar class 80041281cf3SAxel Dörfler 80141281cf3SAxel Dörfler // existence of icon/replicant by name or ID 80241281cf3SAxel Dörfler // returns opposite 80341281cf3SAxel Dörfler // note: name and id are semi-private limiting 80441281cf3SAxel Dörfler // the ability of non-host apps to remove 80541281cf3SAxel Dörfler // icons without a little bit of work 80641281cf3SAxel Dörfler 80741281cf3SAxel Dörfler /** for a specific id 80841281cf3SAxel Dörfler * return the name of the replicant (name of view) 80941281cf3SAxel Dörfler */ 81041281cf3SAxel Dörfler 81141281cf3SAxel Dörfler status_t 81241281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 id, const char** name) 81341281cf3SAxel Dörfler { 81441281cf3SAxel Dörfler if (id < 0) 815a6be6c4dSJohn Scipione return B_BAD_VALUE; 81641281cf3SAxel Dörfler 817e4d65fe7SJohn Scipione int32 index; 818e4d65fe7SJohn Scipione int32 temp; 81941281cf3SAxel Dörfler BView* view = ViewAt(&index, &temp, id, false); 820e4d65fe7SJohn Scipione if (view != NULL) { 82141281cf3SAxel Dörfler *name = view->Name(); 82241281cf3SAxel Dörfler return B_OK; 82341281cf3SAxel Dörfler } 82441281cf3SAxel Dörfler 82541281cf3SAxel Dörfler return B_ERROR; 82641281cf3SAxel Dörfler } 82741281cf3SAxel Dörfler 82841281cf3SAxel Dörfler 8297da06231SAxel Dörfler /** for a specific name 8307da06231SAxel Dörfler * return the id (internal to Deskbar) 8317da06231SAxel Dörfler */ 8327da06231SAxel Dörfler 83341281cf3SAxel Dörfler status_t 83441281cf3SAxel Dörfler TReplicantTray::ItemInfo(const char* name, int32* id) 83541281cf3SAxel Dörfler { 836e4d65fe7SJohn Scipione if (name == NULL || *name == '\0') 837a6be6c4dSJohn Scipione return B_BAD_VALUE; 83841281cf3SAxel Dörfler 83941281cf3SAxel Dörfler int32 index; 84041281cf3SAxel Dörfler BView* view = ViewAt(&index, id, name); 84141281cf3SAxel Dörfler 842378aa08bSJohn Scipione return view != NULL ? B_OK : B_ERROR; 84341281cf3SAxel Dörfler } 84441281cf3SAxel Dörfler 84541281cf3SAxel Dörfler 8467da06231SAxel Dörfler /** at a specific index 8477da06231SAxel Dörfler * return both the name and the id of the replicant 8487da06231SAxel Dörfler */ 8497da06231SAxel Dörfler 85041281cf3SAxel Dörfler status_t 85141281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 index, const char** name, int32* id) 85241281cf3SAxel Dörfler { 85341281cf3SAxel Dörfler if (index < 0) 854a6be6c4dSJohn Scipione return B_BAD_VALUE; 85541281cf3SAxel Dörfler 85641281cf3SAxel Dörfler BView* view; 85741281cf3SAxel Dörfler fShelf->ReplicantAt(index, &view, (uint32*)id, NULL); 858e4d65fe7SJohn Scipione if (view != NULL) { 85941281cf3SAxel Dörfler *name = view->Name(); 86041281cf3SAxel Dörfler return B_OK; 86141281cf3SAxel Dörfler } 86241281cf3SAxel Dörfler 86341281cf3SAxel Dörfler return B_ERROR; 86441281cf3SAxel Dörfler } 86541281cf3SAxel Dörfler 86641281cf3SAxel Dörfler 8677da06231SAxel Dörfler /** replicant exists, by id/index */ 8687da06231SAxel Dörfler 86941281cf3SAxel Dörfler bool 87041281cf3SAxel Dörfler TReplicantTray::IconExists(int32 target, bool byIndex) 87141281cf3SAxel Dörfler { 872e4d65fe7SJohn Scipione int32 index; 873e4d65fe7SJohn Scipione int32 id; 87441281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 87541281cf3SAxel Dörfler 87641281cf3SAxel Dörfler return view && index >= 0; 87741281cf3SAxel Dörfler } 87841281cf3SAxel Dörfler 87941281cf3SAxel Dörfler 8807da06231SAxel Dörfler /** replicant exists, by name */ 8817da06231SAxel Dörfler 88241281cf3SAxel Dörfler bool 88341281cf3SAxel Dörfler TReplicantTray::IconExists(const char* name) 88441281cf3SAxel Dörfler { 885e4d65fe7SJohn Scipione if (name == NULL || *name == '\0') 88641281cf3SAxel Dörfler return false; 88741281cf3SAxel Dörfler 888e4d65fe7SJohn Scipione int32 index; 889e4d65fe7SJohn Scipione int32 id; 89041281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 89141281cf3SAxel Dörfler 892e4d65fe7SJohn Scipione return view != NULL && index >= 0; 89341281cf3SAxel Dörfler } 89441281cf3SAxel Dörfler 89541281cf3SAxel Dörfler 89641281cf3SAxel Dörfler int32 89732b0035aSJohn Scipione TReplicantTray::ReplicantCount() const 89841281cf3SAxel Dörfler { 89941281cf3SAxel Dörfler return fShelf->CountReplicants(); 90041281cf3SAxel Dörfler } 90141281cf3SAxel Dörfler 90241281cf3SAxel Dörfler 903ced3755cSAxel Dörfler /*! Message must contain an archivable view for later rehydration. 904ced3755cSAxel Dörfler This function takes over ownership of the provided message on success 905ced3755cSAxel Dörfler only. 906ced3755cSAxel Dörfler Returns the current replicant ID. 9077da06231SAxel Dörfler */ 90841281cf3SAxel Dörfler status_t 909ced3755cSAxel Dörfler TReplicantTray::AddIcon(BMessage* archive, int32* id, const entry_ref* addOn) 91041281cf3SAxel Dörfler { 911ced3755cSAxel Dörfler if (archive == NULL || id == NULL) 912a6be6c4dSJohn Scipione return B_BAD_VALUE; 91341281cf3SAxel Dörfler 9149c50f36eSAxel Dörfler // find entry_ref 9159c50f36eSAxel Dörfler 9169c50f36eSAxel Dörfler entry_ref ref; 917e4d65fe7SJohn Scipione if (addOn != NULL) { 9189c50f36eSAxel Dörfler // Use it if we got it 9199c50f36eSAxel Dörfler ref = *addOn; 9209c50f36eSAxel Dörfler } else { 9219c50f36eSAxel Dörfler const char* signature; 9221ad8c760SFredrik Holmqvist 923ced3755cSAxel Dörfler status_t status = archive->FindString("add_on", &signature); 9249c50f36eSAxel Dörfler if (status == B_OK) { 9259c50f36eSAxel Dörfler BRoster roster; 9269c50f36eSAxel Dörfler status = roster.FindApp(signature, &ref); 9279c50f36eSAxel Dörfler } 928e4d65fe7SJohn Scipione if (status != B_OK) 9299c50f36eSAxel Dörfler return status; 9309c50f36eSAxel Dörfler } 9319c50f36eSAxel Dörfler 9329c50f36eSAxel Dörfler BFile file; 9339c50f36eSAxel Dörfler status_t status = file.SetTo(&ref, B_READ_ONLY); 934e4d65fe7SJohn Scipione if (status != B_OK) 9359c50f36eSAxel Dörfler return status; 9369c50f36eSAxel Dörfler 9379c50f36eSAxel Dörfler node_ref nodeRef; 9389c50f36eSAxel Dörfler status = file.GetNodeRef(&nodeRef); 939e4d65fe7SJohn Scipione if (status != B_OK) 9409c50f36eSAxel Dörfler return status; 9419c50f36eSAxel Dörfler 9429c50f36eSAxel Dörfler BEntry entry(&ref, true); 9431ad8c760SFredrik Holmqvist // TODO: this resolves an eventual link for the item being added - this 9441ad8c760SFredrik Holmqvist // is okay for now, but in multi-user environments, one might want to 9451ad8c760SFredrik Holmqvist // have links that carry the be:deskbar_item_status attribute 9469c50f36eSAxel Dörfler status = entry.InitCheck(); 9479c50f36eSAxel Dörfler if (status != B_OK) 9489c50f36eSAxel Dörfler return status; 9499c50f36eSAxel Dörfler 95041281cf3SAxel Dörfler *id = 999; 951ced3755cSAxel Dörfler if (archive->what == B_ARCHIVED_OBJECT) 952ced3755cSAxel Dörfler archive->what = 0; 95341281cf3SAxel Dörfler 954ced3755cSAxel Dörfler BRect originalBounds = archive->FindRect("_frame"); 9551ad8c760SFredrik Holmqvist // this is a work-around for buggy replicants that change their size in 9561ad8c760SFredrik Holmqvist // AttachedToWindow() (such as "SVM") 957a5210ab1SAxel Dörfler 9581ad8c760SFredrik Holmqvist // TODO: check for name collisions? 959ced3755cSAxel Dörfler status = fShelf->AddReplicant(archive, BPoint(1, 1)); 9609c50f36eSAxel Dörfler if (status != B_OK) 9619c50f36eSAxel Dörfler return status; 96241281cf3SAxel Dörfler 96332b0035aSJohn Scipione int32 count = ReplicantCount(); 964a5210ab1SAxel Dörfler BView* view; 965a5210ab1SAxel Dörfler fShelf->ReplicantAt(count - 1, &view, (uint32*)id, NULL); 966a5210ab1SAxel Dörfler 967a6be6c4dSJohn Scipione if (view != NULL && originalBounds != view->Bounds()) { 968a5210ab1SAxel Dörfler // The replicant changed its size when added to the window, so we need 96971bd3ba5SJonas Sundström // to recompute all over again (it's already done once via 97071bd3ba5SJonas Sundström // BShelf::AddReplicant() and TReplicantShelf::CanAcceptReplicantView()) 971a5210ab1SAxel Dörfler RealignReplicants(); 972a5210ab1SAxel Dörfler } 973a5210ab1SAxel Dörfler 97441281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 97541281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 97641281cf3SAxel Dörfler float width, height; 97741281cf3SAxel Dörfler GetPreferredSize(&width, &height); 97841281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) 97941281cf3SAxel Dörfler AdjustPlacement(); 98041281cf3SAxel Dörfler 98141281cf3SAxel Dörfler // add the item to the add-on list 98241281cf3SAxel Dörfler 98341281cf3SAxel Dörfler AddItem(*id, nodeRef, entry, addOn != NULL); 98441281cf3SAxel Dörfler return B_OK; 98541281cf3SAxel Dörfler } 98641281cf3SAxel Dörfler 98741281cf3SAxel Dörfler 98841281cf3SAxel Dörfler void 98941281cf3SAxel Dörfler TReplicantTray::RemoveIcon(int32 target, bool byIndex) 99041281cf3SAxel Dörfler { 99141281cf3SAxel Dörfler if (target < 0) 99241281cf3SAxel Dörfler return; 99341281cf3SAxel Dörfler 994e4d65fe7SJohn Scipione int32 index; 995e4d65fe7SJohn Scipione int32 id; 99641281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 997e4d65fe7SJohn Scipione if (view != NULL && index >= 0) { 9987da06231SAxel Dörfler // remove the reference from the item list & the shelf 99941281cf3SAxel Dörfler RemoveItem(id); 100041281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 10017da06231SAxel Dörfler 100241281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 100341281cf3SAxel Dörfler RealReplicantAdjustment(index); 100441281cf3SAxel Dörfler } 100541281cf3SAxel Dörfler } 100641281cf3SAxel Dörfler 100741281cf3SAxel Dörfler 100841281cf3SAxel Dörfler void 100941281cf3SAxel Dörfler TReplicantTray::RemoveIcon(const char* name) 101041281cf3SAxel Dörfler { 1011e4d65fe7SJohn Scipione if (name == NULL || *name == '\0') 101241281cf3SAxel Dörfler return; 101341281cf3SAxel Dörfler 1014378aa08bSJohn Scipione int32 index; 1015378aa08bSJohn Scipione int32 id; 101641281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 1017e4d65fe7SJohn Scipione if (view != NULL && index >= 0) { 10187da06231SAxel Dörfler // remove the reference from the item list & shelf 101941281cf3SAxel Dörfler RemoveItem(id); 102041281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 10217da06231SAxel Dörfler 102241281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 102341281cf3SAxel Dörfler RealReplicantAdjustment(index); 102441281cf3SAxel Dörfler } 102541281cf3SAxel Dörfler } 102641281cf3SAxel Dörfler 102741281cf3SAxel Dörfler 102841281cf3SAxel Dörfler void 10297da06231SAxel Dörfler TReplicantTray::RealReplicantAdjustment(int32 startIndex) 103041281cf3SAxel Dörfler { 10317da06231SAxel Dörfler if (startIndex < 0) 103241281cf3SAxel Dörfler return; 10337da06231SAxel Dörfler 10347da06231SAxel Dörfler if (startIndex == fLastReplicant) 10357da06231SAxel Dörfler startIndex = 0; 10367da06231SAxel Dörfler 103741281cf3SAxel Dörfler // reset the locations of all replicants after the one deleted 10387da06231SAxel Dörfler RealignReplicants(startIndex); 103941281cf3SAxel Dörfler 104041281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 104141281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 104241281cf3SAxel Dörfler float width, height; 104341281cf3SAxel Dörfler GetPreferredSize(&width, &height); 104441281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) { 10451ad8c760SFredrik Holmqvist // resize view to accomodate the replicants, redraw as necessary 104641281cf3SAxel Dörfler AdjustPlacement(); 104741281cf3SAxel Dörfler } 104841281cf3SAxel Dörfler } 104941281cf3SAxel Dörfler 105041281cf3SAxel Dörfler 10517da06231SAxel Dörfler /** looking for a replicant by id/index 10527da06231SAxel Dörfler * return the view and index 10537da06231SAxel Dörfler */ 10547da06231SAxel Dörfler 105541281cf3SAxel Dörfler BView* 105641281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, int32 target, bool byIndex) 105741281cf3SAxel Dörfler { 105841281cf3SAxel Dörfler *index = -1; 105941281cf3SAxel Dörfler 106041281cf3SAxel Dörfler BView* view; 106141281cf3SAxel Dörfler if (byIndex) { 106241281cf3SAxel Dörfler if (fShelf->ReplicantAt(target, &view, (uint32*)id)) { 1063e4d65fe7SJohn Scipione if (view != NULL) { 106441281cf3SAxel Dörfler *index = target; 1065e4d65fe7SJohn Scipione 106641281cf3SAxel Dörfler return view; 106741281cf3SAxel Dörfler } 106841281cf3SAxel Dörfler } 106941281cf3SAxel Dörfler } else { 107032b0035aSJohn Scipione int32 count = ReplicantCount() - 1; 107141281cf3SAxel Dörfler int32 localid; 107241281cf3SAxel Dörfler for (int32 repIndex = count; repIndex >= 0; repIndex--) { 107341281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32*)&localid); 1074e4d65fe7SJohn Scipione if (localid == target && view != NULL) { 107541281cf3SAxel Dörfler *index = repIndex; 107641281cf3SAxel Dörfler *id = localid; 1077e4d65fe7SJohn Scipione 107841281cf3SAxel Dörfler return view; 107941281cf3SAxel Dörfler } 108041281cf3SAxel Dörfler } 108141281cf3SAxel Dörfler } 1082e4d65fe7SJohn Scipione 108341281cf3SAxel Dörfler return NULL; 108441281cf3SAxel Dörfler } 108541281cf3SAxel Dörfler 108641281cf3SAxel Dörfler 10877da06231SAxel Dörfler /** looking for a replicant with a view by name 10887da06231SAxel Dörfler * return the view, index and the id of the replicant 10897da06231SAxel Dörfler */ 10907da06231SAxel Dörfler 109141281cf3SAxel Dörfler BView* 109241281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, const char* name) 109341281cf3SAxel Dörfler { 109441281cf3SAxel Dörfler *index = -1; 109541281cf3SAxel Dörfler *id = -1; 109641281cf3SAxel Dörfler 109741281cf3SAxel Dörfler BView* view; 109832b0035aSJohn Scipione int32 count = ReplicantCount() - 1; 109941281cf3SAxel Dörfler for (int32 repIndex = count; repIndex >= 0; repIndex--) { 110041281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32*)id); 11013641948fSJohn Scipione if (view != NULL && view->Name() != NULL 1102e4d65fe7SJohn Scipione && strcmp(name, view->Name()) == 0) { 110341281cf3SAxel Dörfler *index = repIndex; 1104e4d65fe7SJohn Scipione 110541281cf3SAxel Dörfler return view; 110641281cf3SAxel Dörfler } 110741281cf3SAxel Dörfler } 1108e4d65fe7SJohn Scipione 110941281cf3SAxel Dörfler return NULL; 111041281cf3SAxel Dörfler } 111141281cf3SAxel Dörfler 111241281cf3SAxel Dörfler 11137da06231SAxel Dörfler /** Shelf will call to determine where and if 11147da06231SAxel Dörfler * the replicant is to be added 11157da06231SAxel Dörfler */ 11167da06231SAxel Dörfler 111741281cf3SAxel Dörfler bool 111841281cf3SAxel Dörfler TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage* message) 111941281cf3SAxel Dörfler { 1120e4d65fe7SJohn Scipione if (message == NULL) 112141281cf3SAxel Dörfler return false; 112241281cf3SAxel Dörfler 112341281cf3SAxel Dörfler if (replicantFrame.Height() > kMaxReplicantHeight) 112441281cf3SAxel Dörfler return false; 112541281cf3SAxel Dörfler 112641281cf3SAxel Dörfler alignment align = B_ALIGN_LEFT; 112741281cf3SAxel Dörfler if (fAlignmentSupport && message->HasBool("deskbar:dynamic_align")) { 112841281cf3SAxel Dörfler if (!fBarView->Vertical()) 112941281cf3SAxel Dörfler align = B_ALIGN_RIGHT; 113041281cf3SAxel Dörfler else 113141281cf3SAxel Dörfler align = fBarView->Left() ? B_ALIGN_LEFT : B_ALIGN_RIGHT; 113241281cf3SAxel Dörfler } else if (message->HasInt32("deskbar:align")) 113341281cf3SAxel Dörfler message->FindInt32("deskbar:align", (int32*)&align); 113441281cf3SAxel Dörfler 113541281cf3SAxel Dörfler if (message->HasInt32("deskbar:private_align")) 113641281cf3SAxel Dörfler message->FindInt32("deskbar:private_align", (int32*)&align); 113741281cf3SAxel Dörfler else 113841281cf3SAxel Dörfler align = B_ALIGN_LEFT; 113941281cf3SAxel Dörfler 114032b0035aSJohn Scipione BPoint loc = LocationForReplicant(ReplicantCount(), 11417da06231SAxel Dörfler replicantFrame.Width()); 114241281cf3SAxel Dörfler message->AddPoint("_pjp_loc", loc); 1143e4d65fe7SJohn Scipione 114441281cf3SAxel Dörfler return true; 114541281cf3SAxel Dörfler } 114641281cf3SAxel Dörfler 114741281cf3SAxel Dörfler 114841281cf3SAxel Dörfler /** based on the previous (index - 1) replicant in the list 114941281cf3SAxel Dörfler * calculate where the left point should be for this 115041281cf3SAxel Dörfler * replicant. replicant will flow to the right on its own 115141281cf3SAxel Dörfler */ 115241281cf3SAxel Dörfler 115341281cf3SAxel Dörfler BPoint 115432b0035aSJohn Scipione TReplicantTray::LocationForReplicant(int32 index, float replicantWidth) 115541281cf3SAxel Dörfler { 115670ad5289SJohn Scipione BPoint loc(kTrayPadding, 2); 115770ad5289SJohn Scipione if (fBarView->Vertical()) { 115870ad5289SJohn Scipione if (!fBarView->Left()) 115970ad5289SJohn Scipione loc.x += kDragWidth; // move past dragger 116070ad5289SJohn Scipione } else 116170ad5289SJohn Scipione loc.x += 1; // keeps everything lined up nicely 116241281cf3SAxel Dörfler 11637da06231SAxel Dörfler if (fMultiRowMode) { 11647da06231SAxel Dörfler // try to find free space in every row 11657da06231SAxel Dörfler for (int32 row = 0; ; loc.y += kMaxReplicantHeight + kIconGap, row++) { 11667da06231SAxel Dörfler // determine free space in this row 1167a44504a1SJohn Scipione BRect rowRect(loc.x, loc.y, 11681bb2e623SJohn Scipione loc.x + static_cast<TBarApp*>(be_app)->Settings()->width 1169015b5dd6SJohn Scipione - (kTrayPadding + kDragWidth + kGutter) * 2, 11701bb2e623SJohn Scipione loc.y + kMaxReplicantHeight); 1171bc08a7d6SJohn Scipione if (row == 0 && !fTime->IsHidden()) 1172bc08a7d6SJohn Scipione rowRect.right -= kClockMargin + fTime->Frame().Width(); 11737da06231SAxel Dörfler 1174a44504a1SJohn Scipione BRect replicantRect = rowRect; 11757da06231SAxel Dörfler for (int32 i = 0; i < index; i++) { 11767da06231SAxel Dörfler BView* view = NULL; 11777da06231SAxel Dörfler fShelf->ReplicantAt(i, &view); 1178a44504a1SJohn Scipione if (view == NULL || view->Frame().top != rowRect.top) 11797da06231SAxel Dörfler continue; 11807da06231SAxel Dörfler 1181a44504a1SJohn Scipione // push this replicant placement past the last one 1182a44504a1SJohn Scipione replicantRect.left = view->Frame().right + kIconGap + 1; 11837da06231SAxel Dörfler } 11847da06231SAxel Dörfler 1185bc08a7d6SJohn Scipione // calculated left position, add replicantWidth to get right position 1186bc08a7d6SJohn Scipione replicantRect.right = replicantRect.left + replicantWidth; 1187bc08a7d6SJohn Scipione 1188bc08a7d6SJohn Scipione // check if replicant fits in this row 1189bc08a7d6SJohn Scipione if (replicantRect.right < rowRect.right) { 1190bc08a7d6SJohn Scipione // replicant fits in this row 1191a44504a1SJohn Scipione loc = replicantRect.LeftTop(); 11927da06231SAxel Dörfler break; 11937da06231SAxel Dörfler } 1194bc08a7d6SJohn Scipione 1195bc08a7d6SJohn Scipione // check next row 11967da06231SAxel Dörfler } 1197bc08a7d6SJohn Scipione } else if (index > 0) { 119841281cf3SAxel Dörfler // get the last replicant added for placement reference 119941281cf3SAxel Dörfler BView* view = NULL; 12007da06231SAxel Dörfler fShelf->ReplicantAt(index - 1, &view); 1201e4d65fe7SJohn Scipione if (view != NULL) { 1202a44504a1SJohn Scipione // push this replicant placement past the last one 120341281cf3SAxel Dörfler loc.x = view->Frame().right + kIconGap + 1; 120441281cf3SAxel Dörfler loc.y = view->Frame().top; 120541281cf3SAxel Dörfler } 120641281cf3SAxel Dörfler } 120741281cf3SAxel Dörfler 1208e4d65fe7SJohn Scipione if (loc.y > fRightBottomReplicant.top 1209e4d65fe7SJohn Scipione || (loc.y == fRightBottomReplicant.top 1210e4d65fe7SJohn Scipione && loc.x > fRightBottomReplicant.left)) { 1211a44504a1SJohn Scipione fRightBottomReplicant.Set(loc.x, loc.y, loc.x + replicantWidth, 1212e4d65fe7SJohn Scipione loc.y + kMaxReplicantHeight); 12137da06231SAxel Dörfler fLastReplicant = index; 121441281cf3SAxel Dörfler } 12157da06231SAxel Dörfler 121641281cf3SAxel Dörfler return loc; 121741281cf3SAxel Dörfler } 121841281cf3SAxel Dörfler 121941281cf3SAxel Dörfler 122041281cf3SAxel Dörfler BRect 122141281cf3SAxel Dörfler TReplicantTray::IconFrame(int32 target, bool byIndex) 122241281cf3SAxel Dörfler { 1223378aa08bSJohn Scipione int32 index; 1224378aa08bSJohn Scipione int32 id; 122541281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 122641281cf3SAxel Dörfler 1227378aa08bSJohn Scipione return view != NULL ? view->Frame() : BRect(0, 0, 0, 0); 122841281cf3SAxel Dörfler } 122941281cf3SAxel Dörfler 123041281cf3SAxel Dörfler 123141281cf3SAxel Dörfler BRect 123241281cf3SAxel Dörfler TReplicantTray::IconFrame(const char* name) 123341281cf3SAxel Dörfler { 1234e4d65fe7SJohn Scipione if (name == NULL) 123541281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 123641281cf3SAxel Dörfler 1237378aa08bSJohn Scipione int32 index; 1238378aa08bSJohn Scipione int32 id; 123941281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 124041281cf3SAxel Dörfler 1241378aa08bSJohn Scipione return view != NULL ? view->Frame() : BRect(0, 0, 0, 0); 124241281cf3SAxel Dörfler } 124341281cf3SAxel Dörfler 124441281cf3SAxel Dörfler 12457da06231SAxel Dörfler /** Scan from the startIndex and reset the location 12467da06231SAxel Dörfler * as defined in LocationForReplicant() 124741281cf3SAxel Dörfler */ 124841281cf3SAxel Dörfler 124941281cf3SAxel Dörfler void 125041281cf3SAxel Dörfler TReplicantTray::RealignReplicants(int32 startIndex) 125141281cf3SAxel Dörfler { 125241281cf3SAxel Dörfler if (startIndex < 0) 125341281cf3SAxel Dörfler startIndex = 0; 125441281cf3SAxel Dörfler 125532b0035aSJohn Scipione int32 replicantCount = ReplicantCount(); 125632b0035aSJohn Scipione if (replicantCount <= 0) 125741281cf3SAxel Dörfler return; 125841281cf3SAxel Dörfler 12597da06231SAxel Dörfler if (startIndex == 0) 12607da06231SAxel Dörfler fRightBottomReplicant.Set(0, 0, 0, 0); 12617da06231SAxel Dörfler 126241281cf3SAxel Dörfler BView* view = NULL; 1263a44504a1SJohn Scipione for (int32 index = startIndex; index < replicantCount; index++) { 1264a44504a1SJohn Scipione fShelf->ReplicantAt(index, &view); 1265a44504a1SJohn Scipione if (view == NULL) 1266a44504a1SJohn Scipione continue; 1267a44504a1SJohn Scipione 1268a44504a1SJohn Scipione float replicantWidth = view->Frame().Width(); 1269a44504a1SJohn Scipione BPoint loc = LocationForReplicant(index, replicantWidth); 12700bec7100SStefano Ceccherini if (view->Frame().LeftTop() != loc) 127141281cf3SAxel Dörfler view->MoveTo(loc); 127241281cf3SAxel Dörfler } 127341281cf3SAxel Dörfler } 127441281cf3SAxel Dörfler 127541281cf3SAxel Dörfler 12768aab28f1SRene Gollent status_t 12777625ce51SRene Gollent TReplicantTray::_SaveSettings() 12787625ce51SRene Gollent { 12797625ce51SRene Gollent status_t result; 12807625ce51SRene Gollent BPath path; 128126ea7066SIngo Weinhold if ((result = GetDeskbarSettingsDirectory(path, true)) == B_OK) { 12827625ce51SRene Gollent path.Append(kReplicantSettingsFile); 12837625ce51SRene Gollent 12847625ce51SRene Gollent BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); 12857625ce51SRene Gollent if ((result = file.InitCheck()) == B_OK) 12867625ce51SRene Gollent result = fAddOnSettings.Flatten(&file); 12877625ce51SRene Gollent } 12887625ce51SRene Gollent 12897625ce51SRene Gollent return result; 12907625ce51SRene Gollent } 12917625ce51SRene Gollent 12927625ce51SRene Gollent 12933cf2d117SJohn Scipione void 12943cf2d117SJohn Scipione TReplicantTray::SaveTimeSettings() 12953cf2d117SJohn Scipione { 12963cf2d117SJohn Scipione if (fTime == NULL) 12973cf2d117SJohn Scipione return; 12983cf2d117SJohn Scipione 129931c0024dSJohn Scipione clock_settings* settings = ((TBarApp*)be_app)->ClockSettings(); 13003cf2d117SJohn Scipione settings->showSeconds = fTime->ShowSeconds(); 13013cf2d117SJohn Scipione settings->showDayOfWeek = fTime->ShowDayOfWeek(); 130231c0024dSJohn Scipione settings->showTimeZone = fTime->ShowTimeZone(); 13033cf2d117SJohn Scipione } 13043cf2d117SJohn Scipione 13053cf2d117SJohn Scipione 13061bb2e623SJohn Scipione // #pragma mark - TDragRegion 130741281cf3SAxel Dörfler 130841281cf3SAxel Dörfler 1309ca9acc20SAxel Dörfler /*! Draggable region that is asynchronous so that dragging does not block 1310ca9acc20SAxel Dörfler other activities. 13117da06231SAxel Dörfler */ 131232b0035aSJohn Scipione TDragRegion::TDragRegion(TBarView* parent, BView* replicantTray) 1313ca9acc20SAxel Dörfler : 1314ca9acc20SAxel Dörfler BControl(BRect(0, 0, 0, 0), "", "", NULL, B_FOLLOW_NONE, 131541281cf3SAxel Dörfler B_WILL_DRAW | B_FRAME_EVENTS), 131641281cf3SAxel Dörfler fBarView(parent), 131732b0035aSJohn Scipione fReplicantTray(replicantTray), 131841281cf3SAxel Dörfler fDragLocation(kAutoPlaceDragRegion) 131941281cf3SAxel Dörfler { 132041281cf3SAxel Dörfler } 132141281cf3SAxel Dörfler 132241281cf3SAxel Dörfler 132341281cf3SAxel Dörfler void 132441281cf3SAxel Dörfler TDragRegion::AttachedToWindow() 132541281cf3SAxel Dörfler { 132641281cf3SAxel Dörfler BView::AttachedToWindow(); 1327e4d65fe7SJohn Scipione 1328cb6afcb1SStephan Aßmus if (be_control_look != NULL) 13291bb2e623SJohn Scipione SetViewUIColor(B_MENU_BACKGROUND_COLOR, 1.1); 1330cb6afcb1SStephan Aßmus else 133116c10517Slooncraz SetViewUIColor(B_MENU_BACKGROUND_COLOR); 1332e4d65fe7SJohn Scipione 133341281cf3SAxel Dörfler ResizeToPreferred(); 133441281cf3SAxel Dörfler } 133541281cf3SAxel Dörfler 133641281cf3SAxel Dörfler 133741281cf3SAxel Dörfler void 133841281cf3SAxel Dörfler TDragRegion::GetPreferredSize(float* width, float* height) 133941281cf3SAxel Dörfler { 134032b0035aSJohn Scipione fReplicantTray->ResizeToPreferred(); 134132b0035aSJohn Scipione *width = fReplicantTray->Bounds().Width(); 134232b0035aSJohn Scipione *height = fReplicantTray->Bounds().Height(); 134341281cf3SAxel Dörfler 134441281cf3SAxel Dörfler if (fDragLocation != kNoDragRegion) 13451bb2e623SJohn Scipione *width += kDragWidth + kGutter; 134641281cf3SAxel Dörfler else 134741281cf3SAxel Dörfler *width += 6; 134841281cf3SAxel Dörfler 13491bb2e623SJohn Scipione *height += 2; 135041281cf3SAxel Dörfler } 135141281cf3SAxel Dörfler 135241281cf3SAxel Dörfler 135341281cf3SAxel Dörfler void 135470ad5289SJohn Scipione TDragRegion::Draw(BRect updateRect) 135541281cf3SAxel Dörfler { 1356eaa9af99SStephan Aßmus rgb_color menuColor = ViewColor(); 135741281cf3SAxel Dörfler rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT); 1358cb6afcb1SStephan Aßmus rgb_color ldark = tint_color(menuColor, 1.02); 1359cb6afcb1SStephan Aßmus rgb_color dark = tint_color(menuColor, B_DARKEN_2_TINT); 136041281cf3SAxel Dörfler rgb_color vvdark = tint_color(menuColor, B_DARKEN_4_TINT); 136141281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 136241281cf3SAxel Dörfler 136341281cf3SAxel Dörfler BRect frame(Bounds()); 136441281cf3SAxel Dörfler BeginLineArray(4); 136541281cf3SAxel Dörfler 1366cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 1367cb6afcb1SStephan Aßmus if (fBarView->Vertical()) { 1368cb6afcb1SStephan Aßmus AddLine(frame.LeftTop(), frame.RightTop(), dark); 1369cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1370cb6afcb1SStephan Aßmus BPoint(frame.right, frame.top + 1), ldark); 1371cb6afcb1SStephan Aßmus AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 1372cb6afcb1SStephan Aßmus } else if (fBarView->AcrossTop() || fBarView->AcrossBottom()) { 1373cb6afcb1SStephan Aßmus AddLine(frame.LeftTop(), 1374cb6afcb1SStephan Aßmus BPoint(frame.left, frame.bottom), dark); 1375cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left + 1, frame.top + 1), 1376cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 1377cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right, frame.top + 2), 1378cb6afcb1SStephan Aßmus BPoint(frame.right, frame.bottom), hilite); 1379cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left + 1, frame.bottom), 1380cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom), hilite); 1381cb6afcb1SStephan Aßmus } 1382cb6afcb1SStephan Aßmus } else { 138341281cf3SAxel Dörfler if (fBarView->Vertical()) { 138441281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.RightTop(), light); 138541281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.LeftBottom(), light); 138641281cf3SAxel Dörfler AddLine(frame.RightBottom(), frame.RightTop(), hilite); 138741281cf3SAxel Dörfler } else if (fBarView->AcrossTop()) { 1388cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1389cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 139041281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 1391cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right - 1, frame.top + 2), 1392cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom - 1), hilite); 1393cb6afcb1SStephan Aßmus AddLine(frame.LeftBottom(), 1394cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom), hilite); 139541281cf3SAxel Dörfler } else if (fBarView->AcrossBottom()) { 1396cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1397cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 139841281cf3SAxel Dörfler AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 139941281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 1400cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right - 1, frame.top + 1), 1401cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom - 1), hilite); 1402cb6afcb1SStephan Aßmus } 140341281cf3SAxel Dörfler } 140441281cf3SAxel Dörfler 140541281cf3SAxel Dörfler EndLineArray(); 140641281cf3SAxel Dörfler 140741281cf3SAxel Dörfler if (fDragLocation != kDontDrawDragRegion || fDragLocation != kNoDragRegion) 140841281cf3SAxel Dörfler DrawDragRegion(); 140941281cf3SAxel Dörfler } 141041281cf3SAxel Dörfler 141141281cf3SAxel Dörfler 141241281cf3SAxel Dörfler void 141341281cf3SAxel Dörfler TDragRegion::DrawDragRegion() 141441281cf3SAxel Dörfler { 141541281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 141641281cf3SAxel Dörfler 1417cb6afcb1SStephan Aßmus rgb_color menuColor = ViewColor(); 1418cb6afcb1SStephan Aßmus rgb_color menuHilite = menuColor; 141941281cf3SAxel Dörfler if (IsTracking()) { 14201bb2e623SJohn Scipione // draw drag region highlighted if tracking mouse 1421cb6afcb1SStephan Aßmus menuHilite = tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT); 142241281cf3SAxel Dörfler SetHighColor(menuHilite); 142341281cf3SAxel Dörfler FillRect(dragRegion); 14241bb2e623SJohn Scipione } else { 14251bb2e623SJohn Scipione SetHighColor(menuColor); 14261bb2e623SJohn Scipione FillRect(dragRegion); 142741281cf3SAxel Dörfler } 14281bb2e623SJohn Scipione 1429cb6afcb1SStephan Aßmus rgb_color vdark = tint_color(menuHilite, B_DARKEN_3_TINT); 1430cb6afcb1SStephan Aßmus rgb_color light = tint_color(menuHilite, B_LIGHTEN_2_TINT); 1431cb6afcb1SStephan Aßmus 1432cb6afcb1SStephan Aßmus BeginLineArray(dragRegion.IntegerHeight()); 1433e4d65fe7SJohn Scipione BPoint where; 1434e4d65fe7SJohn Scipione where.x = floorf((dragRegion.left + dragRegion.right) / 2 + 0.5) - 1; 1435e4d65fe7SJohn Scipione where.y = dragRegion.top + 2; 1436cb6afcb1SStephan Aßmus 1437e4d65fe7SJohn Scipione while (where.y + 1 <= dragRegion.bottom) { 1438e4d65fe7SJohn Scipione AddLine(where, where, vdark); 1439e4d65fe7SJohn Scipione AddLine(where + BPoint(1, 1), where + BPoint(1, 1), light); 144041281cf3SAxel Dörfler 1441e4d65fe7SJohn Scipione where.y += 3; 144241281cf3SAxel Dörfler } 144341281cf3SAxel Dörfler EndLineArray(); 144441281cf3SAxel Dörfler } 144541281cf3SAxel Dörfler 144641281cf3SAxel Dörfler 144741281cf3SAxel Dörfler BRect 144841281cf3SAxel Dörfler TDragRegion::DragRegion() const 144941281cf3SAxel Dörfler { 1450cb6afcb1SStephan Aßmus float kTopBottomInset = 2; 1451cb6afcb1SStephan Aßmus float kLeftRightInset = 1; 1452cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 1453cb6afcb1SStephan Aßmus kTopBottomInset = 1; 1454cb6afcb1SStephan Aßmus kLeftRightInset = 0; 1455cb6afcb1SStephan Aßmus } 1456cb6afcb1SStephan Aßmus 145741281cf3SAxel Dörfler BRect dragRegion(Bounds()); 1458cb6afcb1SStephan Aßmus dragRegion.top += kTopBottomInset; 1459cb6afcb1SStephan Aßmus dragRegion.bottom -= kTopBottomInset; 146041281cf3SAxel Dörfler 146141281cf3SAxel Dörfler bool placeOnLeft = false; 146241281cf3SAxel Dörfler if (fDragLocation == kAutoPlaceDragRegion) { 146341281cf3SAxel Dörfler if (fBarView->Vertical() && fBarView->Left()) 146441281cf3SAxel Dörfler placeOnLeft = true; 146541281cf3SAxel Dörfler else 146641281cf3SAxel Dörfler placeOnLeft = false; 14671bb2e623SJohn Scipione } else 14681bb2e623SJohn Scipione placeOnLeft = fDragLocation == kDragRegionLeft; 146941281cf3SAxel Dörfler 147041281cf3SAxel Dörfler if (placeOnLeft) { 1471cb6afcb1SStephan Aßmus dragRegion.left += kLeftRightInset; 1472cb6afcb1SStephan Aßmus dragRegion.right = dragRegion.left + kDragWidth; 147341281cf3SAxel Dörfler } else { 14741bb2e623SJohn Scipione dragRegion.right += kLeftRightInset; 1475cb6afcb1SStephan Aßmus dragRegion.left = dragRegion.right - kDragWidth; 147641281cf3SAxel Dörfler } 147741281cf3SAxel Dörfler 147841281cf3SAxel Dörfler return dragRegion; 147941281cf3SAxel Dörfler } 148041281cf3SAxel Dörfler 148141281cf3SAxel Dörfler 148241281cf3SAxel Dörfler void 1483e4d65fe7SJohn Scipione TDragRegion::MouseDown(BPoint where) 148441281cf3SAxel Dörfler { 1485e9632898SAlex Smith uint32 buttons; 1486e4d65fe7SJohn Scipione BPoint mouseLoc; 148741281cf3SAxel Dörfler 1488e4d65fe7SJohn Scipione BRect dragRegion(DragRegion()); 14891bb2e623SJohn Scipione dragRegion.InsetBy(-2, -2); 14907da06231SAxel Dörfler // DragRegion() is designed for drawing, not clicking 149141281cf3SAxel Dörfler 1492e4d65fe7SJohn Scipione if (!dragRegion.Contains(where)) 149341281cf3SAxel Dörfler return; 149441281cf3SAxel Dörfler 149541281cf3SAxel Dörfler while (true) { 1496e4d65fe7SJohn Scipione GetMouse(&mouseLoc, &buttons); 1497e4d65fe7SJohn Scipione if (buttons == 0) 149841281cf3SAxel Dörfler break; 149941281cf3SAxel Dörfler 150041281cf3SAxel Dörfler if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) != 0) { 1501e4d65fe7SJohn Scipione fPreviousPosition = where; 150241281cf3SAxel Dörfler SetTracking(true); 150341281cf3SAxel Dörfler SetMouseEventMask(B_POINTER_EVENTS, 150441281cf3SAxel Dörfler B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); 150541281cf3SAxel Dörfler Invalidate(DragRegion()); 150641281cf3SAxel Dörfler break; 150741281cf3SAxel Dörfler } 150841281cf3SAxel Dörfler 150941281cf3SAxel Dörfler snooze(25000); 151041281cf3SAxel Dörfler } 151141281cf3SAxel Dörfler } 151241281cf3SAxel Dörfler 151341281cf3SAxel Dörfler 151441281cf3SAxel Dörfler void 1515e4d65fe7SJohn Scipione TDragRegion::MouseUp(BPoint where) 151641281cf3SAxel Dörfler { 151741281cf3SAxel Dörfler if (IsTracking()) { 151841281cf3SAxel Dörfler SetTracking(false); 151941281cf3SAxel Dörfler Invalidate(DragRegion()); 152041281cf3SAxel Dörfler } else 1521e4d65fe7SJohn Scipione BControl::MouseUp(where); 152241281cf3SAxel Dörfler } 152341281cf3SAxel Dörfler 152441281cf3SAxel Dörfler 152541281cf3SAxel Dörfler bool 1526e4d65fe7SJohn Scipione TDragRegion::SwitchModeForRect(BPoint where, BRect rect, 152741281cf3SAxel Dörfler bool newVertical, bool newLeft, bool newTop, int32 newState) 152841281cf3SAxel Dörfler { 1529e4d65fe7SJohn Scipione if (!rect.Contains(where)) { 153041281cf3SAxel Dörfler // not our rect 153141281cf3SAxel Dörfler return false; 15321ad8c760SFredrik Holmqvist } 153341281cf3SAxel Dörfler 15341ad8c760SFredrik Holmqvist if (newVertical == fBarView->Vertical() && newLeft == fBarView->Left() 15351ad8c760SFredrik Holmqvist && newTop == fBarView->Top() && newState == fBarView->State()) { 153641281cf3SAxel Dörfler // already in the correct mode 153741281cf3SAxel Dörfler return true; 15381ad8c760SFredrik Holmqvist } 153941281cf3SAxel Dörfler 1540d7ed9414SRene Gollent fBarView->ChangeState(newState, newVertical, newLeft, newTop, true); 1541e4d65fe7SJohn Scipione 154241281cf3SAxel Dörfler return true; 154341281cf3SAxel Dörfler } 154441281cf3SAxel Dörfler 154541281cf3SAxel Dörfler 154641281cf3SAxel Dörfler void 154741281cf3SAxel Dörfler TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage* message) 154841281cf3SAxel Dörfler { 154941281cf3SAxel Dörfler if (IsTracking()) { 155041281cf3SAxel Dörfler BScreen screen; 155141281cf3SAxel Dörfler BRect frame = screen.Frame(); 155241281cf3SAxel Dörfler 155341281cf3SAxel Dörfler float hDivider = frame.Width() / 6; 15541bb2e623SJohn Scipione hDivider = (hDivider < gMinimumWindowWidth + 10) 15551bb2e623SJohn Scipione ? gMinimumWindowWidth + 10 : hDivider; 15561bb2e623SJohn Scipione float miniDivider = frame.top + kMiniHeight + 10; 155741281cf3SAxel Dörfler float vDivider = frame.Height() / 2; 155841281cf3SAxel Dörfler #ifdef FULL_MODE 155941281cf3SAxel Dörfler float thirdScreen = frame.Height() / 3; 156041281cf3SAxel Dörfler #endif 156171bd3ba5SJonas Sundström BRect topLeft(frame.left, frame.top, frame.left + hDivider, 156271bd3ba5SJonas Sundström miniDivider); 156371bd3ba5SJonas Sundström BRect topMiddle(frame.left + hDivider, frame.top, frame.right 156471bd3ba5SJonas Sundström - hDivider, vDivider); 156571bd3ba5SJonas Sundström BRect topRight(frame.right - hDivider, frame.top, frame.right, 156671bd3ba5SJonas Sundström miniDivider); 156741281cf3SAxel Dörfler 156841281cf3SAxel Dörfler #ifdef FULL_MODE 156941281cf3SAxel Dörfler vDivider = miniDivider + thirdScreen; 157041281cf3SAxel Dörfler #endif 157171bd3ba5SJonas Sundström BRect middleLeft(frame.left, miniDivider, frame.left + hDivider, 157271bd3ba5SJonas Sundström vDivider); 157371bd3ba5SJonas Sundström BRect middleRight(frame.right - hDivider, miniDivider, frame.right, 157471bd3ba5SJonas Sundström vDivider); 157541281cf3SAxel Dörfler 157641281cf3SAxel Dörfler #ifdef FULL_MODE 157771bd3ba5SJonas Sundström BRect leftSide(frame.left, vDivider, frame.left + hDivider, 157871bd3ba5SJonas Sundström frame.bottom - thirdScreen); 157971bd3ba5SJonas Sundström BRect rightSide(frame.right - hDivider, vDivider, frame.right, 158071bd3ba5SJonas Sundström frame.bottom - thirdScreen); 158141281cf3SAxel Dörfler 158241281cf3SAxel Dörfler vDivider = frame.bottom - thirdScreen; 158341281cf3SAxel Dörfler #endif 158471bd3ba5SJonas Sundström BRect bottomLeft(frame.left, vDivider, frame.left + hDivider, 158571bd3ba5SJonas Sundström frame.bottom); 158671bd3ba5SJonas Sundström BRect bottomMiddle(frame.left + hDivider, vDivider, frame.right 158771bd3ba5SJonas Sundström - hDivider, frame.bottom); 158871bd3ba5SJonas Sundström BRect bottomRight(frame.right - hDivider, vDivider, frame.right, 158971bd3ba5SJonas Sundström frame.bottom); 159041281cf3SAxel Dörfler 159141281cf3SAxel Dörfler if (where != fPreviousPosition) { 159241281cf3SAxel Dörfler fPreviousPosition = where; 159341281cf3SAxel Dörfler ConvertToScreen(&where); 159441281cf3SAxel Dörfler 159541281cf3SAxel Dörfler // use short circuit evaluation for convenience 159641281cf3SAxel Dörfler if (SwitchModeForRect(where, topLeft, true, true, true, kMiniState) 159771bd3ba5SJonas Sundström || SwitchModeForRect(where, topMiddle, false, true, true, 159871bd3ba5SJonas Sundström kExpandoState) 159971bd3ba5SJonas Sundström || SwitchModeForRect(where, topRight, true, false, true, 160071bd3ba5SJonas Sundström kMiniState) 160171bd3ba5SJonas Sundström || SwitchModeForRect(where, middleLeft, true, true, true, 160271bd3ba5SJonas Sundström kExpandoState) 160371bd3ba5SJonas Sundström || SwitchModeForRect(where, middleRight, true, false, true, 160471bd3ba5SJonas Sundström kExpandoState) 160541281cf3SAxel Dörfler 160641281cf3SAxel Dörfler #ifdef FULL_MODE 160771bd3ba5SJonas Sundström || SwitchModeForRect(where, leftSide, true, true, true, 160871bd3ba5SJonas Sundström kFullState) 160971bd3ba5SJonas Sundström || SwitchModeForRect(where, rightSide, true, false, true, 161071bd3ba5SJonas Sundström kFullState) 161141281cf3SAxel Dörfler #endif 161271bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomLeft, true, true, false, 161371bd3ba5SJonas Sundström kMiniState) 161471bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomMiddle, false, true, false, 161571bd3ba5SJonas Sundström kExpandoState) 161671bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomRight, true, false, false, 161771bd3ba5SJonas Sundström kMiniState)) 161841281cf3SAxel Dörfler ; 161941281cf3SAxel Dörfler } 162041281cf3SAxel Dörfler } else 162141281cf3SAxel Dörfler BControl::MouseMoved(where, code, message); 162241281cf3SAxel Dörfler } 162341281cf3SAxel Dörfler 162441281cf3SAxel Dörfler 162541281cf3SAxel Dörfler int32 162641281cf3SAxel Dörfler TDragRegion::DragRegionLocation() const 162741281cf3SAxel Dörfler { 162841281cf3SAxel Dörfler return fDragLocation; 162941281cf3SAxel Dörfler } 163041281cf3SAxel Dörfler 163141281cf3SAxel Dörfler 163241281cf3SAxel Dörfler void 163341281cf3SAxel Dörfler TDragRegion::SetDragRegionLocation(int32 location) 163441281cf3SAxel Dörfler { 163541281cf3SAxel Dörfler if (location == fDragLocation) 163641281cf3SAxel Dörfler return; 163741281cf3SAxel Dörfler 163841281cf3SAxel Dörfler fDragLocation = location; 163941281cf3SAxel Dörfler Invalidate(); 164041281cf3SAxel Dörfler } 16411bb2e623SJohn Scipione 16421bb2e623SJohn Scipione 16431bb2e623SJohn Scipione // #pragma mark - TResizeControl 16441bb2e623SJohn Scipione 16451bb2e623SJohn Scipione 16461bb2e623SJohn Scipione /*! Draggable region that is asynchronous so that resizing does not block. 16471bb2e623SJohn Scipione */ 16481bb2e623SJohn Scipione TResizeControl::TResizeControl(TBarView* barView) 16491bb2e623SJohn Scipione : 16501bb2e623SJohn Scipione BControl(BRect(0, kDragWidth, 0, kMenuBarHeight), "", "", NULL, 16511bb2e623SJohn Scipione B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS), 16521bb2e623SJohn Scipione fBarView(barView) 16531bb2e623SJohn Scipione { 16541bb2e623SJohn Scipione } 16551bb2e623SJohn Scipione 16561bb2e623SJohn Scipione 16571bb2e623SJohn Scipione TResizeControl::~TResizeControl() 16581bb2e623SJohn Scipione { 16591bb2e623SJohn Scipione } 16601bb2e623SJohn Scipione 16611bb2e623SJohn Scipione 16621bb2e623SJohn Scipione void 16631bb2e623SJohn Scipione TResizeControl::AttachedToWindow() 16641bb2e623SJohn Scipione { 16651bb2e623SJohn Scipione BView::AttachedToWindow(); 16661bb2e623SJohn Scipione 16671bb2e623SJohn Scipione if (be_control_look != NULL) 16681bb2e623SJohn Scipione SetViewUIColor(B_MENU_BACKGROUND_COLOR, 1.1); 16691bb2e623SJohn Scipione else 16701bb2e623SJohn Scipione SetViewUIColor(B_MENU_BACKGROUND_COLOR); 16711bb2e623SJohn Scipione } 16721bb2e623SJohn Scipione 16731bb2e623SJohn Scipione 16741bb2e623SJohn Scipione void 16751bb2e623SJohn Scipione TResizeControl::Draw(BRect updateRect) 16761bb2e623SJohn Scipione { 16771bb2e623SJohn Scipione if (!fBarView->Vertical()) 16781bb2e623SJohn Scipione return; 16791bb2e623SJohn Scipione 1680092e918bSJohn Scipione BRect dragRegion(Bounds()); 16811bb2e623SJohn Scipione 168200171c6fSJohn Scipione int32 height = dragRegion.IntegerHeight(); 168300171c6fSJohn Scipione if (height <= 0) 168400171c6fSJohn Scipione return; 168500171c6fSJohn Scipione 16861bb2e623SJohn Scipione rgb_color menuColor = ViewColor(); 16871bb2e623SJohn Scipione rgb_color menuHilite = menuColor; 16881bb2e623SJohn Scipione if (IsTracking()) { 16891bb2e623SJohn Scipione // draw drag region highlighted if tracking mouse 16901bb2e623SJohn Scipione menuHilite = tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT); 16911bb2e623SJohn Scipione SetHighColor(menuHilite); 16921bb2e623SJohn Scipione FillRect(dragRegion); 16931bb2e623SJohn Scipione } else { 16941bb2e623SJohn Scipione SetHighColor(menuColor); 16951bb2e623SJohn Scipione FillRect(dragRegion); 16961bb2e623SJohn Scipione } 16971bb2e623SJohn Scipione 16981bb2e623SJohn Scipione rgb_color vdark = tint_color(menuHilite, B_DARKEN_3_TINT); 16991bb2e623SJohn Scipione rgb_color light = tint_color(menuHilite, B_LIGHTEN_2_TINT); 17001bb2e623SJohn Scipione 170100171c6fSJohn Scipione BeginLineArray(height); 17021bb2e623SJohn Scipione BPoint where; 17031bb2e623SJohn Scipione where.x = floorf((dragRegion.left + dragRegion.right) / 2 + 0.5) - 1; 17041bb2e623SJohn Scipione where.y = dragRegion.top + 2; 17051bb2e623SJohn Scipione 17061bb2e623SJohn Scipione while (where.y + 1 <= dragRegion.bottom) { 17071bb2e623SJohn Scipione AddLine(where, where, vdark); 17081bb2e623SJohn Scipione AddLine(where + BPoint(1, 1), where + BPoint(1, 1), light); 17091bb2e623SJohn Scipione 17101bb2e623SJohn Scipione where.y += 3; 17111bb2e623SJohn Scipione } 17121bb2e623SJohn Scipione EndLineArray(); 17131bb2e623SJohn Scipione } 17141bb2e623SJohn Scipione 17151bb2e623SJohn Scipione 17161bb2e623SJohn Scipione void 17171bb2e623SJohn Scipione TResizeControl::MouseDown(BPoint where) 17181bb2e623SJohn Scipione { 17191bb2e623SJohn Scipione uint32 buttons; 17201bb2e623SJohn Scipione BPoint mouseLoc; 17211bb2e623SJohn Scipione 17221bb2e623SJohn Scipione while (true) { 17231bb2e623SJohn Scipione GetMouse(&mouseLoc, &buttons); 17241bb2e623SJohn Scipione if (buttons == 0) 17251bb2e623SJohn Scipione break; 17261bb2e623SJohn Scipione 17271bb2e623SJohn Scipione if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) != 0) { 17281bb2e623SJohn Scipione SetTracking(true); 17291bb2e623SJohn Scipione SetMouseEventMask(B_POINTER_EVENTS, 17301bb2e623SJohn Scipione B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); 17311bb2e623SJohn Scipione Invalidate(); 17321bb2e623SJohn Scipione break; 17331bb2e623SJohn Scipione } 17341bb2e623SJohn Scipione 17351bb2e623SJohn Scipione snooze(25000); 17361bb2e623SJohn Scipione } 17371bb2e623SJohn Scipione } 17381bb2e623SJohn Scipione 17391bb2e623SJohn Scipione 17401bb2e623SJohn Scipione void 17411bb2e623SJohn Scipione TResizeControl::MouseUp(BPoint where) 17421bb2e623SJohn Scipione { 17431bb2e623SJohn Scipione if (IsTracking()) { 17441bb2e623SJohn Scipione SetTracking(false); 17451bb2e623SJohn Scipione Invalidate(); 17461bb2e623SJohn Scipione } else 17471bb2e623SJohn Scipione BControl::MouseUp(where); 17481bb2e623SJohn Scipione } 17491bb2e623SJohn Scipione 17501bb2e623SJohn Scipione 17511bb2e623SJohn Scipione void 17521bb2e623SJohn Scipione TResizeControl::MouseMoved(BPoint where, uint32 code, 17531bb2e623SJohn Scipione const BMessage* dragMessage) 17541bb2e623SJohn Scipione { 17551bb2e623SJohn Scipione if (fBarView->Vertical()) { 17561bb2e623SJohn Scipione if (IsResizing()) { 17571bb2e623SJohn Scipione float windowWidth = Window()->Frame().Width(); 17581bb2e623SJohn Scipione float delta = 0; 17591bb2e623SJohn Scipione BPoint whereScreen = ConvertToScreen(where); 17601bb2e623SJohn Scipione 17611bb2e623SJohn Scipione if (fBarView->Left()) { 17621bb2e623SJohn Scipione delta = whereScreen.x - Window()->Frame().right; 17631bb2e623SJohn Scipione if (delta > 0 && windowWidth >= gMaximumWindowWidth) 17641bb2e623SJohn Scipione ; // do nothing 17651bb2e623SJohn Scipione else if (delta < 0 && windowWidth <= gMinimumWindowWidth) 17661bb2e623SJohn Scipione ; // do nothing 17671bb2e623SJohn Scipione else 17681bb2e623SJohn Scipione Window()->ResizeBy(delta, 0); 17691bb2e623SJohn Scipione } else { 17701bb2e623SJohn Scipione delta = Window()->Frame().left - whereScreen.x; 17711bb2e623SJohn Scipione if (delta > 0 && windowWidth >= gMaximumWindowWidth) 17721bb2e623SJohn Scipione ; // do nothing 17731bb2e623SJohn Scipione else if (delta < 0 && windowWidth <= gMinimumWindowWidth) 17741bb2e623SJohn Scipione ; // do nothing 17751bb2e623SJohn Scipione else { 17761bb2e623SJohn Scipione Window()->MoveBy(delta, 0); 17771bb2e623SJohn Scipione Window()->ResizeBy(delta, 0); 17781bb2e623SJohn Scipione } 17791bb2e623SJohn Scipione } 17801bb2e623SJohn Scipione 17811bb2e623SJohn Scipione windowWidth = Window()->Frame().Width(); 17821bb2e623SJohn Scipione } 17831bb2e623SJohn Scipione } 17841bb2e623SJohn Scipione 17851bb2e623SJohn Scipione BControl::MouseMoved(where, code, dragMessage); 17861bb2e623SJohn Scipione } 1787