OptionsKeyBoard.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // OptionsKeyBoard.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "OptionsKeyBoard.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // COptionsKeyBoard property page
  13. IMPLEMENT_DYNCREATE(COptionsKeyBoard, CPropertyPage)
  14. COptionsKeyBoard::COptionsKeyBoard() : CPropertyPage(COptionsKeyBoard::IDD)
  15. {
  16. //{{AFX_DATA_INIT(COptionsKeyBoard)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. }
  20. COptionsKeyBoard::~COptionsKeyBoard()
  21. {
  22. }
  23. void COptionsKeyBoard::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CPropertyPage::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(COptionsKeyBoard)
  27. DDX_Control(pDX, IDC_NAMED_COPY, m_NamedCopy);
  28. DDX_Control(pDX, IDC_HOTKEY, m_HotKey);
  29. //}}AFX_DATA_MAP
  30. }
  31. BEGIN_MESSAGE_MAP(COptionsKeyBoard, CPropertyPage)
  32. //{{AFX_MSG_MAP(COptionsKeyBoard)
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // COptionsKeyBoard message handlers
  37. BOOL COptionsKeyBoard::OnInitDialog()
  38. {
  39. CPropertyPage::OnInitDialog();
  40. m_pParent = (COptionsSheet *)GetParent();
  41. theApp.m_pDittoHotKey->CopyToCtrl( m_HotKey );
  42. theApp.m_pCopyHotKey->CopyToCtrl( m_NamedCopy );
  43. //Unregister hotkeys and Reregister them on cancel or ok
  44. g_HotKeys.UnregisterAll();
  45. m_HotKey.SetFocus();
  46. return FALSE;
  47. }
  48. LRESULT COptionsKeyBoard::OnWizardNext()
  49. {
  50. return CPropertyPage::OnWizardNext();
  51. }
  52. BOOL COptionsKeyBoard::OnWizardFinish()
  53. {
  54. return CPropertyPage::OnWizardFinish();
  55. }
  56. BOOL COptionsKeyBoard::OnApply()
  57. {
  58. int x,y;
  59. CString str;
  60. ARRAY keys;
  61. g_HotKeys.GetKeys( keys ); // save old keys just in case new ones are invalid
  62. theApp.m_pDittoHotKey->CopyFromCtrl( m_HotKey );
  63. theApp.m_pCopyHotKey->CopyFromCtrl( m_NamedCopy );
  64. if( g_HotKeys.FindFirstConflict(keys,&x,&y) )
  65. {
  66. str = g_HotKeys.ElementAt(x)->GetName();
  67. str += " and ";
  68. str += g_HotKeys.ElementAt(y)->GetName();
  69. str += " cannot be the same.";
  70. MessageBox(str);
  71. g_HotKeys.SetKeys( keys ); // restore the original values
  72. return FALSE;
  73. }
  74. g_HotKeys.SaveAllKeys();
  75. g_HotKeys.RegisterAll(true);
  76. return CPropertyPage::OnApply();
  77. }
  78. /*
  79. BOOL COptionsKeyBoard::ValidateHotKey(WORD wHotKey)
  80. {
  81. ATOM id = GlobalAddAtom("HK_VALIDATE");
  82. BOOL bResult = CGetSetOptions::RegisterHotKey(theApp.m_MainhWnd, wHotKey, FALSE);
  83. if(bResult)
  84. UnregisterHotKey(GetSafeHwnd(), id);
  85. GlobalDeleteAtom(id);
  86. return bResult;
  87. }
  88. */
  89. void COptionsKeyBoard::OnCancel()
  90. {
  91. g_HotKeys.RegisterAll( true );
  92. CPropertyPage::OnCancel();
  93. }