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 3641281cf3SAxel Dörfler #include <Debug.h> 3741281cf3SAxel Dörfler 3841281cf3SAxel Dörfler #include <errno.h> 3941281cf3SAxel Dörfler #include <stdio.h> 4041281cf3SAxel Dörfler #include <string.h> 4141281cf3SAxel Dörfler #include <time.h> 4241281cf3SAxel Dörfler #include <unistd.h> 4341281cf3SAxel Dörfler #include <algorithm> 4441281cf3SAxel Dörfler 4541281cf3SAxel Dörfler #include <fs_index.h> 4641281cf3SAxel Dörfler #include <fs_info.h> 4741281cf3SAxel Dörfler 4841281cf3SAxel Dörfler #include <Application.h> 4941281cf3SAxel Dörfler #include <Beep.h> 50cb6afcb1SStephan Aßmus #include <Bitmap.h> 51ae7a6e3aSAdrien Destugues #include <Catalog.h> 52cb6afcb1SStephan Aßmus #include <ControlLook.h> 5341281cf3SAxel Dörfler #include <Directory.h> 5441281cf3SAxel Dörfler #include <FindDirectory.h> 55ae7a6e3aSAdrien Destugues #include <Locale.h> 5641281cf3SAxel Dörfler #include <MenuItem.h> 57573f748cSJohn Scipione #include <MutableLocaleRoster.h> 5841281cf3SAxel Dörfler #include <NodeInfo.h> 5941281cf3SAxel Dörfler #include <NodeMonitor.h> 6041281cf3SAxel Dörfler #include <Path.h> 6141281cf3SAxel Dörfler #include <PopUpMenu.h> 6241281cf3SAxel Dörfler #include <Roster.h> 6341281cf3SAxel Dörfler #include <Screen.h> 6441281cf3SAxel Dörfler #include <Volume.h> 6541281cf3SAxel Dörfler #include <VolumeRoster.h> 6641281cf3SAxel Dörfler #include <Window.h> 6741281cf3SAxel Dörfler 68cb6afcb1SStephan Aßmus #include "icons_logo.h" 69cb6afcb1SStephan Aßmus #include "BarApp.h" 70323b6546SOliver Tappe #include "DeskbarUtils.h" 71cb6afcb1SStephan Aßmus #include "ResourceSet.h" 7241281cf3SAxel Dörfler #include "StatusView.h" 7341281cf3SAxel Dörfler #include "StatusViewShelf.h" 7441281cf3SAxel Dörfler #include "TimeView.h" 7541281cf3SAxel Dörfler 766d01b66dSAxel Dörfler using std::max; 7741281cf3SAxel Dörfler 7841281cf3SAxel Dörfler #ifdef DB_ADDONS 7941281cf3SAxel Dörfler // Add-on support 8041281cf3SAxel Dörfler // 8141281cf3SAxel Dörfler // Item - internal item list (node, eref, etc) 8241281cf3SAxel Dörfler // Icon - physical replicant handed to the DeskbarClass class 8341281cf3SAxel Dörfler // AddOn - attribute based add-on 8441281cf3SAxel Dörfler 8541281cf3SAxel Dörfler const char* const kInstantiateItemCFunctionName = "instantiate_deskbar_item"; 8641281cf3SAxel Dörfler const char* const kInstantiateEntryCFunctionName = "instantiate_deskbar_entry"; 873e6ff860SRene Gollent const char* const kReplicantSettingsFile = "Deskbar_replicants"; 88c0ad1c91SRene Gollent const char* const kReplicantPathField = "replicant_path"; 8941281cf3SAxel Dörfler 90cb6afcb1SStephan Aßmus float sMinimumWindowWidth = kGutter + kMinimumTrayWidth + kDragRegionWidth; 91cb6afcb1SStephan Aßmus 9241281cf3SAxel Dörfler 9341281cf3SAxel Dörfler static void 9441281cf3SAxel Dörfler DumpItem(DeskbarItemInfo* item) 9541281cf3SAxel Dörfler { 9641281cf3SAxel Dörfler printf("is addon: %i, id: %li\n", item->isAddOn, item->id); 9766eba86fSAxel Dörfler printf("entry_ref: %ld, %Ld, %s\n", item->entryRef.device, 9866eba86fSAxel Dörfler item->entryRef.directory, item->entryRef.name); 9941281cf3SAxel Dörfler printf("node_ref: %ld, %Ld\n", item->nodeRef.device, item->nodeRef.node); 10041281cf3SAxel Dörfler } 10141281cf3SAxel Dörfler 10241281cf3SAxel Dörfler 10341281cf3SAxel Dörfler static void 10441281cf3SAxel Dörfler DumpList(BList* itemlist) 10541281cf3SAxel Dörfler { 10641281cf3SAxel Dörfler int32 count = itemlist->CountItems() - 1; 10741281cf3SAxel Dörfler if (count < 0) { 10841281cf3SAxel Dörfler printf("no items in list\n"); 10941281cf3SAxel Dörfler return; 11041281cf3SAxel Dörfler } 11141281cf3SAxel Dörfler for (int32 i = count; i >= 0; i--) { 11241281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)itemlist->ItemAt(i); 11341281cf3SAxel Dörfler if (!item) 11441281cf3SAxel Dörfler continue; 11541281cf3SAxel Dörfler 11641281cf3SAxel Dörfler DumpItem(item); 11741281cf3SAxel Dörfler } 11841281cf3SAxel Dörfler } 11941281cf3SAxel Dörfler #endif /* DB_ADDONS */ 12041281cf3SAxel Dörfler 12141281cf3SAxel Dörfler 1224eb0cbb0SMatt Madia #undef B_TRANSLATE_CONTEXT 1234eb0cbb0SMatt Madia #define B_TRANSLATE_CONTEXT "Tray" 124ae7a6e3aSAdrien Destugues 1257da06231SAxel Dörfler // don't change the name of this view to anything other than "Status"! 1267da06231SAxel Dörfler 12741281cf3SAxel Dörfler TReplicantTray::TReplicantTray(TBarView* parent, bool vertical) 12841281cf3SAxel Dörfler : BView(BRect(0, 0, 1, 1), "Status", B_FOLLOW_LEFT | B_FOLLOW_TOP, 12941281cf3SAxel Dörfler B_WILL_DRAW | B_FRAME_EVENTS), 130573f748cSJohn Scipione fTime(NULL), 13141281cf3SAxel Dörfler fBarView(parent), 13241281cf3SAxel Dörfler fShelf(new TReplicantShelf(this)), 13341281cf3SAxel Dörfler fMultiRowMode(vertical), 134cb6afcb1SStephan Aßmus fMinimumTrayWidth(kMinimumTrayWidth), 13541281cf3SAxel Dörfler fAlignmentSupport(false) 13641281cf3SAxel Dörfler { 137cb6afcb1SStephan Aßmus // init the minimum window width according to the logo. 138cb6afcb1SStephan Aßmus const BBitmap* logoBitmap = AppResSet()->FindBitmap(B_MESSAGE_TYPE, 1399e8a970bSJonas Sundström R_LeafLogoBitmap); 140cb6afcb1SStephan Aßmus if (logoBitmap != NULL) { 141cb6afcb1SStephan Aßmus sMinimumWindowWidth = max_c(sMinimumWindowWidth, 142cb6afcb1SStephan Aßmus 2 * (logoBitmap->Bounds().Width() + 8)); 143cb6afcb1SStephan Aßmus fMinimumTrayWidth = sMinimumWindowWidth - kGutter - kDragRegionWidth; 144cb6afcb1SStephan Aßmus } 145573f748cSJohn Scipione 146*3cf2d117SJohn Scipione BFormattingConventions conventions; 147*3cf2d117SJohn Scipione BLocale::Default()->GetFormattingConventions(&conventions); 148*3cf2d117SJohn Scipione bool use24HourClock = conventions.Use24HourClock(); 149*3cf2d117SJohn Scipione desk_settings* settings = ((TBarApp*)be_app)->Settings(); 150*3cf2d117SJohn Scipione 151573f748cSJohn Scipione // Create the time view 152573f748cSJohn Scipione fTime = new TTimeView(fMinimumTrayWidth, kMaxReplicantHeight - 1.0, 153*3cf2d117SJohn Scipione use24HourClock, settings->showSeconds, settings->showDayOfWeek, 154*3cf2d117SJohn Scipione settings->showTimeZone); 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 170cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 171cb6afcb1SStephan Aßmus SetViewColor(Parent()->ViewColor()); 172cb6afcb1SStephan Aßmus } else { 17366eba86fSAxel Dörfler SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 17466eba86fSAxel Dörfler B_DARKEN_1_TINT)); 175cb6afcb1SStephan Aßmus } 17641281cf3SAxel Dörfler SetDrawingMode(B_OP_COPY); 17766eba86fSAxel Dörfler 17841281cf3SAxel Dörfler Window()->SetPulseRate(1000000); 17941281cf3SAxel Dörfler 180573f748cSJohn Scipione AddChild(fTime); 181573f748cSJohn Scipione fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - 1, 2); 182573f748cSJohn Scipione if (!((TBarApp*)be_app)->Settings()->showTime) { 183573f748cSJohn Scipione fTime->Hide(); 184573f748cSJohn Scipione RealignReplicants(); 185573f748cSJohn Scipione AdjustPlacement(); 186573f748cSJohn Scipione } 187ae7a6e3aSAdrien Destugues 18841281cf3SAxel Dörfler #ifdef DB_ADDONS 18941281cf3SAxel Dörfler // load addons and rehydrate archives 1903a6add49SAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 19141281cf3SAxel Dörfler InitAddOnSupport(); 19241281cf3SAxel Dörfler #endif 1939c910f9eSStephan Aßmus #endif 19441281cf3SAxel Dörfler ResizeToPreferred(); 19541281cf3SAxel Dörfler } 19641281cf3SAxel Dörfler 19741281cf3SAxel Dörfler 19841281cf3SAxel Dörfler void 19941281cf3SAxel Dörfler TReplicantTray::DetachedFromWindow() 20041281cf3SAxel Dörfler { 20141281cf3SAxel Dörfler #ifdef DB_ADDONS 20241281cf3SAxel Dörfler // clean up add-on support 203465b54cdSAxel Dörfler #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) 20441281cf3SAxel Dörfler DeleteAddOnSupport(); 20541281cf3SAxel Dörfler #endif 206465b54cdSAxel Dörfler #endif 20741281cf3SAxel Dörfler BView::DetachedFromWindow(); 20841281cf3SAxel Dörfler } 20941281cf3SAxel Dörfler 21041281cf3SAxel Dörfler 2111ad8c760SFredrik Holmqvist /*! Width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth 21266eba86fSAxel Dörfler if not in multirowmode and greater than kMinimumReplicantCount 2132ce9bab8SJohn Scipione the width should be calculated based on the actual replicant widths 21441281cf3SAxel Dörfler */ 21541281cf3SAxel Dörfler void 21641281cf3SAxel Dörfler TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight) 21741281cf3SAxel Dörfler { 21841281cf3SAxel Dörfler float width = 0, height = kMinimumTrayHeight; 21941281cf3SAxel Dörfler 22041281cf3SAxel Dörfler if (fMultiRowMode) { 2217da06231SAxel Dörfler if (fShelf->CountReplicants() > 0) 2227da06231SAxel Dörfler height = fRightBottomReplicant.bottom; 22341281cf3SAxel Dörfler 2241ad8c760SFredrik Holmqvist // the height will be uniform for the number of rows necessary to show 2251ad8c760SFredrik Holmqvist // all the reps + any gutters necessary for spacing 22641281cf3SAxel Dörfler int32 rowCount = (int32)(height / kMaxReplicantHeight); 22741281cf3SAxel Dörfler height = kGutter + (rowCount * kMaxReplicantHeight) 22841281cf3SAxel Dörfler + ((rowCount - 1) * kIconGap) + kGutter; 22941281cf3SAxel Dörfler height = max(kMinimumTrayHeight, height); 230cb6afcb1SStephan Aßmus width = fMinimumTrayWidth; 23141281cf3SAxel Dörfler } else { 2321ad8c760SFredrik Holmqvist // if last replicant overruns clock then resize to accomodate 2337da06231SAxel Dörfler if (fShelf->CountReplicants() > 0) { 234573f748cSJohn Scipione if (!fTime->IsHidden() && fTime->Frame().left 235573f748cSJohn Scipione < fRightBottomReplicant.right + 6) { 23666eba86fSAxel Dörfler width = fRightBottomReplicant.right + 6 237573f748cSJohn Scipione + fTime->Frame().Width(); 23841281cf3SAxel Dörfler } else 2397da06231SAxel Dörfler width = fRightBottomReplicant.right + 3; 24041281cf3SAxel Dörfler } 2411ad8c760SFredrik Holmqvist 24241281cf3SAxel Dörfler // this view has a fixed minimum width 243cb6afcb1SStephan Aßmus width = max(fMinimumTrayWidth, width); 2442ce9bab8SJohn Scipione height = kGutter + static_cast<TBarApp*>(be_app)->IconSize() + kGutter; 24541281cf3SAxel Dörfler } 24641281cf3SAxel Dörfler 24741281cf3SAxel Dörfler *preferredWidth = width; 2481ad8c760SFredrik Holmqvist // add 1 for the border 24941281cf3SAxel Dörfler *preferredHeight = height + 1; 25041281cf3SAxel Dörfler } 25141281cf3SAxel Dörfler 25241281cf3SAxel Dörfler 25341281cf3SAxel Dörfler void 25441281cf3SAxel Dörfler TReplicantTray::AdjustPlacement() 25541281cf3SAxel Dörfler { 25641281cf3SAxel Dörfler // called when an add-on has been added or removed 25741281cf3SAxel Dörfler // need to resize the parent of this accordingly 258a5210ab1SAxel Dörfler 25941281cf3SAxel Dörfler BRect bounds = Bounds(); 26041281cf3SAxel Dörfler float width, height; 26141281cf3SAxel Dörfler GetPreferredSize(&width, &height); 26241281cf3SAxel Dörfler 26341281cf3SAxel Dörfler if (width == bounds.Width() && height == bounds.Height()) { 26441281cf3SAxel Dörfler // no need to change anything 26541281cf3SAxel Dörfler return; 26641281cf3SAxel Dörfler } 26741281cf3SAxel Dörfler 26841281cf3SAxel Dörfler Parent()->ResizeToPreferred(); 26941281cf3SAxel Dörfler fBarView->UpdatePlacement(); 27041281cf3SAxel Dörfler Parent()->Invalidate(); 27141281cf3SAxel Dörfler Invalidate(); 27241281cf3SAxel Dörfler } 27341281cf3SAxel Dörfler 27441281cf3SAxel Dörfler 27541281cf3SAxel Dörfler void 27641281cf3SAxel Dörfler TReplicantTray::MessageReceived(BMessage* message) 27741281cf3SAxel Dörfler { 27841281cf3SAxel Dörfler switch (message->what) { 279573f748cSJohn Scipione case kShowHideTime: 28041281cf3SAxel Dörfler // from context menu in clock and in this view 281573f748cSJohn Scipione ShowHideTime(); 28241281cf3SAxel Dörfler break; 28341281cf3SAxel Dörfler 284573f748cSJohn Scipione case kTimeIntervalChanged: 285573f748cSJohn Scipione { 286573f748cSJohn Scipione if (fTime == NULL) 287573f748cSJohn Scipione return; 288573f748cSJohn Scipione 289573f748cSJohn Scipione bool use24HourClock; 290573f748cSJohn Scipione if (message->FindBool("use24HourClock", &use24HourClock) 291573f748cSJohn Scipione == B_OK) { 292573f748cSJohn Scipione BFormattingConventions conventions; 293573f748cSJohn Scipione BLocale::Default()->GetFormattingConventions(&conventions); 294573f748cSJohn Scipione conventions.SetExplicitUse24HourClock(use24HourClock); 295573f748cSJohn Scipione BPrivate::MutableLocaleRoster::Default()-> 296573f748cSJohn Scipione SetDefaultFormattingConventions(conventions); 297*3cf2d117SJohn Scipione fTime->SetUse24HourClock(use24HourClock); 29841281cf3SAxel Dörfler // time string reformat -> realign 29941281cf3SAxel Dörfler RealignReplicants(); 30041281cf3SAxel Dörfler AdjustPlacement(); 301573f748cSJohn Scipione } 30241281cf3SAxel Dörfler 30341281cf3SAxel Dörfler break; 304573f748cSJohn Scipione } 305573f748cSJohn Scipione 306*3cf2d117SJohn Scipione case kShowSeconds: 307573f748cSJohn Scipione if (fTime == NULL) 308573f748cSJohn Scipione return; 309573f748cSJohn Scipione 310*3cf2d117SJohn Scipione fTime->SetShowSeconds(!fTime->ShowSeconds()); 311573f748cSJohn Scipione 312*3cf2d117SJohn Scipione // time string reformat -> realign 313*3cf2d117SJohn Scipione RealignReplicants(); 314*3cf2d117SJohn Scipione AdjustPlacement(); 315573f748cSJohn Scipione break; 316*3cf2d117SJohn Scipione 317*3cf2d117SJohn Scipione case kShowDayOfWeek: 318*3cf2d117SJohn Scipione if (fTime == NULL) 319*3cf2d117SJohn Scipione return; 320*3cf2d117SJohn Scipione 321*3cf2d117SJohn Scipione fTime->SetShowDayOfWeek(!fTime->ShowDayOfWeek()); 322*3cf2d117SJohn Scipione 323*3cf2d117SJohn Scipione // time string reformat -> realign 324*3cf2d117SJohn Scipione RealignReplicants(); 325*3cf2d117SJohn Scipione AdjustPlacement(); 326*3cf2d117SJohn Scipione break; 327*3cf2d117SJohn Scipione 328*3cf2d117SJohn Scipione case kShowTimeZone: 329*3cf2d117SJohn Scipione if (fTime == NULL) 330*3cf2d117SJohn Scipione return; 331*3cf2d117SJohn Scipione 332*3cf2d117SJohn Scipione fTime->SetShowTimeZone(!fTime->ShowTimeZone()); 333*3cf2d117SJohn Scipione 334*3cf2d117SJohn Scipione // time string reformat -> realign 335*3cf2d117SJohn Scipione RealignReplicants(); 336*3cf2d117SJohn Scipione AdjustPlacement(); 337*3cf2d117SJohn Scipione break; 33841281cf3SAxel Dörfler 33941281cf3SAxel Dörfler #ifdef DB_ADDONS 34041281cf3SAxel Dörfler case B_NODE_MONITOR: 34141281cf3SAxel Dörfler HandleEntryUpdate(message); 34241281cf3SAxel Dörfler break; 34341281cf3SAxel Dörfler #endif 34441281cf3SAxel Dörfler 34541281cf3SAxel Dörfler default: 34641281cf3SAxel Dörfler BView::MessageReceived(message); 34741281cf3SAxel Dörfler break; 34841281cf3SAxel Dörfler } 34941281cf3SAxel Dörfler } 35041281cf3SAxel Dörfler 35141281cf3SAxel Dörfler 35241281cf3SAxel Dörfler void 35341281cf3SAxel Dörfler TReplicantTray::MouseDown(BPoint where) 35441281cf3SAxel Dörfler { 35541281cf3SAxel Dörfler #ifdef DB_ADDONS 35641281cf3SAxel Dörfler if (modifiers() & B_CONTROL_KEY) 35741281cf3SAxel Dörfler DumpList(fItemList); 35841281cf3SAxel Dörfler #endif 35941281cf3SAxel Dörfler 36041281cf3SAxel Dörfler uint32 buttons; 36141281cf3SAxel Dörfler 36241281cf3SAxel Dörfler Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons); 36341281cf3SAxel Dörfler if (buttons == B_SECONDARY_MOUSE_BUTTON) { 36441281cf3SAxel Dörfler ShowReplicantMenu(where); 36541281cf3SAxel Dörfler } else { 36641281cf3SAxel Dörfler BPoint save = where; 36741281cf3SAxel Dörfler bigtime_t doubleClickSpeed; 36841281cf3SAxel Dörfler bigtime_t start = system_time(); 36941281cf3SAxel Dörfler uint32 buttons; 37041281cf3SAxel Dörfler 37141281cf3SAxel Dörfler get_click_speed(&doubleClickSpeed); 37241281cf3SAxel Dörfler 37341281cf3SAxel Dörfler do { 37441281cf3SAxel Dörfler if (fabs(where.x - save.x) > 4 || fabs(where.y - save.y) > 4) 37541281cf3SAxel Dörfler // user moved out of bounds of click area 37641281cf3SAxel Dörfler break; 37741281cf3SAxel Dörfler 37841281cf3SAxel Dörfler if ((system_time() - start) > (2 * doubleClickSpeed)) { 37941281cf3SAxel Dörfler ShowReplicantMenu(where); 38041281cf3SAxel Dörfler break; 38141281cf3SAxel Dörfler } 38241281cf3SAxel Dörfler 38341281cf3SAxel Dörfler snooze(50000); 38441281cf3SAxel Dörfler GetMouse(&where, &buttons); 38541281cf3SAxel Dörfler } while (buttons); 38641281cf3SAxel Dörfler } 38741281cf3SAxel Dörfler BView::MouseDown(where); 38841281cf3SAxel Dörfler } 38941281cf3SAxel Dörfler 390*3cf2d117SJohn Scipione 391*3cf2d117SJohn Scipione void 392*3cf2d117SJohn Scipione TReplicantTray::ShowReplicantMenu(BPoint point) 393*3cf2d117SJohn Scipione { 394*3cf2d117SJohn Scipione BPopUpMenu* menu = new BPopUpMenu("", false, false); 395*3cf2d117SJohn Scipione menu->SetFont(be_plain_font); 396*3cf2d117SJohn Scipione 397*3cf2d117SJohn Scipione // If clock is visible show the extended menu, otherwise show "Show time" 398*3cf2d117SJohn Scipione 399*3cf2d117SJohn Scipione if (!fTime->IsHidden()) 400*3cf2d117SJohn Scipione fTime->ShowTimeOptions(ConvertToScreen(point)); 401*3cf2d117SJohn Scipione else { 402*3cf2d117SJohn Scipione BMenuItem* item = new BMenuItem(B_TRANSLATE("Show time"), 403*3cf2d117SJohn Scipione new BMessage(kShowHideTime)); 404*3cf2d117SJohn Scipione menu->AddItem(item); 405*3cf2d117SJohn Scipione menu->SetTargetForItems(this); 406*3cf2d117SJohn Scipione BPoint where = ConvertToScreen(point); 407*3cf2d117SJohn Scipione menu->Go(where, true, true, BRect(where - BPoint(4, 4), 408*3cf2d117SJohn Scipione where + BPoint(4, 4)), true); 409*3cf2d117SJohn Scipione } 410*3cf2d117SJohn Scipione } 411*3cf2d117SJohn Scipione 412*3cf2d117SJohn Scipione 413*3cf2d117SJohn Scipione void 414*3cf2d117SJohn Scipione TReplicantTray::SetMultiRow(bool state) 415*3cf2d117SJohn Scipione { 416*3cf2d117SJohn Scipione fMultiRowMode = state; 417*3cf2d117SJohn Scipione } 418*3cf2d117SJohn Scipione 419*3cf2d117SJohn Scipione 420*3cf2d117SJohn Scipione void 421*3cf2d117SJohn Scipione TReplicantTray::ShowHideTime() 422*3cf2d117SJohn Scipione { 423*3cf2d117SJohn Scipione if (fTime == NULL) 424*3cf2d117SJohn Scipione return; 425*3cf2d117SJohn Scipione 426*3cf2d117SJohn Scipione if (fTime->IsHidden()) 427*3cf2d117SJohn Scipione fTime->Show(); 428*3cf2d117SJohn Scipione else 429*3cf2d117SJohn Scipione fTime->Hide(); 430*3cf2d117SJohn Scipione 431*3cf2d117SJohn Scipione RealignReplicants(); 432*3cf2d117SJohn Scipione AdjustPlacement(); 433*3cf2d117SJohn Scipione } 434*3cf2d117SJohn Scipione 435*3cf2d117SJohn Scipione 43641281cf3SAxel Dörfler #ifdef DB_ADDONS 43741281cf3SAxel Dörfler 438*3cf2d117SJohn Scipione 43941281cf3SAxel Dörfler void 44041281cf3SAxel Dörfler TReplicantTray::InitAddOnSupport() 44141281cf3SAxel Dörfler { 44241281cf3SAxel Dörfler // list to maintain refs to each rep added/deleted 44341281cf3SAxel Dörfler fItemList = new BList(); 44441281cf3SAxel Dörfler BPath path; 4451ad8c760SFredrik Holmqvist 44641281cf3SAxel Dörfler if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) { 4473e6ff860SRene Gollent path.Append(kReplicantSettingsFile); 44841281cf3SAxel Dörfler 44941281cf3SAxel Dörfler BFile file(path.Path(), B_READ_ONLY); 4503e6ff860SRene Gollent if (file.InitCheck() == B_OK) { 4513e6ff860SRene Gollent status_t result; 4523e6ff860SRene Gollent BEntry entry; 4533e6ff860SRene Gollent int32 id; 454c0ad1c91SRene Gollent BString path; 4553e6ff860SRene Gollent if (fAddOnSettings.Unflatten(&file) == B_OK) { 456c0ad1c91SRene Gollent for (int32 i = 0; fAddOnSettings.FindString(kReplicantPathField, 457c0ad1c91SRene Gollent i, &path) == B_OK; i++) { 458c0ad1c91SRene Gollent if (entry.SetTo(path.String()) == B_OK && entry.Exists()) { 4593e6ff860SRene Gollent result = LoadAddOn(&entry, &id, false); 4603e6ff860SRene Gollent } else 4613e6ff860SRene Gollent result = B_ENTRY_NOT_FOUND; 46241281cf3SAxel Dörfler 4633e6ff860SRene Gollent if (result != B_OK) { 464c0ad1c91SRene Gollent fAddOnSettings.RemoveData(kReplicantPathField, i); 4653e6ff860SRene Gollent --i; 46641281cf3SAxel Dörfler } 46741281cf3SAxel Dörfler } 46841281cf3SAxel Dörfler } 4693e6ff860SRene Gollent } 4703e6ff860SRene Gollent } 47141281cf3SAxel Dörfler } 47241281cf3SAxel Dörfler 47341281cf3SAxel Dörfler 47441281cf3SAxel Dörfler void 47541281cf3SAxel Dörfler TReplicantTray::DeleteAddOnSupport() 47641281cf3SAxel Dörfler { 4777625ce51SRene Gollent _SaveSettings(); 4783e6ff860SRene Gollent 47941281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 48041281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->RemoveItem(i); 48141281cf3SAxel Dörfler if (item) { 48241281cf3SAxel Dörfler if (item->isAddOn) 48341281cf3SAxel Dörfler watch_node(&(item->nodeRef), B_STOP_WATCHING, this, Window()); 48441281cf3SAxel Dörfler 48541281cf3SAxel Dörfler delete item; 48641281cf3SAxel Dörfler } 48741281cf3SAxel Dörfler } 48841281cf3SAxel Dörfler delete fItemList; 48941281cf3SAxel Dörfler 49041281cf3SAxel Dörfler // stop the volume mount/unmount watch 49141281cf3SAxel Dörfler stop_watching(this, Window()); 49241281cf3SAxel Dörfler } 49341281cf3SAxel Dörfler 49441281cf3SAxel Dörfler 49541281cf3SAxel Dörfler DeskbarItemInfo* 49641281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(node_ref& nodeRef) 49741281cf3SAxel Dörfler { 49841281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 49966eba86fSAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 50041281cf3SAxel Dörfler if (item == NULL) 50141281cf3SAxel Dörfler continue; 50241281cf3SAxel Dörfler 50341281cf3SAxel Dörfler if (item->nodeRef == nodeRef) 50441281cf3SAxel Dörfler return item; 50541281cf3SAxel Dörfler } 50641281cf3SAxel Dörfler 50741281cf3SAxel Dörfler return NULL; 50841281cf3SAxel Dörfler } 50941281cf3SAxel Dörfler 51041281cf3SAxel Dörfler 51141281cf3SAxel Dörfler DeskbarItemInfo* 51241281cf3SAxel Dörfler TReplicantTray::DeskbarItemFor(int32 id) 51341281cf3SAxel Dörfler { 51441281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 51566eba86fSAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 51641281cf3SAxel Dörfler if (item == NULL) 51741281cf3SAxel Dörfler continue; 51841281cf3SAxel Dörfler 51941281cf3SAxel Dörfler if (item->id == id) 52041281cf3SAxel Dörfler return item; 52141281cf3SAxel Dörfler } 52241281cf3SAxel Dörfler 52341281cf3SAxel Dörfler return NULL; 52441281cf3SAxel Dörfler } 52541281cf3SAxel Dörfler 52641281cf3SAxel Dörfler 52741281cf3SAxel Dörfler bool 52841281cf3SAxel Dörfler TReplicantTray::NodeExists(node_ref& nodeRef) 52941281cf3SAxel Dörfler { 53041281cf3SAxel Dörfler return DeskbarItemFor(nodeRef) != NULL; 53141281cf3SAxel Dörfler } 53241281cf3SAxel Dörfler 53341281cf3SAxel Dörfler 53466eba86fSAxel Dörfler /*! This handles B_NODE_MONITOR & B_QUERY_UPDATE messages received 53566eba86fSAxel Dörfler for the registered add-ons. 53641281cf3SAxel Dörfler */ 53741281cf3SAxel Dörfler void 53841281cf3SAxel Dörfler TReplicantTray::HandleEntryUpdate(BMessage* message) 53941281cf3SAxel Dörfler { 54041281cf3SAxel Dörfler int32 opcode; 54141281cf3SAxel Dörfler if (message->FindInt32("opcode", &opcode) != B_OK) 54241281cf3SAxel Dörfler return; 54341281cf3SAxel Dörfler 54441281cf3SAxel Dörfler BPath path; 54541281cf3SAxel Dörfler switch (opcode) { 54641281cf3SAxel Dörfler case B_ENTRY_MOVED: 54741281cf3SAxel Dörfler { 54841281cf3SAxel Dörfler entry_ref ref; 54941281cf3SAxel Dörfler ino_t todirectory; 55041281cf3SAxel Dörfler ino_t node; 55141281cf3SAxel Dörfler const char* name; 55241281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK 55371bd3ba5SJonas Sundström && message->FindInt64("from directory", &(ref.directory)) 55471bd3ba5SJonas Sundström == B_OK 55541281cf3SAxel Dörfler && message->FindInt64("to directory", &todirectory) == B_OK 55641281cf3SAxel Dörfler && message->FindInt32("device", &(ref.device)) == B_OK 55741281cf3SAxel Dörfler && message->FindInt64("node", &node) == B_OK ) { 55841281cf3SAxel Dörfler 55941281cf3SAxel Dörfler if (!name) 56041281cf3SAxel Dörfler break; 56141281cf3SAxel Dörfler 56241281cf3SAxel Dörfler ref.set_name(name); 56341281cf3SAxel Dörfler // change the directory reference to 56441281cf3SAxel Dörfler // the new directory 56541281cf3SAxel Dörfler MoveItem(&ref, todirectory); 56641281cf3SAxel Dörfler } 56741281cf3SAxel Dörfler break; 56866eba86fSAxel Dörfler } 56941281cf3SAxel Dörfler 57041281cf3SAxel Dörfler case B_ENTRY_REMOVED: 57141281cf3SAxel Dörfler { 57241281cf3SAxel Dörfler // entry was rm'd from the device 57341281cf3SAxel Dörfler node_ref nodeRef; 57441281cf3SAxel Dörfler if (message->FindInt32("device", &(nodeRef.device)) == B_OK 57541281cf3SAxel Dörfler && message->FindInt64("node", &(nodeRef.node)) == B_OK) { 57641281cf3SAxel Dörfler DeskbarItemInfo* item = DeskbarItemFor(nodeRef); 57741281cf3SAxel Dörfler if (item == NULL) 57841281cf3SAxel Dörfler break; 57941281cf3SAxel Dörfler 58041281cf3SAxel Dörfler // If there is a team running where the add-on comes from, 58141281cf3SAxel Dörfler // we don't want to remove the icon yet. 58241281cf3SAxel Dörfler if (be_roster->IsRunning(&item->entryRef)) 58341281cf3SAxel Dörfler break; 58441281cf3SAxel Dörfler 58541281cf3SAxel Dörfler UnloadAddOn(&nodeRef, NULL, true, false); 58641281cf3SAxel Dörfler } 58741281cf3SAxel Dörfler break; 58866eba86fSAxel Dörfler } 58941281cf3SAxel Dörfler } 59066eba86fSAxel Dörfler } 59141281cf3SAxel Dörfler 59241281cf3SAxel Dörfler 5931ad8c760SFredrik Holmqvist /*! The add-ons must support the exported C function API 59466eba86fSAxel Dörfler if they do, they will be loaded and added to deskbar 59566eba86fSAxel Dörfler primary function is the Instantiate function 5967da06231SAxel Dörfler */ 59741281cf3SAxel Dörfler status_t 5983e6ff860SRene Gollent TReplicantTray::LoadAddOn(BEntry* entry, int32* id, bool addToSettings) 59941281cf3SAxel Dörfler { 60041281cf3SAxel Dörfler if (!entry) 60141281cf3SAxel Dörfler return B_ERROR; 60241281cf3SAxel Dörfler 60341281cf3SAxel Dörfler node_ref nodeRef; 60441281cf3SAxel Dörfler entry->GetNodeRef(&nodeRef); 60541281cf3SAxel Dörfler // no duplicates 60641281cf3SAxel Dörfler if (NodeExists(nodeRef)) 60741281cf3SAxel Dörfler return B_ERROR; 60841281cf3SAxel Dörfler 60941281cf3SAxel Dörfler BNode node(entry); 61041281cf3SAxel Dörfler BPath path; 61166eba86fSAxel Dörfler status_t status = entry->GetPath(&path); 61266eba86fSAxel Dörfler if (status < B_OK) 61366eba86fSAxel Dörfler return status; 61441281cf3SAxel Dörfler 61541281cf3SAxel Dörfler // load the add-on 61641281cf3SAxel Dörfler image_id image = load_add_on(path.Path()); 61766eba86fSAxel Dörfler if (image < B_OK) 61866eba86fSAxel Dörfler return image; 61941281cf3SAxel Dörfler 62041281cf3SAxel Dörfler // get the view loading function symbol 62141281cf3SAxel Dörfler // we first look for a symbol that takes an image_id 62241281cf3SAxel Dörfler // and entry_ref pointer, if not found, go with normal 62341281cf3SAxel Dörfler // instantiate function 62441281cf3SAxel Dörfler BView* (*entryFunction)(image_id, const entry_ref*); 62541281cf3SAxel Dörfler BView* (*itemFunction)(void); 62641281cf3SAxel Dörfler BView* view = NULL; 62741281cf3SAxel Dörfler 62841281cf3SAxel Dörfler entry_ref ref; 62941281cf3SAxel Dörfler entry->GetRef(&ref); 63041281cf3SAxel Dörfler 63141281cf3SAxel Dörfler if (get_image_symbol(image, kInstantiateEntryCFunctionName, 63266eba86fSAxel Dörfler B_SYMBOL_TYPE_TEXT, (void**)&entryFunction) >= B_OK) { 63341281cf3SAxel Dörfler view = (*entryFunction)(image, &ref); 63441281cf3SAxel Dörfler } else if (get_image_symbol(image, kInstantiateItemCFunctionName, 63566eba86fSAxel Dörfler B_SYMBOL_TYPE_TEXT, (void**)&itemFunction) >= B_OK) { 63641281cf3SAxel Dörfler view = (*itemFunction)(); 63741281cf3SAxel Dörfler } else { 63841281cf3SAxel Dörfler unload_add_on(image); 63941281cf3SAxel Dörfler return B_ERROR; 64041281cf3SAxel Dörfler } 64141281cf3SAxel Dörfler 64266eba86fSAxel Dörfler if (view == NULL || IconExists(view->Name())) { 64341281cf3SAxel Dörfler delete view; 64441281cf3SAxel Dörfler unload_add_on(image); 64541281cf3SAxel Dörfler return B_ERROR; 64641281cf3SAxel Dörfler } 64741281cf3SAxel Dörfler 64841281cf3SAxel Dörfler BMessage* data = new BMessage; 64941281cf3SAxel Dörfler view->Archive(data); 65041281cf3SAxel Dörfler delete view; 65141281cf3SAxel Dörfler 65241281cf3SAxel Dörfler AddIcon(data, id, &ref); 65341281cf3SAxel Dörfler // add the rep; adds info to list 65441281cf3SAxel Dörfler 6553e6ff860SRene Gollent if (addToSettings) { 656c0ad1c91SRene Gollent fAddOnSettings.AddString(kReplicantPathField, path.Path()); 6577625ce51SRene Gollent _SaveSettings(); 6583e6ff860SRene Gollent } 65941281cf3SAxel Dörfler 66041281cf3SAxel Dörfler return B_OK; 66141281cf3SAxel Dörfler } 66241281cf3SAxel Dörfler 66341281cf3SAxel Dörfler 66441281cf3SAxel Dörfler status_t 66541281cf3SAxel Dörfler TReplicantTray::AddItem(int32 id, node_ref nodeRef, BEntry& entry, bool isAddOn) 66641281cf3SAxel Dörfler { 66741281cf3SAxel Dörfler DeskbarItemInfo* item = new DeskbarItemInfo; 66841281cf3SAxel Dörfler if (item == NULL) 66941281cf3SAxel Dörfler return B_NO_MEMORY; 67041281cf3SAxel Dörfler 67141281cf3SAxel Dörfler item->id = id; 67241281cf3SAxel Dörfler item->isAddOn = isAddOn; 67341281cf3SAxel Dörfler 67441281cf3SAxel Dörfler if (entry.GetRef(&item->entryRef) < B_OK) { 67541281cf3SAxel Dörfler item->entryRef.device = -1; 67641281cf3SAxel Dörfler item->entryRef.directory = -1; 67741281cf3SAxel Dörfler item->entryRef.name = NULL; 67841281cf3SAxel Dörfler } 67941281cf3SAxel Dörfler item->nodeRef = nodeRef; 68041281cf3SAxel Dörfler 68141281cf3SAxel Dörfler fItemList->AddItem(item); 68241281cf3SAxel Dörfler 68341281cf3SAxel Dörfler if (isAddOn) 68441281cf3SAxel Dörfler watch_node(&nodeRef, B_WATCH_NAME | B_WATCH_ATTR, this, Window()); 68541281cf3SAxel Dörfler 68641281cf3SAxel Dörfler return B_OK; 68741281cf3SAxel Dörfler } 68841281cf3SAxel Dörfler 68941281cf3SAxel Dörfler 69041281cf3SAxel Dörfler /** from entry_removed message, when attribute removed 69141281cf3SAxel Dörfler * or when a device is unmounted (use removeall, by device) 69241281cf3SAxel Dörfler */ 69341281cf3SAxel Dörfler 69441281cf3SAxel Dörfler void 69541281cf3SAxel Dörfler TReplicantTray::UnloadAddOn(node_ref* nodeRef, dev_t* device, 69641281cf3SAxel Dörfler bool which, bool removeAll) 69741281cf3SAxel Dörfler { 69841281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 69941281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 70041281cf3SAxel Dörfler if (!item) 70141281cf3SAxel Dörfler continue; 70241281cf3SAxel Dörfler 70341281cf3SAxel Dörfler if ((which && nodeRef && item->nodeRef == *nodeRef) 70441281cf3SAxel Dörfler || (device && item->nodeRef.device == *device)) { 70541281cf3SAxel Dörfler 70641281cf3SAxel Dörfler if (device && be_roster->IsRunning(&item->entryRef)) 70741281cf3SAxel Dörfler continue; 70841281cf3SAxel Dörfler 70941281cf3SAxel Dörfler RemoveIcon(item->id); 71041281cf3SAxel Dörfler 71141281cf3SAxel Dörfler if (!removeAll) 71241281cf3SAxel Dörfler break; 71341281cf3SAxel Dörfler } 71441281cf3SAxel Dörfler } 71541281cf3SAxel Dörfler } 71641281cf3SAxel Dörfler 71741281cf3SAxel Dörfler 71841281cf3SAxel Dörfler void 71941281cf3SAxel Dörfler TReplicantTray::RemoveItem(int32 id) 72041281cf3SAxel Dörfler { 72141281cf3SAxel Dörfler DeskbarItemInfo* item = DeskbarItemFor(id); 72241281cf3SAxel Dörfler if (item == NULL) 72341281cf3SAxel Dörfler return; 72441281cf3SAxel Dörfler 72541281cf3SAxel Dörfler // attribute was added via Deskbar API (AddItem(entry_ref*, int32*) 72641281cf3SAxel Dörfler if (item->isAddOn) { 7277625ce51SRene Gollent BPath path(&item->entryRef); 7287625ce51SRene Gollent BString storedPath; 7297625ce51SRene Gollent for (int32 i = 0; 7308aab28f1SRene Gollent fAddOnSettings.FindString(kReplicantPathField, i, &storedPath) 7317625ce51SRene Gollent == B_OK; i++) { 7327625ce51SRene Gollent if (storedPath == path.Path()) { 7338aab28f1SRene Gollent fAddOnSettings.RemoveData(kReplicantPathField, i); 7347625ce51SRene Gollent break; 7357625ce51SRene Gollent } 7367625ce51SRene Gollent } 7377625ce51SRene Gollent _SaveSettings(); 7387625ce51SRene Gollent 73941281cf3SAxel Dörfler BNode node(&item->entryRef); 74041281cf3SAxel Dörfler watch_node(&item->nodeRef, B_STOP_WATCHING, this, Window()); 74141281cf3SAxel Dörfler } 74241281cf3SAxel Dörfler 74341281cf3SAxel Dörfler fItemList->RemoveItem(item); 74441281cf3SAxel Dörfler delete item; 74541281cf3SAxel Dörfler } 74641281cf3SAxel Dörfler 74741281cf3SAxel Dörfler 74841281cf3SAxel Dörfler /** ENTRY_MOVED message, moving only occurs on a device 74941281cf3SAxel Dörfler * copying will occur (ENTRY_CREATED) between devices 75041281cf3SAxel Dörfler */ 75141281cf3SAxel Dörfler 75241281cf3SAxel Dörfler void 75341281cf3SAxel Dörfler TReplicantTray::MoveItem(entry_ref* ref, ino_t toDirectory) 75441281cf3SAxel Dörfler { 75541281cf3SAxel Dörfler if (!ref) 75641281cf3SAxel Dörfler return; 75741281cf3SAxel Dörfler 75841281cf3SAxel Dörfler // scan for a matching entry_ref and update it 75941281cf3SAxel Dörfler // 76041281cf3SAxel Dörfler // don't need to change node info as it does not change 76141281cf3SAxel Dörfler 76241281cf3SAxel Dörfler for (int32 i = fItemList->CountItems(); i-- > 0 ;) { 76341281cf3SAxel Dörfler DeskbarItemInfo* item = (DeskbarItemInfo*)fItemList->ItemAt(i); 76441281cf3SAxel Dörfler if (!item) 76541281cf3SAxel Dörfler continue; 76641281cf3SAxel Dörfler 76741281cf3SAxel Dörfler if (!strcmp(item->entryRef.name, ref->name) 76841281cf3SAxel Dörfler && item->entryRef.device == ref->device 76941281cf3SAxel Dörfler && item->entryRef.directory == ref->directory) { 77041281cf3SAxel Dörfler item->entryRef.directory = toDirectory; 77141281cf3SAxel Dörfler break; 77241281cf3SAxel Dörfler } 77341281cf3SAxel Dörfler } 77441281cf3SAxel Dörfler } 77541281cf3SAxel Dörfler 77641281cf3SAxel Dörfler #endif // add-on support 77741281cf3SAxel Dörfler 77841281cf3SAxel Dörfler // external add-on API routines 77941281cf3SAxel Dörfler // called using the new BDeskbar class 78041281cf3SAxel Dörfler 78141281cf3SAxel Dörfler // existence of icon/replicant by name or ID 78241281cf3SAxel Dörfler // returns opposite 78341281cf3SAxel Dörfler // note: name and id are semi-private limiting 78441281cf3SAxel Dörfler // the ability of non-host apps to remove 78541281cf3SAxel Dörfler // icons without a little bit of work 78641281cf3SAxel Dörfler 78741281cf3SAxel Dörfler /** for a specific id 78841281cf3SAxel Dörfler * return the name of the replicant (name of view) 78941281cf3SAxel Dörfler */ 79041281cf3SAxel Dörfler 79141281cf3SAxel Dörfler status_t 79241281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 id, const char** name) 79341281cf3SAxel Dörfler { 79441281cf3SAxel Dörfler if (id < 0) 79541281cf3SAxel Dörfler return B_ERROR; 79641281cf3SAxel Dörfler 79741281cf3SAxel Dörfler int32 index, temp; 79841281cf3SAxel Dörfler BView* view = ViewAt(&index, &temp, id, false); 79941281cf3SAxel Dörfler if (view) { 80041281cf3SAxel Dörfler *name = view->Name(); 80141281cf3SAxel Dörfler return B_OK; 80241281cf3SAxel Dörfler } 80341281cf3SAxel Dörfler 80441281cf3SAxel Dörfler return B_ERROR; 80541281cf3SAxel Dörfler } 80641281cf3SAxel Dörfler 80741281cf3SAxel Dörfler 8087da06231SAxel Dörfler /** for a specific name 8097da06231SAxel Dörfler * return the id (internal to Deskbar) 8107da06231SAxel Dörfler */ 8117da06231SAxel Dörfler 81241281cf3SAxel Dörfler status_t 81341281cf3SAxel Dörfler TReplicantTray::ItemInfo(const char* name, int32* id) 81441281cf3SAxel Dörfler { 81541281cf3SAxel Dörfler if (!name || strlen(name) <= 0) 81641281cf3SAxel Dörfler return B_ERROR; 81741281cf3SAxel Dörfler 81841281cf3SAxel Dörfler int32 index; 81941281cf3SAxel Dörfler BView* view = ViewAt(&index, id, name); 82041281cf3SAxel Dörfler if (view) 82141281cf3SAxel Dörfler return B_OK; 82241281cf3SAxel Dörfler 82341281cf3SAxel Dörfler return B_ERROR; 82441281cf3SAxel Dörfler } 82541281cf3SAxel Dörfler 82641281cf3SAxel Dörfler 8277da06231SAxel Dörfler /** at a specific index 8287da06231SAxel Dörfler * return both the name and the id of the replicant 8297da06231SAxel Dörfler */ 8307da06231SAxel Dörfler 83141281cf3SAxel Dörfler status_t 83241281cf3SAxel Dörfler TReplicantTray::ItemInfo(int32 index, const char** name, int32* id) 83341281cf3SAxel Dörfler { 83441281cf3SAxel Dörfler if (index < 0) 83541281cf3SAxel Dörfler return B_ERROR; 83641281cf3SAxel Dörfler 83741281cf3SAxel Dörfler BView* view; 83841281cf3SAxel Dörfler fShelf->ReplicantAt(index, &view, (uint32*)id, NULL); 83941281cf3SAxel Dörfler if (view) { 84041281cf3SAxel Dörfler *name = view->Name(); 84141281cf3SAxel Dörfler return B_OK; 84241281cf3SAxel Dörfler } 84341281cf3SAxel Dörfler 84441281cf3SAxel Dörfler return B_ERROR; 84541281cf3SAxel Dörfler } 84641281cf3SAxel Dörfler 84741281cf3SAxel Dörfler 8487da06231SAxel Dörfler /** replicant exists, by id/index */ 8497da06231SAxel Dörfler 85041281cf3SAxel Dörfler bool 85141281cf3SAxel Dörfler TReplicantTray::IconExists(int32 target, bool byIndex) 85241281cf3SAxel Dörfler { 85341281cf3SAxel Dörfler int32 index, id; 85441281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 85541281cf3SAxel Dörfler 85641281cf3SAxel Dörfler return view && index >= 0; 85741281cf3SAxel Dörfler } 85841281cf3SAxel Dörfler 85941281cf3SAxel Dörfler 8607da06231SAxel Dörfler /** replicant exists, by name */ 8617da06231SAxel Dörfler 86241281cf3SAxel Dörfler bool 86341281cf3SAxel Dörfler TReplicantTray::IconExists(const char* name) 86441281cf3SAxel Dörfler { 86541281cf3SAxel Dörfler if (!name || strlen(name) == 0) 86641281cf3SAxel Dörfler return false; 86741281cf3SAxel Dörfler 86841281cf3SAxel Dörfler int32 index, id; 86941281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 87041281cf3SAxel Dörfler 87141281cf3SAxel Dörfler return view && index >= 0; 87241281cf3SAxel Dörfler } 87341281cf3SAxel Dörfler 87441281cf3SAxel Dörfler 87541281cf3SAxel Dörfler int32 87641281cf3SAxel Dörfler TReplicantTray::IconCount() const 87741281cf3SAxel Dörfler { 87841281cf3SAxel Dörfler return fShelf->CountReplicants(); 87941281cf3SAxel Dörfler } 88041281cf3SAxel Dörfler 88141281cf3SAxel Dörfler 882ced3755cSAxel Dörfler /*! Message must contain an archivable view for later rehydration. 883ced3755cSAxel Dörfler This function takes over ownership of the provided message on success 884ced3755cSAxel Dörfler only. 885ced3755cSAxel Dörfler Returns the current replicant ID. 8867da06231SAxel Dörfler */ 88741281cf3SAxel Dörfler status_t 888ced3755cSAxel Dörfler TReplicantTray::AddIcon(BMessage* archive, int32* id, const entry_ref* addOn) 88941281cf3SAxel Dörfler { 890ced3755cSAxel Dörfler if (archive == NULL || id == NULL) 89141281cf3SAxel Dörfler return B_ERROR; 89241281cf3SAxel Dörfler 8939c50f36eSAxel Dörfler // find entry_ref 8949c50f36eSAxel Dörfler 8959c50f36eSAxel Dörfler entry_ref ref; 8969c50f36eSAxel Dörfler if (addOn) { 8979c50f36eSAxel Dörfler // Use it if we got it 8989c50f36eSAxel Dörfler ref = *addOn; 8999c50f36eSAxel Dörfler } else { 9009c50f36eSAxel Dörfler const char* signature; 9011ad8c760SFredrik Holmqvist 902ced3755cSAxel Dörfler status_t status = archive->FindString("add_on", &signature); 9039c50f36eSAxel Dörfler if (status == B_OK) { 9049c50f36eSAxel Dörfler BRoster roster; 9059c50f36eSAxel Dörfler status = roster.FindApp(signature, &ref); 9069c50f36eSAxel Dörfler } 9079c50f36eSAxel Dörfler if (status < B_OK) 9089c50f36eSAxel Dörfler return status; 9099c50f36eSAxel Dörfler } 9109c50f36eSAxel Dörfler 9119c50f36eSAxel Dörfler BFile file; 9129c50f36eSAxel Dörfler status_t status = file.SetTo(&ref, B_READ_ONLY); 9139c50f36eSAxel Dörfler if (status < B_OK) 9149c50f36eSAxel Dörfler return status; 9159c50f36eSAxel Dörfler 9169c50f36eSAxel Dörfler node_ref nodeRef; 9179c50f36eSAxel Dörfler status = file.GetNodeRef(&nodeRef); 9189c50f36eSAxel Dörfler if (status < B_OK) 9199c50f36eSAxel Dörfler return status; 9209c50f36eSAxel Dörfler 9219c50f36eSAxel Dörfler BEntry entry(&ref, true); 9221ad8c760SFredrik Holmqvist // TODO: this resolves an eventual link for the item being added - this 9231ad8c760SFredrik Holmqvist // is okay for now, but in multi-user environments, one might want to 9241ad8c760SFredrik Holmqvist // have links that carry the be:deskbar_item_status attribute 9259c50f36eSAxel Dörfler status = entry.InitCheck(); 9269c50f36eSAxel Dörfler if (status != B_OK) 9279c50f36eSAxel Dörfler return status; 9289c50f36eSAxel Dörfler 92941281cf3SAxel Dörfler *id = 999; 930ced3755cSAxel Dörfler if (archive->what == B_ARCHIVED_OBJECT) 931ced3755cSAxel Dörfler archive->what = 0; 93241281cf3SAxel Dörfler 933ced3755cSAxel Dörfler BRect originalBounds = archive->FindRect("_frame"); 9341ad8c760SFredrik Holmqvist // this is a work-around for buggy replicants that change their size in 9351ad8c760SFredrik Holmqvist // AttachedToWindow() (such as "SVM") 936a5210ab1SAxel Dörfler 9371ad8c760SFredrik Holmqvist // TODO: check for name collisions? 938ced3755cSAxel Dörfler status = fShelf->AddReplicant(archive, BPoint(1, 1)); 9399c50f36eSAxel Dörfler if (status != B_OK) 9409c50f36eSAxel Dörfler return status; 94141281cf3SAxel Dörfler 942a5210ab1SAxel Dörfler int32 count = fShelf->CountReplicants(); 943a5210ab1SAxel Dörfler BView* view; 944a5210ab1SAxel Dörfler fShelf->ReplicantAt(count - 1, &view, (uint32*)id, NULL); 945a5210ab1SAxel Dörfler 946a5210ab1SAxel Dörfler if (originalBounds != view->Bounds()) { 947a5210ab1SAxel Dörfler // The replicant changed its size when added to the window, so we need 94871bd3ba5SJonas Sundström // to recompute all over again (it's already done once via 94971bd3ba5SJonas Sundström // BShelf::AddReplicant() and TReplicantShelf::CanAcceptReplicantView()) 950a5210ab1SAxel Dörfler RealignReplicants(); 951a5210ab1SAxel Dörfler } 952a5210ab1SAxel Dörfler 95341281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 95441281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 95541281cf3SAxel Dörfler float width, height; 95641281cf3SAxel Dörfler GetPreferredSize(&width, &height); 95741281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) 95841281cf3SAxel Dörfler AdjustPlacement(); 95941281cf3SAxel Dörfler 96041281cf3SAxel Dörfler // add the item to the add-on list 96141281cf3SAxel Dörfler 96241281cf3SAxel Dörfler AddItem(*id, nodeRef, entry, addOn != NULL); 96341281cf3SAxel Dörfler return B_OK; 96441281cf3SAxel Dörfler } 96541281cf3SAxel Dörfler 96641281cf3SAxel Dörfler 96741281cf3SAxel Dörfler void 96841281cf3SAxel Dörfler TReplicantTray::RemoveIcon(int32 target, bool byIndex) 96941281cf3SAxel Dörfler { 97041281cf3SAxel Dörfler if (target < 0) 97141281cf3SAxel Dörfler return; 97241281cf3SAxel Dörfler 97341281cf3SAxel Dörfler int32 index, id; 97441281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 97541281cf3SAxel Dörfler if (view && index >= 0) { 9767da06231SAxel Dörfler // remove the reference from the item list & the shelf 97741281cf3SAxel Dörfler RemoveItem(id); 97841281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 9797da06231SAxel Dörfler 98041281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 98141281cf3SAxel Dörfler RealReplicantAdjustment(index); 98241281cf3SAxel Dörfler } 98341281cf3SAxel Dörfler } 98441281cf3SAxel Dörfler 98541281cf3SAxel Dörfler 98641281cf3SAxel Dörfler void 98741281cf3SAxel Dörfler TReplicantTray::RemoveIcon(const char* name) 98841281cf3SAxel Dörfler { 98941281cf3SAxel Dörfler if (!name || strlen(name) <= 0) 99041281cf3SAxel Dörfler return; 99141281cf3SAxel Dörfler 99241281cf3SAxel Dörfler int32 id, index; 99341281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 99441281cf3SAxel Dörfler if (view && index >= 0) { 9957da06231SAxel Dörfler // remove the reference from the item list & shelf 99641281cf3SAxel Dörfler RemoveItem(id); 99741281cf3SAxel Dörfler fShelf->DeleteReplicant(index); 9987da06231SAxel Dörfler 99941281cf3SAxel Dörfler // force a placement update, !! need to fix BShelf 100041281cf3SAxel Dörfler RealReplicantAdjustment(index); 100141281cf3SAxel Dörfler } 100241281cf3SAxel Dörfler } 100341281cf3SAxel Dörfler 100441281cf3SAxel Dörfler 100541281cf3SAxel Dörfler void 10067da06231SAxel Dörfler TReplicantTray::RealReplicantAdjustment(int32 startIndex) 100741281cf3SAxel Dörfler { 10087da06231SAxel Dörfler if (startIndex < 0) 100941281cf3SAxel Dörfler return; 10107da06231SAxel Dörfler 10117da06231SAxel Dörfler if (startIndex == fLastReplicant) 10127da06231SAxel Dörfler startIndex = 0; 10137da06231SAxel Dörfler 101441281cf3SAxel Dörfler // reset the locations of all replicants after the one deleted 10157da06231SAxel Dörfler RealignReplicants(startIndex); 101641281cf3SAxel Dörfler 101741281cf3SAxel Dörfler float oldWidth = Bounds().Width(); 101841281cf3SAxel Dörfler float oldHeight = Bounds().Height(); 101941281cf3SAxel Dörfler float width, height; 102041281cf3SAxel Dörfler GetPreferredSize(&width, &height); 102141281cf3SAxel Dörfler if (oldWidth != width || oldHeight != height) { 10221ad8c760SFredrik Holmqvist // resize view to accomodate the replicants, redraw as necessary 102341281cf3SAxel Dörfler AdjustPlacement(); 102441281cf3SAxel Dörfler } 102541281cf3SAxel Dörfler } 102641281cf3SAxel Dörfler 102741281cf3SAxel Dörfler 10287da06231SAxel Dörfler /** looking for a replicant by id/index 10297da06231SAxel Dörfler * return the view and index 10307da06231SAxel Dörfler */ 10317da06231SAxel Dörfler 103241281cf3SAxel Dörfler BView* 103341281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, int32 target, bool byIndex) 103441281cf3SAxel Dörfler { 103541281cf3SAxel Dörfler *index = -1; 103641281cf3SAxel Dörfler 103741281cf3SAxel Dörfler BView* view; 103841281cf3SAxel Dörfler if (byIndex) { 103941281cf3SAxel Dörfler if (fShelf->ReplicantAt(target, &view, (uint32*)id)) { 104041281cf3SAxel Dörfler if (view) { 104141281cf3SAxel Dörfler *index = target; 104241281cf3SAxel Dörfler return view; 104341281cf3SAxel Dörfler } 104441281cf3SAxel Dörfler } 104541281cf3SAxel Dörfler } else { 104641281cf3SAxel Dörfler int32 count = fShelf->CountReplicants() - 1; 104741281cf3SAxel Dörfler int32 localid; 104841281cf3SAxel Dörfler for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { 104941281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32*)&localid); 105041281cf3SAxel Dörfler if (localid == target && view) { 105141281cf3SAxel Dörfler *index = repIndex; 105241281cf3SAxel Dörfler *id = localid; 105341281cf3SAxel Dörfler return view; 105441281cf3SAxel Dörfler } 105541281cf3SAxel Dörfler } 105641281cf3SAxel Dörfler } 105741281cf3SAxel Dörfler return NULL; 105841281cf3SAxel Dörfler } 105941281cf3SAxel Dörfler 106041281cf3SAxel Dörfler 10617da06231SAxel Dörfler /** looking for a replicant with a view by name 10627da06231SAxel Dörfler * return the view, index and the id of the replicant 10637da06231SAxel Dörfler */ 10647da06231SAxel Dörfler 106541281cf3SAxel Dörfler BView* 106641281cf3SAxel Dörfler TReplicantTray::ViewAt(int32* index, int32* id, const char* name) 106741281cf3SAxel Dörfler { 106841281cf3SAxel Dörfler *index = -1; 106941281cf3SAxel Dörfler *id = -1; 107041281cf3SAxel Dörfler 107141281cf3SAxel Dörfler BView* view; 107241281cf3SAxel Dörfler int32 count = fShelf->CountReplicants()-1; 107341281cf3SAxel Dörfler for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { 107441281cf3SAxel Dörfler fShelf->ReplicantAt(repIndex, &view, (uint32*)id); 107541281cf3SAxel Dörfler if (view && view->Name() && strcmp(name, view->Name()) == 0) { 107641281cf3SAxel Dörfler *index = repIndex; 107741281cf3SAxel Dörfler return view; 107841281cf3SAxel Dörfler } 107941281cf3SAxel Dörfler } 108041281cf3SAxel Dörfler return NULL; 108141281cf3SAxel Dörfler } 108241281cf3SAxel Dörfler 108341281cf3SAxel Dörfler 10847da06231SAxel Dörfler /** Shelf will call to determine where and if 10857da06231SAxel Dörfler * the replicant is to be added 10867da06231SAxel Dörfler */ 10877da06231SAxel Dörfler 108841281cf3SAxel Dörfler bool 108941281cf3SAxel Dörfler TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage* message) 109041281cf3SAxel Dörfler { 109141281cf3SAxel Dörfler if (!message) 109241281cf3SAxel Dörfler return false; 109341281cf3SAxel Dörfler 109441281cf3SAxel Dörfler if (replicantFrame.Height() > kMaxReplicantHeight) 109541281cf3SAxel Dörfler return false; 109641281cf3SAxel Dörfler 109741281cf3SAxel Dörfler alignment align = B_ALIGN_LEFT; 109841281cf3SAxel Dörfler if (fAlignmentSupport && message->HasBool("deskbar:dynamic_align")) { 109941281cf3SAxel Dörfler if (!fBarView->Vertical()) 110041281cf3SAxel Dörfler align = B_ALIGN_RIGHT; 110141281cf3SAxel Dörfler else 110241281cf3SAxel Dörfler align = fBarView->Left() ? B_ALIGN_LEFT : B_ALIGN_RIGHT; 110341281cf3SAxel Dörfler } else if (message->HasInt32("deskbar:align")) 110441281cf3SAxel Dörfler message->FindInt32("deskbar:align", (int32*)&align); 110541281cf3SAxel Dörfler 110641281cf3SAxel Dörfler if (message->HasInt32("deskbar:private_align")) 110741281cf3SAxel Dörfler message->FindInt32("deskbar:private_align", (int32*)&align); 110841281cf3SAxel Dörfler else 110941281cf3SAxel Dörfler align = B_ALIGN_LEFT; 111041281cf3SAxel Dörfler 11117da06231SAxel Dörfler BPoint loc = LocationForReplicant(fShelf->CountReplicants(), 11127da06231SAxel Dörfler replicantFrame.Width()); 111341281cf3SAxel Dörfler 111441281cf3SAxel Dörfler message->AddPoint("_pjp_loc", loc); 111541281cf3SAxel Dörfler return true; 111641281cf3SAxel Dörfler } 111741281cf3SAxel Dörfler 111841281cf3SAxel Dörfler 111941281cf3SAxel Dörfler /** based on the previous (index - 1) replicant in the list 112041281cf3SAxel Dörfler * calculate where the left point should be for this 112141281cf3SAxel Dörfler * replicant. replicant will flow to the right on its own 112241281cf3SAxel Dörfler */ 112341281cf3SAxel Dörfler 112441281cf3SAxel Dörfler BPoint 11257da06231SAxel Dörfler TReplicantTray::LocationForReplicant(int32 index, float width) 112641281cf3SAxel Dörfler { 112741281cf3SAxel Dörfler BPoint loc(kIconGap + 1, kGutter + 1); 112841281cf3SAxel Dörfler 11297da06231SAxel Dörfler if (fMultiRowMode) { 11307da06231SAxel Dörfler // try to find free space in every row 11317da06231SAxel Dörfler for (int32 row = 0; ; loc.y += kMaxReplicantHeight + kIconGap, row++) { 11327da06231SAxel Dörfler // determine free space in this row 11332ce9bab8SJohn Scipione BRect rect(loc.x, loc.y, loc.x + fMinimumTrayWidth - kIconGap 11342ce9bab8SJohn Scipione - 2.0, loc.y + kMaxReplicantHeight); 1135573f748cSJohn Scipione if (row == 0 && !fTime->IsHidden()) 1136573f748cSJohn Scipione rect.right -= fTime->Frame().Width() + kIconGap; 11377da06231SAxel Dörfler 11387da06231SAxel Dörfler for (int32 i = 0; i < index; i++) { 11397da06231SAxel Dörfler BView* view = NULL; 11407da06231SAxel Dörfler fShelf->ReplicantAt(i, &view); 11417da06231SAxel Dörfler if (view == NULL || view->Frame().top != rect.top) 11427da06231SAxel Dörfler continue; 11437da06231SAxel Dörfler 11447da06231SAxel Dörfler rect.left = view->Frame().right + kIconGap + 1; 11457da06231SAxel Dörfler } 11467da06231SAxel Dörfler 11477da06231SAxel Dörfler if (rect.Width() >= width) { 11487da06231SAxel Dörfler // the icon fits in this row 11497da06231SAxel Dörfler loc = rect.LeftTop(); 11507da06231SAxel Dörfler break; 11517da06231SAxel Dörfler } 11527da06231SAxel Dörfler } 11537da06231SAxel Dörfler } else { 115441281cf3SAxel Dörfler if (index > 0) { 115541281cf3SAxel Dörfler // get the last replicant added for placement reference 115641281cf3SAxel Dörfler BView* view = NULL; 11577da06231SAxel Dörfler fShelf->ReplicantAt(index - 1, &view); 115841281cf3SAxel Dörfler if (view) { 115941281cf3SAxel Dörfler // push this rep placement past the last one 116041281cf3SAxel Dörfler loc.x = view->Frame().right + kIconGap + 1; 116141281cf3SAxel Dörfler loc.y = view->Frame().top; 116241281cf3SAxel Dörfler } 116341281cf3SAxel Dörfler } 11647da06231SAxel Dörfler } 116541281cf3SAxel Dörfler 116671bd3ba5SJonas Sundström if ((loc.y == fRightBottomReplicant.top && loc.x 116771bd3ba5SJonas Sundström > fRightBottomReplicant.left) || loc.y > fRightBottomReplicant.top) { 116871bd3ba5SJonas Sundström fRightBottomReplicant.Set(loc.x, loc.y, loc.x + width, loc.y 116971bd3ba5SJonas Sundström + kMaxReplicantHeight); 11707da06231SAxel Dörfler fLastReplicant = index; 117141281cf3SAxel Dörfler } 11727da06231SAxel Dörfler 117341281cf3SAxel Dörfler return loc; 117441281cf3SAxel Dörfler } 117541281cf3SAxel Dörfler 117641281cf3SAxel Dörfler 117741281cf3SAxel Dörfler BRect 117841281cf3SAxel Dörfler TReplicantTray::IconFrame(int32 target, bool byIndex) 117941281cf3SAxel Dörfler { 118041281cf3SAxel Dörfler int32 index, id; 118141281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, target, byIndex); 118241281cf3SAxel Dörfler if (view) 118341281cf3SAxel Dörfler return view->Frame(); 118441281cf3SAxel Dörfler 118541281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 118641281cf3SAxel Dörfler } 118741281cf3SAxel Dörfler 118841281cf3SAxel Dörfler 118941281cf3SAxel Dörfler BRect 119041281cf3SAxel Dörfler TReplicantTray::IconFrame(const char* name) 119141281cf3SAxel Dörfler { 119241281cf3SAxel Dörfler if (!name) 119341281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 119441281cf3SAxel Dörfler 119541281cf3SAxel Dörfler int32 id, index; 119641281cf3SAxel Dörfler BView* view = ViewAt(&index, &id, name); 119741281cf3SAxel Dörfler if (view) 119841281cf3SAxel Dörfler return view->Frame(); 119941281cf3SAxel Dörfler 120041281cf3SAxel Dörfler return BRect(0, 0, 0, 0); 120141281cf3SAxel Dörfler } 120241281cf3SAxel Dörfler 120341281cf3SAxel Dörfler 12047da06231SAxel Dörfler /** Scan from the startIndex and reset the location 12057da06231SAxel Dörfler * as defined in LocationForReplicant() 120641281cf3SAxel Dörfler */ 120741281cf3SAxel Dörfler 120841281cf3SAxel Dörfler void 120941281cf3SAxel Dörfler TReplicantTray::RealignReplicants(int32 startIndex) 121041281cf3SAxel Dörfler { 121141281cf3SAxel Dörfler if (startIndex < 0) 121241281cf3SAxel Dörfler startIndex = 0; 121341281cf3SAxel Dörfler 121441281cf3SAxel Dörfler int32 count = fShelf->CountReplicants(); 121541281cf3SAxel Dörfler if (count <= 0) 121641281cf3SAxel Dörfler return; 121741281cf3SAxel Dörfler 12187da06231SAxel Dörfler if (startIndex == 0) 12197da06231SAxel Dörfler fRightBottomReplicant.Set(0, 0, 0, 0); 12207da06231SAxel Dörfler 122141281cf3SAxel Dörfler BView* view = NULL; 122241281cf3SAxel Dörfler for (int32 i = startIndex ; i < count ; i++) { 122341281cf3SAxel Dörfler fShelf->ReplicantAt(i, &view); 12240bec7100SStefano Ceccherini if (view != NULL) { 12257da06231SAxel Dörfler BPoint loc = LocationForReplicant(i, view->Frame().Width()); 12260bec7100SStefano Ceccherini if (view->Frame().LeftTop() != loc) 122741281cf3SAxel Dörfler view->MoveTo(loc); 122841281cf3SAxel Dörfler } 122941281cf3SAxel Dörfler } 123041281cf3SAxel Dörfler } 123141281cf3SAxel Dörfler 123241281cf3SAxel Dörfler 12338aab28f1SRene Gollent status_t 12347625ce51SRene Gollent TReplicantTray::_SaveSettings() 12357625ce51SRene Gollent { 12367625ce51SRene Gollent status_t result; 12377625ce51SRene Gollent BPath path; 12387625ce51SRene Gollent if ((result = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true)) 12397625ce51SRene Gollent == B_OK) { 12407625ce51SRene Gollent path.Append(kReplicantSettingsFile); 12417625ce51SRene Gollent 12427625ce51SRene Gollent BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); 12437625ce51SRene Gollent if ((result = file.InitCheck()) == B_OK) 12447625ce51SRene Gollent result = fAddOnSettings.Flatten(&file); 12457625ce51SRene Gollent } 12467625ce51SRene Gollent 12477625ce51SRene Gollent return result; 12487625ce51SRene Gollent } 12497625ce51SRene Gollent 12507625ce51SRene Gollent 1251*3cf2d117SJohn Scipione void 1252*3cf2d117SJohn Scipione TReplicantTray::SaveTimeSettings() 1253*3cf2d117SJohn Scipione { 1254*3cf2d117SJohn Scipione if (fTime == NULL) 1255*3cf2d117SJohn Scipione return; 1256*3cf2d117SJohn Scipione 1257*3cf2d117SJohn Scipione desk_settings* settings = ((TBarApp*)be_app)->Settings(); 1258*3cf2d117SJohn Scipione settings->showTime = !fTime->IsHidden(); 1259*3cf2d117SJohn Scipione settings->showSeconds = fTime->ShowSeconds(); 1260*3cf2d117SJohn Scipione settings->showDayOfWeek = fTime->ShowDayOfWeek(); 1261*3cf2d117SJohn Scipione settings->showTimeZone = fTime->ShowTimeZone(); 1262*3cf2d117SJohn Scipione } 1263*3cf2d117SJohn Scipione 1264*3cf2d117SJohn Scipione 126541281cf3SAxel Dörfler // #pragma mark - 126641281cf3SAxel Dörfler 126741281cf3SAxel Dörfler 1268ca9acc20SAxel Dörfler /*! Draggable region that is asynchronous so that dragging does not block 1269ca9acc20SAxel Dörfler other activities. 12707da06231SAxel Dörfler */ 127141281cf3SAxel Dörfler TDragRegion::TDragRegion(TBarView* parent, BView* child) 1272ca9acc20SAxel Dörfler : 1273ca9acc20SAxel Dörfler BControl(BRect(0, 0, 0, 0), "", "", NULL, B_FOLLOW_NONE, 127441281cf3SAxel Dörfler B_WILL_DRAW | B_FRAME_EVENTS), 127541281cf3SAxel Dörfler fBarView(parent), 127641281cf3SAxel Dörfler fChild(child), 127741281cf3SAxel Dörfler fDragLocation(kAutoPlaceDragRegion) 127841281cf3SAxel Dörfler { 127941281cf3SAxel Dörfler } 128041281cf3SAxel Dörfler 128141281cf3SAxel Dörfler 128241281cf3SAxel Dörfler void 128341281cf3SAxel Dörfler TDragRegion::AttachedToWindow() 128441281cf3SAxel Dörfler { 128541281cf3SAxel Dörfler BView::AttachedToWindow(); 1286cb6afcb1SStephan Aßmus if (be_control_look != NULL) 1287cb6afcb1SStephan Aßmus SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 1.1)); 1288cb6afcb1SStephan Aßmus else 128941281cf3SAxel Dörfler SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); 129041281cf3SAxel Dörfler ResizeToPreferred(); 129141281cf3SAxel Dörfler } 129241281cf3SAxel Dörfler 129341281cf3SAxel Dörfler 129441281cf3SAxel Dörfler void 129541281cf3SAxel Dörfler TDragRegion::GetPreferredSize(float* width, float* height) 129641281cf3SAxel Dörfler { 129741281cf3SAxel Dörfler fChild->ResizeToPreferred(); 129841281cf3SAxel Dörfler *width = fChild->Bounds().Width(); 129941281cf3SAxel Dörfler *height = fChild->Bounds().Height(); 130041281cf3SAxel Dörfler 130141281cf3SAxel Dörfler if (fDragLocation != kNoDragRegion) 130241281cf3SAxel Dörfler *width += 7; 130341281cf3SAxel Dörfler else 130441281cf3SAxel Dörfler *width += 6; 130541281cf3SAxel Dörfler 130641281cf3SAxel Dörfler *height += 3; 130741281cf3SAxel Dörfler } 130841281cf3SAxel Dörfler 130941281cf3SAxel Dörfler 131041281cf3SAxel Dörfler void 131141281cf3SAxel Dörfler TDragRegion::FrameMoved(BPoint) 131241281cf3SAxel Dörfler { 1313ca9acc20SAxel Dörfler if (fBarView->Left() && fBarView->Vertical() 1314ca9acc20SAxel Dörfler && fDragLocation != kNoDragRegion) 131541281cf3SAxel Dörfler fChild->MoveTo(5, 2); 131641281cf3SAxel Dörfler else 131741281cf3SAxel Dörfler fChild->MoveTo(2, 2); 131841281cf3SAxel Dörfler } 131941281cf3SAxel Dörfler 132041281cf3SAxel Dörfler 132141281cf3SAxel Dörfler void 132241281cf3SAxel Dörfler TDragRegion::Draw(BRect) 132341281cf3SAxel Dörfler { 1324eaa9af99SStephan Aßmus rgb_color menuColor = ViewColor(); 132541281cf3SAxel Dörfler rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT); 1326cb6afcb1SStephan Aßmus rgb_color ldark = tint_color(menuColor, 1.02); 1327cb6afcb1SStephan Aßmus rgb_color dark = tint_color(menuColor, B_DARKEN_2_TINT); 132841281cf3SAxel Dörfler rgb_color vvdark = tint_color(menuColor, B_DARKEN_4_TINT); 132941281cf3SAxel Dörfler rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 133041281cf3SAxel Dörfler 133141281cf3SAxel Dörfler BRect frame(Bounds()); 133241281cf3SAxel Dörfler BeginLineArray(4); 133341281cf3SAxel Dörfler 1334cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 1335cb6afcb1SStephan Aßmus if (fBarView->Vertical()) { 1336cb6afcb1SStephan Aßmus AddLine(frame.LeftTop(), frame.RightTop(), dark); 1337cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1338cb6afcb1SStephan Aßmus BPoint(frame.right, frame.top + 1), ldark); 1339cb6afcb1SStephan Aßmus AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 1340cb6afcb1SStephan Aßmus } else if (fBarView->AcrossTop() || fBarView->AcrossBottom()) { 1341cb6afcb1SStephan Aßmus AddLine(frame.LeftTop(), 1342cb6afcb1SStephan Aßmus BPoint(frame.left, frame.bottom), dark); 1343cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left + 1, frame.top + 1), 1344cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 1345cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right, frame.top + 2), 1346cb6afcb1SStephan Aßmus BPoint(frame.right, frame.bottom), hilite); 1347cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left + 1, frame.bottom), 1348cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom), hilite); 1349cb6afcb1SStephan Aßmus } 1350cb6afcb1SStephan Aßmus } else { 135141281cf3SAxel Dörfler if (fBarView->Vertical()) { 135241281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.RightTop(), light); 135341281cf3SAxel Dörfler AddLine(frame.LeftTop(), frame.LeftBottom(), light); 135441281cf3SAxel Dörfler AddLine(frame.RightBottom(), frame.RightTop(), hilite); 135541281cf3SAxel Dörfler } else if (fBarView->AcrossTop()) { 1356cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1357cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 135841281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 1359cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right - 1, frame.top + 2), 1360cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom - 1), hilite); 1361cb6afcb1SStephan Aßmus AddLine(frame.LeftBottom(), 1362cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom), hilite); 136341281cf3SAxel Dörfler } else if (fBarView->AcrossBottom()) { 1364cb6afcb1SStephan Aßmus AddLine(BPoint(frame.left, frame.top + 1), 1365cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.top + 1), light); 136641281cf3SAxel Dörfler AddLine(frame.LeftBottom(), frame.RightBottom(), hilite); 136741281cf3SAxel Dörfler AddLine(frame.RightTop(), frame.RightBottom(), vvdark); 1368cb6afcb1SStephan Aßmus AddLine(BPoint(frame.right - 1, frame.top + 1), 1369cb6afcb1SStephan Aßmus BPoint(frame.right - 1, frame.bottom - 1), hilite); 1370cb6afcb1SStephan Aßmus } 137141281cf3SAxel Dörfler } 137241281cf3SAxel Dörfler 137341281cf3SAxel Dörfler EndLineArray(); 137441281cf3SAxel Dörfler 137541281cf3SAxel Dörfler if (fDragLocation != kDontDrawDragRegion || fDragLocation != kNoDragRegion) 137641281cf3SAxel Dörfler DrawDragRegion(); 137741281cf3SAxel Dörfler } 137841281cf3SAxel Dörfler 137941281cf3SAxel Dörfler 138041281cf3SAxel Dörfler void 138141281cf3SAxel Dörfler TDragRegion::DrawDragRegion() 138241281cf3SAxel Dörfler { 138341281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 138441281cf3SAxel Dörfler 1385cb6afcb1SStephan Aßmus rgb_color menuColor = ViewColor(); 1386cb6afcb1SStephan Aßmus rgb_color menuHilite = menuColor; 138741281cf3SAxel Dörfler if (IsTracking()) { 1388cb6afcb1SStephan Aßmus // Draw drag region highlighted if tracking mouse 1389cb6afcb1SStephan Aßmus menuHilite = tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT); 139041281cf3SAxel Dörfler SetHighColor(menuHilite); 139141281cf3SAxel Dörfler FillRect(dragRegion); 139241281cf3SAxel Dörfler } 1393cb6afcb1SStephan Aßmus rgb_color vdark = tint_color(menuHilite, B_DARKEN_3_TINT); 1394cb6afcb1SStephan Aßmus rgb_color light = tint_color(menuHilite, B_LIGHTEN_2_TINT); 1395cb6afcb1SStephan Aßmus 1396cb6afcb1SStephan Aßmus BeginLineArray(dragRegion.IntegerHeight()); 1397cb6afcb1SStephan Aßmus BPoint pt; 1398cb6afcb1SStephan Aßmus pt.x = floorf((dragRegion.left + dragRegion.right) / 2 + 0.5) - 1; 1399cb6afcb1SStephan Aßmus pt.y = dragRegion.top + 2; 1400cb6afcb1SStephan Aßmus 140141281cf3SAxel Dörfler while (pt.y + 1 <= dragRegion.bottom) { 140241281cf3SAxel Dörfler AddLine(pt, pt, vdark); 140341281cf3SAxel Dörfler AddLine(pt + BPoint(1, 1), pt + BPoint(1, 1), light); 140441281cf3SAxel Dörfler 140541281cf3SAxel Dörfler pt.y += 3; 140641281cf3SAxel Dörfler } 140741281cf3SAxel Dörfler EndLineArray(); 140841281cf3SAxel Dörfler } 140941281cf3SAxel Dörfler 141041281cf3SAxel Dörfler 141141281cf3SAxel Dörfler BRect 141241281cf3SAxel Dörfler TDragRegion::DragRegion() const 141341281cf3SAxel Dörfler { 1414cb6afcb1SStephan Aßmus float kTopBottomInset = 2; 1415cb6afcb1SStephan Aßmus float kLeftRightInset = 1; 1416cb6afcb1SStephan Aßmus float kDragWidth = 3; 1417cb6afcb1SStephan Aßmus if (be_control_look != NULL) { 1418cb6afcb1SStephan Aßmus kTopBottomInset = 1; 1419cb6afcb1SStephan Aßmus kLeftRightInset = 0; 1420cb6afcb1SStephan Aßmus kDragWidth = 4; 1421cb6afcb1SStephan Aßmus } 1422cb6afcb1SStephan Aßmus 142341281cf3SAxel Dörfler BRect dragRegion(Bounds()); 1424cb6afcb1SStephan Aßmus dragRegion.top += kTopBottomInset; 1425cb6afcb1SStephan Aßmus dragRegion.bottom -= kTopBottomInset; 142641281cf3SAxel Dörfler 142741281cf3SAxel Dörfler bool placeOnLeft = false; 142841281cf3SAxel Dörfler if (fDragLocation == kAutoPlaceDragRegion) { 142941281cf3SAxel Dörfler if (fBarView->Vertical() && fBarView->Left()) 143041281cf3SAxel Dörfler placeOnLeft = true; 143141281cf3SAxel Dörfler else 143241281cf3SAxel Dörfler placeOnLeft = false; 143341281cf3SAxel Dörfler } else if (fDragLocation == kDragRegionLeft) 143441281cf3SAxel Dörfler placeOnLeft = true; 143541281cf3SAxel Dörfler else if (fDragLocation == kDragRegionRight) 143641281cf3SAxel Dörfler placeOnLeft = false; 143741281cf3SAxel Dörfler 143841281cf3SAxel Dörfler if (placeOnLeft) { 1439cb6afcb1SStephan Aßmus dragRegion.left += kLeftRightInset; 1440cb6afcb1SStephan Aßmus dragRegion.right = dragRegion.left + kDragWidth; 144141281cf3SAxel Dörfler } else { 1442cb6afcb1SStephan Aßmus dragRegion.right -= kLeftRightInset; 1443cb6afcb1SStephan Aßmus dragRegion.left = dragRegion.right - kDragWidth; 144441281cf3SAxel Dörfler } 144541281cf3SAxel Dörfler 144641281cf3SAxel Dörfler return dragRegion; 144741281cf3SAxel Dörfler } 144841281cf3SAxel Dörfler 144941281cf3SAxel Dörfler 145041281cf3SAxel Dörfler void 145141281cf3SAxel Dörfler TDragRegion::MouseDown(BPoint thePoint) 145241281cf3SAxel Dörfler { 145341281cf3SAxel Dörfler ulong buttons; 145441281cf3SAxel Dörfler BPoint where; 145541281cf3SAxel Dörfler BRect dragRegion(DragRegion()); 145641281cf3SAxel Dörfler 14577da06231SAxel Dörfler dragRegion.InsetBy(-2.0f, -2.0f); 14587da06231SAxel Dörfler // DragRegion() is designed for drawing, not clicking 145941281cf3SAxel Dörfler 146041281cf3SAxel Dörfler if (!dragRegion.Contains(thePoint)) 146141281cf3SAxel Dörfler return; 146241281cf3SAxel Dörfler 146341281cf3SAxel Dörfler while (true) { 146441281cf3SAxel Dörfler GetMouse(&where, &buttons); 146541281cf3SAxel Dörfler if (!buttons) 146641281cf3SAxel Dörfler break; 146741281cf3SAxel Dörfler 146841281cf3SAxel Dörfler if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) != 0) { 146941281cf3SAxel Dörfler fPreviousPosition = thePoint; 147041281cf3SAxel Dörfler SetTracking(true); 147141281cf3SAxel Dörfler SetMouseEventMask(B_POINTER_EVENTS, 147241281cf3SAxel Dörfler B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); 147341281cf3SAxel Dörfler Invalidate(DragRegion()); 147441281cf3SAxel Dörfler break; 147541281cf3SAxel Dörfler } 147641281cf3SAxel Dörfler 147741281cf3SAxel Dörfler snooze(25000); 147841281cf3SAxel Dörfler } 147941281cf3SAxel Dörfler } 148041281cf3SAxel Dörfler 148141281cf3SAxel Dörfler 148241281cf3SAxel Dörfler void 148341281cf3SAxel Dörfler TDragRegion::MouseUp(BPoint pt) 148441281cf3SAxel Dörfler { 148541281cf3SAxel Dörfler if (IsTracking()) { 148641281cf3SAxel Dörfler SetTracking(false); 148741281cf3SAxel Dörfler Invalidate(DragRegion()); 148841281cf3SAxel Dörfler } else 148941281cf3SAxel Dörfler BControl::MouseUp(pt); 149041281cf3SAxel Dörfler } 149141281cf3SAxel Dörfler 149241281cf3SAxel Dörfler 149341281cf3SAxel Dörfler bool 149441281cf3SAxel Dörfler TDragRegion::SwitchModeForRect(BPoint mouse, BRect rect, 149541281cf3SAxel Dörfler bool newVertical, bool newLeft, bool newTop, int32 newState) 149641281cf3SAxel Dörfler { 14971ad8c760SFredrik Holmqvist if (!rect.Contains(mouse)) { 149841281cf3SAxel Dörfler // not our rect 149941281cf3SAxel Dörfler return false; 15001ad8c760SFredrik Holmqvist } 150141281cf3SAxel Dörfler 15021ad8c760SFredrik Holmqvist if (newVertical == fBarView->Vertical() && newLeft == fBarView->Left() 15031ad8c760SFredrik Holmqvist && newTop == fBarView->Top() && newState == fBarView->State()) { 150441281cf3SAxel Dörfler // already in the correct mode 150541281cf3SAxel Dörfler return true; 15061ad8c760SFredrik Holmqvist } 150741281cf3SAxel Dörfler 150841281cf3SAxel Dörfler fBarView->ChangeState(newState, newVertical, newLeft, newTop); 150941281cf3SAxel Dörfler return true; 151041281cf3SAxel Dörfler } 151141281cf3SAxel Dörfler 151241281cf3SAxel Dörfler 151341281cf3SAxel Dörfler void 151441281cf3SAxel Dörfler TDragRegion::MouseMoved(BPoint where, uint32 code, const BMessage* message) 151541281cf3SAxel Dörfler { 151641281cf3SAxel Dörfler if (IsTracking()) { 151741281cf3SAxel Dörfler BScreen screen; 151841281cf3SAxel Dörfler BRect frame = screen.Frame(); 151941281cf3SAxel Dörfler 152041281cf3SAxel Dörfler float hDivider = frame.Width() / 6; 152171bd3ba5SJonas Sundström hDivider = (hDivider < sMinimumWindowWidth + 10.0f) 152271bd3ba5SJonas Sundström ? sMinimumWindowWidth + 10.0f : hDivider; 152341281cf3SAxel Dörfler float miniDivider = frame.top + kMiniHeight + 10.0f; 152441281cf3SAxel Dörfler float vDivider = frame.Height() / 2; 152541281cf3SAxel Dörfler #ifdef FULL_MODE 152641281cf3SAxel Dörfler float thirdScreen = frame.Height() / 3; 152741281cf3SAxel Dörfler #endif 152871bd3ba5SJonas Sundström BRect topLeft(frame.left, frame.top, frame.left + hDivider, 152971bd3ba5SJonas Sundström miniDivider); 153071bd3ba5SJonas Sundström BRect topMiddle(frame.left + hDivider, frame.top, frame.right 153171bd3ba5SJonas Sundström - hDivider, vDivider); 153271bd3ba5SJonas Sundström BRect topRight(frame.right - hDivider, frame.top, frame.right, 153371bd3ba5SJonas Sundström miniDivider); 153441281cf3SAxel Dörfler 153541281cf3SAxel Dörfler #ifdef FULL_MODE 153641281cf3SAxel Dörfler vDivider = miniDivider + thirdScreen; 153741281cf3SAxel Dörfler #endif 153871bd3ba5SJonas Sundström BRect middleLeft(frame.left, miniDivider, frame.left + hDivider, 153971bd3ba5SJonas Sundström vDivider); 154071bd3ba5SJonas Sundström BRect middleRight(frame.right - hDivider, miniDivider, frame.right, 154171bd3ba5SJonas Sundström vDivider); 154241281cf3SAxel Dörfler 154341281cf3SAxel Dörfler #ifdef FULL_MODE 154471bd3ba5SJonas Sundström BRect leftSide(frame.left, vDivider, frame.left + hDivider, 154571bd3ba5SJonas Sundström frame.bottom - thirdScreen); 154671bd3ba5SJonas Sundström BRect rightSide(frame.right - hDivider, vDivider, frame.right, 154771bd3ba5SJonas Sundström frame.bottom - thirdScreen); 154841281cf3SAxel Dörfler 154941281cf3SAxel Dörfler vDivider = frame.bottom - thirdScreen; 155041281cf3SAxel Dörfler #endif 155171bd3ba5SJonas Sundström BRect bottomLeft(frame.left, vDivider, frame.left + hDivider, 155271bd3ba5SJonas Sundström frame.bottom); 155371bd3ba5SJonas Sundström BRect bottomMiddle(frame.left + hDivider, vDivider, frame.right 155471bd3ba5SJonas Sundström - hDivider, frame.bottom); 155571bd3ba5SJonas Sundström BRect bottomRight(frame.right - hDivider, vDivider, frame.right, 155671bd3ba5SJonas Sundström frame.bottom); 155741281cf3SAxel Dörfler 155841281cf3SAxel Dörfler if (where != fPreviousPosition) { 155941281cf3SAxel Dörfler fPreviousPosition = where; 156041281cf3SAxel Dörfler ConvertToScreen(&where); 156141281cf3SAxel Dörfler 156241281cf3SAxel Dörfler // use short circuit evaluation for convenience 156341281cf3SAxel Dörfler if (SwitchModeForRect(where, topLeft, true, true, true, kMiniState) 156471bd3ba5SJonas Sundström || SwitchModeForRect(where, topMiddle, false, true, true, 156571bd3ba5SJonas Sundström kExpandoState) 156671bd3ba5SJonas Sundström || SwitchModeForRect(where, topRight, true, false, true, 156771bd3ba5SJonas Sundström kMiniState) 156871bd3ba5SJonas Sundström || SwitchModeForRect(where, middleLeft, true, true, true, 156971bd3ba5SJonas Sundström kExpandoState) 157071bd3ba5SJonas Sundström || SwitchModeForRect(where, middleRight, true, false, true, 157171bd3ba5SJonas Sundström kExpandoState) 157241281cf3SAxel Dörfler 157341281cf3SAxel Dörfler #ifdef FULL_MODE 157471bd3ba5SJonas Sundström || SwitchModeForRect(where, leftSide, true, true, true, 157571bd3ba5SJonas Sundström kFullState) 157671bd3ba5SJonas Sundström || SwitchModeForRect(where, rightSide, true, false, true, 157771bd3ba5SJonas Sundström kFullState) 157841281cf3SAxel Dörfler #endif 157971bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomLeft, true, true, false, 158071bd3ba5SJonas Sundström kMiniState) 158171bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomMiddle, false, true, false, 158271bd3ba5SJonas Sundström kExpandoState) 158371bd3ba5SJonas Sundström || SwitchModeForRect(where, bottomRight, true, false, false, 158471bd3ba5SJonas Sundström kMiniState)) 158541281cf3SAxel Dörfler ; 158641281cf3SAxel Dörfler } 158741281cf3SAxel Dörfler } else 158841281cf3SAxel Dörfler BControl::MouseMoved(where, code, message); 158941281cf3SAxel Dörfler } 159041281cf3SAxel Dörfler 159141281cf3SAxel Dörfler 159241281cf3SAxel Dörfler int32 159341281cf3SAxel Dörfler TDragRegion::DragRegionLocation() const 159441281cf3SAxel Dörfler { 159541281cf3SAxel Dörfler return fDragLocation; 159641281cf3SAxel Dörfler } 159741281cf3SAxel Dörfler 159841281cf3SAxel Dörfler 159941281cf3SAxel Dörfler void 160041281cf3SAxel Dörfler TDragRegion::SetDragRegionLocation(int32 location) 160141281cf3SAxel Dörfler { 160241281cf3SAxel Dörfler if (location == fDragLocation) 160341281cf3SAxel Dörfler return; 160441281cf3SAxel Dörfler 160541281cf3SAxel Dörfler fDragLocation = location; 160641281cf3SAxel Dörfler Invalidate(); 160741281cf3SAxel Dörfler } 160841281cf3SAxel Dörfler 1609