Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Diff of /trunk/teraterm/teraterm/ttwinman.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3226 by maya, Tue Mar 24 09:37:20 2009 UTC revision 3227 by maya, Tue Mar 24 15:10:33 2009 UTC
# Line 1  Line 1 
1  /* Tera Term  /* Tera Term
2   Copyright(C) 1994-1998 T. Teranishi   Copyright(C) 1994-1998 T. Teranishi
3   All rights reserved. */   All rights reserved. */
4    
5  /* TERATERM.EXE, variables, flags related to VT win and TEK win */  /* TERATERM.EXE, variables, flags related to VT win and TEK win */
6    
7  #include "teraterm.h"  #include "teraterm.h"
8  #include "tttypes.h"  #include "tttypes.h"
9  #include <stdio.h>  #include <stdio.h>
10  #include <string.h>  #include <string.h>
11  #include <malloc.h>  #include <malloc.h>
12  #include "ttlib.h"  #include "ttlib.h"
13  #include "helpid.h"  #include "helpid.h"
14  #include "htmlhelp.h"  #include "htmlhelp.h"
15  #include "i18n.h"  #include "i18n.h"
16  #include "commlib.h"  #include "commlib.h"
17    
18  /* help file names */  /* help file names */
19  #define HTML_HELP "teraterm.chm"  #define HTML_HELP "teraterm.chm"
20    
21  HWND HVTWin = NULL;  HWND HVTWin = NULL;
22  HWND HTEKWin = NULL;  HWND HTEKWin = NULL;
23        
24  int ActiveWin = IdVT; /* IdVT, IdTEK */  int ActiveWin = IdVT; /* IdVT, IdTEK */
25  int TalkStatus = IdTalkKeyb; /* IdTalkKeyb, IdTalkCB, IdTalkTextFile */  int TalkStatus = IdTalkKeyb; /* IdTalkKeyb, IdTalkCB, IdTalkTextFile */
26  BOOL KeybEnabled = TRUE; /* keyboard switch */  BOOL KeybEnabled = TRUE; /* keyboard switch */
27  BOOL Connecting = FALSE;  BOOL Connecting = FALSE;
28    
29  /* 'help' button on dialog box */  /* 'help' button on dialog box */
30  WORD MsgDlgHelp;  WORD MsgDlgHelp;
31  LONG HelpId;  LONG HelpId;
32    
33  TTTSet ts;  TTTSet ts;
34  TComVar cv;  TComVar cv;
35    
36  /* pointers to window objects */  /* pointers to window objects */
37  void* pVTWin = NULL;  void* pVTWin = NULL;
38  void* pTEKWin = NULL;  void* pTEKWin = NULL;
39  /* instance handle */  /* instance handle */
40  HINSTANCE hInst;  HINSTANCE hInst;
41    
42  int SerialNo;  int SerialNo;
43    
44  void VTActivate()  void VTActivate()
45  {  {
46    ActiveWin = IdVT;    ActiveWin = IdVT;
47    ShowWindow(HVTWin, SW_SHOWNORMAL);    ShowWindow(HVTWin, SW_SHOWNORMAL);
48    SetFocus(HVTWin);    SetFocus(HVTWin);
49  }  }
50    
51    
52  // タイトルバーのCP932への変換を行う  // タイトルバーのCP932への変換を行う
53  // 現在、SJIS、EUCのみに対応。  // 現在、SJIS、EUCのみに対応。
54  // (2005.3.13 yutaka)  // (2005.3.13 yutaka)
55  void ConvertToCP932(char *str, int destlen)  void ConvertToCP932(char *str, int destlen)
56  {  {
57  #define IS_SJIS(n) (ts.KanjiCode == IdSJIS && IsDBCSLeadByte(n))  #define IS_SJIS(n) (ts.KanjiCode == IdSJIS && IsDBCSLeadByte(n))
58  #define IS_EUC(n) (ts.KanjiCode == IdEUC && (n & 0x80))  #define IS_EUC(n) (ts.KanjiCode == IdEUC && (n & 0x80))
59          extern WORD FAR PASCAL JIS2SJIS(WORD KCode);          extern WORD FAR PASCAL JIS2SJIS(WORD KCode);
60          int len = strlen(str);          int len = strlen(str);
61          char *cc = _alloca(len + 1);          char *cc = _alloca(len + 1);
62          char *c = cc;          char *c = cc;
63          int i;          int i;
64          unsigned char b;          unsigned char b;
65          WORD word;          WORD word;
66    
67          if (strcmp(ts.Locale, DEFAULT_LOCALE) == 0) {          if (strcmp(ts.Locale, DEFAULT_LOCALE) == 0) {
68                  for (i = 0 ; i < len ; i++) {                  for (i = 0 ; i < len ; i++) {
69                          b = str[i];                          b = str[i];
70                          if (IS_SJIS(b) || IS_EUC(b)) {                          if (IS_SJIS(b) || IS_EUC(b)) {
71                                  word = b<<8;                                  word = b<<8;
72    
73                                  if (i == len - 1) {                                  if (i == len - 1) {
74                                          *c++ = b;                                          *c++ = b;
75                                          continue;                                          continue;
76                                  }                                  }
77    
78                                  b = str[i + 1];                                  b = str[i + 1];
79                                  word |= b;                                  word |= b;
80                                  i++;                                  i++;
81    
82                                  if (ts.KanjiCode == IdSJIS) {                                  if (ts.KanjiCode == IdSJIS) {
83                                          // SJISはそのままCP932として出力する                                          // SJISはそのままCP932として出力する
84    
85                                  } else if (ts.KanjiCode == IdEUC) {                                  } else if (ts.KanjiCode == IdEUC) {
86                                          // EUC -> SJIS                                          // EUC -> SJIS
87                                          word &= ~0x8080;                                          word &= ~0x8080;
88                                          word = JIS2SJIS(word);                                          word = JIS2SJIS(word);
89    
90                                  } else if (ts.KanjiCode == IdJIS) {                                  } else if (ts.KanjiCode == IdJIS) {
91    
92                                  } else if (ts.KanjiCode == IdUTF8) {                                  } else if (ts.KanjiCode == IdUTF8) {
93    
94                                  } else if (ts.KanjiCode == IdUTF8m) {                                  } else if (ts.KanjiCode == IdUTF8m) {
95    
96                                  } else {                                  } else {
97    
98                                  }                                  }
99    
100                                  *c++ = word >> 8;                                  *c++ = word >> 8;
101                                  *c++ = word & 0xff;                                  *c++ = word & 0xff;
102    
103                          } else {                          } else {
104                                  *c++ = b;                                  *c++ = b;
105                          }                          }
106                  }                  }
107    
108                  *c = '\0';                  *c = '\0';
109                  strncpy_s(str, destlen, cc, _TRUNCATE);                  strncpy_s(str, destlen, cc, _TRUNCATE);
110          }          }
111  }  }
112    
113  // キャプションの変更  // キャプションの変更
114  //  //
115  // (2005.2.19 yutaka) format ID=13の新規追加、COM5以上の表示に対応  // (2005.2.19 yutaka) format ID=13の新規追加、COM5以上の表示に対応
116  // (2005.3.13 yutaka) タイトルのSJISへの変換(日本語)を追加  // (2005.3.13 yutaka) タイトルのSJISへの変換(日本語)を追加
117  // (2006.6.15 maya)   ts.KanjiCodeがEUCだと、SJISでもEUCとして  // (2006.6.15 maya)   ts.KanjiCodeがEUCだと、SJISでもEUCとして
118  //                    変換してしまうので、ここでは変換しない  //                    変換してしまうので、ここでは変換しない
119  // (2007.7.19 maya)   TCP ポート番号 と シリアルポートのボーレートの表示に対応  // (2007.7.19 maya)   TCP ポート番号 と シリアルポートのボーレートの表示に対応
120  /*  /*
121   *  TitleFormat   *  TitleFormat
122   *    0 0 0 0 0 0 (2)   *    0 0 0 0 0 0 (2)
123   *    | | | | | +----- displays TCP host/serial port   *    | | | | | +----- displays TCP host/serial port
124   *    | | | | +------- displays session no   *    | | | | +------- displays session no
125   *    | | | +--------- displays VT/TEK   *    | | | +--------- displays VT/TEK
126   *    | | +----------- displays TCP host/serial port first   *    | | +----------- displays TCP host/serial port first
127   *    | +------------- displays TCP port number   *    | +------------- displays TCP port number
128   *    +--------------- displays baud rate of serial port   *    +--------------- displays baud rate of serial port
129   */   */
130  void ChangeTitle()  void ChangeTitle()
131  {  {
132          char TempTitle[HostNameMaxLength + TitleBuffSize * 2 + 1]; // バッファ拡張          char TempTitle[HostNameMaxLength + TitleBuffSize * 2 + 1]; // バッファ拡張
133          char TempTitleWithRemote[TitleBuffSize * 2];          char TempTitleWithRemote[TitleBuffSize * 2];
134    
135          if (Connecting || !cv.Ready || strlen(cv.TitleRemote) == 0) {          if (Connecting || !cv.Ready || strlen(cv.TitleRemote) == 0) {
136                  strncpy_s(TempTitleWithRemote, sizeof(TempTitleWithRemote), ts.Title, _TRUNCATE);                  strncpy_s(TempTitleWithRemote, sizeof(TempTitleWithRemote), ts.Title, _TRUNCATE);
137                  strncpy_s(TempTitle, sizeof(TempTitle), ts.Title, _TRUNCATE);                  strncpy_s(TempTitle, sizeof(TempTitle), ts.Title, _TRUNCATE);
138          }          }
139          else {          else {
140                  // リモートからのタイトルを別に扱う (2008.11.1 maya)                  // リモートからのタイトルを別に扱う (2008.11.1 maya)
141                  if (ts.AcceptTitleChangeRequest == IdTitleChangeRequestOff) {                  if (ts.AcceptTitleChangeRequest == IdTitleChangeRequestOff) {
142                          strncpy_s(TempTitleWithRemote, sizeof(TempTitleWithRemote), ts.Title, _TRUNCATE);                          strncpy_s(TempTitleWithRemote, sizeof(TempTitleWithRemote), ts.Title, _TRUNCATE);
143                  }                  }
144                  else if (ts.AcceptTitleChangeRequest == IdTitleChangeRequestAhead) {                  else if (ts.AcceptTitleChangeRequest == IdTitleChangeRequestAhead) {
145                          _snprintf_s(TempTitleWithRemote, sizeof(TempTitleWithRemote), _TRUNCATE,                          _snprintf_s(TempTitleWithRemote, sizeof(TempTitleWithRemote), _TRUNCATE,
146                                      "%s %s", cv.TitleRemote, ts.Title);                                      "%s %s", cv.TitleRemote, ts.Title);
147                  }                  }
148                  else if (ts.AcceptTitleChangeRequest == IdTitleChangeRequestLast) {                  else if (ts.AcceptTitleChangeRequest == IdTitleChangeRequestLast) {
149                          _snprintf_s(TempTitleWithRemote, sizeof(TempTitleWithRemote), _TRUNCATE,                          _snprintf_s(TempTitleWithRemote, sizeof(TempTitleWithRemote), _TRUNCATE,
150                                      "%s %s", ts.Title, cv.TitleRemote);                                      "%s %s", ts.Title, cv.TitleRemote);
151                  }                  }
152                  else {                  else {
153                          strncpy_s(TempTitleWithRemote, sizeof(TempTitleWithRemote), cv.TitleRemote, _TRUNCATE);                          strncpy_s(TempTitleWithRemote, sizeof(TempTitleWithRemote), cv.TitleRemote, _TRUNCATE);
154                  }                  }
155                  strncpy_s(TempTitle, sizeof(TempTitle), TempTitleWithRemote, _TRUNCATE);                  strncpy_s(TempTitle, sizeof(TempTitle), TempTitleWithRemote, _TRUNCATE);
156          }          }
157    
158          if ((ts.TitleFormat & 1)!=0)          if ((ts.TitleFormat & 1)!=0)
159          { // host name          { // host name
160                  strncat_s(TempTitle,sizeof(TempTitle), " - ",_TRUNCATE);                  strncat_s(TempTitle,sizeof(TempTitle), " - ",_TRUNCATE);
161                  if (Connecting) {                  if (Connecting) {
162                          get_lang_msg("DLG_MAIN_TITLE_CONNECTING", ts.UIMsg, sizeof(ts.UIMsg), "[connecting...]", ts.UILanguageFile);                          get_lang_msg("DLG_MAIN_TITLE_CONNECTING", ts.UIMsg, sizeof(ts.UIMsg), "[connecting...]", ts.UILanguageFile);
163                          strncat_s(TempTitle,sizeof(TempTitle),ts.UIMsg,_TRUNCATE);                          strncat_s(TempTitle,sizeof(TempTitle),ts.UIMsg,_TRUNCATE);
164                  }                  }
165                  else if (! cv.Ready) {                  else if (! cv.Ready) {
166                          get_lang_msg("DLG_MAIN_TITLE_DISCONNECTED", ts.UIMsg, sizeof(ts.UIMsg), "[disconnected]", ts.UILanguageFile);                          get_lang_msg("DLG_MAIN_TITLE_DISCONNECTED", ts.UIMsg, sizeof(ts.UIMsg), "[disconnected]", ts.UILanguageFile);
167                          strncat_s(TempTitle,sizeof(TempTitle),ts.UIMsg,_TRUNCATE);                          strncat_s(TempTitle,sizeof(TempTitle),ts.UIMsg,_TRUNCATE);
168                  }                  }
169                  else if (cv.PortType==IdSerial)                  else if (cv.PortType==IdSerial)
170                  {                  {
171                          // COM5 overに対応                          // COM5 overに対応
172                          char str[20]; // COMxx:xxxxxxbaud                          char str[20]; // COMxx:xxxxxxbaud
173                          if (ts.TitleFormat & 32) {                          if (ts.TitleFormat & 32) {
174                                  _snprintf_s(str, sizeof(str), _TRUNCATE, "COM%d:%dbaud", ts.ComPort, GetCommSerialBaudRate(ts.Baud));                                  _snprintf_s(str, sizeof(str), _TRUNCATE, "COM%d:%dbaud", ts.ComPort, GetCommSerialBaudRate(ts.Baud));
175                          }                          }
176                          else {                          else {
177                                  _snprintf_s(str, sizeof(str), _TRUNCATE, "COM%d", ts.ComPort);                                  _snprintf_s(str, sizeof(str), _TRUNCATE, "COM%d", ts.ComPort);
178                          }                          }
179    
180                          if (ts.TitleFormat & 8) {                          if (ts.TitleFormat & 8) {
181                                  _snprintf_s(TempTitle, sizeof(TempTitle), _TRUNCATE, "%s - %s", str, TempTitleWithRemote);                                  _snprintf_s(TempTitle, sizeof(TempTitle), _TRUNCATE, "%s - %s", str, TempTitleWithRemote);
182                          } else {                          } else {
183                                  strncat_s(TempTitle, sizeof(TempTitle), str, _TRUNCATE);                                  strncat_s(TempTitle, sizeof(TempTitle), str, _TRUNCATE);
184                          }                          }
185                  }                  }
186                  else {                  else {
187                          char str[sizeof(TempTitle)];                          char str[sizeof(TempTitle)];
188                          if (ts.TitleFormat & 16) {                          if (ts.TitleFormat & 16) {
189                                  _snprintf_s(str, sizeof(str), _TRUNCATE, "%s:%d", ts.HostName, ts.TCPPort);                                  _snprintf_s(str, sizeof(str), _TRUNCATE, "%s:%d", ts.HostName, ts.TCPPort);
190                          }                          }
191                          else {                          else {
192                                  strncpy_s(str, sizeof(str), ts.HostName, _TRUNCATE);                                  strncpy_s(str, sizeof(str), ts.HostName, _TRUNCATE);
193                          }                          }
194    
195                          if (ts.TitleFormat & 8) {                          if (ts.TitleFormat & 8) {
196                                  // format ID = 13(8 + 5): <hots/port> - <title>                                  // format ID = 13(8 + 5): <hots/port> - <title>
197                                  _snprintf_s(TempTitle, sizeof(TempTitle), _TRUNCATE, "%s - %s", str, TempTitleWithRemote);                                  _snprintf_s(TempTitle, sizeof(TempTitle), _TRUNCATE, "%s - %s", str, TempTitleWithRemote);
198                          }                          }
199                          else {                          else {
200                                  strncat_s(TempTitle, sizeof(TempTitle), ts.HostName, _TRUNCATE);                                  strncat_s(TempTitle, sizeof(TempTitle), ts.HostName, _TRUNCATE);
201                          }                          }
202                  }                  }
203          }          }
204    
205          if ((ts.TitleFormat & 2)!=0)          if ((ts.TitleFormat & 2)!=0)
206          { // serial no.          { // serial no.
207                  char Num[11];                  char Num[11];
208                  strncat_s(TempTitle,sizeof(TempTitle)," (",_TRUNCATE);                  strncat_s(TempTitle,sizeof(TempTitle)," (",_TRUNCATE);
209                  _snprintf_s(Num,sizeof(Num),_TRUNCATE,"%u",SerialNo);                  _snprintf_s(Num,sizeof(Num),_TRUNCATE,"%u",SerialNo);
210                  strncat_s(TempTitle,sizeof(TempTitle),Num,_TRUNCATE);                  strncat_s(TempTitle,sizeof(TempTitle),Num,_TRUNCATE);
211                  strncat_s(TempTitle,sizeof(TempTitle),")",_TRUNCATE);                  strncat_s(TempTitle,sizeof(TempTitle),")",_TRUNCATE);
212          }          }
213    
214          if ((ts.TitleFormat & 4)!=0) // VT          if ((ts.TitleFormat & 4)!=0) // VT
215                  strncat_s(TempTitle,sizeof(TempTitle)," VT",_TRUNCATE);                  strncat_s(TempTitle,sizeof(TempTitle)," VT",_TRUNCATE);
216    
217          SetWindowText(HVTWin,TempTitle);          SetWindowText(HVTWin,TempTitle);
218    
219          if (HTEKWin!=0)          if (HTEKWin!=0)
220          {          {
221                  if ((ts.TitleFormat & 4)!=0) // TEK                  if ((ts.TitleFormat & 4)!=0) // TEK
222                  {                  {
223                          strncat_s(TempTitle,sizeof(TempTitle)," TEK",_TRUNCATE);                          strncat_s(TempTitle,sizeof(TempTitle)," TEK",_TRUNCATE);
224                  }                  }
225                  SetWindowText(HTEKWin,TempTitle);                  SetWindowText(HTEKWin,TempTitle);
226          }          }
227  }  }
228    
229  void SwitchMenu()  void SwitchMenu()
230  {  {
231    HWND H1, H2;    HWND H1, H2;
232    
233    if (ActiveWin==IdVT)    if (ActiveWin==IdVT)
234    {    {
235      H1 = HTEKWin;      H1 = HTEKWin;
236      H2 = HVTWin;      H2 = HVTWin;
237    }    }
238    else {    else {
239      H1 = HVTWin;      H1 = HVTWin;
240      H2 = HTEKWin;      H2 = HTEKWin;
241    }    }
242    
243    if (H1!=0)    if (H1!=0)
244      PostMessage(H1,WM_USER_CHANGEMENU,0,0);      PostMessage(H1,WM_USER_CHANGEMENU,0,0);
245    if (H2!=0)    if (H2!=0)
246      PostMessage(H2,WM_USER_CHANGEMENU,0,0);      PostMessage(H2,WM_USER_CHANGEMENU,0,0);
247  }  }
248    
249  void SwitchTitleBar()  void SwitchTitleBar()
250  {  {
251    HWND H1, H2;    HWND H1, H2;
252    
253    if (ActiveWin==IdVT)    if (ActiveWin==IdVT)
254    {    {
255      H1 = HTEKWin;      H1 = HTEKWin;
256      H2 = HVTWin;      H2 = HVTWin;
257    }    }
258    else {    else {
259      H1 = HVTWin;      H1 = HVTWin;
260      H2 = HTEKWin;      H2 = HTEKWin;
261    }    }
262    
263    if (H1!=0)    if (H1!=0)
264      PostMessage(H1,WM_USER_CHANGETBAR,0,0);      PostMessage(H1,WM_USER_CHANGETBAR,0,0);
265    if (H2!=0)    if (H2!=0)
266      PostMessage(H2,WM_USER_CHANGETBAR,0,0);      PostMessage(H2,WM_USER_CHANGETBAR,0,0);
267  }  }
268    
269  void OpenHelp(HWND HWin, UINT Command, DWORD Data)  void OpenHelp(HWND HWin, UINT Command, DWORD Data)
270  {  {
271    char HelpFN[MAXPATHLEN];    char HelpFN[MAXPATHLEN];
272    
273    get_lang_msg("HELPFILE", ts.UIMsg, sizeof(ts.UIMsg), HTML_HELP, ts.UILanguageFile);    get_lang_msg("HELPFILE", ts.UIMsg, sizeof(ts.UIMsg), HTML_HELP, ts.UILanguageFile);
274    
275    // ヘルプのオーナーは常にデスクトップになる (2007.5.12 maya)    // ヘルプのオーナーは常にデスクトップになる (2007.5.12 maya)
276    HWin = GetDesktopWindow();    HWin = GetDesktopWindow();
277    _snprintf_s(HelpFN, sizeof(HelpFN), _TRUNCATE, "%s\\%s", ts.HomeDir, ts.UIMsg);    _snprintf_s(HelpFN, sizeof(HelpFN), _TRUNCATE, "%s\\%s", ts.HomeDir, ts.UIMsg);
278    if (HtmlHelp(HWin, HelpFN, Command, Data) == NULL && Command != HH_CLOSE_ALL) {    if (HtmlHelp(HWin, HelpFN, Command, Data) == NULL && Command != HH_CLOSE_ALL) {
279      char buf[MAXPATHLEN];      char buf[MAXPATHLEN];
280      get_lang_msg("MSG_OPENHELP_ERROR", ts.UIMsg, sizeof(ts.UIMsg), "Can't open HTML help file(%s).", ts.UILanguageFile);      get_lang_msg("MSG_OPENHELP_ERROR", ts.UIMsg, sizeof(ts.UIMsg), "Can't open HTML help file(%s).", ts.UILanguageFile);
281      _snprintf_s(buf, sizeof(buf), _TRUNCATE, ts.UIMsg, HelpFN);      _snprintf_s(buf, sizeof(buf), _TRUNCATE, ts.UIMsg, HelpFN);
282      MessageBox(HWin, buf, "Tera Term: HTML help", MB_OK | MB_ICONERROR);      MessageBox(HWin, buf, "Tera Term: HTML help", MB_OK | MB_ICONERROR);
283    }    }
284  }  }
285    
286  // HTML help を開く  // HTML help を開く
287  // HTML Help workshopに含まれる htmlhelp.h と htmlhelp.lib の2つのファイルが、ビルド時に必要。  // HTML Help workshopに含まれる htmlhelp.h と htmlhelp.lib の2つのファイルが、ビルド時に必要。
288  // (2006.3.11 yutaka)  // (2006.3.11 yutaka)
289  #if 0  #if 0
290  void OpenHtmlHelp(HWND HWin, char *filename)  void OpenHtmlHelp(HWND HWin, char *filename)
291  {  {
292          char HelpFN[MAXPATHLEN];          char HelpFN[MAXPATHLEN];
293    
294          _snprintf(HelpFN, sizeof(HelpFN), "%s\\%s", ts.HomeDir, filename);          _snprintf(HelpFN, sizeof(HelpFN), "%s\\%s", ts.HomeDir, filename);
295          // HTMLヘルプのオーナーをTera Termからデスクトップへ変更 (2006.4.7 yutaka)          // HTMLヘルプのオーナーをTera Termからデスクトップへ変更 (2006.4.7 yutaka)
296          if (HtmlHelp(GetDesktopWindow(), HelpFN, HH_DISPLAY_TOPIC, 0) == NULL) {          if (HtmlHelp(GetDesktopWindow(), HelpFN, HH_DISPLAY_TOPIC, 0) == NULL) {
297                  char buf[MAXPATHLEN];                  char buf[MAXPATHLEN];
298                  _snprintf(buf, sizeof(buf), "Can't open HTML help file(%s).", HelpFN);                  _snprintf(buf, sizeof(buf), "Can't open HTML help file(%s).", HelpFN);
299                  MessageBox(HWin, buf, "Tera Term: HTML help", MB_OK | MB_ICONERROR);                  MessageBox(HWin, buf, "Tera Term: HTML help", MB_OK | MB_ICONERROR);
300          }          }
301  }  }
302  #endif  #endif

Legend:
Removed from v.3226  
changed lines
  Added in v.3227

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26