wined3d: Use the FBO cache in stretch_rect_fbo().
[wine/hramrach.git] / dlls / user32 / icontitle.c
blob04f0c69ec30fd26f745fe049ca221cd8e0ccd7df
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 "config.h"
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <string.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "wine/unicode.h"
35 #include "controls.h"
36 #include "win.h"
38 static BOOL bMultiLineTitle;
39 static HFONT hIconTitleFont;
41 /*********************************************************************
42 * icon title class descriptor
44 const struct builtin_class_descr ICONTITLE_builtin_class =
46 (LPCWSTR)ICONTITLE_CLASS_ATOM, /* name */
47 0, /* style */
48 WINPROC_ICONTITLE, /* proc */
49 0, /* extra */
50 IDC_ARROW, /* cursor */
51 0 /* brush */
56 /***********************************************************************
57 * ICONTITLE_Create
59 HWND ICONTITLE_Create( HWND owner )
61 HWND hWnd;
62 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrA( owner, GWLP_HINSTANCE );
63 LONG style = WS_CLIPSIBLINGS;
65 if (!IsWindowEnabled(owner)) style |= WS_DISABLED;
66 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
67 hWnd = CreateWindowExA( 0, (LPCSTR)ICONTITLE_CLASS_ATOM, NULL,
68 style | WS_CHILD, 0, 0, 1, 1,
69 GetParent(owner), 0, instance, NULL );
70 else
71 hWnd = CreateWindowExA( 0, (LPCSTR)ICONTITLE_CLASS_ATOM, NULL,
72 style, 0, 0, 1, 1,
73 owner, 0, instance, NULL );
74 WIN_SetOwner( hWnd, owner ); /* MDI depends on this */
75 SetWindowLongW( hWnd, GWL_STYLE,
76 GetWindowLongW( hWnd, GWL_STYLE ) & ~(WS_CAPTION | WS_BORDER) );
77 return hWnd;
80 /***********************************************************************
81 * ICONTITLE_SetTitlePos
83 static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
85 static const WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
86 WCHAR str[80];
87 HDC hDC;
88 HFONT hPrevFont;
89 RECT rect;
90 INT cx, cy;
91 POINT pt;
93 int length = GetWindowTextW( owner, str, sizeof(str)/sizeof(WCHAR) );
95 while (length && str[length - 1] == ' ') /* remove trailing spaces */
96 str[--length] = 0;
98 if( !length )
100 strcpyW( str, emptyTitleText );
101 length = strlenW( str );
104 if (!(hDC = GetDC( hwnd ))) return FALSE;
106 hPrevFont = SelectObject( hDC, hIconTitleFont );
108 SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
109 GetSystemMetrics(SM_CXBORDER) * 2,
110 GetSystemMetrics(SM_CYBORDER) * 2 );
112 DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
113 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
115 SelectObject( hDC, hPrevFont );
116 ReleaseDC( hwnd, hDC );
118 cx = rect.right - rect.left + 4 * GetSystemMetrics(SM_CXBORDER);
119 cy = rect.bottom - rect.top;
121 pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
122 pt.y = GetSystemMetrics(SM_CYICON);
124 /* point is relative to owner, make it relative to parent */
125 MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
127 SetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
128 return TRUE;
131 /***********************************************************************
132 * ICONTITLE_Paint
134 static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
136 RECT rect;
137 HFONT hPrevFont;
138 HBRUSH hBrush = 0;
139 COLORREF textColor = 0;
141 if( bActive )
143 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
144 textColor = GetSysColor(COLOR_CAPTIONTEXT);
146 else
148 if( GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD )
150 hBrush = (HBRUSH) GetClassLongPtrW(hwnd, GCLP_HBRBACKGROUND);
151 if( hBrush )
153 INT level;
154 LOGBRUSH logBrush;
155 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
156 level = GetRValue(logBrush.lbColor) +
157 GetGValue(logBrush.lbColor) +
158 GetBValue(logBrush.lbColor);
159 if( level < (0x7F * 3) )
160 textColor = RGB( 0xFF, 0xFF, 0xFF );
162 else
163 hBrush = GetStockObject( WHITE_BRUSH );
165 else
167 hBrush = GetStockObject( BLACK_BRUSH );
168 textColor = RGB( 0xFF, 0xFF, 0xFF );
172 GetClientRect( hwnd, &rect );
173 DPtoLP( hDC, (LPPOINT)&rect, 2 );
174 FillRect( hDC, &rect, hBrush );
176 hPrevFont = SelectObject( hDC, hIconTitleFont );
177 if( hPrevFont )
179 WCHAR buffer[80];
181 INT length = GetWindowTextW( owner, buffer, sizeof(buffer)/sizeof(buffer[0]) );
182 SetTextColor( hDC, textColor );
183 SetBkMode( hDC, TRANSPARENT );
185 DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
186 DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
188 SelectObject( hDC, hPrevFont );
190 return (hPrevFont != 0);
193 /***********************************************************************
194 * IconTitleWndProc
196 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
197 WPARAM wParam, LPARAM lParam )
199 HWND owner = GetWindow( hWnd, GW_OWNER );
201 if (!IsWindow(hWnd)) return 0;
203 switch( msg )
205 case WM_CREATE:
206 if (!hIconTitleFont)
208 LOGFONTA logFont;
209 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
210 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
211 hIconTitleFont = CreateFontIndirectA( &logFont );
213 return (hIconTitleFont ? 0 : -1);
214 case WM_NCHITTEST:
215 return HTCAPTION;
216 case WM_NCMOUSEMOVE:
217 case WM_NCLBUTTONDBLCLK:
218 return SendMessageW( owner, msg, wParam, lParam );
219 case WM_ACTIVATE:
220 if( wParam ) SetActiveWindow( owner );
221 return 0;
222 case WM_CLOSE:
223 return 0;
224 case WM_SHOWWINDOW:
225 if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
226 return 0;
227 case WM_ERASEBKGND:
228 if( GetWindowLongW( owner, GWL_STYLE ) & WS_CHILD )
229 lParam = SendMessageW( owner, WM_ISACTIVEICON, 0, 0 );
230 else
231 lParam = (owner == GetActiveWindow());
232 if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
233 ValidateRect( hWnd, NULL );
234 return 1;
236 return DefWindowProcW( hWnd, msg, wParam, lParam );