| 1 |
/* |
| 2 |
* (C) 2005- 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 |
/* TERATERM.EXE, drag and drop dialog */ |
| 30 |
#include "dnddlg.h" |
| 31 |
|
| 32 |
#include <windowsx.h> |
| 33 |
#include <stdio.h> // for _snprintf_s |
| 34 |
|
| 35 |
#include "tt_res.h" |
| 36 |
|
| 37 |
#include "i18n.h" |
| 38 |
#include "ttlib.h" |
| 39 |
#include "dlglib.h" |
| 40 |
#include "asprintf.h" |
| 41 |
#include "win32helper.h" |
| 42 |
|
| 43 |
struct DrapDropDlgParam { |
| 44 |
const wchar_t *TargetFilename; |
| 45 |
enum drop_type DropType; |
| 46 |
unsigned char DropTypePaste; |
| 47 |
bool ScpEnable; |
| 48 |
char *ScpSendDirPtr; |
| 49 |
int ScpSendDirSize; |
| 50 |
bool SendfileEnable; |
| 51 |
bool SendfileBinary; |
| 52 |
int RemaingFileCount; |
| 53 |
bool DoSameProcess; |
| 54 |
bool DoSameProcessNextDrop; |
| 55 |
bool DoNotShowDialogEnable; |
| 56 |
bool DoNotShowDialog; |
| 57 |
const wchar_t *UILanguageFile; |
| 58 |
}; |
| 59 |
|
| 60 |
struct DrapDropDlgData { |
| 61 |
DrapDropDlgParam *Param; |
| 62 |
}; |
| 63 |
|
| 64 |
static LRESULT CALLBACK OnDragDropDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp) |
| 65 |
{ |
| 66 |
static const DlgTextInfo TextInfos[] = { |
| 67 |
{ 0, "DLG_DANDD_TITLE" }, |
| 68 |
{ IDC_DAD_STATIC, "DLG_DANDD_TEXT" }, |
| 69 |
{ IDC_SCP_RADIO, "DLG_DANDD_SCP_RADIO" }, |
| 70 |
{ IDC_SENDFILE_RADIO, "DLG_DANDD_SENDFILE_RADIO" }, |
| 71 |
{ IDC_PASTE_RADIO, "DLG_DANDD_PASTE_RADIO" }, |
| 72 |
{ IDC_SCP_PATH_LABEL, "DLG_DANDD_SCP_DEST_LABEL" }, |
| 73 |
{ IDC_SCP_PATH_NOTE, "DLG_DANDD_SCP_DEST_NOTE" }, |
| 74 |
{ IDC_BINARY_CHECK, "DLG_DANDD_SEND_BINARY_CHECK" }, |
| 75 |
{ IDC_ESCAPE_CHECK, "DLG_DANDD_PASTE_ESCAPE_CHECK" }, |
| 76 |
{ IDC_SPACE_RADIO, "DLG_DANDD_PASTE_SPACE_RADIO" }, |
| 77 |
{ IDC_NEWLINE_RADIO, "DLG_DANDD_PASTE_NEWLINE_RADIO" }, |
| 78 |
{ IDC_SAME_PROCESS_CHECK, "DLG_DANDD_NEXTFILES" }, |
| 79 |
{ IDC_SAME_PROCESS_NEXTDROP_CHECK, "DLG_DANDD_SAME_NEEXTDROP" }, |
| 80 |
{ IDC_DONTSHOW_CHECK, "DLG_DANDD_DONTSHOW_NEEXTDROP" }, |
| 81 |
{ IDC_DAD_NOTE, "DLG_DANDD_NOTE" }, |
| 82 |
{ IDOK, "BTN_OK" }, |
| 83 |
{ IDCANCEL, "BTN_CANCEL" }, |
| 84 |
}; |
| 85 |
DrapDropDlgData *DlgData = (DrapDropDlgData *)GetWindowLongPtr(hDlgWnd, DWLP_USER); |
| 86 |
|
| 87 |
switch (msg) { |
| 88 |
case WM_INITDIALOG: |
| 89 |
{ |
| 90 |
DlgData = (DrapDropDlgData *)malloc(sizeof(DrapDropDlgData)); |
| 91 |
SetWindowLongPtr(hDlgWnd, DWLP_USER, (LONG_PTR)DlgData); |
| 92 |
DrapDropDlgParam *Param = (DrapDropDlgParam *)lp; |
| 93 |
DlgData->Param = Param; |
| 94 |
SetDlgTextsW(hDlgWnd, TextInfos, _countof(TextInfos), Param->UILanguageFile); |
| 95 |
|
| 96 |
// target file |
| 97 |
SetDlgItemTextW(hDlgWnd, IDC_FILENAME_EDIT, Param->TargetFilename); |
| 98 |
|
| 99 |
// drop type |
| 100 |
CheckRadioButton(hDlgWnd, IDC_SCP_RADIO, IDC_PASTE_RADIO, |
| 101 |
Param->DropType == DROP_TYPE_SEND_FILE ? IDC_SENDFILE_RADIO : |
| 102 |
Param->DropType == DROP_TYPE_PASTE_FILENAME ? IDC_PASTE_RADIO : |
| 103 |
IDC_SCP_RADIO); |
| 104 |
|
| 105 |
// SCP |
| 106 |
SetDlgItemTextA(hDlgWnd, IDC_SCP_PATH, Param->ScpSendDirPtr); |
| 107 |
if (!Param->ScpEnable) { |
| 108 |
// ������ |
| 109 |
EnableWindow(GetDlgItem(hDlgWnd, IDC_SCP_RADIO), FALSE); |
| 110 |
EnableWindow(GetDlgItem(hDlgWnd, IDC_SCP_PATH_LABEL), FALSE); |
| 111 |
EnableWindow(GetDlgItem(hDlgWnd, IDC_SCP_PATH), FALSE); |
| 112 |
EnableWindow(GetDlgItem(hDlgWnd, IDC_SCP_PATH_NOTE), FALSE); |
| 113 |
} |
| 114 |
SetEditboxEmacsKeybind(hDlgWnd, IDC_SCP_PATH); |
| 115 |
|
| 116 |
// Send File |
| 117 |
if (Param->SendfileBinary) { |
| 118 |
SendMessage(GetDlgItem(hDlgWnd, IDC_BINARY_CHECK), BM_SETCHECK, BST_CHECKED, 0); |
| 119 |
} |
| 120 |
if (!Param->SendfileEnable) { |
| 121 |
// ������ |
| 122 |
EnableWindow(GetDlgItem(hDlgWnd, IDC_SENDFILE_RADIO), FALSE); |
| 123 |
EnableWindow(GetDlgItem(hDlgWnd, IDC_BINARY_CHECK), FALSE); |
| 124 |
} |
| 125 |
|
| 126 |
// Paste Filename |
| 127 |
if (Param->DropTypePaste & DROP_TYPE_PASTE_ESCAPE) { |
| 128 |
SendMessage(GetDlgItem(hDlgWnd, IDC_ESCAPE_CHECK), BM_SETCHECK, BST_CHECKED, 0); |
| 129 |
} |
| 130 |
CheckRadioButton(hDlgWnd, IDC_SPACE_RADIO, IDC_NEWLINE_RADIO, |
| 131 |
Param->DropTypePaste & DROP_TYPE_PASTE_NEWLINE? |
| 132 |
IDC_NEWLINE_RADIO : IDC_SPACE_RADIO); |
| 133 |
if (Param->RemaingFileCount < 2) { |
| 134 |
EnableWindow(GetDlgItem(hDlgWnd, IDC_SPACE_RADIO), FALSE); |
| 135 |
EnableWindow(GetDlgItem(hDlgWnd, IDC_NEWLINE_RADIO), FALSE); |
| 136 |
} |
| 137 |
|
| 138 |
// Do this for the next %d files |
| 139 |
wchar_t *format; |
| 140 |
hGetDlgItemTextW(hDlgWnd, IDC_SAME_PROCESS_CHECK, &format); |
| 141 |
wchar_t *formated; |
| 142 |
aswprintf(&formated, format, Param->RemaingFileCount - 1); |
| 143 |
SetDlgItemTextW(hDlgWnd, IDC_SAME_PROCESS_CHECK, formated); |
| 144 |
free(format); |
| 145 |
free(formated); |
| 146 |
if (Param->RemaingFileCount < 2) { |
| 147 |
EnableWindow(GetDlgItem(hDlgWnd, IDC_SAME_PROCESS_CHECK), FALSE); |
| 148 |
} |
| 149 |
|
| 150 |
// Dont Show Dialog |
| 151 |
if (Param->DoNotShowDialog) { |
| 152 |
SendMessage(GetDlgItem(hDlgWnd, IDC_DONTSHOW_CHECK), BM_SETCHECK, BST_CHECKED, 0); |
| 153 |
} |
| 154 |
if (!Param->DoNotShowDialogEnable) { |
| 155 |
EnableWindow(GetDlgItem(hDlgWnd, IDC_DONTSHOW_CHECK), FALSE); |
| 156 |
EnableWindow(GetDlgItem(hDlgWnd, IDC_DAD_NOTE), FALSE); |
| 157 |
} |
| 158 |
|
| 159 |
// focus to "SCP dest textbox" or "Cancel" |
| 160 |
{ |
| 161 |
int focus_id; |
| 162 |
if (Param->DropType == DROP_TYPE_SCP) { |
| 163 |
focus_id = IDC_SCP_PATH; |
| 164 |
} else { |
| 165 |
focus_id = IDCANCEL; |
| 166 |
} |
| 167 |
PostMessage(hDlgWnd, WM_NEXTDLGCTL, |
| 168 |
(WPARAM)GetDlgItem(hDlgWnd, focus_id), TRUE); |
| 169 |
} |
| 170 |
|
| 171 |
CenterWindow(hDlgWnd, GetParent(hDlgWnd)); |
| 172 |
// TRUE���������{�^�����t�H�[�J�X�������������B |
| 173 |
return FALSE; |
| 174 |
} |
| 175 |
|
| 176 |
case WM_COMMAND: |
| 177 |
{ |
| 178 |
WORD wID = GET_WM_COMMAND_ID(wp, lp); |
| 179 |
const WORD wCMD = GET_WM_COMMAND_CMD(wp, lp); |
| 180 |
if (wCMD == BN_DBLCLK && |
| 181 |
(wID == IDC_SCP_RADIO || wID == IDC_SENDFILE_RADIO || wID == IDC_PASTE_RADIO)) |
| 182 |
{ // radio buttons double click |
| 183 |
wID = IDOK; |
| 184 |
} |
| 185 |
if (wCMD == EN_SETFOCUS && wID == IDC_SCP_PATH) { |
| 186 |
CheckRadioButton(hDlgWnd, IDC_SCP_RADIO, IDC_PASTE_RADIO, IDC_SCP_RADIO); |
| 187 |
} |
| 188 |
if (wID == IDC_BINARY_CHECK) { |
| 189 |
CheckRadioButton(hDlgWnd, IDC_SCP_RADIO, IDC_PASTE_RADIO, IDC_SENDFILE_RADIO); |
| 190 |
} |
| 191 |
if (wID == IDC_ESCAPE_CHECK || |
| 192 |
wID == IDC_SPACE_RADIO || wID == IDC_NEWLINE_RADIO) |
| 193 |
{ |
| 194 |
CheckRadioButton(hDlgWnd, IDC_SCP_RADIO, IDC_PASTE_RADIO, IDC_PASTE_RADIO); |
| 195 |
} |
| 196 |
if (wID == IDOK) { |
| 197 |
if (IsDlgButtonChecked(hDlgWnd, IDC_SCP_RADIO) == BST_CHECKED) { |
| 198 |
// SCP |
| 199 |
DlgData->Param->DropType = DROP_TYPE_SCP; |
| 200 |
GetDlgItemTextA(hDlgWnd, IDC_SCP_PATH, |
| 201 |
DlgData->Param->ScpSendDirPtr, DlgData->Param->ScpSendDirSize); |
| 202 |
} else if (IsDlgButtonChecked(hDlgWnd, IDC_SENDFILE_RADIO) == BST_CHECKED) { |
| 203 |
// Send File |
| 204 |
DlgData->Param->DropType = DROP_TYPE_SEND_FILE; |
| 205 |
DlgData->Param->SendfileBinary = |
| 206 |
(IsDlgButtonChecked(hDlgWnd, IDC_BINARY_CHECK) == BST_CHECKED) ? |
| 207 |
true : false; |
| 208 |
} else /* if (IsDlgButtonChecked(hDlgWnd, IDC_PASTE_RADIO) == BST_CHECKED) */ { |
| 209 |
// Paste Filename |
| 210 |
DlgData->Param->DropType = DROP_TYPE_PASTE_FILENAME; |
| 211 |
DlgData->Param->DropTypePaste = 0; |
| 212 |
DlgData->Param->DropTypePaste |= |
| 213 |
(IsDlgButtonChecked(hDlgWnd, IDC_ESCAPE_CHECK) == BST_CHECKED) ? |
| 214 |
DROP_TYPE_PASTE_ESCAPE : 0; |
| 215 |
DlgData->Param->DropTypePaste |= |
| 216 |
(IsDlgButtonChecked(hDlgWnd, IDC_NEWLINE_RADIO) == BST_CHECKED) ? |
| 217 |
DROP_TYPE_PASTE_NEWLINE : 0; |
| 218 |
} |
| 219 |
DlgData->Param->DoSameProcess = |
| 220 |
(IsDlgButtonChecked(hDlgWnd, IDC_SAME_PROCESS_CHECK) == BST_CHECKED) ? |
| 221 |
true : false; |
| 222 |
DlgData->Param->DoSameProcessNextDrop = |
| 223 |
(IsDlgButtonChecked(hDlgWnd, IDC_SAME_PROCESS_NEXTDROP_CHECK) == BST_CHECKED) ? |
| 224 |
true : false; |
| 225 |
DlgData->Param->DoNotShowDialog = |
| 226 |
(IsDlgButtonChecked(hDlgWnd, IDC_DONTSHOW_CHECK) == BST_CHECKED) ? |
| 227 |
true : false; |
| 228 |
} |
| 229 |
if (wID == IDCANCEL) { |
| 230 |
DlgData->Param->DropType = DROP_TYPE_CANCEL; |
| 231 |
} |
| 232 |
if (wID == IDOK || wID == IDCANCEL) { |
| 233 |
TTEndDialog(hDlgWnd, wID); |
| 234 |
break; |
| 235 |
} |
| 236 |
return FALSE; |
| 237 |
} |
| 238 |
case WM_NCDESTROY: |
| 239 |
free(DlgData); |
| 240 |
break; |
| 241 |
|
| 242 |
default: |
| 243 |
return FALSE; |
| 244 |
} |
| 245 |
return TRUE; |
| 246 |
} |
| 247 |
|
| 248 |
enum drop_type ShowDropDialogBox( |
| 249 |
HINSTANCE hInstance, HWND hWndParent, |
| 250 |
const wchar_t *TargetFilename, |
| 251 |
enum drop_type DefaultDropType, |
| 252 |
int RemaingFileCount, |
| 253 |
bool EnableSCP, |
| 254 |
bool EnableSendFile, |
| 255 |
bool *SendfileBinary, |
| 256 |
TTTSet *pts, |
| 257 |
unsigned char *DropTypePaste, |
| 258 |
bool *DoSameProcess, |
| 259 |
bool *DoSameProcessNextDrop, |
| 260 |
bool *DoNotShowDialog) |
| 261 |
{ |
| 262 |
DrapDropDlgParam Param; |
| 263 |
Param.TargetFilename = TargetFilename; |
| 264 |
Param.DropType = DefaultDropType; |
| 265 |
Param.DropTypePaste = *DropTypePaste; |
| 266 |
Param.ScpEnable = EnableSCP; |
| 267 |
Param.SendfileEnable = EnableSendFile; |
| 268 |
Param.SendfileBinary = *SendfileBinary; |
| 269 |
Param.RemaingFileCount = RemaingFileCount; |
| 270 |
Param.DoNotShowDialog = *DoNotShowDialog; |
| 271 |
Param.DoNotShowDialogEnable = pts->ConfirmFileDragAndDrop ? false : true, |
| 272 |
Param.ScpSendDirPtr = pts->ScpSendDir; |
| 273 |
Param.ScpSendDirSize = _countof(pts->ScpSendDir); |
| 274 |
Param.UILanguageFile = pts->UILanguageFileW; |
| 275 |
|
| 276 |
INT_PTR ret = TTDialogBoxParam( |
| 277 |
hInstance, MAKEINTRESOURCE(IDD_DAD_DIALOG), |
| 278 |
hWndParent, (DLGPROC)OnDragDropDlgProc, |
| 279 |
(LPARAM)&Param); |
| 280 |
if (ret != IDOK) { |
| 281 |
return DROP_TYPE_CANCEL; |
| 282 |
} |
| 283 |
*DropTypePaste = Param.DropTypePaste; |
| 284 |
*DoSameProcess = Param.DoSameProcess; |
| 285 |
*DoSameProcessNextDrop = Param.DoSameProcessNextDrop; |
| 286 |
*DoNotShowDialog = Param.DoNotShowDialog; |
| 287 |
*SendfileBinary = Param.SendfileBinary; |
| 288 |
return Param.DropType; |
| 289 |
} |