/* ================ Sys_GetClipboardData create buffer, that contain clipboard ================ */ char *Sys_GetClipboardData( void ) { #ifdef XASH_SDL return SDL_GetClipboardText(); #else return 0; #endif }
void console_paste() { char *p = SDL_GetClipboardText(); char *q = p; while( p && *p ) console_put(*p++); SDL_free(q); }
virtual std::string text() const { char* clipboardText = SDL_GetClipboardText(); if (clipboardText == NULL) return std::string{}; else return std::string{clipboardText}; }
const char* CInput::GetClipboardText() { if(m_pClipboardText) { SDL_free(m_pClipboardText); } m_pClipboardText = SDL_GetClipboardText(); return m_pClipboardText; }
int PDC_getclipboard(char **contents, long *length) { PDC_LOG(("PDC_getclipboard() - called\n")); if (SDL_HasClipboardText() == SDL_FALSE) return PDC_CLIP_EMPTY; *contents = SDL_GetClipboardText(); *length = strlen(*contents); return PDC_CLIP_SUCCESS; }
char *Runtime::getClipboardText() { char *result; char *text = SDL_GetClipboardText(); if (text && text[0]) { result = strdup(text); SDL_free(text); } else { result = NULL; } return result; }
/** * \brief Check call to SDL_GetClipboardText * * \sa * http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText */ int clipboard_testGetClipboardText(void *arg) { char *charResult; charResult = SDL_GetClipboardText(); SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded"); if (charResult) SDL_free(charResult); return TEST_COMPLETED; }
std::string copy_from_clipboard(const bool) { char* clipboard = SDL_GetClipboardText(); if(!clipboard) { return std::string(); } const std::string result(clipboard); SDL_free(clipboard); return result; }
const char *CInput::GetClipboardText() { if(m_pClipboardText) { SDL_free(m_pClipboardText); } m_pClipboardText = SDL_GetClipboardText(); if(m_pClipboardText) str_sanitize_cc(m_pClipboardText); return m_pClipboardText; }
Platform::ClipboardData Platform::get_clipboard_data() { if (!SDL_HasClipboardText()) return ClipboardData{}; auto text = SDL_GetClipboardText(); if (!text) return ClipboardData{}; auto data = ClipboardData{text}; SDL_free(text); return data; }
wchar *Sys_GetClipboardTextW(void) { char *tmp; wchar *wtmp = NULL; if (SDL_HasClipboardText()) { tmp = SDL_GetClipboardText(); wtmp = str2wcs(tmp); free(tmp); } return wtmp; }
std::string WindowSDL::getClipboardText() const { if(SDL_HasClipboardText() == SDL_FALSE) { return std::string(); } auto sdlText = SDL_GetClipboardText(); if(sdlText == nullptr) { WARN(std::string("SDL_GetClipboardText failed: ") + SDL_GetError()); return std::string(); } const std::string text(sdlText); SDL_free(sdlText); return text; }
char *osd_get_clipboard_text(void) { char *result = NULL; if (SDL_HasClipboardText()) { char *temp = SDL_GetClipboardText(); result = (char *) osd_malloc_array(strlen(temp) + 1); strcpy(result, temp); SDL_free(temp); } return result; }
/* ================== Sys_GetClipboardData ================== */ char *Sys_GetClipboardData(void) { if ( !SDL_HasClipboardText() ) return NULL; char *cbText = SDL_GetClipboardText(); size_t len = strlen( cbText ) + 1; char *buf = (char *)Z_Malloc( len, TAG_CLIPBOARD, qfalse ); Q_strncpyz( buf, cbText, len ); SDL_free( cbText ); return buf; }
std::string System::getClipboardText() const { std::string text(""); char *ctext = SDL_GetClipboardText(); if (ctext) { text = std::string(ctext); SDL_free(ctext); } return text; }
const char* system_getClipboardText() { char* text = SDL_GetClipboardText(); //it's not null terminated if (text) { moduleData.clipboardText = malloc(strlen(text) + 1); strcpy(moduleData.clipboardText, text); SDL_free(text); return moduleData.clipboardText; } return ""; }
Common::String OSystem_SDL::getTextFromClipboard() { if (!hasTextInClipboard()) return ""; #if SDL_VERSION_ATLEAST(2, 0, 0) char *text = SDL_GetClipboardText(); Common::String strText = text; SDL_free(text); // FIXME: The string returned by SDL is in UTF-8, it is not clear // what encoding should be used for the returned string. return strText; #else return ""; #endif }
char *Sys_GetClipboardData (void) { char *data = NULL; char *cliptext; cliptext = SDL_GetClipboardText(); if (cliptext != NULL) { size_t allocsize; allocsize = strlen(cliptext) + 1; data = (char *)Z_Malloc (allocsize); strlcpy (data, cliptext, allocsize); SDL_free(cliptext); } return data; }
/* ================== Sys_GetClipboardData ================== */ char *Sys_GetClipboardData( void ) { #ifdef DEDICATED return NULL; #else if ( !SDL_HasClipboardText() ) return NULL; char *cbText = SDL_GetClipboardText(); size_t len = strlen( cbText ) + 1; char *buf = (char *)Z_Malloc( len, TAG_CLIPBOARD ); Q_strncpyz( buf, cbText, len ); SDL_free( cbText ); return buf; #endif }
static mrb_value mrb_sdl2_clipboard_text(mrb_state *mrb, mrb_value self) { if (SDL_HasClipboardText()) { mrb_value s; char * text = SDL_GetClipboardText(); if (!text) return mrb_nil_value(); s = mrb_str_new_cstr(mrb, text); free(text); return s; } return mrb_nil_value(); }
static int textinput_event(component *c, SDL_Event *e) { // Handle selection if (e->type == SDL_TEXTINPUT) { textinput *tb = widget_get_obj(c); size_t len = strlen(tb->buf); if (strlen(e->text.text) == 1) { // make sure it is not a unicode sequence unsigned char c = e->text.text[0]; if (c >= 32 && c <= 126) { // only allow ASCII through if (len < sizeof(tb->buf)-1) { tb->buf[len+1] = '\0'; tb->buf[len] = c; } } } } else if (e->type == SDL_KEYDOWN) { textinput *tb = widget_get_obj(c); size_t len = strlen(tb->buf); const unsigned char *state = SDL_GetKeyboardState(NULL); if (state[SDL_SCANCODE_BACKSPACE] || state[SDL_SCANCODE_DELETE]) { if (len > 0) { tb->buf[len-1] = '\0'; } } else if(state[SDL_SCANCODE_LEFT]) { // TODO move cursor to the left } else if(state[SDL_SCANCODE_RIGHT]) { // TODO move cursor to the right } else if(state[SDL_SCANCODE_V] && state[SDL_SCANCODE_LCTRL]) { if(SDL_HasClipboardText()) { char* clip_text = SDL_GetClipboardText(); int c_size = strlen(clip_text); if((c_size + len) > sizeof(tb->buf)-1) { c_size = sizeof(tb->buf) - 1 - len; } memcpy(tb->buf + len, clip_text, c_size); len += c_size; tb->buf[len] = 0; } } } return 1; }
// Get text from the clipboard bool get_scrap(char **dst) { if (has_scrap()) { char *cliptext = SDL_GetClipboardText(); if (!cliptext) { debug(LOG_ERROR, "Could not get clipboard text because : %s", SDL_GetError()); return false; } *dst = cliptext; return true; } else { // wasn't text or no text in the clipboard return false; } }
char *Sys_GetClipboardData (void) { #if SDL_MAJOR_VERSION != 1 char *data = NULL; char *cliptext; cliptext = SDL_GetClipboardText(); if (cliptext != NULL) { size_t allocsize; allocsize = strlen(cliptext) + 1; data = (char *)Z_Malloc (allocsize); strlcpy (data, cliptext, allocsize); SDL_free(cliptext); } return data; #elif defined(WIN32) char *data = NULL; char *cliptext; if (OpenClipboard (NULL) != 0) { HANDLE hClipboardData; if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0) { if ((cliptext = (char *)GlobalLock (hClipboardData)) != 0) { size_t allocsize; allocsize = GlobalSize (hClipboardData) + 1; data = (char *)Z_Malloc (allocsize); strlcpy (data, cliptext, allocsize); GlobalUnlock (hClipboardData); } } CloseClipboard (); } return data; #else return NULL; #endif }
/* ================== Sys_GetClipboardData ================== */ char *Sys_GetClipboardData(void) { #ifdef DEDICATED return NULL; #else char *data = NULL; char *cliptext; if ( ( cliptext = SDL_GetClipboardText() ) != NULL ) { if ( cliptext[0] != '\0' ) { size_t bufsize = strlen( cliptext ) + 1; data = Z_Malloc( bufsize ); Q_strncpyz( data, cliptext, bufsize ); // find first listed char and set to '\0' strtok( data, "\n\r\b" ); } SDL_free( cliptext ); } return data; #endif }
/* ================== Sys_GetClipboardData ================== */ char *Sys_GetClipboardData( clipboard_t clip ) { #ifdef BUILD_CLIENT #if SDL_VERSION_ATLEAST( 2, 0, 0 ) char *buffer = SDL_GetClipboardText(); char *data = NULL; if( !buffer ) { return NULL; } data = ( char * ) Z_Malloc( sizeof( buffer ) ); Q_strncpyz( data, buffer, sizeof( buffer ) ); SDL_free( buffer ); return data; #else return NULL; #endif #else return NULL; #endif }
const char* Clipboard::GetText () { return SDL_GetClipboardText (); }
void SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done) { int i; static SDL_MouseMotionEvent lastEvent; if (state->verbose & VERBOSE_EVENT) { SDLTest_PrintEvent(event); } switch (event->type) { case SDL_WINDOWEVENT: switch (event->window.event) { case SDL_WINDOWEVENT_CLOSE: { SDL_Window *window = SDL_GetWindowFromID(event->window.windowID); if (window) { SDL_DestroyWindow(window); } } break; } break; case SDL_KEYDOWN: switch (event->key.keysym.sym) { /* Add hotkeys here */ case SDLK_PRINTSCREEN: { SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { for (i = 0; i < state->num_windows; ++i) { if (window == state->windows[i]) { SDLTest_ScreenShot(state->renderers[i]); } } } } break; case SDLK_EQUALS: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-+ double the size of the window */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { int w, h; SDL_GetWindowSize(window, &w, &h); SDL_SetWindowSize(window, w*2, h*2); } } break; case SDLK_MINUS: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-- half the size of the window */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { int w, h; SDL_GetWindowSize(window, &w, &h); SDL_SetWindowSize(window, w/2, h/2); } } break; case SDLK_c: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-C copy awesome text! */ SDL_SetClipboardText("SDL rocks!\nYou know it!"); printf("Copied text to clipboard\n"); } if (event->key.keysym.mod & KMOD_ALT) { /* Alt-C toggle a render clip rectangle */ for (i = 0; i < state->num_windows; ++i) { int w, h; if (state->renderers[i]) { SDL_Rect clip; SDL_GetWindowSize(state->windows[i], &w, &h); SDL_RenderGetClipRect(state->renderers[i], &clip); if (SDL_RectEmpty(&clip)) { clip.x = w/4; clip.y = h/4; clip.w = w/2; clip.h = h/2; SDL_RenderSetClipRect(state->renderers[i], &clip); } else { SDL_RenderSetClipRect(state->renderers[i], NULL); } } } } break; case SDLK_v: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-V paste awesome text! */ char *text = SDL_GetClipboardText(); if (*text) { printf("Clipboard: %s\n", text); } else { printf("Clipboard is empty\n"); } SDL_free(text); } break; case SDLK_g: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-G toggle grab */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window) ? SDL_TRUE : SDL_FALSE); } } break; case SDLK_m: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-M maximize */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { Uint32 flags = SDL_GetWindowFlags(window); if (flags & SDL_WINDOW_MAXIMIZED) { SDL_RestoreWindow(window); } else { SDL_MaximizeWindow(window); } } } break; case SDLK_r: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-R toggle mouse relative mode */ SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode() ? SDL_TRUE : SDL_FALSE); } break; case SDLK_z: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-Z minimize */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { SDL_MinimizeWindow(window); } } break; case SDLK_RETURN: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-Enter toggle fullscreen */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { Uint32 flags = SDL_GetWindowFlags(window); if (flags & SDL_WINDOW_FULLSCREEN) { SDL_SetWindowFullscreen(window, SDL_FALSE); } else { SDL_SetWindowFullscreen(window, SDL_TRUE); } } } else if (event->key.keysym.mod & KMOD_ALT) { /* Alt-Enter toggle fullscreen desktop */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { Uint32 flags = SDL_GetWindowFlags(window); if (flags & SDL_WINDOW_FULLSCREEN) { SDL_SetWindowFullscreen(window, SDL_FALSE); } else { SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); } } } break; case SDLK_b: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-B toggle window border */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { const Uint32 flags = SDL_GetWindowFlags(window); const SDL_bool b = ((flags & SDL_WINDOW_BORDERLESS) != 0) ? SDL_TRUE : SDL_FALSE; SDL_SetWindowBordered(window, b); } } break; case SDLK_0: if (event->key.keysym.mod & KMOD_CTRL) { SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window); } break; case SDLK_1: if (event->key.keysym.mod & KMOD_CTRL) { FullscreenTo(0, event->key.windowID); } break; case SDLK_2: if (event->key.keysym.mod & KMOD_CTRL) { FullscreenTo(1, event->key.windowID); } break; case SDLK_ESCAPE: *done = 1; break; case SDLK_SPACE: { char message[256]; SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); SDL_snprintf(message, sizeof(message), "(%i, %i), rel (%i, %i)\n", lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Last mouse position", message, window); break; } default: break; } break; case SDL_QUIT: *done = 1; break; case SDL_MOUSEMOTION: lastEvent = event->motion; break; } }
void TextField::handleKeyboard(const SDL_Event& keyEvent) { if (editable_) { switch (keyEvent.type) { case SDL_TEXTINPUT: // Update only if the glyph is avaiable. if (font_.getTtfFont() != 0 && 0 == TTF_SizeUTF8(font_.getTtfFont(), keyEvent.text.text, 0, 0)) { // A Utf8 string as input. inputFormatter_.update(keyEvent.text.text); text_.setText(inputFormatter_.getText()); markerChanged_ = true; } break; case SDL_KEYDOWN: // Reset marker animation. markerDeltaTime_ = 0; switch (keyEvent.key.keysym.sym) { case SDLK_v: // Paste from clipboard! if ((keyEvent.key.keysym.mod & KMOD_CTRL) && SDL_HasClipboardText()) { char* text = SDL_GetClipboardText(); inputFormatter_.update(SDL_GetClipboardText()); text_.setText(inputFormatter_.getText()); markerChanged_ = true; SDL_free(text); } break; case SDLK_c: // Copy from textfield! if (keyEvent.key.keysym.mod & KMOD_CTRL) { SDL_SetClipboardText(inputFormatter_.getText().c_str()); } break; case SDLK_x: // Cut from textfield! if (keyEvent.key.keysym.mod & KMOD_CTRL) { SDL_SetClipboardText(inputFormatter_.getText().c_str()); inputFormatter_.clear(); text_.setText(inputFormatter_.getText()); markerChanged_ = true; } break; case SDLK_HOME: inputFormatter_.update(InputFormatter::INPUT_MOVE_MARKER_HOME); markerChanged_ = true; break; case SDLK_END: inputFormatter_.update(InputFormatter::INPUT_MOVE_MARKER_END); markerChanged_ = true; break; case SDLK_LEFT: inputFormatter_.update(InputFormatter::INPUT_MOVE_MARKER_LEFT); markerChanged_ = true; break; case SDLK_RIGHT: inputFormatter_.update(InputFormatter::INPUT_MOVE_MARKER_RIGHT); markerChanged_ = true; break; case SDLK_BACKSPACE: inputFormatter_.update(InputFormatter::INPUT_ERASE_LEFT); text_.setText(inputFormatter_.getText()); markerChanged_ = true; break; case SDLK_DELETE: inputFormatter_.update(InputFormatter::INPUT_ERASE_RIGHT); text_.setText(inputFormatter_.getText()); markerChanged_ = true; break; case SDLK_RETURN: // Fall through! case SDLK_KP_ENTER: doAction(); break; } break; } if (markerChanged_) { markerChanged_ = false; int index = inputFormatter_.getMarkerPosition(); std::string leftText = getText().substr(0, index); int w, h; if (font_.getTtfFont()) { TTF_SizeUTF8(font_.getTtfFont(), leftText.c_str(), &w, &h); // One pixel to the right of the last character. } markerWidth_ = (float) w + 1; } } }
int idris_SDL_getClipboardText() { getClipboardText_string = SDL_GetClipboardText(); return getClipboardText_string != NULL; }
void ConsoleInfo::edit(int key, int mod) { if(key == SDLK_UNKNOWN || key == SDLK_BACKQUOTE || key == SDLK_BACKSLASH || !inited) { return; } if(key == SDLK_RETURN) { addLog(m_editingLine); addLine(std::string("> ") + m_editingLine, FontStyle::ConsoleInfo); Engine_ExecCmd(m_editingLine.c_str()); m_editingLine.clear(); m_cursorPos = 0; m_cursorX = 8 + 1; return; } m_blinkTime = 0.0; m_showCursor = 1; int16_t oldLength = utf8_strlen(m_editingLine.c_str()); // int16_t is absolutly enough switch(key) { case SDLK_UP: case SDLK_DOWN: if(m_historyLines.empty()) break; Audio_Send(engine_lua.getGlobalSound(TR_AUDIO_SOUND_GLOBALID_MENUPAGE)); if(key == SDLK_UP && m_historyPos < m_historyLines.size()) ++m_historyPos; else if(key == SDLK_DOWN && m_historyPos > 0) --m_historyPos; if(m_historyPos > 0) m_editingLine = m_historyLines[m_historyPos - 1]; else m_editingLine.clear(); m_cursorPos = utf8_strlen(m_editingLine.c_str()); break; case SDLK_LEFT: if(m_cursorPos > 0) { m_cursorPos--; } break; case SDLK_RIGHT: if(m_cursorPos < oldLength) { m_cursorPos++; } break; case SDLK_HOME: m_cursorPos = 0; break; case SDLK_END: m_cursorPos = oldLength; break; case SDLK_BACKSPACE: if(m_cursorPos > 0) { m_editingLine.erase(m_cursorPos - 1, 1); m_cursorPos--; } break; case SDLK_DELETE: if(m_cursorPos < oldLength) { m_editingLine.erase(m_cursorPos, 1); } break; case SDLK_TAB: { std::string needle = m_editingLine.substr(0, m_cursorPos); // find auto-completion terms, case-insensitive std::vector<std::string> found; std::copy_if(m_completionItems.begin(), m_completionItems.end(), std::back_inserter(found), [needle](const std::string& completion){ return startsWithLowercase(completion, needle); }); if(found.empty()) { // no completion, do nothing } else if(found.size() == 1) { // if we have only one term found, use it! m_editingLine.erase(0, found[0].length()); m_editingLine.insert(0, found[0]); m_cursorPos = found[0].length(); } else { // else we must find the common completion string for(std::string& term : found) { // cut off the needle part term.erase(0, needle.length()); } // now find a common start std::string common = found[0]; for(size_t i=1; !common.empty() && i<found.size(); ++i) { // cut off from the end that's not common with current for(size_t j=0; j<std::min(common.length(), found[i].length()); ++j) { if(std::tolower(common[j]) != std::tolower(found[i][j])) { common.erase(j); break; } } } if(common.empty()) { // nothing common, print possible completions addLine("Possible completions:", FontStyle::ConsoleInfo); for(const std::string& term : found) addLine(std::string("* ") + needle + term, FontStyle::ConsoleInfo); } else { m_editingLine.insert(m_cursorPos, common); m_cursorPos += common.length(); } } } break; default: if( key == SDLK_v && mod>0 && (mod & KMOD_CTRL) ) { if(char* clipboard = SDL_GetClipboardText()) { const int16_t textLength = utf8_strlen(clipboard); if(oldLength < m_lineSize - textLength) { m_editingLine.insert(m_cursorPos, clipboard); m_cursorPos += textLength; } SDL_free(clipboard); } } else if(mod<0 && (oldLength < m_lineSize - 1) && (key >= SDLK_SPACE)) { m_editingLine.insert(m_editingLine.begin() + m_cursorPos, char(key)); m_cursorPos++; } break; } calcCursorPosition(); }