Add define for undocumented status bar message SB_SETBORDERS.
[wine.git] / controls / icontitle.c
blobf3f62c427613e934375366357a39561cf15add65
1 /*
2 * Icontitle window class.
4 * Copyright 1997 Alex Korobka
5 */
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
11 #include "windef.h"
12 #include "winbase.h"
13 #include "wingdi.h"
14 #include "winuser.h"
15 #include "wine/winuser16.h"
16 #include "wine/unicode.h"
17 #include "controls.h"
18 #include "win.h"
20 static BOOL bMultiLineTitle;
21 static HFONT hIconTitleFont;
23 static LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
25 /*********************************************************************
26 * icon title class descriptor
28 const struct builtin_class_descr ICONTITLE_builtin_class =
30 ICONTITLE_CLASS_ATOM, /* name */
31 CS_GLOBALCLASS, /* style */
32 NULL, /* procA (winproc is Unicode only) */
33 IconTitleWndProc, /* procW */
34 0, /* extra */
35 IDC_ARROWA, /* cursor */
36 0 /* brush */
41 /***********************************************************************
42 * ICONTITLE_Create
44 HWND ICONTITLE_Create( HWND owner )
46 HWND hWnd;
47 HINSTANCE instance = GetWindowLongA( owner, GWL_HINSTANCE );
48 LONG style = WS_CLIPSIBLINGS;
50 if (!IsWindowEnabled(owner)) style |= WS_DISABLED;
51 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
52 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
53 style | WS_CHILD, 0, 0, 1, 1,
54 GetParent(owner), 0, instance, NULL );
55 else
56 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
57 style, 0, 0, 1, 1,
58 owner, 0, instance, NULL );
59 WIN_SetOwner( hWnd, owner ); /* MDI depends on this */
60 SetWindowLongW( hWnd, GWL_STYLE,
61 GetWindowLongW( hWnd, GWL_STYLE ) & ~(WS_CAPTION | WS_BORDER) );
62 return hWnd;
65 /***********************************************************************
66 * ICONTITLE_SetTitlePos
68 static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
70 static WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
71 WCHAR str[80];
72 HDC hDC;
73 HFONT hPrevFont;
74 RECT rect;
75 INT cx, cy;
76 POINT pt;
78 int length = GetWindowTextW( owner, str, sizeof(str)/sizeof(WCHAR) );
80 while (length && str[length - 1] == ' ') /* remove trailing spaces */
81 str[--length] = 0;
83 if( !length )
85 strcpyW( str, emptyTitleText );
86 length = strlenW( str );
89 if (!(hDC = GetDC( hwnd ))) return FALSE;
91 hPrevFont = SelectObject( hDC, hIconTitleFont );
93 SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
94 GetSystemMetrics(SM_CXBORDER) * 2,
95 GetSystemMetrics(SM_CYBORDER) * 2 );
97 DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
98 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
100 SelectObject( hDC, hPrevFont );
101 ReleaseDC( hwnd, hDC );
103 cx = rect.right - rect.left + 4 * GetSystemMetrics(SM_CXBORDER);
104 cy = rect.bottom - rect.top;
106 pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
107 pt.y = GetSystemMetrics(SM_CYICON);
109 /* point is relative to owner, make it relative to parent */
110 MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
112 SetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
113 return TRUE;
116 /***********************************************************************
117 * ICONTITLE_Paint
119 static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
121 RECT rect;
122 HFONT hPrevFont;
123 HBRUSH hBrush = 0;
124 COLORREF textColor = 0;
126 if( bActive )
128 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
129 textColor = GetSysColor(COLOR_CAPTIONTEXT);
131 else
133 if( GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD )
135 hBrush = (HBRUSH) GetClassLongA(hwnd, GCL_HBRBACKGROUND);
136 if( hBrush )
138 INT level;
139 LOGBRUSH logBrush;
140 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
141 level = GetRValue(logBrush.lbColor) +
142 GetGValue(logBrush.lbColor) +
143 GetBValue(logBrush.lbColor);
144 if( level < (0x7F * 3) )
145 textColor = RGB( 0xFF, 0xFF, 0xFF );
147 else
148 hBrush = GetStockObject( WHITE_BRUSH );
150 else
152 hBrush = GetStockObject( BLACK_BRUSH );
153 textColor = RGB( 0xFF, 0xFF, 0xFF );
157 GetClientRect( hwnd, &rect );
158 DPtoLP( hDC, (LPPOINT)&rect, 2 );
159 FillRect( hDC, &rect, hBrush );
161 hPrevFont = SelectObject( hDC, hIconTitleFont );
162 if( hPrevFont )
164 WCHAR buffer[80];
166 INT length = GetWindowTextW( owner, buffer, sizeof(buffer) );
167 SetTextColor( hDC, textColor );
168 SetBkMode( hDC, TRANSPARENT );
170 DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
171 DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
173 SelectObject( hDC, hPrevFont );
175 return (hPrevFont != 0);
178 /***********************************************************************
179 * IconTitleWndProc
181 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
182 WPARAM wParam, LPARAM lParam )
184 HWND owner = GetWindow( hWnd, GW_OWNER );
186 if (!IsWindow(hWnd)) return 0;
188 switch( msg )
190 case WM_CREATE:
191 if (!hIconTitleFont)
193 LOGFONTA logFont;
194 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
195 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
196 hIconTitleFont = CreateFontIndirectA( &logFont );
198 return (hIconTitleFont ? 0 : -1);
199 case WM_NCHITTEST:
200 return HTCAPTION;
201 case WM_NCMOUSEMOVE:
202 case WM_NCLBUTTONDBLCLK:
203 return SendMessageW( owner, msg, wParam, lParam );
204 case WM_ACTIVATE:
205 if( wParam ) SetActiveWindow( owner );
206 return 0;
207 case WM_CLOSE:
208 return 0;
209 case WM_SHOWWINDOW:
210 if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
211 return 0;
212 case WM_ERASEBKGND:
213 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
214 lParam = SendMessageA( owner, WM_ISACTIVEICON, 0, 0 );
215 else
216 lParam = (owner == GetActiveWindow());
217 if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
218 ValidateRect( hWnd, NULL );
219 return 1;
221 return DefWindowProcW( hWnd, msg, wParam, lParam );