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> 4241281cf3SAxel Dörfler #include <Directory.h> 4341281cf3SAxel Dörfler #include <FindDirectory.h> 4441281cf3SAxel Dörfler #include <Path.h> 4541281cf3SAxel Dörfler #include <Debug.h> 4641281cf3SAxel Dörfler #include <File.h> 47cd7548f5SJonas Sundström #include <Locale.h> 4841281cf3SAxel Dörfler #include <MenuItem.h> 4941281cf3SAxel Dörfler #include <MessageFilter.h> 5041281cf3SAxel Dörfler #include <Screen.h> 5141281cf3SAxel Dörfler 5241281cf3SAxel Dörfler #include "BarApp.h" 5341281cf3SAxel Dörfler #include "BarMenuBar.h" 5441281cf3SAxel Dörfler #include "BarView.h" 5541281cf3SAxel Dörfler #include "BeMenu.h" 5641281cf3SAxel Dörfler #include "PublicCommands.h" 5741281cf3SAxel Dörfler #include "StatusView.h" 5841281cf3SAxel Dörfler #include "tracker_private.h" 5941281cf3SAxel Dörfler 604c139440SAxel Dörfler #include <MessagePrivate.h> 614c139440SAxel Dörfler 6241281cf3SAxel Dörfler 63cd7548f5SJonas Sundström #undef B_TRANSLATE_CONTEXT 64cd7548f5SJonas Sundström #define B_TRANSLATE_CONTEXT "MainWindow" 65cd7548f5SJonas Sundström 66cd7548f5SJonas Sundström 671075cc34SFredrik Holmqvist // This is a very ugly hack to be able to call the private 681075cc34SFredrik Holmqvist // BMenuBar::StartMenuBar() method from the TBarWindow::ShowBeMenu() method. 6941281cf3SAxel Dörfler // Don't do this at home -- but why the hell is this method private? 7041281cf3SAxel Dörfler #if __MWERKS__ 714a71b881SAxel Dörfler #define BMenuBar_StartMenuBar_Hack StartMenuBar__8BMenuBarFlbbP5BRect 724a71b881SAxel Dörfler #elif __GNUC__ <= 2 734a71b881SAxel Dörfler #define BMenuBar_StartMenuBar_Hack StartMenuBar__8BMenuBarlbT2P5BRect 744a71b881SAxel Dörfler #elif __GNUC__ > 2 754a71b881SAxel Dörfler #define BMenuBar_StartMenuBar_Hack _ZN8BMenuBar12StartMenuBarElbbP5BRect 7641281cf3SAxel Dörfler #else 7741281cf3SAxel Dörfler # error "You may want to port this ugly hack to your compiler ABI" 7841281cf3SAxel Dörfler #endif 791075cc34SFredrik Holmqvist extern "C" void 801075cc34SFredrik Holmqvist BMenuBar_StartMenuBar_Hack(BMenuBar*, int32, bool, bool, BRect*); 8141281cf3SAxel Dörfler 8241281cf3SAxel Dörfler 8341281cf3SAxel Dörfler TBeMenu* TBarWindow::sBeMenu = NULL; 8441281cf3SAxel Dörfler 8541281cf3SAxel Dörfler 8641281cf3SAxel Dörfler TBarWindow::TBarWindow() 8772f5ac30SAxel Dörfler : 88066522e8SJonas Sundström BWindow(BRect(-1000.0f, -1000.0f, -1000.0f, -1000.0f), 89*560ff447SJonas Sundström B_TRANSLATE_SYSTEM_NAME("Deskbar"), B_BORDERED_WINDOW, 9041281cf3SAxel Dörfler B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_CLOSABLE 9174c7ad20SIngo Weinhold | B_NOT_MINIMIZABLE | B_NOT_MOVABLE | B_NOT_RESIZABLE 9274c7ad20SIngo Weinhold | B_AVOID_FRONT | B_ASYNCHRONOUS_CONTROLS, 9341281cf3SAxel Dörfler B_ALL_WORKSPACES) 9441281cf3SAxel Dörfler { 9541281cf3SAxel Dörfler desk_settings* settings = ((TBarApp*)be_app)->Settings(); 9641281cf3SAxel Dörfler if (settings->alwaysOnTop) 9741281cf3SAxel Dörfler SetFeel(B_FLOATING_ALL_WINDOW_FEEL); 9872f5ac30SAxel Dörfler fBarView = new TBarView(Bounds(), settings->vertical, settings->left, 9972f5ac30SAxel Dörfler settings->top, settings->ampmMode, settings->state, settings->width, 10072f5ac30SAxel Dörfler settings->showTime); 10141281cf3SAxel Dörfler AddChild(fBarView); 10241281cf3SAxel Dörfler 10335c6651cSKarsten Heimrich RemoveShortcut('H', B_COMMAND_KEY | B_CONTROL_KEY); 10441281cf3SAxel Dörfler AddShortcut('F', B_COMMAND_KEY, new BMessage(kFindButton)); 10541281cf3SAxel Dörfler } 10641281cf3SAxel Dörfler 10741281cf3SAxel Dörfler 10841281cf3SAxel Dörfler void 10941281cf3SAxel Dörfler TBarWindow::DispatchMessage(BMessage* message, BHandler* handler) 11041281cf3SAxel Dörfler { 1110a201be4SAxel Dörfler // Activate the window when you click on it (ie. on the tray area, 1120a201be4SAxel Dörfler // the menu part will do this automatically) 113ca9acc20SAxel Dörfler if (message->what == B_MOUSE_DOWN) { 114ca9acc20SAxel Dörfler if (!((TBarApp*)be_app)->Settings()->autoRaise) 11541281cf3SAxel Dörfler Activate(true); 11641281cf3SAxel Dörfler 1174c139440SAxel Dörfler if (_IsFocusMessage(message) 1184c139440SAxel Dörfler && (modifiers() & (B_CONTROL_KEY | B_COMMAND_KEY | B_OPTION_KEY 11959eae96dSAxel Dörfler | B_SHIFT_KEY)) == (B_CONTROL_KEY | B_COMMAND_KEY)) { 120ca9acc20SAxel Dörfler // The window key was pressed - enter dragging code 121ca9acc20SAxel Dörfler fBarView->DragRegion()->MouseDown( 122ca9acc20SAxel Dörfler fBarView->DragRegion()->DragRegion().LeftTop()); 123ca9acc20SAxel Dörfler return; 124ca9acc20SAxel Dörfler } 125ca9acc20SAxel Dörfler } 126ca9acc20SAxel Dörfler 12741281cf3SAxel Dörfler BWindow::DispatchMessage(message, handler); 12841281cf3SAxel Dörfler } 12941281cf3SAxel Dörfler 13041281cf3SAxel Dörfler 13141281cf3SAxel Dörfler void 13241281cf3SAxel Dörfler TBarWindow::MenusBeginning() 13341281cf3SAxel Dörfler { 13441281cf3SAxel Dörfler BPath path; 13541281cf3SAxel Dörfler entry_ref ref; 13641281cf3SAxel Dörfler 13741281cf3SAxel Dörfler find_directory (B_USER_DESKBAR_DIRECTORY, &path); 13841281cf3SAxel Dörfler get_ref_for_path(path.Path(), &ref); 13941281cf3SAxel Dörfler 14041281cf3SAxel Dörfler BEntry entry(&ref, true); 14141281cf3SAxel Dörfler if (entry.InitCheck() == B_OK && entry.IsDirectory()) { 14241281cf3SAxel Dörfler // need the entry_ref to the actual item 14341281cf3SAxel Dörfler entry.GetRef(&ref); 14441281cf3SAxel Dörfler // set the nav directory to the be folder 14541281cf3SAxel Dörfler sBeMenu->SetNavDir(&ref); 14641281cf3SAxel Dörfler } else if (!entry.Exists()) { 14741281cf3SAxel Dörfler // the Be folder does not exist 14841281cf3SAxel Dörfler // create one now 14941281cf3SAxel Dörfler BDirectory dir; 15041281cf3SAxel Dörfler if (entry.GetParent(&dir) == B_OK) { 15141281cf3SAxel Dörfler BDirectory bedir; 15241281cf3SAxel Dörfler dir.CreateDirectory("be", &bedir); 15341281cf3SAxel Dörfler if (bedir.GetEntry(&entry) == B_OK 15441281cf3SAxel Dörfler && entry.GetRef(&ref) == B_OK) 15541281cf3SAxel Dörfler sBeMenu->SetNavDir(&ref); 15641281cf3SAxel Dörfler } 15741281cf3SAxel Dörfler } else { 15841281cf3SAxel Dörfler // this really should never happen 15941281cf3SAxel Dörfler TRESPASS(); 16041281cf3SAxel Dörfler return; 16141281cf3SAxel Dörfler } 16241281cf3SAxel Dörfler 16341281cf3SAxel Dörfler sBeMenu->NeedsToRebuild(); 16441281cf3SAxel Dörfler sBeMenu->ResetTargets(); 16541281cf3SAxel Dörfler 166f8ab4e92SAxel Dörfler fBarView->SetEventMask(0); 167f8ab4e92SAxel Dörfler // This works around a BeOS bug - the menu is quit with every 168f8ab4e92SAxel Dörfler // B_MOUSE_DOWN the window receives... 169f8ab4e92SAxel Dörfler 17041281cf3SAxel Dörfler BWindow::MenusBeginning(); 17141281cf3SAxel Dörfler } 17241281cf3SAxel Dörfler 17341281cf3SAxel Dörfler 17441281cf3SAxel Dörfler void 17541281cf3SAxel Dörfler TBarWindow::MenusEnded() 17641281cf3SAxel Dörfler { 17741281cf3SAxel Dörfler BWindow::MenusEnded(); 17841281cf3SAxel Dörfler 1794446e07aSStefano Ceccherini if (sBeMenu->LockLooper()) { 1803702e473SStephan Aßmus // TODO: is this ok? 1814446e07aSStefano Ceccherini sBeMenu->RemoveItems(0, sBeMenu->CountItems(), true); 1823702e473SStephan Aßmus sBeMenu->UnlockLooper(); 18341281cf3SAxel Dörfler } 184f8ab4e92SAxel Dörfler 185f8ab4e92SAxel Dörfler fBarView->UpdateAutoRaise(); 1864446e07aSStefano Ceccherini } 18741281cf3SAxel Dörfler 18841281cf3SAxel Dörfler 18941281cf3SAxel Dörfler void 19041281cf3SAxel Dörfler TBarWindow::MessageReceived(BMessage* message) 19141281cf3SAxel Dörfler { 19241281cf3SAxel Dörfler switch (message->what) { 19341281cf3SAxel Dörfler case kFindButton: 19441281cf3SAxel Dörfler { 19541281cf3SAxel Dörfler BMessenger tracker(kTrackerSignature); 19641281cf3SAxel Dörfler tracker.SendMessage(message); 19741281cf3SAxel Dörfler break; 19841281cf3SAxel Dörfler } 19941281cf3SAxel Dörfler 20041281cf3SAxel Dörfler case 'gloc': 20141281cf3SAxel Dörfler GetLocation(message); 20241281cf3SAxel Dörfler break; 20341281cf3SAxel Dörfler 20441281cf3SAxel Dörfler case 'sloc': 20541281cf3SAxel Dörfler SetLocation(message); 20641281cf3SAxel Dörfler break; 20741281cf3SAxel Dörfler 20841281cf3SAxel Dörfler case 'gexp': 20941281cf3SAxel Dörfler IsExpanded(message); 21041281cf3SAxel Dörfler break; 21141281cf3SAxel Dörfler 21241281cf3SAxel Dörfler case 'sexp': 21341281cf3SAxel Dörfler Expand(message); 21441281cf3SAxel Dörfler break; 21541281cf3SAxel Dörfler 21641281cf3SAxel Dörfler case 'info': 21741281cf3SAxel Dörfler ItemInfo(message); 21841281cf3SAxel Dörfler break; 21941281cf3SAxel Dörfler 22041281cf3SAxel Dörfler case 'exst': 22141281cf3SAxel Dörfler ItemExists(message); 22241281cf3SAxel Dörfler break; 22341281cf3SAxel Dörfler 22441281cf3SAxel Dörfler case 'cwnt': 22541281cf3SAxel Dörfler CountItems(message); 22641281cf3SAxel Dörfler break; 22741281cf3SAxel Dörfler 22841281cf3SAxel Dörfler case 'adon': 22941281cf3SAxel Dörfler case 'icon': 23041281cf3SAxel Dörfler AddItem(message); 23141281cf3SAxel Dörfler break; 23241281cf3SAxel Dörfler 23341281cf3SAxel Dörfler case 'remv': 23441281cf3SAxel Dörfler RemoveItem(message); 23541281cf3SAxel Dörfler break; 23641281cf3SAxel Dörfler 23741281cf3SAxel Dörfler case 'iloc': 23841281cf3SAxel Dörfler GetIconFrame(message); 23941281cf3SAxel Dörfler break; 24041281cf3SAxel Dörfler 24141281cf3SAxel Dörfler default: 24241281cf3SAxel Dörfler BWindow::MessageReceived(message); 24341281cf3SAxel Dörfler break; 24441281cf3SAxel Dörfler } 24541281cf3SAxel Dörfler } 24641281cf3SAxel Dörfler 24741281cf3SAxel Dörfler 24841281cf3SAxel Dörfler void 2495b576468SAxel Dörfler TBarWindow::Minimize(bool minimize) 2505b576468SAxel Dörfler { 2515b576468SAxel Dörfler // Don't allow the Deskbar to be minimized 2525b576468SAxel Dörfler if (!minimize) 2535b576468SAxel Dörfler BWindow::Minimize(false); 2545b576468SAxel Dörfler } 2555b576468SAxel Dörfler 2565b576468SAxel Dörfler 2575b576468SAxel Dörfler void 25841281cf3SAxel Dörfler TBarWindow::SaveSettings() 25941281cf3SAxel Dörfler { 26041281cf3SAxel Dörfler fBarView->SaveSettings(); 26141281cf3SAxel Dörfler } 26241281cf3SAxel Dörfler 26341281cf3SAxel Dörfler 26441281cf3SAxel Dörfler bool 26541281cf3SAxel Dörfler TBarWindow::QuitRequested() 26641281cf3SAxel Dörfler { 26741281cf3SAxel Dörfler be_app->PostMessage(B_QUIT_REQUESTED); 26841281cf3SAxel Dörfler 26941281cf3SAxel Dörfler return BWindow::QuitRequested(); 27041281cf3SAxel Dörfler } 27141281cf3SAxel Dörfler 27241281cf3SAxel Dörfler 27341281cf3SAxel Dörfler void 27441281cf3SAxel Dörfler TBarWindow::WorkspaceActivated(int32 workspace, bool active) 27541281cf3SAxel Dörfler { 27641281cf3SAxel Dörfler BWindow::WorkspaceActivated(workspace, active); 27741281cf3SAxel Dörfler 27841281cf3SAxel Dörfler if (active && !(fBarView->Expando() && fBarView->Vertical())) 27941281cf3SAxel Dörfler fBarView->UpdatePlacement(); 28041281cf3SAxel Dörfler else { 28141281cf3SAxel Dörfler BRect screenFrame = (BScreen(fBarView->Window())).Frame(); 28241281cf3SAxel Dörfler fBarView->SizeWindow(screenFrame); 28341281cf3SAxel Dörfler fBarView->PositionWindow(screenFrame); 28441281cf3SAxel Dörfler fBarView->Invalidate(); 28541281cf3SAxel Dörfler } 28641281cf3SAxel Dörfler } 28741281cf3SAxel Dörfler 28841281cf3SAxel Dörfler 28941281cf3SAxel Dörfler void 29041281cf3SAxel Dörfler TBarWindow::ScreenChanged(BRect size, color_space depth) 29141281cf3SAxel Dörfler { 29241281cf3SAxel Dörfler BWindow::ScreenChanged(size, depth); 29341281cf3SAxel Dörfler 29441281cf3SAxel Dörfler fBarView->UpdatePlacement(); 29541281cf3SAxel Dörfler } 29641281cf3SAxel Dörfler 29741281cf3SAxel Dörfler 29841281cf3SAxel Dörfler void 29941281cf3SAxel Dörfler TBarWindow::SetBeMenu(TBeMenu* menu) 30041281cf3SAxel Dörfler { 30141281cf3SAxel Dörfler sBeMenu = menu; 30241281cf3SAxel Dörfler } 30341281cf3SAxel Dörfler 30441281cf3SAxel Dörfler 30541281cf3SAxel Dörfler TBeMenu* 30641281cf3SAxel Dörfler TBarWindow::BeMenu() 30741281cf3SAxel Dörfler { 30841281cf3SAxel Dörfler return sBeMenu; 30941281cf3SAxel Dörfler } 31041281cf3SAxel Dörfler 31141281cf3SAxel Dörfler 31241281cf3SAxel Dörfler void 31341281cf3SAxel Dörfler TBarWindow::ShowBeMenu() 31441281cf3SAxel Dörfler { 31541281cf3SAxel Dörfler BMenuBar* menuBar = fBarView->BarMenuBar(); 31641281cf3SAxel Dörfler if (menuBar == NULL) 31741281cf3SAxel Dörfler menuBar = KeyMenuBar(); 31841281cf3SAxel Dörfler 31941281cf3SAxel Dörfler if (menuBar == NULL) 32041281cf3SAxel Dörfler return; 32141281cf3SAxel Dörfler 3224a71b881SAxel Dörfler BMenuBar_StartMenuBar_Hack(menuBar, 0, true, true, NULL); 32341281cf3SAxel Dörfler } 32441281cf3SAxel Dörfler 32541281cf3SAxel Dörfler 32641281cf3SAxel Dörfler void 32741281cf3SAxel Dörfler TBarWindow::ShowTeamMenu() 32841281cf3SAxel Dörfler { 32941281cf3SAxel Dörfler int32 index = 0; 33041281cf3SAxel Dörfler if (fBarView->BarMenuBar() == NULL) 33141281cf3SAxel Dörfler index = 2; 33241281cf3SAxel Dörfler 33341281cf3SAxel Dörfler if (KeyMenuBar() == NULL) 33441281cf3SAxel Dörfler return; 33541281cf3SAxel Dörfler 3364a71b881SAxel Dörfler BMenuBar_StartMenuBar_Hack(KeyMenuBar(), index, true, true, NULL); 33741281cf3SAxel Dörfler } 33841281cf3SAxel Dörfler 33941281cf3SAxel Dörfler 3401075cc34SFredrik Holmqvist // determines the actual location of the window 34141281cf3SAxel Dörfler 34241281cf3SAxel Dörfler deskbar_location 34341281cf3SAxel Dörfler TBarWindow::DeskbarLocation() const 34441281cf3SAxel Dörfler { 34541281cf3SAxel Dörfler bool left = fBarView->Left(); 34641281cf3SAxel Dörfler bool top = fBarView->Top(); 34741281cf3SAxel Dörfler 34841281cf3SAxel Dörfler if (fBarView->AcrossTop()) 34941281cf3SAxel Dörfler return B_DESKBAR_TOP; 35041281cf3SAxel Dörfler 35141281cf3SAxel Dörfler if (fBarView->AcrossBottom()) 35241281cf3SAxel Dörfler return B_DESKBAR_BOTTOM; 35341281cf3SAxel Dörfler 35441281cf3SAxel Dörfler if (left && top) 35541281cf3SAxel Dörfler return B_DESKBAR_LEFT_TOP; 35641281cf3SAxel Dörfler 35741281cf3SAxel Dörfler if (!left && top) 35841281cf3SAxel Dörfler return B_DESKBAR_RIGHT_TOP; 35941281cf3SAxel Dörfler 36041281cf3SAxel Dörfler if (left && !top) 36141281cf3SAxel Dörfler return B_DESKBAR_LEFT_BOTTOM; 36241281cf3SAxel Dörfler 36341281cf3SAxel Dörfler return B_DESKBAR_RIGHT_BOTTOM; 36441281cf3SAxel Dörfler } 36541281cf3SAxel Dörfler 36641281cf3SAxel Dörfler 36741281cf3SAxel Dörfler void 36841281cf3SAxel Dörfler TBarWindow::GetLocation(BMessage* message) 36941281cf3SAxel Dörfler { 37041281cf3SAxel Dörfler BMessage reply('rply'); 37141281cf3SAxel Dörfler reply.AddInt32("location", (int32)DeskbarLocation()); 37241281cf3SAxel Dörfler reply.AddBool("expanded", fBarView->Expando()); 37341281cf3SAxel Dörfler 37441281cf3SAxel Dörfler message->SendReply(&reply); 37541281cf3SAxel Dörfler } 37641281cf3SAxel Dörfler 37741281cf3SAxel Dörfler 37841281cf3SAxel Dörfler void 37941281cf3SAxel Dörfler TBarWindow::SetDeskbarLocation(deskbar_location location, bool newExpandState) 38041281cf3SAxel Dörfler { 38141281cf3SAxel Dörfler // left top and right top are the only two that 38241281cf3SAxel Dörfler // currently pay attention to expand, ignore for all others 38341281cf3SAxel Dörfler 38441281cf3SAxel Dörfler bool left = false, top = true, vertical, expand; 38541281cf3SAxel Dörfler 38641281cf3SAxel Dörfler switch (location) { 38741281cf3SAxel Dörfler case B_DESKBAR_TOP: 38841281cf3SAxel Dörfler left = true; 38941281cf3SAxel Dörfler top = true; 39041281cf3SAxel Dörfler vertical = false; 39141281cf3SAxel Dörfler expand = true; 39241281cf3SAxel Dörfler break; 39341281cf3SAxel Dörfler 39441281cf3SAxel Dörfler case B_DESKBAR_BOTTOM: 39541281cf3SAxel Dörfler left = true; 39641281cf3SAxel Dörfler top = false; 39741281cf3SAxel Dörfler vertical = false; 39841281cf3SAxel Dörfler expand = true; 39941281cf3SAxel Dörfler break; 40041281cf3SAxel Dörfler 40141281cf3SAxel Dörfler case B_DESKBAR_LEFT_TOP: 40241281cf3SAxel Dörfler left = true; 40341281cf3SAxel Dörfler top = true; 40441281cf3SAxel Dörfler vertical = true; 40541281cf3SAxel Dörfler expand = newExpandState; 40641281cf3SAxel Dörfler break; 40741281cf3SAxel Dörfler 40841281cf3SAxel Dörfler case B_DESKBAR_RIGHT_TOP: 40941281cf3SAxel Dörfler left = false; 41041281cf3SAxel Dörfler top = true; 41141281cf3SAxel Dörfler vertical = true; 41241281cf3SAxel Dörfler expand = newExpandState; 41341281cf3SAxel Dörfler break; 41441281cf3SAxel Dörfler 41541281cf3SAxel Dörfler case B_DESKBAR_LEFT_BOTTOM: 41641281cf3SAxel Dörfler left = true; 41741281cf3SAxel Dörfler top = false; 41841281cf3SAxel Dörfler vertical = true; 41941281cf3SAxel Dörfler expand = false; 42041281cf3SAxel Dörfler break; 42141281cf3SAxel Dörfler 42241281cf3SAxel Dörfler case B_DESKBAR_RIGHT_BOTTOM: 42341281cf3SAxel Dörfler left = false; 42441281cf3SAxel Dörfler top = false; 42541281cf3SAxel Dörfler vertical = true; 42641281cf3SAxel Dörfler expand = false; 42741281cf3SAxel Dörfler break; 42841281cf3SAxel Dörfler 42941281cf3SAxel Dörfler default: 43041281cf3SAxel Dörfler left = true; 43141281cf3SAxel Dörfler top = true; 43241281cf3SAxel Dörfler vertical = false; 43341281cf3SAxel Dörfler expand = true; 43441281cf3SAxel Dörfler break; 43541281cf3SAxel Dörfler } 43641281cf3SAxel Dörfler 43741281cf3SAxel Dörfler fBarView->ChangeState(expand, vertical, left, top); 43841281cf3SAxel Dörfler } 43941281cf3SAxel Dörfler 4405b576468SAxel Dörfler 44141281cf3SAxel Dörfler void 44241281cf3SAxel Dörfler TBarWindow::SetLocation(BMessage* message) 44341281cf3SAxel Dörfler { 44441281cf3SAxel Dörfler deskbar_location location; 44541281cf3SAxel Dörfler bool expand; 44641281cf3SAxel Dörfler if (message->FindInt32("location", (int32*)&location) == B_OK 44741281cf3SAxel Dörfler && message->FindBool("expand", &expand) == B_OK) 44841281cf3SAxel Dörfler SetDeskbarLocation(location, expand); 44941281cf3SAxel Dörfler } 45041281cf3SAxel Dörfler 45141281cf3SAxel Dörfler 45241281cf3SAxel Dörfler void 45341281cf3SAxel Dörfler TBarWindow::IsExpanded(BMessage* message) 45441281cf3SAxel Dörfler { 45541281cf3SAxel Dörfler BMessage reply('rply'); 45641281cf3SAxel Dörfler reply.AddBool("expanded", fBarView->Expando()); 45741281cf3SAxel Dörfler message->SendReply(&reply); 45841281cf3SAxel Dörfler } 45941281cf3SAxel Dörfler 46041281cf3SAxel Dörfler 46141281cf3SAxel Dörfler void 46241281cf3SAxel Dörfler TBarWindow::Expand(BMessage* message) 46341281cf3SAxel Dörfler { 46441281cf3SAxel Dörfler bool expand; 46541281cf3SAxel Dörfler if (message->FindBool("expand", &expand) == B_OK) { 46641281cf3SAxel Dörfler bool vertical = fBarView->Vertical(); 46741281cf3SAxel Dörfler bool left = fBarView->Left(); 46841281cf3SAxel Dörfler bool top = fBarView->Top(); 46941281cf3SAxel Dörfler fBarView->ChangeState(expand, vertical, left, top); 47041281cf3SAxel Dörfler } 47141281cf3SAxel Dörfler } 47241281cf3SAxel Dörfler 47341281cf3SAxel Dörfler 47441281cf3SAxel Dörfler void 47541281cf3SAxel Dörfler TBarWindow::ItemInfo(BMessage* message) 47641281cf3SAxel Dörfler { 47741281cf3SAxel Dörfler BMessage replyMsg; 47841281cf3SAxel Dörfler const char* name; 47941281cf3SAxel Dörfler int32 id; 48041281cf3SAxel Dörfler DeskbarShelf shelf; 48141281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) { 48241281cf3SAxel Dörfler if (fBarView->ItemInfo(id, &name, &shelf) == B_OK) { 48341281cf3SAxel Dörfler replyMsg.AddString("name", name); 48441281cf3SAxel Dörfler #if SHELF_AWARE 48541281cf3SAxel Dörfler replyMsg.AddInt32("shelf", (int32)shelf); 48641281cf3SAxel Dörfler #endif 48741281cf3SAxel Dörfler } 48841281cf3SAxel Dörfler } else if (message->FindString("name", &name) == B_OK) { 48941281cf3SAxel Dörfler if (fBarView->ItemInfo(name, &id, &shelf) == B_OK) { 49041281cf3SAxel Dörfler replyMsg.AddInt32("id", id); 49141281cf3SAxel Dörfler #if SHELF_AWARE 49241281cf3SAxel Dörfler replyMsg.AddInt32("shelf", (int32)shelf); 49341281cf3SAxel Dörfler #endif 49441281cf3SAxel Dörfler } 49541281cf3SAxel Dörfler } 49641281cf3SAxel Dörfler 49741281cf3SAxel Dörfler message->SendReply(&replyMsg); 49841281cf3SAxel Dörfler } 49941281cf3SAxel Dörfler 50041281cf3SAxel Dörfler 50141281cf3SAxel Dörfler void 50241281cf3SAxel Dörfler TBarWindow::ItemExists(BMessage* message) 50341281cf3SAxel Dörfler { 50441281cf3SAxel Dörfler BMessage replyMsg; 50541281cf3SAxel Dörfler const char* name; 50641281cf3SAxel Dörfler int32 id; 50741281cf3SAxel Dörfler DeskbarShelf shelf; 50841281cf3SAxel Dörfler 50941281cf3SAxel Dörfler #if SHELF_AWARE 51041281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) != B_OK) 51141281cf3SAxel Dörfler #endif 51241281cf3SAxel Dörfler shelf = B_DESKBAR_TRAY; 51341281cf3SAxel Dörfler 51441281cf3SAxel Dörfler bool exists = false; 51541281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) 51641281cf3SAxel Dörfler exists = fBarView->ItemExists(id, shelf); 51741281cf3SAxel Dörfler else if (message->FindString("name", &name) == B_OK) 51841281cf3SAxel Dörfler exists = fBarView->ItemExists(name, shelf); 51941281cf3SAxel Dörfler 52041281cf3SAxel Dörfler replyMsg.AddBool("exists", exists); 52141281cf3SAxel Dörfler message->SendReply(&replyMsg); 52241281cf3SAxel Dörfler } 52341281cf3SAxel Dörfler 52441281cf3SAxel Dörfler 52541281cf3SAxel Dörfler void 52641281cf3SAxel Dörfler TBarWindow::CountItems(BMessage* message) 52741281cf3SAxel Dörfler { 52841281cf3SAxel Dörfler DeskbarShelf shelf; 52941281cf3SAxel Dörfler 53041281cf3SAxel Dörfler #if SHELF_AWARE 53141281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) != B_OK) 53241281cf3SAxel Dörfler #endif 53341281cf3SAxel Dörfler shelf = B_DESKBAR_TRAY; 53441281cf3SAxel Dörfler 53541281cf3SAxel Dörfler BMessage reply('rply'); 53641281cf3SAxel Dörfler reply.AddInt32("count", fBarView->CountItems(shelf)); 53741281cf3SAxel Dörfler message->SendReply(&reply); 53841281cf3SAxel Dörfler } 53941281cf3SAxel Dörfler 54041281cf3SAxel Dörfler 54141281cf3SAxel Dörfler void 54241281cf3SAxel Dörfler TBarWindow::AddItem(BMessage* message) 54341281cf3SAxel Dörfler { 54441281cf3SAxel Dörfler DeskbarShelf shelf; 54541281cf3SAxel Dörfler entry_ref ref; 54641281cf3SAxel Dörfler int32 id = 999; 54741281cf3SAxel Dörfler BMessage reply; 54841281cf3SAxel Dörfler status_t err = B_ERROR; 54941281cf3SAxel Dörfler 55041281cf3SAxel Dörfler BMessage archivedView; 55141281cf3SAxel Dörfler if (message->FindMessage("view", &archivedView) == B_OK) { 55241281cf3SAxel Dörfler #if SHELF_AWARE 55341281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) != B_OK) 55441281cf3SAxel Dörfler #endif 55541281cf3SAxel Dörfler shelf = B_DESKBAR_TRAY; 55641281cf3SAxel Dörfler 557ced3755cSAxel Dörfler BMessage* archive = new BMessage(archivedView); 558ced3755cSAxel Dörfler err = fBarView->AddItem(archive, shelf, &id); 559ced3755cSAxel Dörfler if (err < B_OK) 560ced3755cSAxel Dörfler delete archive; 56141281cf3SAxel Dörfler } else if (message->FindRef("addon", &ref) == B_OK) { 56241281cf3SAxel Dörfler // exposing the name of the view here is not so great 56371bd3ba5SJonas Sundström TReplicantTray* tray 56471bd3ba5SJonas Sundström = dynamic_cast<TReplicantTray*>(FindView("Status")); 56541281cf3SAxel Dörfler if (tray) { 56641281cf3SAxel Dörfler // Force this into the deskbar even if the security code is wrong 56741281cf3SAxel Dörfler // This is OK because the user specifically asked for this replicant 56841281cf3SAxel Dörfler BEntry entry(&ref); 56941281cf3SAxel Dörfler err = tray->LoadAddOn(&entry, &id, true); 57041281cf3SAxel Dörfler } 57141281cf3SAxel Dörfler } 57241281cf3SAxel Dörfler 57341281cf3SAxel Dörfler if (err == B_OK) 57441281cf3SAxel Dörfler reply.AddInt32("id", id); 57541281cf3SAxel Dörfler else 57641281cf3SAxel Dörfler reply.AddInt32("error", err); 57741281cf3SAxel Dörfler 57841281cf3SAxel Dörfler message->SendReply(&reply); 57941281cf3SAxel Dörfler } 58041281cf3SAxel Dörfler 58141281cf3SAxel Dörfler 58241281cf3SAxel Dörfler void 58341281cf3SAxel Dörfler TBarWindow::RemoveItem(BMessage* message) 58441281cf3SAxel Dörfler { 58541281cf3SAxel Dörfler int32 id; 58641281cf3SAxel Dörfler const char* name; 58741281cf3SAxel Dörfler 58841281cf3SAxel Dörfler // ids ought to be unique across all shelves, assuming, of course, 58941281cf3SAxel Dörfler // that sometime in the future there may be more than one 59041281cf3SAxel Dörfler #if SHELF_AWARE 59141281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) == B_OK) { 59241281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK) 59341281cf3SAxel Dörfler fBarView->RemoveItem(name, shelf); 59441281cf3SAxel Dörfler } else { 59541281cf3SAxel Dörfler #endif 59641281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) { 59741281cf3SAxel Dörfler fBarView->RemoveItem(id); 59841281cf3SAxel Dörfler // remove the following two lines if and when the 59941281cf3SAxel Dörfler // shelf option returns 60041281cf3SAxel Dörfler } else if (message->FindString("name", &name) == B_OK) 60141281cf3SAxel Dörfler fBarView->RemoveItem(name, B_DESKBAR_TRAY); 60241281cf3SAxel Dörfler 60341281cf3SAxel Dörfler #if SHELF_AWARE 60441281cf3SAxel Dörfler } 60541281cf3SAxel Dörfler #endif 60641281cf3SAxel Dörfler } 60741281cf3SAxel Dörfler 60841281cf3SAxel Dörfler 60941281cf3SAxel Dörfler void 61041281cf3SAxel Dörfler TBarWindow::GetIconFrame(BMessage* message) 61141281cf3SAxel Dörfler { 61241281cf3SAxel Dörfler BRect frame(0, 0, 0, 0); 61341281cf3SAxel Dörfler 61441281cf3SAxel Dörfler const char* name; 61541281cf3SAxel Dörfler int32 id; 61641281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) 61741281cf3SAxel Dörfler frame = fBarView->IconFrame(id); 61841281cf3SAxel Dörfler else if (message->FindString("name", &name) == B_OK) 61941281cf3SAxel Dörfler frame = fBarView->IconFrame(name); 62041281cf3SAxel Dörfler 62141281cf3SAxel Dörfler BMessage reply('rply'); 62241281cf3SAxel Dörfler reply.AddRect("frame", frame); 62341281cf3SAxel Dörfler message->SendReply(&reply); 62441281cf3SAxel Dörfler } 62571bd3ba5SJonas Sundström 6264c139440SAxel Dörfler 6274c139440SAxel Dörfler bool 6284c139440SAxel Dörfler TBarWindow::_IsFocusMessage(BMessage* message) 6294c139440SAxel Dörfler { 6304c139440SAxel Dörfler BMessage::Private messagePrivate(message); 6314c139440SAxel Dörfler if (!messagePrivate.UsePreferredTarget()) 6324c139440SAxel Dörfler return false; 6334c139440SAxel Dörfler 6344c139440SAxel Dörfler bool feedFocus; 6354c139440SAxel Dörfler if (message->HasInt32("_token") 6364c139440SAxel Dörfler && (message->FindBool("_feed_focus", &feedFocus) != B_OK || !feedFocus)) 6374c139440SAxel Dörfler return false; 6384c139440SAxel Dörfler 6394c139440SAxel Dörfler return true; 6404c139440SAxel Dörfler } 6411075cc34SFredrik Holmqvist 642