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/unicode.h"
38 static BOOL bMultiLineTitle
;
39 static HFONT hIconTitleFont
;
41 static LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
43 /*********************************************************************
44 * icon title class descriptor
46 const struct builtin_class_descr ICONTITLE_builtin_class
=
48 ICONTITLE_CLASS_ATOM
, /* name */
50 NULL
, /* procA (winproc is Unicode only) */
51 IconTitleWndProc
, /* procW */
53 IDC_ARROW
, /* cursor */
59 /***********************************************************************
62 HWND
ICONTITLE_Create( HWND owner
)
65 HINSTANCE instance
= (HINSTANCE
)GetWindowLongPtrA( owner
, GWLP_HINSTANCE
);
66 LONG style
= WS_CLIPSIBLINGS
;
68 if (!IsWindowEnabled(owner
)) style
|= WS_DISABLED
;
69 if( GetWindowLongA( owner
, GWL_STYLE
) & WS_CHILD
)
70 hWnd
= CreateWindowExA( 0, ICONTITLE_CLASS_ATOM
, NULL
,
71 style
| WS_CHILD
, 0, 0, 1, 1,
72 GetParent(owner
), 0, instance
, NULL
);
74 hWnd
= CreateWindowExA( 0, ICONTITLE_CLASS_ATOM
, NULL
,
76 owner
, 0, instance
, NULL
);
77 WIN_SetOwner( hWnd
, owner
); /* MDI depends on this */
78 SetWindowLongW( hWnd
, GWL_STYLE
,
79 GetWindowLongW( hWnd
, GWL_STYLE
) & ~(WS_CAPTION
| WS_BORDER
) );
83 /***********************************************************************
84 * ICONTITLE_SetTitlePos
86 static BOOL
ICONTITLE_SetTitlePos( HWND hwnd
, HWND owner
)
88 static const WCHAR emptyTitleText
[] = {'<','.','.','.','>',0};
96 int length
= GetWindowTextW( owner
, str
, sizeof(str
)/sizeof(WCHAR
) );
98 while (length
&& str
[length
- 1] == ' ') /* remove trailing spaces */
103 strcpyW( str
, emptyTitleText
);
104 length
= strlenW( str
);
107 if (!(hDC
= GetDC( hwnd
))) return FALSE
;
109 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
111 SetRect( &rect
, 0, 0, GetSystemMetrics(SM_CXICONSPACING
) -
112 GetSystemMetrics(SM_CXBORDER
) * 2,
113 GetSystemMetrics(SM_CYBORDER
) * 2 );
115 DrawTextW( hDC
, str
, length
, &rect
, DT_CALCRECT
| DT_CENTER
| DT_NOPREFIX
| DT_WORDBREAK
|
116 (( bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
118 SelectObject( hDC
, hPrevFont
);
119 ReleaseDC( hwnd
, hDC
);
121 cx
= rect
.right
- rect
.left
+ 4 * GetSystemMetrics(SM_CXBORDER
);
122 cy
= rect
.bottom
- rect
.top
;
124 pt
.x
= (GetSystemMetrics(SM_CXICON
) - cx
) / 2;
125 pt
.y
= GetSystemMetrics(SM_CYICON
);
127 /* point is relative to owner, make it relative to parent */
128 MapWindowPoints( owner
, GetParent(hwnd
), &pt
, 1 );
130 SetWindowPos( hwnd
, owner
, pt
.x
, pt
.y
, cx
, cy
, SWP_NOACTIVATE
);
134 /***********************************************************************
137 static BOOL
ICONTITLE_Paint( HWND hwnd
, HWND owner
, HDC hDC
, BOOL bActive
)
142 COLORREF textColor
= 0;
146 hBrush
= GetSysColorBrush(COLOR_ACTIVECAPTION
);
147 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
151 if( GetWindowLongA( hwnd
, GWL_STYLE
) & WS_CHILD
)
153 hBrush
= (HBRUSH
) GetClassLongA(hwnd
, GCL_HBRBACKGROUND
);
158 GetObjectA( hBrush
, sizeof(logBrush
), &logBrush
);
159 level
= GetRValue(logBrush
.lbColor
) +
160 GetGValue(logBrush
.lbColor
) +
161 GetBValue(logBrush
.lbColor
);
162 if( level
< (0x7F * 3) )
163 textColor
= RGB( 0xFF, 0xFF, 0xFF );
166 hBrush
= GetStockObject( WHITE_BRUSH
);
170 hBrush
= GetStockObject( BLACK_BRUSH
);
171 textColor
= RGB( 0xFF, 0xFF, 0xFF );
175 GetClientRect( hwnd
, &rect
);
176 DPtoLP( hDC
, (LPPOINT
)&rect
, 2 );
177 FillRect( hDC
, &rect
, hBrush
);
179 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
184 INT length
= GetWindowTextW( owner
, buffer
, sizeof(buffer
) );
185 SetTextColor( hDC
, textColor
);
186 SetBkMode( hDC
, TRANSPARENT
);
188 DrawTextW( hDC
, buffer
, length
, &rect
, DT_CENTER
| DT_NOPREFIX
|
189 DT_WORDBREAK
| ((bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
191 SelectObject( hDC
, hPrevFont
);
193 return (hPrevFont
!= 0);
196 /***********************************************************************
199 LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
,
200 WPARAM wParam
, LPARAM lParam
)
202 HWND owner
= GetWindow( hWnd
, GW_OWNER
);
204 if (!IsWindow(hWnd
)) return 0;
212 SystemParametersInfoA( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
213 SystemParametersInfoA( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
214 hIconTitleFont
= CreateFontIndirectA( &logFont
);
216 return (hIconTitleFont
? 0 : -1);
220 case WM_NCLBUTTONDBLCLK
:
221 return SendMessageW( owner
, msg
, wParam
, lParam
);
223 if( wParam
) SetActiveWindow( owner
);
228 if (wParam
) ICONTITLE_SetTitlePos( hWnd
, owner
);
231 if( GetWindowLongA( owner
, GWL_STYLE
) & WS_CHILD
)
232 lParam
= SendMessageA( owner
, WM_ISACTIVEICON
, 0, 0 );
234 lParam
= (owner
== GetActiveWindow());
235 if( ICONTITLE_Paint( hWnd
, owner
, (HDC
)wParam
, (BOOL
)lParam
) )
236 ValidateRect( hWnd
, NULL
);
239 return DefWindowProcW( hWnd
, msg
, wParam
, lParam
);