Splitting the other "glutGet" Windows-specific code into its own function
[freeglut] / src / mswin / freeglut_state_mswin.c
1 /*\r
2  * freeglut_state_mswin.c\r
3  *\r
4  * The Windows-specific mouse cursor related stuff.\r
5  *\r
6  * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.\r
7  * Written by John F. Fay, <fayjf@sourceforge.net>\r
8  * Creation date: Sun Jan 22, 2012\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 #include <GL/freeglut.h>\r
29 #include "freeglut_internal_mswin.h"\r
30 \r
31 \r
32 \r
33 /* The following include file is available from SGI but is not standard:\r
34  *   #include <GL/wglext.h>\r
35  * So we copy the necessary parts out of it to support the multisampling query\r
36  */\r
37 #define WGL_SAMPLES_ARB                0x2042\r
38 \r
39 \r
40 \r
41 int fgPlatformGlutGet ( GLenum eWhat )\r
42 {\r
43     int returnValue ;\r
44     GLboolean boolValue ;\r
45 \r
46     int nsamples = 0;\r
47 \r
48     switch( eWhat )\r
49     {\r
50     case GLUT_WINDOW_NUM_SAMPLES:\r
51       glGetIntegerv(WGL_SAMPLES_ARB, &nsamples);\r
52       return nsamples;\r
53 \r
54     /* Handle the OpenGL inquiries */\r
55     case GLUT_WINDOW_RGBA:\r
56 #if defined(_WIN32_WCE)\r
57       boolValue = (GLboolean)0;  /* WinCE doesn't support this feature */\r
58 #else\r
59       glGetBooleanv ( GL_RGBA_MODE, &boolValue );\r
60       returnValue = boolValue ? 1 : 0;\r
61 #endif\r
62       return returnValue;\r
63     case GLUT_WINDOW_DOUBLEBUFFER:\r
64 #if defined(_WIN32_WCE)\r
65       boolValue = (GLboolean)0;  /* WinCE doesn't support this feature */\r
66 #else\r
67       glGetBooleanv ( GL_DOUBLEBUFFER, &boolValue );\r
68       returnValue = boolValue ? 1 : 0;\r
69 #endif\r
70       return returnValue;\r
71     case GLUT_WINDOW_STEREO:\r
72 #if defined(_WIN32_WCE)\r
73       boolValue = (GLboolean)0;  /* WinCE doesn't support this feature */\r
74 #else\r
75       glGetBooleanv ( GL_STEREO, &boolValue );\r
76       returnValue = boolValue ? 1 : 0;\r
77 #endif\r
78       return returnValue;\r
79 \r
80     case GLUT_WINDOW_RED_SIZE:\r
81       glGetIntegerv ( GL_RED_BITS, &returnValue );\r
82       return returnValue;\r
83     case GLUT_WINDOW_GREEN_SIZE:\r
84       glGetIntegerv ( GL_GREEN_BITS, &returnValue );\r
85       return returnValue;\r
86     case GLUT_WINDOW_BLUE_SIZE:\r
87       glGetIntegerv ( GL_BLUE_BITS, &returnValue );\r
88       return returnValue;\r
89     case GLUT_WINDOW_ALPHA_SIZE:\r
90       glGetIntegerv ( GL_ALPHA_BITS, &returnValue );\r
91       return returnValue;\r
92     case GLUT_WINDOW_ACCUM_RED_SIZE:\r
93 #if defined(_WIN32_WCE)\r
94       returnValue = 0;  /* WinCE doesn't support this feature */\r
95 #else\r
96       glGetIntegerv ( GL_ACCUM_RED_BITS, &returnValue );\r
97 #endif\r
98       return returnValue;\r
99     case GLUT_WINDOW_ACCUM_GREEN_SIZE:\r
100 #if defined(_WIN32_WCE)\r
101       returnValue = 0;  /* WinCE doesn't support this feature */\r
102 #else\r
103       glGetIntegerv ( GL_ACCUM_GREEN_BITS, &returnValue );\r
104 #endif\r
105       return returnValue;\r
106     case GLUT_WINDOW_ACCUM_BLUE_SIZE:\r
107 #if defined(_WIN32_WCE)\r
108       returnValue = 0;  /* WinCE doesn't support this feature */\r
109 #else\r
110       glGetIntegerv ( GL_ACCUM_BLUE_BITS, &returnValue );\r
111 #endif\r
112       return returnValue;\r
113     case GLUT_WINDOW_ACCUM_ALPHA_SIZE:\r
114 #if defined(_WIN32_WCE)\r
115       returnValue = 0;  /* WinCE doesn't support this feature */\r
116 #else\r
117       glGetIntegerv ( GL_ACCUM_ALPHA_BITS, &returnValue );\r
118 #endif\r
119       return returnValue;\r
120     case GLUT_WINDOW_DEPTH_SIZE:\r
121       glGetIntegerv ( GL_DEPTH_BITS, &returnValue );\r
122       return returnValue;\r
123 \r
124     case GLUT_WINDOW_BUFFER_SIZE:\r
125       returnValue = 1 ;                                      /* ????? */\r
126       return returnValue;\r
127     case GLUT_WINDOW_STENCIL_SIZE:\r
128       returnValue = 0 ;                                      /* ????? */\r
129       return returnValue;\r
130 \r
131     case GLUT_WINDOW_X:\r
132     case GLUT_WINDOW_Y:\r
133     case GLUT_WINDOW_WIDTH:\r
134     case GLUT_WINDOW_HEIGHT:\r
135     {\r
136         /*\r
137          *  There is considerable confusion about the "right thing to\r
138          *  do" concerning window  size and position.  GLUT itself is\r
139          *  not consistent between Windows and UNIX/X11; since\r
140          *  platform independence is a virtue for "freeglut", we\r
141          *  decided to break with GLUT's behaviour.\r
142          *\r
143          *  Under UNIX/X11, it is apparently not possible to get the\r
144          *  window border sizes in order to subtract them off the\r
145          *  window's initial position until some time after the window\r
146          *  has been created.  Therefore we decided on the following\r
147          *  behaviour, both under Windows and under UNIX/X11:\r
148          *  - When you create a window with position (x,y) and size\r
149          *    (w,h), the upper left hand corner of the outside of the\r
150          *    window is at (x,y) and the size of the drawable area  is\r
151          *    (w,h).\r
152          *  - When you query the size and position of the window--as\r
153          *    is happening here for Windows--"freeglut" will return\r
154          *    the size of the drawable area--the (w,h) that you\r
155          *    specified when you created the window--and the coordinates\r
156          *    of the upper left hand corner of the drawable\r
157          *    area--which is NOT the (x,y) you specified.\r
158          */\r
159 \r
160         RECT winRect;\r
161 \r
162         freeglut_return_val_if_fail( fgStructure.CurrentWindow != NULL, 0 );\r
163 \r
164 #if defined(_WIN32_WCE)\r
165         GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );\r
166 #else\r
167         winRect = fghGetClientArea(fgStructure.CurrentWindow, FALSE);\r
168 #endif /* defined(_WIN32_WCE) */\r
169 \r
170         switch( eWhat )\r
171         {\r
172         case GLUT_WINDOW_X:      return winRect.left                ;\r
173         case GLUT_WINDOW_Y:      return winRect.top                 ;\r
174         case GLUT_WINDOW_WIDTH:  return winRect.right - winRect.left;\r
175         case GLUT_WINDOW_HEIGHT: return winRect.bottom - winRect.top;\r
176         }\r
177     }\r
178     break;\r
179 \r
180     case GLUT_WINDOW_BORDER_WIDTH :\r
181     case GLUT_WINDOW_HEADER_HEIGHT :\r
182 #if defined(_WIN32_WCE)\r
183         return 0;\r
184 #else\r
185         {\r
186             DWORD windowStyle;\r
187 \r
188             if (fgStructure.CurrentWindow && fgStructure.CurrentWindow->Window.Handle)\r
189                 windowStyle = GetWindowLong(fgStructure.CurrentWindow->Window.Handle, GWL_STYLE);\r
190             else\r
191                 /* If no window, return sizes for a default window with title bar and border */\r
192                 windowStyle = WS_OVERLAPPEDWINDOW;\r
193             \r
194             switch( eWhat )\r
195             {\r
196             case GLUT_WINDOW_BORDER_WIDTH:\r
197                 {\r
198                     int xBorderWidth, yBorderWidth;\r
199                     fghGetBorderWidth(windowStyle, &xBorderWidth, &yBorderWidth);\r
200                     return xBorderWidth;\r
201                 }\r
202             case GLUT_WINDOW_HEADER_HEIGHT:\r
203                 /* Need to query for WS_MAXIMIZEBOX to see if we have a title bar, the WS_CAPTION query is also true for a WS_DLGFRAME only... */\r
204                 return (windowStyle & WS_MAXIMIZEBOX)? GetSystemMetrics( SM_CYCAPTION ) : 0;\r
205             }\r
206         }\r
207 #endif /* defined(_WIN32_WCE) */\r
208 \r
209     case GLUT_DISPLAY_MODE_POSSIBLE:\r
210 #if defined(_WIN32_WCE)\r
211         return 0;\r
212 #else\r
213         return fgSetupPixelFormat( fgStructure.CurrentWindow, GL_TRUE,\r
214                                     PFD_MAIN_PLANE );\r
215 #endif /* defined(_WIN32_WCE) */\r
216 \r
217 \r
218     case GLUT_WINDOW_FORMAT_ID:\r
219 #if !defined(_WIN32_WCE)\r
220         if( fgStructure.CurrentWindow != NULL )\r
221             return GetPixelFormat( fgStructure.CurrentWindow->Window.Device );\r
222 #endif /* defined(_WIN32_WCE) */\r
223         return 0;\r
224 \r
225     default:\r
226         fgWarning( "glutGet(): missing enum handle %d", eWhat );\r
227         break;\r
228     }\r
229 \r
230         return -1;\r
231 }\r
232 \r
233 \r
234 int fgPlatformGlutDeviceGet ( GLenum eWhat )\r
235 {\r
236     switch( eWhat )\r
237     {\r
238     case GLUT_HAS_KEYBOARD:\r
239         /*\r
240          * Win32 is assumed a keyboard, and this cannot be queried,\r
241          * except for WindowsCE.\r
242          *\r
243          * X11 has a core keyboard by definition, although it can\r
244          * be present as a virtual/dummy keyboard. For now, there\r
245          * is no reliable way to tell if a real keyboard is present.\r
246          */\r
247 #if defined(_WIN32_CE)\r
248         return ( GetKeyboardStatus() & KBDI_KEYBOARD_PRESENT ) ? 1 : 0;\r
249 #   if FREEGLUT_LIB_PRAGMAS\r
250 #       pragma comment (lib,"Kbdui.lib")\r
251 #   endif\r
252 \r
253 #else\r
254         return 1;\r
255 #endif\r
256 \r
257     case GLUT_HAS_MOUSE:\r
258         /*\r
259          * MS Windows can be booted without a mouse.\r
260          */\r
261         return GetSystemMetrics( SM_MOUSEPRESENT );\r
262 \r
263     case GLUT_NUM_MOUSE_BUTTONS:\r
264 #  if defined(_WIN32_WCE)\r
265         return 1;\r
266 #  else\r
267         return GetSystemMetrics( SM_CMOUSEBUTTONS );\r
268 #  endif\r
269 \r
270     default:\r
271         fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat );\r
272         break;\r
273     }\r
274 \r
275     /* And now -- the failure. */\r
276     return -1;\r
277 }\r
278 \r
279 \r
280 int fgPlatformGlutLayerGet( GLenum eWhat )\r
281 {\r
282     /*\r
283      * This is easy as layers are not implemented ;-)\r
284      *\r
285      * XXX Can we merge the UNIX/X11 and WIN32 sections?  Or\r
286      * XXX is overlay support planned?\r
287      */\r
288     switch( eWhat )\r
289     {\r
290 \r
291     case GLUT_OVERLAY_POSSIBLE:\r
292 /*      return fgSetupPixelFormat( fgStructure.CurrentWindow, GL_TRUE,\r
293                                    PFD_OVERLAY_PLANE ); */\r
294       return 0 ;\r
295 \r
296     case GLUT_LAYER_IN_USE:\r
297         return GLUT_NORMAL;\r
298 \r
299     case GLUT_HAS_OVERLAY:\r
300         return 0;\r
301 \r
302     case GLUT_TRANSPARENT_INDEX:\r
303         /*\r
304          * Return just anything, which is always defined as zero\r
305          *\r
306          * XXX HUH?\r
307          */\r
308         return 0;\r
309 \r
310     case GLUT_NORMAL_DAMAGED:\r
311         /* XXX Actually I do not know. Maybe. */\r
312         return 0;\r
313 \r
314     case GLUT_OVERLAY_DAMAGED:\r
315         return -1;\r
316 \r
317     default:\r
318         fgWarning( "glutLayerGet(): missing enum handle %d", eWhat );\r
319         break;\r
320     }\r
321 \r
322     /* And fail. That's good. Programs do love failing. */\r
323     return -1;\r
324 }\r
325 \r
326 \r
327 \r