src/video/cocoa/SDL_cocoaclipboard.m
author Sam Lantinga
Fri, 27 Jan 2017 06:05:50 -0800
changeset 10856 486aa38c6a88
parent 10737 3406a0f8b041
child 11811 5d94cb6b24d3
permissions -rw-r--r--
Added Thrustmaster Wheel FFB entry to the list of wheels
slouken@4499
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@4499
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@4499
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@4499
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@4499
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@4499
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_COCOA
slouken@6044
    24
slouken@4499
    25
#include "SDL_cocoavideo.h"
slouken@4503
    26
#include "../../events/SDL_clipboardevents_c.h"
slouken@4499
    27
slouken@4499
    28
int
slouken@4499
    29
Cocoa_SetClipboardText(_THIS, const char *text)
slouken@9087
    30
{ @autoreleasepool
slouken@4499
    31
{
slouken@4503
    32
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@4504
    33
    NSPasteboard *pasteboard;
slime73@10176
    34
    NSString *format = NSPasteboardTypeString;
slouken@4499
    35
slouken@6848
    36
    pasteboard = [NSPasteboard generalPasteboard];
slouken@6848
    37
    data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
slouken@6848
    38
    [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
slouken@6848
    39
slouken@4499
    40
    return 0;
slouken@9087
    41
}}
slouken@4499
    42
slouken@4499
    43
char *
slouken@4499
    44
Cocoa_GetClipboardText(_THIS)
slouken@9087
    45
{ @autoreleasepool
slouken@4499
    46
{
slouken@4504
    47
    NSPasteboard *pasteboard;
slime73@10176
    48
    NSString *format = NSPasteboardTypeString;
slouken@4499
    49
    NSString *available;
slouken@4499
    50
    char *text;
slouken@4499
    51
slouken@6848
    52
    pasteboard = [NSPasteboard generalPasteboard];
slime73@10177
    53
    available = [pasteboard availableTypeFromArray:[NSArray arrayWithObject:format]];
slouken@6848
    54
    if ([available isEqualToString:format]) {
slouken@6848
    55
        NSString* string;
slouken@6848
    56
        const char *utf8;
slouken@4499
    57
slouken@6848
    58
        string = [pasteboard stringForType:format];
slouken@6848
    59
        if (string == nil) {
slouken@6848
    60
            utf8 = "";
slouken@4499
    61
        } else {
slouken@6848
    62
            utf8 = [string UTF8String];
slouken@4499
    63
        }
slouken@6848
    64
        text = SDL_strdup(utf8);
slouken@6848
    65
    } else {
slouken@6848
    66
        text = SDL_strdup("");
slouken@4499
    67
    }
slouken@6848
    68
slouken@4499
    69
    return text;
slouken@9087
    70
}}
slouken@4499
    71
slouken@4499
    72
SDL_bool
slouken@4499
    73
Cocoa_HasClipboardText(_THIS)
slouken@4499
    74
{
aschiffler@6036
    75
    SDL_bool result = SDL_FALSE;
aschiffler@6036
    76
    char *text = Cocoa_GetClipboardText(_this);
aschiffler@6036
    77
    if (text) {
slouken@7721
    78
        result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
slouken@8986
    79
        SDL_free(text);
slouken@4499
    80
    }
slouken@4499
    81
    return result;
slouken@4499
    82
}
slouken@4499
    83
slouken@4503
    84
void
slouken@4503
    85
Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
slouken@9087
    86
{ @autoreleasepool
slouken@4503
    87
{
slouken@4504
    88
    NSPasteboard *pasteboard;
slouken@4503
    89
    NSInteger count;
slouken@4503
    90
slouken@6848
    91
    pasteboard = [NSPasteboard generalPasteboard];
slouken@6848
    92
    count = [pasteboard changeCount];
slouken@6848
    93
    if (count != data->clipboard_count) {
slouken@6848
    94
        if (data->clipboard_count) {
slouken@6848
    95
            SDL_SendClipboardUpdate();
slouken@4503
    96
        }
slouken@6848
    97
        data->clipboard_count = count;
slouken@4503
    98
    }
slouken@9087
    99
}}
slouken@4503
   100
slouken@6044
   101
#endif /* SDL_VIDEO_DRIVER_COCOA */
slouken@6044
   102
slouken@4499
   103
/* vi: set ts=4 sw=4 expandtab: */