Release 970824
[wine/multimedia.git] / controls / icontitle.c
blobb54801e2414450f4299a9ccc741867d99e9b289b
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 "windows.h"
11 #include "sysmetrics.h"
12 #include "syscolor.h"
13 #include "win.h"
14 #include "desktop.h"
15 #include "graphics.h"
16 #include "heap.h"
18 static LPCSTR emptyTitleText = "<...>";
20 BOOL32 bMultiLineTitle;
21 HFONT32 hIconTitleFont;
23 /***********************************************************************
24 * ICONTITLE_Init
26 BOOL32 ICONTITLE_Init(void)
28 LOGFONT16 logFont;
30 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
31 SystemParametersInfo16( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
32 hIconTitleFont = CreateFontIndirect16( &logFont );
33 return (hIconTitleFont) ? TRUE : FALSE;
36 /***********************************************************************
37 * ICONTITLE_Create
39 HWND32 ICONTITLE_Create( WND* wnd )
41 WND* wndPtr;
42 HWND32 hWnd;
44 if( wnd->dwStyle & WS_CHILD )
45 hWnd = CreateWindowEx32A( 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 = CreateWindowEx32A( 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 return hWnd;
60 return 0;
63 /***********************************************************************
64 * ICONTITLE_GetTitlePos
66 static BOOL32 ICONTITLE_GetTitlePos( WND* wnd, LPRECT32 lpRect )
68 LPSTR str;
69 int length = lstrlen32A( wnd->owner->text );
71 if( length )
73 str = HeapAlloc( GetProcessHeap(), 0, length + 1 );
74 lstrcpy32A( str, wnd->owner->text );
75 while( str[length - 1] == ' ' ) /* remove trailing spaces */
77 str[--length] = '\0';
78 if( !length )
80 HeapFree( GetProcessHeap(), 0, str );
81 break;
85 if( !length )
87 str = (LPSTR)emptyTitleText;
88 length = lstrlen32A( str );
91 if( str )
93 HDC32 hDC = GetDC32( wnd->hwndSelf );
94 if( hDC )
96 HFONT32 hPrevFont = SelectObject32( hDC, hIconTitleFont );
98 SetRect32( lpRect, 0, 0, sysMetrics[SM_CXICONSPACING] -
99 SYSMETRICS_CXBORDER * 2, SYSMETRICS_CYBORDER * 2 );
101 DrawText32A( hDC, str, length, lpRect, DT_CALCRECT |
102 DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
103 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
105 SelectObject32( hDC, hPrevFont );
106 ReleaseDC32( wnd->hwndSelf, hDC );
108 lpRect->right += 4 * SYSMETRICS_CXBORDER - lpRect->left;
109 lpRect->left = wnd->owner->rectWindow.left + SYSMETRICS_CXICON / 2 -
110 (lpRect->right - lpRect->left) / 2;
111 lpRect->bottom -= lpRect->top;
112 lpRect->top = wnd->owner->rectWindow.top + SYSMETRICS_CYICON;
114 if( str != emptyTitleText ) HeapFree( GetProcessHeap(), 0, str );
115 return ( hDC ) ? TRUE : FALSE;
117 return FALSE;
120 /***********************************************************************
121 * ICONTITLE_Paint
123 static BOOL32 ICONTITLE_Paint( WND* wnd, HDC32 hDC, BOOL32 bActive )
125 HFONT32 hPrevFont;
126 HBRUSH32 hBrush = 0;
127 COLORREF textColor = 0;
129 if( bActive )
131 hBrush = sysColorObjects.hbrushActiveCaption;
132 textColor = GetSysColor32(COLOR_CAPTIONTEXT);
134 else
136 if( wnd->dwStyle & WS_CHILD )
138 hBrush = wnd->parent->class->hbrBackground;
139 if( hBrush )
141 INT32 level;
142 LOGBRUSH32 logBrush;
143 GetObject32A( hBrush, sizeof(logBrush), &logBrush );
144 level = GetRValue(logBrush.lbColor) +
145 GetGValue(logBrush.lbColor) +
146 GetBValue(logBrush.lbColor);
147 if( level < (0x7F * 3) )
148 textColor = RGB( 0xFF, 0xFF, 0xFF );
150 else
151 hBrush = GetStockObject32( WHITE_BRUSH );
153 else
155 hBrush = GetStockObject32( BLACK_BRUSH );
156 textColor = RGB( 0xFF, 0xFF, 0xFF );
160 FillWindow( wnd->parent->hwndSelf, wnd->hwndSelf, hDC, hBrush );
162 hPrevFont = SelectObject32( hDC, hIconTitleFont );
163 if( hPrevFont )
165 RECT16 rect;
166 INT32 length;
167 char buffer[80];
169 rect.left = rect.top = 0;
170 rect.right = wnd->rectWindow.right - wnd->rectWindow.left;
171 rect.bottom = wnd->rectWindow.bottom - wnd->rectWindow.top;
173 length = GetWindowText32A( wnd->owner->hwndSelf, buffer, 80 );
174 SetTextColor32( hDC, textColor );
175 SetBkMode32( hDC, TRANSPARENT );
177 DrawText16( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
178 DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
180 SelectObject32( hDC, hPrevFont );
182 return ( hPrevFont ) ? TRUE : FALSE;
185 /***********************************************************************
186 * IconTitleWndProc
188 LRESULT WINAPI IconTitleWndProc( HWND32 hWnd, UINT32 msg,
189 WPARAM32 wParam, LPARAM lParam )
191 WND *wnd = WIN_FindWndPtr( hWnd );
193 switch( msg )
195 case WM_NCHITTEST:
196 return HTCAPTION;
198 case WM_NCMOUSEMOVE:
199 case WM_NCLBUTTONDBLCLK:
200 return SendMessage32A( wnd->owner->hwndSelf, msg, wParam, lParam );
202 case WM_ACTIVATE:
203 if( wParam ) SetActiveWindow32( wnd->owner->hwndSelf );
204 /* fall through */
206 case WM_CLOSE:
207 return 0;
209 case WM_SHOWWINDOW:
210 if( wnd && wParam )
212 RECT32 titleRect;
214 ICONTITLE_GetTitlePos( wnd, &titleRect );
215 if( wnd->owner->next != wnd ) /* keep icon title behind the owner */
216 SetWindowPos32( hWnd, wnd->owner->hwndSelf,
217 titleRect.left, titleRect.top,
218 titleRect.right, titleRect.bottom, SWP_NOACTIVATE );
219 else
220 SetWindowPos32( hWnd, 0, titleRect.left, titleRect.top,
221 titleRect.right, titleRect.bottom,
222 SWP_NOACTIVATE | SWP_NOZORDER );
224 return 0;
226 case WM_ERASEBKGND:
227 if( wnd )
229 WND* iconWnd = wnd->owner;
231 if( iconWnd->dwStyle & WS_CHILD )
232 lParam = SendMessage32A( iconWnd->hwndSelf, WM_ISACTIVEICON, 0, 0 );
233 else
234 lParam = (iconWnd->hwndSelf == GetActiveWindow16());
236 if( ICONTITLE_Paint( wnd, (HDC32)wParam, (BOOL32)lParam ) )
237 ValidateRect32( hWnd, NULL );
238 return 1;
242 return DefWindowProc32A( hWnd, msg, wParam, lParam );