bool PopupMenu::setItem(S32 pos, const char *title, const char* accelerator)
{
   Win32Window *pWindow = mCanvas ? dynamic_cast<Win32Window*>(mCanvas->getPlatformWindow()) : NULL;
   bool isAttached = isAttachedToMenuBar();
   if(isAttached && pWindow == NULL)
      return false;

   // Are we out of range?
   if ( pos >= getItemCount() )
      return false;

   MENUITEMINFOA mi;
   mi.cbSize = sizeof(mi);
   mi.fMask = MIIM_TYPE;

   if(title && *title)
      mi.fType = MFT_STRING;
   else
      mi.fType = MFT_SEPARATOR;

   char buf[1024];
   if(accelerator && *accelerator)
   {
      dSprintf(buf, sizeof(buf), "%s\t%s", title, accelerator);

      if(isAttached)
         pWindow->removeAccelerators(mData->mAccelerators);

      // Build entry for accelerator table
      EventDescriptor accelDesc;
      if(ActionMap::createEventDescriptor(accelerator, &accelDesc))
         mData->insertAccelerator(accelDesc, pos);
      else
         Con::errorf("PopupMenu::setItem - Could not create event descriptor for accelerator \"%s\"", accelerator);

      if(isAttached)
         pWindow->addAccelerators(mData->mAccelerators);
   }
   else
      dSprintf(buf, sizeof(buf), "%s", title);

   mi.dwTypeData = (LPSTR)buf;

   if(SetMenuItemInfoA(mData->mMenu, pos, TRUE, &mi))
   {
      if(isAttached)
      {
         HWND hWindow = pWindow->getHWND();
         DrawMenuBar(hWindow);
      }

      return true;
   }

   return false;
}
void PopupMenu::checkItem(S32 pos, bool checked)
{
//    U32 flags = checked ? MF_CHECKED : MF_UNCHECKED;
//    CheckMenuItem(mData->mMenu, pos, MF_BYPOSITION|flags);

   MENUITEMINFOA mi;
   mi.cbSize = sizeof(mi);
   mi.fMask = MIIM_STATE;
   mi.fState = checked ? MFS_CHECKED : MFS_UNCHECKED;
   SetMenuItemInfoA(mData->mMenu, pos, TRUE, &mi);
}
void CWindowsFunctions::RecursiveTranslateMenu(HMENU menu)
{
	int items = GetMenuItemCount(menu);

	if (items > 0)
	{
		for (int i = 0; i < items; i++)
		{
			// Get menu type and text length
			MENUITEMINFOA info;
			info.cbSize = sizeof(MENUITEMINFOA);
			info.dwTypeData = NULL;
			info.fMask = MIIM_FTYPE | MIIM_STRING;
			GetMenuItemInfoA(menu, i, true, &info);

			// Ignore seperators and other junk we don't need to translate
			if (info.fType & ~MFT_STRING || info.cch == 1) continue;

			// Get submenu and text
			info.cch += 1;
			info.dwTypeData = new char[info.cch];
			info.fMask = MIIM_SUBMENU | MIIM_STRING;
			GetMenuItemInfoA(menu, i, true, &info);

			// Recursion
			if (info.hSubMenu != NULL)
			{
				RecursiveTranslateMenu(info.hSubMenu);
			}

			// Translation
			bool result = m_resources->TranslateUserInterface(info.dwTypeData, m_uiBuffer, UI_BUFFER);
			delete[] info.dwTypeData;

			if (result)
			{
				// info.cch = strnlen(m_uiBuffer, UI_BUFFER - 1) + 1;
				info.dwTypeData = m_uiBuffer;
				info.fMask = MIIM_STRING;
				SetMenuItemInfoA(menu, i, true, &info);
			}
		}
	}
}
Beispiel #4
0
BOOL SetMenuItemInfoUTF8( HMENU hMenu,UINT uItem, BOOL fByPosition, LPMENUITEMINFO lpmii)
{
  if (lpmii && (lpmii->fMask & MIIM_TYPE) && (lpmii->fType&(MFT_SEPARATOR|MFT_STRING|MFT_BITMAP)) == MFT_STRING && lpmii->dwTypeData && WDL_HasUTF8(lpmii->dwTypeData) && GetVersion()<0x80000000)
  {
    BOOL rv;
    MENUITEMINFOW tmp = *(MENUITEMINFOW*)lpmii;
    MBTOWIDE(wbuf,lpmii->dwTypeData);
    if (wbuf_ok)
    {
      tmp.cbSize=sizeof(tmp);
      tmp.dwTypeData = wbuf;
      rv=SetMenuItemInfoW(hMenu,uItem,fByPosition,&tmp);

      MBTOWIDE_FREE(wbuf);
      return rv;
    }
    MBTOWIDE_FREE(wbuf);
  }
  return SetMenuItemInfoA(hMenu,uItem,fByPosition,lpmii);
}
Beispiel #5
0
void VDSetMenuItemTextByCommandW32(HMENU hmenu, UINT cmd, const wchar_t *text) {
	if (VDIsWindowsNT()) {
		MENUITEMINFOW mmiW;

		mmiW.cbSize		= MENUITEMINFO_SIZE_VERSION_400W;
		mmiW.fMask		= MIIM_TYPE;
		mmiW.fType		= MFT_STRING;
		mmiW.dwTypeData	= (LPWSTR)text;

		SetMenuItemInfoW(hmenu, cmd, FALSE, &mmiW);
	} else {
		MENUITEMINFOA mmiA;
		VDStringA textA(VDTextWToA(text));

		mmiA.cbSize		= MENUITEMINFO_SIZE_VERSION_400A;
		mmiA.fMask		= MIIM_TYPE;
		mmiA.fType		= MFT_STRING;
		mmiA.dwTypeData	= (LPSTR)textA.c_str();

		SetMenuItemInfoA(hmenu, cmd, FALSE, &mmiA);
	}
}
Beispiel #6
0
/* MAKE_EXPORT SetMenuItemInfoW_new=SetMenuItemInfoW */
BOOL WINAPI SetMenuItemInfoW_new(HMENU hMenu, UINT uItem, BOOL fByPosition, LPCMENUITEMINFO lpmii)
{
	MENUITEMINFOA mii;
	BOOL result;
	LPSTR lpTypeData;

	if(IsBadReadPtr(lpmii, sizeof(MENUITEMINFOW)))
		return FALSE;

	memcpy(&mii, lpmii, sizeof(MENUITEMINFOA));

	lpTypeData = NULL;

	STACK_WtoA(lpmii->dwTypeData, lpTypeData);

	mii.dwTypeData = lpTypeData;

	result = SetMenuItemInfoA(hMenu, uItem, fByPosition, lpmii);

	if(!result)
		return FALSE;

	return TRUE;
}