ActionsListControl.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. // ActionsListControl.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #ifdef _DEBUG
  16. #undef new
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CActionsListControl
  23. CActionsListControl::CActionsListControl()
  24. {
  25. }
  26. CActionsListControl::~CActionsListControl()
  27. {
  28. }
  29. BEGIN_MESSAGE_MAP(CActionsListControl, CListCtrl)
  30. //{{AFX_MSG_MAP(CActionsListControl)
  31. ON_WM_LBUTTONDOWN()
  32. ON_WM_KEYUP()
  33. ON_WM_KEYDOWN()
  34. ON_WM_SETFOCUS()
  35. ON_WM_KILLFOCUS()
  36. ON_WM_CONTEXTMENU()
  37. ON_COMMAND(ID_BUTTON_ACTION_ADD, OnButtonActionAdd)
  38. ON_COMMAND(ID_BUTTON_ACTION_EDIT, OnButtonActionEdit)
  39. ON_COMMAND(ID_BUTTON_ACTION_REMOVE, OnButtonActionRemove)
  40. ON_UPDATE_COMMAND_UI(ID_BUTTON_ACTION_EDIT, OnUpdateButtonActionEdit)
  41. ON_UPDATE_COMMAND_UI(ID_BUTTON_ACTION_REMOVE, OnUpdateButtonActionRemove)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CActionsListControl message handlers
  46. void CActionsListControl::OnLButtonDown(UINT nFlags, CPoint point)
  47. {
  48. // get no of items
  49. INDEX iButtonsCt = ((CDlgPlayerControls *)GetParent())->m_listButtonActions.GetItemCount();
  50. // get no of items
  51. for( INDEX iListItem=0; iListItem<iButtonsCt; iListItem++)
  52. {
  53. ((CDlgPlayerControls *)GetParent())->m_listButtonActions.SetItemState( iListItem, 0, LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED);
  54. }
  55. CListCtrl::OnLButtonDown(nFlags, point);
  56. /*
  57. // select wanted item
  58. ((CDlgPlayerControls *)GetParent())->m_listButtonActions.SetItemState( iSelectedButton+1,
  59. LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED, LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED);
  60. ((CDlgPlayerControls *)GetParent())->m_listButtonActions.EnsureVisible( iSelectedButton+1, FALSE);
  61. ((CDlgPlayerControls *)GetParent())->m_listButtonActions.SetFocus();
  62. */
  63. ((CDlgPlayerControls *)GetParent())->SetFirstAndSecondButtonNames();
  64. }
  65. void CActionsListControl::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
  66. {
  67. CListCtrl::OnKeyUp(nChar, nRepCnt, nFlags);
  68. ((CDlgPlayerControls *)GetParent())->SetFirstAndSecondButtonNames();
  69. }
  70. void CActionsListControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  71. {
  72. CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
  73. ((CDlgPlayerControls *)GetParent())->SetFirstAndSecondButtonNames();
  74. }
  75. void CActionsListControl::OnSetFocus(CWnd* pOldWnd)
  76. {
  77. // get selected action
  78. INDEX iSelectedAction = GetNextItem( -1, LVIS_SELECTED);
  79. // if none is selected (initial state)
  80. if( iSelectedAction == -1)
  81. {
  82. iSelectedAction = 0;
  83. SetItemState( iSelectedAction, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED);
  84. }
  85. else
  86. {
  87. // clear hilighted state
  88. SetItemState( iSelectedAction, 0, LVIS_DROPHILITED);
  89. }
  90. CListCtrl::OnSetFocus(pOldWnd);
  91. }
  92. void CActionsListControl::OnKillFocus(CWnd* pNewWnd)
  93. {
  94. CListCtrl::OnKillFocus(pNewWnd);
  95. // get selected action
  96. INDEX iSelectedAction = GetNextItem( -1, LVNI_SELECTED);
  97. // set hilighted state
  98. SetItemState( iSelectedAction, LVIS_DROPHILITED, LVIS_DROPHILITED);
  99. }
  100. BOOL CActionsListControl::PreTranslateMessage(MSG* pMsg)
  101. {
  102. // if return pressed
  103. if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
  104. {
  105. ((CDlgPlayerControls *)GetParent())->m_editFirstControl.SetFocus();
  106. // don't translate messages
  107. return TRUE;
  108. }
  109. return CListCtrl::PreTranslateMessage(pMsg);
  110. }
  111. void CActionsListControl::OnContextMenu(CWnd* pWnd, CPoint point)
  112. {
  113. CMenu menu;
  114. if( menu.LoadMenu( IDR_BUTTON_ACTION_POPUP))
  115. {
  116. CMenu* pPopup = menu.GetSubMenu(0);
  117. ASSERT(pPopup != NULL);
  118. pPopup->TrackPopupMenu( TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_LEFTALIGN,
  119. point.x, point.y, this);
  120. }
  121. }
  122. void CActionsListControl::OnButtonActionAdd()
  123. {
  124. CDlgPlayerControls *pDlg = (CDlgPlayerControls *)GetParent();
  125. // create new button action
  126. CButtonAction *pbaAddedButtonAction = &pDlg->m_ctrlControls.AddButtonAction();
  127. // call edit button dialog
  128. CDlgEditButtonAction dlgEditButtonAction( pbaAddedButtonAction);
  129. dlgEditButtonAction.DoModal();
  130. // refresh list of button actions
  131. pDlg->FillActionsList();
  132. }
  133. void CActionsListControl::OnButtonActionEdit()
  134. {
  135. // obtain selected button action
  136. CButtonAction *pbaToEdit = ((CDlgPlayerControls *)GetParent())->GetSelectedButtonAction();
  137. ASSERT( pbaToEdit != NULL);
  138. // call edit button dialog
  139. CDlgEditButtonAction dlgEditButtonAction( pbaToEdit);
  140. dlgEditButtonAction.DoModal();
  141. // refresh list of button actions
  142. ((CDlgPlayerControls *)GetParent())->FillActionsList();
  143. }
  144. void CActionsListControl::OnButtonActionRemove()
  145. {
  146. // obtain selected button action
  147. CButtonAction *pbaToRemove = ((CDlgPlayerControls *)GetParent())->GetSelectedButtonAction();
  148. ASSERT( pbaToRemove != NULL);
  149. ((CDlgPlayerControls *)GetParent())->m_ctrlControls.RemoveButtonAction( *pbaToRemove);
  150. // refresh list of button actions
  151. ((CDlgPlayerControls *)GetParent())->FillActionsList();
  152. }
  153. void CActionsListControl::OnUpdateButtonActionEdit(CCmdUI* pCmdUI)
  154. {
  155. // obtain selected button action
  156. CButtonAction *pbaToEdit = ((CDlgPlayerControls *)GetParent())->GetSelectedButtonAction();
  157. pCmdUI->Enable( pbaToEdit != NULL);
  158. }
  159. void CActionsListControl::OnUpdateButtonActionRemove(CCmdUI* pCmdUI)
  160. {
  161. // obtain selected button action
  162. CButtonAction *pbaToEdit = ((CDlgPlayerControls *)GetParent())->GetSelectedButtonAction();
  163. pCmdUI->Enable( pbaToEdit != NULL);
  164. }