Change the current directory as the user browses the directory tree.
[wine.git] / controls / icontitle.c
blob85f9c5bc441b1e930f56c40d5ad709a5ddd9aadc
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 "wine/unicode.h"
15 #include "controls.h"
16 #include "win.h"
17 #include "heap.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 */
33 0, /* extra */
34 IDC_ARROWA, /* cursor */
35 0 /* brush */
40 /***********************************************************************
41 * ICONTITLE_Create
43 HWND ICONTITLE_Create( WND* wnd )
45 WND* wndPtr;
46 HWND hWnd;
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 );
52 else
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 );
57 if( wndPtr )
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);
63 return hWnd;
65 return 0;
68 /***********************************************************************
69 * ICONTITLE_GetTitlePos
71 static BOOL ICONTITLE_GetTitlePos( WND* wnd, LPRECT lpRect )
73 static WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
74 LPWSTR str = NULL;
75 int length = lstrlenW( wnd->owner->text );
77 if( length )
79 str = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR) );
80 strcpyW( str, wnd->owner->text );
81 while( str[length - 1] == ' ' ) /* remove trailing spaces */
83 str[--length] = '\0';
84 if( !length )
86 HeapFree( GetProcessHeap(), 0, str );
87 break;
91 if( !length )
93 str = emptyTitleText;
94 length = lstrlenW( str );
97 if( str )
99 HDC hDC = GetDC( wnd->hwndSelf );
100 if( hDC )
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;
124 return FALSE;
127 /***********************************************************************
128 * ICONTITLE_Paint
130 static BOOL ICONTITLE_Paint( WND* wnd, HDC hDC, BOOL bActive )
132 HFONT hPrevFont;
133 HBRUSH hBrush = 0;
134 COLORREF textColor = 0;
136 if( bActive )
138 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
139 textColor = GetSysColor(COLOR_CAPTIONTEXT);
141 else
143 if( wnd->dwStyle & WS_CHILD )
145 hBrush = (HBRUSH) GetClassLongA(wnd->hwndSelf, GCL_HBRBACKGROUND);
146 if( hBrush )
148 INT level;
149 LOGBRUSH logBrush;
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 );
157 else
158 hBrush = GetStockObject( WHITE_BRUSH );
160 else
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 );
170 if( hPrevFont )
172 RECT rect;
173 INT length;
174 char buffer[80];
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 /***********************************************************************
193 * IconTitleWndProc
195 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
196 WPARAM wParam, LPARAM lParam )
198 LRESULT retvalue;
199 WND *wnd = WIN_FindWndPtr( hWnd );
201 switch( msg )
203 case WM_CREATE:
204 if (!hIconTitleFont)
206 LOGFONTA logFont;
207 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
208 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
209 hIconTitleFont = CreateFontIndirectA( &logFont );
211 retvalue = (hIconTitleFont) ? 0 : -1;
212 goto END;
213 case WM_NCHITTEST:
214 retvalue = HTCAPTION;
215 goto END;
216 case WM_NCMOUSEMOVE:
217 case WM_NCLBUTTONDBLCLK:
218 retvalue = SendMessageA( wnd->owner->hwndSelf, msg, wParam, lParam );
219 goto END;
220 case WM_ACTIVATE:
221 if( wParam ) SetActiveWindow( wnd->owner->hwndSelf );
222 /* fall through */
224 case WM_CLOSE:
225 retvalue = 0;
226 goto END;
227 case WM_SHOWWINDOW:
228 if( wnd && wParam )
230 RECT titleRect;
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 );
237 else
238 SetWindowPos( hWnd, 0, titleRect.left, titleRect.top,
239 titleRect.right, titleRect.bottom,
240 SWP_NOACTIVATE | SWP_NOZORDER );
242 retvalue = 0;
243 goto END;
244 case WM_ERASEBKGND:
245 if( wnd )
247 WND* iconWnd = WIN_LockWndPtr(wnd->owner);
249 if( iconWnd->dwStyle & WS_CHILD )
250 lParam = SendMessageA( iconWnd->hwndSelf, WM_ISACTIVEICON, 0, 0 );
251 else
252 lParam = (iconWnd->hwndSelf == GetActiveWindow16());
254 WIN_ReleaseWndPtr(iconWnd);
255 if( ICONTITLE_Paint( wnd, (HDC)wParam, (BOOL)lParam ) )
256 ValidateRect( hWnd, NULL );
257 retvalue = 1;
258 goto END;
262 retvalue = DefWindowProcW( hWnd, msg, wParam, lParam );
263 END:
264 WIN_ReleaseWndPtr(wnd);
265 return retvalue;