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