- Do not modify pointers in the OPENFILENAME structure passed to
[wine/multimedia.git] / controls / icontitle.c
blobe24bb3f892f745abadb3d865c95056fde8802226
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 <stdio.h>
22 #include <string.h>
23 #include <unistd.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "wine/winuser16.h"
30 #include "wine/unicode.h"
31 #include "controls.h"
32 #include "win.h"
34 static BOOL bMultiLineTitle;
35 static HFONT hIconTitleFont;
37 static LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
39 /*********************************************************************
40 * icon title class descriptor
42 const struct builtin_class_descr ICONTITLE_builtin_class =
44 ICONTITLE_CLASS_ATOM, /* name */
45 CS_GLOBALCLASS, /* style */
46 NULL, /* procA (winproc is Unicode only) */
47 IconTitleWndProc, /* procW */
48 0, /* extra */
49 IDC_ARROWA, /* cursor */
50 0 /* brush */
55 /***********************************************************************
56 * ICONTITLE_Create
58 HWND ICONTITLE_Create( HWND owner )
60 HWND hWnd;
61 HINSTANCE instance = GetWindowLongA( owner, GWL_HINSTANCE );
62 LONG style = WS_CLIPSIBLINGS;
64 if (!IsWindowEnabled(owner)) style |= WS_DISABLED;
65 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
66 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
67 style | WS_CHILD, 0, 0, 1, 1,
68 GetParent(owner), 0, instance, NULL );
69 else
70 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
71 style, 0, 0, 1, 1,
72 owner, 0, instance, NULL );
73 WIN_SetOwner( hWnd, owner ); /* MDI depends on this */
74 SetWindowLongW( hWnd, GWL_STYLE,
75 GetWindowLongW( hWnd, GWL_STYLE ) & ~(WS_CAPTION | WS_BORDER) );
76 return hWnd;
79 /***********************************************************************
80 * ICONTITLE_SetTitlePos
82 static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
84 static WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
85 WCHAR str[80];
86 HDC hDC;
87 HFONT hPrevFont;
88 RECT rect;
89 INT cx, cy;
90 POINT pt;
92 int length = GetWindowTextW( owner, str, sizeof(str)/sizeof(WCHAR) );
94 while (length && str[length - 1] == ' ') /* remove trailing spaces */
95 str[--length] = 0;
97 if( !length )
99 strcpyW( str, emptyTitleText );
100 length = strlenW( str );
103 if (!(hDC = GetDC( hwnd ))) return FALSE;
105 hPrevFont = SelectObject( hDC, hIconTitleFont );
107 SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
108 GetSystemMetrics(SM_CXBORDER) * 2,
109 GetSystemMetrics(SM_CYBORDER) * 2 );
111 DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
112 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
114 SelectObject( hDC, hPrevFont );
115 ReleaseDC( hwnd, hDC );
117 cx = rect.right - rect.left + 4 * GetSystemMetrics(SM_CXBORDER);
118 cy = rect.bottom - rect.top;
120 pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
121 pt.y = GetSystemMetrics(SM_CYICON);
123 /* point is relative to owner, make it relative to parent */
124 MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
126 SetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
127 return TRUE;
130 /***********************************************************************
131 * ICONTITLE_Paint
133 static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
135 RECT rect;
136 HFONT hPrevFont;
137 HBRUSH hBrush = 0;
138 COLORREF textColor = 0;
140 if( bActive )
142 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
143 textColor = GetSysColor(COLOR_CAPTIONTEXT);
145 else
147 if( GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD )
149 hBrush = (HBRUSH) GetClassLongA(hwnd, GCL_HBRBACKGROUND);
150 if( hBrush )
152 INT level;
153 LOGBRUSH logBrush;
154 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
155 level = GetRValue(logBrush.lbColor) +
156 GetGValue(logBrush.lbColor) +
157 GetBValue(logBrush.lbColor);
158 if( level < (0x7F * 3) )
159 textColor = RGB( 0xFF, 0xFF, 0xFF );
161 else
162 hBrush = GetStockObject( WHITE_BRUSH );
164 else
166 hBrush = GetStockObject( BLACK_BRUSH );
167 textColor = RGB( 0xFF, 0xFF, 0xFF );
171 GetClientRect( hwnd, &rect );
172 DPtoLP( hDC, (LPPOINT)&rect, 2 );
173 FillRect( hDC, &rect, hBrush );
175 hPrevFont = SelectObject( hDC, hIconTitleFont );
176 if( hPrevFont )
178 WCHAR buffer[80];
180 INT length = GetWindowTextW( owner, buffer, sizeof(buffer) );
181 SetTextColor( hDC, textColor );
182 SetBkMode( hDC, TRANSPARENT );
184 DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
185 DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
187 SelectObject( hDC, hPrevFont );
189 return (hPrevFont != 0);
192 /***********************************************************************
193 * IconTitleWndProc
195 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
196 WPARAM wParam, LPARAM lParam )
198 HWND owner = GetWindow( hWnd, GW_OWNER );
200 if (!IsWindow(hWnd)) return 0;
202 switch( msg )
204 case WM_CREATE:
205 if (!hIconTitleFont)
207 LOGFONTA logFont;
208 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
209 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
210 hIconTitleFont = CreateFontIndirectA( &logFont );
212 return (hIconTitleFont ? 0 : -1);
213 case WM_NCHITTEST:
214 return HTCAPTION;
215 case WM_NCMOUSEMOVE:
216 case WM_NCLBUTTONDBLCLK:
217 return SendMessageW( owner, msg, wParam, lParam );
218 case WM_ACTIVATE:
219 if( wParam ) SetActiveWindow( owner );
220 return 0;
221 case WM_CLOSE:
222 return 0;
223 case WM_SHOWWINDOW:
224 if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
225 return 0;
226 case WM_ERASEBKGND:
227 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
228 lParam = SendMessageA( owner, WM_ISACTIVEICON, 0, 0 );
229 else
230 lParam = (owner == GetActiveWindow());
231 if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
232 ValidateRect( hWnd, NULL );
233 return 1;
235 return DefWindowProcW( hWnd, msg, wParam, lParam );