Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/teraterm/teraterm/clipboarddlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9380 - (show annotations) (download) (as text)
Fri Aug 20 16:31:56 2021 UTC (2 years, 9 months ago) by zmatsuo
File MIME type: text/x-c++src
File size: 7587 byte(s)
クリップボードペースト確認ダイアログが画面からはみ出さないようにした

- 本来はみ出さないようになっていた
- しかしダイアログサイズが変更されたときはみ出しがおこっていた
- 静的変数をなくした
- ts構造体の直接参照をなくした
- clipboarddlgdata の未使用メンバを削除した
- MoveWindowToDisplayPoint() を ttlib_static.c に追加
  - 指定座標が属するデスクトップから
  - ウィンドウをはみださないよう移動する
1 /*
2 * (C) 2019- 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 "teraterm.h"
30 #include "tttypes.h"
31 #include "vtdisp.h"
32 #include "vtterm.h"
33 #include <string.h>
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <commctrl.h>
37 #define _CRTDBG_MAP_ALLOC
38 #include <crtdbg.h>
39
40 #include "ttwinman.h"
41 #include "ttcommon.h"
42 #include "ttlib.h"
43 #include "dlglib.h"
44 #include "tt_res.h"
45 #include "compat_win.h"
46 #include "win32helper.h"
47
48 #include "clipboarddlg.h"
49
50 typedef struct {
51 clipboarddlgdata *data;
52 int init_width;
53 int init_height;
54 HWND hStatus;
55 int ok2right;
56 int edit2ok;
57 int edit2bottom;
58 } DlgPrivateData;
59
60 static void TTGetCaretPos(HWND hDlgWnd, POINT *p)
61 {
62 if (ActiveWin == IdVT) { // VT Window
63 /*
64 * Caret off ���� GetCaretPos() �����m���������������������A
65 * vtdisp.c �������������������l�����v�Z����
66 */
67 int x, y;
68 DispConvScreenToWin(CursorX, CursorY, &x, &y);
69 p->x = x;
70 p->y = y;
71 }
72 else if (!GetCaretPos(p)) { // Tek Window
73 /*
74 * Tek Window �������������l�������������|������ GetCaretPos() ���g��
75 * GetCaretPos() ���G���[���������������O������ 0, 0 ������������
76 */
77 p->x = 0;
78 p->y = 0;
79 }
80
81 // x, y �������� 0 �������e�E�B���h�E���������������������������A
82 // �������h������ x �� 1 ������
83 if (p->x == 0 && p->y == 0) {
84 p->x = 1;
85 }
86
87 ClientToScreen(GetParent(hDlgWnd), p);
88 }
89
90 static INT_PTR CALLBACK OnClipboardDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
91 {
92 static const DlgTextInfo TextInfos[] = {
93 { 0, "DLG_CLIPBOARD_TITLE" },
94 { IDCANCEL, "BTN_CANCEL" },
95 { IDOK, "BTN_OK" },
96 };
97 RECT rc_dlg;
98 RECT rc_edit, rc_ok, rc_cancel;
99 DlgPrivateData *pdata = (DlgPrivateData *)GetWindowLongPtr(hDlgWnd, DWLP_USER);
100
101 switch (msg) {
102 case WM_INITDIALOG:
103 pdata = (DlgPrivateData *)lp;
104 SetWindowLongPtr(hDlgWnd, DWLP_USER, (LONG_PTR)pdata);
105 SetDlgTextsW(hDlgWnd, TextInfos, _countof(TextInfos), pdata->data->UILanguageFileW);
106
107 SetDlgItemTextW(hDlgWnd, IDC_EDIT, pdata->data->strW_ptr);
108
109 // ���T�C�Y�A�C�R�����E�����\���������������A�X�e�[�^�X�o�[���t�����B
110 InitCommonControls();
111 pdata->hStatus = CreateStatusWindow(
112 WS_CHILD | WS_VISIBLE |
113 CCS_BOTTOM | SBARS_SIZEGRIP, NULL, hDlgWnd, 1);
114
115 // �_�C�A���O���T�C�Y(�����l)
116 GetWindowRect(hDlgWnd, &rc_dlg);
117 pdata->init_width = rc_dlg.right-rc_dlg.left;
118 pdata->init_height = rc_dlg.bottom-rc_dlg.top;
119
120 // �����T�C�Y�����K�v���l���v�Z
121 GetClientRect(hDlgWnd, &rc_dlg);
122 GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
123 GetWindowRect(GetDlgItem(hDlgWnd, IDOK), &rc_ok);
124
125 POINT p;
126 p.x = rc_dlg.right;
127 p.y = rc_dlg.bottom;
128 ClientToScreen(hDlgWnd, &p);
129 pdata->ok2right = p.x - rc_ok.left;
130 pdata->edit2bottom = p.y - rc_edit.bottom;
131 pdata->edit2ok = rc_ok.left - rc_edit.right;
132
133 // �T�C�Y������
134 SetWindowPos(hDlgWnd, NULL, 0, 0,
135 pdata->data->PasteDialogSize.cx, pdata->data->PasteDialogSize.cy,
136 SWP_NOZORDER | SWP_NOMOVE);
137
138 // ���u����
139 POINT CaretPos;
140 TTGetCaretPos(hDlgWnd, &CaretPos);
141 SetWindowPos(hDlgWnd, NULL, CaretPos.x, CaretPos.y,
142 0, 0, SWP_NOSIZE | SWP_NOZORDER);
143
144 // �������������o��������������
145 MoveWindowToDisplayPoint(hDlgWnd, &CaretPos);
146 //MoveWindowToDisplay(hDlgWnd);
147
148 return TRUE;
149
150 case WM_COMMAND:
151 switch (LOWORD(wp)) {
152 case IDOK:
153 {
154 INT_PTR result = IDCANCEL;
155
156 wchar_t *strW;
157 DWORD error = hGetDlgItemTextW(hDlgWnd, IDC_EDIT, &strW);
158 if (error == NO_ERROR) {
159 pdata->data->strW_edited_ptr = strW;
160 result = IDOK;
161 }
162
163 TTEndDialog(hDlgWnd, result);
164 }
165 break;
166
167 case IDCANCEL:
168 TTEndDialog(hDlgWnd, IDCANCEL);
169 break;
170
171 default:
172 return FALSE;
173 }
174 return TRUE;
175
176 case WM_SIZE:
177 {
178 // ���z�u
179 int dlg_w, dlg_h;
180
181 GetClientRect(hDlgWnd, &rc_dlg);
182 dlg_w = rc_dlg.right;
183 dlg_h = rc_dlg.bottom;
184
185 GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
186 GetWindowRect(GetDlgItem(hDlgWnd, IDOK), &rc_ok);
187 GetWindowRect(GetDlgItem(hDlgWnd, IDCANCEL), &rc_cancel);
188
189 // OK
190 p.x = rc_ok.left;
191 p.y = rc_ok.top;
192 ScreenToClient(hDlgWnd, &p);
193 SetWindowPos(GetDlgItem(hDlgWnd, IDOK), 0,
194 dlg_w - pdata->ok2right, p.y, 0, 0,
195 SWP_NOSIZE | SWP_NOZORDER);
196
197 // CANCEL
198 p.x = rc_cancel.left;
199 p.y = rc_cancel.top;
200 ScreenToClient(hDlgWnd, &p);
201 SetWindowPos(GetDlgItem(hDlgWnd, IDCANCEL), 0,
202 dlg_w - pdata->ok2right, p.y, 0, 0,
203 SWP_NOSIZE | SWP_NOZORDER);
204
205 // EDIT
206 p.x = rc_edit.left;
207 p.y = rc_edit.top;
208 ScreenToClient(hDlgWnd, &p);
209 SetWindowPos(GetDlgItem(hDlgWnd, IDC_EDIT), 0,
210 0, 0, dlg_w - p.x - pdata->edit2ok - pdata->ok2right, dlg_h - p.y - pdata->edit2bottom,
211 SWP_NOMOVE | SWP_NOZORDER);
212
213 // �T�C�Y������
214 GetWindowRect(hDlgWnd, &rc_dlg);
215 pdata->data->PasteDialogSize.cx = rc_dlg.right - rc_dlg.left;
216 pdata->data->PasteDialogSize.cy = rc_dlg.bottom - rc_dlg.top;
217
218 // status bar
219 SendMessage(pdata->hStatus , msg , wp , lp);
220 }
221 return TRUE;
222
223 case WM_GETMINMAXINFO:
224 {
225 // �_�C�A���O�������T�C�Y����������������������������
226 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lp;
227 lpmmi->ptMinTrackSize.x = pdata->init_width;
228 lpmmi->ptMinTrackSize.y = pdata->init_height;
229 }
230 return FALSE;
231
232 case WM_DESTROY:
233 DestroyWindow(pdata->hStatus);
234 return 0;
235
236 default:
237 return FALSE;
238 }
239 }
240
241 INT_PTR clipboarddlg(
242 HINSTANCE hInstance,
243 HWND hWndParent,
244 clipboarddlgdata *data)
245 {
246 DlgPrivateData *pdata = (DlgPrivateData * )calloc(sizeof(DlgPrivateData), 1);
247 INT_PTR ret;
248 pdata->data = data;
249 ret = TTDialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CLIPBOARD_DIALOG),
250 hWndParent, OnClipboardDlgProc, (LPARAM)pdata);
251 free(pdata);
252 return ret;
253 }

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