src/video/haiku/SDL_bclipboard.cc
changeset 12201 8bdc4d340419
parent 12082 09999a0e8f9a
child 12503 806492103856
equal deleted inserted replaced
12200:c0b17b32b95e 12201:8bdc4d340419
    34 #ifdef __cplusplus
    34 #ifdef __cplusplus
    35 extern "C" {
    35 extern "C" {
    36 #endif
    36 #endif
    37 
    37 
    38 int HAIKU_SetClipboardText(_THIS, const char *text) {
    38 int HAIKU_SetClipboardText(_THIS, const char *text) {
    39 	BMessage *clip = NULL;
    39     BMessage *clip = NULL;
    40 	if(be_clipboard->Lock()) {
    40     if(be_clipboard->Lock()) {
    41 		be_clipboard->Clear();
    41         be_clipboard->Clear();
    42 		if((clip = be_clipboard->Data())) {
    42         if((clip = be_clipboard->Data())) {
    43 			/* Presumably the string of characters is ascii-format */
    43             /* Presumably the string of characters is ascii-format */
    44 			ssize_t asciiLength = 0;
    44             ssize_t asciiLength = 0;
    45 			for(; text[asciiLength] != 0; ++asciiLength) {}
    45             for(; text[asciiLength] != 0; ++asciiLength) {}
    46 			clip->AddData("text/plain", B_MIME_TYPE, text, asciiLength);
    46             clip->AddData("text/plain", B_MIME_TYPE, text, asciiLength);
    47 			be_clipboard->Commit();
    47             be_clipboard->Commit();
    48 		}
    48         }
    49 		be_clipboard->Unlock();
    49         be_clipboard->Unlock();
    50 	}
    50     }
    51 	return 0;
    51     return 0;
    52 }
    52 }
    53 
    53 
    54 char *HAIKU_GetClipboardText(_THIS) {
    54 char *HAIKU_GetClipboardText(_THIS) {
    55 	BMessage *clip = NULL;
    55     BMessage *clip = NULL;
    56 	const char *text = NULL;	
    56     const char *text = NULL;    
    57 	ssize_t length;
    57     ssize_t length;
    58 	char *result;
    58     char *result;
    59 	if(be_clipboard->Lock()) {
    59     if(be_clipboard->Lock()) {
    60 		if((clip = be_clipboard->Data())) {
    60         if((clip = be_clipboard->Data())) {
    61 			/* Presumably the string of characters is ascii-format */
    61             /* Presumably the string of characters is ascii-format */
    62 			clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text,
    62             clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text,
    63 				&length);
    63                 &length);
    64 		}
    64         }
    65 		be_clipboard->Unlock();
    65         be_clipboard->Unlock();
    66 	} 
    66     } 
    67 	
    67     
    68 	if (!text) {
    68     if (!text) {
    69 		result = SDL_strdup("");
    69         result = SDL_strdup("");
    70 	} else {
    70     } else {
    71 		/* Copy the data and pass on to SDL */
    71         /* Copy the data and pass on to SDL */
    72 		result = (char *)SDL_malloc((length + 1) * sizeof(char));
    72         result = (char *)SDL_malloc((length + 1) * sizeof(char));
    73 		SDL_strlcpy(result, text, length + 1);
    73         SDL_strlcpy(result, text, length + 1);
    74 	}
    74     }
    75 	
    75     
    76 	return result;
    76     return result;
    77 }
    77 }
    78 
    78 
    79 SDL_bool HAIKU_HasClipboardText(_THIS) {
    79 SDL_bool HAIKU_HasClipboardText(_THIS) {
    80 	SDL_bool result = SDL_FALSE;
    80     SDL_bool result = SDL_FALSE;
    81 	char *text = HAIKU_GetClipboardText(_this);
    81     char *text = HAIKU_GetClipboardText(_this);
    82 	if (text) {
    82     if (text) {
    83 		result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
    83         result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
    84 		SDL_free(text);
    84         SDL_free(text);
    85 	} 
    85     } 
    86 	return result;
    86     return result;
    87 }
    87 }
    88 
    88 
    89 #ifdef __cplusplus
    89 #ifdef __cplusplus
    90 }
    90 }
    91 #endif
    91 #endif