Added atfork support.
[wine/multimedia.git] / controls / icontitle.c
blob9e657b7f1bf80a96ba02719a6e1328827fafeeb5
1 /*
2 * Icontitle window class.
4 * Copyright 1997 Alex Korobka
5 */
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include "windef.h"
11 #include "wingdi.h"
12 #include "winuser.h"
13 #include "wine/winuser16.h"
14 #include "win.h"
15 #include "desktop.h"
16 #include "heap.h"
18 static LPCSTR emptyTitleText = "<...>";
20 BOOL bMultiLineTitle;
21 HFONT hIconTitleFont;
23 /***********************************************************************
24 * ICONTITLE_Init
26 BOOL ICONTITLE_Init(void)
28 LOGFONTA logFont;
30 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
31 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
32 hIconTitleFont = CreateFontIndirectA( &logFont );
33 return (hIconTitleFont) ? TRUE : FALSE;
36 /***********************************************************************
37 * ICONTITLE_Create
39 HWND ICONTITLE_Create( WND* wnd )
41 WND* wndPtr;
42 HWND hWnd;
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 );
48 else
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 );
53 if( wndPtr )
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);
59 return hWnd;
61 return 0;
64 /***********************************************************************
65 * ICONTITLE_GetTitlePos
67 static BOOL ICONTITLE_GetTitlePos( WND* wnd, LPRECT lpRect )
69 LPSTR str;
70 int length = lstrlenA( wnd->owner->text );
72 if( length )
74 str = HeapAlloc( GetProcessHeap(), 0, length + 1 );
75 lstrcpyA( str, wnd->owner->text );
76 while( str[length - 1] == ' ' ) /* remove trailing spaces */
78 str[--length] = '\0';
79 if( !length )
81 HeapFree( GetProcessHeap(), 0, str );
82 break;
86 if( !length )
88 str = (LPSTR)emptyTitleText;
89 length = lstrlenA( str );
92 if( str )
94 HDC hDC = GetDC( wnd->hwndSelf );
95 if( hDC )
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;
119 return FALSE;
122 /***********************************************************************
123 * ICONTITLE_Paint
125 static BOOL ICONTITLE_Paint( WND* wnd, HDC hDC, BOOL bActive )
127 HFONT hPrevFont;
128 HBRUSH hBrush = 0;
129 COLORREF textColor = 0;
131 if( bActive )
133 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
134 textColor = GetSysColor(COLOR_CAPTIONTEXT);
136 else
138 if( wnd->dwStyle & WS_CHILD )
140 hBrush = (HBRUSH) GetClassLongA(wnd->hwndSelf, GCL_HBRBACKGROUND);
141 if( hBrush )
143 INT level;
144 LOGBRUSH logBrush;
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 );
152 else
153 hBrush = GetStockObject( WHITE_BRUSH );
155 else
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 );
165 if( hPrevFont )
167 RECT rect;
168 INT length;
169 char buffer[80];
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 /***********************************************************************
188 * IconTitleWndProc
190 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
191 WPARAM wParam, LPARAM lParam )
193 LRESULT retvalue;
194 WND *wnd = WIN_FindWndPtr( hWnd );
196 switch( msg )
198 case WM_NCHITTEST:
199 retvalue = HTCAPTION;
200 goto END;
201 case WM_NCMOUSEMOVE:
202 case WM_NCLBUTTONDBLCLK:
203 retvalue = SendMessageA( wnd->owner->hwndSelf, msg, wParam, lParam );
204 goto END;
205 case WM_ACTIVATE:
206 if( wParam ) SetActiveWindow( wnd->owner->hwndSelf );
207 /* fall through */
209 case WM_CLOSE:
210 retvalue = 0;
211 goto END;
212 case WM_SHOWWINDOW:
213 if( wnd && wParam )
215 RECT titleRect;
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 );
222 else
223 SetWindowPos( hWnd, 0, titleRect.left, titleRect.top,
224 titleRect.right, titleRect.bottom,
225 SWP_NOACTIVATE | SWP_NOZORDER );
227 retvalue = 0;
228 goto END;
229 case WM_ERASEBKGND:
230 if( wnd )
232 WND* iconWnd = WIN_LockWndPtr(wnd->owner);
234 if( iconWnd->dwStyle & WS_CHILD )
235 lParam = SendMessageA( iconWnd->hwndSelf, WM_ISACTIVEICON, 0, 0 );
236 else
237 lParam = (iconWnd->hwndSelf == GetActiveWindow16());
239 WIN_ReleaseWndPtr(iconWnd);
240 if( ICONTITLE_Paint( wnd, (HDC)wParam, (BOOL)lParam ) )
241 ValidateRect( hWnd, NULL );
242 retvalue = 1;
243 goto END;
247 retvalue = DefWindowProcA( hWnd, msg, wParam, lParam );
248 END:
249 WIN_ReleaseWndPtr(wnd);
250 return retvalue;