/*
  Copyright 2012-2019 David Robillard <http://drobilla.net>
  Copyright 2019-2020 Filipe Coelho <falktx@falktx.com>

  Permission to use, copy, modify, and/or distribute this software for any
  purpose with or without fee is hereby granted, provided that the above
  copyright notice and this permission notice appear in all copies.

  THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

/**
   @file mac.cpp HaikuOS implementation.
*/

#include "haiku.h"

#include "pugl/detail/implementation.h"

PuglStatus
puglGrabFocus(PuglView* view)
{
    view->impl->bView->MakeFocus(true);
    return PUGL_SUCCESS;
}

// extras follow

void
puglRaiseWindow(PuglView* view)
{
}

void
puglSetWindowSize(PuglView* view, unsigned int width, unsigned int height)
{
    bView->ResizeTo(width, height);

    if (bWindow != nullptr && bWindow->LockLooper())
    {
        bWindow->MoveTo(50, 50);
        bWindow->ResizeTo(width, height);

        if (! forced)
            bWindow->Flush();

        bWindow->UnlockLooper();
    }
    // TODO resizable
}

void setVisible(const bool yesNo)
{
    if (bWindow != nullptr)
    {
        if (bWindow->LockLooper())
        {
            if (yesNo)
                bWindow->Show();
            else
                bWindow->Hide();

            // TODO use flush?
            bWindow->Sync();
            bWindow->UnlockLooper();
        }
    }
    else
    {
        if (yesNo)
            bView->Show();
        else
            bView->Hide();
    }
}
