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
23 #include <wine/debug.h>
26 #define MAKEINTATOMW(atom) ((LPCWSTR)((ULONG_PTR)((WORD)(atom))))
27 #define ICONTITLE_CLASS_ATOM MAKEINTATOMW(32772)
30 static BOOL bMultiLineTitle
;
31 static HFONT hIconTitleFont
;
33 static LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
35 /*********************************************************************
36 * icon title class descriptor
38 const struct builtin_class_descr ICONTITLE_builtin_class
=
41 ICONTITLE_CLASS_ATOM
, /* name */
43 IconTitleWndProc
, /* procW */
44 NULL
, /* procA (winproc is Unicode only) */
46 IDC_ARROW
, /* cursor */
49 ICONTITLE_CLASS_ATOM
, /* name */
51 NULL
, /* procA (winproc is Unicode only) */
52 IconTitleWndProc
, /* procW */
54 IDC_ARROW
, /* cursor */
62 /***********************************************************************
65 HWND
ICONTITLE_Create( HWND owner
)
68 HINSTANCE instance
= (HINSTANCE
)GetWindowLongPtrA( owner
, GWLP_HINSTANCE
);
69 LONG style
= WS_CLIPSIBLINGS
;
71 if (!IsWindowEnabled(owner
)) style
|= WS_DISABLED
;
72 if( GetWindowLongA( owner
, GWL_STYLE
) & WS_CHILD
)
73 hWnd
= CreateWindowExA( 0, ICONTITLE_CLASS_ATOM
, NULL
,
74 style
| WS_CHILD
, 0, 0, 1, 1,
75 GetParent(owner
), 0, instance
, NULL
);
77 hWnd
= CreateWindowExA( 0, ICONTITLE_CLASS_ATOM
, NULL
,
79 owner
, 0, instance
, NULL
);
80 WIN_SetOwner( hWnd
, owner
); /* MDI depends on this */
81 SetWindowLongW( hWnd
, GWL_STYLE
,
82 GetWindowLongW( hWnd
, GWL_STYLE
) & ~(WS_CAPTION
| WS_BORDER
) );
87 /***********************************************************************
88 * ICONTITLE_SetTitlePos
90 static BOOL
ICONTITLE_SetTitlePos( HWND hwnd
, HWND owner
)
92 static const WCHAR emptyTitleText
[] = {'<','.','.','.','>',0};
100 int length
= GetWindowTextW( owner
, str
, sizeof(str
)/sizeof(WCHAR
) );
102 while (length
&& str
[length
- 1] == ' ') /* remove trailing spaces */
107 strcpyW( str
, emptyTitleText
);
108 length
= strlenW( str
);
111 if (!(hDC
= GetDC( hwnd
))) return FALSE
;
113 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
115 SetRect( &rect
, 0, 0, GetSystemMetrics(SM_CXICONSPACING
) -
116 GetSystemMetrics(SM_CXBORDER
) * 2,
117 GetSystemMetrics(SM_CYBORDER
) * 2 );
119 DrawTextW( hDC
, str
, length
, &rect
, DT_CALCRECT
| DT_CENTER
| DT_NOPREFIX
| DT_WORDBREAK
|
120 (( bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
122 SelectObject( hDC
, hPrevFont
);
123 ReleaseDC( hwnd
, hDC
);
125 cx
= rect
.right
- rect
.left
+ 4 * GetSystemMetrics(SM_CXBORDER
);
126 cy
= rect
.bottom
- rect
.top
;
128 pt
.x
= (GetSystemMetrics(SM_CXICON
) - cx
) / 2;
129 pt
.y
= GetSystemMetrics(SM_CYICON
);
131 /* point is relative to owner, make it relative to parent */
132 MapWindowPoints( owner
, GetParent(hwnd
), &pt
, 1 );
134 SetWindowPos( hwnd
, owner
, pt
.x
, pt
.y
, cx
, cy
, SWP_NOACTIVATE
);
138 /***********************************************************************
141 static BOOL
ICONTITLE_Paint( HWND hwnd
, HWND owner
, HDC hDC
, BOOL bActive
)
146 COLORREF textColor
= 0;
150 hBrush
= GetSysColorBrush(COLOR_ACTIVECAPTION
);
151 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
155 if( GetWindowLongA( hwnd
, GWL_STYLE
) & WS_CHILD
)
157 hBrush
= (HBRUSH
) GetClassLongPtrW(hwnd
, GCLP_HBRBACKGROUND
);
162 GetObjectA( hBrush
, sizeof(logBrush
), &logBrush
);
163 level
= GetRValue(logBrush
.lbColor
) +
164 GetGValue(logBrush
.lbColor
) +
165 GetBValue(logBrush
.lbColor
);
166 if( level
< (0x7F * 3) )
167 textColor
= RGB( 0xFF, 0xFF, 0xFF );
170 hBrush
= GetStockObject( WHITE_BRUSH
);
174 hBrush
= GetStockObject( BLACK_BRUSH
);
175 textColor
= RGB( 0xFF, 0xFF, 0xFF );
179 GetClientRect( hwnd
, &rect
);
180 DPtoLP( hDC
, (LPPOINT
)&rect
, 2 );
181 FillRect( hDC
, &rect
, hBrush
);
183 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
188 INT length
= GetWindowTextW( owner
, buffer
, sizeof(buffer
) );
189 SetTextColor( hDC
, textColor
);
190 SetBkMode( hDC
, TRANSPARENT
);
192 DrawTextW( hDC
, buffer
, length
, &rect
, DT_CENTER
| DT_NOPREFIX
|
193 DT_WORDBREAK
| ((bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
195 SelectObject( hDC
, hPrevFont
);
197 return (hPrevFont
!= 0);
200 /***********************************************************************
203 LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
,
204 WPARAM wParam
, LPARAM lParam
)
206 HWND owner
= GetWindow( hWnd
, GW_OWNER
);
208 if (!IsWindow(hWnd
)) return 0;
216 SystemParametersInfoA( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
217 SystemParametersInfoA( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
218 hIconTitleFont
= CreateFontIndirectA( &logFont
);
220 return (hIconTitleFont
? 0 : -1);
224 case WM_NCLBUTTONDBLCLK
:
225 return SendMessageW( owner
, msg
, wParam
, lParam
);
227 if( wParam
) SetActiveWindow( owner
);
232 if (wParam
) ICONTITLE_SetTitlePos( hWnd
, owner
);
235 if( GetWindowLongA( owner
, GWL_STYLE
) & WS_CHILD
)
236 lParam
= SendMessageA( owner
, WM_ISACTIVEICON
, 0, 0 );
238 lParam
= (owner
== GetActiveWindow());
239 if( ICONTITLE_Paint( hWnd
, owner
, (HDC
)wParam
, (BOOL
)lParam
) )
240 ValidateRect( hWnd
, NULL
);
243 return DefWindowProcW( hWnd
, msg
, wParam
, lParam
);