Skip to content

Commit

Permalink
vtwinのフックを含んだダイアログを表示するコードをまとめた
Browse files Browse the repository at this point in the history
- externalsetup.cpp,h に移動した
  • Loading branch information
zmatsuo committed Oct 18, 2024
1 parent f269eb3 commit c16e1d2
Show file tree
Hide file tree
Showing 23 changed files with 868 additions and 458 deletions.
477 changes: 281 additions & 196 deletions teraterm/common/comportinfo.cpp

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions teraterm/common/comportinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ extern "C" {
#endif

typedef struct {
wchar_t *port_name; // ポート名
int port_no; // 0..128(9x)/255(xp)
wchar_t *port_name; // ポート名 "COM%d" 以外もある
int port_no; // "COM%d" の %d部分 0の場合は "COM%d" 以外(1..128(9x)/255(xp)/2^32が上限?)
wchar_t *friendly_name; // 存在しない場合は NULL
wchar_t *property; // 存在しない場合は NULL
wchar_t *property; // 個別の値をまとめた
// 個別の値
wchar_t *class_name;
wchar_t *instance_id;
wchar_t *manufacturer;
wchar_t *provider_name;
wchar_t *driverdate;
wchar_t *driverversion;
} ComPortInfo_t;

ComPortInfo_t *ComPortInfoGet(int *count);
void ComPortInfoFree(ComPortInfo_t *info, int count);

Expand Down
1 change: 0 additions & 1 deletion teraterm/common/tt_res.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@
#define ID_SETUP_TCPIP 50360
#define ID_SETUP_GENERAL 50370
#define ID_SETUP_ADDITIONALSETTINGS 50375
#define ID_SETUP_ADDITIONALSETTINGS_CODING 50376
#define ID_SETUP_SAVE 50380
#define ID_SETUP_RESTORE 50390
#define ID_OPEN_SETUP 50391
Expand Down
2 changes: 2 additions & 0 deletions teraterm/teraterm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ add_executable(
clipboar.h
commlib.c
commlib.h
externalsetup.cpp
externalsetup.h
filesys.cpp
filesys.h
filesys_log.cpp
Expand Down
311 changes: 311 additions & 0 deletions teraterm/teraterm/externalsetup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
/*
* Copyright (C) 2024- 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.
*/

#include <assert.h>

#include "tttypes.h"
#include "ttwinman.h"
#include "buffer.h"
#include "vtdisp.h"
#include "vtwin.h"
#include "vtterm.h"
#include "commlib.h"
#include "dlglib.h"
#include "telnet.h"
#include "setting.h"
#include "ttdialog.h"

#include "externalsetup.h"

static struct {
BOOL PerProcessCalled;
BOOL old_use_unicode_api;
char *orgTitle;
int OnePage;
} ExternalSetupData;

/**
* 設定ダイアログを出す前の処理
*
* @param page 処理するタブ
*/
static void ExternalSetupPreProcess(CAddSettingPropSheetDlgPage page)
{
ExternalSetupData.PerProcessCalled = TRUE;
ExternalSetupData.OnePage = page;
BOOL all = TRUE;
//BOOL all = FALSE;
if (page == CAddSettingPropSheetDlgPage::DefaultPage) {
all = TRUE;
}
if (all || page == CAddSettingPropSheetDlgPage::CodingPage) {
;
}
if (all || page == CAddSettingPropSheetDlgPage::FontPage) {
ts.SampleFont = VTFont[0];
}
if (all || page == CAddSettingPropSheetDlgPage::KeyboardPage) {
;
}
if (all || page == CAddSettingPropSheetDlgPage::TcpIpPage) {
;
}
if (all || page == CAddSettingPropSheetDlgPage::GeneralPage) {
;
}
if (all || page == CAddSettingPropSheetDlgPage::TermPage) {
;
}
if (all || page == CAddSettingPropSheetDlgPage::WinPage) {
ExternalSetupData.orgTitle = _strdup(ts.Title);
}
if (all || page == CAddSettingPropSheetDlgPage::SerialPortPage) {
;
}
}

/**
* 設定ダイアログを閉じた後の処理
* 設定(tsなど)の値を反映する
*
* @param page 処理するタブ
* @param ok TRUE/FALSE = OKが押された/押されなかった
*/
static void ExternalSetupPostProcess(CAddSettingPropSheetDlgPage page, BOOL ok)
{
ExternalSetupData.PerProcessCalled = FALSE;

//BOOL all = FALSE;
BOOL all = TRUE;
if (page == CAddSettingPropSheetDlgPage::DefaultPage) {
all = TRUE;
}
if (all || page == CAddSettingPropSheetDlgPage::CodingPage) {
;
}
if (all || page == CAddSettingPropSheetDlgPage::FontPage) {
;
}
if (all || page == CAddSettingPropSheetDlgPage::KeyboardPage) {
//ResetKeypadMode(TRUE);
//ResetIME();
;
}
if (all || page == CAddSettingPropSheetDlgPage::TcpIpPage) {
;
}
if (all || page == CAddSettingPropSheetDlgPage::GeneralPage) {
if (ok) {
ResetCharSet();
ResetIME();
}
}
if (all || page == CAddSettingPropSheetDlgPage::TermPage) {
if (ok) {
pVTWin->SetupTerm();
}
}
if (all || page == CAddSettingPropSheetDlgPage::WinPage) {
if (ok) {
pVTWin->SetColor();

// タイトルが変更されていたら、リモートタイトルをクリアする
if ((ts.AcceptTitleChangeRequest == IdTitleChangeRequestOverwrite) &&
(strcmp(ExternalSetupData.orgTitle, ts.Title) != 0)) {
free(cv.TitleRemoteW);
cv.TitleRemoteW = NULL;
}
ChangeWin();
ChangeFont();

}
free(ExternalSetupData.orgTitle);
ExternalSetupData.orgTitle = NULL;
}
if (all || page == CAddSettingPropSheetDlgPage::SerialPortPage) {
if (ok) {
if (ts.ComPort > 0) {

if (cv.Ready && (cv.PortType != IdSerial)) {
// シリアル以外に接続中の場合
// TODO cv.Ready と cv.Openの差は?
#if 0
OpenNewComport(&ts);
return;
#endif
}
else if (!cv.Open) {
// 未接続の場合
#if 0
CommOpen(m_hWnd,&ts,&cv);
#endif
}
else {
// シリアルに接続中の場合
#if 0
if (ts.ComPort != cv.ComPort) {
// ポートを変更する
CommClose(&cv);
CommOpen(HVTWin,&ts,&cv);
}
else
#endif
{
// 通信パラメータを変更する
CommResetSerial(&ts, &cv, ts.ClearComBuffOnOpen);
}
}
}
}
}
}

/**
* Additional Setting を表示する
*
* @param page DefaultPage 全てのタブを表示して表示する
* その他 特定のタブを表示する
* @retval TRUE "OK"が押された
* @retval FALSE "Cancel"が押された
*
* 関数をコールする順
* - ExternalSetupPreProcess()
* - OpenExternalSetupTab()
* - ExternalSetupPostProcess()
*/
BOOL OpenExternalSetupTab(HWND hWndParent, CAddSettingPropSheetDlgPage page)
{
SetDialogFont(ts.DialogFontNameW, ts.DialogFontPoint, ts.DialogFontCharSet,
ts.UILanguageFileW, "Tera Term", "DLG_TAHOMA_FONT");

// TEKWin
if (AddsettingCheckWin(hWndParent) == ADDSETTING_WIN_TEK) {
if (page == CAddSettingPropSheetDlgPage::WinPage) {
// Window Setup
CAddSettingPropSheetDlg CAddSetting(hInst, hWndParent);
INT_PTR ret = CAddSetting.DoModal();
return (ret == IDOK) ? TRUE : FALSE;
}
assert(FALSE);
}

// VTWin
assert(ExternalSetupData.PerProcessCalled == TRUE);

int one_page = DefaultPage;
CAddSettingPropSheetDlg CAddSetting(hInst, hWndParent);
if (one_page == CAddSettingPropSheetDlgPage::DefaultPage) {
CAddSetting.SetTreeViewMode(ts.ExperimentalTreeProprtySheetEnable);
}
CAddSetting.SetStartPage((CAddSettingPropSheetDlg::Page)page);
INT_PTR ret = CAddSetting.DoModal();
return (ret == IDOK) ? TRUE : FALSE;
}

/*
* ここ以降は vtwin.cpp から UI操作/プラグインからコールされる
* OpenExternalSetup() 以外はフックされていてダイアログが開かない場合がある
* ダイアログが開く場合は OpenExternalSetupTab() がコールされる
*/

void OpenExternalSetup(HWND hWndParent)
{
ExternalSetupPreProcess(CAddSettingPropSheetDlgPage::DefaultPage);
BOOL r = OpenExternalSetupTab(hWndParent, CAddSettingPropSheetDlgPage::DefaultPage);
ExternalSetupPostProcess(CAddSettingPropSheetDlgPage::DefaultPage, r);
}

void OpenSetupTerminal()
{
if (! LoadTTDLG()) {
return;
}
ExternalSetupPreProcess(CAddSettingPropSheetDlgPage::TermPage);
BOOL r = (*SetupTerminal)(HVTWin, &ts);
ExternalSetupPostProcess(CAddSettingPropSheetDlgPage::TermPage, r);
}

void OpenSetupWin()
{
if (! LoadTTDLG()) {
return;
}
ExternalSetupPreProcess(CAddSettingPropSheetDlgPage::WinPage);
BOOL r = (*SetupWin)(HVTWin, &ts);
ExternalSetupPostProcess(CAddSettingPropSheetDlgPage::WinPage, r);
}

void OpenSetupFont()
{
if (! LoadTTDLG()) {
return;
}
ExternalSetupPreProcess(CAddSettingPropSheetDlgPage::FontPage);
BOOL r = (*ChooseFontDlg)(HVTWin, NULL, &ts);
ExternalSetupPostProcess(CAddSettingPropSheetDlgPage::FontPage, r);
}

void OpenSetupKeyboard()
{
if (! LoadTTDLG()) {
return;
}
ExternalSetupPreProcess(CAddSettingPropSheetDlgPage::KeyboardPage);
BOOL r = (*SetupKeyboard)(HVTWin, &ts);
ExternalSetupPostProcess(CAddSettingPropSheetDlgPage::KeyboardPage, r);
}

void OpenSetupSerialPort()
{
if (! LoadTTDLG()) {
return;
}
ExternalSetupPreProcess(CAddSettingPropSheetDlgPage::SerialPortPage);
BOOL r = (*SetupSerialPort)(HVTWin, &ts);
ExternalSetupPostProcess(CAddSettingPropSheetDlgPage::SerialPortPage, r);
}

void OpenSetupTCPIP()
{
if (! LoadTTDLG()) {
return;
}
ExternalSetupPreProcess(CAddSettingPropSheetDlgPage::TcpIpPage);
BOOL r = (*SetupTCPIP)(HVTWin, &ts);
ExternalSetupPostProcess(CAddSettingPropSheetDlgPage::TcpIpPage, r);
}

void OpenSetupGeneral()
{
if (! LoadTTDLG()) {
return;
}
ExternalSetupPreProcess(CAddSettingPropSheetDlgPage::GeneralPage);
BOOL r = (*SetupGeneral)(HVTWin,&ts);
ExternalSetupPostProcess(CAddSettingPropSheetDlgPage::GeneralPage, r);
}
Loading

0 comments on commit c16e1d2

Please sign in to comment.