1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

John Sullivan's sizetip patch - experimental

[originally from svn r269]
This commit is contained in:
Simon Tatham 1999-11-03 14:08:26 +00:00
parent 0e3f5802b3
commit 5e76cd7a17
4 changed files with 200 additions and 0 deletions

View File

@ -14,6 +14,8 @@
#define GLOBAL extern
#endif
GLOBAL HINSTANCE putty_inst;
#define ATTR_ACTCURS 0x80000000UL /* active cursor (block) */
#define ATTR_PASCURS 0x40000000UL /* passive cursor (box) */
#define ATTR_INVALID 0x20000000UL

185
sizetip.c Normal file
View File

@ -0,0 +1,185 @@
#include <windows.h>
#include <winreg.h>
#include <tchar.h>
#include <stdio.h>
#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) {
case WM_ERASEBKGND:
return TRUE;
case WM_PAINT:
{
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;
case WM_NCHITTEST:
return HTTRANSPARENT;
case WM_DESTROY:
DeleteObject(tip_font);
tip_font = NULL;
break;
case WM_SETTEXT:
{
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)
{
TCHAR str[16];
if (!tip_enabled) return;
if (!tip_wnd) {
NONCLIENTMETRICS nci;
// First make sure the window class is registered
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);
}
// // 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);
// Prepare other GDI objects and drawing info
tip_bg = GetSysColor(COLOR_INFOBK);
tip_text = GetSysColor(COLOR_INFOTEXT);
memset(&nci, 0, sizeof(NONCLIENTMETRICS));
nci.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &nci, 0);
tip_font = CreateFontIndirect(&nci.lfStatusFont);
}
// Generate the tip text
_sntprintf(str, 16, "%dx%d", cx, cy);
if (!tip_wnd) {
HDC hdc;
SIZE sz;
RECT wr;
int ix, iy;
// calculate the tip's size
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;
// Create the tip window
tip_wnd = CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TOPMOST, MAKEINTRESOURCE(tip_class), str, WS_POPUP,
ix, iy, sz.cx, sz.cy,
NULL, NULL, putty_inst, NULL);
ShowWindow(tip_wnd, SW_SHOWNOACTIVATE);
} else {
// Tip already exists, just set the text
SetWindowText(tip_wnd, str);
}
}
void EnableSizeTip(int bEnable)
{
if (tip_wnd && !bEnable) {
DestroyWindow(tip_wnd);
tip_wnd = NULL;
}
tip_enabled = bEnable;
}

3
sizetip.h Normal file
View File

@ -0,0 +1,3 @@
void UpdateSizeTip(HWND src, int cx, int cy);
void EnableSizeTip(int bEnable);

View File

@ -7,6 +7,7 @@
#define PUTTY_DO_GLOBALS /* actually _define_ globals */
#include "putty.h"
#include "win_res.h"
#include "sizetip.h"
#define IDM_SHOWLOG 0x0010
#define IDM_NEWSESS 0x0020
@ -82,6 +83,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) {
MSG msg;
int guess_width, guess_height;
putty_inst = inst;
winsock_ver = MAKEWORD(1, 1);
if (WSAStartup(winsock_ver, &wsadata)) {
MessageBox(NULL, "Unable to initialise WinSock", "WinSock Error",
@ -871,6 +874,12 @@ static int WINAPI WndProc (HWND hwnd, UINT message,
case WM_IGNORE_SIZE:
ignore_size = TRUE; /* don't panic on next WM_SIZE msg */
break;
case WM_ENTERSIZEMOVE:
EnableSizeTip(1);
break;
case WM_EXITSIZEMOVE:
EnableSizeTip(0);
break;
case WM_SIZING:
{
int width, height, w, h, ew, eh;
@ -880,6 +889,7 @@ static int WINAPI WndProc (HWND hwnd, UINT message,
height = r->bottom - r->top - extra_height;
w = (width + font_width/2) / font_width; if (w < 1) w = 1;
h = (height + font_height/2) / font_height; if (h < 1) h = 1;
UpdateSizeTip(hwnd, w, h);
ew = width - w * font_width;
eh = height - h * font_height;
if (ew != 0) {