src/video/haiku/SDL_bclipboard.cc
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 28 May 2017 21:50:11 +0200
changeset 11045 cf4e14eedfdf
parent 11039 d0e35a9ba1f6
child 11811 5d94cb6b24d3
permissions -rw-r--r--
haiku: Fixed SDL_SetClipboardText() putting random data in clipboard.
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
philipp@10991
    25
/* BWindow based clipboard 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) {}
philipp@11045
    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
		}
nathanheisey@5918
    65
		be_clipboard->Unlock();
aschiffler@6036
    66
	} 
aschiffler@6036
    67
	
aschiffler@6036
    68
	if (!text) {
aschiffler@6036
    69
		result = SDL_strdup("");
nathanheisey@5918
    70
	} else {
aschiffler@6036
    71
		/* Copy the data and pass on to SDL */
philipp@11039
    72
		result = (char *)SDL_malloc((length + 1) * sizeof(char));
philipp@11039
    73
		SDL_strlcpy(result, text, length + 1);
nathanheisey@5918
    74
	}
nathanheisey@5918
    75
	
nathanheisey@5918
    76
	return result;
nathanheisey@5918
    77
}
nathanheisey@5918
    78
nathanheisey@5918
    79
SDL_bool BE_HasClipboardText(_THIS) {
aschiffler@6036
    80
	SDL_bool result = SDL_FALSE;
aschiffler@6036
    81
	char *text = BE_GetClipboardText(_this);
aschiffler@6036
    82
	if (text) {
slouken@7721
    83
		result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
aschiffler@6036
    84
		SDL_free(text);
aschiffler@6036
    85
	} 
aschiffler@6036
    86
	return result;
nathanheisey@5918
    87
}
nathanheisey@5918
    88
nathanheisey@5918
    89
#ifdef __cplusplus
icculus@7701
    90
}
nathanheisey@5918
    91
#endif
nathanheisey@5918
    92
icculus@7981
    93
#endif /* SDL_VIDEO_DRIVER_HAIKU */
slouken@10690
    94
slouken@10690
    95
/* vi: set ts=4 sw=4 expandtab: */