Author: dquintana Date: Tue Feb 18 18:18:08 2014 New Revision: 62248
URL: http://svn.reactos.org/svn/reactos?rev=62248&view=rev Log: [RSHELL] * Fix some more C-style casts, and misc coding style changes. * CMenuBand: Create a skeleton of the functions that would handle SMIF_TRACKPOPUP submenus. * CMenuDeskBar: Fix the redraw issue that prevented submenus from working as expected. CORE-7886
Modified: branches/shell-experiments/base/shell/rshell/CDesktopBrowser.cpp branches/shell-experiments/base/shell/rshell/CMenuBand.cpp branches/shell-experiments/base/shell/rshell/CMenuDeskBar.cpp branches/shell-experiments/base/shell/rshell/CMenuSite.cpp branches/shell-experiments/base/shell/rshell/CStartMenu.cpp
Modified: branches/shell-experiments/base/shell/rshell/CDesktopBrowser.cpp URL: http://svn.reactos.org/svn/reactos/branches/shell-experiments/base/shell/rsh... ============================================================================== --- branches/shell-experiments/base/shell/rshell/CDesktopBrowser.cpp [iso-8859-1] (original) +++ branches/shell-experiments/base/shell/rshell/CDesktopBrowser.cpp [iso-8859-1] Tue Feb 18 18:18:08 2014 @@ -402,7 +402,7 @@ switch (uMsg) { case WM_ERASEBKGND: - return (LRESULT) PaintDesktop((HDC) wParam); + return (LRESULT) PaintDesktop(reinterpret_cast<HDC>(wParam));
case WM_GETISHELLBROWSER: Ret = reinterpret_cast<LRESULT>(static_cast<IShellBrowser *>(pThis)); @@ -456,7 +456,7 @@
case WM_NCCREATE: { - LPCREATESTRUCT CreateStruct = (LPCREATESTRUCT) lParam; + LPCREATESTRUCT CreateStruct = reinterpret_cast<LPCREATESTRUCT>(lParam); pThis = SHDESK_Create(hwnd, CreateStruct); if (pThis == NULL) { @@ -466,7 +466,7 @@
SetWindowLongPtrW(hwnd, 0, - (LONG_PTR) pThis); + reinterpret_cast<LONG_PTR>(pThis)); Ret = TRUE; break; } @@ -543,7 +543,7 @@ hWndDesk = CreateWindowExW(0, szProgmanClassName, szProgmanWindowName, WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rcDesk.left, rcDesk.top, rcDesk.right, rcDesk.bottom, - NULL, NULL, shell32_hInstance, (LPVOID) ShellDesk); + NULL, NULL, shell32_hInstance, reinterpret_cast<LPVOID>(ShellDesk)); if (hWndDesk != NULL) return (HANDLE) GetWindowLongPtrW(hWndDesk, 0);
Modified: branches/shell-experiments/base/shell/rshell/CMenuBand.cpp URL: http://svn.reactos.org/svn/reactos/branches/shell-experiments/base/shell/rsh... ============================================================================== --- branches/shell-experiments/base/shell/rshell/CMenuBand.cpp [iso-8859-1] (original) +++ branches/shell-experiments/base/shell/rshell/CMenuBand.cpp [iso-8859-1] Tue Feb 18 18:18:08 2014 @@ -23,7 +23,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(CMenuBand);
-#define WRAP_LOG 1 +#define WRAP_LOG 0
#define TBSTYLE_EX_VERTICAL 4
@@ -56,6 +56,7 @@ HRESULT OnHotItemChange(const NMTBHOTITEM * hot);
HRESULT PopupSubMenu(UINT index, IShellMenu* childShellMenu); + HRESULT PopupSubMenu(UINT index, HMENU menu); HRESULT DoContextMenu(IContextMenu* contextMenu);
static LRESULT CALLBACK s_SubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -68,7 +69,7 @@ CMenuBand *m_menuBand; HWND m_hwnd; DWORD m_dwMenuFlags; - UINT m_hotItem; + INT m_hotItem; WNDPROC m_SubclassOld; };
@@ -164,6 +165,7 @@ DWORD m_dwFlags; PVOID m_UserData; HMENU m_hmenu; + HWND m_menuOwner; #endif
BOOL m_useBigIcons; @@ -254,6 +256,7 @@
HRESULT CallCBWithId(UINT Id, UINT uMsg, WPARAM wParam, LPARAM lParam); HRESULT CallCBWithPidl(LPITEMIDLIST pidl, UINT uMsg, WPARAM wParam, LPARAM lParam); + HRESULT TrackPopup(HMENU popup, INT x, INT y, RECT& rc);
BOOL UseBigIcons() { return m_useBigIcons; @@ -868,11 +871,11 @@
if (m_menuBand->UseBigIcons()) { - SendMessageW(m_hwnd, TB_SETIMAGELIST, 0, (LPARAM) ilBig); + SendMessageW(m_hwnd, TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(ilBig)); } else { - SendMessageW(m_hwnd, TB_SETIMAGELIST, 0, (LPARAM) ilSmall); + SendMessageW(m_hwnd, TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(ilSmall)); }
return S_OK; @@ -934,15 +937,15 @@ //else if (m_menuBand->UseBigIcons()) { - SendMessageW(m_hwnd, TB_SETIMAGELIST, 0, (LPARAM) ilBig); + SendMessageW(m_hwnd, TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(ilBig)); } else { - SendMessageW(m_hwnd, TB_SETIMAGELIST, 0, (LPARAM) ilSmall); - } - - SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)this); - m_SubclassOld = (WNDPROC) SetWindowLongPtr(m_hwnd, GWLP_WNDPROC, (LONG_PTR) CMenuToolbarBase::s_SubclassProc); + SendMessageW(m_hwnd, TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(ilSmall)); + } + + SetWindowLongPtr(m_hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); + m_SubclassOld = (WNDPROC) SetWindowLongPtr(m_hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(CMenuToolbarBase::s_SubclassProc));
return S_OK; } @@ -1009,7 +1012,7 @@ HRESULT hr;
RECT rc; - if (!SendMessage(m_hwnd, TB_GETITEMRECT, index, (LPARAM) &rc)) + if (!SendMessage(m_hwnd, TB_GETITEMRECT, index, reinterpret_cast<LPARAM>(&rc))) return E_FAIL;
POINT a = { rc.left, rc.top }; @@ -1062,6 +1065,27 @@ return S_OK; }
+HRESULT CMenuToolbarBase::PopupSubMenu(UINT index, HMENU menu) +{ + RECT rc; + if (!SendMessage(m_hwnd, TB_GETITEMRECT, index, reinterpret_cast<LPARAM>(&rc))) + return E_FAIL; + + POINT a = { rc.left, rc.top }; + POINT b = { rc.right, rc.bottom }; + + ClientToScreen(m_hwnd, &a); + ClientToScreen(m_hwnd, &b); + + SetRect(&rc, a.x, a.y, b.x, b.y); // maybe-TODO: fetch client area of deskbar? + + HMENU popup = GetSubMenu(menu, index); + + m_menuBand->TrackPopup(popup, rc.right, rc.bottom, rc); + + return S_OK; +} + HRESULT CMenuToolbarBase::DoContextMenu(IContextMenu* contextMenu) { HRESULT hr; @@ -1174,11 +1198,13 @@ tbb.iString = (INT_PTR) MenuString; tbb.idCommand = info.wID;
- SMINFO sminfo = { 0 }; - sminfo.dwMask = SMIM_ICON; - if (info.wID >= 0 && SUCCEEDED(m_menuBand->CallCBWithId(info.wID, SMC_GETINFO, 0, (LPARAM) &sminfo))) + SMINFO * sminfo = new SMINFO(); + sminfo->dwMask = SMIM_ICON | SMIM_FLAGS; + if (info.wID >= 0 && SUCCEEDED(m_menuBand->CallCBWithId(info.wID, SMC_GETINFO, 0, reinterpret_cast<LPARAM>(sminfo)))) { - tbb.iBitmap = sminfo.iIcon; + tbb.iBitmap = sminfo->iIcon; + tbb.dwData = reinterpret_cast<DWORD_PTR>(sminfo); + // FIXME: remove before deleting the toolbar or it will leak } } else @@ -1186,7 +1212,7 @@ tbb.fsStyle |= BTNS_SEP; }
- SendMessageW(m_hwnd, TB_ADDBUTTONS, 1, (LPARAM) (LPTBBUTTON) &tbb); + SendMessageW(m_hwnd, TB_ADDBUTTONS, 1, reinterpret_cast<LPARAM>(&tbb));
if (MenuString) HeapFree(GetProcessHeap(), 0, MenuString); @@ -1198,7 +1224,7 @@ HRESULT CMenuStaticToolbar::OnContextMenu(NMMOUSE * rclick) { CComPtr<IContextMenu> contextMenu; - HRESULT hr = m_menuBand->CallCBWithId(rclick->dwItemSpec, SMC_GETOBJECT, (WPARAM) &IID_IContextMenu, (LPARAM) &contextMenu); + HRESULT hr = m_menuBand->CallCBWithId(rclick->dwItemSpec, SMC_GETOBJECT, reinterpret_cast<WPARAM>(&IID_IContextMenu), reinterpret_cast<LPARAM>(&contextMenu)); if (hr != S_OK) return hr;
@@ -1216,19 +1242,30 @@
HRESULT CMenuStaticToolbar::PopupItem(UINT uItem) { - CComPtr<IShellMenu> shellMenu; - HRESULT hr = m_menuBand->CallCBWithId(uItem, SMC_GETOBJECT, (WPARAM) &IID_IShellMenu, (LPARAM) &shellMenu); - if (FAILED(hr)) - return hr; - TBBUTTONINFO info = { 0 }; info.cbSize = sizeof(TBBUTTONINFO); info.dwMask = 0; - int index = SendMessage(m_hwnd, TB_GETBUTTONINFO, uItem, (LPARAM) &info); + int index = SendMessage(m_hwnd, TB_GETBUTTONINFO, uItem, reinterpret_cast<LPARAM>(&info)); if (index < 0) return E_FAIL; - - return PopupSubMenu(index, shellMenu); + + TBBUTTON btn = { 0 }; + SendMessage(m_hwnd, TB_GETBUTTON, index, reinterpret_cast<LPARAM>(&btn)); + + SMINFO * nfo = reinterpret_cast<SMINFO*>(btn.dwData); + if (nfo->dwFlags&SMIF_TRACKPOPUP) + { + return PopupSubMenu(index, m_hmenu); + } + else + { + CComPtr<IShellMenu> shellMenu; + HRESULT hr = m_menuBand->CallCBWithId(uItem, SMC_GETOBJECT, reinterpret_cast<WPARAM>(&IID_IShellMenu), reinterpret_cast<LPARAM>(&shellMenu)); + if (FAILED(hr)) + return hr; + + return PopupSubMenu(index, shellMenu); + } }
HRESULT CMenuStaticToolbar::HasSubMenu(UINT uItem) @@ -1236,7 +1273,7 @@ TBBUTTONINFO info = { 0 }; info.cbSize = sizeof(TBBUTTONINFO); info.dwMask = 0; - int index = SendMessage(m_hwnd, TB_GETBUTTONINFO, uItem, (LPARAM) &info); + int index = SendMessage(m_hwnd, TB_GETBUTTONINFO, uItem, reinterpret_cast<LPARAM>(&info)); if (index < 0) return E_FAIL; return ::GetSubMenu(m_hmenu, index) ? S_OK : S_FALSE; @@ -1265,7 +1302,7 @@ IEnumIDList * eidl; m_shellFolder->EnumObjects(m_hwnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &eidl);
- LPITEMIDLIST item = (LPITEMIDLIST) CoTaskMemAlloc(sizeof(ITEMIDLIST)); + LPITEMIDLIST item = static_cast<LPITEMIDLIST>(CoTaskMemAlloc(sizeof(ITEMIDLIST))); ULONG fetched; while ((hr = eidl->Next(1, &item, &fetched)) == S_OK) { @@ -1292,9 +1329,10 @@ tbb.idCommand = i++; tbb.iString = (INT_PTR) MenuString; tbb.iBitmap = index; - tbb.dwData = (DWORD_PTR) ILClone(item); - - SendMessageW(m_hwnd, TB_ADDBUTTONS, 1, (LPARAM) (LPTBBUTTON) &tbb); + tbb.dwData = reinterpret_cast<DWORD_PTR>(ILClone(item)); + // FIXME: remove before deleting the toolbar or it will leak + + SendMessageW(m_hwnd, TB_ADDBUTTONS, 1, reinterpret_cast<LPARAM>(&tbb)); HeapFree(GetProcessHeap(), 0, MenuString);
} @@ -1348,7 +1386,7 @@ TBBUTTONINFO info = { 0 }; info.cbSize = sizeof(TBBUTTONINFO); info.dwMask = 0; - int index = SendMessage(m_hwnd, TB_GETBUTTONINFO, uItem, (LPARAM) &info); + int index = SendMessage(m_hwnd, TB_GETBUTTONINFO, uItem, reinterpret_cast<LPARAM>(&info)); if (index < 0) return NULL;
@@ -1356,10 +1394,10 @@ *pIndex = index;
TBBUTTON btn = { 0 }; - if (!SendMessage(m_hwnd, TB_GETBUTTON, index, (LPARAM) &btn)) + if (!SendMessage(m_hwnd, TB_GETBUTTON, index, reinterpret_cast<LPARAM>(&btn))) return NULL;
- return (LPITEMIDLIST) btn.dwData; + return reinterpret_cast<LPITEMIDLIST>(btn.dwData); }
HRESULT CMenuSFToolbar::OnContextMenu(NMMOUSE * rclick) @@ -1479,7 +1517,7 @@ { m_psmc->AddRef();
- _CallCB(SMC_CREATE, 0, (LPARAM) &m_UserData); + _CallCB(SMC_CREATE, 0, reinterpret_cast<LPARAM>(&m_UserData)); }
return S_OK; @@ -1518,6 +1556,7 @@ m_staticToolbar = new CMenuStaticToolbar(this); } m_hmenu = hmenu; + m_menuOwner;
HRESULT hResult = m_staticToolbar->SetMenu(hmenu, hwnd, dwFlags); if (FAILED(hResult)) @@ -1635,8 +1674,8 @@ if (hwndStatic == NULL && hwndShlFld == NULL) return E_FAIL;
- if (hwndStatic) SendMessageW(hwndStatic, TB_GETIDEALSIZE, TRUE, (LPARAM) &sizeStaticY); - if (hwndShlFld) SendMessageW(hwndShlFld, TB_GETIDEALSIZE, TRUE, (LPARAM) &sizeShlFldY); + if (hwndStatic) SendMessageW(hwndStatic, TB_GETIDEALSIZE, TRUE, reinterpret_cast<LPARAM>(&sizeStaticY)); + if (hwndShlFld) SendMessageW(hwndShlFld, TB_GETIDEALSIZE, TRUE, reinterpret_cast<LPARAM>(&sizeShlFldY));
int sy = max(prc->bottom - prc->top, sizeStaticY.cy + sizeShlFldY.cy);
@@ -1699,8 +1738,8 @@ SIZE sizeStatic = { 0 }; SIZE sizeShlFld = { 0 };
- if (hwndStatic) SendMessageW(hwndStatic, TB_GETIDEALSIZE, TRUE, (LPARAM) &sizeStatic); - if (hwndShlFld) SendMessageW(hwndShlFld, TB_GETIDEALSIZE, TRUE, (LPARAM) &sizeShlFld); + if (hwndStatic) SendMessageW(hwndStatic, TB_GETIDEALSIZE, TRUE, reinterpret_cast<LPARAM>(&sizeStatic)); + if (hwndShlFld) SendMessageW(hwndShlFld, TB_GETIDEALSIZE, TRUE, reinterpret_cast<LPARAM>(&sizeShlFld));
pdbi->ptMinSize.x = 0; pdbi->ptMinSize.y = sizeStatic.cy + sizeShlFld.cy; @@ -1710,8 +1749,8 @@ SIZE sizeStatic = { 0 }; SIZE sizeShlFld = { 0 };
- if (hwndStatic) SendMessageW(hwndStatic, TB_GETMAXSIZE, 0, (LPARAM) &sizeStatic); - if (hwndShlFld) SendMessageW(hwndShlFld, TB_GETMAXSIZE, 0, (LPARAM) &sizeShlFld); + if (hwndStatic) SendMessageW(hwndStatic, TB_GETMAXSIZE, 0, reinterpret_cast<LPARAM>(&sizeStatic)); + if (hwndShlFld) SendMessageW(hwndShlFld, TB_GETMAXSIZE, 0, reinterpret_cast<LPARAM>(&sizeShlFld));
pdbi->ptMaxSize.x = max(sizeStatic.cx, sizeShlFld.cx); // ignored pdbi->ptMaxSize.y = sizeStatic.cy + sizeShlFld.cy; @@ -1726,12 +1765,12 @@ SIZE sizeStatic = { 0 }; SIZE sizeShlFld = { 0 };
- if (hwndStatic) SendMessageW(hwndStatic, TB_GETIDEALSIZE, FALSE, (LPARAM) &sizeStatic); - if (hwndShlFld) SendMessageW(hwndShlFld, TB_GETIDEALSIZE, FALSE, (LPARAM) &sizeShlFld); + if (hwndStatic) SendMessageW(hwndStatic, TB_GETIDEALSIZE, FALSE, reinterpret_cast<LPARAM>(&sizeStatic)); + if (hwndShlFld) SendMessageW(hwndShlFld, TB_GETIDEALSIZE, FALSE, reinterpret_cast<LPARAM>(&sizeShlFld)); pdbi->ptActual.x = max(sizeStatic.cx, sizeShlFld.cx);
- if (hwndStatic) SendMessageW(hwndStatic, TB_GETIDEALSIZE, TRUE, (LPARAM) &sizeStatic); - if (hwndShlFld) SendMessageW(hwndShlFld, TB_GETIDEALSIZE, TRUE, (LPARAM) &sizeShlFld); + if (hwndStatic) SendMessageW(hwndStatic, TB_GETIDEALSIZE, TRUE, reinterpret_cast<LPARAM>(&sizeStatic)); + if (hwndShlFld) SendMessageW(hwndShlFld, TB_GETIDEALSIZE, TRUE, reinterpret_cast<LPARAM>(&sizeShlFld)); pdbi->ptActual.y = sizeStatic.cy + sizeShlFld.cy; } if (pdbi->dwMask & DBIM_TITLE) @@ -2196,4 +2235,10 @@ smData.psf->Release(); return hr; } + +HRESULT CMenuBand::TrackPopup(HMENU popup, INT x, INT y, RECT& rc) +{ + ::TrackPopupMenu(popup, 0, x, y, 0, m_menuOwner, &rc); + return S_OK; +} #endif
Modified: branches/shell-experiments/base/shell/rshell/CMenuDeskBar.cpp URL: http://svn.reactos.org/svn/reactos/branches/shell-experiments/base/shell/rsh... ============================================================================== --- branches/shell-experiments/base/shell/rshell/CMenuDeskBar.cpp [iso-8859-1] (original) +++ branches/shell-experiments/base/shell/rshell/CMenuDeskBar.cpp [iso-8859-1] Tue Feb 18 18:18:08 2014 @@ -24,7 +24,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(CMenuDeskBar);
-#define WRAP_LOG 1 +#define WRAP_LOG 0
typedef CWinTraits< WS_POPUP | WS_DLGFRAME | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, @@ -680,7 +680,7 @@
LRESULT CMenuDeskBar::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { - TRACE("OnPaint\n"); + bHandled = FALSE;
if (m_Banner && !m_IconSize) { @@ -716,7 +716,7 @@ EndPaint(&ps); }
- return 0; + return TRUE; }
HRESULT STDMETHODCALLTYPE CMenuDeskBar::Popup(POINTL *ppt, RECTL *prcExclude, MP_POPUPFLAGS dwFlags) @@ -849,7 +849,7 @@ case MPOS_EXECUTE: bubbleUp = true; cancel = true; - // fall through + break; case MPOS_CANCELLEVEL: cancel = true; break; @@ -857,9 +857,9 @@ case MPOS_SELECTRIGHT: // if unhandled, spread upwards? bubbleUp = true; - return S_OK; + break; case MPOS_CHILDTRACKING: - return S_OK; + break; }
if (cancel)
Modified: branches/shell-experiments/base/shell/rshell/CMenuSite.cpp URL: http://svn.reactos.org/svn/reactos/branches/shell-experiments/base/shell/rsh... ============================================================================== --- branches/shell-experiments/base/shell/rshell/CMenuSite.cpp [iso-8859-1] (original) +++ branches/shell-experiments/base/shell/rshell/CMenuSite.cpp [iso-8859-1] Tue Feb 18 18:18:08 2014 @@ -24,6 +24,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(menusite);
+#if 0 bool _assert(bool cond, LPCSTR expr, LPCSTR file, DWORD line, LPCSTR func) { #if DBG @@ -36,6 +37,9 @@ return cond; } #define DBGASSERT(x) _assert(!!(x), #x, __FILE__, __LINE__, __FUNCSIG__) +#else +#define DBGASSERT(x) (!!(x)) +#endif
class CMenuSite : public CComObjectRootEx<CComMultiThreadModelNoCS>,
Modified: branches/shell-experiments/base/shell/rshell/CStartMenu.cpp URL: http://svn.reactos.org/svn/reactos/branches/shell-experiments/base/shell/rsh... ============================================================================== --- branches/shell-experiments/base/shell/rshell/CStartMenu.cpp [iso-8859-1] (original) +++ branches/shell-experiments/base/shell/rshell/CStartMenu.cpp [iso-8859-1] Tue Feb 18 18:18:08 2014 @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
-#define TEST_TRACKPOPUPMENU_SUBMENUS +//#define TEST_TRACKPOPUPMENU_SUBMENUS
#include "precomp.h"