* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
- * FIXME: The order by part of the background context menu should be
- * built according to the columns shown.
- *
* FIXME: CheckToolbar: handle the "new folder" and "folder up" button
*/
/*
TODO:
- Load/Save the view state from/into the stream provided by the ShellBrowser.
-- Code to merge menus in the shellbrowser is incorrect.
-- Move the background context menu creation into shell view. It should store the
- shell view HWND to send commands.
-- Shell view should do SetCommandTarget on internet toolbar.
- When editing starts on item, set edit text to for editing value.
-- When shell view is called back for item info, let listview save the value.
- Fix shell view to handle view mode popup exec.
- The background context menu should have a pidl just like foreground menus. This
causes crashes when dynamic handlers try to use the NULL pidl.
-- The SHELLDLL_DefView should not be filled with blue unconditionally. This causes
- annoying flashing of blue even on XP, and is not correct.
- Reorder of columns doesn't work - might be bug in comctl32
*/
CListView m_ListView;
HWND m_hWndParent;
FOLDERSETTINGS m_FolderSettings;
- HMENU m_hMenu;
- BOOL m_menusLoaded;
+ HMENU m_hMenu; /* Handle to the menu bar of the browser */
+ HMENU m_hMenuArrangeModes; /* Handle to the popup menu with the arrange modes */
+ HMENU m_hMenuViewModes; /* Handle to the popup menu with the view modes */
+ HMENU m_hContextMenu; /* Handle to the open context menu */
+ BOOL m_bmenuBarInitialized;
UINT m_uState;
UINT m_cidl;
PCUITEMID_CHILD *m_apidl;
LONG m_iDragOverItem; /* Dragged over item's index, iff m_pCurDropTarget != NULL */
UINT m_cScrollDelay; /* Send a WM_*SCROLL msg every 250 ms during drag-scroll */
POINT m_ptLastMousePos; /* Mouse position at last DragOver call */
+ POINT m_ptFirstMousePos; /* Mouse position when the drag operation started */
//
CComPtr<IContextMenu> m_pCM;
BOOL m_isEditing;
CLSID m_Category;
- HMENU m_hView;
BOOL m_Destroyed;
private:
BOOLEAN LV_ProdItem(PCUITEMID_CHILD pidl);
static INT CALLBACK fill_list(LPVOID ptr, LPVOID arg);
HRESULT FillList();
- HMENU BuildFileMenu();
- void PrepareShowFileMenu(HMENU hSubMenu);
- void PrepareShowViewMenu(HMENU hSubMenu);
+ HRESULT FillFileMenu();
+ HRESULT FillEditMenu();
+ HRESULT FillViewMenu();
+ HRESULT FillArrangeAsMenu(HMENU hmenuArrange);
+ HRESULT CheckViewMode(HMENU hmenuView);
UINT GetSelections();
HRESULT OpenSelectedItems();
void OnDeactivate();
virtual HRESULT STDMETHODCALLTYPE HandleRename(LPCITEMIDLIST new_pidl);
virtual HRESULT STDMETHODCALLTYPE SelectAndPositionItem(LPCITEMIDLIST item, UINT flags, POINT *point);
+ // *** IShellView3 methods ***
+ virtual HRESULT STDMETHODCALLTYPE CreateViewWindow3(IShellBrowser *psb, IShellView *psvPrevious, SV3CVW3_FLAGS view_flags, FOLDERFLAGS mask, FOLDERFLAGS flags, FOLDERVIEWMODE mode, const SHELLVIEWID *view_id, RECT *prcView, HWND *hwnd);
+
// *** IFolderView methods ***
virtual HRESULT STDMETHODCALLTYPE GetCurrentViewMode(UINT *pViewMode);
virtual HRESULT STDMETHODCALLTYPE SetCurrentViewMode(UINT ViewMode);
// Windows returns E_NOINTERFACE for IOleWindow
// COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IOleWindow)
COM_INTERFACE_ENTRY_IID(IID_IShellView, IShellView)
+ COM_INTERFACE_ENTRY_IID(IID_CDefView, IShellView)
COM_INTERFACE_ENTRY_IID(IID_IShellView2, IShellView2)
COM_INTERFACE_ENTRY_IID(IID_IFolderView, IFolderView)
COM_INTERFACE_ENTRY_IID(IID_IShellFolderView, IShellFolderView)
m_ListView(),
m_hWndParent(NULL),
m_hMenu(NULL),
- m_menusLoaded(FALSE),
+ m_hMenuArrangeModes(NULL),
+ m_hMenuViewModes(NULL),
+ m_hContextMenu(NULL),
+ m_bmenuBarInitialized(FALSE),
m_uState(0),
m_cidl(0),
m_apidl(NULL),
m_iDragOverItem(0),
m_cScrollDelay(0),
m_isEditing(FALSE),
- m_hView(NULL),
m_Destroyed(FALSE)
{
ZeroMemory(&m_FolderSettings, sizeof(m_FolderSettings));
*/
m_ListView.SetBkColor(CLR_NONE);
- RegGetValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
- L"ListviewShadow", RRF_RT_DWORD, NULL, &bDropShadow, &cbDropShadow);
+ SHGetValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
+ L"ListviewShadow", NULL, &bDropShadow, &cbDropShadow);
if (bDropShadow)
{
/* Set the icon background transparent */
m_ListView.DeleteAllItems();
+ m_hMenuArrangeModes = CreateMenu();
+
if (m_pSF2Parent)
{
for (int i = 0; 1; i++)
StrRetToStrNW( szTemp, 50, &sd.str, NULL);
m_ListView.InsertColumn(i, szTemp, sd.fmt, sd.cxChar * 8);
+ InsertMenuW(m_hMenuArrangeModes, -1, MF_STRING, 0x30 + i, szTemp);
}
+
+ InsertMenuW(m_hMenuArrangeModes, -1, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
}
else
{
* #### Handling of the menus ####
*/
-HMENU CDefView::BuildFileMenu()
-{
- HRESULT hr;
- CComPtr<IContextMenu> cm;
-
- GetSelections();
+extern "C" DWORD WINAPI SHMenuIndexFromID(HMENU hMenu, UINT uID);
- hr = m_pSFParent->GetUIObjectOf(m_hWnd, m_cidl, m_apidl, IID_NULL_PPV_ARG(IContextMenu, &cm));
- if (FAILED(hr))
- return NULL;
-
- HMENU hmenu = CreatePopupMenu();
+HMENU GetSubmenuByID(HMENU hmenu, UINT id)
+{
+ MENUITEMINFOW mii = {sizeof(mii), MIIM_SUBMENU};
+ if (::GetMenuItemInfoW(hmenu, id, FALSE, &mii))
+ return mii.hSubMenu;
- // FIXME: get proper numbers ?
- const UINT first = 0x7800;
- const UINT last = 0x7A00;
- hr = cm->QueryContextMenu(hmenu, 0, first, last, 0);
- if (FAILED(hr))
- return NULL;
+ return NULL;
+}
- // TODO: filter or something
+/* ReallyGetMenuItemID returns the id of an item even if it opens a submenu,
+ GetMenuItemID returns -1 if the specified item opens a submenu */
+UINT ReallyGetMenuItemID(HMENU hmenu, int i)
+{
+ MENUITEMINFOW mii = {sizeof(mii), MIIM_ID};
+ if (::GetMenuItemInfoW(hmenu, i, TRUE, &mii))
+ return mii.wID;
- return hmenu;
+ return UINT_MAX;
}
-void CDefView::PrepareShowFileMenu(HMENU hSubMenu)
+HRESULT CDefView::FillFileMenu()
{
- TRACE("(%p)->(submenu=%p) stub\n", this, hSubMenu);
-
- if (!hSubMenu)
- return;
+ HMENU hFileMenu = GetSubmenuByID(m_hMenu, FCIDM_MENU_FILE);
+ if (!hFileMenu)
+ return E_FAIL;
/* Cleanup the items added previously */
- for (int i = 0; i < GetMenuItemCount(hSubMenu); )
+ for (int i = GetMenuItemCount(hFileMenu) - 1; i >= 0; i--)
{
- MENUITEMINFOW mii;
- mii.cbSize = sizeof(mii);
- mii.fMask = MIIM_ID;
- GetMenuItemInfoW(hSubMenu, i, TRUE, &mii);
-
- if (mii.wID < 0x8000)
- {
- DeleteMenu(hSubMenu, i, MF_BYPOSITION);
- }
- else
- {
- i++;
- }
+ UINT id = GetMenuItemID(hFileMenu, i);
+ if (id < FCIDM_BROWSERFIRST || id > FCIDM_BROWSERLAST)
+ DeleteMenu(hFileMenu, i, MF_BYPOSITION);
}
-#if 0
- /* FIXME/TODO: Reenable when they implemented AND localizable (not hardcoded). */
- /* 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);
-#endif
+ /* Store the context menu in m_pCM and keep it in order to invoke the selected command later on */
+ HRESULT hr = GetItemObject(SVGIO_SELECTION, IID_PPV_ARG(IContextMenu, &m_pCM));
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
- HMENU menubase = BuildFileMenu();
- if (menubase)
- {
- int count = ::GetMenuItemCount(menubase);
- int count2 = ::GetMenuItemCount(hSubMenu);
+ IUnknown_SetSite(m_pCM, (IShellView *)this);
- if (count2 > 0 && count > 0)
- {
- _InsertMenuItemW(hSubMenu, 0, TRUE, 0, MFT_SEPARATOR, NULL, MFS_ENABLED);
- }
+ HMENU hmenu = CreatePopupMenu();
- for (int i = count-1; i >= 0; i--)
- {
- WCHAR label[128];
+ hr = m_pCM->QueryContextMenu(hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, 0);
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
- MENUITEMINFOW mii = { 0 };
- 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);
+ // TODO: filter or something
- TRACE("Adding item %d label %S type %d\n", mii.wID, mii.dwTypeData, mii.fType);
+ Shell_MergeMenus(hFileMenu, hmenu, 0, 0, 0xFFFF, MM_ADDSEPARATOR | MM_SUBMENUSHAVEIDS);
- mii.fType |= MFT_RADIOCHECK;
+ ::DestroyMenu(hmenu);
- ::InsertMenuItemW(hSubMenu, 0, TRUE, &mii);
- }
+ return S_OK;
+}
+HRESULT CDefView::FillEditMenu()
+{
+ HMENU hEditMenu = GetSubmenuByID(m_hMenu, FCIDM_MENU_EDIT);
+ if (!hEditMenu)
+ return E_FAIL;
- ::DestroyMenu(menubase);
- }
- TRACE("--\n");
+ HMENU hmenuContents = ::LoadMenuW(shell32_hInstance, L"MENU_003");
+ if (!hmenuContents)
+ return E_FAIL;
+
+ Shell_MergeMenus(hEditMenu, hmenuContents, 0, 0, 0xFFFF, 0);
+
+ ::DestroyMenu(hmenuContents);
+
+ return S_OK;
}
-void CDefView::PrepareShowViewMenu(HMENU hSubMenu)
+HRESULT CDefView::FillViewMenu()
{
- TRACE("(%p)->(submenu=%p)\n", this, hSubMenu);
+ HMENU hViewMenu = GetSubmenuByID(m_hMenu, FCIDM_MENU_VIEW);
+ if (!hViewMenu)
+ return E_FAIL;
- if (!hSubMenu)
- return;
+ m_hMenuViewModes = ::LoadMenuW(shell32_hInstance, L"MENU_001");
+ if (!m_hMenuViewModes)
+ return E_FAIL;
+
+ UINT i = SHMenuIndexFromID(hViewMenu, FCIDM_MENU_VIEW_SEP_OPTIONS);
+ Shell_MergeMenus(hViewMenu, m_hMenuViewModes, i, 0, 0xFFFF, MM_ADDSEPARATOR | MM_DONTREMOVESEPS | MM_SUBMENUSHAVEIDS);
+
+ return S_OK;
+}
+
+HRESULT CDefView::FillArrangeAsMenu(HMENU hmenuArrange)
+{
+ /* We only need to fill this once */
+ if (GetMenuItemID(hmenuArrange, 0) == FCIDM_SHVIEW_AUTOARRANGE)
+ {
+ Shell_MergeMenus(hmenuArrange, m_hMenuArrangeModes, 0, 0, 0xFFFF,0);
+ }
+
+ /* Also check the menu item according to which we sort */
+ CheckMenuRadioItem(hmenuArrange,
+ 0x30,
+ 0x100,
+ m_sortInfo.nHeaderID + 0x30,
+ MF_BYCOMMAND);
+
+ return S_OK;
+}
+HRESULT CDefView::CheckViewMode(HMENU hmenuView)
+{
if (m_FolderSettings.ViewMode >= FVM_FIRST && m_FolderSettings.ViewMode <= FVM_LAST)
{
UINT iItemFirst = FCIDM_SHVIEW_BIGICON;
UINT iItemLast = iItemFirst + FVM_LAST - FVM_FIRST;
UINT iItem = iItemFirst + m_FolderSettings.ViewMode - FVM_FIRST;
- CheckMenuRadioItem(hSubMenu, iItemFirst, iItemLast, iItem, MF_BYCOMMAND);
+ CheckMenuRadioItem(hmenuView, iItemFirst, iItemLast, iItem, MF_BYCOMMAND);
}
+
+ return S_OK;
}
/**********************************************************
if (GetKeyState(VK_CONTROL) & 0x8000)
cmi.fMask |= CMIC_MASK_CONTROL_DOWN;
- return m_pCM->InvokeCommand(&cmi);
+ HRESULT hr = m_pCM->InvokeCommand(&cmi);
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ return S_OK;
}
/**********************************************************
return E_FAIL;
hResult = GetItemObject(SVGIO_SELECTION, IID_PPV_ARG(IContextMenu, &m_pCM));
- if (FAILED(hResult))
+ if (FAILED_UNEXPECTEDLY(hResult))
goto cleanup;
IUnknown_SetSite(m_pCM, (IShellView *)this);
hResult = m_pCM->QueryContextMenu(hMenu, 0, 0x20, 0x7fff, CMF_DEFAULTONLY);
- if (FAILED(hResult))
+ if (FAILED_UNEXPECTEDLY(hResult))
goto cleanup;
uCommand = GetMenuDefaultItem(hMenu, FALSE, 0);
{
WORD x, y;
UINT uCommand;
- HMENU hMenu;
HRESULT hResult;
- // for some reason I haven't figured out, we sometimes recurse into this method
- if (m_pCM != NULL)
- return 0;
-
x = LOWORD(lParam);
y = HIWORD(lParam);
TRACE("(%p)->(0x%08x 0x%08x) stub\n", this, x, y);
- hMenu = CreatePopupMenu();
- if (!hMenu)
+ m_hContextMenu = CreatePopupMenu();
+ if (!m_hContextMenu)
return E_FAIL;
m_cidl = m_ListView.GetSelectedCount();
hResult = GetItemObject( m_cidl ? SVGIO_SELECTION : SVGIO_BACKGROUND, IID_PPV_ARG(IContextMenu, &m_pCM));
- if (FAILED( hResult))
+ if (FAILED_UNEXPECTEDLY(hResult))
goto cleanup;
IUnknown_SetSite(m_pCM, (IShellView *)this);
- hResult = m_pCM->QueryContextMenu(hMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
- if (FAILED( hResult))
+ hResult = m_pCM->QueryContextMenu(m_hContextMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
+ if (FAILED_UNEXPECTEDLY(hResult))
goto cleanup;
- uCommand = TrackPopupMenu(hMenu,
+ uCommand = TrackPopupMenu(m_hContextMenu,
TPM_LEFTALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
x, y, 0, m_hWnd, NULL);
if (uCommand == 0)
m_pCM.Release();
}
- if (hMenu)
- DestroyMenu(hMenu);
+ if (m_hContextMenu)
+ {
+ DestroyMenu(m_hContextMenu);
+ m_hContextMenu = NULL;
+ }
return 0;
}
return 0;
hResult = GetItemObject( bUseSelection ? SVGIO_SELECTION : SVGIO_BACKGROUND, IID_PPV_ARG(IContextMenu, &m_pCM));
- if (FAILED( hResult))
+ if (FAILED_UNEXPECTEDLY( hResult))
goto cleanup;
IUnknown_SetSite(m_pCM, (IShellView *)this);
hResult = m_pCM->QueryContextMenu(hMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
- if (FAILED( hResult))
+ if (FAILED_UNEXPECTEDLY( hResult))
goto cleanup;
InvokeContextMenuCommand(uCommand);
}
else
{
- if (m_hMenu)
+ if(m_hMenu && !m_bmenuBarInitialized)
{
- if (!m_menusLoaded)
- {
- MENUITEMINFOW mii = { 0 };
-
- /* initialize EDIT menu */
- mii.cbSize = sizeof(mii);
- mii.fMask = MIIM_SUBMENU;
- if (::GetMenuItemInfoW(m_hMenu, FCIDM_MENU_EDIT, FALSE, &mii))
- {
- HMENU hSubMenu = mii.hSubMenu;
-
- HMENU menubase = ::LoadMenuW(shell32_hInstance, L"MENU_003");
-
- int count = ::GetMenuItemCount(menubase);
- for (int i = 0; i < count; i++)
- {
- WCHAR label[128];
-
- ZeroMemory(&mii, sizeof(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);
-
- TRACE("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);
- }
-
- /* initialize VIEW menu */
-
- mii.cbSize = sizeof(mii);
- mii.fMask = MIIM_SUBMENU;
- if (::GetMenuItemInfoW(m_hMenu, FCIDM_MENU_VIEW, FALSE, &mii))
- {
- HMENU menubase = ::LoadMenuW(shell32_hInstance, L"MENU_001");
-
- HMENU hSubMenu = mii.hSubMenu;
-
- m_hView = CreatePopupMenu();
-
- _InsertMenuItemW(hSubMenu, FCIDM_MENU_VIEW_SEP_OPTIONS, FALSE, 0, MFT_SEPARATOR, NULL, MFS_ENABLED);
-
- int count = ::GetMenuItemCount(menubase);
- for (int i = 0; i < count; i++)
- {
- WCHAR label[128];
-
- ZeroMemory(&mii, sizeof(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);
-
- ::AppendMenuW(m_hView, mii.fType, mii.wID, mii.dwTypeData);
-
- TRACE("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);
- }
-
-
- TRACE("-- before fnSetMenuSB\n");
- m_pShellBrowser->SetMenuSB(m_hMenu, 0, m_hWnd);
-
- m_menusLoaded = TRUE;
- }
+ FillEditMenu();
+ FillViewMenu();
+ m_pShellBrowser->SetMenuSB(m_hMenu, 0, m_hWnd);
+ m_bmenuBarInitialized = TRUE;
}
if (SVUIA_ACTIVATE_FOCUS == uState)
m_ListView.SortItems(ListViewCompareItems, this);
break;
+ case FCIDM_SHVIEW_SNAPTOGRID:
+ case FCIDM_SHVIEW_AUTOARRANGE:
+ //FIXME
+ break;
case FCIDM_SHVIEW_SELECTALL:
m_ListView.SetItemState(-1, LVIS_SELECTED, LVIS_SELECTED);
break;
case FCIDM_SHVIEW_NEWFOLDER:
return OnExplorerCommand(dwCmdID, FALSE);
default:
- TRACE("-- COMMAND 0x%04x unhandled\n", dwCmdID);
+ /* WM_COMMAND messages from the file menu are routed to the CDefView so as to let m_pCM handle the command */
+ if (m_pCM)
+ {
+ InvokeContextMenuCommand(dwCmdID);
+ }
}
return 0;
if (m_pSF2Parent)
{
SHELLDETAILS sd;
- if (FAILED(m_pSF2Parent->GetDetailsOf(pidl, lpdi->item.iSubItem, &sd)))
- {
- FIXME("failed to get details\n");
+ if (FAILED_UNEXPECTEDLY(m_pSF2Parent->GetDetailsOf(pidl, lpdi->item.iSubItem, &sd)))
break;
- }
if (lpnmh->code == LVN_GETDISPINFOA)
{
if (SUCCEEDED(m_pSFParent->GetUIObjectOf(m_hWnd, m_cidl, m_apidl, IID_NULL_PPV_ARG(IDataObject, &pda))))
{
+ LPNMLISTVIEW params = (LPNMLISTVIEW)lParam;
+
if (SUCCEEDED(m_pSFParent->GetAttributesOf(m_cidl, m_apidl, &dwAttributes)))
{
if (dwAttributes & SFGAO_CANLINK)
DWORD dwEffect2;
m_pSourceDataObject = pda;
+ m_ptFirstMousePos = params->ptAction;
+ ClientToScreen(&m_ptFirstMousePos);
+
+ HIMAGELIST big_icons, small_icons;
+ Shell_GetImageLists(&big_icons, &small_icons);
+ PCUITEMID_CHILD pidl = _PidlByItem(params->iItem);
+ int iIcon = SHMapPIDLToSystemImageListIndex(m_pSFParent, pidl, 0);
+ POINT ptItem;
+ m_ListView.GetItemPosition(params->iItem, &ptItem);
+
+ ImageList_BeginDrag(big_icons, iIcon, params->ptAction.x - ptItem.x, params->ptAction.y - ptItem.y);
DoDragDrop(pda, this, dwEffect, &dwEffect2);
*/
LRESULT CDefView::OnInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{
- MENUITEMINFOW mii = { 0 };
- HMENU hSubmenu = (HMENU) wParam;
+ HMENU hmenu = (HMENU) wParam;
+ int nPos = LOWORD(lParam);
+ UINT menuItemId;
- TRACE("OnInitMenuPopup lParam=%d\n", lParam);
-
- mii.cbSize = sizeof(mii);
- mii.fMask = MIIM_ID | MIIM_SUBMENU;
+ OnCustomItem(uMsg, wParam, lParam, bHandled);
- if (!GetMenuItemInfoW(this->m_hMenu, lParam, TRUE, &mii))
- {
- TRACE("OnInitMenuPopup GetMenuItemInfoW failed!\n");
- return FALSE;
- }
+ HMENU hViewMenu = GetSubmenuByID(m_hMenu, FCIDM_MENU_VIEW);
- UINT menuItemId = mii.wID;
-
- if (mii.hSubMenu != hSubmenu)
- {
- TRACE("OnInitMenuPopup submenu does not match!!!!\n");
+ /* Lets try to find out what the hell wParam is */
+ if (hmenu == GetSubMenu(m_hMenu, nPos))
+ menuItemId = ReallyGetMenuItemID(m_hMenu, nPos);
+ else if (hViewMenu && hmenu == GetSubMenu(hViewMenu, nPos))
+ menuItemId = ReallyGetMenuItemID(hViewMenu, nPos);
+ else if (m_hContextMenu && hmenu == GetSubMenu(m_hContextMenu, nPos))
+ menuItemId = ReallyGetMenuItemID(m_hContextMenu, nPos);
+ else
return FALSE;
- }
-
- TRACE("OnInitMenuPopup id=%d\n", menuItemId);
switch (menuItemId)
{
case FCIDM_MENU_FILE:
- PrepareShowFileMenu(hSubmenu);
- break;
- case FCIDM_MENU_EDIT:
- //PrepareShowEditMenu(hSubmenu);
+ FillFileMenu();
break;
case FCIDM_MENU_VIEW:
- PrepareShowViewMenu(hSubmenu);
+ case FCIDM_SHVIEW_VIEW:
+ CheckViewMode(hmenu);
+ break;
+ case FCIDM_SHVIEW_ARRANGE:
+ FillArrangeAsMenu(hmenu);
break;
}
HRESULT WINAPI CDefView::CreateViewWindow(IShellView *lpPrevView, LPCFOLDERSETTINGS lpfs, IShellBrowser *psb, RECT *prcView, HWND *phWnd)
{
- SV2CVW2_PARAMS view_params;
- HRESULT hr;
-
- view_params.cbSize = sizeof(view_params);
- view_params.pfs = lpfs;
- view_params.psvPrev = lpPrevView;
- view_params.psbOwner = psb;
- view_params.prcView = prcView;
- view_params.pvid = NULL;
-
- hr = CreateViewWindow2(&view_params);
- *phWnd = view_params.hwndView;
-
- return hr;
+ return CreateViewWindow3(psb, lpPrevView, SV3CVW3_DEFAULT,
+ (FOLDERFLAGS)lpfs->fFlags, (FOLDERFLAGS)lpfs->fFlags, (FOLDERVIEWMODE)lpfs->ViewMode, NULL, prcView, phWnd);
}
HRESULT WINAPI CDefView::DestroyViewWindow()
m_hAccel = NULL;
}
- if (m_hView)
+ if (m_hMenuViewModes)
{
- DestroyMenu(m_hView);
- m_hView = NULL;
+ DestroyMenu(m_hMenuViewModes);
+ m_hMenuViewModes = NULL;
}
if (m_hMenu)
lvItem.iItem++;
}
- if(uFlags & SVSI_EDIT)
+ if((uFlags & SVSI_EDIT) == SVSI_EDIT)
m_ListView.EditLabel(i);
return S_OK;
case SVGIO_BACKGROUND:
if (IsEqualIID(riid, IID_IContextMenu))
{
- //*ppvOut = ISvBgCm_Constructor(m_pSFParent, FALSE);
if (!ppvOut)
hr = E_OUTOFMEMORY;
- IContextMenu* pcm;
- hr = CDefFolderMenu_Create2(NULL, NULL, 0, NULL, m_pSFParent, NULL, 0, NULL, &pcm);
- if (FAILED(hr))
+ hr = CDefViewBckgrndMenu_CreateInstance(m_pSF2Parent, riid, ppvOut);
+ if (FAILED_UNEXPECTEDLY(hr))
return hr;
- *ppvOut = pcm;
+
}
else if (IsEqualIID(riid, IID_IDispatch))
{
{
hr = CDefViewDual_Constructor(riid, (LPVOID*)&m_pShellFolderViewDual);
if (FAILED_UNEXPECTEDLY(hr))
- {
return hr;
- }
}
hr = m_pShellFolderViewDual->QueryInterface(riid, ppvOut);
}
case SVGIO_SELECTION:
GetSelections();
hr = m_pSFParent->GetUIObjectOf(m_hWnd, m_cidl, m_apidl, riid, 0, ppvOut);
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
break;
}
m_ListView.SetItemState(iItem, lvItem.state, lvItem.stateMask);
- if (dwFlags & SVSI_EDIT)
+ if ((dwFlags & SVSI_EDIT) == SVSI_EDIT)
m_ListView.EditLabel(iItem);
return S_OK;
HRESULT STDMETHODCALLTYPE CDefView::CreateViewWindow2(LPSV2CVW2_PARAMS view_params)
{
- OLEMENUGROUPWIDTHS omw = { { 0, 0, 0, 0, 0, 0 } };
-
- if (view_params->cbSize != sizeof(SV2CVW2_PARAMS))
- return E_FAIL;
-
- if (view_params->pvid != NULL)
- {
- FIXME("SHELLVIEWID not handled, FAIL\n");
- return E_NOTIMPL;
- }
-
- view_params->hwndView = 0;
+ return CreateViewWindow3(view_params->psbOwner, view_params->psvPrev,
+ SV3CVW3_DEFAULT, (FOLDERFLAGS)view_params->pfs->fFlags, (FOLDERFLAGS)view_params->pfs->fFlags,
+ (FOLDERVIEWMODE)view_params->pfs->ViewMode, view_params->pvid, view_params->prcView, &view_params->hwndView);
+}
- TRACE("(%p)->(shlview=%p set=%p shlbrs=%p rec=%p hwnd=%p) incomplete\n", this, view_params->psvPrev, view_params->pfs, view_params->psbOwner, view_params->prcView, view_params->hwndView);
+HRESULT STDMETHODCALLTYPE CDefView::CreateViewWindow3(IShellBrowser *psb, IShellView *psvPrevious, SV3CVW3_FLAGS view_flags, FOLDERFLAGS mask, FOLDERFLAGS flags, FOLDERVIEWMODE mode, const SHELLVIEWID *view_id, RECT *prcView, HWND *hwnd)
+{
+ OLEMENUGROUPWIDTHS omw = { { 0, 0, 0, 0, 0, 0 } };
- if (view_params->pfs != NULL)
- TRACE("-- vmode=%x flags=%x\n", view_params->pfs->ViewMode, view_params->pfs->fFlags);
- if (view_params->prcView != NULL)
- TRACE("-- left=%i top=%i right=%i bottom=%i\n", view_params->prcView->left, view_params->prcView->top, view_params->prcView->right, view_params->prcView->bottom);
+ *hwnd = NULL;
+ TRACE("(%p)->(shlview=%p shlbrs=%p rec=%p hwnd=%p vmode=%x flags=%x)\n", this, psvPrevious, psb, prcView, hwnd, mode, flags);
+ if (prcView != NULL)
+ TRACE("-- left=%i top=%i right=%i bottom=%i\n", prcView->left, prcView->top, prcView->right, prcView->bottom);
+
/* Validate the Shell Browser */
- if (view_params->psbOwner == NULL || m_hWnd)
+ if (psb == NULL || m_hWnd)
return E_UNEXPECTED;
+ if (view_flags != SV3CVW3_DEFAULT)
+ FIXME("unsupported view flags 0x%08x\n", view_flags);
+
/* Set up the member variables */
- m_pShellBrowser = view_params->psbOwner;
- m_FolderSettings = *view_params->pfs;
+ m_pShellBrowser = psb;
+ m_FolderSettings.ViewMode = mode;
+ m_FolderSettings.fFlags = mask & flags;
+
+ if (view_id)
+ {
+ if (IsEqualIID(*view_id, VID_LargeIcons))
+ m_FolderSettings.ViewMode = FVM_ICON;
+ else if (IsEqualIID(*view_id, VID_SmallIcons))
+ m_FolderSettings.ViewMode = FVM_SMALLICON;
+ else if (IsEqualIID(*view_id, VID_List))
+ m_FolderSettings.ViewMode = FVM_LIST;
+ else if (IsEqualIID(*view_id, VID_Details))
+ m_FolderSettings.ViewMode = FVM_DETAILS;
+ else if (IsEqualIID(*view_id, VID_Thumbnails))
+ m_FolderSettings.ViewMode = FVM_THUMBNAIL;
+ else if (IsEqualIID(*view_id, VID_Tile))
+ m_FolderSettings.ViewMode = FVM_TILE;
+ else if (IsEqualIID(*view_id, VID_ThumbStrip))
+ m_FolderSettings.ViewMode = FVM_THUMBSTRIP;
+ else
+ FIXME("Ignoring unrecognized VID %s\n", debugstr_guid(view_id));
+ }
/* Get our parent window */
m_pShellBrowser->GetWindow(&m_hWndParent);
TRACE("-- CommDlgBrowser\n");
}
- Create(m_hWndParent, view_params->prcView, NULL, WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP, 0, 0U);
+ Create(m_hWndParent, prcView, NULL, WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP, 0, 0U);
if (m_hWnd == NULL)
return E_FAIL;
- view_params->hwndView = m_hWnd;
+ *hwnd = m_hWnd;
CheckToolbar();
- if (!view_params->hwndView)
+ if (!*hwnd)
return E_FAIL;
SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
if (V_VT(pvaIn) != VT_INT_PTR)
return OLECMDERR_E_NOTSUPPORTED;
-
TPMPARAMS params;
params.cbSize = sizeof(params);
params.rcExclude = *(RECT*) V_INTREF(pvaIn);
- HMENU hView = m_hView;
-#if 0
- hView = CreatePopupMenu();
- AppendMenuW(hView, MF_STRING, FCIDM_SHVIEW_BIGICON, L"Big!");
- AppendMenuW(hView, MF_STRING, FCIDM_SHVIEW_SMALLICON, L"Small!");
- AppendMenuW(hView, MF_STRING, FCIDM_SHVIEW_LISTVIEW, L"List!");
- AppendMenuW(hView, MF_STRING, FCIDM_SHVIEW_REPORTVIEW, L"Report!");
-#endif
-
- if (hView)
+ if (m_hMenuViewModes)
{
- PrepareShowViewMenu(hView);
-
- TrackPopupMenuEx(hView, TPM_LEFTALIGN | TPM_TOPALIGN, params.rcExclude.left, params.rcExclude.bottom, m_hWndParent, ¶ms);
+ /* Duplicate all but the last two items of the view modes menu */
+ HMENU hmenuViewPopup = CreatePopupMenu();
+ Shell_MergeMenus(hmenuViewPopup, m_hMenuViewModes, 0, 0, 0xFFFF, 0);
+ DeleteMenu(hmenuViewPopup, GetMenuItemCount(hmenuViewPopup) - 1, MF_BYPOSITION);
+ DeleteMenu(hmenuViewPopup, GetMenuItemCount(hmenuViewPopup) - 1, MF_BYPOSITION);
+ CheckViewMode(hmenuViewPopup);
+ TrackPopupMenuEx(hmenuViewPopup, TPM_LEFTALIGN | TPM_TOPALIGN, params.rcExclude.left, params.rcExclude.bottom, m_hWndParent, ¶ms);
+ ::DestroyMenu(hmenuViewPopup);
}
// pvaOut is VT_I4 with value 0x403 (cmd id of the new mode maybe?)
HRESULT CDefView::drag_notify_subitem(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
{
- LVHITTESTINFO htinfo;
LONG lResult;
HRESULT hr;
RECT clientRect;
/* Map from global to client coordinates and query the index of the listview-item, which is
* currently under the mouse cursor. */
- htinfo.pt.x = pt.x;
- htinfo.pt.y = pt.y;
- htinfo.flags = LVHT_ONITEM;
- ::ScreenToClient(m_ListView, &htinfo.pt);
+ LVHITTESTINFO htinfo = {{pt.x, pt.y}, LVHT_ONITEM};
+ ScreenToClient(&htinfo.pt);
lResult = m_ListView.HitTest(&htinfo);
/* Send WM_*SCROLL messages every 250 ms during drag-scrolling */
m_ptLastMousePos = htinfo.pt;
+ /* We need to check if we drag the selection over itself */
+ if (lResult != -1 && m_pSourceDataObject.p != NULL)
+ {
+ PCUITEMID_CHILD pidl = _PidlByItem(lResult);
+
+ for (UINT i = 0; i < m_cidl; i++)
+ {
+ if (pidl == m_apidl[i])
+ {
+ /* The item that is being draged is hovering itself. */
+ lResult = -1;
+ break;
+ }
+ }
+ }
+
/* If we are still over the previous sub-item, notify it via DragOver and return. */
if (m_pCurDropTarget && lResult == m_iDragOverItem)
return m_pCurDropTarget->DragOver(grfKeyState, pt, pdwEffect);
/* We've left the previous sub-item, notify it via DragLeave and Release it. */
if (m_pCurDropTarget)
{
+ PCUITEMID_CHILD pidl = _PidlByItem(m_iDragOverItem);
+ if (pidl)
+ SelectItem(pidl, 0);
+
m_pCurDropTarget->DragLeave();
m_pCurDropTarget.Release();
}
m_iDragOverItem = lResult;
+
if (lResult == -1)
{
/* We are not above one of the listview's subitems. Bind to the parent folder's
/* If anything failed, m_pCurDropTarget should be NULL now, which ought to be a save state. */
if (FAILED(hr))
+ {
+ *pdwEffect = DROPEFFECT_NONE;
return hr;
+ }
+
+ if (m_iDragOverItem != -1)
+ {
+ SelectItem(m_iDragOverItem, SVSI_SELECT);
+ }
/* Notify the item just entered via DragEnter. */
return m_pCurDropTarget->DragEnter(m_pCurDataObject, grfKeyState, pt, pdwEffect);
{
/* Get a hold on the data object for later calls to DragEnter on the sub-folders */
m_pCurDataObject = pDataObject;
- pDataObject->AddRef();
- return drag_notify_subitem(grfKeyState, pt, pdwEffect);
+ HRESULT hr = drag_notify_subitem(grfKeyState, pt, pdwEffect);
+ if (SUCCEEDED(hr))
+ {
+ POINT ptClient = {pt.x, pt.y};
+ ScreenToClient(&ptClient);
+ ImageList_DragEnter(m_hWnd, ptClient.x, ptClient.y);
+ }
+
+ return hr;
}
HRESULT WINAPI CDefView::DragOver(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
{
+ POINT ptClient = {pt.x, pt.y};
+ ScreenToClient(&ptClient);
+ ImageList_DragMove(ptClient.x, ptClient.y);
return drag_notify_subitem(grfKeyState, pt, pdwEffect);
}
HRESULT WINAPI CDefView::DragLeave()
{
+ ImageList_DragLeave(m_hWnd);
+
if (m_pCurDropTarget)
{
m_pCurDropTarget->DragLeave();
{
ERR("GetKeyState(VK_LBUTTON): %d\n", GetKeyState(VK_LBUTTON));
- if ((m_iDragOverItem == -1) &&
+ ImageList_DragLeave(m_hWnd);
+ ImageList_EndDrag();
+
+ if ((m_iDragOverItem == -1 || m_pCurDropTarget == NULL) &&
(*pdwEffect & DROPEFFECT_MOVE) &&
- (GetKeyState(VK_LBUTTON) != 0) &&
+ /*(GetKeyState(VK_LBUTTON) != 0) &&*/
(m_pSourceDataObject.p) &&
(SHIsSameObject(pDataObject, m_pSourceDataObject)))
{
- ERR("Should implement moving items here!\n");
-
if (m_pCurDropTarget)
{
m_pCurDropTarget->DragLeave();
m_pCurDropTarget.Release();
}
+
+ /* Restore the selection */
+ m_ListView.SetItemState(-1, 0, LVIS_SELECTED);
+ for (UINT i = 0 ; i < m_cidl; i++)
+ SelectItem(m_apidl[i], SVSI_SELECT);
+
+ /* Reposition the items */
+ int lvIndex = -1;
+ while ((lvIndex = m_ListView.GetNextItem(lvIndex, LVNI_SELECTED)) > -1)
+ {
+ POINT ptItem;
+ if (m_ListView.GetItemPosition(lvIndex, &ptItem))
+ {
+ ptItem.x += pt.x - m_ptFirstMousePos.x;
+ ptItem.y += pt.y - m_ptFirstMousePos.y;
+ m_ListView.SetItemPosition(lvIndex, &ptItem);
+ }
+ }
}
else if (m_pCurDropTarget)
{
*/
HRESULT WINAPI IShellView_Constructor(IShellFolder *pFolder, IShellView **newView)
{
- return ShellObjectCreatorInit<CDefView>(pFolder, IID_IShellView, newView);
+ return ShellObjectCreatorInit<CDefView>(pFolder, IID_PPV_ARG(IShellView, newView));
}
HRESULT WINAPI CDefView_Constructor(IShellFolder *pFolder, REFIID riid, LPVOID * ppvOut)