// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QOHOSWINDOWFUNCTIONS_H
#define QOHOSWINDOWFUNCTIONS_H

#include <QtCore/QByteArray>
#include <QtGui/QGuiApplication>

QT_BEGIN_NAMESPACE

class QWindow;

class QOhosFunctions
{
public:
    typedef void (*TagWindowAsSubWindowOf)(QObject *, QWindow *);
    typedef void (*TagWindowOrWidgetAsMainWindow)(QObject *, bool);
    typedef void (*TagWidgetWindowAsHostOfWidget)(QWindow *, QObject *);
    typedef QWindow *(*GetWindowOrWidgetAsSubWindowOfTagValue)(QObject *);
    typedef void (*SetInAppOnlyPasteboardShareOption)(bool);
    static const QByteArray tagWindowOrWidgetAsSubwindowOfIdentifier() { return QByteArrayLiteral("tagWindowOrWidgetAsSubWindowOf"); }
    static const QByteArray tagWindowOrWidgetAsMainWindowIdentifier() { return QByteArrayLiteral("tagWindowOrWidgetAsMainWindow"); }
    static const QByteArray getWindowOrWidgetAsSubWindowOfTagValueIdentifier() { return QByteArrayLiteral("getWindowOrWidgetAsSubWindowOfTagValue"); }
    static const QByteArray setInAppOnlyPasteboardShareOptionIdentifier() { return QByteArrayLiteral("setInAppOnlyPasteboardShareOption"); }

    static void tagWindowOrWidgetAsSubWindowOf(QObject *windowOrWidgetToTag, QWindow *mainWindow)
    {
        static auto func = reinterpret_cast<TagWindowAsSubWindowOf>(
            QGuiApplication::platformFunction(tagWindowOrWidgetAsSubwindowOfIdentifier()));
        Q_ASSERT(func);
        func(windowOrWidgetToTag, mainWindow);
    }

    static void tagWindowOrWidgetAsMainWindow(QObject *windowOrWidgetToTag, bool forceMainWindow = true)
    {
        static auto func = reinterpret_cast<TagWindowOrWidgetAsMainWindow>(
            QGuiApplication::platformFunction(tagWindowOrWidgetAsMainWindowIdentifier()));
        Q_ASSERT(func);
        func(windowOrWidgetToTag, forceMainWindow);
    }

    static QWindow *getWindowOrWidgetAsSubWindowOfTagValue(QObject *targetWindowOrWidget)
    {
        static auto func = reinterpret_cast<GetWindowOrWidgetAsSubWindowOfTagValue>(
            QGuiApplication::platformFunction(getWindowOrWidgetAsSubWindowOfTagValueIdentifier()));
        Q_ASSERT(func);
        return func(targetWindowOrWidget);
    }

    static void setInAppOnlyPasteboardShareOption(bool shareInAppOnly)
    {
        static auto func = reinterpret_cast<SetInAppOnlyPasteboardShareOption>(
            QGuiApplication::platformFunction(setInAppOnlyPasteboardShareOptionIdentifier()));
        Q_ASSERT(func);
        func(shareInAppOnly);
    }
};

QT_END_NAMESPACE

#endif // QOHOSWINDOWFUNCTIONS_H

