2 * Icontitle window class.
4 * Copyright 1997 Alex Korobka
13 #include "wine/winuser16.h"
14 #include "wine/unicode.h"
19 static BOOL bMultiLineTitle
;
20 static HFONT hIconTitleFont
;
22 static LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
24 /*********************************************************************
25 * icon title class descriptor
27 const struct builtin_class_descr ICONTITLE_builtin_class
=
29 ICONTITLE_CLASS_ATOM
, /* name */
30 CS_GLOBALCLASS
, /* style */
31 NULL
, /* procA (winproc is Unicode only) */
32 IconTitleWndProc
, /* procW */
34 IDC_ARROWA
, /* cursor */
40 /***********************************************************************
43 HWND
ICONTITLE_Create( WND
* wnd
)
48 if( wnd
->dwStyle
& WS_CHILD
)
49 hWnd
= CreateWindowExA( 0, ICONTITLE_CLASS_ATOM
, NULL
,
50 WS_CHILD
| WS_CLIPSIBLINGS
, 0, 0, 1, 1,
51 wnd
->parent
->hwndSelf
, 0, wnd
->hInstance
, NULL
);
53 hWnd
= CreateWindowExA( 0, ICONTITLE_CLASS_ATOM
, NULL
,
54 WS_CLIPSIBLINGS
, 0, 0, 1, 1,
55 wnd
->hwndSelf
, 0, wnd
->hInstance
, NULL
);
56 wndPtr
= WIN_FindWndPtr( hWnd
);
59 wndPtr
->owner
= wnd
; /* MDI depends on this */
60 wndPtr
->dwStyle
&= ~(WS_CAPTION
| WS_BORDER
);
61 if( wnd
->dwStyle
& WS_DISABLED
) wndPtr
->dwStyle
|= WS_DISABLED
;
62 WIN_ReleaseWndPtr(wndPtr
);
68 /***********************************************************************
69 * ICONTITLE_GetTitlePos
71 static BOOL
ICONTITLE_GetTitlePos( WND
* wnd
, LPRECT lpRect
)
73 static WCHAR emptyTitleText
[] = {'<','.','.','.','>',0};
75 int length
= lstrlenW( wnd
->owner
->text
);
79 str
= HeapAlloc( GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
) );
80 strcpyW( str
, wnd
->owner
->text
);
81 while( str
[length
- 1] == ' ' ) /* remove trailing spaces */
86 HeapFree( GetProcessHeap(), 0, str
);
94 length
= lstrlenW( str
);
99 HDC hDC
= GetDC( wnd
->hwndSelf
);
102 HFONT hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
104 SetRect( lpRect
, 0, 0, GetSystemMetrics(SM_CXICONSPACING
) -
105 GetSystemMetrics(SM_CXBORDER
) * 2,
106 GetSystemMetrics(SM_CYBORDER
) * 2 );
108 DrawTextW( hDC
, str
, length
, lpRect
, DT_CALCRECT
|
109 DT_CENTER
| DT_NOPREFIX
| DT_WORDBREAK
|
110 (( bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
112 SelectObject( hDC
, hPrevFont
);
113 ReleaseDC( wnd
->hwndSelf
, hDC
);
115 lpRect
->right
+= 4 * GetSystemMetrics(SM_CXBORDER
) - lpRect
->left
;
116 lpRect
->left
= wnd
->owner
->rectWindow
.left
+ GetSystemMetrics(SM_CXICON
) / 2 -
117 (lpRect
->right
- lpRect
->left
) / 2;
118 lpRect
->bottom
-= lpRect
->top
;
119 lpRect
->top
= wnd
->owner
->rectWindow
.top
+ GetSystemMetrics(SM_CYICON
);
121 if( str
!= emptyTitleText
) HeapFree( GetProcessHeap(), 0, str
);
122 return ( hDC
) ? TRUE
: FALSE
;
127 /***********************************************************************
130 static BOOL
ICONTITLE_Paint( WND
* wnd
, HDC hDC
, BOOL bActive
)
134 COLORREF textColor
= 0;
138 hBrush
= GetSysColorBrush(COLOR_ACTIVECAPTION
);
139 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
143 if( wnd
->dwStyle
& WS_CHILD
)
145 hBrush
= (HBRUSH
) GetClassLongA(wnd
->hwndSelf
, GCL_HBRBACKGROUND
);
150 GetObjectA( hBrush
, sizeof(logBrush
), &logBrush
);
151 level
= GetRValue(logBrush
.lbColor
) +
152 GetGValue(logBrush
.lbColor
) +
153 GetBValue(logBrush
.lbColor
);
154 if( level
< (0x7F * 3) )
155 textColor
= RGB( 0xFF, 0xFF, 0xFF );
158 hBrush
= GetStockObject( WHITE_BRUSH
);
162 hBrush
= GetStockObject( BLACK_BRUSH
);
163 textColor
= RGB( 0xFF, 0xFF, 0xFF );
167 FillWindow16( wnd
->parent
->hwndSelf
, wnd
->hwndSelf
, hDC
, hBrush
);
169 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
176 rect
.left
= rect
.top
= 0;
177 rect
.right
= wnd
->rectWindow
.right
- wnd
->rectWindow
.left
;
178 rect
.bottom
= wnd
->rectWindow
.bottom
- wnd
->rectWindow
.top
;
180 length
= GetWindowTextA( wnd
->owner
->hwndSelf
, buffer
, 80 );
181 SetTextColor( hDC
, textColor
);
182 SetBkMode( hDC
, TRANSPARENT
);
184 DrawTextA( hDC
, buffer
, length
, &rect
, DT_CENTER
| DT_NOPREFIX
|
185 DT_WORDBREAK
| ((bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
187 SelectObject( hDC
, hPrevFont
);
189 return ( hPrevFont
) ? TRUE
: FALSE
;
192 /***********************************************************************
195 LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
,
196 WPARAM wParam
, LPARAM lParam
)
199 WND
*wnd
= WIN_FindWndPtr( hWnd
);
207 SystemParametersInfoA( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
208 SystemParametersInfoA( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
209 hIconTitleFont
= CreateFontIndirectA( &logFont
);
211 retvalue
= (hIconTitleFont
) ? 0 : -1;
214 retvalue
= HTCAPTION
;
217 case WM_NCLBUTTONDBLCLK
:
218 retvalue
= SendMessageA( wnd
->owner
->hwndSelf
, msg
, wParam
, lParam
);
221 if( wParam
) SetActiveWindow( wnd
->owner
->hwndSelf
);
232 ICONTITLE_GetTitlePos( wnd
, &titleRect
);
233 if( wnd
->owner
->next
!= wnd
) /* keep icon title behind the owner */
234 SetWindowPos( hWnd
, wnd
->owner
->hwndSelf
,
235 titleRect
.left
, titleRect
.top
,
236 titleRect
.right
, titleRect
.bottom
, SWP_NOACTIVATE
);
238 SetWindowPos( hWnd
, 0, titleRect
.left
, titleRect
.top
,
239 titleRect
.right
, titleRect
.bottom
,
240 SWP_NOACTIVATE
| SWP_NOZORDER
);
247 WND
* iconWnd
= WIN_LockWndPtr(wnd
->owner
);
249 if( iconWnd
->dwStyle
& WS_CHILD
)
250 lParam
= SendMessageA( iconWnd
->hwndSelf
, WM_ISACTIVEICON
, 0, 0 );
252 lParam
= (iconWnd
->hwndSelf
== GetActiveWindow16());
254 WIN_ReleaseWndPtr(iconWnd
);
255 if( ICONTITLE_Paint( wnd
, (HDC
)wParam
, (BOOL
)lParam
) )
256 ValidateRect( hWnd
, NULL
);
262 retvalue
= DefWindowProcW( hWnd
, msg
, wParam
, lParam
);
264 WIN_ReleaseWndPtr(wnd
);