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
23 #include <wine/debug.h>
24 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
26 static BOOL bMultiLineTitle
;
27 static HFONT hIconTitleFont
;
29 /*********************************************************************
30 * icon title class descriptor
32 const struct builtin_class_descr ICONTITLE_builtin_class
=
34 WC_ICONTITLE
, /* name */
36 NULL
, /* procA (winproc is Unicode only) */
37 IconTitleWndProc
, /* procW */
39 IDC_ARROW
, /* cursor */
46 /***********************************************************************
49 HWND
ICONTITLE_Create( HWND owner
)
52 HINSTANCE instance
= (HINSTANCE
)GetWindowLongPtrA( owner
, GWLP_HINSTANCE
);
53 LONG style
= WS_CLIPSIBLINGS
;
55 if (!IsWindowEnabled(owner
)) style
|= WS_DISABLED
;
56 if( GetWindowLongPtrA( owner
, GWL_STYLE
) & WS_CHILD
)
57 hWnd
= CreateWindowExA( 0, (LPCSTR
)ICONTITLE_CLASS_ATOM
, NULL
,
58 style
| WS_CHILD
, 0, 0, 1, 1,
59 GetParent(owner
), 0, instance
, NULL
);
61 hWnd
= CreateWindowExA( 0, (LPCSTR
)ICONTITLE_CLASS_ATOM
, NULL
,
63 owner
, 0, instance
, NULL
);
64 WIN_SetOwner( hWnd
, owner
); /* MDI depends on this */
65 SetWindowLongPtrW( hWnd
, GWL_STYLE
,
66 GetWindowLongPtrW( hWnd
, GWL_STYLE
) & ~(WS_CAPTION
| WS_BORDER
) );
71 /***********************************************************************
72 * ICONTITLE_SetTitlePos
74 static BOOL
ICONTITLE_SetTitlePos( HWND hwnd
, HWND owner
)
76 static const WCHAR emptyTitleText
[] = {'<','.','.','.','>',0};
84 int length
= GetWindowTextW( owner
, str
, sizeof(str
)/sizeof(WCHAR
) );
86 while (length
&& str
[length
- 1] == ' ') /* remove trailing spaces */
91 strcpyW( str
, emptyTitleText
);
92 length
= strlenW( str
);
95 if (!(hDC
= GetDC( hwnd
))) return FALSE
;
97 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
99 SetRect( &rect
, 0, 0, GetSystemMetrics(SM_CXICONSPACING
) -
100 GetSystemMetrics(SM_CXBORDER
) * 2,
101 GetSystemMetrics(SM_CYBORDER
) * 2 );
103 DrawTextW( hDC
, str
, length
, &rect
, DT_CALCRECT
| DT_CENTER
| DT_NOPREFIX
| DT_WORDBREAK
|
104 (( bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
106 SelectObject( hDC
, hPrevFont
);
107 ReleaseDC( hwnd
, hDC
);
109 cx
= rect
.right
- rect
.left
+ 4 * GetSystemMetrics(SM_CXBORDER
);
110 cy
= rect
.bottom
- rect
.top
;
112 pt
.x
= (GetSystemMetrics(SM_CXICON
) - cx
) / 2;
113 pt
.y
= GetSystemMetrics(SM_CYICON
);
115 /* point is relative to owner, make it relative to parent */
116 MapWindowPoints( owner
, GetParent(hwnd
), &pt
, 1 );
118 SetWindowPos( hwnd
, owner
, pt
.x
, pt
.y
, cx
, cy
, SWP_NOACTIVATE
);
122 /***********************************************************************
125 static BOOL
ICONTITLE_Paint( HWND hwnd
, HWND owner
, HDC hDC
, BOOL bActive
)
130 COLORREF textColor
= 0;
134 hBrush
= GetSysColorBrush(COLOR_ACTIVECAPTION
);
135 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
139 if( GetWindowLongPtrA( hwnd
, GWL_STYLE
) & WS_CHILD
)
141 hBrush
= (HBRUSH
) GetClassLongPtrW(hwnd
, GCLP_HBRBACKGROUND
);
146 GetObjectA( hBrush
, sizeof(logBrush
), &logBrush
);
147 level
= GetRValue(logBrush
.lbColor
) +
148 GetGValue(logBrush
.lbColor
) +
149 GetBValue(logBrush
.lbColor
);
150 if( level
< (0x7F * 3) )
151 textColor
= RGB( 0xFF, 0xFF, 0xFF );
154 hBrush
= GetStockObject( WHITE_BRUSH
);
158 hBrush
= GetStockObject( BLACK_BRUSH
);
159 textColor
= RGB( 0xFF, 0xFF, 0xFF );
163 GetClientRect( hwnd
, &rect
);
164 DPtoLP( hDC
, (LPPOINT
)&rect
, 2 );
165 FillRect( hDC
, &rect
, hBrush
);
167 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
172 INT length
= GetWindowTextW( owner
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]) );
173 SetTextColor( hDC
, textColor
);
174 SetBkMode( hDC
, TRANSPARENT
);
176 DrawTextW( hDC
, buffer
, length
, &rect
, DT_CENTER
| DT_NOPREFIX
|
177 DT_WORDBREAK
| ((bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
179 SelectObject( hDC
, hPrevFont
);
181 return (hPrevFont
!= 0);
184 /***********************************************************************
187 LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
,
188 WPARAM wParam
, LPARAM lParam
)
190 HWND owner
= GetWindow( hWnd
, GW_OWNER
);
192 if (!IsWindow(hWnd
)) return 0;
200 SystemParametersInfoA( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
201 SystemParametersInfoA( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
202 hIconTitleFont
= CreateFontIndirectA( &logFont
);
204 return (hIconTitleFont
? 0 : -1);
208 case WM_NCLBUTTONDBLCLK
:
209 return SendMessageW( owner
, msg
, wParam
, lParam
);
211 if( wParam
) SetActiveWindow( owner
);
216 if (wParam
) ICONTITLE_SetTitlePos( hWnd
, owner
);
219 if( GetWindowLongPtrW( owner
, GWL_STYLE
) & WS_CHILD
)
220 lParam
= SendMessageW( owner
, WM_ISACTIVEICON
, 0, 0 );
222 lParam
= (owner
== GetActiveWindow());
223 if( ICONTITLE_Paint( hWnd
, owner
, (HDC
)wParam
, (BOOL
)lParam
) )
224 ValidateRect( hWnd
, NULL
);
227 return DefWindowProcW( hWnd
, msg
, wParam
, lParam
);