[Ttssh2-commit] [3228] f, sキー等による再生速度の変更がうまく動いていなかったのを修正。

svnno****@sourc***** svnno****@sourc*****
2009年 3月 25日 (水) 04:02:33 JST


Revision: 3228
          http://svn.sourceforge.jp/view?root=ttssh2&view=rev&rev=3228
Author:   doda
Date:     2009-03-25 04:02:33 +0900 (Wed, 25 Mar 2009)

Log Message:
-----------
f,sキー等による再生速度の変更がうまく動いていなかったのを修正。
再生速度を変更した時、タイトルバーに現在の再生速度を表示するようにした。

# ベースはPeterPrvyのパッチ。 Thanks.

Modified Paths:
--------------
    trunk/TTXSamples/TTXttyrec/TTXttyplay.c


-------------- next part --------------
Modified: trunk/TTXSamples/TTXttyrec/TTXttyplay.c
===================================================================
--- trunk/TTXSamples/TTXttyrec/TTXttyplay.c	2009-03-24 15:10:33 UTC (rev 3227)
+++ trunk/TTXSamples/TTXttyrec/TTXttyplay.c	2009-03-24 19:02:33 UTC (rev 3228)
@@ -51,6 +51,7 @@
 	struct timeval wait;
 	char openfn[MAX_PATH];
 	char origTitle[TitleBuffSize];
+	char origOLDTitle[TitleBuffSize];
 } TInstVar;
 
 static TInstVar FAR * pvar;
@@ -62,6 +63,21 @@
 #define GetControlMenu(menu)	GetSubMenuByChildID(menu, ID_CONTROL_RESETTERMINAL)
 #define GetHelpMenu(menu)	GetSubMenuByChildID(menu, ID_HELP_ABOUT)
 
+void RestoreOLDTitle() {
+	strncpy_s(pvar->ts->Title, sizeof(pvar->ts->Title), pvar->origOLDTitle, _TRUNCATE);
+	pvar->ChangeTitle = TRUE;
+	SendMessage(pvar->cv->HWin, WM_COMMAND, MAKELONG(ID_SETUP_WINDOW, 0), 0);
+}
+
+void ChangeTitleStatus() {
+  char tbuff[TitleBuffSize];
+  
+  _snprintf_s(tbuff, sizeof(tbuff), _TRUNCATE, "Speed: %d, Pause: %s", pvar->speed, pvar->pause ? "ON": "OFF");
+  strncpy_s(pvar->ts->Title, sizeof(pvar->ts->Title), tbuff, _TRUNCATE);
+  pvar->ChangeTitle = TRUE;
+  SendMessage(pvar->cv->HWin, WM_COMMAND, MAKELONG(ID_SETUP_WINDOW, 0), 0);
+}
+
 HMENU GetSubMenuByChildID(HMENU menu, UINT id) {
   int i, j, items, subitems, cur_id;
   HMENU m;
@@ -97,9 +113,12 @@
 }
 
 void RestoreTitle() {
+	ChangeTitleStatus ();
+/*
 	strncpy_s(pvar->ts->Title, sizeof(pvar->ts->Title), pvar->origTitle, _TRUNCATE);
 	pvar->ChangeTitle = TRUE;
 	SendMessage(pvar->cv->HWin, WM_COMMAND, MAKELONG(ID_SETUP_WINDOW, 0), 0);
+*/
 }
 
 void ChangeTitle(char *title) {
@@ -113,7 +132,7 @@
 	static struct recheader prh = { 0, 0, 0 };
 	static unsigned int lbytes;
 	static char ibuff[BUFFSIZE];
-	static BOOL title_changed = FALSE;
+	static BOOL title_changed = FALSE, first_title_changed = FALSE;
 
 	int b[3], rsize;
 	struct recheader h;
@@ -131,6 +150,11 @@
 		return pvar->origPReadFile(fh, obuff, oblen, rbytes, rol);
 	}
 
+	if (!first_title_changed) {
+		ChangeTitleStatus ();
+		first_title_changed = TRUE;
+	}
+
 	if (prh.len == 0 && lbytes == 0) {
 		if (!pvar->origPReadFile(fh, b, sizeof(b), &rsize, rol)) {
 			return FALSE;
@@ -150,7 +174,7 @@
 		if (prh.tv.tv_sec != 0) {
 			pvar->wait = tvshift(tvdiff(prh.tv, h.tv), pvar->speed);
 			if (pvar->maxwait != 0 && pvar->wait.tv_sec >= pvar->maxwait) {
-				char tbuff[50];
+				char tbuff[TitleBuffSize];
 				_snprintf_s(tbuff, sizeof(tbuff), _TRUNCATE, "%d.%06d secs idle. trim to %d secs.",
 				pvar->wait.tv_sec, pvar->wait.tv_usec, pvar->maxwait);
 				pvar->wait.tv_sec = pvar->maxwait;
@@ -211,20 +235,23 @@
 	char tmpbuff[2048];
 	unsigned int spos, dpos;
 	char *ptr;
+	BOOL speed_changed = FALSE;
 
 	ptr = (char *)buff;
 	*wbytes = 0;
 
-	for (spos = dpos = 0; *ptr && spos < len; spos++, ptr++) {
+	for (spos = dpos = 0; spos < len; spos++, ptr++) {
 		switch (*ptr) {
 		  case '1':
 			pvar->speed = 0;
+			speed_changed = TRUE;
 			break;
 		  case 'f':
 		  case 'F':
 		  case '+':
 			if (pvar->speed < 8) {
 				pvar->speed++;
+				speed_changed = TRUE;
 			}
 			break;
 		  case 's':
@@ -232,11 +259,13 @@
 		  case '-':
 			if (pvar->speed > -8) {
 				pvar->speed--;
+				speed_changed = TRUE;
 			}
 			break;
 		  case 'p':
 		  case 'P':
 			pvar->pause = !(pvar->pause);
+			speed_changed = TRUE;
 			break;
 		  case ' ':
 		  case '.':
@@ -249,9 +278,13 @@
 		}
 	}
 
+	if (speed_changed) {
+		ChangeTitleStatus ();
+	}
 	if (dpos > 0) {
-		return pvar->origPWriteFile(fh, tmpbuff, dpos, wbytes, wol);
+		pvar->origPWriteFile(fh, tmpbuff, dpos, wbytes, wol);
 	}
+	*wbytes = len;
 	return TRUE;
 }
 
@@ -261,6 +294,8 @@
 		pvar->origPWriteFile = *hooks->PWriteFile;
 		*hooks->PReadFile = TTXReadFile;
 		*hooks->PWriteFile = TTXWriteFile;
+
+		strncpy_s(pvar->origOLDTitle, sizeof(pvar->origOLDTitle), pvar->ts->Title, _TRUNCATE);
 	}
 }
 
@@ -271,7 +306,7 @@
 	if (pvar->origPWriteFile) {
 		*hooks->PWriteFile = pvar->origPWriteFile;
 	}
-
+	RestoreOLDTitle();
 	pvar->enable = FALSE;
 }
 
@@ -369,6 +404,7 @@
 			ofn.lpstrDefExt = "tty";
 			// ofn.lpstrTitle = "";
 			ofn.Flags = OFN_FILEMUSTEXIST;
+			
 			if (GetOpenFileName(&ofn)) {
 				pvar->ReplaceHostDlg = TRUE;
 				// Call New-Connection dialog



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