Skip to content

Commit 46dd39c

Browse files
committed
Fix #75 and #79
1 parent 243a38d commit 46dd39c

File tree

4 files changed

+127
-13
lines changed

4 files changed

+127
-13
lines changed

HISTORY.txt

+2
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@
320320
- This time, we do exclusive control properly.
321321
- Added a function to display the dictionary update date and time.
322322
- The "Jump" dialog has been made modeless.
323+
- Added "Jump to letter or word" function.
323324

324325
# 開発履歴 (Japanese)
325326

@@ -959,3 +960,4 @@
959960
- 今度こそ排他制御をちゃんとする。
960961
- 辞書の更新日時を表示する機能を追加。
961962
- 「ジャンプ」ダイアログをモードレス化した。
963+
- 「文字または単語にジャンプ」機能を追加。

XG_JumpDialog.hpp

+109-3
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,49 @@ class XG_JumpDialog : public XG_Dialog
1818
void UpdateUI(HWND hwnd)
1919
{
2020
if (!xg_bSolved) {
21-
m_nType = 0;
21+
if (m_nType == 1)
22+
m_nType = 0;
2223
}
2324

2425
if (m_nType == 0) {
2526
EnableWindow(GetDlgItem(hwnd, edt1), TRUE);
2627
EnableWindow(GetDlgItem(hwnd, edt2), TRUE);
2728
EnableWindow(GetDlgItem(hwnd, edt3), FALSE);
29+
EnableWindow(GetDlgItem(hwnd, edt4), FALSE);
2830
EnableWindow(GetDlgItem(hwnd, rad3), FALSE);
2931
EnableWindow(GetDlgItem(hwnd, rad4), FALSE);
3032
CheckRadioButton(hwnd, rad1, rad2, rad1);
3133
SetDlgItemInt(hwnd, edt1, m_jCol, FALSE);
3234
SetDlgItemInt(hwnd, edt2, m_iRow, FALSE);
33-
} else {
35+
} else if (m_nType == 1) {
3436
EnableWindow(GetDlgItem(hwnd, edt1), FALSE);
3537
EnableWindow(GetDlgItem(hwnd, edt2), FALSE);
3638
EnableWindow(GetDlgItem(hwnd, edt3), TRUE);
39+
EnableWindow(GetDlgItem(hwnd, edt4), FALSE);
3740
EnableWindow(GetDlgItem(hwnd, rad3), TRUE);
3841
EnableWindow(GetDlgItem(hwnd, rad4), TRUE);
3942
CheckRadioButton(hwnd, rad1, rad2, rad2);
4043
SetDlgItemInt(hwnd, edt3, m_nNumber, FALSE);
4144
CheckRadioButton(hwnd, rad3, rad4, (m_bVert ? rad4 : rad3));
45+
} else if (m_nType == 2) {
46+
EnableWindow(GetDlgItem(hwnd, edt1), FALSE);
47+
EnableWindow(GetDlgItem(hwnd, edt2), FALSE);
48+
EnableWindow(GetDlgItem(hwnd, edt3), FALSE);
49+
EnableWindow(GetDlgItem(hwnd, edt4), TRUE);
50+
EnableWindow(GetDlgItem(hwnd, rad3), FALSE);
51+
EnableWindow(GetDlgItem(hwnd, rad4), FALSE);
4252
}
4353
}
4454

4555
BOOL OnOK(HWND hwnd)
4656
{
47-
m_nType = (IsDlgButtonChecked(hwnd, rad2) == BST_CHECKED);
57+
if (IsDlgButtonChecked(hwnd, rad2) == BST_CHECKED)
58+
m_nType = 1;
59+
else if (IsDlgButtonChecked(hwnd, rad5) == BST_CHECKED)
60+
m_nType = 2;
61+
else
62+
m_nType = 0;
63+
4864
m_bVert = (IsDlgButtonChecked(hwnd, rad4) == BST_CHECKED);
4965
m_jCol = GetDlgItemInt(hwnd, edt1, NULL, FALSE);
5066
m_iRow = GetDlgItemInt(hwnd, edt2, NULL, FALSE);
@@ -181,6 +197,90 @@ class XG_JumpDialog : public XG_Dialog
181197
case 1: // カギ位置。
182198
XgJumpNumber(hwnd, m_nNumber, m_bVert);
183199
break;
200+
case 2: // 文字または単語。
201+
{
202+
// テキストを取得する。
203+
WCHAR szText[64];
204+
GetDlgItemText(hwnd, edt4, szText, _countof(szText));
205+
StrTrimW(szText, XG_WHITE_SPACES);
206+
if (!szText[0])
207+
return;
208+
209+
auto str = XgNormalizeString(szText);
210+
XG_Board& xw = (xg_bSolved && xg_bShowAnswer) ? xg_solution : xg_xword;
211+
212+
// 次に進む関数。
213+
auto GetNext = [&](INT& jCol, INT& iRow) {
214+
++jCol;
215+
if (jCol == xg_nCols) {
216+
jCol = 0;
217+
++iRow;
218+
if (iRow == xg_nRows) {
219+
iRow = 0;
220+
}
221+
}
222+
};
223+
// ヨコの単語を取得する関数。
224+
auto GetHorzWord = [&](INT jCol, INT iRow) -> XGStringW {
225+
if (xw.GetAt(iRow, jCol) == ZEN_BLACK) {
226+
return { ZEN_BLACK };
227+
}
228+
if (jCol == 0 || xw.GetAt(iRow, jCol - 1) == ZEN_BLACK) {
229+
XGStringW ret;
230+
for (INT j = jCol; j < xg_nCols; ++j) {
231+
WCHAR ch = xw.GetAt(iRow, j);
232+
if (ch == ZEN_BLACK)
233+
break;
234+
ret += ch;
235+
}
236+
return ret;
237+
}
238+
return { xw.GetAt(iRow, jCol) };
239+
};
240+
// タテの単語を取得する関数。
241+
auto GetVertWord = [&](INT jCol, INT iRow) -> XGStringW {
242+
if (xw.GetAt(iRow, jCol) == ZEN_BLACK) {
243+
return { ZEN_BLACK };
244+
}
245+
if (iRow == 0 || xw.GetAt(iRow - 1, jCol) == ZEN_BLACK) {
246+
XGStringW ret;
247+
for (INT i = iRow; i < xg_nRows; ++i) {
248+
WCHAR ch = xw.GetAt(i, jCol);
249+
if (ch == ZEN_BLACK)
250+
break;
251+
ret += ch;
252+
}
253+
return ret;
254+
}
255+
return { xw.GetAt(iRow, jCol) };
256+
};
257+
258+
// 検索する。
259+
INT j = xg_caret_pos.m_j, i = xg_caret_pos.m_i;
260+
for (INT n = 0; n < xg_nRows * xg_nCols; ++n) {
261+
GetNext(j, i);
262+
auto word0 = GetHorzWord(j, i);
263+
auto j0 = word0.find(str);
264+
if (j0 != word0.npos) {
265+
xg_caret_pos.m_j = j + j0;
266+
xg_caret_pos.m_i = i;
267+
break;
268+
}
269+
auto word1 = GetVertWord(j, i);
270+
auto i0 = word1.find(str);
271+
if (i0 != word1.npos) {
272+
xg_caret_pos.m_j = j;
273+
xg_caret_pos.m_i = i + i0;
274+
break;
275+
}
276+
}
277+
}
278+
// 表示を更新する。
279+
XgEnsureCaretVisible(hwnd);
280+
XgUpdateStatusBar(hwnd);
281+
// すぐに入力できるようにする。
282+
SetFocus(hwnd);
283+
break;
184284
}
185285
}
186286
break;
@@ -201,6 +301,12 @@ class XG_JumpDialog : public XG_Dialog
201301
UpdateUI(hwnd);
202302
}
203303
break;
304+
case rad5:
305+
if (IsDlgButtonChecked(hwnd, rad5) == BST_CHECKED) {
306+
m_nType = 2;
307+
UpdateUI(hwnd);
308+
}
309+
break;
204310
default:
205311
break;
206312
}

lang/en_US.rc

+8-5
Original file line numberDiff line numberDiff line change
@@ -1469,13 +1469,14 @@ FONT 9, "Tahoma"
14691469
PUSHBUTTON "&Clear double-frame", psh5, 5, 185, 80, 17
14701470
}
14711471

1472-
IDD_JUMP DIALOG 0, 0, 193, 135
1472+
IDD_JUMP DIALOG 0, 0, 193, 185
14731473
CAPTION "Jump"
14741474
STYLE DS_CENTER | DS_MODALFRAME | WS_POPUPWINDOW | WS_CAPTION
14751475
FONT 9, "Tahoma"
14761476
{
1477-
AUTORADIOBUTTON "Jump to &position", rad1, 10, 10, 90, 15, WS_GROUP | WS_TABSTOP
1478-
AUTORADIOBUTTON "Jump to &clue", rad2, 10, 60, 90, 15, WS_TABSTOP
1477+
AUTORADIOBUTTON "Jump to &position", rad1, 10, 10, 110, 15, WS_GROUP | WS_TABSTOP
1478+
AUTORADIOBUTTON "Jump to &clue", rad2, 10, 60, 110, 15, WS_TABSTOP
1479+
AUTORADIOBUTTON "Jump to letter or &word", rad5, 10, 110, 110, 15, WS_TABSTOP
14791480
EDITTEXT edt1, 20, 35, 30, 15, ES_NUMBER | ES_AUTOHSCROLL | ES_RIGHT
14801481
CONTROL "", scr1, "msctls_updown32", UDS_ARROWKEYS | UDS_AUTOBUDDY | UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 40, 35, 10, 20
14811482
LTEXT "th from left", -1, 55, 40, 45, 10
@@ -1486,8 +1487,10 @@ FONT 9, "Tahoma"
14861487
AUTORADIOBUTTON "&Down", rad4, 75, 85, 35, 15, WS_TABSTOP
14871488
EDITTEXT edt3, 120, 85, 30, 15, ES_NUMBER | ES_AUTOHSCROLL | ES_RIGHT
14881489
CONTROL "", scr3, "msctls_updown32", UDS_ARROWKEYS | UDS_AUTOBUDDY | UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 100, 25, 10, 20
1489-
DEFPUSHBUTTON "&Jump", IDOK, 65, 115, 60, 15
1490-
PUSHBUTTON "Cancel", IDCANCEL, 130, 115, 60, 15
1490+
LTEXT "Letter or word:", -1, 27, 137, 66, 12
1491+
EDITTEXT edt4, 97, 135, 85, 14, ES_AUTOHSCROLL
1492+
DEFPUSHBUTTON "&Jump", IDOK, 65, 165, 60, 15
1493+
PUSHBUTTON "Cancel", IDCANCEL, 130, 165, 60, 15
14911494
}
14921495

14931496
IDD_FILESETTINGS DIALOG 0, 0, 270, 245

lang/ja_JP.rc

+8-5
Original file line numberDiff line numberDiff line change
@@ -1472,13 +1472,14 @@ FONT 9, "MS UI Gothic"
14721472
PUSHBUTTON "二重マス単語をクリア(&C)", psh5, 5, 185, 80, 17
14731473
}
14741474

1475-
IDD_JUMP DIALOG 0, 0, 193, 135
1475+
IDD_JUMP DIALOG 0, 0, 193, 185
14761476
CAPTION "ジャンプ"
14771477
STYLE DS_CENTER | DS_MODALFRAME | WS_POPUPWINDOW | WS_CAPTION
14781478
FONT 9, "MS UI Gothic"
14791479
{
1480-
AUTORADIOBUTTON "指定位置にジャンプ(&P)", rad1, 10, 10, 90, 15, WS_GROUP | WS_TABSTOP
1481-
AUTORADIOBUTTON "カギにジャンプ(&C)", rad2, 10, 60, 90, 15, WS_TABSTOP
1480+
AUTORADIOBUTTON "指定位置にジャンプ(&P)", rad1, 10, 10, 110, 15, WS_GROUP | WS_TABSTOP
1481+
AUTORADIOBUTTON "カギにジャンプ(&C)", rad2, 10, 60, 110, 15, WS_TABSTOP
1482+
AUTORADIOBUTTON "文字または単語にジャンプ(&W)", rad5, 10, 110, 110, 15, WS_TABSTOP
14821483
RTEXT "左から", -1, 10, 40, 30, 10
14831484
EDITTEXT edt1, 50, 35, 30, 15, ES_NUMBER | ES_AUTOHSCROLL | ES_RIGHT
14841485
CONTROL "", scr1, "msctls_updown32", UDS_ARROWKEYS | UDS_AUTOBUDDY | UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 70, 35, 10, 20
@@ -1490,8 +1491,10 @@ FONT 9, "MS UI Gothic"
14901491
AUTORADIOBUTTON "タテ(&D)", rad4, 75, 85, 35, 15, WS_TABSTOP
14911492
EDITTEXT edt3, 120, 85, 30, 15, ES_NUMBER | ES_AUTOHSCROLL | ES_RIGHT
14921493
CONTROL "", scr3, "msctls_updown32", UDS_ARROWKEYS | UDS_AUTOBUDDY | UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 100, 25, 10, 20
1493-
DEFPUSHBUTTON "ジャンプ", IDOK, 65, 115, 60, 15
1494-
PUSHBUTTON "キャンセル", IDCANCEL, 130, 115, 60, 15
1494+
LTEXT "文字または単語:", -1, 27, 137, 66, 12
1495+
EDITTEXT edt4, 97, 135, 85, 14, ES_AUTOHSCROLL
1496+
DEFPUSHBUTTON "ジャンプ", IDOK, 65, 165, 60, 15
1497+
PUSHBUTTON "キャンセル", IDCANCEL, 130, 165, 60, 15
14951498
}
14961499

14971500
IDD_FILESETTINGS DIALOG 0, 0, 270, 245

0 commit comments

Comments
 (0)