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>
44*396f398dSJohn Scipione #include <ControlLook.h>
4541281cf3SAxel Dörfler #include <Directory.h>
4641281cf3SAxel Dörfler #include <FindDirectory.h>
4741281cf3SAxel Dörfler #include <Path.h>
4841281cf3SAxel Dörfler #include <Debug.h>
4941281cf3SAxel Dörfler #include <File.h>
50cd7548f5SJonas Sundström #include <Locale.h>
5141281cf3SAxel Dörfler #include <MenuItem.h>
5241281cf3SAxel Dörfler #include <MessageFilter.h>
531cd61330SJohn Scipione #include <MessagePrivate.h>
5441281cf3SAxel Dörfler #include <Screen.h>
5541281cf3SAxel Dörfler
565fd3bc6dSAxel Dörfler #include <DeskbarPrivate.h>
575fd3bc6dSAxel Dörfler #include <tracker_private.h>
585fd3bc6dSAxel Dörfler
5941281cf3SAxel Dörfler #include "BarApp.h"
6041281cf3SAxel Dörfler #include "BarMenuBar.h"
6141281cf3SAxel Dörfler #include "BarView.h"
6226ea7066SIngo Weinhold #include "DeskbarUtils.h"
63323b6546SOliver Tappe #include "DeskbarMenu.h"
641bb2e623SJohn Scipione #include "ExpandoMenuBar.h"
6541281cf3SAxel Dörfler #include "StatusView.h"
6641281cf3SAxel Dörfler
6741281cf3SAxel Dörfler
68546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
69546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "MainWindow"
70cd7548f5SJonas Sundström
71cd7548f5SJonas Sundström
7274c38cabSAugustin Cavalier // This is a bit of a hack to be able to call BMenuBar::StartMenuBar(), which
7374c38cabSAugustin Cavalier // is private. Don't do this at home!
7474c38cabSAugustin Cavalier class TStartableMenuBar : public BMenuBar {
7574c38cabSAugustin Cavalier public:
76ceec04eaSAugustin Cavalier TStartableMenuBar();
StartMenuBar(int32 menuIndex,bool sticky=true,bool showMenu=false,BRect * special_rect=NULL)7774c38cabSAugustin Cavalier void StartMenuBar(int32 menuIndex, bool sticky = true, bool showMenu = false,
7874c38cabSAugustin Cavalier BRect* special_rect = NULL) { BMenuBar::StartMenuBar(menuIndex, sticky, showMenu,
7974c38cabSAugustin Cavalier special_rect); }
8074c38cabSAugustin Cavalier };
8141281cf3SAxel Dörfler
8241281cf3SAxel Dörfler
83323b6546SOliver Tappe TDeskbarMenu* TBarWindow::sDeskbarMenu = NULL;
8441281cf3SAxel Dörfler
8541281cf3SAxel Dörfler
TBarWindow()8641281cf3SAxel Dörfler TBarWindow::TBarWindow()
8772f5ac30SAxel Dörfler :
88066522e8SJonas Sundström BWindow(BRect(-1000.0f, -1000.0f, -1000.0f, -1000.0f),
8908f748deSAugustin Cavalier "Deskbar", /* no B_TRANSLATE_SYSTEM_NAME, for binary compatibility */
9008f748deSAugustin Cavalier B_BORDERED_WINDOW,
9141281cf3SAxel Dörfler B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_CLOSABLE
921bb2e623SJohn Scipione | B_NOT_MINIMIZABLE | B_NOT_MOVABLE | B_NOT_V_RESIZABLE
9374c7ad20SIngo Weinhold | B_AVOID_FRONT | B_ASYNCHRONOUS_CONTROLS,
9422812ba2SRene Gollent B_ALL_WORKSPACES),
9574ceffa8SJohn Scipione fBarApp(static_cast<TBarApp*>(be_app)),
9674ceffa8SJohn Scipione fBarView(NULL),
9774ceffa8SJohn Scipione fMenusShown(0)
9841281cf3SAxel Dörfler {
9974ceffa8SJohn Scipione desk_settings* settings = fBarApp->Settings();
10041281cf3SAxel Dörfler if (settings->alwaysOnTop)
10141281cf3SAxel Dörfler SetFeel(B_FLOATING_ALL_WINDOW_FEEL);
102fe624b39SJohn Scipione
10372f5ac30SAxel Dörfler fBarView = new TBarView(Bounds(), settings->vertical, settings->left,
104573f748cSJohn Scipione settings->top, settings->state, settings->width);
10541281cf3SAxel Dörfler AddChild(fBarView);
10641281cf3SAxel Dörfler
10735c6651cSKarsten Heimrich RemoveShortcut('H', B_COMMAND_KEY | B_CONTROL_KEY);
10841281cf3SAxel Dörfler AddShortcut('F', B_COMMAND_KEY, new BMessage(kFindButton));
1097e27cd8eSJohn Scipione
1107e27cd8eSJohn Scipione SetSizeLimits();
11141281cf3SAxel Dörfler }
11241281cf3SAxel Dörfler
11341281cf3SAxel Dörfler
11441281cf3SAxel Dörfler void
MenusBeginning()11541281cf3SAxel Dörfler TBarWindow::MenusBeginning()
11641281cf3SAxel Dörfler {
11741281cf3SAxel Dörfler BPath path;
11841281cf3SAxel Dörfler entry_ref ref;
11926ea7066SIngo Weinhold BEntry entry;
12041281cf3SAxel Dörfler
12126ea7066SIngo Weinhold if (GetDeskbarSettingsDirectory(path) == B_OK
12226ea7066SIngo Weinhold && path.Append(kDeskbarMenuEntriesFileName) == B_OK
12326ea7066SIngo Weinhold && entry.SetTo(path.Path(), true) == B_OK
12426ea7066SIngo Weinhold && entry.Exists()
12526ea7066SIngo Weinhold && entry.GetRef(&ref) == B_OK) {
126323b6546SOliver Tappe sDeskbarMenu->SetNavDir(&ref);
12726ea7066SIngo Weinhold } else if (GetDeskbarDataDirectory(path) == B_OK
12826ea7066SIngo Weinhold && path.Append(kDeskbarMenuEntriesFileName) == B_OK
12926ea7066SIngo Weinhold && entry.SetTo(path.Path(), true) == B_OK
13026ea7066SIngo Weinhold && entry.Exists()
13126ea7066SIngo Weinhold && entry.GetRef(&ref) == B_OK) {
132323b6546SOliver Tappe sDeskbarMenu->SetNavDir(&ref);
13341281cf3SAxel Dörfler } else {
13441281cf3SAxel Dörfler // this really should never happen
13541281cf3SAxel Dörfler TRESPASS();
13641281cf3SAxel Dörfler return;
13741281cf3SAxel Dörfler }
13841281cf3SAxel Dörfler
13974ceffa8SJohn Scipione // raise Deskbar on menu open in auto-raise mode unless always-on-top
14074ceffa8SJohn Scipione desk_settings* settings = fBarApp->Settings();
14174ceffa8SJohn Scipione bool alwaysOnTop = settings->alwaysOnTop;
14274ceffa8SJohn Scipione bool autoRaise = settings->autoRaise;
14374ceffa8SJohn Scipione if (!alwaysOnTop && autoRaise)
14474ceffa8SJohn Scipione fBarView->RaiseDeskbar(true);
14574ceffa8SJohn Scipione
146323b6546SOliver Tappe sDeskbarMenu->ResetTargets();
14741281cf3SAxel Dörfler
14874ceffa8SJohn Scipione fMenusShown++;
14941281cf3SAxel Dörfler BWindow::MenusBeginning();
15041281cf3SAxel Dörfler }
15141281cf3SAxel Dörfler
15241281cf3SAxel Dörfler
15341281cf3SAxel Dörfler void
MenusEnded()15441281cf3SAxel Dörfler TBarWindow::MenusEnded()
15541281cf3SAxel Dörfler {
15674ceffa8SJohn Scipione fMenusShown--;
15741281cf3SAxel Dörfler BWindow::MenusEnded();
15841281cf3SAxel Dörfler
15974ceffa8SJohn Scipione // lower Deskbar back down again on menu close in auto-raise mode
16074ceffa8SJohn Scipione // unless another menu is open or always-on-top.
16174ceffa8SJohn Scipione desk_settings* settings = fBarApp->Settings();
16274ceffa8SJohn Scipione bool alwaysOnTop = settings->alwaysOnTop;
16374ceffa8SJohn Scipione bool autoRaise = settings->autoRaise;
16474ceffa8SJohn Scipione if (!alwaysOnTop && autoRaise && fMenusShown <= 0)
16574ceffa8SJohn Scipione fBarView->RaiseDeskbar(false);
16674ceffa8SJohn Scipione
167323b6546SOliver Tappe if (sDeskbarMenu->LockLooper()) {
16885529c12SJessica Hamilton sDeskbarMenu->ForceRebuild();
169323b6546SOliver Tappe sDeskbarMenu->UnlockLooper();
17041281cf3SAxel Dörfler }
1714446e07aSStefano Ceccherini }
17241281cf3SAxel Dörfler
17341281cf3SAxel Dörfler
17441281cf3SAxel Dörfler void
MessageReceived(BMessage * message)17541281cf3SAxel Dörfler TBarWindow::MessageReceived(BMessage* message)
17641281cf3SAxel Dörfler {
17741281cf3SAxel Dörfler switch (message->what) {
17841281cf3SAxel Dörfler case kFindButton:
17941281cf3SAxel Dörfler {
18041281cf3SAxel Dörfler BMessenger tracker(kTrackerSignature);
18141281cf3SAxel Dörfler tracker.SendMessage(message);
18241281cf3SAxel Dörfler break;
18341281cf3SAxel Dörfler }
18441281cf3SAxel Dörfler
185fc23c097SJohn Scipione case kMsgLocation:
18641281cf3SAxel Dörfler GetLocation(message);
18741281cf3SAxel Dörfler break;
18841281cf3SAxel Dörfler
189fc23c097SJohn Scipione case kMsgSetLocation:
19041281cf3SAxel Dörfler SetLocation(message);
19141281cf3SAxel Dörfler break;
19241281cf3SAxel Dörfler
193fc23c097SJohn Scipione case kMsgIsExpanded:
19441281cf3SAxel Dörfler IsExpanded(message);
19541281cf3SAxel Dörfler break;
19641281cf3SAxel Dörfler
197fc23c097SJohn Scipione case kMsgExpand:
19841281cf3SAxel Dörfler Expand(message);
19941281cf3SAxel Dörfler break;
20041281cf3SAxel Dörfler
201fc23c097SJohn Scipione case kMsgGetItemInfo:
20241281cf3SAxel Dörfler ItemInfo(message);
20341281cf3SAxel Dörfler break;
20441281cf3SAxel Dörfler
205fc23c097SJohn Scipione case kMsgHasItem:
20641281cf3SAxel Dörfler ItemExists(message);
20741281cf3SAxel Dörfler break;
20841281cf3SAxel Dörfler
209fc23c097SJohn Scipione case kMsgCountItems:
21041281cf3SAxel Dörfler CountItems(message);
21141281cf3SAxel Dörfler break;
21241281cf3SAxel Dörfler
213efafab64SAxel Dörfler case kMsgMaxItemSize:
214efafab64SAxel Dörfler MaxItemSize(message);
215efafab64SAxel Dörfler break;
216efafab64SAxel Dörfler
217fc23c097SJohn Scipione case kMsgAddAddOn:
218fc23c097SJohn Scipione case kMsgAddView:
21941281cf3SAxel Dörfler AddItem(message);
22041281cf3SAxel Dörfler break;
22141281cf3SAxel Dörfler
222fc23c097SJohn Scipione case kMsgRemoveItem:
22341281cf3SAxel Dörfler RemoveItem(message);
22441281cf3SAxel Dörfler break;
22541281cf3SAxel Dörfler
22641281cf3SAxel Dörfler case 'iloc':
22741281cf3SAxel Dörfler GetIconFrame(message);
22841281cf3SAxel Dörfler break;
22941281cf3SAxel Dörfler
23041281cf3SAxel Dörfler default:
23141281cf3SAxel Dörfler BWindow::MessageReceived(message);
23241281cf3SAxel Dörfler break;
23341281cf3SAxel Dörfler }
23441281cf3SAxel Dörfler }
23541281cf3SAxel Dörfler
23641281cf3SAxel Dörfler
23741281cf3SAxel Dörfler void
Minimize(bool minimize)2385b576468SAxel Dörfler TBarWindow::Minimize(bool minimize)
2395b576468SAxel Dörfler {
2405b576468SAxel Dörfler // Don't allow the Deskbar to be minimized
2415b576468SAxel Dörfler if (!minimize)
2425b576468SAxel Dörfler BWindow::Minimize(false);
2435b576468SAxel Dörfler }
2445b576468SAxel Dörfler
2455b576468SAxel Dörfler
2465b576468SAxel Dörfler void
FrameResized(float width,float height)2471bb2e623SJohn Scipione TBarWindow::FrameResized(float width, float height)
2481bb2e623SJohn Scipione {
249f9b3a3b1SJohn Scipione if (!fBarView->Vertical())
2501bb2e623SJohn Scipione return BWindow::FrameResized(width, height);
2511bb2e623SJohn Scipione
25274ceffa8SJohn Scipione bool setToHiddenSize = fBarApp->Settings()->autoHide
2531bb2e623SJohn Scipione && fBarView->IsHidden() && !fBarView->DragRegion()->IsDragging();
2541bb2e623SJohn Scipione if (!setToHiddenSize) {
2551bb2e623SJohn Scipione // constrain within limits
2561bb2e623SJohn Scipione float newWidth;
2571bb2e623SJohn Scipione if (width < gMinimumWindowWidth)
2581bb2e623SJohn Scipione newWidth = gMinimumWindowWidth;
2591bb2e623SJohn Scipione else if (width > gMaximumWindowWidth)
2601bb2e623SJohn Scipione newWidth = gMaximumWindowWidth;
2611bb2e623SJohn Scipione else
2621bb2e623SJohn Scipione newWidth = width;
2631bb2e623SJohn Scipione
26474ceffa8SJohn Scipione float oldWidth = fBarApp->Settings()->width;
265938fd26fSJohn Scipione
2661bb2e623SJohn Scipione // update width setting
26774ceffa8SJohn Scipione fBarApp->Settings()->width = newWidth;
2681bb2e623SJohn Scipione
269938fd26fSJohn Scipione if (oldWidth != newWidth) {
2701bb2e623SJohn Scipione fBarView->ResizeTo(width, fBarView->Bounds().Height());
2710d2645e4SJohn Scipione if (fBarView->Vertical() && fBarView->ExpandoMenuBar() != NULL)
2721bb2e623SJohn Scipione fBarView->ExpandoMenuBar()->SetMaxContentWidth(width);
2731bb2e623SJohn Scipione
274938fd26fSJohn Scipione fBarView->UpdatePlacement();
275938fd26fSJohn Scipione }
2761bb2e623SJohn Scipione }
2771bb2e623SJohn Scipione }
2781bb2e623SJohn Scipione
2791bb2e623SJohn Scipione
2801bb2e623SJohn Scipione void
SaveSettings()28141281cf3SAxel Dörfler TBarWindow::SaveSettings()
28241281cf3SAxel Dörfler {
28341281cf3SAxel Dörfler fBarView->SaveSettings();
28441281cf3SAxel Dörfler }
28541281cf3SAxel Dörfler
28641281cf3SAxel Dörfler
28741281cf3SAxel Dörfler bool
QuitRequested()28841281cf3SAxel Dörfler TBarWindow::QuitRequested()
28941281cf3SAxel Dörfler {
29041281cf3SAxel Dörfler be_app->PostMessage(B_QUIT_REQUESTED);
29141281cf3SAxel Dörfler
29241281cf3SAxel Dörfler return BWindow::QuitRequested();
29341281cf3SAxel Dörfler }
29441281cf3SAxel Dörfler
29541281cf3SAxel Dörfler
29641281cf3SAxel Dörfler void
WorkspaceActivated(int32 workspace,bool active)29741281cf3SAxel Dörfler TBarWindow::WorkspaceActivated(int32 workspace, bool active)
29841281cf3SAxel Dörfler {
29941281cf3SAxel Dörfler BWindow::WorkspaceActivated(workspace, active);
30041281cf3SAxel Dörfler
301d0a49328SJohn Scipione if (active && !(fBarView->ExpandoState() && fBarView->Vertical()))
30241281cf3SAxel Dörfler fBarView->UpdatePlacement();
30341281cf3SAxel Dörfler else {
30441281cf3SAxel Dörfler BRect screenFrame = (BScreen(fBarView->Window())).Frame();
30541281cf3SAxel Dörfler fBarView->SizeWindow(screenFrame);
30641281cf3SAxel Dörfler fBarView->PositionWindow(screenFrame);
30741281cf3SAxel Dörfler fBarView->Invalidate();
30841281cf3SAxel Dörfler }
30941281cf3SAxel Dörfler }
31041281cf3SAxel Dörfler
31141281cf3SAxel Dörfler
31241281cf3SAxel Dörfler void
ScreenChanged(BRect size,color_space depth)31341281cf3SAxel Dörfler TBarWindow::ScreenChanged(BRect size, color_space depth)
31441281cf3SAxel Dörfler {
31541281cf3SAxel Dörfler BWindow::ScreenChanged(size, depth);
31641281cf3SAxel Dörfler
3177e27cd8eSJohn Scipione SetSizeLimits();
3180d2645e4SJohn Scipione
3190d2645e4SJohn Scipione if (fBarView != NULL) {
3200d2645e4SJohn Scipione fBarView->DragRegion()->CalculateRegions();
3210d2645e4SJohn Scipione fBarView->UpdatePlacement();
3220d2645e4SJohn Scipione }
32341281cf3SAxel Dörfler }
32441281cf3SAxel Dörfler
32541281cf3SAxel Dörfler
32641281cf3SAxel Dörfler void
SetDeskbarMenu(TDeskbarMenu * menu)327323b6546SOliver Tappe TBarWindow::SetDeskbarMenu(TDeskbarMenu* menu)
32841281cf3SAxel Dörfler {
329323b6546SOliver Tappe sDeskbarMenu = menu;
33041281cf3SAxel Dörfler }
33141281cf3SAxel Dörfler
33241281cf3SAxel Dörfler
333323b6546SOliver Tappe TDeskbarMenu*
DeskbarMenu()334323b6546SOliver Tappe TBarWindow::DeskbarMenu()
33541281cf3SAxel Dörfler {
336323b6546SOliver Tappe return sDeskbarMenu;
33741281cf3SAxel Dörfler }
33841281cf3SAxel Dörfler
33941281cf3SAxel Dörfler
34041281cf3SAxel Dörfler void
ShowDeskbarMenu()341323b6546SOliver Tappe TBarWindow::ShowDeskbarMenu()
34241281cf3SAxel Dörfler {
34374c38cabSAugustin Cavalier TStartableMenuBar* menuBar = (TStartableMenuBar*)fBarView->BarMenuBar();
34441281cf3SAxel Dörfler if (menuBar == NULL)
34574c38cabSAugustin Cavalier menuBar = (TStartableMenuBar*)KeyMenuBar();
34641281cf3SAxel Dörfler
34741281cf3SAxel Dörfler if (menuBar == NULL)
34841281cf3SAxel Dörfler return;
34941281cf3SAxel Dörfler
35074c38cabSAugustin Cavalier menuBar->StartMenuBar(0, true, true, NULL);
35141281cf3SAxel Dörfler }
35241281cf3SAxel Dörfler
35341281cf3SAxel Dörfler
35441281cf3SAxel Dörfler void
ShowTeamMenu()35541281cf3SAxel Dörfler TBarWindow::ShowTeamMenu()
35641281cf3SAxel Dörfler {
35741281cf3SAxel Dörfler int32 index = 0;
35841281cf3SAxel Dörfler if (fBarView->BarMenuBar() == NULL)
35941281cf3SAxel Dörfler index = 2;
36041281cf3SAxel Dörfler
36141281cf3SAxel Dörfler if (KeyMenuBar() == NULL)
36241281cf3SAxel Dörfler return;
36341281cf3SAxel Dörfler
36474c38cabSAugustin Cavalier ((TStartableMenuBar*)KeyMenuBar())->StartMenuBar(index, true, true, NULL);
36541281cf3SAxel Dörfler }
36641281cf3SAxel Dörfler
36741281cf3SAxel Dörfler
3681075cc34SFredrik Holmqvist // determines the actual location of the window
36941281cf3SAxel Dörfler
37041281cf3SAxel Dörfler deskbar_location
DeskbarLocation() const37141281cf3SAxel Dörfler TBarWindow::DeskbarLocation() const
37241281cf3SAxel Dörfler {
37341281cf3SAxel Dörfler bool left = fBarView->Left();
37441281cf3SAxel Dörfler bool top = fBarView->Top();
37541281cf3SAxel Dörfler
37641281cf3SAxel Dörfler if (fBarView->AcrossTop())
37741281cf3SAxel Dörfler return B_DESKBAR_TOP;
37841281cf3SAxel Dörfler
37941281cf3SAxel Dörfler if (fBarView->AcrossBottom())
38041281cf3SAxel Dörfler return B_DESKBAR_BOTTOM;
38141281cf3SAxel Dörfler
38241281cf3SAxel Dörfler if (left && top)
38341281cf3SAxel Dörfler return B_DESKBAR_LEFT_TOP;
38441281cf3SAxel Dörfler
38541281cf3SAxel Dörfler if (!left && top)
38641281cf3SAxel Dörfler return B_DESKBAR_RIGHT_TOP;
38741281cf3SAxel Dörfler
38841281cf3SAxel Dörfler if (left && !top)
38941281cf3SAxel Dörfler return B_DESKBAR_LEFT_BOTTOM;
39041281cf3SAxel Dörfler
39141281cf3SAxel Dörfler return B_DESKBAR_RIGHT_BOTTOM;
39241281cf3SAxel Dörfler }
39341281cf3SAxel Dörfler
39441281cf3SAxel Dörfler
39541281cf3SAxel Dörfler void
GetLocation(BMessage * message)39641281cf3SAxel Dörfler TBarWindow::GetLocation(BMessage* message)
39741281cf3SAxel Dörfler {
39841281cf3SAxel Dörfler BMessage reply('rply');
39941281cf3SAxel Dörfler reply.AddInt32("location", (int32)DeskbarLocation());
400d0a49328SJohn Scipione reply.AddBool("expanded", fBarView->ExpandoState());
40141281cf3SAxel Dörfler
40241281cf3SAxel Dörfler message->SendReply(&reply);
40341281cf3SAxel Dörfler }
40441281cf3SAxel Dörfler
40541281cf3SAxel Dörfler
40641281cf3SAxel Dörfler void
SetDeskbarLocation(deskbar_location location,bool newExpandState)40741281cf3SAxel Dörfler TBarWindow::SetDeskbarLocation(deskbar_location location, bool newExpandState)
40841281cf3SAxel Dörfler {
40941281cf3SAxel Dörfler // left top and right top are the only two that
41041281cf3SAxel Dörfler // currently pay attention to expand, ignore for all others
41141281cf3SAxel Dörfler
41241281cf3SAxel Dörfler bool left = false, top = true, vertical, expand;
41341281cf3SAxel Dörfler
41441281cf3SAxel Dörfler switch (location) {
41541281cf3SAxel Dörfler case B_DESKBAR_TOP:
41641281cf3SAxel Dörfler left = true;
41741281cf3SAxel Dörfler top = true;
41841281cf3SAxel Dörfler vertical = false;
41941281cf3SAxel Dörfler expand = true;
42041281cf3SAxel Dörfler break;
42141281cf3SAxel Dörfler
42241281cf3SAxel Dörfler case B_DESKBAR_BOTTOM:
42341281cf3SAxel Dörfler left = true;
42441281cf3SAxel Dörfler top = false;
42541281cf3SAxel Dörfler vertical = false;
42641281cf3SAxel Dörfler expand = true;
42741281cf3SAxel Dörfler break;
42841281cf3SAxel Dörfler
42941281cf3SAxel Dörfler case B_DESKBAR_LEFT_TOP:
43041281cf3SAxel Dörfler left = true;
43141281cf3SAxel Dörfler top = true;
43241281cf3SAxel Dörfler vertical = true;
43341281cf3SAxel Dörfler expand = newExpandState;
43441281cf3SAxel Dörfler break;
43541281cf3SAxel Dörfler
43641281cf3SAxel Dörfler case B_DESKBAR_RIGHT_TOP:
43741281cf3SAxel Dörfler left = false;
43841281cf3SAxel Dörfler top = true;
43941281cf3SAxel Dörfler vertical = true;
44041281cf3SAxel Dörfler expand = newExpandState;
44141281cf3SAxel Dörfler break;
44241281cf3SAxel Dörfler
44341281cf3SAxel Dörfler case B_DESKBAR_LEFT_BOTTOM:
44441281cf3SAxel Dörfler left = true;
44541281cf3SAxel Dörfler top = false;
44641281cf3SAxel Dörfler vertical = true;
44741281cf3SAxel Dörfler expand = false;
44841281cf3SAxel Dörfler break;
44941281cf3SAxel Dörfler
45041281cf3SAxel Dörfler case B_DESKBAR_RIGHT_BOTTOM:
45141281cf3SAxel Dörfler left = false;
45241281cf3SAxel Dörfler top = false;
45341281cf3SAxel Dörfler vertical = true;
45441281cf3SAxel Dörfler expand = false;
45541281cf3SAxel Dörfler break;
45641281cf3SAxel Dörfler
45741281cf3SAxel Dörfler default:
45841281cf3SAxel Dörfler left = true;
45941281cf3SAxel Dörfler top = true;
46041281cf3SAxel Dörfler vertical = false;
46141281cf3SAxel Dörfler expand = true;
46241281cf3SAxel Dörfler break;
46341281cf3SAxel Dörfler }
46441281cf3SAxel Dörfler
46541281cf3SAxel Dörfler fBarView->ChangeState(expand, vertical, left, top);
46641281cf3SAxel Dörfler }
46741281cf3SAxel Dörfler
4685b576468SAxel Dörfler
46941281cf3SAxel Dörfler void
SetLocation(BMessage * message)47041281cf3SAxel Dörfler TBarWindow::SetLocation(BMessage* message)
47141281cf3SAxel Dörfler {
47241281cf3SAxel Dörfler deskbar_location location;
47341281cf3SAxel Dörfler bool expand;
47441281cf3SAxel Dörfler if (message->FindInt32("location", (int32*)&location) == B_OK
47541281cf3SAxel Dörfler && message->FindBool("expand", &expand) == B_OK)
47641281cf3SAxel Dörfler SetDeskbarLocation(location, expand);
47741281cf3SAxel Dörfler }
47841281cf3SAxel Dörfler
47941281cf3SAxel Dörfler
48041281cf3SAxel Dörfler void
IsExpanded(BMessage * message)48141281cf3SAxel Dörfler TBarWindow::IsExpanded(BMessage* message)
48241281cf3SAxel Dörfler {
48341281cf3SAxel Dörfler BMessage reply('rply');
484d0a49328SJohn Scipione reply.AddBool("expanded", fBarView->ExpandoState());
48541281cf3SAxel Dörfler message->SendReply(&reply);
48641281cf3SAxel Dörfler }
48741281cf3SAxel Dörfler
48841281cf3SAxel Dörfler
48941281cf3SAxel Dörfler void
Expand(BMessage * message)49041281cf3SAxel Dörfler TBarWindow::Expand(BMessage* message)
49141281cf3SAxel Dörfler {
49241281cf3SAxel Dörfler bool expand;
49341281cf3SAxel Dörfler if (message->FindBool("expand", &expand) == B_OK) {
49441281cf3SAxel Dörfler bool vertical = fBarView->Vertical();
49541281cf3SAxel Dörfler bool left = fBarView->Left();
49641281cf3SAxel Dörfler bool top = fBarView->Top();
49741281cf3SAxel Dörfler fBarView->ChangeState(expand, vertical, left, top);
49841281cf3SAxel Dörfler }
49941281cf3SAxel Dörfler }
50041281cf3SAxel Dörfler
50141281cf3SAxel Dörfler
50241281cf3SAxel Dörfler void
ItemInfo(BMessage * message)50341281cf3SAxel Dörfler TBarWindow::ItemInfo(BMessage* message)
50441281cf3SAxel Dörfler {
50541281cf3SAxel Dörfler BMessage replyMsg;
50641281cf3SAxel Dörfler const char* name;
50741281cf3SAxel Dörfler int32 id;
50841281cf3SAxel Dörfler DeskbarShelf shelf;
50941281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) {
51041281cf3SAxel Dörfler if (fBarView->ItemInfo(id, &name, &shelf) == B_OK) {
51141281cf3SAxel Dörfler replyMsg.AddString("name", name);
51241281cf3SAxel Dörfler #if SHELF_AWARE
51341281cf3SAxel Dörfler replyMsg.AddInt32("shelf", (int32)shelf);
51441281cf3SAxel Dörfler #endif
51541281cf3SAxel Dörfler }
51641281cf3SAxel Dörfler } else if (message->FindString("name", &name) == B_OK) {
51741281cf3SAxel Dörfler if (fBarView->ItemInfo(name, &id, &shelf) == B_OK) {
51841281cf3SAxel Dörfler replyMsg.AddInt32("id", id);
51941281cf3SAxel Dörfler #if SHELF_AWARE
52041281cf3SAxel Dörfler replyMsg.AddInt32("shelf", (int32)shelf);
52141281cf3SAxel Dörfler #endif
52241281cf3SAxel Dörfler }
52341281cf3SAxel Dörfler }
52441281cf3SAxel Dörfler
52541281cf3SAxel Dörfler message->SendReply(&replyMsg);
52641281cf3SAxel Dörfler }
52741281cf3SAxel Dörfler
52841281cf3SAxel Dörfler
52941281cf3SAxel Dörfler void
ItemExists(BMessage * message)53041281cf3SAxel Dörfler TBarWindow::ItemExists(BMessage* message)
53141281cf3SAxel Dörfler {
53241281cf3SAxel Dörfler BMessage replyMsg;
53341281cf3SAxel Dörfler const char* name;
53441281cf3SAxel Dörfler int32 id;
53541281cf3SAxel Dörfler DeskbarShelf shelf;
53641281cf3SAxel Dörfler
53741281cf3SAxel Dörfler #if SHELF_AWARE
53841281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) != B_OK)
53941281cf3SAxel Dörfler #endif
54041281cf3SAxel Dörfler shelf = B_DESKBAR_TRAY;
54141281cf3SAxel Dörfler
54241281cf3SAxel Dörfler bool exists = false;
54341281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK)
54441281cf3SAxel Dörfler exists = fBarView->ItemExists(id, shelf);
54541281cf3SAxel Dörfler else if (message->FindString("name", &name) == B_OK)
54641281cf3SAxel Dörfler exists = fBarView->ItemExists(name, shelf);
54741281cf3SAxel Dörfler
54841281cf3SAxel Dörfler replyMsg.AddBool("exists", exists);
54941281cf3SAxel Dörfler message->SendReply(&replyMsg);
55041281cf3SAxel Dörfler }
55141281cf3SAxel Dörfler
55241281cf3SAxel Dörfler
55341281cf3SAxel Dörfler void
CountItems(BMessage * message)55441281cf3SAxel Dörfler TBarWindow::CountItems(BMessage* message)
55541281cf3SAxel Dörfler {
55641281cf3SAxel Dörfler DeskbarShelf shelf;
55741281cf3SAxel Dörfler
55841281cf3SAxel Dörfler #if SHELF_AWARE
55941281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) != B_OK)
56041281cf3SAxel Dörfler #endif
56141281cf3SAxel Dörfler shelf = B_DESKBAR_TRAY;
56241281cf3SAxel Dörfler
56341281cf3SAxel Dörfler BMessage reply('rply');
56441281cf3SAxel Dörfler reply.AddInt32("count", fBarView->CountItems(shelf));
56541281cf3SAxel Dörfler message->SendReply(&reply);
56641281cf3SAxel Dörfler }
56741281cf3SAxel Dörfler
56841281cf3SAxel Dörfler
56941281cf3SAxel Dörfler void
MaxItemSize(BMessage * message)570efafab64SAxel Dörfler TBarWindow::MaxItemSize(BMessage* message)
571efafab64SAxel Dörfler {
572efafab64SAxel Dörfler DeskbarShelf shelf;
573efafab64SAxel Dörfler #if SHELF_AWARE
574efafab64SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) != B_OK)
575efafab64SAxel Dörfler #endif
576efafab64SAxel Dörfler shelf = B_DESKBAR_TRAY;
577efafab64SAxel Dörfler
578efafab64SAxel Dörfler BSize size = fBarView->MaxItemSize(shelf);
579efafab64SAxel Dörfler
580efafab64SAxel Dörfler BMessage reply('rply');
581efafab64SAxel Dörfler reply.AddFloat("width", size.width);
582efafab64SAxel Dörfler reply.AddFloat("height", size.height);
583efafab64SAxel Dörfler message->SendReply(&reply);
584efafab64SAxel Dörfler }
585efafab64SAxel Dörfler
586efafab64SAxel Dörfler
587efafab64SAxel Dörfler void
AddItem(BMessage * message)58841281cf3SAxel Dörfler TBarWindow::AddItem(BMessage* message)
58941281cf3SAxel Dörfler {
5903e6ff860SRene Gollent DeskbarShelf shelf = B_DESKBAR_TRAY;
59141281cf3SAxel Dörfler entry_ref ref;
59241281cf3SAxel Dörfler int32 id = 999;
59341281cf3SAxel Dörfler BMessage reply;
59441281cf3SAxel Dörfler status_t err = B_ERROR;
59541281cf3SAxel Dörfler
5960fc30d89SDario Casalinuovo BMessage* archivedView = new BMessage();
5970fc30d89SDario Casalinuovo ObjectDeleter<BMessage> deleter(archivedView);
5980fc30d89SDario Casalinuovo if (message->FindMessage("view", archivedView) == B_OK) {
59941281cf3SAxel Dörfler #if SHELF_AWARE
6003e6ff860SRene Gollent message->FindInt32("shelf", &shelf);
60141281cf3SAxel Dörfler #endif
6020fc30d89SDario Casalinuovo err = fBarView->AddItem(archivedView, shelf, &id);
6030fc30d89SDario Casalinuovo if (err == B_OK) {
6040fc30d89SDario Casalinuovo // Detach the deleter since AddReplicant is taking ownership
6050fc30d89SDario Casalinuovo // on success. This should be changed on server side.
6060fc30d89SDario Casalinuovo deleter.Detach();
6070fc30d89SDario Casalinuovo }
60841281cf3SAxel Dörfler } else if (message->FindRef("addon", &ref) == B_OK) {
60941281cf3SAxel Dörfler BEntry entry(&ref);
6103e6ff860SRene Gollent err = entry.InitCheck();
6113e6ff860SRene Gollent if (err == B_OK)
6123e6ff860SRene Gollent err = fBarView->AddItem(&entry, shelf, &id);
61341281cf3SAxel Dörfler }
61441281cf3SAxel Dörfler
61541281cf3SAxel Dörfler if (err == B_OK)
61641281cf3SAxel Dörfler reply.AddInt32("id", id);
61741281cf3SAxel Dörfler else
61841281cf3SAxel Dörfler reply.AddInt32("error", err);
61941281cf3SAxel Dörfler
62041281cf3SAxel Dörfler message->SendReply(&reply);
62141281cf3SAxel Dörfler }
62241281cf3SAxel Dörfler
62341281cf3SAxel Dörfler
62441281cf3SAxel Dörfler void
RemoveItem(BMessage * message)62541281cf3SAxel Dörfler TBarWindow::RemoveItem(BMessage* message)
62641281cf3SAxel Dörfler {
62741281cf3SAxel Dörfler int32 id;
62841281cf3SAxel Dörfler const char* name;
62941281cf3SAxel Dörfler
63041281cf3SAxel Dörfler // ids ought to be unique across all shelves, assuming, of course,
63141281cf3SAxel Dörfler // that sometime in the future there may be more than one
63241281cf3SAxel Dörfler #if SHELF_AWARE
63341281cf3SAxel Dörfler if (message->FindInt32("shelf", (int32*)&shelf) == B_OK) {
63441281cf3SAxel Dörfler if (message->FindString("name", &name) == B_OK)
63541281cf3SAxel Dörfler fBarView->RemoveItem(name, shelf);
63641281cf3SAxel Dörfler } else {
63741281cf3SAxel Dörfler #endif
63841281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK) {
63941281cf3SAxel Dörfler fBarView->RemoveItem(id);
64041281cf3SAxel Dörfler // remove the following two lines if and when the
64141281cf3SAxel Dörfler // shelf option returns
64241281cf3SAxel Dörfler } else if (message->FindString("name", &name) == B_OK)
64341281cf3SAxel Dörfler fBarView->RemoveItem(name, B_DESKBAR_TRAY);
64441281cf3SAxel Dörfler
64541281cf3SAxel Dörfler #if SHELF_AWARE
64641281cf3SAxel Dörfler }
64741281cf3SAxel Dörfler #endif
64841281cf3SAxel Dörfler }
64941281cf3SAxel Dörfler
65041281cf3SAxel Dörfler
65141281cf3SAxel Dörfler void
GetIconFrame(BMessage * message)65241281cf3SAxel Dörfler TBarWindow::GetIconFrame(BMessage* message)
65341281cf3SAxel Dörfler {
65441281cf3SAxel Dörfler BRect frame(0, 0, 0, 0);
65541281cf3SAxel Dörfler
65641281cf3SAxel Dörfler const char* name;
65741281cf3SAxel Dörfler int32 id;
65841281cf3SAxel Dörfler if (message->FindInt32("id", &id) == B_OK)
65941281cf3SAxel Dörfler frame = fBarView->IconFrame(id);
66041281cf3SAxel Dörfler else if (message->FindString("name", &name) == B_OK)
66141281cf3SAxel Dörfler frame = fBarView->IconFrame(name);
66241281cf3SAxel Dörfler
66341281cf3SAxel Dörfler BMessage reply('rply');
66441281cf3SAxel Dörfler reply.AddRect("frame", frame);
66541281cf3SAxel Dörfler message->SendReply(&reply);
66641281cf3SAxel Dörfler }
66771bd3ba5SJonas Sundström
6684c139440SAxel Dörfler
6694c139440SAxel Dörfler bool
IsShowingMenu() const67022812ba2SRene Gollent TBarWindow::IsShowingMenu() const
67122812ba2SRene Gollent {
67274ceffa8SJohn Scipione return fMenusShown > 0;
67322812ba2SRene Gollent }
67422812ba2SRene Gollent
67522812ba2SRene Gollent
6767e27cd8eSJohn Scipione void
SetSizeLimits()6777e27cd8eSJohn Scipione TBarWindow::SetSizeLimits()
6787e27cd8eSJohn Scipione {
6797e27cd8eSJohn Scipione BRect screenFrame = (BScreen(this)).Frame();
68074ceffa8SJohn Scipione bool setToHiddenSize = fBarApp->Settings()->autoHide
6811c765f5bSJohn Scipione && fBarView->IsHidden() && !fBarView->DragRegion()->IsDragging();
6821c765f5bSJohn Scipione
6831c765f5bSJohn Scipione if (setToHiddenSize) {
6841c765f5bSJohn Scipione if (fBarView->Vertical())
6851c765f5bSJohn Scipione BWindow::SetSizeLimits(0, kHiddenDimension, 0, kHiddenDimension);
6861c765f5bSJohn Scipione else {
6871c765f5bSJohn Scipione BWindow::SetSizeLimits(screenFrame.Width(), screenFrame.Width(),
6881c765f5bSJohn Scipione 0, kHiddenDimension);
6891c765f5bSJohn Scipione }
6901c765f5bSJohn Scipione } else {
691f9b3a3b1SJohn Scipione float minHeight;
692f9b3a3b1SJohn Scipione float maxHeight;
693f9b3a3b1SJohn Scipione float minWidth;
694f9b3a3b1SJohn Scipione float maxWidth;
695f9b3a3b1SJohn Scipione
6967e27cd8eSJohn Scipione if (fBarView->Vertical()) {
697f9b3a3b1SJohn Scipione minHeight = fBarView->TabHeight();
698f9b3a3b1SJohn Scipione maxHeight = B_SIZE_UNLIMITED;
699f9b3a3b1SJohn Scipione minWidth = gMinimumWindowWidth;
700f9b3a3b1SJohn Scipione maxWidth = gMaximumWindowWidth;
7017e27cd8eSJohn Scipione } else {
702f9b3a3b1SJohn Scipione // horizontal
703f9b3a3b1SJohn Scipione if (fBarView->MiniState()) {
704*396f398dSJohn Scipione // horizontal mini-mode
705f9b3a3b1SJohn Scipione minWidth = gMinimumWindowWidth;
706f9b3a3b1SJohn Scipione maxWidth = B_SIZE_UNLIMITED;
707f9b3a3b1SJohn Scipione minHeight = fBarView->TabHeight();
708f9b3a3b1SJohn Scipione maxHeight = std::max(fBarView->TabHeight(), kGutter
709f9b3a3b1SJohn Scipione + fBarView->ReplicantTray()->MaxReplicantHeight()
710f9b3a3b1SJohn Scipione + kGutter);
711f9b3a3b1SJohn Scipione } else {
712*396f398dSJohn Scipione // horizontal expando-mode
713*396f398dSJohn Scipione const int32 max
714*396f398dSJohn Scipione = be_control_look->ComposeIconSize(kMaximumIconSize)
715*396f398dSJohn Scipione .IntegerWidth() + 1;
716*396f398dSJohn Scipione const float iconPadding
717*396f398dSJohn Scipione = be_control_look->ComposeSpacing(kIconPadding);
718*396f398dSJohn Scipione
719f9b3a3b1SJohn Scipione minWidth = maxWidth = screenFrame.Width();
720f9b3a3b1SJohn Scipione minHeight = kMenuBarHeight - 1;
721*396f398dSJohn Scipione maxHeight = max + iconPadding / 2;
7227e27cd8eSJohn Scipione }
7237e27cd8eSJohn Scipione }
7240d2645e4SJohn Scipione
725f9b3a3b1SJohn Scipione BWindow::SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
726f9b3a3b1SJohn Scipione }
7271c765f5bSJohn Scipione }
7287e27cd8eSJohn Scipione
7297e27cd8eSJohn Scipione
73022812ba2SRene Gollent bool
_IsFocusMessage(BMessage * message)7314c139440SAxel Dörfler TBarWindow::_IsFocusMessage(BMessage* message)
7324c139440SAxel Dörfler {
7334c139440SAxel Dörfler BMessage::Private messagePrivate(message);
7344c139440SAxel Dörfler if (!messagePrivate.UsePreferredTarget())
7354c139440SAxel Dörfler return false;
7364c139440SAxel Dörfler
7374c139440SAxel Dörfler bool feedFocus;
7384c139440SAxel Dörfler if (message->HasInt32("_token")
7394c139440SAxel Dörfler && (message->FindBool("_feed_focus", &feedFocus) != B_OK || !feedFocus))
7404c139440SAxel Dörfler return false;
7414c139440SAxel Dörfler
7424c139440SAxel Dörfler return true;
7434c139440SAxel Dörfler }
744