[Ttssh2-commit] [5223] 「重ねて表示」「左右に並べて表示」「上下に並べて表示」を行う関数を追加した。

svnno****@sourc***** svnno****@sourc*****
2013年 5月 2日 (木) 14:37:15 JST


Revision: 5223
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5223
Author:   yutakapon
Date:     2013-05-02 14:37:15 +0900 (Thu, 02 May 2013)
Log Message:
-----------
「重ねて表示」「左右に並べて表示」「上下に並べて表示」を行う関数を追加した。
結局、自前でやらずに、Win32APIを利用する。

共有メモリを拡張したので、以前のTera Termとの混在は不可。

Modified Paths:
--------------
    trunk/teraterm/common/tttypes.h
    trunk/teraterm/ttpcmn/ttcmn.c

-------------- next part --------------
Modified: trunk/teraterm/common/tttypes.h
===================================================================
--- trunk/teraterm/common/tttypes.h	2013-05-01 15:55:25 UTC (rev 5222)
+++ trunk/teraterm/common/tttypes.h	2013-05-02 05:37:15 UTC (rev 5223)
@@ -1009,6 +1009,8 @@
 	 * char[1] : COM16 15 14 13 12 11 10  9 ...
 	 */
 	unsigned char ComFlag[(MAXCOMPORT-1)/CHAR_BIT+1];
+	/* Previous window rect (Tera Term 4.78 or later) */
+	WINDOWPLACEMENT WinPrevRect[MAXNWIN];
 } TMap;
 typedef TMap far *PMap;
 

Modified: trunk/teraterm/ttpcmn/ttcmn.c
===================================================================
--- trunk/teraterm/ttpcmn/ttcmn.c	2013-05-01 15:55:25 UTC (rev 5222)
+++ trunk/teraterm/ttpcmn/ttcmn.c	2013-05-02 05:37:15 UTC (rev 5223)
@@ -838,6 +838,7 @@
 		return 0;
 	}
 	pm->WinList[pm->NWin++] = HWinVT;
+	memset(&pm->WinPrevRect[pm->NWin - 1], 0, sizeof(pm->WinPrevRect[pm->NWin - 1])); // RECT clear
 	if (pm->NWin==1) {
 		return 1;
 	}
@@ -860,6 +861,7 @@
 	}
 	for (j=i ; j<pm->NWin-1 ; j++) {
 		pm->WinList[j] = pm->WinList[j+1];
+		pm->WinPrevRect[j] = pm->WinPrevRect[j+1];  // RECT shift
 	}
 	if (pm->NWin>0) {
 		pm->NWin--;
@@ -1012,9 +1014,58 @@
 
 void FAR PASCAL ShowAllWin(int stat) {
 	int i;
+	WINDOWPLACEMENT rc0;
+	RECT rc;
+	HMONITOR hMonitor;
+	MONITORINFO mi;
 
+	memset(&rc0, 0, sizeof(rc0));
+
 	for (i=0; i < pm->NWin; i++) {
-		ShowWindow(pm->WinList[i], stat);
+		// \x95\x9C\x8C\xB3\x8Ew\x92\xE8\x82ŁA\x91O\x89\xF1\x82̏\xF3\x91Ԃ\xAA\x8Ec\x82\xC1\x82Ă\xA2\x82\xE9\x8Fꍇ\x82́A\x83E\x83B\x83\x93\x83h\x83E\x82̏\xF3\x91Ԃ\xF0\x8C\xB3\x82ɖ߂\xB7\x81B
+		if (stat == SW_RESTORE && memcmp(&pm->WinPrevRect[i], &rc0, sizeof(rc0)) != 0) {
+			rc = pm->WinPrevRect[i].rcNormalPosition;
+
+			// \x91Ώۃ\x82\x83j\x83^\x82̏\xEE\x95\xF1\x82\xF0\x8E擾
+			hMonitor = MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST);
+			mi.cbSize = sizeof(MONITORINFO);
+			GetMonitorInfo(hMonitor, &mi);
+
+			// \x88ʒu\x95␳\x81i\x95\x9C\x8C\xB3\x91O\x8C\xE3\x82ʼn𑜓x\x82\xAA\x95ς\xED\x82\xC1\x82Ă\xA2\x82\xE9\x8Fꍇ\x82ւ̑΍\xF4\x81j
+			if (rc.right > mi.rcMonitor.right) {
+				rc.left -= rc.right - mi.rcMonitor.right;
+				rc.right = mi.rcMonitor.right;
+			}
+			if (rc.left < mi.rcMonitor.left) {
+				rc.right += mi.rcMonitor.left - rc.left;
+				rc.left = mi.rcMonitor.left;
+			}
+			if (rc.bottom > mi.rcMonitor.bottom) {
+				rc.top -= rc.bottom - mi.rcMonitor.bottom;
+				rc.bottom = mi.rcMonitor.bottom;
+			}
+			if (rc.top < mi.rcMonitor.top) {
+				rc.bottom += mi.rcMonitor.top - rc.top;
+				rc.top = mi.rcMonitor.top;
+			}
+
+			// \x83E\x83B\x83\x93\x83h\x83E\x88ʒu\x95\x9C\x8C\xB3
+			SetWindowPos(
+				pm->WinList[i], NULL, 
+				rc.left, 
+				rc.top,
+				rc.right - rc.left, 
+				rc.bottom - rc.top,
+				SWP_NOZORDER);
+
+			// \x8Dő剻\x82\xB5\x82Ă\xA2\x82\xBD\x82\xA9\x81H
+			if (pm->WinPrevRect[i].showCmd == SW_SHOWMAXIMIZED) {
+				ShowWindow(pm->WinList[i], SW_MAXIMIZE);
+			}
+
+		} else {
+			ShowWindow(pm->WinList[i], stat);
+		}
 	}
 }
 
@@ -1028,6 +1079,7 @@
 	}
 }
 
+#if 0
 // \x83}\x83\x8B\x83`\x83\x82\x83j\x83^\x81[\x82\xF0\x8Dl\x97\xB6\x82\xB5\x82āA\x83^\x83X\x83N\x83o\x81[\x82\xF0\x8F\x9C\x82\xA2\x82\xBD\x83f\x83B\x83X\x83v\x83\x8C\x83C\x83T\x83C\x83Y\x82\xF0\x8E擾\x82\xB7\x82\xE9\x81B
 static void get_desktop_size_by_multi_monitor(HWND hwnd, RECT *rect)
 {
@@ -1042,21 +1094,27 @@
 	GetMonitorInfo(hMon, &mi);
 	*rect = mi.rcWork;  // \x83^\x83X\x83N\x83o\x81[\x82\xF0\x8F\x9C\x82\xA2\x82\xBD\x83f\x83B\x83X\x83v\x83\x8C\x83C\x83T\x83C\x83Y
 }
+#endif
 
-// \x83E\x83B\x83\x93\x83h\x83E\x82\xF0\x8D\xB6\x89E\x82ɕ\xC0\x82ׂĕ\\x8E\xA6\x82\xB7\x82\xE9(Show Windows Side by Side)
-void FAR PASCAL ShowAllWinSidebySide(HWND myhwnd)
+// \x97L\x8C\xF8\x82ȃE\x83B\x83\x93\x83h\x83E\x82\xF0\x92T\x82\xB5\x81A\x8C\xBB\x8D݈ʒu\x82\xF0\x8BL\x89\xAF\x82\xB3\x82\xB9\x82Ă\xA8\x82\xAD\x81B
+static void get_valid_window_and_memorize_rect(HWND myhwnd, HWND hwnd[], int *num)
 {
-	int i, n, width;
-	HWND hwnd[MAXNWIN];
-	RECT rc;
+	int i, n;
+	WINDOWPLACEMENT wndPlace;
 
-	get_desktop_size_by_multi_monitor(myhwnd, &rc);
-
 	n = 0;
 	for (i = 0 ; i < pm->NWin ; i++) {
-		if (IsIconic(pm->WinList[i]) || !IsWindowVisible(pm->WinList[i]))
+		if (IsIconic(pm->WinList[i]) || !IsWindowVisible(pm->WinList[i])) {
+			memset(&pm->WinPrevRect[i], 0, sizeof(pm->WinPrevRect[i]));
 			continue;
+		}
 
+		// \x8C\xBB\x8D݈ʒu\x82\xF0\x8Ao\x82\xA6\x82Ă\xA8\x82\xAD\x81B
+		wndPlace.length = sizeof(WINDOWPLACEMENT);
+		GetWindowPlacement(pm->WinList[i], &wndPlace);
+		pm->WinPrevRect[i] = wndPlace;
+
+		// \x8E\xA9\x95\xAA\x8E\xA9\x90g\x82͐擪\x82ɂ\xB7\x82\xE9\x81B
 		if (pm->WinList[i] == myhwnd) {
 			hwnd[n] = hwnd[0];
 			hwnd[0] = myhwnd;
@@ -1065,70 +1123,47 @@
 		}
 		n++;
 	}
-	if (n <= 1)    // \x97L\x8C\xF8\x82ȃE\x83B\x83\x93\x83h\x83E\x82\xAA2\x82ˆȏ\xE3\x82̏ꍇ\x82Ɍ\xC0\x82\xE9
-		goto error;
+	*num = n;
 
-	width = (rc.right - rc.left) / n;
-	for (i = 0 ; i < n ; i++) {
-		ShowWindow(hwnd[i], SW_RESTORE);
-		SetWindowPos(hwnd[i], 0, 
-			width*i + rc.left,
-			rc.top,
-			width,
-			rc.bottom - rc.top,
-			SWP_NOOWNERZORDER | SWP_NOZORDER);
+	// \x97L\x8C\xF8\x82ȃE\x83B\x83\x93\x83h\x83E\x82\xAA2\x82–\xA2\x96\x9E\x82Ȃ\xE7\x82΁A\x8BL\x89\xAF\x82\xF0\x83N\x83\x8A\x83A\x82\xB7\x82\xE9\x81B
+	if (n <= 1) {
+		for (i = 0 ; i < pm->NWin ; i++) {
+			memset(&pm->WinPrevRect[i], 0, sizeof(pm->WinPrevRect[i]));
+		}
 	}
-	SetFocus(hwnd[0]);
+}
 
-error:
-	return;
+// \x83E\x83B\x83\x93\x83h\x83E\x82\xF0\x8D\xB6\x89E\x82ɕ\xC0\x82ׂĕ\\x8E\xA6\x82\xB7\x82\xE9(Show Windows Side by Side)
+void FAR PASCAL ShowAllWinSidebySide(HWND myhwnd)
+{
+	int n;
+	HWND hwnd[MAXNWIN];
+
+	get_valid_window_and_memorize_rect(myhwnd, hwnd, &n);
+	if (n >= 2)    // \x97L\x8C\xF8\x82ȃE\x83B\x83\x93\x83h\x83E\x82\xAA2\x82ˆȏ\xE3\x82̏ꍇ\x82Ɍ\xC0\x82\xE9
+		TileWindows(NULL, MDITILE_HORIZONTAL, NULL, n, hwnd);
 }
 
 // \x83E\x83B\x83\x93\x83h\x83E\x82\xF0\x8F㉺\x82ɕ\xC0\x82ׂĕ\\x8E\xA6\x82\xB7\x82\xE9(Show Windows Stacked)
 void FAR PASCAL ShowAllWinStacked(HWND myhwnd) 
 {
-	int i, n, height;
+	int n;
 	HWND hwnd[MAXNWIN];
-	RECT rc;
 
-	get_desktop_size_by_multi_monitor(myhwnd, &rc);
-
-	n = 0;
-	for (i = 0 ; i < pm->NWin ; i++) {
-		if (IsIconic(pm->WinList[i]) || !IsWindowVisible(pm->WinList[i]))
-			continue;
-
-		if (pm->WinList[i] == myhwnd) {
-			hwnd[n] = hwnd[0];
-			hwnd[0] = myhwnd;
-		} else {
-			hwnd[n] = pm->WinList[i];
-		}
-		n++;
-	}
-	if (n <= 1)    // \x97L\x8C\xF8\x82ȃE\x83B\x83\x93\x83h\x83E\x82\xAA2\x82ˆȏ\xE3\x82̏ꍇ\x82Ɍ\xC0\x82\xE9
-		goto error;
-
-	height = (rc.bottom - rc.top) / n;
-	for (i = 0 ; i < n ; i++) {
-		ShowWindow(hwnd[i], SW_RESTORE);
-		SetWindowPos(hwnd[i], 0, 
-			rc.left,
-			rc.top + height*i,
-			rc.right - rc.left,
-			height,
-			SWP_NOOWNERZORDER | SWP_NOZORDER);
-	}
-	SetFocus(hwnd[0]);
-
-error:
-	return;
+	get_valid_window_and_memorize_rect(myhwnd, hwnd, &n);
+	if (n >= 2)    // \x97L\x8C\xF8\x82ȃE\x83B\x83\x93\x83h\x83E\x82\xAA2\x82ˆȏ\xE3\x82̏ꍇ\x82Ɍ\xC0\x82\xE9
+		TileWindows(NULL, MDITILE_VERTICAL, NULL, n, hwnd);
 }
 
 // \x83E\x83B\x83\x93\x83h\x83E\x82\xF0\x8Fd\x82˂ĕ\\x8E\xA6\x82\xB7\x82\xE9(Cascade)
 void FAR PASCAL ShowAllWinCascade(HWND myhwnd) 
 {
-	// TODO:
+	int n;
+	HWND hwnd[MAXNWIN];
+
+	get_valid_window_and_memorize_rect(myhwnd, hwnd, &n);
+	if (n >= 2)    // \x97L\x8C\xF8\x82ȃE\x83B\x83\x93\x83h\x83E\x82\xAA2\x82ˆȏ\xE3\x82̏ꍇ\x82Ɍ\xC0\x82\xE9
+		CascadeWindows(NULL, MDITILE_SKIPDISABLED, NULL, n, hwnd);
 }
 
 int FAR PASCAL CommReadRawByte(PComVar cv, LPBYTE b)



Ttssh2-commit メーリングリストの案内