Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/sizetip.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8100 - (hide annotations) (download) (as text)
Mon Sep 9 10:34:40 2019 UTC (4 years, 7 months ago) by yutakapon
File MIME type: text/x-csrc
File size: 5442 byte(s)
リサイズ中の縦横サイズツールチップの表示位置をリサイズ後の座標に追従するようにした。
1 zmatsuo 7507 /*
2     * Copyright (C) 2008-2019 TeraTerm Project
3 doda 7089 * 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 7507 /* original idea from PuTTY 0.60 windows/sizetip.c */
29 doda 7089
30     #include "teraterm.h"
31     #include "tttypes.h"
32     #include "ttlib.h"
33     #include "ttwinman.h"
34    
35     #include <windows.h>
36     #include <stdio.h>
37 zmatsuo 7507 #include <tchar.h>
38 doda 7089
39 zmatsuo 7507 #include "TipWin.h"
40    
41     static TipWin *SizeTip;
42 doda 7089 static int tip_enabled = 0;
43    
44 yutakapon 8097 /**
45     * point を
46     * スクリーンからはみ出している場合、入るように補正する
47     * NearestMonitor が TRUE のとき、最も近いモニタ
48     * FALSEのとき、マウスのあるモニタに移動させる
49     * ディスプレイの端から FrameWidth(pixel) より離れるようにする
50     */
51     static void FixPosFromFrame(POINT *point, int FrameWidth, BOOL NearestMonitor)
52     {
53     if (HasMultiMonitorSupport()) {
54     // マルチモニタがサポートされている場合
55     HMONITOR hm;
56     MONITORINFO mi;
57     int ix, iy;
58    
59     // 元の座標を保存しておく
60     ix = point->x;
61     iy = point->y;
62    
63     hm = MonitorFromPoint(*point, MONITOR_DEFAULTTONULL);
64     if (hm == NULL) {
65     if (NearestMonitor) {
66     // 最も近いモニタに表示する
67     hm = MonitorFromPoint(*point, MONITOR_DEFAULTTONEAREST);
68     } else {
69     // スクリーンからはみ出している場合はマウスのあるモニタに表示する
70     GetCursorPos(point);
71     hm = MonitorFromPoint(*point, MONITOR_DEFAULTTONEAREST);
72     }
73     }
74    
75     mi.cbSize = sizeof(MONITORINFO);
76     GetMonitorInfo(hm, &mi);
77     if (ix < mi.rcMonitor.left + FrameWidth) {
78     ix = mi.rcMonitor.left + FrameWidth;
79     }
80     if (iy < mi.rcMonitor.top + FrameWidth) {
81     iy = mi.rcMonitor.top + FrameWidth;
82     }
83    
84     point->x = ix;
85     point->y = iy;
86     }
87     else
88     {
89     // マルチモニタがサポートされていない場合
90     if (point->x < FrameWidth) {
91     point->x = FrameWidth;
92     }
93     if (point->y < FrameWidth) {
94     point->y = FrameWidth;
95     }
96     }
97     }
98    
99 yutakapon 8100 /* リサイズ用ツールチップを表示する
100     *
101     * 引数:
102     * src ウィンドウハンドル
103     * cx, cy ツールチップに表示する縦横サイズ
104     * fwSide リサイズ時にどこのウィンドウを掴んだか
105     * newX, newY リサイズ後の左上の座標
106     *
107     * 注意: Windows9x では動作しない
108     */
109     void UpdateSizeTip(HWND src, int cx, int cy, UINT fwSide, int newX, int newY)
110 doda 7089 {
111     TCHAR str[32];
112 yutakapon 8100 int tooltip_movable = 0;
113 doda 7089
114     if (!tip_enabled)
115     return;
116    
117     /* Generate the tip text */
118 zmatsuo 7507 _stprintf_s(str, _countof(str), _T("%dx%d"), cx, cy);
119 doda 7089
120 yutakapon 8100 // ウィンドウの右、右下、下を掴んだ場合は、ツールチップを左上隅に配置する。
121     // それら以外はリサイズ後の左上隅に配置する。
122     if (!(fwSide == WMSZ_RIGHT || fwSide == WMSZ_BOTTOMRIGHT || fwSide == WMSZ_BOTTOM)) {
123     tooltip_movable = 1;
124     }
125    
126 zmatsuo 7507 if (SizeTip == NULL) {
127 doda 7089 RECT wr;
128 yutakapon 8097 POINT point;
129     int w, h;
130    
131     // 文字列の縦横サイズを取得する
132     TipWinGetTextWidthHeight(src, str, &w, &h);
133    
134 zmatsuo 7507 // ウィンドウの位置を取得
135 doda 7089 GetWindowRect(src, &wr);
136 yutakapon 8100
137 yutakapon 8097 // sizetipを出す位置は、ウィンドウ左上(X, Y)に対して、
138     // (X, Y - 文字列の高さ - FRAME_WIDTH * 2) とする。
139     point.x = wr.left;
140     point.y = wr.top - (h + FRAME_WIDTH * 2);
141     FixPosFromFrame(&point, 16, FALSE);
142     cx = point.x;
143     cy = point.y;
144    
145     SizeTip = TipWinCreate(src, cx, cy, str);
146 yutakapon 8100
147     //OutputDebugPrintf("Created: (%d,%d)\n", cx, cy);
148    
149 doda 7089 } else {
150     /* Tip already exists, just set the text */
151 zmatsuo 7507 TipWinSetText(SizeTip, str);
152     //SetWindowText(tip_wnd, str);
153 yutakapon 8100
154     //OutputDebugPrintf("Updated: (%d,%d)\n", cx, cy);
155    
156     // ウィンドウの左上が移動する場合
157     if (tooltip_movable) {
158     TipWinSetPos(SizeTip, newX + FRAME_WIDTH*2, newY + FRAME_WIDTH*2);
159     //OutputDebugPrintf("Moved: (%d,%d)\n", newX, newY);
160     }
161 doda 7089 }
162     }
163    
164     void EnableSizeTip(int bEnable)
165     {
166 zmatsuo 7507 if (SizeTip && !bEnable) {
167     TipWinDestroy(SizeTip);
168     SizeTip = NULL;
169 doda 7089 }
170    
171     tip_enabled = bEnable;
172     }

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