2 * Icontitle window class.
4 * Copyright 1997 Alex Korobka
15 #include "wine/winuser16.h"
16 #include "wine/unicode.h"
21 static BOOL bMultiLineTitle;
22 static HFONT hIconTitleFont;
24 static LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
26 /*********************************************************************
27 * icon title class descriptor
29 const struct builtin_class_descr ICONTITLE_builtin_class =
31 ICONTITLE_CLASS_ATOM, /* name */
32 CS_GLOBALCLASS, /* style */
33 NULL, /* procA (winproc is Unicode only) */
34 IconTitleWndProc, /* procW */
36 IDC_ARROWA, /* cursor */
42 /***********************************************************************
45 HWND ICONTITLE_Create( WND* wnd )
50 if( wnd->dwStyle & WS_CHILD )
51 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
52 WS_CHILD | WS_CLIPSIBLINGS, 0, 0, 1, 1,
53 wnd->parent->hwndSelf, 0, wnd->hInstance, NULL );
55 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
56 WS_CLIPSIBLINGS, 0, 0, 1, 1,
57 wnd->hwndSelf, 0, wnd->hInstance, NULL );
58 wndPtr = WIN_FindWndPtr( hWnd );
61 wndPtr->owner = wnd; /* MDI depends on this */
62 wndPtr->dwStyle &= ~(WS_CAPTION | WS_BORDER);
63 if( wnd->dwStyle & WS_DISABLED ) wndPtr->dwStyle |= WS_DISABLED;
64 WIN_ReleaseWndPtr(wndPtr);
70 /***********************************************************************
71 * ICONTITLE_GetTitlePos
73 static BOOL ICONTITLE_GetTitlePos( WND* wnd, LPRECT lpRect )
75 static WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
77 int length = lstrlenW( wnd->owner->text );
81 str = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR) );
82 strcpyW( str, wnd->owner->text );
83 while( str[length - 1] == ' ' ) /* remove trailing spaces */
88 HeapFree( GetProcessHeap(), 0, str );
96 length = lstrlenW( str );
101 HDC hDC = GetDC( wnd->hwndSelf );
104 HFONT hPrevFont = SelectObject( hDC, hIconTitleFont );
106 SetRect( lpRect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
107 GetSystemMetrics(SM_CXBORDER) * 2,
108 GetSystemMetrics(SM_CYBORDER) * 2 );
110 DrawTextW( hDC, str, length, lpRect, DT_CALCRECT |
111 DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
112 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
114 SelectObject( hDC, hPrevFont );
115 ReleaseDC( wnd->hwndSelf, hDC );
117 lpRect->right += 4 * GetSystemMetrics(SM_CXBORDER) - lpRect->left;
118 lpRect->left = wnd->owner->rectWindow.left + GetSystemMetrics(SM_CXICON) / 2 -
119 (lpRect->right - lpRect->left) / 2;
120 lpRect->bottom -= lpRect->top;
121 lpRect->top = wnd->owner->rectWindow.top + GetSystemMetrics(SM_CYICON);
123 if( str != emptyTitleText ) HeapFree( GetProcessHeap(), 0, str );
124 return ( hDC ) ? TRUE : FALSE;
129 /***********************************************************************
132 static BOOL ICONTITLE_Paint( WND* wnd, HDC hDC, BOOL bActive )
136 COLORREF textColor = 0;
140 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
141 textColor = GetSysColor(COLOR_CAPTIONTEXT);
145 if( wnd->dwStyle & WS_CHILD )
147 hBrush = (HBRUSH) GetClassLongA(wnd->hwndSelf, GCL_HBRBACKGROUND);
152 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
153 level = GetRValue(logBrush.lbColor) +
154 GetGValue(logBrush.lbColor) +
155 GetBValue(logBrush.lbColor);
156 if( level < (0x7F * 3) )
157 textColor = RGB( 0xFF, 0xFF, 0xFF );
160 hBrush = GetStockObject( WHITE_BRUSH );
164 hBrush = GetStockObject( BLACK_BRUSH );
165 textColor = RGB( 0xFF, 0xFF, 0xFF );
169 FillWindow16( wnd->parent->hwndSelf, wnd->hwndSelf, hDC, hBrush );
171 hPrevFont = SelectObject( hDC, hIconTitleFont );
178 rect.left = rect.top = 0;
179 rect.right = wnd->rectWindow.right - wnd->rectWindow.left;
180 rect.bottom = wnd->rectWindow.bottom - wnd->rectWindow.top;
182 length = GetWindowTextA( wnd->owner->hwndSelf, buffer, 80 );
183 SetTextColor( hDC, textColor );
184 SetBkMode( hDC, TRANSPARENT );
186 DrawTextA( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
187 DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
189 SelectObject( hDC, hPrevFont );
191 return ( hPrevFont ) ? TRUE : FALSE;
194 /***********************************************************************
197 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
198 WPARAM wParam, LPARAM lParam )
201 WND *wnd = WIN_FindWndPtr( hWnd );
209 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
210 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
211 hIconTitleFont = CreateFontIndirectA( &logFont );
213 retvalue = (hIconTitleFont) ? 0 : -1;
216 retvalue = HTCAPTION;
219 case WM_NCLBUTTONDBLCLK:
220 retvalue = SendMessageA( wnd->owner->hwndSelf, msg, wParam, lParam );
223 if( wParam ) SetActiveWindow( wnd->owner->hwndSelf );
234 ICONTITLE_GetTitlePos( wnd, &titleRect );
235 if( wnd->owner->next != wnd ) /* keep icon title behind the owner */
236 SetWindowPos( hWnd, wnd->owner->hwndSelf,
237 titleRect.left, titleRect.top,
238 titleRect.right, titleRect.bottom, SWP_NOACTIVATE );
240 SetWindowPos( hWnd, 0, titleRect.left, titleRect.top,
241 titleRect.right, titleRect.bottom,
242 SWP_NOACTIVATE | SWP_NOZORDER );
249 WND* iconWnd = WIN_LockWndPtr(wnd->owner);
251 if( iconWnd->dwStyle & WS_CHILD )
252 lParam = SendMessageA( iconWnd->hwndSelf, WM_ISACTIVEICON, 0, 0 );
254 lParam = (iconWnd->hwndSelf == GetActiveWindow16());
256 WIN_ReleaseWndPtr(iconWnd);
257 if( ICONTITLE_Paint( wnd, (HDC)wParam, (BOOL)lParam ) )
258 ValidateRect( hWnd, NULL );
264 retvalue = DefWindowProcW( hWnd, msg, wParam, lParam );
266 WIN_ReleaseWndPtr(wnd);