Esempio n. 1
0
/*
 * Gets the currently available types from the active clipboard.
 */
static PyObject*
_scrap_get_types (PyObject *self, PyObject *args)
{
    int i = 0;
    char **types;
    PyObject *list;
    PyObject *tmp;
    
    PYGAME_SCRAP_INIT_CHECK ();
    if (!pygame_scrap_lost ())
    {
        switch (_currentmode)
        {
        case SCRAP_SELECTION:
            return PyDict_Keys (_selectiondata);
        case SCRAP_CLIPBOARD:
        default:
            return PyDict_Keys (_clipdata);
        }
    }

    list = PyList_New (0);
    types = pygame_scrap_get_types ();
    if (!types)
        return list;
    while (types[i] != NULL)
    {
        tmp = PyString_FromString (types[i]);
        PyList_Append (list, tmp);
        Py_DECREF (tmp);
        i++;
    }
    return list;
}
Esempio n. 2
0
/*
 * Checks whether the pygame window has lost the clipboard.
 */
static PyObject*
_scrap_lost_scrap (PyObject* self, PyObject* args)
{
    PYGAME_SCRAP_INIT_CHECK ();

    if (pygame_scrap_lost ())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
Esempio n. 3
0
/*
 * Gets the content for a certain type from the active clipboard.
 */
static PyObject*
_scrap_get_scrap (PyObject* self, PyObject* args)
{
    char *scrap = NULL;
    PyObject *retval;
    char *scrap_type;
    PyObject *val;
    unsigned long count;

    PYGAME_SCRAP_INIT_CHECK ();

    if(!PyArg_ParseTuple (args, "s", &scrap_type))
        return NULL;

    if (!pygame_scrap_lost ())
    {
        /* We are still the active one. */
        switch (_currentmode)
        {
        case SCRAP_SELECTION:
            val = PyDict_GetItemString (_selectiondata, scrap_type);
            break;
        case SCRAP_CLIPBOARD:
        default:
            val = PyDict_GetItemString (_clipdata, scrap_type);
            break;
        }
        Py_XINCREF (val);
        return val;
    }

    /* pygame_get_scrap() only returns NULL or !NULL, but won't set any
     * errors. */
    scrap = pygame_scrap_get (scrap_type, &count);
    if (!scrap)
        Py_RETURN_NONE;

    retval = PyString_FromStringAndSize (scrap, count);
    return retval;
}
Esempio n. 4
0
char*
pygame_scrap_get (char *type, unsigned long *count)
{
    UINT format = _convert_format (type);
    char *retval = NULL;

    if (!pygame_scrap_initialized ())
    {
        PyErr_SetString (PyExc_SDLError, "scrap system not initialized.");
        return NULL;
    }

    if (!pygame_scrap_lost ())
        return Bytes_AsString (PyDict_GetItemString (_clipdata, type));

    if (!OpenClipboard (SDL_Window))
        return NULL;

    if (!IsClipboardFormatAvailable (format))
    {
        /* The format was not found - was it a mapped type? */
        format = _convert_internal_type (type);
        if (format == -1)
        {
            CloseClipboard ();
            return NULL;
        }
    }

    if (IsClipboardFormatAvailable (format))
    {
        HANDLE hMem;
        char *src;
        src = NULL;

        hMem = GetClipboardData (format);
        if (hMem)
        {
            *count = 0;

            /* CF_BITMAP is not a global, so do not lock it. */
            if (format != CF_BITMAP)
            {
                src = GlobalLock (hMem);
                if (!src)
                {
                    CloseClipboard ();
                    return NULL;
                }
                *count = GlobalSize (hMem);
            }

            if (format == CF_DIB || format == CF_DIBV5)
            {
                /* Count will be increased accordingly in
                 * _create_dib_buffer.
                 */
                src = _create_dib_buffer (src, count);
                GlobalUnlock (hMem);
                CloseClipboard ();
                return src;
            }
            else if (*count != 0)
            {
                /* weird error, shouldn't get here. */
                if(!src) {
                    return NULL;
                }

                retval = malloc (*count);
                if (retval)
                {
                    memset (retval, 0, *count);
                    memcpy (retval, src, *count);
                }
            }
            GlobalUnlock (hMem);
        }
    }

    CloseClipboard ();
    return retval;
}