2 * Icontitle window class.
4 * Copyright 1997 Alex Korobka
15 #include "wine/winuser16.h"
16 #include "wine/unicode.h"
20 static BOOL bMultiLineTitle;
21 static HFONT hIconTitleFont;
23 static LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
25 /*********************************************************************
26 * icon title class descriptor
28 const struct builtin_class_descr ICONTITLE_builtin_class =
30 ICONTITLE_CLASS_ATOM, /* name */
31 CS_GLOBALCLASS, /* style */
32 NULL, /* procA (winproc is Unicode only) */
33 IconTitleWndProc, /* procW */
35 IDC_ARROWA, /* cursor */
41 /***********************************************************************
44 HWND ICONTITLE_Create( HWND owner )
47 HINSTANCE instance = GetWindowLongA( owner, GWL_HINSTANCE );
48 LONG style = WS_CLIPSIBLINGS;
50 if (!IsWindowEnabled(owner)) style |= WS_DISABLED;
51 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
52 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
53 style | WS_CHILD, 0, 0, 1, 1,
54 GetParent(owner), 0, instance, NULL );
56 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
58 owner, 0, instance, NULL );
59 WIN_SetOwner( hWnd, owner ); /* MDI depends on this */
60 SetWindowLongW( hWnd, GWL_STYLE,
61 GetWindowLongW( hWnd, GWL_STYLE ) & ~(WS_CAPTION | WS_BORDER) );
65 /***********************************************************************
66 * ICONTITLE_SetTitlePos
68 static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
70 static WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
78 int length = GetWindowTextW( owner, str, sizeof(str)/sizeof(WCHAR) );
80 while (length && str[length - 1] == ' ') /* remove trailing spaces */
85 strcpyW( str, emptyTitleText );
86 length = strlenW( str );
89 if (!(hDC = GetDC( hwnd ))) return FALSE;
91 hPrevFont = SelectObject( hDC, hIconTitleFont );
93 SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
94 GetSystemMetrics(SM_CXBORDER) * 2,
95 GetSystemMetrics(SM_CYBORDER) * 2 );
97 DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
98 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
100 SelectObject( hDC, hPrevFont );
101 ReleaseDC( hwnd, hDC );
103 cx = rect.right - rect.left + 4 * GetSystemMetrics(SM_CXBORDER);
104 cy = rect.bottom - rect.top;
106 pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
107 pt.y = GetSystemMetrics(SM_CYICON);
109 /* point is relative to owner, make it relative to parent */
110 MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
112 SetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
116 /***********************************************************************
119 static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
124 COLORREF textColor = 0;
128 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
129 textColor = GetSysColor(COLOR_CAPTIONTEXT);
133 if( GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD )
135 hBrush = (HBRUSH) GetClassLongA(hwnd, GCL_HBRBACKGROUND);
140 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
141 level = GetRValue(logBrush.lbColor) +
142 GetGValue(logBrush.lbColor) +
143 GetBValue(logBrush.lbColor);
144 if( level < (0x7F * 3) )
145 textColor = RGB( 0xFF, 0xFF, 0xFF );
148 hBrush = GetStockObject( WHITE_BRUSH );
152 hBrush = GetStockObject( BLACK_BRUSH );
153 textColor = RGB( 0xFF, 0xFF, 0xFF );
157 GetClientRect( hwnd, &rect );
158 DPtoLP( hDC, (LPPOINT)&rect, 2 );
159 FillRect( hDC, &rect, hBrush );
161 hPrevFont = SelectObject( hDC, hIconTitleFont );
166 INT length = GetWindowTextW( owner, buffer, sizeof(buffer) );
167 SetTextColor( hDC, textColor );
168 SetBkMode( hDC, TRANSPARENT );
170 DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
171 DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
173 SelectObject( hDC, hPrevFont );
175 return (hPrevFont != 0);
178 /***********************************************************************
181 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
182 WPARAM wParam, LPARAM lParam )
184 HWND owner = GetWindow( hWnd, GW_OWNER );
186 if (!IsWindow(hWnd)) return 0;
194 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
195 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
196 hIconTitleFont = CreateFontIndirectA( &logFont );
198 return (hIconTitleFont ? 0 : -1);
202 case WM_NCLBUTTONDBLCLK:
203 return SendMessageW( owner, msg, wParam, lParam );
205 if( wParam ) SetActiveWindow( owner );
210 if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
213 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
214 lParam = SendMessageA( owner, WM_ISACTIVEICON, 0, 0 );
216 lParam = (owner == GetActiveWindow());
217 if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
218 ValidateRect( hWnd, NULL );
221 return DefWindowProcW( hWnd, msg, wParam, lParam );