autotools: Android port
[freeglut] / src / Common / freeglut_callbacks.c
index d536326..a40f7da 100644 (file)
-/*\r
- * freeglut_callbacks.c\r
- *\r
- * The callbacks setting methods.\r
- *\r
- * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.\r
- * Written by Pawel W. Olszta, <olszta@sourceforge.net>\r
- * Creation date: Fri Dec 3 1999\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the "Software"),\r
- * to deal in the Software without restriction, including without limitation\r
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
- * and/or sell copies of the Software, and to permit persons to whom the\r
- * Software is furnished to do so, subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included\r
- * in all copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
- * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-#include <GL/freeglut.h>\r
-#include "freeglut_internal.h"\r
-\r
-/* -- INTERFACE FUNCTIONS -------------------------------------------------- */\r
-\r
-/*\r
- * All of the callbacks setting methods can be generalized to this:\r
- */\r
-#define SET_CALLBACK(a)                                         \\r
-do                                                              \\r
-{                                                               \\r
-    if( fgStructure.CurrentWindow == NULL )                     \\r
-        return;                                                 \\r
-    SET_WCB( ( *( fgStructure.CurrentWindow ) ), a, callback ); \\r
-} while( 0 )\r
-\r
-/*\r
- * Sets the Display callback for the current window\r
- */\r
-void FGAPIENTRY glutDisplayFunc( void (* callback)( void ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDisplayFunc" );\r
-    if( !callback )\r
-        fgError( "Fatal error in program.  NULL display callback not "\r
-                 "permitted in GLUT 3.0+ or freeglut 2.0.1+" );\r
-    SET_CALLBACK( Display );\r
-}\r
-\r
-/*\r
- * Sets the Reshape callback for the current window\r
- */\r
-void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeFunc" );\r
-    SET_CALLBACK( Reshape );\r
-}\r
-\r
-/*\r
- * Sets the Keyboard callback for the current window\r
- */\r
-void FGAPIENTRY glutKeyboardFunc( void (* callback)\r
-                                  ( unsigned char, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutKeyboardFunc" );\r
-    SET_CALLBACK( Keyboard );\r
-}\r
-\r
-/*\r
- * Sets the Special callback for the current window\r
- */\r
-void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpecialFunc" );\r
-    SET_CALLBACK( Special );\r
-}\r
-\r
-/*\r
- * Sets the global idle callback\r
- */\r
-void FGAPIENTRY glutIdleFunc( void (* callback)( void ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIdleFunc" );\r
-    fgState.IdleCallback = callback;\r
-}\r
-\r
-/*\r
- * Sets the Timer callback for the current window\r
- */\r
-void FGAPIENTRY glutTimerFunc( unsigned int timeOut, void (* callback)( int ),\r
-                               int timerID )\r
-{\r
-    SFG_Timer *timer, *node;\r
-\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTimerFunc" );\r
-\r
-    if( (timer = fgState.FreeTimers.Last) )\r
-    {\r
-        fgListRemove( &fgState.FreeTimers, &timer->Node );\r
-    }\r
-    else\r
-    {\r
-        if( ! (timer = malloc(sizeof(SFG_Timer))) )\r
-            fgError( "Fatal error: "\r
-                     "Memory allocation failure in glutTimerFunc()" );\r
-    }\r
-\r
-    timer->Callback  = callback;\r
-    timer->ID        = timerID;\r
-    timer->TriggerTime = fgElapsedTime() + timeOut;\r
-\r
-    for( node = fgState.Timers.First; node; node = node->Node.Next )\r
-    {\r
-        if( node->TriggerTime > timer->TriggerTime )\r
-            break;\r
-    }\r
-\r
-    fgListInsert( &fgState.Timers, &node->Node, &timer->Node );\r
-}\r
-\r
-/*\r
- * Sets the Visibility callback for the current window.\r
- */\r
-static void fghVisibility( int status )\r
-{\r
-    int glut_status = GLUT_VISIBLE;\r
-\r
-    FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Visibility Callback" );\r
-    freeglut_return_if_fail( fgStructure.CurrentWindow );\r
-\r
-    if( ( GLUT_HIDDEN == status )  || ( GLUT_FULLY_COVERED == status ) )\r
-        glut_status = GLUT_NOT_VISIBLE;\r
-    INVOKE_WCB( *( fgStructure.CurrentWindow ), Visibility, ( glut_status ) );\r
-}\r
-\r
-void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutVisibilityFunc" );\r
-    SET_CALLBACK( Visibility );\r
-\r
-    if( callback )\r
-        glutWindowStatusFunc( fghVisibility );\r
-    else\r
-        glutWindowStatusFunc( NULL );\r
-}\r
-\r
-/*\r
- * Sets the keyboard key release callback for the current window\r
- */\r
-void FGAPIENTRY glutKeyboardUpFunc( void (* callback)\r
-                                    ( unsigned char, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutKeyboardUpFunc" );\r
-    SET_CALLBACK( KeyboardUp );\r
-}\r
-\r
-/*\r
- * Sets the special key release callback for the current window\r
- */\r
-void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpecialUpFunc" );\r
-    SET_CALLBACK( SpecialUp );\r
-}\r
-\r
-/*\r
- * Sets the joystick callback and polling rate for the current window\r
- */\r
-void FGAPIENTRY glutJoystickFunc( void (* callback)\r
-                                  ( unsigned int, int, int, int ),\r
-                                  int pollInterval )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutJoystickFunc" );\r
-    fgInitialiseJoysticks ();\r
-\r
-    if ( ( ( fgStructure.CurrentWindow->State.JoystickPollRate < 0 ) ||\r
-           !FETCH_WCB(*fgStructure.CurrentWindow,Joystick) ) &&  /* Joystick callback was disabled */\r
-         ( callback && ( pollInterval >= 0 ) ) )               /* but is now enabled */\r
-        ++fgState.NumActiveJoysticks;\r
-    else if ( ( ( fgStructure.CurrentWindow->State.JoystickPollRate >= 0 ) &&\r
-                FETCH_WCB(*fgStructure.CurrentWindow,Joystick) ) &&  /* Joystick callback was enabled */\r
-              ( !callback || ( pollInterval < 0 ) ) )              /* but is now disabled */\r
-        --fgState.NumActiveJoysticks;\r
-\r
-    SET_CALLBACK( Joystick );\r
-    fgStructure.CurrentWindow->State.JoystickPollRate = pollInterval;\r
-\r
-    fgStructure.CurrentWindow->State.JoystickLastPoll =\r
-        fgElapsedTime() - fgStructure.CurrentWindow->State.JoystickPollRate;\r
-\r
-    if( fgStructure.CurrentWindow->State.JoystickLastPoll < 0 )\r
-        fgStructure.CurrentWindow->State.JoystickLastPoll = 0;\r
-}\r
-\r
-/*\r
- * Sets the mouse callback for the current window\r
- */\r
-void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseFunc" );\r
-    SET_CALLBACK( Mouse );\r
-}\r
-\r
-/*\r
- * Sets the mouse wheel callback for the current window\r
- */\r
-void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseWheelFunc" );\r
-    SET_CALLBACK( MouseWheel );\r
-}\r
-\r
-/*\r
- * Sets the mouse motion callback for the current window (one or more buttons\r
- * are pressed)\r
- */\r
-void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMotionFunc" );\r
-    SET_CALLBACK( Motion );\r
-}\r
-\r
-/*\r
- * Sets the passive mouse motion callback for the current window (no mouse\r
- * buttons are pressed)\r
- */\r
-void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPassiveMotionFunc" );\r
-    SET_CALLBACK( Passive );\r
-}\r
-\r
-/*\r
- * Window mouse entry/leave callback\r
- */\r
-void FGAPIENTRY glutEntryFunc( void (* callback)( int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEntryFunc" );\r
-    SET_CALLBACK( Entry );\r
-}\r
-\r
-/*\r
- * Window destruction callbacks\r
- */\r
-void FGAPIENTRY glutCloseFunc( void (* callback)( void ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCloseFunc" );\r
-    SET_CALLBACK( Destroy );\r
-}\r
-\r
-void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWMCloseFunc" );\r
-    glutCloseFunc( callback );\r
-}\r
-\r
-/* A. Donev: Destruction callback for menus */\r
-void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuDestroyFunc" );\r
-    if( fgStructure.CurrentMenu )\r
-        fgStructure.CurrentMenu->Destroy = callback;\r
-}\r
-\r
-/*\r
- * Deprecated version of glutMenuStatusFunc callback setting method\r
- */\r
-void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStateFunc" );\r
-    fgState.MenuStateCallback = callback;\r
-}\r
-\r
-/*\r
- * Sets the global menu status callback for the current window\r
- */\r
-void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStatusFunc" );\r
-    fgState.MenuStatusCallback = callback;\r
-}\r
-\r
-/*\r
- * Sets the overlay display callback for the current window\r
- */\r
-void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutOverlayDisplayFunc" );\r
-    SET_CALLBACK( OverlayDisplay );\r
-}\r
-\r
-/*\r
- * Sets the window status callback for the current window\r
- */\r
-void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWindowStatusFunc" );\r
-    SET_CALLBACK( WindowStatus );\r
-}\r
-\r
-/*\r
- * Sets the spaceball motion callback for the current window\r
- */\r
-void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballMotionFunc" );\r
-    fgInitialiseSpaceball();\r
-\r
-    SET_CALLBACK( SpaceMotion );\r
-}\r
-\r
-/*\r
- * Sets the spaceball rotate callback for the current window\r
- */\r
-void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballRotateFunc" );\r
-    fgInitialiseSpaceball();\r
-\r
-    SET_CALLBACK( SpaceRotation );\r
-}\r
-\r
-/*\r
- * Sets the spaceball button callback for the current window\r
- */\r
-void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballButtonFunc" );\r
-    fgInitialiseSpaceball();\r
-\r
-    SET_CALLBACK( SpaceButton );\r
-}\r
-\r
-/*\r
- * Sets the button box callback for the current window\r
- */\r
-void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutButtonBoxFunc" );\r
-    SET_CALLBACK( ButtonBox );\r
-}\r
-\r
-/*\r
- * Sets the dials box callback for the current window\r
- */\r
-void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDialsFunc" );\r
-    SET_CALLBACK( Dials );\r
-}\r
-\r
-/*\r
- * Sets the tablet motion callback for the current window\r
- */\r
-void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletMotionFunc" );\r
-    SET_CALLBACK( TabletMotion );\r
-}\r
-\r
-/*\r
- * Sets the tablet buttons callback for the current window\r
- */\r
-void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletButtonFunc" );\r
-    SET_CALLBACK( TabletButton );\r
-}\r
-\r
-/*\r
- * Sets the multi-pointer entry callback for the current window\r
- */\r
-void FGAPIENTRY glutMultiEntryFunc( void (* callback)(int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiEntryFunc" );\r
-    SET_CALLBACK( MultiEntry );\r
-}\r
-\r
-/*\r
- * Sets the multi-pointer button callback for the current window\r
- */\r
-void FGAPIENTRY glutMultiButtonFunc( void (* callback)(int, int, int, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiButtonFunc" );\r
-    SET_CALLBACK( MultiButton );\r
-}\r
-\r
-/*\r
- * Sets the multi-pointer motion callback for the current window\r
- */\r
-void FGAPIENTRY glutMultiMotionFunc( void (* callback)(int, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiMotionFunc" );\r
-    SET_CALLBACK( MultiMotion );\r
-}\r
-\r
-/*\r
- * Sets the multi-pointer passive motion callback for the current window\r
- */\r
-void FGAPIENTRY glutMultiPassiveFunc( void (* callback)(int, int, int ) )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiPassiveFunc" );\r
-    SET_CALLBACK( MultiPassive );\r
-}\r
-\r
-/*** END OF FILE ***/\r
+/*
+ * freeglut_callbacks.c
+ *
+ * The callbacks setting methods.
+ *
+ * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
+ * Written by Pawel W. Olszta, <olszta@sourceforge.net>
+ * Creation date: Fri Dec 3 1999
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <GL/freeglut.h>
+#include "freeglut_internal.h"
+
+/* -- INTERFACE FUNCTIONS -------------------------------------------------- */
+
+/*
+ * All of the callbacks setting methods can be generalized to this:
+ */
+#define SET_CALLBACK(a)                                         \
+do                                                              \
+{                                                               \
+    if( fgStructure.CurrentWindow == NULL )                     \
+        return;                                                 \
+    SET_WCB( ( *( fgStructure.CurrentWindow ) ), a, callback ); \
+} while( 0 )
+
+/*
+ * Sets the Display callback for the current window
+ */
+void FGAPIENTRY glutDisplayFunc( void (* callback)( void ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDisplayFunc" );
+    if( !callback )
+        fgError( "Fatal error in program.  NULL display callback not "
+                 "permitted in GLUT 3.0+ or freeglut 2.0.1+" );
+    SET_CALLBACK( Display );
+}
+
+/*
+ * Sets the Reshape callback for the current window
+ */
+void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeFunc" );
+    SET_CALLBACK( Reshape );
+}
+
+/*
+ * Sets the Keyboard callback for the current window
+ */
+void FGAPIENTRY glutKeyboardFunc( void (* callback)
+                                  ( unsigned char, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutKeyboardFunc" );
+    SET_CALLBACK( Keyboard );
+}
+
+/*
+ * Sets the Special callback for the current window
+ */
+void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpecialFunc" );
+    SET_CALLBACK( Special );
+}
+
+/*
+ * Sets the global idle callback
+ */
+void FGAPIENTRY glutIdleFunc( void (* callback)( void ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIdleFunc" );
+    fgState.IdleCallback = callback;
+}
+
+/*
+ * Sets the Timer callback for the current window
+ */
+void FGAPIENTRY glutTimerFunc( unsigned int timeOut, void (* callback)( int ),
+                               int timerID )
+{
+    SFG_Timer *timer, *node;
+
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTimerFunc" );
+
+    if( (timer = fgState.FreeTimers.Last) )
+    {
+        fgListRemove( &fgState.FreeTimers, &timer->Node );
+    }
+    else
+    {
+        if( ! (timer = malloc(sizeof(SFG_Timer))) )
+            fgError( "Fatal error: "
+                     "Memory allocation failure in glutTimerFunc()" );
+    }
+
+    timer->Callback  = callback;
+    timer->ID        = timerID;
+    timer->TriggerTime = fgElapsedTime() + timeOut;
+
+    for( node = fgState.Timers.First; node; node = node->Node.Next )
+    {
+        if( node->TriggerTime > timer->TriggerTime )
+            break;
+    }
+
+    fgListInsert( &fgState.Timers, &node->Node, &timer->Node );
+}
+
+/*
+ * Sets the Visibility callback for the current window.
+ */
+static void fghVisibility( int status )
+{
+    int glut_status = GLUT_VISIBLE;
+
+    FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Visibility Callback" );
+    freeglut_return_if_fail( fgStructure.CurrentWindow );
+
+    if( ( GLUT_HIDDEN == status )  || ( GLUT_FULLY_COVERED == status ) )
+        glut_status = GLUT_NOT_VISIBLE;
+    INVOKE_WCB( *( fgStructure.CurrentWindow ), Visibility, ( glut_status ) );
+}
+
+void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutVisibilityFunc" );
+    SET_CALLBACK( Visibility );
+
+    if( callback )
+        glutWindowStatusFunc( fghVisibility );
+    else
+        glutWindowStatusFunc( NULL );
+}
+
+/*
+ * Sets the keyboard key release callback for the current window
+ */
+void FGAPIENTRY glutKeyboardUpFunc( void (* callback)
+                                    ( unsigned char, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutKeyboardUpFunc" );
+    SET_CALLBACK( KeyboardUp );
+}
+
+/*
+ * Sets the special key release callback for the current window
+ */
+void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpecialUpFunc" );
+    SET_CALLBACK( SpecialUp );
+}
+
+/*
+ * Sets the joystick callback and polling rate for the current window
+ */
+void FGAPIENTRY glutJoystickFunc( void (* callback)
+                                  ( unsigned int, int, int, int ),
+                                  int pollInterval )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutJoystickFunc" );
+    fgInitialiseJoysticks ();
+
+    if ( ( ( fgStructure.CurrentWindow->State.JoystickPollRate < 0 ) ||
+           !FETCH_WCB(*fgStructure.CurrentWindow,Joystick) ) &&  /* Joystick callback was disabled */
+         ( callback && ( pollInterval >= 0 ) ) )               /* but is now enabled */
+        ++fgState.NumActiveJoysticks;
+    else if ( ( ( fgStructure.CurrentWindow->State.JoystickPollRate >= 0 ) &&
+                FETCH_WCB(*fgStructure.CurrentWindow,Joystick) ) &&  /* Joystick callback was enabled */
+              ( !callback || ( pollInterval < 0 ) ) )              /* but is now disabled */
+        --fgState.NumActiveJoysticks;
+
+    SET_CALLBACK( Joystick );
+    fgStructure.CurrentWindow->State.JoystickPollRate = pollInterval;
+
+    fgStructure.CurrentWindow->State.JoystickLastPoll =
+        fgElapsedTime() - fgStructure.CurrentWindow->State.JoystickPollRate;
+
+    if( fgStructure.CurrentWindow->State.JoystickLastPoll < 0 )
+        fgStructure.CurrentWindow->State.JoystickLastPoll = 0;
+}
+
+/*
+ * Sets the mouse callback for the current window
+ */
+void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseFunc" );
+    SET_CALLBACK( Mouse );
+}
+
+/*
+ * Sets the mouse wheel callback for the current window
+ */
+void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMouseWheelFunc" );
+    SET_CALLBACK( MouseWheel );
+}
+
+/*
+ * Sets the mouse motion callback for the current window (one or more buttons
+ * are pressed)
+ */
+void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMotionFunc" );
+    SET_CALLBACK( Motion );
+}
+
+/*
+ * Sets the passive mouse motion callback for the current window (no mouse
+ * buttons are pressed)
+ */
+void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPassiveMotionFunc" );
+    SET_CALLBACK( Passive );
+}
+
+/*
+ * Window mouse entry/leave callback
+ */
+void FGAPIENTRY glutEntryFunc( void (* callback)( int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEntryFunc" );
+    SET_CALLBACK( Entry );
+}
+
+/*
+ * Window destruction callbacks
+ */
+void FGAPIENTRY glutCloseFunc( void (* callback)( void ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCloseFunc" );
+    SET_CALLBACK( Destroy );
+}
+
+void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWMCloseFunc" );
+    glutCloseFunc( callback );
+}
+
+/* A. Donev: Destruction callback for menus */
+void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuDestroyFunc" );
+    if( fgStructure.CurrentMenu )
+        fgStructure.CurrentMenu->Destroy = callback;
+}
+
+/*
+ * Deprecated version of glutMenuStatusFunc callback setting method
+ */
+void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStateFunc" );
+    fgState.MenuStateCallback = callback;
+}
+
+/*
+ * Sets the global menu status callback for the current window
+ */
+void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMenuStatusFunc" );
+    fgState.MenuStatusCallback = callback;
+}
+
+/*
+ * Sets the overlay display callback for the current window
+ */
+void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutOverlayDisplayFunc" );
+    SET_CALLBACK( OverlayDisplay );
+}
+
+/*
+ * Sets the window status callback for the current window
+ */
+void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWindowStatusFunc" );
+    SET_CALLBACK( WindowStatus );
+}
+
+/*
+ * Sets the spaceball motion callback for the current window
+ */
+void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballMotionFunc" );
+    fgInitialiseSpaceball();
+
+    SET_CALLBACK( SpaceMotion );
+}
+
+/*
+ * Sets the spaceball rotate callback for the current window
+ */
+void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballRotateFunc" );
+    fgInitialiseSpaceball();
+
+    SET_CALLBACK( SpaceRotation );
+}
+
+/*
+ * Sets the spaceball button callback for the current window
+ */
+void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSpaceballButtonFunc" );
+    fgInitialiseSpaceball();
+
+    SET_CALLBACK( SpaceButton );
+}
+
+/*
+ * Sets the button box callback for the current window
+ */
+void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutButtonBoxFunc" );
+    SET_CALLBACK( ButtonBox );
+}
+
+/*
+ * Sets the dials box callback for the current window
+ */
+void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDialsFunc" );
+    SET_CALLBACK( Dials );
+}
+
+/*
+ * Sets the tablet motion callback for the current window
+ */
+void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletMotionFunc" );
+    SET_CALLBACK( TabletMotion );
+}
+
+/*
+ * Sets the tablet buttons callback for the current window
+ */
+void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTabletButtonFunc" );
+    SET_CALLBACK( TabletButton );
+}
+
+/*
+ * Sets the multi-pointer entry callback for the current window
+ */
+void FGAPIENTRY glutMultiEntryFunc( void (* callback)(int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiEntryFunc" );
+    SET_CALLBACK( MultiEntry );
+}
+
+/*
+ * Sets the multi-pointer button callback for the current window
+ */
+void FGAPIENTRY glutMultiButtonFunc( void (* callback)(int, int, int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiButtonFunc" );
+    SET_CALLBACK( MultiButton );
+}
+
+/*
+ * Sets the multi-pointer motion callback for the current window
+ */
+void FGAPIENTRY glutMultiMotionFunc( void (* callback)(int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiMotionFunc" );
+    SET_CALLBACK( MultiMotion );
+}
+
+/*
+ * Sets the multi-pointer passive motion callback for the current window
+ */
+void FGAPIENTRY glutMultiPassiveFunc( void (* callback)(int, int, int ) )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMultiPassiveFunc" );
+    SET_CALLBACK( MultiPassive );
+}
+
+/*** END OF FILE ***/