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"; 893e6ff860SRene Gollent const char* const kReplicantSettingsFile = "Deskbar_replicants"; 90c0ad1c91SRene Gollent const char* const kReplicantPathField = "replicant_path"; 9141281cf3SAxel Dörfler 92cb6afcb1SStephan Aßmus float sMinimumWindowWidth = 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) { 145cb6afcb1SStephan Aßmus sMinimumWindowWidth = max_c(sMinimumWindowWidth, 146cb6afcb1SStephan Aßmus 2 * (logoBitmap->Bounds().Width() + 8)); 147cb6afcb1SStephan Aßmus fMinimumTrayWidth = sMinimumWindowWidth - kGutter - kDragRegionWidth; 148cb6afcb1SStephan Aßmus } 149573f748cSJohn Scipione 150573f748cSJohn Scipione // Create the time view 151*31c0024dSJohn Scipione fTime = new TTimeView(fMinimumTrayWidth, kMaxReplicantHeight - 1.0); 15241281cf3SAxel Dörfler } 15341281cf3SAxel Dörfler 15441281cf3SAxel Dörfler 15541281cf3SAxel Dörfler TReplicantTray::~TReplicantTray() 15641281cf3SAxel Dörfler { 15741281cf3SAxel Dörfler delete fShelf; 158573f748cSJohn Scipione delete fTime; 15941281cf3SAxel Dörfler } 16041281cf3SAxel Dörfler 16141281cf3SAxel Dörfler 16241281cf3SAxel Dörfler void 16341281cf3SAxel Dörfler TReplicantTray::AttachedToWindow() 16441281cf3SAxel Dörfler { 16541281cf3SAxel Dörfler BView::AttachedToWindow(); 16641281cf3SAxel Dörfler 167cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 168cb6afcb1SStephan Aßmus SetViewColor(Parent()->ViewColor()); 169cb6afcb1SStephan Aßmus } else { 17066eba86fSAxel Dörfler SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 17166eba86fSAxel Dörfler B_DARKEN_1_TINT)); 172cb6afcb1SStephan Aßmus } 17341281cf3SAxel Dörfler SetDrawingMode(B_OP_COPY); 17466eba86fSAxel Dörfler 17541281cf3SAxel Dörfler Window()->SetPulseRate(1000000); 17641281cf3SAxel Dörfler 177*31c0024dSJohn Scipione // Set clock settings 178*31c0024dSJohn Scipione clock_settings* settings = ((TBarApp*)be_app)->ClockSettings(); 179*31c0024dSJohn Scipione fTime->SetShowSeconds(settings->showSeconds); 180*31c0024dSJohn Scipione fTime->SetShowDayOfWeek(settings->showDayOfWeek); 181*31c0024dSJohn Scipione fTime->SetShowTimeZone(settings->showTimeZone); 182*31c0024dSJohn Scipione 183573f748cSJohn Scipione AddChild(fTime); 184573f748cSJohn Scipione fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - 1, 2); 185ae7a6e3aSAdrien Destugues 18641281cf3SAxel Dörfler #ifdef DB_ADDONS 18741281cf3SAxel Dörfler // load addons and rehydrate archives 1883a6add49SAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 18941281cf3SAxel Dörfler InitAddOnSupport(); 19041281cf3SAxel Dörfler #endif 1919c910f9eSStephan Aßmus #endif 19241281cf3SAxel Dörfler ResizeToPreferred(); 19341281cf3SAxel Dörfler } 19441281cf3SAxel Dörfler 19541281cf3SAxel Dörfler 19641281cf3SAxel Dörfler void 19741281cf3SAxel Dörfler TReplicantTray::DetachedFromWindow() 19841281cf3SAxel Dörfler { 19941281cf3SAxel Dörfler #ifdef DB_ADDONS 20041281cf3SAxel Dörfler // clean up add-on support 201465b54cdSAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 20241281cf3SAxel Dörfler DeleteAddOnSupport(); 20341281cf3SAxel Dörfler #endif 204465b54cdSAxel Dörfler #endif 20541281cf3SAxel Dörfler BView::DetachedFromWindow(); 20641281cf3SAxel Dörfler } 20741281cf3SAxel Dörfler 20841281cf3SAxel Dörfler 2091ad8c760SFredrik Holmqvist /*! Width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth 21066eba86fSAxel Dörfler if not in multirowmode and greater than kMinimumReplicantCount 2112ce9bab8SJohn Scipione the width should be calculated based on the actual replicant widths 21241281cf3SAxel Dörfler */ 21341281cf3SAxel Dörfler void 21441281cf3SAxel Dörfler TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight) 21541281cf3SAxel Dörfler { 21641281cf3SAxel Dörfler float width = 0, height = kMinimumTrayHeight; 21741281cf3SAxel Dörfler 21841281cf3SAxel Dörfler if (fMultiRowMode) { 2197da06231SAxel Dörfler if (fShelf->CountReplicants() > 0) 2207da06231SAxel Dörfler height = fRightBottomReplicant.bottom; 22141281cf3SAxel Dörfler 2221ad8c760SFredrik Holmqvist // the height will be uniform for the number of rows necessary to show 2231ad8c760SFredrik Holmqvist // all the reps + any gutters necessary for spacing 22441281cf3SAxel Dörfler int32 rowCount = (int32)(height / kMaxReplicantHeight); 22541281cf3SAxel Dörfler height = kGutter + (rowCount * kMaxReplicantHeight) 22641281cf3SAxel Dörfler + ((rowCount - 1) * kIconGap) + kGutter; 22741281cf3SAxel Dörfler height = max(kMinimumTrayHeight, height); 228cb6afcb1SStephan Aßmus width = fMinimumTrayWidth; 22941281cf3SAxel Dörfler } else { 2301ad8c760SFredrik Holmqvist // if last replicant overruns clock then resize to accomodate 2317da06231SAxel Dörfler if (fShelf->CountReplicants() > 0) { 232573f748cSJohn Scipione if (!fTime->IsHidden() && fTime->Frame().left 233573f748cSJohn Scipione < fRightBottomReplicant.right + 6) { 23466eba86fSAxel Dörfler width = fRightBottomReplicant.right + 6 235573f748cSJohn Scipione + fTime->Frame().Width(); 23641281cf3SAxel Dörfler } else 2377da06231SAxel Dörfler width = fRightBottomReplicant.right + 3; 23841281cf3SAxel Dörfler } 2391ad8c760SFredrik Holmqvist 24041281cf3SAxel Dörfler // this view has a fixed minimum width 241cb6afcb1SStephan Aßmus width = max(fMinimumTrayWidth, width); 2422ce9bab8SJohn Scipione height = kGutter + static_cast<TBarApp*>(be_app)->IconSize() + kGutter; 24341281cf3SAxel Dörfler } 24441281cf3SAxel Dörfler 24541281cf3SAxel Dörfler *preferredWidth = width; 2461ad8c760SFredrik Holmqvist // add 1 for the border 24741281cf3SAxel Dörfler *preferredHeight = height + 1; 24841281cf3SAxel Dörfler } 24941281cf3SAxel Dörfler 25041281cf3SAxel Dörfler 25141281cf3SAxel Dörfler void 25241281cf3SAxel Dörfler TReplicantTray::AdjustPlacement() 25341281cf3SAxel Dörfler { 25441281cf3SAxel Dörfler // called when an add-on has been added or removed 25541281cf3SAxel Dörfler // need to resize the parent of this accordingly 256a5210ab1SAxel Dörfler 25741281cf3SAxel Dörfler BRect bounds = Bounds(); 25841281cf3SAxel Dörfler float width, height; 25941281cf3SAxel Dörfler GetPreferredSize(&width, &height); 26041281cf3SAxel Dörfler 26141281cf3SAxel Dörfler if (width == bounds.Width() && height == bounds.Height()) { 26241281cf3SAxel Dörfler // no need to change anything 26341281cf3SAxel Dörfler return; 26441281cf3SAxel Dörfler } 26541281cf3SAxel Dörfler 26641281cf3SAxel Dörfler Parent()->ResizeToPreferred(); 26741281cf3SAxel Dörfler fBarView->UpdatePlacement(); 26841281cf3SAxel Dörfler Parent()->Invalidate(); 26941281cf3SAxel Dörfler Invalidate(); 27041281cf3SAxel Dörfler } 27141281cf3SAxel Dörfler 27241281cf3SAxel Dörfler 27341281cf3SAxel Dörfler void 27441281cf3SAxel Dörfler TReplicantTray::MessageReceived(BMessage* message) 27541281cf3SAxel Dörfler { 27641281cf3SAxel Dörfler switch (message->what) { 27730a55802SJohn Scipione case B_LOCALE_CHANGED: 278573f748cSJohn Scipione { 279573f748cSJohn Scipione if (fTime == NULL) 280573f748cSJohn Scipione return; 281573f748cSJohn Scipione 282*31c0024dSJohn Scipione fTime->Update(); 28330a55802SJohn Scipione 28441281cf3SAxel Dörfler // time string reformat -> realign 28541281cf3SAxel Dörfler RealignReplicants(); 28641281cf3SAxel Dörfler AdjustPlacement(); 28741281cf3SAxel Dörfler break; 288573f748cSJohn Scipione } 289573f748cSJohn Scipione 29030a55802SJohn Scipione case kShowHideTime: 29130a55802SJohn Scipione // from context menu in clock and in this view 29230a55802SJohn Scipione ShowHideTime(); 29330a55802SJohn Scipione break; 29430a55802SJohn Scipione 2953cf2d117SJohn Scipione case kShowSeconds: 296573f748cSJohn Scipione if (fTime == NULL) 297573f748cSJohn Scipione return; 298573f748cSJohn Scipione 2993cf2d117SJohn Scipione fTime->SetShowSeconds(!fTime->ShowSeconds()); 300573f748cSJohn Scipione 3013cf2d117SJohn Scipione // time string reformat -> realign 3023cf2d117SJohn Scipione RealignReplicants(); 3033cf2d117SJohn Scipione AdjustPlacement(); 304573f748cSJohn Scipione break; 3053cf2d117SJohn Scipione 3063cf2d117SJohn Scipione case kShowDayOfWeek: 3073cf2d117SJohn Scipione if (fTime == NULL) 3083cf2d117SJohn Scipione return; 3093cf2d117SJohn Scipione 3103cf2d117SJohn Scipione fTime->SetShowDayOfWeek(!fTime->ShowDayOfWeek()); 3113cf2d117SJohn Scipione 3123cf2d117SJohn Scipione // time string reformat -> realign 3133cf2d117SJohn Scipione RealignReplicants(); 3143cf2d117SJohn Scipione AdjustPlacement(); 3153cf2d117SJohn Scipione break; 3163cf2d117SJohn Scipione 317*31c0024dSJohn Scipione case kShowTimeZone: 318*31c0024dSJohn Scipione if (fTime == NULL) 319*31c0024dSJohn Scipione return; 320*31c0024dSJohn Scipione 321*31c0024dSJohn Scipione fTime->SetShowTimeZone(!fTime->ShowTimeZone()); 322*31c0024dSJohn Scipione 323*31c0024dSJohn Scipione // time string reformat -> realign 324*31c0024dSJohn Scipione RealignReplicants(); 325*31c0024dSJohn Scipione AdjustPlacement(); 326*31c0024dSJohn Scipione break; 327*31c0024dSJohn Scipione 328*31c0024dSJohn Scipione case kGetClockSettings: 329*31c0024dSJohn Scipione { 330*31c0024dSJohn Scipione if (fTime == NULL) 331*31c0024dSJohn Scipione return; 332*31c0024dSJohn Scipione 333*31c0024dSJohn Scipione bool showClock = !fTime->IsHidden(); 334*31c0024dSJohn Scipione bool showSeconds = fTime->ShowSeconds(); 335*31c0024dSJohn Scipione bool showDayOfWeek = fTime->ShowDayOfWeek(); 336*31c0024dSJohn Scipione bool showTimeZone = fTime->ShowTimeZone(); 337*31c0024dSJohn Scipione 338*31c0024dSJohn Scipione BMessage* reply = new BMessage(kGetClockSettings); 339*31c0024dSJohn Scipione reply->AddBool("showClock", showClock); 340*31c0024dSJohn Scipione reply->AddBool("showSeconds", showSeconds); 341*31c0024dSJohn Scipione reply->AddBool("showDayOfWeek", showDayOfWeek); 342*31c0024dSJohn Scipione reply->AddBool("showTimeZone", showTimeZone); 343*31c0024dSJohn Scipione message->SendReply(reply); 344*31c0024dSJohn Scipione break; 345*31c0024dSJohn Scipione } 346*31c0024dSJohn Scipione 34741281cf3SAxel Dörfler #ifdef DB_ADDONS 34841281cf3SAxel Dörfler case B_NODE_MONITOR: 34941281cf3SAxel Dörfler HandleEntryUpdate(message); 35041281cf3SAxel Dörfler break; 35141281cf3SAxel Dörfler #endif 35241281cf3SAxel Dörfler 35341281cf3SAxel Dörfler default: 35441281cf3SAxel Dörfler BView::MessageReceived(message); 35541281cf3SAxel Dörfler break; 35641281cf3SAxel Dörfler } 35741281cf3SAxel Dörfler } 35841281cf3SAxel Dörfler 35941281cf3SAxel Dörfler 36041281cf3SAxel Dörfler void 36141281cf3SAxel Dörfler TReplicantTray::MouseDown(BPoint where) 36241281cf3SAxel Dörfler { 36341281cf3SAxel Dörfler #ifdef DB_ADDONS 36441281cf3SAxel Dörfler if (modifiers() & B_CONTROL_KEY) 36541281cf3SAxel Dörfler DumpList(fItemList); 36641281cf3SAxel Dörfler #endif 36741281cf3SAxel Dörfler 36841281cf3SAxel Dörfler uint32 buttons; 36941281cf3SAxel Dörfler 37041281cf3SAxel Dörfler Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons); 37141281cf3SAxel Dörfler if (buttons == B_SECONDARY_MOUSE_BUTTON) { 37241281cf3SAxel Dörfler ShowReplicantMenu(where); 37341281cf3SAxel Dörfler } else { 37441281cf3SAxel Dörfler BPoint save = where; 37541281cf3SAxel Dörfler bigtime_t doubleClickSpeed; 37641281cf3SAxel Dörfler bigtime_t start = system_time(); 37741281cf3SAxel Dörfler uint32 buttons; 37841281cf3SAxel Dörfler 37941281cf3SAxel Dörfler get_click_speed(&doubleClickSpeed); 38041281cf3SAxel Dörfler 38141281cf3SAxel Dörfler do { 38241281cf3SAxel Dörfler if (fabs(where.x - save.x) > 4 || fabs(where.y - save.y) > 4) 38341281cf3SAxel Dörfler // user moved out of bounds of click area 38441281cf3SAxel Dörfler break; 38541281cf3SAxel Dörfler 38641281cf3SAxel Dörfler if ((system_time() - start) > (2 * doubleClickSpeed)) { 38741281cf3SAxel Dörfler ShowReplicantMenu(where); 38841281cf3SAxel Dörfler break; 38941281cf3SAxel Dörfler } 39041281cf3SAxel Dörfler 39141281cf3SAxel Dörfler snooze(50000); 39241281cf3SAxel Dörfler GetMouse(&where, &buttons); 39341281cf3SAxel Dörfler } while (buttons); 39441281cf3SAxel Dörfler } 39541281cf3SAxel Dörfler BView::MouseDown(where); 39641281cf3SAxel Dörfler } 39741281cf3SAxel Dörfler 3983cf2d117SJohn Scipione 3993cf2d117SJohn Scipione void 4003cf2d117SJohn Scipione TReplicantTray::ShowReplicantMenu(BPoint point) 4013cf2d117SJohn Scipione { 4023cf2d117SJohn Scipione BPopUpMenu* menu = new BPopUpMenu("", false, false); 4033cf2d117SJohn Scipione menu->SetFont(be_plain_font); 4043cf2d117SJohn Scipione 405*31c0024dSJohn Scipione // If clock is visible show the extended menu, otherwise show "Show clock" 4063cf2d117SJohn Scipione 4073cf2d117SJohn Scipione if (!fTime->IsHidden()) 4083cf2d117SJohn Scipione fTime->ShowTimeOptions(ConvertToScreen(point)); 4093cf2d117SJohn Scipione else { 410*31c0024dSJohn Scipione BMenuItem* item = new BMenuItem(B_TRANSLATE("Show clock"), 4113cf2d117SJohn Scipione new BMessage(kShowHideTime)); 4123cf2d117SJohn Scipione menu->AddItem(item); 4133cf2d117SJohn Scipione menu->SetTargetForItems(this); 4143cf2d117SJohn Scipione BPoint where = ConvertToScreen(point); 4153cf2d117SJohn Scipione menu->Go(where, true, true, BRect(where - BPoint(4, 4), 4163cf2d117SJohn Scipione where + BPoint(4, 4)), true); 4173cf2d117SJohn Scipione } 4183cf2d117SJohn Scipione } 4193cf2d117SJohn Scipione 4203cf2d117SJohn Scipione 4213cf2d117SJohn Scipione void 4223cf2d117SJohn Scipione TReplicantTray::SetMultiRow(bool state) 4233cf2d117SJohn Scipione { 4243cf2d117SJohn Scipione fMultiRowMode = state; 4253cf2d117SJohn Scipione } 4263cf2d117SJohn Scipione 4273cf2d117SJohn Scipione 4283cf2d117SJohn Scipione void 4293cf2d117SJohn Scipione TReplicantTray::ShowHideTime() 4303cf2d117SJohn Scipione { 4313cf2d117SJohn Scipione if (fTime == NULL) 4323cf2d117SJohn Scipione return; 4333cf2d117SJohn Scipione 4343cf2d117SJohn Scipione if (fTime->IsHidden()) 4353cf2d117SJohn Scipione fTime->Show(); 4363cf2d117SJohn Scipione else 4373cf2d117SJohn Scipione fTime->Hide(); 4383cf2d117SJohn Scipione 4393cf2d117SJohn Scipione RealignReplicants(); 4403cf2d117SJohn Scipione AdjustPlacement(); 441*31c0024dSJohn Scipione 442*31c0024dSJohn Scipione // message Time preferences to update it's show time setting 443*31c0024dSJohn Scipione BMessenger messenger("application/x-vnd.Haiku-Time"); 444*31c0024dSJohn Scipione BMessage* message = new BMessage(kShowHideTime); 445*31c0024dSJohn Scipione message->AddBool("showClock", !fTime->IsHidden()); 446*31c0024dSJohn Scipione messenger.SendMessage(message); 4473cf2d117SJohn Scipione } 4483cf2d117SJohn Scipione 4493cf2d117SJohn Scipione 45041281cf3SAxel Dörfler #ifdef DB_ADDONS 45141281cf3SAxel Dörfler 4523cf2d117SJohn Scipione 45341281cf3SAxel Dörfler void 45441281cf3SAxel Dörfler TReplicantTray::InitAddOnSupport() 45541281cf3SAxel Dörfler { 45641281cf3SAxel Dörfler // list to maintain refs to each rep added/deleted 45741281cf3SAxel Dörfler fItemList = new BList(); 45841281cf3SAxel Dörfler BPath path; 4591ad8c760SFredrik Holmqvist 46041281cf3SAxel Dörfler if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) { 4613e6ff860SRene Gollent path.Append(kReplicantSettingsFile); 46241281cf3SAxel Dörfler 46341281cf3SAxel Dörfler BFile file(path.Path(), B_READ_ONLY); 4643e6ff860SRene Gollent if (file.InitCheck() == B_OK) { 4653e6ff860SRene Gollent status_t result; 4663e6ff860SRene Gollent BEntry entry; 4673e6ff860SRene Gollent int32 id; 468c0ad1c91SRene Gollent BString path; 4693e6ff860SRene Gollent if (fAddOnSettings.Unflatten(&file) == B_OK) { 470c0ad1c91SRene Gollent for (int32 i = 0; fAddOnSettings.FindString(kReplicantPathField, 471c0ad1c91SRene Gollent i, &path) == B_OK; i++) { 472c0ad1c91SRene Gollent if (entry.SetTo(path.String()) == B_OK && entry.Exists()) { 4733e6ff860SRene Gollent result = LoadAddOn(&entry, &id, false); 4743e6ff860SRene Gollent } else 4753e6ff860SRene Gollent result = B_ENTRY_NOT_FOUND; 47641281cf3SAxel Dörfler 4773e6ff860SRene Gollent if (result != B_OK) { 478c0ad1c91SRene Gollent fAddOnSettings.RemoveData(kReplicantPathField, i); 4793e6ff860SRene Gollent --i; 48041281cf3SAxel Dörfler } 48141281cf3SAxel Dörfler } 48241281cf3SAxel Dörfler } 4833e6ff860SRene Gollent } 4843e6ff860SRene Gollent } 48541281cf3SAxel Dörfler } 48641281cf3SAxel Dörfler 48741281cf3SAxel Dörfler 48841281cf3SAxel Dörfler void 48941281cf3SAxel Dörfler TReplicantTray::DeleteAddOnSupport() 49041281cf3SAxel Dörfler { 4917625ce51SRene Gollent _SaveSettings(); 4923e6ff860SRene Gollent 49341281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 49441281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->RemoveItem(i); 49541281cf3SAxel Dörfler if (item) { 49641281cf3SAxel Dörfler if (item->isAddOn) 49741281cf3SAxel Dörfler watch_node(&(item->nodeRef), B_STOP_WATCHING, this, Window()); 49841281cf3SAxel Dörfler 49941281cf3SAxel Dörfler delete item; 50041281cf3SAxel Dörfler } 50141281cf3SAxel Dörfler } 50241281cf3SAxel Dörfler delete fItemList; 50341281cf3SAxel Dörfler 50441281cf3SAxel Dörfler // stop the volume mount/unmount watch 50541281cf3SAxel Dörfler stop_watching(this, Window()); 50641281cf3SAxel Dörfler } 50741281cf3SAxel Dörfler 50841281cf3SAxel Dörfler 50941281cf3SAxel Dörfler DeskbarItemInfo* 51041281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(node_ref& nodeRef) 51141281cf3SAxel Dörfler { 51241281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 51366eba86fSAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 51441281cf3SAxel Dörfler if (item == NULL) 51541281cf3SAxel Dörfler continue; 51641281cf3SAxel Dörfler 51741281cf3SAxel Dörfler if (item->nodeRef == nodeRef) 51841281cf3SAxel Dörfler return item; 51941281cf3SAxel Dörfler } 52041281cf3SAxel Dörfler 52141281cf3SAxel Dörfler return NULL; 52241281cf3SAxel Dörfler } 52341281cf3SAxel Dörfler 52441281cf3SAxel Dörfler 52541281cf3SAxel Dörfler DeskbarItemInfo* 52641281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(int32 id) 52741281cf3SAxel Dörfler { 52841281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 52966eba86fSAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 53041281cf3SAxel Dörfler if (item == NULL) 53141281cf3SAxel Dörfler continue; 53241281cf3SAxel Dörfler 53341281cf3SAxel Dörfler if (item->id == id) 53441281cf3SAxel Dörfler return item; 53541281cf3SAxel Dörfler } 53641281cf3SAxel Dörfler 53741281cf3SAxel Dörfler return NULL; 53841281cf3SAxel Dörfler } 53941281cf3SAxel Dörfler 54041281cf3SAxel Dörfler 54141281cf3SAxel Dörfler bool 54241281cf3SAxel Dörfler TReplicantTray::NodeExists(node_ref& nodeRef) 54341281cf3SAxel Dörfler { 54441281cf3SAxel Dörfler return DeskbarItemFor(nodeRef) != NULL; 54541281cf3SAxel Dörfler } 54641281cf3SAxel Dörfler 54741281cf3SAxel Dörfler 54866eba86fSAxel Dörfler /*! This handles B_NODE_MONITOR & B_QUERY_UPDATE messages received 54966eba86fSAxel Dörfler for the registered add-ons. 55041281cf3SAxel Dörfler */ 55141281cf3SAxel Dörfler void 55241281cf3SAxel Dörfler TReplicantTray::HandleEntryUpdate(BMessage* message) 55341281cf3SAxel Dörfler { 55441281cf3SAxel Dörfler int32 opcode; 55541281cf3SAxel Dörfler if (message->FindInt32("opcode", &opcode) != B_OK) 55641281cf3SAxel Dörfler return; 55741281cf3SAxel Dörfler 55841281cf3SAxel Dörfler BPath path; 55941281cf3SAxel Dörfler switch (opcode) { 56041281cf3SAxel Dörfler case B_ENTRY_MOVED: 56141281cf3SAxel Dörfler { 56241281cf3SAxel Dörfler entry_ref ref; 56341281cf3SAxel Dörfler ino_t todirectory; 56441281cf3SAxel Dörfler ino_t node; 56541281cf3SAxel Dörfler const char* name; 56641281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK 56771bd3ba5SJonas Sundström && message->FindInt64("from directory", &(ref.directory)) 56871bd3ba5SJonas Sundström == B_OK 56941281cf3SAxel Dörfler && message->FindInt64("to directory", &todirectory) == B_OK 57041281cf3SAxel Dörfler && message->FindInt32("device", &(ref.device)) == B_OK 57141281cf3SAxel Dörfler && message->FindInt64("node", &node) == B_OK ) { 57241281cf3SAxel Dörfler 57341281cf3SAxel Dörfler if (!name) 57441281cf3SAxel Dörfler break; 57541281cf3SAxel Dörfler 57641281cf3SAxel Dörfler ref.set_name(name); 57741281cf3SAxel Dörfler // change the directory reference to 57841281cf3SAxel Dörfler // the new directory 57941281cf3SAxel Dörfler MoveItem(&ref, todirectory); 58041281cf3SAxel Dörfler } 58141281cf3SAxel Dörfler break; 58266eba86fSAxel Dörfler } 58341281cf3SAxel Dörfler 58441281cf3SAxel Dörfler case B_ENTRY_REMOVED: 58541281cf3SAxel Dörfler { 58641281cf3SAxel Dörfler // entry was rm'd from the device 58741281cf3SAxel Dörfler node_ref nodeRef; 58841281cf3SAxel Dörfler if (message->FindInt32("device", &(nodeRef.device)) == B_OK 58941281cf3SAxel Dörfler && message->FindInt64("node", &(nodeRef.node)) == B_OK) { 59041281cf3SAxel Dörfler DeskbarItemInfo* item = DeskbarItemFor(nodeRef); 59141281cf3SAxel Dörfler if (item == NULL) 59241281cf3SAxel Dörfler break; 59341281cf3SAxel Dörfler 59441281cf3SAxel Dörfler // If there is a team running where the add-on comes from, 59541281cf3SAxel Dörfler // we don't want to remove the icon yet. 59641281cf3SAxel Dörfler if (be_roster->IsRunning(&item->entryRef)) 59741281cf3SAxel Dörfler break; 59841281cf3SAxel Dörfler 59941281cf3SAxel Dörfler UnloadAddOn(&nodeRef, NULL, true, false); 60041281cf3SAxel Dörfler } 60141281cf3SAxel Dörfler break; 60266eba86fSAxel Dörfler } 60341281cf3SAxel Dörfler } 60466eba86fSAxel Dörfler } 60541281cf3SAxel Dörfler 60641281cf3SAxel Dörfler 6071ad8c760SFredrik Holmqvist /*! The add-ons must support the exported C function API 60866eba86fSAxel Dörfler if they do, they will be loaded and added to deskbar 60966eba86fSAxel Dörfler primary function is the Instantiate function 6107da06231SAxel Dörfler */ 61141281cf3SAxel Dörfler status_t 6123e6ff860SRene Gollent TReplicantTray::LoadAddOn(BEntry* entry, int32* id, bool addToSettings) 61341281cf3SAxel Dörfler { 61441281cf3SAxel Dörfler if (!entry) 61541281cf3SAxel Dörfler return B_ERROR; 61641281cf3SAxel Dörfler 61741281cf3SAxel Dörfler node_ref nodeRef; 61841281cf3SAxel Dörfler entry->GetNodeRef(&nodeRef); 61941281cf3SAxel Dörfler // no duplicates 62041281cf3SAxel Dörfler if (NodeExists(nodeRef)) 62141281cf3SAxel Dörfler return B_ERROR; 62241281cf3SAxel Dörfler 62341281cf3SAxel Dörfler BNode node(entry); 62441281cf3SAxel Dörfler BPath path; 62566eba86fSAxel Dörfler status_t status = entry->GetPath(&path); 62666eba86fSAxel Dörfler if (status < B_OK) 62766eba86fSAxel Dörfler return status; 62841281cf3SAxel Dörfler 62941281cf3SAxel Dörfler // load the add-on 63041281cf3SAxel Dörfler image_id image = load_add_on(path.Path()); 63166eba86fSAxel Dörfler if (image < B_OK) 63266eba86fSAxel Dörfler return image; 63341281cf3SAxel Dörfler 63441281cf3SAxel Dörfler // get the view loading function symbol 63541281cf3SAxel Dörfler // we first look for a symbol that takes an image_id 63641281cf3SAxel Dörfler // and entry_ref pointer, if not found, go with normal 63741281cf3SAxel Dörfler // instantiate function 63841281cf3SAxel Dörfler BView* (*entryFunction)(image_id, const entry_ref*); 63941281cf3SAxel Dörfler BView* (*itemFunction)(void); 64041281cf3SAxel Dörfler BView* view = NULL; 64141281cf3SAxel Dörfler 64241281cf3SAxel Dörfler entry_ref ref; 64341281cf3SAxel Dörfler entry->GetRef(&ref); 64441281cf3SAxel Dörfler 64541281cf3SAxel Dörfler if (get_image_symbol(image, kInstantiateEntryCFunctionName, 64666eba86fSAxel Dörfler B_SYMBOL_TYPE_TEXT, (void**)&entryFunction) >= B_OK) { 64741281cf3SAxel Dörfler view = (*entryFunction)(image, &ref); 64841281cf3SAxel Dörfler } else if (get_image_symbol(image, kInstantiateItemCFunctionName, 64966eba86fSAxel Dörfler B_SYMBOL_TYPE_TEXT, (void**)&itemFunction) >= B_OK) { 65041281cf3SAxel Dörfler view = (*itemFunction)(); 65141281cf3SAxel Dörfler } else { 65241281cf3SAxel Dörfler unload_add_on(image); 65341281cf3SAxel Dörfler return B_ERROR; 65441281cf3SAxel Dörfler } 65541281cf3SAxel Dörfler 65666eba86fSAxel Dörfler if (view == NULL || IconExists(view->Name())) { 65741281cf3SAxel Dörfler delete view; 65841281cf3SAxel Dörfler unload_add_on(image); 65941281cf3SAxel Dörfler return B_ERROR; 66041281cf3SAxel Dörfler } 66141281cf3SAxel Dörfler 66241281cf3SAxel Dörfler BMessage* data = new BMessage; 66341281cf3SAxel Dörfler view->Archive(data); 66441281cf3SAxel Dörfler delete view; 66541281cf3SAxel Dörfler 66641281cf3SAxel Dörfler AddIcon(data, id, &ref); 66741281cf3SAxel Dörfler // add the rep; adds info to list 66841281cf3SAxel Dörfler 6693e6ff860SRene Gollent if (addToSettings) { 670c0ad1c91SRene Gollent fAddOnSettings.AddString(kReplicantPathField, path.Path()); 6717625ce51SRene Gollent _SaveSettings(); 6723e6ff860SRene Gollent } 67341281cf3SAxel Dörfler 67441281cf3SAxel Dörfler return B_OK; 67541281cf3SAxel Dörfler } 67641281cf3SAxel Dörfler 67741281cf3SAxel Dörfler 67841281cf3SAxel Dörfler status_t 67941281cf3SAxel Dörfler TReplicantTray::AddItem(int32 id, node_ref nodeRef, BEntry& entry, bool isAddOn) 68041281cf3SAxel Dörfler { 68141281cf3SAxel Dörfler DeskbarItemInfo* item = new DeskbarItemInfo; 68241281cf3SAxel Dörfler if (item == NULL) 68341281cf3SAxel Dörfler return B_NO_MEMORY; 68441281cf3SAxel Dörfler 68541281cf3SAxel Dörfler item->id = id; 68641281cf3SAxel Dörfler item->isAddOn = isAddOn; 68741281cf3SAxel Dörfler 68841281cf3SAxel Dörfler if (entry.GetRef(&item->entryRef) < B_OK) { 68941281cf3SAxel Dörfler item->entryRef.device = -1; 69041281cf3SAxel Dörfler item->entryRef.directory = -1; 69141281cf3SAxel Dörfler item->entryRef.name = NULL; 69241281cf3SAxel Dörfler } 69341281cf3SAxel Dörfler item->nodeRef = nodeRef; 69441281cf3SAxel Dörfler 69541281cf3SAxel Dörfler fItemList->AddItem(item); 69641281cf3SAxel Dörfler 69741281cf3SAxel Dörfler if (isAddOn) 69841281cf3SAxel Dörfler watch_node(&nodeRef, B_WATCH_NAME | B_WATCH_ATTR, this, Window()); 69941281cf3SAxel Dörfler 70041281cf3SAxel Dörfler return B_OK; 70141281cf3SAxel Dörfler } 70241281cf3SAxel Dörfler 70341281cf3SAxel Dörfler 70441281cf3SAxel Dörfler /** from entry_removed message, when attribute removed 70541281cf3SAxel Dörfler * or when a device is unmounted (use removeall, by device) 70641281cf3SAxel Dörfler */ 70741281cf3SAxel Dörfler 70841281cf3SAxel Dörfler void 70941281cf3SAxel Dörfler TReplicantTray::UnloadAddOn(node_ref* nodeRef, dev_t* device, 71041281cf3SAxel Dörfler bool which, bool removeAll) 71141281cf3SAxel Dörfler { 71241281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 71341281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 71441281cf3SAxel Dörfler if (!item) 71541281cf3SAxel Dörfler continue; 71641281cf3SAxel Dörfler 71741281cf3SAxel Dörfler if ((which && nodeRef && item->nodeRef == *nodeRef) 71841281cf3SAxel Dörfler || (device && item->nodeRef.device == *device)) { 71941281cf3SAxel Dörfler 72041281cf3SAxel Dörfler if (device && be_roster->IsRunning(&item->entryRef)) 72141281cf3SAxel Dörfler continue; 72241281cf3SAxel Dörfler 72341281cf3SAxel Dörfler RemoveIcon(item->id); 72441281cf3SAxel Dörfler 72541281cf3SAxel Dörfler if (!removeAll) 72641281cf3SAxel Dörfler break; 72741281cf3SAxel Dörfler } 72841281cf3SAxel Dörfler } 72941281cf3SAxel Dörfler } 73041281cf3SAxel Dörfler 73141281cf3SAxel Dörfler 73241281cf3SAxel Dörfler void 73341281cf3SAxel Dörfler TReplicantTray::RemoveItem(int32 id) 73441281cf3SAxel Dörfler { 73541281cf3SAxel Dörfler DeskbarItemInfo* item = DeskbarItemFor(id); 73641281cf3SAxel Dörfler if (item == NULL) 73741281cf3SAxel Dörfler return; 73841281cf3SAxel Dörfler 73941281cf3SAxel Dörfler // attribute was added via Deskbar API (AddItem(entry_ref*, int32*) 74041281cf3SAxel Dörfler if (item->isAddOn) { 7417625ce51SRene Gollent BPath path(&item->entryRef); 7427625ce51SRene Gollent BString storedPath; 7437625ce51SRene Gollent for (int32 i = 0; 7448aab28f1SRene Gollent fAddOnSettings.FindString(kReplicantPathField, i, &storedPath) 7457625ce51SRene Gollent == B_OK; i++) { 7467625ce51SRene Gollent if (storedPath == path.Path()) { 7478aab28f1SRene Gollent fAddOnSettings.RemoveData(kReplicantPathField, i); 7487625ce51SRene Gollent break; 7497625ce51SRene Gollent } 7507625ce51SRene Gollent } 7517625ce51SRene Gollent _SaveSettings(); 7527625ce51SRene Gollent 75341281cf3SAxel Dörfler BNode node(&item->entryRef); 75441281cf3SAxel Dörfler watch_node(&item->nodeRef, B_STOP_WATCHING, this, Window()); 75541281cf3SAxel Dörfler } 75641281cf3SAxel Dörfler 75741281cf3SAxel Dörfler fItemList->RemoveItem(item); 75841281cf3SAxel Dörfler delete item; 75941281cf3SAxel Dörfler } 76041281cf3SAxel Dörfler 76141281cf3SAxel Dörfler 76241281cf3SAxel Dörfler /** ENTRY_MOVED message, moving only occurs on a device 76341281cf3SAxel Dörfler * copying will occur (ENTRY_CREATED) between devices 76441281cf3SAxel Dörfler */ 76541281cf3SAxel Dörfler 76641281cf3SAxel Dörfler void 76741281cf3SAxel Dörfler TReplicantTray::MoveItem(entry_ref* ref, ino_t toDirectory) 76841281cf3SAxel Dörfler { 76941281cf3SAxel Dörfler if (!ref) 77041281cf3SAxel Dörfler return; 77141281cf3SAxel Dörfler 77241281cf3SAxel Dörfler // scan for a matching entry_ref and update it 77341281cf3SAxel Dörfler // 77441281cf3SAxel Dörfler // don't need to change node info as it does not change 77541281cf3SAxel Dörfler 77641281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 77741281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 77841281cf3SAxel Dörfler if (!item) 77941281cf3SAxel Dörfler continue; 78041281cf3SAxel Dörfler 78141281cf3SAxel Dörfler if (!strcmp(item->entryRef.name, ref->name) 78241281cf3SAxel Dörfler && item->entryRef.device == ref->device 78341281cf3SAxel Dörfler && item->entryRef.directory == ref->directory) { 78441281cf3SAxel Dörfler item->entryRef.directory = toDirectory; 78541281cf3SAxel Dörfler break; 78641281cf3SAxel Dörfler } 78741281cf3SAxel Dörfler } 78841281cf3SAxel Dörfler } 78941281cf3SAxel Dörfler 79041281cf3SAxel Dörfler #endif // add-on support 79141281cf3SAxel Dörfler 79241281cf3SAxel Dörfler // external add-on API routines 79341281cf3SAxel Dörfler // called using the new BDeskbar class 79441281cf3SAxel Dörfler 79541281cf3SAxel Dörfler // existence of icon/replicant by name or ID 79641281cf3SAxel Dörfler // returns opposite 79741281cf3SAxel Dörfler // note: name and id are semi-private limiting 79841281cf3SAxel Dörfler // the ability of non-host apps to remove 79941281cf3SAxel Dörfler // icons without a little bit of work 80041281cf3SAxel Dörfler 80141281cf3SAxel Dörfler /** for a specific id 80241281cf3SAxel Dörfler * return the name of the replicant (name of view) 80341281cf3SAxel Dörfler */ 80441281cf3SAxel Dörfler 80541281cf3SAxel Dörfler status_t 80641281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 id, const char** name) 80741281cf3SAxel Dörfler { 80841281cf3SAxel Dörfler if (id < 0) 80941281cf3SAxel Dörfler return B_ERROR; 81041281cf3SAxel Dörfler 81141281cf3SAxel Dörfler int32 index, temp; 81241281cf3SAxel Dörfler BView* view = ViewAt(&index, &temp, id, false); 81341281cf3SAxel Dörfler if (view) { 81441281cf3SAxel Dörfler *name = view->Name(); 81541281cf3SAxel Dörfler return B_OK; 81641281cf3SAxel Dörfler } 81741281cf3SAxel Dörfler 81841281cf3SAxel Dörfler return B_ERROR; 81941281cf3SAxel Dörfler } 82041281cf3SAxel Dörfler 82141281cf3SAxel Dörfler 8227da06231SAxel Dörfler /** for a specific name 8237da06231SAxel Dörfler * return the id (internal to Deskbar) 8247da06231SAxel Dörfler */ 8257da06231SAxel Dörfler 82641281cf3SAxel Dörfler status_t 82741281cf3SAxel Dörfler TReplicantTray::ItemInfo(const char* name, int32* id) 82841281cf3SAxel Dörfler { 82941281cf3SAxel Dörfler if (!name || strlen(name) <= 0) 83041281cf3SAxel Dörfler return B_ERROR; 83141281cf3SAxel Dörfler 83241281cf3SAxel Dörfler int32 index; 83341281cf3SAxel Dörfler BView* view = ViewAt(&index, id, name); 83441281cf3SAxel Dörfler if (view) 83541281cf3SAxel Dörfler return B_OK; 83641281cf3SAxel Dörfler 83741281cf3SAxel Dörfler return B_ERROR; 83841281cf3SAxel Dörfler } 83941281cf3SAxel Dörfler 84041281cf3SAxel Dörfler 8417da06231SAxel Dörfler /** at a specific index 8427da06231SAxel Dörfler * return both the name and the id of the replicant 8437da06231SAxel Dörfler */ 8447da06231SAxel Dörfler 84541281cf3SAxel Dörfler status_t 84641281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 index, const char** name, int32* id) 84741281cf3SAxel Dörfler { 84841281cf3SAxel Dörfler if (index < 0) 84941281cf3SAxel Dörfler return B_ERROR; 85041281cf3SAxel Dörfler 85141281cf3SAxel Dörfler BView* view; 85241281cf3SAxel Dörfler fShelf->ReplicantAt(index, &view, (uint32*)id, NULL); 85341281cf3SAxel Dörfler if (view) { 85441281cf3SAxel Dörfler *name = view->Name(); 85541281cf3SAxel Dörfler return B_OK; 85641281cf3SAxel Dörfler } 85741281cf3SAxel Dörfler 85841281cf3SAxel Dörfler return B_ERROR; 85941281cf3SAxel Dörfler } 86041281cf3SAxel Dörfler 86141281cf3SAxel Dörfler 8627da06231SAxel Dörfler /** replicant exists, by id/index */ 8637da06231SAxel Dörfler 86441281cf3SAxel Dörfler bool 86541281cf3SAxel Dörfler TReplicantTray::IconExists(int32 target, bool byIndex) 86641281cf3SAxel Dörfler { 86741281cf3SAxel Dörfler int32 index, id; 86841281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 86941281cf3SAxel Dörfler 87041281cf3SAxel Dörfler return view && index >= 0; 87141281cf3SAxel Dörfler } 87241281cf3SAxel Dörfler 87341281cf3SAxel Dörfler 8747da06231SAxel Dörfler /** replicant exists, by name */ 8757da06231SAxel Dörfler 87641281cf3SAxel Dörfler bool 87741281cf3SAxel Dörfler TReplicantTray::IconExists(const char* name) 87841281cf3SAxel Dörfler { 87941281cf3SAxel Dörfler if (!name || strlen(name) == 0) 88041281cf3SAxel Dörfler return false; 88141281cf3SAxel Dörfler 88241281cf3SAxel Dörfler int32 index, id; 88341281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 88441281cf3SAxel Dörfler 88541281cf3SAxel Dörfler return view && index >= 0; 88641281cf3SAxel Dörfler } 88741281cf3SAxel Dörfler 88841281cf3SAxel Dörfler 88941281cf3SAxel Dörfler int32 89041281cf3SAxel Dörfler TReplicantTray::IconCount() const 89141281cf3SAxel Dörfler { 89241281cf3SAxel Dörfler return fShelf->CountReplicants(); 89341281cf3SAxel Dörfler } 89441281cf3SAxel Dörfler 89541281cf3SAxel Dörfler 896ced3755cSAxel Dörfler /*! Message must contain an archivable view for later rehydration. 897ced3755cSAxel Dörfler This function takes over ownership of the provided message on success 898ced3755cSAxel Dörfler only. 899ced3755cSAxel Dörfler Returns the current replicant ID. 9007da06231SAxel Dörfler */ 90141281cf3SAxel Dörfler status_t 902ced3755cSAxel Dörfler TReplicantTray::AddIcon(BMessage* archive, int32* id, const entry_ref* addOn) 90341281cf3SAxel Dörfler { 904ced3755cSAxel Dörfler if (archive == NULL || id == NULL) 90541281cf3SAxel Dörfler return B_ERROR; 90641281cf3SAxel Dörfler 9079c50f36eSAxel Dörfler // find entry_ref 9089c50f36eSAxel Dörfler 9099c50f36eSAxel Dörfler entry_ref ref; 9109c50f36eSAxel Dörfler if (addOn) { 9119c50f36eSAxel Dörfler // Use it if we got it 9129c50f36eSAxel Dörfler ref = *addOn; 9139c50f36eSAxel Dörfler } else { 9149c50f36eSAxel Dörfler const char* signature; 9151ad8c760SFredrik Holmqvist 916ced3755cSAxel Dörfler status_t status = archive->FindString("add_on", &signature); 9179c50f36eSAxel Dörfler if (status == B_OK) { 9189c50f36eSAxel Dörfler BRoster roster; 9199c50f36eSAxel Dörfler status = roster.FindApp(signature, &ref); 9209c50f36eSAxel Dörfler } 9219c50f36eSAxel Dörfler if (status < B_OK) 9229c50f36eSAxel Dörfler return status; 9239c50f36eSAxel Dörfler } 9249c50f36eSAxel Dörfler 9259c50f36eSAxel Dörfler BFile file; 9269c50f36eSAxel Dörfler status_t status = file.SetTo(&ref, B_READ_ONLY); 9279c50f36eSAxel Dörfler if (status < B_OK) 9289c50f36eSAxel Dörfler return status; 9299c50f36eSAxel Dörfler 9309c50f36eSAxel Dörfler node_ref nodeRef; 9319c50f36eSAxel Dörfler status = file.GetNodeRef(&nodeRef); 9329c50f36eSAxel Dörfler if (status < B_OK) 9339c50f36eSAxel Dörfler return status; 9349c50f36eSAxel Dörfler 9359c50f36eSAxel Dörfler BEntry entry(&ref, true); 9361ad8c760SFredrik Holmqvist // TODO: this resolves an eventual link for the item being added - this 9371ad8c760SFredrik Holmqvist // is okay for now, but in multi-user environments, one might want to 9381ad8c760SFredrik Holmqvist // have links that carry the be:deskbar_item_status attribute 9399c50f36eSAxel Dörfler status = entry.InitCheck(); 9409c50f36eSAxel Dörfler if (status != B_OK) 9419c50f36eSAxel Dörfler return status; 9429c50f36eSAxel Dörfler 94341281cf3SAxel Dörfler *id = 999; 944ced3755cSAxel Dörfler if (archive->what == B_ARCHIVED_OBJECT) 945ced3755cSAxel Dörfler archive->what = 0; 94641281cf3SAxel Dörfler 947ced3755cSAxel Dörfler BRect originalBounds = archive->FindRect("_frame"); 9481ad8c760SFredrik Holmqvist // this is a work-around for buggy replicants that change their size in 9491ad8c760SFredrik Holmqvist // AttachedToWindow() (such as "SVM") 950a5210ab1SAxel Dörfler 9511ad8c760SFredrik Holmqvist // TODO: check for name collisions? 952ced3755cSAxel Dörfler status = fShelf->AddReplicant(archive, BPoint(1, 1)); 9539c50f36eSAxel Dörfler if (status != B_OK) 9549c50f36eSAxel Dörfler return status; 95541281cf3SAxel Dörfler 956a5210ab1SAxel Dörfler int32 count = fShelf->CountReplicants(); 957a5210ab1SAxel Dörfler BView* view; 958a5210ab1SAxel Dörfler fShelf->ReplicantAt(count - 1, &view, (uint32*)id, NULL); 959a5210ab1SAxel Dörfler 960a5210ab1SAxel Dörfler if (originalBounds != view->Bounds()) { 961a5210ab1SAxel Dörfler // The replicant changed its size when added to the window, so we need 96271bd3ba5SJonas Sundström // to recompute all over again (it's already done once via 96371bd3ba5SJonas Sundström // BShelf::AddReplicant() and TReplicantShelf::CanAcceptReplicantView()) 964a5210ab1SAxel Dörfler RealignReplicants(); 965a5210ab1SAxel Dörfler } 966a5210ab1SAxel Dörfler 96741281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 96841281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 96941281cf3SAxel Dörfler float width, height; 97041281cf3SAxel Dörfler GetPreferredSize(&width, &height); 97141281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) 97241281cf3SAxel Dörfler AdjustPlacement(); 97341281cf3SAxel Dörfler 97441281cf3SAxel Dörfler // add the item to the add-on list 97541281cf3SAxel Dörfler 97641281cf3SAxel Dörfler AddItem(*id, nodeRef, entry, addOn != NULL); 97741281cf3SAxel Dörfler return B_OK; 97841281cf3SAxel Dörfler } 97941281cf3SAxel Dörfler 98041281cf3SAxel Dörfler 98141281cf3SAxel Dörfler void 98241281cf3SAxel Dörfler TReplicantTray::RemoveIcon(int32 target, bool byIndex) 98341281cf3SAxel Dörfler { 98441281cf3SAxel Dörfler if (target < 0) 98541281cf3SAxel Dörfler return; 98641281cf3SAxel Dörfler 98741281cf3SAxel Dörfler int32 index, id; 98841281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 98941281cf3SAxel Dörfler if (view && index >= 0) { 9907da06231SAxel Dörfler // remove the reference from the item list & the shelf 99141281cf3SAxel Dörfler RemoveItem(id); 99241281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 9937da06231SAxel Dörfler 99441281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 99541281cf3SAxel Dörfler RealReplicantAdjustment(index); 99641281cf3SAxel Dörfler } 99741281cf3SAxel Dörfler } 99841281cf3SAxel Dörfler 99941281cf3SAxel Dörfler 100041281cf3SAxel Dörfler void 100141281cf3SAxel Dörfler TReplicantTray::RemoveIcon(const char* name) 100241281cf3SAxel Dörfler { 100341281cf3SAxel Dörfler if (!name || strlen(name) <= 0) 100441281cf3SAxel Dörfler return; 100541281cf3SAxel Dörfler 100641281cf3SAxel Dörfler int32 id, index; 100741281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 100841281cf3SAxel Dörfler if (view && index >= 0) { 10097da06231SAxel Dörfler // remove the reference from the item list & shelf 101041281cf3SAxel Dörfler RemoveItem(id); 101141281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 10127da06231SAxel Dörfler 101341281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 101441281cf3SAxel Dörfler RealReplicantAdjustment(index); 101541281cf3SAxel Dörfler } 101641281cf3SAxel Dörfler } 101741281cf3SAxel Dörfler 101841281cf3SAxel Dörfler 101941281cf3SAxel Dörfler void 10207da06231SAxel Dörfler TReplicantTray::RealReplicantAdjustment(int32 startIndex) 102141281cf3SAxel Dörfler { 10227da06231SAxel Dörfler if (startIndex < 0) 102341281cf3SAxel Dörfler return; 10247da06231SAxel Dörfler 10257da06231SAxel Dörfler if (startIndex == fLastReplicant) 10267da06231SAxel Dörfler startIndex = 0; 10277da06231SAxel Dörfler 102841281cf3SAxel Dörfler // reset the locations of all replicants after the one deleted 10297da06231SAxel Dörfler RealignReplicants(startIndex); 103041281cf3SAxel Dörfler 103141281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 103241281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 103341281cf3SAxel Dörfler float width, height; 103441281cf3SAxel Dörfler GetPreferredSize(&width, &height); 103541281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) { 10361ad8c760SFredrik Holmqvist // resize view to accomodate the replicants, redraw as necessary 103741281cf3SAxel Dörfler AdjustPlacement(); 103841281cf3SAxel Dörfler } 103941281cf3SAxel Dörfler } 104041281cf3SAxel Dörfler 104141281cf3SAxel Dörfler 10427da06231SAxel Dörfler /** looking for a replicant by id/index 10437da06231SAxel Dörfler * return the view and index 10447da06231SAxel Dörfler */ 10457da06231SAxel Dörfler 104641281cf3SAxel Dörfler BView* 104741281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, int32 target, bool byIndex) 104841281cf3SAxel Dörfler { 104941281cf3SAxel Dörfler *index = -1; 105041281cf3SAxel Dörfler 105141281cf3SAxel Dörfler BView* view; 105241281cf3SAxel Dörfler if (byIndex) { 105341281cf3SAxel Dörfler if (fShelf->ReplicantAt(target, &view, (uint32*)id)) { 105441281cf3SAxel Dörfler if (view) { 105541281cf3SAxel Dörfler *index = target; 105641281cf3SAxel Dörfler return view; 105741281cf3SAxel Dörfler } 105841281cf3SAxel Dörfler } 105941281cf3SAxel Dörfler } else { 106041281cf3SAxel Dörfler int32 count = fShelf->CountReplicants() - 1; 106141281cf3SAxel Dörfler int32 localid; 106241281cf3SAxel Dörfler for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { 106341281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32*)&localid); 106441281cf3SAxel Dörfler if (localid == target && view) { 106541281cf3SAxel Dörfler *index = repIndex; 106641281cf3SAxel Dörfler *id = localid; 106741281cf3SAxel Dörfler return view; 106841281cf3SAxel Dörfler } 106941281cf3SAxel Dörfler } 107041281cf3SAxel Dörfler } 107141281cf3SAxel Dörfler return NULL; 107241281cf3SAxel Dörfler } 107341281cf3SAxel Dörfler 107441281cf3SAxel Dörfler 10757da06231SAxel Dörfler /** looking for a replicant with a view by name 10767da06231SAxel Dörfler * return the view, index and the id of the replicant 10777da06231SAxel Dörfler */ 10787da06231SAxel Dörfler 107941281cf3SAxel Dörfler BView* 108041281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, const char* name) 108141281cf3SAxel Dörfler { 108241281cf3SAxel Dörfler *index = -1; 108341281cf3SAxel Dörfler *id = -1; 108441281cf3SAxel Dörfler 108541281cf3SAxel Dörfler BView* view; 108641281cf3SAxel Dörfler int32 count = fShelf->CountReplicants()-1; 108741281cf3SAxel Dörfler for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { 108841281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32*)id); 108941281cf3SAxel Dörfler if (view && view->Name() && strcmp(name, view->Name()) == 0) { 109041281cf3SAxel Dörfler *index = repIndex; 109141281cf3SAxel Dörfler return view; 109241281cf3SAxel Dörfler } 109341281cf3SAxel Dörfler } 109441281cf3SAxel Dörfler return NULL; 109541281cf3SAxel Dörfler } 109641281cf3SAxel Dörfler 109741281cf3SAxel Dörfler 10987da06231SAxel Dörfler /** Shelf will call to determine where and if 10997da06231SAxel Dörfler * the replicant is to be added 11007da06231SAxel Dörfler */ 11017da06231SAxel Dörfler 110241281cf3SAxel Dörfler bool 110341281cf3SAxel Dörfler TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage* message) 110441281cf3SAxel Dörfler { 110541281cf3SAxel Dörfler if (!message) 110641281cf3SAxel Dörfler return false; 110741281cf3SAxel Dörfler 110841281cf3SAxel Dörfler if (replicantFrame.Height() > kMaxReplicantHeight) 110941281cf3SAxel Dörfler return false; 111041281cf3SAxel Dörfler 111141281cf3SAxel Dörfler alignment align = B_ALIGN_LEFT; 111241281cf3SAxel Dörfler if (fAlignmentSupport && message->HasBool("deskbar:dynamic_align")) { 111341281cf3SAxel Dörfler if (!fBarView->Vertical()) 111441281cf3SAxel Dörfler align = B_ALIGN_RIGHT; 111541281cf3SAxel Dörfler else 111641281cf3SAxel Dörfler align = fBarView->Left() ? B_ALIGN_LEFT : B_ALIGN_RIGHT; 111741281cf3SAxel Dörfler } else if (message->HasInt32("deskbar:align")) 111841281cf3SAxel Dörfler message->FindInt32("deskbar:align", (int32*)&align); 111941281cf3SAxel Dörfler 112041281cf3SAxel Dörfler if (message->HasInt32("deskbar:private_align")) 112141281cf3SAxel Dörfler message->FindInt32("deskbar:private_align", (int32*)&align); 112241281cf3SAxel Dörfler else 112341281cf3SAxel Dörfler align = B_ALIGN_LEFT; 112441281cf3SAxel Dörfler 11257da06231SAxel Dörfler BPoint loc = LocationForReplicant(fShelf->CountReplicants(), 11267da06231SAxel Dörfler replicantFrame.Width()); 112741281cf3SAxel Dörfler 112841281cf3SAxel Dörfler message->AddPoint("_pjp_loc", loc); 112941281cf3SAxel Dörfler return true; 113041281cf3SAxel Dörfler } 113141281cf3SAxel Dörfler 113241281cf3SAxel Dörfler 113341281cf3SAxel Dörfler /** based on the previous (index - 1) replicant in the list 113441281cf3SAxel Dörfler * calculate where the left point should be for this 113541281cf3SAxel Dörfler * replicant. replicant will flow to the right on its own 113641281cf3SAxel Dörfler */ 113741281cf3SAxel Dörfler 113841281cf3SAxel Dörfler BPoint 11397da06231SAxel Dörfler TReplicantTray::LocationForReplicant(int32 index, float width) 114041281cf3SAxel Dörfler { 114141281cf3SAxel Dörfler BPoint loc(kIconGap + 1, kGutter + 1); 114241281cf3SAxel Dörfler 11437da06231SAxel Dörfler if (fMultiRowMode) { 11447da06231SAxel Dörfler // try to find free space in every row 11457da06231SAxel Dörfler for (int32 row = 0; ; loc.y += kMaxReplicantHeight + kIconGap, row++) { 11467da06231SAxel Dörfler // determine free space in this row 11472ce9bab8SJohn Scipione BRect rect(loc.x, loc.y, loc.x + fMinimumTrayWidth - kIconGap 11482ce9bab8SJohn Scipione - 2.0, loc.y + kMaxReplicantHeight); 1149573f748cSJohn Scipione if (row == 0 && !fTime->IsHidden()) 1150573f748cSJohn Scipione rect.right -= fTime->Frame().Width() + kIconGap; 11517da06231SAxel Dörfler 11527da06231SAxel Dörfler for (int32 i = 0; i < index; i++) { 11537da06231SAxel Dörfler BView* view = NULL; 11547da06231SAxel Dörfler fShelf->ReplicantAt(i, &view); 11557da06231SAxel Dörfler if (view == NULL || view->Frame().top != rect.top) 11567da06231SAxel Dörfler continue; 11577da06231SAxel Dörfler 11587da06231SAxel Dörfler rect.left = view->Frame().right + kIconGap + 1; 11597da06231SAxel Dörfler } 11607da06231SAxel Dörfler 11617da06231SAxel Dörfler if (rect.Width() >= width) { 11627da06231SAxel Dörfler // the icon fits in this row 11637da06231SAxel Dörfler loc = rect.LeftTop(); 11647da06231SAxel Dörfler break; 11657da06231SAxel Dörfler } 11667da06231SAxel Dörfler } 11677da06231SAxel Dörfler } else { 116841281cf3SAxel Dörfler if (index > 0) { 116941281cf3SAxel Dörfler // get the last replicant added for placement reference 117041281cf3SAxel Dörfler BView* view = NULL; 11717da06231SAxel Dörfler fShelf->ReplicantAt(index - 1, &view); 117241281cf3SAxel Dörfler if (view) { 117341281cf3SAxel Dörfler // push this rep placement past the last one 117441281cf3SAxel Dörfler loc.x = view->Frame().right + kIconGap + 1; 117541281cf3SAxel Dörfler loc.y = view->Frame().top; 117641281cf3SAxel Dörfler } 117741281cf3SAxel Dörfler } 11787da06231SAxel Dörfler } 117941281cf3SAxel Dörfler 118071bd3ba5SJonas Sundström if ((loc.y == fRightBottomReplicant.top && loc.x 118171bd3ba5SJonas Sundström > fRightBottomReplicant.left) || loc.y > fRightBottomReplicant.top) { 118271bd3ba5SJonas Sundström fRightBottomReplicant.Set(loc.x, loc.y, loc.x + width, loc.y 118371bd3ba5SJonas Sundström + kMaxReplicantHeight); 11847da06231SAxel Dörfler fLastReplicant = index; 118541281cf3SAxel Dörfler } 11867da06231SAxel Dörfler 118741281cf3SAxel Dörfler return loc; 118841281cf3SAxel Dörfler } 118941281cf3SAxel Dörfler 119041281cf3SAxel Dörfler 119141281cf3SAxel Dörfler BRect 119241281cf3SAxel Dörfler TReplicantTray::IconFrame(int32 target, bool byIndex) 119341281cf3SAxel Dörfler { 119441281cf3SAxel Dörfler int32 index, id; 119541281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 119641281cf3SAxel Dörfler if (view) 119741281cf3SAxel Dörfler return view->Frame(); 119841281cf3SAxel Dörfler 119941281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 120041281cf3SAxel Dörfler } 120141281cf3SAxel Dörfler 120241281cf3SAxel Dörfler 120341281cf3SAxel Dörfler BRect 120441281cf3SAxel Dörfler TReplicantTray::IconFrame(const char* name) 120541281cf3SAxel Dörfler { 120641281cf3SAxel Dörfler if (!name) 120741281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 120841281cf3SAxel Dörfler 120941281cf3SAxel Dörfler int32 id, index; 121041281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 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 12187da06231SAxel Dörfler /** Scan from the startIndex and reset the location 12197da06231SAxel Dörfler * as defined in LocationForReplicant() 122041281cf3SAxel Dörfler */ 122141281cf3SAxel Dörfler 122241281cf3SAxel Dörfler void 122341281cf3SAxel Dörfler TReplicantTray::RealignReplicants(int32 startIndex) 122441281cf3SAxel Dörfler { 122541281cf3SAxel Dörfler if (startIndex < 0) 122641281cf3SAxel Dörfler startIndex = 0; 122741281cf3SAxel Dörfler 122841281cf3SAxel Dörfler int32 count = fShelf->CountReplicants(); 122941281cf3SAxel Dörfler if (count <= 0) 123041281cf3SAxel Dörfler return; 123141281cf3SAxel Dörfler 12327da06231SAxel Dörfler if (startIndex == 0) 12337da06231SAxel Dörfler fRightBottomReplicant.Set(0, 0, 0, 0); 12347da06231SAxel Dörfler 123541281cf3SAxel Dörfler BView* view = NULL; 123641281cf3SAxel Dörfler for (int32 i = startIndex ; i < count ; i++) { 123741281cf3SAxel Dörfler fShelf->ReplicantAt(i, &view); 12380bec7100SStefano Ceccherini if (view != NULL) { 12397da06231SAxel Dörfler BPoint loc = LocationForReplicant(i, view->Frame().Width()); 12400bec7100SStefano Ceccherini if (view->Frame().LeftTop() != loc) 124141281cf3SAxel Dörfler view->MoveTo(loc); 124241281cf3SAxel Dörfler } 124341281cf3SAxel Dörfler } 124441281cf3SAxel Dörfler } 124541281cf3SAxel Dörfler 124641281cf3SAxel Dörfler 12478aab28f1SRene Gollent status_t 12487625ce51SRene Gollent TReplicantTray::_SaveSettings() 12497625ce51SRene Gollent { 12507625ce51SRene Gollent status_t result; 12517625ce51SRene Gollent BPath path; 12527625ce51SRene Gollent if ((result = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true)) 12537625ce51SRene Gollent == B_OK) { 12547625ce51SRene Gollent path.Append(kReplicantSettingsFile); 12557625ce51SRene Gollent 12567625ce51SRene Gollent BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); 12577625ce51SRene Gollent if ((result = file.InitCheck()) == B_OK) 12587625ce51SRene Gollent result = fAddOnSettings.Flatten(&file); 12597625ce51SRene Gollent } 12607625ce51SRene Gollent 12617625ce51SRene Gollent return result; 12627625ce51SRene Gollent } 12637625ce51SRene Gollent 12647625ce51SRene Gollent 12653cf2d117SJohn Scipione void 12663cf2d117SJohn Scipione TReplicantTray::SaveTimeSettings() 12673cf2d117SJohn Scipione { 12683cf2d117SJohn Scipione if (fTime == NULL) 12693cf2d117SJohn Scipione return; 12703cf2d117SJohn Scipione 1271*31c0024dSJohn Scipione clock_settings* settings = ((TBarApp*)be_app)->ClockSettings(); 12723cf2d117SJohn Scipione settings->showSeconds = fTime->ShowSeconds(); 12733cf2d117SJohn Scipione settings->showDayOfWeek = fTime->ShowDayOfWeek(); 1274*31c0024dSJohn Scipione settings->showTimeZone = fTime->ShowTimeZone(); 12753cf2d117SJohn Scipione } 12763cf2d117SJohn Scipione 12773cf2d117SJohn Scipione 127841281cf3SAxel Dörfler // #pragma mark - 127941281cf3SAxel Dörfler 128041281cf3SAxel Dörfler 1281ca9acc20SAxel Dörfler /*! Draggable region that is asynchronous so that dragging does not block 1282ca9acc20SAxel Dörfler other activities. 12837da06231SAxel Dörfler */ 128441281cf3SAxel Dörfler TDragRegion::TDragRegion(TBarView* parent, BView* child) 1285ca9acc20SAxel Dörfler : 1286ca9acc20SAxel Dörfler BControl(BRect(0, 0, 0, 0), "", "", NULL, B_FOLLOW_NONE, 128741281cf3SAxel Dörfler B_WILL_DRAW | B_FRAME_EVENTS), 128841281cf3SAxel Dörfler fBarView(parent), 128941281cf3SAxel Dörfler fChild(child), 129041281cf3SAxel Dörfler fDragLocation(kAutoPlaceDragRegion) 129141281cf3SAxel Dörfler { 129241281cf3SAxel Dörfler } 129341281cf3SAxel Dörfler 129441281cf3SAxel Dörfler 129541281cf3SAxel Dörfler void 129641281cf3SAxel Dörfler TDragRegion::AttachedToWindow() 129741281cf3SAxel Dörfler { 129841281cf3SAxel Dörfler BView::AttachedToWindow(); 1299cb6afcb1SStephan Aßmus if (be_control_look != NULL) 1300cb6afcb1SStephan Aßmus SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 1.1)); 1301cb6afcb1SStephan Aßmus else 130241281cf3SAxel Dörfler SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); 130341281cf3SAxel Dörfler ResizeToPreferred(); 130441281cf3SAxel Dörfler } 130541281cf3SAxel Dörfler 130641281cf3SAxel Dörfler 130741281cf3SAxel Dörfler void 130841281cf3SAxel Dörfler TDragRegion::GetPreferredSize(float* width, float* height) 130941281cf3SAxel Dörfler { 131041281cf3SAxel Dörfler fChild->ResizeToPreferred(); 131141281cf3SAxel Dörfler *width = fChild->Bounds().Width(); 131241281cf3SAxel Dörfler *height = fChild->Bounds().Height(); 131341281cf3SAxel Dörfler 131441281cf3SAxel Dörfler if (fDragLocation != kNoDragRegion) 131541281cf3SAxel Dörfler *width += 7; 131641281cf3SAxel Dörfler else 131741281cf3SAxel Dörfler *width += 6; 131841281cf3SAxel Dörfler 131941281cf3SAxel Dörfler *height += 3; 132041281cf3SAxel Dörfler } 132141281cf3SAxel Dörfler 132241281cf3SAxel Dörfler 132341281cf3SAxel Dörfler void 132441281cf3SAxel Dörfler TDragRegion::FrameMoved(BPoint) 132541281cf3SAxel Dörfler { 1326ca9acc20SAxel Dörfler if (fBarView->Left() && fBarView->Vertical() 1327ca9acc20SAxel Dörfler && fDragLocation != kNoDragRegion) 132841281cf3SAxel Dörfler fChild->MoveTo(5, 2); 132941281cf3SAxel Dörfler else 133041281cf3SAxel Dörfler fChild->MoveTo(2, 2); 133141281cf3SAxel Dörfler } 133241281cf3SAxel Dörfler 133341281cf3SAxel Dörfler 133441281cf3SAxel Dörfler void 133541281cf3SAxel Dörfler TDragRegion::Draw(BRect) 133641281cf3SAxel Dörfler { 1337eaa9af99SStephan Aßmus rgb_color menuColor = ViewColor(); 133841281cf3SAxel Dörfler rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT); 1339cb6afcb1SStephan Aßmus rgb_color ldark = tint_color(menuColor, 1.02); 1340cb6afcb1SStephan Aßmus rgb_color dark = tint_color(menuColor, B_DARKEN_2_TINT); 134141281cf3SAxel Dörfler rgb_color vvdark = tint_color(menuColor, B_DARKEN_4_TINT); 134241281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 134341281cf3SAxel Dörfler 134441281cf3SAxel Dörfler BRect frame(Bounds()); 134541281cf3SAxel Dörfler BeginLineArray(4); 134641281cf3SAxel Dörfler 1347cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 1348cb6afcb1SStephan Aßmus if (fBarView->Vertical()) { 1349cb6afcb1SStephan Aßmus AddLine(frame.LeftTop(), frame.RightTop(), dark); 1350cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1351cb6afcb1SStephan Aßmus BPoint(frame.right, frame.top + 1), ldark); 1352cb6afcb1SStephan Aßmus AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 1353cb6afcb1SStephan Aßmus } else if (fBarView->AcrossTop() || fBarView->AcrossBottom()) { 1354cb6afcb1SStephan Aßmus AddLine(frame.LeftTop(), 1355cb6afcb1SStephan Aßmus BPoint(frame.left, frame.bottom), dark); 1356cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left + 1, frame.top + 1), 1357cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 1358cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right, frame.top + 2), 1359cb6afcb1SStephan Aßmus BPoint(frame.right, frame.bottom), hilite); 1360cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left + 1, frame.bottom), 1361cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom), hilite); 1362cb6afcb1SStephan Aßmus } 1363cb6afcb1SStephan Aßmus } else { 136441281cf3SAxel Dörfler if (fBarView->Vertical()) { 136541281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.RightTop(), light); 136641281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.LeftBottom(), light); 136741281cf3SAxel Dörfler AddLine(frame.RightBottom(), frame.RightTop(), hilite); 136841281cf3SAxel Dörfler } else if (fBarView->AcrossTop()) { 1369cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1370cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 137141281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 1372cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right - 1, frame.top + 2), 1373cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom - 1), hilite); 1374cb6afcb1SStephan Aßmus AddLine(frame.LeftBottom(), 1375cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom), hilite); 137641281cf3SAxel Dörfler } else if (fBarView->AcrossBottom()) { 1377cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1378cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 137941281cf3SAxel Dörfler AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 138041281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 1381cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right - 1, frame.top + 1), 1382cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom - 1), hilite); 1383cb6afcb1SStephan Aßmus } 138441281cf3SAxel Dörfler } 138541281cf3SAxel Dörfler 138641281cf3SAxel Dörfler EndLineArray(); 138741281cf3SAxel Dörfler 138841281cf3SAxel Dörfler if (fDragLocation != kDontDrawDragRegion || fDragLocation != kNoDragRegion) 138941281cf3SAxel Dörfler DrawDragRegion(); 139041281cf3SAxel Dörfler } 139141281cf3SAxel Dörfler 139241281cf3SAxel Dörfler 139341281cf3SAxel Dörfler void 139441281cf3SAxel Dörfler TDragRegion::DrawDragRegion() 139541281cf3SAxel Dörfler { 139641281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 139741281cf3SAxel Dörfler 1398cb6afcb1SStephan Aßmus rgb_color menuColor = ViewColor(); 1399cb6afcb1SStephan Aßmus rgb_color menuHilite = menuColor; 140041281cf3SAxel Dörfler if (IsTracking()) { 1401cb6afcb1SStephan Aßmus // Draw drag region highlighted if tracking mouse 1402cb6afcb1SStephan Aßmus menuHilite = tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT); 140341281cf3SAxel Dörfler SetHighColor(menuHilite); 140441281cf3SAxel Dörfler FillRect(dragRegion); 140541281cf3SAxel Dörfler } 1406cb6afcb1SStephan Aßmus rgb_color vdark = tint_color(menuHilite, B_DARKEN_3_TINT); 1407cb6afcb1SStephan Aßmus rgb_color light = tint_color(menuHilite, B_LIGHTEN_2_TINT); 1408cb6afcb1SStephan Aßmus 1409cb6afcb1SStephan Aßmus BeginLineArray(dragRegion.IntegerHeight()); 1410cb6afcb1SStephan Aßmus BPoint pt; 1411cb6afcb1SStephan Aßmus pt.x = floorf((dragRegion.left + dragRegion.right) / 2 + 0.5) - 1; 1412cb6afcb1SStephan Aßmus pt.y = dragRegion.top + 2; 1413cb6afcb1SStephan Aßmus 141441281cf3SAxel Dörfler while (pt.y + 1 <= dragRegion.bottom) { 141541281cf3SAxel Dörfler AddLine(pt, pt, vdark); 141641281cf3SAxel Dörfler AddLine(pt + BPoint(1, 1), pt + BPoint(1, 1), light); 141741281cf3SAxel Dörfler 141841281cf3SAxel Dörfler pt.y += 3; 141941281cf3SAxel Dörfler } 142041281cf3SAxel Dörfler EndLineArray(); 142141281cf3SAxel Dörfler } 142241281cf3SAxel Dörfler 142341281cf3SAxel Dörfler 142441281cf3SAxel Dörfler BRect 142541281cf3SAxel Dörfler TDragRegion::DragRegion() const 142641281cf3SAxel Dörfler { 1427cb6afcb1SStephan Aßmus float kTopBottomInset = 2; 1428cb6afcb1SStephan Aßmus float kLeftRightInset = 1; 1429cb6afcb1SStephan Aßmus float kDragWidth = 3; 1430cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 1431cb6afcb1SStephan Aßmus kTopBottomInset = 1; 1432cb6afcb1SStephan Aßmus kLeftRightInset = 0; 1433cb6afcb1SStephan Aßmus kDragWidth = 4; 1434cb6afcb1SStephan Aßmus } 1435cb6afcb1SStephan Aßmus 143641281cf3SAxel Dörfler BRect dragRegion(Bounds()); 1437cb6afcb1SStephan Aßmus dragRegion.top += kTopBottomInset; 1438cb6afcb1SStephan Aßmus dragRegion.bottom -= kTopBottomInset; 143941281cf3SAxel Dörfler 144041281cf3SAxel Dörfler bool placeOnLeft = false; 144141281cf3SAxel Dörfler if (fDragLocation == kAutoPlaceDragRegion) { 144241281cf3SAxel Dörfler if (fBarView->Vertical() && fBarView->Left()) 144341281cf3SAxel Dörfler placeOnLeft = true; 144441281cf3SAxel Dörfler else 144541281cf3SAxel Dörfler placeOnLeft = false; 144641281cf3SAxel Dörfler } else if (fDragLocation == kDragRegionLeft) 144741281cf3SAxel Dörfler placeOnLeft = true; 144841281cf3SAxel Dörfler else if (fDragLocation == kDragRegionRight) 144941281cf3SAxel Dörfler placeOnLeft = false; 145041281cf3SAxel Dörfler 145141281cf3SAxel Dörfler if (placeOnLeft) { 1452cb6afcb1SStephan Aßmus dragRegion.left += kLeftRightInset; 1453cb6afcb1SStephan Aßmus dragRegion.right = dragRegion.left + kDragWidth; 145441281cf3SAxel Dörfler } else { 1455cb6afcb1SStephan Aßmus dragRegion.right -= kLeftRightInset; 1456cb6afcb1SStephan Aßmus dragRegion.left = dragRegion.right - kDragWidth; 145741281cf3SAxel Dörfler } 145841281cf3SAxel Dörfler 145941281cf3SAxel Dörfler return dragRegion; 146041281cf3SAxel Dörfler } 146141281cf3SAxel Dörfler 146241281cf3SAxel Dörfler 146341281cf3SAxel Dörfler void 146441281cf3SAxel Dörfler TDragRegion::MouseDown(BPoint thePoint) 146541281cf3SAxel Dörfler { 1466e9632898SAlex Smith uint32 buttons; 146741281cf3SAxel Dörfler BPoint where; 146841281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 146941281cf3SAxel Dörfler 14707da06231SAxel Dörfler dragRegion.InsetBy(-2.0f, -2.0f); 14717da06231SAxel Dörfler // DragRegion() is designed for drawing, not clicking 147241281cf3SAxel Dörfler 147341281cf3SAxel Dörfler if (!dragRegion.Contains(thePoint)) 147441281cf3SAxel Dörfler return; 147541281cf3SAxel Dörfler 147641281cf3SAxel Dörfler while (true) { 147741281cf3SAxel Dörfler GetMouse(&where, &buttons); 147841281cf3SAxel Dörfler if (!buttons) 147941281cf3SAxel Dörfler break; 148041281cf3SAxel Dörfler 148141281cf3SAxel Dörfler if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) != 0) { 148241281cf3SAxel Dörfler fPreviousPosition = thePoint; 148341281cf3SAxel Dörfler SetTracking(true); 148441281cf3SAxel Dörfler SetMouseEventMask(B_POINTER_EVENTS, 148541281cf3SAxel Dörfler B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); 148641281cf3SAxel Dörfler Invalidate(DragRegion()); 148741281cf3SAxel Dörfler break; 148841281cf3SAxel Dörfler } 148941281cf3SAxel Dörfler 149041281cf3SAxel Dörfler snooze(25000); 149141281cf3SAxel Dörfler } 149241281cf3SAxel Dörfler } 149341281cf3SAxel Dörfler 149441281cf3SAxel Dörfler 149541281cf3SAxel Dörfler void 149641281cf3SAxel Dörfler TDragRegion::MouseUp(BPoint pt) 149741281cf3SAxel Dörfler { 149841281cf3SAxel Dörfler if (IsTracking()) { 149941281cf3SAxel Dörfler SetTracking(false); 150041281cf3SAxel Dörfler Invalidate(DragRegion()); 150141281cf3SAxel Dörfler } else 150241281cf3SAxel Dörfler BControl::MouseUp(pt); 150341281cf3SAxel Dörfler } 150441281cf3SAxel Dörfler 150541281cf3SAxel Dörfler 150641281cf3SAxel Dörfler bool 150741281cf3SAxel Dörfler TDragRegion::SwitchModeForRect(BPoint mouse, BRect rect, 150841281cf3SAxel Dörfler bool newVertical, bool newLeft, bool newTop, int32 newState) 150941281cf3SAxel Dörfler { 15101ad8c760SFredrik Holmqvist if (!rect.Contains(mouse)) { 151141281cf3SAxel Dörfler // not our rect 151241281cf3SAxel Dörfler return false; 15131ad8c760SFredrik Holmqvist } 151441281cf3SAxel Dörfler 15151ad8c760SFredrik Holmqvist if (newVertical == fBarView->Vertical() && newLeft == fBarView->Left() 15161ad8c760SFredrik Holmqvist && newTop == fBarView->Top() && newState == fBarView->State()) { 151741281cf3SAxel Dörfler // already in the correct mode 151841281cf3SAxel Dörfler return true; 15191ad8c760SFredrik Holmqvist } 152041281cf3SAxel Dörfler 1521d7ed9414SRene Gollent fBarView->ChangeState(newState, newVertical, newLeft, newTop, true); 152241281cf3SAxel Dörfler return true; 152341281cf3SAxel Dörfler } 152441281cf3SAxel Dörfler 152541281cf3SAxel Dörfler 152641281cf3SAxel Dörfler void 152741281cf3SAxel Dörfler TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage* message) 152841281cf3SAxel Dörfler { 152941281cf3SAxel Dörfler if (IsTracking()) { 153041281cf3SAxel Dörfler BScreen screen; 153141281cf3SAxel Dörfler BRect frame = screen.Frame(); 153241281cf3SAxel Dörfler 153341281cf3SAxel Dörfler float hDivider = frame.Width() / 6; 153471bd3ba5SJonas Sundström hDivider = (hDivider < sMinimumWindowWidth + 10.0f) 153571bd3ba5SJonas Sundström ? sMinimumWindowWidth + 10.0f : hDivider; 153641281cf3SAxel Dörfler float miniDivider = frame.top + kMiniHeight + 10.0f; 153741281cf3SAxel Dörfler float vDivider = frame.Height() / 2; 153841281cf3SAxel Dörfler #ifdef FULL_MODE 153941281cf3SAxel Dörfler float thirdScreen = frame.Height() / 3; 154041281cf3SAxel Dörfler #endif 154171bd3ba5SJonas Sundström BRect topLeft(frame.left, frame.top, frame.left + hDivider, 154271bd3ba5SJonas Sundström miniDivider); 154371bd3ba5SJonas Sundström BRect topMiddle(frame.left + hDivider, frame.top, frame.right 154471bd3ba5SJonas Sundström - hDivider, vDivider); 154571bd3ba5SJonas Sundström BRect topRight(frame.right - hDivider, frame.top, frame.right, 154671bd3ba5SJonas Sundström miniDivider); 154741281cf3SAxel Dörfler 154841281cf3SAxel Dörfler #ifdef FULL_MODE 154941281cf3SAxel Dörfler vDivider = miniDivider + thirdScreen; 155041281cf3SAxel Dörfler #endif 155171bd3ba5SJonas Sundström BRect middleLeft(frame.left, miniDivider, frame.left + hDivider, 155271bd3ba5SJonas Sundström vDivider); 155371bd3ba5SJonas Sundström BRect middleRight(frame.right - hDivider, miniDivider, frame.right, 155471bd3ba5SJonas Sundström vDivider); 155541281cf3SAxel Dörfler 155641281cf3SAxel Dörfler #ifdef FULL_MODE 155771bd3ba5SJonas Sundström BRect leftSide(frame.left, vDivider, frame.left + hDivider, 155871bd3ba5SJonas Sundström frame.bottom - thirdScreen); 155971bd3ba5SJonas Sundström BRect rightSide(frame.right - hDivider, vDivider, frame.right, 156071bd3ba5SJonas Sundström frame.bottom - thirdScreen); 156141281cf3SAxel Dörfler 156241281cf3SAxel Dörfler vDivider = frame.bottom - thirdScreen; 156341281cf3SAxel Dörfler #endif 156471bd3ba5SJonas Sundström BRect bottomLeft(frame.left, vDivider, frame.left + hDivider, 156571bd3ba5SJonas Sundström frame.bottom); 156671bd3ba5SJonas Sundström BRect bottomMiddle(frame.left + hDivider, vDivider, frame.right 156771bd3ba5SJonas Sundström - hDivider, frame.bottom); 156871bd3ba5SJonas Sundström BRect bottomRight(frame.right - hDivider, vDivider, frame.right, 156971bd3ba5SJonas Sundström frame.bottom); 157041281cf3SAxel Dörfler 157141281cf3SAxel Dörfler if (where != fPreviousPosition) { 157241281cf3SAxel Dörfler fPreviousPosition = where; 157341281cf3SAxel Dörfler ConvertToScreen(&where); 157441281cf3SAxel Dörfler 157541281cf3SAxel Dörfler // use short circuit evaluation for convenience 157641281cf3SAxel Dörfler if (SwitchModeForRect(where, topLeft, true, true, true, kMiniState) 157771bd3ba5SJonas Sundström || SwitchModeForRect(where, topMiddle, false, true, true, 157871bd3ba5SJonas Sundström kExpandoState) 157971bd3ba5SJonas Sundström || SwitchModeForRect(where, topRight, true, false, true, 158071bd3ba5SJonas Sundström kMiniState) 158171bd3ba5SJonas Sundström || SwitchModeForRect(where, middleLeft, true, true, true, 158271bd3ba5SJonas Sundström kExpandoState) 158371bd3ba5SJonas Sundström || SwitchModeForRect(where, middleRight, true, false, true, 158471bd3ba5SJonas Sundström kExpandoState) 158541281cf3SAxel Dörfler 158641281cf3SAxel Dörfler #ifdef FULL_MODE 158771bd3ba5SJonas Sundström || SwitchModeForRect(where, leftSide, true, true, true, 158871bd3ba5SJonas Sundström kFullState) 158971bd3ba5SJonas Sundström || SwitchModeForRect(where, rightSide, true, false, true, 159071bd3ba5SJonas Sundström kFullState) 159141281cf3SAxel Dörfler #endif 159271bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomLeft, true, true, false, 159371bd3ba5SJonas Sundström kMiniState) 159471bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomMiddle, false, true, false, 159571bd3ba5SJonas Sundström kExpandoState) 159671bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomRight, true, false, false, 159771bd3ba5SJonas Sundström kMiniState)) 159841281cf3SAxel Dörfler ; 159941281cf3SAxel Dörfler } 160041281cf3SAxel Dörfler } else 160141281cf3SAxel Dörfler BControl::MouseMoved(where, code, message); 160241281cf3SAxel Dörfler } 160341281cf3SAxel Dörfler 160441281cf3SAxel Dörfler 160541281cf3SAxel Dörfler int32 160641281cf3SAxel Dörfler TDragRegion::DragRegionLocation() const 160741281cf3SAxel Dörfler { 160841281cf3SAxel Dörfler return fDragLocation; 160941281cf3SAxel Dörfler } 161041281cf3SAxel Dörfler 161141281cf3SAxel Dörfler 161241281cf3SAxel Dörfler void 161341281cf3SAxel Dörfler TDragRegion::SetDragRegionLocation(int32 location) 161441281cf3SAxel Dörfler { 161541281cf3SAxel Dörfler if (location == fDragLocation) 161641281cf3SAxel Dörfler return; 161741281cf3SAxel Dörfler 161841281cf3SAxel Dörfler fDragLocation = location; 161941281cf3SAxel Dörfler Invalidate(); 162041281cf3SAxel Dörfler } 1621