Use proper system directory.
[wine/multimedia.git] / controls / icontitle.c
bloba50f807d3a85e0cd66eee83e44858eda0778da01
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 "winuser.h"
11 #include "wine/winuser16.h"
12 #include "sysmetrics.h"
13 #include "win.h"
14 #include "desktop.h"
15 #include "heap.h"
17 static LPCSTR emptyTitleText = "<...>";
19 BOOL32 bMultiLineTitle;
20 HFONT32 hIconTitleFont;
22 /***********************************************************************
23 * ICONTITLE_Init
25 BOOL32 ICONTITLE_Init(void)
27 LOGFONT32A logFont;
29 SystemParametersInfo32A( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
30 SystemParametersInfo32A( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
31 hIconTitleFont = CreateFontIndirect32A( &logFont );
32 return (hIconTitleFont) ? TRUE : FALSE;
35 /***********************************************************************
36 * ICONTITLE_Create
38 HWND32 ICONTITLE_Create( WND* wnd )
40 WND* wndPtr;
41 HWND32 hWnd;
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 );
47 else
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 );
52 if( wndPtr )
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 return hWnd;
59 return 0;
62 /***********************************************************************
63 * ICONTITLE_GetTitlePos
65 static BOOL32 ICONTITLE_GetTitlePos( WND* wnd, LPRECT32 lpRect )
67 LPSTR str;
68 int length = lstrlen32A( wnd->owner->text );
70 if( length )
72 str = HeapAlloc( GetProcessHeap(), 0, length + 1 );
73 lstrcpy32A( str, wnd->owner->text );
74 while( str[length - 1] == ' ' ) /* remove trailing spaces */
76 str[--length] = '\0';
77 if( !length )
79 HeapFree( GetProcessHeap(), 0, str );
80 break;
84 if( !length )
86 str = (LPSTR)emptyTitleText;
87 length = lstrlen32A( str );
90 if( str )
92 HDC32 hDC = GetDC32( wnd->hwndSelf );
93 if( hDC )
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;
116 return FALSE;
119 /***********************************************************************
120 * ICONTITLE_Paint
122 static BOOL32 ICONTITLE_Paint( WND* wnd, HDC32 hDC, BOOL32 bActive )
124 HFONT32 hPrevFont;
125 HBRUSH32 hBrush = 0;
126 COLORREF textColor = 0;
128 if( bActive )
130 hBrush = GetSysColorBrush32(COLOR_ACTIVECAPTION);
131 textColor = GetSysColor32(COLOR_CAPTIONTEXT);
133 else
135 if( wnd->dwStyle & WS_CHILD )
137 hBrush = wnd->parent->class->hbrBackground;
138 if( hBrush )
140 INT32 level;
141 LOGBRUSH32 logBrush;
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 );
149 else
150 hBrush = GetStockObject32( WHITE_BRUSH );
152 else
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 );
162 if( hPrevFont )
164 RECT32 rect;
165 INT32 length;
166 char buffer[80];
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 /***********************************************************************
185 * IconTitleWndProc
187 LRESULT WINAPI IconTitleWndProc( HWND32 hWnd, UINT32 msg,
188 WPARAM32 wParam, LPARAM lParam )
190 WND *wnd = WIN_FindWndPtr( hWnd );
192 switch( msg )
194 case WM_NCHITTEST:
195 return HTCAPTION;
197 case WM_NCMOUSEMOVE:
198 case WM_NCLBUTTONDBLCLK:
199 return SendMessage32A( wnd->owner->hwndSelf, msg, wParam, lParam );
201 case WM_ACTIVATE:
202 if( wParam ) SetActiveWindow32( wnd->owner->hwndSelf );
203 /* fall through */
205 case WM_CLOSE:
206 return 0;
208 case WM_SHOWWINDOW:
209 if( wnd && wParam )
211 RECT32 titleRect;
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 );
218 else
219 SetWindowPos32( hWnd, 0, titleRect.left, titleRect.top,
220 titleRect.right, titleRect.bottom,
221 SWP_NOACTIVATE | SWP_NOZORDER );
223 return 0;
225 case WM_ERASEBKGND:
226 if( wnd )
228 WND* iconWnd = wnd->owner;
230 if( iconWnd->dwStyle & WS_CHILD )
231 lParam = SendMessage32A( iconWnd->hwndSelf, WM_ISACTIVEICON, 0, 0 );
232 else
233 lParam = (iconWnd->hwndSelf == GetActiveWindow16());
235 if( ICONTITLE_Paint( wnd, (HDC32)wParam, (BOOL32)lParam ) )
236 ValidateRect32( hWnd, NULL );
237 return 1;
241 return DefWindowProc32A( hWnd, msg, wParam, lParam );