1997-06-16 19:43:53 +02:00
|
|
|
/*
|
|
|
|
* Icontitle window class.
|
|
|
|
*
|
|
|
|
* Copyright 1997 Alex Korobka
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2000-12-19 05:53:20 +01:00
|
|
|
|
2000-02-10 20:03:02 +01:00
|
|
|
#include "windef.h"
|
2000-12-19 05:53:20 +01:00
|
|
|
#include "winbase.h"
|
2000-02-10 20:03:02 +01:00
|
|
|
#include "wingdi.h"
|
1999-01-01 19:57:33 +01:00
|
|
|
#include "winuser.h"
|
|
|
|
#include "wine/winuser16.h"
|
2000-08-14 16:41:19 +02:00
|
|
|
#include "wine/unicode.h"
|
2000-12-11 00:01:33 +01:00
|
|
|
#include "controls.h"
|
1997-06-16 19:43:53 +02:00
|
|
|
#include "win.h"
|
|
|
|
|
2000-11-27 23:03:23 +01:00
|
|
|
static BOOL bMultiLineTitle;
|
|
|
|
static HFONT hIconTitleFont;
|
1997-06-16 19:43:53 +02:00
|
|
|
|
2000-12-11 00:01:33 +01:00
|
|
|
static LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* icon title class descriptor
|
1997-06-16 19:43:53 +02:00
|
|
|
*/
|
2000-12-11 00:01:33 +01:00
|
|
|
const struct builtin_class_descr ICONTITLE_builtin_class =
|
1997-06-16 19:43:53 +02:00
|
|
|
{
|
2000-12-11 00:01:33 +01:00
|
|
|
ICONTITLE_CLASS_ATOM, /* name */
|
|
|
|
CS_GLOBALCLASS, /* style */
|
|
|
|
NULL, /* procA (winproc is Unicode only) */
|
|
|
|
IconTitleWndProc, /* procW */
|
|
|
|
0, /* extra */
|
|
|
|
IDC_ARROWA, /* cursor */
|
|
|
|
0 /* brush */
|
|
|
|
};
|
|
|
|
|
1997-06-16 19:43:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ICONTITLE_Create
|
|
|
|
*/
|
2001-08-11 00:51:42 +02:00
|
|
|
HWND ICONTITLE_Create( HWND owner )
|
1997-06-16 19:43:53 +02:00
|
|
|
{
|
|
|
|
WND* wndPtr;
|
1999-02-26 12:11:13 +01:00
|
|
|
HWND hWnd;
|
2001-08-11 00:51:42 +02:00
|
|
|
HINSTANCE instance = GetWindowLongA( owner, GWL_HINSTANCE );
|
1997-06-16 19:43:53 +02:00
|
|
|
|
2001-08-11 00:51:42 +02:00
|
|
|
if( GetWindowLongA( owner, GWL_STYLE ) & 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,
|
2001-08-11 00:51:42 +02:00
|
|
|
GetParent(owner), 0, instance, NULL );
|
1997-06-16 19:43:53 +02:00
|
|
|
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,
|
2001-08-11 00:51:42 +02:00
|
|
|
owner, 0, instance, NULL );
|
1997-06-16 19:43:53 +02:00
|
|
|
wndPtr = WIN_FindWndPtr( hWnd );
|
|
|
|
if( wndPtr )
|
|
|
|
{
|
2001-08-11 00:51:42 +02:00
|
|
|
WND *wnd = WIN_FindWndPtr(owner);
|
1997-06-16 19:43:53 +02:00
|
|
|
wndPtr->owner = wnd; /* MDI depends on this */
|
|
|
|
wndPtr->dwStyle &= ~(WS_CAPTION | WS_BORDER);
|
2001-08-11 00:51:42 +02:00
|
|
|
if (!IsWindowEnabled(owner)) wndPtr->dwStyle |= WS_DISABLED;
|
1999-03-14 18:25:32 +01:00
|
|
|
WIN_ReleaseWndPtr(wndPtr);
|
2001-08-11 00:51:42 +02:00
|
|
|
WIN_ReleaseWndPtr(wnd);
|
1997-06-16 19:43:53 +02:00
|
|
|
return hWnd;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-08-11 00:51:42 +02:00
|
|
|
* ICONTITLE_SetTitlePos
|
1997-06-16 19:43:53 +02:00
|
|
|
*/
|
2001-08-11 00:51:42 +02:00
|
|
|
static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
|
1997-06-16 19:43:53 +02:00
|
|
|
{
|
2000-07-10 14:09:31 +02:00
|
|
|
static WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
|
2001-08-11 00:51:42 +02:00
|
|
|
WCHAR str[80];
|
|
|
|
HDC hDC;
|
|
|
|
HFONT hPrevFont;
|
|
|
|
RECT rect;
|
|
|
|
INT cx, cy;
|
|
|
|
POINT pt;
|
1997-06-16 19:43:53 +02:00
|
|
|
|
2001-08-11 00:51:42 +02:00
|
|
|
int length = GetWindowTextW( owner, str, sizeof(str)/sizeof(WCHAR) );
|
|
|
|
|
|
|
|
while (length && str[length - 1] == ' ') /* remove trailing spaces */
|
|
|
|
str[--length] = 0;
|
|
|
|
|
|
|
|
if( !length )
|
1997-06-16 19:43:53 +02:00
|
|
|
{
|
2001-08-11 00:51:42 +02:00
|
|
|
strcpyW( str, emptyTitleText );
|
|
|
|
length = strlenW( str );
|
1997-06-16 19:43:53 +02:00
|
|
|
}
|
|
|
|
|
2001-08-11 00:51:42 +02:00
|
|
|
if (!(hDC = GetDC( hwnd ))) return FALSE;
|
1997-06-16 19:43:53 +02:00
|
|
|
|
2001-08-11 00:51:42 +02:00
|
|
|
hPrevFont = SelectObject( hDC, hIconTitleFont );
|
1997-06-16 19:43:53 +02:00
|
|
|
|
2001-08-11 00:51:42 +02:00
|
|
|
SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
|
|
|
|
GetSystemMetrics(SM_CXBORDER) * 2,
|
|
|
|
GetSystemMetrics(SM_CYBORDER) * 2 );
|
1997-06-16 19:43:53 +02:00
|
|
|
|
2001-08-11 00:51:42 +02:00
|
|
|
DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
|
|
|
|
(( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
|
1997-06-16 19:43:53 +02:00
|
|
|
|
2001-08-11 00:51:42 +02:00
|
|
|
SelectObject( hDC, hPrevFont );
|
|
|
|
ReleaseDC( hwnd, hDC );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
SetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
|
|
|
|
return TRUE;
|
1997-06-16 19:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ICONTITLE_Paint
|
|
|
|
*/
|
2001-08-11 00:51:42 +02:00
|
|
|
static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, 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
|
|
|
|
{
|
2001-08-11 00:51:42 +02:00
|
|
|
if( GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD )
|
1997-06-16 19:43:53 +02:00
|
|
|
{
|
2001-08-11 00:51:42 +02:00
|
|
|
hBrush = (HBRUSH) GetClassLongA(hwnd, GCL_HBRBACKGROUND);
|
1997-06-16 19:43:53 +02:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-11 00:51:42 +02:00
|
|
|
FillWindow16( GetParent(hwnd), hwnd, 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;
|
2001-08-11 00:51:42 +02:00
|
|
|
WCHAR buffer[80];
|
1997-06-16 19:43:53 +02:00
|
|
|
|
2001-08-11 00:51:42 +02:00
|
|
|
GetClientRect( hwnd, &rect );
|
1997-06-16 19:43:53 +02:00
|
|
|
|
2001-08-11 00:51:42 +02:00
|
|
|
length = GetWindowTextW( owner, buffer, 80 );
|
1999-02-26 12:11:13 +01:00
|
|
|
SetTextColor( hDC, textColor );
|
|
|
|
SetBkMode( hDC, TRANSPARENT );
|
2001-08-11 00:51:42 +02:00
|
|
|
|
|
|
|
DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
|
|
|
|
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;
|
2001-08-11 00:51:42 +02:00
|
|
|
HWND owner = GetWindow( hWnd, GW_OWNER );
|
1997-06-16 19:43:53 +02:00
|
|
|
WND *wnd = WIN_FindWndPtr( hWnd );
|
|
|
|
|
2001-07-24 03:16:16 +02:00
|
|
|
if( !wnd )
|
|
|
|
return 0;
|
|
|
|
|
1997-06-16 19:43:53 +02:00
|
|
|
switch( msg )
|
|
|
|
{
|
2000-12-11 00:01:33 +01:00
|
|
|
case WM_CREATE:
|
|
|
|
if (!hIconTitleFont)
|
|
|
|
{
|
|
|
|
LOGFONTA logFont;
|
|
|
|
SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
|
|
|
|
SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
|
|
|
|
hIconTitleFont = CreateFontIndirectA( &logFont );
|
|
|
|
}
|
|
|
|
retvalue = (hIconTitleFont) ? 0 : -1;
|
|
|
|
goto END;
|
1997-06-16 19:43:53 +02:00
|
|
|
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:
|
2001-08-11 00:51:42 +02:00
|
|
|
retvalue = SendMessageW( owner, msg, wParam, lParam );
|
1999-03-14 18:25:32 +01:00
|
|
|
goto END;
|
1997-06-16 19:43:53 +02:00
|
|
|
case WM_ACTIVATE:
|
2001-08-11 00:51:42 +02:00
|
|
|
if( wParam ) SetActiveWindow( owner );
|
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:
|
2001-08-11 00:51:42 +02:00
|
|
|
if( wnd && wParam ) ICONTITLE_SetTitlePos( hWnd, owner );
|
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 )
|
|
|
|
{
|
2001-08-11 00:51:42 +02:00
|
|
|
if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
|
|
|
|
lParam = SendMessageA( owner, WM_ISACTIVEICON, 0, 0 );
|
1997-06-16 19:43:53 +02:00
|
|
|
else
|
2001-08-11 00:51:42 +02:00
|
|
|
lParam = (owner == GetActiveWindow());
|
|
|
|
if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
|
1999-02-26 12:11:13 +01:00
|
|
|
ValidateRect( hWnd, NULL );
|
1999-03-14 18:25:32 +01:00
|
|
|
retvalue = 1;
|
|
|
|
goto END;
|
1997-06-16 19:43:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-11 00:01:33 +01:00
|
|
|
retvalue = DefWindowProcW( hWnd, msg, wParam, lParam );
|
1999-03-14 18:25:32 +01:00
|
|
|
END:
|
|
|
|
WIN_ReleaseWndPtr(wnd);
|
|
|
|
return retvalue;
|
1997-06-16 19:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|