dwrite: Always initialize output glyph count in GetGlyphs().
[wine.git] / dlls / user32 / icontitle.c
blob3c454ae69fc9f80007b67e7df519a0d8bc8536c0
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "controls.h"
30 #include "win.h"
32 static BOOL bMultiLineTitle;
33 static HFONT hIconTitleFont;
35 /*********************************************************************
36 * icon title class descriptor
38 const struct builtin_class_descr ICONTITLE_builtin_class =
40 (LPCWSTR)ICONTITLE_CLASS_ATOM, /* name */
41 0, /* style */
42 WINPROC_ICONTITLE, /* proc */
43 0, /* extra */
44 IDC_ARROW, /* cursor */
45 0 /* brush */
48 /***********************************************************************
49 * ICONTITLE_SetTitlePos
51 static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
53 WCHAR str[80];
54 HDC hDC;
55 HFONT hPrevFont;
56 RECT rect;
57 INT cx, cy;
58 POINT pt;
60 int length = GetWindowTextW( owner, str, ARRAY_SIZE( str ));
62 while (length && str[length - 1] == ' ') /* remove trailing spaces */
63 str[--length] = 0;
65 if( !length )
67 lstrcpyW( str, L"<...>" );
68 length = lstrlenW( str );
71 if (!(hDC = GetDC( hwnd ))) return FALSE;
73 hPrevFont = SelectObject( hDC, hIconTitleFont );
75 SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
76 GetSystemMetrics(SM_CXBORDER) * 2,
77 GetSystemMetrics(SM_CYBORDER) * 2 );
79 DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
80 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
82 SelectObject( hDC, hPrevFont );
83 ReleaseDC( hwnd, hDC );
85 cx = rect.right - rect.left + 4 * GetSystemMetrics(SM_CXBORDER);
86 cy = rect.bottom - rect.top;
88 pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
89 pt.y = GetSystemMetrics(SM_CYICON);
91 /* point is relative to owner, make it relative to parent */
92 MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
94 SetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
95 return TRUE;
98 /***********************************************************************
99 * ICONTITLE_Paint
101 static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
103 RECT rect;
104 HFONT hPrevFont;
105 HBRUSH hBrush;
106 COLORREF textColor = 0;
108 if( bActive )
110 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
111 textColor = GetSysColor(COLOR_CAPTIONTEXT);
113 else
115 if( GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD )
117 hBrush = (HBRUSH) GetClassLongPtrW(hwnd, GCLP_HBRBACKGROUND);
118 if( hBrush )
120 INT level;
121 LOGBRUSH logBrush;
122 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
123 level = GetRValue(logBrush.lbColor) +
124 GetGValue(logBrush.lbColor) +
125 GetBValue(logBrush.lbColor);
126 if( level < (0x7F * 3) )
127 textColor = RGB( 0xFF, 0xFF, 0xFF );
129 else
130 hBrush = GetStockObject( WHITE_BRUSH );
132 else
134 hBrush = GetStockObject( BLACK_BRUSH );
135 textColor = RGB( 0xFF, 0xFF, 0xFF );
139 GetClientRect( hwnd, &rect );
140 DPtoLP( hDC, (LPPOINT)&rect, 2 );
141 FillRect( hDC, &rect, hBrush );
143 hPrevFont = SelectObject( hDC, hIconTitleFont );
144 if( hPrevFont )
146 WCHAR buffer[80];
148 INT length = GetWindowTextW( owner, buffer, ARRAY_SIZE( buffer ));
149 SetTextColor( hDC, textColor );
150 SetBkMode( hDC, TRANSPARENT );
152 DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
153 DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
155 SelectObject( hDC, hPrevFont );
157 return (hPrevFont != 0);
160 /***********************************************************************
161 * IconTitleWndProc
163 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
164 WPARAM wParam, LPARAM lParam )
166 HWND owner = GetWindow( hWnd, GW_OWNER );
168 if (!IsWindow(hWnd)) return 0;
170 switch( msg )
172 case WM_CREATE:
173 if (!hIconTitleFont)
175 LOGFONTA logFont;
176 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
177 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
178 hIconTitleFont = CreateFontIndirectA( &logFont );
180 return (hIconTitleFont ? 0 : -1);
181 case WM_NCHITTEST:
182 return HTCAPTION;
183 case WM_NCMOUSEMOVE:
184 case WM_NCLBUTTONDBLCLK:
185 return SendMessageW( owner, msg, wParam, lParam );
186 case WM_ACTIVATE:
187 if( wParam ) SetActiveWindow( owner );
188 return 0;
189 case WM_CLOSE:
190 return 0;
191 case WM_SHOWWINDOW:
192 if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
193 return 0;
194 case WM_ERASEBKGND:
195 if( GetWindowLongW( owner, GWL_STYLE ) & WS_CHILD )
196 lParam = SendMessageW( owner, WM_ISACTIVEICON, 0, 0 );
197 else
198 lParam = (owner == GetActiveWindow());
199 if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
200 ValidateRect( hWnd, NULL );
201 return 1;
203 return DefWindowProcW( hWnd, msg, wParam, lParam );