• R/O
  • SSH
  • HTTPS

ttssh2: コミット


コミットメタ情報

リビジョン7165 (tree)
日時2018-07-24 12:47:23
作者zmatsuo

ログメッセージ

merge trunk 7164

変更サマリ

差分

--- branches/cmake/teraterm/common/dlglib.cpp (revision 7164)
+++ branches/cmake/teraterm/common/dlglib.cpp (nonexistent)
@@ -1,353 +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 <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-}
--- branches/cmake/teraterm/common/dlglib.c (nonexistent)
+++ branches/cmake/teraterm/common/dlglib.c (revision 7165)
@@ -0,0 +1,355 @@
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+ LRESULT Result;
222+ int max, select, len;
223+ char *str, *orgstr;
224+
225+ switch (msg) {
226+ // キーが押されたのを検知する
227+ case WM_KEYDOWN:
228+ if (GetKeyState(VK_CONTROL) < 0) {
229+ switch (wParam) {
230+ case 0x50: // Ctrl+p ... up
231+ if (data->ComboBox) {
232+ HWND parent = GetParent(dlg);
233+ select = SendMessage(parent, CB_GETCURSEL, 0, 0);
234+ if (select > 0) {
235+ PostMessage(parent, CB_SETCURSEL, select - 1, 0);
236+ }
237+ return 0;
238+ }
239+ break;
240+ case 0x4e: // Ctrl+n ... down
241+ if (data->ComboBox) {
242+ HWND parent = GetParent(dlg);
243+ max = SendMessage(parent, CB_GETCOUNT, 0, 0);
244+ select = SendMessage(parent, CB_GETCURSEL, 0, 0);
245+ if (select < max - 1) {
246+ PostMessage(parent, CB_SETCURSEL, select + 1, 0);
247+ }
248+ return 0;
249+ }
250+ break;
251+ case 0x42: // Ctrl+b ... left
252+ SendMessage(dlg, EM_GETSEL, 0, (LPARAM)&select);
253+ PostMessage(dlg, EM_SETSEL, select-1, select-1);
254+ return 0;
255+ case 0x46: // Ctrl+f ... right
256+ SendMessage(dlg, EM_GETSEL, 0, (LPARAM)&select);
257+ max = GetWindowTextLength(dlg) ;
258+ PostMessage(dlg, EM_SETSEL, select+1, select+1);
259+ return 0;
260+ case 0x41: // Ctrl+a ... home
261+ PostMessage(dlg, EM_SETSEL, 0, 0);
262+ return 0;
263+ case 0x45: // Ctrl+e ... end
264+ max = GetWindowTextLength(dlg) ;
265+ PostMessage(dlg, EM_SETSEL, max, max);
266+ return 0;
267+
268+ case 0x44: // Ctrl+d
269+ case 0x4b: // Ctrl+k
270+ case 0x55: // Ctrl+u
271+ SendMessage(dlg, EM_GETSEL, 0, (LPARAM)&select);
272+ max = GetWindowTextLength(dlg);
273+ max++; // '\0'
274+ orgstr = str = (char *)malloc(max);
275+ if (str != NULL) {
276+ len = GetWindowText(dlg, str, max);
277+ if (select >= 0 && select < len) {
278+ if (wParam == 0x44) { // カーソル配下の文字のみを削除する
279+ memmove(&str[select], &str[select + 1], len - select - 1);
280+ str[len - 1] = '\0';
281+
282+ } else if (wParam == 0x4b) { // カーソルから行末まで削除する
283+ str[select] = '\0';
284+
285+ }
286+ }
287+
288+ if (wParam == 0x55) { // カーソルより左側をすべて消す
289+ if (select >= len) {
290+ str[0] = '\0';
291+ } else {
292+ str = &str[select];
293+ }
294+ select = 0;
295+ }
296+
297+ SetWindowText(dlg, str);
298+ SendMessage(dlg, EM_SETSEL, select, select);
299+ free(orgstr);
300+ return 0;
301+ }
302+ break;
303+ }
304+ }
305+ break;
306+
307+ // 上のキーを押した結果送られる文字で音が鳴るので捨てる
308+ case WM_CHAR:
309+ switch (wParam) {
310+ case 0x01:
311+ case 0x02:
312+ case 0x04:
313+ case 0x05:
314+ case 0x06:
315+ case 0x0b:
316+ case 0x0e:
317+ case 0x10:
318+ case 0x15:
319+ return 0;
320+ }
321+ break;
322+ }
323+
324+ SetWindowLongPtr(dlg, GWLP_WNDPROC, (LONG_PTR)data->OrigProc);
325+ SetWindowLongPtr(dlg, GWLP_USERDATA, (LONG_PTR)data->OrigUser);
326+ Result = CallWindowProc(data->OrigProc, dlg, msg, wParam, lParam);
327+ SetWindowLongPtr(dlg, GWLP_WNDPROC, (LONG_PTR)HostnameEditProc);
328+ SetWindowLongPtr(dlg, GWLP_USERDATA, (LONG_PTR)data);
329+
330+ switch (msg) {
331+ case WM_DESTROY:
332+ SetWindowLongPtr(dlg, GWLP_WNDPROC, (LONG_PTR)data->OrigProc);
333+ SetWindowLongPtr(dlg, GWLP_USERDATA, (LONG_PTR)data->OrigUser);
334+ free(data);
335+ break;
336+ }
337+
338+ return Result;
339+}
340+
341+// C-n/C-p のためにサブクラス化
342+void SetEditboxSubclass(HWND hDlg, int nID, BOOL ComboBox)
343+{
344+ EditSubclassData *data;
345+ HWND hWndEdit = GetDlgItem(hDlg, nID);
346+ if (ComboBox) {
347+ hWndEdit = GetWindow(hWndEdit, GW_CHILD);
348+ }
349+ data = (EditSubclassData *)malloc(sizeof(EditSubclassData));
350+ data->OrigProc = (WNDPROC)GetWindowLong(hWndEdit, GWLP_WNDPROC);
351+ data->OrigUser = (LONG_PTR)GetWindowLong(hWndEdit, GWLP_USERDATA);
352+ data->ComboBox = ComboBox;
353+ SetWindowLongPtr(hWndEdit, GWL_WNDPROC, (LONG_PTR)HostnameEditProc);
354+ SetWindowLongPtr(hWndEdit, GWLP_USERDATA, (LONG_PTR)data);
355+}
旧リポジトリブラウザで表示