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 2941281cf3SAxel Dörfler Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 3041281cf3SAxel Dörfler of Be Incorporated in the United States and other countries. Other brand product 3141281cf3SAxel Dörfler names are registered trademarks or trademarks of their respective holders. 3241281cf3SAxel Dörfler All rights reserved. 3341281cf3SAxel Dörfler */ 3441281cf3SAxel Dörfler 3541281cf3SAxel Dörfler #include <stdio.h> 3641281cf3SAxel Dörfler #include <Application.h> 3741281cf3SAxel Dörfler #include <Directory.h> 3841281cf3SAxel Dörfler #include <FindDirectory.h> 3941281cf3SAxel Dörfler #include <Path.h> 4041281cf3SAxel Dörfler #include <Debug.h> 4141281cf3SAxel Dörfler #include <File.h> 4241281cf3SAxel Dörfler #include <MenuItem.h> 4341281cf3SAxel Dörfler #include <MessageFilter.h> 4441281cf3SAxel Dörfler #include <Screen.h> 4541281cf3SAxel Dörfler 4641281cf3SAxel Dörfler #include "BarWindow.h" 4741281cf3SAxel Dörfler #include "BarApp.h" 4841281cf3SAxel Dörfler #include "BarMenuBar.h" 4941281cf3SAxel Dörfler #include "BarView.h" 5041281cf3SAxel Dörfler #include "BeMenu.h" 5141281cf3SAxel Dörfler #include "PublicCommands.h" 5241281cf3SAxel Dörfler #include "StatusView.h" 5341281cf3SAxel Dörfler #include "tracker_private.h" 5441281cf3SAxel Dörfler 5541281cf3SAxel Dörfler 5641281cf3SAxel Dörfler // This is a very ugly hack to be able to call the private BMenuBar::StartMenuBar() 5741281cf3SAxel Dörfler // method from the TBarWindow::ShowBeMenu() method. 5841281cf3SAxel Dörfler // Don't do this at home -- but why the hell is this method private? 5941281cf3SAxel Dörfler #if __MWERKS__ 60*4a71b881SAxel Dörfler #define BMenuBar_StartMenuBar_Hack StartMenuBar__8BMenuBarFlbbP5BRect 61*4a71b881SAxel Dörfler #elif __GNUC__ <= 2 62*4a71b881SAxel Dörfler #define BMenuBar_StartMenuBar_Hack StartMenuBar__8BMenuBarlbT2P5BRect 63*4a71b881SAxel Dörfler #elif __GNUC__ > 2 64*4a71b881SAxel Dörfler #define BMenuBar_StartMenuBar_Hack _ZN8BMenuBar12StartMenuBarElbbP5BRect 6541281cf3SAxel Dörfler #else 6641281cf3SAxel Dörfler # error "You may want to port this ugly hack to your compiler ABI" 6741281cf3SAxel Dörfler #endif 68*4a71b881SAxel Dörfler extern "C" void BMenuBar_StartMenuBar_Hack(BMenuBar *,int32,bool,bool,BRect *); 6941281cf3SAxel Dörfler 7041281cf3SAxel Dörfler 7141281cf3SAxel Dörfler TBeMenu *TBarWindow::sBeMenu = NULL; 7241281cf3SAxel Dörfler 7341281cf3SAxel Dörfler 7441281cf3SAxel Dörfler TBarWindow::TBarWindow() 7541281cf3SAxel Dörfler : BWindow(BRect(-1000.0f, -1000.0f, -1000.0f, -1000.0f), "Deskbar", 7641281cf3SAxel Dörfler B_BORDERED_WINDOW, 7741281cf3SAxel Dörfler B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_CLOSABLE 7841281cf3SAxel Dörfler | B_NOT_MOVABLE | B_AVOID_FRONT | B_ASYNCHRONOUS_CONTROLS, 7941281cf3SAxel Dörfler B_ALL_WORKSPACES) 8041281cf3SAxel Dörfler { 8141281cf3SAxel Dörfler desk_settings *settings = ((TBarApp *)be_app)->Settings(); 8241281cf3SAxel Dörfler if (settings->alwaysOnTop) 8341281cf3SAxel Dörfler SetFeel(B_FLOATING_ALL_WINDOW_FEEL); 8441281cf3SAxel Dörfler fBarView = new TBarView(Bounds(), settings->vertical,settings->left, settings->top, 8541281cf3SAxel Dörfler settings->ampmMode, settings->state, settings->width, settings->showTime); 8641281cf3SAxel Dörfler AddChild(fBarView); 8741281cf3SAxel Dörfler 8841281cf3SAxel Dörfler AddShortcut('F', B_COMMAND_KEY, new BMessage(kFindButton)); 8941281cf3SAxel Dörfler #if SA_CLOCK 9041281cf3SAxel Dörfler AddShortcut('H', B_COMMAND_KEY, new BMessage('clok')); 9141281cf3SAxel Dörfler #endif 9241281cf3SAxel Dörfler } 9341281cf3SAxel Dörfler 9441281cf3SAxel Dörfler 9541281cf3SAxel Dörfler void 9641281cf3SAxel Dörfler TBarWindow::DispatchMessage(BMessage *message, BHandler *handler) 9741281cf3SAxel Dörfler { 9841281cf3SAxel Dörfler // ToDo: check if the two following lines are doing anything... 9941281cf3SAxel Dörfler if (message->what == B_MOUSE_DOWN) 10041281cf3SAxel Dörfler Activate(true); 10141281cf3SAxel Dörfler 10241281cf3SAxel Dörfler BWindow::DispatchMessage(message, handler); 10341281cf3SAxel Dörfler } 10441281cf3SAxel Dörfler 10541281cf3SAxel Dörfler 10641281cf3SAxel Dörfler void 10741281cf3SAxel Dörfler TBarWindow::MenusBeginning() 10841281cf3SAxel Dörfler { 10941281cf3SAxel Dörfler BPath path; 11041281cf3SAxel Dörfler entry_ref ref; 11141281cf3SAxel Dörfler 11241281cf3SAxel Dörfler find_directory (B_USER_DESKBAR_DIRECTORY, &path); 11341281cf3SAxel Dörfler get_ref_for_path(path.Path(), &ref); 11441281cf3SAxel Dörfler 11541281cf3SAxel Dörfler BEntry entry(&ref, true); 11641281cf3SAxel Dörfler if (entry.InitCheck() == B_OK && entry.IsDirectory()) { 11741281cf3SAxel Dörfler // need the entry_ref to the actual item 11841281cf3SAxel Dörfler entry.GetRef(&ref); 11941281cf3SAxel Dörfler // set the nav directory to the be folder 12041281cf3SAxel Dörfler sBeMenu->SetNavDir(&ref); 12141281cf3SAxel Dörfler } else if (!entry.Exists()) { 12241281cf3SAxel Dörfler // the Be folder does not exist 12341281cf3SAxel Dörfler // create one now 12441281cf3SAxel Dörfler BDirectory dir; 12541281cf3SAxel Dörfler if (entry.GetParent(&dir) == B_OK) { 12641281cf3SAxel Dörfler BDirectory bedir; 12741281cf3SAxel Dörfler dir.CreateDirectory("be", &bedir); 12841281cf3SAxel Dörfler if (bedir.GetEntry(&entry) == B_OK 12941281cf3SAxel Dörfler && entry.GetRef(&ref) == B_OK) 13041281cf3SAxel Dörfler sBeMenu->SetNavDir(&ref); 13141281cf3SAxel Dörfler } 13241281cf3SAxel Dörfler } else { 13341281cf3SAxel Dörfler // this really should never happen 13441281cf3SAxel Dörfler TRESPASS(); 13541281cf3SAxel Dörfler return; 13641281cf3SAxel Dörfler } 13741281cf3SAxel Dörfler 13841281cf3SAxel Dörfler sBeMenu->NeedsToRebuild(); 13941281cf3SAxel Dörfler sBeMenu->ResetTargets(); 14041281cf3SAxel Dörfler 14141281cf3SAxel Dörfler BWindow::MenusBeginning(); 14241281cf3SAxel Dörfler } 14341281cf3SAxel Dörfler 14441281cf3SAxel Dörfler 14541281cf3SAxel Dörfler void 14641281cf3SAxel Dörfler TBarWindow::MenusEnded() 14741281cf3SAxel Dörfler { 14841281cf3SAxel Dörfler BWindow::MenusEnded(); 14941281cf3SAxel Dörfler 15041281cf3SAxel Dörfler BMenuItem *item = NULL; 15141281cf3SAxel Dörfler while ((item = sBeMenu->RemoveItem((int32)0)) != NULL) 15241281cf3SAxel Dörfler delete item; 15341281cf3SAxel Dörfler } 15441281cf3SAxel Dörfler 15541281cf3SAxel Dörfler 15641281cf3SAxel Dörfler void 15741281cf3SAxel Dörfler TBarWindow::MessageReceived(BMessage *message) 15841281cf3SAxel Dörfler { 15941281cf3SAxel Dörfler switch (message->what) { 16041281cf3SAxel Dörfler case kFindButton: 16141281cf3SAxel Dörfler { 16241281cf3SAxel Dörfler BMessenger tracker(kTrackerSignature); 16341281cf3SAxel Dörfler tracker.SendMessage(message); 16441281cf3SAxel Dörfler break; 16541281cf3SAxel Dörfler } 16641281cf3SAxel Dörfler 16741281cf3SAxel Dörfler #if SA_CLOCK 16841281cf3SAxel Dörfler case 'clok': 16941281cf3SAxel Dörfler fBarView->ToggleClock(); 17041281cf3SAxel Dörfler break; 17141281cf3SAxel Dörfler #endif 17241281cf3SAxel Dörfler 17341281cf3SAxel Dörfler case 'gloc': 17441281cf3SAxel Dörfler GetLocation(message); 17541281cf3SAxel Dörfler break; 17641281cf3SAxel Dörfler 17741281cf3SAxel Dörfler case 'sloc': 17841281cf3SAxel Dörfler SetLocation(message); 17941281cf3SAxel Dörfler break; 18041281cf3SAxel Dörfler 18141281cf3SAxel Dörfler case 'gexp': 18241281cf3SAxel Dörfler IsExpanded(message); 18341281cf3SAxel Dörfler break; 18441281cf3SAxel Dörfler 18541281cf3SAxel Dörfler case 'sexp': 18641281cf3SAxel Dörfler Expand(message); 18741281cf3SAxel Dörfler break; 18841281cf3SAxel Dörfler 18941281cf3SAxel Dörfler case 'info': 19041281cf3SAxel Dörfler ItemInfo(message); 19141281cf3SAxel Dörfler break; 19241281cf3SAxel Dörfler 19341281cf3SAxel Dörfler case 'exst': 19441281cf3SAxel Dörfler ItemExists(message); 19541281cf3SAxel Dörfler break; 19641281cf3SAxel Dörfler 19741281cf3SAxel Dörfler case 'cwnt': 19841281cf3SAxel Dörfler CountItems(message); 19941281cf3SAxel Dörfler break; 20041281cf3SAxel Dörfler 20141281cf3SAxel Dörfler case 'adon': 20241281cf3SAxel Dörfler case 'icon': 20341281cf3SAxel Dörfler AddItem(message); 20441281cf3SAxel Dörfler break; 20541281cf3SAxel Dörfler 20641281cf3SAxel Dörfler case 'remv': 20741281cf3SAxel Dörfler RemoveItem(message); 20841281cf3SAxel Dörfler break; 20941281cf3SAxel Dörfler 21041281cf3SAxel Dörfler case 'iloc': 21141281cf3SAxel Dörfler GetIconFrame(message); 21241281cf3SAxel Dörfler break; 21341281cf3SAxel Dörfler 21441281cf3SAxel Dörfler default: 21541281cf3SAxel Dörfler BWindow::MessageReceived(message); 21641281cf3SAxel Dörfler break; 21741281cf3SAxel Dörfler } 21841281cf3SAxel Dörfler } 21941281cf3SAxel Dörfler 22041281cf3SAxel Dörfler 22141281cf3SAxel Dörfler void 22241281cf3SAxel Dörfler TBarWindow::SaveSettings() 22341281cf3SAxel Dörfler { 22441281cf3SAxel Dörfler fBarView->SaveSettings(); 22541281cf3SAxel Dörfler } 22641281cf3SAxel Dörfler 22741281cf3SAxel Dörfler 22841281cf3SAxel Dörfler bool 22941281cf3SAxel Dörfler TBarWindow::QuitRequested() 23041281cf3SAxel Dörfler { 23141281cf3SAxel Dörfler be_app->PostMessage(B_QUIT_REQUESTED); 23241281cf3SAxel Dörfler 23341281cf3SAxel Dörfler return BWindow::QuitRequested(); 23441281cf3SAxel Dörfler } 23541281cf3SAxel Dörfler 23641281cf3SAxel Dörfler 23741281cf3SAxel Dörfler void 23841281cf3SAxel Dörfler TBarWindow::WorkspaceActivated(int32 workspace, bool active) 23941281cf3SAxel Dörfler { 24041281cf3SAxel Dörfler BWindow::WorkspaceActivated(workspace, active); 24141281cf3SAxel Dörfler 24241281cf3SAxel Dörfler if (active && !(fBarView->Expando() && fBarView->Vertical())) 24341281cf3SAxel Dörfler fBarView->UpdatePlacement(); 24441281cf3SAxel Dörfler else { 24541281cf3SAxel Dörfler BRect screenFrame = (BScreen(fBarView->Window())).Frame(); 24641281cf3SAxel Dörfler fBarView->SizeWindow(screenFrame); 24741281cf3SAxel Dörfler fBarView->PositionWindow(screenFrame); 24841281cf3SAxel Dörfler fBarView->Invalidate(); 24941281cf3SAxel Dörfler } 25041281cf3SAxel Dörfler } 25141281cf3SAxel Dörfler 25241281cf3SAxel Dörfler 25341281cf3SAxel Dörfler void 25441281cf3SAxel Dörfler TBarWindow::ScreenChanged(BRect size, color_space depth) 25541281cf3SAxel Dörfler { 25641281cf3SAxel Dörfler BWindow::ScreenChanged(size, depth); 25741281cf3SAxel Dörfler 25841281cf3SAxel Dörfler fBarView->UpdatePlacement(); 25941281cf3SAxel Dörfler } 26041281cf3SAxel Dörfler 26141281cf3SAxel Dörfler 26241281cf3SAxel Dörfler void 26341281cf3SAxel Dörfler TBarWindow::SetBeMenu(TBeMenu *menu) 26441281cf3SAxel Dörfler { 26541281cf3SAxel Dörfler sBeMenu = menu; 26641281cf3SAxel Dörfler } 26741281cf3SAxel Dörfler 26841281cf3SAxel Dörfler 26941281cf3SAxel Dörfler TBeMenu * 27041281cf3SAxel Dörfler TBarWindow::BeMenu() 27141281cf3SAxel Dörfler { 27241281cf3SAxel Dörfler return sBeMenu; 27341281cf3SAxel Dörfler } 27441281cf3SAxel Dörfler 27541281cf3SAxel Dörfler 27641281cf3SAxel Dörfler void 27741281cf3SAxel Dörfler TBarWindow::ShowBeMenu() 27841281cf3SAxel Dörfler { 27941281cf3SAxel Dörfler BMenuBar *menuBar = fBarView->BarMenuBar(); 28041281cf3SAxel Dörfler if (menuBar == NULL) 28141281cf3SAxel Dörfler menuBar = KeyMenuBar(); 28241281cf3SAxel Dörfler 28341281cf3SAxel Dörfler if (menuBar == NULL) 28441281cf3SAxel Dörfler return; 28541281cf3SAxel Dörfler 286*4a71b881SAxel Dörfler BMenuBar_StartMenuBar_Hack(menuBar,0,true,true,NULL); 28741281cf3SAxel Dörfler } 28841281cf3SAxel Dörfler 28941281cf3SAxel Dörfler 29041281cf3SAxel Dörfler void 29141281cf3SAxel Dörfler TBarWindow::ShowTeamMenu() 29241281cf3SAxel Dörfler { 29341281cf3SAxel Dörfler int32 index = 0; 29441281cf3SAxel Dörfler if (fBarView->BarMenuBar() == NULL) 29541281cf3SAxel Dörfler index = 2; 29641281cf3SAxel Dörfler 29741281cf3SAxel Dörfler if (KeyMenuBar() == NULL) 29841281cf3SAxel Dörfler return; 29941281cf3SAxel Dörfler 300*4a71b881SAxel Dörfler BMenuBar_StartMenuBar_Hack(KeyMenuBar(),index,true,true,NULL); 30141281cf3SAxel Dörfler } 30241281cf3SAxel Dörfler 30341281cf3SAxel Dörfler 30441281cf3SAxel Dörfler /** determines the actual location of the window */ 30541281cf3SAxel Dörfler 30641281cf3SAxel Dörfler deskbar_location 30741281cf3SAxel Dörfler TBarWindow::DeskbarLocation() const 30841281cf3SAxel Dörfler { 30941281cf3SAxel Dörfler bool left = fBarView->Left(); 31041281cf3SAxel Dörfler bool top = fBarView->Top(); 31141281cf3SAxel Dörfler 31241281cf3SAxel Dörfler if (fBarView->AcrossTop()) 31341281cf3SAxel Dörfler return B_DESKBAR_TOP; 31441281cf3SAxel Dörfler 31541281cf3SAxel Dörfler if (fBarView->AcrossBottom()) 31641281cf3SAxel Dörfler return B_DESKBAR_BOTTOM; 31741281cf3SAxel Dörfler 31841281cf3SAxel Dörfler if (left && top) 31941281cf3SAxel Dörfler return B_DESKBAR_LEFT_TOP; 32041281cf3SAxel Dörfler 32141281cf3SAxel Dörfler if (!left && top) 32241281cf3SAxel Dörfler return B_DESKBAR_RIGHT_TOP; 32341281cf3SAxel Dörfler 32441281cf3SAxel Dörfler if (left && !top) 32541281cf3SAxel Dörfler return B_DESKBAR_LEFT_BOTTOM; 32641281cf3SAxel Dörfler 32741281cf3SAxel Dörfler return B_DESKBAR_RIGHT_BOTTOM; 32841281cf3SAxel Dörfler } 32941281cf3SAxel Dörfler 33041281cf3SAxel Dörfler 33141281cf3SAxel Dörfler void 33241281cf3SAxel Dörfler TBarWindow::GetLocation(BMessage *message) 33341281cf3SAxel Dörfler { 33441281cf3SAxel Dörfler BMessage reply('rply'); 33541281cf3SAxel Dörfler reply.AddInt32("location", (int32)DeskbarLocation()); 33641281cf3SAxel Dörfler reply.AddBool("expanded", fBarView->Expando()); 33741281cf3SAxel Dörfler 33841281cf3SAxel Dörfler message->SendReply(&reply); 33941281cf3SAxel Dörfler } 34041281cf3SAxel Dörfler 34141281cf3SAxel Dörfler 34241281cf3SAxel Dörfler void 34341281cf3SAxel Dörfler TBarWindow::SetDeskbarLocation(deskbar_location location, bool newExpandState) 34441281cf3SAxel Dörfler { 34541281cf3SAxel Dörfler // left top and right top are the only two that 34641281cf3SAxel Dörfler // currently pay attention to expand, ignore for all others 34741281cf3SAxel Dörfler 34841281cf3SAxel Dörfler bool left = false, top = true, vertical, expand; 34941281cf3SAxel Dörfler 35041281cf3SAxel Dörfler switch (location) { 35141281cf3SAxel Dörfler case B_DESKBAR_TOP: 35241281cf3SAxel Dörfler left = true; 35341281cf3SAxel Dörfler top = true; 35441281cf3SAxel Dörfler vertical = false; 35541281cf3SAxel Dörfler expand = true; 35641281cf3SAxel Dörfler break; 35741281cf3SAxel Dörfler 35841281cf3SAxel Dörfler case B_DESKBAR_BOTTOM: 35941281cf3SAxel Dörfler left = true; 36041281cf3SAxel Dörfler top = false; 36141281cf3SAxel Dörfler vertical = false; 36241281cf3SAxel Dörfler expand = true; 36341281cf3SAxel Dörfler break; 36441281cf3SAxel Dörfler 36541281cf3SAxel Dörfler case B_DESKBAR_LEFT_TOP: 36641281cf3SAxel Dörfler left = true; 36741281cf3SAxel Dörfler top = true; 36841281cf3SAxel Dörfler vertical = true; 36941281cf3SAxel Dörfler expand = newExpandState; 37041281cf3SAxel Dörfler break; 37141281cf3SAxel Dörfler 37241281cf3SAxel Dörfler case B_DESKBAR_RIGHT_TOP: 37341281cf3SAxel Dörfler left = false; 37441281cf3SAxel Dörfler top = true; 37541281cf3SAxel Dörfler vertical = true; 37641281cf3SAxel Dörfler expand = newExpandState; 37741281cf3SAxel Dörfler break; 37841281cf3SAxel Dörfler 37941281cf3SAxel Dörfler case B_DESKBAR_LEFT_BOTTOM: 38041281cf3SAxel Dörfler left = true; 38141281cf3SAxel Dörfler top = false; 38241281cf3SAxel Dörfler vertical = true; 38341281cf3SAxel Dörfler expand = false; 38441281cf3SAxel Dörfler break; 38541281cf3SAxel Dörfler 38641281cf3SAxel Dörfler case B_DESKBAR_RIGHT_BOTTOM: 38741281cf3SAxel Dörfler left = false; 38841281cf3SAxel Dörfler top = false; 38941281cf3SAxel Dörfler vertical = true; 39041281cf3SAxel Dörfler expand = false; 39141281cf3SAxel Dörfler break; 39241281cf3SAxel Dörfler 39341281cf3SAxel Dörfler default: 39441281cf3SAxel Dörfler left = true; 39541281cf3SAxel Dörfler top = true; 39641281cf3SAxel Dörfler vertical = false; 39741281cf3SAxel Dörfler expand = true; 39841281cf3SAxel Dörfler break; 39941281cf3SAxel Dörfler } 40041281cf3SAxel Dörfler 40141281cf3SAxel Dörfler fBarView->ChangeState(expand, vertical, left, top); 40241281cf3SAxel Dörfler } 40341281cf3SAxel Dörfler 40441281cf3SAxel Dörfler void 40541281cf3SAxel Dörfler TBarWindow::SetLocation(BMessage *message) 40641281cf3SAxel Dörfler { 40741281cf3SAxel Dörfler deskbar_location location; 40841281cf3SAxel Dörfler bool expand; 40941281cf3SAxel Dörfler if (message->FindInt32("location", (int32 *)&location) == B_OK 41041281cf3SAxel Dörfler && message->FindBool("expand", &expand) == B_OK) 41141281cf3SAxel Dörfler SetDeskbarLocation(location, expand); 41241281cf3SAxel Dörfler } 41341281cf3SAxel Dörfler 41441281cf3SAxel Dörfler 41541281cf3SAxel Dörfler void 41641281cf3SAxel Dörfler TBarWindow::IsExpanded(BMessage *message) 41741281cf3SAxel Dörfler { 41841281cf3SAxel Dörfler BMessage reply('rply'); 41941281cf3SAxel Dörfler reply.AddBool("expanded", fBarView->Expando()); 42041281cf3SAxel Dörfler message->SendReply(&reply); 42141281cf3SAxel Dörfler } 42241281cf3SAxel Dörfler 42341281cf3SAxel Dörfler 42441281cf3SAxel Dörfler void 42541281cf3SAxel Dörfler TBarWindow::Expand(BMessage *message) 42641281cf3SAxel Dörfler { 42741281cf3SAxel Dörfler bool expand; 42841281cf3SAxel Dörfler if (message->FindBool("expand", &expand) == B_OK) { 42941281cf3SAxel Dörfler bool vertical = fBarView->Vertical(); 43041281cf3SAxel Dörfler bool left = fBarView->Left(); 43141281cf3SAxel Dörfler bool top = fBarView->Top(); 43241281cf3SAxel Dörfler fBarView->ChangeState(expand, vertical, left, top); 43341281cf3SAxel Dörfler } 43441281cf3SAxel Dörfler } 43541281cf3SAxel Dörfler 43641281cf3SAxel Dörfler 43741281cf3SAxel Dörfler void 43841281cf3SAxel Dörfler TBarWindow::ItemInfo(BMessage *message) 43941281cf3SAxel Dörfler { 44041281cf3SAxel Dörfler BMessage replyMsg; 44141281cf3SAxel Dörfler const char *name; 44241281cf3SAxel Dörfler int32 id; 44341281cf3SAxel Dörfler DeskbarShelf shelf; 44441281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) { 44541281cf3SAxel Dörfler if (fBarView->ItemInfo(id, &name, &shelf) == B_OK) { 44641281cf3SAxel Dörfler replyMsg.AddString("name", name); 44741281cf3SAxel Dörfler #if SHELF_AWARE 44841281cf3SAxel Dörfler replyMsg.AddInt32("shelf", (int32)shelf); 44941281cf3SAxel Dörfler #endif 45041281cf3SAxel Dörfler } 45141281cf3SAxel Dörfler } else if (message->FindString("name", &name) == B_OK) { 45241281cf3SAxel Dörfler if (fBarView->ItemInfo(name, &id, &shelf) == B_OK) { 45341281cf3SAxel Dörfler replyMsg.AddInt32("id", id); 45441281cf3SAxel Dörfler #if SHELF_AWARE 45541281cf3SAxel Dörfler replyMsg.AddInt32("shelf", (int32)shelf); 45641281cf3SAxel Dörfler #endif 45741281cf3SAxel Dörfler } 45841281cf3SAxel Dörfler } 45941281cf3SAxel Dörfler 46041281cf3SAxel Dörfler message->SendReply(&replyMsg); 46141281cf3SAxel Dörfler } 46241281cf3SAxel Dörfler 46341281cf3SAxel Dörfler 46441281cf3SAxel Dörfler void 46541281cf3SAxel Dörfler TBarWindow::ItemExists(BMessage *message) 46641281cf3SAxel Dörfler { 46741281cf3SAxel Dörfler BMessage replyMsg; 46841281cf3SAxel Dörfler const char *name; 46941281cf3SAxel Dörfler int32 id; 47041281cf3SAxel Dörfler DeskbarShelf shelf; 47141281cf3SAxel Dörfler 47241281cf3SAxel Dörfler #if SHELF_AWARE 47341281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32 *)&shelf) != B_OK) 47441281cf3SAxel Dörfler #endif 47541281cf3SAxel Dörfler shelf = B_DESKBAR_TRAY; 47641281cf3SAxel Dörfler 47741281cf3SAxel Dörfler bool exists = false; 47841281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) 47941281cf3SAxel Dörfler exists = fBarView->ItemExists(id, shelf); 48041281cf3SAxel Dörfler else if (message->FindString("name", &name) == B_OK) 48141281cf3SAxel Dörfler exists = fBarView->ItemExists(name, shelf); 48241281cf3SAxel Dörfler 48341281cf3SAxel Dörfler replyMsg.AddBool("exists", exists); 48441281cf3SAxel Dörfler message->SendReply(&replyMsg); 48541281cf3SAxel Dörfler } 48641281cf3SAxel Dörfler 48741281cf3SAxel Dörfler 48841281cf3SAxel Dörfler void 48941281cf3SAxel Dörfler TBarWindow::CountItems(BMessage *message) 49041281cf3SAxel Dörfler { 49141281cf3SAxel Dörfler DeskbarShelf shelf; 49241281cf3SAxel Dörfler 49341281cf3SAxel Dörfler #if SHELF_AWARE 49441281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32 *)&shelf) != B_OK) 49541281cf3SAxel Dörfler #endif 49641281cf3SAxel Dörfler shelf = B_DESKBAR_TRAY; 49741281cf3SAxel Dörfler 49841281cf3SAxel Dörfler BMessage reply('rply'); 49941281cf3SAxel Dörfler reply.AddInt32("count", fBarView->CountItems(shelf)); 50041281cf3SAxel Dörfler message->SendReply(&reply); 50141281cf3SAxel Dörfler } 50241281cf3SAxel Dörfler 50341281cf3SAxel Dörfler 50441281cf3SAxel Dörfler void 50541281cf3SAxel Dörfler TBarWindow::AddItem(BMessage *message) 50641281cf3SAxel Dörfler { 50741281cf3SAxel Dörfler DeskbarShelf shelf; 50841281cf3SAxel Dörfler entry_ref ref; 50941281cf3SAxel Dörfler int32 id = 999; 51041281cf3SAxel Dörfler BMessage reply; 51141281cf3SAxel Dörfler status_t err = B_ERROR; 51241281cf3SAxel Dörfler 51341281cf3SAxel Dörfler BMessage archivedView; 51441281cf3SAxel Dörfler if (message->FindMessage("view", &archivedView) == B_OK) { 51541281cf3SAxel Dörfler #if SHELF_AWARE 51641281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32 *)&shelf) != B_OK) 51741281cf3SAxel Dörfler #endif 51841281cf3SAxel Dörfler shelf = B_DESKBAR_TRAY; 51941281cf3SAxel Dörfler 52041281cf3SAxel Dörfler err = fBarView->AddItem(new BMessage(archivedView), shelf, &id); 52141281cf3SAxel Dörfler } else if (message->FindRef("addon", &ref) == B_OK) { 52241281cf3SAxel Dörfler // 52341281cf3SAxel Dörfler // exposing the name of the view here is not so great 52441281cf3SAxel Dörfler TReplicantTray *tray = dynamic_cast<TReplicantTray *>(FindView("Status")); 52541281cf3SAxel Dörfler if (tray) { 52641281cf3SAxel Dörfler // Force this into the deskbar even if the security code is wrong 52741281cf3SAxel Dörfler // This is OK because the user specifically asked for this replicant 52841281cf3SAxel Dörfler BEntry entry(&ref); 52941281cf3SAxel Dörfler err = tray->LoadAddOn(&entry, &id, true); 53041281cf3SAxel Dörfler } 53141281cf3SAxel Dörfler } 53241281cf3SAxel Dörfler 53341281cf3SAxel Dörfler if (err == B_OK) 53441281cf3SAxel Dörfler reply.AddInt32("id", id); 53541281cf3SAxel Dörfler else 53641281cf3SAxel Dörfler reply.AddInt32("error", err); 53741281cf3SAxel Dörfler 53841281cf3SAxel Dörfler message->SendReply(&reply); 53941281cf3SAxel Dörfler } 54041281cf3SAxel Dörfler 54141281cf3SAxel Dörfler 54241281cf3SAxel Dörfler void 54341281cf3SAxel Dörfler TBarWindow::RemoveItem(BMessage *message) 54441281cf3SAxel Dörfler { 54541281cf3SAxel Dörfler int32 id; 54641281cf3SAxel Dörfler const char *name; 54741281cf3SAxel Dörfler 54841281cf3SAxel Dörfler // ids ought to be unique across all shelves, assuming, of course, 54941281cf3SAxel Dörfler // that sometime in the future there may be more than one 55041281cf3SAxel Dörfler #if SHELF_AWARE 55141281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32 *)&shelf) == B_OK) { 55241281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK) 55341281cf3SAxel Dörfler fBarView->RemoveItem(name, shelf); 55441281cf3SAxel Dörfler } else { 55541281cf3SAxel Dörfler #endif 55641281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) { 55741281cf3SAxel Dörfler fBarView->RemoveItem(id); 55841281cf3SAxel Dörfler // remove the following two lines if and when the 55941281cf3SAxel Dörfler // shelf option returns 56041281cf3SAxel Dörfler } else if (message->FindString("name", &name) == B_OK) 56141281cf3SAxel Dörfler fBarView->RemoveItem(name, B_DESKBAR_TRAY); 56241281cf3SAxel Dörfler 56341281cf3SAxel Dörfler #if SHELF_AWARE 56441281cf3SAxel Dörfler } 56541281cf3SAxel Dörfler #endif 56641281cf3SAxel Dörfler } 56741281cf3SAxel Dörfler 56841281cf3SAxel Dörfler 56941281cf3SAxel Dörfler void 57041281cf3SAxel Dörfler TBarWindow::GetIconFrame(BMessage *message) 57141281cf3SAxel Dörfler { 57241281cf3SAxel Dörfler BRect frame(0, 0, 0, 0); 57341281cf3SAxel Dörfler 57441281cf3SAxel Dörfler const char *name; 57541281cf3SAxel Dörfler int32 id; 57641281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) 57741281cf3SAxel Dörfler frame = fBarView->IconFrame(id); 57841281cf3SAxel Dörfler else if (message->FindString("name", &name) == B_OK) 57941281cf3SAxel Dörfler frame = fBarView->IconFrame(name); 58041281cf3SAxel Dörfler 58141281cf3SAxel Dörfler BMessage reply('rply'); 58241281cf3SAxel Dörfler reply.AddRect("frame", frame); 58341281cf3SAxel Dörfler message->SendReply(&reply); 58441281cf3SAxel Dörfler } 585