From f0ba4e97608a444ae0a94e2408ed1a647ee38672 Mon Sep 17 00:00:00 2001 From: Diederick Niehorster Date: Fri, 1 Mar 2013 17:20:47 +0000 Subject: [PATCH] implemented glutSetIconTitle that works on win32, when a window is minimized, its title is now changed, and changed back when it is restored git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1543 7f0cb862-5218-0410-a997-914c9d46530a --- progs/demos/CallbackMaker/CallbackMaker.c | 1 + src/fg_structure.c | 9 +++++--- src/mswin/fg_internal_mswin.h | 8 +++++++ src/mswin/fg_main_mswin.c | 14 ++++++++++++ src/mswin/fg_window_mswin.c | 34 +++++++++++++++++++---------- 5 files changed, 52 insertions(+), 14 deletions(-) diff --git a/progs/demos/CallbackMaker/CallbackMaker.c b/progs/demos/CallbackMaker/CallbackMaker.c index 43c31ba..b6bb7dc 100644 --- a/progs/demos/CallbackMaker/CallbackMaker.c +++ b/progs/demos/CallbackMaker/CallbackMaker.c @@ -650,6 +650,7 @@ main(int argc, char *argv[]) /* callbacks, settings and menus for this window */ SetWindowCallbacks( 1 ); glutIgnoreKeyRepeat(GL_TRUE); + glutSetIconTitle("Icon Test - Callback Demo"); subMenuA = glutCreateMenu( MenuCallback ); glutAddMenuEntry( "Sub menu A1 (01)", 11 ); diff --git a/src/fg_structure.c b/src/fg_structure.c index 8a5b4f5..88b2614 100644 --- a/src/fg_structure.c +++ b/src/fg_structure.c @@ -92,14 +92,17 @@ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, /* Set the default mouse cursor and reset the modifiers value */ window->State.Cursor = GLUT_CURSOR_INHERIT; - - window->IsMenu = isMenu; - + window->State.IgnoreKeyRepeat = GL_FALSE; window->State.KeyRepeating = GL_FALSE; window->State.IsFullscreen = GL_FALSE; window->State.VisualizeNormals= GL_FALSE; + window->State.pWState.WindowTitle = NULL; + window->State.pWState.IconTitle = NULL; + + window->IsMenu = isMenu; + /* * Open the window now. The fgOpenWindow() function is system * dependant, and resides in freeglut_window.c. Uses fgState. diff --git a/src/mswin/fg_internal_mswin.h b/src/mswin/fg_internal_mswin.h index 3e7d5c7..0e97c95 100644 --- a/src/mswin/fg_internal_mswin.h +++ b/src/mswin/fg_internal_mswin.h @@ -98,6 +98,14 @@ struct tagSFG_PlatformWindowState GLboolean MouseTracking; /* Needed for generating GLUT_ENTERED and GLUT_LEFT entry func callbacks on windows */ GLboolean WindowFuncCalled; /* Indicate whether windowStatus/visibility func was notified that this window was created */ + + /* Need to store window titles to emulate + * glutSetIconTitle/glutSetWindowTitle as Windows has only + * one title associated with a window and we need to swap + * them out based on the window's iconic state + */ + char* WindowTitle; + char* IconTitle; }; diff --git a/src/mswin/fg_main_mswin.c b/src/mswin/fg_main_mswin.c index 656ae51..3cbac50 100644 --- a/src/mswin/fg_main_mswin.c +++ b/src/mswin/fg_main_mswin.c @@ -135,7 +135,21 @@ static void fghUpdateWindowStatus(SFG_Window *window, GLboolean visState) if (window->State.Visible != visState) { window->State.Visible = visState; + /* On win32 we only have two states, window displayed and window not displayed (iconified) + * We map these to GLUT_FULLY_RETAINED and GLUT_HIDDEN respectively. + */ INVOKE_WCB( *window, WindowStatus, ( visState ? GLUT_FULLY_RETAINED:GLUT_HIDDEN ) ); + + /* If top level window (not a subwindow/child), and icon title text available, switch titles based on visibility state */ + if (!window->Parent && window->State.pWState.IconTitle) + { + if (visState) + /* visible, set window title */ + SetWindowText( window->Window.Handle, window->State.pWState.WindowTitle ); + else + /* not visible, set icon title */ + SetWindowText( window->Window.Handle, window->State.pWState.IconTitle ); + } } /* Also set visibility state for children */ diff --git a/src/mswin/fg_window_mswin.c b/src/mswin/fg_window_mswin.c index dd4d3a8..dbc87b1 100644 --- a/src/mswin/fg_window_mswin.c +++ b/src/mswin/fg_window_mswin.c @@ -702,6 +702,12 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, if( !( window->Window.Handle ) ) fgError( "Failed to create a window (%s)!", title ); + /* Store title */ + { + window->State.pWState.WindowTitle = malloc (strlen(title) + 1); + strcpy(window->State.pWState.WindowTitle, title); + } + #if !defined(_WIN32_WCE) /* Need to set requested style again, apparently Windows doesn't listen when requesting windows without title bar or borders */ SetWindowLong(window->Window.Handle, GWL_STYLE, flags); @@ -859,6 +865,12 @@ void fgPlatformCloseWindow( SFG_Window* window ) } DestroyWindow( window->Window.Handle ); + + /* clean up copied title text(s) */ + if (window->State.pWState.WindowTitle) + free(window->State.pWState.WindowTitle); + if (window->State.pWState.IconTitle) + free(window->State.pWState.IconTitle); } @@ -908,24 +920,24 @@ void fgPlatformGlutSetWindowTitle( const char* title ) #else SetWindowText( fgStructure.CurrentWindow->Window.Handle, title ); #endif + + /* Make copy of string to refer to later */ + if (fgStructure.CurrentWindow->State.pWState.WindowTitle) + free(fgStructure.CurrentWindow->State.pWState.WindowTitle); + fgStructure.CurrentWindow->State.pWState.WindowTitle = malloc (strlen(title) + 1); + strcpy(fgStructure.CurrentWindow->State.pWState.WindowTitle, title); } /* * Set the current window's iconified title - * There really isn't a way to set the icon name separate from the - * windows name in Win32, so, just set the windows name. */ void fgPlatformGlutSetIconTitle( const char* title ) { -#ifdef _WIN32_WCE - { - wchar_t* wstr = fghWstrFromStr(title); - SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr ); - free(wstr); - } -#else - SetWindowText( fgStructure.CurrentWindow->Window.Handle, title ); -#endif + /* Make copy of string to refer to later */ + if (fgStructure.CurrentWindow->State.pWState.IconTitle) + free(fgStructure.CurrentWindow->State.pWState.IconTitle); + fgStructure.CurrentWindow->State.pWState.IconTitle = malloc (strlen(title) + 1); + strcpy(fgStructure.CurrentWindow->State.pWState.IconTitle, title); } /* -- 1.7.10.4