Revision: 7961 https://osdn.net/projects/ttssh2/scm/svn/commits/7961 Author: zmatsuo Date: 2019-08-15 23:02:02 +0900 (Thu, 15 Aug 2019) Log Message: ----------- クリップボードへのコピー追加 - 内部バッファから文字列を取得するBuffGetStringForCB() - 今のところクリップボード用 - 他の用途でも使用予定(URL文字列調査、漢字再変換など) Modified Paths: -------------- branches/unicode_buf/teraterm/teraterm/buffer.c branches/unicode_buf/teraterm/teraterm/buffer.h branches/unicode_buf/teraterm/teraterm/vtwin.cpp -------------- next part -------------- Modified: branches/unicode_buf/teraterm/teraterm/buffer.c =================================================================== --- branches/unicode_buf/teraterm/teraterm/buffer.c 2019-08-15 14:01:28 UTC (rev 7960) +++ branches/unicode_buf/teraterm/teraterm/buffer.c 2019-08-15 14:02:02 UTC (rev 7961) @@ -1729,6 +1729,191 @@ return i; } +/** + * (\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x97p\x82\xC9)\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x8E擾 + * @param[in] sx,sy,ex,ey \x91I\x91\xF0\x97̈\xE6 + * @param[in] box_select TRUE=\x94\xA0\x8C^(\x8B\xE9\x8C`)\x91I\x91\xF0 + * FALSE=\x8Ds\x91I\x91\xF0 + * @param[out] _str_len \x95\xB6\x8E\x9A\x97\xF1\x92\xB7(\x95\xB6\x8E\x9A\x92[L'\0'\x82\xF0\x8A܂\xDE) + * @return \x95\xB6\x8E\x9A\x97\xF1 + * \x8Eg\x97p\x8C\xE3\x82\xCD free() \x82\xB7\x82邱\x82\xC6 + */ +#if UNICODE_INTERNAL_BUFF +static wchar_t *BuffGetStringForCB(int sx, int sy, int ex, int ey, BOOL box_select, size_t *_str_len) +{ + wchar_t *str_w; + size_t str_size; // \x8Am\x95ۂ\xB5\x82\xBD\x83T\x83C\x83Y + size_t k; + LONG TmpPtr; + int IStart, IEnd; + int x, y; + BOOL LineContinued; + + str_size = NumOfColumns * (ey - sy + 1); + str_w = malloc(sizeof(wchar_t) * str_size); + + LockBuffer(); + + str_w[0] = 0; + TmpPtr = GetLinePtr(sy); + k = 0; + for (y = sy; y<=ey ; y++) { + if (box_select) { + IStart = SelectStart.x; + IEnd = SelectEnd.x-1; + } + else { + IStart = 0; + IEnd = NumOfColumns-1; + if (y== sy) { + IStart = sx; + } + if (y== ey) { + IEnd = ex -1; + } + } + + // \x8E\x9F\x82̍s\x82ɑ\xB1\x82\xA2\x82Ă\xE9? + LineContinued = FALSE; + if (!box_select) { + // \x8Ds\x91I\x91\xF0\x82̏ꍇ\x82̂\xDD + if (ts.EnableContinuedLineCopy && y!= ey ) { + LONG NextTmpPtr = NextLinePtr(TmpPtr); + if ((AttrBuff[NextTmpPtr] & AttrLineContinued) != 0) { + LineContinued = TRUE; + } + } + } + + if (!LineContinued) { + while ((IEnd>0)) { + // \x83R\x83s\x81[\x95s\x97v\x95\xAA\x82\xF0\x8D폜 + const buff_char_t *b = &CodeBuffW[TmpPtr + IEnd]; + if (b->u32 == 0x20) { + MoveCharPtr(TmpPtr,&IEnd,-1); // \x90\xE8\x8Bl\x82߂\xE9 + } + else { + break; + } + } + } + + x = IStart; + while (x <= IEnd) { + const buff_char_t *b = &CodeBuffW[TmpPtr + x]; + if (b->u32 != 0) { + str_w[k++] = b->wc2[0]; + if (b->wc2[1] != 0) { + str_w[k++] = b->wc2[1]; + } + if (k + 2 >= str_size) { + str_size *= 2; + str_w = realloc(str_w, sizeof(wchar_t) * str_size); + } + { + int i; + // \x83R\x83\x93\x83r\x83l\x81[\x83V\x83\x87\x83\x93 + if (k + b->CombinationCharCount16 >= str_size) { + str_size += + b->CombinationCharCount16; + str_w = realloc(str_w, sizeof(wchar_t) * str_size); + } + for (i = 0 ; i < (int)b->CombinationCharCount16; i++) { + str_w[k++] = b->pCombinationChars16[i]; + } + } + } + x++; + } + + if (y < ey) { + // \x89\xFC\x8Ds\x82\xF0\x89\xC1\x82\xA6\x82\xE9(\x8DŌ\xE3\x82̍s\x88ȊO\x82̏ꍇ) + if (!LineContinued) { + str_w[k++] = 0x0d; + str_w[k++] = 0x0a; + } + } + + TmpPtr = NextLinePtr(TmpPtr); + } + str_w[k++] = 0; + + UnlockBuffer(); + + *_str_len = k; + return str_w; +} +#endif + +/** + * \x98A\x91\xB1\x82\xB5\x82\xBD\x83X\x83y\x81[\x83X\x82\xF0\x83^\x83u1\x82ɒu\x8A\xB7\x82\xB7\x82\xE9 + * @param[out] _str_len \x95\xB6\x8E\x9A\x97\xF1\x92\xB7(L'\0'\x82\xF0\x8A܂\xDE) + * @return \x95\xB6\x8E\x9A\x97\xF1 + * \x8Eg\x97p\x8C\xE3\x82\xCD free() \x82\xB7\x82邱\x82\xC6 + */ +static wchar_t *ConvertTable(const wchar_t *src, size_t src_len, size_t *str_len) +{ + wchar_t *dest_top = malloc(sizeof(wchar_t) * src_len); + wchar_t *dest = dest_top; + BOOL WhiteSpace = FALSE; + while (*src != '\0') { + wchar_t c = *src++; + if (c == 0x0d || c == 0x0a) { + *dest++ = c; + WhiteSpace = FALSE; + } else if (c <= L' ') { + if (!WhiteSpace) { + // insert tab + *dest++ = 0x09; + WhiteSpace = TRUE; + } + } else { + *dest++ = c; + WhiteSpace = FALSE; + } + } + *dest = L'\0'; + *str_len = dest - dest_top + 1; + return dest_top; +} + + +#if UNICODE_INTERNAL_BUFF +void BuffCBCopyUnicode(BOOL Table) +{ + wchar_t *str_ptr; + size_t str_len; + str_ptr = BuffGetStringForCB( + SelectStart.x, SelectStart.y, + SelectEnd.x, SelectEnd.y, BoxSelect, + &str_len); + + // \x83e\x81[\x83u\x83\x8B\x8C`\x8E\xAE\x82֕ϊ\xB7 + if (Table) { + size_t table_len; + wchar_t *table_ptr = ConvertTable(str_ptr, str_len, &table_len); + free(str_ptr); + str_ptr = table_ptr; + str_len = table_len; + } + OutputDebugPrintfW(L"BuffCBCopyUnicode()\n" + L"%d, '%s'\n", str_len, str_ptr); + + // \x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82ɃZ\x83b\x83g + if (OpenClipboard(HVTWin)) { + HGLOBAL CBCopyWideHandle = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * str_len); + wchar_t *CBCopyWidePtr = (wchar_t *)GlobalLock(CBCopyWideHandle); + memcpy(CBCopyWidePtr, str_ptr, str_len * sizeof(wchar_t)); + GlobalUnlock(CBCopyWideHandle); + EmptyClipboard(); + SetClipboardData(CF_UNICODETEXT, CBCopyWideHandle); + // TODO 9x\x8Cn\x82ł͎\xA9\x93\xAE\x82\xC5CF_TEXT\x82ɃZ\x83b\x83g\x82\xB3\x82\xEA\x82Ȃ\xA2\x82炵\x82\xA2? + CloseClipboard(); + } + free(str_ptr); +} +#endif + +#if !UNICODE_INTERNAL_BUFF void BuffCBCopy(BOOL Table) // copy selected text to clipboard { @@ -1876,6 +2061,7 @@ CBClose(); return; } +#endif void BuffPrint(BOOL ScrollRegion) // Print screen or selected text @@ -3939,7 +4125,11 @@ /* copy to the clipboard */ if (ts.AutoTextCopy>0) { LockBuffer(); +#if UNICODE_INTERNAL_BUFF + BuffCBCopyUnicode(FALSE); +#else BuffCBCopy(FALSE); +#endif UnlockBuffer(); } } Modified: branches/unicode_buf/teraterm/teraterm/buffer.h =================================================================== --- branches/unicode_buf/teraterm/teraterm/buffer.h 2019-08-15 14:01:28 UTC (rev 7960) +++ branches/unicode_buf/teraterm/teraterm/buffer.h 2019-08-15 14:02:02 UTC (rev 7961) @@ -59,6 +59,7 @@ void BuffChangeAttrBox(int XStart, int YStart, int XEnd, int YEnd, PCharAttr attr, PCharAttr mask); void BuffChangeAttrStream(int XStart, int YStart, int XEnd, int YEnd, PCharAttr attr, PCharAttr mask); void BuffCBCopy(BOOL Table); +void BuffCBCopyUnicode(BOOL Table); void BuffPrint(BOOL ScrollRegion); void BuffDumpCurrentLine(BYTE TERM); void BuffPutChar(BYTE b, TCharAttr Attr, BOOL Insert); Modified: branches/unicode_buf/teraterm/teraterm/vtwin.cpp =================================================================== --- branches/unicode_buf/teraterm/teraterm/vtwin.cpp 2019-08-15 14:01:28 UTC (rev 7960) +++ branches/unicode_buf/teraterm/teraterm/vtwin.cpp 2019-08-15 14:02:02 UTC (rev 7961) @@ -4373,13 +4373,21 @@ void CVTWindow::OnEditCopy() { // copy selected text to clipboard +#if UNICODE_INTERNAL_BUFF + BuffCBCopyUnicode(FALSE); +#else BuffCBCopy(FALSE); +#endif } void CVTWindow::OnEditCopyTable() { // copy selected text to clipboard in Excel format +#if UNICODE_INTERNAL_BUFF + BuffCBCopyUnicode(TRUE); +#else BuffCBCopy(TRUE); +#endif } void CVTWindow::OnEditPaste()