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
32 static BOOL bMultiLineTitle
;
33 static HFONT hIconTitleFont
;
35 /*********************************************************************
36 * icon title class descriptor
38 const struct builtin_class_descr ICONTITLE_builtin_class
=
40 (LPCWSTR
)ICONTITLE_CLASS_ATOM
, /* name */
42 WINPROC_ICONTITLE
, /* proc */
44 IDC_ARROW
, /* cursor */
48 /***********************************************************************
49 * ICONTITLE_SetTitlePos
51 static BOOL
ICONTITLE_SetTitlePos( HWND hwnd
, HWND owner
)
60 int length
= GetWindowTextW( owner
, str
, ARRAY_SIZE( str
));
62 while (length
&& str
[length
- 1] == ' ') /* remove trailing spaces */
67 lstrcpyW( str
, L
"<...>" );
68 length
= lstrlenW( str
);
71 if (!(hDC
= GetDC( hwnd
))) return FALSE
;
73 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
75 SetRect( &rect
, 0, 0, GetSystemMetrics(SM_CXICONSPACING
) -
76 GetSystemMetrics(SM_CXBORDER
) * 2,
77 GetSystemMetrics(SM_CYBORDER
) * 2 );
79 DrawTextW( hDC
, str
, length
, &rect
, DT_CALCRECT
| DT_CENTER
| DT_NOPREFIX
| DT_WORDBREAK
|
80 (( bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
82 SelectObject( hDC
, hPrevFont
);
83 ReleaseDC( hwnd
, hDC
);
85 cx
= rect
.right
- rect
.left
+ 4 * GetSystemMetrics(SM_CXBORDER
);
86 cy
= rect
.bottom
- rect
.top
;
88 pt
.x
= (GetSystemMetrics(SM_CXICON
) - cx
) / 2;
89 pt
.y
= GetSystemMetrics(SM_CYICON
);
91 /* point is relative to owner, make it relative to parent */
92 MapWindowPoints( owner
, GetParent(hwnd
), &pt
, 1 );
94 SetWindowPos( hwnd
, owner
, pt
.x
, pt
.y
, cx
, cy
, SWP_NOACTIVATE
);
98 /***********************************************************************
101 static BOOL
ICONTITLE_Paint( HWND hwnd
, HWND owner
, HDC hDC
, BOOL bActive
)
106 COLORREF textColor
= 0;
110 hBrush
= GetSysColorBrush(COLOR_ACTIVECAPTION
);
111 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
115 if( GetWindowLongA( hwnd
, GWL_STYLE
) & WS_CHILD
)
117 hBrush
= (HBRUSH
) GetClassLongPtrW(hwnd
, GCLP_HBRBACKGROUND
);
122 GetObjectA( hBrush
, sizeof(logBrush
), &logBrush
);
123 level
= GetRValue(logBrush
.lbColor
) +
124 GetGValue(logBrush
.lbColor
) +
125 GetBValue(logBrush
.lbColor
);
126 if( level
< (0x7F * 3) )
127 textColor
= RGB( 0xFF, 0xFF, 0xFF );
130 hBrush
= GetStockObject( WHITE_BRUSH
);
134 hBrush
= GetStockObject( BLACK_BRUSH
);
135 textColor
= RGB( 0xFF, 0xFF, 0xFF );
139 GetClientRect( hwnd
, &rect
);
140 DPtoLP( hDC
, (LPPOINT
)&rect
, 2 );
141 FillRect( hDC
, &rect
, hBrush
);
143 hPrevFont
= SelectObject( hDC
, hIconTitleFont
);
148 INT length
= GetWindowTextW( owner
, buffer
, ARRAY_SIZE( buffer
));
149 SetTextColor( hDC
, textColor
);
150 SetBkMode( hDC
, TRANSPARENT
);
152 DrawTextW( hDC
, buffer
, length
, &rect
, DT_CENTER
| DT_NOPREFIX
|
153 DT_WORDBREAK
| ((bMultiLineTitle
) ? 0 : DT_SINGLELINE
) );
155 SelectObject( hDC
, hPrevFont
);
157 return (hPrevFont
!= 0);
160 /***********************************************************************
163 LRESULT WINAPI
IconTitleWndProc( HWND hWnd
, UINT msg
,
164 WPARAM wParam
, LPARAM lParam
)
166 HWND owner
= GetWindow( hWnd
, GW_OWNER
);
168 if (!IsWindow(hWnd
)) return 0;
176 SystemParametersInfoA( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
177 SystemParametersInfoA( SPI_GETICONTITLEWRAP
, 0, &bMultiLineTitle
, 0 );
178 hIconTitleFont
= CreateFontIndirectA( &logFont
);
180 return (hIconTitleFont
? 0 : -1);
184 case WM_NCLBUTTONDBLCLK
:
185 return SendMessageW( owner
, msg
, wParam
, lParam
);
187 if( wParam
) SetActiveWindow( owner
);
192 if (wParam
) ICONTITLE_SetTitlePos( hWnd
, owner
);
195 if( GetWindowLongW( owner
, GWL_STYLE
) & WS_CHILD
)
196 lParam
= SendMessageW( owner
, WM_ISACTIVEICON
, 0, 0 );
198 lParam
= (owner
== GetActiveWindow());
199 if( ICONTITLE_Paint( hWnd
, owner
, (HDC
)wParam
, (BOOL
)lParam
) )
200 ValidateRect( hWnd
, NULL
);
203 return DefWindowProcW( hWnd
, msg
, wParam
, lParam
);