2 * Icontitle window class.
4 * Copyright 1997 Alex Korobka
11 #include "wine/winuser16.h"
12 #include "sysmetrics.h"
17 static LPCSTR emptyTitleText
= "<...>";
19 BOOL32 bMultiLineTitle
;
20 HFONT32 hIconTitleFont
;
22 /***********************************************************************
25 BOOL32
ICONTITLE_Init(void)
29 SystemParametersInfo32A( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
30 SystemParametersInfo32A( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
31 hIconTitleFont
= CreateFontIndirect32A( &logFont
);
32 return (hIconTitleFont
) ? TRUE
: FALSE
;
35 /***********************************************************************
38 HWND32
ICONTITLE_Create( WND
* wnd
)
43 if( wnd
->dwStyle
& WS_CHILD
)
44 hWnd
= CreateWindowEx32A( 0, ICONTITLE_CLASS_ATOM
, NULL
,
45 WS_CHILD
| WS_CLIPSIBLINGS
, 0, 0, 1, 1,
46 wnd
->parent
->hwndSelf
, 0, wnd
->hInstance
, NULL
);
48 hWnd
= CreateWindowEx32A( 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
;
62 /***********************************************************************
63 * ICONTITLE_GetTitlePos
65 static BOOL32
ICONTITLE_GetTitlePos( WND
* wnd
, LPRECT32 lpRect
)
68 int length
= lstrlen32A( wnd
->owner
->text
);
72 str
= HeapAlloc( GetProcessHeap(), 0, length
+ 1 );
73 lstrcpy32A( str
, wnd
->owner
->text
);
74 while( str
[length
- 1] == ' ' ) /* remove trailing spaces */
79 HeapFree( GetProcessHeap(), 0, str
);
86 str
= (LPSTR
)emptyTitleText
;
87 length
= lstrlen32A( str
);
92 HDC32 hDC
= GetDC32( wnd
->hwndSelf
);
95 HFONT32 hPrevFont
= SelectObject32( hDC
, hIconTitleFont
);
97 SetRect32( lpRect
, 0, 0, sysMetrics
[SM_CXICONSPACING
] -
98 SYSMETRICS_CXBORDER
* 2, SYSMETRICS_CYBORDER
* 2 );
100 DrawText32A( hDC
, str
, length
, lpRect
, DT_CALCRECT
|
101 DT_CENTER
| DT_NOPREFIX
| DT_WORDBREAK
|
102 (( bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
104 SelectObject32( hDC
, hPrevFont
);
105 ReleaseDC32( wnd
->hwndSelf
, hDC
);
107 lpRect
->right
+= 4 * SYSMETRICS_CXBORDER
- lpRect
->left
;
108 lpRect
->left
= wnd
->owner
->rectWindow
.left
+ SYSMETRICS_CXICON
/ 2 -
109 (lpRect
->right
- lpRect
->left
) / 2;
110 lpRect
->bottom
-= lpRect
->top
;
111 lpRect
->top
= wnd
->owner
->rectWindow
.top
+ SYSMETRICS_CYICON
;
113 if( str
!= emptyTitleText
) HeapFree( GetProcessHeap(), 0, str
);
114 return ( hDC
) ? TRUE
: FALSE
;
119 /***********************************************************************
122 static BOOL32
ICONTITLE_Paint( WND
* wnd
, HDC32 hDC
, BOOL32 bActive
)
126 COLORREF textColor
= 0;
130 hBrush
= GetSysColorBrush32(COLOR_ACTIVECAPTION
);
131 textColor
= GetSysColor32(COLOR_CAPTIONTEXT
);
135 if( wnd
->dwStyle
& WS_CHILD
)
137 hBrush
= wnd
->parent
->class->hbrBackground
;
142 GetObject32A( hBrush
, sizeof(logBrush
), &logBrush
);
143 level
= GetRValue(logBrush
.lbColor
) +
144 GetGValue(logBrush
.lbColor
) +
145 GetBValue(logBrush
.lbColor
);
146 if( level
< (0x7F * 3) )
147 textColor
= RGB( 0xFF, 0xFF, 0xFF );
150 hBrush
= GetStockObject32( WHITE_BRUSH
);
154 hBrush
= GetStockObject32( BLACK_BRUSH
);
155 textColor
= RGB( 0xFF, 0xFF, 0xFF );
159 FillWindow( wnd
->parent
->hwndSelf
, wnd
->hwndSelf
, hDC
, hBrush
);
161 hPrevFont
= SelectObject32( hDC
, hIconTitleFont
);
168 rect
.left
= rect
.top
= 0;
169 rect
.right
= wnd
->rectWindow
.right
- wnd
->rectWindow
.left
;
170 rect
.bottom
= wnd
->rectWindow
.bottom
- wnd
->rectWindow
.top
;
172 length
= GetWindowText32A( wnd
->owner
->hwndSelf
, buffer
, 80 );
173 SetTextColor32( hDC
, textColor
);
174 SetBkMode32( hDC
, TRANSPARENT
);
176 DrawText32A( hDC
, buffer
, length
, &rect
, DT_CENTER
| DT_NOPREFIX
|
177 DT_WORDBREAK
| ((bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
179 SelectObject32( hDC
, hPrevFont
);
181 return ( hPrevFont
) ? TRUE
: FALSE
;
184 /***********************************************************************
187 LRESULT WINAPI
IconTitleWndProc( HWND32 hWnd
, UINT32 msg
,
188 WPARAM32 wParam
, LPARAM lParam
)
190 WND
*wnd
= WIN_FindWndPtr( hWnd
);
198 case WM_NCLBUTTONDBLCLK
:
199 return SendMessage32A( wnd
->owner
->hwndSelf
, msg
, wParam
, lParam
);
202 if( wParam
) SetActiveWindow32( wnd
->owner
->hwndSelf
);
213 ICONTITLE_GetTitlePos( wnd
, &titleRect
);
214 if( wnd
->owner
->next
!= wnd
) /* keep icon title behind the owner */
215 SetWindowPos32( hWnd
, wnd
->owner
->hwndSelf
,
216 titleRect
.left
, titleRect
.top
,
217 titleRect
.right
, titleRect
.bottom
, SWP_NOACTIVATE
);
219 SetWindowPos32( hWnd
, 0, titleRect
.left
, titleRect
.top
,
220 titleRect
.right
, titleRect
.bottom
,
221 SWP_NOACTIVATE
| SWP_NOZORDER
);
228 WND
* iconWnd
= wnd
->owner
;
230 if( iconWnd
->dwStyle
& WS_CHILD
)
231 lParam
= SendMessage32A( iconWnd
->hwndSelf
, WM_ISACTIVEICON
, 0, 0 );
233 lParam
= (iconWnd
->hwndSelf
== GetActiveWindow16());
235 if( ICONTITLE_Paint( wnd
, (HDC32
)wParam
, (BOOL32
)lParam
) )
236 ValidateRect32( hWnd
, NULL
);
241 return DefWindowProc32A( hWnd
, msg
, wParam
, lParam
);