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 5541281cf3SAxel Dörfler #include "BarApp.h" 5641281cf3SAxel Dörfler #include "BarMenuBar.h" 5741281cf3SAxel Dörfler #include "BarView.h" 5826ea7066SIngo Weinhold #include "DeskbarUtils.h" 59323b6546SOliver Tappe #include "DeskbarMenu.h" 601bb2e623SJohn Scipione #include "ExpandoMenuBar.h" 6141281cf3SAxel Dörfler #include "StatusView.h" 6241281cf3SAxel Dörfler 63039f5926SJohn Scipione #include "tracker_private.h" 6441281cf3SAxel Dörfler 65546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT 66546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "MainWindow" 67cd7548f5SJonas Sundström 68cd7548f5SJonas Sundström 691075cc34SFredrik Holmqvist // This is a very ugly hack to be able to call the private 701075cc34SFredrik Holmqvist // BMenuBar::StartMenuBar() method from the TBarWindow::ShowBeMenu() method. 7141281cf3SAxel Dörfler // Don't do this at home -- but why the hell is this method private? 7241281cf3SAxel Dörfler #if __MWERKS__ 734a71b881SAxel Dörfler #define BMenuBar_StartMenuBar_Hack StartMenuBar__8BMenuBarFlbbP5BRect 744a71b881SAxel Dörfler #elif __GNUC__ <= 2 754a71b881SAxel Dörfler #define BMenuBar_StartMenuBar_Hack StartMenuBar__8BMenuBarlbT2P5BRect 764a71b881SAxel Dörfler #elif __GNUC__ > 2 77e9632898SAlex Smith #if B_HAIKU_64_BIT 78e9632898SAlex Smith #define BMenuBar_StartMenuBar_Hack _ZN8BMenuBar12StartMenuBarEibbP5BRect 79e9632898SAlex Smith #else 804a71b881SAxel Dörfler #define BMenuBar_StartMenuBar_Hack _ZN8BMenuBar12StartMenuBarElbbP5BRect 81e9632898SAlex Smith #endif 8241281cf3SAxel Dörfler #else 8341281cf3SAxel Dörfler # error "You may want to port this ugly hack to your compiler ABI" 8441281cf3SAxel Dörfler #endif 851075cc34SFredrik Holmqvist extern "C" void 861075cc34SFredrik Holmqvist BMenuBar_StartMenuBar_Hack(BMenuBar*, int32, bool, bool, BRect*); 8741281cf3SAxel Dörfler 8841281cf3SAxel Dörfler 89323b6546SOliver Tappe TDeskbarMenu* TBarWindow::sDeskbarMenu = NULL; 9041281cf3SAxel Dörfler 9141281cf3SAxel Dörfler 9241281cf3SAxel Dörfler TBarWindow::TBarWindow() 9372f5ac30SAxel Dörfler : 94066522e8SJonas Sundström BWindow(BRect(-1000.0f, -1000.0f, -1000.0f, -1000.0f), 95560ff447SJonas Sundström B_TRANSLATE_SYSTEM_NAME("Deskbar"), B_BORDERED_WINDOW, 9641281cf3SAxel Dörfler B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_CLOSABLE 971bb2e623SJohn Scipione | B_NOT_MINIMIZABLE | B_NOT_MOVABLE | B_NOT_V_RESIZABLE 9874c7ad20SIngo Weinhold | B_AVOID_FRONT | B_ASYNCHRONOUS_CONTROLS, 9922812ba2SRene Gollent B_ALL_WORKSPACES), 10022812ba2SRene Gollent fShowingMenu(false) 10141281cf3SAxel Dörfler { 10241281cf3SAxel Dörfler desk_settings* settings = ((TBarApp*)be_app)->Settings(); 10341281cf3SAxel Dörfler if (settings->alwaysOnTop) 10441281cf3SAxel Dörfler SetFeel(B_FLOATING_ALL_WINDOW_FEEL); 105fe624b39SJohn Scipione 10672f5ac30SAxel Dörfler fBarView = new TBarView(Bounds(), settings->vertical, settings->left, 107573f748cSJohn Scipione settings->top, settings->state, settings->width); 10841281cf3SAxel Dörfler AddChild(fBarView); 10941281cf3SAxel Dörfler 11035c6651cSKarsten Heimrich RemoveShortcut('H', B_COMMAND_KEY | B_CONTROL_KEY); 11141281cf3SAxel Dörfler AddShortcut('F', B_COMMAND_KEY, new BMessage(kFindButton)); 11241281cf3SAxel Dörfler } 11341281cf3SAxel Dörfler 11441281cf3SAxel Dörfler 11541281cf3SAxel Dörfler void 11641281cf3SAxel Dörfler TBarWindow::MenusBeginning() 11741281cf3SAxel Dörfler { 11841281cf3SAxel Dörfler BPath path; 11941281cf3SAxel Dörfler entry_ref ref; 12026ea7066SIngo Weinhold BEntry entry; 12141281cf3SAxel Dörfler 12226ea7066SIngo Weinhold if (GetDeskbarSettingsDirectory(path) == B_OK 12326ea7066SIngo Weinhold && path.Append(kDeskbarMenuEntriesFileName) == B_OK 12426ea7066SIngo Weinhold && entry.SetTo(path.Path(), true) == B_OK 12526ea7066SIngo Weinhold && entry.Exists() 12626ea7066SIngo Weinhold && entry.GetRef(&ref) == B_OK) { 127323b6546SOliver Tappe sDeskbarMenu->SetNavDir(&ref); 12826ea7066SIngo Weinhold } else if (GetDeskbarDataDirectory(path) == B_OK 12926ea7066SIngo Weinhold && path.Append(kDeskbarMenuEntriesFileName) == B_OK 13026ea7066SIngo Weinhold && entry.SetTo(path.Path(), true) == B_OK 13126ea7066SIngo Weinhold && entry.Exists() 13226ea7066SIngo Weinhold && entry.GetRef(&ref) == B_OK) { 133323b6546SOliver Tappe sDeskbarMenu->SetNavDir(&ref); 13441281cf3SAxel Dörfler } else { 13541281cf3SAxel Dörfler // this really should never happen 13641281cf3SAxel Dörfler TRESPASS(); 13741281cf3SAxel Dörfler return; 13841281cf3SAxel Dörfler } 13941281cf3SAxel Dörfler 140323b6546SOliver Tappe sDeskbarMenu->ResetTargets(); 14141281cf3SAxel Dörfler 14222812ba2SRene Gollent fShowingMenu = true; 14341281cf3SAxel Dörfler BWindow::MenusBeginning(); 14441281cf3SAxel Dörfler } 14541281cf3SAxel Dörfler 14641281cf3SAxel Dörfler 14741281cf3SAxel Dörfler void 14841281cf3SAxel Dörfler TBarWindow::MenusEnded() 14941281cf3SAxel Dörfler { 15022812ba2SRene Gollent fShowingMenu = false; 15141281cf3SAxel Dörfler BWindow::MenusEnded(); 15241281cf3SAxel Dörfler 153323b6546SOliver Tappe if (sDeskbarMenu->LockLooper()) { 15485529c12SJessica Hamilton sDeskbarMenu->ForceRebuild(); 155323b6546SOliver Tappe sDeskbarMenu->UnlockLooper(); 15641281cf3SAxel Dörfler } 1574446e07aSStefano Ceccherini } 15841281cf3SAxel Dörfler 15941281cf3SAxel Dörfler 16041281cf3SAxel Dörfler void 16141281cf3SAxel Dörfler TBarWindow::MessageReceived(BMessage* message) 16241281cf3SAxel Dörfler { 16341281cf3SAxel Dörfler switch (message->what) { 16441281cf3SAxel Dörfler case kFindButton: 16541281cf3SAxel Dörfler { 16641281cf3SAxel Dörfler BMessenger tracker(kTrackerSignature); 16741281cf3SAxel Dörfler tracker.SendMessage(message); 16841281cf3SAxel Dörfler break; 16941281cf3SAxel Dörfler } 17041281cf3SAxel Dörfler 17141281cf3SAxel Dörfler case 'gloc': 17241281cf3SAxel Dörfler GetLocation(message); 17341281cf3SAxel Dörfler break; 17441281cf3SAxel Dörfler 17541281cf3SAxel Dörfler case 'sloc': 17641281cf3SAxel Dörfler SetLocation(message); 17741281cf3SAxel Dörfler break; 17841281cf3SAxel Dörfler 17941281cf3SAxel Dörfler case 'gexp': 18041281cf3SAxel Dörfler IsExpanded(message); 18141281cf3SAxel Dörfler break; 18241281cf3SAxel Dörfler 18341281cf3SAxel Dörfler case 'sexp': 18441281cf3SAxel Dörfler Expand(message); 18541281cf3SAxel Dörfler break; 18641281cf3SAxel Dörfler 18741281cf3SAxel Dörfler case 'info': 18841281cf3SAxel Dörfler ItemInfo(message); 18941281cf3SAxel Dörfler break; 19041281cf3SAxel Dörfler 19141281cf3SAxel Dörfler case 'exst': 19241281cf3SAxel Dörfler ItemExists(message); 19341281cf3SAxel Dörfler break; 19441281cf3SAxel Dörfler 19541281cf3SAxel Dörfler case 'cwnt': 19641281cf3SAxel Dörfler CountItems(message); 19741281cf3SAxel Dörfler break; 19841281cf3SAxel Dörfler 19941281cf3SAxel Dörfler case 'adon': 20041281cf3SAxel Dörfler case 'icon': 20141281cf3SAxel Dörfler AddItem(message); 20241281cf3SAxel Dörfler break; 20341281cf3SAxel Dörfler 20441281cf3SAxel Dörfler case 'remv': 20541281cf3SAxel Dörfler RemoveItem(message); 20641281cf3SAxel Dörfler break; 20741281cf3SAxel Dörfler 20841281cf3SAxel Dörfler case 'iloc': 20941281cf3SAxel Dörfler GetIconFrame(message); 21041281cf3SAxel Dörfler break; 21141281cf3SAxel Dörfler 21241281cf3SAxel Dörfler default: 21341281cf3SAxel Dörfler BWindow::MessageReceived(message); 21441281cf3SAxel Dörfler break; 21541281cf3SAxel Dörfler } 21641281cf3SAxel Dörfler } 21741281cf3SAxel Dörfler 21841281cf3SAxel Dörfler 21941281cf3SAxel Dörfler void 2205b576468SAxel Dörfler TBarWindow::Minimize(bool minimize) 2215b576468SAxel Dörfler { 2225b576468SAxel Dörfler // Don't allow the Deskbar to be minimized 2235b576468SAxel Dörfler if (!minimize) 2245b576468SAxel Dörfler BWindow::Minimize(false); 2255b576468SAxel Dörfler } 2265b576468SAxel Dörfler 2275b576468SAxel Dörfler 2285b576468SAxel Dörfler void 2291bb2e623SJohn Scipione TBarWindow::FrameResized(float width, float height) 2301bb2e623SJohn Scipione { 2311bb2e623SJohn Scipione if (!fBarView->Vertical()) 2321bb2e623SJohn Scipione return BWindow::FrameResized(width, height); 2331bb2e623SJohn Scipione 2341bb2e623SJohn Scipione bool setToHiddenSize = static_cast<TBarApp*>(be_app)->Settings()->autoHide 2351bb2e623SJohn Scipione && fBarView->IsHidden() && !fBarView->DragRegion()->IsDragging(); 2361bb2e623SJohn Scipione if (!setToHiddenSize) { 2371bb2e623SJohn Scipione // constrain within limits 2381bb2e623SJohn Scipione float newWidth; 2391bb2e623SJohn Scipione if (width < gMinimumWindowWidth) 2401bb2e623SJohn Scipione newWidth = gMinimumWindowWidth; 2411bb2e623SJohn Scipione else if (width > gMaximumWindowWidth) 2421bb2e623SJohn Scipione newWidth = gMaximumWindowWidth; 2431bb2e623SJohn Scipione else 2441bb2e623SJohn Scipione newWidth = width; 2451bb2e623SJohn Scipione 246*938fd26fSJohn Scipione float oldWidth = static_cast<TBarApp*>(be_app)->Settings()->width; 247*938fd26fSJohn Scipione 2481bb2e623SJohn Scipione // update width setting 2491bb2e623SJohn Scipione static_cast<TBarApp*>(be_app)->Settings()->width = newWidth; 2501bb2e623SJohn Scipione 251*938fd26fSJohn Scipione if (oldWidth != newWidth) { 2521bb2e623SJohn Scipione fBarView->ResizeTo(width, fBarView->Bounds().Height()); 2531bb2e623SJohn Scipione if (fBarView->Vertical() && fBarView->ExpandoState()) 2541bb2e623SJohn Scipione fBarView->ExpandoMenuBar()->SetMaxContentWidth(width); 2551bb2e623SJohn Scipione 256*938fd26fSJohn Scipione fBarView->UpdatePlacement(); 257*938fd26fSJohn Scipione } 2581bb2e623SJohn Scipione } 2591bb2e623SJohn Scipione } 2601bb2e623SJohn Scipione 2611bb2e623SJohn Scipione 2621bb2e623SJohn Scipione void 26341281cf3SAxel Dörfler TBarWindow::SaveSettings() 26441281cf3SAxel Dörfler { 26541281cf3SAxel Dörfler fBarView->SaveSettings(); 26641281cf3SAxel Dörfler } 26741281cf3SAxel Dörfler 26841281cf3SAxel Dörfler 26941281cf3SAxel Dörfler bool 27041281cf3SAxel Dörfler TBarWindow::QuitRequested() 27141281cf3SAxel Dörfler { 27241281cf3SAxel Dörfler be_app->PostMessage(B_QUIT_REQUESTED); 27341281cf3SAxel Dörfler 27441281cf3SAxel Dörfler return BWindow::QuitRequested(); 27541281cf3SAxel Dörfler } 27641281cf3SAxel Dörfler 27741281cf3SAxel Dörfler 27841281cf3SAxel Dörfler void 27941281cf3SAxel Dörfler TBarWindow::WorkspaceActivated(int32 workspace, bool active) 28041281cf3SAxel Dörfler { 28141281cf3SAxel Dörfler BWindow::WorkspaceActivated(workspace, active); 28241281cf3SAxel Dörfler 283d0a49328SJohn Scipione if (active && !(fBarView->ExpandoState() && fBarView->Vertical())) 28441281cf3SAxel Dörfler fBarView->UpdatePlacement(); 28541281cf3SAxel Dörfler else { 28641281cf3SAxel Dörfler BRect screenFrame = (BScreen(fBarView->Window())).Frame(); 28741281cf3SAxel Dörfler fBarView->SizeWindow(screenFrame); 28841281cf3SAxel Dörfler fBarView->PositionWindow(screenFrame); 28941281cf3SAxel Dörfler fBarView->Invalidate(); 29041281cf3SAxel Dörfler } 29141281cf3SAxel Dörfler } 29241281cf3SAxel Dörfler 29341281cf3SAxel Dörfler 29441281cf3SAxel Dörfler void 29541281cf3SAxel Dörfler TBarWindow::ScreenChanged(BRect size, color_space depth) 29641281cf3SAxel Dörfler { 29741281cf3SAxel Dörfler BWindow::ScreenChanged(size, depth); 29841281cf3SAxel Dörfler 29941281cf3SAxel Dörfler fBarView->UpdatePlacement(); 30041281cf3SAxel Dörfler } 30141281cf3SAxel Dörfler 30241281cf3SAxel Dörfler 30341281cf3SAxel Dörfler void 304323b6546SOliver Tappe TBarWindow::SetDeskbarMenu(TDeskbarMenu* menu) 30541281cf3SAxel Dörfler { 306323b6546SOliver Tappe sDeskbarMenu = menu; 30741281cf3SAxel Dörfler } 30841281cf3SAxel Dörfler 30941281cf3SAxel Dörfler 310323b6546SOliver Tappe TDeskbarMenu* 311323b6546SOliver Tappe TBarWindow::DeskbarMenu() 31241281cf3SAxel Dörfler { 313323b6546SOliver Tappe return sDeskbarMenu; 31441281cf3SAxel Dörfler } 31541281cf3SAxel Dörfler 31641281cf3SAxel Dörfler 31741281cf3SAxel Dörfler void 318323b6546SOliver Tappe TBarWindow::ShowDeskbarMenu() 31941281cf3SAxel Dörfler { 32041281cf3SAxel Dörfler BMenuBar* menuBar = fBarView->BarMenuBar(); 32141281cf3SAxel Dörfler if (menuBar == NULL) 32241281cf3SAxel Dörfler menuBar = KeyMenuBar(); 32341281cf3SAxel Dörfler 32441281cf3SAxel Dörfler if (menuBar == NULL) 32541281cf3SAxel Dörfler return; 32641281cf3SAxel Dörfler 3274a71b881SAxel Dörfler BMenuBar_StartMenuBar_Hack(menuBar, 0, true, true, NULL); 32841281cf3SAxel Dörfler } 32941281cf3SAxel Dörfler 33041281cf3SAxel Dörfler 33141281cf3SAxel Dörfler void 33241281cf3SAxel Dörfler TBarWindow::ShowTeamMenu() 33341281cf3SAxel Dörfler { 33441281cf3SAxel Dörfler int32 index = 0; 33541281cf3SAxel Dörfler if (fBarView->BarMenuBar() == NULL) 33641281cf3SAxel Dörfler index = 2; 33741281cf3SAxel Dörfler 33841281cf3SAxel Dörfler if (KeyMenuBar() == NULL) 33941281cf3SAxel Dörfler return; 34041281cf3SAxel Dörfler 3414a71b881SAxel Dörfler BMenuBar_StartMenuBar_Hack(KeyMenuBar(), index, true, true, NULL); 34241281cf3SAxel Dörfler } 34341281cf3SAxel Dörfler 34441281cf3SAxel Dörfler 3451075cc34SFredrik Holmqvist // determines the actual location of the window 34641281cf3SAxel Dörfler 34741281cf3SAxel Dörfler deskbar_location 34841281cf3SAxel Dörfler TBarWindow::DeskbarLocation() const 34941281cf3SAxel Dörfler { 35041281cf3SAxel Dörfler bool left = fBarView->Left(); 35141281cf3SAxel Dörfler bool top = fBarView->Top(); 35241281cf3SAxel Dörfler 35341281cf3SAxel Dörfler if (fBarView->AcrossTop()) 35441281cf3SAxel Dörfler return B_DESKBAR_TOP; 35541281cf3SAxel Dörfler 35641281cf3SAxel Dörfler if (fBarView->AcrossBottom()) 35741281cf3SAxel Dörfler return B_DESKBAR_BOTTOM; 35841281cf3SAxel Dörfler 35941281cf3SAxel Dörfler if (left && top) 36041281cf3SAxel Dörfler return B_DESKBAR_LEFT_TOP; 36141281cf3SAxel Dörfler 36241281cf3SAxel Dörfler if (!left && top) 36341281cf3SAxel Dörfler return B_DESKBAR_RIGHT_TOP; 36441281cf3SAxel Dörfler 36541281cf3SAxel Dörfler if (left && !top) 36641281cf3SAxel Dörfler return B_DESKBAR_LEFT_BOTTOM; 36741281cf3SAxel Dörfler 36841281cf3SAxel Dörfler return B_DESKBAR_RIGHT_BOTTOM; 36941281cf3SAxel Dörfler } 37041281cf3SAxel Dörfler 37141281cf3SAxel Dörfler 37241281cf3SAxel Dörfler void 37341281cf3SAxel Dörfler TBarWindow::GetLocation(BMessage* message) 37441281cf3SAxel Dörfler { 37541281cf3SAxel Dörfler BMessage reply('rply'); 37641281cf3SAxel Dörfler reply.AddInt32("location", (int32)DeskbarLocation()); 377d0a49328SJohn Scipione reply.AddBool("expanded", fBarView->ExpandoState()); 37841281cf3SAxel Dörfler 37941281cf3SAxel Dörfler message->SendReply(&reply); 38041281cf3SAxel Dörfler } 38141281cf3SAxel Dörfler 38241281cf3SAxel Dörfler 38341281cf3SAxel Dörfler void 38441281cf3SAxel Dörfler TBarWindow::SetDeskbarLocation(deskbar_location location, bool newExpandState) 38541281cf3SAxel Dörfler { 38641281cf3SAxel Dörfler // left top and right top are the only two that 38741281cf3SAxel Dörfler // currently pay attention to expand, ignore for all others 38841281cf3SAxel Dörfler 38941281cf3SAxel Dörfler bool left = false, top = true, vertical, expand; 39041281cf3SAxel Dörfler 39141281cf3SAxel Dörfler switch (location) { 39241281cf3SAxel Dörfler case B_DESKBAR_TOP: 39341281cf3SAxel Dörfler left = true; 39441281cf3SAxel Dörfler top = true; 39541281cf3SAxel Dörfler vertical = false; 39641281cf3SAxel Dörfler expand = true; 39741281cf3SAxel Dörfler break; 39841281cf3SAxel Dörfler 39941281cf3SAxel Dörfler case B_DESKBAR_BOTTOM: 40041281cf3SAxel Dörfler left = true; 40141281cf3SAxel Dörfler top = false; 40241281cf3SAxel Dörfler vertical = false; 40341281cf3SAxel Dörfler expand = true; 40441281cf3SAxel Dörfler break; 40541281cf3SAxel Dörfler 40641281cf3SAxel Dörfler case B_DESKBAR_LEFT_TOP: 40741281cf3SAxel Dörfler left = true; 40841281cf3SAxel Dörfler top = true; 40941281cf3SAxel Dörfler vertical = true; 41041281cf3SAxel Dörfler expand = newExpandState; 41141281cf3SAxel Dörfler break; 41241281cf3SAxel Dörfler 41341281cf3SAxel Dörfler case B_DESKBAR_RIGHT_TOP: 41441281cf3SAxel Dörfler left = false; 41541281cf3SAxel Dörfler top = true; 41641281cf3SAxel Dörfler vertical = true; 41741281cf3SAxel Dörfler expand = newExpandState; 41841281cf3SAxel Dörfler break; 41941281cf3SAxel Dörfler 42041281cf3SAxel Dörfler case B_DESKBAR_LEFT_BOTTOM: 42141281cf3SAxel Dörfler left = true; 42241281cf3SAxel Dörfler top = false; 42341281cf3SAxel Dörfler vertical = true; 42441281cf3SAxel Dörfler expand = false; 42541281cf3SAxel Dörfler break; 42641281cf3SAxel Dörfler 42741281cf3SAxel Dörfler case B_DESKBAR_RIGHT_BOTTOM: 42841281cf3SAxel Dörfler left = false; 42941281cf3SAxel Dörfler top = false; 43041281cf3SAxel Dörfler vertical = true; 43141281cf3SAxel Dörfler expand = false; 43241281cf3SAxel Dörfler break; 43341281cf3SAxel Dörfler 43441281cf3SAxel Dörfler default: 43541281cf3SAxel Dörfler left = true; 43641281cf3SAxel Dörfler top = true; 43741281cf3SAxel Dörfler vertical = false; 43841281cf3SAxel Dörfler expand = true; 43941281cf3SAxel Dörfler break; 44041281cf3SAxel Dörfler } 44141281cf3SAxel Dörfler 44241281cf3SAxel Dörfler fBarView->ChangeState(expand, vertical, left, top); 44341281cf3SAxel Dörfler } 44441281cf3SAxel Dörfler 4455b576468SAxel Dörfler 44641281cf3SAxel Dörfler void 44741281cf3SAxel Dörfler TBarWindow::SetLocation(BMessage* message) 44841281cf3SAxel Dörfler { 44941281cf3SAxel Dörfler deskbar_location location; 45041281cf3SAxel Dörfler bool expand; 45141281cf3SAxel Dörfler if (message->FindInt32("location", (int32*)&location) == B_OK 45241281cf3SAxel Dörfler && message->FindBool("expand", &expand) == B_OK) 45341281cf3SAxel Dörfler SetDeskbarLocation(location, expand); 45441281cf3SAxel Dörfler } 45541281cf3SAxel Dörfler 45641281cf3SAxel Dörfler 45741281cf3SAxel Dörfler void 45841281cf3SAxel Dörfler TBarWindow::IsExpanded(BMessage* message) 45941281cf3SAxel Dörfler { 46041281cf3SAxel Dörfler BMessage reply('rply'); 461d0a49328SJohn Scipione reply.AddBool("expanded", fBarView->ExpandoState()); 46241281cf3SAxel Dörfler message->SendReply(&reply); 46341281cf3SAxel Dörfler } 46441281cf3SAxel Dörfler 46541281cf3SAxel Dörfler 46641281cf3SAxel Dörfler void 46741281cf3SAxel Dörfler TBarWindow::Expand(BMessage* message) 46841281cf3SAxel Dörfler { 46941281cf3SAxel Dörfler bool expand; 47041281cf3SAxel Dörfler if (message->FindBool("expand", &expand) == B_OK) { 47141281cf3SAxel Dörfler bool vertical = fBarView->Vertical(); 47241281cf3SAxel Dörfler bool left = fBarView->Left(); 47341281cf3SAxel Dörfler bool top = fBarView->Top(); 47441281cf3SAxel Dörfler fBarView->ChangeState(expand, vertical, left, top); 47541281cf3SAxel Dörfler } 47641281cf3SAxel Dörfler } 47741281cf3SAxel Dörfler 47841281cf3SAxel Dörfler 47941281cf3SAxel Dörfler void 48041281cf3SAxel Dörfler TBarWindow::ItemInfo(BMessage* message) 48141281cf3SAxel Dörfler { 48241281cf3SAxel Dörfler BMessage replyMsg; 48341281cf3SAxel Dörfler const char* name; 48441281cf3SAxel Dörfler int32 id; 48541281cf3SAxel Dörfler DeskbarShelf shelf; 48641281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) { 48741281cf3SAxel Dörfler if (fBarView->ItemInfo(id, &name, &shelf) == B_OK) { 48841281cf3SAxel Dörfler replyMsg.AddString("name", name); 48941281cf3SAxel Dörfler #if SHELF_AWARE 49041281cf3SAxel Dörfler replyMsg.AddInt32("shelf", (int32)shelf); 49141281cf3SAxel Dörfler #endif 49241281cf3SAxel Dörfler } 49341281cf3SAxel Dörfler } else if (message->FindString("name", &name) == B_OK) { 49441281cf3SAxel Dörfler if (fBarView->ItemInfo(name, &id, &shelf) == B_OK) { 49541281cf3SAxel Dörfler replyMsg.AddInt32("id", id); 49641281cf3SAxel Dörfler #if SHELF_AWARE 49741281cf3SAxel Dörfler replyMsg.AddInt32("shelf", (int32)shelf); 49841281cf3SAxel Dörfler #endif 49941281cf3SAxel Dörfler } 50041281cf3SAxel Dörfler } 50141281cf3SAxel Dörfler 50241281cf3SAxel Dörfler message->SendReply(&replyMsg); 50341281cf3SAxel Dörfler } 50441281cf3SAxel Dörfler 50541281cf3SAxel Dörfler 50641281cf3SAxel Dörfler void 50741281cf3SAxel Dörfler TBarWindow::ItemExists(BMessage* message) 50841281cf3SAxel Dörfler { 50941281cf3SAxel Dörfler BMessage replyMsg; 51041281cf3SAxel Dörfler const char* name; 51141281cf3SAxel Dörfler int32 id; 51241281cf3SAxel Dörfler DeskbarShelf shelf; 51341281cf3SAxel Dörfler 51441281cf3SAxel Dörfler #if SHELF_AWARE 51541281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) != B_OK) 51641281cf3SAxel Dörfler #endif 51741281cf3SAxel Dörfler shelf = B_DESKBAR_TRAY; 51841281cf3SAxel Dörfler 51941281cf3SAxel Dörfler bool exists = false; 52041281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) 52141281cf3SAxel Dörfler exists = fBarView->ItemExists(id, shelf); 52241281cf3SAxel Dörfler else if (message->FindString("name", &name) == B_OK) 52341281cf3SAxel Dörfler exists = fBarView->ItemExists(name, shelf); 52441281cf3SAxel Dörfler 52541281cf3SAxel Dörfler replyMsg.AddBool("exists", exists); 52641281cf3SAxel Dörfler message->SendReply(&replyMsg); 52741281cf3SAxel Dörfler } 52841281cf3SAxel Dörfler 52941281cf3SAxel Dörfler 53041281cf3SAxel Dörfler void 53141281cf3SAxel Dörfler TBarWindow::CountItems(BMessage* message) 53241281cf3SAxel Dörfler { 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 BMessage reply('rply'); 54141281cf3SAxel Dörfler reply.AddInt32("count", fBarView->CountItems(shelf)); 54241281cf3SAxel Dörfler message->SendReply(&reply); 54341281cf3SAxel Dörfler } 54441281cf3SAxel Dörfler 54541281cf3SAxel Dörfler 54641281cf3SAxel Dörfler void 54741281cf3SAxel Dörfler TBarWindow::AddItem(BMessage* message) 54841281cf3SAxel Dörfler { 5493e6ff860SRene Gollent DeskbarShelf shelf = B_DESKBAR_TRAY; 55041281cf3SAxel Dörfler entry_ref ref; 55141281cf3SAxel Dörfler int32 id = 999; 55241281cf3SAxel Dörfler BMessage reply; 55341281cf3SAxel Dörfler status_t err = B_ERROR; 55441281cf3SAxel Dörfler 5550fc30d89SDario Casalinuovo BMessage* archivedView = new BMessage(); 5560fc30d89SDario Casalinuovo ObjectDeleter<BMessage> deleter(archivedView); 5570fc30d89SDario Casalinuovo if (message->FindMessage("view", archivedView) == B_OK) { 55841281cf3SAxel Dörfler #if SHELF_AWARE 5593e6ff860SRene Gollent message->FindInt32("shelf", &shelf); 56041281cf3SAxel Dörfler #endif 5610fc30d89SDario Casalinuovo err = fBarView->AddItem(archivedView, shelf, &id); 5620fc30d89SDario Casalinuovo if (err == B_OK) { 5630fc30d89SDario Casalinuovo // Detach the deleter since AddReplicant is taking ownership 5640fc30d89SDario Casalinuovo // on success. This should be changed on server side. 5650fc30d89SDario Casalinuovo deleter.Detach(); 5660fc30d89SDario Casalinuovo } 56741281cf3SAxel Dörfler } else if (message->FindRef("addon", &ref) == B_OK) { 56841281cf3SAxel Dörfler BEntry entry(&ref); 5693e6ff860SRene Gollent err = entry.InitCheck(); 5703e6ff860SRene Gollent if (err == B_OK) 5713e6ff860SRene Gollent err = fBarView->AddItem(&entry, shelf, &id); 57241281cf3SAxel Dörfler } 57341281cf3SAxel Dörfler 57441281cf3SAxel Dörfler if (err == B_OK) 57541281cf3SAxel Dörfler reply.AddInt32("id", id); 57641281cf3SAxel Dörfler else 57741281cf3SAxel Dörfler reply.AddInt32("error", err); 57841281cf3SAxel Dörfler 57941281cf3SAxel Dörfler message->SendReply(&reply); 58041281cf3SAxel Dörfler } 58141281cf3SAxel Dörfler 58241281cf3SAxel Dörfler 58341281cf3SAxel Dörfler void 58441281cf3SAxel Dörfler TBarWindow::RemoveItem(BMessage* message) 58541281cf3SAxel Dörfler { 58641281cf3SAxel Dörfler int32 id; 58741281cf3SAxel Dörfler const char* name; 58841281cf3SAxel Dörfler 58941281cf3SAxel Dörfler // ids ought to be unique across all shelves, assuming, of course, 59041281cf3SAxel Dörfler // that sometime in the future there may be more than one 59141281cf3SAxel Dörfler #if SHELF_AWARE 59241281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) == B_OK) { 59341281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK) 59441281cf3SAxel Dörfler fBarView->RemoveItem(name, shelf); 59541281cf3SAxel Dörfler } else { 59641281cf3SAxel Dörfler #endif 59741281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) { 59841281cf3SAxel Dörfler fBarView->RemoveItem(id); 59941281cf3SAxel Dörfler // remove the following two lines if and when the 60041281cf3SAxel Dörfler // shelf option returns 60141281cf3SAxel Dörfler } else if (message->FindString("name", &name) == B_OK) 60241281cf3SAxel Dörfler fBarView->RemoveItem(name, B_DESKBAR_TRAY); 60341281cf3SAxel Dörfler 60441281cf3SAxel Dörfler #if SHELF_AWARE 60541281cf3SAxel Dörfler } 60641281cf3SAxel Dörfler #endif 60741281cf3SAxel Dörfler } 60841281cf3SAxel Dörfler 60941281cf3SAxel Dörfler 61041281cf3SAxel Dörfler void 61141281cf3SAxel Dörfler TBarWindow::GetIconFrame(BMessage* message) 61241281cf3SAxel Dörfler { 61341281cf3SAxel Dörfler BRect frame(0, 0, 0, 0); 61441281cf3SAxel Dörfler 61541281cf3SAxel Dörfler const char* name; 61641281cf3SAxel Dörfler int32 id; 61741281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) 61841281cf3SAxel Dörfler frame = fBarView->IconFrame(id); 61941281cf3SAxel Dörfler else if (message->FindString("name", &name) == B_OK) 62041281cf3SAxel Dörfler frame = fBarView->IconFrame(name); 62141281cf3SAxel Dörfler 62241281cf3SAxel Dörfler BMessage reply('rply'); 62341281cf3SAxel Dörfler reply.AddRect("frame", frame); 62441281cf3SAxel Dörfler message->SendReply(&reply); 62541281cf3SAxel Dörfler } 62671bd3ba5SJonas Sundström 6274c139440SAxel Dörfler 6284c139440SAxel Dörfler bool 62922812ba2SRene Gollent TBarWindow::IsShowingMenu() const 63022812ba2SRene Gollent { 63122812ba2SRene Gollent return fShowingMenu; 63222812ba2SRene Gollent } 63322812ba2SRene Gollent 63422812ba2SRene Gollent 63522812ba2SRene Gollent bool 6364c139440SAxel Dörfler TBarWindow::_IsFocusMessage(BMessage* message) 6374c139440SAxel Dörfler { 6384c139440SAxel Dörfler BMessage::Private messagePrivate(message); 6394c139440SAxel Dörfler if (!messagePrivate.UsePreferredTarget()) 6404c139440SAxel Dörfler return false; 6414c139440SAxel Dörfler 6424c139440SAxel Dörfler bool feedFocus; 6434c139440SAxel Dörfler if (message->HasInt32("_token") 6444c139440SAxel Dörfler && (message->FindBool("_feed_focus", &feedFocus) != B_OK || !feedFocus)) 6454c139440SAxel Dörfler return false; 6464c139440SAxel Dörfler 6474c139440SAxel Dörfler return true; 6484c139440SAxel Dörfler } 649