6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered
30 trademarks of Be Incorporated in the United States and other countries. Other
31 brand product names are registered trademarks or trademarks of their respective
37 #include "BarWindow.h"
41 #include <Application.h>
42 #include <AutoDeleter.h>
44 #include <Directory.h>
45 #include <FindDirectory.h>
51 #include <MessageFilter.h>
52 #include <MessagePrivate.h>
56 #include "BarMenuBar.h"
58 #include "DeskbarUtils.h"
59 #include "DeskbarMenu.h"
60 #include "StatusView.h"
62 #include "tracker_private.h"
64 #undef B_TRANSLATION_CONTEXT
65 #define B_TRANSLATION_CONTEXT "MainWindow"
68 // This is a very ugly hack to be able to call the private
69 // BMenuBar::StartMenuBar() method from the TBarWindow::ShowBeMenu() method.
70 // Don't do this at home -- but why the hell is this method private?
72 #define BMenuBar_StartMenuBar_Hack StartMenuBar__8BMenuBarFlbbP5BRect
74 #define BMenuBar_StartMenuBar_Hack StartMenuBar__8BMenuBarlbT2P5BRect
77 #define BMenuBar_StartMenuBar_Hack _ZN8BMenuBar12StartMenuBarEibbP5BRect
79 #define BMenuBar_StartMenuBar_Hack _ZN8BMenuBar12StartMenuBarElbbP5BRect
82 # error "You may want to port this ugly hack to your compiler ABI"
85 BMenuBar_StartMenuBar_Hack(BMenuBar
*, int32
, bool, bool, BRect
*);
88 TDeskbarMenu
* TBarWindow::sDeskbarMenu
= NULL
;
91 TBarWindow::TBarWindow()
93 BWindow(BRect(-1000.0f
, -1000.0f
, -1000.0f
, -1000.0f
),
94 B_TRANSLATE_SYSTEM_NAME("Deskbar"), B_BORDERED_WINDOW
,
95 B_WILL_ACCEPT_FIRST_CLICK
| B_NOT_ZOOMABLE
| B_NOT_CLOSABLE
96 | B_NOT_MINIMIZABLE
| B_NOT_MOVABLE
| B_NOT_RESIZABLE
97 | B_AVOID_FRONT
| B_ASYNCHRONOUS_CONTROLS
,
101 desk_settings
* settings
= ((TBarApp
*)be_app
)->Settings();
102 if (settings
->alwaysOnTop
)
103 SetFeel(B_FLOATING_ALL_WINDOW_FEEL
);
105 fBarView
= new TBarView(Bounds(), settings
->vertical
, settings
->left
,
106 settings
->top
, settings
->state
, settings
->width
);
109 RemoveShortcut('H', B_COMMAND_KEY
| B_CONTROL_KEY
);
110 AddShortcut('F', B_COMMAND_KEY
, new BMessage(kFindButton
));
115 TBarWindow::MenusBeginning()
121 if (GetDeskbarSettingsDirectory(path
) == B_OK
122 && path
.Append(kDeskbarMenuEntriesFileName
) == B_OK
123 && entry
.SetTo(path
.Path(), true) == B_OK
125 && entry
.GetRef(&ref
) == B_OK
) {
126 sDeskbarMenu
->SetNavDir(&ref
);
127 } else if (GetDeskbarDataDirectory(path
) == B_OK
128 && path
.Append(kDeskbarMenuEntriesFileName
) == B_OK
129 && entry
.SetTo(path
.Path(), true) == B_OK
131 && entry
.GetRef(&ref
) == B_OK
) {
132 sDeskbarMenu
->SetNavDir(&ref
);
134 // this really should never happen
139 sDeskbarMenu
->ResetTargets();
142 BWindow::MenusBeginning();
147 TBarWindow::MenusEnded()
149 fShowingMenu
= false;
150 BWindow::MenusEnded();
152 if (sDeskbarMenu
->LockLooper()) {
153 sDeskbarMenu
->ForceRebuild();
154 sDeskbarMenu
->UnlockLooper();
160 TBarWindow::MessageReceived(BMessage
* message
)
162 switch (message
->what
) {
165 BMessenger
tracker(kTrackerSignature
);
166 tracker
.SendMessage(message
);
171 GetLocation(message
);
175 SetLocation(message
);
208 GetIconFrame(message
);
212 BWindow::MessageReceived(message
);
219 TBarWindow::Minimize(bool minimize
)
221 // Don't allow the Deskbar to be minimized
223 BWindow::Minimize(false);
228 TBarWindow::SaveSettings()
230 fBarView
->SaveSettings();
235 TBarWindow::QuitRequested()
237 be_app
->PostMessage(B_QUIT_REQUESTED
);
239 return BWindow::QuitRequested();
244 TBarWindow::WorkspaceActivated(int32 workspace
, bool active
)
246 BWindow::WorkspaceActivated(workspace
, active
);
248 if (active
&& !(fBarView
->ExpandoState() && fBarView
->Vertical()))
249 fBarView
->UpdatePlacement();
251 BRect screenFrame
= (BScreen(fBarView
->Window())).Frame();
252 fBarView
->SizeWindow(screenFrame
);
253 fBarView
->PositionWindow(screenFrame
);
254 fBarView
->Invalidate();
260 TBarWindow::ScreenChanged(BRect size
, color_space depth
)
262 BWindow::ScreenChanged(size
, depth
);
264 fBarView
->UpdatePlacement();
269 TBarWindow::SetDeskbarMenu(TDeskbarMenu
* menu
)
276 TBarWindow::DeskbarMenu()
283 TBarWindow::ShowDeskbarMenu()
285 BMenuBar
* menuBar
= fBarView
->BarMenuBar();
287 menuBar
= KeyMenuBar();
292 BMenuBar_StartMenuBar_Hack(menuBar
, 0, true, true, NULL
);
297 TBarWindow::ShowTeamMenu()
300 if (fBarView
->BarMenuBar() == NULL
)
303 if (KeyMenuBar() == NULL
)
306 BMenuBar_StartMenuBar_Hack(KeyMenuBar(), index
, true, true, NULL
);
310 // determines the actual location of the window
313 TBarWindow::DeskbarLocation() const
315 bool left
= fBarView
->Left();
316 bool top
= fBarView
->Top();
318 if (fBarView
->AcrossTop())
319 return B_DESKBAR_TOP
;
321 if (fBarView
->AcrossBottom())
322 return B_DESKBAR_BOTTOM
;
325 return B_DESKBAR_LEFT_TOP
;
328 return B_DESKBAR_RIGHT_TOP
;
331 return B_DESKBAR_LEFT_BOTTOM
;
333 return B_DESKBAR_RIGHT_BOTTOM
;
338 TBarWindow::GetLocation(BMessage
* message
)
340 BMessage
reply('rply');
341 reply
.AddInt32("location", (int32
)DeskbarLocation());
342 reply
.AddBool("expanded", fBarView
->ExpandoState());
344 message
->SendReply(&reply
);
349 TBarWindow::SetDeskbarLocation(deskbar_location location
, bool newExpandState
)
351 // left top and right top are the only two that
352 // currently pay attention to expand, ignore for all others
354 bool left
= false, top
= true, vertical
, expand
;
364 case B_DESKBAR_BOTTOM
:
371 case B_DESKBAR_LEFT_TOP
:
375 expand
= newExpandState
;
378 case B_DESKBAR_RIGHT_TOP
:
382 expand
= newExpandState
;
385 case B_DESKBAR_LEFT_BOTTOM
:
392 case B_DESKBAR_RIGHT_BOTTOM
:
407 fBarView
->ChangeState(expand
, vertical
, left
, top
);
412 TBarWindow::SetLocation(BMessage
* message
)
414 deskbar_location location
;
416 if (message
->FindInt32("location", (int32
*)&location
) == B_OK
417 && message
->FindBool("expand", &expand
) == B_OK
)
418 SetDeskbarLocation(location
, expand
);
423 TBarWindow::IsExpanded(BMessage
* message
)
425 BMessage
reply('rply');
426 reply
.AddBool("expanded", fBarView
->ExpandoState());
427 message
->SendReply(&reply
);
432 TBarWindow::Expand(BMessage
* message
)
435 if (message
->FindBool("expand", &expand
) == B_OK
) {
436 bool vertical
= fBarView
->Vertical();
437 bool left
= fBarView
->Left();
438 bool top
= fBarView
->Top();
439 fBarView
->ChangeState(expand
, vertical
, left
, top
);
445 TBarWindow::ItemInfo(BMessage
* message
)
451 if (message
->FindInt32("id", &id
) == B_OK
) {
452 if (fBarView
->ItemInfo(id
, &name
, &shelf
) == B_OK
) {
453 replyMsg
.AddString("name", name
);
455 replyMsg
.AddInt32("shelf", (int32
)shelf
);
458 } else if (message
->FindString("name", &name
) == B_OK
) {
459 if (fBarView
->ItemInfo(name
, &id
, &shelf
) == B_OK
) {
460 replyMsg
.AddInt32("id", id
);
462 replyMsg
.AddInt32("shelf", (int32
)shelf
);
467 message
->SendReply(&replyMsg
);
472 TBarWindow::ItemExists(BMessage
* message
)
480 if (message
->FindInt32("shelf", (int32
*)&shelf
) != B_OK
)
482 shelf
= B_DESKBAR_TRAY
;
485 if (message
->FindInt32("id", &id
) == B_OK
)
486 exists
= fBarView
->ItemExists(id
, shelf
);
487 else if (message
->FindString("name", &name
) == B_OK
)
488 exists
= fBarView
->ItemExists(name
, shelf
);
490 replyMsg
.AddBool("exists", exists
);
491 message
->SendReply(&replyMsg
);
496 TBarWindow::CountItems(BMessage
* message
)
501 if (message
->FindInt32("shelf", (int32
*)&shelf
) != B_OK
)
503 shelf
= B_DESKBAR_TRAY
;
505 BMessage
reply('rply');
506 reply
.AddInt32("count", fBarView
->CountItems(shelf
));
507 message
->SendReply(&reply
);
512 TBarWindow::AddItem(BMessage
* message
)
514 DeskbarShelf shelf
= B_DESKBAR_TRAY
;
518 status_t err
= B_ERROR
;
520 BMessage
* archivedView
= new BMessage();
521 ObjectDeleter
<BMessage
> deleter(archivedView
);
522 if (message
->FindMessage("view", archivedView
) == B_OK
) {
524 message
->FindInt32("shelf", &shelf
);
526 err
= fBarView
->AddItem(archivedView
, shelf
, &id
);
528 // Detach the deleter since AddReplicant is taking ownership
529 // on success. This should be changed on server side.
532 } else if (message
->FindRef("addon", &ref
) == B_OK
) {
534 err
= entry
.InitCheck();
536 err
= fBarView
->AddItem(&entry
, shelf
, &id
);
540 reply
.AddInt32("id", id
);
542 reply
.AddInt32("error", err
);
544 message
->SendReply(&reply
);
549 TBarWindow::RemoveItem(BMessage
* message
)
554 // ids ought to be unique across all shelves, assuming, of course,
555 // that sometime in the future there may be more than one
557 if (message
->FindInt32("shelf", (int32
*)&shelf
) == B_OK
) {
558 if (message
->FindString("name", &name
) == B_OK
)
559 fBarView
->RemoveItem(name
, shelf
);
562 if (message
->FindInt32("id", &id
) == B_OK
) {
563 fBarView
->RemoveItem(id
);
564 // remove the following two lines if and when the
565 // shelf option returns
566 } else if (message
->FindString("name", &name
) == B_OK
)
567 fBarView
->RemoveItem(name
, B_DESKBAR_TRAY
);
576 TBarWindow::GetIconFrame(BMessage
* message
)
578 BRect
frame(0, 0, 0, 0);
582 if (message
->FindInt32("id", &id
) == B_OK
)
583 frame
= fBarView
->IconFrame(id
);
584 else if (message
->FindString("name", &name
) == B_OK
)
585 frame
= fBarView
->IconFrame(name
);
587 BMessage
reply('rply');
588 reply
.AddRect("frame", frame
);
589 message
->SendReply(&reply
);
594 TBarWindow::IsShowingMenu() const
601 TBarWindow::_IsFocusMessage(BMessage
* message
)
603 BMessage::Private
messagePrivate(message
);
604 if (!messagePrivate
.UsePreferredTarget())
608 if (message
->HasInt32("_token")
609 && (message
->FindBool("_feed_focus", &feedFocus
) != B_OK
|| !feedFocus
))