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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <wine/debug.h>
26 #define MAKEINTATOMW(atom) ((LPCWSTR)((ULONG_PTR)((WORD)(atom))))
27 #define ICONTITLE_CLASS_ATOM MAKEINTATOMW(32772)
30 static BOOL bMultiLineTitle
;
31 static HFONT hIconTitleFont
;
33 //static LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
35 /*********************************************************************
36 * icon title class descriptor
38 const struct builtin_class_descr ICONTITLE_builtin_class
=
40 (LPCWSTR
)ICONTITLE_CLASS_ATOM
, /* name */
42 NULL
, /* procA (winproc is Unicode only) */
43 IconTitleWndProc
, /* procW */
45 IDC_ARROW
, /* cursor */
52 /***********************************************************************
55 HWND
ICONTITLE_Create( HWND owner
)
58 HINSTANCE instance
= (HINSTANCE
)GetWindowLongPtrA( owner
, GWLP_HINSTANCE
);
59 LONG style
= WS_CLIPSIBLINGS
;
61 if (!IsWindowEnabled(owner
)) style
|= WS_DISABLED
;
62 if( GetWindowLongPtrA( owner
, GWL_STYLE
) & WS_CHILD
)
63 hWnd
= CreateWindowExA( 0, (LPCSTR
)ICONTITLE_CLASS_ATOM
, NULL
,
64 style
| WS_CHILD
, 0, 0, 1, 1,
65 GetParent(owner
), 0, instance
, NULL
);
67 hWnd
= CreateWindowExA( 0, (LPCSTR
)ICONTITLE_CLASS_ATOM
, NULL
,
69 owner
, 0, instance
, NULL
);
70 WIN_SetOwner( hWnd
, owner
); /* MDI depends on this */
71 SetWindowLongPtrW( hWnd
, GWL_STYLE
,
72 GetWindowLongPtrW( hWnd
, GWL_STYLE
) & ~(WS_CAPTION
| WS_BORDER
) );
77 /***********************************************************************
78 * ICONTITLE_SetTitlePos
80 static BOOL
ICONTITLE_SetTitlePos( HWND hwnd
, HWND owner
)
82 static const WCHAR emptyTitleText
[] = {'<','.','.','.','>',0};
90 int length
= GetWindowTextW( owner
, str
, sizeof(str
)/sizeof(WCHAR
) );
92 while (length
&& str
[length
- 1] == ' ') /* remove trailing spaces */
97 strcpyW( str
, emptyTitleText
);
98 length
= strlenW( str
);
101 if (!(hDC
= GetDC( hwnd
))) return FALSE
;
103 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
105 SetRect( &rect
, 0, 0, GetSystemMetrics(SM_CXICONSPACING
) -
106 GetSystemMetrics(SM_CXBORDER
) * 2,
107 GetSystemMetrics(SM_CYBORDER
) * 2 );
109 DrawTextW( hDC
, str
, length
, &rect
, DT_CALCRECT
| DT_CENTER
| DT_NOPREFIX
| DT_WORDBREAK
|
110 (( bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
112 SelectObject( hDC
, hPrevFont
);
113 ReleaseDC( hwnd
, hDC
);
115 cx
= rect
.right
- rect
.left
+ 4 * GetSystemMetrics(SM_CXBORDER
);
116 cy
= rect
.bottom
- rect
.top
;
118 pt
.x
= (GetSystemMetrics(SM_CXICON
) - cx
) / 2;
119 pt
.y
= GetSystemMetrics(SM_CYICON
);
121 /* point is relative to owner, make it relative to parent */
122 MapWindowPoints( owner
, GetParent(hwnd
), &pt
, 1 );
124 SetWindowPos( hwnd
, owner
, pt
.x
, pt
.y
, cx
, cy
, SWP_NOACTIVATE
);
128 /***********************************************************************
131 static BOOL
ICONTITLE_Paint( HWND hwnd
, HWND owner
, HDC hDC
, BOOL bActive
)
136 COLORREF textColor
= 0;
140 hBrush
= GetSysColorBrush(COLOR_ACTIVECAPTION
);
141 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
145 if( GetWindowLongPtrA( hwnd
, GWL_STYLE
) & WS_CHILD
)
147 hBrush
= (HBRUSH
) GetClassLongPtrW(hwnd
, GCLP_HBRBACKGROUND
);
152 GetObjectA( hBrush
, sizeof(logBrush
), &logBrush
);
153 level
= GetRValue(logBrush
.lbColor
) +
154 GetGValue(logBrush
.lbColor
) +
155 GetBValue(logBrush
.lbColor
);
156 if( level
< (0x7F * 3) )
157 textColor
= RGB( 0xFF, 0xFF, 0xFF );
160 hBrush
= GetStockObject( WHITE_BRUSH
);
164 hBrush
= GetStockObject( BLACK_BRUSH
);
165 textColor
= RGB( 0xFF, 0xFF, 0xFF );
169 GetClientRect( hwnd
, &rect
);
170 DPtoLP( hDC
, (LPPOINT
)&rect
, 2 );
171 FillRect( hDC
, &rect
, hBrush
);
173 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
178 INT length
= GetWindowTextW( owner
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]) );
179 SetTextColor( hDC
, textColor
);
180 SetBkMode( hDC
, TRANSPARENT
);
182 DrawTextW( hDC
, buffer
, length
, &rect
, DT_CENTER
| DT_NOPREFIX
|
183 DT_WORDBREAK
| ((bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
185 SelectObject( hDC
, hPrevFont
);
187 return (hPrevFont
!= 0);
190 /***********************************************************************
193 LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
,
194 WPARAM wParam
, LPARAM lParam
)
196 HWND owner
= GetWindow( hWnd
, GW_OWNER
);
198 if (!IsWindow(hWnd
)) return 0;
206 SystemParametersInfoA( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
207 SystemParametersInfoA( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
208 hIconTitleFont
= CreateFontIndirectA( &logFont
);
210 return (hIconTitleFont
? 0 : -1);
214 case WM_NCLBUTTONDBLCLK
:
215 return SendMessageW( owner
, msg
, wParam
, lParam
);
217 if( wParam
) SetActiveWindow( owner
);
222 if (wParam
) ICONTITLE_SetTitlePos( hWnd
, owner
);
225 if( GetWindowLongPtrW( owner
, GWL_STYLE
) & WS_CHILD
)
226 lParam
= SendMessageW( owner
, WM_ISACTIVEICON
, 0, 0 );
228 lParam
= (owner
== GetActiveWindow());
229 if( ICONTITLE_Paint( hWnd
, owner
, (HDC
)wParam
, (BOOL
)lParam
) )
230 ValidateRect( hWnd
, NULL
);
233 return DefWindowProcW( hWnd
, msg
, wParam
, lParam
);