示例#1
0
void
TTeamMenuItem::ToggleExpandState(bool resizeWindow)
{
	fExpanded = !fExpanded;

	if (fExpanded) {
		// Populate Menu() with the stuff from SubMenu().
		TWindowMenu* sub = (static_cast<TWindowMenu*>(Submenu()));
		if (sub) {
			// force the menu to update it's contents.
			bool locked = sub->LockLooper();
				// if locking the looper failed, the menu is just not visible
			sub->AttachedToWindow();
			if (locked)
				sub->UnlockLooper();

			if (sub->CountItems() > 1) {
				TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu());
				int myindex = parent->IndexOf(this) + 1;

				TWindowMenuItem* windowItem = NULL;
				int childIndex = 0;
				int totalChildren = sub->CountItems() - 4;
					// hide, show, close, separator.
				for (; childIndex < totalChildren; childIndex++) {
					windowItem = static_cast<TWindowMenuItem*>
						(sub->RemoveItem((int32)0));
					parent->AddItem(windowItem, myindex + childIndex);
					windowItem->ExpandedItem(true);
				}
				sub->SetExpanded(true, myindex + childIndex);

				if (resizeWindow)
					parent->SizeWindow();
			}
		}
	} else {
		// Remove the goodies from the Menu() that should be in the SubMenu();
		TWindowMenu* sub = static_cast<TWindowMenu*>(Submenu());

		if (sub) {
			TExpandoMenuBar* parent = static_cast<TExpandoMenuBar*>(Menu());

			TWindowMenuItem* windowItem = NULL;
			int childIndex = parent->IndexOf(this) + 1;
			while (!parent->SubmenuAt(childIndex) && childIndex
				< parent->CountItems()) {
				windowItem = static_cast<TWindowMenuItem*>
					(parent->RemoveItem(childIndex));
				sub->AddItem(windowItem, 0);
				windowItem->ExpandedItem(false);
			}
			sub->SetExpanded(false, 0);

			if (resizeWindow)
				parent->SizeWindow();
		}
	}
}
示例#2
0
	virtual void PrepareToShow(BLooper* parentLooper, BHandler* targetHandler,
		Settings* settings)
	{
		SettingsOption* selectedOption = settings->OptionValue(
			dynamic_cast<OptionsSetting*>(GetSetting()));

		for (int32 i = 0; BMenuItem* item = Submenu()->ItemAt(i); i++) {
			OptionMenuItem* optionItem = dynamic_cast<OptionMenuItem*>(item);
			if (optionItem != NULL)
				optionItem->PrepareToShow(parentLooper, targetHandler,
					settings, dynamic_cast<OptionsSetting*>(GetSetting()));

			optionItem->SetMarked(optionItem->Option() == selectedOption);
		}
	}
示例#3
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);
}