| 1 |
doda |
7089 |
// 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 |
|
|
// ���T�C�Y�c�[���`�b�v (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 |
|
|
// �}���`���j�^���T�|�[�g�������������� |
| 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 |
|
|
// �c�[���`�b�v���X�N���[�����������o���������������}�E�X���������j�^���\������ |
| 233 |
|
|
GetCursorPos(&p); |
| 234 |
|
|
hm = MonitorFromPoint(p, MONITOR_DEFAULTTONEAREST); |
| 235 |
|
|
#else |
| 236 |
|
|
// �c�[���`�b�v���X�N���[�����������o�������������������������j�^���\������ |
| 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 |
|
|
// �}���`���j�^���T�|�[�g���������������� |
| 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 |
|
|
} |