[Ttssh2-commit] [8354] パラメータなしの SetDlgPos を実装

scmno****@osdn***** scmno****@osdn*****
2019年 11月 2日 (土) 23:49:29 JST


Revision: 8354
          https://osdn.net/projects/ttssh2/scm/svn/commits/8354
Author:   zmatsuo
Date:     2019-11-02 23:49:29 +0900 (Sat, 02 Nov 2019)
Log Message:
-----------
パラメータなしの SetDlgPos を実装

- ダイアログの位置調整部分を macrodlgbase.h にくくりだした

Modified Paths:
--------------
    trunk/teraterm/ttpmacro/CMakeLists.txt
    trunk/teraterm/ttpmacro/ListDlg.cpp
    trunk/teraterm/ttpmacro/ListDlg.h
    trunk/teraterm/ttpmacro/errdlg.cpp
    trunk/teraterm/ttpmacro/errdlg.h
    trunk/teraterm/ttpmacro/inpdlg.cpp
    trunk/teraterm/ttpmacro/inpdlg.h
    trunk/teraterm/ttpmacro/msgdlg.cpp
    trunk/teraterm/ttpmacro/msgdlg.h
    trunk/teraterm/ttpmacro/statdlg.cpp
    trunk/teraterm/ttpmacro/statdlg.h
    trunk/teraterm/ttpmacro/ttl.c
    trunk/teraterm/ttpmacro/ttmdlg.cpp

Added Paths:
-----------
    trunk/teraterm/ttpmacro/macrodlgbase.h

-------------- next part --------------
Modified: trunk/teraterm/ttpmacro/CMakeLists.txt
===================================================================
--- trunk/teraterm/ttpmacro/CMakeLists.txt	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/CMakeLists.txt	2019-11-02 14:49:29 UTC (rev 8354)
@@ -53,6 +53,7 @@
   msgdlg.h
   statdlg.cpp
   statdlg.h
+  macrodlgbase.h
   ttl.c
   ttl.h
   ttm_res.h

Modified: trunk/teraterm/ttpmacro/ListDlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ListDlg.cpp	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/ListDlg.cpp	2019-11-02 14:49:29 UTC (rev 8354)
@@ -196,21 +196,7 @@
 	::MoveWindow(HOk,CONTROL_GAP_W+CONTROL_GAP_W+LW,BH/2,BW,BH,TRUE);
 	::MoveWindow(HCancel,CONTROL_GAP_W+CONTROL_GAP_W+LW,BH*2,BW,BH,TRUE);
 
-	// PosX\x82\xAA\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̊O\x82\xCC-100\x88ȉ\xBA\x82̈ʒu\x82ɂ\xA0\x82\xE9\x8Fꍇ
-	if (PosX<=GetMonitorLeftmost(PosX, PosY)-100) {
-		// \x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x83Z\x83b\x83g
-		::SetWindowPos(m_hWnd, HWND_TOP,0,0,WW,WH,SWP_NOMOVE);
-		// \x92\x86\x89\x9B\x82Ɉړ\xAE\x82\xB7\x82\xE9
-		CenterWindow(m_hWnd, NULL);
-		// \x88ʒu\x82\xF0\x95ۑ\xB6
-		RECT rcWnd;
-		GetWindowRect(&rcWnd);
-		PosX = rcWnd.left;
-		PosY = rcWnd.top;
-	} else {
-		// \x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x83Z\x83b\x83g + \x8Ew\x92\xE8\x88ʒu\x82ֈړ\xAE
-		::SetWindowPos(m_hWnd, HWND_TOP,PosX,PosY,WW,WH, 0);
-	}
+	SetDlgPos();
 
 	::InvalidateRect(m_hWnd, NULL, TRUE);
 }

Modified: trunk/teraterm/ttpmacro/ListDlg.h
===================================================================
--- trunk/teraterm/ttpmacro/ListDlg.h	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/ListDlg.h	2019-11-02 14:49:29 UTC (rev 8354)
@@ -27,8 +27,11 @@
  */
 #pragma once
 
+#include "../common/tmfc.h"
+#include "macrodlgbase.h"
+
 // CListDlg \x83_\x83C\x83A\x83\x8D\x83O
-class CListDlg : public TTCDialog
+class CListDlg : public CMacroDlgBase
 {
 public:
 	CListDlg(PCHAR Text, PCHAR Caption, const CHAR **Lists, int Selected, int x, int y);
@@ -41,7 +44,7 @@
 	PCHAR m_Caption;
 	const CHAR **m_Lists;
 	int m_Selected;
-	int PosX, PosY, init_WW, WW, WH, TW, TH, BH, BW, LW, LH;
+	int init_WW, TW, TH, BH, BW, LW, LH;
 	SIZE s;
 
 	void Relocation(BOOL is_init, int WW);

Modified: trunk/teraterm/ttpmacro/errdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/errdlg.cpp	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/errdlg.cpp	2019-11-02 14:49:29 UTC (rev 8354)
@@ -99,15 +99,8 @@
 		strncat_s(buf, sizeof(buf), ">>>", _TRUNCATE);
 	SetDlgItemText(IDC_EDIT_ERRLINE, buf);
 
-	if (PosX<=GetMonitorLeftmost(PosX, PosY)-100) {
-		// \x92\x86\x89\x9B\x82Ɉړ\xAE\x82\xB7\x82\xE9
-		CenterWindow(m_hWnd, m_hParentWnd);
-		// \x88ʒu\x82\xF0\x95ۑ\xB6
-		RECT rcWnd;
-		GetWindowRect(&rcWnd);
-		PosX = rcWnd.left;
-		PosY = rcWnd.top;
-	}
+	SetDlgPos();
+
 	::SetForegroundWindow(m_hWnd);
 
 	return TRUE;

Modified: trunk/teraterm/ttpmacro/errdlg.h
===================================================================
--- trunk/teraterm/ttpmacro/errdlg.h	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/errdlg.h	2019-11-02 14:49:29 UTC (rev 8354)
@@ -31,8 +31,9 @@
 
 // CErrDlg dialog
 #include "tmfc.h"
+#include "macrodlgbase.h"
 
-class CErrDlg : public TTCDialog
+class CErrDlg : public CMacroDlgBase
 {
 public:
 	CErrDlg(const char *Msg, PCHAR Line, int x, int y, int lineno, int start, int end, PCHAR FileName);
@@ -43,7 +44,6 @@
 
 	const char* MsgStr;
 	PCHAR LineStr;
-	int PosX, PosY;
 	int LineNo;
 	int StartPos, EndPos;
 	PCHAR MacroFileName;

Modified: trunk/teraterm/ttpmacro/inpdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/inpdlg.cpp	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/inpdlg.cpp	2019-11-02 14:49:29 UTC (rev 8354)
@@ -167,20 +167,7 @@
 
 	SendDlgItemMessage(IDC_INPEDIT, EM_LIMITTEXT, MaxStrLen, 0);
 
-	if (PosX<=GetMonitorLeftmost(PosX, PosY)-100) {
-		// \x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x83Z\x83b\x83g
-		::SetWindowPos(m_hWnd, HWND_TOP,0,0,WW,WH,SWP_NOMOVE);
-		// \x92\x86\x89\x9B\x82Ɉړ\xAE\x82\xB7\x82\xE9
-		CenterWindow(m_hWnd, m_hParentWnd);
-		// \x88ʒu\x82\xF0\x95ۑ\xB6
-		RECT rcWnd;
-		GetWindowRect(&rcWnd);
-		PosX = rcWnd.left;
-		PosY = rcWnd.top;
-	} else {
-		// \x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x83Z\x83b\x83g + \x8Ew\x92\xE8\x88ʒu\x82ֈړ\xAE
-		::SetWindowPos(m_hWnd, HWND_TOP,PosX,PosY,WW,WH, 0);
-	}
+	SetDlgPos();
 
 	InvalidateRect(NULL, TRUE);
 }

Modified: trunk/teraterm/ttpmacro/inpdlg.h
===================================================================
--- trunk/teraterm/ttpmacro/inpdlg.h	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/inpdlg.h	2019-11-02 14:49:29 UTC (rev 8354)
@@ -29,9 +29,12 @@
 
 /* TTMACRO.EXE, input dialog box */
 
+#pragma once
+
 #include "../common/tmfc.h"
+#include "macrodlgbase.h"
 
-class CInpDlg : public TTCDialog
+class CInpDlg : public CMacroDlgBase
 {
 public:
 	CInpDlg(PCHAR Input, PCHAR Text, PCHAR Title,
@@ -44,7 +47,7 @@
 
 	PCHAR InputStr, TextStr, TitleStr, DefaultStr;
 	BOOL PaswdFlag;
-	int PosX, PosY, init_WW, WW, WH, TW, TH, BH, BW, EW, EH;
+	int init_WW, TW, TH, BH, BW, EW, EH;
 	SIZE s;
 
 	virtual BOOL OnInitDialog();

Copied: trunk/teraterm/ttpmacro/macrodlgbase.h (from rev 8353, trunk/teraterm/ttpmacro/inpdlg.h)
===================================================================
--- trunk/teraterm/ttpmacro/macrodlgbase.h	                        (rev 0)
+++ trunk/teraterm/ttpmacro/macrodlgbase.h	2019-11-02 14:49:29 UTC (rev 8354)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2019 TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "../common/tmfc.h"
+#include "ttmlib.h"
+
+class CMacroDlgBase : public TTCDialog
+{
+protected:
+	int PosX, PosY;  // \x83E\x83B\x83\x93\x83h\x83E\x88ʒu
+	int WW, WH;		 // \x83E\x83B\x83\x93\x83h\x83E\x95\x9D
+
+	CMacroDlgBase()
+	{
+		PosX = 0;
+		PosY = 0;
+		WW = 0;
+		WH = 0;
+	}
+
+	/**
+	 *	\x83_\x83C\x83A\x83\x8D\x83O\x82̃T\x83C\x83Y\x82ƈʒu\x82\xF0\x90ݒ肷\x82\xE9
+	 */
+	void SetDlgPos()
+	{
+		if (WW == 0 || WH == 0) {
+			// \x83E\x83B\x83\x93\x83h\x83E\x88ʒu\x82̂ݐݒ肷\x82\xE9 errdlg
+			if (IsValidPos()) {
+				::SetWindowPos(m_hWnd, HWND_TOP, PosX, PosY, 0, 0, SWP_NOSIZE);
+			}
+			else {
+				// \x92\x86\x89\x9B\x82Ɉړ\xAE\x82\xB7\x82\xE9
+				CenterWindow(m_hWnd, NULL);
+				// \x88ʒu\x82\xF0\x95ۑ\xB6
+				RECT rcWnd;
+				GetWindowRect(&rcWnd);
+				PosX = rcWnd.left;
+				PosY = rcWnd.top;
+			}
+		}
+		else {
+			// \x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xE0\x8D\x87\x82킹\x82Đݒ肷\x82\xE9
+			if (IsValidPos()) {
+				// \x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x83Z\x83b\x83g + \x8Ew\x92\xE8\x88ʒu\x82ֈړ\xAE
+				::SetWindowPos(m_hWnd, HWND_TOP, PosX, PosY, WW, WH, 0);
+			}
+			else {
+				// \x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x83Z\x83b\x83g
+				::SetWindowPos(m_hWnd, HWND_TOP, 0, 0, WW, WH, SWP_NOMOVE);
+				// \x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̒\x86\x89\x9B\x82Ɉړ\xAE\x82\xB7\x82\xE9
+				CenterWindow(m_hWnd, NULL);
+				// \x88ʒu\x82\xF0\x95ۑ\xB6
+				RECT rcWnd;
+				GetWindowRect(&rcWnd);
+				PosX = rcWnd.left;
+				PosY = rcWnd.top;
+			}
+		}
+	}
+
+private:
+	/**
+	 *	\x83_\x83C\x83A\x83\x8D\x83O\x88ʒu\x82\xAA\x97L\x8C\xF8?
+	 *	@retval TRUE	\x97L\x8C\xF8
+	 *	@retval FALSE	\x96\xB3\x8C\xF8
+	 */
+	BOOL IsValidPos()
+	{
+		// return !(PosX <= GetMonitorLeftmost(PosX, PosY) - 100);
+		return !((PosX == CW_USEDEFAULT) || (PosY == CW_USEDEFAULT));
+	}
+};

Modified: trunk/teraterm/ttpmacro/msgdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/msgdlg.cpp	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/msgdlg.cpp	2019-11-02 14:49:29 UTC (rev 8354)
@@ -162,20 +162,7 @@
 		::MoveWindow(HOk,(TW-BW)/2,TH+BH,BW,BH,TRUE);
 	}
 
-	if (PosX<=GetMonitorLeftmost(PosX, PosY)-100) {
-		// \x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x83Z\x83b\x83g
-		::SetWindowPos(m_hWnd, HWND_TOP,0,0,WW,WH,SWP_NOMOVE);
-		// \x92\x86\x89\x9B\x82Ɉړ\xAE\x82\xB7\x82\xE9
-		CenterWindow(m_hWnd, m_hParentWnd);
-		// \x88ʒu\x82\xF0\x95ۑ\xB6
-		RECT rcWnd;
-		GetWindowRect(&rcWnd);
-		PosX = rcWnd.left;
-		PosY = rcWnd.top;
-	} else {
-		// \x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x83Z\x83b\x83g + \x8Ew\x92\xE8\x88ʒu\x82ֈړ\xAE
-		::SetWindowPos(m_hWnd, HWND_TOP,PosX,PosY,WW,WH, 0);
-	}
+	SetDlgPos();
 
 	InvalidateRect(NULL);
 }

Modified: trunk/teraterm/ttpmacro/msgdlg.h
===================================================================
--- trunk/teraterm/ttpmacro/msgdlg.h	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/msgdlg.h	2019-11-02 14:49:29 UTC (rev 8354)
@@ -29,9 +29,11 @@
 
 /* TTMACRO.EXE, message dialog box */
 
+#include "../common/tmfc.h"
+#include "macrodlgbase.h"
 #include "ttm_res.h"
 
-class CMsgDlg : public TTCDialog
+class CMsgDlg : public CMacroDlgBase
 {
 public:
 	CMsgDlg(const TCHAR *Text, const TCHAR *Title, BOOL YesNo, int x, int y);
@@ -43,7 +45,7 @@
 	const TCHAR *TextStr;
 	const TCHAR *TitleStr;
 	BOOL YesNoFlag;
-	int  PosX, PosY, init_WW, WW, WH, TW, TH, BH, BW;
+	int  init_WW, TW, TH, BH, BW;
 	SIZE s;
 
 	virtual BOOL OnInitDialog();

Modified: trunk/teraterm/ttpmacro/statdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/statdlg.cpp	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/statdlg.cpp	2019-11-02 14:49:29 UTC (rev 8354)
@@ -48,7 +48,7 @@
 	TitleStr = Title;
 	PosX = x;
 	PosY = y;
-	return TTCDialog::Create(hInst, GetDesktopWindow(), CStatDlg::IDD);
+	return TTCDialog::Create(hInst, NULL, CStatDlg::IDD);
 }
 
 void CStatDlg::Update(PCHAR Text, PCHAR Title, int x, int y)
@@ -203,20 +203,7 @@
 		::MoveWindow(HText,(TW-s.cx)/2,5,TW,TH,TRUE);
 	}
 
-	if (PosX<=GetMonitorLeftmost(PosX, PosY)-100) {
-		// \x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x83Z\x83b\x83g
-		::SetWindowPos(m_hWnd, HWND_TOP,0,0,WW,WH,SWP_NOMOVE);
-		// \x92\x86\x89\x9B\x82Ɉړ\xAE\x82\xB7\x82\xE9
-		CenterWindow(m_hWnd, NULL);
-		// \x88ʒu\x82\xF0\x95ۑ\xB6
-		RECT rcWnd;
-		GetWindowRect(&rcWnd);
-		PosX = rcWnd.left;
-		PosY = rcWnd.top;
-	} else {
-		// \x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x83Z\x83b\x83g + \x8Ew\x92\xE8\x88ʒu\x82ֈړ\xAE
-		::SetWindowPos(m_hWnd, HWND_TOP,PosX,PosY,WW,WH, 0);
-	}
+	SetDlgPos();
 
 	InvalidateRect(NULL, TRUE);
 }

Modified: trunk/teraterm/ttpmacro/statdlg.h
===================================================================
--- trunk/teraterm/ttpmacro/statdlg.h	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/statdlg.h	2019-11-02 14:49:29 UTC (rev 8354)
@@ -29,7 +29,9 @@
 
 /* TTMACRO.EXE, status dialog box */
 
-class CStatDlg : public TTCDialog
+#include "macrodlgbase.h"
+
+class CStatDlg : public CMacroDlgBase
 {
 public:
 	BOOL Create(HINSTANCE hInst, PCHAR Text, PCHAR Title, int x, int y);
@@ -38,7 +40,7 @@
 	enum { IDD = IDD_STATDLG };
 private:
 	PCHAR TextStr, TitleStr;
-	int  PosX, PosY, init_WW, WW, WH, TW, TH;
+	int  init_WW, TW, TH;
 	SIZE s;
 
 	virtual BOOL OnInitDialog();

Modified: trunk/teraterm/ttpmacro/ttl.c
===================================================================
--- trunk/teraterm/ttpmacro/ttl.c	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/ttl.c	2019-11-02 14:49:29 UTC (rev 8354)
@@ -4324,16 +4324,22 @@
 
 WORD TTLSetDlgPos()
 {
-	WORD Err;
-	int x, y;
+	WORD Err = 0;
 
-	Err = 0;
-	GetIntVal(&x,&Err);
-	GetIntVal(&y,&Err);
-	if ((Err==0) && (GetFirstChar()!=0))
-		Err = ErrSyntax;
-	if (Err!=0) return Err;
-	SetDlgPos(x,y);
+	if (CheckParameterGiven()) {
+		// \x83p\x83\x89\x83\x81\x81[\x83^\x82\xAA\x82\xA0\x82\xEA\x82΁Ax  y \x82\xCC2\x82‚̃p\x83\x89\x83\x81\x81[\x83^\x82\xAA\x82\xA0\x82\xE9
+		int x, y;
+		GetIntVal(&x,&Err);
+		GetIntVal(&y,&Err);
+		if ((Err==0) && (GetFirstChar()!=0))
+			Err = ErrSyntax;
+		if (Err!=0) return Err;
+		SetDlgPos(x,y);
+	}
+	else {
+		// \x83p\x83\x89\x83\x81\x81[\x83^\x82\xAA\x82Ȃ\xAF\x82\xEA\x82΃f\x83t\x83H\x83\x8B\x83g\x88ʒu\x82ɖ߂\xB7
+		SetDlgPos(CW_USEDEFAULT, CW_USEDEFAULT);
+	}
 	return Err;
 }
 

Modified: trunk/teraterm/ttpmacro/ttmdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttmdlg.cpp	2019-10-30 13:33:16 UTC (rev 8353)
+++ trunk/teraterm/ttpmacro/ttmdlg.cpp	2019-11-02 14:49:29 UTC (rev 8354)
@@ -68,8 +68,9 @@
 int ParamsSize;
 BOOL SleepFlag;
 
-static int DlgPosX = -10000;
-static int DlgPosY = 0;
+// (x,y) = (CW_USEDEFAULT, CW_USEDEFAULT)\x82̂Ƃ\xAB\x83Z\x83\x93\x83^\x81[\x82ɕ\\x8E\xA6
+static int DlgPosX = CW_USEDEFAULT;
+static int DlgPosY = CW_USEDEFAULT;
 
 static CStatDlg *StatDlg = NULL;
 


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