123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #include "main.h"
- #include "./local_menu.h"
- unsigned int
- Menu_InsertDeviceItems(HMENU menu, int position, unsigned int baseId,
- ifc_device *device, DeviceCommandContext context)
- {
- unsigned int count, separator;
- MENUITEMINFO itemInfo = {0};
- wchar_t itemName[512] = {0};
- ifc_devicecommand *commandInfo;
- ifc_devicesupportedcommandenum *enumerator;
- ifc_devicesupportedcommand *command;
- DeviceCommandFlags commandFlags;
- if (NULL == device || NULL == menu)
- return 0;
- if (FAILED(device->EnumerateCommands(&enumerator, context)))
- return 0;
- itemInfo.cbSize = sizeof(itemInfo);
- itemInfo.fMask = MIIM_DATA | MIIM_ID | MIIM_FTYPE | MIIM_STATE | MIIM_STRING;
-
- count = 0;
- separator = 0;
- while(S_OK == enumerator->Next(&command, 1, NULL))
- {
- if(SUCCEEDED(command->GetFlags(&commandFlags)))
- {
- if (0 != (DeviceCommandFlag_Group & commandFlags) &&
- separator != count)
- {
- itemInfo.fType = MFT_SEPARATOR;
- itemInfo.fState = MFS_ENABLED;
- itemInfo.wID = 0xFFFE;
- itemInfo.dwItemData = NULL;
- if (0 != InsertMenuItem(menu, position + count, TRUE, &itemInfo))
- {
- count++;
- separator = count;
- }
- }
- if (0 == (DeviceCommandFlag_Hidden & commandFlags))
- {
- if (S_OK == WASABI_API_DEVICES->CommandFind(command->GetName(), &commandInfo))
- {
- if (SUCCEEDED(commandInfo->GetDisplayName(itemName, ARRAYSIZE(itemName))))
- {
- itemInfo.dwItemData = (ULONG_PTR)AnsiString_Duplicate(command->GetName());
- if (NULL != itemInfo.dwItemData)
- {
- itemInfo.fType = MFT_STRING;
- itemInfo.dwTypeData = itemName;
- itemInfo.fState = 0;
- itemInfo.wID = baseId + count;
- if (0 == (DeviceCommandFlag_Disabled & commandFlags))
- itemInfo.fState |= MFS_ENABLED;
- else
- itemInfo.fState |= (MFS_DISABLED | MFS_GRAYED);
-
- if (0 != (DeviceCommandFlag_Primary & commandFlags))
- itemInfo.fState |= MFS_DEFAULT;
- if (0 != InsertMenuItem(menu, position + count, TRUE, &itemInfo))
- count++;
- else
- AnsiString_Free((char*)itemInfo.dwItemData);
- }
- }
- commandInfo->Release();
- }
- }
- }
- command->Release();
- }
-
- enumerator->Release();
-
- return count;
- }
- unsigned int
- Menu_FreeItemData(HMENU menu, unsigned int start, int count)
- {
- unsigned int processed;
- MENUITEMINFO itemInfo;
- if (NULL == menu)
- return 0;
-
- if (count < 0 )
- count = GetMenuItemCount(menu);
- if (start > (unsigned int)count)
- return 0;
-
- count -= start;
- processed = 0;
- itemInfo.cbSize = sizeof(itemInfo);
- itemInfo.fMask = MIIM_DATA;
- while(count-- &&
- FALSE != GetMenuItemInfo(menu, start + processed, TRUE, &itemInfo))
- {
- AnsiString_Free((char*)itemInfo.dwItemData);
- processed++;
- }
-
- return processed;
- }
- ULONG_PTR
- Menu_GetItemData(HMENU menu, unsigned int item, BOOL byPosition)
- {
- MENUITEMINFO itemInfo;
- if (NULL == menu)
- return 0;
- itemInfo.cbSize = sizeof(itemInfo);
- itemInfo.fMask = MIIM_DATA;
- if (FALSE != GetMenuItemInfo(menu, item, byPosition, &itemInfo))
- return itemInfo.dwItemData;
-
- return 0;
- }
- unsigned int
- Menu_FindItemByData(HMENU menu, Menu_FindItemByDataCb callback, void *user)
- {
- int index, count;
- MENUITEMINFO itemInfo;
- if (NULL == menu || NULL == callback)
- return -1;
- count = GetMenuItemCount(menu);
- if (0 == count)
- return -1;
- itemInfo.cbSize = sizeof(itemInfo);
- itemInfo.fMask = MIIM_DATA | MIIM_ID;
- for (index = 0; index < count; index++)
- {
- if (FALSE != GetMenuItemInfo(menu, index, TRUE, &itemInfo) &&
- FALSE != callback(itemInfo.dwItemData, user))
- {
- return itemInfo.wID;
- }
- }
-
- return -1;
- }
- static BOOL
- Menu_FindItemByAnsiStringDataCb(ULONG_PTR param, void *user)
- {
- const char *string1, *string2;
-
- string1 = (const char*)param;
- string2 = (const char*)user;
-
- if (NULL == string1 || NULL == string2)
- return (string1 == string2);
- return (CSTR_EQUAL == CompareStringA(CSTR_INVARIANT, 0, string1, -1, string2, -1));
- }
- unsigned int
- Menu_FindItemByAnsiStringData(HMENU menu, const char *string)
- {
- return Menu_FindItemByData(menu, Menu_FindItemByAnsiStringDataCb, (void*)string);
- }
|