include: Add missing SQL prototype.
[wine.git] / dlls / user32 / icontitle.c
blob687f2b69d72a7eb6b4818bee72b61323795adaa1
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 "user_private.h"
22 #include "controls.h"
24 static BOOL bMultiLineTitle;
25 static HFONT hIconTitleFont;
27 /***********************************************************************
28 * ICONTITLE_SetTitlePos
30 static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
32 WCHAR str[80];
33 HDC hDC;
34 HFONT hPrevFont;
35 RECT rect;
36 INT cx, cy;
37 POINT pt;
39 int length = GetWindowTextW( owner, str, ARRAY_SIZE( str ));
41 while (length && str[length - 1] == ' ') /* remove trailing spaces */
42 str[--length] = 0;
44 if( !length )
46 lstrcpyW( str, L"<...>" );
47 length = lstrlenW( str );
50 if (!(hDC = NtUserGetDC( hwnd ))) return FALSE;
52 hPrevFont = SelectObject( hDC, hIconTitleFont );
54 SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
55 GetSystemMetrics(SM_CXBORDER) * 2,
56 GetSystemMetrics(SM_CYBORDER) * 2 );
58 DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
59 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
61 SelectObject( hDC, hPrevFont );
62 NtUserReleaseDC( hwnd, hDC );
64 cx = rect.right - rect.left + 4 * GetSystemMetrics(SM_CXBORDER);
65 cy = rect.bottom - rect.top;
67 pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
68 pt.y = GetSystemMetrics(SM_CYICON);
70 /* point is relative to owner, make it relative to parent */
71 MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
73 NtUserSetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
74 return TRUE;
77 /***********************************************************************
78 * ICONTITLE_Paint
80 static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
82 RECT rect;
83 HFONT hPrevFont;
84 HBRUSH hBrush;
85 COLORREF textColor = 0;
87 if( bActive )
89 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
90 textColor = GetSysColor(COLOR_CAPTIONTEXT);
92 else
94 if( GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD )
96 hBrush = (HBRUSH) GetClassLongPtrW(hwnd, GCLP_HBRBACKGROUND);
97 if( hBrush )
99 INT level;
100 LOGBRUSH logBrush;
101 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
102 level = GetRValue(logBrush.lbColor) +
103 GetGValue(logBrush.lbColor) +
104 GetBValue(logBrush.lbColor);
105 if( level < (0x7F * 3) )
106 textColor = RGB( 0xFF, 0xFF, 0xFF );
108 else
109 hBrush = GetStockObject( WHITE_BRUSH );
111 else
113 hBrush = GetStockObject( BLACK_BRUSH );
114 textColor = RGB( 0xFF, 0xFF, 0xFF );
118 GetClientRect( hwnd, &rect );
119 DPtoLP( hDC, (LPPOINT)&rect, 2 );
120 FillRect( hDC, &rect, hBrush );
122 hPrevFont = SelectObject( hDC, hIconTitleFont );
123 if( hPrevFont )
125 WCHAR buffer[80];
127 INT length = GetWindowTextW( owner, buffer, ARRAY_SIZE( buffer ));
128 SetTextColor( hDC, textColor );
129 SetBkMode( hDC, TRANSPARENT );
131 DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
132 DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
134 SelectObject( hDC, hPrevFont );
136 return (hPrevFont != 0);
139 /***********************************************************************
140 * IconTitleWndProc
142 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
143 WPARAM wParam, LPARAM lParam )
145 HWND owner = GetWindow( hWnd, GW_OWNER );
147 if (!IsWindow(hWnd)) return 0;
149 switch( msg )
151 case WM_CREATE:
152 if (!hIconTitleFont)
154 LOGFONTA logFont;
155 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
156 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
157 hIconTitleFont = CreateFontIndirectA( &logFont );
159 return (hIconTitleFont ? 0 : -1);
160 case WM_NCHITTEST:
161 return HTCAPTION;
162 case WM_NCMOUSEMOVE:
163 case WM_NCLBUTTONDBLCLK:
164 return SendMessageW( owner, msg, wParam, lParam );
165 case WM_ACTIVATE:
166 if (wParam) NtUserSetActiveWindow( owner );
167 return 0;
168 case WM_CLOSE:
169 return 0;
170 case WM_SHOWWINDOW:
171 if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
172 return 0;
173 case WM_ERASEBKGND:
174 if( GetWindowLongW( owner, GWL_STYLE ) & WS_CHILD )
175 lParam = SendMessageW( owner, WM_ISACTIVEICON, 0, 0 );
176 else
177 lParam = (owner == GetActiveWindow());
178 if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
179 NtUserValidateRect( hWnd, NULL );
180 return 1;
182 return DefWindowProcW( hWnd, msg, wParam, lParam );