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 291075cc34SFredrik Holmqvist Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered 301075cc34SFredrik Holmqvist trademarks of Be Incorporated in the United States and other countries. Other 311075cc34SFredrik Holmqvist brand product names are registered trademarks or trademarks of their respective 321075cc34SFredrik Holmqvist holders. 3341281cf3SAxel Dörfler All rights reserved. 3441281cf3SAxel Dörfler */ 3541281cf3SAxel Dörfler 365b576468SAxel Dörfler 375b576468SAxel Dörfler #include "BarWindow.h" 385b576468SAxel Dörfler 3941281cf3SAxel Dörfler #include <stdio.h> 405b576468SAxel Dörfler 4141281cf3SAxel Dörfler #include <Application.h> 420fc30d89SDario Casalinuovo #include <AutoDeleter.h> 433cf2d117SJohn Scipione #include <Catalog.h> 4441281cf3SAxel Dörfler #include <Directory.h> 4541281cf3SAxel Dörfler #include <FindDirectory.h> 4641281cf3SAxel Dörfler #include <Path.h> 4741281cf3SAxel Dörfler #include <Debug.h> 4841281cf3SAxel Dörfler #include <File.h> 49cd7548f5SJonas Sundström #include <Locale.h> 5041281cf3SAxel Dörfler #include <MenuItem.h> 5141281cf3SAxel Dörfler #include <MessageFilter.h> 521cd61330SJohn Scipione #include <MessagePrivate.h> 5341281cf3SAxel Dörfler #include <Screen.h> 5441281cf3SAxel Dörfler 555fd3bc6dSAxel Dörfler #include <DeskbarPrivate.h> 565fd3bc6dSAxel Dörfler #include <tracker_private.h> 575fd3bc6dSAxel Dörfler 5841281cf3SAxel Dörfler #include "BarApp.h" 5941281cf3SAxel Dörfler #include "BarMenuBar.h" 6041281cf3SAxel Dörfler #include "BarView.h" 6126ea7066SIngo Weinhold #include "DeskbarUtils.h" 62323b6546SOliver Tappe #include "DeskbarMenu.h" 631bb2e623SJohn Scipione #include "ExpandoMenuBar.h" 6441281cf3SAxel Dörfler #include "StatusView.h" 6541281cf3SAxel Dörfler 6641281cf3SAxel Dörfler 67546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT 68546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "MainWindow" 69cd7548f5SJonas Sundström 70cd7548f5SJonas Sundström 7174c38cabSAugustin Cavalier // This is a bit of a hack to be able to call BMenuBar::StartMenuBar(), which 7274c38cabSAugustin Cavalier // is private. Don't do this at home! 7374c38cabSAugustin Cavalier class TStartableMenuBar : public BMenuBar { 7474c38cabSAugustin Cavalier public: 75ceec04eaSAugustin Cavalier TStartableMenuBar(); 7674c38cabSAugustin Cavalier void StartMenuBar(int32 menuIndex, bool sticky = true, bool showMenu = false, 7774c38cabSAugustin Cavalier BRect* special_rect = NULL) { BMenuBar::StartMenuBar(menuIndex, sticky, showMenu, 7874c38cabSAugustin Cavalier special_rect); } 7974c38cabSAugustin Cavalier }; 8041281cf3SAxel Dörfler 8141281cf3SAxel Dörfler 82323b6546SOliver Tappe TDeskbarMenu* TBarWindow::sDeskbarMenu = NULL; 8341281cf3SAxel Dörfler 8441281cf3SAxel Dörfler 8541281cf3SAxel Dörfler TBarWindow::TBarWindow() 8672f5ac30SAxel Dörfler : 87066522e8SJonas Sundström BWindow(BRect(-1000.0f, -1000.0f, -1000.0f, -1000.0f), 88560ff447SJonas Sundström B_TRANSLATE_SYSTEM_NAME("Deskbar"), B_BORDERED_WINDOW, 8941281cf3SAxel Dörfler B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_CLOSABLE 901bb2e623SJohn Scipione | B_NOT_MINIMIZABLE | B_NOT_MOVABLE | B_NOT_V_RESIZABLE 9174c7ad20SIngo Weinhold | B_AVOID_FRONT | B_ASYNCHRONOUS_CONTROLS, 9222812ba2SRene Gollent B_ALL_WORKSPACES), 9374ceffa8SJohn Scipione fBarApp(static_cast<TBarApp*>(be_app)), 9474ceffa8SJohn Scipione fBarView(NULL), 9574ceffa8SJohn Scipione fMenusShown(0) 9641281cf3SAxel Dörfler { 9774ceffa8SJohn Scipione desk_settings* settings = fBarApp->Settings(); 9841281cf3SAxel Dörfler if (settings->alwaysOnTop) 9941281cf3SAxel Dörfler SetFeel(B_FLOATING_ALL_WINDOW_FEEL); 100fe624b39SJohn Scipione 10172f5ac30SAxel Dörfler fBarView = new TBarView(Bounds(), settings->vertical, settings->left, 102573f748cSJohn Scipione settings->top, settings->state, settings->width); 10341281cf3SAxel Dörfler AddChild(fBarView); 10441281cf3SAxel Dörfler 10535c6651cSKarsten Heimrich RemoveShortcut('H', B_COMMAND_KEY | B_CONTROL_KEY); 10641281cf3SAxel Dörfler AddShortcut('F', B_COMMAND_KEY, new BMessage(kFindButton)); 1077e27cd8eSJohn Scipione 1087e27cd8eSJohn Scipione SetSizeLimits(); 10941281cf3SAxel Dörfler } 11041281cf3SAxel Dörfler 11141281cf3SAxel Dörfler 11241281cf3SAxel Dörfler void 11341281cf3SAxel Dörfler TBarWindow::MenusBeginning() 11441281cf3SAxel Dörfler { 11541281cf3SAxel Dörfler BPath path; 11641281cf3SAxel Dörfler entry_ref ref; 11726ea7066SIngo Weinhold BEntry entry; 11841281cf3SAxel Dörfler 11926ea7066SIngo Weinhold if (GetDeskbarSettingsDirectory(path) == B_OK 12026ea7066SIngo Weinhold && path.Append(kDeskbarMenuEntriesFileName) == B_OK 12126ea7066SIngo Weinhold && entry.SetTo(path.Path(), true) == B_OK 12226ea7066SIngo Weinhold && entry.Exists() 12326ea7066SIngo Weinhold && entry.GetRef(&ref) == B_OK) { 124323b6546SOliver Tappe sDeskbarMenu->SetNavDir(&ref); 12526ea7066SIngo Weinhold } else if (GetDeskbarDataDirectory(path) == B_OK 12626ea7066SIngo Weinhold && path.Append(kDeskbarMenuEntriesFileName) == B_OK 12726ea7066SIngo Weinhold && entry.SetTo(path.Path(), true) == B_OK 12826ea7066SIngo Weinhold && entry.Exists() 12926ea7066SIngo Weinhold && entry.GetRef(&ref) == B_OK) { 130323b6546SOliver Tappe sDeskbarMenu->SetNavDir(&ref); 13141281cf3SAxel Dörfler } else { 13241281cf3SAxel Dörfler // this really should never happen 13341281cf3SAxel Dörfler TRESPASS(); 13441281cf3SAxel Dörfler return; 13541281cf3SAxel Dörfler } 13641281cf3SAxel Dörfler 13774ceffa8SJohn Scipione // raise Deskbar on menu open in auto-raise mode unless always-on-top 13874ceffa8SJohn Scipione desk_settings* settings = fBarApp->Settings(); 13974ceffa8SJohn Scipione bool alwaysOnTop = settings->alwaysOnTop; 14074ceffa8SJohn Scipione bool autoRaise = settings->autoRaise; 14174ceffa8SJohn Scipione if (!alwaysOnTop && autoRaise) 14274ceffa8SJohn Scipione fBarView->RaiseDeskbar(true); 14374ceffa8SJohn Scipione 144323b6546SOliver Tappe sDeskbarMenu->ResetTargets(); 14541281cf3SAxel Dörfler 14674ceffa8SJohn Scipione fMenusShown++; 14741281cf3SAxel Dörfler BWindow::MenusBeginning(); 14841281cf3SAxel Dörfler } 14941281cf3SAxel Dörfler 15041281cf3SAxel Dörfler 15141281cf3SAxel Dörfler void 15241281cf3SAxel Dörfler TBarWindow::MenusEnded() 15341281cf3SAxel Dörfler { 15474ceffa8SJohn Scipione fMenusShown--; 15541281cf3SAxel Dörfler BWindow::MenusEnded(); 15641281cf3SAxel Dörfler 15774ceffa8SJohn Scipione // lower Deskbar back down again on menu close in auto-raise mode 15874ceffa8SJohn Scipione // unless another menu is open or always-on-top. 15974ceffa8SJohn Scipione desk_settings* settings = fBarApp->Settings(); 16074ceffa8SJohn Scipione bool alwaysOnTop = settings->alwaysOnTop; 16174ceffa8SJohn Scipione bool autoRaise = settings->autoRaise; 16274ceffa8SJohn Scipione if (!alwaysOnTop && autoRaise && fMenusShown <= 0) 16374ceffa8SJohn Scipione fBarView->RaiseDeskbar(false); 16474ceffa8SJohn Scipione 165323b6546SOliver Tappe if (sDeskbarMenu->LockLooper()) { 16685529c12SJessica Hamilton sDeskbarMenu->ForceRebuild(); 167323b6546SOliver Tappe sDeskbarMenu->UnlockLooper(); 16841281cf3SAxel Dörfler } 1694446e07aSStefano Ceccherini } 17041281cf3SAxel Dörfler 17141281cf3SAxel Dörfler 17241281cf3SAxel Dörfler void 17341281cf3SAxel Dörfler TBarWindow::MessageReceived(BMessage* message) 17441281cf3SAxel Dörfler { 17541281cf3SAxel Dörfler switch (message->what) { 17641281cf3SAxel Dörfler case kFindButton: 17741281cf3SAxel Dörfler { 17841281cf3SAxel Dörfler BMessenger tracker(kTrackerSignature); 17941281cf3SAxel Dörfler tracker.SendMessage(message); 18041281cf3SAxel Dörfler break; 18141281cf3SAxel Dörfler } 18241281cf3SAxel Dörfler 183fc23c097SJohn Scipione case kMsgLocation: 18441281cf3SAxel Dörfler GetLocation(message); 18541281cf3SAxel Dörfler break; 18641281cf3SAxel Dörfler 187fc23c097SJohn Scipione case kMsgSetLocation: 18841281cf3SAxel Dörfler SetLocation(message); 18941281cf3SAxel Dörfler break; 19041281cf3SAxel Dörfler 191fc23c097SJohn Scipione case kMsgIsExpanded: 19241281cf3SAxel Dörfler IsExpanded(message); 19341281cf3SAxel Dörfler break; 19441281cf3SAxel Dörfler 195fc23c097SJohn Scipione case kMsgExpand: 19641281cf3SAxel Dörfler Expand(message); 19741281cf3SAxel Dörfler break; 19841281cf3SAxel Dörfler 199fc23c097SJohn Scipione case kMsgGetItemInfo: 20041281cf3SAxel Dörfler ItemInfo(message); 20141281cf3SAxel Dörfler break; 20241281cf3SAxel Dörfler 203fc23c097SJohn Scipione case kMsgHasItem: 20441281cf3SAxel Dörfler ItemExists(message); 20541281cf3SAxel Dörfler break; 20641281cf3SAxel Dörfler 207fc23c097SJohn Scipione case kMsgCountItems: 20841281cf3SAxel Dörfler CountItems(message); 20941281cf3SAxel Dörfler break; 21041281cf3SAxel Dörfler 211efafab64SAxel Dörfler case kMsgMaxItemSize: 212efafab64SAxel Dörfler MaxItemSize(message); 213efafab64SAxel Dörfler break; 214efafab64SAxel Dörfler 215fc23c097SJohn Scipione case kMsgAddAddOn: 216fc23c097SJohn Scipione case kMsgAddView: 21741281cf3SAxel Dörfler AddItem(message); 21841281cf3SAxel Dörfler break; 21941281cf3SAxel Dörfler 220fc23c097SJohn Scipione case kMsgRemoveItem: 22141281cf3SAxel Dörfler RemoveItem(message); 22241281cf3SAxel Dörfler break; 22341281cf3SAxel Dörfler 22441281cf3SAxel Dörfler case 'iloc': 22541281cf3SAxel Dörfler GetIconFrame(message); 22641281cf3SAxel Dörfler break; 22741281cf3SAxel Dörfler 22841281cf3SAxel Dörfler default: 22941281cf3SAxel Dörfler BWindow::MessageReceived(message); 23041281cf3SAxel Dörfler break; 23141281cf3SAxel Dörfler } 23241281cf3SAxel Dörfler } 23341281cf3SAxel Dörfler 23441281cf3SAxel Dörfler 23541281cf3SAxel Dörfler void 2365b576468SAxel Dörfler TBarWindow::Minimize(bool minimize) 2375b576468SAxel Dörfler { 2385b576468SAxel Dörfler // Don't allow the Deskbar to be minimized 2395b576468SAxel Dörfler if (!minimize) 2405b576468SAxel Dörfler BWindow::Minimize(false); 2415b576468SAxel Dörfler } 2425b576468SAxel Dörfler 2435b576468SAxel Dörfler 2445b576468SAxel Dörfler void 2451bb2e623SJohn Scipione TBarWindow::FrameResized(float width, float height) 2461bb2e623SJohn Scipione { 247*0d2645e4SJohn Scipione if (fBarView->MiniState() || !fBarView->Vertical()) 2481bb2e623SJohn Scipione return BWindow::FrameResized(width, height); 2491bb2e623SJohn Scipione 25074ceffa8SJohn Scipione bool setToHiddenSize = fBarApp->Settings()->autoHide 2511bb2e623SJohn Scipione && fBarView->IsHidden() && !fBarView->DragRegion()->IsDragging(); 2521bb2e623SJohn Scipione if (!setToHiddenSize) { 2531bb2e623SJohn Scipione // constrain within limits 2541bb2e623SJohn Scipione float newWidth; 2551bb2e623SJohn Scipione if (width < gMinimumWindowWidth) 2561bb2e623SJohn Scipione newWidth = gMinimumWindowWidth; 2571bb2e623SJohn Scipione else if (width > gMaximumWindowWidth) 2581bb2e623SJohn Scipione newWidth = gMaximumWindowWidth; 2591bb2e623SJohn Scipione else 2601bb2e623SJohn Scipione newWidth = width; 2611bb2e623SJohn Scipione 26274ceffa8SJohn Scipione float oldWidth = fBarApp->Settings()->width; 263938fd26fSJohn Scipione 2641bb2e623SJohn Scipione // update width setting 26574ceffa8SJohn Scipione fBarApp->Settings()->width = newWidth; 2661bb2e623SJohn Scipione 267938fd26fSJohn Scipione if (oldWidth != newWidth) { 2681bb2e623SJohn Scipione fBarView->ResizeTo(width, fBarView->Bounds().Height()); 269*0d2645e4SJohn Scipione if (fBarView->Vertical() && fBarView->ExpandoMenuBar() != NULL) 2701bb2e623SJohn Scipione fBarView->ExpandoMenuBar()->SetMaxContentWidth(width); 2711bb2e623SJohn Scipione 272938fd26fSJohn Scipione fBarView->UpdatePlacement(); 273938fd26fSJohn Scipione } 2741bb2e623SJohn Scipione } 2751bb2e623SJohn Scipione } 2761bb2e623SJohn Scipione 2771bb2e623SJohn Scipione 2781bb2e623SJohn Scipione void 27941281cf3SAxel Dörfler TBarWindow::SaveSettings() 28041281cf3SAxel Dörfler { 28141281cf3SAxel Dörfler fBarView->SaveSettings(); 28241281cf3SAxel Dörfler } 28341281cf3SAxel Dörfler 28441281cf3SAxel Dörfler 28541281cf3SAxel Dörfler bool 28641281cf3SAxel Dörfler TBarWindow::QuitRequested() 28741281cf3SAxel Dörfler { 28841281cf3SAxel Dörfler be_app->PostMessage(B_QUIT_REQUESTED); 28941281cf3SAxel Dörfler 29041281cf3SAxel Dörfler return BWindow::QuitRequested(); 29141281cf3SAxel Dörfler } 29241281cf3SAxel Dörfler 29341281cf3SAxel Dörfler 29441281cf3SAxel Dörfler void 29541281cf3SAxel Dörfler TBarWindow::WorkspaceActivated(int32 workspace, bool active) 29641281cf3SAxel Dörfler { 29741281cf3SAxel Dörfler BWindow::WorkspaceActivated(workspace, active); 29841281cf3SAxel Dörfler 299d0a49328SJohn Scipione if (active && !(fBarView->ExpandoState() && fBarView->Vertical())) 30041281cf3SAxel Dörfler fBarView->UpdatePlacement(); 30141281cf3SAxel Dörfler else { 30241281cf3SAxel Dörfler BRect screenFrame = (BScreen(fBarView->Window())).Frame(); 30341281cf3SAxel Dörfler fBarView->SizeWindow(screenFrame); 30441281cf3SAxel Dörfler fBarView->PositionWindow(screenFrame); 30541281cf3SAxel Dörfler fBarView->Invalidate(); 30641281cf3SAxel Dörfler } 30741281cf3SAxel Dörfler } 30841281cf3SAxel Dörfler 30941281cf3SAxel Dörfler 31041281cf3SAxel Dörfler void 31141281cf3SAxel Dörfler TBarWindow::ScreenChanged(BRect size, color_space depth) 31241281cf3SAxel Dörfler { 31341281cf3SAxel Dörfler BWindow::ScreenChanged(size, depth); 31441281cf3SAxel Dörfler 3157e27cd8eSJohn Scipione SetSizeLimits(); 316*0d2645e4SJohn Scipione 317*0d2645e4SJohn Scipione if (fBarView != NULL) { 318*0d2645e4SJohn Scipione fBarView->DragRegion()->CalculateRegions(); 319*0d2645e4SJohn Scipione fBarView->UpdatePlacement(); 320*0d2645e4SJohn Scipione } 32141281cf3SAxel Dörfler } 32241281cf3SAxel Dörfler 32341281cf3SAxel Dörfler 32441281cf3SAxel Dörfler void 325323b6546SOliver Tappe TBarWindow::SetDeskbarMenu(TDeskbarMenu* menu) 32641281cf3SAxel Dörfler { 327323b6546SOliver Tappe sDeskbarMenu = menu; 32841281cf3SAxel Dörfler } 32941281cf3SAxel Dörfler 33041281cf3SAxel Dörfler 331323b6546SOliver Tappe TDeskbarMenu* 332323b6546SOliver Tappe TBarWindow::DeskbarMenu() 33341281cf3SAxel Dörfler { 334323b6546SOliver Tappe return sDeskbarMenu; 33541281cf3SAxel Dörfler } 33641281cf3SAxel Dörfler 33741281cf3SAxel Dörfler 33841281cf3SAxel Dörfler void 339323b6546SOliver Tappe TBarWindow::ShowDeskbarMenu() 34041281cf3SAxel Dörfler { 34174c38cabSAugustin Cavalier TStartableMenuBar* menuBar = (TStartableMenuBar*)fBarView->BarMenuBar(); 34241281cf3SAxel Dörfler if (menuBar == NULL) 34374c38cabSAugustin Cavalier menuBar = (TStartableMenuBar*)KeyMenuBar(); 34441281cf3SAxel Dörfler 34541281cf3SAxel Dörfler if (menuBar == NULL) 34641281cf3SAxel Dörfler return; 34741281cf3SAxel Dörfler 34874c38cabSAugustin Cavalier menuBar->StartMenuBar(0, true, true, NULL); 34941281cf3SAxel Dörfler } 35041281cf3SAxel Dörfler 35141281cf3SAxel Dörfler 35241281cf3SAxel Dörfler void 35341281cf3SAxel Dörfler TBarWindow::ShowTeamMenu() 35441281cf3SAxel Dörfler { 35541281cf3SAxel Dörfler int32 index = 0; 35641281cf3SAxel Dörfler if (fBarView->BarMenuBar() == NULL) 35741281cf3SAxel Dörfler index = 2; 35841281cf3SAxel Dörfler 35941281cf3SAxel Dörfler if (KeyMenuBar() == NULL) 36041281cf3SAxel Dörfler return; 36141281cf3SAxel Dörfler 36274c38cabSAugustin Cavalier ((TStartableMenuBar*)KeyMenuBar())->StartMenuBar(index, true, true, NULL); 36341281cf3SAxel Dörfler } 36441281cf3SAxel Dörfler 36541281cf3SAxel Dörfler 3661075cc34SFredrik Holmqvist // determines the actual location of the window 36741281cf3SAxel Dörfler 36841281cf3SAxel Dörfler deskbar_location 36941281cf3SAxel Dörfler TBarWindow::DeskbarLocation() const 37041281cf3SAxel Dörfler { 37141281cf3SAxel Dörfler bool left = fBarView->Left(); 37241281cf3SAxel Dörfler bool top = fBarView->Top(); 37341281cf3SAxel Dörfler 37441281cf3SAxel Dörfler if (fBarView->AcrossTop()) 37541281cf3SAxel Dörfler return B_DESKBAR_TOP; 37641281cf3SAxel Dörfler 37741281cf3SAxel Dörfler if (fBarView->AcrossBottom()) 37841281cf3SAxel Dörfler return B_DESKBAR_BOTTOM; 37941281cf3SAxel Dörfler 38041281cf3SAxel Dörfler if (left && top) 38141281cf3SAxel Dörfler return B_DESKBAR_LEFT_TOP; 38241281cf3SAxel Dörfler 38341281cf3SAxel Dörfler if (!left && top) 38441281cf3SAxel Dörfler return B_DESKBAR_RIGHT_TOP; 38541281cf3SAxel Dörfler 38641281cf3SAxel Dörfler if (left && !top) 38741281cf3SAxel Dörfler return B_DESKBAR_LEFT_BOTTOM; 38841281cf3SAxel Dörfler 38941281cf3SAxel Dörfler return B_DESKBAR_RIGHT_BOTTOM; 39041281cf3SAxel Dörfler } 39141281cf3SAxel Dörfler 39241281cf3SAxel Dörfler 39341281cf3SAxel Dörfler void 39441281cf3SAxel Dörfler TBarWindow::GetLocation(BMessage* message) 39541281cf3SAxel Dörfler { 39641281cf3SAxel Dörfler BMessage reply('rply'); 39741281cf3SAxel Dörfler reply.AddInt32("location", (int32)DeskbarLocation()); 398d0a49328SJohn Scipione reply.AddBool("expanded", fBarView->ExpandoState()); 39941281cf3SAxel Dörfler 40041281cf3SAxel Dörfler message->SendReply(&reply); 40141281cf3SAxel Dörfler } 40241281cf3SAxel Dörfler 40341281cf3SAxel Dörfler 40441281cf3SAxel Dörfler void 40541281cf3SAxel Dörfler TBarWindow::SetDeskbarLocation(deskbar_location location, bool newExpandState) 40641281cf3SAxel Dörfler { 40741281cf3SAxel Dörfler // left top and right top are the only two that 40841281cf3SAxel Dörfler // currently pay attention to expand, ignore for all others 40941281cf3SAxel Dörfler 41041281cf3SAxel Dörfler bool left = false, top = true, vertical, expand; 41141281cf3SAxel Dörfler 41241281cf3SAxel Dörfler switch (location) { 41341281cf3SAxel Dörfler case B_DESKBAR_TOP: 41441281cf3SAxel Dörfler left = true; 41541281cf3SAxel Dörfler top = true; 41641281cf3SAxel Dörfler vertical = false; 41741281cf3SAxel Dörfler expand = true; 41841281cf3SAxel Dörfler break; 41941281cf3SAxel Dörfler 42041281cf3SAxel Dörfler case B_DESKBAR_BOTTOM: 42141281cf3SAxel Dörfler left = true; 42241281cf3SAxel Dörfler top = false; 42341281cf3SAxel Dörfler vertical = false; 42441281cf3SAxel Dörfler expand = true; 42541281cf3SAxel Dörfler break; 42641281cf3SAxel Dörfler 42741281cf3SAxel Dörfler case B_DESKBAR_LEFT_TOP: 42841281cf3SAxel Dörfler left = true; 42941281cf3SAxel Dörfler top = true; 43041281cf3SAxel Dörfler vertical = true; 43141281cf3SAxel Dörfler expand = newExpandState; 43241281cf3SAxel Dörfler break; 43341281cf3SAxel Dörfler 43441281cf3SAxel Dörfler case B_DESKBAR_RIGHT_TOP: 43541281cf3SAxel Dörfler left = false; 43641281cf3SAxel Dörfler top = true; 43741281cf3SAxel Dörfler vertical = true; 43841281cf3SAxel Dörfler expand = newExpandState; 43941281cf3SAxel Dörfler break; 44041281cf3SAxel Dörfler 44141281cf3SAxel Dörfler case B_DESKBAR_LEFT_BOTTOM: 44241281cf3SAxel Dörfler left = true; 44341281cf3SAxel Dörfler top = false; 44441281cf3SAxel Dörfler vertical = true; 44541281cf3SAxel Dörfler expand = false; 44641281cf3SAxel Dörfler break; 44741281cf3SAxel Dörfler 44841281cf3SAxel Dörfler case B_DESKBAR_RIGHT_BOTTOM: 44941281cf3SAxel Dörfler left = false; 45041281cf3SAxel Dörfler top = false; 45141281cf3SAxel Dörfler vertical = true; 45241281cf3SAxel Dörfler expand = false; 45341281cf3SAxel Dörfler break; 45441281cf3SAxel Dörfler 45541281cf3SAxel Dörfler default: 45641281cf3SAxel Dörfler left = true; 45741281cf3SAxel Dörfler top = true; 45841281cf3SAxel Dörfler vertical = false; 45941281cf3SAxel Dörfler expand = true; 46041281cf3SAxel Dörfler break; 46141281cf3SAxel Dörfler } 46241281cf3SAxel Dörfler 46341281cf3SAxel Dörfler fBarView->ChangeState(expand, vertical, left, top); 46441281cf3SAxel Dörfler } 46541281cf3SAxel Dörfler 4665b576468SAxel Dörfler 46741281cf3SAxel Dörfler void 46841281cf3SAxel Dörfler TBarWindow::SetLocation(BMessage* message) 46941281cf3SAxel Dörfler { 47041281cf3SAxel Dörfler deskbar_location location; 47141281cf3SAxel Dörfler bool expand; 47241281cf3SAxel Dörfler if (message->FindInt32("location", (int32*)&location) == B_OK 47341281cf3SAxel Dörfler && message->FindBool("expand", &expand) == B_OK) 47441281cf3SAxel Dörfler SetDeskbarLocation(location, expand); 47541281cf3SAxel Dörfler } 47641281cf3SAxel Dörfler 47741281cf3SAxel Dörfler 47841281cf3SAxel Dörfler void 47941281cf3SAxel Dörfler TBarWindow::IsExpanded(BMessage* message) 48041281cf3SAxel Dörfler { 48141281cf3SAxel Dörfler BMessage reply('rply'); 482d0a49328SJohn Scipione reply.AddBool("expanded", fBarView->ExpandoState()); 48341281cf3SAxel Dörfler message->SendReply(&reply); 48441281cf3SAxel Dörfler } 48541281cf3SAxel Dörfler 48641281cf3SAxel Dörfler 48741281cf3SAxel Dörfler void 48841281cf3SAxel Dörfler TBarWindow::Expand(BMessage* message) 48941281cf3SAxel Dörfler { 49041281cf3SAxel Dörfler bool expand; 49141281cf3SAxel Dörfler if (message->FindBool("expand", &expand) == B_OK) { 49241281cf3SAxel Dörfler bool vertical = fBarView->Vertical(); 49341281cf3SAxel Dörfler bool left = fBarView->Left(); 49441281cf3SAxel Dörfler bool top = fBarView->Top(); 49541281cf3SAxel Dörfler fBarView->ChangeState(expand, vertical, left, top); 49641281cf3SAxel Dörfler } 49741281cf3SAxel Dörfler } 49841281cf3SAxel Dörfler 49941281cf3SAxel Dörfler 50041281cf3SAxel Dörfler void 50141281cf3SAxel Dörfler TBarWindow::ItemInfo(BMessage* message) 50241281cf3SAxel Dörfler { 50341281cf3SAxel Dörfler BMessage replyMsg; 50441281cf3SAxel Dörfler const char* name; 50541281cf3SAxel Dörfler int32 id; 50641281cf3SAxel Dörfler DeskbarShelf shelf; 50741281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) { 50841281cf3SAxel Dörfler if (fBarView->ItemInfo(id, &name, &shelf) == B_OK) { 50941281cf3SAxel Dörfler replyMsg.AddString("name", name); 51041281cf3SAxel Dörfler #if SHELF_AWARE 51141281cf3SAxel Dörfler replyMsg.AddInt32("shelf", (int32)shelf); 51241281cf3SAxel Dörfler #endif 51341281cf3SAxel Dörfler } 51441281cf3SAxel Dörfler } else if (message->FindString("name", &name) == B_OK) { 51541281cf3SAxel Dörfler if (fBarView->ItemInfo(name, &id, &shelf) == B_OK) { 51641281cf3SAxel Dörfler replyMsg.AddInt32("id", id); 51741281cf3SAxel Dörfler #if SHELF_AWARE 51841281cf3SAxel Dörfler replyMsg.AddInt32("shelf", (int32)shelf); 51941281cf3SAxel Dörfler #endif 52041281cf3SAxel Dörfler } 52141281cf3SAxel Dörfler } 52241281cf3SAxel Dörfler 52341281cf3SAxel Dörfler message->SendReply(&replyMsg); 52441281cf3SAxel Dörfler } 52541281cf3SAxel Dörfler 52641281cf3SAxel Dörfler 52741281cf3SAxel Dörfler void 52841281cf3SAxel Dörfler TBarWindow::ItemExists(BMessage* message) 52941281cf3SAxel Dörfler { 53041281cf3SAxel Dörfler BMessage replyMsg; 53141281cf3SAxel Dörfler const char* name; 53241281cf3SAxel Dörfler int32 id; 53341281cf3SAxel Dörfler DeskbarShelf shelf; 53441281cf3SAxel Dörfler 53541281cf3SAxel Dörfler #if SHELF_AWARE 53641281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) != B_OK) 53741281cf3SAxel Dörfler #endif 53841281cf3SAxel Dörfler shelf = B_DESKBAR_TRAY; 53941281cf3SAxel Dörfler 54041281cf3SAxel Dörfler bool exists = false; 54141281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) 54241281cf3SAxel Dörfler exists = fBarView->ItemExists(id, shelf); 54341281cf3SAxel Dörfler else if (message->FindString("name", &name) == B_OK) 54441281cf3SAxel Dörfler exists = fBarView->ItemExists(name, shelf); 54541281cf3SAxel Dörfler 54641281cf3SAxel Dörfler replyMsg.AddBool("exists", exists); 54741281cf3SAxel Dörfler message->SendReply(&replyMsg); 54841281cf3SAxel Dörfler } 54941281cf3SAxel Dörfler 55041281cf3SAxel Dörfler 55141281cf3SAxel Dörfler void 55241281cf3SAxel Dörfler TBarWindow::CountItems(BMessage* message) 55341281cf3SAxel Dörfler { 55441281cf3SAxel Dörfler DeskbarShelf shelf; 55541281cf3SAxel Dörfler 55641281cf3SAxel Dörfler #if SHELF_AWARE 55741281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) != B_OK) 55841281cf3SAxel Dörfler #endif 55941281cf3SAxel Dörfler shelf = B_DESKBAR_TRAY; 56041281cf3SAxel Dörfler 56141281cf3SAxel Dörfler BMessage reply('rply'); 56241281cf3SAxel Dörfler reply.AddInt32("count", fBarView->CountItems(shelf)); 56341281cf3SAxel Dörfler message->SendReply(&reply); 56441281cf3SAxel Dörfler } 56541281cf3SAxel Dörfler 56641281cf3SAxel Dörfler 56741281cf3SAxel Dörfler void 568efafab64SAxel Dörfler TBarWindow::MaxItemSize(BMessage* message) 569efafab64SAxel Dörfler { 570efafab64SAxel Dörfler DeskbarShelf shelf; 571efafab64SAxel Dörfler #if SHELF_AWARE 572efafab64SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) != B_OK) 573efafab64SAxel Dörfler #endif 574efafab64SAxel Dörfler shelf = B_DESKBAR_TRAY; 575efafab64SAxel Dörfler 576efafab64SAxel Dörfler BSize size = fBarView->MaxItemSize(shelf); 577efafab64SAxel Dörfler 578efafab64SAxel Dörfler BMessage reply('rply'); 579efafab64SAxel Dörfler reply.AddFloat("width", size.width); 580efafab64SAxel Dörfler reply.AddFloat("height", size.height); 581efafab64SAxel Dörfler message->SendReply(&reply); 582efafab64SAxel Dörfler } 583efafab64SAxel Dörfler 584efafab64SAxel Dörfler 585efafab64SAxel Dörfler void 58641281cf3SAxel Dörfler TBarWindow::AddItem(BMessage* message) 58741281cf3SAxel Dörfler { 5883e6ff860SRene Gollent DeskbarShelf shelf = B_DESKBAR_TRAY; 58941281cf3SAxel Dörfler entry_ref ref; 59041281cf3SAxel Dörfler int32 id = 999; 59141281cf3SAxel Dörfler BMessage reply; 59241281cf3SAxel Dörfler status_t err = B_ERROR; 59341281cf3SAxel Dörfler 5940fc30d89SDario Casalinuovo BMessage* archivedView = new BMessage(); 5950fc30d89SDario Casalinuovo ObjectDeleter<BMessage> deleter(archivedView); 5960fc30d89SDario Casalinuovo if (message->FindMessage("view", archivedView) == B_OK) { 59741281cf3SAxel Dörfler #if SHELF_AWARE 5983e6ff860SRene Gollent message->FindInt32("shelf", &shelf); 59941281cf3SAxel Dörfler #endif 6000fc30d89SDario Casalinuovo err = fBarView->AddItem(archivedView, shelf, &id); 6010fc30d89SDario Casalinuovo if (err == B_OK) { 6020fc30d89SDario Casalinuovo // Detach the deleter since AddReplicant is taking ownership 6030fc30d89SDario Casalinuovo // on success. This should be changed on server side. 6040fc30d89SDario Casalinuovo deleter.Detach(); 6050fc30d89SDario Casalinuovo } 60641281cf3SAxel Dörfler } else if (message->FindRef("addon", &ref) == B_OK) { 60741281cf3SAxel Dörfler BEntry entry(&ref); 6083e6ff860SRene Gollent err = entry.InitCheck(); 6093e6ff860SRene Gollent if (err == B_OK) 6103e6ff860SRene Gollent err = fBarView->AddItem(&entry, shelf, &id); 61141281cf3SAxel Dörfler } 61241281cf3SAxel Dörfler 61341281cf3SAxel Dörfler if (err == B_OK) 61441281cf3SAxel Dörfler reply.AddInt32("id", id); 61541281cf3SAxel Dörfler else 61641281cf3SAxel Dörfler reply.AddInt32("error", err); 61741281cf3SAxel Dörfler 61841281cf3SAxel Dörfler message->SendReply(&reply); 61941281cf3SAxel Dörfler } 62041281cf3SAxel Dörfler 62141281cf3SAxel Dörfler 62241281cf3SAxel Dörfler void 62341281cf3SAxel Dörfler TBarWindow::RemoveItem(BMessage* message) 62441281cf3SAxel Dörfler { 62541281cf3SAxel Dörfler int32 id; 62641281cf3SAxel Dörfler const char* name; 62741281cf3SAxel Dörfler 62841281cf3SAxel Dörfler // ids ought to be unique across all shelves, assuming, of course, 62941281cf3SAxel Dörfler // that sometime in the future there may be more than one 63041281cf3SAxel Dörfler #if SHELF_AWARE 63141281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) == B_OK) { 63241281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK) 63341281cf3SAxel Dörfler fBarView->RemoveItem(name, shelf); 63441281cf3SAxel Dörfler } else { 63541281cf3SAxel Dörfler #endif 63641281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) { 63741281cf3SAxel Dörfler fBarView->RemoveItem(id); 63841281cf3SAxel Dörfler // remove the following two lines if and when the 63941281cf3SAxel Dörfler // shelf option returns 64041281cf3SAxel Dörfler } else if (message->FindString("name", &name) == B_OK) 64141281cf3SAxel Dörfler fBarView->RemoveItem(name, B_DESKBAR_TRAY); 64241281cf3SAxel Dörfler 64341281cf3SAxel Dörfler #if SHELF_AWARE 64441281cf3SAxel Dörfler } 64541281cf3SAxel Dörfler #endif 64641281cf3SAxel Dörfler } 64741281cf3SAxel Dörfler 64841281cf3SAxel Dörfler 64941281cf3SAxel Dörfler void 65041281cf3SAxel Dörfler TBarWindow::GetIconFrame(BMessage* message) 65141281cf3SAxel Dörfler { 65241281cf3SAxel Dörfler BRect frame(0, 0, 0, 0); 65341281cf3SAxel Dörfler 65441281cf3SAxel Dörfler const char* name; 65541281cf3SAxel Dörfler int32 id; 65641281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) 65741281cf3SAxel Dörfler frame = fBarView->IconFrame(id); 65841281cf3SAxel Dörfler else if (message->FindString("name", &name) == B_OK) 65941281cf3SAxel Dörfler frame = fBarView->IconFrame(name); 66041281cf3SAxel Dörfler 66141281cf3SAxel Dörfler BMessage reply('rply'); 66241281cf3SAxel Dörfler reply.AddRect("frame", frame); 66341281cf3SAxel Dörfler message->SendReply(&reply); 66441281cf3SAxel Dörfler } 66571bd3ba5SJonas Sundström 6664c139440SAxel Dörfler 6674c139440SAxel Dörfler bool 66822812ba2SRene Gollent TBarWindow::IsShowingMenu() const 66922812ba2SRene Gollent { 67074ceffa8SJohn Scipione return fMenusShown > 0; 67122812ba2SRene Gollent } 67222812ba2SRene Gollent 67322812ba2SRene Gollent 6747e27cd8eSJohn Scipione void 6757e27cd8eSJohn Scipione TBarWindow::SetSizeLimits() 6767e27cd8eSJohn Scipione { 6777e27cd8eSJohn Scipione BRect screenFrame = (BScreen(this)).Frame(); 67874ceffa8SJohn Scipione bool setToHiddenSize = fBarApp->Settings()->autoHide 6791c765f5bSJohn Scipione && fBarView->IsHidden() && !fBarView->DragRegion()->IsDragging(); 6801c765f5bSJohn Scipione 6811c765f5bSJohn Scipione if (setToHiddenSize) { 6821c765f5bSJohn Scipione if (fBarView->Vertical()) 6831c765f5bSJohn Scipione BWindow::SetSizeLimits(0, kHiddenDimension, 0, kHiddenDimension); 6841c765f5bSJohn Scipione else { 6851c765f5bSJohn Scipione BWindow::SetSizeLimits(screenFrame.Width(), screenFrame.Width(), 6861c765f5bSJohn Scipione 0, kHiddenDimension); 6871c765f5bSJohn Scipione } 6881c765f5bSJohn Scipione } else { 6897e27cd8eSJohn Scipione if (fBarView->Vertical()) { 690*0d2645e4SJohn Scipione float minHeight = 0; 691*0d2645e4SJohn Scipione float maxHeight = B_SIZE_UNLIMITED; 692*0d2645e4SJohn Scipione float minWidth = gMinimumWindowWidth; 693*0d2645e4SJohn Scipione float maxWidth = fBarView->MiniState() ? B_SIZE_UNLIMITED 694*0d2645e4SJohn Scipione : gMaximumWindowWidth; 695*0d2645e4SJohn Scipione BWindow::SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight); 6967e27cd8eSJohn Scipione } else { 6977e27cd8eSJohn Scipione BWindow::SetSizeLimits(screenFrame.Width(), screenFrame.Width(), 6987e27cd8eSJohn Scipione kMenuBarHeight - 1, kMaximumIconSize + 4); 6997e27cd8eSJohn Scipione } 7007e27cd8eSJohn Scipione } 701*0d2645e4SJohn Scipione 7021c765f5bSJohn Scipione } 7037e27cd8eSJohn Scipione 7047e27cd8eSJohn Scipione 70522812ba2SRene Gollent bool 7064c139440SAxel Dörfler TBarWindow::_IsFocusMessage(BMessage* message) 7074c139440SAxel Dörfler { 7084c139440SAxel Dörfler BMessage::Private messagePrivate(message); 7094c139440SAxel Dörfler if (!messagePrivate.UsePreferredTarget()) 7104c139440SAxel Dörfler return false; 7114c139440SAxel Dörfler 7124c139440SAxel Dörfler bool feedFocus; 7134c139440SAxel Dörfler if (message->HasInt32("_token") 7144c139440SAxel Dörfler && (message->FindBool("_feed_focus", &feedFocus) != B_OK || !feedFocus)) 7154c139440SAxel Dörfler return false; 7164c139440SAxel Dörfler 7174c139440SAxel Dörfler return true; 7184c139440SAxel Dörfler } 719