CmdUI.cpp

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 // CmdUIDialog.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include <afxpriv.h>
00027 #include "CmdUI.h"
00028 
00029 // CCmdUIDialog dialog
00030 
00031 IMPLEMENT_DYNAMIC(CCmdUIDialog, CDialog)
00032 
00033 CCmdUIDialog::CCmdUIDialog()
00034 {
00035 }
00036 
00037 CCmdUIDialog::CCmdUIDialog(UINT nIDTemplate, CWnd* pParent /*=NULL*/)
00038         : CDialog(nIDTemplate, pParent)
00039 {
00040 }
00041 
00042 CCmdUIDialog::CCmdUIDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
00043         : CDialog(lpszTemplateName, pParentWnd)
00044 {
00045 }
00046 
00047 CCmdUIDialog::~CCmdUIDialog()
00048 {
00049 }
00050 
00051 LRESULT CCmdUIDialog::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
00052 {
00053         LRESULT ret = __super::DefWindowProc(message, wParam, lParam);
00054 
00055         if(message == WM_INITDIALOG)
00056         {
00057                 SendMessage(WM_KICKIDLE);
00058         }
00059 
00060         return(ret);
00061 }
00062 
00063 BEGIN_MESSAGE_MAP(CCmdUIDialog, CDialog)
00064         ON_MESSAGE_VOID(WM_KICKIDLE, OnKickIdle)
00065         ON_WM_INITMENUPOPUP()
00066 END_MESSAGE_MAP()
00067 
00068 
00069 // CCmdUIDialog message handlers
00070 
00071 void CCmdUIDialog::OnKickIdle()
00072 {
00073         UpdateDialogControls(this, false);
00074 
00075         // TODO: maybe we should send this call to modeless child cdialogs too
00076 }
00077 
00078 // Q242577
00079 
00080 void CCmdUIDialog::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
00081 {
00082     ASSERT(pPopupMenu != NULL);
00083     // Check the enabled state of various menu items.
00084 
00085     CCmdUI state;
00086     state.m_pMenu = pPopupMenu;
00087     ASSERT(state.m_pOther == NULL);
00088     ASSERT(state.m_pParentMenu == NULL);
00089 
00090     // Determine if menu is popup in top-level menu and set m_pOther to
00091     // it if so (m_pParentMenu == NULL indicates that it is secondary popup).
00092     HMENU hParentMenu;
00093     if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
00094         state.m_pParentMenu = pPopupMenu;    // Parent == child for tracking popup.
00095     else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
00096     {
00097         CWnd* pParent = this;
00098            // Child windows don't have menus--need to go to the top!
00099         if (pParent != NULL &&
00100            (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
00101         {
00102            int nIndexMax = ::GetMenuItemCount(hParentMenu);
00103            for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
00104            {
00105             if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
00106             {
00107                 // When popup is found, m_pParentMenu is containing menu.
00108                 state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
00109                 break;
00110             }
00111            }
00112         }
00113     }
00114 
00115     state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
00116     for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
00117       state.m_nIndex++)
00118     {
00119         state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
00120         if (state.m_nID == 0)
00121            continue; // Menu separator or invalid cmd - ignore it.
00122 
00123         ASSERT(state.m_pOther == NULL);
00124         ASSERT(state.m_pMenu != NULL);
00125         if (state.m_nID == (UINT)-1)
00126         {
00127            // Possibly a popup menu, route to first item of that popup.
00128            state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
00129            if (state.m_pSubMenu == NULL ||
00130             (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
00131             state.m_nID == (UINT)-1)
00132            {
00133             continue;       // First item of popup can't be routed to.
00134            }
00135            state.DoUpdate(this, TRUE);   // Popups are never auto disabled.
00136         }
00137         else
00138         {
00139            // Normal menu item.
00140            // Auto enable/disable if frame window has m_bAutoMenuEnable
00141            // set and command is _not_ a system command.
00142            state.m_pSubMenu = NULL;
00143            state.DoUpdate(this, FALSE);
00144         }
00145 
00146         // Adjust for menu deletions and additions.
00147         UINT nCount = pPopupMenu->GetMenuItemCount();
00148         if (nCount < state.m_nIndexMax)
00149         {
00150            state.m_nIndex -= (state.m_nIndexMax - nCount);
00151            while (state.m_nIndex < nCount &&
00152             pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
00153            {
00154             state.m_nIndex++;
00155            }
00156         }
00157         state.m_nIndexMax = nCount;
00158     }
00159 }
00160 
00161 // CCmdUIPropertyPage
00162 
00163 IMPLEMENT_DYNAMIC(CCmdUIPropertyPage, CPropertyPage)
00164 CCmdUIPropertyPage::CCmdUIPropertyPage(UINT nIDTemplate, UINT nIDCaption)
00165         : CPropertyPage(nIDTemplate, nIDCaption)
00166 {
00167 }
00168 
00169 CCmdUIPropertyPage::~CCmdUIPropertyPage()
00170 {
00171 }
00172 
00173 LRESULT CCmdUIPropertyPage::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
00174 {
00175         if(message == WM_COMMAND)
00176         {
00177                 switch(HIWORD(wParam))
00178                 {
00179                         case BN_CLICKED: case CBN_SELCHANGE: case EN_CHANGE:
00180                                 SetModified();
00181                         default:;
00182                 }
00183         }
00184 
00185         LRESULT ret = __super::DefWindowProc(message, wParam, lParam);
00186 
00187         if(message == WM_INITDIALOG)
00188         {
00189                 SendMessage(WM_KICKIDLE);
00190         }
00191 
00192         return(ret);
00193 }
00194 
00195 BEGIN_MESSAGE_MAP(CCmdUIPropertyPage, CPropertyPage)
00196         ON_MESSAGE_VOID(WM_KICKIDLE, OnKickIdle)
00197 END_MESSAGE_MAP()
00198 
00199 
00200 // CCmdUIPropertyPage message handlers
00201 
00202 void CCmdUIPropertyPage::OnKickIdle()
00203 {
00204         UpdateDialogControls(this, false);
00205 
00206         // TODO: maybe we should send this call to modeless child cPropertyPages too
00207 }
00208 

Generated on Tue Dec 13 14:47:57 2005 for guliverkli by  doxygen 1.4.5