2 * Icontitle window class.
4 * Copyright 1997 Alex Korobka
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * COPYRIGHT: See COPYING in the top level directory
23 * PROJECT: ReactOS User32
24 * PURPOSE: Static control
25 * FILE: lib/user32/controls/icontitle.c
26 * PROGRAMER: Steven Edwards
27 * REVISION HISTORY: 2003/06/21 SAE Created
28 * NOTES: Adapted from Wine
32 #include "user32/regcontrol.h"
35 static BOOL bMultiLineTitle;
36 static HFONT hIconTitleFont;
38 static LRESULT CALLBACK IconTitleWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
40 /*********************************************************************
41 * icon title class descriptor
43 const struct builtin_class_descr ICONTITLE_builtin_class =
45 L"ICONTITLE_CLASS_ATOM", /* name */
46 CS_GLOBALCLASS, /* style */
47 (WNDPROC) IconTitleWndProc, /* procW */
49 (LPCWSTR) IDC_ARROW, /* cursor */ /* FIXME Wine uses IDC_ARROWA */
55 /***********************************************************************
58 HWND ICONTITLE_Create( HWND owner )
61 HINSTANCE instance = (HINSTANCE)GetWindowLongA( owner, GWL_HINSTANCE );
62 LONG style = WS_CLIPSIBLINGS;
64 if (!IsWindowEnabled(owner)) style |= WS_DISABLED;
65 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
66 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
67 style | WS_CHILD, 0, 0, 1, 1,
68 GetParent(owner), 0, instance, NULL );
70 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
72 owner, 0, instance, NULL );
73 //WIN_SetOwner( hWnd, owner ); /* MDI depends on this */
74 SetWindowLongW( hWnd, GWL_STYLE,
75 GetWindowLongW( hWnd, GWL_STYLE ) & ~(WS_CAPTION | WS_BORDER) );
79 /***********************************************************************
80 * ICONTITLE_SetTitlePos
82 static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
84 static WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
92 int length = GetWindowTextW( owner, str, sizeof(str)/sizeof(WCHAR) );
94 while (length && str[length - 1] == ' ') /* remove trailing spaces */
99 lstrcpyW( str, emptyTitleText );
100 length = lstrlenW( str );
103 if (!(hDC = GetDC( hwnd ))) return FALSE;
105 hPrevFont = SelectObject( hDC, hIconTitleFont );
107 SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
108 GetSystemMetrics(SM_CXBORDER) * 2,
109 GetSystemMetrics(SM_CYBORDER) * 2 );
111 DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
112 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
114 SelectObject( hDC, hPrevFont );
115 ReleaseDC( hwnd, hDC );
117 cx = rect.right - rect.left + 4 * GetSystemMetrics(SM_CXBORDER);
118 cy = rect.bottom - rect.top;
120 pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
121 pt.y = GetSystemMetrics(SM_CYICON);
123 /* point is relative to owner, make it relative to parent */
124 MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
126 SetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
130 /***********************************************************************
133 static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
138 COLORREF textColor = 0;
142 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
143 textColor = GetSysColor(COLOR_CAPTIONTEXT);
147 if( GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD )
149 hBrush = (HBRUSH) GetClassLongA(hwnd, GCL_HBRBACKGROUND);
154 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
155 level = GetRValue(logBrush.lbColor) +
156 GetGValue(logBrush.lbColor) +
157 GetBValue(logBrush.lbColor);
158 if( level < (0x7F * 3) )
159 textColor = RGB( 0xFF, 0xFF, 0xFF );
162 hBrush = GetStockObject( WHITE_BRUSH );
166 hBrush = GetStockObject( BLACK_BRUSH );
167 textColor = RGB( 0xFF, 0xFF, 0xFF );
171 GetClientRect( hwnd, &rect );
172 DPtoLP( hDC, (LPPOINT)&rect, 2 );
173 FillRect( hDC, &rect, hBrush );
175 hPrevFont = SelectObject( hDC, hIconTitleFont );
180 INT length = GetWindowTextW( owner, buffer, sizeof(buffer) );
181 SetTextColor( hDC, textColor );
182 SetBkMode( hDC, TRANSPARENT );
184 DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
185 DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
187 SelectObject( hDC, hPrevFont );
189 return (hPrevFont != 0);
192 /***********************************************************************
195 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
196 WPARAM wParam, LPARAM lParam )
198 HWND owner = GetWindow( hWnd, GW_OWNER );
200 if (!IsWindow(hWnd)) return 0;
208 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
209 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
210 hIconTitleFont = CreateFontIndirectA( &logFont );
212 return (hIconTitleFont ? 0 : -1);
216 case WM_NCLBUTTONDBLCLK:
217 return SendMessageW( owner, msg, wParam, lParam );
219 if( wParam ) SetActiveWindow( owner );
224 if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
227 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
228 lParam = SendMessageA( owner, WM_ISACTIVEICON, 0, 0 );
230 lParam = (owner == GetActiveWindow());
231 if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
232 ValidateRect( hWnd, NULL );
235 return DefWindowProcW( hWnd, msg, wParam, lParam );