src/video/bwindow/SDL_bclipboard.cc
author Ryan C. Gordon <icculus@icculus.org>
Sun, 25 Aug 2013 21:28:03 -0400
changeset 7701 7d3fff679fae
parent 6885 700f1b25f77f
child 7721 bdf8c2c84e14
permissions -rw-r--r--
Removed obvious comment to trigger buildbot.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5918
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
     1
/*
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
5918
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
     4
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
     5
  This software is provided 'as-is', without any express or implied
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
     7
  arising from the use of this software.
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
     8
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    11
  freely, subject to the following restrictions:
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    12
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    14
     claim that you wrote the original software. If you use this software
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    16
     appreciated but is not required.
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    18
     misrepresented as being the original software.
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    20
*/
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6037
diff changeset
    21
#include "SDL_config.h"
5918
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6037
diff changeset
    23
#if SDL_VIDEO_DRIVER_BWINDOW
5918
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    24
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    25
/* BWindow based framebuffer implementation */
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    26
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    27
#include <unistd.h>
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    28
#include <TypeConstants.h>
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    29
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    30
#include "SDL_BWin.h"
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    31
#include "SDL_timer.h"
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    32
#include "../SDL_sysvideo.h"
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    33
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    34
#ifdef __cplusplus
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    35
extern "C" {
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    36
#endif
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    37
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    38
int BE_SetClipboardText(_THIS, const char *text) {
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    39
	BMessage *clip = NULL;
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    40
	if(be_clipboard->Lock()) {
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    41
		be_clipboard->Clear();
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    42
		if((clip = be_clipboard->Data())) {
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    43
			/* Presumably the string of characters is ascii-format */
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    44
			ssize_t asciiLength = 0;
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    45
			for(; text[asciiLength] != 0; ++asciiLength) {}
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    46
			clip->AddData("text/plain", B_MIME_TYPE, &text, asciiLength);
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    47
			be_clipboard->Commit();
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    48
		}
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    49
		be_clipboard->Unlock();
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    50
	}
6037
2feab4874268 Fix sdl-haiku buildbot compiler warnings
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6036
diff changeset
    51
	return 0;
5918
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    52
}
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    53
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    54
char *BE_GetClipboardText(_THIS) {
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    55
	BMessage *clip = NULL;
6036
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    56
	const char *text = NULL;	
5918
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    57
	ssize_t length;
6036
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    58
	char *result;
5918
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    59
	if(be_clipboard->Lock()) {
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    60
		if((clip = be_clipboard->Data())) {
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    61
			/* Presumably the string of characters is ascii-format */
5939
d9e9c343d264 Partially cleaned out code
Nathan Heisey <nathanheisey@gmail.com>
parents: 5918
diff changeset
    62
			clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text,
d9e9c343d264 Partially cleaned out code
Nathan Heisey <nathanheisey@gmail.com>
parents: 5918
diff changeset
    63
				&length);
5918
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    64
		} else {
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    65
			be_clipboard->Unlock();
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    66
		}
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    67
		be_clipboard->Unlock();
6036
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    68
	} 
5918
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    69
	
6036
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    70
	if (!text) {
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    71
		result = SDL_strdup("");
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    72
	} else {
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    73
		/* Copy the data and pass on to SDL */
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    74
		result = (char*)SDL_calloc(1, sizeof(char*)*length);
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    75
		SDL_strlcpy(result, text, length);
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    76
	}
5918
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    77
	
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    78
	return result;
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    79
}
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    80
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    81
SDL_bool BE_HasClipboardText(_THIS) {
6036
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    82
	SDL_bool result = SDL_FALSE;
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    83
	char *text = BE_GetClipboardText(_this);
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    84
	if (text) {
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    85
		result = (SDL_strlen(text)>0) ? SDL_TRUE : SDL_FALSE;
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    86
		SDL_free(text);
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    87
	} 
f2a89f2a6157 Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 5939
diff changeset
    88
	return result;
5918
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    89
}
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    90
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    91
#ifdef __cplusplus
7701
7d3fff679fae Removed obvious comment to trigger buildbot.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
    92
}
5918
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    93
#endif
2063df37190b Renamed all .c files in src/video/bwindow to .cc files.
Nathan Heisey <nathanheisey@gmail.com>
parents:
diff changeset
    94
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6037
diff changeset
    95
#endif /* SDL_VIDEO_DRIVER_BWINDOW */