SDL  2.0
SDL_dropevents.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../SDL_internal.h"
22 
23 /* Drag and drop event handling code for SDL */
24 
25 #include "SDL_events.h"
26 #include "SDL_events_c.h"
27 #include "SDL_dropevents_c.h"
28 
29 #include "../video/SDL_sysvideo.h" /* for SDL_Window internals. */
30 
31 
32 static int
33 SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const char *data)
34 {
35  static SDL_bool app_is_dropping = SDL_FALSE;
36  int posted = 0;
37 
38  /* Post the event, if desired */
39  if (SDL_GetEventState(evtype) == SDL_ENABLE) {
40  const SDL_bool need_begin = window ? !window->is_dropping : !app_is_dropping;
42 
43  if (need_begin) {
44  SDL_zero(event);
45  event.type = SDL_DROPBEGIN;
46 
47  if (window) {
48  event.drop.windowID = window->id;
49  }
50 
51  posted = (SDL_PushEvent(&event) > 0);
52  if (!posted) {
53  return 0;
54  }
55  if (window) {
56  window->is_dropping = SDL_TRUE;
57  } else {
58  app_is_dropping = SDL_TRUE;
59  }
60  }
61 
62  SDL_zero(event);
63  event.type = evtype;
64  event.drop.file = data ? SDL_strdup(data) : NULL;
65  event.drop.windowID = window ? window->id : 0;
66  posted = (SDL_PushEvent(&event) > 0);
67 
68  if (posted && (evtype == SDL_DROPCOMPLETE)) {
69  if (window) {
70  window->is_dropping = SDL_FALSE;
71  } else {
72  app_is_dropping = SDL_FALSE;
73  }
74  }
75  }
76  return posted;
77 }
78 
79 int
80 SDL_SendDropFile(SDL_Window *window, const char *file)
81 {
82  return SDL_SendDrop(window, SDL_DROPFILE, file);
83 }
84 
85 int
87 {
88  return SDL_SendDrop(window, SDL_DROPTEXT, text);
89 }
90 
91 int
93 {
94  return SDL_SendDrop(window, SDL_DROPCOMPLETE, NULL);
95 }
96 
97 
98 /* vi: set ts=4 sw=4 expandtab: */
static int SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const char *data)
int SDL_SendDropFile(SDL_Window *window, const char *file)
SDL_bool is_dropping
Definition: SDL_sysvideo.h:102
#define SDL_ENABLE
Definition: SDL_events.h:722
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
int SDL_SendDropComplete(SDL_Window *window)
int SDL_SendDropText(SDL_Window *window, const char *text)
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
#define SDL_PushEvent
SDL_EventType
The types of events that can be delivered.
Definition: SDL_events.h:55
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
#define NULL
Definition: begin_code.h:164
SDL_bool
Definition: SDL_stdinc.h:139
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
#define SDL_strdup
The type used to identify a window.
Definition: SDL_sysvideo.h:73
Uint32 id
Definition: SDL_sysvideo.h:76
General event structure.
Definition: SDL_events.h:525