[Ttssh2-commit] [8544] SSH Authentication Banner の バルーン通知を Unicode 対応とした

scmno****@osdn***** scmno****@osdn*****
2020年 2月 18日 (火) 00:27:46 JST


Revision: 8544
          https://osdn.net/projects/ttssh2/scm/svn/commits/8544
Author:   zmatsuo
Date:     2020-02-18 00:27:46 +0900 (Tue, 18 Feb 2020)
Log Message:
-----------
SSH Authentication Banner の バルーン通知を Unicode 対応とした

- r8530
- NotifyMessageW() 追加 (ttpcmn.dll)
- ttcmn から NotifyIcon 関連を ttcmn_notify.cpp に移動
- vs2005,vs2019,cmake

Revision Links:
--------------
    https://osdn.net/projects/ttssh2/scm/svn/commits/8530

Modified Paths:
--------------
    trunk/teraterm/common/ttcommon.h
    trunk/teraterm/common/tttypes.h
    trunk/teraterm/ttpcmn/CMakeLists.txt
    trunk/teraterm/ttpcmn/ttcmn.c
    trunk/teraterm/ttpcmn/ttpcmn.v16.vcxproj
    trunk/teraterm/ttpcmn/ttpcmn.v16.vcxproj.filters
    trunk/teraterm/ttpcmn/ttpcmn.vcproj
    trunk/ttssh2/ttxssh/ssh.c

Added Paths:
-----------
    trunk/teraterm/ttpcmn/ttcmn_notify.cpp

-------------- next part --------------
Modified: trunk/teraterm/common/ttcommon.h
===================================================================
--- trunk/teraterm/common/ttcommon.h	2020-02-17 15:27:34 UTC (rev 8543)
+++ trunk/teraterm/common/ttcommon.h	2020-02-17 15:27:46 UTC (rev 8544)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 1994-1998 T. Teranishi
- * (C) 2004-2019 TeraTerm Project
+ * (C) 2004-2020 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -87,7 +87,8 @@
 
 DllExport void PASCAL CreateNotifyIcon(PComVar cv);
 DllExport void PASCAL DeleteNotifyIcon(PComVar cv);
-DllExport void PASCAL NotifyMessage(PComVar cv, PCHAR message, PCHAR title, DWORD flag);
+DllExport void PASCAL NotifyMessageW(PComVar cv, const wchar_t *message, const wchar_t *title, DWORD flag);
+DllExport void PASCAL NotifyMessage(PComVar cv, const char *message, const char *title, DWORD flag);
 DllExport void PASCAL ShowNotifyIcon(PComVar cv);
 DllExport void PASCAL HideNotifyIcon(PComVar cv);
 DllExport void PASCAL SetVerNotifyIcon(PComVar cv, unsigned int ver);
@@ -97,6 +98,9 @@
 #define NotifyInfoMessage(cv, msg, title) NotifyMessage(cv, msg, title, 1)
 #define NotifyWarnMessage(cv, msg, title) NotifyMessage(cv, msg, title, 2)
 #define NotifyErrorMessage(cv, msg, title) NotifyMessage(cv, msg, title, 3)
+#define NotifyInfoMessageW(cv, msg, title) NotifyMessageW(cv, msg, title, 1)
+#define NotifyWarnMessageW(cv, msg, title) NotifyMessageW(cv, msg, title, 2)
+#define NotifyErrorMessageW(cv, msg, title) NotifyMessageW(cv, msg, title, 3)
 
 #include "../ttpcmn/language.h"
 

Modified: trunk/teraterm/common/tttypes.h
===================================================================
--- trunk/teraterm/common/tttypes.h	2020-02-17 15:27:34 UTC (rev 8543)
+++ trunk/teraterm/common/tttypes.h	2020-02-17 15:27:46 UTC (rev 8544)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 1994-1998 T. Teranishi
- * (C) 2004-2019 TeraTerm Project
+ * (C) 2004-2020 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -1123,7 +1123,7 @@
 	_locale_t locale;
 	BOOL VirtualStoreEnabled;
 
-	NOTIFYICONDATA *NotifyIcon;
+	void *NotifyIcon;
 
 	DWORD ConnectedTime;
 } TComVar;

Modified: trunk/teraterm/ttpcmn/CMakeLists.txt
===================================================================
--- trunk/teraterm/ttpcmn/CMakeLists.txt	2020-02-17 15:27:34 UTC (rev 8543)
+++ trunk/teraterm/ttpcmn/CMakeLists.txt	2020-02-17 15:27:46 UTC (rev 8544)
@@ -29,6 +29,7 @@
   language.c
   language.h
   ttcmn.c
+  ttcmn_notify.cpp
   comportinfo.cpp
   comportinfo.h
   comportinfo.cpp

Modified: trunk/teraterm/ttpcmn/ttcmn.c
===================================================================
--- trunk/teraterm/ttpcmn/ttcmn.c	2020-02-17 15:27:34 UTC (rev 8543)
+++ trunk/teraterm/ttpcmn/ttcmn.c	2020-02-17 15:27:46 UTC (rev 8544)
@@ -2801,142 +2801,6 @@
 	return found;
 }
 
-// Notify Icon \x8A֘A
-static NOTIFYICONDATA notify_icon = {0};
-static int NotifyIconShowCount = 0;
-static HICON CustomIcon = NULL;
-
-void WINAPI SetCustomNotifyIcon(HICON icon)
-{
-	CustomIcon = icon;
-}
-
-HICON WINAPI GetCustomNotifyIcon(void)
-{
-	return CustomIcon;
-}
-
-void WINAPI CreateNotifyIcon(PComVar cv)
-{
-	if (cv->NotifyIcon == NULL) {
-		notify_icon.cbSize = sizeof(notify_icon);
-		notify_icon.hWnd = cv->HWin;
-		notify_icon.uID = 1;
-		notify_icon.uFlags = NIF_ICON | NIF_MESSAGE;
-		notify_icon.uCallbackMessage = WM_USER_NOTIFYICON;
-		if (CustomIcon) {
-			notify_icon.hIcon = CustomIcon;
-		}
-		else {
-			notify_icon.hIcon = (HICON)SendMessage(cv->HWin, WM_GETICON, ICON_SMALL, 0);
-		}
-		notify_icon.szTip[0] = '\0';
-		notify_icon.dwState = 0;
-		notify_icon.dwStateMask = 0;
-		notify_icon.szInfo[0] = '\0';
-		notify_icon.uTimeout = 0;
-		notify_icon.szInfoTitle[0] = '\0';
-		notify_icon.dwInfoFlags = 0;
-
-		cv->NotifyIcon = &notify_icon;
-
-		Shell_NotifyIcon(NIM_ADD, cv->NotifyIcon);
-
-		NotifyIconShowCount = 0;
-	}
-
-	return;
-}
-
-void WINAPI DeleteNotifyIcon(PComVar cv)
-{
-	if (cv->NotifyIcon) {
-		Shell_NotifyIcon(NIM_DELETE, cv->NotifyIcon);
-		cv->NotifyIcon = NULL;
-		NotifyIconShowCount = 0;
-	}
-
-	return;
-}
-
-void WINAPI ShowNotifyIcon(PComVar cv)
-{
-	if (cv->NotifyIcon == NULL) {
-		CreateNotifyIcon(cv);
-	}
-
-	cv->NotifyIcon->uFlags = NIF_STATE;
-	cv->NotifyIcon->dwState = 0;
-	cv->NotifyIcon->dwStateMask = NIS_HIDDEN;
-	Shell_NotifyIcon(NIM_MODIFY, cv->NotifyIcon);
-	NotifyIconShowCount += 1;
-
-	return;
-}
-
-void WINAPI HideNotifyIcon(PComVar cv)
-{
-	if (NotifyIconShowCount > 1) {
-		NotifyIconShowCount -= 1;
-	}
-	else {
-		if (cv->NotifyIcon) {
-			cv->NotifyIcon->uFlags = NIF_STATE;
-			cv->NotifyIcon->dwState = NIS_HIDDEN;
-			cv->NotifyIcon->dwStateMask = NIS_HIDDEN;
-			Shell_NotifyIcon(NIM_MODIFY, cv->NotifyIcon);
-		}
-		NotifyIconShowCount = 0;
-	}
-
-	return;
-}
-
-void WINAPI SetVerNotifyIcon(PComVar cv, unsigned int ver)
-{
-	if (cv->NotifyIcon) {
-		cv->NotifyIcon->uVersion = ver;
-		Shell_NotifyIcon(NIM_SETVERSION, cv->NotifyIcon);
-	}
-	return;
-}
-
-void WINAPI NotifyMessage(PComVar cv, char *msg, char *title, DWORD flag)
-{
-	if (msg == NULL) {
-		return;
-	}
-
-	if (! HasBalloonTipSupport()) {
-		return;
-	}
-
-	if (cv->NotifyIcon == NULL) {
-		CreateNotifyIcon(cv);
-	}
-
-	cv->NotifyIcon->uFlags = NIF_INFO | NIF_STATE;
-	cv->NotifyIcon->dwState = 0;
-	cv->NotifyIcon->dwStateMask = NIS_HIDDEN;
-
-	if (title) {
-		cv->NotifyIcon->dwInfoFlags = flag;
-		strncpy_s(cv->NotifyIcon->szInfoTitle, sizeof(cv->NotifyIcon->szInfoTitle), title, _TRUNCATE);
-	}
-	else {
-		cv->NotifyIcon->dwInfoFlags = NIIF_NONE;
-		cv->NotifyIcon->szInfoTitle[0] = 0;
-	}
-
-	strncpy_s(cv->NotifyIcon->szInfo, sizeof(cv->NotifyIcon->szInfo), msg, _TRUNCATE);
-
-	Shell_NotifyIcon(NIM_MODIFY, cv->NotifyIcon);
-
-	NotifyIconShowCount += 1;
-
-	return;
-}
-
 /*
  *	@return		\x83G\x83\x89\x81[\x82\xAA\x97L\x82\xE9\x8Fꍇ FALSE
  *	@param[in]	BOOL first_instance

Added: trunk/teraterm/ttpcmn/ttcmn_notify.cpp
===================================================================
--- trunk/teraterm/ttpcmn/ttcmn_notify.cpp	                        (rev 0)
+++ trunk/teraterm/ttpcmn/ttcmn_notify.cpp	2020-02-17 15:27:46 UTC (rev 8544)
@@ -0,0 +1,226 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+/* TTCMN.DLL, notify icon */
+
+#define _WIN32_IE 0x0600
+#include <string.h>
+#include <windows.h>
+#include <wchar.h>
+#define _CRTDBG_MAP_ALLOC
+#include <stdlib.h>
+#include <crtdbg.h>
+
+#include "teraterm.h"
+#include "tttypes.h"
+#include "ttftypes.h"
+#include "ttcommon.h"
+#include "codeconv.h"
+#include "layer_for_unicode.h"
+
+typedef struct {
+	TT_NOTIFYICONDATAW_V2 notify_icon;
+	int NotifyIconShowCount;
+	HICON CustomIcon;
+} NotifyIcon;
+
+static NotifyIcon *NotifyCreate(HWND hWnd, HICON icon, UINT msg)
+{
+	NotifyIcon *ni = (NotifyIcon *)malloc(sizeof(NotifyIcon));
+	memset(ni, 0, sizeof(*ni));
+
+	TT_NOTIFYICONDATAW_V2 *p = &ni->notify_icon;
+	p->cbSize = sizeof(*p);
+	p->hWnd = hWnd;
+	p->uID = 1;
+	p->uFlags = NIF_ICON | NIF_MESSAGE;
+	p->uCallbackMessage = msg;
+	p->hIcon = icon;
+
+	_Shell_NotifyIconW(NIM_ADD, p);
+
+	ni->NotifyIconShowCount = 0;
+
+	return ni;
+}
+
+static void NotifyDelete(NotifyIcon *ni)
+{
+	TT_NOTIFYICONDATAW_V2 *NotifyIcon = &ni->notify_icon;
+	_Shell_NotifyIconW(NIM_DELETE, NotifyIcon);
+	ni->NotifyIconShowCount = 0;
+}
+
+static void NotifyShowIcon(NotifyIcon *ni)
+{
+	TT_NOTIFYICONDATAW_V2 *NotifyIcon = &ni->notify_icon;
+	NotifyIcon->uFlags = NIF_STATE;
+	NotifyIcon->dwState = 0;
+	NotifyIcon->dwStateMask = NIS_HIDDEN;
+	_Shell_NotifyIconW(NIM_MODIFY, NotifyIcon);
+	ni->NotifyIconShowCount += 1;
+}
+
+static void NotifyHide(NotifyIcon *ni)
+{
+	if (ni->NotifyIconShowCount > 1) {
+		ni->NotifyIconShowCount -= 1;
+	}
+	else {
+		TT_NOTIFYICONDATAW_V2 *NotifyIcon = &ni->notify_icon;
+		NotifyIcon->uFlags = NIF_STATE;
+		NotifyIcon->dwState = NIS_HIDDEN;
+		NotifyIcon->dwStateMask = NIS_HIDDEN;
+		_Shell_NotifyIconW(NIM_MODIFY, NotifyIcon);
+		ni->NotifyIconShowCount = 0;
+	}
+}
+
+static void NotifySetVersion(NotifyIcon *ni, unsigned int ver)
+{
+	TT_NOTIFYICONDATAW_V2 *NotifyIcon = &ni->notify_icon;
+	NotifyIcon->uVersion = ver;
+	_Shell_NotifyIconW(NIM_SETVERSION, NotifyIcon);
+}
+
+static void NotifySetMessageW(NotifyIcon *ni, const wchar_t *msg, const wchar_t *title, DWORD flag)
+{
+	if (msg == NULL) {
+		return;
+	}
+
+	if (! HasBalloonTipSupport()) {
+		return;
+	}
+
+	TT_NOTIFYICONDATAW_V2 *NotifyIcon = &ni->notify_icon;
+	NotifyIcon->uFlags = NIF_INFO | NIF_STATE;
+	NotifyIcon->dwState = 0;
+	NotifyIcon->dwStateMask = NIS_HIDDEN;
+
+	if (title) {
+		NotifyIcon->dwInfoFlags = flag;
+		wcsncpy_s(NotifyIcon->szInfoTitle, _countof(NotifyIcon->szInfoTitle), title, _TRUNCATE);
+	}
+	else {
+		NotifyIcon->dwInfoFlags = NIIF_NONE;
+		NotifyIcon->szInfoTitle[0] = 0;
+	}
+
+	wcsncpy_s(NotifyIcon->szInfo, _countof(NotifyIcon->szInfo), msg, _TRUNCATE);
+
+	_Shell_NotifyIconW(NIM_MODIFY, NotifyIcon);
+
+	ni->NotifyIconShowCount += 1;
+}
+
+/*
+ *	EXPORT API
+ */
+static HICON CustomIcon = NULL;
+
+static NotifyIcon *GetNotifyData(PComVar cv)
+{
+	NotifyIcon *p = (NotifyIcon *)cv->NotifyIcon;
+	return p;
+}
+
+void WINAPI SetCustomNotifyIcon(HICON icon)
+{
+	CustomIcon = icon;
+}
+
+HICON WINAPI GetCustomNotifyIcon()
+{
+	return CustomIcon;
+}
+
+void WINAPI CreateNotifyIcon(PComVar cv)
+{
+	NotifyIcon *ni = GetNotifyData(cv);
+	if (ni != NULL) {
+		return;
+	}
+	HICON icon = CustomIcon;
+	if (icon == NULL) {
+		icon = (HICON)SendMessage(cv->HWin, WM_GETICON, ICON_SMALL, 0);
+	}
+
+	ni = NotifyCreate(cv->HWin, icon, WM_USER_NOTIFYICON);
+	cv->NotifyIcon = ni;
+}
+
+void WINAPI DeleteNotifyIcon(PComVar cv)
+{
+	NotifyIcon* ni = GetNotifyData(cv);
+	NotifyDelete(ni);
+}
+
+void WINAPI ShowNotifyIcon(PComVar cv)
+{
+	NotifyIcon* ni = GetNotifyData(cv);
+	if (ni == NULL) {
+		CreateNotifyIcon(cv);
+		ni = GetNotifyData(cv);
+	}
+
+	NotifyShowIcon(ni);
+}
+
+void WINAPI HideNotifyIcon(PComVar cv)
+{
+	NotifyIcon *ni = GetNotifyData(cv);
+	NotifyHide(ni);
+}
+
+// \x8Eg\x82\xED\x82\xEA\x82Ă\xA2\x82Ȃ\xA2
+void WINAPI SetVerNotifyIcon(PComVar cv, unsigned int ver)
+{
+	NotifyIcon *ni = GetNotifyData(cv);
+	NotifySetVersion(ni, ver);
+}
+
+void WINAPI NotifyMessageW(PComVar cv, const wchar_t *msg, const wchar_t *title, DWORD flag)
+{
+	NotifyIcon *ni = GetNotifyData(cv);
+	if (ni == NULL) {
+		CreateNotifyIcon(cv);
+		ni = GetNotifyData(cv);
+	}
+
+	NotifySetMessageW(ni, msg, title, flag);
+}
+
+void WINAPI NotifyMessage(PComVar cv, const char *msg, const char *title, DWORD flag)
+{
+	wchar_t *titleW = ToWcharA(title);
+	wchar_t *msgW = ToWcharA(msg);
+	NotifyMessageW(cv, msgW, titleW, flag);
+	free(titleW);
+	free(msgW);
+}

Modified: trunk/teraterm/ttpcmn/ttpcmn.v16.vcxproj
===================================================================
--- trunk/teraterm/ttpcmn/ttpcmn.v16.vcxproj	2020-02-17 15:27:34 UTC (rev 8543)
+++ trunk/teraterm/ttpcmn/ttpcmn.v16.vcxproj	2020-02-17 15:27:46 UTC (rev 8544)
@@ -136,6 +136,7 @@
     <ClCompile Include="comportinfo.cpp" />
     <ClCompile Include="language.c" />
     <ClCompile Include="ttcmn.c" />
+    <ClCompile Include="ttcmn_notify.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\common\compat_win.h" />

Modified: trunk/teraterm/ttpcmn/ttpcmn.v16.vcxproj.filters
===================================================================
--- trunk/teraterm/ttpcmn/ttpcmn.v16.vcxproj.filters	2020-02-17 15:27:34 UTC (rev 8543)
+++ trunk/teraterm/ttpcmn/ttpcmn.v16.vcxproj.filters	2020-02-17 15:27:46 UTC (rev 8544)
@@ -34,6 +34,9 @@
     <ClCompile Include="comportinfo.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="ttcmn_notify.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\common\i18n.h">

Modified: trunk/teraterm/ttpcmn/ttpcmn.vcproj
===================================================================
--- trunk/teraterm/ttpcmn/ttpcmn.vcproj	2020-02-17 15:27:34 UTC (rev 8543)
+++ trunk/teraterm/ttpcmn/ttpcmn.vcproj	2020-02-17 15:27:46 UTC (rev 8544)
@@ -223,6 +223,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\ttcmn_notify.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\common\ttlib.c"
 				>
 			</File>

Modified: trunk/ttssh2/ttxssh/ssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ssh.c	2020-02-17 15:27:34 UTC (rev 8543)
+++ trunk/ttssh2/ttxssh/ssh.c	2020-02-17 15:27:46 UTC (rev 8544)
@@ -7794,10 +7794,10 @@
 			}
 			break;
 		case 3:
-			msgA = ToCharU8(msg);
-			if (msgA) {
-				NotifyInfoMessage(pvar->cv, msgA, "Authentication Banner");
-				free(msgA);
+			msgW = ToWcharU8(msg);
+			if (msgW) {
+				NotifyInfoMessageW(pvar->cv, msgW, L"Authentication Banner");
+				free(msgW);
 			}
 			break;
 		}


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