diff src/win32/Commands.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/Commands.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,75 @@
     1.4 +#include "stdafx.h"
     1.5 +#include <afxres.h>
     1.6 +#include "resource.h"
     1.7 +#include "AcceleratorManager.h"
     1.8 +
     1.9 +#ifndef CMapStringToWord
    1.10 +typedef CMap< CString, LPCSTR, WORD, WORD & > CMapStringToWord;
    1.11 +#endif
    1.12 +
    1.13 +static CMapStringToWord winAccelStrings;
    1.14 +static bool initialized = false;
    1.15 +
    1.16 +struct
    1.17 +{
    1.18 +	const char *command;
    1.19 +	WORD        id;
    1.20 +} winAccelCommands[] = {
    1.21 +	{	"Minimize",				ID_SYSTEM_MINIMIZE	},
    1.22 +	{	"Maximize",				ID_SYSTEM_MAXIMIZE	},
    1.23 +};
    1.24 +
    1.25 +void winAccelAddCommandsFromTable(CAcceleratorManager &mgr)
    1.26 +{
    1.27 +	int count = sizeof(winAccelCommands)/sizeof(winAccelCommands[0]);
    1.28 +
    1.29 +	for (int i = 0; i < count; i++)
    1.30 +	{
    1.31 +		if (!mgr.AddCommandAccel(winAccelCommands[i].id, winAccelCommands[i].command, false))
    1.32 +			mgr.CreateEntry(winAccelCommands[i].id, winAccelCommands[i].command);
    1.33 +	}
    1.34 +}
    1.35 +
    1.36 +// recursive calls
    1.37 +void winAccelAddCommandsFromMenu(CAcceleratorManager &mgr, CMenu *pMenu, const CString &parentStr)
    1.38 +{
    1.39 +	UINT nIndexMax = pMenu->GetMenuItemCount();
    1.40 +	for (UINT nIndex = 0; nIndex < nIndexMax; ++nIndex)
    1.41 +	{
    1.42 +		UINT nID = pMenu->GetMenuItemID(nIndex);
    1.43 +		if (nID == 0)
    1.44 +			continue; // menu separator or invalid cmd - ignore it
    1.45 +
    1.46 +		if (nID == (UINT)-1)
    1.47 +		{
    1.48 +			// possibly a submenu
    1.49 +			CMenu *pSubMenu = pMenu->GetSubMenu(nIndex);
    1.50 +			if (pSubMenu != NULL)
    1.51 +			{
    1.52 +				CString tempStr;
    1.53 +				pMenu->GetMenuString(nIndex, tempStr, MF_BYPOSITION);
    1.54 +				tempStr.Remove('&');
    1.55 +				winAccelAddCommandsFromMenu(mgr, pSubMenu, parentStr + '\\' + tempStr);
    1.56 +			}
    1.57 +		}
    1.58 +		else
    1.59 +		{
    1.60 +			// normal menu item
    1.61 +			// generate the strings
    1.62 +			CString command;
    1.63 +			pMenu->GetMenuString(nIndex, command, MF_BYPOSITION);
    1.64 +			int nPos = command.ReverseFind('\t');
    1.65 +			if (nPos != -1)
    1.66 +			{
    1.67 +				command.Delete(nPos, command.GetLength() - nPos);
    1.68 +			}
    1.69 +			command.Remove('&');
    1.70 +			command = parentStr + '\\' + command;
    1.71 +			if (!mgr.AddCommandAccel(nID, command, false))
    1.72 +			{
    1.73 +				mgr.CreateEntry(nID, command);
    1.74 +			}
    1.75 +		}
    1.76 +	}
    1.77 +}
    1.78 +