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 8618 - (hide annotations) (download) (as text)
Mon Mar 23 15:54:48 2020 UTC (4 years ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/sendfiledlg.cpp
File MIME type: text/x-c++src
File size: 11513 byte(s)
ファイル送信ダイアログのファイルオープンを layer for unicode 版に置き換え

- ファイルヘッダを付けていなかったので追加
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     /**
50     * GetOpenFileName(), GetSaveFileName() �p�t�B���^����������
51     *
52     * @param[in] user_filter_mask ���[�U�[�t�B���^������
53     * "*.txt", "*.txt;*.log" ����
54     * NULL�������g�p������
55     * @param[in] UILanguageFile
56     * @param[out] len ����������������(wchar_t�P��)
57     * NULL����������������
58     * @retval "User define(*.txt)\0*.txt\0All(*.*)\0*.*\0" ����
59     * �I�[�� "\0\0" ������
60     */
61     static wchar_t *GetCommonDialogFilterW(const char *user_filter_mask, const char *UILanguageFile, size_t *len)
62     {
63     // "���[�U���`(*.txt)\0*.txt"
64     wchar_t *user_filter_str = NULL;
65     size_t user_filter_len = 0;
66     if (user_filter_mask != NULL && user_filter_mask[0] != 0) {
67     wchar_t user_filter_name[MAX_UIMSG];
68     get_lang_msgW("FILEDLG_USER_FILTER_NAME", user_filter_name, sizeof(user_filter_name), L"User define",
69     UILanguageFile);
70     size_t user_filter_name_len = wcslen(user_filter_name);
71     wchar_t *user_filter_maskW = ToWcharA(user_filter_mask);
72     size_t user_filter_mask_len = wcslen(user_filter_maskW);
73     user_filter_len = user_filter_name_len + 1 + user_filter_mask_len + 1 + 1 + user_filter_mask_len + 1;
74     user_filter_str = (wchar_t *)malloc(user_filter_len * sizeof(wchar_t));
75     wchar_t *p = user_filter_str;
76     wmemcpy(p, user_filter_name, user_filter_name_len);
77     p += user_filter_name_len;
78     *p++ = '(';
79     wmemcpy(p, user_filter_maskW, user_filter_mask_len);
80     p += user_filter_mask_len;
81     *p++ = ')';
82     *p++ = '\0';
83     wmemcpy(p, user_filter_maskW, user_filter_mask_len);
84     p += user_filter_mask_len;
85     *p++ = '\0';
86     free(user_filter_maskW);
87     }
88    
89     // "���������t�@�C��(*.*)\0*.*"
90     wchar_t all_filter_str[MAX_UIMSG];
91     get_lang_msgW("FILEDLG_ALL_FILTER", all_filter_str, _countof(all_filter_str), L"All(*.*)\\0*.*", UILanguageFile);
92     size_t all_filter_len;
93     {
94     size_t all_filter_title_len = wcsnlen(all_filter_str, _countof(all_filter_str));
95     if (all_filter_title_len == 0 || all_filter_title_len == _countof(all_filter_str)) {
96     all_filter_str[0] = 0;
97     all_filter_len = 0;
98     } else {
99     size_t all_filter_mask_max = _countof(all_filter_str) - all_filter_title_len - 1;
100     size_t all_filter_mask_len = wcsnlen(all_filter_str + all_filter_title_len + 1, all_filter_mask_max);
101     if (all_filter_mask_len == 0 || all_filter_mask_len == _countof(all_filter_str)) {
102     all_filter_str[0] = 0;
103     all_filter_len = 0;
104     } else {
105     all_filter_len = all_filter_title_len + 1 + all_filter_mask_len + 1;
106     }
107     }
108     }
109    
110     // �t�B���^������������
111     size_t filter_len = user_filter_len + all_filter_len;
112     wchar_t* filter_str;
113     if (filter_len != 0) {
114     filter_len++;
115     filter_str = (wchar_t*)malloc(filter_len * sizeof(wchar_t));
116     wchar_t *p = filter_str;
117     if (user_filter_len != 0) {
118     wmemcpy(p, user_filter_str, user_filter_len);
119     p += user_filter_len;
120     }
121     wmemcpy(p, all_filter_str, all_filter_len);
122     p += all_filter_len;
123     *p = '\0';
124     } else {
125     filter_len = 2;
126     filter_str = (wchar_t*)malloc(filter_len * sizeof(wchar_t));
127     filter_str[0] = 0;
128     filter_str[1] = 0;
129     }
130    
131     if (user_filter_len != 0) {
132     free(user_filter_str);
133     }
134    
135     if (len != NULL) {
136     *len = filter_len;
137     }
138     return filter_str;
139     }
140    
141     static INT_PTR CALLBACK SendFileDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
142     {
143     static const DlgTextInfo TextInfos[] = {
144     {0, "FILEDLG_TRANS_TITLE_SENDFILE"},
145     {IDC_SENDFILE_FILENAME_TITLE, "DLG_SENDFILE_FILENAME_TITLE"},
146     {IDC_SENDFILE_CHECK_BINARY, "DLG_FOPT_BINARY"},
147     {IDC_SENDFILE_DELAYTYPE_LABEL, "test"},
148     {IDC_SENDFILE_SEND_SIZE_LABEL, "test"},
149     {IDC_SENDFILE_DELAYTIME_LABEL, "test"},
150     {IDCANCEL, "BTN_CANCEL"},
151     {IDOK, "BTN_OK"},
152     };
153     static const I18nTextInfo l[] = {
154     {"DLG_SENDFILE_DELAYTYPE_NO_DELAY", L"no delay"},
155     {"DLG_SENDFILE_DELAYTYPE_PER_CHAR", L"per charactor"},
156     {"DLG_SENDFILE_DELAYTYPE_PER_LINE", L"per line"},
157     {"DLG_SENDFILE_DELAYTYPE_PER_SENDSIZE", L"per sendsize"},
158     };
159     static const int send_size_list[] = {16, 256, 4 * 1024};
160     sendfiledlgdata *data = (sendfiledlgdata *)GetWindowLongPtr(hDlgWnd, DWLP_USER);
161     int i;
162    
163     switch (msg) {
164     case WM_INITDIALOG:
165     data = (sendfiledlgdata *)lp;
166     data->MsgDlgHelp = RegisterWindowMessage(HELPMSGSTRING);
167     SetWindowLongPtr(hDlgWnd, DWLP_USER, (LONG_PTR)data);
168     ::DragAcceptFiles(hDlgWnd, TRUE);
169     SetDlgTexts(hDlgWnd, TextInfos, _countof(TextInfos), data->UILanguageFile);
170     CenterWindow(hDlgWnd, GetParent(hDlgWnd));
171    
172     SetI18nList("TeraTerm", hDlgWnd, IDC_SENDFILE_DELAYTYPE_DROPDOWN, l, _countof(l), data->UILanguageFile, 0);
173    
174     for (i = 0; i < _countof(send_size_list); i++) {
175     char buf[32];
176     sprintf(buf, "%d", send_size_list[i]);
177     SendDlgItemMessageA(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN, CB_ADDSTRING, 0, (LPARAM)buf);
178     }
179     SendDlgItemMessage(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN, CB_SETCURSEL, _countof(send_size_list) - 1, 0);
180    
181     SetDlgItemTextA(hDlgWnd, IDC_SENDFILE_DELAYTIME_EDIT, "1");
182    
183     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN), FALSE);
184     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_DELAYTIME_EDIT), FALSE);
185    
186     return TRUE;
187    
188     case WM_COMMAND:
189     switch (wp) {
190     case IDOK | (BN_CLICKED << 16): {
191 zmatsuo 8618 wchar_t *strW = AllocControlTextW(GetDlgItem(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT));
192 zmatsuo 8588
193     const DWORD attr = _GetFileAttributesW(strW);
194     if (attr == INVALID_FILE_ATTRIBUTES || attr & FILE_ATTRIBUTE_DIRECTORY) {
195 zmatsuo 8618 static const TTMessageBoxInfoW mbinfo = {
196     "Tera Term",
197     "MSG_TT_ERROR", L"Tera Term: Error",
198     "MSG_CANTOPEN_FILE_ERROR", L"Cannot open file" };
199     TTMessageBoxW(hDlgWnd, &mbinfo, MB_TASKMODAL | MB_ICONEXCLAMATION, data->UILanguageFile);
200 zmatsuo 8588
201     free(strW);
202    
203     PostMessage(hDlgWnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT),
204     TRUE);
205    
206     return TRUE;
207     }
208    
209     data->filename = strW;
210     data->binary =
211     SendMessage(GetDlgItem(hDlgWnd, IDC_SENDFILE_CHECK_BINARY), BM_GETCHECK, 0, 0) == BST_CHECKED
212     ? TRUE
213     : FALSE;
214     data->delay_type = (int)SendDlgItemMessage(hDlgWnd, IDC_SENDFILE_DELAYTYPE_DROPDOWN, CB_GETCURSEL, 0, 0);
215     data->delay_tick = GetDlgItemInt(hDlgWnd, IDC_SENDFILE_DELAYTIME_EDIT, NULL, FALSE);
216     data->send_size = GetDlgItemInt(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN, NULL, FALSE);
217    
218     TTEndDialog(hDlgWnd, IDOK);
219     return TRUE;
220     }
221    
222     case IDHELP | (BN_CLICKED << 16):
223     PostMessage(GetParent(hDlgWnd), WM_USER_DLGHELP2, HlpMenuFileSendfile, 0);
224     return TRUE;
225    
226     case IDCANCEL | (BN_CLICKED << 16):
227     data->filename = NULL;
228     TTEndDialog(hDlgWnd, IDCANCEL);
229     return TRUE;
230    
231     case IDC_SENDFILE_FILENAME_BUTTON | (BN_CLICKED << 16): {
232 zmatsuo 8618 wchar_t TempDir[MAX_PATH];
233     _GetCurrentDirectoryW(_countof(TempDir), TempDir);
234 zmatsuo 8588
235 zmatsuo 8618 #define TitSendFileW L"Send file"
236     wchar_t *uimsg = TTGetLangStrW("Tera Term", "FILEDLG_TRANS_TITLE_SENDFILE", TitSendFileW, data->UILanguageFile);
237     wchar_t *title;
238     aswprintf(&title, L"Tera Term: %s", uimsg);
239     free(uimsg);
240     uimsg = NULL;
241 zmatsuo 8588
242     size_t filter_len;
243     wchar_t *filterW = GetCommonDialogFilterW(data->filesend_filter, data->UILanguageFile, &filter_len);
244    
245 zmatsuo 8618 wchar_t filename[MAX_PATH];
246 zmatsuo 8588 filename[0] = 0;
247 zmatsuo 8618 OPENFILENAMEW ofn = {};
248     ofn.lStructSize = get_OPENFILENAME_SIZEW();
249 zmatsuo 8588 ofn.hwndOwner = hDlgWnd;
250     ofn.lpstrFile = filename;
251     ofn.nMaxFile = MAX_PATH;
252 zmatsuo 8618 ofn.lpstrFilter = filterW;
253 zmatsuo 8588 ofn.nFilterIndex = 0;
254     ofn.lpstrTitle = title;
255     ofn.Flags = OFN_FILEMUSTEXIST | OFN_SHOWHELP | OFN_HIDEREADONLY;
256 zmatsuo 8618 BOOL Ok = _GetOpenFileNameW(&ofn);
257     free(filterW);
258     free(title);
259 zmatsuo 8588
260 zmatsuo 8618 _SetCurrentDirectoryW(TempDir);
261 zmatsuo 8588
262     if (Ok) {
263 zmatsuo 8618 _SetDlgItemTextW(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT, filename);
264 zmatsuo 8588 PostMessage(hDlgWnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlgWnd, IDOK), TRUE);
265     }
266    
267     return TRUE;
268     }
269    
270     case IDC_SENDFILE_DELAYTYPE_DROPDOWN | (CBN_SELCHANGE << 16): {
271     int sel = (int)SendDlgItemMessage(hDlgWnd, IDC_SENDFILE_DELAYTYPE_DROPDOWN, CB_GETCURSEL, 0, 0);
272     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN), sel != 3 ? FALSE : TRUE);
273     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_DELAYTIME_EDIT), sel == 0 ? FALSE : TRUE);
274     return TRUE;
275     }
276    
277     default:
278     return FALSE;
279     }
280     return FALSE;
281    
282     case WM_DROPFILES: {
283     // �����h���b�v��������������1������������
284     HDROP hDrop = (HDROP)wp;
285     const UINT len = _DragQueryFileW(hDrop, 0, NULL, 0);
286     if (len == 0) {
287     DragFinish(hDrop);
288     return TRUE;
289     }
290     wchar_t *filename = (wchar_t *)malloc(sizeof(wchar_t) * (len + 1));
291     _DragQueryFileW(hDrop, 0, filename, len + 1);
292     filename[len] = '\0';
293     _SetDlgItemTextW(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT, filename);
294     SendDlgItemMessage(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT, EM_SETSEL, len, len);
295     PostMessage(hDlgWnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlgWnd, IDOK), TRUE);
296    
297     free(filename);
298     DragFinish(hDrop);
299     return TRUE;
300     }
301     default:
302     if (data != NULL && msg == data->MsgDlgHelp) {
303     // �R�����_�C�A���O���w���v�{�^������������
304     PostMessage(GetParent(hDlgWnd), WM_USER_DLGHELP2, HlpMenuFileSendfile, 0);
305     return TRUE;
306     }
307     return FALSE;
308     }
309     }
310    
311     INT_PTR sendfiledlg(HINSTANCE hInstance, HWND hWndParent, sendfiledlgdata *data)
312     {
313     INT_PTR ret;
314     ret = TTDialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_SENDFILEDLG), hWndParent, SendFileDlgProc, (LPARAM)data);
315     return ret;
316     }

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