• R/O
  • SSH
  • HTTPS

ttssh2: コミット


コミットメタ情報

リビジョン7089 (tree)
日時2018-04-02 18:07:45
作者doda

ログメッセージ

sizetip 絡みの PuTTY 由来の関数を別ファイルに分離した

ライセンスの影響範囲を明確にする為。

変更サマリ

差分

--- trunk/teraterm/teraterm/vtwin.cpp (revision 7088)
+++ trunk/teraterm/teraterm/vtwin.cpp (revision 7089)
@@ -76,6 +76,7 @@
7676 #include "vtwin.h"
7777 #include "addsetting.h"
7878 #include "winjump.h"
79+#include "sizetip.h"
7980
8081 #include "initguid.h"
8182 //#include "Usbiodef.h"
@@ -2604,225 +2605,6 @@
26042605 CFrameWnd::OnSetFocus(pOldWnd);
26052606 }
26062607
2607-
2608-//
2609-// リサイズツールチップ(based on PuTTY sizetip.c)
2610-//
2611-static ATOM tip_class = 0;
2612-static HFONT tip_font;
2613-static COLORREF tip_bg;
2614-static COLORREF tip_text;
2615-static HWND tip_wnd = NULL;
2616-static int tip_enabled = 0;
2617-
2618-static LRESULT CALLBACK SizeTipWndProc(HWND hWnd, UINT nMsg,
2619- WPARAM wParam, LPARAM lParam)
2620-{
2621-
2622- switch (nMsg) {
2623- case WM_ERASEBKGND:
2624- return TRUE;
2625-
2626- case WM_PAINT:
2627- {
2628- HBRUSH hbr;
2629- HGDIOBJ holdbr;
2630- RECT cr;
2631- int wtlen;
2632- LPTSTR wt;
2633- HDC hdc;
2634-
2635- PAINTSTRUCT ps;
2636- hdc = BeginPaint(hWnd, &ps);
2637-
2638- SelectObject(hdc, tip_font);
2639- SelectObject(hdc, GetStockObject(BLACK_PEN));
2640-
2641- hbr = CreateSolidBrush(tip_bg);
2642- holdbr = SelectObject(hdc, hbr);
2643-
2644- GetClientRect(hWnd, &cr);
2645- Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
2646-
2647- wtlen = GetWindowTextLength(hWnd);
2648- wt = (LPTSTR) malloc((wtlen + 1) * sizeof(TCHAR));
2649- GetWindowText(hWnd, wt, wtlen + 1);
2650-
2651- SetTextColor(hdc, tip_text);
2652- SetBkColor(hdc, tip_bg);
2653-
2654- TextOut(hdc, cr.left + 3, cr.top + 3, wt, wtlen);
2655-
2656- free(wt);
2657-
2658- SelectObject(hdc, holdbr);
2659- DeleteObject(hbr);
2660-
2661- EndPaint(hWnd, &ps);
2662- }
2663- return 0;
2664-
2665- case WM_NCHITTEST:
2666- return HTTRANSPARENT;
2667-
2668- case WM_DESTROY:
2669- DeleteObject(tip_font);
2670- tip_font = NULL;
2671- break;
2672-
2673- case WM_SETTEXT:
2674- {
2675- LPCTSTR str = (LPCTSTR) lParam;
2676- SIZE sz;
2677- HDC hdc = CreateCompatibleDC(NULL);
2678-
2679- SelectObject(hdc, tip_font);
2680- GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);
2681-
2682- SetWindowPos(hWnd, NULL, 0, 0, sz.cx + 6, sz.cy + 6,
2683- SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
2684- InvalidateRect(hWnd, NULL, FALSE);
2685-
2686- DeleteDC(hdc);
2687- }
2688- break;
2689- }
2690-
2691- return DefWindowProc(hWnd, nMsg, wParam, lParam);
2692-}
2693-
2694-static void UpdateSizeTip(HWND src, int cx, int cy)
2695-{
2696- TCHAR str[32];
2697-
2698- if (!tip_enabled)
2699- return;
2700-
2701- if (!tip_wnd) {
2702- NONCLIENTMETRICS nci;
2703-
2704- /* First make sure the window class is registered */
2705-
2706- if (!tip_class) {
2707- WNDCLASS wc;
2708- wc.style = CS_HREDRAW | CS_VREDRAW;
2709- wc.lpfnWndProc = SizeTipWndProc;
2710- wc.cbClsExtra = 0;
2711- wc.cbWndExtra = 0;
2712- wc.hInstance = hInst;
2713- wc.hIcon = NULL;
2714- wc.hCursor = NULL;
2715- wc.hbrBackground = NULL;
2716- wc.lpszMenuName = NULL;
2717- wc.lpszClassName = "SizeTipClass";
2718-
2719- tip_class = RegisterClass(&wc);
2720- }
2721-#if 0
2722- /* Default values based on Windows Standard color scheme */
2723-
2724- tip_font = GetStockObject(SYSTEM_FONT);
2725- tip_bg = RGB(255, 255, 225);
2726- tip_text = RGB(0, 0, 0);
2727-#endif
2728-
2729- /* Prepare other GDI objects and drawing info */
2730-
2731- tip_bg = GetSysColor(COLOR_INFOBK);
2732- tip_text = GetSysColor(COLOR_INFOTEXT);
2733-
2734- memset(&nci, 0, sizeof(NONCLIENTMETRICS));
2735- nci.cbSize = sizeof(NONCLIENTMETRICS);
2736- SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
2737- sizeof(NONCLIENTMETRICS), &nci, 0);
2738- tip_font = CreateFontIndirect(&nci.lfStatusFont);
2739- }
2740-
2741- /* Generate the tip text */
2742-
2743- sprintf(str, "%dx%d", cx, cy);
2744-
2745- if (!tip_wnd) {
2746- HDC hdc;
2747- SIZE sz;
2748- RECT wr;
2749- int ix, iy;
2750- HMONITOR hm;
2751-
2752- /* calculate the tip's size */
2753-
2754- hdc = CreateCompatibleDC(NULL);
2755- GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);
2756- DeleteDC(hdc);
2757-
2758- GetWindowRect(src, &wr);
2759-
2760- ix = wr.left;
2761- iy = wr.top - sz.cy;
2762-
2763- if (HasMultiMonitorSupport()) {
2764- // マルチモニタがサポートされている場合
2765- POINT p;
2766- p.x = ix;
2767- p.y = iy;
2768- hm = MonitorFromPoint(p, MONITOR_DEFAULTTONULL);
2769- if (hm == NULL) {
2770-#if 1
2771- // ツールチップがスクリーンからはみ出している場合はマウスのあるモニタに表示する
2772- GetCursorPos(&p);
2773- hm = MonitorFromPoint(p, MONITOR_DEFAULTTONEAREST);
2774-#else
2775- // ツールチップがスクリーンからはみ出している場合は最も近いモニタに表示する
2776- hm = MonitorFromPoint(p, MONITOR_DEFAULTTONEAREST);
2777-#endif
2778- }
2779- MONITORINFO mi;
2780- mi.cbSize = sizeof(MONITORINFO);
2781- GetMonitorInfo(hm, &mi);
2782- if (ix < mi.rcMonitor.left + 16) {
2783- ix = mi.rcMonitor.left + 16;
2784- }
2785- if (iy < mi.rcMonitor.top + 16) {
2786- iy = mi.rcMonitor.top + 16;
2787- }
2788- }
2789- else {
2790- // マルチモニタがサポートされていない場合
2791- if (ix < 16) {
2792- ix = 16;
2793- }
2794- if (iy < 16) {
2795- iy = 16;
2796- }
2797- }
2798-
2799- /* Create the tip window */
2800-
2801- tip_wnd =
2802- CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
2803- MAKEINTRESOURCE(tip_class), str, WS_POPUP, ix,
2804- iy, sz.cx, sz.cy, NULL, NULL, hInst, NULL);
2805-
2806- ShowWindow(tip_wnd, SW_SHOWNOACTIVATE);
2807-
2808- } else {
2809-
2810- /* Tip already exists, just set the text */
2811-
2812- SetWindowText(tip_wnd, str);
2813- }
2814-}
2815-
2816-static void EnableSizeTip(int bEnable)
2817-{
2818- if (tip_wnd && !bEnable) {
2819- DestroyWindow(tip_wnd);
2820- tip_wnd = NULL;
2821- }
2822-
2823- tip_enabled = bEnable;
2824-}
2825-
28262608 void CVTWindow::OnSize(UINT nType, int cx, int cy)
28272609 {
28282610 RECT R;
--- trunk/teraterm/teraterm/sizetip.c (revision 0)
+++ trunk/teraterm/teraterm/sizetip.c (revision 7089)
@@ -0,0 +1,285 @@
1+// Import from PuTTY 0.60 windows/sizetip.c
2+/*
3+ * PuTTY is copyright 1997-2004 Simon Tatham.
4+ *
5+ * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
6+ * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
7+ * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
8+ * Kuhn, Colin Watson, Christopher Staite, and CORE SDI S.A.
9+ *
10+ * Permission is hereby granted, free of charge, to any person
11+ * obtaining a copy of this software and associated documentation files
12+ * (the "Software"), to deal in the Software without restriction,
13+ * including without limitation the rights to use, copy, modify, merge,
14+ * publish, distribute, sublicense, and/or sell copies of the Software,
15+ * and to permit persons to whom the Software is furnished to do so,
16+ * subject to the following conditions:
17+ *
18+ * The above copyright notice and this permission notice shall be
19+ * included in all copies or substantial portions of the Software.
20+ *
21+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24+ * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
25+ * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28+ */
29+/*
30+ * Copyright (C) 2008-2018 TeraTerm Project
31+ * All rights reserved.
32+ *
33+ * Redistribution and use in source and binary forms, with or without
34+ * modification, are permitted provided that the following conditions
35+ * are met:
36+ *
37+ * 1. Redistributions of source code must retain the above copyright
38+ * notice, this list of conditions and the following disclaimer.
39+ * 2. Redistributions in binary form must reproduce the above copyright
40+ * notice, this list of conditions and the following disclaimer in the
41+ * documentation and/or other materials provided with the distribution.
42+ * 3. The name of the author may not be used to endorse or promote products
43+ * derived from this software without specific prior written permission.
44+ *
45+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
46+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
48+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
49+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
51+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
52+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
53+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
54+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55+ */
56+
57+#include "teraterm.h"
58+#include "tttypes.h"
59+#include "ttlib.h"
60+#include "ttwinman.h"
61+
62+#include <windows.h>
63+#include <stdio.h>
64+
65+//
66+// リサイズツールチップ (based on PuTTY sizetip.c)
67+//
68+static ATOM tip_class = 0;
69+static HFONT tip_font;
70+static COLORREF tip_bg;
71+static COLORREF tip_text;
72+static HWND tip_wnd = NULL;
73+static int tip_enabled = 0;
74+
75+static LRESULT CALLBACK SizeTipWndProc(HWND hWnd, UINT nMsg,
76+ WPARAM wParam, LPARAM lParam)
77+{
78+
79+ switch (nMsg) {
80+ case WM_ERASEBKGND:
81+ return TRUE;
82+
83+ case WM_PAINT:
84+ {
85+ HBRUSH hbr;
86+ HGDIOBJ holdbr;
87+ RECT cr;
88+ int wtlen;
89+ LPTSTR wt;
90+ HDC hdc;
91+
92+ PAINTSTRUCT ps;
93+ hdc = BeginPaint(hWnd, &ps);
94+
95+ SelectObject(hdc, tip_font);
96+ SelectObject(hdc, GetStockObject(BLACK_PEN));
97+
98+ hbr = CreateSolidBrush(tip_bg);
99+ holdbr = SelectObject(hdc, hbr);
100+
101+ GetClientRect(hWnd, &cr);
102+ Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
103+
104+ wtlen = GetWindowTextLength(hWnd);
105+ wt = (LPTSTR) malloc((wtlen + 1) * sizeof(TCHAR));
106+ GetWindowText(hWnd, wt, wtlen + 1);
107+
108+ SetTextColor(hdc, tip_text);
109+ SetBkColor(hdc, tip_bg);
110+
111+ TextOut(hdc, cr.left + 3, cr.top + 3, wt, wtlen);
112+
113+ free(wt);
114+
115+ SelectObject(hdc, holdbr);
116+ DeleteObject(hbr);
117+
118+ EndPaint(hWnd, &ps);
119+ }
120+ return 0;
121+
122+ case WM_NCHITTEST:
123+ return HTTRANSPARENT;
124+
125+ case WM_DESTROY:
126+ DeleteObject(tip_font);
127+ tip_font = NULL;
128+ break;
129+
130+ case WM_SETTEXT:
131+ {
132+ LPCTSTR str = (LPCTSTR) lParam;
133+ SIZE sz;
134+ HDC hdc = CreateCompatibleDC(NULL);
135+
136+ SelectObject(hdc, tip_font);
137+ GetTextExtentPoint32(hdc, str, strlen(str), &sz);
138+
139+ SetWindowPos(hWnd, NULL, 0, 0, sz.cx + 6, sz.cy + 6,
140+ SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
141+ InvalidateRect(hWnd, NULL, FALSE);
142+
143+ DeleteDC(hdc);
144+ }
145+ break;
146+ }
147+
148+ return DefWindowProc(hWnd, nMsg, wParam, lParam);
149+}
150+
151+void UpdateSizeTip(HWND src, int cx, int cy)
152+{
153+ TCHAR str[32];
154+
155+ if (!tip_enabled)
156+ return;
157+
158+ if (!tip_wnd) {
159+ NONCLIENTMETRICS nci;
160+
161+ /* First make sure the window class is registered */
162+
163+ if (!tip_class) {
164+ WNDCLASS wc;
165+ wc.style = CS_HREDRAW | CS_VREDRAW;
166+ wc.lpfnWndProc = SizeTipWndProc;
167+ wc.cbClsExtra = 0;
168+ wc.cbWndExtra = 0;
169+ wc.hInstance = hInst;
170+ wc.hIcon = NULL;
171+ wc.hCursor = NULL;
172+ wc.hbrBackground = NULL;
173+ wc.lpszMenuName = NULL;
174+ wc.lpszClassName = "SizeTipClass";
175+
176+ tip_class = RegisterClass(&wc);
177+ }
178+#if 0
179+ /* Default values based on Windows Standard color scheme */
180+
181+ tip_font = GetStockObject(SYSTEM_FONT);
182+ tip_bg = RGB(255, 255, 225);
183+ tip_text = RGB(0, 0, 0);
184+#endif
185+
186+ /* Prepare other GDI objects and drawing info */
187+
188+ tip_bg = GetSysColor(COLOR_INFOBK);
189+ tip_text = GetSysColor(COLOR_INFOTEXT);
190+
191+ memset(&nci, 0, sizeof(NONCLIENTMETRICS));
192+ nci.cbSize = sizeof(NONCLIENTMETRICS);
193+ SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
194+ sizeof(NONCLIENTMETRICS), &nci, 0);
195+ tip_font = CreateFontIndirect(&nci.lfStatusFont);
196+ }
197+
198+ /* Generate the tip text */
199+
200+ sprintf(str, "%dx%d", cx, cy);
201+
202+ if (!tip_wnd) {
203+ HDC hdc;
204+ SIZE sz;
205+ RECT wr;
206+ int ix, iy;
207+ HMONITOR hm;
208+
209+ /* calculate the tip's size */
210+
211+ hdc = CreateCompatibleDC(NULL);
212+ GetTextExtentPoint32(hdc, str, strlen(str), &sz);
213+ DeleteDC(hdc);
214+
215+ GetWindowRect(src, &wr);
216+
217+ ix = wr.left;
218+ iy = wr.top - sz.cy;
219+
220+ if (HasMultiMonitorSupport()) {
221+ // マルチモニタがサポートされている場合
222+ POINT p;
223+ MONITORINFO mi;
224+
225+ p.x = ix;
226+ p.y = iy;
227+
228+ hm = MonitorFromPoint(p, MONITOR_DEFAULTTONULL);
229+
230+ if (hm == NULL) {
231+#if 1
232+ // ツールチップがスクリーンからはみ出している場合はマウスのあるモニタに表示する
233+ GetCursorPos(&p);
234+ hm = MonitorFromPoint(p, MONITOR_DEFAULTTONEAREST);
235+#else
236+ // ツールチップがスクリーンからはみ出している場合は最も近いモニタに表示する
237+ hm = MonitorFromPoint(p, MONITOR_DEFAULTTONEAREST);
238+#endif
239+ }
240+
241+ mi.cbSize = sizeof(MONITORINFO);
242+ GetMonitorInfo(hm, &mi);
243+ if (ix < mi.rcMonitor.left + 16) {
244+ ix = mi.rcMonitor.left + 16;
245+ }
246+ if (iy < mi.rcMonitor.top + 16) {
247+ iy = mi.rcMonitor.top + 16;
248+ }
249+ }
250+ else {
251+ // マルチモニタがサポートされていない場合
252+ if (ix < 16) {
253+ ix = 16;
254+ }
255+ if (iy < 16) {
256+ iy = 16;
257+ }
258+ }
259+
260+ /* Create the tip window */
261+
262+ tip_wnd =
263+ CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
264+ MAKEINTRESOURCE(tip_class), str, WS_POPUP, ix,
265+ iy, sz.cx, sz.cy, NULL, NULL, hInst, NULL);
266+
267+ ShowWindow(tip_wnd, SW_SHOWNOACTIVATE);
268+
269+ } else {
270+
271+ /* Tip already exists, just set the text */
272+
273+ SetWindowText(tip_wnd, str);
274+ }
275+}
276+
277+void EnableSizeTip(int bEnable)
278+{
279+ if (tip_wnd && !bEnable) {
280+ DestroyWindow(tip_wnd);
281+ tip_wnd = NULL;
282+ }
283+
284+ tip_enabled = bEnable;
285+}
--- trunk/teraterm/teraterm/sizetip.h (revision 0)
+++ trunk/teraterm/teraterm/sizetip.h (revision 7089)
@@ -0,0 +1,38 @@
1+/*
2+ * Copyright (C) 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+#ifdef __cplusplus
30+extern "C" {
31+#endif
32+
33+void UpdateSizeTip(HWND src, int cx, int cy);
34+void EnableSizeTip(int bEnable);
35+
36+#ifdef __cplusplus
37+}
38+#endif
旧リポジトリブラウザで表示