test/testdropfile.c
author Alex Baines <alex@abaines.me.uk>
Tue, 19 Aug 2014 23:31:50 +0100
changeset 9097 56d712662a82
parent 8776 29aac8b813d9
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Add a SDL_IM_INTERNAL_EDITING event to make IMs like iBus render editing text in its own UI instead of sending TEXTEDITING events.
This is useful for applications that handle TEXTINPUT events but not TEXTEDITING events.
urkle@7807
     1
/*
slouken@8149
     2
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
urkle@7807
     3
urkle@7807
     4
  This software is provided 'as-is', without any express or implied
urkle@7807
     5
  warranty.  In no event will the authors be held liable for any damages
urkle@7807
     6
  arising from the use of this software.
urkle@7807
     7
urkle@7807
     8
  Permission is granted to anyone to use this software for any purpose,
urkle@7807
     9
  including commercial applications, and to alter it and redistribute it
urkle@7807
    10
  freely.
urkle@7807
    11
*/
urkle@7807
    12
urkle@7807
    13
#include <stdlib.h>
urkle@7807
    14
#include <stdio.h>
urkle@7807
    15
urkle@7807
    16
#include "SDL_test_common.h"
urkle@7807
    17
urkle@7807
    18
static SDLTest_CommonState *state;
urkle@7807
    19
urkle@7807
    20
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
urkle@7807
    21
static void
urkle@7807
    22
quit(int rc)
urkle@7807
    23
{
urkle@7807
    24
    SDLTest_CommonQuit(state);
urkle@7807
    25
    exit(rc);
urkle@7807
    26
}
urkle@7807
    27
urkle@7807
    28
int
urkle@7807
    29
main(int argc, char *argv[])
urkle@7807
    30
{
urkle@7807
    31
    int i, done;
urkle@7807
    32
    SDL_Event event;
urkle@7807
    33
urkle@7807
    34
	/* Enable standard application logging */
urkle@7807
    35
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
urkle@7807
    36
urkle@7807
    37
    /* Initialize test framework */
urkle@7807
    38
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
urkle@7807
    39
    if (!state) {
urkle@7807
    40
        return 1;
urkle@7807
    41
    }
urkle@7807
    42
urkle@7807
    43
    for (i = 1; i < argc;) {
urkle@7807
    44
        int consumed;
urkle@7807
    45
urkle@7807
    46
        consumed = SDLTest_CommonArg(state, i);
philipp@8776
    47
        /* needed voodoo to allow app to launch via OS X Finder */
urkle@8174
    48
        if (SDL_strncmp(argv[i], "-psn", 4)==0) {
urkle@8174
    49
            consumed = 1;
urkle@8174
    50
        }
urkle@7807
    51
        if (consumed == 0) {
urkle@7807
    52
            consumed = -1;
urkle@7807
    53
        }
urkle@7807
    54
        if (consumed < 0) {
urkle@7807
    55
            SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
urkle@7807
    56
            quit(1);
urkle@7807
    57
        }
urkle@7807
    58
        i += consumed;
urkle@7807
    59
    }
urkle@7807
    60
    if (!SDLTest_CommonInit(state)) {
urkle@7807
    61
        quit(2);
urkle@7807
    62
    }
urkle@7807
    63
urkle@7807
    64
    for (i = 0; i < state->num_windows; ++i) {
urkle@7807
    65
        SDL_Renderer *renderer = state->renderers[i];
urkle@7807
    66
        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
urkle@7807
    67
        SDL_RenderClear(renderer);
urkle@7807
    68
        SDL_RenderPresent(renderer);
urkle@7807
    69
    }
urkle@7807
    70
urkle@8174
    71
    SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
urkle@8174
    72
urkle@7807
    73
    /* Main render loop */
urkle@7807
    74
    done = 0;
urkle@7807
    75
    while (!done) {
urkle@7807
    76
        /* Check for events */
urkle@7807
    77
        while (SDL_PollEvent(&event)) {
urkle@7807
    78
            SDLTest_CommonEvent(state, &event, &done);
urkle@7807
    79
urkle@7807
    80
            if (event.type == SDL_DROPFILE) {
urkle@7807
    81
                char *dropped_filedir = event.drop.file;
urkle@7807
    82
                SDL_Log("File dropped on window: %s", dropped_filedir);
urkle@7807
    83
                SDL_free(dropped_filedir);
urkle@7807
    84
            }
urkle@7807
    85
        }
urkle@7807
    86
    }
urkle@7807
    87
urkle@7807
    88
    quit(0);
urkle@7807
    89
    /* keep the compiler happy ... */
urkle@7807
    90
    return(0);
urkle@7807
    91
}
urkle@7807
    92
urkle@7807
    93
/* vi: set ts=4 sw=4 expandtab: */