Permalink
Browse files

ckw-0.8.10-mod4-20100501 by craftware

・タイトルバーを右クリックしたときに出てくるメニューに、[Copy All]を追加しました。
  コンソールの中のすべてのテキストをクリップボードに格納します。
  • Loading branch information...
1 parent 25fec25 commit b9e928cf41230fea902203a2bab44e4ff96a2b67 unknown committed Jun 9, 2010
Showing with 143 additions and 69 deletions.
  1. +7 −0 ckw-mod_readme.txt
  2. +3 −0 ckw.h
  3. +2 −2 main.cpp
  4. +114 −2 misc.cpp
  5. +15 −63 selection.cpp
  6. +2 −2 version.h
View
@@ -1,5 +1,12 @@
ckw-mod�ύX�_
+----- 2010/05/01 -----
+
+(craftware)
+
+�E�^�C�g���o�[��E�N���b�N�����Ƃ��ɏo�Ă��郁�j���[�ɁA[Copy All]��lj���܂����B
+ �R���\�[���̒��̂��ׂẴe�L�X�g��N���b�v�{�[�h�Ɋi�[���܂��B
+
----- 2010/04/26 -----
(craftware)
View
3 ckw.h
@@ -38,6 +38,9 @@ void onLBtnUp(HWND hWnd, int x, int y);
void onMouseMove(HWND hWnd, int x, int y);
/* misc.cpp */
+void copyChar(wchar_t*& p, CHAR_INFO* src, SHORT start, SHORT end, bool ret = true);
+void copyStringToClipboard(HWND hWnd, const wchar_t * str);
+void copyAllStringToClipboard(HWND hWnd);
void onPasteFromClipboard(HWND hWnd);
void onDropFile(HDROP hDrop);
void sysmenu_init(HWND hWnd);
View
@@ -717,7 +717,7 @@ static BOOL create_window(ckOpt& opt)
}else{
title = new wchar_t[ strlen(conf_title)+1 ];
ZeroMemory(title, sizeof(wchar_t) * (strlen(conf_title)+1));
- MultiByteToWideChar(CP_ACP, 0, conf_title, strlen(conf_title), title, sizeof(wchar_t) * (strlen(conf_title)+1));
+ MultiByteToWideChar(CP_ACP, 0, conf_title, (int)strlen(conf_title), title, (int)(sizeof(wchar_t) * (strlen(conf_title)+1)) );
}
/* calc window size */
@@ -928,7 +928,7 @@ static BOOL create_console(ckOpt& opt)
}else{
title = new wchar_t[ strlen(conf_title)+1 ];
ZeroMemory(title, sizeof(wchar_t) * (strlen(conf_title)+1));
- MultiByteToWideChar(CP_ACP, 0, conf_title, strlen(conf_title), title, sizeof(wchar_t) * (strlen(conf_title)+1));
+ MultiByteToWideChar(CP_ACP, 0, conf_title, (int)strlen(conf_title), title, (int)(sizeof(wchar_t) * (strlen(conf_title)+1)) );
}
__hide_alloc_console();
View
116 misc.cpp
@@ -18,6 +18,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*---------------------------------------------------------------------------*/
+
+#include <string>
+
#include "ckw.h"
#include "rsrc.h"
@@ -44,6 +47,30 @@ static void __write_console_input(LPCWSTR str, DWORD length)
}
/*----------*/
+void copyChar(wchar_t*& p, CHAR_INFO* src, SHORT start, SHORT end, bool ret)
+{
+ CHAR_INFO* pend = src + end;
+ CHAR_INFO* test = src + start;
+ CHAR_INFO* last = test-1;
+
+ /* search last char */
+ for( ; test <= pend ; test++) {
+ if(test->Char.UnicodeChar > 0x20)
+ last = test;
+ }
+ /* copy */
+ for(test = src+start ; test <= last ; test++) {
+ if(!(test->Attributes & COMMON_LVB_TRAILING_BYTE))
+ *p++ = test->Char.UnicodeChar;
+ }
+ if(ret && last < pend) {
+ *p++ = L'\r';
+ *p++ = L'\n';
+ }
+ *p = 0;
+}
+
+/*----------*/
void onPasteFromClipboard(HWND hWnd)
{
bool result = true;
@@ -70,6 +97,92 @@ void onPasteFromClipboard(HWND hWnd)
}
/*----------*/
+/* (craftware) */
+void copyStringToClipboard( HWND hWnd, const wchar_t * str )
+{
+ size_t length = wcslen(str) +1;
+ HANDLE hMem;
+ wchar_t* ptr;
+ bool result = true;
+
+ hMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * length);
+ if(!hMem) result = false;
+
+ if(result && !(ptr = (wchar_t*) GlobalLock(hMem))) {
+ result = false;
+ }
+ if(result) {
+ memcpy(ptr, str, sizeof(wchar_t) * length);
+ GlobalUnlock(hMem);
+ }
+ if(result && !OpenClipboard(hWnd)) {
+ Sleep(10);
+ if(!OpenClipboard(hWnd))
+ result = false;
+ }
+ if(result) {
+ if(!EmptyClipboard() ||
+ !SetClipboardData(CF_UNICODETEXT, hMem))
+ result = false;
+ CloseClipboard();
+ }
+ if(!result && hMem) {
+ GlobalFree(hMem);
+ }
+}
+
+/*----------*/
+/* (craftware) */
+wchar_t * getAllString()
+{
+ int nb;
+
+ nb = gCSI->dwSize.X * gCSI->dwSize.Y;
+
+ COORD size = { gCSI->dwSize.X, 1 };
+ CHAR_INFO* work = new CHAR_INFO[ gCSI->dwSize.X ];
+ wchar_t* buffer = new wchar_t[ nb ];
+ wchar_t* wp = buffer;
+ COORD pos = { 0,0 };
+ SMALL_RECT sr = { 0, 0, gCSI->dwSize.X-1, 0 };
+
+ *wp = 0;
+
+ for( int y=0 ; y<gCSI->dwSize.Y ; ++y )
+ {
+ sr.Top = sr.Bottom = y;
+ ReadConsoleOutput_Unicode(gStdOut, work, size, pos, &sr);
+ copyChar( wp, work, 0, gCSI->dwSize.X-1 );
+ }
+
+ delete [] work;
+
+ return(buffer);
+}
+
+/*----------*/
+/* (craftware) */
+void copyAllStringToClipboard(HWND hWnd)
+{
+ wchar_t* str = getAllString();
+ if(!str) return;
+
+ std::wstring s = str;
+
+ // skip empty line
+ size_t begin = s.find_first_not_of(L"\r\n");
+ size_t end = s.find_last_not_of(L"\r\n");
+ if(begin!=s.npos && end!=s.npos)
+ {
+ s = s.substr( begin, end+1-begin );
+ }
+
+ copyStringToClipboard( hWnd, s.c_str() );
+
+ delete [] str;
+}
+
+/*----------*/
void onDropFile(HDROP hDrop)
{
DWORD i, nb, len;
@@ -146,7 +259,6 @@ void sysmenu_init(HWND hWnd)
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_TYPE | MIIM_ID;
- #if 0 // preparing "Copy All" command (craftware)
mii.fType = MFT_STRING;
mii.wID = IDM_COPYALL;
mii.dwTypeData = L"&Copy All";
@@ -158,7 +270,6 @@ void sysmenu_init(HWND hWnd)
mii.dwTypeData = 0;
mii.cch = 0;
InsertMenuItem(hMenu, SC_CLOSE, FALSE, &mii);
- #endif
mii.fType = MFT_STRING;
mii.wID = IDM_ABOUT;
@@ -178,6 +289,7 @@ BOOL onSysCommand(HWND hWnd, DWORD id)
{
switch(id) {
case IDM_COPYALL:
+ copyAllStringToClipboard(hWnd);
return(TRUE);
case IDM_ABOUT:
DialogBox(GetModuleHandle(NULL),
View
@@ -121,29 +121,6 @@ inline void __select_expand()
}
}
-static void copy_char(wchar_t*& p, CHAR_INFO* src, SHORT start, SHORT end, bool ret = true)
-{
- CHAR_INFO* pend = src + end;
- CHAR_INFO* test = src + start;
- CHAR_INFO* last = test-1;
-
- /* search last char */
- for( ; test <= pend ; test++) {
- if(test->Char.UnicodeChar > 0x20)
- last = test;
- }
- /* copy */
- for(test = src+start ; test <= last ; test++) {
- if(!(test->Attributes & COMMON_LVB_TRAILING_BYTE))
- *p++ = test->Char.UnicodeChar;
- }
- if(ret && last < pend) {
- *p++ = L'\r';
- *p++ = L'\n';
- }
- *p = 0;
-}
-
static void window_to_charpos(int& x, int& y)
{
x -= gBorderSize;
@@ -160,15 +137,17 @@ static void window_to_charpos(int& x, int& y)
/*****************************************************************************/
-#define SELECT_Invalid \
- (gSelectRect.Top > gSelectRect.Bottom || \
- (gSelectRect.Top == gSelectRect.Bottom && \
- gSelectRect.Left >= gSelectRect.Right)) \
+static inline bool __select_invalid()
+{
+ return ( gSelectRect.Top > gSelectRect.Bottom ||
+ (gSelectRect.Top == gSelectRect.Bottom &&
+ gSelectRect.Left >= gSelectRect.Right) );
+}
/*----------*/
BOOL selectionGetArea(SMALL_RECT& sr)
{
- if(SELECT_Invalid)
+ if( __select_invalid() )
return(FALSE);
sr = gSelectRect;
return(TRUE);
@@ -177,17 +156,17 @@ BOOL selectionGetArea(SMALL_RECT& sr)
/*----------*/
void selectionClear(HWND hWnd)
{
- if(SELECT_Invalid)
+ if( __select_invalid() )
return;
gSelectRect.Left = gSelectRect.Right = \
gSelectRect.Top = gSelectRect.Bottom = 0;
InvalidateRect(hWnd, NULL, FALSE);
}
/*----------*/
-wchar_t* selectionGetString()
+wchar_t * selectionGetString()
{
- if(SELECT_Invalid)
+ if( __select_invalid() )
return(NULL);
int nb, y;
@@ -214,20 +193,20 @@ wchar_t* selectionGetString()
if(gSelectRect.Top == gSelectRect.Bottom) {
sr.Top = sr.Bottom = gSelectRect.Top;
ReadConsoleOutput_Unicode(gStdOut, work, size, pos, &sr);
- copy_char(wp, work, gSelectRect.Left, gSelectRect.Right-1, false);
+ copyChar(wp, work, gSelectRect.Left, gSelectRect.Right-1, false);
}
else {
sr.Top = sr.Bottom = gSelectRect.Top;
ReadConsoleOutput_Unicode(gStdOut, work, size, pos, &sr);
- copy_char(wp, work, gSelectRect.Left, gCSI->srWindow.Right);
+ copyChar(wp, work, gSelectRect.Left, gCSI->srWindow.Right);
for(y = gSelectRect.Top+1 ; y <= gSelectRect.Bottom-1 ; y++) {
sr.Top = sr.Bottom = y;
ReadConsoleOutput_Unicode(gStdOut, work, size, pos, &sr);
- copy_char(wp, work, gCSI->srWindow.Left, gCSI->srWindow.Right);
+ copyChar(wp, work, gCSI->srWindow.Left, gCSI->srWindow.Right);
}
sr.Top = sr.Bottom = gSelectRect.Bottom;
ReadConsoleOutput_Unicode(gStdOut, work, size, pos, &sr);
- copy_char(wp, work, gCSI->srWindow.Left, gSelectRect.Right-1, false);
+ copyChar(wp, work, gCSI->srWindow.Left, gSelectRect.Right-1, false);
}
delete [] work;
@@ -296,35 +275,8 @@ void onLBtnUp(HWND hWnd, int x, int y)
wchar_t* str = selectionGetString();
if(!str) return;
- size_t length = wcslen(str) +1;
- HANDLE hMem;
- wchar_t* ptr;
- bool result = true;
-
- hMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * length);
- if(!hMem) result = false;
+ copyStringToClipboard( hWnd, str );
- if(result && !(ptr = (wchar_t*) GlobalLock(hMem))) {
- result = false;
- }
- if(result) {
- memcpy(ptr, str, sizeof(wchar_t) * length);
- GlobalUnlock(hMem);
- }
- if(result && !OpenClipboard(hWnd)) {
- Sleep(10);
- if(!OpenClipboard(hWnd))
- result = false;
- }
- if(result) {
- if(!EmptyClipboard() ||
- !SetClipboardData(CF_UNICODETEXT, hMem))
- result = false;
- CloseClipboard();
- }
- if(!result && hMem) {
- GlobalFree(hMem);
- }
delete [] str;
}
View
@@ -3,6 +3,6 @@
#define VERSION_BUGFIX 10
#define VERSION_STRING "0.8.10-mod"
#define VERSION_NUMSTRING "008101"
-#define BUILDDATE_STRING "2010/04/26 0:33:50 UTC+9"
+#define BUILDDATE_STRING "2010/05/01 22:15:41 UTC+9"
#define COPYRIGHT_STRING "Copyright (C) 2005 Kazuo Ishii <k-ishii@wb4.so-net.ne.jp>"
-#define ABOUT_DLG_STRING "ckw version 0.8.10-mod , build 2010/04/26 0:33:50 UTC+9\r\nCopyright (C) 2005 Kazuo Ishii <k-ishii@wb4.so-net.ne.jp>"
+#define ABOUT_DLG_STRING "ckw version 0.8.10-mod , build 2010/05/01 22:15:41 UTC+9\r\nCopyright (C) 2005 Kazuo Ishii <k-ishii@wb4.so-net.ne.jp>"

0 comments on commit b9e928c

Please sign in to comment.