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"
24 static BOOL bMultiLineTitle
;
25 static HFONT hIconTitleFont
;
27 /***********************************************************************
28 * ICONTITLE_SetTitlePos
30 static BOOL
ICONTITLE_SetTitlePos( HWND hwnd
, HWND owner
)
39 int length
= GetWindowTextW( owner
, str
, ARRAY_SIZE( str
));
41 while (length
&& str
[length
- 1] == ' ') /* remove trailing spaces */
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
);
77 /***********************************************************************
80 static BOOL
ICONTITLE_Paint( HWND hwnd
, HWND owner
, HDC hDC
, BOOL bActive
)
85 COLORREF textColor
= 0;
89 hBrush
= GetSysColorBrush(COLOR_ACTIVECAPTION
);
90 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
94 if( GetWindowLongA( hwnd
, GWL_STYLE
) & WS_CHILD
)
96 hBrush
= (HBRUSH
) GetClassLongPtrW(hwnd
, GCLP_HBRBACKGROUND
);
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 );
109 hBrush
= GetStockObject( WHITE_BRUSH
);
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
);
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 /***********************************************************************
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;
155 SystemParametersInfoA( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
156 SystemParametersInfoA( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
157 hIconTitleFont
= CreateFontIndirectA( &logFont
);
159 return (hIconTitleFont
? 0 : -1);
163 case WM_NCLBUTTONDBLCLK
:
164 return SendMessageW( owner
, msg
, wParam
, lParam
);
166 if (wParam
) NtUserSetActiveWindow( owner
);
171 if (wParam
) ICONTITLE_SetTitlePos( hWnd
, owner
);
174 if( GetWindowLongW( owner
, GWL_STYLE
) & WS_CHILD
)
175 lParam
= SendMessageW( owner
, WM_ISACTIVEICON
, 0, 0 );
177 lParam
= (owner
== GetActiveWindow());
178 if( ICONTITLE_Paint( hWnd
, owner
, (HDC
)wParam
, (BOOL
)lParam
) )
179 NtUserValidateRect( hWnd
, NULL
);
182 return DefWindowProcW( hWnd
, msg
, wParam
, lParam
);