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 9048 - (hide annotations) (download) (as text)
Wed Dec 16 12:24:13 2020 UTC (3 years, 3 months ago) by nmaya
Original Path: trunk/teraterm/teraterm/sendfiledlg.cpp
File MIME type: text/x-c++src
File size: 8427 byte(s)
ソースファイルの著作権表記の "最後の発行の年" を削除

ticket #40996
1 zmatsuo 8618 /*
2 nmaya 9048 * (C) 2020- TeraTerm Project
3 zmatsuo 8618 * 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 static INT_PTR CALLBACK SendFileDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
52     {
53     static const DlgTextInfo TextInfos[] = {
54     {0, "FILEDLG_TRANS_TITLE_SENDFILE"},
55     {IDC_SENDFILE_FILENAME_TITLE, "DLG_SENDFILE_FILENAME_TITLE"},
56     {IDC_SENDFILE_CHECK_BINARY, "DLG_FOPT_BINARY"},
57 zmatsuo 8621 {IDC_SENDFILE_DELAYTYPE_LABEL, "DLG_SENDFILE_DELAYTYPE_TITLE"},
58     {IDC_SENDFILE_SEND_SIZE_LABEL, "DLG_SENDFILE_SEND_SIZE_TITLE"},
59     {IDC_SENDFILE_DELAYTIME_LABEL, "DLG_SENDFILE_DELAYTIME_TITLE"},
60 zmatsuo 8588 {IDCANCEL, "BTN_CANCEL"},
61     {IDOK, "BTN_OK"},
62     };
63 zmatsuo 8621 static const I18nTextInfo delaytype_list[] = {
64 zmatsuo 8588 {"DLG_SENDFILE_DELAYTYPE_NO_DELAY", L"no delay"},
65     {"DLG_SENDFILE_DELAYTYPE_PER_CHAR", L"per charactor"},
66     {"DLG_SENDFILE_DELAYTYPE_PER_LINE", L"per line"},
67     {"DLG_SENDFILE_DELAYTYPE_PER_SENDSIZE", L"per sendsize"},
68     };
69     static const int send_size_list[] = {16, 256, 4 * 1024};
70     sendfiledlgdata *data = (sendfiledlgdata *)GetWindowLongPtr(hDlgWnd, DWLP_USER);
71     int i;
72    
73     switch (msg) {
74     case WM_INITDIALOG:
75     data = (sendfiledlgdata *)lp;
76     data->MsgDlgHelp = RegisterWindowMessage(HELPMSGSTRING);
77     SetWindowLongPtr(hDlgWnd, DWLP_USER, (LONG_PTR)data);
78     ::DragAcceptFiles(hDlgWnd, TRUE);
79     SetDlgTexts(hDlgWnd, TextInfos, _countof(TextInfos), data->UILanguageFile);
80     CenterWindow(hDlgWnd, GetParent(hDlgWnd));
81    
82 zmatsuo 8621 SetI18nList("TeraTerm", hDlgWnd, IDC_SENDFILE_DELAYTYPE_DROPDOWN, delaytype_list, _countof(delaytype_list),
83     data->UILanguageFile, 0);
84 zmatsuo 8588
85     for (i = 0; i < _countof(send_size_list); i++) {
86     char buf[32];
87     sprintf(buf, "%d", send_size_list[i]);
88     SendDlgItemMessageA(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN, CB_ADDSTRING, 0, (LPARAM)buf);
89     }
90     SendDlgItemMessage(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN, CB_SETCURSEL, _countof(send_size_list) - 1, 0);
91    
92     SetDlgItemTextA(hDlgWnd, IDC_SENDFILE_DELAYTIME_EDIT, "1");
93    
94     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN), FALSE);
95     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_DELAYTIME_EDIT), FALSE);
96    
97     return TRUE;
98    
99     case WM_COMMAND:
100     switch (wp) {
101     case IDOK | (BN_CLICKED << 16): {
102 zmatsuo 8618 wchar_t *strW = AllocControlTextW(GetDlgItem(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT));
103 zmatsuo 8588
104     const DWORD attr = _GetFileAttributesW(strW);
105     if (attr == INVALID_FILE_ATTRIBUTES || attr & FILE_ATTRIBUTE_DIRECTORY) {
106 zmatsuo 8618 static const TTMessageBoxInfoW mbinfo = {
107     "Tera Term",
108     "MSG_TT_ERROR", L"Tera Term: Error",
109     "MSG_CANTOPEN_FILE_ERROR", L"Cannot open file" };
110     TTMessageBoxW(hDlgWnd, &mbinfo, MB_TASKMODAL | MB_ICONEXCLAMATION, data->UILanguageFile);
111 zmatsuo 8588
112     free(strW);
113    
114     PostMessage(hDlgWnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT),
115     TRUE);
116    
117     return TRUE;
118     }
119    
120     data->filename = strW;
121     data->binary =
122     SendMessage(GetDlgItem(hDlgWnd, IDC_SENDFILE_CHECK_BINARY), BM_GETCHECK, 0, 0) == BST_CHECKED
123     ? TRUE
124     : FALSE;
125     data->delay_type = (int)SendDlgItemMessage(hDlgWnd, IDC_SENDFILE_DELAYTYPE_DROPDOWN, CB_GETCURSEL, 0, 0);
126     data->delay_tick = GetDlgItemInt(hDlgWnd, IDC_SENDFILE_DELAYTIME_EDIT, NULL, FALSE);
127     data->send_size = GetDlgItemInt(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN, NULL, FALSE);
128    
129     TTEndDialog(hDlgWnd, IDOK);
130     return TRUE;
131     }
132    
133     case IDHELP | (BN_CLICKED << 16):
134     PostMessage(GetParent(hDlgWnd), WM_USER_DLGHELP2, HlpMenuFileSendfile, 0);
135     return TRUE;
136    
137     case IDCANCEL | (BN_CLICKED << 16):
138     data->filename = NULL;
139     TTEndDialog(hDlgWnd, IDCANCEL);
140     return TRUE;
141    
142     case IDC_SENDFILE_FILENAME_BUTTON | (BN_CLICKED << 16): {
143 zmatsuo 8618 wchar_t TempDir[MAX_PATH];
144     _GetCurrentDirectoryW(_countof(TempDir), TempDir);
145 zmatsuo 8588
146 zmatsuo 8618 wchar_t *uimsg = TTGetLangStrW("Tera Term", "FILEDLG_TRANS_TITLE_SENDFILE", TitSendFileW, data->UILanguageFile);
147     wchar_t *title;
148     aswprintf(&title, L"Tera Term: %s", uimsg);
149     free(uimsg);
150     uimsg = NULL;
151 zmatsuo 8588
152 zmatsuo 8943 wchar_t *filterW = GetCommonDialogFilterW(data->filesend_filter, data->UILanguageFile);
153 zmatsuo 8618 wchar_t filename[MAX_PATH];
154 zmatsuo 8588 filename[0] = 0;
155 zmatsuo 8618 OPENFILENAMEW ofn = {};
156     ofn.lStructSize = get_OPENFILENAME_SIZEW();
157 zmatsuo 8588 ofn.hwndOwner = hDlgWnd;
158     ofn.lpstrFile = filename;
159     ofn.nMaxFile = MAX_PATH;
160 zmatsuo 8618 ofn.lpstrFilter = filterW;
161 zmatsuo 8588 ofn.nFilterIndex = 0;
162     ofn.lpstrTitle = title;
163     ofn.Flags = OFN_FILEMUSTEXIST | OFN_SHOWHELP | OFN_HIDEREADONLY;
164 zmatsuo 8618 BOOL Ok = _GetOpenFileNameW(&ofn);
165     free(filterW);
166     free(title);
167 zmatsuo 8588
168 zmatsuo 8618 _SetCurrentDirectoryW(TempDir);
169 zmatsuo 8588
170     if (Ok) {
171 zmatsuo 8618 _SetDlgItemTextW(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT, filename);
172 zmatsuo 8588 PostMessage(hDlgWnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlgWnd, IDOK), TRUE);
173     }
174    
175     return TRUE;
176     }
177    
178     case IDC_SENDFILE_DELAYTYPE_DROPDOWN | (CBN_SELCHANGE << 16): {
179     int sel = (int)SendDlgItemMessage(hDlgWnd, IDC_SENDFILE_DELAYTYPE_DROPDOWN, CB_GETCURSEL, 0, 0);
180     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_SEND_SIZE_DROPDOWN), sel != 3 ? FALSE : TRUE);
181     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_DELAYTIME_EDIT), sel == 0 ? FALSE : TRUE);
182     return TRUE;
183     }
184    
185     default:
186     return FALSE;
187     }
188     return FALSE;
189    
190     case WM_DROPFILES: {
191     // �����h���b�v��������������1������������
192     HDROP hDrop = (HDROP)wp;
193     const UINT len = _DragQueryFileW(hDrop, 0, NULL, 0);
194     if (len == 0) {
195     DragFinish(hDrop);
196     return TRUE;
197     }
198     wchar_t *filename = (wchar_t *)malloc(sizeof(wchar_t) * (len + 1));
199     _DragQueryFileW(hDrop, 0, filename, len + 1);
200     filename[len] = '\0';
201     _SetDlgItemTextW(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT, filename);
202     SendDlgItemMessage(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT, EM_SETSEL, len, len);
203     PostMessage(hDlgWnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlgWnd, IDOK), TRUE);
204    
205     free(filename);
206     DragFinish(hDrop);
207     return TRUE;
208     }
209     default:
210     if (data != NULL && msg == data->MsgDlgHelp) {
211     // �R�����_�C�A���O���w���v�{�^������������
212     PostMessage(GetParent(hDlgWnd), WM_USER_DLGHELP2, HlpMenuFileSendfile, 0);
213     return TRUE;
214     }
215     return FALSE;
216     }
217     }
218    
219     INT_PTR sendfiledlg(HINSTANCE hInstance, HWND hWndParent, sendfiledlgdata *data)
220     {
221     INT_PTR ret;
222     ret = TTDialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_SENDFILEDLG), hWndParent, SendFileDlgProc, (LPARAM)data);
223     return ret;
224     }

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