1999-11-03 17:08:26 +03:00
|
|
|
#include <windows.h>
|
|
|
|
#include <winreg.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <stdio.h>
|
1999-11-22 13:07:24 +03:00
|
|
|
#include <stdlib.h>
|
1999-11-03 17:08:26 +03:00
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
|
|
|
|
ATOM tip_class = 0;
|
|
|
|
|
|
|
|
HFONT tip_font;
|
|
|
|
COLORREF tip_bg;
|
|
|
|
COLORREF tip_text;
|
|
|
|
|
|
|
|
LRESULT CALLBACK SizeTipWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (nMsg) {
|
1999-11-08 14:13:53 +03:00
|
|
|
case WM_ERASEBKGND:
|
1999-11-03 17:08:26 +03:00
|
|
|
return TRUE;
|
|
|
|
|
1999-11-08 14:13:53 +03:00
|
|
|
case WM_PAINT:
|
1999-11-03 17:08:26 +03:00
|
|
|
{
|
|
|
|
HBRUSH hbr;
|
|
|
|
HGDIOBJ holdbr;
|
|
|
|
RECT cr;
|
|
|
|
int wtlen;
|
|
|
|
LPTSTR wt;
|
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
hdc = BeginPaint(hWnd, &ps);
|
|
|
|
|
|
|
|
SelectObject(hdc, tip_font);
|
|
|
|
SelectObject(hdc, GetStockObject(BLACK_PEN));
|
|
|
|
|
|
|
|
hbr = CreateSolidBrush(tip_bg);
|
|
|
|
holdbr = SelectObject(hdc, hbr);
|
|
|
|
|
|
|
|
GetClientRect(hWnd, &cr);
|
|
|
|
Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
|
|
|
|
|
|
|
|
wtlen = GetWindowTextLength(hWnd);
|
|
|
|
wt = (LPTSTR)malloc((wtlen+1)*sizeof(TCHAR));
|
|
|
|
GetWindowText(hWnd, wt, wtlen+1);
|
|
|
|
|
|
|
|
SetTextColor(hdc, tip_text);
|
|
|
|
SetBkColor(hdc, tip_bg);
|
|
|
|
|
|
|
|
TextOut(hdc, cr.left+3, cr.top+3, wt, wtlen);
|
|
|
|
|
|
|
|
free(wt);
|
|
|
|
|
|
|
|
SelectObject(hdc, holdbr);
|
|
|
|
DeleteObject(hbr);
|
|
|
|
|
|
|
|
EndPaint(hWnd, &ps);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
1999-11-08 14:13:53 +03:00
|
|
|
case WM_NCHITTEST:
|
1999-11-03 17:08:26 +03:00
|
|
|
return HTTRANSPARENT;
|
|
|
|
|
1999-11-08 14:13:53 +03:00
|
|
|
case WM_DESTROY:
|
1999-11-03 17:08:26 +03:00
|
|
|
DeleteObject(tip_font);
|
|
|
|
tip_font = NULL;
|
|
|
|
break;
|
|
|
|
|
1999-11-08 14:13:53 +03:00
|
|
|
case WM_SETTEXT:
|
1999-11-03 17:08:26 +03:00
|
|
|
{
|
|
|
|
LPCTSTR str = (LPCTSTR)lParam;
|
|
|
|
SIZE sz;
|
|
|
|
HDC hdc = CreateCompatibleDC(NULL);
|
|
|
|
|
|
|
|
SelectObject(hdc, tip_font);
|
|
|
|
GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);
|
|
|
|
|
|
|
|
SetWindowPos(hWnd, NULL, 0, 0, sz.cx+6, sz.cy+6, SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE);
|
|
|
|
InvalidateRect(hWnd, NULL, FALSE);
|
|
|
|
|
|
|
|
DeleteDC(hdc);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProc(hWnd, nMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND tip_wnd = NULL;
|
|
|
|
int tip_enabled = 0;
|
|
|
|
|
|
|
|
void UpdateSizeTip(HWND src, int cx, int cy)
|
|
|
|
{
|
1999-11-11 13:13:40 +03:00
|
|
|
TCHAR str[32];
|
1999-11-03 17:08:26 +03:00
|
|
|
|
|
|
|
if (!tip_enabled) return;
|
|
|
|
|
|
|
|
if (!tip_wnd) {
|
|
|
|
NONCLIENTMETRICS nci;
|
|
|
|
|
1999-11-08 14:13:53 +03:00
|
|
|
/* First make sure the window class is registered */
|
1999-11-03 17:08:26 +03:00
|
|
|
|
|
|
|
if (!tip_class) {
|
|
|
|
WNDCLASS wc;
|
|
|
|
wc.style = CS_HREDRAW|CS_VREDRAW;
|
|
|
|
wc.lpfnWndProc = SizeTipWndProc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = putty_inst;
|
|
|
|
wc.hIcon = NULL;
|
|
|
|
wc.hCursor = NULL;
|
|
|
|
wc.hbrBackground = NULL;
|
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.lpszClassName = "SizeTipClass";
|
|
|
|
|
|
|
|
tip_class = RegisterClass(&wc);
|
|
|
|
}
|
|
|
|
|
1999-11-08 14:13:53 +03:00
|
|
|
#if 0
|
|
|
|
/* Default values based on Windows Standard color scheme */
|
|
|
|
|
|
|
|
tip_font = GetStockObject(SYSTEM_FONT);
|
|
|
|
tip_bg = RGB(255, 255, 225);
|
|
|
|
tip_text = RGB(0, 0, 0);
|
|
|
|
#endif
|
1999-11-03 17:08:26 +03:00
|
|
|
|
1999-11-08 14:13:53 +03:00
|
|
|
/* Prepare other GDI objects and drawing info */
|
1999-11-03 17:08:26 +03:00
|
|
|
|
|
|
|
tip_bg = GetSysColor(COLOR_INFOBK);
|
|
|
|
tip_text = GetSysColor(COLOR_INFOTEXT);
|
1999-11-08 14:13:53 +03:00
|
|
|
|
1999-11-03 17:08:26 +03:00
|
|
|
memset(&nci, 0, sizeof(NONCLIENTMETRICS));
|
|
|
|
nci.cbSize = sizeof(NONCLIENTMETRICS);
|
|
|
|
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &nci, 0);
|
|
|
|
tip_font = CreateFontIndirect(&nci.lfStatusFont);
|
|
|
|
}
|
|
|
|
|
1999-11-08 14:13:53 +03:00
|
|
|
/* Generate the tip text */
|
1999-11-03 17:08:26 +03:00
|
|
|
|
1999-11-11 13:13:40 +03:00
|
|
|
sprintf(str, "%dx%d", cx, cy);
|
1999-11-03 17:08:26 +03:00
|
|
|
|
|
|
|
if (!tip_wnd) {
|
|
|
|
HDC hdc;
|
|
|
|
SIZE sz;
|
|
|
|
RECT wr;
|
|
|
|
int ix, iy;
|
|
|
|
|
1999-11-08 14:13:53 +03:00
|
|
|
/* calculate the tip's size */
|
1999-11-03 17:08:26 +03:00
|
|
|
|
|
|
|
hdc = CreateCompatibleDC(NULL);
|
|
|
|
GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);
|
|
|
|
DeleteDC(hdc);
|
|
|
|
|
|
|
|
GetWindowRect(src, &wr);
|
|
|
|
|
|
|
|
ix = wr.left;
|
|
|
|
if (ix<16) ix = 16;
|
|
|
|
|
|
|
|
iy = wr.top - sz.cy;
|
|
|
|
if (iy<16) iy = 16;
|
|
|
|
|
1999-11-08 14:13:53 +03:00
|
|
|
/* Create the tip window */
|
1999-11-03 17:08:26 +03:00
|
|
|
|
|
|
|
tip_wnd = CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TOPMOST, MAKEINTRESOURCE(tip_class), str, WS_POPUP,
|
1999-11-08 14:13:53 +03:00
|
|
|
ix, iy, sz.cx, sz.cy,
|
|
|
|
NULL, NULL, putty_inst, NULL);
|
1999-11-03 17:08:26 +03:00
|
|
|
|
|
|
|
ShowWindow(tip_wnd, SW_SHOWNOACTIVATE);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
1999-11-08 14:13:53 +03:00
|
|
|
/* Tip already exists, just set the text */
|
1999-11-03 17:08:26 +03:00
|
|
|
|
|
|
|
SetWindowText(tip_wnd, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableSizeTip(int bEnable)
|
|
|
|
{
|
|
|
|
if (tip_wnd && !bEnable) {
|
|
|
|
DestroyWindow(tip_wnd);
|
|
|
|
tip_wnd = NULL;
|
|
|
|
}
|
1999-11-08 14:13:53 +03:00
|
|
|
|
1999-11-03 17:08:26 +03:00
|
|
|
tip_enabled = bEnable;
|
|
|
|
}
|