• R/O
  • SSH
  • HTTPS

ttssh2: コミット


コミットメタ情報

リビジョン7159 (tree)
日時2018-07-20 00:34:03
作者zmatsuo

ログメッセージ

dlglib.cをdlglib.cppにリネーム、
dlglib.cppインクルードヘッダファイルを最適化
vs2017のプロジェクトファイルを修正

変更サマリ

差分

--- trunk/teraterm/common/dlglib.c (revision 7158)
+++ trunk/teraterm/common/dlglib.c (revision 7159)
@@ -1,352 +0,0 @@
1-/*
2- * Copyright (C) 1994-1998 T. Teranishi
3- * (C) 2008-2018 TeraTerm Project
4- * All rights reserved.
5- *
6- * Redistribution and use in source and binary forms, with or without
7- * modification, are permitted provided that the following conditions
8- * are met:
9- *
10- * 1. Redistributions of source code must retain the above copyright
11- * notice, this list of conditions and the following disclaimer.
12- * 2. Redistributions in binary form must reproduce the above copyright
13- * notice, this list of conditions and the following disclaimer in the
14- * documentation and/or other materials provided with the distribution.
15- * 3. The name of the author may not be used to endorse or promote products
16- * derived from this software without specific prior written permission.
17- *
18- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28- */
29-
30-/* Routines for dialog boxes */
31-#include "teraterm.h"
32-#include <stdio.h>
33-#include <commctrl.h>
34-
35-void EnableDlgItem(HWND HDlg, int FirstId, int LastId)
36-{
37- int i;
38- HWND HControl;
39-
40- for (i = FirstId ; i <= LastId ; i++) {
41- HControl = GetDlgItem(HDlg, i);
42- EnableWindow(HControl,TRUE);
43- }
44-}
45-
46-void DisableDlgItem(HWND HDlg, int FirstId, int LastId)
47-{
48- int i;
49- HWND HControl;
50-
51- for (i = FirstId ; i <= LastId ; i++) {
52- HControl = GetDlgItem(HDlg, i);
53- EnableWindow(HControl,FALSE);
54- }
55-}
56-
57-void ShowDlgItem(HWND HDlg, int FirstId, int LastId)
58-{
59- int i;
60- HWND HControl;
61-
62- for (i = FirstId ; i <= LastId ; i++) {
63- HControl = GetDlgItem(HDlg, i);
64- ShowWindow(HControl,SW_SHOW);
65- }
66-}
67-
68-void SetRB(HWND HDlg, int R, int FirstId, int LastId)
69-{
70- HWND HControl;
71- DWORD Style;
72-
73- if ( R<1 ) {
74- return;
75- }
76- if ( FirstId+R-1 > LastId ) {
77- return;
78- }
79- HControl = GetDlgItem(HDlg, FirstId + R - 1);
80- SendMessage(HControl, BM_SETCHECK, 1, 0);
81- Style = GetClassLong(HControl, GCL_STYLE);
82- SetClassLong(HControl, GCL_STYLE, Style | WS_TABSTOP);
83-}
84-
85-void GetRB(HWND HDlg, LPWORD R, int FirstId, int LastId)
86-{
87- int i;
88-
89- *R = 0;
90- for (i = FirstId ; i <= LastId ; i++) {
91- if (SendDlgItemMessage(HDlg, i, BM_GETCHECK, 0, 0) != 0) {
92- *R = i - FirstId + 1;
93- return;
94- }
95- }
96-}
97-
98-void SetDlgNum(HWND HDlg, int id_Item, LONG Num)
99-{
100- char Temp[16];
101-
102- /* In Win16, SetDlgItemInt can not be used to display long integer. */
103- _snprintf_s(Temp,sizeof(Temp),_TRUNCATE,"%d",Num);
104- SetDlgItemText(HDlg,id_Item,Temp);
105-}
106-
107-void InitDlgProgress(HWND HDlg, int id_Progress, int *CurProgStat) {
108- HWND HProg;
109- HProg = GetDlgItem(HDlg, id_Progress);
110-
111- *CurProgStat = 0;
112-
113- SendMessage(HProg, PBM_SETRANGE, (WPARAM)0, MAKELPARAM(0, 100));
114- SendMessage(HProg, PBM_SETSTEP, (WPARAM)1, 0);
115- SendMessage(HProg, PBM_SETPOS, (WPARAM)0, 0);
116-
117- ShowWindow(HProg, SW_SHOW);
118- return;
119-}
120-
121-void SetDlgPercent(HWND HDlg, int id_Item, int id_Progress, LONG a, LONG b, int *p)
122-{
123- // 20MB以上のファイルをアップロードしようとすると、buffer overflowで
124- // 落ちる問題への対処。(2005.3.18 yutaka)
125- // cf. http://sourceforge.jp/tracker/index.php?func=detail&aid=5713&group_id=1412&atid=5333
126- double Num;
127- char NumStr[10];
128-
129- if (b==0) {
130- Num = 100.0;
131- }
132- else {
133- Num = 100.0 * (double)a / (double)b;
134- }
135- _snprintf_s(NumStr,sizeof(NumStr),_TRUNCATE,"%3.1f%%",Num);
136- SetDlgItemText(HDlg, id_Item, NumStr);
137-
138- if (id_Progress != 0 && p != NULL && *p >= 0 && (double)*p < Num) {
139- *p = (int)Num;
140- SendMessage(GetDlgItem(HDlg, id_Progress), PBM_SETPOS, (WPARAM)*p, 0);
141- }
142-}
143-
144-void SetDlgTime(HWND HDlg, int id_Item, DWORD stime, int bytes)
145-{
146- static int prev_elapsed;
147- int elapsed, rate;
148- char buff[64];
149-
150- elapsed = (GetTickCount() - stime) / 1000;
151-
152- if (elapsed == 0) {
153- prev_elapsed = 0;
154- SetDlgItemText(HDlg, id_Item, "0:00");
155- return;
156- }
157-
158- if (elapsed == prev_elapsed) {
159- return;
160- }
161- prev_elapsed = elapsed;
162-
163- rate = bytes / elapsed;
164- if (rate < 1200) {
165- _snprintf_s(buff, sizeof(buff), _TRUNCATE, "%d:%02d (%dBytes/s)", elapsed / 60, elapsed % 60, rate);
166- }
167- else if (rate < 1200000) {
168- _snprintf_s(buff, sizeof(buff), _TRUNCATE, "%d:%02d (%d.%02dKB/s)", elapsed / 60, elapsed % 60, rate / 1000, rate / 10 % 100);
169- }
170- else {
171- _snprintf_s(buff, sizeof(buff), _TRUNCATE, "%d:%02d (%d.%02dMB/s)", elapsed / 60, elapsed % 60, rate / (1000 * 1000), rate / 10000 % 100);
172- }
173-
174- SetDlgItemText(HDlg, id_Item, buff);
175-}
176-
177-void SetDropDownList(HWND HDlg, int Id_Item, const TCHAR **List, int nsel)
178-{
179- int i;
180-
181- i = 0;
182- while (List[i] != NULL) {
183- SendDlgItemMessage(HDlg, Id_Item, CB_ADDSTRING,
184- 0, (LPARAM)List[i]);
185- i++;
186- }
187- SendDlgItemMessage(HDlg, Id_Item, CB_SETCURSEL,nsel-1,0);
188-}
189-
190-LONG GetCurSel(HWND HDlg, int Id_Item)
191-{
192- LONG n;
193-
194- n = SendDlgItemMessage(HDlg, Id_Item, CB_GETCURSEL, 0, 0);
195- if (n==CB_ERR) {
196- n = 0;
197- }
198- else {
199- n++;
200- }
201-
202- return n;
203-}
204-
205-typedef struct {
206- WNDPROC OrigProc; // Original window procedure
207- LONG_PTR OrigUser; // DWLP_USER
208- BOOL ComboBox;
209-} EditSubclassData;
210-
211-// C-n/C-p のためにサブクラス化 (2007.9.4 maya)
212-// C-p/C-n/C-b/C-f/C-a/C-e をサポート (2007.9.5 maya)
213-// C-d/C-k をサポート (2007.10.3 yutaka)
214-// ドロップダウンの中のエディットコントロールを
215-// サブクラス化するためのウインドウプロシージャ
216-static LRESULT CALLBACK HostnameEditProc(HWND dlg, UINT msg,
217- WPARAM wParam, LPARAM lParam)
218-{
219- EditSubclassData *data = (EditSubclassData *)GetWindowLong(dlg, GWLP_USERDATA);
220- int max, select, len;
221- char *str, *orgstr;
222-
223- switch (msg) {
224- // キーが押されたのを検知する
225- case WM_KEYDOWN:
226- if (GetKeyState(VK_CONTROL) < 0) {
227- switch (wParam) {
228- case 0x50: // Ctrl+p ... up
229- if (data->ComboBox) {
230- HWND parent = GetParent(dlg);
231- select = SendMessage(parent, CB_GETCURSEL, 0, 0);
232- if (select > 0) {
233- PostMessage(parent, CB_SETCURSEL, select - 1, 0);
234- }
235- return 0;
236- }
237- break;
238- case 0x4e: // Ctrl+n ... down
239- if (data->ComboBox) {
240- HWND parent = GetParent(dlg);
241- max = SendMessage(parent, CB_GETCOUNT, 0, 0);
242- select = SendMessage(parent, CB_GETCURSEL, 0, 0);
243- if (select < max - 1) {
244- PostMessage(parent, CB_SETCURSEL, select + 1, 0);
245- }
246- return 0;
247- }
248- break;
249- case 0x42: // Ctrl+b ... left
250- SendMessage(dlg, EM_GETSEL, 0, (LPARAM)&select);
251- PostMessage(dlg, EM_SETSEL, select-1, select-1);
252- return 0;
253- case 0x46: // Ctrl+f ... right
254- SendMessage(dlg, EM_GETSEL, 0, (LPARAM)&select);
255- max = GetWindowTextLength(dlg) ;
256- PostMessage(dlg, EM_SETSEL, select+1, select+1);
257- return 0;
258- case 0x41: // Ctrl+a ... home
259- PostMessage(dlg, EM_SETSEL, 0, 0);
260- return 0;
261- case 0x45: // Ctrl+e ... end
262- max = GetWindowTextLength(dlg) ;
263- PostMessage(dlg, EM_SETSEL, max, max);
264- return 0;
265-
266- case 0x44: // Ctrl+d
267- case 0x4b: // Ctrl+k
268- case 0x55: // Ctrl+u
269- SendMessage(dlg, EM_GETSEL, 0, (LPARAM)&select);
270- max = GetWindowTextLength(dlg);
271- max++; // '\0'
272- orgstr = str = malloc(max);
273- if (str != NULL) {
274- len = GetWindowText(dlg, str, max);
275- if (select >= 0 && select < len) {
276- if (wParam == 0x44) { // カーソル配下の文字のみを削除する
277- memmove(&str[select], &str[select + 1], len - select - 1);
278- str[len - 1] = '\0';
279-
280- } else if (wParam == 0x4b) { // カーソルから行末まで削除する
281- str[select] = '\0';
282-
283- }
284- }
285-
286- if (wParam == 0x55) { // カーソルより左側をすべて消す
287- if (select >= len) {
288- str[0] = '\0';
289- } else {
290- str = &str[select];
291- }
292- select = 0;
293- }
294-
295- SetWindowText(dlg, str);
296- SendMessage(dlg, EM_SETSEL, select, select);
297- free(orgstr);
298- return 0;
299- }
300- break;
301- }
302- }
303- break;
304-
305- // 上のキーを押した結果送られる文字で音が鳴るので捨てる
306- case WM_CHAR:
307- switch (wParam) {
308- case 0x01:
309- case 0x02:
310- case 0x04:
311- case 0x05:
312- case 0x06:
313- case 0x0b:
314- case 0x0e:
315- case 0x10:
316- case 0x15:
317- return 0;
318- }
319- break;
320- }
321-
322- SetWindowLong(dlg, GWL_WNDPROC, (LONG_PTR)data->OrigProc);
323- SetWindowLong(dlg, GWLP_USERDATA, (LONG_PTR)data->OrigUser);
324- LRESULT Result = CallWindowProc(data->OrigProc, dlg, msg, wParam, lParam);
325- SetWindowLong(dlg, GWL_WNDPROC, (LONG_PTR)HostnameEditProc);
326- SetWindowLong(dlg, GWLP_USERDATA, (LONG_PTR)data);
327-
328- switch (msg) {
329- case WM_DESTROY:
330- SetWindowLong(dlg, GWL_WNDPROC, (LONG_PTR)data->OrigProc);
331- SetWindowLong(dlg, GWLP_USERDATA, (LONG_PTR)data->OrigUser);
332- free(data);
333- break;
334- }
335-
336- return Result;
337-}
338-
339-// C-n/C-p のためにサブクラス化
340-void SetEditboxSubclass(HWND hDlg, int nID, BOOL ComboBox)
341-{
342- HWND hWndEdit = GetDlgItem(hDlg, nID);
343- if (ComboBox) {
344- hWndEdit = GetWindow(hWndEdit, GW_CHILD);
345- }
346- EditSubclassData *data = (EditSubclassData *)malloc(sizeof(EditSubclassData));
347- data->OrigProc = (WNDPROC)GetWindowLong(hWndEdit, GWL_WNDPROC);
348- data->OrigUser = (LONG_PTR)GetWindowLong(hWndEdit, GWLP_USERDATA);
349- data->ComboBox = ComboBox;
350- SetWindowLong(hWndEdit, GWL_WNDPROC, (LONG_PTR)HostnameEditProc);
351- SetWindowLong(hWndEdit, GWLP_USERDATA, (LONG_PTR)data);
352-}
--- trunk/teraterm/common/dlglib.cpp (revision 0)
+++ trunk/teraterm/common/dlglib.cpp (revision 7159)
@@ -0,0 +1,353 @@
1+/*
2+ * Copyright (C) 1994-1998 T. Teranishi
3+ * (C) 2008-2018 TeraTerm Project
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions
8+ * are met:
9+ *
10+ * 1. Redistributions of source code must retain the above copyright
11+ * notice, this list of conditions and the following disclaimer.
12+ * 2. Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ * 3. The name of the author may not be used to endorse or promote products
16+ * derived from this software without specific prior written permission.
17+ *
18+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+ */
29+
30+/* Routines for dialog boxes */
31+#include <windows.h>
32+#include "dlglib.h"
33+#include <stdio.h>
34+#include <commctrl.h>
35+
36+void EnableDlgItem(HWND HDlg, int FirstId, int LastId)
37+{
38+ int i;
39+ HWND HControl;
40+
41+ for (i = FirstId ; i <= LastId ; i++) {
42+ HControl = GetDlgItem(HDlg, i);
43+ EnableWindow(HControl,TRUE);
44+ }
45+}
46+
47+void DisableDlgItem(HWND HDlg, int FirstId, int LastId)
48+{
49+ int i;
50+ HWND HControl;
51+
52+ for (i = FirstId ; i <= LastId ; i++) {
53+ HControl = GetDlgItem(HDlg, i);
54+ EnableWindow(HControl,FALSE);
55+ }
56+}
57+
58+void ShowDlgItem(HWND HDlg, int FirstId, int LastId)
59+{
60+ int i;
61+ HWND HControl;
62+
63+ for (i = FirstId ; i <= LastId ; i++) {
64+ HControl = GetDlgItem(HDlg, i);
65+ ShowWindow(HControl,SW_SHOW);
66+ }
67+}
68+
69+void SetRB(HWND HDlg, int R, int FirstId, int LastId)
70+{
71+ HWND HControl;
72+ DWORD Style;
73+
74+ if ( R<1 ) {
75+ return;
76+ }
77+ if ( FirstId+R-1 > LastId ) {
78+ return;
79+ }
80+ HControl = GetDlgItem(HDlg, FirstId + R - 1);
81+ SendMessage(HControl, BM_SETCHECK, 1, 0);
82+ Style = GetClassLong(HControl, GCL_STYLE);
83+ SetClassLong(HControl, GCL_STYLE, Style | WS_TABSTOP);
84+}
85+
86+void GetRB(HWND HDlg, LPWORD R, int FirstId, int LastId)
87+{
88+ int i;
89+
90+ *R = 0;
91+ for (i = FirstId ; i <= LastId ; i++) {
92+ if (SendDlgItemMessage(HDlg, i, BM_GETCHECK, 0, 0) != 0) {
93+ *R = i - FirstId + 1;
94+ return;
95+ }
96+ }
97+}
98+
99+void SetDlgNum(HWND HDlg, int id_Item, LONG Num)
100+{
101+ char Temp[16];
102+
103+ /* In Win16, SetDlgItemInt can not be used to display long integer. */
104+ _snprintf_s(Temp,sizeof(Temp),_TRUNCATE,"%d",Num);
105+ SetDlgItemText(HDlg,id_Item,Temp);
106+}
107+
108+void InitDlgProgress(HWND HDlg, int id_Progress, int *CurProgStat) {
109+ HWND HProg;
110+ HProg = GetDlgItem(HDlg, id_Progress);
111+
112+ *CurProgStat = 0;
113+
114+ SendMessage(HProg, PBM_SETRANGE, (WPARAM)0, MAKELPARAM(0, 100));
115+ SendMessage(HProg, PBM_SETSTEP, (WPARAM)1, 0);
116+ SendMessage(HProg, PBM_SETPOS, (WPARAM)0, 0);
117+
118+ ShowWindow(HProg, SW_SHOW);
119+ return;
120+}
121+
122+void SetDlgPercent(HWND HDlg, int id_Item, int id_Progress, LONG a, LONG b, int *p)
123+{
124+ // 20MB以上のファイルをアップロードしようとすると、buffer overflowで
125+ // 落ちる問題への対処。(2005.3.18 yutaka)
126+ // cf. http://sourceforge.jp/tracker/index.php?func=detail&aid=5713&group_id=1412&atid=5333
127+ double Num;
128+ char NumStr[10];
129+
130+ if (b==0) {
131+ Num = 100.0;
132+ }
133+ else {
134+ Num = 100.0 * (double)a / (double)b;
135+ }
136+ _snprintf_s(NumStr,sizeof(NumStr),_TRUNCATE,"%3.1f%%",Num);
137+ SetDlgItemText(HDlg, id_Item, NumStr);
138+
139+ if (id_Progress != 0 && p != NULL && *p >= 0 && (double)*p < Num) {
140+ *p = (int)Num;
141+ SendMessage(GetDlgItem(HDlg, id_Progress), PBM_SETPOS, (WPARAM)*p, 0);
142+ }
143+}
144+
145+void SetDlgTime(HWND HDlg, int id_Item, DWORD stime, int bytes)
146+{
147+ static int prev_elapsed;
148+ int elapsed, rate;
149+ char buff[64];
150+
151+ elapsed = (GetTickCount() - stime) / 1000;
152+
153+ if (elapsed == 0) {
154+ prev_elapsed = 0;
155+ SetDlgItemText(HDlg, id_Item, "0:00");
156+ return;
157+ }
158+
159+ if (elapsed == prev_elapsed) {
160+ return;
161+ }
162+ prev_elapsed = elapsed;
163+
164+ rate = bytes / elapsed;
165+ if (rate < 1200) {
166+ _snprintf_s(buff, sizeof(buff), _TRUNCATE, "%d:%02d (%dBytes/s)", elapsed / 60, elapsed % 60, rate);
167+ }
168+ else if (rate < 1200000) {
169+ _snprintf_s(buff, sizeof(buff), _TRUNCATE, "%d:%02d (%d.%02dKB/s)", elapsed / 60, elapsed % 60, rate / 1000, rate / 10 % 100);
170+ }
171+ else {
172+ _snprintf_s(buff, sizeof(buff), _TRUNCATE, "%d:%02d (%d.%02dMB/s)", elapsed / 60, elapsed % 60, rate / (1000 * 1000), rate / 10000 % 100);
173+ }
174+
175+ SetDlgItemText(HDlg, id_Item, buff);
176+}
177+
178+void SetDropDownList(HWND HDlg, int Id_Item, const TCHAR **List, int nsel)
179+{
180+ int i;
181+
182+ i = 0;
183+ while (List[i] != NULL) {
184+ SendDlgItemMessage(HDlg, Id_Item, CB_ADDSTRING,
185+ 0, (LPARAM)List[i]);
186+ i++;
187+ }
188+ SendDlgItemMessage(HDlg, Id_Item, CB_SETCURSEL,nsel-1,0);
189+}
190+
191+LONG GetCurSel(HWND HDlg, int Id_Item)
192+{
193+ LONG n;
194+
195+ n = SendDlgItemMessage(HDlg, Id_Item, CB_GETCURSEL, 0, 0);
196+ if (n==CB_ERR) {
197+ n = 0;
198+ }
199+ else {
200+ n++;
201+ }
202+
203+ return n;
204+}
205+
206+typedef struct {
207+ WNDPROC OrigProc; // Original window procedure
208+ LONG_PTR OrigUser; // DWLP_USER
209+ BOOL ComboBox;
210+} EditSubclassData;
211+
212+// C-n/C-p のためにサブクラス化 (2007.9.4 maya)
213+// C-p/C-n/C-b/C-f/C-a/C-e をサポート (2007.9.5 maya)
214+// C-d/C-k をサポート (2007.10.3 yutaka)
215+// ドロップダウンの中のエディットコントロールを
216+// サブクラス化するためのウインドウプロシージャ
217+static LRESULT CALLBACK HostnameEditProc(HWND dlg, UINT msg,
218+ WPARAM wParam, LPARAM lParam)
219+{
220+ EditSubclassData *data = (EditSubclassData *)GetWindowLong(dlg, GWLP_USERDATA);
221+ int max, select, len;
222+ char *str, *orgstr;
223+
224+ switch (msg) {
225+ // キーが押されたのを検知する
226+ case WM_KEYDOWN:
227+ if (GetKeyState(VK_CONTROL) < 0) {
228+ switch (wParam) {
229+ case 0x50: // Ctrl+p ... up
230+ if (data->ComboBox) {
231+ HWND parent = GetParent(dlg);
232+ select = SendMessage(parent, CB_GETCURSEL, 0, 0);
233+ if (select > 0) {
234+ PostMessage(parent, CB_SETCURSEL, select - 1, 0);
235+ }
236+ return 0;
237+ }
238+ break;
239+ case 0x4e: // Ctrl+n ... down
240+ if (data->ComboBox) {
241+ HWND parent = GetParent(dlg);
242+ max = SendMessage(parent, CB_GETCOUNT, 0, 0);
243+ select = SendMessage(parent, CB_GETCURSEL, 0, 0);
244+ if (select < max - 1) {
245+ PostMessage(parent, CB_SETCURSEL, select + 1, 0);
246+ }
247+ return 0;
248+ }
249+ break;
250+ case 0x42: // Ctrl+b ... left
251+ SendMessage(dlg, EM_GETSEL, 0, (LPARAM)&select);
252+ PostMessage(dlg, EM_SETSEL, select-1, select-1);
253+ return 0;
254+ case 0x46: // Ctrl+f ... right
255+ SendMessage(dlg, EM_GETSEL, 0, (LPARAM)&select);
256+ max = GetWindowTextLength(dlg) ;
257+ PostMessage(dlg, EM_SETSEL, select+1, select+1);
258+ return 0;
259+ case 0x41: // Ctrl+a ... home
260+ PostMessage(dlg, EM_SETSEL, 0, 0);
261+ return 0;
262+ case 0x45: // Ctrl+e ... end
263+ max = GetWindowTextLength(dlg) ;
264+ PostMessage(dlg, EM_SETSEL, max, max);
265+ return 0;
266+
267+ case 0x44: // Ctrl+d
268+ case 0x4b: // Ctrl+k
269+ case 0x55: // Ctrl+u
270+ SendMessage(dlg, EM_GETSEL, 0, (LPARAM)&select);
271+ max = GetWindowTextLength(dlg);
272+ max++; // '\0'
273+ orgstr = str = (char *)malloc(max);
274+ if (str != NULL) {
275+ len = GetWindowText(dlg, str, max);
276+ if (select >= 0 && select < len) {
277+ if (wParam == 0x44) { // カーソル配下の文字のみを削除する
278+ memmove(&str[select], &str[select + 1], len - select - 1);
279+ str[len - 1] = '\0';
280+
281+ } else if (wParam == 0x4b) { // カーソルから行末まで削除する
282+ str[select] = '\0';
283+
284+ }
285+ }
286+
287+ if (wParam == 0x55) { // カーソルより左側をすべて消す
288+ if (select >= len) {
289+ str[0] = '\0';
290+ } else {
291+ str = &str[select];
292+ }
293+ select = 0;
294+ }
295+
296+ SetWindowText(dlg, str);
297+ SendMessage(dlg, EM_SETSEL, select, select);
298+ free(orgstr);
299+ return 0;
300+ }
301+ break;
302+ }
303+ }
304+ break;
305+
306+ // 上のキーを押した結果送られる文字で音が鳴るので捨てる
307+ case WM_CHAR:
308+ switch (wParam) {
309+ case 0x01:
310+ case 0x02:
311+ case 0x04:
312+ case 0x05:
313+ case 0x06:
314+ case 0x0b:
315+ case 0x0e:
316+ case 0x10:
317+ case 0x15:
318+ return 0;
319+ }
320+ break;
321+ }
322+
323+ SetWindowLongPtr(dlg, GWLP_WNDPROC, (LONG_PTR)data->OrigProc);
324+ SetWindowLongPtr(dlg, GWLP_USERDATA, (LONG_PTR)data->OrigUser);
325+ const LRESULT Result = CallWindowProc(data->OrigProc, dlg, msg, wParam, lParam);
326+ SetWindowLongPtr(dlg, GWLP_WNDPROC, (LONG_PTR)HostnameEditProc);
327+ SetWindowLongPtr(dlg, GWLP_USERDATA, (LONG_PTR)data);
328+
329+ switch (msg) {
330+ case WM_DESTROY:
331+ SetWindowLongPtr(dlg, GWLP_WNDPROC, (LONG_PTR)data->OrigProc);
332+ SetWindowLongPtr(dlg, GWLP_USERDATA, (LONG_PTR)data->OrigUser);
333+ free(data);
334+ break;
335+ }
336+
337+ return Result;
338+}
339+
340+// C-n/C-p のためにサブクラス化
341+void SetEditboxSubclass(HWND hDlg, int nID, BOOL ComboBox)
342+{
343+ HWND hWndEdit = GetDlgItem(hDlg, nID);
344+ if (ComboBox) {
345+ hWndEdit = GetWindow(hWndEdit, GW_CHILD);
346+ }
347+ EditSubclassData *data = (EditSubclassData *)malloc(sizeof(EditSubclassData));
348+ data->OrigProc = (WNDPROC)GetWindowLong(hWndEdit, GWLP_WNDPROC);
349+ data->OrigUser = (LONG_PTR)GetWindowLong(hWndEdit, GWLP_USERDATA);
350+ data->ComboBox = ComboBox;
351+ SetWindowLongPtr(hWndEdit, GWL_WNDPROC, (LONG_PTR)HostnameEditProc);
352+ SetWindowLongPtr(hWndEdit, GWLP_USERDATA, (LONG_PTR)data);
353+}
旧リポジトリブラウザで表示