src/events/SDL_dropevents.c
author Ethan Lee <flibitijibibo@flibitijibibo.com>
Wed, 17 Jul 2019 23:20:57 -0400
changeset 12950 05dddfb66b85
parent 12503 806492103856
permissions -rw-r--r--
Copypaste SDL_NSLog to UIKit backend, document it as such
slouken@6091
     1
/*
slouken@6091
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
slouken@6091
     4
slouken@6091
     5
  This software is provided 'as-is', without any express or implied
slouken@6091
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@6091
     7
  arising from the use of this software.
slouken@6091
     8
slouken@6091
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@6091
    10
  including commercial applications, and to alter it and redistribute it
slouken@6091
    11
  freely, subject to the following restrictions:
slouken@6091
    12
slouken@6091
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@6091
    14
     claim that you wrote the original software. If you use this software
slouken@6091
    15
     in a product, an acknowledgment in the product documentation would be
slouken@6091
    16
     appreciated but is not required.
slouken@6091
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@6091
    18
     misrepresented as being the original software.
slouken@6091
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@6091
    20
*/
icculus@8093
    21
#include "../SDL_internal.h"
slouken@6091
    22
slouken@6091
    23
/* Drag and drop event handling code for SDL */
slouken@6091
    24
slouken@6091
    25
#include "SDL_events.h"
slouken@6091
    26
#include "SDL_events_c.h"
slouken@6091
    27
#include "SDL_dropevents_c.h"
slouken@6091
    28
icculus@10022
    29
#include "../video/SDL_sysvideo.h"  /* for SDL_Window internals. */
icculus@10022
    30
slouken@6091
    31
icculus@10020
    32
static int
icculus@10022
    33
SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const char *data)
slouken@6091
    34
{
icculus@10022
    35
    static SDL_bool app_is_dropping = SDL_FALSE;
icculus@10022
    36
    int posted = 0;
slouken@6091
    37
slouken@6091
    38
    /* Post the event, if desired */
icculus@10020
    39
    if (SDL_GetEventState(evtype) == SDL_ENABLE) {
icculus@10022
    40
        const SDL_bool need_begin = window ? !window->is_dropping : !app_is_dropping;
slouken@6091
    41
        SDL_Event event;
icculus@10022
    42
icculus@10022
    43
        if (need_begin) {
icculus@10022
    44
            SDL_zero(event);
icculus@10022
    45
            event.type = SDL_DROPBEGIN;
icculus@10042
    46
icculus@10042
    47
            if (window) {
icculus@10042
    48
                event.drop.windowID = window->id;
icculus@10042
    49
            }
icculus@10042
    50
icculus@10022
    51
            posted = (SDL_PushEvent(&event) > 0);
icculus@10022
    52
            if (!posted) {
icculus@10022
    53
                return 0;
icculus@10022
    54
            }
icculus@10022
    55
            if (window) {
icculus@10022
    56
                window->is_dropping = SDL_TRUE;
icculus@10022
    57
            } else {
icculus@10022
    58
                app_is_dropping = SDL_TRUE;
icculus@10022
    59
            }
icculus@10022
    60
        }
icculus@10022
    61
icculus@10020
    62
        SDL_zero(event);
icculus@10020
    63
        event.type = evtype;
icculus@10022
    64
        event.drop.file = data ? SDL_strdup(data) : NULL;
icculus@10022
    65
        event.drop.windowID = window ? window->id : 0;
slouken@6091
    66
        posted = (SDL_PushEvent(&event) > 0);
icculus@10022
    67
icculus@10022
    68
        if (posted && (evtype == SDL_DROPCOMPLETE)) {
icculus@10022
    69
            if (window) {
icculus@10022
    70
                window->is_dropping = SDL_FALSE;
icculus@10022
    71
            } else {
icculus@10022
    72
                app_is_dropping = SDL_FALSE;
icculus@10022
    73
            }
icculus@10022
    74
        }
slouken@6091
    75
    }
icculus@10020
    76
    return posted;
icculus@10020
    77
}
icculus@10020
    78
icculus@10020
    79
int
icculus@10022
    80
SDL_SendDropFile(SDL_Window *window, const char *file)
icculus@10020
    81
{
icculus@10022
    82
    return SDL_SendDrop(window, SDL_DROPFILE, file);
icculus@10020
    83
}
icculus@10020
    84
icculus@10020
    85
int
icculus@10022
    86
SDL_SendDropText(SDL_Window *window, const char *text)
icculus@10020
    87
{
icculus@10022
    88
    return SDL_SendDrop(window, SDL_DROPTEXT, text);
slouken@6091
    89
}
slouken@6091
    90
icculus@10022
    91
int
icculus@10022
    92
SDL_SendDropComplete(SDL_Window *window)
icculus@10022
    93
{
icculus@10022
    94
    return SDL_SendDrop(window, SDL_DROPCOMPLETE, NULL);
icculus@10022
    95
}
icculus@10022
    96
icculus@10022
    97
slouken@6091
    98
/* vi: set ts=4 sw=4 expandtab: */