Imported current OpenTracker Deskbar: it can now start apps (and show the

"About Haiku" window) without having Tracker running.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15803 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-01-03 08:38:28 +00:00
parent 20c2f67293
commit f4a73641e0
6 changed files with 259 additions and 224 deletions

View File

@ -59,9 +59,11 @@ All rights reserved.
#include "BarView.h" #include "BarView.h"
#include "BarWindow.h" #include "BarWindow.h"
#include "DeskBarUtils.h" #include "DeskBarUtils.h"
#include "TeamMenu.h" #include "FSUtils.h"
#include "Switcher.h" #include "PublicCommands.h"
#include "ResourceSet.h" #include "ResourceSet.h"
#include "Switcher.h"
#include "TeamMenu.h"
#include "WindowMenuItem.h" #include "WindowMenuItem.h"
@ -480,6 +482,14 @@ TBarApp::MessageReceived(BMessage *message)
} }
#endif // __HAIKU__ #endif // __HAIKU__
// in case Tracker is not running
case kShowSplash:
#ifdef B_BEOS_VERSION_5
run_be_about();
#endif
break;
default: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(message);
break; break;
@ -487,10 +497,30 @@ TBarApp::MessageReceived(BMessage *message)
} }
// called when ExpandoMenuBar, TeamMenu or Switcher are built/rebuilt /** In case Tracker is not running, the TBeMenu will use us as a target.
* We'll make sure the user won't be completely confused and take over
* Tracker's duties until it's back.
*/
void
TBarApp::RefsReceived(BMessage *refs)
{
entry_ref ref;
for (int32 i = 0; refs->FindRef("refs", i, &ref) == B_OK; i++) {
BMessage refsReceived(B_REFS_RECEIVED);
refsReceived.AddRef("refs", &ref);
BEntry entry(&ref);
if (!entry.IsDirectory())
TrackerLaunch(&refsReceived, true);
}
}
void void
TBarApp::Subscribe(const BMessenger &subscriber, BList *list) TBarApp::Subscribe(const BMessenger &subscriber, BList *list)
{ {
// called when ExpandoMenuBar, TeamMenu or Switcher are built/rebuilt
list->MakeEmpty(); list->MakeEmpty();
BAutolock autolock(sSubscriberLock); BAutolock autolock(sSubscriberLock);

View File

@ -139,7 +139,8 @@ class TBarApp : public BApplication {
virtual ~TBarApp(); virtual ~TBarApp();
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MessageReceived(BMessage *); virtual void MessageReceived(BMessage *message);
virtual void RefsReceived(BMessage *refs);
desk_settings *Settings() desk_settings *Settings()
{ return &fSettings; } { return &fSettings; }
@ -173,4 +174,4 @@ class TBarApp : public BApplication {
static BList sSubscribers; static BList sSubscribers;
}; };
#endif #endif // BAR_APP_H

View File

@ -87,7 +87,7 @@ TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
fMaxRecentApps(kDefaultRecentAppCount), fMaxRecentApps(kDefaultRecentAppCount),
fLastDragItem(NULL), fLastDragItem(NULL),
fClickToOpen(_menu_info_ptr_->click_to_open) fClickToOpen(_menu_info_ptr_->click_to_open)
//init click to open to current local setting // init click to open to current local setting
{ {
} }
@ -150,7 +150,7 @@ TBarView::Draw(BRect)
void void
TBarView::MessageReceived(BMessage *message) TBarView::MessageReceived(BMessage *message)
{ {
switch(message->what) { switch (message->what) {
case B_REFS_RECEIVED: case B_REFS_RECEIVED:
// received when an item is selected during DnD // received when an item is selected during DnD
// message is targeted here from Be menu // message is targeted here from Be menu
@ -158,15 +158,15 @@ TBarView::MessageReceived(BMessage *message)
break; break;
case B_ARCHIVED_OBJECT: case B_ARCHIVED_OBJECT:
{
// this message has been retargeted to here // this message has been retargeted to here
// instead of directly to the replicant tray // instead of directly to the replicant tray
// so that I can follow the common pathway // so that I can follow the common pathway
// for adding icons to the tray // for adding icons to the tray
{
int32 id; int32 id;
AddItem(new BMessage(*message), B_DESKBAR_TRAY, &id); AddItem(new BMessage(*message), B_DESKBAR_TRAY, &id);
}
break; break;
}
default: default:
BView::MessageReceived(message); BView::MessageReceived(message);
@ -207,7 +207,8 @@ TBarView::PlaceBeMenu()
fBarMenuBar->RemoveTeamMenu(); fBarMenuBar->RemoveTeamMenu();
width = 8 + 16 + 8; width = 8 + 16 + 8;
loc = Bounds().LeftTop(); loc = Bounds().LeftTop();
} else if (fState == kExpandoState) { // shows apps below tray } else if (fState == kExpandoState) {
// shows apps below tray
fBarMenuBar->RemoveTeamMenu(); fBarMenuBar->RemoveTeamMenu();
if (fVertical) if (fVertical)
width += 1; width += 1;
@ -215,7 +216,7 @@ TBarView::PlaceBeMenu()
width = floorf(width) / 2; width = floorf(width) / 2;
loc = Bounds().LeftTop(); loc = Bounds().LeftTop();
} else } else
// mini mode, bemenu next to team menu // mini mode, BeMenu next to team menu
fBarMenuBar->AddTeamMenu(); fBarMenuBar->AddTeamMenu();
fBarMenuBar->SmartResize(width, menuFrame.Height()); fBarMenuBar->SmartResize(width, menuFrame.Height());
@ -280,9 +281,8 @@ TBarView::PlaceApplicationBar(BRect screenFrame)
// top left/right // top left/right
if (fTrayLocation != 0) if (fTrayLocation != 0)
expandoFrame.top = fDragRegion->Frame().bottom + 2; expandoFrame.top = fDragRegion->Frame().bottom + 2;
else { else
expandoFrame.top = fBarMenuBar->Frame().bottom + 2; expandoFrame.top = fBarMenuBar->Frame().bottom + 2;
}
expandoFrame.bottom = expandoFrame.top + 1; expandoFrame.bottom = expandoFrame.top + 1;
if (fState == kFullState) if (fState == kFullState)
@ -293,15 +293,14 @@ TBarView::PlaceApplicationBar(BRect screenFrame)
// top or bottom // top or bottom
expandoFrame.top = -1; expandoFrame.top = -1;
expandoFrame.bottom = kHModeHeight; expandoFrame.bottom = kHModeHeight;
if (fTrayLocation != 0) { if (fTrayLocation != 0)
expandoFrame.right = fDragRegion->Frame().left; expandoFrame.right = fDragRegion->Frame().left;
} else else
expandoFrame.right = screenFrame.Width(); expandoFrame.right = screenFrame.Width();
} }
fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", fVertical, fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar",
(fState != kFullState)); fVertical, fState != kFullState);
AddChild(fExpando); AddChild(fExpando);
} }
@ -557,15 +556,16 @@ TBarView::CacheDragData(BMessage *incoming)
static void static void
init_tracking_hook(BMenuItem *item, init_tracking_hook(BMenuItem *item,
bool (*hookfunction)(BMenu *, void *), void *state) bool (*hookFunction)(BMenu *, void *), void *state)
{ {
if (!item) if (!item)
return; return;
BMenu *windowmenu = item->Submenu(); BMenu *windowMenu = item->Submenu();
if (windowmenu) if (windowMenu) {
// have a menu, set the tracking hook // have a menu, set the tracking hook
windowmenu->SetTrackingHook(hookfunction, state); windowMenu->SetTrackingHook(hookFunction, state);
}
} }
@ -615,12 +615,10 @@ TBarView::MenuTrackingHook(BMenu *menu, void *castToThis)
if (!data) if (!data)
return false; return false;
TBarView *barview = dynamic_cast<TBarView *>(data->fTarget.Target(NULL)); TBarView *barview = dynamic_cast<TBarView *>(data->fTarget.Target(NULL));
if (!barview || !menu->LockLooper()) if (!barview || !menu->LockLooper())
return false; return false;
uint32 buttons; uint32 buttons;
BPoint location; BPoint location;
menu->GetMouse(&location, &buttons); menu->GetMouse(&location, &buttons);
@ -663,13 +661,11 @@ TBarView::MenuTrackingHook(BMenu *menu, void *castToThis)
} }
//
// used by WindowMenu and TeamMenu to // used by WindowMenu and TeamMenu to
// set the tracking hook for dragging // set the tracking hook for dragging
TrackingHookData * TrackingHookData *
TBarView::GetTrackingHookData() TBarView::GetTrackingHookData()
{ {
//
// all tracking hook data is // all tracking hook data is
// preset in AttachedToWindow // preset in AttachedToWindow
// data should never change // data should never change
@ -683,7 +679,6 @@ TBarView::DragStop(bool full)
if (!Dragging()) if (!Dragging())
return; return;
//
// revert the local click to open to // revert the local click to open to
// the launch state, cached in constructor // the launch state, cached in constructor
_menu_info_ptr_->click_to_open = fClickToOpen; _menu_info_ptr_->click_to_open = fClickToOpen;
@ -710,17 +705,20 @@ TBarView::AppCanHandleTypes(const char *signature)
{ {
// used for filtering apps/teams in the ExpandoMenuBar and TeamMenu // used for filtering apps/teams in the ExpandoMenuBar and TeamMenu
if (modifiers() & B_CONTROL_KEY) if (modifiers() & B_CONTROL_KEY) {
return true; // control key forces acceptance, just like drag&drop on icons // control key forces acceptance, just like drag&drop on icons
return true;
}
if (!signature || strlen(signature) == 0 if (!signature || strlen(signature) == 0
|| !fCachedTypesList || fCachedTypesList->CountItems() == 0) || !fCachedTypesList || fCachedTypesList->CountItems() == 0)
return false; return false;
if (strcmp(signature, kTrackerSignature) == 0) if (strcmp(signature, kTrackerSignature) == 0) {
// tracker should support all types // tracker should support all types
// and should pass them on to the appropriate application // and should pass them on to the appropriate application
return true; return true;
}
entry_ref hintref; entry_ref hintref;
BMimeType appmime(signature); BMimeType appmime(signature);
@ -737,9 +735,10 @@ TBarView::AppCanHandleTypes(const char *signature)
// only one item needs to match in the list of refs // only one item needs to match in the list of refs
int32 count = fCachedTypesList->CountItems(); int32 count = fCachedTypesList->CountItems();
for (int32 i = 0 ; i < count ; i++) for (int32 i = 0 ; i < count ; i++) {
if (fileinfo.IsSupportedType(fCachedTypesList->ItemAt(i)->String())) if (fileinfo.IsSupportedType(fCachedTypesList->ItemAt(i)->String()))
return true; return true;
}
return false; return false;
} }
@ -830,9 +829,10 @@ TBarView::HandleBeMenu(BMessage *messagewithdestination)
} else } else
SendDragMessage(NULL, &ref); SendDragMessage(NULL, &ref);
} }
} else } else {
// adds drag refs to top level in be menu // adds drag refs to top level in be menu
AddRefsToBeMenu(DragMessage(), NULL); AddRefsToBeMenu(DragMessage(), NULL);
}
// clean up drag message and types list // clean up drag message and types list
DragStop(true); DragStop(true);
@ -841,6 +841,7 @@ TBarView::HandleBeMenu(BMessage *messagewithdestination)
// #pragma mark - Add-ons // #pragma mark - Add-ons
// shelf is ignored for now, // shelf is ignored for now,
// it exists in anticipation of having other 'shelves' for // it exists in anticipation of having other 'shelves' for
// storing items // storing items
@ -930,4 +931,3 @@ TBarView::IconFrame(const char *name) const
return OffsetIconFrame(fReplicantTray->IconFrame(name)); return OffsetIconFrame(fReplicantTray->IconFrame(name));
} }

View File

@ -83,13 +83,14 @@ namespace BPrivate {
} }
using namespace BPrivate; using namespace BPrivate;
//********************************************************************************
// #pragma mark -
TBeMenu::TBeMenu(TBarView *barview) TBeMenu::TBeMenu(TBarView *barView)
: BNavMenu("BeMenu", B_REFS_RECEIVED, BMessenger(kTrackerSignature)), : BNavMenu("BeMenu", B_REFS_RECEIVED, DefaultTarget()),
fAddState(kStart), fAddState(kStart),
fBarView(barview) fBarView(barView)
{ {
} }
@ -106,7 +107,7 @@ TBeMenu::AttachedToWindow()
fBarView->DragStart(); fBarView->DragStart();
} else { } else {
SetTypesList(NULL); SetTypesList(NULL);
SetTarget(BMessenger(kTrackerSignature)); SetTarget(DefaultTarget());
SetTrackingHookDeep(this, NULL, NULL); SetTrackingHookDeep(this, NULL, NULL);
} }
@ -403,16 +404,13 @@ TBeMenu::ResetTargets()
{ {
BNavMenu::ResetTargets(); BNavMenu::ResetTargets();
//
// if we are dragging, set the target to whatever was set // if we are dragging, set the target to whatever was set
// else set it to the default (Tracker) // else set it to the default (Tracker)
//
if (!fBarView->Dragging()) if (!fBarView->Dragging())
SetTarget(BMessenger(kTrackerSignature)); SetTarget(DefaultTarget());
//
// now set the target for the menuitems to the currently // now set the target for the menuitems to the currently
// set target, which may or may not be tracker // set target, which may or may not be tracker
//
SetTargetForItems(Target()); SetTargetForItems(Target());
for (int32 i = 0; ; i++) { for (int32 i = 0; ; i++) {
@ -424,10 +422,8 @@ TBeMenu::ResetTargets()
switch (item->Message()->what) { switch (item->Message()->what) {
case kShowSplash: case kShowSplash:
#ifdef B_BEOS_VERSION_5 #ifdef B_BEOS_VERSION_5
#if 0
run_be_about();
// about box in libbe in BeOS R5 // about box in libbe in BeOS R5
#endif item->SetTarget(be_app);
#endif #endif
break; break;
case kFindButton: case kFindButton:
@ -464,33 +460,45 @@ TBeMenu::ResetTargets()
BPoint BPoint
TBeMenu::ScreenLocation() TBeMenu::ScreenLocation()
{ {
BPoint pt;
BRect r;
bool vertical = fBarView->Vertical(); bool vertical = fBarView->Vertical();
int32 expando = (fBarView->State() == kExpandoState); int32 expando = (fBarView->State() == kExpandoState);
BPoint point;
BRect rect = Supermenu()->Bounds();
Supermenu()->ConvertToScreen(&rect);
r = Supermenu()->Bounds();
Supermenu()->ConvertToScreen(&r);
if (expando && vertical && fBarView->Left()) { if (expando && vertical && fBarView->Left()) {
PRINT(("Left\n")); PRINT(("Left\n"));
pt = r.RightTop() + BPoint(0,3); point = rect.RightTop() + BPoint(0,3);
} else if (expando && vertical && !fBarView->Left()) { } else if (expando && vertical && !fBarView->Left()) {
PRINT(("Right\n")); PRINT(("Right\n"));
pt = r.LeftTop() - BPoint(Bounds().Width(), 0) + BPoint(0,3); point = rect.LeftTop() - BPoint(Bounds().Width(), 0) + BPoint(0,3);
} else { } else
pt = BMenu::ScreenLocation(); point = BMenu::ScreenLocation();
}
return pt; return point;
}
/*static*/
BMessenger
TBeMenu::DefaultTarget()
{
// if Tracker is not available we target the BarApp
BMessenger target(kTrackerSignature);
if (target.IsValid())
return target;
return BMessenger(be_app);
} }
//********************************************************************************
// #pragma mark - // #pragma mark -
//
TRecentsMenu::TRecentsMenu(const char *name, TBarView *bar, int32 which, const char *signature, entry_ref *appRef) TRecentsMenu::TRecentsMenu(const char *name, TBarView *bar, int32 which,
: BNavMenu(name, B_REFS_RECEIVED, BMessenger(kTrackerSignature)), const char *signature, entry_ref *appRef)
: BNavMenu(name, B_REFS_RECEIVED, TBeMenu::DefaultTarget()),
fWhich(which), fWhich(which),
fAppRef(NULL), fAppRef(NULL),
fSignature(NULL), fSignature(NULL),
@ -551,7 +559,7 @@ TRecentsMenu::StartBuildingItemList()
RemoveItem(index); RemoveItem(index);
delete item; delete item;
} }
//
// !! note: don't call inherited from here // !! note: don't call inherited from here
// the navref is not set for this menu // the navref is not set for this menu
// but it still needs to be a draggable navmenu // but it still needs to be a draggable navmenu
@ -662,9 +670,7 @@ TRecentsMenu::AddRecents(int32 count)
} }
} }
//
// return false if we are done with this list // return false if we are done with this list
//
return false; return false;
} }
@ -672,12 +678,10 @@ TRecentsMenu::AddRecents(int32 count)
void void
TRecentsMenu::DoneBuildingItemList() TRecentsMenu::DoneBuildingItemList()
{ {
//
// !! note: don't call inherited here // !! note: don't call inherited here
// the object list is not built // the object list is not built
// and this list does not need to be sorted // and this list does not need to be sorted
// BNavMenu::DoneBuildingItemList(); // BNavMenu::DoneBuildingItemList();
//
if (CountItems() > 0) if (CountItems() > 0)
SetTargetForItems(Target()); SetTargetForItems(Target());
@ -696,16 +700,14 @@ void
TRecentsMenu::ResetTargets() TRecentsMenu::ResetTargets()
{ {
BNavMenu::ResetTargets(); BNavMenu::ResetTargets();
//
// if we are dragging, set the target to whatever was set // if we are dragging, set the target to whatever was set
// else set it to the default (Tracker) // else set it to the default (Tracker)
//
if (!fBarView->Dragging()) if (!fBarView->Dragging())
SetTarget(BMessenger(kTrackerSignature)); SetTarget(TBeMenu::DefaultTarget());
//
// now set the target for the menuitems to the currently // now set the target for the menuitems to the currently
// set target, which may or may not be tracker // set target, which may or may not be tracker
//
SetTargetForItems(Target()); SetTargetForItems(Target());
} }
@ -730,17 +732,13 @@ MountMenu::AddDynamicItem(add_state s)
while ((item = RemoveItem(0L)) != NULL) while ((item = RemoveItem(0L)) != NULL)
delete item; delete item;
//
// Send message to tracker to get items. // Send message to tracker to get items.
//
BMessage request('gmtv'); BMessage request('gmtv');
BMessage reply; BMessage reply;
BMessenger(kTrackerSignature).SendMessage(&request, BMessenger(kTrackerSignature).SendMessage(&request,
&reply); &reply);
//
// populate menu // populate menu
//
type_code code; type_code code;
int32 countFound; int32 countFound;
reply.GetInfo("DisplayName", &code, &countFound); reply.GetInfo("DisplayName", &code, &countFound);

View File

@ -95,6 +95,8 @@ class TBeMenu : public BNavMenu {
void ResetTargets(); void ResetTargets();
static BMessenger DefaultTarget();
private: private:
enum State { enum State {
kStart, kStart,

View File

@ -41,6 +41,7 @@ All rights reserved.
#include "StatusViewShelf.h" #include "StatusViewShelf.h"
#include "StatusView.h" #include "StatusView.h"
TReplicantShelf::TReplicantShelf(TReplicantTray* parent) TReplicantShelf::TReplicantShelf(TReplicantTray* parent)
: BShelf(parent, false, "DeskbarShelf") : BShelf(parent, false, "DeskbarShelf")
{ {
@ -48,19 +49,21 @@ TReplicantShelf::TReplicantShelf(TReplicantTray* parent)
SetAllowsZombies(false); SetAllowsZombies(false);
} }
TReplicantShelf::~TReplicantShelf() TReplicantShelf::~TReplicantShelf()
{ {
} }
void void
TReplicantShelf::MessageReceived(BMessage* message) TReplicantShelf::MessageReceived(BMessage* message)
{ {
switch(message->what) { switch (message->what) {
case B_DELETE_PROPERTY: case B_DELETE_PROPERTY:
{ {
BMessage repspec; BMessage repspec;
int32 index = 0; int32 index = 0;
//
// this should only occur via scripting // this should only occur via scripting
// since we can't use ReplicantDeleted // since we can't use ReplicantDeleted
// catch the message and find the id or name specifier // catch the message and find the id or name specifier
@ -70,7 +73,7 @@ TReplicantShelf::MessageReceived(BMessage* message)
// after a remove when done through scripting // after a remove when done through scripting
// //
// note: if specified by index its the index not the id! // note: if specified by index its the index not the id!
//
while (message->FindMessage("specifiers", index++, &repspec) == B_OK) { while (message->FindMessage("specifiers", index++, &repspec) == B_OK) {
const char* str; const char* str;
if (repspec.FindString("property", &str) == B_OK) { if (repspec.FindString("property", &str) == B_OK) {
@ -89,8 +92,8 @@ TReplicantShelf::MessageReceived(BMessage* message)
} }
} }
} }
}
break; break;
}
default: default:
BShelf::MessageReceived(message); BShelf::MessageReceived(message);
@ -98,8 +101,10 @@ TReplicantShelf::MessageReceived(BMessage* message)
} }
} }
bool bool
TReplicantShelf::CanAcceptReplicantView(BRect frame, BView* view, BMessage* message) const TReplicantShelf::CanAcceptReplicantView(BRect frame, BView* view,
BMessage* message) const
{ {
if (view->ResizingMode() != B_FOLLOW_NONE) if (view->ResizingMode() != B_FOLLOW_NONE)
view->SetResizingMode(B_FOLLOW_NONE); view->SetResizingMode(B_FOLLOW_NONE);
@ -108,24 +113,23 @@ TReplicantShelf::CanAcceptReplicantView(BRect frame, BView* view, BMessage* mess
return fParent->AcceptAddon(frame, message); return fParent->AcceptAddon(frame, message);
} }
BPoint BPoint
TReplicantShelf::AdjustReplicantBy(BRect frame, BMessage *message) const TReplicantShelf::AdjustReplicantBy(BRect frame, BMessage *message) const
{ {
// added in AcceptAddon, from TReplicantTray // added in AcceptAddon, from TReplicantTray
BPoint pt; BPoint point;
message->FindPoint("_pjp_loc", &pt); message->FindPoint("_pjp_loc", &point);
message->RemoveName("_pjp_loc"); message->RemoveName("_pjp_loc");
pt = pt - frame.LeftTop(); return point - frame.LeftTop();
return pt;
} }
//
// the virtual BShelf::ReplicantDeleted is called before the // the virtual BShelf::ReplicantDeleted is called before the
// replicant is actually removed from BShelf's internal list // replicant is actually removed from BShelf's internal list
// thus, this returns the wrong number of replicants. // thus, this returns the wrong number of replicants.
//
void void
TReplicantShelf::ReplicantDeleted(int32, const BMessage*, const BView*) TReplicantShelf::ReplicantDeleted(int32, const BMessage*, const BView*)
{ {