2 * Icontitle window class.
4 * Copyright 1997 Alex Korobka
13 #include "wine/winuser16.h"
18 static LPCSTR emptyTitleText
= "<...>";
23 /***********************************************************************
26 BOOL
ICONTITLE_Init(void)
30 SystemParametersInfoA( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
31 SystemParametersInfoA( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
32 hIconTitleFont
= CreateFontIndirectA( &logFont
);
33 return (hIconTitleFont
) ? TRUE
: FALSE
;
36 /***********************************************************************
39 HWND
ICONTITLE_Create( WND
* wnd
)
44 if( wnd
->dwStyle
& WS_CHILD
)
45 hWnd
= CreateWindowExA( 0, ICONTITLE_CLASS_ATOM
, NULL
,
46 WS_CHILD
| WS_CLIPSIBLINGS
, 0, 0, 1, 1,
47 wnd
->parent
->hwndSelf
, 0, wnd
->hInstance
, NULL
);
49 hWnd
= CreateWindowExA( 0, ICONTITLE_CLASS_ATOM
, NULL
,
50 WS_CLIPSIBLINGS
, 0, 0, 1, 1,
51 wnd
->hwndSelf
, 0, wnd
->hInstance
, NULL
);
52 wndPtr
= WIN_FindWndPtr( hWnd
);
55 wndPtr
->owner
= wnd
; /* MDI depends on this */
56 wndPtr
->dwStyle
&= ~(WS_CAPTION
| WS_BORDER
);
57 if( wnd
->dwStyle
& WS_DISABLED
) wndPtr
->dwStyle
|= WS_DISABLED
;
58 WIN_ReleaseWndPtr(wndPtr
);
64 /***********************************************************************
65 * ICONTITLE_GetTitlePos
67 static BOOL
ICONTITLE_GetTitlePos( WND
* wnd
, LPRECT lpRect
)
70 int length
= lstrlenA( wnd
->owner
->text
);
74 str
= HeapAlloc( GetProcessHeap(), 0, length
+ 1 );
75 lstrcpyA( str
, wnd
->owner
->text
);
76 while( str
[length
- 1] == ' ' ) /* remove trailing spaces */
81 HeapFree( GetProcessHeap(), 0, str
);
88 str
= (LPSTR
)emptyTitleText
;
89 length
= lstrlenA( str
);
94 HDC hDC
= GetDC( wnd
->hwndSelf
);
97 HFONT hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
99 SetRect( lpRect
, 0, 0, GetSystemMetrics(SM_CXICONSPACING
) -
100 GetSystemMetrics(SM_CXBORDER
) * 2,
101 GetSystemMetrics(SM_CYBORDER
) * 2 );
103 DrawTextA( hDC
, str
, length
, lpRect
, DT_CALCRECT
|
104 DT_CENTER
| DT_NOPREFIX
| DT_WORDBREAK
|
105 (( bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
107 SelectObject( hDC
, hPrevFont
);
108 ReleaseDC( wnd
->hwndSelf
, hDC
);
110 lpRect
->right
+= 4 * GetSystemMetrics(SM_CXBORDER
) - lpRect
->left
;
111 lpRect
->left
= wnd
->owner
->rectWindow
.left
+ GetSystemMetrics(SM_CXICON
) / 2 -
112 (lpRect
->right
- lpRect
->left
) / 2;
113 lpRect
->bottom
-= lpRect
->top
;
114 lpRect
->top
= wnd
->owner
->rectWindow
.top
+ GetSystemMetrics(SM_CYICON
);
116 if( str
!= emptyTitleText
) HeapFree( GetProcessHeap(), 0, str
);
117 return ( hDC
) ? TRUE
: FALSE
;
122 /***********************************************************************
125 static BOOL
ICONTITLE_Paint( WND
* wnd
, HDC hDC
, BOOL bActive
)
129 COLORREF textColor
= 0;
133 hBrush
= GetSysColorBrush(COLOR_ACTIVECAPTION
);
134 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
138 if( wnd
->dwStyle
& WS_CHILD
)
140 hBrush
= (HBRUSH
) GetClassLongA(wnd
->hwndSelf
, GCL_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 FillWindow16( wnd
->parent
->hwndSelf
, wnd
->hwndSelf
, hDC
, hBrush
);
164 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
171 rect
.left
= rect
.top
= 0;
172 rect
.right
= wnd
->rectWindow
.right
- wnd
->rectWindow
.left
;
173 rect
.bottom
= wnd
->rectWindow
.bottom
- wnd
->rectWindow
.top
;
175 length
= GetWindowTextA( wnd
->owner
->hwndSelf
, buffer
, 80 );
176 SetTextColor( hDC
, textColor
);
177 SetBkMode( hDC
, TRANSPARENT
);
179 DrawTextA( hDC
, buffer
, length
, &rect
, DT_CENTER
| DT_NOPREFIX
|
180 DT_WORDBREAK
| ((bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
182 SelectObject( hDC
, hPrevFont
);
184 return ( hPrevFont
) ? TRUE
: FALSE
;
187 /***********************************************************************
190 LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
,
191 WPARAM wParam
, LPARAM lParam
)
194 WND
*wnd
= WIN_FindWndPtr( hWnd
);
199 retvalue
= HTCAPTION
;
202 case WM_NCLBUTTONDBLCLK
:
203 retvalue
= SendMessageA( wnd
->owner
->hwndSelf
, msg
, wParam
, lParam
);
206 if( wParam
) SetActiveWindow( wnd
->owner
->hwndSelf
);
217 ICONTITLE_GetTitlePos( wnd
, &titleRect
);
218 if( wnd
->owner
->next
!= wnd
) /* keep icon title behind the owner */
219 SetWindowPos( hWnd
, wnd
->owner
->hwndSelf
,
220 titleRect
.left
, titleRect
.top
,
221 titleRect
.right
, titleRect
.bottom
, SWP_NOACTIVATE
);
223 SetWindowPos( hWnd
, 0, titleRect
.left
, titleRect
.top
,
224 titleRect
.right
, titleRect
.bottom
,
225 SWP_NOACTIVATE
| SWP_NOZORDER
);
232 WND
* iconWnd
= WIN_LockWndPtr(wnd
->owner
);
234 if( iconWnd
->dwStyle
& WS_CHILD
)
235 lParam
= SendMessageA( iconWnd
->hwndSelf
, WM_ISACTIVEICON
, 0, 0 );
237 lParam
= (iconWnd
->hwndSelf
== GetActiveWindow16());
239 WIN_ReleaseWndPtr(iconWnd
);
240 if( ICONTITLE_Paint( wnd
, (HDC
)wParam
, (BOOL
)lParam
) )
241 ValidateRect( hWnd
, NULL
);
247 retvalue
= DefWindowProcA( hWnd
, msg
, wParam
, lParam
);
249 WIN_ReleaseWndPtr(wnd
);