MCPcopy Create free account
hub / github.com/WheretIB/nullc / OnCopyOrCut

Method OnCopyOrCut

GUI/RichTextarea.cpp:1669–1726  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1667}
1668
1669void TextareaData::OnCopyOrCut(bool cut)
1670{
1671 // Get linear text
1672 const char *start = RichTextarea::GetAreaText(areaWnd);
1673 AreaLine *curr = firstLine;
1674
1675 // If there is no selection, remember this fact, and select current line
1676 bool genuineSelection = selectionOn;
1677 if(!selectionOn)
1678 {
1679 dragStartX = 0;
1680 dragEndX = currLine->length;
1681 dragStartY = cursorCharY;
1682 dragEndY = cursorCharY;
1683 selectionOn = true;
1684 }
1685 // Sort selection range
1686 unsigned int startX, startY, endX, endY;
1687 SortSelPoints(startX, endX, startY, endY);
1688
1689 // Clamp selection points in Y axis
1690 startY = startY > lineCount ? lineCount - 1 : startY;
1691 endY = endY > lineCount ? lineCount-1 : endY;
1692
1693 // Find first line start in linear buffer
1694 for(unsigned int i = 0; i < startY; i++)
1695 {
1696 start += curr->length + 2;
1697 curr = curr->next;
1698 }
1699 const char *end = start;
1700 // Move start to the first selected symbol
1701 start += (startX < curr->length ? startX : curr->length);
1702 // Find last line start in linear buffer
1703 for(unsigned int i = startY; i < endY; i++)
1704 {
1705 end += curr->length + 2;
1706 curr = curr->next;
1707 }
1708 // Move end to the last selected symbol
1709 end += (endX < curr->length ? endX : curr->length);
1710
1711 // Copy to clipboard
1712 OpenClipboard(areaWnd);
1713 EmptyClipboard();
1714 HGLOBAL hClipboardData = GlobalAlloc(GMEM_DDESHARE, end - start + 1);
1715 char *pchData = (char*)GlobalLock(hClipboardData);
1716 memcpy(pchData, start, end - start);
1717 GlobalUnlock(hClipboardData);
1718 SetClipboardData(CF_TEXT, hClipboardData);
1719 CloseClipboard();
1720 // If it is a cut operation, remove selection
1721 if(cut)
1722 DeleteSelection();
1723 // If we had to make an artificial selection, disable it
1724 if(!genuineSelection)
1725 selectionOn = false;
1726}

Callers 1

TextareaProcMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected