Exemplo n.º 1
0
bool OSystem_SDL::hasTextInClipboard() {
#if SDL_VERSION_ATLEAST(2, 0, 0)
	return SDL_HasClipboardText() == SDL_TRUE;
#else
	return false;
#endif
}
Exemplo n.º 2
0
static int textinput_event(component *c, SDL_Event *e) {
    // Handle selection
    if(e->type == SDL_TEXTINPUT) {
        textinput *tb = widget_get_obj(c);
        strncat(tb->buf, e->text.text, tb->max_chars - strlen(tb->buf));
        return 0;
    } 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()) {
                strncat(tb->buf, SDL_GetClipboardText(), tb->max_chars - strlen(tb->buf));
            }
        }
        return 0;
    }
    return 1;
}
Exemplo n.º 3
0
char *IN_GetClipboardData(void)
{
	if (SDL_HasClipboardText())
	{
		char *data = NULL, *temp = NULL;
		int  len   = 0;

		temp = SDL_GetClipboardText();
		if (!temp || !temp[0])
		{
			return NULL;
		}

		//len = u8_strlen(temp) + 1;
		len = strlen(temp) + 1;

		data = Z_Malloc(len);

		//u8_escape(data, len, temp, qfalse);
		Q_strncpyz(data, temp, len);

		strtok(data, "\n\r\b");
		SDL_free(temp);

		return data;
	}
	else
	{
		return NULL;
	}
}
Exemplo n.º 4
0
/**
 * \brief Check call to SDL_HasClipboardText
 *
 * \sa
 * http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
 */
int
clipboard_testHasClipboardText(void *arg)
{
    SDL_bool result;
    result = SDL_HasClipboardText();
    SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");

    return TEST_COMPLETED;
}
Exemplo n.º 5
0
int PDC_clearclipboard(void)
{
    PDC_LOG(("PDC_clearclipboard() - called\n"));

    if (SDL_HasClipboardText() == SDL_TRUE)
    {
        SDL_SetClipboardText(NULL);
    }

    return PDC_CLIP_SUCCESS;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
wchar *Sys_GetClipboardTextW(void)
{
	char *tmp;
	wchar *wtmp = NULL;

	if (SDL_HasClipboardText()) {
		tmp = SDL_GetClipboardText();
		wtmp = str2wcs(tmp);
		free(tmp);
	}

	return wtmp;
}
Exemplo n.º 9
0
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;
}
Exemplo n.º 10
0
/*
==================
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;
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
/*
==================
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
}
Exemplo n.º 13
0
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();
}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
0
bool GerenciadorDeEventos::temStringNaAreaDeTransferencia()
{
	return SDL_HasClipboardText();
}
Exemplo n.º 16
0
// See if we have TEXT in the clipboard
bool has_scrap(void)
{
	return SDL_HasClipboardText();
}
Exemplo n.º 17
0
/**
 * \brief End-to-end test of SDL_xyzClipboardText functions
 * \sa
 * http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
 * http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
 * http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
 */
int
clipboard_testClipboardTextFunctions(void *arg)
{
    char *textRef = SDLTest_RandomAsciiString();
    char *text = SDL_strdup(textRef);
    SDL_bool boolResult;
    int intResult;
    char *charResult;

    /* Clear clipboard text state */
    boolResult = SDL_HasClipboardText();
    SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
    if (boolResult == SDL_TRUE) {
        intResult = SDL_SetClipboardText((const char *)NULL);
        SDLTest_AssertPass("Call to SDL_SetClipboardText(NULL) succeeded");
        SDLTest_AssertCheck(
            intResult == 0,
            "Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
            intResult);
        charResult = SDL_GetClipboardText();
        SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
        boolResult = SDL_HasClipboardText();
        SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
        SDLTest_AssertCheck(
            boolResult == SDL_FALSE,
            "Verify SDL_HasClipboardText returned SDL_FALSE, got %s",
            (boolResult) ? "SDL_TRUE" : "SDL_FALSE");
    }

    /* Empty clipboard  */
    charResult = SDL_GetClipboardText();
    SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
    SDLTest_AssertCheck(
        charResult != NULL,
        "Verify SDL_GetClipboardText did not return NULL");
    SDLTest_AssertCheck(
        SDL_strlen(charResult) == 0,
        "Verify SDL_GetClipboardText returned string with length 0, got length %i",
        SDL_strlen(charResult));
    intResult = SDL_SetClipboardText((const char *)text);
    SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
    SDLTest_AssertCheck(
        intResult == 0,
        "Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
        intResult);
    SDLTest_AssertCheck(
        SDL_strcmp(textRef, text) == 0,
        "Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
        textRef, text);
    boolResult = SDL_HasClipboardText();
    SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
    SDLTest_AssertCheck(
        boolResult == SDL_TRUE,
        "Verify SDL_HasClipboardText returned SDL_TRUE, got %s",
        (boolResult) ? "SDL_TRUE" : "SDL_FALSE");
    charResult = SDL_GetClipboardText();
    SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
    SDLTest_AssertCheck(
        SDL_strcmp(textRef, charResult) == 0,
        "Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'",
        textRef, charResult);

    /* Cleanup */
    if (textRef) SDL_free(textRef);
    if (text) SDL_free(text);
    if (charResult) SDL_free(charResult);

   return TEST_COMPLETED;
}
Exemplo n.º 18
0
// Clipboard
bool hasClipboardString() { return SDL_HasClipboardText() == SDL_TRUE; }
void PGE_TextInputBox::processBox(double tickTime)
{
    PGE_BoxBase::processBox(tickTime);

    bool wasExitKeyPress = m_keys.run_pressed || m_keys.alt_run_pressed || m_keys.start_pressed;
    if(wasExitKeyPress)
    {
        if(m_keys.start_pressed || m_keys.jump_pressed || m_keys.alt_jump_pressed)
            m_inputTextSrc = m_inputText;
        nextPage();
        setFade(10, 0.0, 0.05);
        SDL_StopTextInput();
        return;
    }

    m_blinkTimeout -= tickTime;
    if(m_blinkTimeout < 0.0)
    {
        m_blinkShown = !m_blinkShown;
        m_blinkTimeout += (tickTime < 250.0) ? 250.0 : tickTime + 250.0;
    }

    SDL_StartTextInput();
    SDL_Event event;

    while(SDL_PollEvent(&event))
    {
        PGE_Window::processEvents(event);

        switch(event.type)
        {
        case SDL_QUIT:
            nextPage();
            setFade(10, 0.0, 0.05);
            SDL_StopTextInput();
            break;

        case SDL_KEYDOWN: // If pressed key
        {
            switch(event.key.keysym.sym)
            {
            // Check which
            case SDLK_ESCAPE: // ESC
            case SDLK_RETURN:// Enter
            case SDLK_KP_ENTER:
            case SDLK_AC_BACK://Android "back" key
            {
                if(event.key.keysym.sym != SDLK_ESCAPE && event.key.keysym.sym != SDLK_AC_BACK)
                    m_inputTextSrc = m_inputText;
                nextPage();
                setFade(10, 0.0, 0.05);
                SDL_StopTextInput();
                break;
            }

            case SDLK_BACKSPACE:
            {
                if(m_inputText.length() > 0)
                {
                    FontManager::utf8_pop_back(m_inputText);
                    updatePrintable();
                }
                break;
            }

            default:
                break;
            }

            switch(event.key.keysym.scancode)
            {
            case SDL_SCANCODE_V:
            {
                if((event.key.keysym.mod & KMOD_CTRL) && (SDL_HasClipboardText() == SDL_TRUE))
                {
                    m_inputText.append(SDL_GetClipboardText());
                    std::remove(m_inputText.begin(), m_inputText.end(), '\r');
                    std::replace(m_inputText.begin(), m_inputText.end(), '\n', ' ');
                    updatePrintable();
                }
                break;
            }
            default:
                break;
            }

            break;
        }

        case SDL_TEXTINPUT:
        {
            D_pLogDebug("TEXT INPUT EVENT %s", event.text.text);
            m_inputText.append(event.text.text);
            updatePrintable();
        }
        break;

        case SDL_TEXTEDITING:
        {
            D_pLogDebug("TEXT EDIT EVENT start %d, %s", event.edit.start, event.edit.text);
            m_inputText      = event.edit.text;
            m_cursor          = event.edit.start;
            m_selectionLength   = event.edit.length;
            updatePrintable();
        }
        break;

        //            case SDL_MOUSEBUTTONDOWN:
        //                switch(event.button.button)
        //                {
        //                    case SDL_BUTTON_LEFT:
        //                    {
        //                        _page++;
        //                        setFade(10, 0.0f, 0.05f);
        //                    }
        //                    break;
        //                }
        //            break;
        default:
            break;
        }
    }
}
Exemplo n.º 20
0
	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;
			}
		}
	}
Exemplo n.º 21
0
/*
* Sys_GetClipboardData
*/
char *Sys_GetClipboardData( void )
{
	if( SDL_HasClipboardText() == SDL_TRUE )
		return SDL_GetClipboardText();
	return NULL;
}
Exemplo n.º 22
0
static mrb_value
mrb_sdl2_clipboard_has_text(mrb_state *mrb, mrb_value self)
{
  SDL_bool r = SDL_HasClipboardText();
  return (SDL_FALSE == r) ? mrb_false_value() : mrb_true_value();
}
Exemplo n.º 23
0
void TextEntry::HandleKeyDown(const KeyboardEvent &event)
{
    std::string text(m_label->GetText());

    switch (event.keysym.sym) {
    case SDLK_LEFT:
        if (m_cursor > 0) {
            const char *cstr = text.c_str();
            m_cursor -= Text::utf8_prev_char_offset(cstr + m_cursor, cstr);
        }
        break;

    case SDLK_RIGHT:
        if (m_cursor < text.size()) {
            m_cursor += Text::utf8_next_char_offset(text.c_str() + m_cursor);
        }
        break;

    case SDLK_HOME:
        m_cursor = 0;
        break;

    case SDLK_END:
        m_cursor = text.size();
        break;

    case SDLK_BACKSPACE:
        if (text.size() > 0 && m_cursor > 0) {
            const char *cstr = text.c_str();
            const int len = Text::utf8_prev_char_offset(cstr + m_cursor, cstr);
            m_cursor -= len;
            text.erase(m_cursor, len);

            m_label->SetText(text);
            onChange.emit(text);
        }
        break;

    case SDLK_DELETE:
        if (text.size() > m_cursor) {
            const int len = Text::utf8_next_char_offset(text.c_str() + m_cursor);
            text.erase(m_cursor, len);

            m_label->SetText(text);
            onChange.emit(text);
        }
        break;

    case SDLK_RETURN:
        GetContext()->DeselectWidget(this);
        onEnter.emit(text);
        break;

    default:
        if (event.keysym.mod & KMOD_CTRL) {
            switch (event.keysym.sym) {
            case SDLK_u:
                m_cursor = 0;
                m_label->SetText("");
                onChange.emit("");
                break;

            case SDLK_w: {
                size_t pos = text.find_last_not_of(' ', m_cursor);
                if (pos != std::string::npos) pos = text.find_last_of(' ', pos);
                m_cursor = pos != std::string::npos ? pos+1 : 0;
                text.erase(m_cursor);
                m_label->SetText(text);
                onChange.emit(text);
                break;
            }

            case SDLK_v: { // XXX SDLK_PASTE?
                if (SDL_HasClipboardText()) {
                    char *paste = SDL_GetClipboardText();
                    int len = strlen(paste); // XXX strlen not utf8-aware
                    text.insert(m_cursor, paste, len);
                    m_label->SetText(text);
                    m_cursor += len;
                    SDL_free(paste);
                }
            }

            default:
                break;
            }
        }

    }
}
Exemplo n.º 24
0
Arquivo: nanovg.c Projeto: caivega/gui
static gui_bool
clipboard_is_filled(void)
{return SDL_HasClipboardText();}
Exemplo n.º 25
0
		virtual bool has_text() const
		{
			return SDL_HasClipboardText() == SDL_TRUE;
		}
Exemplo n.º 26
0
	bool Clipboard::HasText () {
		
		return SDL_HasClipboardText ();
		
	}
Exemplo n.º 27
0
	static int lua_SDL_HasClipboardText(lutok::state& state){
		state.push_boolean(SDL_HasClipboardText() == SDL_TRUE);
		return 1;
	}