Beispiel #1
0
void ttext_box::delete_char(const bool before_cursor)
{
	if(before_cursor) {
		set_cursor(get_selection_start() - 1, false);
	}

	set_selection_length(1);

	delete_selection();
}
Beispiel #2
0
void ttext_::handle_key_delete(SDLMod /*modifier*/, bool& handled)
{
	DBG_GUI_E << LOG_SCOPE_HEADER << '\n';

	handled = true;
	if(selection_length_ != 0) {
		delete_selection();
	} else if (selection_start_ < text_.get_length()) {
		delete_char(false);
	}
}
Beispiel #3
0
void ttext_::handle_key_backspace(SDLMod /*modifier*/, bool& handled)
{
	DBG_GUI_E << LOG_SCOPE_HEADER << '\n';

	handled = true;
	if(selection_length_ != 0) {
		delete_selection();
	} else if(selection_start_){
		delete_char(true);
	}
	fire(event::NOTIFY_MODIFIED, *this, NULL);
}
Beispiel #4
0
void ttext_::insert_char(const Uint16 unicode)
{
	delete_selection();

	if(text_.insert_unicode(selection_start_, unicode)) {

		// Update status
		set_cursor(selection_start_ + 1, false);
		update_canvas();
		set_dirty(true);
	}
}
Beispiel #5
0
void ttext_::handle_key_delete(SDL_Keymod /*modifier*/, bool& handled)
{
	DBG_GUI_E << LOG_SCOPE_HEADER << '\n';

	handled = true;
	if(selection_length_ != 0) {
		delete_selection();
	} else if(selection_start_ < text_.get_length()) {
		delete_char(false);
	}
	fire(event::NOTIFY_MODIFIED, *this, nullptr);
}
Beispiel #6
0
void ttext_::insert_char(const utf8::string& unicode)
{
	delete_selection();

	if(text_.insert_text(selection_start_, unicode)) {

		// Update status
		set_cursor(selection_start_ + 1, false);
		update_canvas();
		set_is_dirty(true);
	}
}
Beispiel #7
0
void ttext_::paste_selection(const bool mouse)
{
	const std::string& text = copy_from_clipboard(mouse);
	if(text.empty()) {
		return;
	}

	delete_selection();

	selection_start_ += text_.insert_text(selection_start_, text);

	update_canvas();
	set_dirty();
}
static gboolean
treeview_key_press_event_cb (GtkTreeView *treeview,
			     GdkEventKey *event,
			     DialogTab *tab)
{
	if (event->keyval == GDK_Delete || event->keyval == GDK_KP_Delete)
	{
		delete_selection (tab);

		return TRUE;
	}

	return FALSE;
}
Beispiel #9
0
void ttext_::paste_selection(const bool mouse)
{
	const std::string& text = copy_from_clipboard(mouse);
	if(text.empty()) {
		return;
	}

	delete_selection();

	selection_start_ += text_.insert_text(selection_start_, text);

	update_canvas();
	set_dirty(true);
	fire(event::NOTIFY_MODIFIED, *this, NULL);
}
Beispiel #10
0
void tpassword_box::handle_key_delete(SDLMod /*modifier*/, bool& handled) {
	pre_function();

	// Copy & paste from ttext_::handle_key_delete()
	DBG_GUI_E << LOG_SCOPE_HEADER << '\n';

	handled = true;
	if(get_selection_length() != 0) {
		delete_selection();
	} else if (get_selection_start() < get_text_length(text())) {
		delete_char(false);
	}

	post_function();
}
Beispiel #11
0
void ttext_::signal_handler_sdl_key_down(const event::tevent event
		, bool& handled
		, const SDLKey key
		, SDLMod modifier
		, const Uint16 unicode)
{

	DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";

// For copy/paste we use a different key on the MAC. Other ctrl modifiers won't
// be modifed seems not to be required when I read the comment in
// widgets/textbox.cpp:516. Would be nice if somebody on a MAC would test it.
#ifdef __APPLE__
	const unsigned copypaste_modifier = KMOD_LMETA | KMOD_RMETA;
#else
	const unsigned copypaste_modifier = KMOD_CTRL;
#endif

	switch(key) {

		case SDLK_LEFT :
			handle_key_left_arrow(modifier, handled);
			break;

		case SDLK_RIGHT :
			handle_key_right_arrow(modifier, handled);
			break;

		case SDLK_UP :
			handle_key_up_arrow(modifier, handled);
			break;

		case SDLK_DOWN :
			handle_key_down_arrow(modifier, handled);
			break;

		case SDLK_PAGEUP :
			handle_key_page_up(modifier, handled);
			break;

		case SDLK_PAGEDOWN :
			handle_key_page_down(modifier, handled);
			break;

		case SDLK_a :
			if(!(modifier & KMOD_CTRL)) {
				handle_key_default(handled, key, modifier, unicode);
				break;
			}

			// If ctrl-a is used for home drop the control modifier
			modifier = static_cast<SDLMod>(modifier &~ KMOD_CTRL);
			/* FALL DOWN */

		case SDLK_HOME :
			handle_key_home(modifier, handled);
			break;

		case SDLK_e :
			if(!(modifier & KMOD_CTRL)) {
				handle_key_default(handled, key, modifier, unicode);
				break;
			}

			// If ctrl-e is used for end drop the control modifier
			modifier = static_cast<SDLMod>(modifier &~ KMOD_CTRL);
			/* FALL DOWN */

		case SDLK_END :
			handle_key_end(modifier, handled);
			break;

		case SDLK_BACKSPACE :
			handle_key_backspace(modifier, handled);
			break;

		case SDLK_u :
			if(modifier & KMOD_CTRL) {
				handle_key_clear_line(modifier, handled);
			} else {
				handle_key_default(handled, key, modifier, unicode);
			}
			break;

		case SDLK_DELETE :
			handle_key_delete(modifier, handled);
			break;

		case SDLK_c :
			if(!(modifier & copypaste_modifier)) {
				handle_key_default(handled, key, modifier, unicode);
				break;
			}

			// atm we don't care whether there is something to copy or paste
			// if nothing is there we still don't want to be chained.
			copy_selection(false);
			handled = true;
			break;

		case SDLK_x :
			if(!(modifier & copypaste_modifier)) {
				handle_key_default(handled, key, modifier, unicode);
				break;
			}

			copy_selection(false);
			delete_selection();
			handled = true;
			break;

		case SDLK_v :
			if(!(modifier & copypaste_modifier)) {
				handle_key_default(handled, key, modifier, unicode);
				break;
			}

			paste_selection(false);
			handled = true;
			break;

		default :
			handle_key_default(handled, key, modifier, unicode);

	}

	if(text_changed_callback_) {
		text_changed_callback_(this, this->text());
	}

}
static void
remove_button_clicked_cb (GtkWidget *button,
			  DialogTab *tab)
{
	delete_selection (tab);
}
Beispiel #13
0
void Text::keystroke(const Event& event) {
  if (readOnly_) {
    return;
  }
  char buffer[8]; // needs to be dynamically adjusted
  int count = event.mapkey(buffer, 8);
  if (count <= 0) {
    return;
  }

  // return causes a newline
  if (buffer[0] == '\r') {
    buffer[0] = '\n';
  }
	context_key(buffer[0]);

	 if (buffer[0] == 2) // control-b
    {
        if (insertion_.column_ > 0)
        {
            --insertion_.column_;
            damage(insertion_);
            repair();
        }else if (insertion_.line_ > 0) {
        	damage(insertion_);
        	--insertion_.line_;
        	// now just like a control-e
        	int index = text_->LineIndex(insertion_.line_);
        	int end = text_->EndOfLine(index);
        	insertion_.column_ = end - index;
       	 	damage(insertion_);
       	 	repair();
       	}
        return;
    }
	 else if (buffer[0] == 1) // control-a
    {
        insertion_.column_ = 0;
        damage(insertion_);
        repair();
        return;
    }
	 else if (buffer[0] == 6) // control-f
    {
        int index = text_->LineIndex(insertion_.line_);
        int end = text_->EndOfLine(index);
        if (insertion_.column_ < end - index)
        {
            ++insertion_.column_;
            damage(insertion_);
            repair();
        }else if (insertion_.line_ < text_->Height()-1) {
        	damage(insertion_);
        	++insertion_.line_;
        	// now just like control-a
        	insertion_.column_ = 0;
        	damage(insertion_);
        	repair();
        }
        return;
    }
    else if (buffer[0] == 5) // control-e
    {
        int index = text_->LineIndex(insertion_.line_);
        int end = text_->EndOfLine(index);
        insertion_.column_ = end - index;
        damage(insertion_);
        repair();
        return;
    }
    else if (buffer[0] == 16) { // control-p
    	if (insertion_.line_ > 0) {
    		damage(insertion_);
    		--insertion_.line_;
		insertion_.column_ = ctl_pn_col_;
    		int index = text_->LineIndex(insertion_.line_);
        	int col = text_->EndOfLine(index) - index;
        	if (col < insertion_.column_){
        		insertion_.column_ = col;
        	}
        	damage(insertion_);
        	repair();
        }
		return;
    }else if (buffer[0] == 14) { // control-n
    	if (insertion_.line_ < text_->Height()-1) {
    		damage(insertion_);
    		++insertion_.line_;
		insertion_.column_ = ctl_pn_col_;
    		int index = text_->LineIndex(insertion_.line_);
        	int col = text_->EndOfLine(index) - index;
        	if (col < insertion_.column_){
        		insertion_.column_ = col;
        	}
        	damage(insertion_);
        	repair();
        }
		return;
    }else if (escape_ == 1) { // escaped chars
	if (buffer[0] == '>') { // to end of buffer
		damage(insertion_);
		if (text_->Height() >0) {
			insertion_.line_ = text_->Height()-1;
		} else {
			insertion_.line_ = 0;
		}
		int index = text_->LineIndex(text_->EndOfText());
		insertion_.column_ = text_->EndOfText()-index;
		damage(insertion_);
		repair();
	}else if (buffer[0] == '<') {// to beginning of buffer
		damage(insertion_);
		insertion_.line_ = 0;
		insertion_.column_ = 0;
		damage(insertion_);
		repair();
	}
	return;
    }else if (buffer[0] == 033) { // ignore the escape itself
	return;
    }
    else if (buffer[0] == 4) // ctrl-d
    {
      if (!delete_selection()) {
    	// like a ctrl-f then backspace
        int index = text_->LineIndex(insertion_.line_);
        int end = text_->EndOfLine(index);
        if (insertion_.column_ < end - index)
        {
            ++insertion_.column_;
            backspace();
        }else if (insertion_.line_ < text_->Height()-1) {
        	++insertion_.line_;
        	// now just like control-a
        	insertion_.column_ = 0;
        	backspace();
        }
      }
    }

  else if (buffer[0] == 21) {
    // control u
    eraseLine();
  }
  else if ((buffer[0] == '\b') || (buffer[0] == 127)) {
    // backspace and delete
  	if (!delete_selection()) {
	 	backspace();
	}
  }
  else {
  	delete_selection();
	 insertChars(buffer, count);
  }

  dirty(true);
}