DlgTreeShortcuts.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // DlgTreeShortcuts.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "DlgTreeShortcuts.h"
  16. #ifdef _DEBUG
  17. #undef new
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CDlgTreeShortcuts dialog
  24. CDlgTreeShortcuts::CDlgTreeShortcuts(CWnd* pParent /*=NULL*/)
  25. : CDialog(CDlgTreeShortcuts::IDD, pParent)
  26. {
  27. //{{AFX_DATA_INIT(CDlgTreeShortcuts)
  28. //}}AFX_DATA_INIT
  29. m_iPressedShortcut = -1;
  30. }
  31. void CDlgTreeShortcuts::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  34. CDialog::DoDataExchange(pDX);
  35. // if dialog is recieving data
  36. if(pDX->m_bSaveAndValidate == FALSE)
  37. {
  38. CTString astrShortcutNames[ DIRECTORY_SHORTCT_CT];
  39. // obtain tree shortcut names
  40. for( INDEX iShortcut=0;iShortcut<DIRECTORY_SHORTCT_CT; iShortcut++)
  41. {
  42. // obtain tree item
  43. INDEX iSubDirsCt;
  44. iSubDirsCt = pMainFrame->m_Browser.m_aiSubDirectoriesCt[ iShortcut];
  45. // get virtual directory item
  46. HTREEITEM pItem = pMainFrame->m_Browser.GetVirtualDirectoryItem(
  47. pMainFrame->m_Browser.m_astrVTreeBuffer[iShortcut], iSubDirsCt);
  48. ASSERT( pItem != NULL);
  49. // obtain shortcut's virtual tree node
  50. CVirtualTreeNode *pvtnNode =
  51. (CVirtualTreeNode *) pMainFrame->m_Browser.m_TreeCtrl.GetItemData( pItem);
  52. char achrShortcutIndex[ 16];
  53. sprintf( achrShortcutIndex, "%d. ", iShortcut+1);
  54. // obtain full path name
  55. astrShortcutNames[ iShortcut] = achrShortcutIndex+theApp.GetNameForVirtualTreeNode( pvtnNode);
  56. }
  57. for(INDEX iCtrl=0; iCtrl<10; iCtrl++)
  58. {
  59. // set names to buttons
  60. GetDlgItem( IDC_SHORTCUT01+iCtrl)->SetWindowText( CString(astrShortcutNames[ iCtrl]));
  61. }
  62. }
  63. //{{AFX_DATA_MAP(CDlgTreeShortcuts)
  64. //}}AFX_DATA_MAP
  65. }
  66. BEGIN_MESSAGE_MAP(CDlgTreeShortcuts, CDialog)
  67. //{{AFX_MSG_MAP(CDlgTreeShortcuts)
  68. // NOTE: the ClassWizard will add message map macros here
  69. //}}AFX_MSG_MAP
  70. ON_COMMAND_RANGE(IDC_SHORTCUT01, IDC_SHORTCUT10, OnTreeShortcut)
  71. END_MESSAGE_MAP()
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CDlgTreeShortcuts message handlers
  74. BOOL CDlgTreeShortcuts::PreTranslateMessage(MSG* pMsg)
  75. {
  76. if( pMsg->message==WM_KEYDOWN)
  77. {
  78. if(pMsg->wParam == VK_RETURN)
  79. {
  80. pMsg->wParam = VK_SPACE;
  81. }
  82. // if we caught key down message
  83. if( (pMsg->wParam!=VK_CONTROL) &&
  84. (pMsg->wParam!=VK_ESCAPE) &&
  85. (pMsg->wParam!=VK_TAB) &&
  86. (pMsg->wParam!=VK_UP) &&
  87. (pMsg->wParam!=VK_DOWN) &&
  88. (pMsg->wParam!='W') )
  89. {
  90. if( (pMsg->wParam>='0') && (pMsg->wParam<='9') )
  91. {
  92. // remap key ID to number 0-9
  93. if( pMsg->wParam == '0') m_iPressedShortcut = 9;
  94. else m_iPressedShortcut = pMsg->wParam-'1';
  95. }
  96. EndDialog( 0);
  97. return TRUE;
  98. }
  99. if( pMsg->wParam == 'W')
  100. {
  101. EndDialog( 0);
  102. }
  103. }
  104. return CDialog::PreTranslateMessage(pMsg);
  105. }
  106. void CDlgTreeShortcuts::OnTreeShortcut(UINT nID)
  107. {
  108. m_iPressedShortcut = nID-IDC_SHORTCUT01;
  109. EndDialog( 0);
  110. }