当前位置: 首页>>代码示例>>C++>>正文


C++ BMenu::CountItems方法代码示例

本文整理汇总了C++中BMenu::CountItems方法的典型用法代码示例。如果您正苦于以下问题:C++ BMenu::CountItems方法的具体用法?C++ BMenu::CountItems怎么用?C++ BMenu::CountItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BMenu的用法示例。


在下文中一共展示了BMenu::CountItems方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BMessage

void
FilterView::AdoptModel(const Model& model)
{
	BMenu* repositoryMenu = fRepositoryField->Menu();
		repositoryMenu->RemoveItems(0, repositoryMenu->CountItems(), true);

	repositoryMenu->AddItem(new BMenuItem(B_TRANSLATE("All depots"),
		new BMessage(MSG_DEPOT_SELECTED)));
	repositoryMenu->ItemAt(0)->SetMarked(true);

	repositoryMenu->AddItem(new BSeparatorItem());

	const DepotList& depots = model.Depots();
	for (int i = 0; i < depots.CountItems(); i++) {
		const DepotInfo& depot = depots.ItemAtFast(i);
		BMessage* message = new BMessage(MSG_DEPOT_SELECTED);
		message->AddString("name", depot.Name());
		BMenuItem* item = new BMenuItem(depot.Name(), message);
		repositoryMenu->AddItem(item);
	}

	BMenu* showMenu = fShowField->Menu();
	showMenu->RemoveItems(0, showMenu->CountItems(), true);

	showMenu->AddItem(new BMenuItem(B_TRANSLATE("All categories"),
		new BMessage(MSG_CATEGORY_SELECTED)));

	showMenu->AddItem(new BSeparatorItem());

	add_categories_to_menu(model.Categories(), showMenu);

	showMenu->ItemAt(0)->SetMarked(true);

	AdoptCheckmarks(model);
}
开发者ID:,项目名称:,代码行数:35,代码来源:

示例2: UpdateDirectoryPopup

void CFtpDialog::UpdateDirectoryPopup()
{
	BMenu* menu = fDirectoryField->Menu();
	BMenuItem *item;

	while ((item = menu->ItemAt(menu->CountItems() - 1)) != NULL)
	{
		menu->RemoveItem(item);
		delete item;
	}

	char p[PATH_MAX], *l;
	strcpy(p, fPath);

	l = strtok(p, "/");

	menu->AddItem(new BMenuItem("/", new BMessage(msg_SelectedDirectory)));

	while (l)
	{
		menu->AddItem(new BMenuItem(l, new BMessage(msg_SelectedDirectory)));
		l = strtok(NULL, "/");
	}

	menu->ItemAt(menu->CountItems() - 1)->SetMarked(true);
} // CFtpDialog::UpdateDirectoryPopup
开发者ID:pgellert,项目名称:Pe,代码行数:26,代码来源:CFtpDialog.cpp

示例3: BMessage

void
FilterView::AdoptModel(const Model& model)
{
	// Adopt depots
	BMenu* repositoryMenu = fRepositoryField->Menu();
		repositoryMenu->RemoveItems(0, repositoryMenu->CountItems(), true);

	repositoryMenu->AddItem(new BMenuItem(B_TRANSLATE("All depots"),
		new BMessage(MSG_DEPOT_SELECTED)));

	repositoryMenu->AddItem(new BSeparatorItem());

	bool foundSelectedDepot = false;
	const DepotList& depots = model.Depots();
	for (int i = 0; i < depots.CountItems(); i++) {
		const DepotInfo& depot = depots.ItemAtFast(i);
		BMessage* message = new BMessage(MSG_DEPOT_SELECTED);
		message->AddString("name", depot.Name());
		BMenuItem* item = new BMenuItem(depot.Name(), message);
		repositoryMenu->AddItem(item);

		if (depot.Name() == model.Depot()) {
			item->SetMarked(true);
			foundSelectedDepot = true;
		}
	}

	if (!foundSelectedDepot)
		repositoryMenu->ItemAt(0)->SetMarked(true);

	// Adopt categories
	BMenu* showMenu = fShowField->Menu();
	showMenu->RemoveItems(0, showMenu->CountItems(), true);

	showMenu->AddItem(new BMenuItem(B_TRANSLATE("All categories"),
		new BMessage(MSG_CATEGORY_SELECTED)));

	showMenu->AddItem(new BSeparatorItem());

	add_categories_to_menu(model.Categories(), showMenu);

	bool foundSelectedCategory = false;
	for (int32 i = 0; i < showMenu->CountItems(); i++) {
		BMenuItem* item = showMenu->ItemAt(i);
		BMessage* message = item->Message();
		if (message == NULL)
			continue;
		BString category;
		if (message->FindString("name", &category) == B_OK
			&& model.Category() == category) {
			item->SetMarked(true);
			foundSelectedCategory = true;
			break;
		}
	}
	if (!foundSelectedCategory)
		showMenu->ItemAt(0)->SetMarked(true);
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:58,代码来源:FilterView.cpp

示例4: BMessage

void
PPPoEView::MessageReceived(BMessage *message)
{
	switch(message->what) {
		case kMsgSelectInterface: {
			BMenuItem *item = fInterface->Menu()->FindMarked();
			if(item)
				fInterfaceName = item->Label();
		} break;
		
		case kMsgSelectOther:
			(new TextRequestDialog("InterfaceName", NULL, kRequestInterfaceName,
				fInterfaceName.String()))->Go(new BInvoker(
				new BMessage(kMsgFinishSelectOther), this));
		break;
		
		case kMsgFinishSelectOther: {
			int32 which;
			message->FindInt32("which", &which);
			
			const char *name = message->FindString("text");
			BMenu *menu = fInterface->Menu();
			BMenuItem *item;
			if(which != 1 || !name || strlen(name) == 0) {
				item = menu->FindItem(fInterfaceName.String());
				if(item && menu->IndexOf(item) <= menu->CountItems() - 2)
					item->SetMarked(true);
				else
					fOtherInterface->SetMarked(true);
				
				return;
			}
			
			fInterfaceName = name;
			
			item = menu->FindItem(fInterfaceName.String());
			if(item && menu->IndexOf(item) <= menu->CountItems() - 2) {
				item->SetMarked(true);
				return;
			}
			
			BString label(kLabelOtherInterface);
			label << " " << name;
			fOtherInterface->SetLabel(label.String());
			fOtherInterface->SetMarked(true);
				// XXX: this is needed to tell the owning menu to update its label
		} break;
		
		default:
			BView::MessageReceived(message);
	}
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:52,代码来源:PPPoEAddon.cpp

示例5: if

void
PPPoEView::ReloadInterfaces()
{
	// delete all items and request a new bunch from the pppoe kernel module
	BMenu *menu = fInterface->Menu();
	while(menu->CountItems() > 2)
		delete menu->RemoveItem((int32) 0);
	fOtherInterface->SetLabel(kLabelOtherInterface);
	
	PPPManager manager;
	char *interfaces = new char[8192];
		// reserve enough space for approximately 512 entries
	int32 count = manager.ControlModule("pppoe", PPPoE_GET_INTERFACES, interfaces,
		8192);
	
	BMenuItem *item;
	char *name = interfaces;
	int32 insertAt;
	for(int32 index = 0; index < count; index++) {
		item = new BMenuItem(name, new BMessage(kMsgSelectInterface));
		insertAt = FindNextMenuInsertionIndex(menu, name);
		if(insertAt > menu->CountItems() - 2)
			insertAt = menu->CountItems() - 2;
		
		item->SetTarget(this);
		menu->AddItem(item, insertAt);
		name += strlen(name) + 1;
	}
	
	// set interface or some default value if nothing was found
	if(Addon()->InterfaceName() && strlen(Addon()->InterfaceName()) > 0)
		fInterfaceName = Addon()->InterfaceName();
	else if(count > 0)
		fInterfaceName = interfaces;
	else
		fInterfaceName = "";
	
	delete interfaces;
	
	item = menu->FindItem(fInterfaceName.String());
	if(item && menu->IndexOf(item) <= menu->CountItems() - 2)
		item->SetMarked(true);
	else if(Addon()->InterfaceName()) {
		BString label(kLabelOtherInterface);
		label << " " << fInterfaceName;
		fOtherInterface->SetLabel(label.String());
		fOtherInterface->SetMarked(true);
	}
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:49,代码来源:PPPoEAddon.cpp

示例6: BWindow

Tearoff::Tearoff(BRect frame, const char *name, MainWindow *parent, MenuName menu_name, int idx)
	: BWindow(frame, name, B_FLOATING_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE, 0)
{
	int y = 0;
	BFont font;
	BMenu *menu;
	
	this->parent = parent;
	menu = parent->GetMenu(menu_name);
	menu->GetFont(&font);
	for(int i = 1; i < menu->CountItems(); i++) {
		BMenuItem *item = menu->ItemAt(i);
		if(item->Message()) {
			BButton *b = new BButton(BRect(0, y, frame.IntegerWidth(), y + TEAROFF_BUTTON_HEIGHT), "", item->Label(), new BMessage(item->Message()->what), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); 
			font.SetSize(TEAROFF_FONT_SIZE);
			b->SetFont(&font);
			AddChild(b);
			y = y + TEAROFF_BUTTON_HEIGHT;
		}
	}
	this->ResizeTo(frame.IntegerWidth(), y);
	this->SetTitle(menu->Name());
	this->index = idx;
	delete menu;
}
开发者ID:brennanos,项目名称:XFile-Haiku,代码行数:25,代码来源:Tearoff.cpp

示例7: english

BMenuItem*
BootPromptWindow::_KeymapItemForLanguage(BLanguage& language) const
{
	BLanguage english("en");
	BString name;
	if (language.GetName(name, &english) != B_OK)
		return fDefaultKeymapItem;

	// Check special mappings first
	for (size_t i = 0; i < kLanguageKeymapMappingsSize; i += 2) {
		if (!strcmp(name, kLanguageKeymapMappings[i])) {
			name = kLanguageKeymapMappings[i + 1];
			break;
		}
	}

	BMenu* menu = fKeymapsMenuField->Menu();
	for (int32 i = 0; i < menu->CountItems(); i++) {
		BMenuItem* item = menu->ItemAt(i);
		BMessage* message = item->Message();

		entry_ref ref;
		if (message->FindRef("ref", &ref) == B_OK
			&& name == ref.name)
			return item;
	}

	return fDefaultKeymapItem;
}
开发者ID:,项目名称:,代码行数:29,代码来源:

示例8:

/*! \brief Set the control's value.
	\param value The new value of the control.
	Selects the option which has the given value.
*/
void
BOptionPopUp::SetValue(int32 value)
{
	BControl::SetValue(value);
	BMenu *menu = fMenuField->Menu();
	if (menu == NULL)
		return;

	int32 numItems = menu->CountItems();
	for (int32 i = 0; i < numItems; i++) {
		BMenuItem *item = menu->ItemAt(i);
		if (item && item->Message()) {
			int32 itemValue;
			item->Message()->FindInt32("be:value", &itemValue);
			if (itemValue == value) {
				item->SetMarked(true);

#if BEHAVE_LIKE_R5
				item->SetMarked(false);
#endif

				break;
			}
		}
	}
}
开发者ID:mmanley,项目名称:Antares,代码行数:30,代码来源:OptionPopUp.cpp

示例9: MakeValueMessage

/*! \brief Adds an option to the control, at the given position.
	\param name The name of the option to add.
	\param value The value of the option.
	\param index The index which the new option will have in the control.
	\return \c B_OK if the option was added succesfully,
		\c B_BAD_VALUE if the given index was invalid.
		\c B_ERROR if something else happened.
*/
status_t
BOptionPopUp::AddOptionAt(const char *name, int32 value, int32 index)
{
	BMenu *menu = fMenuField->Menu();
	if (menu == NULL)
		return B_ERROR;
	
	int32 numItems = menu->CountItems();
	if (index < 0 || index > numItems)
		return B_BAD_VALUE;
	
	BMessage *message = MakeValueMessage(value);
	if (message == NULL)
		return B_NO_MEMORY;
	
	BMenuItem *newItem = new BMenuItem(name, message);
	if (newItem == NULL) {
		delete message;
		return B_NO_MEMORY;
	}
	
	menu->AddItem(newItem, index);
	newItem->SetTarget(this);
	
	// We didnt' have any items before, so select the newly added one
	if (numItems == 0)
		SetValue(value);
	
	return B_OK;
}
开发者ID:mmanley,项目名称:Antares,代码行数:38,代码来源:OptionPopUp.cpp

示例10:

void
AttributeWindow::_CheckDisplayAs()
{
	// check display as suported types

	type_code currentType = _CurrentType();

	BMenu* menu = fDisplayAsMenuField->Menu();
	for (int32 i = menu->CountItems(); i-- > 0;) {
		BMenuItem* item = menu->ItemAt(i);
		bool supported = item == _DefaultDisplayAs();
			// the default type is always supported
		type_code type;
		for (int32 j = 0; item->Message()->FindInt32("supports",
				j, (int32*)&type) == B_OK; j++) {
			if (type == currentType) {
				supported = true;
				break;
			}
		}

		item->SetEnabled(supported);
		if (item->IsMarked() && !supported)
			menu->ItemAt(0)->SetMarked(true);
	}

	fSpecialControl->SetEnabled(!_DefaultDisplayAs()->IsMarked());
}
开发者ID:mmanley,项目名称:Antares,代码行数:28,代码来源:AttributeWindow.cpp

示例11: SetEvent

void AmProgramChangeView::SetEvent(AmPhraseEvent* container, AmProgramChange* pc)
{
	ArpASSERT(container && pc);
	mContainer = container;
	bool		updateAll = false;
	if (mProgramChange != pc) updateAll = true;
	mProgramChange = pc;
	if (updateAll || mCachedBankNumber != int32(BankNumber()) )
		SetTrackRef(mTrackRef);
	if (updateAll || mCachedProgramNumber != int32(mProgramChange->ProgramNumber()) ) {
		BMenu*		m = Menu();
		if (m) {
			int32		count = m->CountItems();
			for( int32 k = 0; k < count; k++ ) {
				BMenuItem*	item = m->ItemAt( k );
				if (item) {
					if( pc && k == pc->ProgramNumber() ) item->SetMarked( true );
					else item->SetMarked(false);
				}
			}
		}
	}
	mCachedProgramNumber = mProgramChange->ProgramNumber();
	mCachedBankNumber = BankNumber();
}
开发者ID:HaikuArchives,项目名称:Sequitur,代码行数:25,代码来源:AmEventControls.cpp

示例12: BuildProtocolMenu

void ChatWindow::BuildProtocolMenu(void) {
	BMessage getStatus(IM::GET_CONTACT_STATUS);
	getStatus.AddRef("contact", &fEntry);
	BMessage statusMsg;

	BMenu *menu = fProtocolMenu->Menu();
	if (menu == NULL) {
		LOG("im_emoclient", liHigh, "BuildProtocolMenu(): fProtocolMenu is NULL.");
		return;
	}

//	You have to do this twice... buggered if I know why...
	for (int32 i = 0; i < menu->CountItems(); i++) delete menu->RemoveItem(0L);
	for (int32 i = 0; i < menu->CountItems(); i++) delete menu->RemoveItem(0L);

	menu->AddItem(new IconMenuItem(NULL, _T("Any Protocol"), NULL,
		new BMessage(PROTOCOL_SELECTED)));
	
	if (fMan->SendMessage(&getStatus, &statusMsg) != B_OK) {
		LOG("im_emoclient", liHigh, "Failed to get contact statues");
		return;
	};
	
	BPath iconDir;
	find_directory(B_USER_ADDONS_DIRECTORY, &iconDir, true);
	iconDir.Append("im_kit/protocols");
			
	menu->AddSeparatorItem();
	
	for (int32 i = 0; statusMsg.FindString("connection", i); i++) {
		BString status = statusMsg.FindString("status", i);
		IM::Connection connection( statusMsg.FindString("connection", i) );

		BString iconPath = iconDir.Path();
		iconPath << "/" << connection.Protocol();
			
		BBitmap *icon = ReadNodeIcon(iconPath.String(), kSmallIcon, true);
		BString label = connection.String();
		label << " (" << _T(status.String()) << ")";
			
		menu->AddItem(
			new IconMenuItem(
				icon, 
				label.String(), 
				connection.String(), 
				new BMessage(PROTOCOL_SELECTED)
			)
		);
	};
	
	// TODO: Is this call needed or not?
	//menu->SetFont(be_plain_font);
	
	fStatusBar->PositionViews();

	fInfoView->ResizeTo(fStatusBar->Bounds().Width() - fInfoView->Frame().left,
		fInfoView->Bounds().Height());
};
开发者ID:HaikuArchives,项目名称:IMKit,代码行数:58,代码来源:ChatWindow.cpp

示例13: lock

void
InspectorWindow::TextModeChanged(int32 newMode)
{
	AutoLocker<BLooper> lock(this);
	if (lock.IsLocked()) {
		BMenu* menu = fTextMode->Menu();
		if (newMode < 0 || newMode > menu->CountItems())
			return;
		BMenuItem* item = menu->ItemAt(newMode);
		item->SetMarked(true);
	}
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:12,代码来源:InspectorWindow.cpp

示例14: handleMouseEvent

void BWebPage::handleMouseEvent(const BMessage* message)
{
    WebCore::Frame* frame = fMainFrame->Frame();
    if (!frame->view() || !frame->document())
        return;

    PlatformMouseEvent event(message);
    switch (message->what) {
    case B_MOUSE_DOWN:
        // Handle context menus, if necessary.
        if (event.button() == RightButton) {
            fPage->contextMenuController()->clearContextMenu();

            WebCore::Frame* focusedFrame = fPage->focusController()->focusedOrMainFrame();
            focusedFrame->eventHandler()->sendContextMenuEvent(event);
            // If the web page implements it's own context menu handling, then
            // the contextMenu() pointer will be zero. In this case, we should
            // also swallow the event.
            ContextMenu* contextMenu = fPage->contextMenuController()->contextMenu();
            if (contextMenu) {
            	BMenu* platformMenu = contextMenu->releasePlatformDescription();
            	if (platformMenu) {
            		// Need to convert the BMenu into BPopUpMenu.
	            	BPopUpMenu* popupMenu = new BPopUpMenu("context menu");
					for (int32 i = platformMenu->CountItems() - 1; i >= 0; i--) {
					    BMenuItem* item = platformMenu->RemoveItem(i);
					    popupMenu->AddItem(item, 0);
					}
					BPoint screenLocation(event.globalPosition().x() + 2,
					    event.globalPosition().y() + 2);
            	    popupMenu->Go(screenLocation, true, true, true);
            	    delete platformMenu;
            	}
            }
            break;
    	}
    	// Handle regular mouse events.
        frame->eventHandler()->handleMousePressEvent(event);
        break;
    case B_MOUSE_UP:
        frame->eventHandler()->handleMouseReleaseEvent(event);
        break;
    case B_MOUSE_MOVED:
    default:
        frame->eventHandler()->mouseMoved(event);
        break;
    }
}
开发者ID:,项目名称:,代码行数:48,代码来源:

示例15: ChildAt

void
AccountView::AttachedToWindow()
{
	// Once we are attached to window, the GUI is already created
	// so we can set our window as target for messages
	for (int32 i = 0; i < CountChildren(); i++) {
		BView* child = ChildAt(i);

		BMenu* menu = dynamic_cast<BMenu*>(child);
		BMenuField* menuField
			= dynamic_cast<BMenuField*>(child);
		BTextControl* textControl
			= dynamic_cast<BTextControl*>(child);
		NotifyingTextView* textView
			= dynamic_cast<NotifyingTextView*>(child);
		BCheckBox* checkBox = dynamic_cast<BCheckBox*>(child);

		if (menuField)
			menu = menuField->Menu();

		if (menu) {
			for (int32 j = 0; j < menu->CountItems(); j++) {
				BMenuItem* item = menu->ItemAt(j);
				item->SetMessage(new BMessage(kChanged));
				item->SetTarget(Window());
			}

			menu->SetTargetForItems(Window());
		}

		if (textControl) {
			textControl->SetMessage(new BMessage(kChanged));
			textControl->SetTarget(Window());
		}

		if (checkBox) {
			checkBox->SetMessage(new BMessage(kChanged));
			checkBox->SetTarget(Window());
		}

		if (textView) {
			textView->SetMessage(new BMessage(kChanged));
			textView->SetTarget(Window());
		}
	}
}
开发者ID:Barrett17,项目名称:Caya,代码行数:46,代码来源:AccountView.cpp


注:本文中的BMenu::CountItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。