src/video/cocoa/SDL_cocoaclipboard.m
author Sam Lantinga
Tue, 08 Feb 2011 16:50:51 -0800
changeset 5229 c015d3e63631
parent 4925 514f811a4887
child 5262 b530ef003506
permissions -rw-r--r--
Fixed setting the texture unit, still doesn't work.
slouken@4499
     1
/*
slouken@4499
     2
    SDL - Simple DirectMedia Layer
slouken@4499
     3
    Copyright (C) 1997-2010 Sam Lantinga
slouken@4499
     4
slouken@4499
     5
    This library is free software; you can redistribute it and/or
slouken@4499
     6
    modify it under the terms of the GNU Lesser General Public
slouken@4499
     7
    License as published by the Free Software Foundation; either
slouken@4499
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@4499
     9
slouken@4499
    10
    This library is distributed in the hope that it will be useful,
slouken@4499
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@4499
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@4499
    13
    Lesser General Public License for more details.
slouken@4499
    14
slouken@4499
    15
    You should have received a copy of the GNU Lesser General Public
slouken@4499
    16
    License along with this library; if not, write to the Free Software
slouken@4499
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@4499
    18
slouken@4499
    19
    Sam Lantinga
slouken@4499
    20
    slouken@libsdl.org
slouken@4499
    21
*/
slouken@4499
    22
#include "SDL_config.h"
slouken@4499
    23
slouken@4499
    24
#include "SDL_cocoavideo.h"
slouken@4503
    25
#include "../../events/SDL_clipboardevents_c.h"
slouken@4499
    26
slouken@4501
    27
static NSString *
slouken@4501
    28
GetTextFormat(_THIS)
slouken@4501
    29
{
slouken@4925
    30
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
slouken@4501
    31
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@4501
    32
slouken@4501
    33
    if (data->osversion >= 0x1060) {
slouken@4501
    34
        return NSPasteboardTypeString;
slouken@4501
    35
    } else {
slouken@4501
    36
        return NSStringPboardType;
slouken@4501
    37
    }
slouken@4925
    38
#else
slouken@4925
    39
    return NSStringPboardType;
slouken@4501
    40
#endif
slouken@4501
    41
}
slouken@4499
    42
slouken@4499
    43
int
slouken@4499
    44
Cocoa_SetClipboardText(_THIS, const char *text)
slouken@4499
    45
{
slouken@4503
    46
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@4499
    47
    NSAutoreleasePool *pool;
slouken@4504
    48
    NSPasteboard *pasteboard;
slouken@4501
    49
    NSString *format = GetTextFormat(_this);
slouken@4499
    50
slouken@4499
    51
    pool = [[NSAutoreleasePool alloc] init];
slouken@4499
    52
slouken@4499
    53
    pasteboard = [NSPasteboard generalPasteboard];
slouken@4503
    54
    data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
slouken@4499
    55
    [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
slouken@4499
    56
slouken@4499
    57
    [pool release];
slouken@4499
    58
slouken@4499
    59
    return 0;
slouken@4499
    60
}
slouken@4499
    61
slouken@4499
    62
char *
slouken@4499
    63
Cocoa_GetClipboardText(_THIS)
slouken@4499
    64
{
slouken@4499
    65
    NSAutoreleasePool *pool;
slouken@4504
    66
    NSPasteboard *pasteboard;
slouken@4501
    67
    NSString *format = GetTextFormat(_this);
slouken@4499
    68
    NSString *available;
slouken@4499
    69
    char *text;
slouken@4499
    70
slouken@4499
    71
    pool = [[NSAutoreleasePool alloc] init];
slouken@4499
    72
slouken@4499
    73
    pasteboard = [NSPasteboard generalPasteboard];
slouken@4499
    74
    available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
slouken@4499
    75
    if ([available isEqualToString:format]) {
slouken@4499
    76
        NSString* string;
slouken@4499
    77
        const char *utf8;
slouken@4499
    78
slouken@4499
    79
        string = [pasteboard stringForType:format];
slouken@4499
    80
        if (string == nil) {
slouken@4499
    81
            utf8 = "";
slouken@4499
    82
        } else {
slouken@4499
    83
            utf8 = [string UTF8String];
slouken@4499
    84
        }
slouken@4499
    85
        text = SDL_strdup(utf8);
slouken@4499
    86
    } else {
slouken@4499
    87
        text = SDL_strdup("");
slouken@4499
    88
    }
slouken@4499
    89
slouken@4499
    90
    [pool release];
slouken@4499
    91
slouken@4499
    92
    return text;
slouken@4499
    93
}
slouken@4499
    94
slouken@4499
    95
SDL_bool
slouken@4499
    96
Cocoa_HasClipboardText(_THIS)
slouken@4499
    97
{
slouken@4499
    98
    NSAutoreleasePool *pool;
slouken@4504
    99
    NSPasteboard *pasteboard;
slouken@4501
   100
    NSString *format = GetTextFormat(_this);
slouken@4499
   101
    NSString *available;
slouken@4499
   102
    SDL_bool result;
slouken@4499
   103
slouken@4499
   104
    pool = [[NSAutoreleasePool alloc] init];
slouken@4499
   105
slouken@4499
   106
    pasteboard = [NSPasteboard generalPasteboard];
slouken@4499
   107
    available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
slouken@4499
   108
    if ([available isEqualToString:format]) {
slouken@4499
   109
        result = SDL_TRUE;
slouken@4499
   110
    } else {
slouken@4499
   111
        result = SDL_FALSE;
slouken@4499
   112
    }
slouken@4499
   113
slouken@4499
   114
    [pool release];
slouken@4499
   115
slouken@4499
   116
    return result;
slouken@4499
   117
}
slouken@4499
   118
slouken@4503
   119
void
slouken@4503
   120
Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
slouken@4503
   121
{
slouken@4503
   122
    NSAutoreleasePool *pool;
slouken@4504
   123
    NSPasteboard *pasteboard;
slouken@4503
   124
    NSInteger count;
slouken@4503
   125
slouken@4503
   126
    pool = [[NSAutoreleasePool alloc] init];
slouken@4503
   127
slouken@4503
   128
    pasteboard = [NSPasteboard generalPasteboard];
slouken@4503
   129
    count = [pasteboard changeCount];
slouken@4503
   130
    if (count != data->clipboard_count) {
slouken@4503
   131
        if (data->clipboard_count) {
slouken@4503
   132
            SDL_SendClipboardUpdate();
slouken@4503
   133
        }
slouken@4503
   134
        data->clipboard_count = count;
slouken@4503
   135
    }
slouken@4503
   136
slouken@4503
   137
    [pool release];
slouken@4503
   138
}
slouken@4503
   139
slouken@4499
   140
/* vi: set ts=4 sw=4 expandtab: */