<commit_before>/*************** <auto-copyright.pl BEGIN do not edit this line> **************
 *
 * VR Juggler is (C) Copyright 1998-2010 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.
 *
 *************** <auto-copyright.pl END do not edit this line> ***************/

#include <vrj/Draw/OpenGL/Config.h>

#include <iomanip>

#include <jccl/Config/ConfigElement.h>

#include <vpr/vpr.h>
#include <vpr/System.h>
#include <vpr/Util/Assert.h>
#include <vpr/Perf/ProfileManager.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/OpenGL/Window.h>
#include <vrj/Draw/OpenGL/WindowWin32.h>

// The following is used below in
// vrj::opengl::WindowWin32::registerWindowClass(). The key parts are
// VJ_LIB_RT_OPT and VJ_VERSION_STR.
#  if defined(VJ_DEBUG)
#     if defined(_DEBUG)
#        define VJ_LIB_RT_OPT "_d"
#     else
#        define VJ_LIB_RT_OPT "_g"
#     endif
#  else
#     define VJ_LIB_RT_OPT ""
#  endif

#  define VJ_STRINGIZE(X) VJ_DO_STRINGIZE(X)
#  define VJ_DO_STRINGIZE(X) #X
#  define VJ_VERSION_STR VJ_STRINGIZE(__VJ_MAJOR__) "_" \
                         VJ_STRINGIZE(__VJ_MINOR__) "_" \
                         VJ_STRINGIZE(__VJ_PATCH__)


static const char* GL_WINDOW_WIN32_CLASSNAME("vrj::opengl::WindowWin32");

namespace vrj
{

namespace opengl
{

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

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

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

   if ( mWindowIsOpen )
   {
      return true;
   }

   HMODULE hMod = GetModuleHandle(NULL);
   int root_height;

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

   if ( mIsFullScreen )
   {
      style |= WS_MAXIMIZE | WS_POPUP;
      mWindowWidth  = GetSystemMetrics(SM_CXSCREEN);
      mWindowHeight = GetSystemMetrics(SM_CYSCREEN);
   }
   // If we want a border, create an overlapped window.  This will have
   // a titlebar and a border.
   else if ( mHasBorder )
   {
      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HVERB_LVL)
         << "[vrj::opengl::WindowWin32::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::opengl::WindowWin32::open()] Attempting to make window "
         << "borderless." << std::endl << vprDEBUG_FLUSH;
      style |= WS_OVERLAPPED | WS_POPUP | WS_VISIBLE;
   }

   DWORD ex_style(0);

   if ( mAlwaysOnTop )
   {
      ex_style = WS_EX_TOPMOST;
   }

   root_height = GetSystemMetrics(SM_CYSCREEN);

   // The desired client rectangle size (left, top, right, bottom).
   RECT rc = { 0, 0, mWindowWidth, mWindowHeight };

   if ( ! AdjustWindowRect(&rc, style, false) )
   {
      doInternalError("Failed to adjust window rectangle");
      return false;
   }

   // Ensure that the input window base class has the right dimension
   // information.
   InputAreaWin32::resize(mWindowWidth, mWindowHeight);

   // Create the main application window
   mWinHandle = CreateWindowEx(ex_style, GL_WINDOW_WIN32_CLASSNAME,
                               mWindowName.c_str(), style, mOriginX,
                               root_height - mOriginY - mWindowHeight,
                               rc.right - rc.left, rc.bottom - rc.top,
                               NULL, NULL, hMod, NULL);

   // If window was not created, quit
   if ( NULL == mWinHandle )
   {
      doInternalError("Could not create window using CreateWindowEx()!");<commit_msg>From the submitter:<commit_after>/*************** <auto-copyright.pl BEGIN do not edit this line> **************
 *
 * VR Juggler is (C) Copyright 1998-2010 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.
 *
 *************** <auto-copyright.pl END do not edit this line> ***************/

#include <vrj/Draw/OpenGL/Config.h>

#include <iomanip>

#include <jccl/Config/ConfigElement.h>

#include <vpr/vpr.h>
#include <vpr/System.h>
#include <vpr/Util/Assert.h>
#include <vpr/Perf/ProfileManager.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/OpenGL/Window.h>
#include <vrj/Draw/OpenGL/WindowWin32.h>

// The following is used below in
// vrj::opengl::WindowWin32::registerWindowClass(). The key parts are
// VJ_LIB_RT_OPT and VJ_VERSION_STR.
#  if defined(VJ_DEBUG)
#     if defined(_DEBUG)
#        define VJ_LIB_RT_OPT "_d"
#     else
#        define VJ_LIB_RT_OPT "_g"
#     endif
#  else
#     define VJ_LIB_RT_OPT ""
#  endif

#  define VJ_STRINGIZE(X) VJ_DO_STRINGIZE(X)
#  define VJ_DO_STRINGIZE(X) #X
#  define VJ_VERSION_STR VJ_STRINGIZE(__VJ_MAJOR__) "_" \
                         VJ_STRINGIZE(__VJ_MINOR__) "_" \
                         VJ_STRINGIZE(__VJ_PATCH__)


static const char* GL_WINDOW_WIN32_CLASSNAME("vrj::opengl::WindowWin32");

namespace vrj
{

namespace opengl
{

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

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

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

   if ( mWindowIsOpen )
   {
      return true;
   }

   HMODULE hMod = GetModuleHandle(NULL);
  
   // OpenGL requires WS_CLIPCHILDREN and WS_CLIPSIBLINGS.
   DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;

   if ( mIsFullScreen )
   {
      style |= WS_MAXIMIZE | WS_POPUP;
      mWindowWidth  = GetSystemMetrics(SM_CXSCREEN);
      mWindowHeight = GetSystemMetrics(SM_CYSCREEN);
   }
   // If we want a border, create an overlapped window.  This will have
   // a titlebar and a border.
   else if ( mHasBorder )
   {
      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HVERB_LVL)
         << "[vrj::opengl::WindowWin32::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::opengl::WindowWin32::open()] Attempting to make window "
         << "borderless." << std::endl << vprDEBUG_FLUSH;
      style |= WS_OVERLAPPED | WS_POPUP | WS_VISIBLE;
   }

   DWORD ex_style(0);

   if ( mAlwaysOnTop )
   {
      ex_style = WS_EX_TOPMOST;
   }

   int root_height = GetSystemMetrics(SM_CYSCREEN);

   // The desired client rectangle size (left, top, right, bottom).
   RECT rc = { 0, 0, mWindowWidth, mWindowHeight };

   if ( ! AdjustWindowRect(&rc, style, false) )
   {
      doInternalError("Failed to adjust window rectangle");
      return false;
   }

   // Ensure that the input window base class has the right dimension
   // information.
   InputAreaWin32::resize(mWindowWidth, mWindowHeight);

   int win32_y_origin = root_height - mOriginY - mWindowHeight;
   if ( mHasBorder )
   {
      // Get the border height to calculate the window origin properly
      // Height of the vertical border
      int verical_border_height = GetSystemMetrics(SM_CYFRAME);
      // Height of the caption/menu bar
      int caption_border_height = GetSystemMetrics(SM_CYCAPTION);
      win32_y_origin = win32_y_origin -
         (2*verical_border_height) - caption_border_height;
   }

   // Create the main application window
   mWinHandle = CreateWindowEx(ex_style, GL_WINDOW_WIN32_CLASSNAME,
                               mWindowName.c_str(), 
                               style, mOriginX,
                               win32_y_origin,
                               rc.right - rc.left, rc.bottom - rc.top,
                               NULL, NULL, hMod, NULL);

   // If window was not created, quit
   if ( NULL == mWinHandle )
   {
      doInternalError("Could not create window using CreateWindowEx()!");
{'fraction_non_alphanumeric': 0.11305544632324027, 'fraction_numerical': 0.011502162799842706, 'mean_word_length': 2.958365758754864, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1881773', 'n_tokens_mistral': 3449, 'n_tokens_neox': 3299, 'n_words': 909}