MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / EditCopyAppend

Function EditCopyAppend

src/Edit.c:472–548  ·  view source on GitHub ↗

============================================================================= EditCopyAppend()

Source from the content-addressed store, hash-verified

470// EditCopyAppend()
471//
472BOOL EditCopyAppend ( HWND hwnd )
473{
474 HANDLE hOld;
475 WCHAR *pszOld;
476 HANDLE hNew;
477 WCHAR *pszNew;
478 char *pszText;
479 int cchTextW;
480 WCHAR *pszTextW;
481 WCHAR *pszSep = L"\r\n";
482 UINT uCodePage;
483 int iCurPos;
484 int iAnchorPos;
485 if ( !IsClipboardFormatAvailable ( CF_UNICODETEXT ) ) {
486 SendMessage ( hwnd, SCI_COPY, 0, 0 );
487 return ( TRUE );
488 }
489 iCurPos = ( int ) SendMessage ( hwnd, SCI_GETCURRENTPOS, 0, 0 );
490 iAnchorPos = ( int ) SendMessage ( hwnd, SCI_GETANCHOR, 0, 0 );
491 if ( iCurPos != iAnchorPos ) {
492 if ( SC_SEL_RECTANGLE == SendMessage ( hwnd, SCI_GETSELECTIONMODE, 0, 0 ) ) {
493 MsgBox ( MBINFO, IDS_SELRECT );
494 return ( FALSE );
495 } else {
496 int iSelCount =
497 ( int ) SendMessage ( hwnd, SCI_GETSELECTIONEND, 0, 0 ) -
498 ( int ) SendMessage ( hwnd, SCI_GETSELECTIONSTART, 0, 0 );
499 pszText = LocalAlloc ( LPTR, iSelCount + 1 );
500 ( int ) SendMessage ( hwnd, SCI_GETSELTEXT, 0, ( LPARAM ) pszText );
501 }
502 } else {
503
504 int line ;
505 struct Sci_TextRange tr;
506
507 line = SendMessage(hwnd, SCI_LINEFROMPOSITION, iCurPos, 0);
508 tr.chrg.cpMin = SendMessage(hwnd, SCI_POSITIONFROMLINE, line, 0);
509 tr.chrg.cpMax = SendMessage(hwnd, SCI_GETLINEENDPOSITION, line, 0);
510 if (tr.chrg.cpMax > tr.chrg.cpMin) {
511 tr.lpstrText = LocalAlloc(LPTR, tr.chrg.cpMax - tr.chrg.cpMin + 1);
512 SendMessage(hwnd, SCI_GETTEXTRANGE, 0, (LPARAM)&tr);
513 pszText = tr.lpstrText;
514 }
515 else {
516 int cchText = (int)SendMessage(hwnd, SCI_GETLENGTH, 0, 0);
517 pszText = LocalAlloc(LPTR, cchText + 1);
518 SendMessage(hwnd, SCI_GETTEXT, (int)LocalSize(pszText), (LPARAM)pszText);
519 }
520 }
521 uCodePage = ( SendMessage ( hwnd, SCI_GETCODEPAGE, 0, 0 ) == SC_CP_UTF8 ) ? CP_UTF8 : CP_ACP;
522 cchTextW = MultiByteToWideChar ( uCodePage, 0, pszText, -1, NULL, 0 );
523 if ( cchTextW > 0 ) {
524 pszTextW = LocalAlloc ( LPTR, sizeof ( WCHAR ) * ( lstrlen ( pszSep ) + cchTextW + 1 ) );
525 lstrcpy ( pszTextW, pszSep );
526 MultiByteToWideChar ( uCodePage, 0, pszText, -1, StrEnd ( pszTextW ), ( int ) LocalSize ( pszTextW ) / sizeof ( WCHAR ) );
527 } else {
528 pszTextW = L"";
529 }

Callers 1

MsgCommandFunction · 0.85

Calls 1

MsgBoxFunction · 0.85

Tested by

no test coverage detected