X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/01c034ad857128c51482a563befb374e38ebe668..32874aeac8dacbca26663777b39a79efc5d8dc4b:/sizetip.c diff --git a/sizetip.c b/sizetip.c index 8a37b478..c8832113 100644 --- a/sizetip.c +++ b/sizetip.c @@ -14,75 +14,76 @@ static COLORREF tip_bg; static COLORREF tip_text; static LRESULT CALLBACK SizeTipWndProc(HWND hWnd, UINT nMsg, - WPARAM wParam, LPARAM lParam) + WPARAM wParam, LPARAM lParam) { switch (nMsg) { case WM_ERASEBKGND: - return TRUE; + return TRUE; case WM_PAINT: - { - HBRUSH hbr; - HGDIOBJ holdbr; - RECT cr; - int wtlen; - LPTSTR wt; - HDC hdc; + { + HBRUSH hbr; + HGDIOBJ holdbr; + RECT cr; + int wtlen; + LPTSTR wt; + HDC hdc; - PAINTSTRUCT ps; - hdc = BeginPaint(hWnd, &ps); + PAINTSTRUCT ps; + hdc = BeginPaint(hWnd, &ps); - SelectObject(hdc, tip_font); - SelectObject(hdc, GetStockObject(BLACK_PEN)); + SelectObject(hdc, tip_font); + SelectObject(hdc, GetStockObject(BLACK_PEN)); - hbr = CreateSolidBrush(tip_bg); - holdbr = SelectObject(hdc, hbr); + hbr = CreateSolidBrush(tip_bg); + holdbr = SelectObject(hdc, hbr); - GetClientRect(hWnd, &cr); - Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom); + GetClientRect(hWnd, &cr); + Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom); - wtlen = GetWindowTextLength(hWnd); - wt = (LPTSTR)smalloc((wtlen+1)*sizeof(TCHAR)); - GetWindowText(hWnd, wt, wtlen+1); + wtlen = GetWindowTextLength(hWnd); + wt = (LPTSTR) smalloc((wtlen + 1) * sizeof(TCHAR)); + GetWindowText(hWnd, wt, wtlen + 1); - SetTextColor(hdc, tip_text); - SetBkColor(hdc, tip_bg); + SetTextColor(hdc, tip_text); + SetBkColor(hdc, tip_bg); - TextOut(hdc, cr.left+3, cr.top+3, wt, wtlen); + TextOut(hdc, cr.left + 3, cr.top + 3, wt, wtlen); - sfree(wt); + sfree(wt); - SelectObject(hdc, holdbr); - DeleteObject(hbr); + SelectObject(hdc, holdbr); + DeleteObject(hbr); - EndPaint(hWnd, &ps); - } - return 0; + EndPaint(hWnd, &ps); + } + return 0; case WM_NCHITTEST: - return HTTRANSPARENT; + return HTTRANSPARENT; case WM_DESTROY: - DeleteObject(tip_font); - tip_font = NULL; - break; + DeleteObject(tip_font); + tip_font = NULL; + break; case WM_SETTEXT: - { - LPCTSTR str = (LPCTSTR)lParam; - SIZE sz; - HDC hdc = CreateCompatibleDC(NULL); + { + LPCTSTR str = (LPCTSTR) lParam; + SIZE sz; + HDC hdc = CreateCompatibleDC(NULL); - SelectObject(hdc, tip_font); - GetTextExtentPoint32(hdc, str, _tcslen(str), &sz); + 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); + SetWindowPos(hWnd, NULL, 0, 0, sz.cx + 6, sz.cy + 6, + SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); + InvalidateRect(hWnd, NULL, FALSE); - DeleteDC(hdc); - } - break; + DeleteDC(hdc); + } + break; } return DefWindowProc(hWnd, nMsg, wParam, lParam); @@ -95,46 +96,47 @@ void UpdateSizeTip(HWND src, int cx, int cy) { TCHAR str[32]; - if (!tip_enabled) return; + 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 = hinst; - wc.hIcon = NULL; - wc.hCursor = NULL; - wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; - wc.lpszClassName = "SizeTipClass"; - - tip_class = RegisterClass(&wc); - } - + 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 = hinst; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.lpszClassName = "SizeTipClass"; + + tip_class = RegisterClass(&wc); + } #if 0 - /* Default values based on Windows Standard color scheme */ + /* 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); + tip_font = GetStockObject(SYSTEM_FONT); + tip_bg = RGB(255, 255, 225); + tip_text = RGB(0, 0, 0); #endif - /* Prepare other GDI objects and drawing info */ + /* Prepare other GDI objects and drawing info */ - tip_bg = GetSysColor(COLOR_INFOBK); - tip_text = GetSysColor(COLOR_INFOTEXT); + 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); + 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 */ @@ -142,46 +144,49 @@ void UpdateSizeTip(HWND src, int cx, int cy) sprintf(str, "%dx%d", cx, cy); if (!tip_wnd) { - HDC hdc; - SIZE sz; - RECT wr; - int ix, iy; + HDC hdc; + SIZE sz; + RECT wr; + int ix, iy; - /* calculate the tip's size */ + /* calculate the tip's size */ - hdc = CreateCompatibleDC(NULL); - GetTextExtentPoint32(hdc, str, _tcslen(str), &sz); - DeleteDC(hdc); + hdc = CreateCompatibleDC(NULL); + GetTextExtentPoint32(hdc, str, _tcslen(str), &sz); + DeleteDC(hdc); - GetWindowRect(src, &wr); + GetWindowRect(src, &wr); - ix = wr.left; - if (ix<16) ix = 16; + ix = wr.left; + if (ix < 16) + ix = 16; - iy = wr.top - sz.cy; - if (iy<16) iy = 16; + iy = wr.top - sz.cy; + if (iy < 16) + iy = 16; - /* Create the tip window */ + /* 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, hinst, NULL); + tip_wnd = + CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, + MAKEINTRESOURCE(tip_class), str, WS_POPUP, ix, + iy, sz.cx, sz.cy, NULL, NULL, hinst, NULL); - ShowWindow(tip_wnd, SW_SHOWNOACTIVATE); + ShowWindow(tip_wnd, SW_SHOWNOACTIVATE); } else { - /* Tip already exists, just set the text */ + /* Tip already exists, just set the text */ - SetWindowText(tip_wnd, str); + SetWindowText(tip_wnd, str); } } void EnableSizeTip(int bEnable) { if (tip_wnd && !bEnable) { - DestroyWindow(tip_wnd); - tip_wnd = NULL; + DestroyWindow(tip_wnd); + tip_wnd = NULL; } tip_enabled = bEnable;