Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7148 - (hide annotations) (download) (as text)
Fri Jul 13 11:05:13 2018 UTC (5 years, 9 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/dnddlg.cpp
File MIME type: text/x-c++src
File size: 11607 byte(s)
merge drag and drop branch r7147

- drag and drop branchをマージ
- ttssh2/installer/release/lang/Russian.lngが未編集
- teraterm/teraterm/dnddlg.cpp,hをプロジェクトファイルに追加できていない

1 zmatsuo 7145 /*
2     * (C) 2005-2018 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    
29     #include "dnddlg.h"
30    
31     #include <windowsx.h>
32     #include <stdio.h> // for _snprintf_s
33    
34     #include "tt_res.h"
35    
36     #include "i18n.h"
37     #include "ttlib.h"
38     #include "dlglib.h"
39     #include "tttypes.h" // for ttwinman.h
40     #include "ttwinman.h" // for ts
41    
42     struct DlgTextInfo {
43     int nIDDlgItem;
44     char *key;
45     };
46    
47     struct DrapDropDlgParam {
48     const char *TargetFilename;
49     enum drop_type DropType;
50     unsigned char DropTypePaste;
51     bool ScpEnable;
52     char *ScpSendDirPtr;
53     int ScpSendDirSize;
54     bool SendfileEnable;
55     bool PasteNewlineEnable;
56     int RemaingFileCount;
57     bool DoSameProcess;
58     bool DoSameProcessNextDrop;
59     bool DoNotShowDialogEnable;
60     bool DoNotShowDialog;
61     const char *UILanguageFile;
62     };
63    
64     struct DrapDropDlgData {
65     HFONT hPrevFont;
66     DrapDropDlgParam *Param;
67     };
68    
69     static HFONT SetDlgFonts(HWND hDlg, const int nIDDlgItems[], int nIDDlgItemCount, const char *UILanguageFile, PCHAR key)
70     {
71     if (key == NULL) key = "DLG_TAHOMA_FONT";
72     HFONT hPrevFont = (HFONT)SendMessage(hDlg, WM_GETFONT, 0, 0);
73     LOGFONT logfont;
74     GetObject(hPrevFont, sizeof(LOGFONT), &logfont);
75     HFONT hNewFont;
76     if (get_lang_font("DLG_TAHOMA_FONT", hDlg, &logfont, &hNewFont, UILanguageFile)) {
77     for (int i = 0 ; i < nIDDlgItemCount ; i++) {
78     const int nIDDlgItem = nIDDlgItems[i];
79     SendDlgItemMessage(hDlg, nIDDlgItem, WM_SETFONT, (WPARAM)hNewFont, MAKELPARAM(TRUE,0));
80     }
81     }
82     return hNewFont;
83     }
84    
85     static void SetDlgTexts(HWND hDlgWnd, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile)
86     {
87     for (int i = 0 ; i < infoCount; i++) {
88     char *key = infos[i].key;
89     char uimsg[MAX_UIMSG];
90     get_lang_msg(key, uimsg, sizeof(uimsg), "", UILanguageFile);
91     if (uimsg[0] != '\0') {
92     const int nIDDlgItem = infos[i].nIDDlgItem;
93     if (nIDDlgItem == 0) {
94     SetWindowText(hDlgWnd, uimsg);
95     } else {
96     SetDlgItemText(hDlgWnd, nIDDlgItem, uimsg);
97     }
98     }
99     }
100     }
101    
102     static LRESULT CALLBACK OnDragDropDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
103     {
104     static const int FontIDs[] = {
105     IDC_FILENAME_EDIT,
106     IDC_DAD_STATIC,
107     IDC_SCP_RADIO, IDC_SENDFILE_RADIO, IDC_PASTE_RADIO,
108     IDC_SCP_PATH_LABEL, IDC_SCP_PATH, IDC_SCP_PATH_NOTE,
109     IDC_BINARY_CHECK,
110     IDC_ESCAPE_CHECK, IDC_NEWLINE_RADIO, IDC_SPACE_RADIO,
111     IDC_SAME_PROCESS_CHECK, IDC_SAME_PROCESS_NEXTDROP_CHECK, IDC_DONTSHOW_CHECK,
112     IDC_DAD_NOTE,
113     IDOK, IDCANCEL,
114     };
115     static const DlgTextInfo TextInfos[] = {
116     { 0, "DLG_DANDD_TITLE" },
117     { IDC_DAD_STATIC, "DLG_DANDD_TEXT" },
118     { IDC_SCP_PATH_NOTE, "DLG_DADDD_DEST_NOTE" },
119     { IDC_SAME_PROCESS_CHECK, "DLG_DANDD_CONFLICTS" },
120     { IDC_SAME_PROCESS_NEXTDROP_CHECK, "DLG_DANDD_SAME_NEEXTDROP" },
121     { IDC_DONTSHOW_CHECK, "DLG_DANDD_DONTSHOW_NEEXTDROP" },
122     { IDC_DAD_NOTE, "DLG_DANDD_NOTE" },
123     { IDOK, "BTN_OK" },
124     { IDCANCEL, "BTN_CANCEL" },
125     };
126     DrapDropDlgData *DlgData = (DrapDropDlgData *)GetWindowLongPtr(hDlgWnd, GWLP_USERDATA);
127    
128     switch (msg) {
129     case WM_INITDIALOG:
130     {
131     DlgData = (DrapDropDlgData *)malloc(sizeof(DrapDropDlgData));
132     SetWindowLongPtr(hDlgWnd, GWLP_USERDATA, (LONG_PTR)DlgData);
133     DrapDropDlgParam *Param = (DrapDropDlgParam *)lp;
134     DlgData->Param = Param;
135     DlgData->hPrevFont = SetDlgFonts(hDlgWnd, FontIDs, _countof(FontIDs), Param->UILanguageFile, NULL);
136     SetDlgTexts(hDlgWnd, TextInfos, _countof(TextInfos), Param->UILanguageFile);
137    
138     // target file
139     SetDlgItemText(hDlgWnd, IDC_FILENAME_EDIT, Param->TargetFilename);
140    
141     // checkbox
142     CheckRadioButton(hDlgWnd, IDC_SCP_RADIO, IDC_PASTE_RADIO,
143     (Param->DropType == DROP_TYPE_SEND_FILE ||
144     Param->DropType == DROP_TYPE_SEND_FILE_BINARY) ? IDC_SENDFILE_RADIO :
145     Param->DropType == DROP_TYPE_PASTE_FILENAME ? IDC_PASTE_RADIO :
146     IDC_SCP_RADIO);
147    
148     // SCP
149     SendMessage(GetDlgItem(hDlgWnd, IDC_SCP_PATH), WM_SETTEXT, 0, (LPARAM)Param->ScpSendDirPtr);
150     if (!Param->ScpEnable) {
151     // 無効化
152     EnableWindow(GetDlgItem(hDlgWnd, IDC_SCP_RADIO), FALSE);
153     EnableWindow(GetDlgItem(hDlgWnd, IDC_SCP_PATH_LABEL), FALSE);
154     EnableWindow(GetDlgItem(hDlgWnd, IDC_SCP_PATH), FALSE);
155     EnableWindow(GetDlgItem(hDlgWnd, IDC_SCP_PATH_NOTE), FALSE);
156     }
157    
158     // Send File
159     if (Param->DropType == DROP_TYPE_SEND_FILE_BINARY) {
160     SendMessage(GetDlgItem(hDlgWnd, IDC_BINARY_CHECK), BM_SETCHECK, BST_CHECKED, 0);
161     }
162     if (!Param->SendfileEnable) {
163     // 無効化
164     EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_RADIO), FALSE);
165     EnableWindow(GetDlgItem(hDlgWnd, IDC_BINARY_CHECK), FALSE);
166     }
167    
168     // Paste Filename
169     if (Param->DropTypePaste & DROP_TYPE_PASTE_ESCAPE) {
170     SendMessage(GetDlgItem(hDlgWnd, IDC_ESCAPE_CHECK), BM_SETCHECK, BST_CHECKED, 0);
171     }
172     CheckRadioButton(hDlgWnd, IDC_SPACE_RADIO, IDC_NEWLINE_RADIO,
173     Param->DropTypePaste & DROP_TYPE_PASTE_NEWLINE?
174     IDC_NEWLINE_RADIO : IDC_SPACE_RADIO);
175     if (Param->RemaingFileCount < 2) {
176     EnableWindow(GetDlgItem(hDlgWnd, IDC_SPACE_RADIO), FALSE);
177     EnableWindow(GetDlgItem(hDlgWnd, IDC_NEWLINE_RADIO), FALSE);
178     }
179    
180     // Do this for the next %d conflicts
181     char orgmsg[MAX_UIMSG];
182     GetDlgItemText(hDlgWnd, IDC_SAME_PROCESS_CHECK, orgmsg, sizeof(orgmsg));
183     char uimsg[MAX_UIMSG];
184     _snprintf_s(uimsg, sizeof(uimsg), _TRUNCATE, orgmsg, Param->RemaingFileCount - 1);
185     SetDlgItemText(hDlgWnd, IDC_SAME_PROCESS_CHECK, uimsg);
186     if (Param->RemaingFileCount < 2) {
187     EnableWindow(GetDlgItem(hDlgWnd, IDC_SAME_PROCESS_CHECK), FALSE);
188     }
189    
190     // Dont Show Dialog
191     if (Param->DoNotShowDialog) {
192     SendMessage(GetDlgItem(hDlgWnd, IDC_DONTSHOW_CHECK), BM_SETCHECK, BST_CHECKED, 0);
193     }
194     if (!Param->DoNotShowDialogEnable) {
195     EnableWindow(GetDlgItem(hDlgWnd, IDC_DONTSHOW_CHECK), FALSE);
196     EnableWindow(GetDlgItem(hDlgWnd, IDC_DAD_NOTE), FALSE);
197     }
198    
199     // focus to "SCP dest textbox" or "Cancel"
200     if (Param->ScpEnable) {
201     // "SCP" 有効時は Cancel にフォーカスを当て、最終的に SCP PATH にフォーカスが
202     // 当たるようにする。
203     SetFocus(GetDlgItem(hDlgWnd, IDC_SCP_RADIO));
204     } else {
205     // フォーカスの初期状態を Cancel にする為、この時点では IDOK に
206     // フォーカスを当てる。後で WM_NEXTDLGCTL でフォーカスが次のボタンになる。
207     SetFocus(GetDlgItem(hDlgWnd, IDOK));
208     }
209     // フォーカスを次のボタンに移す
210     // SetFocus() で直接フォーカスを当てるとタブキーの動作等に問題が出るため、
211     // このメッセージを併用する
212     PostMessage(hDlgWnd, WM_NEXTDLGCTL, 0, 0L);
213    
214     // TRUEにするとボタンにフォーカスが当たらない。
215     return FALSE;
216     }
217    
218     case WM_COMMAND:
219     {
220     WORD wID = GET_WM_COMMAND_ID(wp, lp);
221     const WORD wCMD = GET_WM_COMMAND_CMD(wp, lp);
222     if (wCMD == BN_DBLCLK &&
223     (wID == IDC_SCP_RADIO || wID == IDC_SENDFILE_RADIO || wID == IDC_PASTE_RADIO))
224     { // radio buttons double click
225     wID = IDOK;
226     }
227     if (wCMD == EN_SETFOCUS && wID == IDC_SCP_PATH) {
228     CheckRadioButton(hDlgWnd, IDC_SCP_RADIO, IDC_PASTE_RADIO, IDC_SCP_RADIO);
229     }
230     if (wID == IDC_BINARY_CHECK) {
231     CheckRadioButton(hDlgWnd, IDC_SCP_RADIO, IDC_PASTE_RADIO, IDC_SENDFILE_RADIO);
232     }
233     if (wID == IDC_ESCAPE_CHECK ||
234     wID == IDC_SPACE_RADIO || wID == IDC_NEWLINE_RADIO)
235     {
236     CheckRadioButton(hDlgWnd, IDC_SCP_RADIO, IDC_PASTE_RADIO, IDC_PASTE_RADIO);
237     }
238     if (wID == IDOK) {
239     if (IsDlgButtonChecked(hDlgWnd, IDC_SCP_RADIO) == BST_CHECKED) {
240     // SCP
241     DlgData->Param->DropType = DROP_TYPE_SCP;
242     SendMessage(GetDlgItem(hDlgWnd, IDC_SCP_PATH), WM_GETTEXT,
243     (WPARAM)DlgData->Param->ScpSendDirSize,
244     (LPARAM)DlgData->Param->ScpSendDirPtr);
245     } else if (IsDlgButtonChecked(hDlgWnd, IDC_SENDFILE_RADIO) == BST_CHECKED) {
246     // Send File
247     DlgData->Param->DropType =
248     (IsDlgButtonChecked(hDlgWnd, IDC_BINARY_CHECK) == BST_CHECKED) ?
249     DROP_TYPE_SEND_FILE_BINARY : DROP_TYPE_SEND_FILE;
250     } else /* if (IsDlgButtonChecked(hDlgWnd, IDC_PASTE_RADIO) == BST_CHECKED) */ {
251     // Paste Filename
252     DlgData->Param->DropType = DROP_TYPE_PASTE_FILENAME;
253     DlgData->Param->DropTypePaste = 0;
254     DlgData->Param->DropTypePaste |=
255     (IsDlgButtonChecked(hDlgWnd, IDC_ESCAPE_CHECK) == BST_CHECKED) ?
256     DROP_TYPE_PASTE_ESCAPE : 0;
257     DlgData->Param->DropTypePaste |=
258     (IsDlgButtonChecked(hDlgWnd, IDC_NEWLINE_RADIO) == BST_CHECKED) ?
259     DROP_TYPE_PASTE_NEWLINE : 0;
260     }
261     DlgData->Param->DoSameProcess =
262     (IsDlgButtonChecked(hDlgWnd, IDC_SAME_PROCESS_CHECK) == BST_CHECKED) ?
263     true : false;
264     DlgData->Param->DoSameProcessNextDrop =
265     (IsDlgButtonChecked(hDlgWnd, IDC_SAME_PROCESS_NEXTDROP_CHECK) == BST_CHECKED) ?
266     true : false;
267     DlgData->Param->DoNotShowDialog =
268     (IsDlgButtonChecked(hDlgWnd, IDC_DONTSHOW_CHECK) == BST_CHECKED) ?
269     true : false;
270     }
271     if (wID == IDCANCEL) {
272     DlgData->Param->DropType = DROP_TYPE_CANCEL;
273     }
274     if (wID == IDOK || wID == IDCANCEL) {
275     if (DlgData->hPrevFont != NULL) {
276     DeleteObject(DlgData->hPrevFont);
277     }
278     EndDialog(hDlgWnd, wID);
279     free(DlgData);
280     break;
281     }
282     return FALSE;
283     }
284    
285     default:
286     return FALSE;
287     }
288     return TRUE;
289     }
290    
291     enum drop_type ShowDropDialogBox(
292     HINSTANCE hInstance, HWND hWndParent,
293     const char *TargetFilename,
294     enum drop_type DefaultDropType,
295     int RemaingFileCount,
296     bool EnableSCP,
297     bool EnableSendFile,
298     bool EnableDoNotShowDialog,
299     unsigned char *DropTypePaste,
300     bool *DoSameProcess,
301     bool *DoSameProcessNextDrop,
302     bool *DoNotShowDialog)
303     {
304     DrapDropDlgParam Param;
305     Param.TargetFilename = TargetFilename;
306     Param.DropType = DefaultDropType;
307     Param.DropTypePaste = *DropTypePaste;
308     Param.ScpEnable = EnableSCP;
309     Param.ScpSendDirPtr = ts.ScpSendDir;
310     Param.ScpSendDirSize = sizeof(ts.ScpSendDir);
311     Param.SendfileEnable = EnableSendFile;
312     Param.PasteNewlineEnable = true;
313     Param.RemaingFileCount = RemaingFileCount;
314     Param.DoNotShowDialog = *DoNotShowDialog;
315     Param.DoNotShowDialogEnable = EnableDoNotShowDialog;
316     Param.UILanguageFile = ts.UILanguageFile;
317     int ret = DialogBoxParam(
318     hInstance, MAKEINTRESOURCE(IDD_DAD_DIALOG),
319     hWndParent, (DLGPROC)OnDragDropDlgProc,
320     (LPARAM)&Param);
321     if (ret != IDOK) {
322     return DROP_TYPE_CANCEL;
323     }
324     *DropTypePaste = Param.DropTypePaste;
325     *DoSameProcess = Param.DoSameProcess;
326     *DoSameProcessNextDrop = Param.DoSameProcessNextDrop;
327     *DoNotShowDialog = Param.DoNotShowDialog;
328     return Param.DropType;
329     }

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