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
+33 -3
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);
+3 -2
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
+124 -124
View File
@@ -69,25 +69,25 @@ const int32 kMenuTrackMargin = 20;
TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
bool showInterval, uint32 state, float, bool showTime) bool showInterval, uint32 state, float, bool showTime)
: BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
fBarMenuBar(NULL), fBarMenuBar(NULL),
fExpando(NULL), fExpando(NULL),
fTrayLocation(1), fTrayLocation(1),
fShowInterval(showInterval), fShowInterval(showInterval),
fShowClock(showTime), fShowClock(showTime),
fVertical(vertical), fVertical(vertical),
fTop(top), fTop(top),
fLeft(left), fLeft(left),
fState(static_cast<int32>(state)), fState(static_cast<int32>(state)),
fRefsRcvdOnly(true), fRefsRcvdOnly(true),
fDragMessage(NULL), fDragMessage(NULL),
fCachedTypesList(NULL), fCachedTypesList(NULL),
fMaxRecentDocs(kDefaultRecentDocCount), fMaxRecentDocs(kDefaultRecentDocCount),
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
{ {
} }
@@ -96,9 +96,9 @@ TBarView::~TBarView()
{ {
delete fDragMessage; delete fDragMessage;
delete fCachedTypesList; delete fCachedTypesList;
// !! this should be done in DetachedFromWindow // !! this should be done in DetachedFromWindow
// to be symetric // to be symetric
delete fTrackingHookData.fDragMessage; delete fTrackingHookData.fDragMessage;
} }
@@ -150,24 +150,24 @@ 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
HandleBeMenu(message); HandleBeMenu(message);
break; break;
case B_ARCHIVED_OBJECT: case B_ARCHIVED_OBJECT:
// this message has been retargeted to here {
// instead of directly to the replicant tray // this message has been retargeted to here
// so that I can follow the common pathway // instead of directly to the replicant tray
// for adding icons to the tray // so that I can follow the common pathway
{ // 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());
@@ -226,22 +227,22 @@ TBarView::PlaceBeMenu()
void void
TBarView::PlaceTray(bool, bool, BRect screenFrame) TBarView::PlaceTray(bool, bool, BRect screenFrame)
{ {
BPoint statusLoc; BPoint statusLoc;
if (fState == kFullState) { if (fState == kFullState) {
fDragRegion->ResizeTo(fBarMenuBar->Frame().Width(), kMenuBarHeight); fDragRegion->ResizeTo(fBarMenuBar->Frame().Width(), kMenuBarHeight);
statusLoc.y = fBarMenuBar->Frame().bottom + 1; statusLoc.y = fBarMenuBar->Frame().bottom + 1;
statusLoc.x = 0; statusLoc.x = 0;
fDragRegion->MoveTo(statusLoc); fDragRegion->MoveTo(statusLoc);
if (!fReplicantTray->IsHidden()) if (!fReplicantTray->IsHidden())
fReplicantTray->Hide(); fReplicantTray->Hide();
return; return;
} }
if (fReplicantTray->IsHidden()) if (fReplicantTray->IsHidden())
fReplicantTray->Show(); fReplicantTray->Show();
if (fTrayLocation != 0) { if (fTrayLocation != 0) {
fReplicantTray->SetMultiRow(fVertical); fReplicantTray->SetMultiRow(fVertical);
fReplicantTray->RealignReplicants(); fReplicantTray->RealignReplicants();
@@ -274,15 +275,14 @@ TBarView::PlaceApplicationBar(BRect screenFrame)
} }
if (fState == kMiniState) if (fState == kMiniState)
return; return;
BRect expandoFrame(0, 0, 0, 0); BRect expandoFrame(0, 0, 0, 0);
if (fVertical) { if (fVertical) {
// 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);
} }
@@ -331,7 +330,7 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float *width, float *height)
else else
windowHeight = fBarMenuBar->Frame().bottom; windowHeight = fBarMenuBar->Frame().bottom;
} }
*width = windowWidth; *width = windowWidth;
*height = windowHeight; *height = windowHeight;
} }
@@ -406,7 +405,7 @@ TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)
fVertical = vertical; fVertical = vertical;
fLeft = left; fLeft = left;
fTop = top; fTop = top;
BRect screenFrame = (BScreen(Window())).Frame(); BRect screenFrame = (BScreen(Window())).Frame();
PlaceBeMenu(); PlaceBeMenu();
@@ -548,41 +547,42 @@ TBarView::CacheDragData(BMessage *incoming)
if (Dragging() && SpringLoadedFolderCompareMessages(incoming, fDragMessage)) if (Dragging() && SpringLoadedFolderCompareMessages(incoming, fDragMessage))
return; return;
// disposes then fills cached drag message and // disposes then fills cached drag message and
// mimetypes list // mimetypes list
SpringLoadedFolderCacheDragData(incoming, &fDragMessage, &fCachedTypesList); SpringLoadedFolderCacheDragData(incoming, &fDragMessage, &fCachedTypesList);
} }
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);
}
} }
status_t status_t
TBarView::DragStart() TBarView::DragStart()
{ {
// always set the click to open state // always set the click to open state
// to false during a drag // to false during a drag
// so that a release on a menu/menubar will not // so that a release on a menu/menubar will not
// leave the menu open (ExpandoMenuBar, BarMenuBar) // leave the menu open (ExpandoMenuBar, BarMenuBar)
// will get reset to actual initial system // will get reset to actual initial system
// state on DragStop // state on DragStop
_menu_info_ptr_->click_to_open = false; _menu_info_ptr_->click_to_open = false;
if (!Dragging()) if (!Dragging())
return B_OK; return B_OK;
BPoint loc; BPoint loc;
uint32 buttons; uint32 buttons;
GetMouse(&loc, &buttons); GetMouse(&loc, &buttons);
@@ -602,7 +602,7 @@ TBarView::DragStart()
fLastDragItem = item; fLastDragItem = item;
} }
} }
return B_OK; return B_OK;
} }
@@ -610,17 +610,15 @@ TBarView::DragStart()
bool bool
TBarView::MenuTrackingHook(BMenu *menu, void *castToThis) TBarView::MenuTrackingHook(BMenu *menu, void *castToThis)
{ {
// return true if the menu should go away // return true if the menu should go away
TrackingHookData *data = static_cast<TrackingHookData *>(castToThis); TrackingHookData *data = static_cast<TrackingHookData *>(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);
@@ -630,16 +628,16 @@ TBarView::MenuTrackingHook(BMenu *menu, void *castToThis)
frame.InsetBy(-kMenuTrackMargin, -kMenuTrackMargin); frame.InsetBy(-kMenuTrackMargin, -kMenuTrackMargin);
if (frame.Contains(location)) { if (frame.Contains(location)) {
// if current loc is still in the menu // if current loc is still in the menu
// keep tracking // keep tracking
returnvalue = false; returnvalue = false;
} else { } else {
// see if the mouse is in the team/be menu item // see if the mouse is in the team/be menu item
menu->ConvertToScreen(&location); menu->ConvertToScreen(&location);
if (barview->LockLooper()) { if (barview->LockLooper()) {
TExpandoMenuBar *expando = barview->ExpandoMenuBar(); TExpandoMenuBar *expando = barview->ExpandoMenuBar();
TBeMenu *bemenu = (dynamic_cast<TBarWindow*>(barview->Window()))->BeMenu(); TBeMenu *bemenu = (dynamic_cast<TBarWindow*>(barview->Window()))->BeMenu();
if (bemenu && bemenu->LockLooper()) { if (bemenu && bemenu->LockLooper()) {
bemenu->ConvertFromScreen(&location); bemenu->ConvertFromScreen(&location);
if (bemenu->Frame().Contains(location)) if (bemenu->Frame().Contains(location))
@@ -647,7 +645,7 @@ TBarView::MenuTrackingHook(BMenu *menu, void *castToThis)
bemenu->UnlockLooper(); bemenu->UnlockLooper();
} }
if (returnvalue && expando) { if (returnvalue && expando) {
expando->ConvertFromScreen(&location); expando->ConvertFromScreen(&location);
TTeamMenuItem *item = expando->ItemAtPoint(location); TTeamMenuItem *item = expando->ItemAtPoint(location);
@@ -657,22 +655,20 @@ TBarView::MenuTrackingHook(BMenu *menu, void *castToThis)
barview->UnlockLooper(); barview->UnlockLooper();
} }
} }
menu->UnlockLooper(); menu->UnlockLooper();
return returnvalue; return returnvalue;
} }
// // 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
return &fTrackingHookData; return &fTrackingHookData;
} }
@@ -682,10 +678,9 @@ 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;
if (fExpando) { if (fExpando) {
@@ -694,11 +689,11 @@ TBarView::DragStop(bool full)
fLastDragItem = NULL; fLastDragItem = NULL;
} }
} }
if (full) { if (full) {
delete fDragMessage; delete fDragMessage;
fDragMessage = NULL; fDragMessage = NULL;
delete fCachedTypesList; delete fCachedTypesList;
fCachedTypesList = NULL; fCachedTypesList = NULL;
} }
@@ -709,37 +704,41 @@ bool
TBarView::AppCanHandleTypes(const char *signature) 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);
if (appmime.GetAppHint(&hintref) != B_OK) if (appmime.GetAppHint(&hintref) != B_OK)
return false; return false;
// an app was found, now see if it supports any of // an app was found, now see if it supports any of
// the refs in the message // the refs in the message
BFile file(&hintref, O_RDONLY); BFile file(&hintref, O_RDONLY);
BAppFileInfo fileinfo(&file); BAppFileInfo fileinfo(&file);
// scan the cached mimetype list and see if this app // scan the cached mimetype list and see if this app
// supports anything in the list // supports anything in the list
// 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;
} }
@@ -765,15 +764,15 @@ TBarView::SendDragMessage(const char *signature, entry_ref *ref)
status_t err = B_ERROR; status_t err = B_ERROR;
if (fDragMessage) { if (fDragMessage) {
if (fRefsRcvdOnly) { if (fRefsRcvdOnly) {
// current message sent to apps is only B_REFS_RECEIVED // current message sent to apps is only B_REFS_RECEIVED
fDragMessage->what = B_REFS_RECEIVED; fDragMessage->what = B_REFS_RECEIVED;
} }
BRoster roster; BRoster roster;
if (signature && strlen(signature) > 0 && roster.IsRunning(signature)) { if (signature && strlen(signature) > 0 && roster.IsRunning(signature)) {
BMessenger mess(signature); BMessenger mess(signature);
// drag message is still owned by DB, copy is sent // drag message is still owned by DB, copy is sent
// can toss it after send // can toss it after send
err = mess.SendMessage(fDragMessage); err = mess.SendMessage(fDragMessage);
} else if (ref) { } else if (ref) {
FSLaunchItem((const entry_ref*)ref, (const BMessage*)fDragMessage, FSLaunchItem((const entry_ref*)ref, (const BMessage*)fDragMessage,
@@ -789,14 +788,14 @@ TBarView::SendDragMessage(const char *signature, entry_ref *ref)
bool bool
TBarView::InvokeItem(const char *signature) TBarView::InvokeItem(const char *signature)
{ {
// sent from TeamMenuItem // sent from TeamMenuItem
if (Dragging() && AppCanHandleTypes(signature)) { if (Dragging() && AppCanHandleTypes(signature)) {
SendDragMessage(signature); SendDragMessage(signature);
// invoking okay to toss memory // invoking okay to toss memory
DragStop(true); DragStop(true);
return true; return true;
} }
return false; return false;
} }
@@ -806,10 +805,10 @@ TBarView::HandleBeMenu(BMessage *messagewithdestination)
{ {
if (!Dragging()) if (!Dragging())
return; return;
// in mini-mode // in mini-mode
if (Vertical() && !Expando()) { if (Vertical() && !Expando()) {
// if drop is in the team menu, bail // if drop is in the team menu, bail
if (fBarMenuBar->CountItems() >= 2) { if (fBarMenuBar->CountItems() >= 2) {
uint32 buttons; uint32 buttons;
BPoint location; BPoint location;
@@ -818,32 +817,34 @@ TBarView::HandleBeMenu(BMessage *messagewithdestination)
return; return;
} }
} }
if (messagewithdestination) { if (messagewithdestination) {
entry_ref ref; entry_ref ref;
if (messagewithdestination->FindRef("refs", &ref) == B_OK) { if (messagewithdestination->FindRef("refs", &ref) == B_OK) {
BEntry entry(&ref, true); BEntry entry(&ref, true);
if (entry.IsDirectory()) { if (entry.IsDirectory()) {
// if the ref received (should only be 1) is a directory // if the ref received (should only be 1) is a directory
// then add the drag refs to the directory // then add the drag refs to the directory
AddRefsToBeMenu(DragMessage(), &ref); AddRefsToBeMenu(DragMessage(), &ref);
} 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);
} }
// #pragma mark - Add-ons // #pragma mark - Add-ons
// shelf is ignored for now,
// it exists in anticipation of having other 'shelves' for // shelf is ignored for now,
// storing items // it exists in anticipation of having other 'shelves' for
// storing items
status_t status_t
TBarView::ItemInfo(int32 id, const char **name, DeskbarShelf *shelf) TBarView::ItemInfo(int32 id, const char **name, DeskbarShelf *shelf)
@@ -909,10 +910,10 @@ TBarView::OffsetIconFrame(BRect rect) const
BRect frame(Frame()); BRect frame(Frame());
frame.left += fDragRegion->Frame().left + fReplicantTray->Frame().left + rect.left; frame.left += fDragRegion->Frame().left + fReplicantTray->Frame().left + rect.left;
frame.top += fDragRegion->Frame().top + fReplicantTray->Frame().top + rect.top; frame.top += fDragRegion->Frame().top + fReplicantTray->Frame().top + rect.top;
frame.right = frame.left + rect.Width(); frame.right = frame.left + rect.Width();
frame.bottom = frame.top + rect.Height(); frame.bottom = frame.top + rect.Height();
return frame; return frame;
} }
@@ -930,4 +931,3 @@ TBarView::IconFrame(const char *name) const
return OffsetIconFrame(fReplicantTray->IconFrame(name)); return OffsetIconFrame(fReplicantTray->IconFrame(name));
} }
+65 -67
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)
{ {
} }
@@ -101,13 +102,13 @@ TBeMenu::AttachedToWindow()
if (fBarView->Dragging()) { if (fBarView->Dragging()) {
SetTypesList(fBarView->CachedTypesList()); SetTypesList(fBarView->CachedTypesList());
SetTarget(BMessenger(fBarView)); SetTarget(BMessenger(fBarView));
SetTrackingHookDeep(this, fBarView->MenuTrackingHook, SetTrackingHookDeep(this, fBarView->MenuTrackingHook,
fBarView->GetTrackingHookData()); fBarView->GetTrackingHookData());
fBarView->DragStart(); fBarView->DragStart();
} else { } else {
SetTypesList(NULL); SetTypesList(NULL);
SetTarget(BMessenger(kTrackerSignature)); SetTarget(DefaultTarget());
SetTrackingHookDeep(this, NULL, NULL); SetTrackingHookDeep(this, NULL, NULL);
} }
fBarView->UnlockLooper(); fBarView->UnlockLooper();
@@ -336,7 +337,7 @@ TBeMenu::AddStandardBeMenuItems()
AddItem(subMenu); AddItem(subMenu);
if ((modifiers() & (B_LEFT_SHIFT_KEY|B_LEFT_CONTROL_KEY|B_LEFT_COMMAND_KEY)) if ((modifiers() & (B_LEFT_SHIFT_KEY|B_LEFT_CONTROL_KEY|B_LEFT_COMMAND_KEY))
== (B_LEFT_SHIFT_KEY|B_LEFT_CONTROL_KEY|B_LEFT_COMMAND_KEY)) { == (B_LEFT_SHIFT_KEY|B_LEFT_CONTROL_KEY|B_LEFT_COMMAND_KEY)) {
subMenu = new BMenu("Window Decor"); subMenu = new BMenu("Window Decor");
subMenu->SetEnabled(!dragging); subMenu->SetEnabled(!dragging);
@@ -402,17 +403,14 @@ void
TBeMenu::ResetTargets() 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,17 +422,15 @@ 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:
// about, find // about, find
item->SetTarget(BMessenger(kTrackerSignature)); item->SetTarget(BMessenger(kTrackerSignature));
break; break;
case msg_ToggleDraggers: case msg_ToggleDraggers:
case msg_config_db: case msg_config_db:
case msg_AlwaysTop: case msg_AlwaysTop:
@@ -464,33 +460,45 @@ TBeMenu::ResetTargets()
BPoint BPoint
TBeMenu::ScreenLocation() TBeMenu::ScreenLocation()
{ {
BPoint pt; bool vertical = fBarView->Vertical();
BRect r; int32 expando = (fBarView->State() == kExpandoState);
bool vertical = fBarView->Vertical(); BPoint point;
int32 expando = (fBarView->State() == kExpandoState);
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,13 +559,13 @@ TRecentsMenu::StartBuildingItemList()
RemoveItem(index); RemoveItem(index);
delete item; delete item;
} }
// !! note: don't call inherited from here
// the navref is not set for this menu
// but it still needs to be a draggable navmenu
// simply return true so that AddNextItem is called
// //
// !! note: don't call inherited from here // return BNavMenu::StartBuildingItemList();
// the navref is not set for this menu
// but it still needs to be a draggable navmenu
// simply return true so that AddNextItem is called
//
// return BNavMenu::StartBuildingItemList();
return true; return true;
} }
@@ -657,14 +665,12 @@ TRecentsMenu::AddRecents(int32 count)
} }
} }
// return true so that we know to reenter this list // return true so that we know to reenter this list
return true; return true;
} }
} }
// // 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);
+6 -4
View File
@@ -57,16 +57,16 @@ class TRecentsMenu : public BNavMenu {
void DetachedFromWindow(); void DetachedFromWindow();
void ResetTargets(); void ResetTargets();
int32 RecentsCount(); int32 RecentsCount();
private: private:
virtual bool StartBuildingItemList(); virtual bool StartBuildingItemList();
virtual bool AddNextItem(); virtual bool AddNextItem();
bool AddRecents(int32 count); bool AddRecents(int32 count);
virtual void DoneBuildingItemList(); virtual void DoneBuildingItemList();
virtual void ClearMenuBuildingState(); virtual void ClearMenuBuildingState();
private: private:
int32 fWhich; int32 fWhich;
entry_ref *fAppRef; entry_ref *fAppRef;
char *fSignature; char *fSignature;
@@ -95,6 +95,8 @@ class TBeMenu : public BNavMenu {
void ResetTargets(); void ResetTargets();
static BMessenger DefaultTarget();
private: private:
enum State { enum State {
kStart, kStart,
+28 -24
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,29 +49,31 @@ 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
// since we can't use ReplicantDeleted
// catch the message and find the id or name specifier
// then delete the rep vi the api,
// //
// this should only occur via scripting // this will fix the problem of realigning the reps
// since we can't use ReplicantDeleted // after a remove when done through scripting
// catch the message and find the id or name specifier
// then delete the rep vi the api,
//
// this will fix the problem of realigning the reps
// 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,17 +92,19 @@ TReplicantShelf::MessageReceived(BMessage* message)
} }
} }
} }
break;
} }
break;
default: default:
BShelf::MessageReceived(message); BShelf::MessageReceived(message);
break; break;
} }
} }
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*)
{ {