Skip to content

Commit fe47f84

Browse files
committed
Don't close menu(s) on certain operations
In several cases we don't want menu(s) to close when an action on menu was done. For example on drag-n-drop or menu item deletion (where confirmation dialog is shown). In such situations `s_bPreventClosing` was set to true (and then back to false when closing was allowed again). Though original code honored this variable only in certain situations and typically (at least on Win10) menus were hidden/closed despite of it. This patch changes the behavior and menus(s) are not closed when `s_bPreventClosing` is set to true. Basically now menu(s) stay visible until there is an action that changes active window. Following functionality was also removed because it is not needed now: * CMenuContainer::HideTemp * COwnerWindow::OnClear WM_CLEAR was sent to the window only by already removed `HideTemp`
1 parent f33cd60 commit fe47f84

File tree

6 files changed

+16
-68
lines changed

6 files changed

+16
-68
lines changed

Src/StartMenu/StartMenuDLL/DragDrop.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ bool CMenuContainer::DragOutApps( const CItemManager::ItemInfo *pInfo )
248248
s_bDragFromTree=false;
249249
if (!m_bDestroyed)
250250
KillTimer(TIMER_DRAG);
251-
HideTemp(false);
252251
s_bPreventClosing=false;
253252

254253
if (s_bDragClosed)
@@ -343,7 +342,6 @@ bool CMenuContainer::DragOut( int index, bool bApp )
343342
if (!m_bDestroyed)
344343
KillTimer(TIMER_DRAG);
345344
s_bDragMovable=false;
346-
HideTemp(false);
347345
s_bPreventClosing=false;
348346

349347
if (s_bDragClosed)
@@ -863,8 +861,6 @@ HRESULT STDMETHODCALLTYPE CMenuContainer::Drop( IDataObject *pDataObj, DWORD grf
863861
s_bPreventClosing=true;
864862
AddRef();
865863
pTarget->Drop(pDataObj,grfKeyState,pt,pdwEffect);
866-
if (!bOld)
867-
HideTemp(false);
868864
s_bPreventClosing=bOld;
869865
for (std::vector<CMenuContainer*>::iterator it=s_Menus.begin();it!=s_Menus.end();++it)
870866
if (!(*it)->m_bDestroyed)

Src/StartMenu/StartMenuDLL/MenuCommands.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,7 +2396,6 @@ void CMenuContainer::ActivateItem( int index, TActivateType type, const POINT *p
23962396
}
23972397
}
23982398
DestroyMenu(menu2);
2399-
HideTemp(false);
24002399
s_bPreventClosing=false;
24012400

24022401
PITEMID_CHILD newPidl=NULL;
@@ -2485,7 +2484,6 @@ void CMenuContainer::ActivateItem( int index, TActivateType type, const POINT *p
24852484
Invalidate();
24862485
if (m_HotItem<0) SetHotItem(index);
24872486
}
2488-
HideTemp(false);
24892487
s_bPreventClosing=false;
24902488
}
24912489
SetContextItem(-1);
@@ -2742,7 +2740,6 @@ void CMenuContainer::ActivateItem( int index, TActivateType type, const POINT *p
27422740
else
27432741
SetFocus();
27442742
}
2745-
HideTemp(false);
27462743
s_bPreventClosing=false;
27472744
s_HotPos=GetMessagePos();
27482745
res=CMD_RENAME;
@@ -2802,8 +2799,7 @@ void CMenuContainer::ActivateItem( int index, TActivateType type, const POINT *p
28022799
if (bRefresh || bRefreshMain)
28032800
info.fMask|=CMIC_MASK_NOASYNC; // wait for delete/link commands to finish so we can refresh the menu
28042801

2805-
if ((type!=ACTIVATE_MENU && type!=ACTIVATE_DELETE) || GetWinVersion()<WIN_VER_WIN8)
2806-
s_bPreventClosing=true;
2802+
s_bPreventClosing=true;
28072803
for (std::vector<CMenuContainer*>::iterator it=s_Menus.begin();it!=s_Menus.end();++it)
28082804
(*it)->EnableWindow(FALSE); // disable all menus
28092805
bool bAllPrograms=s_bAllPrograms;
@@ -2880,7 +2876,6 @@ void CMenuContainer::ActivateItem( int index, TActivateType type, const POINT *p
28802876
else
28812877
SetFocus();
28822878
}
2883-
HideTemp(false);
28842879
s_bPreventClosing=false;
28852880

28862881
if (!bKeepOpen && !bRefresh && !bRefreshMain)

Src/StartMenu/StartMenuDLL/MenuContainer.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6365,11 +6365,6 @@ LRESULT CMenuContainer::OnRefresh( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
63656365
return 0;
63666366
}
63676367

6368-
void CMenuContainer::HideTemp( bool bHide )
6369-
{
6370-
::PostMessage(g_OwnerWindow,WM_CLEAR,bHide,0);
6371-
}
6372-
63736368
LRESULT CMenuContainer::OnActivate( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
63746369
{
63756370
if (LOWORD(wParam)!=WA_INACTIVE)
@@ -6379,6 +6374,9 @@ LRESULT CMenuContainer::OnActivate( UINT uMsg, WPARAM wParam, LPARAM lParam, BOO
63796374
return 0;
63806375
}
63816376
#ifndef PREVENT_CLOSING
6377+
if (s_bPreventClosing)
6378+
return 0;
6379+
63826380
if (lParam)
63836381
{
63846382
// check if another menu window is being activated
@@ -6389,24 +6387,15 @@ LRESULT CMenuContainer::OnActivate( UINT uMsg, WPARAM wParam, LPARAM lParam, BOO
63896387

63906388
if ((HWND)lParam==g_OwnerWindow || (HWND)lParam==g_TopWin7Menu)
63916389
return 0;
6392-
6393-
if (s_bPreventClosing && (::GetWindowLong((HWND)lParam,GWL_EXSTYLE)&WS_EX_TOPMOST))
6394-
return 0;
63956390
}
63966391

6397-
// a non-top-most window tries to activate while we are still here
6398-
if (s_bPreventClosing && (!g_TopWin7Menu || !s_bAllPrograms))
6399-
HideTemp(true);
6400-
else
6401-
{
6402-
for (std::vector<CMenuContainer*>::reverse_iterator it=s_Menus.rbegin();it!=s_Menus.rend();++it)
6403-
if ((*it)->m_hWnd && !(*it)->m_bDestroyed)
6404-
{
6405-
(*it)->PostMessage(WM_CLOSE);
6406-
(*it)->m_bClosing=true;
6407-
}
6408-
if (g_TopWin7Menu && s_bAllPrograms) ::PostMessage(g_TopWin7Menu,WM_CLOSE,0,0);
6409-
}
6392+
for (std::vector<CMenuContainer*>::reverse_iterator it=s_Menus.rbegin();it!=s_Menus.rend();++it)
6393+
if ((*it)->m_hWnd && !(*it)->m_bDestroyed)
6394+
{
6395+
(*it)->PostMessage(WM_CLOSE);
6396+
(*it)->m_bClosing=true;
6397+
}
6398+
if (g_TopWin7Menu && s_bAllPrograms) ::PostMessage(g_TopWin7Menu,WM_CLOSE,0,0);
64106399
#endif
64116400

64126401
return 0;

Src/StartMenu/StartMenuDLL/MenuContainer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,6 @@ class CMenuContainer: public IDropTarget, public IFrameworkInputPaneHandler, pub
957957
friend LRESULT CALLBACK SubclassTopMenuProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData );
958958
friend HRESULT CreatePinLink( PCIDLIST_ABSOLUTE sourcePidl, const wchar_t *name, const wchar_t *iconPath, int iconIndex );
959959

960-
static void HideTemp( bool bHide );
961960
static void AddMRUShortcut( const wchar_t *path );
962961
static void AddMRUAppId( const wchar_t *appid );
963962
static void DeleteMRUShortcut( const wchar_t *path );

Src/StartMenu/StartMenuDLL/ProgramsTree.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,8 +1601,6 @@ HRESULT CProgramsTree::Drop( IDataObject *pDataObj, DWORD grfKeyState, POINTL pt
16011601
CMenuContainer::s_bPreventClosing=true;
16021602
m_pOwner->AddRef();
16031603
pTarget->Drop(pDataObj,grfKeyState,pt,pdwEffect);
1604-
if (!bOld)
1605-
CMenuContainer::HideTemp(false);
16061604
CMenuContainer::s_bPreventClosing=bOld;
16071605
for (std::vector<CMenuContainer*>::iterator it=CMenuContainer::s_Menus.begin();it!=CMenuContainer::s_Menus.end();++it)
16081606
if (!(*it)->m_bDestroyed)

Src/StartMenu/StartMenuDLL/StartMenuDLL.cpp

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ class COwnerWindow: public CWindowImpl<COwnerWindow>
292292
// message handlers
293293
BEGIN_MSG_MAP( COwnerWindow )
294294
MESSAGE_HANDLER( WM_ACTIVATE, OnActivate )
295-
MESSAGE_HANDLER( WM_CLEAR, OnClear )
296295
MESSAGE_HANDLER( WM_SYSCOLORCHANGE, OnColorChange )
297296
MESSAGE_HANDLER( WM_SETTINGCHANGE, OnSettingChange )
298297
MESSAGE_HANDLER( WM_DISPLAYCHANGE, OnDisplayChange )
@@ -304,7 +303,7 @@ class COwnerWindow: public CWindowImpl<COwnerWindow>
304303
if (LOWORD(wParam)!=WA_INACTIVE)
305304
return 0;
306305

307-
if (CMenuContainer::s_bPreventClosing && lParam && (::GetWindowLongPtr((HWND)lParam,GWL_EXSTYLE)&WS_EX_TOPMOST))
306+
if (CMenuContainer::s_bPreventClosing)
308307
return 0;
309308

310309
// check if another menu window is being activated
@@ -313,42 +312,14 @@ class COwnerWindow: public CWindowImpl<COwnerWindow>
313312
if ((*it)->m_hWnd==(HWND)lParam)
314313
return 0;
315314

316-
if (CMenuContainer::s_bPreventClosing)
317-
{
318-
CMenuContainer::HideTemp(true);
319-
}
320-
else
321-
{
322-
for (std::vector<CMenuContainer*>::reverse_iterator it=CMenuContainer::s_Menus.rbegin();it!=CMenuContainer::s_Menus.rend();++it)
323-
if (!(*it)->m_bDestroyed)
324-
(*it)->PostMessage(WM_CLOSE);
325-
}
326-
return 0;
327-
}
315+
for (std::vector<CMenuContainer*>::reverse_iterator it=CMenuContainer::s_Menus.rbegin();it!=CMenuContainer::s_Menus.rend();++it)
316+
if (!(*it)->m_bDestroyed)
317+
(*it)->PostMessage(WM_CLOSE);
328318

329-
LRESULT OnClear( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
330-
{
331-
bool bHide=(wParam!=0); // hide or destroy
332-
if (CMenuContainer::s_bTempHidden!=bHide)
333-
{
334-
CMenuContainer::s_bTempHidden=bHide;
335-
if (bHide && CMenuContainer::s_UserPicture.m_hWnd)
336-
CMenuContainer::s_UserPicture.ShowWindow(SW_HIDE);
337-
for (std::vector<CMenuContainer*>::iterator it=CMenuContainer::s_Menus.begin();it!=CMenuContainer::s_Menus.end();++it)
338-
{
339-
if ((*it)->m_hWnd && !(*it)->m_bDestroyed)
340-
{
341-
(*it)->m_bClosing=true;
342-
if (!bHide)
343-
(*it)->PostMessage(WM_CLOSE);
344-
else
345-
(*it)->ShowWindow(SW_HIDE);
346-
}
347-
}
348-
}
349319
return 0;
350320
}
351321

322+
352323
LRESULT OnColorChange( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
353324
{
354325
CMenuContainer::s_Skin.Hash=0;

0 commit comments

Comments
 (0)