Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/sendfiledlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8621 - (hide annotations) (download) (as text)
Wed Mar 25 14:27:06 2020 UTC (4 years ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/sendfiledlg.cpp
File MIME type: text/x-c++src
File size: 11667 byte(s)
変数名、lngのキーを適切な名前に修正

- ダイアログのデザインなどが変化するかもしれないのでlngは未着手
1 zmatsuo 8618 /*
2     * (C) 2020 TeraTerm Project
3     * All rights reserved.
4     *
5     * Redistribution and use in source and binary forms, with or without
6     * modification, are permitted provided that the following conditions
7     * are met:
8     *
9     * 1. Redistributions of source code must retain the above copyright
10     * notice, this list of conditions and the following disclaimer.
11     * 2. Redistributions in binary form must reproduce the above copyright
12     * notice, this list of conditions and the following disclaimer in the
13     * documentation and/or other materials provided with the distribution.
14     * 3. The name of the author may not be used to endorse or promote products
15     * derived from this software without specific prior written permission.
16     *
17     * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27     */
28 zmatsuo 8588
29     #include <windows.h>
30     #include <stdio.h>
31     #define _CRTDBG_MAP_ALLOC
32     #include <stdlib.h>
33     #include <crtdbg.h>
34     #include <wchar.h>
35    
36     #include "i18n.h"
37     #include "tt_res.h"
38     #include "ttlib.h"
39     #include "dlglib.h"
40     #include "layer_for_unicode.h"
41     #include "tttypes.h" // for WM_USER_DLGHELP2
42     #include "helpid.h"
43     #include "codeconv.h"
44     #include "ttftypes.h" // for TitSendFile
45 zmatsuo 8618 #include "asprintf.h"
46 zmatsuo 8588
47     #include "sendfiledlg.h"
48    
49 zmatsuo 8621 #define TitSendFileW L"Send file" // TODO ttftype.h����ANSI��������
50    
51 zmatsuo 8588 /**
52     * GetOpenFileName(), GetSaveFileName() �p�t�B���^����������
53     *
54     * @param[in] user_filter_mask ���[�U�[�t�B���^������
55     * "*.txt", "*.txt;*.log" ����
56     * NULL�������g�p������
57     * @param[in] UILanguageFile
58     * @param[out] len ����������������(wchar_t�P��)
59     * NULL����������������
60     * @retval "User define(*.txt)\0*.txt\0All(*.*)\0*.*\0" ����
61     * �I�[�� "\0\0" ������
62     */
63     static wchar_t *GetCommonDialogFilterW(const char *user_filter_mask, const char *UILanguageFile, size_t *len)
64     {
65     // "���[�U���`(*.txt)\0*.txt"
66     wchar_t *user_filter_str = NULL;
67     size_t user_filter_len = 0;
68     if (user_filter_mask != NULL && user_filter_mask[0] != 0) {
69     wchar_t user_filter_name[MAX_UIMSG];
70     get_lang_msgW("FILEDLG_USER_FILTER_NAME", user_filter_name, sizeof(user_filter_name), L"User define",
71     UILanguageFile);
72     size_t user_filter_name_len = wcslen(user_filter_name);
73     wchar_t *user_filter_maskW = ToWcharA(user_filter_mask);
74     size_t user_filter_mask_len = wcslen(user_filter_maskW);
75     user_filter_len = user_filter_name_len + 1 + user_filter_mask_len + 1 + 1 + user_filter_mask_len + 1;
76     user_filter_str = (wchar_t *)malloc(user_filter_len * sizeof(wchar_t));
77     wchar_t *p = user_filter_str;
78     wmemcpy(p, user_filter_name, user_filter_name_len);
79     p += user_filter_name_len;
80     *p++ = '(';
81     wmemcpy(p, user_filter_maskW, user_filter_mask_len);
82     p += user_filter_mask_len;
83     *p++ = ')';
84     *p++ = '\0';
85     wmemcpy(p, user_filter_maskW, user_filter_mask_len);
86     p += user_filter_mask_len;
87     *p++ = '\0';
88     free(user_filter_maskW);
89     }
90    
91     // "���������t�@�C��(*.*)\0*.*"
92     wchar_t all_filter_str[MAX_UIMSG];
93     get_lang_msgW("FILEDLG_ALL_FILTER", all_filter_str, _countof(all_filter_str), L"All(*.*)\\0*.*", UILanguageFile);
94     size_t all_filter_len;
95     {
96     size_t all_filter_title_len = wcsnlen(all_filter_str, _countof(all_filter_str));
97     if (all_filter_title_len == 0 || all_filter_title_len == _countof(all_filter_str)) {
98     all_filter_str[0] = 0;
99     all_filter_len = 0;
100     } else {
101     size_t all_filter_mask_max = _countof(all_filter_str) - all_filter_title_len - 1;
102     size_t all_filter_mask_len = wcsnlen(all_filter_str + all_filter_title_len + 1, all_filter_mask_max);
103     if (all_filter_mask_len == 0 || all_filter_mask_len == _countof(all_filter_str)) {
104     all_filter_str[0] = 0;
105     all_filter_len = 0;
106     } else {
107     all_filter_len = all_filter_title_len + 1 + all_filter_mask_len + 1;
108     }
109     }
110     }
111    
112     // �t�B���^������������
113     size_t filter_len = user_filter_len + all_filter_len;
114     wchar_t* filter_str;
115     if (filter_len != 0) {
116     filter_len++;
117     filter_str = (wchar_t*)malloc(filter_len * sizeof(wchar_t));
118     wchar_t *p = filter_str;
119     if (user_filter_len != 0) {
120     wmemcpy(p, user_filter_str, user_filter_len);
121     p += user_filter_len;
122     }
123     wmemcpy(p, all_filter_str, all_filter_len);
124     p += all_filter_len;
125     *p = '\0';
126     } else {
127     filter_len = 2;
128     filter_str = (wchar_t*)malloc(filter_len * sizeof(wchar_t));
129     filter_str[0] = 0;
130     filter_str[1] = 0;
131     }
132    
133     if (user_filter_len != 0) {
134     free(user_filter_str);
135     }
136    
137     if (len != NULL) {
138     *len = filter_len;
139     }
140     return filter_str;
141     }
142    
143     static INT_PTR CALLBACK SendFileDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
144     {
145     static const DlgTextInfo TextInfos[] = {
146     {0, "FILEDLG_TRANS_TITLE_SENDFILE"},
147     {IDC_SENDFILE_FILENAME_TITLE, "DLG_SENDFILE_FILENAME_TITLE"},
148     {IDC_SENDFILE_CHECK_BINARY, "DLG_FOPT_BINARY"},
149 zmatsuo 8621 {IDC_SENDFILE_DELAYTYPE_LABEL, "DLG_SENDFILE_DELAYTYPE_TITLE"},
150     {IDC_SENDFILE_SEND_SIZE_LABEL, "DLG_SENDFILE_SEND_SIZE_TITLE"},
151     {IDC_SENDFILE_DELAYTIME_LABEL, "DLG_SENDFILE_DELAYTIME_TITLE"},
152 zmatsuo 8588 {IDCANCEL, "BTN_CANCEL"},
153     {IDOK, "BTN_OK"},
154     };
155 zmatsuo 8621 static const I18nTextInfo delaytype_list[] = {
156 zmatsuo 8588 {"DLG_SENDFILE_DELAYTYPE_NO_DELAY", L"no delay"},
157     {"DLG_SENDFILE_DELAYTYPE_PER_CHAR", L"per charactor"},
158     {"DLG_SENDFILE_DELAYTYPE_PER_LINE", L"per line"},
159     {"DLG_SENDFILE_DELAYTYPE_PER_SENDSIZE", L"per sendsize"},
160     };
161     static const int send_size_list[] = {16, 256, 4 * 1024};
162     sendfiledlgdata *data = (sendfiledlgdata *)GetWindowLongPtr(hDlgWnd, DWLP_USER);
163     int i;
164    
165     switch (msg) {
166     case WM_INITDIALOG:
167     data = (sendfiledlgdata *)lp;
168     data->MsgDlgHelp = RegisterWindowMessage(HELPMSGSTRING);
169     SetWindowLongPtr(hDlgWnd, DWLP_USER, (LONG_PTR)data);
170     ::DragAcceptFiles(hDlgWnd, TRUE);
171     SetDlgTexts(hDlgWnd, TextInfos, _countof(TextInfos), data->UILanguageFile);
172     CenterWindow(hDlgWnd, GetParent(hDlgWnd));
173    
174 zmatsuo 8621 SetI18nList("TeraTerm", hDlgWnd, IDC_SENDFILE_DELAYTYPE_DROPDOWN, delaytype_list, _countof(delaytype_list),
175     data->UILanguageFile, 0);
176 zmatsuo 8588
177     for (i = 0; i < _countof(send_size_list); i++) {
178     char buf[32];
179     sprintf(buf, "%d", send_size_list[i]);
180     SendDlgItemMessageA(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN, CB_ADDSTRING, 0, (LPARAM)buf);
181     }
182     SendDlgItemMessage(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN, CB_SETCURSEL, _countof(send_size_list) - 1, 0);
183    
184     SetDlgItemTextA(hDlgWnd, IDC_SENDFILE_DELAYTIME_EDIT, "1");
185    
186     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN), FALSE);
187     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_DELAYTIME_EDIT), FALSE);
188    
189     return TRUE;
190    
191     case WM_COMMAND:
192     switch (wp) {
193     case IDOK | (BN_CLICKED << 16): {
194 zmatsuo 8618 wchar_t *strW = AllocControlTextW(GetDlgItem(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT));
195 zmatsuo 8588
196     const DWORD attr = _GetFileAttributesW(strW);
197     if (attr == INVALID_FILE_ATTRIBUTES || attr & FILE_ATTRIBUTE_DIRECTORY) {
198 zmatsuo 8618 static const TTMessageBoxInfoW mbinfo = {
199     "Tera Term",
200     "MSG_TT_ERROR", L"Tera Term: Error",
201     "MSG_CANTOPEN_FILE_ERROR", L"Cannot open file" };
202     TTMessageBoxW(hDlgWnd, &mbinfo, MB_TASKMODAL | MB_ICONEXCLAMATION, data->UILanguageFile);
203 zmatsuo 8588
204     free(strW);
205    
206     PostMessage(hDlgWnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT),
207     TRUE);
208    
209     return TRUE;
210     }
211    
212     data->filename = strW;
213     data->binary =
214     SendMessage(GetDlgItem(hDlgWnd, IDC_SENDFILE_CHECK_BINARY), BM_GETCHECK, 0, 0) == BST_CHECKED
215     ? TRUE
216     : FALSE;
217     data->delay_type = (int)SendDlgItemMessage(hDlgWnd, IDC_SENDFILE_DELAYTYPE_DROPDOWN, CB_GETCURSEL, 0, 0);
218     data->delay_tick = GetDlgItemInt(hDlgWnd, IDC_SENDFILE_DELAYTIME_EDIT, NULL, FALSE);
219     data->send_size = GetDlgItemInt(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN, NULL, FALSE);
220    
221     TTEndDialog(hDlgWnd, IDOK);
222     return TRUE;
223     }
224    
225     case IDHELP | (BN_CLICKED << 16):
226     PostMessage(GetParent(hDlgWnd), WM_USER_DLGHELP2, HlpMenuFileSendfile, 0);
227     return TRUE;
228    
229     case IDCANCEL | (BN_CLICKED << 16):
230     data->filename = NULL;
231     TTEndDialog(hDlgWnd, IDCANCEL);
232     return TRUE;
233    
234     case IDC_SENDFILE_FILENAME_BUTTON | (BN_CLICKED << 16): {
235 zmatsuo 8618 wchar_t TempDir[MAX_PATH];
236     _GetCurrentDirectoryW(_countof(TempDir), TempDir);
237 zmatsuo 8588
238 zmatsuo 8618 wchar_t *uimsg = TTGetLangStrW("Tera Term", "FILEDLG_TRANS_TITLE_SENDFILE", TitSendFileW, data->UILanguageFile);
239     wchar_t *title;
240     aswprintf(&title, L"Tera Term: %s", uimsg);
241     free(uimsg);
242     uimsg = NULL;
243 zmatsuo 8588
244     size_t filter_len;
245     wchar_t *filterW = GetCommonDialogFilterW(data->filesend_filter, data->UILanguageFile, &filter_len);
246    
247 zmatsuo 8618 wchar_t filename[MAX_PATH];
248 zmatsuo 8588 filename[0] = 0;
249 zmatsuo 8618 OPENFILENAMEW ofn = {};
250     ofn.lStructSize = get_OPENFILENAME_SIZEW();
251 zmatsuo 8588 ofn.hwndOwner = hDlgWnd;
252     ofn.lpstrFile = filename;
253     ofn.nMaxFile = MAX_PATH;
254 zmatsuo 8618 ofn.lpstrFilter = filterW;
255 zmatsuo 8588 ofn.nFilterIndex = 0;
256     ofn.lpstrTitle = title;
257     ofn.Flags = OFN_FILEMUSTEXIST | OFN_SHOWHELP | OFN_HIDEREADONLY;
258 zmatsuo 8618 BOOL Ok = _GetOpenFileNameW(&ofn);
259     free(filterW);
260     free(title);
261 zmatsuo 8588
262 zmatsuo 8618 _SetCurrentDirectoryW(TempDir);
263 zmatsuo 8588
264     if (Ok) {
265 zmatsuo 8618 _SetDlgItemTextW(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT, filename);
266 zmatsuo 8588 PostMessage(hDlgWnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlgWnd, IDOK), TRUE);
267     }
268    
269     return TRUE;
270     }
271    
272     case IDC_SENDFILE_DELAYTYPE_DROPDOWN | (CBN_SELCHANGE << 16): {
273     int sel = (int)SendDlgItemMessage(hDlgWnd, IDC_SENDFILE_DELAYTYPE_DROPDOWN, CB_GETCURSEL, 0, 0);
274     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN), sel != 3 ? FALSE : TRUE);
275     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_DELAYTIME_EDIT), sel == 0 ? FALSE : TRUE);
276     return TRUE;
277     }
278    
279     default:
280     return FALSE;
281     }
282     return FALSE;
283    
284     case WM_DROPFILES: {
285     // �����h���b�v��������������1������������
286     HDROP hDrop = (HDROP)wp;
287     const UINT len = _DragQueryFileW(hDrop, 0, NULL, 0);
288     if (len == 0) {
289     DragFinish(hDrop);
290     return TRUE;
291     }
292     wchar_t *filename = (wchar_t *)malloc(sizeof(wchar_t) * (len + 1));
293     _DragQueryFileW(hDrop, 0, filename, len + 1);
294     filename[len] = '\0';
295     _SetDlgItemTextW(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT, filename);
296     SendDlgItemMessage(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT, EM_SETSEL, len, len);
297     PostMessage(hDlgWnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlgWnd, IDOK), TRUE);
298    
299     free(filename);
300     DragFinish(hDrop);
301     return TRUE;
302     }
303     default:
304     if (data != NULL && msg == data->MsgDlgHelp) {
305     // �R�����_�C�A���O���w���v�{�^������������
306     PostMessage(GetParent(hDlgWnd), WM_USER_DLGHELP2, HlpMenuFileSendfile, 0);
307     return TRUE;
308     }
309     return FALSE;
310     }
311     }
312    
313     INT_PTR sendfiledlg(HINSTANCE hInstance, HWND hWndParent, sendfiledlgdata *data)
314     {
315     INT_PTR ret;
316     ret = TTDialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_SENDFILEDLG), hWndParent, SendFileDlgProc, (LPARAM)data);
317     return ret;
318     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26