src/video/haiku/SDL_bclipboard.cc
author Sam Lantinga <slouken@libsdl.org>
Sun, 01 Jan 2017 18:33:28 -0800
changeset 10737 3406a0f8b041
parent 10690 23a825f341e6
child 10991 d5f65647a97e
permissions -rw-r--r--
Updated copyright for 2017
nathanheisey@5918
     1
/*
nathanheisey@5918
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
nathanheisey@5918
     4
nathanheisey@5918
     5
  This software is provided 'as-is', without any express or implied
nathanheisey@5918
     6
  warranty.  In no event will the authors be held liable for any damages
nathanheisey@5918
     7
  arising from the use of this software.
nathanheisey@5918
     8
nathanheisey@5918
     9
  Permission is granted to anyone to use this software for any purpose,
nathanheisey@5918
    10
  including commercial applications, and to alter it and redistribute it
nathanheisey@5918
    11
  freely, subject to the following restrictions:
nathanheisey@5918
    12
nathanheisey@5918
    13
  1. The origin of this software must not be misrepresented; you must not
nathanheisey@5918
    14
     claim that you wrote the original software. If you use this software
nathanheisey@5918
    15
     in a product, an acknowledgment in the product documentation would be
nathanheisey@5918
    16
     appreciated but is not required.
nathanheisey@5918
    17
  2. Altered source versions must be plainly marked as such, and must not be
nathanheisey@5918
    18
     misrepresented as being the original software.
nathanheisey@5918
    19
  3. This notice may not be removed or altered from any source distribution.
nathanheisey@5918
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
nathanheisey@5918
    22
icculus@7981
    23
#if SDL_VIDEO_DRIVER_HAIKU
nathanheisey@5918
    24
nathanheisey@5918
    25
/* BWindow based framebuffer implementation */
nathanheisey@5918
    26
nathanheisey@5918
    27
#include <unistd.h>
nathanheisey@5918
    28
#include <TypeConstants.h>
nathanheisey@5918
    29
nathanheisey@5918
    30
#include "SDL_BWin.h"
nathanheisey@5918
    31
#include "SDL_timer.h"
nathanheisey@5918
    32
#include "../SDL_sysvideo.h"
nathanheisey@5918
    33
nathanheisey@5918
    34
#ifdef __cplusplus
nathanheisey@5918
    35
extern "C" {
nathanheisey@5918
    36
#endif
nathanheisey@5918
    37
nathanheisey@5918
    38
int BE_SetClipboardText(_THIS, const char *text) {
nathanheisey@5918
    39
	BMessage *clip = NULL;
nathanheisey@5918
    40
	if(be_clipboard->Lock()) {
nathanheisey@5918
    41
		be_clipboard->Clear();
nathanheisey@5918
    42
		if((clip = be_clipboard->Data())) {
nathanheisey@5918
    43
			/* Presumably the string of characters is ascii-format */
nathanheisey@5918
    44
			ssize_t asciiLength = 0;
nathanheisey@5918
    45
			for(; text[asciiLength] != 0; ++asciiLength) {}
nathanheisey@5918
    46
			clip->AddData("text/plain", B_MIME_TYPE, &text, asciiLength);
nathanheisey@5918
    47
			be_clipboard->Commit();
nathanheisey@5918
    48
		}
nathanheisey@5918
    49
		be_clipboard->Unlock();
nathanheisey@5918
    50
	}
aschiffler@6037
    51
	return 0;
nathanheisey@5918
    52
}
nathanheisey@5918
    53
nathanheisey@5918
    54
char *BE_GetClipboardText(_THIS) {
nathanheisey@5918
    55
	BMessage *clip = NULL;
aschiffler@6036
    56
	const char *text = NULL;	
nathanheisey@5918
    57
	ssize_t length;
aschiffler@6036
    58
	char *result;
nathanheisey@5918
    59
	if(be_clipboard->Lock()) {
nathanheisey@5918
    60
		if((clip = be_clipboard->Data())) {
nathanheisey@5918
    61
			/* Presumably the string of characters is ascii-format */
nathanheisey@5939
    62
			clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text,
nathanheisey@5939
    63
				&length);
nathanheisey@5918
    64
		} else {
nathanheisey@5918
    65
			be_clipboard->Unlock();
nathanheisey@5918
    66
		}
nathanheisey@5918
    67
		be_clipboard->Unlock();
aschiffler@6036
    68
	} 
aschiffler@6036
    69
	
aschiffler@6036
    70
	if (!text) {
aschiffler@6036
    71
		result = SDL_strdup("");
nathanheisey@5918
    72
	} else {
aschiffler@6036
    73
		/* Copy the data and pass on to SDL */
aschiffler@6036
    74
		result = (char*)SDL_calloc(1, sizeof(char*)*length);
aschiffler@6036
    75
		SDL_strlcpy(result, text, length);
nathanheisey@5918
    76
	}
nathanheisey@5918
    77
	
nathanheisey@5918
    78
	return result;
nathanheisey@5918
    79
}
nathanheisey@5918
    80
nathanheisey@5918
    81
SDL_bool BE_HasClipboardText(_THIS) {
aschiffler@6036
    82
	SDL_bool result = SDL_FALSE;
aschiffler@6036
    83
	char *text = BE_GetClipboardText(_this);
aschiffler@6036
    84
	if (text) {
slouken@7721
    85
		result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
aschiffler@6036
    86
		SDL_free(text);
aschiffler@6036
    87
	} 
aschiffler@6036
    88
	return result;
nathanheisey@5918
    89
}
nathanheisey@5918
    90
nathanheisey@5918
    91
#ifdef __cplusplus
icculus@7701
    92
}
nathanheisey@5918
    93
#endif
nathanheisey@5918
    94
icculus@7981
    95
#endif /* SDL_VIDEO_DRIVER_HAIKU */
slouken@10690
    96
slouken@10690
    97
/* vi: set ts=4 sw=4 expandtab: */