1997-06-16 19:43:53 +02:00
|
|
|
/*
|
|
|
|
* Icontitle window class.
|
|
|
|
*
|
|
|
|
* Copyright 1997 Alex Korobka
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
1999-01-01 19:57:33 +01:00
|
|
|
#include "winuser.h"
|
|
|
|
#include "wine/winuser16.h"
|
1997-06-16 19:43:53 +02:00
|
|
|
#include "win.h"
|
|
|
|
#include "desktop.h"
|
|
|
|
#include "heap.h"
|
|
|
|
|
|
|
|
static LPCSTR emptyTitleText = "<...>";
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL bMultiLineTitle;
|
|
|
|
HFONT hIconTitleFont;
|
1997-06-16 19:43:53 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ICONTITLE_Init
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL ICONTITLE_Init(void)
|
1997-06-16 19:43:53 +02:00
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
LOGFONTA logFont;
|
1997-06-16 19:43:53 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
|
|
|
|
SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
|
|
|
|
hIconTitleFont = CreateFontIndirectA( &logFont );
|
1997-06-16 19:43:53 +02:00
|
|
|
return (hIconTitleFont) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ICONTITLE_Create
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
HWND ICONTITLE_Create( WND* wnd )
|
1997-06-16 19:43:53 +02:00
|
|
|
{
|
|
|
|
WND* wndPtr;
|
1999-02-26 12:11:13 +01:00
|
|
|
HWND hWnd;
|
1997-06-16 19:43:53 +02:00
|
|
|
|
|
|
|
if( wnd->dwStyle & WS_CHILD )
|
1999-02-26 12:11:13 +01:00
|
|
|
hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
|
1997-06-16 19:43:53 +02:00
|
|
|
WS_CHILD | WS_CLIPSIBLINGS, 0, 0, 1, 1,
|
|
|
|
wnd->parent->hwndSelf, 0, wnd->hInstance, NULL );
|
|
|
|
else
|
1999-02-26 12:11:13 +01:00
|
|
|
hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
|
1997-06-16 19:43:53 +02:00
|
|
|
WS_CLIPSIBLINGS, 0, 0, 1, 1,
|
|
|
|
wnd->hwndSelf, 0, wnd->hInstance, NULL );
|
|
|
|
wndPtr = WIN_FindWndPtr( hWnd );
|
|
|
|
if( wndPtr )
|
|
|
|
{
|
|
|
|
wndPtr->owner = wnd; /* MDI depends on this */
|
|
|
|
wndPtr->dwStyle &= ~(WS_CAPTION | WS_BORDER);
|
|
|
|
if( wnd->dwStyle & WS_DISABLED ) wndPtr->dwStyle |= WS_DISABLED;
|
1999-03-14 18:25:32 +01:00
|
|
|
WIN_ReleaseWndPtr(wndPtr);
|
1997-06-16 19:43:53 +02:00
|
|
|
return hWnd;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ICONTITLE_GetTitlePos
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
static BOOL ICONTITLE_GetTitlePos( WND* wnd, LPRECT lpRect )
|
1997-06-16 19:43:53 +02:00
|
|
|
{
|
|
|
|
LPSTR str;
|
1999-02-26 12:11:13 +01:00
|
|
|
int length = lstrlenA( wnd->owner->text );
|
1997-06-16 19:43:53 +02:00
|
|
|
|
|
|
|
if( length )
|
|
|
|
{
|
|
|
|
str = HeapAlloc( GetProcessHeap(), 0, length + 1 );
|
1999-02-26 12:11:13 +01:00
|
|
|
lstrcpyA( str, wnd->owner->text );
|
1997-06-16 19:43:53 +02:00
|
|
|
while( str[length - 1] == ' ' ) /* remove trailing spaces */
|
|
|
|
{
|
|
|
|
str[--length] = '\0';
|
|
|
|
if( !length )
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, str );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( !length )
|
|
|
|
{
|
|
|
|
str = (LPSTR)emptyTitleText;
|
1999-02-26 12:11:13 +01:00
|
|
|
length = lstrlenA( str );
|
1997-06-16 19:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( str )
|
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
HDC hDC = GetDC( wnd->hwndSelf );
|
1997-06-16 19:43:53 +02:00
|
|
|
if( hDC )
|
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
HFONT hPrevFont = SelectObject( hDC, hIconTitleFont );
|
1997-06-16 19:43:53 +02:00
|
|
|
|
1999-05-22 13:33:23 +02:00
|
|
|
SetRect( lpRect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
|
|
|
|
GetSystemMetrics(SM_CXBORDER) * 2,
|
|
|
|
GetSystemMetrics(SM_CYBORDER) * 2 );
|
1997-06-16 19:43:53 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
DrawTextA( hDC, str, length, lpRect, DT_CALCRECT |
|
1997-06-16 19:43:53 +02:00
|
|
|
DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
|
|
|
|
(( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
SelectObject( hDC, hPrevFont );
|
|
|
|
ReleaseDC( wnd->hwndSelf, hDC );
|
1997-06-16 19:43:53 +02:00
|
|
|
|
1999-05-22 13:33:23 +02:00
|
|
|
lpRect->right += 4 * GetSystemMetrics(SM_CXBORDER) - lpRect->left;
|
|
|
|
lpRect->left = wnd->owner->rectWindow.left + GetSystemMetrics(SM_CXICON) / 2 -
|
1997-06-16 19:43:53 +02:00
|
|
|
(lpRect->right - lpRect->left) / 2;
|
|
|
|
lpRect->bottom -= lpRect->top;
|
1999-05-22 13:33:23 +02:00
|
|
|
lpRect->top = wnd->owner->rectWindow.top + GetSystemMetrics(SM_CYICON);
|
1997-06-16 19:43:53 +02:00
|
|
|
}
|
|
|
|
if( str != emptyTitleText ) HeapFree( GetProcessHeap(), 0, str );
|
|
|
|
return ( hDC ) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ICONTITLE_Paint
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
static BOOL ICONTITLE_Paint( WND* wnd, HDC hDC, BOOL bActive )
|
1997-06-16 19:43:53 +02:00
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
HFONT hPrevFont;
|
|
|
|
HBRUSH hBrush = 0;
|
1997-06-16 19:43:53 +02:00
|
|
|
COLORREF textColor = 0;
|
|
|
|
|
|
|
|
if( bActive )
|
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
|
|
|
|
textColor = GetSysColor(COLOR_CAPTIONTEXT);
|
1997-06-16 19:43:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( wnd->dwStyle & WS_CHILD )
|
|
|
|
{
|
|
|
|
hBrush = wnd->parent->class->hbrBackground;
|
|
|
|
if( hBrush )
|
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
INT level;
|
|
|
|
LOGBRUSH logBrush;
|
|
|
|
GetObjectA( hBrush, sizeof(logBrush), &logBrush );
|
1997-06-16 19:43:53 +02:00
|
|
|
level = GetRValue(logBrush.lbColor) +
|
|
|
|
GetGValue(logBrush.lbColor) +
|
|
|
|
GetBValue(logBrush.lbColor);
|
|
|
|
if( level < (0x7F * 3) )
|
|
|
|
textColor = RGB( 0xFF, 0xFF, 0xFF );
|
|
|
|
}
|
|
|
|
else
|
1999-02-26 12:11:13 +01:00
|
|
|
hBrush = GetStockObject( WHITE_BRUSH );
|
1997-06-16 19:43:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
hBrush = GetStockObject( BLACK_BRUSH );
|
1997-06-16 19:43:53 +02:00
|
|
|
textColor = RGB( 0xFF, 0xFF, 0xFF );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
FillWindow16( wnd->parent->hwndSelf, wnd->hwndSelf, hDC, hBrush );
|
1997-06-16 19:43:53 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
hPrevFont = SelectObject( hDC, hIconTitleFont );
|
1997-06-16 19:43:53 +02:00
|
|
|
if( hPrevFont )
|
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
RECT rect;
|
|
|
|
INT length;
|
1997-06-16 19:43:53 +02:00
|
|
|
char buffer[80];
|
|
|
|
|
|
|
|
rect.left = rect.top = 0;
|
|
|
|
rect.right = wnd->rectWindow.right - wnd->rectWindow.left;
|
|
|
|
rect.bottom = wnd->rectWindow.bottom - wnd->rectWindow.top;
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
length = GetWindowTextA( wnd->owner->hwndSelf, buffer, 80 );
|
|
|
|
SetTextColor( hDC, textColor );
|
|
|
|
SetBkMode( hDC, TRANSPARENT );
|
1997-06-16 19:43:53 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
DrawTextA( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
|
1998-03-29 21:44:57 +02:00
|
|
|
DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
|
1997-06-16 19:43:53 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
SelectObject( hDC, hPrevFont );
|
1997-06-16 19:43:53 +02:00
|
|
|
}
|
|
|
|
return ( hPrevFont ) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* IconTitleWndProc
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
|
|
|
|
WPARAM wParam, LPARAM lParam )
|
1997-06-16 19:43:53 +02:00
|
|
|
{
|
1999-03-14 18:25:32 +01:00
|
|
|
LRESULT retvalue;
|
1997-06-16 19:43:53 +02:00
|
|
|
WND *wnd = WIN_FindWndPtr( hWnd );
|
|
|
|
|
|
|
|
switch( msg )
|
|
|
|
{
|
|
|
|
case WM_NCHITTEST:
|
1999-03-14 18:25:32 +01:00
|
|
|
retvalue = HTCAPTION;
|
|
|
|
goto END;
|
1997-06-16 19:43:53 +02:00
|
|
|
case WM_NCMOUSEMOVE:
|
|
|
|
case WM_NCLBUTTONDBLCLK:
|
1999-03-14 18:25:32 +01:00
|
|
|
retvalue = SendMessageA( wnd->owner->hwndSelf, msg, wParam, lParam );
|
|
|
|
goto END;
|
1997-06-16 19:43:53 +02:00
|
|
|
case WM_ACTIVATE:
|
1999-02-26 12:11:13 +01:00
|
|
|
if( wParam ) SetActiveWindow( wnd->owner->hwndSelf );
|
1997-06-16 19:43:53 +02:00
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
1999-03-14 18:25:32 +01:00
|
|
|
retvalue = 0;
|
|
|
|
goto END;
|
1997-06-16 19:43:53 +02:00
|
|
|
case WM_SHOWWINDOW:
|
|
|
|
if( wnd && wParam )
|
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
RECT titleRect;
|
1997-06-16 19:43:53 +02:00
|
|
|
|
|
|
|
ICONTITLE_GetTitlePos( wnd, &titleRect );
|
|
|
|
if( wnd->owner->next != wnd ) /* keep icon title behind the owner */
|
1999-02-26 12:11:13 +01:00
|
|
|
SetWindowPos( hWnd, wnd->owner->hwndSelf,
|
1997-06-16 19:43:53 +02:00
|
|
|
titleRect.left, titleRect.top,
|
|
|
|
titleRect.right, titleRect.bottom, SWP_NOACTIVATE );
|
|
|
|
else
|
1999-02-26 12:11:13 +01:00
|
|
|
SetWindowPos( hWnd, 0, titleRect.left, titleRect.top,
|
1997-06-16 19:43:53 +02:00
|
|
|
titleRect.right, titleRect.bottom,
|
|
|
|
SWP_NOACTIVATE | SWP_NOZORDER );
|
|
|
|
}
|
1999-03-14 18:25:32 +01:00
|
|
|
retvalue = 0;
|
|
|
|
goto END;
|
1997-06-16 19:43:53 +02:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
if( wnd )
|
|
|
|
{
|
1999-03-14 18:25:32 +01:00
|
|
|
WND* iconWnd = WIN_LockWndPtr(wnd->owner);
|
1997-06-16 19:43:53 +02:00
|
|
|
|
|
|
|
if( iconWnd->dwStyle & WS_CHILD )
|
1999-02-26 12:11:13 +01:00
|
|
|
lParam = SendMessageA( iconWnd->hwndSelf, WM_ISACTIVEICON, 0, 0 );
|
1997-06-16 19:43:53 +02:00
|
|
|
else
|
|
|
|
lParam = (iconWnd->hwndSelf == GetActiveWindow16());
|
|
|
|
|
1999-03-14 18:25:32 +01:00
|
|
|
WIN_ReleaseWndPtr(iconWnd);
|
1999-02-26 12:11:13 +01:00
|
|
|
if( ICONTITLE_Paint( wnd, (HDC)wParam, (BOOL)lParam ) )
|
|
|
|
ValidateRect( hWnd, NULL );
|
1999-03-14 18:25:32 +01:00
|
|
|
retvalue = 1;
|
|
|
|
goto END;
|
1997-06-16 19:43:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-14 18:25:32 +01:00
|
|
|
retvalue = DefWindowProcA( hWnd, msg, wParam, lParam );
|
|
|
|
END:
|
|
|
|
WIN_ReleaseWndPtr(wnd);
|
|
|
|
return retvalue;
|
1997-06-16 19:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|