Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

menu.c

Go to the documentation of this file.
00001 /****************************** Module Header ******************************\ 00002 * Module Name: menu.c 00003 * 00004 * Copyright (c) 1985 - 1999, Microsoft Corporation 00005 * 00006 * This module contains common menu functions. 00007 * 00008 * History: 00009 * 11-15-94 JimA Created. 00010 \***************************************************************************/ 00011 00012 00013 /***************************************************************************\ 00014 * 00015 * GetMenuDefaultItem() - 00016 * 00017 * Searches through a menu for the default item. A menu can have at most 00018 * one default. We will return either the ID or the position, as requested. 00019 * 00020 * We try to return back the first non-disabled default item. However, if 00021 * all of the defaults we encountered were disabled, we'll return back the 00022 * the first default if we found it. 00023 * 00024 \***************************************************************************/ 00025 00026 DWORD _GetMenuDefaultItem(PMENU pMenu, BOOL fByPosition, UINT uFlags) 00027 { 00028 int iItem; 00029 int cItems; 00030 PITEM pItem; 00031 PMENU pSubMenu; 00032 00033 pItem = REBASEALWAYS(pMenu, rgItems); 00034 cItems = pMenu->cItems; 00035 00036 /* 00037 * Walk the list of items sequentially until we find one that has 00038 * MFS_DEFAULT set. 00039 */ 00040 for (iItem = 0; iItem < cItems; iItem++, pItem++) { 00041 if (TestMFS(pItem, MFS_DEFAULT)) { 00042 if ((uFlags & GMDI_USEDISABLED) || !TestMFS(pItem, MFS_GRAYED)) { 00043 if ((uFlags & GMDI_GOINTOPOPUPS) && (pItem->spSubMenu != NULL)) { 00044 DWORD id; 00045 00046 /* 00047 * Is there a valid submenu default? If not, we'll use 00048 * this one. 00049 */ 00050 pSubMenu = REBASEPTR(pMenu, pItem->spSubMenu); 00051 id = _GetMenuDefaultItem(pSubMenu, fByPosition, uFlags); 00052 if (id != MFMWFP_NOITEM) 00053 return(id); 00054 } 00055 00056 break; 00057 } 00058 } 00059 } 00060 00061 if (iItem < cItems) { 00062 return (fByPosition ? iItem : pItem->wID); 00063 } else { 00064 return (MFMWFP_NOITEM); 00065 } 00066 } 00067 00068 /***************************************************************************\ 00069 * 00070 * MNCanClose 00071 * 00072 * returns TRUE if the given window either doesn't have a system menu or has 00073 * a system menu which has an enabled menu item with the SC_CLOSE syscommand 00074 * id. 00075 * 00076 \***************************************************************************/ 00077 00078 BOOL xxxMNCanClose(PWND pwnd) 00079 { 00080 PMENU pMenu; 00081 PITEM pItem; 00082 PCLS pcls; 00083 00084 CheckLock(pwnd); 00085 00086 pcls = (PCLS)REBASEALWAYS(pwnd, pcls); 00087 if ( TestCF2(pcls, CFNOCLOSE) ) 00088 return FALSE; 00089 00090 pMenu = xxxGetSysMenuHandle(pwnd); 00091 if (!pMenu || !(pMenu = REBASEPTR(pwnd, pMenu))) 00092 return(FALSE); 00093 00094 /* 00095 * Note how this parallels the code in SetCloseDefault--we check for 00096 * 3 different IDs. 00097 */ 00098 pItem = MNLookUpItem(pMenu, SC_CLOSE, FALSE, NULL); 00099 00100 if (!(pItem)) 00101 pItem = MNLookUpItem(pMenu, SC_CLOSE-0x7000, FALSE, NULL); 00102 00103 if (!(pItem)) 00104 pItem = MNLookUpItem(pMenu, 0xC070, FALSE, NULL); 00105 00106 return((pItem) && !TestMFS(pItem, MFS_GRAYED)); 00107 } 00108 00109 /***************************************************************************\ 00110 * xxxLoadSysMenu 00111 * 00112 * Loads a menu from USER32.DLL and then gives the "NT5 look" 00113 * 00114 * History 00115 * 04/02/97 GerardoB Created 00116 \***************************************************************************/ 00117 RTLMENU xxxLoadSysMenu (UINT uMenuId) 00118 { 00119 RTLMENU rtlMenu; 00120 MENUINFO mi; 00121 MENUITEMINFO mii; 00122 TL tlMenu; 00123 00124 #ifdef _USERK_ 00125 UNICODE_STRING strMenuName; 00126 RtlInitUnicodeStringOrId(&strMenuName, MAKEINTRESOURCE(uMenuId)); 00127 rtlMenu = xxxClientLoadMenu(NULL, &strMenuName); 00128 #else 00129 rtlMenu = LoadMenu(hmodUser, MAKEINTRESOURCE(uMenuId)); 00130 #endif 00131 00132 if (rtlMenu == NULL) { 00133 RIPMSG1(RIP_WARNING, "xxxLoadSysMenu failed to load:%#lx", uMenuId); 00134 return NULL; 00135 } 00136 00137 ThreadLockAlways(rtlMenu, &tlMenu); 00138 /* 00139 * Add the checkorbmp style. (draw bitmaps and checkmarks on the 00140 * same column) 00141 */ 00142 mi.cbSize = sizeof(mi); 00143 mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS; 00144 mi.dwStyle = MNS_CHECKORBMP; 00145 xxxRtlSetMenuInfo(rtlMenu, &mi); 00146 /* 00147 * Add the bitmaps for close, minimize, maximize and restore items. 00148 */ 00149 mii.cbSize = sizeof(mii); 00150 mii.fMask = MIIM_BITMAP; 00151 mii.hbmpItem = HBMMENU_POPUP_CLOSE; 00152 xxxRtlSetMenuItemInfo (rtlMenu, SC_CLOSE, &mii); 00153 if (uMenuId != ID_DIALOGSYSMENU) { 00154 mii.hbmpItem = HBMMENU_POPUP_MINIMIZE; 00155 xxxRtlSetMenuItemInfo (rtlMenu, SC_MINIMIZE, &mii); 00156 mii.hbmpItem = HBMMENU_POPUP_MAXIMIZE; 00157 xxxRtlSetMenuItemInfo (rtlMenu, SC_MAXIMIZE, &mii); 00158 mii.hbmpItem = HBMMENU_POPUP_RESTORE; 00159 xxxRtlSetMenuItemInfo (rtlMenu, SC_RESTORE, &mii); 00160 } 00161 00162 ThreadUnlock(&tlMenu); 00163 return rtlMenu; 00164 } 00165

Generated on Sat May 15 19:40:44 2004 for test by doxygen 1.3.7