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
34 #include "wine/unicode.h"
38 static BOOL bMultiLineTitle
;
39 static HFONT hIconTitleFont
;
41 /*********************************************************************
42 * icon title class descriptor
44 const struct builtin_class_descr ICONTITLE_builtin_class
=
46 (LPCWSTR
)ICONTITLE_CLASS_ATOM
, /* name */
48 WINPROC_ICONTITLE
, /* proc */
50 IDC_ARROW
, /* cursor */
56 /***********************************************************************
59 HWND
ICONTITLE_Create( HWND owner
)
62 HINSTANCE instance
= (HINSTANCE
)GetWindowLongPtrA( owner
, GWLP_HINSTANCE
);
63 LONG style
= WS_CLIPSIBLINGS
;
65 if (!IsWindowEnabled(owner
)) style
|= WS_DISABLED
;
66 if( GetWindowLongA( owner
, GWL_STYLE
) & WS_CHILD
)
67 hWnd
= CreateWindowExA( 0, (LPCSTR
)ICONTITLE_CLASS_ATOM
, NULL
,
68 style
| WS_CHILD
, 0, 0, 1, 1,
69 GetParent(owner
), 0, instance
, NULL
);
71 hWnd
= CreateWindowExA( 0, (LPCSTR
)ICONTITLE_CLASS_ATOM
, NULL
,
73 owner
, 0, instance
, NULL
);
74 WIN_SetOwner( hWnd
, owner
); /* MDI depends on this */
75 SetWindowLongW( hWnd
, GWL_STYLE
,
76 GetWindowLongW( hWnd
, GWL_STYLE
) & ~(WS_CAPTION
| WS_BORDER
) );
80 /***********************************************************************
81 * ICONTITLE_SetTitlePos
83 static BOOL
ICONTITLE_SetTitlePos( HWND hwnd
, HWND owner
)
85 static const WCHAR emptyTitleText
[] = {'<','.','.','.','>',0};
93 int length
= GetWindowTextW( owner
, str
, sizeof(str
)/sizeof(WCHAR
) );
95 while (length
&& str
[length
- 1] == ' ') /* remove trailing spaces */
100 strcpyW( str
, emptyTitleText
);
101 length
= strlenW( str
);
104 if (!(hDC
= GetDC( hwnd
))) return FALSE
;
106 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
108 SetRect( &rect
, 0, 0, GetSystemMetrics(SM_CXICONSPACING
) -
109 GetSystemMetrics(SM_CXBORDER
) * 2,
110 GetSystemMetrics(SM_CYBORDER
) * 2 );
112 DrawTextW( hDC
, str
, length
, &rect
, DT_CALCRECT
| DT_CENTER
| DT_NOPREFIX
| DT_WORDBREAK
|
113 (( bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
115 SelectObject( hDC
, hPrevFont
);
116 ReleaseDC( hwnd
, hDC
);
118 cx
= rect
.right
- rect
.left
+ 4 * GetSystemMetrics(SM_CXBORDER
);
119 cy
= rect
.bottom
- rect
.top
;
121 pt
.x
= (GetSystemMetrics(SM_CXICON
) - cx
) / 2;
122 pt
.y
= GetSystemMetrics(SM_CYICON
);
124 /* point is relative to owner, make it relative to parent */
125 MapWindowPoints( owner
, GetParent(hwnd
), &pt
, 1 );
127 SetWindowPos( hwnd
, owner
, pt
.x
, pt
.y
, cx
, cy
, SWP_NOACTIVATE
);
131 /***********************************************************************
134 static BOOL
ICONTITLE_Paint( HWND hwnd
, HWND owner
, HDC hDC
, BOOL bActive
)
139 COLORREF textColor
= 0;
143 hBrush
= GetSysColorBrush(COLOR_ACTIVECAPTION
);
144 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
148 if( GetWindowLongA( hwnd
, GWL_STYLE
) & WS_CHILD
)
150 hBrush
= (HBRUSH
) GetClassLongPtrW(hwnd
, GCLP_HBRBACKGROUND
);
155 GetObjectA( hBrush
, sizeof(logBrush
), &logBrush
);
156 level
= GetRValue(logBrush
.lbColor
) +
157 GetGValue(logBrush
.lbColor
) +
158 GetBValue(logBrush
.lbColor
);
159 if( level
< (0x7F * 3) )
160 textColor
= RGB( 0xFF, 0xFF, 0xFF );
163 hBrush
= GetStockObject( WHITE_BRUSH
);
167 hBrush
= GetStockObject( BLACK_BRUSH
);
168 textColor
= RGB( 0xFF, 0xFF, 0xFF );
172 GetClientRect( hwnd
, &rect
);
173 DPtoLP( hDC
, (LPPOINT
)&rect
, 2 );
174 FillRect( hDC
, &rect
, hBrush
);
176 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
181 INT length
= GetWindowTextW( owner
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]) );
182 SetTextColor( hDC
, textColor
);
183 SetBkMode( hDC
, TRANSPARENT
);
185 DrawTextW( hDC
, buffer
, length
, &rect
, DT_CENTER
| DT_NOPREFIX
|
186 DT_WORDBREAK
| ((bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
188 SelectObject( hDC
, hPrevFont
);
190 return (hPrevFont
!= 0);
193 /***********************************************************************
196 LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
,
197 WPARAM wParam
, LPARAM lParam
)
199 HWND owner
= GetWindow( hWnd
, GW_OWNER
);
201 if (!IsWindow(hWnd
)) return 0;
209 SystemParametersInfoA( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
210 SystemParametersInfoA( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
211 hIconTitleFont
= CreateFontIndirectA( &logFont
);
213 return (hIconTitleFont
? 0 : -1);
217 case WM_NCLBUTTONDBLCLK
:
218 return SendMessageW( owner
, msg
, wParam
, lParam
);
220 if( wParam
) SetActiveWindow( owner
);
225 if (wParam
) ICONTITLE_SetTitlePos( hWnd
, owner
);
228 if( GetWindowLongW( owner
, GWL_STYLE
) & WS_CHILD
)
229 lParam
= SendMessageW( owner
, WM_ISACTIVEICON
, 0, 0 );
231 lParam
= (owner
== GetActiveWindow());
232 if( ICONTITLE_Paint( hWnd
, owner
, (HDC
)wParam
, (BOOL
)lParam
) )
233 ValidateRect( hWnd
, NULL
);
236 return DefWindowProcW( hWnd
, msg
, wParam
, lParam
);