2 * freeglut_state_mswin.c
\r
4 * The Windows-specific mouse cursor related stuff.
\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
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
17 * The above copyright notice and this permission notice shall be included
\r
18 * in all copies or substantial portions of the Software.
\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
28 #include <GL/freeglut.h>
\r
29 #include "freeglut_internal_mswin.h"
\r
32 extern GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
\r
33 unsigned char layer_type );
\r
36 /* The following include file is available from SGI but is not standard:
\r
37 * #include <GL/wglext.h>
\r
38 * So we copy the necessary parts out of it to support the multisampling query
\r
40 #define WGL_SAMPLES_ARB 0x2042
\r
44 int fgPlatformGlutGet ( GLenum eWhat )
\r
47 GLboolean boolValue ;
\r
53 case GLUT_WINDOW_NUM_SAMPLES:
\r
54 glGetIntegerv(WGL_SAMPLES_ARB, &nsamples);
\r
57 /* Handle the OpenGL inquiries */
\r
58 case GLUT_WINDOW_RGBA:
\r
59 #if defined(_WIN32_WCE)
\r
60 boolValue = (GLboolean)0; /* WinCE doesn't support this feature */
\r
62 glGetBooleanv ( GL_RGBA_MODE, &boolValue );
\r
63 returnValue = boolValue ? 1 : 0;
\r
66 case GLUT_WINDOW_DOUBLEBUFFER:
\r
67 #if defined(_WIN32_WCE)
\r
68 boolValue = (GLboolean)0; /* WinCE doesn't support this feature */
\r
70 glGetBooleanv ( GL_DOUBLEBUFFER, &boolValue );
\r
71 returnValue = boolValue ? 1 : 0;
\r
74 case GLUT_WINDOW_STEREO:
\r
75 #if defined(_WIN32_WCE)
\r
76 boolValue = (GLboolean)0; /* WinCE doesn't support this feature */
\r
78 glGetBooleanv ( GL_STEREO, &boolValue );
\r
79 returnValue = boolValue ? 1 : 0;
\r
83 case GLUT_WINDOW_RED_SIZE:
\r
84 glGetIntegerv ( GL_RED_BITS, &returnValue );
\r
86 case GLUT_WINDOW_GREEN_SIZE:
\r
87 glGetIntegerv ( GL_GREEN_BITS, &returnValue );
\r
89 case GLUT_WINDOW_BLUE_SIZE:
\r
90 glGetIntegerv ( GL_BLUE_BITS, &returnValue );
\r
92 case GLUT_WINDOW_ALPHA_SIZE:
\r
93 glGetIntegerv ( GL_ALPHA_BITS, &returnValue );
\r
95 case GLUT_WINDOW_ACCUM_RED_SIZE:
\r
96 #if defined(_WIN32_WCE)
\r
97 returnValue = 0; /* WinCE doesn't support this feature */
\r
99 glGetIntegerv ( GL_ACCUM_RED_BITS, &returnValue );
\r
101 return returnValue;
\r
102 case GLUT_WINDOW_ACCUM_GREEN_SIZE:
\r
103 #if defined(_WIN32_WCE)
\r
104 returnValue = 0; /* WinCE doesn't support this feature */
\r
106 glGetIntegerv ( GL_ACCUM_GREEN_BITS, &returnValue );
\r
108 return returnValue;
\r
109 case GLUT_WINDOW_ACCUM_BLUE_SIZE:
\r
110 #if defined(_WIN32_WCE)
\r
111 returnValue = 0; /* WinCE doesn't support this feature */
\r
113 glGetIntegerv ( GL_ACCUM_BLUE_BITS, &returnValue );
\r
115 return returnValue;
\r
116 case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
\r
117 #if defined(_WIN32_WCE)
\r
118 returnValue = 0; /* WinCE doesn't support this feature */
\r
120 glGetIntegerv ( GL_ACCUM_ALPHA_BITS, &returnValue );
\r
122 return returnValue;
\r
123 case GLUT_WINDOW_DEPTH_SIZE:
\r
124 glGetIntegerv ( GL_DEPTH_BITS, &returnValue );
\r
125 return returnValue;
\r
127 case GLUT_WINDOW_BUFFER_SIZE:
\r
128 returnValue = 1 ; /* ????? */
\r
129 return returnValue;
\r
130 case GLUT_WINDOW_STENCIL_SIZE:
\r
131 returnValue = 0 ; /* ????? */
\r
132 return returnValue;
\r
134 case GLUT_WINDOW_X:
\r
135 case GLUT_WINDOW_Y:
\r
136 case GLUT_WINDOW_WIDTH:
\r
137 case GLUT_WINDOW_HEIGHT:
\r
140 * There is considerable confusion about the "right thing to
\r
141 * do" concerning window size and position. GLUT itself is
\r
142 * not consistent between Windows and UNIX/X11; since
\r
143 * platform independence is a virtue for "freeglut", we
\r
144 * decided to break with GLUT's behaviour.
\r
146 * Under UNIX/X11, it is apparently not possible to get the
\r
147 * window border sizes in order to subtract them off the
\r
148 * window's initial position until some time after the window
\r
149 * has been created. Therefore we decided on the following
\r
150 * behaviour, both under Windows and under UNIX/X11:
\r
151 * - When you create a window with position (x,y) and size
\r
152 * (w,h), the upper left hand corner of the outside of the
\r
153 * window is at (x,y) and the size of the drawable area is
\r
155 * - When you query the size and position of the window--as
\r
156 * is happening here for Windows--"freeglut" will return
\r
157 * the size of the drawable area--the (w,h) that you
\r
158 * specified when you created the window--and the coordinates
\r
159 * of the upper left hand corner of the drawable
\r
160 * area--which is NOT the (x,y) you specified.
\r
165 freeglut_return_val_if_fail( fgStructure.CurrentWindow != NULL, 0 );
\r
167 #if defined(_WIN32_WCE)
\r
168 GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
\r
170 winRect = fghGetClientArea(fgStructure.CurrentWindow, FALSE);
\r
171 #endif /* defined(_WIN32_WCE) */
\r
175 case GLUT_WINDOW_X: return winRect.left ;
\r
176 case GLUT_WINDOW_Y: return winRect.top ;
\r
177 case GLUT_WINDOW_WIDTH: return winRect.right - winRect.left;
\r
178 case GLUT_WINDOW_HEIGHT: return winRect.bottom - winRect.top;
\r
183 case GLUT_WINDOW_BORDER_WIDTH :
\r
184 case GLUT_WINDOW_HEADER_HEIGHT :
\r
185 #if defined(_WIN32_WCE)
\r
191 if (fgStructure.CurrentWindow && fgStructure.CurrentWindow->Window.Handle)
\r
192 windowStyle = GetWindowLong(fgStructure.CurrentWindow->Window.Handle, GWL_STYLE);
\r
194 /* If no window, return sizes for a default window with title bar and border */
\r
195 windowStyle = WS_OVERLAPPEDWINDOW;
\r
199 case GLUT_WINDOW_BORDER_WIDTH:
\r
201 int xBorderWidth, yBorderWidth;
\r
202 fghGetBorderWidth(windowStyle, &xBorderWidth, &yBorderWidth);
\r
203 return xBorderWidth;
\r
205 case GLUT_WINDOW_HEADER_HEIGHT:
\r
206 /* 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
207 return (windowStyle & WS_MAXIMIZEBOX)? GetSystemMetrics( SM_CYCAPTION ) : 0;
\r
210 #endif /* defined(_WIN32_WCE) */
\r
212 case GLUT_DISPLAY_MODE_POSSIBLE:
\r
213 #if defined(_WIN32_WCE)
\r
216 return fgSetupPixelFormat( fgStructure.CurrentWindow, GL_TRUE,
\r
218 #endif /* defined(_WIN32_WCE) */
\r
221 case GLUT_WINDOW_FORMAT_ID:
\r
222 #if !defined(_WIN32_WCE)
\r
223 if( fgStructure.CurrentWindow != NULL )
\r
224 return GetPixelFormat( fgStructure.CurrentWindow->Window.Device );
\r
225 #endif /* defined(_WIN32_WCE) */
\r
229 fgWarning( "glutGet(): missing enum handle %d", eWhat );
\r
237 int fgPlatformGlutDeviceGet ( GLenum eWhat )
\r
241 case GLUT_HAS_KEYBOARD:
\r
243 * Win32 is assumed a keyboard, and this cannot be queried,
\r
244 * except for WindowsCE.
\r
246 * X11 has a core keyboard by definition, although it can
\r
247 * be present as a virtual/dummy keyboard. For now, there
\r
248 * is no reliable way to tell if a real keyboard is present.
\r
250 #if defined(_WIN32_CE)
\r
251 return ( GetKeyboardStatus() & KBDI_KEYBOARD_PRESENT ) ? 1 : 0;
\r
252 # if FREEGLUT_LIB_PRAGMAS
\r
253 # pragma comment (lib,"Kbdui.lib")
\r
260 case GLUT_HAS_MOUSE:
\r
262 * MS Windows can be booted without a mouse.
\r
264 return GetSystemMetrics( SM_MOUSEPRESENT );
\r
266 case GLUT_NUM_MOUSE_BUTTONS:
\r
267 # if defined(_WIN32_WCE)
\r
270 return GetSystemMetrics( SM_CMOUSEBUTTONS );
\r
274 fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat );
\r
278 /* And now -- the failure. */
\r
283 int fgPlatformGlutLayerGet( GLenum eWhat )
\r
286 * This is easy as layers are not implemented ;-)
\r
288 * XXX Can we merge the UNIX/X11 and WIN32 sections? Or
\r
289 * XXX is overlay support planned?
\r
294 case GLUT_OVERLAY_POSSIBLE:
\r
295 /* return fgSetupPixelFormat( fgStructure.CurrentWindow, GL_TRUE,
\r
296 PFD_OVERLAY_PLANE ); */
\r
299 case GLUT_LAYER_IN_USE:
\r
300 return GLUT_NORMAL;
\r
302 case GLUT_HAS_OVERLAY:
\r
305 case GLUT_TRANSPARENT_INDEX:
\r
307 * Return just anything, which is always defined as zero
\r
313 case GLUT_NORMAL_DAMAGED:
\r
314 /* XXX Actually I do not know. Maybe. */
\r
317 case GLUT_OVERLAY_DAMAGED:
\r
321 fgWarning( "glutLayerGet(): missing enum handle %d", eWhat );
\r
325 /* And fail. That's good. Programs do love failing. */
\r