Skip to content

Commit

Permalink
fix marking dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Oct 1, 2022
1 parent bee64b1 commit 1127e5f
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions XG_MarkingDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class XG_MarkingDialog : public XG_Dialog
}

// テキストの取得。
std::wstring GetText(HWND hwnd, BOOL bEdit)
std::wstring GetText(HWND hwnd, BOOL bEdit, BOOL bNormalize = TRUE)
{
WCHAR szText[256];
szText[0] = 0;
Expand All @@ -77,8 +77,10 @@ class XG_MarkingDialog : public XG_Dialog
::SendDlgItemMessageW(hwnd, lst1, LB_GETTEXT, i, (LPARAM)szText);
}
std::wstring str = szText;
xg_str_trim(str);
str = XgNormalizeString(str);
if (bNormalize) {
xg_str_trim(str);
str = XgNormalizeString(str);
}
return str;
}

Expand Down Expand Up @@ -147,6 +149,8 @@ class XG_MarkingDialog : public XG_Dialog
// テキストを取得する。
auto str = GetText(hwnd, FALSE);
SetText(hwnd, str, FALSE);

::KillTimer(hwnd, 999);
::SetTimer(hwnd, 999, MARKED_INTERVAL, NULL);
}

Expand All @@ -155,6 +159,8 @@ class XG_MarkingDialog : public XG_Dialog
// テキストを取得する。
auto str = GetText(hwnd, TRUE);
SetText(hwnd, str, TRUE);

::KillTimer(hwnd, 999);
::SetTimer(hwnd, 999, MARKED_INTERVAL, NULL);
}

Expand Down Expand Up @@ -274,29 +280,6 @@ class XG_MarkingDialog : public XG_Dialog
XgUpdateImage(xg_hMainWnd);
}

void OnTimer(HWND hwnd, UINT id)
{
if (id != 999)
return;

::KillTimer(hwnd, 999);

// テキストの更新。
WCHAR szText[256];
szText[0] = 0;
::GetDlgItemTextW(hwnd, edt1, szText, _countof(szText));
std::wstring str = szText;
auto strText = str;
xg_str_trim(strText);
auto strNormalized = XgNormalizeString(strText);
if (str != strNormalized) {
::SetDlgItemTextW(hwnd, edt1, str.c_str());

// 盤面を更新する。
XgUpdateImage(xg_hMainWnd);
}
}

void OnMove(HWND hwnd, int x, int y)
{
if (m_bInitted) {
Expand All @@ -307,26 +290,42 @@ class XG_MarkingDialog : public XG_Dialog
}
}

void OnTimer(HWND hwnd, UINT id)
{
if (id != 999)
return;

::KillTimer(hwnd, 999);

auto str1 = GetText(hwnd, TRUE, FALSE);
auto str2 = GetText(hwnd, TRUE, TRUE);
if (str1 != str2)
{
m_bUpdating = TRUE;
INT iStart, iEnd;
::SendDlgItemMessageW(hwnd, edt1, EM_GETSEL, (WPARAM)&iStart, (LPARAM)&iEnd);
::SetDlgItemTextW(hwnd, edt1, str2.c_str());
::SendDlgItemMessageW(hwnd, edt1, EM_SETSEL, iStart, iEnd);
m_bUpdating = FALSE;
}
}

void OnDestroy(HWND hwnd)
{
::KillTimer(hwnd, 999);
m_hWnd = NULL;
m_bInitted = FALSE;
}

virtual INT_PTR CALLBACK
DialogProcDx(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg != WM_TIMER)
{
if (::KillTimer(hwnd, 999))
::SetTimer(hwnd, 999, MARKED_INTERVAL, NULL);
}
switch (uMsg)
{
HANDLE_MSG(hwnd, WM_INITDIALOG, OnInitDialog);
HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
HANDLE_MSG(hwnd, WM_TIMER, OnTimer);
HANDLE_MSG(hwnd, WM_MOVE, OnMove);
HANDLE_MSG(hwnd, WM_TIMER, OnTimer);
HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
}
return 0;
Expand Down

0 comments on commit 1127e5f

Please sign in to comment.