Beispiel #1
0
void
TExpandoMenuBar::CheckItemSizes(int32 delta)
{
	float width = Frame().Width();
	int32 count = CountItems();
	bool reset = false;
	float newWidth = 0;
	float fullWidth = (sMinimumWindowWidth * count);

	if (!fBarView->Vertical()) {
		// in this case there are 2 extra items:
		//   - The Be Menu
		//   - The little separator item
		fullWidth = fullWidth - (sMinimumWindowWidth * 2)
			+ (fBeMenuWidth + kSepItemWidth);
		width -= (fBeMenuWidth + kSepItemWidth);
		count -= 2;
	}

	if (delta >= 0 && fullWidth > width) {
		fOverflow = true;
		reset = true;
		newWidth = floorf(width / count);
	} else if (delta < 0 && fOverflow) {
		reset = true;
		if (fullWidth > width)
			newWidth = floorf(width / count);
		else
			newWidth = sMinimumWindowWidth;
	}
	if (newWidth > sMinimumWindowWidth)
		newWidth = sMinimumWindowWidth;

	if (reset) {
		SetMaxContentWidth(newWidth);
		if (newWidth == sMinimumWindowWidth)
			fOverflow = false;
		InvalidateLayout();

		for (int32 index = fFirstApp; ; index++) {
			TTeamMenuItem* item = (TTeamMenuItem*)ItemAt(index);
			if (!item)
				break;
			item->SetOverrideWidth(newWidth);
		}

		Invalidate();
		Window()->UpdateIfNeeded();
	}
}
Beispiel #2
0
void
TExpandoMenuBar::BuildItems()
{
	BMessenger self(this);
	TBarApp::Subscribe(self, &fTeamList);

	int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
	desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();

	float itemWidth = -1.0f;
	if (fVertical)
		itemWidth = Frame().Width();
	else {
		itemWidth = iconSize;
		if (!settings->hideLabels)
			itemWidth += gMinimumWindowWidth - kMinimumIconSize;
		else
			itemWidth += kIconPadding * 2;
	}
	float itemHeight = -1.0f;

	TeamMenuItemMap items;
	int32 itemCount = CountItems();
	BList itemList(itemCount);
	for (int32 i = 0; i < itemCount; i++) {
		BMenuItem* menuItem = RemoveItem((int32)0);
		itemList.AddItem(menuItem);
		TTeamMenuItem* item = dynamic_cast<TTeamMenuItem*>(menuItem);
		if (item != NULL)
			items[BString(item->Signature()).ToLower()] = item;
	}

	if (settings->sortRunningApps)
		fTeamList.SortItems(TTeamMenu::CompareByName);

	int32 teamCount = fTeamList.CountItems();
	for (int32 i = 0; i < teamCount; i++) {
		BarTeamInfo* barInfo = (BarTeamInfo*)fTeamList.ItemAt(i);
		TeamMenuItemMap::const_iterator iter
			= items.find(BString(barInfo->sig).ToLower());
		if (iter == items.end()) {
			// new team
			TTeamMenuItem* item = new TTeamMenuItem(barInfo->teams,
				barInfo->icon, barInfo->name, barInfo->sig, itemWidth,
				itemHeight);

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

			if (fFirstBuild && fVertical && settings->expandNewTeams)
				item->ToggleExpandState(true);

		} else {
			// existing team, update info and add it
			TTeamMenuItem* item = iter->second;
			item->SetIcon(barInfo->icon);
			item->SetOverrideWidth(itemWidth);
			item->SetOverrideHeight(itemHeight);

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

			// add window items back
			int32 index = itemList.IndexOf(item);
			TWindowMenuItem* windowItem;
			TWindowMenu* submenu = dynamic_cast<TWindowMenu*>(item->Submenu());
			bool hasWindowItems = false;
			while ((windowItem = dynamic_cast<TWindowMenuItem*>(
					(BMenuItem*)(itemList.ItemAt(++index)))) != NULL) {
				if (fVertical)
					AddItem(windowItem);
				else {
					delete windowItem;
					hasWindowItems = submenu != NULL;
				}
			}

			// unexpand if turn off show team expander
			if (fVertical && !settings->superExpando && item->IsExpanded())
				item->ToggleExpandState(false);

			if (hasWindowItems) {
				// add (new) window items in submenu
				submenu->SetExpanded(false, 0);
				submenu->AttachedToWindow();
			}
		}
	}

	if (CountItems() == 0) {
		// If we're empty, BMenuBar::AttachedToWindow() resizes us to some
		// weird value - we just override it again
		ResizeTo(itemWidth, 0);
	}

	fFirstBuild = false;
}
Beispiel #3
0
void
TExpandoMenuBar::CheckItemSizes(int32 delta)
{
	if (fBarView->Vertical())
		return;

	bool drawLabels = !static_cast<TBarApp*>(be_app)->Settings()->hideLabels;

	float maxWidth = fBarView->DragRegion()->Frame().left
		- fDeskbarMenuWidth - kSepItemWidth;
	int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
	float iconOnlyWidth = kIconPadding + iconSize + kIconPadding;
	float minItemWidth = drawLabels
		? iconOnlyWidth + kMinMenuItemWidth
		: iconOnlyWidth - kIconPadding;
	float maxItemWidth = drawLabels
		? gMinimumWindowWidth + iconSize - kMinimumIconSize
		: iconOnlyWidth;
	float menuWidth = maxItemWidth * CountItems() + fDeskbarMenuWidth
		+ kSepItemWidth;

	bool reset = false;
	float newWidth = -1.0f;

	if (delta >= 0 && menuWidth > maxWidth) {
		fOverflow = true;
		reset = true;
		newWidth = floorf(maxWidth / CountItems());
	} else if (delta < 0 && fOverflow) {
		reset = true;
		if (menuWidth > maxWidth)
			newWidth = floorf(maxWidth / CountItems());
		else
			newWidth = maxItemWidth;
	}

	if (reset) {
		if (newWidth > maxItemWidth)
			newWidth = maxItemWidth;
		else if (newWidth < minItemWidth)
			newWidth = minItemWidth;

		SetMaxContentWidth(newWidth);
		if (newWidth == maxItemWidth)
			fOverflow = false;

		InvalidateLayout();

		for (int32 index = 0; ; index++) {
			TTeamMenuItem* item = (TTeamMenuItem*)ItemAt(index);
			if (item == NULL)
				break;

			item->SetOverrideWidth(newWidth);
		}

		Invalidate();
		Window()->UpdateIfNeeded();
		fBarView->CheckForScrolling();
	}
}
Beispiel #4
0
void
TExpandoMenuBar::CheckItemSizes(int32 delta)
{
	if (fBarView->Vertical())
		return;

	int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
	float maxContentWidth = sMinimumWindowWidth + iconSize - kMinimumIconSize;

	// There are 2 extra items:
	//     The Be Menu
	//     The little separator item
	int32 count = CountItems() - 2;
	float maxWidth = Frame().Width() - fDeskbarMenuWidth - kSepItemWidth * 2;
	float fullWidth = maxContentWidth * count + fDeskbarMenuWidth
		+ kSepItemWidth;
	float iconOnlyWidth = kIconPadding + iconSize + kIconPadding;

	bool reset = false;
	float newWidth = 0.0f;

	if (delta >= 0 && fullWidth > maxWidth) {
		fOverflow = true;
		reset = true;
		if (fDrawLabel)
			newWidth = floorf(maxWidth / count);
		else
			newWidth = iconOnlyWidth;
	} else if (delta < 0 && fOverflow) {
		reset = true;
		if (fullWidth > maxWidth) {
			if (fDrawLabel)
				newWidth = floorf(maxWidth / count);
			else
				newWidth = iconOnlyWidth;
		} else
			newWidth = maxContentWidth;
	}

	if (newWidth > maxContentWidth)
		newWidth = maxContentWidth;

	if (reset) {
		SetMaxContentWidth(newWidth);
		if (newWidth == maxContentWidth)
			fOverflow = false;
		InvalidateLayout();

		for (int32 index = fFirstApp; ; index++) {
			TTeamMenuItem* item = (TTeamMenuItem*)ItemAt(index);
			if (!item)
				break;

			if (!fDrawLabel && newWidth > iconOnlyWidth) {
				item->SetOverrideWidth(iconOnlyWidth);
			} else {
				item->SetOverrideWidth(newWidth);
			}
		}

		Invalidate();
		Window()->UpdateIfNeeded();
	}
}