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
34 #include "wine/winuser16.h"
35 #include "wine/unicode.h"
39 static BOOL bMultiLineTitle;
40 static HFONT hIconTitleFont;
42 static LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
44 /*********************************************************************
45 * icon title class descriptor
47 const struct builtin_class_descr ICONTITLE_builtin_class =
49 ICONTITLE_CLASS_ATOM, /* name */
50 CS_GLOBALCLASS, /* style */
51 NULL, /* procA (winproc is Unicode only) */
52 IconTitleWndProc, /* procW */
54 IDC_ARROWA, /* cursor */
60 /***********************************************************************
63 HWND ICONTITLE_Create( HWND owner )
66 HINSTANCE instance = (HINSTANCE)GetWindowLongA( owner, GWL_HINSTANCE );
67 LONG style = WS_CLIPSIBLINGS;
69 if (!IsWindowEnabled(owner)) style |= WS_DISABLED;
70 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
71 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
72 style | WS_CHILD, 0, 0, 1, 1,
73 GetParent(owner), 0, instance, NULL );
75 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
77 owner, 0, instance, NULL );
78 WIN_SetOwner( hWnd, owner ); /* MDI depends on this */
79 SetWindowLongW( hWnd, GWL_STYLE,
80 GetWindowLongW( hWnd, GWL_STYLE ) & ~(WS_CAPTION | WS_BORDER) );
84 /***********************************************************************
85 * ICONTITLE_SetTitlePos
87 static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
89 static WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
97 int length = GetWindowTextW( owner, str, sizeof(str)/sizeof(WCHAR) );
99 while (length && str[length - 1] == ' ') /* remove trailing spaces */
104 strcpyW( str, emptyTitleText );
105 length = strlenW( str );
108 if (!(hDC = GetDC( hwnd ))) return FALSE;
110 hPrevFont = SelectObject( hDC, hIconTitleFont );
112 SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
113 GetSystemMetrics(SM_CXBORDER) * 2,
114 GetSystemMetrics(SM_CYBORDER) * 2 );
116 DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
117 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
119 SelectObject( hDC, hPrevFont );
120 ReleaseDC( hwnd, hDC );
122 cx = rect.right - rect.left + 4 * GetSystemMetrics(SM_CXBORDER);
123 cy = rect.bottom - rect.top;
125 pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
126 pt.y = GetSystemMetrics(SM_CYICON);
128 /* point is relative to owner, make it relative to parent */
129 MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
131 SetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
135 /***********************************************************************
138 static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
143 COLORREF textColor = 0;
147 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
148 textColor = GetSysColor(COLOR_CAPTIONTEXT);
152 if( GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD )
154 hBrush = (HBRUSH) GetClassLongA(hwnd, GCL_HBRBACKGROUND);
159 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
160 level = GetRValue(logBrush.lbColor) +
161 GetGValue(logBrush.lbColor) +
162 GetBValue(logBrush.lbColor);
163 if( level < (0x7F * 3) )
164 textColor = RGB( 0xFF, 0xFF, 0xFF );
167 hBrush = GetStockObject( WHITE_BRUSH );
171 hBrush = GetStockObject( BLACK_BRUSH );
172 textColor = RGB( 0xFF, 0xFF, 0xFF );
176 GetClientRect( hwnd, &rect );
177 DPtoLP( hDC, (LPPOINT)&rect, 2 );
178 FillRect( hDC, &rect, hBrush );
180 hPrevFont = SelectObject( hDC, hIconTitleFont );
185 INT length = GetWindowTextW( owner, buffer, sizeof(buffer) );
186 SetTextColor( hDC, textColor );
187 SetBkMode( hDC, TRANSPARENT );
189 DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
190 DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
192 SelectObject( hDC, hPrevFont );
194 return (hPrevFont != 0);
197 /***********************************************************************
200 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
201 WPARAM wParam, LPARAM lParam )
203 HWND owner = GetWindow( hWnd, GW_OWNER );
205 if (!IsWindow(hWnd)) return 0;
213 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
214 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
215 hIconTitleFont = CreateFontIndirectA( &logFont );
217 return (hIconTitleFont ? 0 : -1);
221 case WM_NCLBUTTONDBLCLK:
222 return SendMessageW( owner, msg, wParam, lParam );
224 if( wParam ) SetActiveWindow( owner );
229 if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
232 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
233 lParam = SendMessageA( owner, WM_ISACTIVEICON, 0, 0 );
235 lParam = (owner == GetActiveWindow());
236 if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
237 ValidateRect( hWnd, NULL );
240 return DefWindowProcW( hWnd, msg, wParam, lParam );