1997-06-16 17:43:53 +00:00
|
|
|
/*
|
|
|
|
* Icontitle window class.
|
|
|
|
*
|
|
|
|
* Copyright 1997 Alex Korobka
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1997-06-16 17:43:53 +00:00
|
|
|
*/
|
|
|
|
|
2022-08-26 10:23:34 +00:00
|
|
|
#include "user_private.h"
|
2000-12-10 23:01:33 +00:00
|
|
|
#include "controls.h"
|
1997-06-16 17:43:53 +00:00
|
|
|
|
2000-11-27 22:03:23 +00:00
|
|
|
static BOOL bMultiLineTitle;
|
|
|
|
static HFONT hIconTitleFont;
|
1997-06-16 17:43:53 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
2001-08-10 22:51:42 +00:00
|
|
|
* ICONTITLE_SetTitlePos
|
1997-06-16 17:43:53 +00:00
|
|
|
*/
|
2001-08-10 22:51:42 +00:00
|
|
|
static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
|
1997-06-16 17:43:53 +00:00
|
|
|
{
|
2001-08-10 22:51:42 +00:00
|
|
|
WCHAR str[80];
|
|
|
|
HDC hDC;
|
|
|
|
HFONT hPrevFont;
|
|
|
|
RECT rect;
|
|
|
|
INT cx, cy;
|
|
|
|
POINT pt;
|
1997-06-16 17:43:53 +00:00
|
|
|
|
2018-08-08 20:20:04 +00:00
|
|
|
int length = GetWindowTextW( owner, str, ARRAY_SIZE( str ));
|
2001-08-10 22:51:42 +00:00
|
|
|
|
|
|
|
while (length && str[length - 1] == ' ') /* remove trailing spaces */
|
|
|
|
str[--length] = 0;
|
|
|
|
|
|
|
|
if( !length )
|
1997-06-16 17:43:53 +00:00
|
|
|
{
|
2020-09-21 14:31:11 +00:00
|
|
|
lstrcpyW( str, L"<...>" );
|
2020-09-21 11:53:21 +00:00
|
|
|
length = lstrlenW( str );
|
1997-06-16 17:43:53 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 20:24:27 +00:00
|
|
|
if (!(hDC = NtUserGetDC( hwnd ))) return FALSE;
|
1997-06-16 17:43:53 +00:00
|
|
|
|
2001-08-10 22:51:42 +00:00
|
|
|
hPrevFont = SelectObject( hDC, hIconTitleFont );
|
1997-06-16 17:43:53 +00:00
|
|
|
|
2001-08-10 22:51:42 +00:00
|
|
|
SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
|
|
|
|
GetSystemMetrics(SM_CXBORDER) * 2,
|
|
|
|
GetSystemMetrics(SM_CYBORDER) * 2 );
|
1997-06-16 17:43:53 +00:00
|
|
|
|
2001-08-10 22:51:42 +00:00
|
|
|
DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
|
|
|
|
(( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
|
1997-06-16 17:43:53 +00:00
|
|
|
|
2001-08-10 22:51:42 +00:00
|
|
|
SelectObject( hDC, hPrevFont );
|
2022-03-14 10:45:12 +00:00
|
|
|
NtUserReleaseDC( hwnd, hDC );
|
2001-08-10 22:51:42 +00:00
|
|
|
|
|
|
|
cx = rect.right - rect.left + 4 * GetSystemMetrics(SM_CXBORDER);
|
|
|
|
cy = rect.bottom - rect.top;
|
|
|
|
|
|
|
|
pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
|
|
|
|
pt.y = GetSystemMetrics(SM_CYICON);
|
|
|
|
|
|
|
|
/* point is relative to owner, make it relative to parent */
|
|
|
|
MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
|
|
|
|
|
2022-03-15 13:27:14 +00:00
|
|
|
NtUserSetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
|
2001-08-10 22:51:42 +00:00
|
|
|
return TRUE;
|
1997-06-16 17:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ICONTITLE_Paint
|
|
|
|
*/
|
2001-08-10 22:51:42 +00:00
|
|
|
static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
|
1997-06-16 17:43:53 +00:00
|
|
|
{
|
2001-09-19 20:37:04 +00:00
|
|
|
RECT rect;
|
1999-02-26 11:11:13 +00:00
|
|
|
HFONT hPrevFont;
|
2015-11-06 04:00:42 +00:00
|
|
|
HBRUSH hBrush;
|
1997-06-16 17:43:53 +00:00
|
|
|
COLORREF textColor = 0;
|
|
|
|
|
|
|
|
if( bActive )
|
|
|
|
{
|
1999-02-26 11:11:13 +00:00
|
|
|
hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
|
|
|
|
textColor = GetSysColor(COLOR_CAPTIONTEXT);
|
1997-06-16 17:43:53 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
else
|
1997-06-16 17:43:53 +00:00
|
|
|
{
|
2001-08-10 22:51:42 +00:00
|
|
|
if( GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD )
|
2002-05-31 23:06:46 +00:00
|
|
|
{
|
2005-02-15 21:51:06 +00:00
|
|
|
hBrush = (HBRUSH) GetClassLongPtrW(hwnd, GCLP_HBRBACKGROUND);
|
1997-06-16 17:43:53 +00:00
|
|
|
if( hBrush )
|
|
|
|
{
|
1999-02-26 11:11:13 +00:00
|
|
|
INT level;
|
|
|
|
LOGBRUSH logBrush;
|
|
|
|
GetObjectA( hBrush, sizeof(logBrush), &logBrush );
|
1997-06-16 17:43:53 +00:00
|
|
|
level = GetRValue(logBrush.lbColor) +
|
|
|
|
GetGValue(logBrush.lbColor) +
|
|
|
|
GetBValue(logBrush.lbColor);
|
|
|
|
if( level < (0x7F * 3) )
|
|
|
|
textColor = RGB( 0xFF, 0xFF, 0xFF );
|
|
|
|
}
|
|
|
|
else
|
1999-02-26 11:11:13 +00:00
|
|
|
hBrush = GetStockObject( WHITE_BRUSH );
|
1997-06-16 17:43:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-02-26 11:11:13 +00:00
|
|
|
hBrush = GetStockObject( BLACK_BRUSH );
|
2002-05-31 23:06:46 +00:00
|
|
|
textColor = RGB( 0xFF, 0xFF, 0xFF );
|
1997-06-16 17:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-19 20:37:04 +00:00
|
|
|
GetClientRect( hwnd, &rect );
|
|
|
|
DPtoLP( hDC, (LPPOINT)&rect, 2 );
|
|
|
|
FillRect( hDC, &rect, hBrush );
|
1997-06-16 17:43:53 +00:00
|
|
|
|
1999-02-26 11:11:13 +00:00
|
|
|
hPrevFont = SelectObject( hDC, hIconTitleFont );
|
1997-06-16 17:43:53 +00:00
|
|
|
if( hPrevFont )
|
|
|
|
{
|
2001-08-10 22:51:42 +00:00
|
|
|
WCHAR buffer[80];
|
1997-06-16 17:43:53 +00:00
|
|
|
|
2018-08-08 20:20:04 +00:00
|
|
|
INT length = GetWindowTextW( owner, buffer, ARRAY_SIZE( buffer ));
|
1999-02-26 11:11:13 +00:00
|
|
|
SetTextColor( hDC, textColor );
|
|
|
|
SetBkMode( hDC, TRANSPARENT );
|
2001-08-10 22:51:42 +00:00
|
|
|
|
|
|
|
DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
|
|
|
|
DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
|
1997-06-16 17:43:53 +00:00
|
|
|
|
1999-02-26 11:11:13 +00:00
|
|
|
SelectObject( hDC, hPrevFont );
|
1997-06-16 17:43:53 +00:00
|
|
|
}
|
2001-09-19 20:37:04 +00:00
|
|
|
return (hPrevFont != 0);
|
1997-06-16 17:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* IconTitleWndProc
|
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
|
|
|
|
WPARAM wParam, LPARAM lParam )
|
1997-06-16 17:43:53 +00:00
|
|
|
{
|
2001-08-10 22:51:42 +00:00
|
|
|
HWND owner = GetWindow( hWnd, GW_OWNER );
|
1997-06-16 17:43:53 +00:00
|
|
|
|
2001-09-19 20:37:04 +00:00
|
|
|
if (!IsWindow(hWnd)) return 0;
|
2001-07-24 01:16:16 +00:00
|
|
|
|
1997-06-16 17:43:53 +00:00
|
|
|
switch( msg )
|
|
|
|
{
|
2000-12-10 23:01:33 +00:00
|
|
|
case WM_CREATE:
|
|
|
|
if (!hIconTitleFont)
|
|
|
|
{
|
|
|
|
LOGFONTA logFont;
|
|
|
|
SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
|
|
|
|
SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
|
|
|
|
hIconTitleFont = CreateFontIndirectA( &logFont );
|
|
|
|
}
|
2001-09-19 20:37:04 +00:00
|
|
|
return (hIconTitleFont ? 0 : -1);
|
1997-06-16 17:43:53 +00:00
|
|
|
case WM_NCHITTEST:
|
2001-09-19 20:37:04 +00:00
|
|
|
return HTCAPTION;
|
1997-06-16 17:43:53 +00:00
|
|
|
case WM_NCMOUSEMOVE:
|
|
|
|
case WM_NCLBUTTONDBLCLK:
|
2001-09-19 20:37:04 +00:00
|
|
|
return SendMessageW( owner, msg, wParam, lParam );
|
1997-06-16 17:43:53 +00:00
|
|
|
case WM_ACTIVATE:
|
2022-03-11 13:21:31 +00:00
|
|
|
if (wParam) NtUserSetActiveWindow( owner );
|
2001-09-19 20:37:04 +00:00
|
|
|
return 0;
|
1997-06-16 17:43:53 +00:00
|
|
|
case WM_CLOSE:
|
2001-09-19 20:37:04 +00:00
|
|
|
return 0;
|
1997-06-16 17:43:53 +00:00
|
|
|
case WM_SHOWWINDOW:
|
2012-12-21 19:18:48 +00:00
|
|
|
if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
|
2001-09-19 20:37:04 +00:00
|
|
|
return 0;
|
1997-06-16 17:43:53 +00:00
|
|
|
case WM_ERASEBKGND:
|
2006-05-10 19:33:33 +00:00
|
|
|
if( GetWindowLongW( owner, GWL_STYLE ) & WS_CHILD )
|
|
|
|
lParam = SendMessageW( owner, WM_ISACTIVEICON, 0, 0 );
|
2001-09-19 20:37:04 +00:00
|
|
|
else
|
|
|
|
lParam = (owner == GetActiveWindow());
|
|
|
|
if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
|
2022-11-28 20:35:53 +00:00
|
|
|
NtUserValidateRect( hWnd, NULL );
|
2001-09-19 20:37:04 +00:00
|
|
|
return 1;
|
1997-06-16 17:43:53 +00:00
|
|
|
}
|
2001-09-19 20:37:04 +00:00
|
|
|
return DefWindowProcW( hWnd, msg, wParam, lParam );
|
1997-06-16 17:43:53 +00:00
|
|
|
}
|