Support unrar64.dll
[xy_vsfilter.git] / src / ui / CmdUI / CmdUI.cpp
blobc1bf6d16db4a5b39818c50e02039fba3e1bcae46
1 /*
2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // CmdUIDialog.cpp : implementation file
25 #include "stdafx.h"
26 #include <afxpriv.h>
27 #include "CmdUI.h"
29 // CCmdUIDialog dialog
31 IMPLEMENT_DYNAMIC(CCmdUIDialog, CDialog)
33 CCmdUIDialog::CCmdUIDialog()
37 CCmdUIDialog::CCmdUIDialog(UINT nIDTemplate, CWnd* pParent /*=NULL*/)
38 : CDialog(nIDTemplate, pParent)
42 CCmdUIDialog::CCmdUIDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
43 : CDialog(lpszTemplateName, pParentWnd)
47 CCmdUIDialog::~CCmdUIDialog()
51 LRESULT CCmdUIDialog::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
53 LRESULT ret = __super::DefWindowProc(message, wParam, lParam);
55 if(message == WM_INITDIALOG)
57 SendMessage(WM_KICKIDLE);
60 return(ret);
63 BEGIN_MESSAGE_MAP(CCmdUIDialog, CDialog)
64 ON_MESSAGE_VOID(WM_KICKIDLE, OnKickIdle)
65 ON_WM_INITMENUPOPUP()
66 END_MESSAGE_MAP()
69 // CCmdUIDialog message handlers
71 void CCmdUIDialog::OnKickIdle()
73 UpdateDialogControls(this, false);
75 // TODO: maybe we should send this call to modeless child cdialogs too
78 // Q242577
80 void CCmdUIDialog::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
82 ASSERT(pPopupMenu != NULL);
83 // Check the enabled state of various menu items.
85 CCmdUI state;
86 state.m_pMenu = pPopupMenu;
87 ASSERT(state.m_pOther == NULL);
88 ASSERT(state.m_pParentMenu == NULL);
90 // Determine if menu is popup in top-level menu and set m_pOther to
91 // it if so (m_pParentMenu == NULL indicates that it is secondary popup).
92 HMENU hParentMenu;
93 if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
94 state.m_pParentMenu = pPopupMenu; // Parent == child for tracking popup.
95 else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
97 CWnd* pParent = this;
98 // Child windows don't have menus--need to go to the top!
99 if (pParent != NULL &&
100 (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
102 int nIndexMax = ::GetMenuItemCount(hParentMenu);
103 for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
105 if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
107 // When popup is found, m_pParentMenu is containing menu.
108 state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
109 break;
115 state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
116 for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
117 state.m_nIndex++)
119 state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
120 if (state.m_nID == 0)
121 continue; // Menu separator or invalid cmd - ignore it.
123 ASSERT(state.m_pOther == NULL);
124 ASSERT(state.m_pMenu != NULL);
125 if (state.m_nID == (UINT)-1)
127 // Possibly a popup menu, route to first item of that popup.
128 state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
129 if (state.m_pSubMenu == NULL ||
130 (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
131 state.m_nID == (UINT)-1)
133 continue; // First item of popup can't be routed to.
135 state.DoUpdate(this, TRUE); // Popups are never auto disabled.
137 else
139 // Normal menu item.
140 // Auto enable/disable if frame window has m_bAutoMenuEnable
141 // set and command is _not_ a system command.
142 state.m_pSubMenu = NULL;
143 state.DoUpdate(this, FALSE);
146 // Adjust for menu deletions and additions.
147 UINT nCount = pPopupMenu->GetMenuItemCount();
148 if (nCount < state.m_nIndexMax)
150 state.m_nIndex -= (state.m_nIndexMax - nCount);
151 while (state.m_nIndex < nCount &&
152 pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
154 state.m_nIndex++;
157 state.m_nIndexMax = nCount;
161 // CCmdUIPropertyPage
163 IMPLEMENT_DYNAMIC(CCmdUIPropertyPage, CPropertyPage)
164 CCmdUIPropertyPage::CCmdUIPropertyPage(UINT nIDTemplate, UINT nIDCaption)
165 : CPropertyPage(nIDTemplate, nIDCaption)
169 CCmdUIPropertyPage::~CCmdUIPropertyPage()
173 LRESULT CCmdUIPropertyPage::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
175 if(message == WM_COMMAND)
177 switch(HIWORD(wParam))
179 case BN_CLICKED: case CBN_SELCHANGE: case EN_CHANGE:
180 SetModified();
181 default:;
185 LRESULT ret = __super::DefWindowProc(message, wParam, lParam);
187 if(message == WM_INITDIALOG)
189 SendMessage(WM_KICKIDLE);
192 return(ret);
195 BEGIN_MESSAGE_MAP(CCmdUIPropertyPage, CPropertyPage)
196 ON_MESSAGE_VOID(WM_KICKIDLE, OnKickIdle)
197 END_MESSAGE_MAP()
200 // CCmdUIPropertyPage message handlers
202 void CCmdUIPropertyPage::OnKickIdle()
204 UpdateDialogControls(this, false);
206 // TODO: maybe we should send this call to modeless child cPropertyPages too