Messaging.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. //-----------------------------------------------------------------------------
  19. //
  20. // $LogFile$
  21. // $Revision: 1.1.2.1 $
  22. // $Author: ttimo $
  23. // $Date: 2000/02/04 22:59:34 $
  24. // $Log: Messaging.cpp,v $
  25. // Revision 1.1.2.1 2000/02/04 22:59:34 ttimo
  26. // messaging API preview
  27. //
  28. //
  29. // DESCRIPTION:
  30. // implementation of IMessaging specific interface
  31. //
  32. #include "stdafx.h"
  33. CPtrArray l_Listeners[RADIANT_MSGCOUNT];
  34. CPtrArray l_WindowListeners;
  35. CXYWndWrapper l_XYWndWrapper;
  36. void WINAPI QERApp_HookWindow(IWindowListener* pListen)
  37. {
  38. l_WindowListeners.Add( pListen );
  39. pListen->IncRef();
  40. }
  41. void WINAPI QERApp_UnHookWindow(IWindowListener* pListen)
  42. {
  43. for ( int i = 0; i < l_WindowListeners.GetSize(); i++ )
  44. {
  45. if (l_WindowListeners.GetAt(i) == pListen)
  46. {
  47. l_WindowListeners.RemoveAt(i);
  48. pListen->DecRef();
  49. return;
  50. }
  51. }
  52. #ifdef _DEBUG
  53. Sys_Printf("WARNING: IWindowListener not found in QERApp_UnHookWindow\n");
  54. #endif
  55. }
  56. void DispatchOnMouseMove(UINT nFlags, int x, int y)
  57. {
  58. for( int i = 0; i < l_WindowListeners.GetSize(); i++ )
  59. static_cast<IWindowListener*>(l_WindowListeners.GetAt(i))->OnMouseMove( nFlags, x, y );
  60. }
  61. bool DispatchOnLButtonDown(UINT nFlags, int x, int y)
  62. {
  63. for( int i = 0; i < l_WindowListeners.GetSize(); i++ )
  64. if (static_cast<IWindowListener*>(l_WindowListeners.GetAt(i))->OnLButtonDown( nFlags, x, y ))
  65. return true;
  66. return false;
  67. }
  68. bool DispatchOnLButtonUp(UINT nFlags, int x, int y)
  69. {
  70. for( int i = 0; i < l_WindowListeners.GetSize(); i++ )
  71. if (static_cast<IWindowListener*>(l_WindowListeners.GetAt(i))->OnLButtonUp( nFlags, x, y ))
  72. return true;
  73. return false;
  74. }
  75. void WINAPI QERApp_HookListener(IListener* pListen, int Msg)
  76. {
  77. #ifdef _DEBUG
  78. if (Msg >= RADIANT_MSGCOUNT)
  79. {
  80. Sys_Printf("ERROR: bad index in QERApp_HookListener\n");
  81. return;
  82. }
  83. #endif
  84. l_Listeners[Msg].Add( pListen );
  85. pListen->IncRef();
  86. }
  87. int WINAPI QERApp_UnHookListener(IListener* pListen)
  88. {
  89. int count = 0;
  90. for( int i = 0; i<RADIANT_MSGCOUNT; i++ )
  91. for( int j = 0; j<l_Listeners[i].GetSize(); j++ )
  92. if (l_Listeners[i].GetAt(j) == pListen)
  93. {
  94. l_Listeners[i].RemoveAt(j);
  95. pListen->DecRef();
  96. count++;
  97. }
  98. return count;
  99. }
  100. void DispatchRadiantMsg( int Msg )
  101. {
  102. #ifdef _DEBUG
  103. if (Msg >= RADIANT_MSGCOUNT)
  104. {
  105. Sys_Printf("ERROR: bad index in DispatchRadiantMsg\n");
  106. return;
  107. }
  108. #endif
  109. for(int i = 0; i<l_Listeners[Msg].GetSize(); i++)
  110. static_cast<IListener *>(l_Listeners[Msg].GetAt(i))->DispatchRadiantMsg(Msg);
  111. }
  112. void CXYWndWrapper::SnapToGrid( int x1, int y1, vec3_t pt )
  113. {
  114. CRect rctZ;
  115. g_pParentWnd->ActiveXY()->GetClientRect( rctZ );
  116. g_pParentWnd->ActiveXY()->SnapToPoint( x1, rctZ.Height() - 1 - y1, pt );
  117. }
  118. IXYWndWrapper* WINAPI QERApp_GetXYWndWrapper()
  119. {
  120. return &l_XYWndWrapper;
  121. }