2 * Icontitle window class.
4 * Copyright 1997 Alex Korobka
11 #include "wine/winuser16.h"
12 #include "sysmetrics.h"
17 static LPCSTR emptyTitleText
= "<...>";
22 /***********************************************************************
25 BOOL
ICONTITLE_Init(void)
29 SystemParametersInfoA( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
30 SystemParametersInfoA( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
31 hIconTitleFont
= CreateFontIndirectA( &logFont
);
32 return (hIconTitleFont
) ? TRUE
: FALSE
;
35 /***********************************************************************
38 HWND
ICONTITLE_Create( WND
* wnd
)
43 if( wnd
->dwStyle
& WS_CHILD
)
44 hWnd
= CreateWindowExA( 0, ICONTITLE_CLASS_ATOM
, NULL
,
45 WS_CHILD
| WS_CLIPSIBLINGS
, 0, 0, 1, 1,
46 wnd
->parent
->hwndSelf
, 0, wnd
->hInstance
, NULL
);
48 hWnd
= CreateWindowExA( 0, ICONTITLE_CLASS_ATOM
, NULL
,
49 WS_CLIPSIBLINGS
, 0, 0, 1, 1,
50 wnd
->hwndSelf
, 0, wnd
->hInstance
, NULL
);
51 wndPtr
= WIN_FindWndPtr( hWnd
);
54 wndPtr
->owner
= wnd
; /* MDI depends on this */
55 wndPtr
->dwStyle
&= ~(WS_CAPTION
| WS_BORDER
);
56 if( wnd
->dwStyle
& WS_DISABLED
) wndPtr
->dwStyle
|= WS_DISABLED
;
57 WIN_ReleaseWndPtr(wndPtr
);
63 /***********************************************************************
64 * ICONTITLE_GetTitlePos
66 static BOOL
ICONTITLE_GetTitlePos( WND
* wnd
, LPRECT lpRect
)
69 int length
= lstrlenA( wnd
->owner
->text
);
73 str
= HeapAlloc( GetProcessHeap(), 0, length
+ 1 );
74 lstrcpyA( str
, wnd
->owner
->text
);
75 while( str
[length
- 1] == ' ' ) /* remove trailing spaces */
80 HeapFree( GetProcessHeap(), 0, str
);
87 str
= (LPSTR
)emptyTitleText
;
88 length
= lstrlenA( str
);
93 HDC hDC
= GetDC( wnd
->hwndSelf
);
96 HFONT hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
98 SetRect( lpRect
, 0, 0, sysMetrics
[SM_CXICONSPACING
] -
99 SYSMETRICS_CXBORDER
* 2, SYSMETRICS_CYBORDER
* 2 );
101 DrawTextA( hDC
, str
, length
, lpRect
, DT_CALCRECT
|
102 DT_CENTER
| DT_NOPREFIX
| DT_WORDBREAK
|
103 (( bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
105 SelectObject( hDC
, hPrevFont
);
106 ReleaseDC( wnd
->hwndSelf
, hDC
);
108 lpRect
->right
+= 4 * SYSMETRICS_CXBORDER
- lpRect
->left
;
109 lpRect
->left
= wnd
->owner
->rectWindow
.left
+ SYSMETRICS_CXICON
/ 2 -
110 (lpRect
->right
- lpRect
->left
) / 2;
111 lpRect
->bottom
-= lpRect
->top
;
112 lpRect
->top
= wnd
->owner
->rectWindow
.top
+ SYSMETRICS_CYICON
;
114 if( str
!= emptyTitleText
) HeapFree( GetProcessHeap(), 0, str
);
115 return ( hDC
) ? TRUE
: FALSE
;
120 /***********************************************************************
123 static BOOL
ICONTITLE_Paint( WND
* wnd
, HDC hDC
, BOOL bActive
)
127 COLORREF textColor
= 0;
131 hBrush
= GetSysColorBrush(COLOR_ACTIVECAPTION
);
132 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
136 if( wnd
->dwStyle
& WS_CHILD
)
138 hBrush
= wnd
->parent
->class->hbrBackground
;
143 GetObjectA( hBrush
, sizeof(logBrush
), &logBrush
);
144 level
= GetRValue(logBrush
.lbColor
) +
145 GetGValue(logBrush
.lbColor
) +
146 GetBValue(logBrush
.lbColor
);
147 if( level
< (0x7F * 3) )
148 textColor
= RGB( 0xFF, 0xFF, 0xFF );
151 hBrush
= GetStockObject( WHITE_BRUSH
);
155 hBrush
= GetStockObject( BLACK_BRUSH
);
156 textColor
= RGB( 0xFF, 0xFF, 0xFF );
160 FillWindow16( wnd
->parent
->hwndSelf
, wnd
->hwndSelf
, hDC
, hBrush
);
162 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
169 rect
.left
= rect
.top
= 0;
170 rect
.right
= wnd
->rectWindow
.right
- wnd
->rectWindow
.left
;
171 rect
.bottom
= wnd
->rectWindow
.bottom
- wnd
->rectWindow
.top
;
173 length
= GetWindowTextA( wnd
->owner
->hwndSelf
, buffer
, 80 );
174 SetTextColor( hDC
, textColor
);
175 SetBkMode( hDC
, TRANSPARENT
);
177 DrawTextA( hDC
, buffer
, length
, &rect
, DT_CENTER
| DT_NOPREFIX
|
178 DT_WORDBREAK
| ((bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
180 SelectObject( hDC
, hPrevFont
);
182 return ( hPrevFont
) ? TRUE
: FALSE
;
185 /***********************************************************************
188 LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
,
189 WPARAM wParam
, LPARAM lParam
)
192 WND
*wnd
= WIN_FindWndPtr( hWnd
);
197 retvalue
= HTCAPTION
;
200 case WM_NCLBUTTONDBLCLK
:
201 retvalue
= SendMessageA( wnd
->owner
->hwndSelf
, msg
, wParam
, lParam
);
204 if( wParam
) SetActiveWindow( wnd
->owner
->hwndSelf
);
215 ICONTITLE_GetTitlePos( wnd
, &titleRect
);
216 if( wnd
->owner
->next
!= wnd
) /* keep icon title behind the owner */
217 SetWindowPos( hWnd
, wnd
->owner
->hwndSelf
,
218 titleRect
.left
, titleRect
.top
,
219 titleRect
.right
, titleRect
.bottom
, SWP_NOACTIVATE
);
221 SetWindowPos( hWnd
, 0, titleRect
.left
, titleRect
.top
,
222 titleRect
.right
, titleRect
.bottom
,
223 SWP_NOACTIVATE
| SWP_NOZORDER
);
230 WND
* iconWnd
= WIN_LockWndPtr(wnd
->owner
);
232 if( iconWnd
->dwStyle
& WS_CHILD
)
233 lParam
= SendMessageA( iconWnd
->hwndSelf
, WM_ISACTIVEICON
, 0, 0 );
235 lParam
= (iconWnd
->hwndSelf
== GetActiveWindow16());
237 WIN_ReleaseWndPtr(iconWnd
);
238 if( ICONTITLE_Paint( wnd
, (HDC
)wParam
, (BOOL
)lParam
) )
239 ValidateRect( hWnd
, NULL
);
245 retvalue
= DefWindowProcA( hWnd
, msg
, wParam
, lParam
);
247 WIN_ReleaseWndPtr(wnd
);