annotate src/win32/Commands.cpp @ 2:3549bbe597ed

adding makefile.am
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:47 -0600
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 #include "stdafx.h"
rlm@1 2 #include <afxres.h>
rlm@1 3 #include "resource.h"
rlm@1 4 #include "AcceleratorManager.h"
rlm@1 5
rlm@1 6 #ifndef CMapStringToWord
rlm@1 7 typedef CMap< CString, LPCSTR, WORD, WORD & > CMapStringToWord;
rlm@1 8 #endif
rlm@1 9
rlm@1 10 static CMapStringToWord winAccelStrings;
rlm@1 11 static bool initialized = false;
rlm@1 12
rlm@1 13 struct
rlm@1 14 {
rlm@1 15 const char *command;
rlm@1 16 WORD id;
rlm@1 17 } winAccelCommands[] = {
rlm@1 18 { "Minimize", ID_SYSTEM_MINIMIZE },
rlm@1 19 { "Maximize", ID_SYSTEM_MAXIMIZE },
rlm@1 20 };
rlm@1 21
rlm@1 22 void winAccelAddCommandsFromTable(CAcceleratorManager &mgr)
rlm@1 23 {
rlm@1 24 int count = sizeof(winAccelCommands)/sizeof(winAccelCommands[0]);
rlm@1 25
rlm@1 26 for (int i = 0; i < count; i++)
rlm@1 27 {
rlm@1 28 if (!mgr.AddCommandAccel(winAccelCommands[i].id, winAccelCommands[i].command, false))
rlm@1 29 mgr.CreateEntry(winAccelCommands[i].id, winAccelCommands[i].command);
rlm@1 30 }
rlm@1 31 }
rlm@1 32
rlm@1 33 // recursive calls
rlm@1 34 void winAccelAddCommandsFromMenu(CAcceleratorManager &mgr, CMenu *pMenu, const CString &parentStr)
rlm@1 35 {
rlm@1 36 UINT nIndexMax = pMenu->GetMenuItemCount();
rlm@1 37 for (UINT nIndex = 0; nIndex < nIndexMax; ++nIndex)
rlm@1 38 {
rlm@1 39 UINT nID = pMenu->GetMenuItemID(nIndex);
rlm@1 40 if (nID == 0)
rlm@1 41 continue; // menu separator or invalid cmd - ignore it
rlm@1 42
rlm@1 43 if (nID == (UINT)-1)
rlm@1 44 {
rlm@1 45 // possibly a submenu
rlm@1 46 CMenu *pSubMenu = pMenu->GetSubMenu(nIndex);
rlm@1 47 if (pSubMenu != NULL)
rlm@1 48 {
rlm@1 49 CString tempStr;
rlm@1 50 pMenu->GetMenuString(nIndex, tempStr, MF_BYPOSITION);
rlm@1 51 tempStr.Remove('&');
rlm@1 52 winAccelAddCommandsFromMenu(mgr, pSubMenu, parentStr + '\\' + tempStr);
rlm@1 53 }
rlm@1 54 }
rlm@1 55 else
rlm@1 56 {
rlm@1 57 // normal menu item
rlm@1 58 // generate the strings
rlm@1 59 CString command;
rlm@1 60 pMenu->GetMenuString(nIndex, command, MF_BYPOSITION);
rlm@1 61 int nPos = command.ReverseFind('\t');
rlm@1 62 if (nPos != -1)
rlm@1 63 {
rlm@1 64 command.Delete(nPos, command.GetLength() - nPos);
rlm@1 65 }
rlm@1 66 command.Remove('&');
rlm@1 67 command = parentStr + '\\' + command;
rlm@1 68 if (!mgr.AddCommandAccel(nID, command, false))
rlm@1 69 {
rlm@1 70 mgr.CreateEntry(nID, command);
rlm@1 71 }
rlm@1 72 }
rlm@1 73 }
rlm@1 74 }
rlm@1 75