ConsoleSymbolsCombo.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. // ConsoleSymbolsCombo.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. // CConsoleSymbolsCombo
  23. CConsoleSymbolsCombo::CConsoleSymbolsCombo()
  24. {
  25. }
  26. CConsoleSymbolsCombo::~CConsoleSymbolsCombo()
  27. {
  28. }
  29. BEGIN_MESSAGE_MAP(CConsoleSymbolsCombo, CComboBox)
  30. //{{AFX_MSG_MAP(CConsoleSymbolsCombo)
  31. ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange)
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CConsoleSymbolsCombo message handlers
  36. BOOL CConsoleSymbolsCombo::PreTranslateMessage(MSG* pMsg)
  37. {
  38. if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
  39. {
  40. INDEX iSelectedSymbol = GetCurSel();
  41. // if there is a valid player selected
  42. if( iSelectedSymbol != LB_ERR)
  43. {
  44. CString strSelectedSymbolW;
  45. GetLBText( iSelectedSymbol, strSelectedSymbolW);
  46. CTString strSelectedSymbol = CStringA(strSelectedSymbolW);
  47. INDEX ctLetters = strlen(strSelectedSymbol);
  48. char achrSelectedSymbol[ 256];
  49. sprintf( achrSelectedSymbol, strSelectedSymbol);
  50. if( achrSelectedSymbol[ ctLetters-1] == ']')
  51. {
  52. for( INDEX iLetter=ctLetters-2; iLetter>0; iLetter--)
  53. {
  54. ASSERT( iLetter>0);
  55. if( ((char *)achrSelectedSymbol)[ iLetter] == '[')
  56. {
  57. achrSelectedSymbol[ iLetter+1] = ']';
  58. achrSelectedSymbol[ iLetter+2] = 0;
  59. strSelectedSymbol = achrSelectedSymbol;
  60. break;
  61. }
  62. }
  63. }
  64. ((CDlgConsole *)GetParent())->m_ctrlEditConsole.ReplaceSel( CString(strSelectedSymbol), TRUE);
  65. ((CDlgConsole *)GetParent())->m_ctrlEditConsole.SetFocus();
  66. return TRUE;
  67. }
  68. }
  69. return CComboBox::PreTranslateMessage(pMsg);
  70. }
  71. void CConsoleSymbolsCombo::OnSelchange()
  72. {
  73. ShowDropDown( TRUE);
  74. }