home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / AcceleratorManager.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-11-04  |  4.5 KB  |  144 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) 1998 by Thierry Maurel
  3. // All rights reserved
  4. //
  5. // Distribute freely, except: don't remove my name from the source or
  6. // documentation (don't take credit for my work), mark your changes (don't
  7. // get me blamed for your possible bugs), don't alter or remove this
  8. // notice.
  9. // No warrantee of any kind, express or implied, is included with this
  10. // software; use at your own risk, responsibility for damages (if any) to
  11. // anyone resulting from the use of this software rests entirely with the
  12. // user.
  13. //
  14. // Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  15. // I'll try to keep a version up to date.  I can be reached as follows:
  16. //    tmaurel@caramail.com   (or tmaurel@hol.fr)
  17. //
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // File    : AcceleratorManager.h
  20. // Project : AccelsEditor
  21. ////////////////////////////////////////////////////////////////////////////////
  22. // Version : 1.0                       * Author : T.Maurel
  23. // Date    : 17.08.98
  24. //
  25. // Remarks : interface for the CAcceleratorManager class.
  26. //
  27. ////////////////////////////////////////////////////////////////////////////////
  28. #if !defined(AFX_ACCELERATORMANAGER_H__A6D76F4B_26C6_11D2_BE72_006097AC8D00__INCLUDED_)
  29. #define AFX_ACCELERATORMANAGER_H__A6D76F4B_26C6_11D2_BE72_006097AC8D00__INCLUDED_
  30.  
  31. #if _MSC_VER >= 1000
  32. #pragma once
  33. #endif // _MSC_VER >= 1000
  34.  
  35.  
  36.  
  37. #include "CmdAccelOb.h"
  38.  
  39.  
  40. // Helper map
  41. #include <afxtempl.h>  // MFC Templates extension
  42. #ifndef CMapStringToWord
  43. typedef CMap< CString, LPCSTR, WORD, WORD& > CMapStringToWord;
  44. #endif
  45.  
  46. #ifndef CMapWordToCCmdAccelOb
  47. typedef CMap< WORD, WORD&, CCmdAccelOb*, CCmdAccelOb*& > CMapWordToCCmdAccelOb;
  48. #endif
  49.  
  50.  
  51. //////////////////////////////////////////////////////////////////////
  52. //
  53. //
  54. class CAcceleratorManager : public CObject {
  55.   friend class AccelEditor;
  56.  public:
  57.   CAcceleratorManager();
  58.   virtual ~CAcceleratorManager();
  59.  
  60.   // Operations
  61.  public:
  62.   void UpdateMenu(HMENU menu);
  63.   void UpdateMenu();
  64.   // Connection to the main application wnd
  65.   void Connect(CWnd *pWnd, bool bAutoSave = true);
  66.   // In/Out with the registry
  67.   bool Load(HKEY hRegKey, LPCTSTR szRegKey);
  68.   bool Load();
  69.   bool Write();
  70.   // Get the initials accels, not the user's
  71.   bool Default(); 
  72.   // Save a copy in the 2 maps called xxxSaved, which are used in case
  73.   // of Default(), to reload the defaults accels.
  74.   bool CreateDefaultTable();
  75.   bool IsDefaultTableAvailable() {return m_bDefaultTable;}
  76.   bool IsMapStringCommandsEmpty() {
  77.     if (m_mapAccelString.IsEmpty())
  78.       return true;
  79.     else
  80.       return false;
  81.   }
  82.  
  83.   // Registry access configuration
  84.   bool GetRegKey(HKEY& hRegKey, CString &szRegKey);
  85.   bool SetRegKey(HKEY hRegKey, LPCTSTR szRegKey);
  86.   bool IsAutoSave() {return m_bAutoSave;}
  87.   void SetAutoSave(bool bAutoSave) {m_bAutoSave = bAutoSave;}
  88.  
  89.   // Helper fct, used for new menus strings
  90.   bool GetStringFromACCEL(ACCEL* pACCEL, CString& szAccel);
  91.   bool GetStringFromACCEL(BYTE cVirt, WORD nCode, CString& szAccel);
  92.  
  93.   // Update the ACCELS table in the application, from the specified
  94.   // datas in the manager.
  95.   bool UpdateWndTable();
  96.  
  97.   // Modification helper fcts
  98.   bool SetAccel(BYTE cVirt, WORD wIDCommand, WORD wNewCaract,
  99.                 LPCTSTR szCommand, bool bLocked = false);
  100.   bool AddCommandAccel(WORD wIDCommand, LPCTSTR szCommand, bool bLocked = true);
  101.   bool CreateEntry(WORD wIDCommand, LPCTSTR szCommand);
  102.  
  103.   bool DeleteEntry(LPCTSTR szCommand);
  104.   bool DeleteEntry(WORD wIDCommand);
  105.   bool DeleteAccel(BYTE cVirt, WORD wIDCommand, WORD wNewCaract);
  106.  
  107.   // Affectation operator
  108.   CAcceleratorManager& operator=(const CAcceleratorManager& accelmgr);
  109.  
  110.  public:
  111. #ifdef _DEBUG
  112.   virtual void AssertValid() const;
  113.   virtual void Dump(CDumpContext& dc) const;
  114. #endif
  115.  
  116.  protected:
  117.   // Erase all the datas
  118.   void Reset();
  119.   // Internal affect fct.
  120.   bool AddAccel(BYTE cVirt, WORD wIDCommand, WORD wKey,
  121.                 LPCTSTR szCommand, bool bLocked);
  122.  
  123.   // Attributes
  124.  protected:
  125.   CWnd *m_pWndConnected;
  126.  
  127.   // User datas
  128.   CMapStringToWord m_mapAccelString;
  129.   CMapWordToCCmdAccelOb m_mapAccelTable;
  130.   // Default datas
  131.   CMapWordToCCmdAccelOb m_mapAccelTableSaved;
  132.   bool m_bDefaultTable;
  133.  
  134.   // Where the users datas will be saved in the registry
  135.   HKEY m_hRegKey;
  136.   CString m_szRegKey;
  137.   // if true, there is an auto-save in the registry, when the destructor is called
  138.   bool m_bAutoSave;
  139.  
  140. };
  141.  
  142.  
  143. #endif // !defined(AFX_ACCELERATORMANAGER_H__A6D76F4B_26C6_11D2_BE72_006097AC8D00__INCLUDED_)
  144.