Moving the platform-specific window handle and context type definitions into platform...
[freeglut] / src / Common / freeglut_internal.h
1 /*\r
2  * freeglut_internal.h\r
3  *\r
4  * The freeglut library private include file.\r
5  *\r
6  * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.\r
7  * Written by Pawel W. Olszta, <olszta@sourceforge.net>\r
8  * Creation date: Thu Dec 2 1999\r
9  *\r
10  * Permission is hereby granted, free of charge, to any person obtaining a\r
11  * copy of this software and associated documentation files (the "Software"),\r
12  * to deal in the Software without restriction, including without limitation\r
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
14  * and/or sell copies of the Software, and to permit persons to whom the\r
15  * Software is furnished to do so, subject to the following conditions:\r
16  *\r
17  * The above copyright notice and this permission notice shall be included\r
18  * in all copies or substantial portions of the Software.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
23  * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
24  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
26  */\r
27 \r
28 #ifndef  FREEGLUT_INTERNAL_H\r
29 #define  FREEGLUT_INTERNAL_H\r
30 \r
31 #ifdef HAVE_CONFIG_H\r
32 #    include "config.h"\r
33 #endif\r
34 \r
35 /* XXX Update these for each release! */\r
36 #define  VERSION_MAJOR 2\r
37 #define  VERSION_MINOR 7\r
38 #define  VERSION_PATCH 0\r
39 \r
40 /* Freeglut is intended to function under all Unix/X11 and Win32 platforms. */\r
41 /* XXX: Don't all MS-Windows compilers (except Cygwin) have _WIN32 defined?\r
42  * XXX: If so, remove the first set of defined()'s below.\r
43  */\r
44 #if !defined(TARGET_HOST_POSIX_X11) && !defined(TARGET_HOST_MS_WINDOWS) && !defined(TARGET_HOST_MAC_OSX) && !defined(TARGET_HOST_SOLARIS)\r
45 #if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW32__) \\r
46     || defined(_WIN32) || defined(_WIN32_WCE) \\r
47     || ( defined(__CYGWIN__) && defined(X_DISPLAY_MISSING) )\r
48 #   define  TARGET_HOST_MS_WINDOWS 1\r
49 \r
50 #elif defined(__posix__) || defined(__unix__) || defined(__linux__) || defined(__sun)\r
51 #   define  TARGET_HOST_POSIX_X11  1\r
52 \r
53 #elif defined(__APPLE__)\r
54 /* This is a placeholder until we get native OSX support ironed out -- JFF 11/18/09 */\r
55 #   define  TARGET_HOST_POSIX_X11  1\r
56 /* #   define  TARGET_HOST_MAC_OSX    1 */\r
57 \r
58 #else\r
59 #   error "Unrecognized target host!"\r
60 \r
61 #endif\r
62 #endif\r
63 \r
64 /* Detect both SunPro and gcc compilers on Sun Solaris */\r
65 #if defined (__SVR4) && defined (__sun)\r
66 #   define TARGET_HOST_SOLARIS 1\r
67 #endif\r
68 \r
69 #ifndef TARGET_HOST_MS_WINDOWS\r
70 #   define  TARGET_HOST_MS_WINDOWS 0\r
71 #endif\r
72 \r
73 #ifndef  TARGET_HOST_POSIX_X11\r
74 #   define  TARGET_HOST_POSIX_X11  0\r
75 #endif\r
76 \r
77 #ifndef  TARGET_HOST_MAC_OSX\r
78 #   define  TARGET_HOST_MAC_OSX    0\r
79 #endif\r
80 \r
81 #ifndef  TARGET_HOST_SOLARIS\r
82 #   define  TARGET_HOST_SOLARIS    0\r
83 #endif\r
84 \r
85 /* -- FIXED CONFIGURATION LIMITS ------------------------------------------- */\r
86 \r
87 #define  FREEGLUT_MAX_MENUS         3\r
88 \r
89 /* -- PLATFORM-SPECIFIC INCLUDES ------------------------------------------- */\r
90 \r
91 /* All Win32 headers depend on the huge windows.h recursive include.\r
92  * Note: Lower-case header names are used, for best cross-platform\r
93  * compatibility.\r
94  */\r
95 #if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
96 #    include <windows.h>\r
97 #    include <windowsx.h>\r
98 #    include <mmsystem.h>\r
99 /* CYGWIN does not have tchar.h, but has TEXT(x), defined in winnt.h. */\r
100 #    ifndef __CYGWIN__\r
101 #      include <tchar.h>\r
102 #    else\r
103 #      define _TEXT(x) TEXT(x)\r
104 #      define _T(x)    TEXT(x)\r
105 #    endif\r
106 \r
107 #elif TARGET_HOST_POSIX_X11\r
108 #    include <GL/glx.h>\r
109 #    include <X11/Xlib.h>\r
110 #    include <X11/Xatom.h>\r
111 #    include <X11/keysym.h>\r
112 #    include <X11/extensions/XInput.h>\r
113 #    ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H\r
114 #        include <X11/extensions/xf86vmode.h>\r
115 #    endif\r
116 #    ifdef HAVE_X11_EXTENSIONS_XRANDR_H\r
117 #        include <X11/extensions/Xrandr.h>\r
118 #    endif\r
119 /* If GLX is too old, we will fail during runtime when multisampling\r
120    is requested, but at least freeglut compiles. */\r
121 #    ifndef GLX_SAMPLE_BUFFERS\r
122 #        define GLX_SAMPLE_BUFFERS 0x80A8\r
123 #    endif\r
124 #    ifndef GLX_SAMPLES\r
125 #        define GLX_SAMPLES 0x80A9\r
126 #    endif\r
127 \r
128 #endif\r
129 \r
130 /* These files should be available on every platform. */\r
131 #include <stdio.h>\r
132 #include <string.h>\r
133 #include <math.h>\r
134 #include <stdlib.h>\r
135 #include <stdarg.h>\r
136 \r
137 /* These are included based on autoconf directives. */\r
138 #ifdef HAVE_SYS_TYPES_H\r
139 #    include <sys/types.h>\r
140 #endif\r
141 #ifdef HAVE_UNISTD_H\r
142 #    include <unistd.h>\r
143 #endif\r
144 #ifdef TIME_WITH_SYS_TIME\r
145 #    include <sys/time.h>\r
146 #    include <time.h>\r
147 #elif defined(HAVE_SYS_TIME_H)\r
148 #    include <sys/time.h>\r
149 #else\r
150 #    include <time.h>\r
151 #endif\r
152 \r
153 /* -- AUTOCONF HACKS --------------------------------------------------------*/\r
154 \r
155 /* XXX: Update autoconf to avoid these.\r
156  * XXX: Are non-POSIX platforms intended not to use autoconf?\r
157  * If so, perhaps there should be a config_guess.h for them. Alternatively,\r
158  * config guesses could be placed above, just after the config.h exclusion.\r
159  */\r
160 #if defined(__FreeBSD__) || defined(__NetBSD__)\r
161 #    define HAVE_USB_JS 1\r
162 #    if defined(__NetBSD__) || ( defined(__FreeBSD__) && __FreeBSD_version >= 500000)\r
163 #        define HAVE_USBHID_H 1\r
164 #    endif\r
165 #endif\r
166 \r
167 #if TARGET_HOST_MS_WINDOWS\r
168 #    define  HAVE_VFPRINTF 1\r
169 #endif\r
170 \r
171 /* MinGW may lack a prototype for ChangeDisplaySettingsEx() (depending on the version?) */\r
172 #if TARGET_HOST_MS_WINDOWS && !defined(ChangeDisplaySettingsEx)\r
173 LONG WINAPI ChangeDisplaySettingsExA(LPCSTR,LPDEVMODEA,HWND,DWORD,LPVOID);\r
174 LONG WINAPI ChangeDisplaySettingsExW(LPCWSTR,LPDEVMODEW,HWND,DWORD,LPVOID);\r
175 #    ifdef UNICODE\r
176 #        define ChangeDisplaySettingsEx ChangeDisplaySettingsExW\r
177 #    else\r
178 #        define ChangeDisplaySettingsEx ChangeDisplaySettingsExA\r
179 #    endif\r
180 #endif\r
181 \r
182 #if defined(_MSC_VER) || defined(__WATCOMC__)\r
183 /* strdup() is non-standard, for all but POSIX-2001 */\r
184 #define strdup   _strdup\r
185 #endif\r
186 \r
187 /* M_PI is non-standard (defined by BSD, not ISO-C) */\r
188 #ifndef M_PI\r
189 #    define  M_PI  3.14159265358979323846\r
190 #endif\r
191 \r
192 #ifdef HAVE_STDBOOL_H\r
193 #    include <stdbool.h>\r
194 #    ifndef TRUE\r
195 #        define TRUE true\r
196 #    endif\r
197 #    ifndef FALSE\r
198 #        define FALSE false\r
199 #    endif\r
200 #else\r
201 #    ifndef TRUE\r
202 #        define  TRUE  1\r
203 #    endif\r
204 #    ifndef FALSE\r
205 #        define  FALSE  0\r
206 #    endif\r
207 #endif\r
208 \r
209 /* General defines */\r
210 \r
211 #define INVALID_MODIFIERS 0xffffffff\r
212 \r
213 \r
214 \r
215 /* Platform-specific includes */\r
216 #if TARGET_HOST_POSIX_X11\r
217 \r
218 typedef struct tagSFG_PlatformDisplay SFG_PlatformDisplay;\r
219 struct tagSFG_PlatformDisplay\r
220 {\r
221     Display*        Display;            /* The display we are being run in.  */\r
222     int             Screen;             /* The screen we are about to use.   */\r
223     Window          RootWindow;         /* The screen's root window.         */\r
224     int             Connection;         /* The display's connection number   */\r
225     Atom            DeleteWindow;       /* The window deletion atom          */\r
226     Atom            State;              /* The state atom                    */\r
227     Atom            StateFullScreen;    /* The full screen atom              */\r
228 \r
229 #ifdef HAVE_X11_EXTENSIONS_XRANDR_H\r
230     int prev_xsz, prev_ysz;\r
231     int prev_refresh;\r
232     int prev_size_valid;\r
233 #endif  /* HAVE_X11_EXTENSIONS_XRANDR_H */\r
234 \r
235 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H\r
236     /*\r
237      * XF86VidMode may be compilable even if it fails at runtime.  Therefore,\r
238      * the validity of the VidMode has to be tracked\r
239      */\r
240     int             DisplayModeValid;   /* Flag that indicates runtime status*/\r
241     XF86VidModeModeLine DisplayMode;    /* Current screen's display settings */\r
242     int             DisplayModeClock;   /* The display mode's refresh rate   */\r
243     int             DisplayViewPortX;   /* saved X location of the viewport  */\r
244     int             DisplayViewPortY;   /* saved Y location of the viewport  */\r
245 #endif /* HAVE_X11_EXTENSIONS_XF86VMODE_H */\r
246 \r
247     int             DisplayPointerX;    /* saved X location of the pointer   */\r
248     int             DisplayPointerY;    /* saved Y location of the pointer   */\r
249 };\r
250 \r
251 \r
252 /*\r
253  * Make "freeglut" window handle and context types so that we don't need so\r
254  * much conditionally-compiled code later in the library.\r
255  */\r
256 typedef Window     SFG_WindowHandleType ;\r
257 typedef GLXContext SFG_WindowContextType ;\r
258 \r
259 \r
260 #endif\r
261 #if TARGET_HOST_MS_WINDOWS\r
262 #include "../mswin/freeglut_internal_mswin.h"\r
263 #endif\r
264 \r
265 \r
266 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */\r
267 \r
268 /* Freeglut callbacks type definitions */\r
269 typedef void (* FGCBDisplay       )( void );\r
270 typedef void (* FGCBReshape       )( int, int );\r
271 typedef void (* FGCBVisibility    )( int );\r
272 typedef void (* FGCBKeyboard      )( unsigned char, int, int );\r
273 typedef void (* FGCBSpecial       )( int, int, int );\r
274 typedef void (* FGCBMouse         )( int, int, int, int );\r
275 typedef void (* FGCBMouseWheel    )( int, int, int, int );\r
276 typedef void (* FGCBMotion        )( int, int );\r
277 typedef void (* FGCBPassive       )( int, int );\r
278 typedef void (* FGCBEntry         )( int );\r
279 typedef void (* FGCBWindowStatus  )( int );\r
280 typedef void (* FGCBSelect        )( int, int, int );\r
281 typedef void (* FGCBJoystick      )( unsigned int, int, int, int );\r
282 typedef void (* FGCBKeyboardUp    )( unsigned char, int, int );\r
283 typedef void (* FGCBSpecialUp     )( int, int, int );\r
284 typedef void (* FGCBOverlayDisplay)( void );\r
285 typedef void (* FGCBSpaceMotion   )( int, int, int );\r
286 typedef void (* FGCBSpaceRotation )( int, int, int );\r
287 typedef void (* FGCBSpaceButton   )( int, int );\r
288 typedef void (* FGCBDials         )( int, int );\r
289 typedef void (* FGCBButtonBox     )( int, int );\r
290 typedef void (* FGCBTabletMotion  )( int, int );\r
291 typedef void (* FGCBTabletButton  )( int, int, int, int );\r
292 typedef void (* FGCBDestroy       )( void );\r
293 \r
294 typedef void (* FGCBMultiEntry   )( int, int );\r
295 typedef void (* FGCBMultiButton  )( int, int, int, int, int );\r
296 typedef void (* FGCBMultiMotion  )( int, int, int );\r
297 typedef void (* FGCBMultiPassive )( int, int, int );\r
298 \r
299 /* The global callbacks type definitions */\r
300 typedef void (* FGCBIdle          )( void );\r
301 typedef void (* FGCBTimer         )( int );\r
302 typedef void (* FGCBMenuState     )( int );\r
303 typedef void (* FGCBMenuStatus    )( int, int, int );\r
304 \r
305 /* The callback used when creating/using menus */\r
306 typedef void (* FGCBMenu          )( int );\r
307 \r
308 /* The FreeGLUT error/warning handler type definition */\r
309 typedef void (* FGError           ) ( const char *fmt, va_list ap);\r
310 typedef void (* FGWarning         ) ( const char *fmt, va_list ap);\r
311 \r
312 \r
313 /* A list structure */\r
314 typedef struct tagSFG_List SFG_List;\r
315 struct tagSFG_List\r
316 {\r
317     void *First;\r
318     void *Last;\r
319 };\r
320 \r
321 /* A list node structure */\r
322 typedef struct tagSFG_Node SFG_Node;\r
323 struct tagSFG_Node\r
324 {\r
325     void *Next;\r
326     void *Prev;\r
327 };\r
328 \r
329 /* A helper structure holding two ints and a boolean */\r
330 typedef struct tagSFG_XYUse SFG_XYUse;\r
331 struct tagSFG_XYUse\r
332 {\r
333     GLint           X, Y;               /* The two integers...               */\r
334     GLboolean       Use;                /* ...and a single boolean.          */\r
335 };\r
336 \r
337 /*\r
338  * An enumeration containing the state of the GLUT execution:\r
339  * initializing, running, or stopping\r
340  */\r
341 typedef enum\r
342 {\r
343   GLUT_EXEC_STATE_INIT,\r
344   GLUT_EXEC_STATE_RUNNING,\r
345   GLUT_EXEC_STATE_STOP\r
346 } fgExecutionState ;\r
347 \r
348 /* This structure holds different freeglut settings */\r
349 typedef struct tagSFG_State SFG_State;\r
350 struct tagSFG_State\r
351 {\r
352     SFG_XYUse        Position;             /* The default windows' position  */\r
353     SFG_XYUse        Size;                 /* The default windows' size      */\r
354     unsigned int     DisplayMode;          /* Display mode for new windows   */\r
355 \r
356     GLboolean        Initialised;          /* freeglut has been initialised  */\r
357 \r
358     int              DirectContext;        /* Direct rendering state         */\r
359 \r
360     GLboolean        ForceIconic;          /* New top windows are iconified  */\r
361     GLboolean        UseCurrentContext;    /* New windows share with current */\r
362 \r
363     GLboolean        GLDebugSwitch;        /* OpenGL state debugging switch  */\r
364     GLboolean        XSyncSwitch;          /* X11 sync protocol switch       */\r
365 \r
366     int              KeyRepeat;            /* Global key repeat mode.        */\r
367     int              Modifiers;            /* Current ALT/SHIFT/CTRL state   */\r
368 \r
369     GLuint           FPSInterval;          /* Interval between FPS printfs   */\r
370     GLuint           SwapCount;            /* Count of glutSwapBuffer calls  */\r
371     GLuint           SwapTime;             /* Time of last SwapBuffers       */\r
372 \r
373     unsigned long    Time;                 /* Time that glutInit was called  */\r
374     SFG_List         Timers;               /* The freeglut timer hooks       */\r
375     SFG_List         FreeTimers;           /* The unused timer hooks         */\r
376 \r
377     FGCBIdle         IdleCallback;         /* The global idle callback       */\r
378 \r
379     int              ActiveMenus;          /* Num. of currently active menus */\r
380     FGCBMenuState    MenuStateCallback;    /* Menu callbacks are global      */\r
381     FGCBMenuStatus   MenuStatusCallback;\r
382 \r
383     SFG_XYUse        GameModeSize;         /* Game mode screen's dimensions  */\r
384     int              GameModeDepth;        /* The pixel depth for game mode  */\r
385     int              GameModeRefresh;      /* The refresh rate for game mode */\r
386 \r
387     int              ActionOnWindowClose; /* Action when user closes window  */\r
388 \r
389     fgExecutionState ExecState;           /* Used for GLUT termination       */\r
390     char            *ProgramName;         /* Name of the invoking program    */\r
391     GLboolean        JoysticksInitialised;  /* Only initialize if application calls for them */\r
392     int              NumActiveJoysticks;    /* Number of active joysticks -- if zero, don't poll joysticks */\r
393     GLboolean        InputDevsInitialised;  /* Only initialize if application calls for them */\r
394 \r
395         int              MouseWheelTicks;      /* Number of ticks the mouse wheel has turned */\r
396 \r
397     int              AuxiliaryBufferNumber;  /* Number of auxiliary buffers */\r
398     int              SampleNumber;         /*  Number of samples per pixel  */\r
399 \r
400     int              MajorVersion;         /* Major OpenGL context version  */\r
401     int              MinorVersion;         /* Minor OpenGL context version  */\r
402     int              ContextFlags;         /* OpenGL context flags          */\r
403     int              ContextProfile;       /* OpenGL context profile        */\r
404     FGError          ErrorFunc;            /* User defined error handler    */\r
405     FGWarning        WarningFunc;          /* User defined warning handler  */\r
406 };\r
407 \r
408 /* The structure used by display initialization in freeglut_init.c */\r
409 typedef struct tagSFG_Display SFG_Display;\r
410 struct tagSFG_Display\r
411 {\r
412         SFG_PlatformDisplay pDisplay;\r
413 \r
414     int             ScreenWidth;        /* The screen's width in pixels      */\r
415     int             ScreenHeight;       /* The screen's height in pixels     */\r
416     int             ScreenWidthMM;      /* The screen's width in milimeters  */\r
417     int             ScreenHeightMM;     /* The screen's height in milimeters */\r
418 };\r
419 \r
420 \r
421 /* The user can create any number of timer hooks */\r
422 typedef struct tagSFG_Timer SFG_Timer;\r
423 struct tagSFG_Timer\r
424 {\r
425     SFG_Node        Node;\r
426     int             ID;                 /* The timer ID integer              */\r
427     FGCBTimer       Callback;           /* The timer callback                */\r
428     long            TriggerTime;        /* The timer trigger time            */\r
429 };\r
430 \r
431 /*\r
432  * A window and its OpenGL context. The contents of this structure\r
433  * are highly dependant on the target operating system we aim at...\r
434  */\r
435 typedef struct tagSFG_Context SFG_Context;\r
436 struct tagSFG_Context\r
437 {\r
438     SFG_WindowHandleType  Handle;    /* The window's handle                 */\r
439     SFG_WindowContextType Context;   /* The window's OpenGL/WGL context     */\r
440 \r
441 #if TARGET_HOST_POSIX_X11\r
442     GLXFBConfig*    FBConfig;        /* The window's FBConfig               */\r
443 #elif TARGET_HOST_MS_WINDOWS\r
444     HDC             Device;          /* The window's device context         */\r
445 #endif\r
446 \r
447     int             DoubleBuffered;  /* Treat the window as double-buffered */\r
448 };\r
449 \r
450 /* Window's state description. This structure should be kept portable. */\r
451 typedef struct tagSFG_WindowState SFG_WindowState;\r
452 struct tagSFG_WindowState\r
453 {\r
454     /* Note that on Windows, sizes always refer to the client area, thus without the window decorations */\r
455     int             Width;              /* Window's width in pixels          */\r
456     int             Height;             /* The same about the height         */\r
457 #if TARGET_HOST_POSIX_X11\r
458     int             OldWidth;           /* Window width from before a resize */\r
459     int             OldHeight;          /*   "    height  "    "    "   "    */\r
460 #elif TARGET_HOST_MS_WINDOWS\r
461     RECT            OldRect;            /* window rect - stored before the window is made fullscreen */\r
462     DWORD           OldStyle;           /* window style - stored before the window is made fullscreen */\r
463 #endif\r
464 \r
465     GLboolean       Redisplay;          /* Do we have to redisplay?          */\r
466     GLboolean       Visible;            /* Is the window visible now         */\r
467 \r
468     int             Cursor;             /* The currently selected cursor     */\r
469 \r
470     long            JoystickPollRate;   /* The joystick polling rate         */\r
471     long            JoystickLastPoll;   /* When the last poll happened       */\r
472 \r
473     int             MouseX, MouseY;     /* The most recent mouse position    */\r
474 \r
475     GLboolean       IgnoreKeyRepeat;    /* Whether to ignore key repeat.     */\r
476     GLboolean       KeyRepeating;       /* Currently in repeat mode          */\r
477 \r
478     GLboolean       NeedToResize;       /* Do we need to resize the window?  */\r
479 \r
480     GLboolean       IsFullscreen;       /* is the window fullscreen? */\r
481 };\r
482 \r
483 \r
484 /*\r
485  * A generic function pointer.  We should really use the GLUTproc type\r
486  * defined in freeglut_ext.h, but if we include that header in this file\r
487  * a bunch of other stuff (font-related) blows up!\r
488  */\r
489 typedef void (*SFG_Proc)();\r
490 \r
491 \r
492 /*\r
493  * SET_WCB() is used as:\r
494  *\r
495  *     SET_WCB( window, cbname, func );\r
496  *\r
497  * ...where {window} is the freeglut window to set the callback,\r
498  *          {cbname} is the window-specific callback to set,\r
499  *          {func} is a function-pointer.\r
500  *\r
501  * Originally, {FETCH_WCB( ... ) = func} was rather sloppily used,\r
502  * but this can cause warnings because the FETCH_WCB() macro type-\r
503  * casts its result, and a type-cast value shouldn't be an lvalue.\r
504  *\r
505  * The {if( FETCH_WCB( ... ) != func )} test is to do type-checking\r
506  * and for no other reason.  Since it's hidden in the macro, the\r
507  * ugliness is felt to be rather benign.\r
508  */\r
509 #define SET_WCB(window,cbname,func)                            \\r
510 do                                                             \\r
511 {                                                              \\r
512     if( FETCH_WCB( window, cbname ) != (SFG_Proc)(func) )      \\r
513         (((window).CallBacks[CB_ ## cbname]) = (SFG_Proc)(func)); \\r
514 } while( 0 )\r
515 \r
516 /*\r
517  * FETCH_WCB() is used as:\r
518  *\r
519  *     FETCH_WCB( window, cbname );\r
520  *\r
521  * ...where {window} is the freeglut window to fetch the callback from,\r
522  *          {cbname} is the window-specific callback to fetch.\r
523  *\r
524  * The result is correctly type-cast to the callback function pointer\r
525  * type.\r
526  */\r
527 #define FETCH_WCB(window,cbname) \\r
528     ((window).CallBacks[CB_ ## cbname])\r
529 \r
530 /*\r
531  * INVOKE_WCB() is used as:\r
532  *\r
533  *     INVOKE_WCB( window, cbname, ( arg_list ) );\r
534  *\r
535  * ...where {window} is the freeglut window,\r
536  *          {cbname} is the window-specific callback to be invoked,\r
537  *          {(arg_list)} is the parameter list.\r
538  *\r
539  * The callback is invoked as:\r
540  *\r
541  *    callback( arg_list );\r
542  *\r
543  * ...so the parentheses are REQUIRED in the {arg_list}.\r
544  *\r
545  * NOTE that it does a sanity-check and also sets the\r
546  * current window.\r
547  *\r
548  */\r
549 #if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: also WinCE? */\r
550 #define INVOKE_WCB(window,cbname,arg_list)    \\r
551 do                                            \\r
552 {                                             \\r
553     if( FETCH_WCB( window, cbname ) )         \\r
554     {                                         \\r
555         FGCB ## cbname func = (FGCB ## cbname)(FETCH_WCB( window, cbname )); \\r
556         fgSetWindow( &window );               \\r
557         func arg_list;                        \\r
558     }                                         \\r
559 } while( 0 )\r
560 #else\r
561 #define INVOKE_WCB(window,cbname,arg_list)    \\r
562 do                                            \\r
563 {                                             \\r
564     if( FETCH_WCB( window, cbname ) )         \\r
565     {                                         \\r
566         fgSetWindow( &window );               \\r
567         ((FGCB ## cbname)FETCH_WCB( window, cbname )) arg_list; \\r
568     }                                         \\r
569 } while( 0 )\r
570 #endif\r
571 \r
572 /*\r
573  * The window callbacks the user can supply us with. Should be kept portable.\r
574  *\r
575  * This enumeration provides the freeglut CallBack numbers.\r
576  * The symbolic constants are indices into a window's array of\r
577  * function callbacks.  The names are formed by splicing a common\r
578  * prefix onto the callback's base name.  (This was originally\r
579  * done so that an early stage of development could live side-by-\r
580  * side with the old callback code.  The old callback code used\r
581  * the bare callback's name as a structure member, so I used a\r
582  * prefix for the array index name.)\r
583  *\r
584  * XXX For consistancy, perhaps the prefix should match the\r
585  * XXX FETCH* and INVOKE* macro suffices.  I.e., WCB_, rather than\r
586  * XXX CB_.\r
587  */\r
588 enum\r
589 {\r
590     CB_Display,\r
591     CB_Reshape,\r
592     CB_Keyboard,\r
593     CB_KeyboardUp,\r
594     CB_Special,\r
595     CB_SpecialUp,\r
596     CB_Mouse,\r
597     CB_MouseWheel,\r
598     CB_Motion,\r
599     CB_Passive,\r
600     CB_Entry,\r
601     CB_Visibility,\r
602     CB_WindowStatus,\r
603     CB_Joystick,\r
604     CB_Destroy,\r
605 \r
606     /* MPX-related */\r
607     CB_MultiEntry,\r
608     CB_MultiButton,\r
609     CB_MultiMotion,\r
610     CB_MultiPassive,\r
611 \r
612     /* Presently ignored */\r
613     CB_Select,\r
614     CB_OverlayDisplay,\r
615     CB_SpaceMotion,     /* presently implemented only on UNIX/X11 */\r
616     CB_SpaceRotation,   /* presently implemented only on UNIX/X11 */\r
617     CB_SpaceButton,     /* presently implemented only on UNIX/X11 */\r
618     CB_Dials,\r
619     CB_ButtonBox,\r
620     CB_TabletMotion,\r
621     CB_TabletButton,\r
622 \r
623     /* Always make this the LAST one */\r
624     TOTAL_CALLBACKS\r
625 };\r
626 \r
627 \r
628 /* This structure holds the OpenGL rendering context for all the menu windows */\r
629 typedef struct tagSFG_MenuContext SFG_MenuContext;\r
630 struct tagSFG_MenuContext\r
631 {\r
632     SFG_WindowContextType MContext;       /* The menu window's WGL context   */\r
633 };\r
634 \r
635 /* This structure describes a menu */\r
636 typedef struct tagSFG_Window SFG_Window;\r
637 typedef struct tagSFG_MenuEntry SFG_MenuEntry;\r
638 typedef struct tagSFG_Menu SFG_Menu;\r
639 struct tagSFG_Menu\r
640 {\r
641     SFG_Node            Node;\r
642     void               *UserData;     /* User data passed back at callback   */\r
643     int                 ID;           /* The global menu ID                  */\r
644     SFG_List            Entries;      /* The menu entries list               */\r
645     FGCBMenu            Callback;     /* The menu callback                   */\r
646     FGCBDestroy         Destroy;      /* Destruction callback                */\r
647     GLboolean           IsActive;     /* Is the menu selected?               */\r
648     int                 Width;        /* Menu box width in pixels            */\r
649     int                 Height;       /* Menu box height in pixels           */\r
650     int                 X, Y;         /* Menu box raster position            */\r
651 \r
652     SFG_MenuEntry      *ActiveEntry;  /* Currently active entry in the menu  */\r
653     SFG_Window         *Window;       /* Window for menu                     */\r
654     SFG_Window         *ParentWindow; /* Window in which the menu is invoked */\r
655 };\r
656 \r
657 /* This is a menu entry */\r
658 struct tagSFG_MenuEntry\r
659 {\r
660     SFG_Node            Node;\r
661     int                 ID;                     /* The menu entry ID (local) */\r
662     int                 Ordinal;                /* The menu's ordinal number */\r
663     char*               Text;                   /* The text to be displayed  */\r
664     SFG_Menu*           SubMenu;                /* Optional sub-menu tree    */\r
665     GLboolean           IsActive;               /* Is the entry highlighted? */\r
666     int                 Width;                  /* Label's width in pixels   */\r
667 };\r
668 \r
669 /*\r
670  * A window, making part of freeglut windows hierarchy.\r
671  * Should be kept portable.\r
672  *\r
673  * NOTE that ActiveMenu is set to menu itself if the window is a menu.\r
674  */\r
675 struct tagSFG_Window\r
676 {\r
677     SFG_Node            Node;\r
678     int                 ID;                     /* Window's ID number        */\r
679 \r
680     SFG_Context         Window;                 /* Window and OpenGL context */\r
681     SFG_WindowState     State;                  /* The window state          */\r
682     SFG_Proc            CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */\r
683     void               *UserData ;              /* For use by user           */\r
684 \r
685     SFG_Menu*       Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window  */\r
686     SFG_Menu*       ActiveMenu;                 /* The window's active menu  */\r
687 \r
688     SFG_Window*         Parent;                 /* The parent to this window */\r
689     SFG_List            Children;               /* The subwindows d.l. list  */\r
690 \r
691     GLboolean           IsMenu;                 /* Set to 1 if we are a menu */\r
692 };\r
693 \r
694 \r
695 /* A linked list structure of windows */\r
696 typedef struct tagSFG_WindowList SFG_WindowList ;\r
697 struct tagSFG_WindowList\r
698 {\r
699     SFG_Node node;\r
700     SFG_Window *window ;\r
701 };\r
702 \r
703 /* This holds information about all the windows, menus etc. */\r
704 typedef struct tagSFG_Structure SFG_Structure;\r
705 struct tagSFG_Structure\r
706 {\r
707     SFG_List        Windows;         /* The global windows list            */\r
708     SFG_List        Menus;           /* The global menus list              */\r
709     SFG_List        WindowsToDestroy;\r
710 \r
711     SFG_Window*     CurrentWindow;   /* The currently set window          */\r
712     SFG_Menu*       CurrentMenu;     /* Same, but menu...                 */\r
713 \r
714     SFG_MenuContext* MenuContext;    /* OpenGL rendering context for menus */\r
715 \r
716     SFG_Window*      GameModeWindow; /* The game mode window               */\r
717 \r
718     int              WindowID;       /* The new current window ID          */\r
719     int              MenuID;         /* The new current menu ID            */\r
720 };\r
721 \r
722 /*\r
723  * This structure is used for the enumeration purposes.\r
724  * You can easily extend its functionalities by declaring\r
725  * a structure containing enumerator's contents and custom\r
726  * data, then casting its pointer to (SFG_Enumerator *).\r
727  */\r
728 typedef struct tagSFG_Enumerator SFG_Enumerator;\r
729 struct tagSFG_Enumerator\r
730 {\r
731     GLboolean   found;                          /* Used to terminate search  */\r
732     void*       data;                           /* Custom data pointer       */\r
733 };\r
734 typedef void (* FGCBenumerator  )( SFG_Window *, SFG_Enumerator * );\r
735 \r
736 /* The bitmap font structure */\r
737 typedef struct tagSFG_Font SFG_Font;\r
738 struct tagSFG_Font\r
739 {\r
740     char*           Name;         /* The source font name             */\r
741     int             Quantity;     /* Number of chars in font          */\r
742     int             Height;       /* Height of the characters         */\r
743     const GLubyte** Characters;   /* The characters mapping           */\r
744 \r
745     float           xorig, yorig; /* Relative origin of the character */\r
746 };\r
747 \r
748 /* The stroke font structures */\r
749 \r
750 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;\r
751 struct tagSFG_StrokeVertex\r
752 {\r
753     GLfloat         X, Y;\r
754 };\r
755 \r
756 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;\r
757 struct tagSFG_StrokeStrip\r
758 {\r
759     int             Number;\r
760     const SFG_StrokeVertex* Vertices;\r
761 };\r
762 \r
763 typedef struct tagSFG_StrokeChar SFG_StrokeChar;\r
764 struct tagSFG_StrokeChar\r
765 {\r
766     GLfloat         Right;\r
767     int             Number;\r
768     const SFG_StrokeStrip* Strips;\r
769 };\r
770 \r
771 typedef struct tagSFG_StrokeFont SFG_StrokeFont;\r
772 struct tagSFG_StrokeFont\r
773 {\r
774     char*           Name;                       /* The source font name      */\r
775     int             Quantity;                   /* Number of chars in font   */\r
776     GLfloat         Height;                     /* Height of the characters  */\r
777     const SFG_StrokeChar** Characters;          /* The characters mapping    */\r
778 };\r
779 \r
780 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */\r
781 \r
782 /* Freeglut display related stuff (initialized once per session) */\r
783 extern SFG_Display fgDisplay;\r
784 \r
785 /* Freeglut internal structure */\r
786 extern SFG_Structure fgStructure;\r
787 \r
788 /* The current freeglut settings */\r
789 extern SFG_State fgState;\r
790 \r
791 \r
792 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */\r
793 \r
794 /*\r
795  * A call to this function makes us sure that the Display and Structure\r
796  * subsystems have been properly initialized and are ready to be used\r
797  */\r
798 #define  FREEGLUT_EXIT_IF_NOT_INITIALISED( string )               \\r
799   if ( ! fgState.Initialised )                                    \\r
800   {                                                               \\r
801     fgError ( " ERROR:  Function <%s> called"                     \\r
802               " without first calling 'glutInit'.", (string) ) ;  \\r
803   }\r
804 \r
805 #define  FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED( string )  \\r
806   if ( ! fgState.Initialised )                                      \\r
807   {                                                                 \\r
808     fgError ( " ERROR:  Internal <%s> function called"              \\r
809               " without first calling 'glutInit'.", (string) ) ;    \\r
810   }\r
811 \r
812 #define  FREEGLUT_INTERNAL_ERROR_EXIT( cond, string, function )  \\r
813   if ( ! ( cond ) )                                              \\r
814   {                                                              \\r
815     fgError ( " ERROR:  Internal error <%s> in function %s",     \\r
816               (string), (function) ) ;                           \\r
817   }\r
818 \r
819 /*\r
820  * Following definitions are somewhat similiar to GLib's,\r
821  * but do not generate any log messages:\r
822  */\r
823 #define  freeglut_return_if_fail( expr ) \\r
824     if( !(expr) )                        \\r
825         return;\r
826 #define  freeglut_return_val_if_fail( expr, val ) \\r
827     if( !(expr) )                                 \\r
828         return val ;\r
829 \r
830 /*\r
831  * A call to those macros assures us that there is a current\r
832  * window set, respectively:\r
833  */\r
834 #define  FREEGLUT_EXIT_IF_NO_WINDOW( string )                               \\r
835   if ( ! fgStructure.CurrentWindow &&                                       \\r
836        ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION ) )  \\r
837   {                                                                         \\r
838     fgError ( " ERROR:  Function <%s> called"                               \\r
839               " with no current window defined.", (string) ) ;              \\r
840   }\r
841 \r
842 /*\r
843  * The deinitialize function gets called on glutMainLoop() end. It should clean up\r
844  * everything inside of the freeglut\r
845  */\r
846 void fgDeinitialize( void );\r
847 \r
848 /*\r
849  * Those two functions are used to create/destroy the freeglut internal\r
850  * structures. This actually happens when calling glutInit() and when\r
851  * quitting the glutMainLoop() (which actually happens, when all windows\r
852  * have been closed).\r
853  */\r
854 void fgCreateStructure( void );\r
855 void fgDestroyStructure( void );\r
856 \r
857 /*\r
858  * Window creation, opening, closing and destruction.\r
859  * Also CallBack clearing/initialization.\r
860  * Defined in freeglut_structure.c, freeglut_window.c.\r
861  */\r
862 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,\r
863                             GLboolean positionUse, int x, int y,\r
864                             GLboolean sizeUse, int w, int h,\r
865                             GLboolean gameMode, GLboolean isMenu );\r
866 void        fgSetWindow ( SFG_Window *window );\r
867 void        fgOpenWindow( SFG_Window* window, const char* title,\r
868                           GLboolean positionUse, int x, int y,\r
869                           GLboolean sizeUse, int w, int h,\r
870                           GLboolean gameMode, GLboolean isSubWindow );\r
871 void        fgCloseWindow( SFG_Window* window );\r
872 void        fgAddToWindowDestroyList ( SFG_Window* window );\r
873 void        fgCloseWindows ();\r
874 void        fgDestroyWindow( SFG_Window* window );\r
875 \r
876 /* Menu creation and destruction. Defined in freeglut_structure.c */\r
877 SFG_Menu*   fgCreateMenu( FGCBMenu menuCallback );\r
878 void        fgDestroyMenu( SFG_Menu* menu );\r
879 \r
880 /* Joystick device management functions, defined in freeglut_joystick.c */\r
881 int         fgJoystickDetect( void );\r
882 void        fgInitialiseJoysticks( void );\r
883 void        fgJoystickClose( void );\r
884 void        fgJoystickPollWindow( SFG_Window* window );\r
885 \r
886 /* InputDevice Initialisation and Closure */\r
887 int         fgInputDeviceDetect( void );\r
888 void        fgInitialiseInputDevices( void );\r
889 void        fgInputDeviceClose( void );\r
890 \r
891 /* spaceball device functions, defined in freeglut_spaceball.c */\r
892 void        fgInitialiseSpaceball( void );\r
893 void        fgSpaceballClose( void );\r
894 void        fgSpaceballSetWindow( SFG_Window *window );\r
895 \r
896 int         fgHasSpaceball( void );\r
897 int         fgSpaceballNumButtons( void );\r
898 \r
899 #if TARGET_HOST_POSIX_X11\r
900 int         fgIsSpaceballXEvent( const XEvent *ev );\r
901 void        fgSpaceballHandleXEvent( const XEvent *ev );\r
902 #endif\r
903 \r
904 /* Setting the cursor for a given window */\r
905 void fgSetCursor ( SFG_Window *window, int cursorID );\r
906 \r
907 /*\r
908  * Helper function to enumerate through all registered windows\r
909  * and one to enumerate all of a window's subwindows...\r
910  *\r
911  * The GFunc callback for those functions will be defined as:\r
912  *\r
913  *      void enumCallback( gpointer window, gpointer enumerator );\r
914  *\r
915  * where window is the enumerated (sub)window pointer (SFG_Window *),\r
916  * and userData is the a custom user-supplied pointer. Functions\r
917  * are defined and exported from freeglut_structure.c file.\r
918  */\r
919 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );\r
920 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,\r
921                        SFG_Enumerator* enumerator );\r
922 \r
923 /*\r
924  * fgWindowByHandle returns a (SFG_Window *) value pointing to the\r
925  * first window in the queue matching the specified window handle.\r
926  * The function is defined in freeglut_structure.c file.\r
927  */\r
928 SFG_Window* fgWindowByHandle( SFG_WindowHandleType hWindow );\r
929 \r
930 /*\r
931  * This function is similiar to the previous one, except it is\r
932  * looking for a specified (sub)window identifier. The function\r
933  * is defined in freeglut_structure.c file.\r
934  */\r
935 SFG_Window* fgWindowByID( int windowID );\r
936 \r
937 /*\r
938  * Looks up a menu given its ID. This is easier than fgWindowByXXX\r
939  * as all menus are placed in a single doubly linked list...\r
940  */\r
941 SFG_Menu* fgMenuByID( int menuID );\r
942 \r
943 /*\r
944  * The menu activation and deactivation the code. This is the meat\r
945  * of the menu user interface handling code...\r
946  */\r
947 void fgUpdateMenuHighlight ( SFG_Menu *menu );\r
948 GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed,\r
949                               int mouse_x, int mouse_y );\r
950 void fgDeactivateMenu( SFG_Window *window );\r
951 \r
952 /*\r
953  * This function gets called just before the buffers swap, so that\r
954  * freeglut can display the pull-down menus via OpenGL. The function\r
955  * is defined in freeglut_menu.c file.\r
956  */\r
957 void fgDisplayMenu( void );\r
958 \r
959 /* Elapsed time as per glutGet(GLUT_ELAPSED_TIME). */\r
960 long fgElapsedTime( void );\r
961 \r
962 /* System time in milliseconds */\r
963 long unsigned fgSystemTime(void);\r
964 \r
965 /* List functions */\r
966 void fgListInit(SFG_List *list);\r
967 void fgListAppend(SFG_List *list, SFG_Node *node);\r
968 void fgListRemove(SFG_List *list, SFG_Node *node);\r
969 int fgListLength(SFG_List *list);\r
970 void fgListInsert(SFG_List *list, SFG_Node *next, SFG_Node *node);\r
971 \r
972 /* Error Message functions */\r
973 void fgError( const char *fmt, ... );\r
974 void fgWarning( const char *fmt, ... );\r
975 \r
976 /*\r
977  * Check if "hint" is present in "property" for "window".  See freeglut_init.c\r
978  */\r
979 #if TARGET_HOST_POSIX_X11\r
980 int fgHintPresent(Window window, Atom property, Atom hint);\r
981 \r
982 /* Handler for X extension Events */\r
983 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H\r
984   void fgHandleExtensionEvents( XEvent * ev );\r
985   void fgRegisterDevices( Display* dpy, Window* win );\r
986 #endif\r
987 \r
988 #endif\r
989 \r
990 SFG_Proc fghGetProcAddress( const char *procName );\r
991 \r
992 #if TARGET_HOST_MS_WINDOWS\r
993 extern void (__cdecl *__glutExitFunc)( int return_value );\r
994 #endif\r
995 \r
996 #endif /* FREEGLUT_INTERNAL_H */\r
997 \r
998 /*** END OF FILE ***/\r