Skip to content

Commit

Permalink
Merge pull request #282 from hkanou/hkanou_ttpmacro
Browse files Browse the repository at this point in the history
getttpos コマンドで取得位置がずれることがある #275 の修正
  • Loading branch information
zmatsuo authored Aug 24, 2024
2 parents 0ac498a + 3204a9e commit b748e68
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 114 deletions.
32 changes: 15 additions & 17 deletions TTXSamples/TTXCheckUpdate/ttxcheckupdate.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "teraterm.h"
#include "tttypes.h"
#include "ttplugin.h"
#include "ttlib.h"

#include "codeconv.h"
#include "dlglib.h"
Expand All @@ -56,7 +55,6 @@ typedef struct {
PComVar cv;
version_one_t *versions;
size_t versions_count;
PReadIniFile ReadIniFile;
} TInstVar;

static TInstVar InstVar;
Expand Down Expand Up @@ -205,7 +203,13 @@ static void ShowDialog(HWND hWnd)
result_bool = GetContent(update_info_url, agent, (void**)&json_raw_ptr, &json_raw_size);
free(update_info_url);
if (!result_bool) {
MessageBoxW(hWnd, L"access error?", L"Tera Term", MB_OK | MB_ICONEXCLAMATION);
static const TTMessageBoxInfoW info = {
"TTXCheckUpdate",
NULL, L"Tera Term",
"MSG_ERROR_ACCESS", L"access error?",
MB_OK | MB_ICONEXCLAMATION
};
TTMessageBoxW(hWnd, &info, UILanguageFileW);
return;
}
json_size = json_raw_size + 1;
Expand All @@ -220,7 +224,13 @@ static void ShowDialog(HWND hWnd)
/* jsonをパースする, versionsに情報が入る */
pvar->versions = ParseJson(json_ptr, &pvar->versions_count);
if (pvar->versions == NULL) {
MessageBoxW(hWnd, L"parse error?", L"Tera Term", MB_OK | MB_ICONEXCLAMATION);
static const TTMessageBoxInfoW info = {
"TTXCheckUpdate",
NULL, L"Tera Term",
"MSG_ERROR_PARSE", L"parse error?",
MB_OK | MB_ICONEXCLAMATION
};
TTMessageBoxW(hWnd, &info, UILanguageFileW);
return;
}

Expand All @@ -241,18 +251,6 @@ static void WINAPI TTXInit(PTTSet ts, PComVar cv)
pvar->cv = cv;
}

static void PASCAL TTXReadINIFile(const wchar_t *fileName, PTTSet ts)
{
(pvar->ReadIniFile) (fileName, ts);
MessageBoxPosParentRelative = ts->MessageBoxPosParentRelative;
}

static void PASCAL TTXGetSetupHooks(TTXSetupHooks *hooks)
{
pvar->ReadIniFile = *hooks->ReadIniFile;
*hooks->ReadIniFile = TTXReadINIFile;
}

static void WINAPI TTXModifyMenu(HMENU menu)
{
static const DlgTextInfo MenuTextInfo[] = {
Expand Down Expand Up @@ -283,7 +281,7 @@ static TTXExports Exports = {

TTXInit,
NULL,
TTXGetSetupHooks,
NULL,
NULL,
NULL,
NULL,
Expand Down
3 changes: 1 addition & 2 deletions doc/en/html/about/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ <h3 id="teraterm_5.3">YYYY.MM.DD (Ver 5.3 not released yet)</h3>
</li>
<li>Add ViewlogEditor argument on <a href="../menu/setup-additional-log.html#ViewlogEditorArg">Log Tab</a> in Additional settings.</li>
<li>Setup - Font was integrated into <a href="../menu/setup-additional-font.html">Font tab</a> of Additional settings.</li>
<li>Added the <a href="../setup/teraterm-misc.html#MessageBoxPosParentRelative">MessageBoxPosParentRelative</a> option to change the display position of the message box (excluding some) from the center of the screen to the center of the parent window.</li>
<li>Setup - Font was integrated into <a href="../menu/setup-additional-font.html">Font tab</a> of Additional settings.
<li>Returned the display position of the message box to its previous behavior (center of the parent window) before 4.103, excluding some message boxes.</li>
<li>Add <a href="../menu/setup-additional-tcpip.html">TCP/IP tab</a> of Additional setting dialog.
<ul>
<li>TCP/IP dialog is moved to TCP/IP tab.</li>
Expand Down
2 changes: 1 addition & 1 deletion doc/en/html/macro/command/getttpos.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h2>Example</h2>

<pre class="macro-example">
testlink
if result > 1 then
if result > 0 then
:start
getttpos showflag w_x w_y w_width w_height c_x c_y c_width c_height
if showflag != 3 then
Expand Down
6 changes: 0 additions & 6 deletions doc/en/html/setup/teraterm-ini.html
Original file line number Diff line number Diff line change
Expand Up @@ -919,12 +919,6 @@ <h2>Tera Term</h2>
<td style="width:250px;">&lt;-</td>
<td></td>
</tr>
<tr>
<td id="MessageBoxPosParentRelative"><a href="teraterm-misc.html#MessageBoxPosParentRelative">MessageBoxPosParentRelative</a></td>
<td style="width:250px;">off</td>
<td style="width:250px;">&lt;-</td>
<td></td>
</tr>
<tr>
<td id="Meta8Bit"><a href="teraterm-term.html#Meta8Bit">Meta8Bit</a></td>
<td style="width:250px;">off</td>
Expand Down
17 changes: 0 additions & 17 deletions doc/en/html/setup/teraterm-misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -474,22 +474,5 @@ <h1 id="BracketedControlOnly">Limit bracketed pasting to cases containing contro
BracketedControlOnly=off
</pre>

<h1 id="MessageBoxPosParentRelative">Display the message box in the center of the parent window</h1>

<p>
By default, the message box is displayed in the center of the display.<br>
To display the message box in the center of the parent window, edit the MessageBoxPosParentRelative line in the [Tera Term] section as follows.<br>
(Even if set MessageBoxPosParentRelative=on, some message boxes may still be displayed in the center of the display.)
</p>

<pre>
MessageBoxPosParentRelative=on
</pre>

<pre>
Default:
MessageBoxPosParentRelative=off
</pre>

</BODY>
</HTML>
1 change: 0 additions & 1 deletion doc/en/html/setup/teraterm.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ <h3>Miscellaneous</h3>
<li><a href="teraterm-misc.html#IniAutoBackup">Auto backup of Tera Term setup file</a></li>
<li><a href="teraterm-misc.html#BracketedSupport">Support bracketed paste</a></li>
<li><a href="teraterm-misc.html#BracketedControlOnly">Limit bracketed pasting to cases containing control characters</a></li>
<li><a href="teraterm-misc.html#MessageBoxPosParentRelative">Display the message box in the center of the parent window</a></li>
</ul>

<h3>TTSSH</h3>
Expand Down
2 changes: 1 addition & 1 deletion doc/ja/html/about/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ <h3 id="teraterm_5.3">YYYY.MM.DD (Ver 5.3 not released yet)</h3>
</li>
<li>Additional settings の <a href="../menu/setup-additional-log.html#ViewlogEditorArg">Log タブ</a>に ViewlogEditor の引き数を追加した。</li>
<li>設定-フォント設定を Additional settings の <a href="../menu/setup-additional-font.html">フォントタブ</a>へ統合した。</li>
<li>メッセージボックス(一部を除く)の表示位置を画面中央から親ウィンドウ中央に変更する <a href="../setup/teraterm-misc.html#MessageBoxPosParentRelative">MessageBoxPosParentRelative</a> オプションを追加した。</li>
<li>メッセージボックスの表示位置を4.103より前の動作(親ウィンドウ中央)に戻した。(一部のメッセージボックスを除く)</li>
<li>Additional settings に <a href="../menu/setup-additional-tcpip.html">TCP/IP タブ</a> を追加した。
<ul>
<li>TCP/IP setup ダイアログを TCP/IP タブへ移動した。</li>
Expand Down
2 changes: 1 addition & 1 deletion doc/ja/html/macro/command/getttpos.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h1>getttpos</h1>

<pre class="macro-example">
testlink
if result > 1 then
if result > 0 then
:start
getttpos showflag w_x w_y w_width w_height c_x c_y c_width c_height
if showflag != 3 then
Expand Down
6 changes: 0 additions & 6 deletions doc/ja/html/setup/teraterm-ini.html
Original file line number Diff line number Diff line change
Expand Up @@ -919,12 +919,6 @@ <h2>Tera Term</h2>
<td style="width:250px;">&lt;-</td>
<td></td>
</tr>
<tr>
<td id="MessageBoxPosParentRelative"><a href="teraterm-misc.html#MessageBoxPosParentRelative">MessageBoxPosParentRelative</a></td>
<td style="width:250px;">off</td>
<td style="width:250px;">&lt;-</td>
<td></td>
</tr>
<tr>
<td id="Meta8Bit"><a href="teraterm-term.html#Meta8Bit">Meta8Bit</a></td>
<td style="width:250px;">off</td>
Expand Down
17 changes: 0 additions & 17 deletions doc/ja/html/setup/teraterm-misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -504,22 +504,5 @@
BracketedControlOnly=off
</pre>

<h1 id="MessageBoxPosParentRelative">メッセージボックスを親ウインドウの中央に表示する</h1>

<p>
デフォルトでは、メッセージボックスはディスプレイの中央に表示されます。<br>
メッセージボックスを親ウインドウの中央に表示するには、[Tera Term] セクションの MessageBoxPosParentRelative 行を以下のように変更してください。<br>
(MessageBoxPosParentRelative=onを設定しても、一部のメッセージボックスはディスプレイの中央に表示されます)
</p>

<pre>
MessageBoxPosParentRelative=on
</pre>

<pre>
省略時:
MessageBoxPosParentRelative=off
</pre>

</BODY>
</HTML>
1 change: 0 additions & 1 deletion doc/ja/html/setup/teraterm.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@
<li><a href="teraterm-misc.html#IniAutoBackup">設定ファイルの自動バックアップ</a></li>
<li><a href="teraterm-misc.html#BracketedSupport">ブラケットペーストのサポート</a></li>
<li><a href="teraterm-misc.html#BracketedControlOnly">ブラケットペーストを制御文字を含む場合に限定する</a></li>
<li><a href="teraterm-misc.html#MessageBoxPosParentRelative">メッセージボックスを親ウインドウの中央に表示する</a></li>
</ul>

<h3>TTSSH</h3>
Expand Down
3 changes: 0 additions & 3 deletions installer/release/TERATERM.INI
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,6 @@ MaxComPort=256
; Max buffer size of OSC string
MaxOSCBufferSize=4096
; Display a MessageBox in the center of the parent window.
MessageBoxPosParentRelative=off
; Mouse event tracking
MouseEventTracking=on
Expand Down
2 changes: 0 additions & 2 deletions teraterm/common/ttlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ extern "C" {
#define _Printf_format_string_
#endif

extern WORD MessageBoxPosParentRelative;

BOOL GetFileNamePos(const char *PathName, int *DirLen, int *FNPos);
BOOL GetFileNamePosU8(const char *PathName, int *DirLen, int *FNPos);
BOOL GetFileNamePosW(const wchar_t *PathName, size_t *DirLen, size_t *FNPos);
Expand Down
6 changes: 1 addition & 5 deletions teraterm/common/ttlib_static_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,12 @@
#include "compat_win.h"
#include "fileread.h"
#include "tt-version.h"
#include "tttypes.h"

#include "ttlib.h"

// for isInvalidFileNameCharW / replaceInvalidFileNameCharW
static const wchar_t *invalidFileNameCharsW = L"\\/:*?\"<>|";

// for TTMessageBoxW()
WORD MessageBoxPosParentRelative = 0;

/**
* MessageBoxを表示する
*
Expand Down Expand Up @@ -112,7 +108,7 @@ int TTMessageBoxW(HWND hWnd, const TTMessageBoxInfoW *info, const wchar_t *UILan
free(format);
}

if (hWnd != NULL && MessageBoxPosParentRelative == 1) {
if (hWnd != NULL) {
SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE, NULL,
&TTMessageBoxW_WinEventProc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_OUTOFCONTEXT);
}
Expand Down
1 change: 0 additions & 1 deletion teraterm/common/tttypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@ struct tttset {
WORD BracketedControlOnly;
wchar_t *ViewlogEditorW;
wchar_t *ViewlogEditorArg;
WORD MessageBoxPosParentRelative;

// Experimental
BYTE ExperimentalTreeProprtySheetEnable;
Expand Down
39 changes: 29 additions & 10 deletions teraterm/ttpmacro/ttl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <string.h>
#include <time.h>
#include <errno.h>
#include "compat_win.h"
#include "tt-version.h"
#include "ttmdlg.h"
#include "ttmbuff.h"
Expand Down Expand Up @@ -2912,18 +2913,36 @@ static WORD TTLGetTTPos(void)
int tmp_showflag;
int tmpw_x, tmpw_y, tmpw_width, tmpw_height;
int tmpc_x, tmpc_y, tmpc_width, tmpc_height;
HMONITOR hMonitor;
RECT rc;
UINT dpi_x, dpi_y;
float mag = 1;

if (sscanf_s(Str, "%d %d %d %d %d %d %d %d %d", &tmp_showflag,
&tmpw_x, &tmpw_y, &tmpw_width, &tmpw_height,
&tmpc_x, &tmpc_y, &tmpc_width, &tmpc_height) == 9) {
&tmpw_x, &tmpw_y, &tmpw_width, &tmpw_height,
&tmpc_x, &tmpc_y, &tmpc_width, &tmpc_height) == 9) {
if (DPIAware == DPI_AWARENESS_CONTEXT_UNAWARE) {
if (pMonitorFromRect != NULL && pGetDpiForMonitor != NULL) {
rc.left = tmpw_x;
rc.top = tmpw_y;
rc.right = tmpw_x + tmpw_width;
rc.bottom = tmpw_y + tmpw_height;
hMonitor = pMonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST);
if (hMonitor != NULL) {
pGetDpiForMonitor(hMonitor, (MONITOR_DPI_TYPE)0 /*0=MDT_EFFECTIVE_DPI*/, &dpi_x, &dpi_y);
mag = dpi_x / 96.f;
}
}
}
SetIntVal(showflag, tmp_showflag);
SetIntVal(w_x, tmpw_x);
SetIntVal(w_y, tmpw_y);
SetIntVal(w_width, tmpw_width);
SetIntVal(w_height, tmpw_height);
SetIntVal(c_x, tmpc_x);
SetIntVal(c_y, tmpc_y);
SetIntVal(c_width, tmpc_width);
SetIntVal(c_height, tmpc_height);
SetIntVal(w_x, (int)(tmpw_x * mag));
SetIntVal(w_y, (int)(tmpw_y * mag));
SetIntVal(w_width, (int)(tmpw_width * mag));
SetIntVal(w_height, (int)(tmpw_height * mag));
SetIntVal(c_x, (int)(tmpc_x * mag));
SetIntVal(c_y, (int)(tmpc_y * mag));
SetIntVal(c_width, (int)(tmpc_width * mag));
SetIntVal(c_height, (int)(tmpc_height * mag));
SetResult(0);
} else {
SetResult(-1);
Expand Down
20 changes: 5 additions & 15 deletions teraterm/ttpmacro/ttmacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ static HINSTANCE hInst;
static BOOL Busy;
static CCtrlWindow *pCCtrlWindow;

DPI_AWARENESS_CONTEXT DPIAware;

HINSTANCE GetInstance()
{
return hInst;
Expand All @@ -75,8 +77,6 @@ HWND GetHWND()

static void init()
{
wchar_t Temp[4];

HomeDirW = GetHomeDirW(hInst);
SetupFNameW = GetDefaultFNameW(HomeDirW, L"TERATERM.INI");

Expand All @@ -86,11 +86,14 @@ static void init()
WinCompatInit();

// DPI Aware (高DPI対応)
DPIAware = DPI_AWARENESS_CONTEXT_UNAWARE;
if (pIsValidDpiAwarenessContext != NULL && pSetThreadDpiAwarenessContext != NULL) {
wchar_t Temp[4];
GetPrivateProfileStringW(L"Tera Term", L"DPIAware", NULL, Temp, _countof(Temp), SetupFNameW);
if (_wcsicmp(Temp, L"on") == 0) {
if (pIsValidDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) == TRUE) {
pSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
DPIAware = DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2;
}
}
}
Expand All @@ -100,12 +103,6 @@ static void init()
GetI18nLogfontW(L"Tera Term", L"DlgFont", &logfont, 0, SetupFNameW);
SetDialogFont(logfont.lfFaceName, logfont.lfHeight, logfont.lfCharSet,
UILanguageFileW, "Tera Term", "DLG_SYSTEM_FONT");

// MessageBoxPosParentRelativeの取得
GetPrivateProfileStringW(L"Tera Term", L"MessageBoxPosParentRelative", NULL, Temp, _countof(Temp), SetupFNameW);
if (_wcsicmp(Temp, L"on") == 0) {
MessageBoxPosParentRelative = 1;
}
}

// TTMACRO main engine
Expand Down Expand Up @@ -140,13 +137,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst,
#endif
DebugSetException();

// DPI Aware (高DPI対応)
if (pIsValidDpiAwarenessContext != NULL && pSetThreadDpiAwarenessContext != NULL) {
if (pIsValidDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) == TRUE) {
pSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
}
}

// InitCommonControls();
init();

Expand Down
1 change: 1 addition & 0 deletions teraterm/ttpmacro/ttmdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ extern wchar_t ShortName[MAX_PATH];
extern wchar_t **Params;
extern int ParamCnt;
extern BOOL SleepFlag;
extern DPI_AWARENESS_CONTEXT DPIAware;

#ifdef __cplusplus
}
Expand Down
7 changes: 0 additions & 7 deletions teraterm/ttpset/ttset.c
Original file line number Diff line number Diff line change
Expand Up @@ -2072,10 +2072,6 @@ void PASCAL _ReadIniFile(const wchar_t *FName, PTTSet ts)
ts->BracketedSupport = GetOnOff(Section, "BracketedSupport", FName, TRUE);
ts->BracketedControlOnly = GetOnOff(Section, "BracketedControlOnly", FName, FALSE);

// MessageBoxの表示位置
ts->MessageBoxPosParentRelative = GetOnOff(Section, "MessageBoxPosParentRelative", FName, FALSE);
MessageBoxPosParentRelative = ts->MessageBoxPosParentRelative;

// Experimental
ts->ExperimentalTreeProprtySheetEnable = GetOnOff("Experimental", "TreeProprtySheet", FName, FALSE);
}
Expand Down Expand Up @@ -3333,9 +3329,6 @@ void PASCAL _WriteIniFile(const wchar_t *FName, PTTSet ts)
// Bracketed paste mode
WriteOnOff(Section, "BracketedSupport", FName, ts->BracketedSupport);
WriteOnOff(Section, "BracketedControlOnly", FName, ts->BracketedControlOnly);

// MessageBoxの表示位置
WriteOnOff(Section, "MessageBoxPosParentRelative", FName, ts->MessageBoxPosParentRelative);
}

void PASCAL _CopySerialList(const wchar_t *IniSrc, const wchar_t *IniDest, const wchar_t *section,
Expand Down
Loading

0 comments on commit b748e68

Please sign in to comment.