src/video/haiku/SDL_bclipboard.cc
changeset 7981 6d538bc1b395
parent 7721 bdf8c2c84e14
child 8093 b43765095a6f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/haiku/SDL_bclipboard.cc	Thu Nov 14 11:51:24 2013 -0500
     1.3 @@ -0,0 +1,95 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +#include "SDL_config.h"
    1.25 +
    1.26 +#if SDL_VIDEO_DRIVER_HAIKU
    1.27 +
    1.28 +/* BWindow based framebuffer implementation */
    1.29 +
    1.30 +#include <unistd.h>
    1.31 +#include <TypeConstants.h>
    1.32 +
    1.33 +#include "SDL_BWin.h"
    1.34 +#include "SDL_timer.h"
    1.35 +#include "../SDL_sysvideo.h"
    1.36 +
    1.37 +#ifdef __cplusplus
    1.38 +extern "C" {
    1.39 +#endif
    1.40 +
    1.41 +int BE_SetClipboardText(_THIS, const char *text) {
    1.42 +	BMessage *clip = NULL;
    1.43 +	if(be_clipboard->Lock()) {
    1.44 +		be_clipboard->Clear();
    1.45 +		if((clip = be_clipboard->Data())) {
    1.46 +			/* Presumably the string of characters is ascii-format */
    1.47 +			ssize_t asciiLength = 0;
    1.48 +			for(; text[asciiLength] != 0; ++asciiLength) {}
    1.49 +			clip->AddData("text/plain", B_MIME_TYPE, &text, asciiLength);
    1.50 +			be_clipboard->Commit();
    1.51 +		}
    1.52 +		be_clipboard->Unlock();
    1.53 +	}
    1.54 +	return 0;
    1.55 +}
    1.56 +
    1.57 +char *BE_GetClipboardText(_THIS) {
    1.58 +	BMessage *clip = NULL;
    1.59 +	const char *text = NULL;	
    1.60 +	ssize_t length;
    1.61 +	char *result;
    1.62 +	if(be_clipboard->Lock()) {
    1.63 +		if((clip = be_clipboard->Data())) {
    1.64 +			/* Presumably the string of characters is ascii-format */
    1.65 +			clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text,
    1.66 +				&length);
    1.67 +		} else {
    1.68 +			be_clipboard->Unlock();
    1.69 +		}
    1.70 +		be_clipboard->Unlock();
    1.71 +	} 
    1.72 +	
    1.73 +	if (!text) {
    1.74 +		result = SDL_strdup("");
    1.75 +	} else {
    1.76 +		/* Copy the data and pass on to SDL */
    1.77 +		result = (char*)SDL_calloc(1, sizeof(char*)*length);
    1.78 +		SDL_strlcpy(result, text, length);
    1.79 +	}
    1.80 +	
    1.81 +	return result;
    1.82 +}
    1.83 +
    1.84 +SDL_bool BE_HasClipboardText(_THIS) {
    1.85 +	SDL_bool result = SDL_FALSE;
    1.86 +	char *text = BE_GetClipboardText(_this);
    1.87 +	if (text) {
    1.88 +		result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
    1.89 +		SDL_free(text);
    1.90 +	} 
    1.91 +	return result;
    1.92 +}
    1.93 +
    1.94 +#ifdef __cplusplus
    1.95 +}
    1.96 +#endif
    1.97 +
    1.98 +#endif /* SDL_VIDEO_DRIVER_HAIKU */