Revision: 7320 http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7320 Author: zmatsuo Date: 2018-12-11 00:01:58 +0900 (Tue, 11 Dec 2018) Log Message: ----------- 通知をunicode対応 Modified Paths: -------------- branches/cmake/teraterm/common/ttcommon.h branches/cmake/teraterm/common/tttypes.h branches/cmake/teraterm/teraterm/CMakeLists.txt branches/cmake/teraterm/teraterm/commlib.c branches/cmake/teraterm/teraterm/vtterm.c branches/cmake/teraterm/ttpcmn/CMakeLists.txt branches/cmake/teraterm/ttpcmn/ttcmn.c Added Paths: ----------- branches/cmake/teraterm/ttpcmn/ttcmn_notify.c -------------- next part -------------- Modified: branches/cmake/teraterm/common/ttcommon.h =================================================================== --- branches/cmake/teraterm/common/ttcommon.h 2018-12-10 15:01:44 UTC (rev 7319) +++ branches/cmake/teraterm/common/ttcommon.h 2018-12-10 15:01:58 UTC (rev 7320) @@ -95,7 +95,7 @@ DllExport void WINAPI CreateNotifyIcon(PComVar cv); DllExport void WINAPI DeleteNotifyIcon(PComVar cv); -DllExport void WINAPI NotifyMessage(PComVar cv, PCHAR message, PCHAR title, DWORD flag); +DllExport void WINAPI NotifyMessage(PComVar cv, const TCHAR *message, const TCHAR *title, DWORD flag); DllExport void WINAPI ShowNotifyIcon(PComVar cv); DllExport void WINAPI HideNotifyIcon(PComVar cv); DllExport void WINAPI SetVerNotifyIcon(PComVar cv, unsigned int ver); Modified: branches/cmake/teraterm/common/tttypes.h =================================================================== --- branches/cmake/teraterm/common/tttypes.h 2018-12-10 15:01:44 UTC (rev 7319) +++ branches/cmake/teraterm/common/tttypes.h 2018-12-10 15:01:58 UTC (rev 7320) @@ -1087,7 +1087,7 @@ _locale_t locale; BOOL VirtualStoreEnabled; - NOTIFYICONDATA *NotifyIcon; + void *CmnNotifyData; DWORD ConnectedTime; } TComVar; Modified: branches/cmake/teraterm/teraterm/CMakeLists.txt =================================================================== --- branches/cmake/teraterm/teraterm/CMakeLists.txt 2018-12-10 15:01:44 UTC (rev 7319) +++ branches/cmake/teraterm/teraterm/CMakeLists.txt 2018-12-10 15:01:58 UTC (rev 7320) @@ -45,6 +45,8 @@ ../common/i18n.h ../common/win16api.h ../common/win16api.c + ../common/codeconv.h + ../common/codeconv.cpp ) source_group( Modified: branches/cmake/teraterm/teraterm/commlib.c =================================================================== --- branches/cmake/teraterm/teraterm/commlib.c 2018-12-10 15:01:44 UTC (rev 7319) +++ branches/cmake/teraterm/teraterm/commlib.c 2018-12-10 15:01:58 UTC (rev 7320) @@ -154,7 +154,7 @@ cv->isSSH = 0; cv->TitleRemote[0] = '\0'; - cv->NotifyIcon = NULL; + cv->CmnNotifyData = NULL; cv->ConnectedTime = 0; } Modified: branches/cmake/teraterm/teraterm/vtterm.c =================================================================== --- branches/cmake/teraterm/teraterm/vtterm.c 2018-12-10 15:01:44 UTC (rev 7319) +++ branches/cmake/teraterm/teraterm/vtterm.c 2018-12-10 15:01:58 UTC (rev 7320) @@ -37,6 +37,7 @@ #include <locale.h> #include <ctype.h> #include <crtdbg.h> +#include <tchar.h> #include "buffer.h" #include "ttwinman.h" @@ -51,6 +52,7 @@ #include "telnet.h" #include "ttime.h" #include "clipboar.h" +#include "codeconv.h" #include "vtterm.h" @@ -4736,7 +4738,8 @@ void XsProcClipboard(PCHAR buff) { int len, blen; - char *p, *cbbuff, hdr[20], notify_buff[256], notify_title[MAX_UIMSG]; + char *p, *cbbuff, hdr[20]; + TCHAR notify_buff[256], notify_title[MAX_UIMSG]; HGLOBAL cbmem; int wide_len; HGLOBAL wide_cbmem; @@ -4751,10 +4754,10 @@ if (*p == '?' && *(p+1) == 0) { // Read access if (ts.CtrlFlag & CSF_CBREAD) { if (ts.NotifyClipboardAccess) { - get_lang_msg("MSG_CBACCESS_TITLE", notify_title, sizeof(notify_title), - "Clipboard Access", ts.UILanguageFile); - get_lang_msg("MSG_CBACCESS_READ", notify_buff, sizeof(notify_buff), - "Remote host reads clipboard contents.", ts.UILanguageFile); + get_lang_msgT("MSG_CBACCESS_TITLE", notify_title, sizeof(notify_title), + _T("Clipboard Access"), ts.UILanguageFile); + get_lang_msgT("MSG_CBACCESS_READ", notify_buff, sizeof(notify_buff), + _T("Remote host reads clipboard contents."), ts.UILanguageFile); NotifyInfoMessage(&cv, notify_buff, notify_title); } strncpy_s(hdr, sizeof(hdr), "\033]52;", _TRUNCATE); @@ -4763,10 +4766,10 @@ } } else if (ts.NotifyClipboardAccess) { - get_lang_msg("MSG_CBACCESS_REJECT_TITLE", notify_title, sizeof(notify_title), - "Rejected Clipboard Access", ts.UILanguageFile); - get_lang_msg("MSG_CBACCESS_READ_REJECT", notify_buff, sizeof(notify_buff), - "Reject clipboard read access from remote.", ts.UILanguageFile); + get_lang_msgT("MSG_CBACCESS_REJECT_TITLE", notify_title, sizeof(notify_title), + _T("Rejected Clipboard Access"), ts.UILanguageFile); + get_lang_msgT("MSG_CBACCESS_READ_REJECT", notify_buff, sizeof(notify_buff), + _T("Reject clipboard read access from remote."), ts.UILanguageFile); NotifyWarnMessage(&cv, notify_buff, notify_title); } } @@ -4794,11 +4797,15 @@ GlobalUnlock(cbmem); if (ts.NotifyClipboardAccess) { - get_lang_msg("MSG_CBACCESS_TITLE", notify_title, sizeof(notify_title), - "Clipboard Access", ts.UILanguageFile); - get_lang_msg("MSG_CBACCESS_WRITE", ts.UIMsg, sizeof(ts.UIMsg), - "Remote host wirtes clipboard.", ts.UILanguageFile); - _snprintf_s(notify_buff, sizeof(notify_buff), _TRUNCATE, "%s\n--\n%s", ts.UIMsg, cbbuff); + TCHAR buff[256]; + const TCHAR *cbbuffT; + get_lang_msgT("MSG_CBACCESS_TITLE", notify_title, sizeof(notify_title), + _T("Clipboard Access"), ts.UILanguageFile); + get_lang_msgT("MSG_CBACCESS_WRITE", buff, sizeof(buff), + _T("Remote host wirtes clipboard."), ts.UILanguageFile); + cbbuffT = ToTcharA(cbbuff); + _sntprintf_s(notify_buff, sizeof(notify_buff), _TRUNCATE, _T("%s\n--\n%s"), buff, cbbuffT); + free((void *)cbbuffT); NotifyInfoMessage(&cv, notify_buff, notify_title); } @@ -4820,10 +4827,10 @@ } } else if (ts.NotifyClipboardAccess) { - get_lang_msg("MSG_CBACCESS_REJECT_TITLE", notify_title, sizeof(notify_title), - "Rejected Clipboard Access", ts.UILanguageFile); - get_lang_msg("MSG_CBACCESS_WRITE_REJECT", notify_buff, sizeof(notify_buff), - "Reject clipboard write access from remote.", ts.UILanguageFile); + get_lang_msgT("MSG_CBACCESS_REJECT_TITLE", notify_title, sizeof(notify_title), + _T("Rejected Clipboard Access"), ts.UILanguageFile); + get_lang_msgT("MSG_CBACCESS_WRITE_REJECT", notify_buff, sizeof(notify_buff), + _T("Reject clipboard write access from remote."), ts.UILanguageFile); NotifyWarnMessage(&cv, notify_buff, notify_title); } } Modified: branches/cmake/teraterm/ttpcmn/CMakeLists.txt =================================================================== --- branches/cmake/teraterm/ttpcmn/CMakeLists.txt 2018-12-10 15:01:44 UTC (rev 7319) +++ branches/cmake/teraterm/ttpcmn/CMakeLists.txt 2018-12-10 15:01:58 UTC (rev 7320) @@ -30,6 +30,8 @@ ../common/ttftypes.h ../common/ttcommon.h ../common/tt_res.h + ../common/codeconv.h + ../common/codeconv.cpp ) source_group( @@ -43,6 +45,7 @@ language.c language.h ttcmn.c + ttcmn_notify.c ttpcmn-version.rc ${COMMON_SRC} ) Modified: branches/cmake/teraterm/ttpcmn/ttcmn.c =================================================================== --- branches/cmake/teraterm/ttpcmn/ttcmn.c 2018-12-10 15:01:44 UTC (rev 7319) +++ branches/cmake/teraterm/ttpcmn/ttcmn.c 2018-12-10 15:01:58 UTC (rev 7320) @@ -55,6 +55,7 @@ #include "compat_w95.h" #include "tt_res.h" #include "ttcommon.h" +#include "codeconv.h" // TMap \x82\xF0\x8Ai\x94[\x82\xB7\x82\xE9\x83t\x83@\x83C\x83\x8B\x83}\x83b\x83s\x83\x93\x83O\x83I\x83u\x83W\x83F\x83N\x83g(\x8B\xA4\x97L\x83\x81\x83\x82\x83\x8A)\x82̖\xBC\x91O // TMap(\x82Ƃ\xBB\x82̃\x81\x83\x93\x83o)\x82̍X\x90V\x8E\x9E\x82͋\x8C\x83o\x81[\x83W\x83\x87\x83\x93\x82Ƃ̓\xAF\x8E\x9E\x8BN\x93\xAE\x82ׂ̈ɕς\xA6\x82\xE9\x95K\x97v\x82\xAA\x82\xA0\x82邪 @@ -2422,142 +2423,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() -{ - 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 = ¬ify_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: branches/cmake/teraterm/ttpcmn/ttcmn_notify.c =================================================================== --- branches/cmake/teraterm/ttpcmn/ttcmn_notify.c (rev 0) +++ branches/cmake/teraterm/ttpcmn/ttcmn_notify.c 2018-12-10 15:01:58 UTC (rev 7320) @@ -0,0 +1,206 @@ +/* + * Copyright (C) 1994-1998 T. Teranishi + * (C) 2004-2017 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. + */ + +//#ifndef _WIN32_IE +//#define _WIN32_IE 0x501 +//#endif +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0500 // 2000 +//#define _WIN32_WINNT 0x0501 // XP +#define _WIN32_IE _WIN32_WINNT + +/* TTCMN.DLL, main */ +#include <string.h> +#include <windows.h> +#include <tchar.h> + +#include "teraterm.h" +#include "tttypes.h" +#include "ttftypes.h" +#include "ttcommon.h" + +// Notify Icon 関連 +static HICON CustomIcon = NULL; + +typedef struct { + NOTIFYICONDATA notify_icon; + int NotifyIconShowCount; +// HICON CustomIcon; +} CommonNotifyData; + +static CommonNotifyData *GetNotifyData(PComVar cv) +{ + CommonNotifyData *p = cv->CmnNotifyData; + return p; +} + +void WINAPI SetCustomNotifyIcon(HICON icon) +{ + CustomIcon = icon; +} + +HICON WINAPI GetCustomNotifyIcon() +{ + return CustomIcon; +} + +void WINAPI CreateNotifyIcon(PComVar cv) +{ + if (cv->CmnNotifyData != NULL) { + return; + } else { +#if 0 + CommonNotifyData *CmnNotifyData = malloc(sizeof(CommonNotifyData)); +#else + static CommonNotifyData CmnNotifyDataPool; + CommonNotifyData *CmnNotifyData = &CmnNotifyDataPool; +#endif + NOTIFYICONDATA *notify_icon; + memset(CmnNotifyData, 0, sizeof(CmnNotifyData)); + cv->CmnNotifyData = CmnNotifyData; + + notify_icon = &CmnNotifyData->notify_icon; + 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; + + Shell_NotifyIcon(NIM_ADD, notify_icon); + + CmnNotifyData->NotifyIconShowCount = 0; + } +} + +void WINAPI DeleteNotifyIcon(PComVar cv) +{ + CommonNotifyData *CmnNotifyData = GetNotifyData(cv); + NOTIFYICONDATA *NotifyIcon = &CmnNotifyData->notify_icon; + if (NotifyIcon) { + Shell_NotifyIcon(NIM_DELETE, NotifyIcon); + CmnNotifyData->NotifyIconShowCount = 0; + } +} + +void WINAPI ShowNotifyIcon(PComVar cv) +{ + CommonNotifyData *CmnNotifyData = GetNotifyData(cv); + NOTIFYICONDATA *NotifyIcon; + if (CmnNotifyData == NULL) { + CreateNotifyIcon(cv); + CmnNotifyData = GetNotifyData(cv); + } + + NotifyIcon = &CmnNotifyData->notify_icon; + NotifyIcon->uFlags = NIF_STATE; + NotifyIcon->dwState = 0; + NotifyIcon->dwStateMask = NIS_HIDDEN; + Shell_NotifyIcon(NIM_MODIFY, NotifyIcon); + CmnNotifyData->NotifyIconShowCount += 1; +} + +void WINAPI HideNotifyIcon(PComVar cv) +{ + CommonNotifyData *CmnNotifyData = GetNotifyData(cv); + if (CmnNotifyData->NotifyIconShowCount > 1) { + CmnNotifyData->NotifyIconShowCount -= 1; + } + else { + NOTIFYICONDATA *NotifyIcon = &CmnNotifyData->notify_icon; + if (NotifyIcon) { + NotifyIcon->uFlags = NIF_STATE; + NotifyIcon->dwState = NIS_HIDDEN; + NotifyIcon->dwStateMask = NIS_HIDDEN; + Shell_NotifyIcon(NIM_MODIFY, NotifyIcon); + } + CmnNotifyData->NotifyIconShowCount = 0; + } +} + +void WINAPI SetVerNotifyIcon(PComVar cv, unsigned int ver) +{ + CommonNotifyData *CmnNotifyData = GetNotifyData(cv); + NOTIFYICONDATA *NotifyIcon = &CmnNotifyData->notify_icon; + if (NotifyIcon) { + NotifyIcon->uVersion = ver; + Shell_NotifyIcon(NIM_SETVERSION, NotifyIcon); + } +} + +void WINAPI NotifyMessage(PComVar cv, const TCHAR *msg, const TCHAR *title, DWORD flag) +{ + CommonNotifyData *CmnNotifyData; + NOTIFYICONDATA *NotifyIcon; + if (msg == NULL) { + return; + } + + if (! HasBalloonTipSupport()) { + return; + } + + CmnNotifyData = GetNotifyData(cv); + if (CmnNotifyData == NULL) { + CreateNotifyIcon(cv); + CmnNotifyData = GetNotifyData(cv); + } + + NotifyIcon = &CmnNotifyData->notify_icon; + NotifyIcon->uFlags = NIF_INFO | NIF_STATE; + NotifyIcon->dwState = 0; + NotifyIcon->dwStateMask = NIS_HIDDEN; + + if (title) { + NotifyIcon->dwInfoFlags = flag; + _tcsncpy_s(NotifyIcon->szInfoTitle, _countof(NotifyIcon->szInfoTitle), title, _TRUNCATE); + } + else { + NotifyIcon->dwInfoFlags = NIIF_NONE; + NotifyIcon->szInfoTitle[0] = 0; + } + + _tcsncpy_s(NotifyIcon->szInfo, _countof(NotifyIcon->szInfo), msg, _TRUNCATE); + + Shell_NotifyIcon(NIM_MODIFY, NotifyIcon); + + CmnNotifyData->NotifyIconShowCount += 1; +}