Remove the WINEDEBUG variable from the environment of the debugger
[wine/multimedia.git] / controls / icontitle.c
blob9f89c4e29c6b5915a45545b6af5e03b479c87f4f
1 /*
2 * Icontitle window class.
4 * Copyright 1997 Alex Korobka
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <string.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "wine/winuser16.h"
35 #include "wine/unicode.h"
36 #include "controls.h"
37 #include "win.h"
39 static BOOL bMultiLineTitle;
40 static HFONT hIconTitleFont;
42 static LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
44 /*********************************************************************
45 * icon title class descriptor
47 const struct builtin_class_descr ICONTITLE_builtin_class =
49 ICONTITLE_CLASS_ATOM, /* name */
50 0, /* style */
51 NULL, /* procA (winproc is Unicode only) */
52 IconTitleWndProc, /* procW */
53 0, /* extra */
54 IDC_ARROW, /* cursor */
55 0 /* brush */
60 /***********************************************************************
61 * ICONTITLE_Create
63 HWND ICONTITLE_Create( HWND owner )
65 HWND hWnd;
66 HINSTANCE instance = (HINSTANCE)GetWindowLongA( owner, GWL_HINSTANCE );
67 LONG style = WS_CLIPSIBLINGS;
69 if (!IsWindowEnabled(owner)) style |= WS_DISABLED;
70 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
71 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
72 style | WS_CHILD, 0, 0, 1, 1,
73 GetParent(owner), 0, instance, NULL );
74 else
75 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
76 style, 0, 0, 1, 1,
77 owner, 0, instance, NULL );
78 WIN_SetOwner( hWnd, owner ); /* MDI depends on this */
79 SetWindowLongW( hWnd, GWL_STYLE,
80 GetWindowLongW( hWnd, GWL_STYLE ) & ~(WS_CAPTION | WS_BORDER) );
81 return hWnd;
84 /***********************************************************************
85 * ICONTITLE_SetTitlePos
87 static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
89 static WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
90 WCHAR str[80];
91 HDC hDC;
92 HFONT hPrevFont;
93 RECT rect;
94 INT cx, cy;
95 POINT pt;
97 int length = GetWindowTextW( owner, str, sizeof(str)/sizeof(WCHAR) );
99 while (length && str[length - 1] == ' ') /* remove trailing spaces */
100 str[--length] = 0;
102 if( !length )
104 strcpyW( str, emptyTitleText );
105 length = strlenW( str );
108 if (!(hDC = GetDC( hwnd ))) return FALSE;
110 hPrevFont = SelectObject( hDC, hIconTitleFont );
112 SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
113 GetSystemMetrics(SM_CXBORDER) * 2,
114 GetSystemMetrics(SM_CYBORDER) * 2 );
116 DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
117 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
119 SelectObject( hDC, hPrevFont );
120 ReleaseDC( hwnd, hDC );
122 cx = rect.right - rect.left + 4 * GetSystemMetrics(SM_CXBORDER);
123 cy = rect.bottom - rect.top;
125 pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
126 pt.y = GetSystemMetrics(SM_CYICON);
128 /* point is relative to owner, make it relative to parent */
129 MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
131 SetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
132 return TRUE;
135 /***********************************************************************
136 * ICONTITLE_Paint
138 static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
140 RECT rect;
141 HFONT hPrevFont;
142 HBRUSH hBrush = 0;
143 COLORREF textColor = 0;
145 if( bActive )
147 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
148 textColor = GetSysColor(COLOR_CAPTIONTEXT);
150 else
152 if( GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD )
154 hBrush = (HBRUSH) GetClassLongA(hwnd, GCL_HBRBACKGROUND);
155 if( hBrush )
157 INT level;
158 LOGBRUSH logBrush;
159 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
160 level = GetRValue(logBrush.lbColor) +
161 GetGValue(logBrush.lbColor) +
162 GetBValue(logBrush.lbColor);
163 if( level < (0x7F * 3) )
164 textColor = RGB( 0xFF, 0xFF, 0xFF );
166 else
167 hBrush = GetStockObject( WHITE_BRUSH );
169 else
171 hBrush = GetStockObject( BLACK_BRUSH );
172 textColor = RGB( 0xFF, 0xFF, 0xFF );
176 GetClientRect( hwnd, &rect );
177 DPtoLP( hDC, (LPPOINT)&rect, 2 );
178 FillRect( hDC, &rect, hBrush );
180 hPrevFont = SelectObject( hDC, hIconTitleFont );
181 if( hPrevFont )
183 WCHAR buffer[80];
185 INT length = GetWindowTextW( owner, buffer, sizeof(buffer) );
186 SetTextColor( hDC, textColor );
187 SetBkMode( hDC, TRANSPARENT );
189 DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
190 DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
192 SelectObject( hDC, hPrevFont );
194 return (hPrevFont != 0);
197 /***********************************************************************
198 * IconTitleWndProc
200 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
201 WPARAM wParam, LPARAM lParam )
203 HWND owner = GetWindow( hWnd, GW_OWNER );
205 if (!IsWindow(hWnd)) return 0;
207 switch( msg )
209 case WM_CREATE:
210 if (!hIconTitleFont)
212 LOGFONTA logFont;
213 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
214 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
215 hIconTitleFont = CreateFontIndirectA( &logFont );
217 return (hIconTitleFont ? 0 : -1);
218 case WM_NCHITTEST:
219 return HTCAPTION;
220 case WM_NCMOUSEMOVE:
221 case WM_NCLBUTTONDBLCLK:
222 return SendMessageW( owner, msg, wParam, lParam );
223 case WM_ACTIVATE:
224 if( wParam ) SetActiveWindow( owner );
225 return 0;
226 case WM_CLOSE:
227 return 0;
228 case WM_SHOWWINDOW:
229 if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
230 return 0;
231 case WM_ERASEBKGND:
232 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
233 lParam = SendMessageA( owner, WM_ISACTIVEICON, 0, 0 );
234 else
235 lParam = (owner == GetActiveWindow());
236 if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
237 ValidateRect( hWnd, NULL );
238 return 1;
240 return DefWindowProcW( hWnd, msg, wParam, lParam );