blob: 8c0ca329956c57bbd393ea0afce89cfcf9f56a18 [file] [log] [blame]
Alexandre Julliard23946ad1997-06-16 17:43:53 +00001/*
2 * Icontitle window class.
3 *
4 * Copyright 1997 Alex Korobka
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00005 *
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.
10 *
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.
15 *
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
Alexandre Julliard23946ad1997-06-16 17:43:53 +000019 */
20
Patrik Stridvalld016f812002-08-17 00:43:16 +000021#include "config.h"
22
Alexandre Julliard23946ad1997-06-16 17:43:53 +000023#include <stdio.h>
24#include <string.h>
Patrik Stridvalld016f812002-08-17 00:43:16 +000025#ifdef HAVE_UNISTD_H
26# include <unistd.h>
27#endif
François Gouget44a18222000-12-19 04:53:20 +000028
Jeremy Whited3e22d92000-02-10 19:03:02 +000029#include "windef.h"
François Gouget44a18222000-12-19 04:53:20 +000030#include "winbase.h"
Jeremy Whited3e22d92000-02-10 19:03:02 +000031#include "wingdi.h"
Michael Vekslerca1bc861999-01-01 18:57:33 +000032#include "winuser.h"
33#include "wine/winuser16.h"
Alexandre Julliardc7e7df82000-08-14 14:41:19 +000034#include "wine/unicode.h"
Alexandre Julliard91222da2000-12-10 23:01:33 +000035#include "controls.h"
Alexandre Julliard23946ad1997-06-16 17:43:53 +000036#include "win.h"
Alexandre Julliard23946ad1997-06-16 17:43:53 +000037
Alexandre Julliard2682bc22000-11-27 22:03:23 +000038static BOOL bMultiLineTitle;
39static HFONT hIconTitleFont;
Alexandre Julliard23946ad1997-06-16 17:43:53 +000040
Alexandre Julliard91222da2000-12-10 23:01:33 +000041static LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
Alexandre Julliard23946ad1997-06-16 17:43:53 +000042
Alexandre Julliard91222da2000-12-10 23:01:33 +000043/*********************************************************************
44 * icon title class descriptor
45 */
46const struct builtin_class_descr ICONTITLE_builtin_class =
47{
48 ICONTITLE_CLASS_ATOM, /* name */
49 CS_GLOBALCLASS, /* style */
50 NULL, /* procA (winproc is Unicode only) */
51 IconTitleWndProc, /* procW */
52 0, /* extra */
53 IDC_ARROWA, /* cursor */
54 0 /* brush */
55};
56
57
Alexandre Julliard23946ad1997-06-16 17:43:53 +000058
59/***********************************************************************
60 * ICONTITLE_Create
61 */
Alexandre Julliardde424282001-08-10 22:51:42 +000062HWND ICONTITLE_Create( HWND owner )
Alexandre Julliard23946ad1997-06-16 17:43:53 +000063{
Alexandre Julliarda3960291999-02-26 11:11:13 +000064 HWND hWnd;
Alexandre Julliard7ef66af2002-11-22 04:47:10 +000065 HINSTANCE instance = (HINSTANCE)GetWindowLongA( owner, GWL_HINSTANCE );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000066 LONG style = WS_CLIPSIBLINGS;
Alexandre Julliard23946ad1997-06-16 17:43:53 +000067
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000068 if (!IsWindowEnabled(owner)) style |= WS_DISABLED;
Alexandre Julliardde424282001-08-10 22:51:42 +000069 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
Alexandre Julliarda3960291999-02-26 11:11:13 +000070 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000071 style | WS_CHILD, 0, 0, 1, 1,
72 GetParent(owner), 0, instance, NULL );
Alexandre Julliard23946ad1997-06-16 17:43:53 +000073 else
Alexandre Julliarda3960291999-02-26 11:11:13 +000074 hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000075 style, 0, 0, 1, 1,
76 owner, 0, instance, NULL );
Alexandre Julliardfb0ff052001-10-16 21:58:58 +000077 WIN_SetOwner( hWnd, owner ); /* MDI depends on this */
78 SetWindowLongW( hWnd, GWL_STYLE,
79 GetWindowLongW( hWnd, GWL_STYLE ) & ~(WS_CAPTION | WS_BORDER) );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000080 return hWnd;
Alexandre Julliard23946ad1997-06-16 17:43:53 +000081}
82
83/***********************************************************************
Alexandre Julliardde424282001-08-10 22:51:42 +000084 * ICONTITLE_SetTitlePos
Alexandre Julliard23946ad1997-06-16 17:43:53 +000085 */
Alexandre Julliardde424282001-08-10 22:51:42 +000086static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
Alexandre Julliard23946ad1997-06-16 17:43:53 +000087{
Dmitry Timoshkov04da8b82000-07-10 12:09:31 +000088 static WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
Alexandre Julliardde424282001-08-10 22:51:42 +000089 WCHAR str[80];
90 HDC hDC;
91 HFONT hPrevFont;
92 RECT rect;
93 INT cx, cy;
94 POINT pt;
Alexandre Julliard23946ad1997-06-16 17:43:53 +000095
Alexandre Julliardde424282001-08-10 22:51:42 +000096 int length = GetWindowTextW( owner, str, sizeof(str)/sizeof(WCHAR) );
97
98 while (length && str[length - 1] == ' ') /* remove trailing spaces */
99 str[--length] = 0;
100
101 if( !length )
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000102 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000103 strcpyW( str, emptyTitleText );
104 length = strlenW( str );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000105 }
106
Alexandre Julliardde424282001-08-10 22:51:42 +0000107 if (!(hDC = GetDC( hwnd ))) return FALSE;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000108
Alexandre Julliardde424282001-08-10 22:51:42 +0000109 hPrevFont = SelectObject( hDC, hIconTitleFont );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000110
Alexandre Julliardde424282001-08-10 22:51:42 +0000111 SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
112 GetSystemMetrics(SM_CXBORDER) * 2,
113 GetSystemMetrics(SM_CYBORDER) * 2 );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000114
Alexandre Julliardde424282001-08-10 22:51:42 +0000115 DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
116 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000117
Alexandre Julliardde424282001-08-10 22:51:42 +0000118 SelectObject( hDC, hPrevFont );
119 ReleaseDC( hwnd, hDC );
120
121 cx = rect.right - rect.left + 4 * GetSystemMetrics(SM_CXBORDER);
122 cy = rect.bottom - rect.top;
123
124 pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
125 pt.y = GetSystemMetrics(SM_CYICON);
126
127 /* point is relative to owner, make it relative to parent */
128 MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
129
130 SetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
131 return TRUE;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000132}
133
134/***********************************************************************
135 * ICONTITLE_Paint
136 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000137static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000138{
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000139 RECT rect;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000140 HFONT hPrevFont;
141 HBRUSH hBrush = 0;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000142 COLORREF textColor = 0;
143
144 if( bActive )
145 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000146 hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
147 textColor = GetSysColor(COLOR_CAPTIONTEXT);
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000148 }
Vincent Béron9a624912002-05-31 23:06:46 +0000149 else
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000150 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000151 if( GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD )
Vincent Béron9a624912002-05-31 23:06:46 +0000152 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000153 hBrush = (HBRUSH) GetClassLongA(hwnd, GCL_HBRBACKGROUND);
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000154 if( hBrush )
155 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000156 INT level;
157 LOGBRUSH logBrush;
158 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000159 level = GetRValue(logBrush.lbColor) +
160 GetGValue(logBrush.lbColor) +
161 GetBValue(logBrush.lbColor);
162 if( level < (0x7F * 3) )
163 textColor = RGB( 0xFF, 0xFF, 0xFF );
164 }
165 else
Alexandre Julliarda3960291999-02-26 11:11:13 +0000166 hBrush = GetStockObject( WHITE_BRUSH );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000167 }
168 else
169 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000170 hBrush = GetStockObject( BLACK_BRUSH );
Vincent Béron9a624912002-05-31 23:06:46 +0000171 textColor = RGB( 0xFF, 0xFF, 0xFF );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000172 }
173 }
174
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000175 GetClientRect( hwnd, &rect );
176 DPtoLP( hDC, (LPPOINT)&rect, 2 );
177 FillRect( hDC, &rect, hBrush );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000178
Alexandre Julliarda3960291999-02-26 11:11:13 +0000179 hPrevFont = SelectObject( hDC, hIconTitleFont );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000180 if( hPrevFont )
181 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000182 WCHAR buffer[80];
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000183
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000184 INT length = GetWindowTextW( owner, buffer, sizeof(buffer) );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000185 SetTextColor( hDC, textColor );
186 SetBkMode( hDC, TRANSPARENT );
Alexandre Julliardde424282001-08-10 22:51:42 +0000187
188 DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
189 DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000190
Alexandre Julliarda3960291999-02-26 11:11:13 +0000191 SelectObject( hDC, hPrevFont );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000192 }
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000193 return (hPrevFont != 0);
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000194}
195
196/***********************************************************************
197 * IconTitleWndProc
198 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000199LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
200 WPARAM wParam, LPARAM lParam )
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000201{
Alexandre Julliardde424282001-08-10 22:51:42 +0000202 HWND owner = GetWindow( hWnd, GW_OWNER );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000203
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000204 if (!IsWindow(hWnd)) return 0;
Jukka Heinonen186a79c2001-07-24 01:16:16 +0000205
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000206 switch( msg )
207 {
Alexandre Julliard91222da2000-12-10 23:01:33 +0000208 case WM_CREATE:
209 if (!hIconTitleFont)
210 {
211 LOGFONTA logFont;
212 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
213 SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
214 hIconTitleFont = CreateFontIndirectA( &logFont );
215 }
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000216 return (hIconTitleFont ? 0 : -1);
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000217 case WM_NCHITTEST:
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000218 return HTCAPTION;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000219 case WM_NCMOUSEMOVE:
220 case WM_NCLBUTTONDBLCLK:
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000221 return SendMessageW( owner, msg, wParam, lParam );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000222 case WM_ACTIVATE:
Alexandre Julliardde424282001-08-10 22:51:42 +0000223 if( wParam ) SetActiveWindow( owner );
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000224 return 0;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000225 case WM_CLOSE:
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000226 return 0;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000227 case WM_SHOWWINDOW:
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000228 if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
229 return 0;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000230 case WM_ERASEBKGND:
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000231 if( GetWindowLongA( owner, GWL_STYLE ) & WS_CHILD )
232 lParam = SendMessageA( owner, WM_ISACTIVEICON, 0, 0 );
233 else
234 lParam = (owner == GetActiveWindow());
235 if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
236 ValidateRect( hWnd, NULL );
237 return 1;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000238 }
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000239 return DefWindowProcW( hWnd, msg, wParam, lParam );
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000240}