+#define SET_WCB(window,cbname,func) \
+do \
+{ \
+ if( FETCH_WCB( window, cbname ) != (SFG_Proc)(func) ) \
+ (((window).CallBacks[CB_ ## cbname]) = (SFG_Proc)(func)); \
+} while( 0 )
+
+/*
+ * FETCH_WCB() is used as:
+ *
+ * FETCH_WCB( window, cbname );
+ *
+ * ...where {window} is the freeglut window to fetch the callback from,
+ * {cbname} is the window-specific callback to fetch.
+ *
+ * The result is correctly type-cast to the callback function pointer
+ * type.
+ */
+#define FETCH_WCB(window,cbname) \
+ ((window).CallBacks[CB_ ## cbname])
+
+/*
+ * INVOKE_WCB() is used as:
+ *
+ * INVOKE_WCB( window, cbname, ( arg_list ) );
+ *
+ * ...where {window} is the freeglut window,
+ * {cbname} is the window-specific callback to be invoked,
+ * {(arg_list)} is the parameter list.
+ *
+ * The callback is invoked as:
+ *
+ * callback( arg_list );
+ *
+ * ...so the parentheses are REQUIRED in the {arg_list}.
+ *
+ * NOTE that it does a sanity-check and also sets the
+ * current window.
+ *
+ */
+#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: also WinCE? */
+#define INVOKE_WCB(window,cbname,arg_list) \
+do \
+{ \
+ if( FETCH_WCB( window, cbname ) ) \
+ { \
+ FGCB ## cbname func = (FGCB ## cbname)(FETCH_WCB( window, cbname )); \
+ fgSetWindow( &window ); \
+ func arg_list; \
+ } \
+} while( 0 )
+#else
+#define INVOKE_WCB(window,cbname,arg_list) \
+do \
+{ \
+ if( FETCH_WCB( window, cbname ) ) \
+ { \
+ fgSetWindow( &window ); \
+ ((FGCB ## cbname)FETCH_WCB( window, cbname )) arg_list; \
+ } \
+} while( 0 )
+#endif
+
+/*
+ * The window callbacks the user can supply us with. Should be kept portable.
+ *
+ * This enumeration provides the freeglut CallBack numbers.
+ * The symbolic constants are indices into a window's array of
+ * function callbacks. The names are formed by splicing a common
+ * prefix onto the callback's base name. (This was originally
+ * done so that an early stage of development could live side-by-
+ * side with the old callback code. The old callback code used
+ * the bare callback's name as a structure member, so I used a
+ * prefix for the array index name.)
+ *
+ * XXX For consistancy, perhaps the prefix should match the
+ * XXX FETCH* and INVOKE* macro suffices. I.e., WCB_, rather than
+ * XXX CB_.
+ */
+enum
+{
+ CB_Display,
+ CB_Reshape,
+ CB_Keyboard,
+ CB_KeyboardUp,
+ CB_Special,
+ CB_SpecialUp,
+ CB_Mouse,
+ CB_MouseWheel,
+ CB_Motion,
+ CB_Passive,
+ CB_Entry,
+ CB_Visibility,
+ CB_WindowStatus,
+ CB_Joystick,
+ CB_Destroy,
+
+ /* Presently ignored */
+ CB_Select,
+ CB_OverlayDisplay,
+ CB_SpaceMotion,
+ CB_SpaceRotation,
+ CB_SpaceButton,
+ CB_Dials,
+ CB_ButtonBox,
+ CB_TabletMotion,
+ CB_TabletButton,
+
+ /* Always make this the LAST one */
+ TOTAL_CALLBACKS
+};
+
+
+/* This structure holds the OpenGL rendering context for all the menu windows */