<commit_before>/*************** <auto-copyright.pl BEGIN do not edit this line> **************
 *
 * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
 *
 * Original Authors:
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * -----------------------------------------------------------------
 * File:          $RCSfile$
 * Date modified: $Date$
 * Version:       $Revision$
 * -----------------------------------------------------------------
 *
 *************** <auto-copyright.pl END do not edit this line> ***************/

#include <vrj/vrjConfig.h>

#include <iomanip>

#include <jccl/Config/ConfigElement.h>

#include <vpr/Util/Assert.h>
#include <gadget/InputManager.h>
#include <vrj/Util/Debug.h>
#include <vrj/Kernel/Kernel.h>
#include <vrj/Display/Display.h>
#include <vrj/Display/DisplayManager.h>
#include <vrj/Draw/OGL/GlWindow.h>
#include <vrj/Draw/OGL/GlWindowWin32.h>

static const char* GL_WINDOW_WIN32_CLASSNAME("vrj::GlWindowWin32");

namespace vrj
{

GlWindowWin32::GlWindowWin32()
   : mRenderContext(NULL)
   , mDeviceContext(NULL)
{
   // Event processing is not blocking.
   mBlocking = false;
}

GlWindowWin32::~GlWindowWin32()
{
   this->close();
}

// Open the window
// - Creates a window
// - Creates a rendering context
// - Registers new window with the window list
bool GlWindowWin32::open()
{
   if ( false == GlWindowWin32::registerWindowClass() )
   {
      return false;
   }
   
   if ( mWindowIsOpen )
   {
      return true;
   }

   HMODULE hMod = GetModuleHandle(NULL);
   DWORD style;
   int root_height;

   // OpenGL requires WS_CLIPCHILDREN and WS_CLIPSIBLINGS.
   style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;

   // If we want a border, create an overlapped window.  This will have
   // a titlebar and a border.
   if ( mHasBorder )
   {
      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HVERB_LVL)
         << "[vrj::GlWindowWin32::open()] Attempting to give window a border"
         << std::endl << vprDEBUG_FLUSH;
      style |= WS_OVERLAPPEDWINDOW;
   }
   // Otherwise, come as close as possible to having no border by using
   // the thin-line border.
   else
   {
      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HVERB_LVL)
         << "[vrj::GlWindowWin32::open()] Attempting to make window borderless"
         << std::endl << vprDEBUG_FLUSH;
      style |= WS_OVERLAPPED | WS_POPUP | WS_VISIBLE;
   }

   root_height = GetSystemMetrics(SM_CYSCREEN);

   // Create the main application window
   mWinHandle = CreateWindow(GL_WINDOW_WIN32_CLASSNAME, mWindowName.c_str(),
                             style, mOriginX,
                             root_height - mOriginY - mWindowHeight,
                             mWindowWidth, mWindowHeight, NULL, NULL, hMod,
                             NULL);

   // If window was not created, quit
   if ( NULL == mWinHandle )
   {
      doInternalError("Could not create GlWindowWin32!");
      return false;
   }

   // Attach a pointer to the device for use from the WNDPROC
   SetWindowLong(mWinHandle, GWL_USERDATA, (LPARAM) this);

   // We have a valid window, so... Create the context
   mDeviceContext = GetDC(mWinHandle);            // Store the device context
   if ( false == setPixelFormat(mDeviceContext) ) // Select the pixel format
   {
      return false;
   }

   // Create the rendering context and make it current
   mRenderContext = wglCreateContext(mDeviceContext);

   if ( NULL == mRenderContext )
   {
      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CRITICAL_LVL)
         << "ERROR: [vrj::GlWindowWin32::open()] wglCreateContext() failed "
         << "with error code " << GetLastError() << std::endl
         << vprDEBUG_FLUSH;
      return false;
   }

   wglMakeCurrent(mDeviceContext, mRenderContext);

   // Register the window with the window list
   GlWindowWin32::addWindow(mWinHandle,this);

   // Display the window
   ShowWindow(mWinHandle, SW_SHOW);
   UpdateWindow(mWinHandle);             // Tell the window to paint
   mWindowIsOpen = true;

   // If mHideMouse is true we must pass false to ShowCursor
   ShowCursor(! mHideMouse);

   return true;
}

/**
 * Closes the OpenGL window.
 * @note Must be called by the same thread that called open.
 */
bool GlWindowWin32::close()
{
   // if not open, then don't bother.
   if ( !mWindowIsOpen )
   {
      return false;
   }

   // Remove window from window list
   GlWindowWin32::removeWindow(mWinHandle);

   mWindowIsOpen = false;

   // destroy the win32 window
   return(1 == DestroyWindow(mWinHandle));
}

/**
 * Sets the current OpenGL context to this window.
 * @post this.context is active context.
 */
bool GlWindowWin32::makeCurrent()
{
   vprASSERT((mDeviceContext != NULL) && (mRenderContext != NULL));
   wglMakeCurrent(mDeviceContext, mRenderContext);  // Make our context current
   return true;
}

// Swap the front and back buffers
// Process events here
void GlWindowWin32::swapBuffers()
{
   vprASSERT(mDeviceContext != NULL);
   SwapBuffers(mDeviceContext);
}


void GlWindowWin32::checkEvents()
{
   handleEvents();
}

void GlWindowWin32::configWindow(vrj::Display* disp)
{
   const char neg_one_STRING[] = "-1";
   vprASSERT( disp != NULL );
   vrj::GlWindow::configWindow(disp);

   // Get the vector of display chunks
   jccl::ConfigElementPtr disp_sys_elt =
      DisplayManager::instance()->getDisplaySystemElement();
   jccl::ConfigElementPtr display_elt = disp->getConfigElement();

   // Get the lock KeyboardMouseDevice information.
   gadget::InputArea::config(display_elt);

   mWindowName = disp->getName();
   mPipe = disp->getPipe();
   vprASSERT(mPipe >= 0);

   mXDisplayName = disp_sys_elt->getProperty<std::string>("x11_pipes", mPipe);
   if (mXDisplayName == neg_one_STRING)    // Use display env
   {
       const std::string DISPLAY_str("DISPLAY");
       const char* d = getenv(DISPLAY_str.c_str());
       if (NULL != d)
       {
          mXDisplayName = std::string( d );
       }
   }
   vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_VERB_LVL)
      << "glxWindow::config: display name is: "
      << mXDisplayName << std::endl << vprDEBUG_FLUSH;
}

// WindowProcedure to deal with the generated messages.
// Called only for the window that we are controlling.
LRESULT GlWindowWin32::handleEvent(HWND hWnd, UINT message, WPARAM wParam,
                                   LPARAM lParam)
{
   switch ( message )
   {
      // ---- Window creation, setup for OpenGL ---- //
      case WM_CREATE:
         vprASSERT(false);                               // Should never get called because
                                                         //we are not registered when this gets called

         mDeviceContext = GetDC(hWnd);                   // Store the device context
         if ( false == setPixelFormat(mDeviceContext) )  // Select the pixel format
         {
            return 0;
         }

         // Create the rendering context and make it current
         mRenderContext = wglCreateContext(mDeviceContext);
         wglMakeCurrent(mDeviceContext, mRenderContext);
         break;<commit_msg>Updated output to reflect the correct name of the function from which the output is generated.<commit_after>/*************** <auto-copyright.pl BEGIN do not edit this line> **************
 *
 * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
 *
 * Original Authors:
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * -----------------------------------------------------------------
 * File:          $RCSfile$
 * Date modified: $Date$
 * Version:       $Revision$
 * -----------------------------------------------------------------
 *
 *************** <auto-copyright.pl END do not edit this line> ***************/

#include <vrj/vrjConfig.h>

#include <iomanip>

#include <jccl/Config/ConfigElement.h>

#include <vpr/Util/Assert.h>
#include <gadget/InputManager.h>
#include <vrj/Util/Debug.h>
#include <vrj/Kernel/Kernel.h>
#include <vrj/Display/Display.h>
#include <vrj/Display/DisplayManager.h>
#include <vrj/Draw/OGL/GlWindow.h>
#include <vrj/Draw/OGL/GlWindowWin32.h>

static const char* GL_WINDOW_WIN32_CLASSNAME("vrj::GlWindowWin32");

namespace vrj
{

GlWindowWin32::GlWindowWin32()
   : mRenderContext(NULL)
   , mDeviceContext(NULL)
{
   // Event processing is not blocking.
   mBlocking = false;
}

GlWindowWin32::~GlWindowWin32()
{
   this->close();
}

// Open the window
// - Creates a window
// - Creates a rendering context
// - Registers new window with the window list
bool GlWindowWin32::open()
{
   if ( false == GlWindowWin32::registerWindowClass() )
   {
      return false;
   }
   
   if ( mWindowIsOpen )
   {
      return true;
   }

   HMODULE hMod = GetModuleHandle(NULL);
   DWORD style;
   int root_height;

   // OpenGL requires WS_CLIPCHILDREN and WS_CLIPSIBLINGS.
   style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;

   // If we want a border, create an overlapped window.  This will have
   // a titlebar and a border.
   if ( mHasBorder )
   {
      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HVERB_LVL)
         << "[vrj::GlWindowWin32::open()] Attempting to give window a border"
         << std::endl << vprDEBUG_FLUSH;
      style |= WS_OVERLAPPEDWINDOW;
   }
   // Otherwise, come as close as possible to having no border by using
   // the thin-line border.
   else
   {
      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HVERB_LVL)
         << "[vrj::GlWindowWin32::open()] Attempting to make window borderless"
         << std::endl << vprDEBUG_FLUSH;
      style |= WS_OVERLAPPED | WS_POPUP | WS_VISIBLE;
   }

   root_height = GetSystemMetrics(SM_CYSCREEN);

   // Create the main application window
   mWinHandle = CreateWindow(GL_WINDOW_WIN32_CLASSNAME, mWindowName.c_str(),
                             style, mOriginX,
                             root_height - mOriginY - mWindowHeight,
                             mWindowWidth, mWindowHeight, NULL, NULL, hMod,
                             NULL);

   // If window was not created, quit
   if ( NULL == mWinHandle )
   {
      doInternalError("Could not create GlWindowWin32!");
      return false;
   }

   // Attach a pointer to the device for use from the WNDPROC
   SetWindowLong(mWinHandle, GWL_USERDATA, (LPARAM) this);

   // We have a valid window, so... Create the context
   mDeviceContext = GetDC(mWinHandle);            // Store the device context
   if ( false == setPixelFormat(mDeviceContext) ) // Select the pixel format
   {
      return false;
   }

   // Create the rendering context and make it current
   mRenderContext = wglCreateContext(mDeviceContext);

   if ( NULL == mRenderContext )
   {
      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CRITICAL_LVL)
         << "ERROR: [vrj::GlWindowWin32::open()] wglCreateContext() failed "
         << "with error code " << GetLastError() << std::endl
         << vprDEBUG_FLUSH;
      return false;
   }

   wglMakeCurrent(mDeviceContext, mRenderContext);

   // Register the window with the window list
   GlWindowWin32::addWindow(mWinHandle,this);

   // Display the window
   ShowWindow(mWinHandle, SW_SHOW);
   UpdateWindow(mWinHandle);             // Tell the window to paint
   mWindowIsOpen = true;

   // If mHideMouse is true we must pass false to ShowCursor
   ShowCursor(! mHideMouse);

   return true;
}

/**
 * Closes the OpenGL window.
 * @note Must be called by the same thread that called open.
 */
bool GlWindowWin32::close()
{
   // if not open, then don't bother.
   if ( !mWindowIsOpen )
   {
      return false;
   }

   // Remove window from window list
   GlWindowWin32::removeWindow(mWinHandle);

   mWindowIsOpen = false;

   // destroy the win32 window
   return(1 == DestroyWindow(mWinHandle));
}

/**
 * Sets the current OpenGL context to this window.
 * @post this.context is active context.
 */
bool GlWindowWin32::makeCurrent()
{
   vprASSERT((mDeviceContext != NULL) && (mRenderContext != NULL));
   wglMakeCurrent(mDeviceContext, mRenderContext);  // Make our context current
   return true;
}

// Swap the front and back buffers
// Process events here
void GlWindowWin32::swapBuffers()
{
   vprASSERT(mDeviceContext != NULL);
   SwapBuffers(mDeviceContext);
}


void GlWindowWin32::checkEvents()
{
   handleEvents();
}

void GlWindowWin32::configWindow(vrj::Display* disp)
{
   const char neg_one_STRING[] = "-1";
   vprASSERT( disp != NULL );
   vrj::GlWindow::configWindow(disp);

   // Get the vector of display chunks
   jccl::ConfigElementPtr disp_sys_elt =
      DisplayManager::instance()->getDisplaySystemElement();
   jccl::ConfigElementPtr display_elt = disp->getConfigElement();

   // Get the lock KeyboardMouseDevice information.
   gadget::InputArea::config(display_elt);

   mWindowName = disp->getName();
   mPipe = disp->getPipe();
   vprASSERT(mPipe >= 0);

   mXDisplayName = disp_sys_elt->getProperty<std::string>("x11_pipes", mPipe);
   if (mXDisplayName == neg_one_STRING)    // Use display env
   {
       const std::string DISPLAY_str("DISPLAY");
       const char* d = getenv(DISPLAY_str.c_str());
       if (NULL != d)
       {
          mXDisplayName = std::string( d );
       }
   }
   vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_VERB_LVL)
      << "[vrj::GlWindowWin32::configWindow()] display name is: "
      << mXDisplayName << std::endl << vprDEBUG_FLUSH;
}

// WindowProcedure to deal with the generated messages.
// Called only for the window that we are controlling.
LRESULT GlWindowWin32::handleEvent(HWND hWnd, UINT message, WPARAM wParam,
                                   LPARAM lParam)
{
   switch ( message )
   {
      // ---- Window creation, setup for OpenGL ---- //
      case WM_CREATE:
         vprASSERT(false);                               // Should never get called because
                                                         //we are not registered when this gets called

         mDeviceContext = GetDC(hWnd);                   // Store the device context
         if ( false == setPixelFormat(mDeviceContext) )  // Select the pixel format
         {
            return 0;
         }

         // Create the rendering context and make it current
         mRenderContext = wglCreateContext(mDeviceContext);
         wglMakeCurrent(mDeviceContext, mRenderContext);
         break;
{'fraction_non_alphanumeric': 0.12468827930174564, 'fraction_numerical': 0.009719291514802737, 'mean_word_length': 2.6670574443141852, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7052081', 'n_tokens_mistral': 4816, 'n_tokens_neox': 4648, 'n_words': 1348}