Permalink
Browse files

Merge mod4 (craftware's) patch.

  • Loading branch information...
2 parents 6316cb2 + 45d0bcf commit 6758bcb95f581c0629e2b29eae7f18d7f45b01e1 @deflis committed Jun 9, 2010
Showing with 199 additions and 75 deletions.
  1. +30 −0 ckw-mod_readme.txt
  2. +3 −0 ckw.h
  3. +21 −5 main.cpp
  4. +122 −0 misc.cpp
  5. +3 −2 rsrc.h
  6. +15 −63 selection.cpp
  7. +1 −1 version.bat
  8. +4 −4 version.h
View
@@ -1,5 +1,35 @@
ckw-mod変更点
+----- 2010/05/17 -----
+
+(craftware)
+
+・AllocConsole 時に SW_HIDE を与えるために、__readfsdword を用いてアドレスを指定する
+ ようにしました。(これによって、もう少し整理できるかも)
+
+----- 2010/05/07 -----
+
+(craftware)
+
+・下記のサイトの変更をマージして、コマンドプロンプトが一瞬表示されるのを修正しました。
+ http://nocd5.blog59.fc2.com/blog-entry-402.html
+
+----- 2010/05/01 -----
+
+(craftware)
+
+・タイトルバーを右クリックしたときに出てくるメニューに、[Copy All]を追加しました。
+ コンソールの中のすべてのテキストをクリップボードに格納します。
+
+----- 2010/04/26 -----
+
+(craftware)
+
+・マウスによるテキスト選択中に、マウスがウインドウの上下外側に行ったときに、
+ 自動的にスクロールするようにしました。
+
+・VC2008を使うようにしました。ckw.sln と ckw.vcproj を VC2008の形式に変換しました。
+
----- 2009/11/18 -----
http://twitter.com/you_and_i/status/5812581561 での修正を取り込みました。(bleis-tift)
View
@@ -39,6 +39,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
@@ -587,6 +587,21 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
break;
case WM_MOUSEMOVE:
onMouseMove(hWnd, (short)LOWORD(lp),(short)HIWORD(lp));
+ // scroll when mouse is outside (craftware)
+ {
+ short x = (short)LOWORD(lp);
+ short y = (short)HIWORD(lp);
+
+ RECT rc;
+ GetClientRect(hWnd, &rc);
+
+ if( y<0 ) {
+ PostMessage(gConWnd, WM_MOUSEWHEEL, WHEEL_DELTA<<16, y<<16|x );
+ }
+ else if(y>=rc.bottom) {
+ PostMessage(gConWnd, WM_MOUSEWHEEL, -WHEEL_DELTA<<16, y<<16|x );
+ }
+ }
break;
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
@@ -702,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 */
@@ -876,8 +891,10 @@ static void __hide_alloc_console()
* Open Console Window
* hack StartupInfo.wShowWindow flag
*/
- DWORD* pflags = (DWORD*) 0x00020068; /* private memory */
- WORD* pshow = (WORD*) 0x0002006C;
+ INT_PTR peb = __readfsdword(0x30);
+ INT_PTR param = *(INT_PTR*) (peb + 0x10);
+ DWORD* pflags = (DWORD*) (param + 0x68);
+ WORD* pshow = (WORD*) (param + 0x6C);
DWORD backup_flags = *pflags;
WORD backup_show = *pshow;
@@ -898,7 +915,6 @@ static void __hide_alloc_console()
*pflags = backup_flags;
*pshow = backup_show;
-
while((gConWnd = GetConsoleWindow()) == NULL) {
Sleep(10);
}
@@ -931,7 +947,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
@@ -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"
#include "option.h"
@@ -57,6 +60,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;
@@ -83,6 +110,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;
@@ -164,6 +277,12 @@ void sysmenu_init(HWND hWnd)
mii.fMask = MIIM_TYPE | MIIM_ID;
mii.fType = MFT_STRING;
+ mii.wID = IDM_COPYALL;
+ mii.dwTypeData = L"Copy All(&C)";
+ mii.cch = (UINT) wcslen(mii.dwTypeData);
+ InsertMenuItem(hMenu, SC_CLOSE, FALSE, &mii);
+
+ mii.fType = MFT_STRING;
mii.wID = IDM_NEW;
mii.dwTypeData = L"New (&N)";
mii.cch = (UINT) wcslen(mii.dwTypeData);
@@ -329,6 +448,9 @@ void changeStateTopMostMenu(HWND hWnd,HMENU hMenu)
BOOL onSysCommand(HWND hWnd, DWORD id)
{
switch(id) {
+ case IDM_COPYALL:
+ copyAllStringToClipboard(hWnd);
+ return(TRUE);
case IDM_ABOUT:
DialogBox(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_DIALOG1),
View
@@ -5,10 +5,11 @@
#define IDC_EDIT1 10002
#define IDM_ABOUT 40001
+#define IDM_COPYALL 40002
#define IDM_CONFIG_SELECT 50000
#define IDM_CONFIG_SELECT_1 50001
#define IDM_CONFIG_SELECT_2 50002
/* ... 50003, 50004, ... */
#define IDM_CONFIG_SELECT_MAX 50100
-#define IDM_NEW 60001
-#define IDM_TOPMOST 70001
+#define IDM_NEW 40003
+#define IDM_TOPMOST 40004
Oops, something went wrong.

0 comments on commit 6758bcb

Please sign in to comment.