4 * Window management methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #include <GL/freeglut.h>
33 #include "freeglut_internal.h"
37 #pragma comment( lib, "Aygshell.lib" )
39 static wchar_t* fghWstrFromStr(const char* str)
41 int i,len=strlen(str);
42 wchar_t* wstr = (wchar_t*)malloc(2*len+2);
50 #endif /* TARGET_HOST_WINCE */
53 * TODO BEFORE THE STABLE RELEASE:
55 * fgChooseVisual() -- OK, but what about glutInitDisplayString()?
56 * fgSetupPixelFormat -- ignores the display mode settings
57 * fgOpenWindow() -- check the Win32 version, -iconic handling!
58 * fgCloseWindow() -- check the Win32 version
59 * glutCreateWindow() -- Check when default position and size is {-1,-1}
60 * glutCreateSubWindow() -- Check when default position and size is {-1,-1}
61 * glutDestroyWindow() -- check the Win32 version
62 * glutSetWindow() -- check the Win32 version
63 * glutGetWindow() -- OK
64 * glutSetWindowTitle() -- check the Win32 version
65 * glutSetIconTitle() -- check the Win32 version
66 * glutShowWindow() -- check the Win32 version
67 * glutHideWindow() -- check the Win32 version
68 * glutIconifyWindow() -- check the Win32 version
69 * glutReshapeWindow() -- check the Win32 version
70 * glutPositionWindow() -- check the Win32 version
71 * glutPushWindow() -- check the Win32 version
72 * glutPopWindow() -- check the Win32 version
75 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
78 * Chooses a visual basing on the current display mode settings
80 #if TARGET_HOST_UNIX_X11
82 XVisualInfo* fgChooseVisual( void )
84 #define BUFFER_SIZES 6
85 int bufferSize[BUFFER_SIZES] = { 16, 12, 8, 4, 2, 1 };
86 GLboolean wantIndexedMode = GL_FALSE;
90 /* First we have to process the display mode settings... */
92 * XXX Why is there a semi-colon in this #define? The code
93 * XXX that uses the macro seems to always add more semicolons...
95 #define ATTRIB(a) attributes[where++]=a;
96 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
98 if( fgState.DisplayMode & GLUT_INDEX )
100 ATTRIB_VAL( GLX_BUFFER_SIZE, 8 );
101 wantIndexedMode = GL_TRUE;
106 ATTRIB_VAL( GLX_RED_SIZE, 1 );
107 ATTRIB_VAL( GLX_GREEN_SIZE, 1 );
108 ATTRIB_VAL( GLX_BLUE_SIZE, 1 );
109 if( fgState.DisplayMode & GLUT_ALPHA )
110 ATTRIB_VAL( GLX_ALPHA_SIZE, 1 );
113 if( fgState.DisplayMode & GLUT_DOUBLE )
114 ATTRIB( GLX_DOUBLEBUFFER );
116 if( fgState.DisplayMode & GLUT_STEREO )
117 ATTRIB( GLX_STEREO );
119 if( fgState.DisplayMode & GLUT_DEPTH )
120 ATTRIB_VAL( GLX_DEPTH_SIZE, 1 );
122 if( fgState.DisplayMode & GLUT_STENCIL )
123 ATTRIB_VAL( GLX_STENCIL_SIZE, 1 );
125 if( fgState.DisplayMode & GLUT_ACCUM )
127 ATTRIB_VAL( GLX_ACCUM_RED_SIZE, 1 );
128 ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 );
129 ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE, 1 );
130 if( fgState.DisplayMode & GLUT_ALPHA )
131 ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 );
134 /* Push a null at the end of the list */
137 if( ! wantIndexedMode )
138 return glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
142 XVisualInfo* visualInfo;
146 * In indexed mode, we need to check how many bits of depth can we
147 * achieve. We do this by trying each possibility from the list
148 * given in the {bufferSize} array. If we match, we return to caller.
150 for( i=0; i<BUFFER_SIZES; i++ )
152 attributes[ 1 ] = bufferSize[ i ];
153 visualInfo = glXChooseVisual( fgDisplay.Display, fgDisplay.Screen,
155 if( visualInfo != NULL )
164 * Setup the pixel format for a Win32 window
166 #if TARGET_HOST_WIN32
167 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
168 unsigned char layer_type )
170 #if TARGET_HOST_WINCE
173 PIXELFORMATDESCRIPTOR* ppfd, pfd;
174 int flags, pixelformat;
176 freeglut_return_val_if_fail( window != NULL, 0 );
177 flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
178 if( fgState.DisplayMode & GLUT_DOUBLE )
179 flags |= PFD_DOUBLEBUFFER;
181 #if defined(_MSC_VER)
182 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
185 /* Specify which pixel format do we opt for... */
186 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
189 pfd.iPixelType = PFD_TYPE_RGBA;
200 pfd.cAccumRedBits = 0;
201 pfd.cAccumGreenBits = 0;
202 pfd.cAccumBlueBits = 0;
203 pfd.cAccumAlphaBits = 0;
206 pfd.cStencilBits = 0;
209 pfd.cStencilBits = 8;
212 pfd.iLayerType = layer_type;
215 pfd.dwVisibleMask = 0;
216 pfd.dwDamageMask = 0;
218 pfd.cColorBits = (BYTE) GetDeviceCaps( window->Window.Device, BITSPIXEL );
221 pixelformat = ChoosePixelFormat( window->Window.Device, ppfd );
222 if( pixelformat == 0 )
227 return SetPixelFormat( window->Window.Device, pixelformat, ppfd );
228 #endif /* TARGET_HOST_WINCE */
233 * Sets the OpenGL context and the fgStructure "Current Window" pointer to
234 * the window structure passed in.
236 void fgSetWindow ( SFG_Window *window )
238 #if TARGET_HOST_UNIX_X11
242 window->Window.Handle,
243 window->Window.Context
245 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
246 if( fgStructure.Window )
247 ReleaseDC( fgStructure.Window->Window.Handle,
248 fgStructure.Window->Window.Device );
252 window->Window.Device = GetDC( window->Window.Handle );
254 window->Window.Device,
255 window->Window.Context
259 fgStructure.Window = window;
264 * Opens a window. Requires a SFG_Window object created and attached
265 * to the freeglut structure. OpenGL context is created here.
267 void fgOpenWindow( SFG_Window* window, const char* title,
268 int x, int y, int w, int h,
269 GLboolean gameMode, GLboolean isSubWindow )
271 #if TARGET_HOST_UNIX_X11
272 XSetWindowAttributes winAttr;
273 XTextProperty textProperty;
274 XSizeHints sizeHints;
279 * XXX fgChooseVisual() is a common part of all three.
280 * XXX With a little thought, we should be able to greatly
283 if( !window->IsMenu )
284 window->Window.VisualInfo = fgChooseVisual( );
285 else if( fgStructure.MenuContext )
286 window->Window.VisualInfo = fgChooseVisual( );
289 /* XXX Why are menus double- and depth-buffered? */
290 unsigned int current_DisplayMode = fgState.DisplayMode ;
291 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ;
292 window->Window.VisualInfo = fgChooseVisual( );
293 fgState.DisplayMode = current_DisplayMode ;
296 if( ! window->Window.VisualInfo )
299 * The "fgChooseVisual" returned a null meaning that the visual
300 * context is not available.
301 * Try a couple of variations to see if they will work.
303 if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
305 fgState.DisplayMode |= GLUT_DOUBLE ;
306 window->Window.VisualInfo = fgChooseVisual( );
307 fgState.DisplayMode &= ~GLUT_DOUBLE;
311 * GLUT also checks for multi-sampling, but I don't see that
312 * anywhere else in FREEGLUT so I won't bother with it for the moment.
316 FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.VisualInfo != NULL,
317 "Unable to get window visual info", "fgOpenWindow" );
320 * XXX HINT: the masks should be updated when adding/removing callbacks.
321 * XXX This might speed up message processing. Is that true?
323 * XXX A: Not appreciably, but it WILL make it easier to debug.
324 * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT
325 * XXX turns off events that it doesn't need and is a whole lot
326 * XXX more pleasant to trace. (Think mouse-motion! Tons of
327 * XXX ``bonus'' GUI events stream in.)
330 StructureNotifyMask | SubstructureNotifyMask | ExposureMask |
331 ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyRelease |
332 VisibilityChangeMask | EnterWindowMask | LeaveWindowMask |
333 PointerMotionMask | ButtonMotionMask;
334 winAttr.background_pixmap = None;
335 winAttr.background_pixel = 0;
336 winAttr.border_pixel = 0;
338 winAttr.colormap = XCreateColormap(
339 fgDisplay.Display, fgDisplay.RootWindow,
340 window->Window.VisualInfo->visual, AllocNone
343 mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
347 winAttr.override_redirect = True;
348 mask |= CWOverrideRedirect;
351 window->Window.Handle = XCreateWindow(
353 window->Parent == NULL ? fgDisplay.RootWindow :
354 window->Parent->Window.Handle,
356 window->Window.VisualInfo->depth, InputOutput,
357 window->Window.VisualInfo->visual, mask,
362 * The GLX context creation, possibly trying the direct context rendering
363 * or else use the current context if the user has so specified
368 * If there isn't already an OpenGL rendering context for menu
371 if( !fgStructure.MenuContext )
373 fgStructure.MenuContext =
374 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
375 fgStructure.MenuContext->VisualInfo = window->Window.VisualInfo;
376 fgStructure.MenuContext->Context = glXCreateContext(
377 fgDisplay.Display, fgStructure.MenuContext->VisualInfo,
378 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
382 /* window->Window.Context = fgStructure.MenuContext->Context; */
383 window->Window.Context = glXCreateContext(
384 fgDisplay.Display, window->Window.VisualInfo,
385 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
388 else if( fgState.UseCurrentContext )
390 window->Window.Context = glXGetCurrentContext( );
392 if( ! window->Window.Context )
393 window->Window.Context = glXCreateContext(
394 fgDisplay.Display, window->Window.VisualInfo,
395 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
399 window->Window.Context = glXCreateContext(
400 fgDisplay.Display, window->Window.VisualInfo,
401 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
404 #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ )
405 if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
407 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
408 fgError( "Unable to force direct context rendering for window '%s'",
410 else if( fgState.DirectContext == GLUT_TRY_DIRECT_CONTEXT )
411 fgWarning( "Unable to create direct context rendering for window '%s'\nThis may hurt performance.",
418 window->Window.Handle,
419 window->Window.Context
423 * XXX Assume the new window is visible by default
424 * XXX Is this a safe assumption?
426 window->State.Visible = GL_TRUE;
429 if ( fgState.Position.Use )
430 sizeHints.flags |= USPosition;
431 if ( fgState.Size.Use )
432 sizeHints.flags |= USSize;
435 * Fill in the size hints values now (the x, y, width and height
436 * settings are obsolete, are there any more WMs that support them?)
437 * Unless the X servers actually stop supporting these, we should
438 * continue to fill them in. It is *not* our place to tell the user
439 * that they should replace a window manager that they like, and which
440 * works, just because *we* think that it's not "modern" enough.
442 #if TARGET_HOST_WINCE /* Since this is in the X11 branch, it's pretty dumb */
445 sizeHints.width = 320;
446 sizeHints.height = 240;
451 sizeHints.height = h;
452 #endif /* TARGET_HOST_WINCE */
454 wmHints.flags = StateHint;
455 wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState;
456 /* Prepare the window and iconified window names... */
457 XStringListToTextProperty( (char **) &title, 1, &textProperty );
461 window->Window.Handle,
471 XSetWMProtocols( fgDisplay.Display, window->Window.Handle,
472 &fgDisplay.DeleteWindow, 1 );
474 XMapWindow( fgDisplay.Display, window->Window.Handle );
476 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
483 /* Grab the window class we have registered on glutInit(): */
484 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
485 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Info Not Found",
490 FREEGLUT_INTERNAL_ERROR_EXIT ( window->Parent == NULL,
491 "Game mode being invoked on a subwindow",
495 * Set the window creation flags appropriately to make the window
498 flags = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
502 #if !TARGET_HOST_WINCE
503 if ( ( ! isSubWindow ) && ( ! window->IsMenu ) )
506 * Update the window dimensions, taking account of window
507 * decorations. "freeglut" is to create the window with the
508 * outside of its border at (x,y) and with dimensions (w,h).
510 w += (GetSystemMetrics( SM_CXSIZEFRAME ) )*2;
511 h += (GetSystemMetrics( SM_CYSIZEFRAME ) )*2 +
512 GetSystemMetrics( SM_CYCAPTION );
514 #endif /* TARGET_HOST_WINCE */
516 if( ! fgState.Position.Use )
521 if( ! fgState.Size.Use )
528 * There's a small difference between creating the top, child and
531 flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
533 if ( window->IsMenu )
536 exFlags |= WS_EX_TOOLWINDOW;
538 #if !TARGET_HOST_WINCE
539 else if( window->Parent == NULL )
540 flags |= WS_OVERLAPPEDWINDOW;
546 #if TARGET_HOST_WINCE
548 wchar_t* wstr = fghWstrFromStr(title);
550 window->Window.Handle = CreateWindow(
553 WS_VISIBLE | WS_POPUP,
563 SHFullScreen(window->Window.Handle, SHFS_HIDESTARTICON);
564 SHFullScreen(window->Window.Handle, SHFS_HIDESIPBUTTON);
565 SHFullScreen(window->Window.Handle, SHFS_HIDETASKBAR);
566 MoveWindow(window->Window.Handle, 0, 0, 240, 320, TRUE);
567 ShowWindow(window->Window.Handle, SW_SHOW);
568 UpdateWindow(window->Window.Handle);
571 window->Window.Handle = CreateWindowEx(
577 (HWND) window->Parent == NULL ? NULL : window->Parent->Window.Handle,
582 #endif /* TARGET_HOST_WINCE */
584 if( !( window->Window.Handle ) )
585 fgError( "Failed to create a window (%s)!", title );
587 #if TARGET_HOST_WINCE
588 ShowWindow( window->Window.Handle, SW_SHOW );
590 ShowWindow( window->Window.Handle,
591 fgState.ForceIconic ? SW_SHOWMINIMIZED : SW_SHOW );
592 #endif /* TARGET_HOST_WINCE */
594 UpdateWindow( window->Window.Handle );
595 ShowCursor( TRUE ); /* XXX Old comments say "hide cusror"! */
599 fgSetWindow( window );
601 window->Window.DoubleBuffered =
602 ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
604 if ( ! window->Window.DoubleBuffered )
606 glDrawBuffer ( GL_FRONT );
607 glReadBuffer ( GL_FRONT );
612 * Closes a window, destroying the frame and OpenGL context
614 void fgCloseWindow( SFG_Window* window )
616 #if TARGET_HOST_UNIX_X11
618 glXDestroyContext( fgDisplay.Display, window->Window.Context );
619 XDestroyWindow( fgDisplay.Display, window->Window.Handle );
620 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
622 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
624 /* Make sure we don't close a window with current context active */
625 if( fgStructure.Window == window )
626 wglMakeCurrent( NULL, NULL );
629 * Step through the list of windows. If the rendering context
630 * is not being used by another window, then we delete it.
636 for( iter = (SFG_Window *)fgStructure.Windows.First;
638 iter = (SFG_Window *)iter->Node.Next )
640 if( ( iter->Window.Context == window->Window.Context ) &&
646 wglDeleteContext( window->Window.Context );
649 DestroyWindow( window->Window.Handle );
654 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
657 * Creates a new top-level freeglut window
659 int FGAPIENTRY glutCreateWindow( const char* title )
661 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateWindow" );
663 return fgCreateWindow( NULL, title, fgState.Position.X, fgState.Position.Y,
664 fgState.Size.X, fgState.Size.Y, GL_FALSE,
669 * This function creates a sub window.
671 int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
674 SFG_Window* window = NULL;
675 SFG_Window* parent = NULL;
677 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateSubWindow" );
678 parent = fgWindowByID( parentID );
679 freeglut_return_val_if_fail( parent != NULL, 0 );
680 window = fgCreateWindow( parent, "", x, y, w, h, GL_FALSE, GL_FALSE );
687 * Destroys a window and all of its subwindows
689 void FGAPIENTRY glutDestroyWindow( int windowID )
692 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDestroyWindow" );
693 window = fgWindowByID( windowID );
694 freeglut_return_if_fail( window != NULL );
696 fgExecutionState ExecState = fgState.ExecState;
697 fgAddToWindowDestroyList( window );
698 fgState.ExecState = ExecState;
703 * This function selects the current window
705 void FGAPIENTRY glutSetWindow( int ID )
707 SFG_Window* window = NULL;
709 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindow" );
710 if( fgStructure.Window != NULL )
711 if( fgStructure.Window->ID == ID )
714 window = fgWindowByID( ID );
717 fgWarning( "glutSetWindow(): window ID %d not found!", ID );
721 fgSetWindow( window );
725 * This function returns the ID number of the current window, 0 if none exists
727 int FGAPIENTRY glutGetWindow( void )
729 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindow" );
730 if( fgStructure.Window == NULL )
732 return fgStructure.Window->ID;
736 * This function makes the current window visible
738 void FGAPIENTRY glutShowWindow( void )
740 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" );
741 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" );
743 #if TARGET_HOST_UNIX_X11
745 XMapWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
746 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
748 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
750 ShowWindow( fgStructure.Window->Window.Handle, SW_SHOW );
754 fgStructure.Window->State.Redisplay = GL_TRUE;
758 * This function hides the current window
760 void FGAPIENTRY glutHideWindow( void )
762 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" );
763 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" );
765 #if TARGET_HOST_UNIX_X11
767 if( fgStructure.Window->Parent == NULL )
768 XWithdrawWindow( fgDisplay.Display,
769 fgStructure.Window->Window.Handle,
772 XUnmapWindow( fgDisplay.Display,
773 fgStructure.Window->Window.Handle );
774 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
776 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
778 ShowWindow( fgStructure.Window->Window.Handle, SW_HIDE );
782 fgStructure.Window->State.Redisplay = GL_FALSE;
786 * Iconify the current window (top-level windows only)
788 void FGAPIENTRY glutIconifyWindow( void )
790 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutIconifyWindow" );
791 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" );
793 fgStructure.Window->State.Visible = GL_FALSE;
794 #if TARGET_HOST_UNIX_X11
796 XIconifyWindow( fgDisplay.Display, fgStructure.Window->Window.Handle,
798 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
800 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
802 ShowWindow( fgStructure.Window->Window.Handle, SW_MINIMIZE );
806 fgStructure.Window->State.Redisplay = GL_FALSE;
810 * Set the current window's title
812 void FGAPIENTRY glutSetWindowTitle( const char* title )
814 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowTitle" );
815 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
816 if( ! fgStructure.Window->Parent )
818 #if TARGET_HOST_UNIX_X11
822 text.value = (unsigned char *) title;
823 text.encoding = XA_STRING;
825 text.nitems = strlen( title );
829 fgStructure.Window->Window.Handle,
833 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
835 #elif TARGET_HOST_WIN32
837 SetWindowText( fgStructure.Window->Window.Handle, title );
839 #elif TARGET_HOST_WINCE
841 wchar_t* wstr = fghWstrFromStr(title);
843 SetWindowText( fgStructure.Window->Window.Handle, wstr );
852 * Set the current window's iconified title
854 void FGAPIENTRY glutSetIconTitle( const char* title )
856 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
857 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );
859 if( ! fgStructure.Window->Parent )
861 #if TARGET_HOST_UNIX_X11
865 text.value = (unsigned char *) title;
866 text.encoding = XA_STRING;
868 text.nitems = strlen( title );
872 fgStructure.Window->Window.Handle,
876 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
878 #elif TARGET_HOST_WIN32
880 SetWindowText( fgStructure.Window->Window.Handle, title );
882 #elif TARGET_HOST_WINCE
884 wchar_t* wstr = fghWstrFromStr(title);
886 SetWindowText( fgStructure.Window->Window.Handle, wstr );
895 * Change the current window's size
897 void FGAPIENTRY glutReshapeWindow( int width, int height )
899 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutReshapeWindow" );
900 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutReshapeWindow" );
902 fgStructure.Window->State.NeedToResize = GL_TRUE;
903 fgStructure.Window->State.Width = width ;
904 fgStructure.Window->State.Height = height;
908 * Change the current window's position
910 void FGAPIENTRY glutPositionWindow( int x, int y )
912 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPositionWindow" );
913 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPositionWindow" );
915 #if TARGET_HOST_UNIX_X11
917 XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle,
919 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
921 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
926 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
927 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
929 fgStructure.Window->Window.Handle,
932 winRect.right - winRect.left,
933 winRect.bottom - winRect.top,
942 * Lowers the current window (by Z order change)
944 void FGAPIENTRY glutPushWindow( void )
946 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" );
947 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" );
949 #if TARGET_HOST_UNIX_X11
951 XLowerWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
953 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
956 fgStructure.Window->Window.Handle,
959 SWP_NOSIZE | SWP_NOMOVE
966 * Raises the current window (by Z order change)
968 void FGAPIENTRY glutPopWindow( void )
970 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" );
971 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" );
973 #if TARGET_HOST_UNIX_X11
975 XRaiseWindow( fgDisplay.Display, fgStructure.Window->Window.Handle );
977 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
980 fgStructure.Window->Window.Handle,
983 SWP_NOSIZE | SWP_NOMOVE
990 * Resize the current window so that it fits the whole screen
992 void FGAPIENTRY glutFullScreen( void )
994 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFullScreen" );
995 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutFullScreen" );
998 #if TARGET_HOST_UNIX_X11
1004 fgStructure.Window->Window.Handle,
1006 fgDisplay.ScreenWidth,
1007 fgDisplay.ScreenHeight
1010 XFlush( fgDisplay.Display ); /* This is needed */
1012 XTranslateCoordinates(
1014 fgStructure.Window->Window.Handle,
1015 fgDisplay.RootWindow,
1023 fgStructure.Window->Window.Handle,
1026 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
1028 #elif TARGET_HOST_WIN32
1031 /* For fullscreen mode, force the top-left corner to 0,0
1032 * and adjust the window rectangle so that the client area
1033 * covers the whole screen.
1038 rect.right = fgDisplay.ScreenWidth;
1039 rect.bottom = fgDisplay.ScreenHeight;
1041 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
1042 WS_CLIPCHILDREN, FALSE );
1045 * SWP_NOACTIVATE Do not activate the window
1046 * SWP_NOOWNERZORDER Do not change position in z-order
1047 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
1048 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
1051 SetWindowPos( fgStructure.Window->Window.Handle,
1055 rect.right - rect.left,
1056 rect.bottom - rect.top,
1057 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
1065 * A.Donev: Set and retrieve the window's user data
1067 void* FGAPIENTRY glutGetWindowData( void )
1069 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindowData" );
1070 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutGetWindowData" );
1071 return fgStructure.Window->UserData;
1074 void FGAPIENTRY glutSetWindowData(void* data)
1076 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetWindowData" );
1077 FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowData" );
1078 fgStructure.Window->UserData = data;
1081 /*** END OF FILE ***/