SDL_dropevents.c
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
/* Drag and drop event handling code for SDL */
#include "SDL_events.h"
#include "SDL_events_c.h"
#include "SDL_dropevents_c.h"
#include "../video/SDL_sysvideo.h" /* for SDL_Window internals. */
static int
SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const char *data)
{
static SDL_bool app_is_dropping = SDL_FALSE;
int posted = 0;
/* Post the event, if desired */
if (SDL_GetEventState(evtype) == SDL_ENABLE) {
const SDL_bool need_begin = window ? !window->is_dropping : !app_is_dropping;
SDL_Event event;
if (need_begin) {
SDL_zero(event);
event.type = SDL_DROPBEGIN;
if (window) {
event.drop.windowID = window->id;
}
posted = (SDL_PushEvent(&event) > 0);
if (!posted) {
return 0;
}
if (window) {
window->is_dropping = SDL_TRUE;
} else {
app_is_dropping = SDL_TRUE;
}
}
SDL_zero(event);
event.type = evtype;
event.drop.file = data ? SDL_strdup(data) : NULL;
event.drop.windowID = window ? window->id : 0;
posted = (SDL_PushEvent(&event) > 0);
if (posted && (evtype == SDL_DROPCOMPLETE)) {
if (window) {
window->is_dropping = SDL_FALSE;
} else {
app_is_dropping = SDL_FALSE;
}
}
}
return posted;
}
int
SDL_SendDropFile(SDL_Window *window, const char *file)
{
return SDL_SendDrop(window, SDL_DROPFILE, file);
}
int
SDL_SendDropText(SDL_Window *window, const char *text)
{
return SDL_SendDrop(window, SDL_DROPTEXT, text);
}
int
SDL_SendDropComplete(SDL_Window *window)
{
return SDL_SendDrop(window, SDL_DROPCOMPLETE, NULL);
}
/* vi: set ts=4 sw=4 expandtab: */
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
SDL_events.h
NULL
#define NULL
Definition: begin_code.h:167
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:759
SDL_dropevents_c.h
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:73
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:772
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_DROPCOMPLETE
@ SDL_DROPCOMPLETE
Definition: SDL_events.h:144
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
SDL_DROPTEXT
@ SDL_DROPTEXT
Definition: SDL_events.h:142
SDL_SendDropFile
int SDL_SendDropFile(SDL_Window *window, const char *file)
Definition: SDL_dropevents.c:80
text
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
SDL_SendDropComplete
int SDL_SendDropComplete(SDL_Window *window)
Definition: SDL_dropevents.c:92
SDL_DROPBEGIN
@ SDL_DROPBEGIN
Definition: SDL_events.h:143
SDL_SendDropText
int SDL_SendDropText(SDL_Window *window, const char *text)
Definition: SDL_dropevents.c:86
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_SendDrop
static int SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const char *data)
Definition: SDL_dropevents.c:33
SDL_events_c.h
SDL_strdup
#define SDL_strdup
Definition: SDL_dynapi_overrides.h:397
SDL_EventType
SDL_EventType
The types of events that can be delivered.
Definition: SDL_events.h:55
SDL_Event
General event structure.
Definition: SDL_events.h:557
SDL_DROPFILE
@ SDL_DROPFILE
Definition: SDL_events.h:141
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:161