[BROWSEUI]

* Find the menu index so that the forwarded WM_INITMENUPOPUP has all the info shell32 needs.

[SHELL32]
* Begin implementing dynamic menu editing, which is used by the shell views in order to change, add or remove items from the filebrowser menus. Some menu items may be temporarily lost until this is finished.

svn path=/branches/shell-experiments/; revision=63809
This commit is contained in:
David Quintana 2014-08-04 21:19:22 +00:00
parent 7292674928
commit d13da089e5
2 changed files with 162 additions and 84 deletions

View file

@ -3161,12 +3161,38 @@ LRESULT CShellBrowser::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHa
LRESULT CShellBrowser::OnInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) LRESULT CShellBrowser::OnInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{ {
HMENU theMenu; HMENU theMenu;
LPARAM menuIndex = lParam;
theMenu = reinterpret_cast<HMENU>(wParam); theMenu = reinterpret_cast<HMENU>(wParam);
if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_VIEW))
if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_FILE))
{
menuIndex = 0;
}
else if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_EDIT))
{
menuIndex = 1;
}
else if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_VIEW))
{
UpdateViewMenu(theMenu); UpdateViewMenu(theMenu);
return RelayMsgToShellView(uMsg, wParam, lParam, bHandled); menuIndex = 2;
}
else if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_FAVORITES))
{
menuIndex = 3;
}
else if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_TOOLS))
{
menuIndex = 4;
}
else if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_HELP))
{
menuIndex = 5;
}
return RelayMsgToShellView(uMsg, wParam, menuIndex, bHandled);
} }
LRESULT CShellBrowser::RelayMsgToShellView(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) LRESULT CShellBrowser::RelayMsgToShellView(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)

View file

@ -243,6 +243,7 @@ class CDefView :
LRESULT OnChangeNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); LRESULT OnChangeNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
LRESULT OnCustomItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); LRESULT OnCustomItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
LRESULT OnSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); LRESULT OnSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
LRESULT OnInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
static ATL::CWndClassInfo& GetWndClassInfo() static ATL::CWndClassInfo& GetWndClassInfo()
{ {
@ -294,6 +295,7 @@ class CDefView :
MESSAGE_HANDLER(WM_SYSCOLORCHANGE, OnSysColorChange) MESSAGE_HANDLER(WM_SYSCOLORCHANGE, OnSysColorChange)
MESSAGE_HANDLER(CWM_GETISHELLBROWSER, OnGetShellBrowser) MESSAGE_HANDLER(CWM_GETISHELLBROWSER, OnGetShellBrowser)
MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChange) MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChange)
MESSAGE_HANDLER(WM_INITMENUPOPUP, OnInitMenuPopup)
END_MSG_MAP() END_MSG_MAP()
BEGIN_COM_MAP(CDefView) BEGIN_COM_MAP(CDefView)
@ -1050,17 +1052,36 @@ void CDefView::MergeFileMenu(HMENU hSubMenu)
{ {
TRACE("(%p)->(submenu=%p) stub\n", this, hSubMenu); TRACE("(%p)->(submenu=%p) stub\n", this, hSubMenu);
if (hSubMenu) if (!hSubMenu)
{ /*insert This item at the beginning of the menu */ return;
_InsertMenuItemW(hSubMenu, 0, TRUE, 0, MFT_SEPARATOR, NULL, MFS_ENABLED);
_InsertMenuItemW(hSubMenu, 0, TRUE, IDM_MYFILEITEM+4, MFT_STRING, L"Properties", MFS_DISABLED); /* Cleanup the items added previously */
_InsertMenuItemW(hSubMenu, 0, TRUE, IDM_MYFILEITEM+3, MFT_STRING, L"Rename", MFS_DISABLED); for (int i = 0; i < GetMenuItemCount(hSubMenu); )
_InsertMenuItemW(hSubMenu, 0, TRUE, IDM_MYFILEITEM+2, MFT_STRING, L"Delete", MFS_DISABLED); {
_InsertMenuItemW(hSubMenu, 0, TRUE, IDM_MYFILEITEM+1, MFT_STRING, L"Create Shortcut", MFS_DISABLED); MENUITEMINFOW mii;
_InsertMenuItemW(hSubMenu, 0, TRUE, 0, MFT_SEPARATOR, NULL, MFS_ENABLED); mii.cbSize = sizeof(mii);
_InsertMenuItemW(hSubMenu, 0, TRUE, IDM_MYFILEITEM, MFT_STRING, L"New", MFS_ENABLED); mii.fMask = MIIM_ID;
GetMenuItemInfoW(hSubMenu, i, TRUE, &mii);
if (mii.wID < 0x8000)
{
DeleteMenu(hSubMenu, i, MF_BYPOSITION);
}
else
{
i++;
}
} }
/* Insert This item at the beginning of the menu. */
_InsertMenuItemW(hSubMenu, 0, TRUE, 0, MFT_SEPARATOR, NULL, MFS_ENABLED);
_InsertMenuItemW(hSubMenu, 0, TRUE, IDM_MYFILEITEM+4, MFT_STRING, L"Properties", MFS_DISABLED);
_InsertMenuItemW(hSubMenu, 0, TRUE, IDM_MYFILEITEM+3, MFT_STRING, L"Rename", MFS_DISABLED);
_InsertMenuItemW(hSubMenu, 0, TRUE, IDM_MYFILEITEM+2, MFT_STRING, L"Delete", MFS_DISABLED);
_InsertMenuItemW(hSubMenu, 0, TRUE, IDM_MYFILEITEM+1, MFT_STRING, L"Create Shortcut", MFS_DISABLED);
_InsertMenuItemW(hSubMenu, 0, TRUE, 0, MFT_SEPARATOR, NULL, MFS_ENABLED);
_InsertMenuItemW(hSubMenu, 0, TRUE, IDM_MYFILEITEM, MFT_STRING, L"New", MFS_ENABLED);
TRACE("--\n"); TRACE("--\n");
} }
@ -1071,21 +1092,57 @@ void CDefView::MergeViewMenu(HMENU hSubMenu)
{ {
TRACE("(%p)->(submenu=%p)\n", this, hSubMenu); TRACE("(%p)->(submenu=%p)\n", this, hSubMenu);
if (hSubMenu) if (!hSubMenu)
return;
__debugbreak();
DWORD item;
item |= SHCheckMenuItem(hSubMenu, FCIDM_SHVIEW_BIGICON, FALSE);
item |= SHCheckMenuItem(hSubMenu, FCIDM_SHVIEW_SMALLICON, FALSE);
item |= SHCheckMenuItem(hSubMenu, FCIDM_SHVIEW_LISTVIEW, FALSE);
item |= SHCheckMenuItem(hSubMenu, FCIDM_SHVIEW_REPORTVIEW, FALSE);
if (item == -1)
{ {
/*add a separator at the correct position in the menu*/ HMENU menubase = ::LoadMenuW(shell32_hInstance, L"MENU_001");
MENUITEMINFOW mii;
static WCHAR view[] = L"View";
_InsertMenuItemW(hSubMenu, FCIDM_MENU_VIEW_SEP_OPTIONS, FALSE, 0, MFT_SEPARATOR, NULL, MFS_ENABLED); _InsertMenuItemW(hSubMenu, FCIDM_MENU_VIEW_SEP_OPTIONS, FALSE, 0, MFT_SEPARATOR, NULL, MFS_ENABLED);
ZeroMemory(&mii, sizeof(mii)); INT count = ::GetMenuItemCount(menubase);
mii.cbSize = sizeof(mii); for (int i = 0; i < count; i++)
mii.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_DATA; {
mii.fType = MFT_STRING; MENUITEMINFOW mii = { 0 };
mii.dwTypeData = view; WCHAR label[128];
mii.hSubMenu = LoadMenuW(shell32_hInstance, L"MENU_001");
InsertMenuItemW(hSubMenu, FCIDM_MENU_VIEW_SEP_OPTIONS, FALSE, &mii); mii.cbSize = sizeof(mii);
mii.fMask = MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_DATA | MIIM_STRING | MIIM_BITMAP | MIIM_FTYPE;
mii.dwTypeData = label;
mii.cch = _countof(label);
::GetMenuItemInfoW(menubase, i, TRUE, &mii);
DbgPrint("Adding item %d label %S type %d\n", mii.wID, mii.dwTypeData, mii.fType);
mii.fType |= MFT_RADIOCHECK;
::InsertMenuItemW(hSubMenu, FCIDM_MENU_VIEW_SEP_OPTIONS, FALSE, &mii);
}
::DestroyMenu(menubase);
}
DbgPrint("View mode is %d\n", m_FolderSettings.ViewMode);
if (m_FolderSettings.ViewMode >= FVM_FIRST && m_FolderSettings.ViewMode <= FVM_LAST)
{
UINT iItem = FCIDM_SHVIEW_BIGICON + m_FolderSettings.ViewMode - FVM_FIRST;
DbgPrint("Checking item %d ...\n", iItem);
item = SHCheckMenuItem(hSubMenu, iItem, TRUE);
DbgPrint("SHCheckMenuItem returned %d\n", item);
if (item == -1)
{
DbgPrint("GetLastError returned %d\n", GetLastError());
}
} }
} }
@ -1357,9 +1414,6 @@ void CDefView::OnDeactivate()
void CDefView::DoActivate(UINT uState) void CDefView::DoActivate(UINT uState)
{ {
MENUITEMINFOA mii;
CHAR szText[MAX_PATH];
TRACE("%p uState=%x\n", this, uState); TRACE("%p uState=%x\n", this, uState);
/*don't do anything if the state isn't really changing */ /*don't do anything if the state isn't really changing */
@ -1368,71 +1422,24 @@ void CDefView::DoActivate(UINT uState)
return; return;
} }
OnDeactivate(); if (uState == SVUIA_DEACTIVATE)
{
/*only do This if we are active */ OnDeactivate();
if(uState != SVUIA_DEACTIVATE) }
else
{ {
// FIXME: windows does not do this.
// temporary solution (HACK): wipe the contents and refill
{
OLEMENUGROUPWIDTHS omw = { { 0 } };
INT mic = GetMenuItemCount(m_hMenu);
for (int i = 0; i < mic; i++)
{
DeleteMenu(m_hMenu, 0, MF_BYPOSITION);
}
m_pShellBrowser->InsertMenusSB(m_hMenu, &omw);
}
/*merge the menus */
if(m_hMenu) if(m_hMenu)
{ {
/*build the top level menu get the menu item's text*/
strcpy(szText, "dummy 31");
ZeroMemory(&mii, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_STATE;
mii.fType = MFT_STRING;
mii.fState = MFS_ENABLED;
mii.dwTypeData = szText;
mii.hSubMenu = BuildFileMenu();
/*get the view menu so we can merge with it*/
ZeroMemory(&mii, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_SUBMENU;
if (GetMenuItemInfoA(m_hMenu, FCIDM_MENU_VIEW, FALSE, &mii))
{
MergeViewMenu(mii.hSubMenu);
}
/*add the items that should only be added if we have the focus*/
if (SVUIA_ACTIVATE_FOCUS == uState)
{
/*get the file menu so we can merge with it */
ZeroMemory(&mii, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_SUBMENU;
if (GetMenuItemInfoA(m_hMenu, FCIDM_MENU_FILE, FALSE, &mii))
{
MergeFileMenu(mii.hSubMenu);
}
::SetFocus(m_hWndList);
}
TRACE("-- before fnSetMenuSB\n"); TRACE("-- before fnSetMenuSB\n");
m_pShellBrowser->SetMenuSB(m_hMenu, 0, m_hWnd); m_pShellBrowser->SetMenuSB(m_hMenu, 0, m_hWnd);
} }
if (SVUIA_ACTIVATE_FOCUS == uState)
{
::SetFocus(m_hWndList);
}
} }
m_uState = uState; m_uState = uState;
TRACE("--\n"); TRACE("--\n");
} }
@ -1869,6 +1876,51 @@ LRESULT CDefView::OnSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
return S_OK; return S_OK;
} }
/**********************************************************
* CDefView::OnInitMenuPopup
*/
LRESULT CDefView::OnInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{
MENUITEMINFOW mii = { 0 };
HMENU hSubmenu = (HMENU) wParam;
DbgPrint("OnInitMenuPopup lParam=%d\n", lParam);
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_ID | MIIM_SUBMENU;
if (!GetMenuItemInfoW(this->m_hMenu, lParam, TRUE, &mii))
{
DbgPrint("OnInitMenuPopup GetMenuItemInfoW failed!\n");
return FALSE;
}
UINT menuItemId = mii.wID;
if (mii.hSubMenu != hSubmenu)
{
DbgPrint("OnInitMenuPopup submenu does not match!!!!\n");
return FALSE;
}
DbgPrint("OnInitMenuPopup id=%d\n", menuItemId);
switch (menuItemId)
{
case FCIDM_MENU_FILE:
MergeFileMenu(hSubmenu);
break;
case FCIDM_MENU_EDIT:
//MergeEditMenu(hSubmenu);
break;
case FCIDM_MENU_VIEW:
MergeViewMenu(hSubmenu);
break;
}
return FALSE;
}
/********************************************************** /**********************************************************
* *
* *