<commit_before>//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004-2020 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//    * Redistributions of source code must retain the above copyright notice,
//      this list of conditions and the following disclaimer.
//
//    * Redistributions in binary form must reproduce the above copyright
//      notice, this list of conditions and the following disclaimer in the
//      documentation and/or other materials provided with the distribution.
//
//    * Neither the name of the author nor the names of other contributors may
//      be used to endorse or promote products derived from this software
//      without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////

#include <stdafx.h>
#include <cursespp/Window.h>
#include <cursespp/IWindowGroup.h>
#include <cursespp/IInput.h>
#include <cursespp/ILayout.h>
#include <cursespp/Colors.h>
#include <cursespp/Screen.h>
#include <cursespp/Text.h>

#include <musikcore/runtime/Message.h>
#include <musikcore/runtime/MessageQueue.h>

#include <cassert>

using namespace cursespp;
using namespace musik::core::runtime;

static int NEXT_ID = 0;

static bool drawPending = false;
static bool freeze = false;
static Window* top = nullptr;
static Window* focused = nullptr;
static bool cursorVisible = false;

static MessageQueue messageQueue;
static std::shared_ptr<INavigationKeys> keys;

#if defined(DEBUG) || defined(_DEBUG)
    #ifdef WIN32
        static DWORD mainThreadId = GetCurrentThreadId();
        #define ASSERT_MAIN_THREAD() assert(GetCurrentThreadId() == mainThreadId);
    #else
        static pthread_t mainThreadId = pthread_self();
        #define ASSERT_MAIN_THREAD() assert(pthread_self() == mainThreadId);
    #endif
#else
    #define ASSERT_MAIN_THREAD()
#endif

const int Window::kLastReservedMessageId = INT_MAX;
const int Window::kFirstReservedMessageId = kLastReservedMessageId - 1024;
static const int kNotifyVisibilityChangedMessageId = Window::kFirstReservedMessageId + 1;

#define ENABLE_BOUNDS_CHECK 1

/* clangen says: we used to just be able to call wbkgd() prior to ncurses 6.2;
however, something changed internally that causes the drawing to get corrupted
if we don't call wbkgdset() first. this looks like a bug, and the release notes
mention wbkgd() was changed, but it's unclear what exactly happened... */
#ifndef WIN32
    #define wbkgd_internal(window, color) \
        wbkgdset(window, color); \
        wbkgd(window, color);
#else
    #define wbkgd_internal(window, color) \
        wbkgd(window, color);
#endif

static inline void DrawCursor(IInput* input) {
    if (input) {
        const Window* inputWindow = dynamic_cast<Window*>(input);
        if (inputWindow && inputWindow->GetContent()) {
            if (!cursorVisible) {
                curs_set(1);
                cursorVisible = true;
            }
            WINDOW* content = inputWindow->GetContent();
            if (content) {
                wtimeout(content, IDLE_TIMEOUT_MS);
                int currentX = 0, currentY = 0;
                getyx(content, currentY, currentX);
                int const targetY = 0, const targetX = (int) input->Position();<commit_msg>Fix compile issues on Unix<commit_after>//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004-2020 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//    * Redistributions of source code must retain the above copyright notice,
//      this list of conditions and the following disclaimer.
//
//    * Redistributions in binary form must reproduce the above copyright
//      notice, this list of conditions and the following disclaimer in the
//      documentation and/or other materials provided with the distribution.
//
//    * Neither the name of the author nor the names of other contributors may
//      be used to endorse or promote products derived from this software
//      without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////

#include <stdafx.h>
#include <cursespp/Window.h>
#include <cursespp/IWindowGroup.h>
#include <cursespp/IInput.h>
#include <cursespp/ILayout.h>
#include <cursespp/Colors.h>
#include <cursespp/Screen.h>
#include <cursespp/Text.h>

#include <musikcore/runtime/Message.h>
#include <musikcore/runtime/MessageQueue.h>

#include <cassert>

using namespace cursespp;
using namespace musik::core::runtime;

static int NEXT_ID = 0;

static bool drawPending = false;
static bool freeze = false;
static Window* top = nullptr;
static Window* focused = nullptr;
static bool cursorVisible = false;

static MessageQueue messageQueue;
static std::shared_ptr<INavigationKeys> keys;

#if defined(DEBUG) || defined(_DEBUG)
    #ifdef WIN32
        static DWORD mainThreadId = GetCurrentThreadId();
        #define ASSERT_MAIN_THREAD() assert(GetCurrentThreadId() == mainThreadId);
    #else
        static pthread_t mainThreadId = pthread_self();
        #define ASSERT_MAIN_THREAD() assert(pthread_self() == mainThreadId);
    #endif
#else
    #define ASSERT_MAIN_THREAD()
#endif

const int Window::kLastReservedMessageId = INT_MAX;
const int Window::kFirstReservedMessageId = kLastReservedMessageId - 1024;
static const int kNotifyVisibilityChangedMessageId = Window::kFirstReservedMessageId + 1;

#define ENABLE_BOUNDS_CHECK 1

/* clangen says: we used to just be able to call wbkgd() prior to ncurses 6.2;
however, something changed internally that causes the drawing to get corrupted
if we don't call wbkgdset() first. this looks like a bug, and the release notes
mention wbkgd() was changed, but it's unclear what exactly happened... */
#ifndef WIN32
    #define wbkgd_internal(window, color) \
        wbkgdset(window, color); \
        wbkgd(window, color);
#else
    #define wbkgd_internal(window, color) \
        wbkgd(window, color);
#endif

static inline void DrawCursor(IInput* input) {
    if (input) {
        const Window* inputWindow = dynamic_cast<Window*>(input);
        if (inputWindow && inputWindow->GetContent()) {
            if (!cursorVisible) {
                curs_set(1);
                cursorVisible = true;
            }
            WINDOW* content = inputWindow->GetContent();
            if (content) {
                wtimeout(content, IDLE_TIMEOUT_MS);
                int currentX = 0, currentY = 0;
                getyx(content, currentY, currentX);
                const int targetY = 0;
                const int targetX = (int) input->Position();
{'fraction_non_alphanumeric': 0.12136892861343056, 'fraction_numerical': 0.005880277549100318, 'mean_word_length': 2.9962406015037595, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 35, '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': '7568698', 'n_tokens_mistral': 2380, 'n_tokens_neox': 2211, 'n_words': 870}