| 1 |
/* |
| 2 |
* Copyright (C) 1994-1998 T. Teranishi |
| 3 |
* (C) 2005- TeraTerm Project |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
| 7 |
* modification, are permitted provided that the following conditions |
| 8 |
* are met: |
| 9 |
* |
| 10 |
* 1. Redistributions of source code must retain the above copyright |
| 11 |
* notice, this list of conditions and the following disclaimer. |
| 12 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
* notice, this list of conditions and the following disclaimer in the |
| 14 |
* documentation and/or other materials provided with the distribution. |
| 15 |
* 3. The name of the author may not be used to endorse or promote products |
| 16 |
* derived from this software without specific prior written permission. |
| 17 |
* |
| 18 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| 19 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 |
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
*/ |
| 29 |
|
| 30 |
/* TERATERM.EXE, variables, flags related to VT win and TEK win */ |
| 31 |
|
| 32 |
#include "teraterm.h" |
| 33 |
#include "tttypes.h" |
| 34 |
#include <stdio.h> |
| 35 |
#include <string.h> |
| 36 |
#include <malloc.h> |
| 37 |
#include "ttlib.h" |
| 38 |
#include "helpid.h" |
| 39 |
#include "i18n.h" |
| 40 |
#include "commlib.h" |
| 41 |
#include "codeconv.h" |
| 42 |
#include "asprintf.h" |
| 43 |
|
| 44 |
HWND HVTWin = NULL; |
| 45 |
HWND HTEKWin = NULL; |
| 46 |
|
| 47 |
int ActiveWin = IdVT; /* IdVT, IdTEK */ |
| 48 |
IdTalk TalkStatus = IdTalkKeyb; /* IdTalkKeyb, IdTalkCB, IdTalkTextFile */ |
| 49 |
BOOL KeybEnabled = TRUE; /* keyboard switch */ |
| 50 |
BOOL Connecting = FALSE; |
| 51 |
|
| 52 |
/* 'help' button on dialog box */ |
| 53 |
WORD MsgDlgHelp; |
| 54 |
|
| 55 |
TTTSet ts; |
| 56 |
TComVar cv; |
| 57 |
|
| 58 |
/* pointers to window objects */ |
| 59 |
void* pTEKWin = NULL; |
| 60 |
/* instance handle */ |
| 61 |
HINSTANCE hInst; |
| 62 |
|
| 63 |
int SerialNo; |
| 64 |
|
| 65 |
void VTActivate() |
| 66 |
{ |
| 67 |
ActiveWin = IdVT; |
| 68 |
ShowWindow(HVTWin, SW_SHOWNORMAL); |
| 69 |
SetFocus(HVTWin); |
| 70 |
} |
| 71 |
|
| 72 |
// �L���v�V���������X |
| 73 |
// |
| 74 |
// (2005.2.19 yutaka) format ID=13���V�K�����ACOM5�������\�������� |
| 75 |
// (2005.3.13 yutaka) �^�C�g����SJIS���������i���{���j������ |
| 76 |
// (2006.6.15 maya) ts.KanjiCode��EUC�����ASJIS����EUC������ |
| 77 |
// �������������������A������������������ |
| 78 |
// (2007.7.19 maya) TCP �|�[�g���� �� �V���A���|�[�g���{�[���[�g���\�������� |
| 79 |
/* |
| 80 |
* TitleFormat |
| 81 |
* 0 0 0 0 0 0 (2) |
| 82 |
* | | | | | +----- displays TCP host/serial port |
| 83 |
* | | | | +------- displays session no |
| 84 |
* | | | +--------- displays VT/TEK |
| 85 |
* | | +----------- displays TCP host/serial port first |
| 86 |
* | +------------- displays TCP port number |
| 87 |
* +--------------- displays speed of serial port |
| 88 |
*/ |
| 89 |
void ChangeTitle(void) |
| 90 |
{ |
| 91 |
#define HostNameMaxLength 1024 // �z�X�g�������� TODO �������������� or ������������������ |
| 92 |
wchar_t TempTitle[HostNameMaxLength + TitleBuffSize * 2 + 1]; // �o�b�t�@�g�� |
| 93 |
wchar_t TempTitleWithRemote[TitleBuffSize * 2]; |
| 94 |
|
| 95 |
{ |
| 96 |
wchar_t *title = ToWcharA(ts.Title); |
| 97 |
const wchar_t *title_remote = cv.TitleRemoteW; |
| 98 |
if (Connecting || !cv.Ready || title_remote == NULL || title_remote[0] == 0) { |
| 99 |
// �����[�g�^�C�g�����g�p������ or ���������������� |
| 100 |
wcsncpy_s(TempTitleWithRemote, _countof(TempTitleWithRemote), title, _TRUNCATE); |
| 101 |
wcsncpy_s(TempTitle, _countof(TempTitle), title, _TRUNCATE); |
| 102 |
} |
| 103 |
else { |
| 104 |
// �����[�g�������^�C�g������������ (2008.11.1 maya) |
| 105 |
if (ts.AcceptTitleChangeRequest == IdTitleChangeRequestOff) { |
| 106 |
wcsncpy_s(TempTitleWithRemote, _countof(TempTitleWithRemote), title, _TRUNCATE); |
| 107 |
} |
| 108 |
else if (ts.AcceptTitleChangeRequest == IdTitleChangeRequestAhead) { |
| 109 |
_snwprintf_s(TempTitleWithRemote, _countof(TempTitleWithRemote), _TRUNCATE, |
| 110 |
L"%s %s", title_remote, title); |
| 111 |
} |
| 112 |
else if (ts.AcceptTitleChangeRequest == IdTitleChangeRequestLast) { |
| 113 |
_snwprintf_s(TempTitleWithRemote, _countof(TempTitleWithRemote), _TRUNCATE, |
| 114 |
L"%s %s", title, title_remote); |
| 115 |
} |
| 116 |
else { |
| 117 |
wcsncpy_s(TempTitleWithRemote, _countof(TempTitleWithRemote), title_remote, _TRUNCATE); |
| 118 |
} |
| 119 |
wcsncpy_s(TempTitle, _countof(TempTitle), TempTitleWithRemote, _TRUNCATE); |
| 120 |
} |
| 121 |
free(title); |
| 122 |
} |
| 123 |
|
| 124 |
if ((ts.TitleFormat & 1)!=0) |
| 125 |
{ // host name |
| 126 |
wchar_t *UIMsg; |
| 127 |
wcsncat_s(TempTitle,_countof(TempTitle), L" - ",_TRUNCATE); |
| 128 |
if (Connecting) { |
| 129 |
GetI18nStrWW("Tera Term", "DLG_MAIN_TITLE_CONNECTING", L"[connecting...]", ts.UILanguageFileW, &UIMsg); |
| 130 |
wcsncat_s(TempTitle,_countof(TempTitle), UIMsg,_TRUNCATE); |
| 131 |
free(UIMsg); |
| 132 |
} |
| 133 |
else if (! cv.Ready) { |
| 134 |
GetI18nStrWW("Tera Term", "DLG_MAIN_TITLE_DISCONNECTED", L"[disconnected]", ts.UILanguageFileW, &UIMsg); |
| 135 |
wcsncat_s(TempTitle,_countof(TempTitle), UIMsg,_TRUNCATE); |
| 136 |
free(UIMsg); |
| 137 |
} |
| 138 |
else if (cv.PortType==IdSerial) |
| 139 |
{ |
| 140 |
// COM5 over������ |
| 141 |
wchar_t str[24]; // COMxxxx:xxxxxxxxxxbps |
| 142 |
if (ts.TitleFormat & 32) { |
| 143 |
_snwprintf_s(str, _countof(str), _TRUNCATE, L"COM%d:%ubps", ts.ComPort, ts.Baud); |
| 144 |
} |
| 145 |
else { |
| 146 |
_snwprintf_s(str, _countof(str), _TRUNCATE, L"COM%d", ts.ComPort); |
| 147 |
} |
| 148 |
|
| 149 |
if (ts.TitleFormat & 8) { |
| 150 |
_snwprintf_s(TempTitle, _countof(TempTitle), _TRUNCATE, L"%s - %s", str, TempTitleWithRemote); |
| 151 |
} else { |
| 152 |
wcsncat_s(TempTitle, _countof(TempTitle), str, _TRUNCATE); |
| 153 |
} |
| 154 |
} |
| 155 |
else if (cv.PortType == IdNamedPipe) |
| 156 |
{ |
| 157 |
wchar_t str[_countof(TempTitle)]; |
| 158 |
wchar_t *host_name = ToWcharA(ts.HostName); |
| 159 |
wcsncpy_s(str, _countof(str), host_name, _TRUNCATE); |
| 160 |
free(host_name); |
| 161 |
|
| 162 |
if (ts.TitleFormat & 8) { |
| 163 |
// format ID = 13(8 + 5): <hots/port> - <title> |
| 164 |
_snwprintf_s(TempTitle, _countof(TempTitle), _TRUNCATE, L"%s - %s", str, TempTitleWithRemote); |
| 165 |
} |
| 166 |
else { |
| 167 |
wcsncat_s(TempTitle, _countof(TempTitle), str, _TRUNCATE); |
| 168 |
} |
| 169 |
} |
| 170 |
else { |
| 171 |
wchar_t str[_countof(TempTitle)]; |
| 172 |
wchar_t *host_name = ToWcharA(ts.HostName); |
| 173 |
if (ts.TitleFormat & 16) { |
| 174 |
_snwprintf_s(str, _countof(str), _TRUNCATE, L"%s:%d", host_name, ts.TCPPort); |
| 175 |
} |
| 176 |
else { |
| 177 |
wcsncpy_s(str, _countof(str), host_name, _TRUNCATE); |
| 178 |
} |
| 179 |
free(host_name); |
| 180 |
|
| 181 |
if (ts.TitleFormat & 8) { |
| 182 |
// format ID = 13(8 + 5): <hots/port> - <title> |
| 183 |
_snwprintf_s(TempTitle, _countof(TempTitle), _TRUNCATE, L"%s - %s", str, TempTitleWithRemote); |
| 184 |
} |
| 185 |
else { |
| 186 |
wcsncat_s(TempTitle, _countof(TempTitle), str, _TRUNCATE); |
| 187 |
} |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
if ((ts.TitleFormat & 2)!=0) |
| 192 |
{ // serial no. |
| 193 |
wchar_t Num[11]; |
| 194 |
wcsncat_s(TempTitle,_countof(TempTitle),L" (",_TRUNCATE); |
| 195 |
_snwprintf_s(Num,_countof(Num),_TRUNCATE,L"%u",SerialNo); |
| 196 |
wcsncat_s(TempTitle,_countof(TempTitle),Num,_TRUNCATE); |
| 197 |
wcsncat_s(TempTitle,_countof(TempTitle),L")",_TRUNCATE); |
| 198 |
} |
| 199 |
|
| 200 |
if ((ts.TitleFormat & 4)!=0) // VT |
| 201 |
wcsncat_s(TempTitle,_countof(TempTitle),L" VT",_TRUNCATE); |
| 202 |
|
| 203 |
SetWindowTextW(HVTWin,TempTitle); |
| 204 |
|
| 205 |
if (HTEKWin!=0) |
| 206 |
{ |
| 207 |
if ((ts.TitleFormat & 4)!=0) // TEK |
| 208 |
{ |
| 209 |
wcsncat_s(TempTitle,_countof(TempTitle),L" TEK",_TRUNCATE); |
| 210 |
} |
| 211 |
SetWindowTextW(HTEKWin,TempTitle); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
void SwitchMenu() |
| 216 |
{ |
| 217 |
HWND H1, H2; |
| 218 |
|
| 219 |
if (ActiveWin==IdVT) |
| 220 |
{ |
| 221 |
H1 = HTEKWin; |
| 222 |
H2 = HVTWin; |
| 223 |
} |
| 224 |
else { |
| 225 |
H1 = HVTWin; |
| 226 |
H2 = HTEKWin; |
| 227 |
} |
| 228 |
|
| 229 |
if (H1!=0) |
| 230 |
PostMessage(H1,WM_USER_CHANGEMENU,0,0); |
| 231 |
if (H2!=0) |
| 232 |
PostMessage(H2,WM_USER_CHANGEMENU,0,0); |
| 233 |
} |
| 234 |
|
| 235 |
void SwitchTitleBar() |
| 236 |
{ |
| 237 |
HWND H1, H2; |
| 238 |
|
| 239 |
if (ActiveWin==IdVT) |
| 240 |
{ |
| 241 |
H1 = HTEKWin; |
| 242 |
H2 = HVTWin; |
| 243 |
} |
| 244 |
else { |
| 245 |
H1 = HVTWin; |
| 246 |
H2 = HTEKWin; |
| 247 |
} |
| 248 |
|
| 249 |
if (H1!=0) |
| 250 |
PostMessage(H1,WM_USER_CHANGETBAR,0,0); |
| 251 |
if (H2!=0) |
| 252 |
PostMessage(H2,WM_USER_CHANGETBAR,0,0); |
| 253 |
} |
| 254 |
|
| 255 |
HMODULE LoadHomeDLL(const wchar_t *DLLname) |
| 256 |
{ |
| 257 |
HMODULE handle; |
| 258 |
wchar_t *DLLpath; |
| 259 |
aswprintf(&DLLpath, L"%s\\%s", ts.ExeDirW, DLLname); |
| 260 |
handle = LoadLibraryW(DLLpath); |
| 261 |
free(DLLpath); |
| 262 |
return handle; |
| 263 |
} |