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


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

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


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

示例1: Window

BMenuItem*
BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu)
{
	// TODO: Cleanup, merge some "if" blocks if possible
	fChosenItem = NULL;

	BWindow* window = Window();
	fState = MENU_STATE_TRACKING;

	BPoint where;
	uint32 buttons;
	if (window->Lock()) {
		if (startIndex != -1) {
			be_app->ObscureCursor();
			_SelectItem(ItemAt(startIndex), true, false);
		}
		GetMouse(&where, &buttons);
		window->Unlock();
	}

	while (fState != MENU_STATE_CLOSED) {
		bigtime_t snoozeAmount = 40000;
		if (Window() == NULL || !window->Lock())
			break;

		BMenuItem* menuItem = NULL;
		if (dynamic_cast<_BMCMenuBar_*>(this))
			menuItem = ItemAt(0);
		else
			menuItem = _HitTestItems(where, B_ORIGIN);
		if (_OverSubmenu(fSelected, ConvertToScreen(where))
			|| fState == MENU_STATE_KEY_TO_SUBMENU) {
			// call _Track() from the selected sub-menu when the mouse cursor
			// is over its window
			BMenu* menu = fSelected->Submenu();
			window->Unlock();
			snoozeAmount = 30000;
			bool wasSticky = _IsStickyMode();
			menu->_SetStickyMode(wasSticky);
			int localAction;
			fChosenItem = menu->_Track(&localAction);

			// The mouse could have meen moved since the last time we
			// checked its position, or buttons might have been pressed.
			// Unfortunately our child menus don't tell
			// us the new position.
			// TODO: Maybe have a shared struct between all menus
			// where to store the current mouse position ?
			// (Or just use the BView mouse hooks)
			BPoint newWhere;
			if (window->Lock()) {
				GetMouse(&newWhere, &buttons);
				window->Unlock();
			}

			// This code is needed to make menus
			// that are children of BMenuFields "sticky" (see ticket #953)
			if (localAction == MENU_STATE_CLOSED) {
				if (fExtraRect != NULL && fExtraRect->Contains(where)
					// 9 = 3 pixels ^ 2 (since point_distance() returns the
					// square of the distance)
					&& point_distance(newWhere, where) < 9) {
					_SetStickyMode(true);
					fExtraRect = NULL;
				} else
					fState = MENU_STATE_CLOSED;
			}
			if (!window->Lock())
				break;
		} else if (menuItem != NULL) {
			if (menuItem->Submenu() != NULL && menuItem != fSelected) {
				if (menuItem->Submenu()->Window() == NULL) {
					// open the menu if it's not opened yet
					_SelectItem(menuItem);
				} else {
					// Menu was already opened, close it and bail
					_SelectItem(NULL);
					fState = MENU_STATE_CLOSED;
					fChosenItem = NULL;
				}
			} else {
				// No submenu, just select the item
				_SelectItem(menuItem);
			}
		} else if (menuItem == NULL && fSelected != NULL
			&& !_IsStickyMode() && Bounds().Contains(where)) {
			_SelectItem(NULL);
			fState = MENU_STATE_TRACKING;
		}

		window->Unlock();

		if (fState != MENU_STATE_CLOSED) {
			// If user doesn't move the mouse, loop here,
			// so we don't interfere with keyboard menu navigation
			BPoint newLocation = where;
			uint32 newButtons = buttons;
			do {
				snooze(snoozeAmount);
				if (!LockLooper())
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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