/*
 * Interface wrapper code.
 *
 * Generated by SIP 6.15.1
 *
 *     Copyright: (c) 2020 by Total Control Software
 *     License:   wxWindows License
 */

#include "sipAPI_glcanvas.h"
        #include <wx/glcanvas.h>
        #include <wx/glcanvas.h>
        #include <wx/glcanvas.h>
        #include <wx/object.h>
        #include <wx/object.h>
        #include <wx/object.h>


class sipwxGLContext : public ::wxGLContext
{
public:
    sipwxGLContext(::wxGLCanvas*, const ::wxGLContext*, const ::wxGLContextAttrs*);
    virtual ~sipwxGLContext();

    /*
     * There is a protected method for every virtual method visible from
     * this class.
     */
protected:
    bool SetCurrent(const ::wxGLCanvas&) const SIP_OVERRIDE;

public:
    sipSimpleWrapper *sipPySelf;

private:
    sipwxGLContext(const sipwxGLContext &);
    sipwxGLContext &operator = (const sipwxGLContext &);

    char sipPyMethods[1];
};

sipwxGLContext::sipwxGLContext(::wxGLCanvas*win, const ::wxGLContext*other, const ::wxGLContextAttrs*ctxAttrs): ::wxGLContext(win, other, ctxAttrs), sipPySelf(SIP_NULLPTR)
{
    memset(sipPyMethods, 0, sizeof (sipPyMethods));
}

sipwxGLContext::~sipwxGLContext()
{
    sipInstanceDestroyedEx(&sipPySelf);
}

bool sipwxGLContext::SetCurrent(const ::wxGLCanvas& win) const
{
    sip_gilstate_t sipGILState;
    PyObject *sipMeth;

    sipMeth = sipIsPyMethod(&sipGILState, const_cast<char *>(&sipPyMethods[0]), const_cast<sipSimpleWrapper **>(&sipPySelf), SIP_NULLPTR, sipName_SetCurrent);

    if (!sipMeth)
        return ::wxGLContext::SetCurrent(win);

    extern bool sipVH__glcanvas_0(sip_gilstate_t, sipVirtErrorHandlerFunc, sipSimpleWrapper *, PyObject *, const ::wxGLCanvas&);

    return sipVH__glcanvas_0(sipGILState, 0, sipPySelf, sipMeth, win);
}


PyDoc_STRVAR(doc_wxGLContext_IsOK, "IsOK() -> bool\n"
"\n"
"Checks if the underlying OpenGL rendering context was correctly\n"
"created by the system with the requested attributes.");

extern "C" {static PyObject *meth_wxGLContext_IsOK(PyObject *, PyObject *);}
static PyObject *meth_wxGLContext_IsOK(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        ::wxGLContext *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_wxGLContext, &sipCpp))
        {
            bool sipRes;

            PyErr_Clear();

            Py_BEGIN_ALLOW_THREADS
            sipRes = sipCpp->IsOK();
            Py_END_ALLOW_THREADS

            if (PyErr_Occurred())
                return 0;

            return PyBool_FromLong(sipRes);
        }
    }

    sipNoMethod(sipParseErr, sipName_GLContext, sipName_IsOK, SIP_NULLPTR);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_wxGLContext_SetCurrent, "SetCurrent(win) -> bool\n"
"\n"
"Makes the OpenGL state that is represented by this rendering context\n"
"current with the wxGLCanvas win.");

extern "C" {static PyObject *meth_wxGLContext_SetCurrent(PyObject *, PyObject *, PyObject *);}
static PyObject *meth_wxGLContext_SetCurrent(PyObject *sipSelf, PyObject *sipArgs, PyObject *sipKwds)
{
    PyObject *sipParseErr = SIP_NULLPTR;
    bool sipSelfWasArg = (!sipSelf || sipIsDerivedClass((sipSimpleWrapper *)sipSelf));

    {
        const ::wxGLCanvas* win;
        const ::wxGLContext *sipCpp;

        static const char *sipKwdList[] = {
            sipName_win,
        };

        if (sipParseKwdArgs(&sipParseErr, sipArgs, sipKwds, sipKwdList, SIP_NULLPTR, "BJ9", &sipSelf, sipType_wxGLContext, &sipCpp, sipType_wxGLCanvas, &win))
        {
            bool sipRes;

            PyErr_Clear();

            Py_BEGIN_ALLOW_THREADS
            sipRes = (sipSelfWasArg ? sipCpp->::wxGLContext::SetCurrent(*win) : sipCpp->SetCurrent(*win));
            Py_END_ALLOW_THREADS

            if (PyErr_Occurred())
                return 0;

            return PyBool_FromLong(sipRes);
        }
    }

    sipNoMethod(sipParseErr, sipName_GLContext, sipName_SetCurrent, SIP_NULLPTR);

    return SIP_NULLPTR;
}


/* Cast a pointer to a type somewhere in its inheritance hierarchy. */
extern "C" {static void *cast_wxGLContext(void *, const sipTypeDef *);}
static void *cast_wxGLContext(void *sipCppV, const sipTypeDef *targetType)
{
    ::wxGLContext *sipCpp = reinterpret_cast< ::wxGLContext *>(sipCppV);

    if (targetType == sipType_wxGLContext)
        return sipCppV;

    if (targetType == sipType_wxObject)
        return static_cast< ::wxObject *>(sipCpp);

    return SIP_NULLPTR;
}


/* Call the instance's destructor. */
extern "C" {static void release_wxGLContext(void *, int);}
static void release_wxGLContext(void *sipCppV, int sipState)
{
    Py_BEGIN_ALLOW_THREADS

    if (sipState & SIP_DERIVED_CLASS)
        delete reinterpret_cast<sipwxGLContext *>(sipCppV);
    else
        delete reinterpret_cast< ::wxGLContext *>(sipCppV);

    Py_END_ALLOW_THREADS
}


extern "C" {static void dealloc_wxGLContext(sipSimpleWrapper *);}
static void dealloc_wxGLContext(sipSimpleWrapper *sipSelf)
{
    if (sipIsDerivedClass(sipSelf))
        reinterpret_cast<sipwxGLContext *>(sipGetAddress(sipSelf))->sipPySelf = SIP_NULLPTR;

    if (sipIsOwnedByPython(sipSelf))
    {
        release_wxGLContext(sipGetAddress(sipSelf), sipIsDerivedClass(sipSelf));
    }
}


extern "C" {static void *init_type_wxGLContext(sipSimpleWrapper *, PyObject *, PyObject *, PyObject **, PyObject **, PyObject **);}
static void *init_type_wxGLContext(sipSimpleWrapper *sipSelf, PyObject *sipArgs, PyObject *sipKwds, PyObject **sipUnused, PyObject **, PyObject **sipParseErr)
{
    sipwxGLContext *sipCpp = SIP_NULLPTR;

    {
        ::wxGLCanvas* win;
        const ::wxGLContext* other = 0;
        const ::wxGLContextAttrs* ctxAttrs = 0;

        static const char *sipKwdList[] = {
            sipName_win,
            sipName_other,
            sipName_ctxAttrs,
        };

        if (sipParseKwdArgs(sipParseErr, sipArgs, sipKwds, sipKwdList, sipUnused, "J8|J8J8", sipType_wxGLCanvas, &win, sipType_wxGLContext, &other, sipType_wxGLContextAttrs, &ctxAttrs))
        {
        if (!wxPyCheckForApp()) return NULL;

            PyErr_Clear();

            Py_BEGIN_ALLOW_THREADS
            sipCpp = new sipwxGLContext(win, other, ctxAttrs);
            Py_END_ALLOW_THREADS

            if (PyErr_Occurred())
            {
                delete sipCpp;
                return SIP_NULLPTR;
            }

            sipCpp->sipPySelf = sipSelf;

            return sipCpp;
        }
    }

    return SIP_NULLPTR;
}


/* Define this type's super-types. */
static sipEncodedTypeDef supers_wxGLContext[] = {{4, 0, 1}};


static PyMethodDef methods_wxGLContext[] = {
    {sipName_IsOK, meth_wxGLContext_IsOK, METH_VARARGS, doc_wxGLContext_IsOK},
    {sipName_SetCurrent, SIP_MLMETH_CAST(meth_wxGLContext_SetCurrent), METH_VARARGS|METH_KEYWORDS, doc_wxGLContext_SetCurrent}
};

PyDoc_STRVAR(doc_wxGLContext, "GLContext(win, other=None, ctxAttrs=None) -> None\n"
"\n"
"An instance of a wxGLContext represents the state of an OpenGL state\n"
"machine and the connection between OpenGL and the system.");


sipClassTypeDef sipTypeDef__glcanvas_wxGLContext = {
    {
        -1,
        SIP_NULLPTR,
        SIP_NULLPTR,
        SIP_TYPE_SCC|SIP_TYPE_CLASS,
        sipNameNr_wxGLContext,
        SIP_NULLPTR,
        SIP_NULLPTR,
    },
    {
        sipNameNr_GLContext,
        {0, 0, 1},
        2, methods_wxGLContext,
        0, SIP_NULLPTR,
        0, SIP_NULLPTR,
        {SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR},
    },
    doc_wxGLContext,
    -1,
    -1,
    supers_wxGLContext,
    SIP_NULLPTR,
    init_type_wxGLContext,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    dealloc_wxGLContext,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    release_wxGLContext,
    cast_wxGLContext,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    sizeof (::wxGLContext),
};
