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 786d01b66dSAxel Dörfler using std::max; 7941281cf3SAxel Dörfler 8041281cf3SAxel Dörfler #ifdef DB_ADDONS 8141281cf3SAxel Dörfler // Add-on support 8241281cf3SAxel Dörfler // 8341281cf3SAxel Dörfler // Item - internal item list (node, eref, etc) 8441281cf3SAxel Dörfler // Icon - physical replicant handed to the DeskbarClass class 8541281cf3SAxel Dörfler // AddOn - attribute based add-on 8641281cf3SAxel Dörfler 8741281cf3SAxel Dörfler const char* const kInstantiateItemCFunctionName = "instantiate_deskbar_item"; 8841281cf3SAxel Dörfler const char* const kInstantiateEntryCFunctionName = "instantiate_deskbar_entry"; 8926ea7066SIngo Weinhold const char* const kReplicantSettingsFile = "replicants"; 90c0ad1c91SRene Gollent const char* const kReplicantPathField = "replicant_path"; 9141281cf3SAxel Dörfler 92b49e806dSAxel Dörfler float gMinimumWindowWidth = kGutter + kMinimumTrayWidth + kDragRegionWidth; 93cb6afcb1SStephan Aßmus 9441281cf3SAxel Dörfler 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), 138cb6afcb1SStephan Aßmus fMinimumTrayWidth(kMinimumTrayWidth), 13941281cf3SAxel Dörfler fAlignmentSupport(false) 14041281cf3SAxel Dörfler { 141cb6afcb1SStephan Aßmus // init the minimum window width according to the logo. 142cb6afcb1SStephan Aßmus const BBitmap* logoBitmap = AppResSet()->FindBitmap(B_MESSAGE_TYPE, 1439e8a970bSJonas Sundström R_LeafLogoBitmap); 144cb6afcb1SStephan Aßmus if (logoBitmap != NULL) { 145b49e806dSAxel Dörfler gMinimumWindowWidth = std::max(gMinimumWindowWidth, 146cb6afcb1SStephan Aßmus 2 * (logoBitmap->Bounds().Width() + 8)); 147cb6afcb1SStephan Aßmus } 148fb956f25SAxel Dörfler gMinimumWindowWidth = std::max(gMinimumWindowWidth, 149fb956f25SAxel Dörfler be_plain_font->StringWidth("WWWWWWWWW") + 20); 150fb956f25SAxel Dörfler if (vertical) 151fb956f25SAxel Dörfler fMinimumTrayWidth = gMinimumWindowWidth - kGutter - kDragRegionWidth; 152573f748cSJohn Scipione 153573f748cSJohn Scipione // Create the time view 15431c0024dSJohn Scipione fTime = new TTimeView(fMinimumTrayWidth, kMaxReplicantHeight - 1.0); 15541281cf3SAxel Dörfler } 15641281cf3SAxel Dörfler 15741281cf3SAxel Dörfler 15841281cf3SAxel Dörfler TReplicantTray::~TReplicantTray() 15941281cf3SAxel Dörfler { 16041281cf3SAxel Dörfler delete fShelf; 161573f748cSJohn Scipione delete fTime; 16241281cf3SAxel Dörfler } 16341281cf3SAxel Dörfler 16441281cf3SAxel Dörfler 16541281cf3SAxel Dörfler void 16641281cf3SAxel Dörfler TReplicantTray::AttachedToWindow() 16741281cf3SAxel Dörfler { 16841281cf3SAxel Dörfler BView::AttachedToWindow(); 16941281cf3SAxel Dörfler 170*16c10517Slooncraz float tint = B_NO_TINT; 171*16c10517Slooncraz 172cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 173*16c10517Slooncraz SetViewUIColor(Parent()->ViewUIColor(&tint), tint); 174cb6afcb1SStephan Aßmus } else { 175*16c10517Slooncraz SetViewUIColor(B_MENU_BACKGROUND_COLOR, B_DARKEN_1_TINT); 176cb6afcb1SStephan Aßmus } 17741281cf3SAxel Dörfler SetDrawingMode(B_OP_COPY); 17866eba86fSAxel Dörfler 17941281cf3SAxel Dörfler Window()->SetPulseRate(1000000); 18041281cf3SAxel Dörfler 1813722e640SJohn Scipione clock_settings* clock = ((TBarApp*)be_app)->ClockSettings(); 1823722e640SJohn Scipione fTime->SetShowSeconds(clock->showSeconds); 1833722e640SJohn Scipione fTime->SetShowDayOfWeek(clock->showDayOfWeek); 1843722e640SJohn Scipione fTime->SetShowTimeZone(clock->showTimeZone); 18531c0024dSJohn Scipione 186573f748cSJohn Scipione AddChild(fTime); 187573f748cSJohn Scipione fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - 1, 2); 188ae7a6e3aSAdrien Destugues 1893722e640SJohn Scipione if (!((TBarApp*)be_app)->Settings()->showClock) 1903722e640SJohn Scipione fTime->Hide(); 1913722e640SJohn Scipione 19241281cf3SAxel Dörfler #ifdef DB_ADDONS 19341281cf3SAxel Dörfler // load addons and rehydrate archives 1943a6add49SAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 19541281cf3SAxel Dörfler InitAddOnSupport(); 19641281cf3SAxel Dörfler #endif 1979c910f9eSStephan Aßmus #endif 19841281cf3SAxel Dörfler ResizeToPreferred(); 19941281cf3SAxel Dörfler } 20041281cf3SAxel Dörfler 20141281cf3SAxel Dörfler 20241281cf3SAxel Dörfler void 20341281cf3SAxel Dörfler TReplicantTray::DetachedFromWindow() 20441281cf3SAxel Dörfler { 20541281cf3SAxel Dörfler #ifdef DB_ADDONS 20641281cf3SAxel Dörfler // clean up add-on support 207465b54cdSAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 20841281cf3SAxel Dörfler DeleteAddOnSupport(); 20941281cf3SAxel Dörfler #endif 210465b54cdSAxel Dörfler #endif 21141281cf3SAxel Dörfler BView::DetachedFromWindow(); 21241281cf3SAxel Dörfler } 21341281cf3SAxel Dörfler 21441281cf3SAxel Dörfler 2151ad8c760SFredrik Holmqvist /*! Width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth 21666eba86fSAxel Dörfler if not in multirowmode and greater than kMinimumReplicantCount 2172ce9bab8SJohn Scipione the width should be calculated based on the actual replicant widths 21841281cf3SAxel Dörfler */ 21941281cf3SAxel Dörfler void 22041281cf3SAxel Dörfler TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight) 22141281cf3SAxel Dörfler { 22241281cf3SAxel Dörfler float width = 0, height = kMinimumTrayHeight; 22341281cf3SAxel Dörfler 22441281cf3SAxel Dörfler if (fMultiRowMode) { 2257da06231SAxel Dörfler if (fShelf->CountReplicants() > 0) 2267da06231SAxel Dörfler height = fRightBottomReplicant.bottom; 22741281cf3SAxel Dörfler 2281ad8c760SFredrik Holmqvist // the height will be uniform for the number of rows necessary to show 2291ad8c760SFredrik Holmqvist // all the reps + any gutters necessary for spacing 23041281cf3SAxel Dörfler int32 rowCount = (int32)(height / kMaxReplicantHeight); 23141281cf3SAxel Dörfler height = kGutter + (rowCount * kMaxReplicantHeight) 23241281cf3SAxel Dörfler + ((rowCount - 1) * kIconGap) + kGutter; 23341281cf3SAxel Dörfler height = max(kMinimumTrayHeight, height); 234cb6afcb1SStephan Aßmus width = fMinimumTrayWidth; 23541281cf3SAxel Dörfler } else { 2361ad8c760SFredrik Holmqvist // if last replicant overruns clock then resize to accomodate 2377da06231SAxel Dörfler if (fShelf->CountReplicants() > 0) { 238573f748cSJohn Scipione if (!fTime->IsHidden() && fTime->Frame().left 239573f748cSJohn Scipione < fRightBottomReplicant.right + 6) { 24066eba86fSAxel Dörfler width = fRightBottomReplicant.right + 6 241573f748cSJohn Scipione + fTime->Frame().Width(); 24241281cf3SAxel Dörfler } else 2437da06231SAxel Dörfler width = fRightBottomReplicant.right + 3; 24441281cf3SAxel Dörfler } 2451ad8c760SFredrik Holmqvist 24641281cf3SAxel Dörfler // this view has a fixed minimum width 247cb6afcb1SStephan Aßmus width = max(fMinimumTrayWidth, width); 2482ce9bab8SJohn Scipione height = kGutter + static_cast<TBarApp*>(be_app)->IconSize() + kGutter; 24941281cf3SAxel Dörfler } 25041281cf3SAxel Dörfler 25141281cf3SAxel Dörfler *preferredWidth = width; 2521ad8c760SFredrik Holmqvist // add 1 for the border 25341281cf3SAxel Dörfler *preferredHeight = height + 1; 25441281cf3SAxel Dörfler } 25541281cf3SAxel Dörfler 25641281cf3SAxel Dörfler 25741281cf3SAxel Dörfler void 25841281cf3SAxel Dörfler TReplicantTray::AdjustPlacement() 25941281cf3SAxel Dörfler { 26041281cf3SAxel Dörfler // called when an add-on has been added or removed 26141281cf3SAxel Dörfler // need to resize the parent of this accordingly 262a5210ab1SAxel Dörfler 26341281cf3SAxel Dörfler BRect bounds = Bounds(); 26441281cf3SAxel Dörfler float width, height; 26541281cf3SAxel Dörfler GetPreferredSize(&width, &height); 26641281cf3SAxel Dörfler 26741281cf3SAxel Dörfler if (width == bounds.Width() && height == bounds.Height()) { 26841281cf3SAxel Dörfler // no need to change anything 26941281cf3SAxel Dörfler return; 27041281cf3SAxel Dörfler } 27141281cf3SAxel Dörfler 27241281cf3SAxel Dörfler Parent()->ResizeToPreferred(); 27341281cf3SAxel Dörfler fBarView->UpdatePlacement(); 27441281cf3SAxel Dörfler Parent()->Invalidate(); 27541281cf3SAxel Dörfler Invalidate(); 27641281cf3SAxel Dörfler } 27741281cf3SAxel Dörfler 27841281cf3SAxel Dörfler 27941281cf3SAxel Dörfler void 28041281cf3SAxel Dörfler TReplicantTray::MessageReceived(BMessage* message) 28141281cf3SAxel Dörfler { 28241281cf3SAxel Dörfler switch (message->what) { 28330a55802SJohn Scipione case B_LOCALE_CHANGED: 284573f748cSJohn Scipione { 285573f748cSJohn Scipione if (fTime == NULL) 286573f748cSJohn Scipione return; 287573f748cSJohn Scipione 28831c0024dSJohn Scipione fTime->Update(); 28930a55802SJohn Scipione 29041281cf3SAxel Dörfler // time string reformat -> realign 29141281cf3SAxel Dörfler RealignReplicants(); 29241281cf3SAxel Dörfler AdjustPlacement(); 29341281cf3SAxel Dörfler break; 294573f748cSJohn Scipione } 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 3083cf2d117SJohn Scipione RealignReplicants(); 3093cf2d117SJohn Scipione AdjustPlacement(); 310573f748cSJohn Scipione break; 3113cf2d117SJohn Scipione 3123cf2d117SJohn Scipione case kShowDayOfWeek: 3133cf2d117SJohn Scipione if (fTime == NULL) 3143cf2d117SJohn Scipione return; 3153cf2d117SJohn Scipione 3163cf2d117SJohn Scipione fTime->SetShowDayOfWeek(!fTime->ShowDayOfWeek()); 3173cf2d117SJohn Scipione 3183cf2d117SJohn Scipione // time string reformat -> realign 3193cf2d117SJohn Scipione RealignReplicants(); 3203cf2d117SJohn Scipione AdjustPlacement(); 3213cf2d117SJohn Scipione break; 3223cf2d117SJohn Scipione 32331c0024dSJohn Scipione case kShowTimeZone: 32431c0024dSJohn Scipione if (fTime == NULL) 32531c0024dSJohn Scipione return; 32631c0024dSJohn Scipione 32731c0024dSJohn Scipione fTime->SetShowTimeZone(!fTime->ShowTimeZone()); 32831c0024dSJohn Scipione 32931c0024dSJohn Scipione // time string reformat -> realign 33031c0024dSJohn Scipione RealignReplicants(); 33131c0024dSJohn Scipione AdjustPlacement(); 33231c0024dSJohn Scipione break; 33331c0024dSJohn Scipione 33431c0024dSJohn Scipione case kGetClockSettings: 33531c0024dSJohn Scipione { 33631c0024dSJohn Scipione if (fTime == NULL) 33731c0024dSJohn Scipione return; 33831c0024dSJohn Scipione 33931c0024dSJohn Scipione bool showClock = !fTime->IsHidden(); 34031c0024dSJohn Scipione bool showSeconds = fTime->ShowSeconds(); 34131c0024dSJohn Scipione bool showDayOfWeek = fTime->ShowDayOfWeek(); 34231c0024dSJohn Scipione bool showTimeZone = fTime->ShowTimeZone(); 34331c0024dSJohn Scipione 3440fc30d89SDario Casalinuovo BMessage reply(kGetClockSettings); 3450fc30d89SDario Casalinuovo reply.AddBool("showClock", showClock); 3460fc30d89SDario Casalinuovo reply.AddBool("showSeconds", showSeconds); 3470fc30d89SDario Casalinuovo reply.AddBool("showDayOfWeek", showDayOfWeek); 3480fc30d89SDario Casalinuovo reply.AddBool("showTimeZone", showTimeZone); 3490fc30d89SDario Casalinuovo message->SendReply(&reply); 35031c0024dSJohn Scipione break; 35131c0024dSJohn Scipione } 35231c0024dSJohn Scipione 35341281cf3SAxel Dörfler #ifdef DB_ADDONS 35441281cf3SAxel Dörfler case B_NODE_MONITOR: 35541281cf3SAxel Dörfler HandleEntryUpdate(message); 35641281cf3SAxel Dörfler break; 35741281cf3SAxel Dörfler #endif 35841281cf3SAxel Dörfler 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 4133cf2d117SJohn Scipione if (!fTime->IsHidden()) 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 4543722e640SJohn Scipione ((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 58741281cf3SAxel Dörfler if (!name) 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 { 62841281cf3SAxel Dörfler if (!entry) 62941281cf3SAxel Dörfler return B_ERROR; 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); 64066eba86fSAxel Dörfler 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 65241281cf3SAxel Dörfler BView* (*entryFunction)(image_id, const entry_ref*); 65341281cf3SAxel Dörfler BView* (*itemFunction)(void); 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) { 66141281cf3SAxel Dörfler view = (*entryFunction)(image, &ref); 66241281cf3SAxel Dörfler } else if (get_image_symbol(image, kInstantiateItemCFunctionName, 66366eba86fSAxel Dörfler B_SYMBOL_TYPE_TEXT, (void**)&itemFunction) >= B_OK) { 66441281cf3SAxel Dörfler view = (*itemFunction)(); 66541281cf3SAxel Dörfler } else { 66641281cf3SAxel Dörfler unload_add_on(image); 66741281cf3SAxel Dörfler return B_ERROR; 66841281cf3SAxel Dörfler } 66941281cf3SAxel Dörfler 67066eba86fSAxel Dörfler if (view == NULL || IconExists(view->Name())) { 67141281cf3SAxel Dörfler delete view; 67241281cf3SAxel Dörfler unload_add_on(image); 67341281cf3SAxel Dörfler return B_ERROR; 67441281cf3SAxel Dörfler } 67541281cf3SAxel Dörfler 67641281cf3SAxel Dörfler BMessage* data = new BMessage; 67741281cf3SAxel Dörfler view->Archive(data); 67841281cf3SAxel Dörfler delete view; 67941281cf3SAxel Dörfler 68041281cf3SAxel Dörfler // add the rep; adds info to list 6810fc30d89SDario Casalinuovo if (AddIcon(data, id, &ref) != B_OK) 6820fc30d89SDario Casalinuovo delete data; 68341281cf3SAxel Dörfler 6843e6ff860SRene Gollent if (addToSettings) { 685c0ad1c91SRene Gollent fAddOnSettings.AddString(kReplicantPathField, path.Path()); 6867625ce51SRene Gollent _SaveSettings(); 6873e6ff860SRene Gollent } 68841281cf3SAxel Dörfler 68941281cf3SAxel Dörfler return B_OK; 69041281cf3SAxel Dörfler } 69141281cf3SAxel Dörfler 69241281cf3SAxel Dörfler 69341281cf3SAxel Dörfler status_t 69441281cf3SAxel Dörfler TReplicantTray::AddItem(int32 id, node_ref nodeRef, BEntry& entry, bool isAddOn) 69541281cf3SAxel Dörfler { 69641281cf3SAxel Dörfler DeskbarItemInfo* item = new DeskbarItemInfo; 69741281cf3SAxel Dörfler if (item == NULL) 69841281cf3SAxel Dörfler return B_NO_MEMORY; 69941281cf3SAxel Dörfler 70041281cf3SAxel Dörfler item->id = id; 70141281cf3SAxel Dörfler item->isAddOn = isAddOn; 70241281cf3SAxel Dörfler 70341281cf3SAxel Dörfler if (entry.GetRef(&item->entryRef) < B_OK) { 70441281cf3SAxel Dörfler item->entryRef.device = -1; 70541281cf3SAxel Dörfler item->entryRef.directory = -1; 70641281cf3SAxel Dörfler item->entryRef.name = NULL; 70741281cf3SAxel Dörfler } 70841281cf3SAxel Dörfler item->nodeRef = nodeRef; 70941281cf3SAxel Dörfler 71041281cf3SAxel Dörfler fItemList->AddItem(item); 71141281cf3SAxel Dörfler 71241281cf3SAxel Dörfler if (isAddOn) 71341281cf3SAxel Dörfler watch_node(&nodeRef, B_WATCH_NAME | B_WATCH_ATTR, this, Window()); 71441281cf3SAxel Dörfler 71541281cf3SAxel Dörfler return B_OK; 71641281cf3SAxel Dörfler } 71741281cf3SAxel Dörfler 71841281cf3SAxel Dörfler 71941281cf3SAxel Dörfler /** from entry_removed message, when attribute removed 72041281cf3SAxel Dörfler * or when a device is unmounted (use removeall, by device) 72141281cf3SAxel Dörfler */ 72241281cf3SAxel Dörfler 72341281cf3SAxel Dörfler void 72441281cf3SAxel Dörfler TReplicantTray::UnloadAddOn(node_ref* nodeRef, dev_t* device, 72541281cf3SAxel Dörfler bool which, bool removeAll) 72641281cf3SAxel Dörfler { 7279f2cce2fSJohn Scipione for (int32 i = fItemList->CountItems() - 1; i >= 0; i--) { 72841281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 72941281cf3SAxel Dörfler if (!item) 73041281cf3SAxel Dörfler continue; 73141281cf3SAxel Dörfler 73241281cf3SAxel Dörfler if ((which && nodeRef && item->nodeRef == *nodeRef) 73341281cf3SAxel Dörfler || (device && item->nodeRef.device == *device)) { 73441281cf3SAxel Dörfler 73541281cf3SAxel Dörfler if (device && be_roster->IsRunning(&item->entryRef)) 73641281cf3SAxel Dörfler continue; 73741281cf3SAxel Dörfler 73841281cf3SAxel Dörfler RemoveIcon(item->id); 73941281cf3SAxel Dörfler 74041281cf3SAxel Dörfler if (!removeAll) 74141281cf3SAxel Dörfler break; 74241281cf3SAxel Dörfler } 74341281cf3SAxel Dörfler } 74441281cf3SAxel Dörfler } 74541281cf3SAxel Dörfler 74641281cf3SAxel Dörfler 74741281cf3SAxel Dörfler void 74841281cf3SAxel Dörfler TReplicantTray::RemoveItem(int32 id) 74941281cf3SAxel Dörfler { 75041281cf3SAxel Dörfler DeskbarItemInfo* item = DeskbarItemFor(id); 75141281cf3SAxel Dörfler if (item == NULL) 75241281cf3SAxel Dörfler return; 75341281cf3SAxel Dörfler 75441281cf3SAxel Dörfler // attribute was added via Deskbar API (AddItem(entry_ref*, int32*) 75541281cf3SAxel Dörfler if (item->isAddOn) { 7567625ce51SRene Gollent BPath path(&item->entryRef); 7577625ce51SRene Gollent BString storedPath; 7587625ce51SRene Gollent for (int32 i = 0; 7598aab28f1SRene Gollent fAddOnSettings.FindString(kReplicantPathField, i, &storedPath) 7607625ce51SRene Gollent == B_OK; i++) { 7617625ce51SRene Gollent if (storedPath == path.Path()) { 7628aab28f1SRene Gollent fAddOnSettings.RemoveData(kReplicantPathField, i); 7637625ce51SRene Gollent break; 7647625ce51SRene Gollent } 7657625ce51SRene Gollent } 7667625ce51SRene Gollent _SaveSettings(); 7677625ce51SRene Gollent 76841281cf3SAxel Dörfler BNode node(&item->entryRef); 76941281cf3SAxel Dörfler watch_node(&item->nodeRef, B_STOP_WATCHING, this, Window()); 77041281cf3SAxel Dörfler } 77141281cf3SAxel Dörfler 77241281cf3SAxel Dörfler fItemList->RemoveItem(item); 77341281cf3SAxel Dörfler delete item; 77441281cf3SAxel Dörfler } 77541281cf3SAxel Dörfler 77641281cf3SAxel Dörfler 77741281cf3SAxel Dörfler /** ENTRY_MOVED message, moving only occurs on a device 77841281cf3SAxel Dörfler * copying will occur (ENTRY_CREATED) between devices 77941281cf3SAxel Dörfler */ 78041281cf3SAxel Dörfler 78141281cf3SAxel Dörfler void 78241281cf3SAxel Dörfler TReplicantTray::MoveItem(entry_ref* ref, ino_t toDirectory) 78341281cf3SAxel Dörfler { 78441281cf3SAxel Dörfler if (!ref) 78541281cf3SAxel Dörfler return; 78641281cf3SAxel Dörfler 78741281cf3SAxel Dörfler // scan for a matching entry_ref and update it 78841281cf3SAxel Dörfler // 78941281cf3SAxel Dörfler // don't need to change node info as it does not change 79041281cf3SAxel Dörfler 7919f2cce2fSJohn Scipione for (int32 i = fItemList->CountItems() - 1; i >= 0; i--) { 79241281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 79341281cf3SAxel Dörfler if (!item) 79441281cf3SAxel Dörfler continue; 79541281cf3SAxel Dörfler 79641281cf3SAxel Dörfler if (!strcmp(item->entryRef.name, ref->name) 79741281cf3SAxel Dörfler && item->entryRef.device == ref->device 79841281cf3SAxel Dörfler && item->entryRef.directory == ref->directory) { 79941281cf3SAxel Dörfler item->entryRef.directory = toDirectory; 80041281cf3SAxel Dörfler break; 80141281cf3SAxel Dörfler } 80241281cf3SAxel Dörfler } 80341281cf3SAxel Dörfler } 80441281cf3SAxel Dörfler 80541281cf3SAxel Dörfler #endif // add-on support 80641281cf3SAxel Dörfler 80741281cf3SAxel Dörfler // external add-on API routines 80841281cf3SAxel Dörfler // called using the new BDeskbar class 80941281cf3SAxel Dörfler 81041281cf3SAxel Dörfler // existence of icon/replicant by name or ID 81141281cf3SAxel Dörfler // returns opposite 81241281cf3SAxel Dörfler // note: name and id are semi-private limiting 81341281cf3SAxel Dörfler // the ability of non-host apps to remove 81441281cf3SAxel Dörfler // icons without a little bit of work 81541281cf3SAxel Dörfler 81641281cf3SAxel Dörfler /** for a specific id 81741281cf3SAxel Dörfler * return the name of the replicant (name of view) 81841281cf3SAxel Dörfler */ 81941281cf3SAxel Dörfler 82041281cf3SAxel Dörfler status_t 82141281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 id, const char** name) 82241281cf3SAxel Dörfler { 82341281cf3SAxel Dörfler if (id < 0) 82441281cf3SAxel Dörfler return B_ERROR; 82541281cf3SAxel Dörfler 82641281cf3SAxel Dörfler int32 index, temp; 82741281cf3SAxel Dörfler BView* view = ViewAt(&index, &temp, id, false); 82841281cf3SAxel Dörfler if (view) { 82941281cf3SAxel Dörfler *name = view->Name(); 83041281cf3SAxel Dörfler return B_OK; 83141281cf3SAxel Dörfler } 83241281cf3SAxel Dörfler 83341281cf3SAxel Dörfler return B_ERROR; 83441281cf3SAxel Dörfler } 83541281cf3SAxel Dörfler 83641281cf3SAxel Dörfler 8377da06231SAxel Dörfler /** for a specific name 8387da06231SAxel Dörfler * return the id (internal to Deskbar) 8397da06231SAxel Dörfler */ 8407da06231SAxel Dörfler 84141281cf3SAxel Dörfler status_t 84241281cf3SAxel Dörfler TReplicantTray::ItemInfo(const char* name, int32* id) 84341281cf3SAxel Dörfler { 84441281cf3SAxel Dörfler if (!name || strlen(name) <= 0) 84541281cf3SAxel Dörfler return B_ERROR; 84641281cf3SAxel Dörfler 84741281cf3SAxel Dörfler int32 index; 84841281cf3SAxel Dörfler BView* view = ViewAt(&index, id, name); 84941281cf3SAxel Dörfler if (view) 85041281cf3SAxel Dörfler return B_OK; 85141281cf3SAxel Dörfler 85241281cf3SAxel Dörfler return 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) 86441281cf3SAxel Dörfler return B_ERROR; 86541281cf3SAxel Dörfler 86641281cf3SAxel Dörfler BView* view; 86741281cf3SAxel Dörfler fShelf->ReplicantAt(index, &view, (uint32*)id, NULL); 86841281cf3SAxel Dörfler if (view) { 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 { 88241281cf3SAxel Dörfler int32 index, id; 88341281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 88441281cf3SAxel Dörfler 88541281cf3SAxel Dörfler return view && index >= 0; 88641281cf3SAxel Dörfler } 88741281cf3SAxel Dörfler 88841281cf3SAxel Dörfler 8897da06231SAxel Dörfler /** replicant exists, by name */ 8907da06231SAxel Dörfler 89141281cf3SAxel Dörfler bool 89241281cf3SAxel Dörfler TReplicantTray::IconExists(const char* name) 89341281cf3SAxel Dörfler { 89441281cf3SAxel Dörfler if (!name || strlen(name) == 0) 89541281cf3SAxel Dörfler return false; 89641281cf3SAxel Dörfler 89741281cf3SAxel Dörfler int32 index, id; 89841281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 89941281cf3SAxel Dörfler 90041281cf3SAxel Dörfler return view && index >= 0; 90141281cf3SAxel Dörfler } 90241281cf3SAxel Dörfler 90341281cf3SAxel Dörfler 90441281cf3SAxel Dörfler int32 90541281cf3SAxel Dörfler TReplicantTray::IconCount() const 90641281cf3SAxel Dörfler { 90741281cf3SAxel Dörfler return fShelf->CountReplicants(); 90841281cf3SAxel Dörfler } 90941281cf3SAxel Dörfler 91041281cf3SAxel Dörfler 911ced3755cSAxel Dörfler /*! Message must contain an archivable view for later rehydration. 912ced3755cSAxel Dörfler This function takes over ownership of the provided message on success 913ced3755cSAxel Dörfler only. 914ced3755cSAxel Dörfler Returns the current replicant ID. 9157da06231SAxel Dörfler */ 91641281cf3SAxel Dörfler status_t 917ced3755cSAxel Dörfler TReplicantTray::AddIcon(BMessage* archive, int32* id, const entry_ref* addOn) 91841281cf3SAxel Dörfler { 919ced3755cSAxel Dörfler if (archive == NULL || id == NULL) 92041281cf3SAxel Dörfler return B_ERROR; 92141281cf3SAxel Dörfler 9229c50f36eSAxel Dörfler // find entry_ref 9239c50f36eSAxel Dörfler 9249c50f36eSAxel Dörfler entry_ref ref; 9259c50f36eSAxel Dörfler if (addOn) { 9269c50f36eSAxel Dörfler // Use it if we got it 9279c50f36eSAxel Dörfler ref = *addOn; 9289c50f36eSAxel Dörfler } else { 9299c50f36eSAxel Dörfler const char* signature; 9301ad8c760SFredrik Holmqvist 931ced3755cSAxel Dörfler status_t status = archive->FindString("add_on", &signature); 9329c50f36eSAxel Dörfler if (status == B_OK) { 9339c50f36eSAxel Dörfler BRoster roster; 9349c50f36eSAxel Dörfler status = roster.FindApp(signature, &ref); 9359c50f36eSAxel Dörfler } 9369c50f36eSAxel Dörfler if (status < B_OK) 9379c50f36eSAxel Dörfler return status; 9389c50f36eSAxel Dörfler } 9399c50f36eSAxel Dörfler 9409c50f36eSAxel Dörfler BFile file; 9419c50f36eSAxel Dörfler status_t status = file.SetTo(&ref, B_READ_ONLY); 9429c50f36eSAxel Dörfler if (status < B_OK) 9439c50f36eSAxel Dörfler return status; 9449c50f36eSAxel Dörfler 9459c50f36eSAxel Dörfler node_ref nodeRef; 9469c50f36eSAxel Dörfler status = file.GetNodeRef(&nodeRef); 9479c50f36eSAxel Dörfler if (status < B_OK) 9489c50f36eSAxel Dörfler return status; 9499c50f36eSAxel Dörfler 9509c50f36eSAxel Dörfler BEntry entry(&ref, true); 9511ad8c760SFredrik Holmqvist // TODO: this resolves an eventual link for the item being added - this 9521ad8c760SFredrik Holmqvist // is okay for now, but in multi-user environments, one might want to 9531ad8c760SFredrik Holmqvist // have links that carry the be:deskbar_item_status attribute 9549c50f36eSAxel Dörfler status = entry.InitCheck(); 9559c50f36eSAxel Dörfler if (status != B_OK) 9569c50f36eSAxel Dörfler return status; 9579c50f36eSAxel Dörfler 95841281cf3SAxel Dörfler *id = 999; 959ced3755cSAxel Dörfler if (archive->what == B_ARCHIVED_OBJECT) 960ced3755cSAxel Dörfler archive->what = 0; 96141281cf3SAxel Dörfler 962ced3755cSAxel Dörfler BRect originalBounds = archive->FindRect("_frame"); 9631ad8c760SFredrik Holmqvist // this is a work-around for buggy replicants that change their size in 9641ad8c760SFredrik Holmqvist // AttachedToWindow() (such as "SVM") 965a5210ab1SAxel Dörfler 9661ad8c760SFredrik Holmqvist // TODO: check for name collisions? 967ced3755cSAxel Dörfler status = fShelf->AddReplicant(archive, BPoint(1, 1)); 9689c50f36eSAxel Dörfler if (status != B_OK) 9699c50f36eSAxel Dörfler return status; 97041281cf3SAxel Dörfler 971a5210ab1SAxel Dörfler int32 count = fShelf->CountReplicants(); 972a5210ab1SAxel Dörfler BView* view; 973a5210ab1SAxel Dörfler fShelf->ReplicantAt(count - 1, &view, (uint32*)id, NULL); 974a5210ab1SAxel Dörfler 975a5210ab1SAxel Dörfler if (originalBounds != view->Bounds()) { 976a5210ab1SAxel Dörfler // The replicant changed its size when added to the window, so we need 97771bd3ba5SJonas Sundström // to recompute all over again (it's already done once via 97871bd3ba5SJonas Sundström // BShelf::AddReplicant() and TReplicantShelf::CanAcceptReplicantView()) 979a5210ab1SAxel Dörfler RealignReplicants(); 980a5210ab1SAxel Dörfler } 981a5210ab1SAxel Dörfler 98241281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 98341281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 98441281cf3SAxel Dörfler float width, height; 98541281cf3SAxel Dörfler GetPreferredSize(&width, &height); 98641281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) 98741281cf3SAxel Dörfler AdjustPlacement(); 98841281cf3SAxel Dörfler 98941281cf3SAxel Dörfler // add the item to the add-on list 99041281cf3SAxel Dörfler 99141281cf3SAxel Dörfler AddItem(*id, nodeRef, entry, addOn != NULL); 99241281cf3SAxel Dörfler return B_OK; 99341281cf3SAxel Dörfler } 99441281cf3SAxel Dörfler 99541281cf3SAxel Dörfler 99641281cf3SAxel Dörfler void 99741281cf3SAxel Dörfler TReplicantTray::RemoveIcon(int32 target, bool byIndex) 99841281cf3SAxel Dörfler { 99941281cf3SAxel Dörfler if (target < 0) 100041281cf3SAxel Dörfler return; 100141281cf3SAxel Dörfler 100241281cf3SAxel Dörfler int32 index, id; 100341281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 100441281cf3SAxel Dörfler if (view && index >= 0) { 10057da06231SAxel Dörfler // remove the reference from the item list & the shelf 100641281cf3SAxel Dörfler RemoveItem(id); 100741281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 10087da06231SAxel Dörfler 100941281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 101041281cf3SAxel Dörfler RealReplicantAdjustment(index); 101141281cf3SAxel Dörfler } 101241281cf3SAxel Dörfler } 101341281cf3SAxel Dörfler 101441281cf3SAxel Dörfler 101541281cf3SAxel Dörfler void 101641281cf3SAxel Dörfler TReplicantTray::RemoveIcon(const char* name) 101741281cf3SAxel Dörfler { 101841281cf3SAxel Dörfler if (!name || strlen(name) <= 0) 101941281cf3SAxel Dörfler return; 102041281cf3SAxel Dörfler 102141281cf3SAxel Dörfler int32 id, index; 102241281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 102341281cf3SAxel Dörfler if (view && index >= 0) { 10247da06231SAxel Dörfler // remove the reference from the item list & shelf 102541281cf3SAxel Dörfler RemoveItem(id); 102641281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 10277da06231SAxel Dörfler 102841281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 102941281cf3SAxel Dörfler RealReplicantAdjustment(index); 103041281cf3SAxel Dörfler } 103141281cf3SAxel Dörfler } 103241281cf3SAxel Dörfler 103341281cf3SAxel Dörfler 103441281cf3SAxel Dörfler void 10357da06231SAxel Dörfler TReplicantTray::RealReplicantAdjustment(int32 startIndex) 103641281cf3SAxel Dörfler { 10377da06231SAxel Dörfler if (startIndex < 0) 103841281cf3SAxel Dörfler return; 10397da06231SAxel Dörfler 10407da06231SAxel Dörfler if (startIndex == fLastReplicant) 10417da06231SAxel Dörfler startIndex = 0; 10427da06231SAxel Dörfler 104341281cf3SAxel Dörfler // reset the locations of all replicants after the one deleted 10447da06231SAxel Dörfler RealignReplicants(startIndex); 104541281cf3SAxel Dörfler 104641281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 104741281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 104841281cf3SAxel Dörfler float width, height; 104941281cf3SAxel Dörfler GetPreferredSize(&width, &height); 105041281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) { 10511ad8c760SFredrik Holmqvist // resize view to accomodate the replicants, redraw as necessary 105241281cf3SAxel Dörfler AdjustPlacement(); 105341281cf3SAxel Dörfler } 105441281cf3SAxel Dörfler } 105541281cf3SAxel Dörfler 105641281cf3SAxel Dörfler 10577da06231SAxel Dörfler /** looking for a replicant by id/index 10587da06231SAxel Dörfler * return the view and index 10597da06231SAxel Dörfler */ 10607da06231SAxel Dörfler 106141281cf3SAxel Dörfler BView* 106241281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, int32 target, bool byIndex) 106341281cf3SAxel Dörfler { 106441281cf3SAxel Dörfler *index = -1; 106541281cf3SAxel Dörfler 106641281cf3SAxel Dörfler BView* view; 106741281cf3SAxel Dörfler if (byIndex) { 106841281cf3SAxel Dörfler if (fShelf->ReplicantAt(target, &view, (uint32*)id)) { 106941281cf3SAxel Dörfler if (view) { 107041281cf3SAxel Dörfler *index = target; 107141281cf3SAxel Dörfler return view; 107241281cf3SAxel Dörfler } 107341281cf3SAxel Dörfler } 107441281cf3SAxel Dörfler } else { 107541281cf3SAxel Dörfler int32 count = fShelf->CountReplicants() - 1; 107641281cf3SAxel Dörfler int32 localid; 107741281cf3SAxel Dörfler for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { 107841281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32*)&localid); 107941281cf3SAxel Dörfler if (localid == target && view) { 108041281cf3SAxel Dörfler *index = repIndex; 108141281cf3SAxel Dörfler *id = localid; 108241281cf3SAxel Dörfler return view; 108341281cf3SAxel Dörfler } 108441281cf3SAxel Dörfler } 108541281cf3SAxel Dörfler } 108641281cf3SAxel Dörfler return NULL; 108741281cf3SAxel Dörfler } 108841281cf3SAxel Dörfler 108941281cf3SAxel Dörfler 10907da06231SAxel Dörfler /** looking for a replicant with a view by name 10917da06231SAxel Dörfler * return the view, index and the id of the replicant 10927da06231SAxel Dörfler */ 10937da06231SAxel Dörfler 109441281cf3SAxel Dörfler BView* 109541281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, const char* name) 109641281cf3SAxel Dörfler { 109741281cf3SAxel Dörfler *index = -1; 109841281cf3SAxel Dörfler *id = -1; 109941281cf3SAxel Dörfler 110041281cf3SAxel Dörfler BView* view; 110141281cf3SAxel Dörfler int32 count = fShelf->CountReplicants()-1; 110241281cf3SAxel Dörfler for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { 110341281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32*)id); 110441281cf3SAxel Dörfler if (view && view->Name() && strcmp(name, view->Name()) == 0) { 110541281cf3SAxel Dörfler *index = repIndex; 110641281cf3SAxel Dörfler return view; 110741281cf3SAxel Dörfler } 110841281cf3SAxel Dörfler } 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 { 112041281cf3SAxel Dörfler if (!message) 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 11407da06231SAxel Dörfler BPoint loc = LocationForReplicant(fShelf->CountReplicants(), 11417da06231SAxel Dörfler replicantFrame.Width()); 114241281cf3SAxel Dörfler 114341281cf3SAxel Dörfler message->AddPoint("_pjp_loc", loc); 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 11547da06231SAxel Dörfler TReplicantTray::LocationForReplicant(int32 index, float width) 115541281cf3SAxel Dörfler { 115641281cf3SAxel Dörfler BPoint loc(kIconGap + 1, kGutter + 1); 115741281cf3SAxel Dörfler 11587da06231SAxel Dörfler if (fMultiRowMode) { 11597da06231SAxel Dörfler // try to find free space in every row 11607da06231SAxel Dörfler for (int32 row = 0; ; loc.y += kMaxReplicantHeight + kIconGap, row++) { 11617da06231SAxel Dörfler // determine free space in this row 11622ce9bab8SJohn Scipione BRect rect(loc.x, loc.y, loc.x + fMinimumTrayWidth - kIconGap 11632ce9bab8SJohn Scipione - 2.0, loc.y + kMaxReplicantHeight); 1164573f748cSJohn Scipione if (row == 0 && !fTime->IsHidden()) 1165573f748cSJohn Scipione rect.right -= fTime->Frame().Width() + kIconGap; 11667da06231SAxel Dörfler 11677da06231SAxel Dörfler for (int32 i = 0; i < index; i++) { 11687da06231SAxel Dörfler BView* view = NULL; 11697da06231SAxel Dörfler fShelf->ReplicantAt(i, &view); 11707da06231SAxel Dörfler if (view == NULL || view->Frame().top != rect.top) 11717da06231SAxel Dörfler continue; 11727da06231SAxel Dörfler 11737da06231SAxel Dörfler rect.left = view->Frame().right + kIconGap + 1; 11747da06231SAxel Dörfler } 11757da06231SAxel Dörfler 11767da06231SAxel Dörfler if (rect.Width() >= width) { 11777da06231SAxel Dörfler // the icon fits in this row 11787da06231SAxel Dörfler loc = rect.LeftTop(); 11797da06231SAxel Dörfler break; 11807da06231SAxel Dörfler } 11817da06231SAxel Dörfler } 11827da06231SAxel Dörfler } else { 118341281cf3SAxel Dörfler if (index > 0) { 118441281cf3SAxel Dörfler // get the last replicant added for placement reference 118541281cf3SAxel Dörfler BView* view = NULL; 11867da06231SAxel Dörfler fShelf->ReplicantAt(index - 1, &view); 118741281cf3SAxel Dörfler if (view) { 118841281cf3SAxel Dörfler // push this rep placement past the last one 118941281cf3SAxel Dörfler loc.x = view->Frame().right + kIconGap + 1; 119041281cf3SAxel Dörfler loc.y = view->Frame().top; 119141281cf3SAxel Dörfler } 119241281cf3SAxel Dörfler } 11937da06231SAxel Dörfler } 119441281cf3SAxel Dörfler 119571bd3ba5SJonas Sundström if ((loc.y == fRightBottomReplicant.top && loc.x 119671bd3ba5SJonas Sundström > fRightBottomReplicant.left) || loc.y > fRightBottomReplicant.top) { 119771bd3ba5SJonas Sundström fRightBottomReplicant.Set(loc.x, loc.y, loc.x + width, loc.y 119871bd3ba5SJonas Sundström + kMaxReplicantHeight); 11997da06231SAxel Dörfler fLastReplicant = index; 120041281cf3SAxel Dörfler } 12017da06231SAxel Dörfler 120241281cf3SAxel Dörfler return loc; 120341281cf3SAxel Dörfler } 120441281cf3SAxel Dörfler 120541281cf3SAxel Dörfler 120641281cf3SAxel Dörfler BRect 120741281cf3SAxel Dörfler TReplicantTray::IconFrame(int32 target, bool byIndex) 120841281cf3SAxel Dörfler { 120941281cf3SAxel Dörfler int32 index, id; 121041281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 121141281cf3SAxel Dörfler if (view) 121241281cf3SAxel Dörfler return view->Frame(); 121341281cf3SAxel Dörfler 121441281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 121541281cf3SAxel Dörfler } 121641281cf3SAxel Dörfler 121741281cf3SAxel Dörfler 121841281cf3SAxel Dörfler BRect 121941281cf3SAxel Dörfler TReplicantTray::IconFrame(const char* name) 122041281cf3SAxel Dörfler { 122141281cf3SAxel Dörfler if (!name) 122241281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 122341281cf3SAxel Dörfler 122441281cf3SAxel Dörfler int32 id, index; 122541281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 122641281cf3SAxel Dörfler if (view) 122741281cf3SAxel Dörfler return view->Frame(); 122841281cf3SAxel Dörfler 122941281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 123041281cf3SAxel Dörfler } 123141281cf3SAxel Dörfler 123241281cf3SAxel Dörfler 12337da06231SAxel Dörfler /** Scan from the startIndex and reset the location 12347da06231SAxel Dörfler * as defined in LocationForReplicant() 123541281cf3SAxel Dörfler */ 123641281cf3SAxel Dörfler 123741281cf3SAxel Dörfler void 123841281cf3SAxel Dörfler TReplicantTray::RealignReplicants(int32 startIndex) 123941281cf3SAxel Dörfler { 124041281cf3SAxel Dörfler if (startIndex < 0) 124141281cf3SAxel Dörfler startIndex = 0; 124241281cf3SAxel Dörfler 124341281cf3SAxel Dörfler int32 count = fShelf->CountReplicants(); 124441281cf3SAxel Dörfler if (count <= 0) 124541281cf3SAxel Dörfler return; 124641281cf3SAxel Dörfler 12477da06231SAxel Dörfler if (startIndex == 0) 12487da06231SAxel Dörfler fRightBottomReplicant.Set(0, 0, 0, 0); 12497da06231SAxel Dörfler 125041281cf3SAxel Dörfler BView* view = NULL; 125141281cf3SAxel Dörfler for (int32 i = startIndex ; i < count ; i++) { 125241281cf3SAxel Dörfler fShelf->ReplicantAt(i, &view); 12530bec7100SStefano Ceccherini if (view != NULL) { 12547da06231SAxel Dörfler BPoint loc = LocationForReplicant(i, view->Frame().Width()); 12550bec7100SStefano Ceccherini if (view->Frame().LeftTop() != loc) 125641281cf3SAxel Dörfler view->MoveTo(loc); 125741281cf3SAxel Dörfler } 125841281cf3SAxel Dörfler } 125941281cf3SAxel Dörfler } 126041281cf3SAxel Dörfler 126141281cf3SAxel Dörfler 12628aab28f1SRene Gollent status_t 12637625ce51SRene Gollent TReplicantTray::_SaveSettings() 12647625ce51SRene Gollent { 12657625ce51SRene Gollent status_t result; 12667625ce51SRene Gollent BPath path; 126726ea7066SIngo Weinhold if ((result = GetDeskbarSettingsDirectory(path, true)) == B_OK) { 12687625ce51SRene Gollent path.Append(kReplicantSettingsFile); 12697625ce51SRene Gollent 12707625ce51SRene Gollent BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); 12717625ce51SRene Gollent if ((result = file.InitCheck()) == B_OK) 12727625ce51SRene Gollent result = fAddOnSettings.Flatten(&file); 12737625ce51SRene Gollent } 12747625ce51SRene Gollent 12757625ce51SRene Gollent return result; 12767625ce51SRene Gollent } 12777625ce51SRene Gollent 12787625ce51SRene Gollent 12793cf2d117SJohn Scipione void 12803cf2d117SJohn Scipione TReplicantTray::SaveTimeSettings() 12813cf2d117SJohn Scipione { 12823cf2d117SJohn Scipione if (fTime == NULL) 12833cf2d117SJohn Scipione return; 12843cf2d117SJohn Scipione 128531c0024dSJohn Scipione clock_settings* settings = ((TBarApp*)be_app)->ClockSettings(); 12863cf2d117SJohn Scipione settings->showSeconds = fTime->ShowSeconds(); 12873cf2d117SJohn Scipione settings->showDayOfWeek = fTime->ShowDayOfWeek(); 128831c0024dSJohn Scipione settings->showTimeZone = fTime->ShowTimeZone(); 12893cf2d117SJohn Scipione } 12903cf2d117SJohn Scipione 12913cf2d117SJohn Scipione 129241281cf3SAxel Dörfler // #pragma mark - 129341281cf3SAxel Dörfler 129441281cf3SAxel Dörfler 1295ca9acc20SAxel Dörfler /*! Draggable region that is asynchronous so that dragging does not block 1296ca9acc20SAxel Dörfler other activities. 12977da06231SAxel Dörfler */ 129841281cf3SAxel Dörfler TDragRegion::TDragRegion(TBarView* parent, BView* child) 1299ca9acc20SAxel Dörfler : 1300ca9acc20SAxel Dörfler BControl(BRect(0, 0, 0, 0), "", "", NULL, B_FOLLOW_NONE, 130141281cf3SAxel Dörfler B_WILL_DRAW | B_FRAME_EVENTS), 130241281cf3SAxel Dörfler fBarView(parent), 130341281cf3SAxel Dörfler fChild(child), 130441281cf3SAxel Dörfler fDragLocation(kAutoPlaceDragRegion) 130541281cf3SAxel Dörfler { 130641281cf3SAxel Dörfler } 130741281cf3SAxel Dörfler 130841281cf3SAxel Dörfler 130941281cf3SAxel Dörfler void 131041281cf3SAxel Dörfler TDragRegion::AttachedToWindow() 131141281cf3SAxel Dörfler { 131241281cf3SAxel Dörfler BView::AttachedToWindow(); 1313cb6afcb1SStephan Aßmus if (be_control_look != NULL) 1314*16c10517Slooncraz SetViewUIColor(B_MENU_BACKGROUND_COLOR, 1.1); 1315cb6afcb1SStephan Aßmus else 1316*16c10517Slooncraz SetViewUIColor(B_MENU_BACKGROUND_COLOR); 131741281cf3SAxel Dörfler ResizeToPreferred(); 131841281cf3SAxel Dörfler } 131941281cf3SAxel Dörfler 132041281cf3SAxel Dörfler 132141281cf3SAxel Dörfler void 132241281cf3SAxel Dörfler TDragRegion::GetPreferredSize(float* width, float* height) 132341281cf3SAxel Dörfler { 132441281cf3SAxel Dörfler fChild->ResizeToPreferred(); 132541281cf3SAxel Dörfler *width = fChild->Bounds().Width(); 132641281cf3SAxel Dörfler *height = fChild->Bounds().Height(); 132741281cf3SAxel Dörfler 132841281cf3SAxel Dörfler if (fDragLocation != kNoDragRegion) 132941281cf3SAxel Dörfler *width += 7; 133041281cf3SAxel Dörfler else 133141281cf3SAxel Dörfler *width += 6; 133241281cf3SAxel Dörfler 133341281cf3SAxel Dörfler *height += 3; 133441281cf3SAxel Dörfler } 133541281cf3SAxel Dörfler 133641281cf3SAxel Dörfler 133741281cf3SAxel Dörfler void 133841281cf3SAxel Dörfler TDragRegion::FrameMoved(BPoint) 133941281cf3SAxel Dörfler { 1340ca9acc20SAxel Dörfler if (fBarView->Left() && fBarView->Vertical() 1341ca9acc20SAxel Dörfler && fDragLocation != kNoDragRegion) 134241281cf3SAxel Dörfler fChild->MoveTo(5, 2); 134341281cf3SAxel Dörfler else 134441281cf3SAxel Dörfler fChild->MoveTo(2, 2); 134541281cf3SAxel Dörfler } 134641281cf3SAxel Dörfler 134741281cf3SAxel Dörfler 134841281cf3SAxel Dörfler void 134941281cf3SAxel Dörfler TDragRegion::Draw(BRect) 135041281cf3SAxel Dörfler { 1351eaa9af99SStephan Aßmus rgb_color menuColor = ViewColor(); 135241281cf3SAxel Dörfler rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT); 1353cb6afcb1SStephan Aßmus rgb_color ldark = tint_color(menuColor, 1.02); 1354cb6afcb1SStephan Aßmus rgb_color dark = tint_color(menuColor, B_DARKEN_2_TINT); 135541281cf3SAxel Dörfler rgb_color vvdark = tint_color(menuColor, B_DARKEN_4_TINT); 135641281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 135741281cf3SAxel Dörfler 135841281cf3SAxel Dörfler BRect frame(Bounds()); 135941281cf3SAxel Dörfler BeginLineArray(4); 136041281cf3SAxel Dörfler 1361cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 1362cb6afcb1SStephan Aßmus if (fBarView->Vertical()) { 1363cb6afcb1SStephan Aßmus AddLine(frame.LeftTop(), frame.RightTop(), dark); 1364cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1365cb6afcb1SStephan Aßmus BPoint(frame.right, frame.top + 1), ldark); 1366cb6afcb1SStephan Aßmus AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 1367cb6afcb1SStephan Aßmus } else if (fBarView->AcrossTop() || fBarView->AcrossBottom()) { 1368cb6afcb1SStephan Aßmus AddLine(frame.LeftTop(), 1369cb6afcb1SStephan Aßmus BPoint(frame.left, frame.bottom), dark); 1370cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left + 1, frame.top + 1), 1371cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 1372cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right, frame.top + 2), 1373cb6afcb1SStephan Aßmus BPoint(frame.right, frame.bottom), hilite); 1374cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left + 1, frame.bottom), 1375cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom), hilite); 1376cb6afcb1SStephan Aßmus } 1377cb6afcb1SStephan Aßmus } else { 137841281cf3SAxel Dörfler if (fBarView->Vertical()) { 137941281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.RightTop(), light); 138041281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.LeftBottom(), light); 138141281cf3SAxel Dörfler AddLine(frame.RightBottom(), frame.RightTop(), hilite); 138241281cf3SAxel Dörfler } else if (fBarView->AcrossTop()) { 1383cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1384cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 138541281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 1386cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right - 1, frame.top + 2), 1387cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom - 1), hilite); 1388cb6afcb1SStephan Aßmus AddLine(frame.LeftBottom(), 1389cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom), hilite); 139041281cf3SAxel Dörfler } else if (fBarView->AcrossBottom()) { 1391cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1392cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 139341281cf3SAxel Dörfler AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 139441281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 1395cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right - 1, frame.top + 1), 1396cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom - 1), hilite); 1397cb6afcb1SStephan Aßmus } 139841281cf3SAxel Dörfler } 139941281cf3SAxel Dörfler 140041281cf3SAxel Dörfler EndLineArray(); 140141281cf3SAxel Dörfler 140241281cf3SAxel Dörfler if (fDragLocation != kDontDrawDragRegion || fDragLocation != kNoDragRegion) 140341281cf3SAxel Dörfler DrawDragRegion(); 140441281cf3SAxel Dörfler } 140541281cf3SAxel Dörfler 140641281cf3SAxel Dörfler 140741281cf3SAxel Dörfler void 140841281cf3SAxel Dörfler TDragRegion::DrawDragRegion() 140941281cf3SAxel Dörfler { 141041281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 141141281cf3SAxel Dörfler 1412cb6afcb1SStephan Aßmus rgb_color menuColor = ViewColor(); 1413cb6afcb1SStephan Aßmus rgb_color menuHilite = menuColor; 141441281cf3SAxel Dörfler if (IsTracking()) { 1415cb6afcb1SStephan Aßmus // Draw drag region highlighted if tracking mouse 1416cb6afcb1SStephan Aßmus menuHilite = tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT); 141741281cf3SAxel Dörfler SetHighColor(menuHilite); 141841281cf3SAxel Dörfler FillRect(dragRegion); 141941281cf3SAxel Dörfler } 1420cb6afcb1SStephan Aßmus rgb_color vdark = tint_color(menuHilite, B_DARKEN_3_TINT); 1421cb6afcb1SStephan Aßmus rgb_color light = tint_color(menuHilite, B_LIGHTEN_2_TINT); 1422cb6afcb1SStephan Aßmus 1423cb6afcb1SStephan Aßmus BeginLineArray(dragRegion.IntegerHeight()); 1424cb6afcb1SStephan Aßmus BPoint pt; 1425cb6afcb1SStephan Aßmus pt.x = floorf((dragRegion.left + dragRegion.right) / 2 + 0.5) - 1; 1426cb6afcb1SStephan Aßmus pt.y = dragRegion.top + 2; 1427cb6afcb1SStephan Aßmus 142841281cf3SAxel Dörfler while (pt.y + 1 <= dragRegion.bottom) { 142941281cf3SAxel Dörfler AddLine(pt, pt, vdark); 143041281cf3SAxel Dörfler AddLine(pt + BPoint(1, 1), pt + BPoint(1, 1), light); 143141281cf3SAxel Dörfler 143241281cf3SAxel Dörfler pt.y += 3; 143341281cf3SAxel Dörfler } 143441281cf3SAxel Dörfler EndLineArray(); 143541281cf3SAxel Dörfler } 143641281cf3SAxel Dörfler 143741281cf3SAxel Dörfler 143841281cf3SAxel Dörfler BRect 143941281cf3SAxel Dörfler TDragRegion::DragRegion() const 144041281cf3SAxel Dörfler { 1441cb6afcb1SStephan Aßmus float kTopBottomInset = 2; 1442cb6afcb1SStephan Aßmus float kLeftRightInset = 1; 1443cb6afcb1SStephan Aßmus float kDragWidth = 3; 1444cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 1445cb6afcb1SStephan Aßmus kTopBottomInset = 1; 1446cb6afcb1SStephan Aßmus kLeftRightInset = 0; 1447cb6afcb1SStephan Aßmus kDragWidth = 4; 1448cb6afcb1SStephan Aßmus } 1449cb6afcb1SStephan Aßmus 145041281cf3SAxel Dörfler BRect dragRegion(Bounds()); 1451cb6afcb1SStephan Aßmus dragRegion.top += kTopBottomInset; 1452cb6afcb1SStephan Aßmus dragRegion.bottom -= kTopBottomInset; 145341281cf3SAxel Dörfler 145441281cf3SAxel Dörfler bool placeOnLeft = false; 145541281cf3SAxel Dörfler if (fDragLocation == kAutoPlaceDragRegion) { 145641281cf3SAxel Dörfler if (fBarView->Vertical() && fBarView->Left()) 145741281cf3SAxel Dörfler placeOnLeft = true; 145841281cf3SAxel Dörfler else 145941281cf3SAxel Dörfler placeOnLeft = false; 146041281cf3SAxel Dörfler } else if (fDragLocation == kDragRegionLeft) 146141281cf3SAxel Dörfler placeOnLeft = true; 146241281cf3SAxel Dörfler else if (fDragLocation == kDragRegionRight) 146341281cf3SAxel Dörfler placeOnLeft = false; 146441281cf3SAxel Dörfler 146541281cf3SAxel Dörfler if (placeOnLeft) { 1466cb6afcb1SStephan Aßmus dragRegion.left += kLeftRightInset; 1467cb6afcb1SStephan Aßmus dragRegion.right = dragRegion.left + kDragWidth; 146841281cf3SAxel Dörfler } else { 1469cb6afcb1SStephan Aßmus dragRegion.right -= kLeftRightInset; 1470cb6afcb1SStephan Aßmus dragRegion.left = dragRegion.right - kDragWidth; 147141281cf3SAxel Dörfler } 147241281cf3SAxel Dörfler 147341281cf3SAxel Dörfler return dragRegion; 147441281cf3SAxel Dörfler } 147541281cf3SAxel Dörfler 147641281cf3SAxel Dörfler 147741281cf3SAxel Dörfler void 147841281cf3SAxel Dörfler TDragRegion::MouseDown(BPoint thePoint) 147941281cf3SAxel Dörfler { 1480e9632898SAlex Smith uint32 buttons; 148141281cf3SAxel Dörfler BPoint where; 148241281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 148341281cf3SAxel Dörfler 14847da06231SAxel Dörfler dragRegion.InsetBy(-2.0f, -2.0f); 14857da06231SAxel Dörfler // DragRegion() is designed for drawing, not clicking 148641281cf3SAxel Dörfler 148741281cf3SAxel Dörfler if (!dragRegion.Contains(thePoint)) 148841281cf3SAxel Dörfler return; 148941281cf3SAxel Dörfler 149041281cf3SAxel Dörfler while (true) { 149141281cf3SAxel Dörfler GetMouse(&where, &buttons); 149241281cf3SAxel Dörfler if (!buttons) 149341281cf3SAxel Dörfler break; 149441281cf3SAxel Dörfler 149541281cf3SAxel Dörfler if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) != 0) { 149641281cf3SAxel Dörfler fPreviousPosition = thePoint; 149741281cf3SAxel Dörfler SetTracking(true); 149841281cf3SAxel Dörfler SetMouseEventMask(B_POINTER_EVENTS, 149941281cf3SAxel Dörfler B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); 150041281cf3SAxel Dörfler Invalidate(DragRegion()); 150141281cf3SAxel Dörfler break; 150241281cf3SAxel Dörfler } 150341281cf3SAxel Dörfler 150441281cf3SAxel Dörfler snooze(25000); 150541281cf3SAxel Dörfler } 150641281cf3SAxel Dörfler } 150741281cf3SAxel Dörfler 150841281cf3SAxel Dörfler 150941281cf3SAxel Dörfler void 151041281cf3SAxel Dörfler TDragRegion::MouseUp(BPoint pt) 151141281cf3SAxel Dörfler { 151241281cf3SAxel Dörfler if (IsTracking()) { 151341281cf3SAxel Dörfler SetTracking(false); 151441281cf3SAxel Dörfler Invalidate(DragRegion()); 151541281cf3SAxel Dörfler } else 151641281cf3SAxel Dörfler BControl::MouseUp(pt); 151741281cf3SAxel Dörfler } 151841281cf3SAxel Dörfler 151941281cf3SAxel Dörfler 152041281cf3SAxel Dörfler bool 152141281cf3SAxel Dörfler TDragRegion::SwitchModeForRect(BPoint mouse, BRect rect, 152241281cf3SAxel Dörfler bool newVertical, bool newLeft, bool newTop, int32 newState) 152341281cf3SAxel Dörfler { 15241ad8c760SFredrik Holmqvist if (!rect.Contains(mouse)) { 152541281cf3SAxel Dörfler // not our rect 152641281cf3SAxel Dörfler return false; 15271ad8c760SFredrik Holmqvist } 152841281cf3SAxel Dörfler 15291ad8c760SFredrik Holmqvist if (newVertical == fBarView->Vertical() && newLeft == fBarView->Left() 15301ad8c760SFredrik Holmqvist && newTop == fBarView->Top() && newState == fBarView->State()) { 153141281cf3SAxel Dörfler // already in the correct mode 153241281cf3SAxel Dörfler return true; 15331ad8c760SFredrik Holmqvist } 153441281cf3SAxel Dörfler 1535d7ed9414SRene Gollent fBarView->ChangeState(newState, newVertical, newLeft, newTop, true); 153641281cf3SAxel Dörfler return true; 153741281cf3SAxel Dörfler } 153841281cf3SAxel Dörfler 153941281cf3SAxel Dörfler 154041281cf3SAxel Dörfler void 154141281cf3SAxel Dörfler TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage* message) 154241281cf3SAxel Dörfler { 154341281cf3SAxel Dörfler if (IsTracking()) { 154441281cf3SAxel Dörfler BScreen screen; 154541281cf3SAxel Dörfler BRect frame = screen.Frame(); 154641281cf3SAxel Dörfler 154741281cf3SAxel Dörfler float hDivider = frame.Width() / 6; 1548b49e806dSAxel Dörfler hDivider = (hDivider < gMinimumWindowWidth + 10.0f) 1549b49e806dSAxel Dörfler ? gMinimumWindowWidth + 10.0f : hDivider; 155041281cf3SAxel Dörfler float miniDivider = frame.top + kMiniHeight + 10.0f; 155141281cf3SAxel Dörfler float vDivider = frame.Height() / 2; 155241281cf3SAxel Dörfler #ifdef FULL_MODE 155341281cf3SAxel Dörfler float thirdScreen = frame.Height() / 3; 155441281cf3SAxel Dörfler #endif 155571bd3ba5SJonas Sundström BRect topLeft(frame.left, frame.top, frame.left + hDivider, 155671bd3ba5SJonas Sundström miniDivider); 155771bd3ba5SJonas Sundström BRect topMiddle(frame.left + hDivider, frame.top, frame.right 155871bd3ba5SJonas Sundström - hDivider, vDivider); 155971bd3ba5SJonas Sundström BRect topRight(frame.right - hDivider, frame.top, frame.right, 156071bd3ba5SJonas Sundström miniDivider); 156141281cf3SAxel Dörfler 156241281cf3SAxel Dörfler #ifdef FULL_MODE 156341281cf3SAxel Dörfler vDivider = miniDivider + thirdScreen; 156441281cf3SAxel Dörfler #endif 156571bd3ba5SJonas Sundström BRect middleLeft(frame.left, miniDivider, frame.left + hDivider, 156671bd3ba5SJonas Sundström vDivider); 156771bd3ba5SJonas Sundström BRect middleRight(frame.right - hDivider, miniDivider, frame.right, 156871bd3ba5SJonas Sundström vDivider); 156941281cf3SAxel Dörfler 157041281cf3SAxel Dörfler #ifdef FULL_MODE 157171bd3ba5SJonas Sundström BRect leftSide(frame.left, vDivider, frame.left + hDivider, 157271bd3ba5SJonas Sundström frame.bottom - thirdScreen); 157371bd3ba5SJonas Sundström BRect rightSide(frame.right - hDivider, vDivider, frame.right, 157471bd3ba5SJonas Sundström frame.bottom - thirdScreen); 157541281cf3SAxel Dörfler 157641281cf3SAxel Dörfler vDivider = frame.bottom - thirdScreen; 157741281cf3SAxel Dörfler #endif 157871bd3ba5SJonas Sundström BRect bottomLeft(frame.left, vDivider, frame.left + hDivider, 157971bd3ba5SJonas Sundström frame.bottom); 158071bd3ba5SJonas Sundström BRect bottomMiddle(frame.left + hDivider, vDivider, frame.right 158171bd3ba5SJonas Sundström - hDivider, frame.bottom); 158271bd3ba5SJonas Sundström BRect bottomRight(frame.right - hDivider, vDivider, frame.right, 158371bd3ba5SJonas Sundström frame.bottom); 158441281cf3SAxel Dörfler 158541281cf3SAxel Dörfler if (where != fPreviousPosition) { 158641281cf3SAxel Dörfler fPreviousPosition = where; 158741281cf3SAxel Dörfler ConvertToScreen(&where); 158841281cf3SAxel Dörfler 158941281cf3SAxel Dörfler // use short circuit evaluation for convenience 159041281cf3SAxel Dörfler if (SwitchModeForRect(where, topLeft, true, true, true, kMiniState) 159171bd3ba5SJonas Sundström || SwitchModeForRect(where, topMiddle, false, true, true, 159271bd3ba5SJonas Sundström kExpandoState) 159371bd3ba5SJonas Sundström || SwitchModeForRect(where, topRight, true, false, true, 159471bd3ba5SJonas Sundström kMiniState) 159571bd3ba5SJonas Sundström || SwitchModeForRect(where, middleLeft, true, true, true, 159671bd3ba5SJonas Sundström kExpandoState) 159771bd3ba5SJonas Sundström || SwitchModeForRect(where, middleRight, true, false, true, 159871bd3ba5SJonas Sundström kExpandoState) 159941281cf3SAxel Dörfler 160041281cf3SAxel Dörfler #ifdef FULL_MODE 160171bd3ba5SJonas Sundström || SwitchModeForRect(where, leftSide, true, true, true, 160271bd3ba5SJonas Sundström kFullState) 160371bd3ba5SJonas Sundström || SwitchModeForRect(where, rightSide, true, false, true, 160471bd3ba5SJonas Sundström kFullState) 160541281cf3SAxel Dörfler #endif 160671bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomLeft, true, true, false, 160771bd3ba5SJonas Sundström kMiniState) 160871bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomMiddle, false, true, false, 160971bd3ba5SJonas Sundström kExpandoState) 161071bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomRight, true, false, false, 161171bd3ba5SJonas Sundström kMiniState)) 161241281cf3SAxel Dörfler ; 161341281cf3SAxel Dörfler } 161441281cf3SAxel Dörfler } else 161541281cf3SAxel Dörfler BControl::MouseMoved(where, code, message); 161641281cf3SAxel Dörfler } 161741281cf3SAxel Dörfler 161841281cf3SAxel Dörfler 161941281cf3SAxel Dörfler int32 162041281cf3SAxel Dörfler TDragRegion::DragRegionLocation() const 162141281cf3SAxel Dörfler { 162241281cf3SAxel Dörfler return fDragLocation; 162341281cf3SAxel Dörfler } 162441281cf3SAxel Dörfler 162541281cf3SAxel Dörfler 162641281cf3SAxel Dörfler void 162741281cf3SAxel Dörfler TDragRegion::SetDragRegionLocation(int32 location) 162841281cf3SAxel Dörfler { 162941281cf3SAxel Dörfler if (location == fDragLocation) 163041281cf3SAxel Dörfler return; 163141281cf3SAxel Dörfler 163241281cf3SAxel Dörfler fDragLocation = location; 163341281cf3SAxel Dörfler Invalidate(); 163441281cf3SAxel Dörfler } 1635