MCPcopy Create free account
hub / github.com/davisking/dlib / on_paste

Method on_paste

dlib/gui_widgets/widgets.cpp:504–542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

502// ----------------------------------------------------------------------------------------
503
504 void text_field::
505 on_paste (
506 )
507 {
508 ustring temp_str;
509 get_from_clipboard(temp_str);
510
511 // If this is a multi line string then just take the first line.
512 ustring::size_type pos = temp_str.find_first_of('\n');
513 if (pos != ustring::npos)
514 {
515 temp_str = temp_str.substr(0,pos);
516 }
517
518 if (highlight_start <= highlight_end)
519 {
520 text_ = text_.substr(0,highlight_start) + temp_str +
521 text_.substr(highlight_end+1,text_.size()-highlight_end-1);
522 move_cursor(highlight_start+temp_str.size());
523 highlight_start = 0;
524 highlight_end = -1;
525 parent.invalidate_rectangle(rect);
526 on_no_text_selected();
527
528 // send out the text modified event
529 if (text_modified_handler.is_set())
530 text_modified_handler();
531 }
532 else
533 {
534 text_ = text_.substr(0,cursor_pos) + temp_str +
535 text_.substr(cursor_pos,text_.size()-cursor_pos);
536 move_cursor(cursor_pos+temp_str.size());
537
538 // send out the text modified event
539 if (temp_str.size() != 0 && text_modified_handler.is_set())
540 text_modified_handler();
541 }
542 }
543
544// ----------------------------------------------------------------------------------------
545

Callers

nothing calls this directly

Calls 3

get_from_clipboardFunction · 0.50
sizeMethod · 0.45
is_setMethod · 0.45

Tested by

no test coverage detected