cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

SDL_bclipboard.cc (2543B)


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