<commit_before>
#ifndef SA_RESIZER_INCLUDED
#define SA_RESIZER_INCLUDED

#include "kali/ui/native.h"

// ............................................................................

namespace sa {

// ............................................................................

using namespace kali;

/*  The method used here is sort of one big kludge. It (a simplified version) was
    tempting initially, but now it turns out to be too Host/OS versions/settings
    depended, and what's most important, it brings too many barely ever fixable
    side-effects/issues in certain hosts. It becomes a real nightmare to test/
    improve/maintain this method, so I'm about to give it up in favour of
    something more safe and simple.
    (Trivial "resize-triangle"/"near-edges-trigger" with in-Editor-mouse-tracking
    should be enough and will be equally usable from a user point of view.)
*/

struct Resizer : ui::native::LayerBase
{
    int poll(HWND editor_)
    {
        if (!editor)
            ctor(editor_);

        if (!parent || !::IsWindowVisible(parent))
            return ::ShowWindow(handle, SW_HIDE);

        if (!resizingNow) {
            Rect r = rect(parent);
            if (curRect != r)
            {
                tf
                curRect  = r;
                return ::SetWindowPos(handle, 0, r.x, r.y, r.w, r.h,
                    SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW | SWP_SHOWWINDOW);
            }
        }

        return ::IsWindowVisible(handle) ? ~0
            : ::ShowWindow(handle, SW_SHOWNA);
    }

    bool msgHook(LRESULT& result, UINT msg, WPARAM wparam, LPARAM lparam)
    {
        switch (msg)
        {
        case WM_ERASEBKGND:
            result = ~0;
            break;

        case WM_ENTERSIZEMOVE:
            resizingNow = 1;
            break;

        case WM_EXITSIZEMOVE:
            trace.full("msgHook: WM_EXITSIZEMOVE\n");
            resizingNow = 0;
            // always return focus to the parent:
            ::SwitchToThisWindow(parent, 0);
            break;

        case WM_NCHITTEST:
            result = ::DefWindowProc(handle, msg, wparam, lparam);
            // return HTTRANSPARENT for anything except right and bottom edges:
            // (can't resize by left/top edges since some (rare) hosts get plugin
            // window screwed if resized w/o SWP_NOMOVE)
            switch (result)<commit_msg>fix editor focus when resizing<commit_after>
#ifndef SA_RESIZER_INCLUDED
#define SA_RESIZER_INCLUDED

#include "kali/ui/native.h"

// ............................................................................

namespace sa {

// ............................................................................

using namespace kali;

/*  The method used here is sort of one big kludge. It (a simplified version) was
    tempting initially, but now it turns out to be too Host/OS versions/settings
    depended, and what's most important, it brings too many barely ever fixable
    side-effects/issues in certain hosts. It becomes a real nightmare to test/
    improve/maintain this method, so I'm about to give it up in favour of
    something more safe and simple.
    (Trivial "resize-triangle"/"near-edges-trigger" with in-Editor-mouse-tracking
    should be enough and will be equally usable from a user point of view.)
*/

struct Resizer : ui::native::LayerBase
{
    int poll(HWND editor_)
    {
        if (!editor)
            ctor(editor_);

        if (!parent || !::IsWindowVisible(parent))
            return ::ShowWindow(handle, SW_HIDE);

        if (!resizingNow) {
            Rect r = rect(parent);
            if (curRect != r)
            {
                tf
                curRect  = r;
                return ::SetWindowPos(handle, 0, r.x, r.y, r.w, r.h,
                    SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW | SWP_SHOWWINDOW);
            }
        }

        return ::IsWindowVisible(handle) ? ~0
            : ::ShowWindow(handle, SW_SHOWNA);
    }

    bool msgHook(LRESULT& result, UINT msg, WPARAM wparam, LPARAM lparam)
    {
        switch (msg)
        {
        case WM_ERASEBKGND:
            result = ~0;
            break;

        case WM_ENTERSIZEMOVE:
            resizingNow = 1;
            break;

        case WM_EXITSIZEMOVE:
            trace.full("msgHook: WM_EXITSIZEMOVE\n");
            resizingNow = 0;
            // always return focus to the parent:
            ::SetForegroundWindow(parent);
            break;

        case WM_NCHITTEST:
            result = ::DefWindowProc(handle, msg, wparam, lparam);
            // return HTTRANSPARENT for anything except right and bottom edges:
            // (can't resize by left/top edges since some (rare) hosts get plugin
            // window screwed if resized w/o SWP_NOMOVE)
            switch (result)
{'fraction_non_alphanumeric': 0.14517133956386294, 'fraction_numerical': 0.002284527518172378, 'mean_word_length': 1.6403508771929824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1628940', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1324, 'n_words': 424}