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>
25 static BOOL bMultiLineTitle
;
26 static HFONT hIconTitleFont
;
28 /*********************************************************************
29 * icon title class descriptor
31 const struct builtin_class_descr ICONTITLE_builtin_class
=
33 WC_ICONTITLE
, /* name */
35 NULL
, /* procA (winproc is Unicode only) */
36 IconTitleWndProc
, /* procW */
38 IDC_ARROW
, /* cursor */
45 /***********************************************************************
48 HWND
ICONTITLE_Create( HWND owner
)
51 HINSTANCE instance
= (HINSTANCE
)GetWindowLongPtrA( owner
, GWLP_HINSTANCE
);
52 LONG style
= WS_CLIPSIBLINGS
;
54 if (!IsWindowEnabled(owner
)) style
|= WS_DISABLED
;
55 if( GetWindowLongPtrA( owner
, GWL_STYLE
) & WS_CHILD
)
56 hWnd
= CreateWindowExA( 0, (LPCSTR
)ICONTITLE_CLASS_ATOM
, NULL
,
57 style
| WS_CHILD
, 0, 0, 1, 1,
58 GetParent(owner
), 0, instance
, NULL
);
60 hWnd
= CreateWindowExA( 0, (LPCSTR
)ICONTITLE_CLASS_ATOM
, NULL
,
62 owner
, 0, instance
, NULL
);
63 WIN_SetOwner( hWnd
, owner
); /* MDI depends on this */
64 SetWindowLongPtrW( hWnd
, GWL_STYLE
,
65 GetWindowLongPtrW( hWnd
, GWL_STYLE
) & ~(WS_CAPTION
| WS_BORDER
) );
70 /***********************************************************************
71 * ICONTITLE_SetTitlePos
73 static BOOL
ICONTITLE_SetTitlePos( HWND hwnd
, HWND owner
)
75 static const WCHAR emptyTitleText
[] = {'<','.','.','.','>',0};
83 int length
= GetWindowTextW( owner
, str
, sizeof(str
)/sizeof(WCHAR
) );
85 while (length
&& str
[length
- 1] == ' ') /* remove trailing spaces */
90 strcpyW( str
, emptyTitleText
);
91 length
= strlenW( str
);
94 if (!(hDC
= GetDC( hwnd
))) return FALSE
;
96 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
98 SetRect( &rect
, 0, 0, GetSystemMetrics(SM_CXICONSPACING
) -
99 GetSystemMetrics(SM_CXBORDER
) * 2,
100 GetSystemMetrics(SM_CYBORDER
) * 2 );
102 DrawTextW( hDC
, str
, length
, &rect
, DT_CALCRECT
| DT_CENTER
| DT_NOPREFIX
| DT_WORDBREAK
|
103 (( bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
105 SelectObject( hDC
, hPrevFont
);
106 ReleaseDC( hwnd
, hDC
);
108 cx
= rect
.right
- rect
.left
+ 4 * GetSystemMetrics(SM_CXBORDER
);
109 cy
= rect
.bottom
- rect
.top
;
111 pt
.x
= (GetSystemMetrics(SM_CXICON
) - cx
) / 2;
112 pt
.y
= GetSystemMetrics(SM_CYICON
);
114 /* point is relative to owner, make it relative to parent */
115 MapWindowPoints( owner
, GetParent(hwnd
), &pt
, 1 );
117 SetWindowPos( hwnd
, owner
, pt
.x
, pt
.y
, cx
, cy
, SWP_NOACTIVATE
);
121 /***********************************************************************
124 static BOOL
ICONTITLE_Paint( HWND hwnd
, HWND owner
, HDC hDC
, BOOL bActive
)
129 COLORREF textColor
= 0;
133 hBrush
= GetSysColorBrush(COLOR_ACTIVECAPTION
);
134 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
138 if( GetWindowLongPtrA( hwnd
, GWL_STYLE
) & WS_CHILD
)
140 hBrush
= (HBRUSH
) GetClassLongPtrW(hwnd
, GCLP_HBRBACKGROUND
);
145 GetObjectA( hBrush
, sizeof(logBrush
), &logBrush
);
146 level
= GetRValue(logBrush
.lbColor
) +
147 GetGValue(logBrush
.lbColor
) +
148 GetBValue(logBrush
.lbColor
);
149 if( level
< (0x7F * 3) )
150 textColor
= RGB( 0xFF, 0xFF, 0xFF );
153 hBrush
= GetStockObject( WHITE_BRUSH
);
157 hBrush
= GetStockObject( BLACK_BRUSH
);
158 textColor
= RGB( 0xFF, 0xFF, 0xFF );
162 GetClientRect( hwnd
, &rect
);
163 DPtoLP( hDC
, (LPPOINT
)&rect
, 2 );
164 FillRect( hDC
, &rect
, hBrush
);
166 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
171 INT length
= GetWindowTextW( owner
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]) );
172 SetTextColor( hDC
, textColor
);
173 SetBkMode( hDC
, TRANSPARENT
);
175 DrawTextW( hDC
, buffer
, length
, &rect
, DT_CENTER
| DT_NOPREFIX
|
176 DT_WORDBREAK
| ((bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
178 SelectObject( hDC
, hPrevFont
);
180 return (hPrevFont
!= 0);
183 /***********************************************************************
186 LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
,
187 WPARAM wParam
, LPARAM lParam
)
189 HWND owner
= GetWindow( hWnd
, GW_OWNER
);
191 if (!IsWindow(hWnd
)) return 0;
199 SystemParametersInfoA( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
200 SystemParametersInfoA( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
201 hIconTitleFont
= CreateFontIndirectA( &logFont
);
203 return (hIconTitleFont
? 0 : -1);
207 case WM_NCLBUTTONDBLCLK
:
208 return SendMessageW( owner
, msg
, wParam
, lParam
);
210 if( wParam
) SetActiveWindow( owner
);
215 if (wParam
) ICONTITLE_SetTitlePos( hWnd
, owner
);
218 if( GetWindowLongPtrW( owner
, GWL_STYLE
) & WS_CHILD
)
219 lParam
= SendMessageW( owner
, WM_ISACTIVEICON
, 0, 0 );
221 lParam
= (owner
== GetActiveWindow());
222 if( ICONTITLE_Paint( hWnd
, owner
, (HDC
)wParam
, (BOOL
)lParam
) )
223 ValidateRect( hWnd
, NULL
);
226 return DefWindowProcW( hWnd
, msg
, wParam
, lParam
);