Add support for selection of console mode drivers to use using the
[wine/multimedia.git] / controls / icontitle.c
blob3ea9656c9b56d151d9a16ef92a3ff034378190cc
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 "win.h"
13 #include "desktop.h"
14 #include "heap.h"
16 static LPCSTR emptyTitleText = "<...>";
18 BOOL32 bMultiLineTitle;
19 HFONT32 hIconTitleFont;
21 /***********************************************************************
22 * ICONTITLE_Init
24 BOOL32 ICONTITLE_Init(void)
26 LOGFONT32A logFont;
28 SystemParametersInfo32A( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
29 SystemParametersInfo32A( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
30 hIconTitleFont = CreateFontIndirect32A( &logFont );
31 return (hIconTitleFont) ? TRUE : FALSE;
34 /***********************************************************************
35 * ICONTITLE_Create
37 HWND32 ICONTITLE_Create( WND* wnd )
39 WND* wndPtr;
40 HWND32 hWnd;
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 );
46 else
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 );
51 if( wndPtr )
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;
56 return hWnd;
58 return 0;
61 /***********************************************************************
62 * ICONTITLE_GetTitlePos
64 static BOOL32 ICONTITLE_GetTitlePos( WND* wnd, LPRECT32 lpRect )
66 LPSTR str;
67 int length = lstrlen32A( wnd->owner->text );
69 if( length )
71 str = HeapAlloc( GetProcessHeap(), 0, length + 1 );
72 lstrcpy32A( str, wnd->owner->text );
73 while( str[length - 1] == ' ' ) /* remove trailing spaces */
75 str[--length] = '\0';
76 if( !length )
78 HeapFree( GetProcessHeap(), 0, str );
79 break;
83 if( !length )
85 str = (LPSTR)emptyTitleText;
86 length = lstrlen32A( str );
89 if( str )
91 HDC32 hDC = GetDC32( wnd->hwndSelf );
92 if( hDC )
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;
115 return FALSE;
118 /***********************************************************************
119 * ICONTITLE_Paint
121 static BOOL32 ICONTITLE_Paint( WND* wnd, HDC32 hDC, BOOL32 bActive )
123 HFONT32 hPrevFont;
124 HBRUSH32 hBrush = 0;
125 COLORREF textColor = 0;
127 if( bActive )
129 hBrush = GetSysColorBrush32(COLOR_ACTIVECAPTION);
130 textColor = GetSysColor32(COLOR_CAPTIONTEXT);
132 else
134 if( wnd->dwStyle & WS_CHILD )
136 hBrush = wnd->parent->class->hbrBackground;
137 if( hBrush )
139 INT32 level;
140 LOGBRUSH32 logBrush;
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 );
148 else
149 hBrush = GetStockObject32( WHITE_BRUSH );
151 else
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 );
161 if( hPrevFont )
163 RECT32 rect;
164 INT32 length;
165 char buffer[80];
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 /***********************************************************************
184 * IconTitleWndProc
186 LRESULT WINAPI IconTitleWndProc( HWND32 hWnd, UINT32 msg,
187 WPARAM32 wParam, LPARAM lParam )
189 WND *wnd = WIN_FindWndPtr( hWnd );
191 switch( msg )
193 case WM_NCHITTEST:
194 return HTCAPTION;
196 case WM_NCMOUSEMOVE:
197 case WM_NCLBUTTONDBLCLK:
198 return SendMessage32A( wnd->owner->hwndSelf, msg, wParam, lParam );
200 case WM_ACTIVATE:
201 if( wParam ) SetActiveWindow32( wnd->owner->hwndSelf );
202 /* fall through */
204 case WM_CLOSE:
205 return 0;
207 case WM_SHOWWINDOW:
208 if( wnd && wParam )
210 RECT32 titleRect;
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 );
217 else
218 SetWindowPos32( hWnd, 0, titleRect.left, titleRect.top,
219 titleRect.right, titleRect.bottom,
220 SWP_NOACTIVATE | SWP_NOZORDER );
222 return 0;
224 case WM_ERASEBKGND:
225 if( wnd )
227 WND* iconWnd = wnd->owner;
229 if( iconWnd->dwStyle & WS_CHILD )
230 lParam = SendMessage32A( iconWnd->hwndSelf, WM_ISACTIVEICON, 0, 0 );
231 else
232 lParam = (iconWnd->hwndSelf == GetActiveWindow16());
234 if( ICONTITLE_Paint( wnd, (HDC32)wParam, (BOOL32)lParam ) )
235 ValidateRect32( hWnd, NULL );
236 return 1;
240 return DefWindowProc32A( hWnd, msg, wParam, lParam );