00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "OSDLMouseHandler.h"
00028
00029 #include "OSDLMouse.h"
00030 #include "OSDLController.h"
00031
00032
00033
00034 using std::string ;
00035 using std::list ;
00036
00037
00038 using namespace Ceylan::Log ;
00039 using namespace OSDL::Events ;
00040
00041
00042 #ifdef OSDL_USES_CONFIG_H
00043 #include <OSDLConfig.h>
00044 #endif // OSDL_USES_CONFIG_H
00045
00046 #if OSDL_ARCH_NINTENDO_DS
00047 #include "OSDLConfigForNintendoDS.h"
00048 #endif // OSDL_ARCH_NINTENDO_DS
00049
00050
00051
00052
00053
00054 #if OSDL_VERBOSE_MOUSE_HANDLER
00055
00056 #include <iostream>
00057 #define OSDL_MOUSE_HANDLER_LOG( message ) std::cout << "[OSDL Mouse Handler] " << message << std::endl ;
00058
00059 #else // OSDL_VERBOSE_MOUSE_HANDLER
00060
00061 #define OSDL_MOUSE_HANDLER_LOG( message )
00062
00063 #endif // OSDL_VERBOSE_MOUSE_HANDLER
00064
00065
00066
00067
00068 MouseHandler::MouseHandler( bool useClassicalMice ) :
00069 InputDeviceHandler(),
00070 _miceCount( 0 ),
00071 _mice( 0 ),
00072 _useClassicalMice( useClassicalMice )
00073 {
00074
00075 #if OSDL_USES_SDL
00076
00077 send( "Initializing Mouse subsystem." ) ;
00078
00079
00080
00081 _miceCount = GetAvailableMiceCount() ;
00082
00083 _mice = new Mouse *[ _miceCount ] ;
00084
00085 for ( MouseNumber i = 0; i < _miceCount ; i++ )
00086 _mice[i] = new Mouse( i, _useClassicalMice ) ;
00087
00088 send( "Mouse subsystem initialized." ) ;
00089
00090 dropIdentifier() ;
00091
00092 #else // OSDL_USES_SDL
00093
00094 throw InputDeviceHandlerException( "MouseHandler constructor failed: "
00095 "no SDL support available" ) ;
00096
00097 #endif // OSDL_USES_SDL
00098
00099 }
00100
00101
00102
00103 MouseHandler::~MouseHandler() throw()
00104 {
00105
00106 send( "Stopping Mouse subsystem." ) ;
00107
00108
00109 blank() ;
00110
00111
00112
00113 send( "Mouse subsystem stopped." ) ;
00114
00115 }
00116
00117
00118
00119 bool MouseHandler::hasDefaultMouse() const
00120 {
00121
00122 return ( _miceCount != 0 ) ;
00123
00124 }
00125
00126
00127
00128 Mouse & MouseHandler::getDefaultMouse()
00129 {
00130
00131 if ( _miceCount == 0 )
00132 throw MouseException( "MouseHandler::getDefaultMouse failed: "
00133 "no mouse detected." ) ;
00134
00135 return *_mice[DefaultMouse] ;
00136
00137 }
00138
00139
00140
00141 void MouseHandler::linkToController( OSDL::MVC::Controller & controller )
00142 {
00143
00144 linkToController( DefaultMouse, controller ) ;
00145
00146 }
00147
00148
00149
00150 void MouseHandler::linkToController( MouseNumber mouseIndex,
00151 OSDL::MVC::Controller & controller )
00152 {
00153
00154
00155
00156
00157
00158
00159 if ( mouseIndex >= static_cast<MouseNumber>( GetAvailableMiceCount() ) )
00160 throw MouseException( "MouseHandler::linkToController: index "
00161 + Ceylan::toString( mouseIndex ) + " out of bounds ("
00162 + Ceylan::toString( GetAvailableMiceCount() )
00163 + " mice attached)." ) ;
00164
00165 if ( mouseIndex >= _miceCount )
00166 throw MouseException( "MouseHandler::linkToController: index "
00167 + Ceylan::toString( mouseIndex ) + " out of bounds ("
00168 + Ceylan::toString( _miceCount )
00169 + " mice attached according to internal mouse list)." ) ;
00170
00171 #if OSDL_DEBUG
00172 if ( _mice[ mouseIndex ] == 0 )
00173 throw MouseException( "MouseHandler::linkToController: "
00174 "no known mouse for index "
00175 + Ceylan::toString( mouseIndex ) + "." ) ;
00176 #endif // OSDL_DEBUG
00177
00178 _mice[ mouseIndex ]->setController( controller ) ;
00179
00180 }
00181
00182
00183
00184 const string MouseHandler::toString( Ceylan::VerbosityLevels level ) const
00185 {
00186
00187 string res = "Mouse handler " ;
00188
00189 switch( _miceCount )
00190 {
00191
00192 case 0:
00193 res += "does not manage any mouse" ;
00194 break ;
00195
00196 case 1:
00197 res += "managing one mouse" ;
00198 break ;
00199
00200 default:
00201 res += "managing " + Ceylan::toNumericalString( _miceCount )
00202 + " mice" ;
00203
00204 }
00205
00206 if ( level == Ceylan::low )
00207 return res ;
00208
00209 res += ". Listing detected mice: " ;
00210
00211 list<string> mice ;
00212
00213 for ( MouseNumber i = 0; i < _miceCount; i++ )
00214 if ( _mice[i] != 0 )
00215 mice.push_back( _mice[i]->toString( level ) ) ;
00216 else
00217 mice.push_back( "no mouse at index " + Ceylan::toString( i )
00218 + " (abnormal)" ) ;
00219
00220 return res + Ceylan::formatStringList( mice ) ;
00221
00222 }
00223
00224
00225
00226 MouseNumber MouseHandler::GetAvailableMiceCount()
00227 {
00228
00229
00230
00231
00232
00233 return static_cast<MouseNumber>( 1 ) ;
00234
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 void MouseHandler::focusGained( const FocusEvent & mouseFocusEvent ) const
00246 {
00247
00248 #if OSDL_USES_SDL
00249
00250 #if OSDL_DEBUG
00251 checkMouseAt( DefaultMouse ) ;
00252 #endif // OSDL_DEBUG
00253
00254 _mice[ DefaultMouse ]->focusGained( mouseFocusEvent ) ;
00255
00256 #endif // OSDL_USES_SDL
00257
00258 }
00259
00260
00261
00262 void MouseHandler::focusLost( const FocusEvent & mouseFocusEvent ) const
00263 {
00264
00265 #if OSDL_USES_SDL
00266
00267 #if OSDL_DEBUG
00268 checkMouseAt( DefaultMouse ) ;
00269 #endif // OSDL_DEBUG
00270
00271 _mice[ DefaultMouse ]->focusLost( mouseFocusEvent ) ;
00272
00273 #endif // OSDL_USES_SDL
00274
00275 }
00276
00277
00278
00279 void MouseHandler::mouseMoved( const MouseMotionEvent & mouseMovedEvent ) const
00280 {
00281
00282 #if OSDL_USES_SDL
00283
00284 #if OSDL_DEBUG
00285 checkMouseAt( mouseMovedEvent.which ) ;
00286 #endif // OSDL_DEBUG
00287
00288 _mice[ mouseMovedEvent.which ]->mouseMoved( mouseMovedEvent ) ;
00289
00290 #endif // OSDL_USES_SDL
00291
00292 }
00293
00294
00295
00296 void MouseHandler::buttonPressed(
00297 const MouseButtonEvent & mouseButtonPressedEvent ) const
00298 {
00299
00300 #if OSDL_USES_SDL
00301
00302 #if OSDL_DEBUG
00303 checkMouseAt( mouseButtonPressedEvent.which ) ;
00304 #endif // OSDL_DEBUG
00305
00306 _mice[ mouseButtonPressedEvent.which ]->buttonPressed(
00307 mouseButtonPressedEvent ) ;
00308
00309 #endif // OSDL_USES_SDL
00310
00311 }
00312
00313
00314 void MouseHandler::buttonReleased(
00315 const MouseButtonEvent & mouseButtonReleasedEvent ) const
00316 {
00317
00318 #if OSDL_USES_SDL
00319
00320 #if OSDL_DEBUG
00321 checkMouseAt( mouseButtonReleasedEvent.which ) ;
00322 #endif // OSDL_DEBUG
00323
00324 _mice[ mouseButtonReleasedEvent.which ]->buttonReleased(
00325 mouseButtonReleasedEvent ) ;
00326
00327 #endif // OSDL_USES_SDL
00328
00329 }
00330
00331
00332
00333 void MouseHandler::blank()
00334 {
00335
00336 if ( _mice != 0 )
00337 {
00338
00339 for ( MouseNumber c = 0; c < _miceCount; c++ )
00340 {
00341 delete _mice[c] ;
00342 }
00343
00344 delete [] _mice ;
00345 _mice = 0 ;
00346 }
00347
00348 _miceCount = 0 ;
00349
00350 }
00351
00352
00353
00354 void MouseHandler::checkMouseAt( MouseNumber index ) const
00355 {
00356
00357 if ( index >= _miceCount )
00358 Ceylan::emergencyShutdown(
00359 "MouseHandler::checkMouseAt: index "
00360 + Ceylan::toNumericalString( index )
00361 + " out of bounds (maximum value is "
00362 + Ceylan::toNumericalString( _miceCount - 1 ) + ")." ) ;
00363
00364 if ( _mice[ index ] == 0 )
00365 Ceylan::emergencyShutdown( "MouseHandler::checkMouseAt: "
00366 "no mouse intance at index "
00367 + Ceylan::toNumericalString( index ) + "." ) ;
00368
00369 }
00370