filter_result
BarViewMessageFilter::Filter(BMessage* message, BHandler** target)
{
	if (message->what == B_MOUSE_DOWN || message->what == B_MOUSE_MOVED) {
		BPoint where = message->FindPoint("be:view_where");
		uint32 transit = message->FindInt32("be:transit");
		BMessage* dragMessage = NULL;
		if (message->HasMessage("be:drag_message")) {
			dragMessage = new BMessage();
			message->FindMessage("be:drag_message", dragMessage);
		}

		switch (message->what) {
			case B_MOUSE_DOWN:
				fBarView->MouseDown(where);
				break;

			case B_MOUSE_MOVED:
				fBarView->MouseMoved(where, transit, dragMessage);
				break;
		}

		delete dragMessage;
	}

	return B_DISPATCH_MESSAGE;
}
Example #2
0
bool
TBarView::MenuTrackingHook(BMenu *menu, void *castToThis)
{
	//	return true if the menu should go away
	TrackingHookData *data = static_cast<TrackingHookData *>(castToThis);
	if (!data) 
		return false;

	
	TBarView *barview = dynamic_cast<TBarView *>(data->fTarget.Target(NULL));
	if (!barview || !menu->LockLooper())
		return false;

		
	uint32 buttons;
	BPoint location;
	menu->GetMouse(&location, &buttons);

	bool returnvalue = true;
	BRect frame(menu->Bounds());
	frame.InsetBy(-kMenuTrackMargin, -kMenuTrackMargin);

	if (frame.Contains(location)) {
		//	if current loc is still in the menu
		//	keep tracking
		returnvalue = false;
	} else {
		//	see if the mouse is in the team/be menu item
		menu->ConvertToScreen(&location);
		if (barview->LockLooper()) {
			TExpandoMenuBar *expando = barview->ExpandoMenuBar();
			TBeMenu *bemenu = (dynamic_cast<TBarWindow*>(barview->Window()))->BeMenu();
							
			if (bemenu && bemenu->LockLooper()) {
				bemenu->ConvertFromScreen(&location);
				if (bemenu->Frame().Contains(location)) 
					returnvalue = false;

				bemenu->UnlockLooper();
			}
			
			if (returnvalue && expando) {
				expando->ConvertFromScreen(&location);
				TTeamMenuItem *item = expando->ItemAtPoint(location);
				if (item) 
					returnvalue = false;
			}
			barview->UnlockLooper();
		}
	}
	
	menu->UnlockLooper();
	return returnvalue;
}
Example #3
0
status_t
TBarMenuTitle::Invoke(BMessage* message)
{
	TBarView* barview = dynamic_cast<TBarApp*>(be_app)->BarView();
	if (barview) {
		BLooper* looper = barview->Looper();
		if (looper->Lock()) {
			// tell barview to add the refs to the deskbar menu
			barview->HandleDeskbarMenu(NULL);
			looper->Unlock();
		}
	}

	return BMenuItem::Invoke(message);
}
Example #4
0
void
TTeamMenuItem::DrawContentLabel()
{
	BMenu* menu = Menu();
	menu->MovePenBy(0, fLabelAscent);

	float cachedWidth = menu->StringWidth(Label());
	if (Submenu() && fVertical)
		cachedWidth += 18;

	const char* label = Label();
	char* truncLabel = NULL;
	float max = 0;

	if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando)
		max = menu->MaxContentWidth() - kSwitchWidth;
	else
		max = menu->MaxContentWidth() - 4.0f;

	if (max > 0) {
		BPoint penloc = menu->PenLocation();
		BRect frame = Frame();
		float offset = penloc.x - frame.left;
		if (cachedWidth + offset > max) {
			truncLabel = (char*)malloc(strlen(label) + 4);
			if (!truncLabel)
				return;
			TruncateLabel(max-offset, truncLabel);
			label = truncLabel;
		}
	}

	if (!label)
		label = Label();

	TBarView* barview = (static_cast<TBarApp*>(be_app))->BarView();
	bool canHandle = !barview->Dragging()
		|| barview->AppCanHandleTypes(Signature());
	if (_IsSelected() && IsEnabled() && canHandle)
		menu->SetLowColor(tint_color(menu->LowColor(),
			B_HIGHLIGHT_BACKGROUND_TINT));
	else
		menu->SetLowColor(menu->LowColor());

	menu->DrawString(label);

	free(truncLabel);
}
Example #5
0
void
TWindowMenuItem::Draw()
{
	if (!fExpanded) {
		BMenuItem::Draw();
		return;
	}

	// TODO: Tint this smartly based on the low color, this does
	// nothing to black.
	rgb_color menuColor = tint_color(Menu()->LowColor(), 1.07);
	BRect frame(Frame());
	BMenu* menu = Menu();

	menu->PushState();

	// if not selected or being tracked on, fill with gray
	TBarView* barview = (static_cast<TBarApp*>(be_app))->BarView();
	if ((!IsSelected() && !menu->IsRedrawAfterSticky())
		|| barview->Dragging() || !IsEnabled()) {

		rgb_color shadow = tint_color(menuColor, 1.09);
		menu->SetHighColor(shadow);
		frame.right = frame.left + kHPad / 2;
		menu->FillRect(frame);

		menu->SetHighColor(menuColor);
		frame.left = frame.right + 1;
		frame.right = Frame().right;
		menu->FillRect(frame);
	}

	if (IsEnabled() && IsSelected() && !menu->IsRedrawAfterSticky()) {
		// fill
		rgb_color backColor = tint_color(menuColor,
			B_HIGHLIGHT_BACKGROUND_TINT);
		menu->SetLowColor(backColor);
		menu->SetHighColor(backColor);
		menu->FillRect(frame);
	} else {
		menu->SetLowColor(menuColor);
		menu->SetHighColor(menuColor);
	}

	DrawContent();

	menu->PopState();
}
Example #6
0
void
TTeamMenu::DetachedFromWindow()
{
	TBarView* barView = (dynamic_cast<TBarApp*>(be_app))->BarView();
	if (barView != NULL) {
		BLooper* looper = barView->Looper();
		if (looper != NULL && looper->Lock()) {
			barView->DragStop();
			looper->Unlock();
		}
	}

	BMenu::DetachedFromWindow();

	BMessenger self(this);
	TBarApp::Unsubscribe(self);
}
Example #7
0
void
TWindowMenu::DetachedFromWindow()
{
	// in expando mode the teammenu will not call DragStop,
	// thus, it needs to be called from here
	TBarView *barview = (dynamic_cast<TBarApp*>(be_app))->BarView();
	if (barview && barview->Expando()) {
		BLooper *looper = barview->Looper();
		if (looper->Lock()) {
			Window()->Show();		// We changed the show level in AttachedToWindow().  Undo it.
			barview->DragStop();
			looper->Unlock();
		}
	}
	
	BMenu::DetachedFromWindow();
}
Example #8
0
status_t
TTeamMenuItem::Invoke(BMessage* message)
{
	if ((static_cast<TBarApp*>(be_app))->BarView()->InvokeItem(Signature()))
		// handles drop on application
		return B_OK;

	// if the app could not handle the drag message
	// and we were dragging, then kill the drag
	// should never get here, disabled item will not invoke
	TBarView* barView = (static_cast<TBarApp*>(be_app))->BarView();
	if (barView && barView->Dragging())
		barView->DragStop();

	// bring to front or minimize shortcuts
	uint32 mods = modifiers();
	if (mods & B_CONTROL_KEY) {
		TShowHideMenuItem::TeamShowHideCommon((mods & B_SHIFT_KEY)
			? B_MINIMIZE_WINDOW : B_BRING_TO_FRONT, Teams());
	}

	return BMenuItem::Invoke(message);
}
Example #9
0
void
TTeamMenuItem::DrawContent()
{
	BMenu* menu = Menu();
	if (fIcon != NULL) {
		if (fIcon->ColorSpace() == B_RGBA32) {
			menu->SetDrawingMode(B_OP_ALPHA);
			menu->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
		} else
			menu->SetDrawingMode(B_OP_OVER);

		BRect frame(Frame());
		BRect iconBounds(fIcon->Bounds());
		BRect dstRect(iconBounds);
		float extra = fVertical ? 0.0f : -1.0f;
		BPoint contLoc = ContentLocation();
		BPoint drawLoc = contLoc + BPoint(kHPad, kVPad);

		if (!fDrawLabel || (fVertical && iconBounds.Width() > 32)) {
			float offsetx = contLoc.x
				+ ((frame.Width() - iconBounds.Width()) / 2) + extra;
			float offsety = contLoc.y + 3.0f + extra;

			dstRect.OffsetTo(BPoint(offsetx, offsety));
			menu->DrawBitmapAsync(fIcon, dstRect);

			drawLoc.x = ((frame.Width() - LabelWidth()) / 2);
			drawLoc.y = frame.top + iconBounds.Height() + 4.0f;
		} else {
			float offsetx = contLoc.x + kHPad;
			float offsety = contLoc.y + 
				((frame.Height() - iconBounds.Height()) / 2) + extra;

			dstRect.OffsetTo(BPoint(offsetx, offsety));
			menu->DrawBitmapAsync(fIcon, dstRect);

			float labelHeight = fLabelAscent + fLabelDescent;
			drawLoc.x += iconBounds.Width() + kLabelOffset;
			drawLoc.y = frame.top + ((frame.Height() - labelHeight) / 2) + extra;
		}

		menu->MovePenTo(drawLoc);
	}

	// set the pen to black so that either method will draw in the same color
	// low color is set in inherited::DrawContent, override makes sure its
	// what we want
	if (fDrawLabel) {
		menu->SetDrawingMode(B_OP_OVER);
		menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));

		// override the drawing of the content when the item is disabled
		// the wrong lowcolor is used when the item is disabled since the
		// text color does not change
		DrawContentLabel();
	}

	// Draw the expandable icon.
	TBarView* barView = (static_cast<TBarApp*>(be_app))->BarView();
	if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando
		&& barView->ExpandoState()) {
		BRect frame(Frame());
		BRect rect(0, 0, kSwitchWidth, 10);
		rect.OffsetTo(BPoint(frame.right - rect.Width(),
			ContentLocation().y + ((frame.Height() - rect.Height()) / 2)));

		if (be_control_look != NULL) {
			uint32 arrowDirection = fExpanded
				? BControlLook::B_UP_ARROW : BControlLook::B_DOWN_ARROW;
			be_control_look->DrawArrowShape(menu, rect, rect, menu->LowColor(),
				arrowDirection, 0, B_DARKEN_3_TINT);
		} else {
			rgb_color outlineColor = {80, 80, 80, 255};
			rgb_color middleColor = {200, 200, 200, 255};

			menu->SetDrawingMode(B_OP_OVER);

			if (!fExpanded) {
				menu->BeginLineArray(6);

				menu->AddLine(BPoint(rect.left + 3, rect.top + 1),
					BPoint(rect.left + 3, rect.bottom - 1), outlineColor);
				menu->AddLine(BPoint(rect.left + 3, rect.top + 1),
					BPoint(rect.left + 7, rect.top + 5), outlineColor);
				menu->AddLine(BPoint(rect.left + 7, rect.top + 5),
					BPoint(rect.left + 3, rect.bottom - 1), outlineColor);

				menu->AddLine(BPoint(rect.left + 4, rect.top + 3),
					BPoint(rect.left + 4, rect.bottom - 3), middleColor);
				menu->AddLine(BPoint(rect.left + 5, rect.top + 4),
					BPoint(rect.left + 5, rect.bottom - 4), middleColor);
				menu->AddLine(BPoint(rect.left + 5, rect.top + 5),
					BPoint(rect.left + 6, rect.top + 5), middleColor);
				menu->EndLineArray();
			} else {
				// expanded state

				menu->BeginLineArray(6);
				menu->AddLine(BPoint(rect.left + 1, rect.top + 3),
					BPoint(rect.right - 3, rect.top + 3), outlineColor);
				menu->AddLine(BPoint(rect.left + 1, rect.top + 3),
					BPoint(rect.left + 5, rect.top + 7), outlineColor);
				menu->AddLine(BPoint(rect.left + 5, rect.top + 7),
					BPoint(rect.right - 3, rect.top + 3), outlineColor);

				menu->AddLine(BPoint(rect.left + 3, rect.top + 4),
					BPoint(rect.right - 5, rect.top + 4), middleColor);
				menu->AddLine(BPoint(rect.left + 4, rect.top + 5),
					BPoint(rect.right - 6, rect.top + 5), middleColor);
				menu->AddLine(BPoint(rect.left + 5, rect.top + 5),
					BPoint(rect.left + 5, rect.top + 6), middleColor);
				menu->EndLineArray();
			}
		}
	}
}
Example #10
0
void
TTeamMenuItem::Draw()
{
	BRect frame(Frame());
	BMenu* menu = Menu();
	menu->PushState();
	rgb_color menuColor = menu->LowColor();
	TBarView* barView = (static_cast<TBarApp*>(be_app))->BarView();

	bool canHandle = !barView->Dragging()
		|| barView->AppCanHandleTypes(Signature());

	if (be_control_look != NULL) {
		uint32 flags = 0;
		if (_IsSelected() && canHandle)
			flags |= BControlLook::B_ACTIVATED;

		uint32 borders = BControlLook::B_TOP_BORDER;
		if (fVertical) {
			menu->SetHighColor(tint_color(menuColor, B_DARKEN_1_TINT));
			borders |= BControlLook::B_LEFT_BORDER
				| BControlLook::B_RIGHT_BORDER;
			menu->StrokeLine(frame.LeftBottom(), frame.RightBottom());
			frame.bottom--;

			be_control_look->DrawMenuBarBackground(menu, frame, frame,
				menuColor, flags, borders);
		} else {
			if (flags & BControlLook::B_ACTIVATED)
				menu->SetHighColor(tint_color(menuColor, B_DARKEN_3_TINT));
			else
				menu->SetHighColor(tint_color(menuColor, 1.22));
			borders |= BControlLook::B_BOTTOM_BORDER;
			menu->StrokeLine(frame.LeftTop(), frame.LeftBottom());
			frame.left++;

			be_control_look->DrawButtonBackground(menu, frame, frame,
				menuColor, flags, borders);
		}

		menu->MovePenTo(ContentLocation());
		DrawContent();
		menu->PopState();
		return;
	}

	// if not selected or being tracked on, fill with gray
	if ((!_IsSelected() && !menu->IsRedrawAfterSticky()) || !canHandle
		|| !IsEnabled()) {
		frame.InsetBy(1, 1);
		menu->SetHighColor(menuColor);
		menu->FillRect(frame);
	}

	// draw the gray, unselected item, border
	if (!_IsSelected() || !IsEnabled()) {
		rgb_color shadow = tint_color(menuColor, B_DARKEN_1_TINT);
		rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT);

		frame = Frame();

		menu->SetHighColor(shadow);
		if (fVertical)
			menu->StrokeLine(frame.LeftBottom(), frame.RightBottom());
		else
			menu->StrokeLine(frame.LeftBottom() + BPoint(1, 0),
				frame.RightBottom());

		menu->StrokeLine(frame.RightBottom(), frame.RightTop());

		menu->SetHighColor(light);
		menu->StrokeLine(frame.RightTop() + BPoint(-1, 0), frame.LeftTop());
		if (fVertical)
			menu->StrokeLine(frame.LeftTop(), frame.LeftBottom()
				+ BPoint(0, -1));
		else
			menu->StrokeLine(frame.LeftTop(), frame.LeftBottom());
	}

	// if selected or being tracked on, fill with the hilite gray color
	if (IsEnabled() && _IsSelected() && !menu->IsRedrawAfterSticky()
		&& canHandle) {
		// fill
		menu->SetHighColor(tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT));
		menu->FillRect(frame);

		// these continue the dark grey border on the left or top edge
		menu->SetHighColor(tint_color(menuColor, B_DARKEN_4_TINT));
		if (fVertical) {
			// dark line at top
			menu->StrokeLine(frame.LeftTop(), frame.RightTop());
		} else {
			// dark line on the left
			menu->StrokeLine(frame.LeftTop(), frame.LeftBottom());
		}
	} else
		menu->SetLowColor(menuColor);

	menu->MovePenTo(ContentLocation());
	DrawContent();
	menu->PopState();
}
Example #11
0
void
TWindowMenu::AttachedToWindow()
{
	SetFont(be_plain_font);

	RemoveItems(0, CountItems(), true);

	int32 miniCount = 0;

	bool dragging = false;
	TBarView* barview =(static_cast<TBarApp*>(be_app))->BarView();
	if (barview && barview->LockLooper()) {
		//	'dragging' mode set in BarView::CacheDragData
		//		invoke in MouseEnter in ExpandoMenuBar
		dragging = barview->Dragging();
		if (dragging) {
			// We don't want to show the menu when dragging, but it's not
			// possible to remove a submenu once it exists, so we simply hide it
			// Don't call BMenu::Hide(), it causes the menu to pop up every now
			// and then.
			Window()->Hide();
			//	if in expando (horizontal or vertical)
			if (barview->Expando()) {
				SetTrackingHook(barview->MenuTrackingHook,
					barview->GetTrackingHookData());
			}
			barview->DragStart();
		}
		barview->UnlockLooper();
	}

	int32 parentMenuItems = 0;

	int32 numTeams = fTeam->CountItems();
	for (int32 i = 0; i < numTeams; i++) {
		team_id	theTeam = (team_id)fTeam->ItemAt(i);
		int32 count = 0;
		int32* tokens = get_token_list(theTeam, &count);

		for (int32 j = 0; j < count; j++) {
			client_window_info* wInfo = get_window_info(tokens[j]);
			if (wInfo == NULL)
				continue;

			if (WindowShouldBeListed(wInfo->feel)
				&& (wInfo->show_hide_level <= 0 || wInfo->is_mini)) {
				// Don't add new items if we're expanded. We've already done
				// this, they've just been moved.
				int32 numItems = CountItems();
				int32 addIndex = 0;
				for (; addIndex < numItems; addIndex++)
					if (strcasecmp(ItemAt(addIndex)->Label(), wInfo->name) > 0)
						break;

				if (!fExpanded) {
					TWindowMenuItem* item = new TWindowMenuItem(wInfo->name,
						wInfo->server_token, wInfo->is_mini,
						((1 << current_workspace()) & wInfo->workspaces) != 0,
						dragging);

					// disable app's window dropping for now
					if (dragging)
						item->SetEnabled(false);

					AddItem(item,
						TWindowMenuItem::InsertIndexFor(this, 0, item));
				} else {
					TTeamMenuItem* parentItem
						= static_cast<TTeamMenuItem*>(Superitem());
					if (parentItem->ExpandedWindowItem(wInfo->server_token)) {
						TWindowMenuItem* item = parentItem->ExpandedWindowItem(
							wInfo->server_token);
						if (item == NULL)
							continue;

						item->SetTo(wInfo->name, wInfo->server_token,
							wInfo->is_mini,
							((1 << current_workspace()) & wInfo->workspaces)
								!= 0, dragging);
						parentMenuItems++;
					}
				}

				if (wInfo->is_mini)
					miniCount++;
			}
			free(wInfo);
		}
		free(tokens);
	}

	int32 itemCount = CountItems() + parentMenuItems;
	if (itemCount < 1) {
		TWindowMenuItem* noWindowsItem =
 			new TWindowMenuItem("No windows", -1, false, false);

		noWindowsItem->SetEnabled(false);

		AddItem(noWindowsItem);

		// if an application has no windows, this feature makes it easy to quit
		// it. (but we only add this option if the application is not Tracker.)
 		if (fApplicationSignature.ICompare(kTrackerSignature) != 0) {
			AddSeparatorItem();
			AddItem(new TShowHideMenuItem("Quit application", fTeam,
				B_QUIT_REQUESTED));
 		}
	} else {
		//	if we are in drag mode, then don't add the window controls
		//	to the menu
		if (!dragging) {
			TShowHideMenuItem* hide =
				new TShowHideMenuItem("Hide all", fTeam, B_MINIMIZE_WINDOW);
			TShowHideMenuItem* show =
				new TShowHideMenuItem("Show all", fTeam, B_BRING_TO_FRONT);
			TShowHideMenuItem* close =
				new TShowHideMenuItem("Close all", fTeam, B_QUIT_REQUESTED);

			if (miniCount == itemCount)
				hide->SetEnabled(false);
			else if (miniCount == 0)
				show->SetEnabled(false);

			if (!parentMenuItems)
				AddSeparatorItem();
			AddItem(hide);
			AddItem(show);
			AddItem(close);
		}
	}

	BMenu::AttachedToWindow();
}
Example #12
0
void
TTeamMenu::AttachedToWindow()
{
	RemoveItems(0, CountItems(), true);
		// remove all items

	BMessenger self(this);
	BList teamList;
	TBarApp::Subscribe(self, &teamList);

	TBarView* barview = (dynamic_cast<TBarApp*>(be_app))->BarView();
	bool dragging = barview && barview->Dragging();
	int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
	desk_settings* settings = ((TBarApp*)be_app)->Settings();

	float width = sMinimumWindowWidth - iconSize - 4;

	if (settings->sortRunningApps)
		teamList.SortItems(CompareByName);

	int32 count = teamList.CountItems();
	for (int32 i = 0; i < count; i++) {
		// add items back
		BarTeamInfo* barInfo = (BarTeamInfo*)teamList.ItemAt(i);
		TTeamMenuItem* item = new TTeamMenuItem(barInfo->teams,
			barInfo->icon, barInfo->name, barInfo->sig,
			width, -1, !settings->hideLabels, true);

		if (settings->trackerAlwaysFirst
			&& strcmp(barInfo->sig, kTrackerSignature) == 0) {
			AddItem(item, 0);
		} else
			AddItem(item);

		if (dragging && item != NULL) {
			bool canhandle = (dynamic_cast<TBarApp*>(be_app))->BarView()->
				AppCanHandleTypes(item->Signature());
			if (item->IsEnabled() != canhandle)
				item->SetEnabled(canhandle);

			BMenu* menu = item->Submenu();
			if (menu)
				menu->SetTrackingHook(barview->MenuTrackingHook,
					barview->GetTrackingHookData());
		}
	}

	if (CountItems() == 0) {
		BMenuItem* item = new BMenuItem("no application running", NULL);
		item->SetEnabled(false);
		AddItem(item);
	}

	if (dragging && barview->LockLooper()) {
		SetTrackingHook(barview->MenuTrackingHook,
			barview->GetTrackingHookData());
		barview->DragStart();
		barview->UnlockLooper();
	}

	BMenu::AttachedToWindow();
}