2 * Icontitle window class.
4 * Copyright 1997 Alex Korobka
11 #include "sysmetrics.h"
16 static LPCSTR emptyTitleText
= "<...>";
18 BOOL32 bMultiLineTitle
;
19 HFONT32 hIconTitleFont
;
21 /***********************************************************************
24 BOOL32
ICONTITLE_Init(void)
28 SystemParametersInfo32A( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
29 SystemParametersInfo32A( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
30 hIconTitleFont
= CreateFontIndirect32A( &logFont
);
31 return (hIconTitleFont
) ? TRUE
: FALSE
;
34 /***********************************************************************
37 HWND32
ICONTITLE_Create( WND
* wnd
)
42 if( wnd
->dwStyle
& WS_CHILD
)
43 hWnd
= CreateWindowEx32A( 0, ICONTITLE_CLASS_ATOM
, NULL
,
44 WS_CHILD
| WS_CLIPSIBLINGS
, 0, 0, 1, 1,
45 wnd
->parent
->hwndSelf
, 0, wnd
->hInstance
, NULL
);
47 hWnd
= CreateWindowEx32A( 0, ICONTITLE_CLASS_ATOM
, NULL
,
48 WS_CLIPSIBLINGS
, 0, 0, 1, 1,
49 wnd
->hwndSelf
, 0, wnd
->hInstance
, NULL
);
50 wndPtr
= WIN_FindWndPtr( hWnd
);
53 wndPtr
->owner
= wnd
; /* MDI depends on this */
54 wndPtr
->dwStyle
&= ~(WS_CAPTION
| WS_BORDER
);
55 if( wnd
->dwStyle
& WS_DISABLED
) wndPtr
->dwStyle
|= WS_DISABLED
;
61 /***********************************************************************
62 * ICONTITLE_GetTitlePos
64 static BOOL32
ICONTITLE_GetTitlePos( WND
* wnd
, LPRECT32 lpRect
)
67 int length
= lstrlen32A( wnd
->owner
->text
);
71 str
= HeapAlloc( GetProcessHeap(), 0, length
+ 1 );
72 lstrcpy32A( str
, wnd
->owner
->text
);
73 while( str
[length
- 1] == ' ' ) /* remove trailing spaces */
78 HeapFree( GetProcessHeap(), 0, str
);
85 str
= (LPSTR
)emptyTitleText
;
86 length
= lstrlen32A( str
);
91 HDC32 hDC
= GetDC32( wnd
->hwndSelf
);
94 HFONT32 hPrevFont
= SelectObject32( hDC
, hIconTitleFont
);
96 SetRect32( lpRect
, 0, 0, sysMetrics
[SM_CXICONSPACING
] -
97 SYSMETRICS_CXBORDER
* 2, SYSMETRICS_CYBORDER
* 2 );
99 DrawText32A( hDC
, str
, length
, lpRect
, DT_CALCRECT
|
100 DT_CENTER
| DT_NOPREFIX
| DT_WORDBREAK
|
101 (( bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
103 SelectObject32( hDC
, hPrevFont
);
104 ReleaseDC32( wnd
->hwndSelf
, hDC
);
106 lpRect
->right
+= 4 * SYSMETRICS_CXBORDER
- lpRect
->left
;
107 lpRect
->left
= wnd
->owner
->rectWindow
.left
+ SYSMETRICS_CXICON
/ 2 -
108 (lpRect
->right
- lpRect
->left
) / 2;
109 lpRect
->bottom
-= lpRect
->top
;
110 lpRect
->top
= wnd
->owner
->rectWindow
.top
+ SYSMETRICS_CYICON
;
112 if( str
!= emptyTitleText
) HeapFree( GetProcessHeap(), 0, str
);
113 return ( hDC
) ? TRUE
: FALSE
;
118 /***********************************************************************
121 static BOOL32
ICONTITLE_Paint( WND
* wnd
, HDC32 hDC
, BOOL32 bActive
)
125 COLORREF textColor
= 0;
129 hBrush
= GetSysColorBrush32(COLOR_ACTIVECAPTION
);
130 textColor
= GetSysColor32(COLOR_CAPTIONTEXT
);
134 if( wnd
->dwStyle
& WS_CHILD
)
136 hBrush
= wnd
->parent
->class->hbrBackground
;
141 GetObject32A( hBrush
, sizeof(logBrush
), &logBrush
);
142 level
= GetRValue(logBrush
.lbColor
) +
143 GetGValue(logBrush
.lbColor
) +
144 GetBValue(logBrush
.lbColor
);
145 if( level
< (0x7F * 3) )
146 textColor
= RGB( 0xFF, 0xFF, 0xFF );
149 hBrush
= GetStockObject32( WHITE_BRUSH
);
153 hBrush
= GetStockObject32( BLACK_BRUSH
);
154 textColor
= RGB( 0xFF, 0xFF, 0xFF );
158 FillWindow( wnd
->parent
->hwndSelf
, wnd
->hwndSelf
, hDC
, hBrush
);
160 hPrevFont
= SelectObject32( hDC
, hIconTitleFont
);
167 rect
.left
= rect
.top
= 0;
168 rect
.right
= wnd
->rectWindow
.right
- wnd
->rectWindow
.left
;
169 rect
.bottom
= wnd
->rectWindow
.bottom
- wnd
->rectWindow
.top
;
171 length
= GetWindowText32A( wnd
->owner
->hwndSelf
, buffer
, 80 );
172 SetTextColor32( hDC
, textColor
);
173 SetBkMode32( hDC
, TRANSPARENT
);
175 DrawText32A( hDC
, buffer
, length
, &rect
, DT_CENTER
| DT_NOPREFIX
|
176 DT_WORDBREAK
| ((bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
178 SelectObject32( hDC
, hPrevFont
);
180 return ( hPrevFont
) ? TRUE
: FALSE
;
183 /***********************************************************************
186 LRESULT WINAPI
IconTitleWndProc( HWND32 hWnd
, UINT32 msg
,
187 WPARAM32 wParam
, LPARAM lParam
)
189 WND
*wnd
= WIN_FindWndPtr( hWnd
);
197 case WM_NCLBUTTONDBLCLK
:
198 return SendMessage32A( wnd
->owner
->hwndSelf
, msg
, wParam
, lParam
);
201 if( wParam
) SetActiveWindow32( wnd
->owner
->hwndSelf
);
212 ICONTITLE_GetTitlePos( wnd
, &titleRect
);
213 if( wnd
->owner
->next
!= wnd
) /* keep icon title behind the owner */
214 SetWindowPos32( hWnd
, wnd
->owner
->hwndSelf
,
215 titleRect
.left
, titleRect
.top
,
216 titleRect
.right
, titleRect
.bottom
, SWP_NOACTIVATE
);
218 SetWindowPos32( hWnd
, 0, titleRect
.left
, titleRect
.top
,
219 titleRect
.right
, titleRect
.bottom
,
220 SWP_NOACTIVATE
| SWP_NOZORDER
);
227 WND
* iconWnd
= wnd
->owner
;
229 if( iconWnd
->dwStyle
& WS_CHILD
)
230 lParam
= SendMessage32A( iconWnd
->hwndSelf
, WM_ISACTIVEICON
, 0, 0 );
232 lParam
= (iconWnd
->hwndSelf
== GetActiveWindow16());
234 if( ICONTITLE_Paint( wnd
, (HDC32
)wParam
, (BOOL32
)lParam
) )
235 ValidateRect32( hWnd
, NULL
);
240 return DefWindowProc32A( hWnd
, msg
, wParam
, lParam
);