ReactOS 0.4.17-dev-1321-g5c122a9
icontitle.c
Go to the documentation of this file.
1/*
2 * Icontitle window class.
3 *
4 * Copyright 1997 Alex Korobka
5 *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <user32.h>
22
24static HFONT hIconTitleFont;
25
26#ifdef __REACTOS__
27/*********************************************************************
28 * icon title class descriptor
29 */
31{
32 WC_ICONTITLE, /* name */
33 0, /* style */
34 &pfnClientA.pfnTitleWndProc, /* procA (winproc is Unicode only) */
35 &pfnClientW.pfnTitleWndProc, /* procW */
36 0, /* extra */
37 IDC_ARROW, /* cursor */
38 0 /* brush */
39};
40#endif
41
42/***********************************************************************
43 * ICONTITLE_SetTitlePos
44 */
46{
47 WCHAR str[80];
48 HDC hDC;
49 HFONT hPrevFont;
50 RECT rect;
51 INT cx, cy;
52 POINT pt;
53
54 int length = GetWindowTextW( owner, str, ARRAY_SIZE( str ));
55
56 while (length && str[length - 1] == ' ') /* remove trailing spaces */
57 str[--length] = 0;
58
59 if( !length )
60 {
61 lstrcpyW( str, L"<...>" );
62 length = lstrlenW( str );
63 }
64
65 if (!(hDC = NtUserGetDC( hwnd ))) return FALSE;
66
67 hPrevFont = SelectObject( hDC, hIconTitleFont );
68
72
74 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
75
76 SelectObject( hDC, hPrevFont );
78
80 cy = rect.bottom - rect.top;
81
82 pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
84
85 /* point is relative to owner, make it relative to parent */
86 MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
87
88 NtUserSetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
89 return TRUE;
90}
91
92/***********************************************************************
93 * ICONTITLE_Paint
94 */
95static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
96{
97 RECT rect;
98 HFONT hPrevFont;
99 HBRUSH hBrush;
100 COLORREF textColor = 0;
101
102 if( bActive )
103 {
105 textColor = GetSysColor(COLOR_CAPTIONTEXT);
106 }
107 else
108 {
110 {
111 hBrush = (HBRUSH) GetClassLongPtrW(hwnd, GCLP_HBRBACKGROUND);
112 if( hBrush )
113 {
114 INT level;
115 LOGBRUSH logBrush;
116 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
117 level = GetRValue(logBrush.lbColor) +
118 GetGValue(logBrush.lbColor) +
119 GetBValue(logBrush.lbColor);
120 if( level < (0x7F * 3) )
121 textColor = RGB( 0xFF, 0xFF, 0xFF );
122 }
123 else
124 hBrush = GetStockObject( WHITE_BRUSH );
125 }
126 else
127 {
128 hBrush = GetStockObject( BLACK_BRUSH );
129 textColor = RGB( 0xFF, 0xFF, 0xFF );
130 }
131 }
132
134 DPtoLP( hDC, (LPPOINT)&rect, 2 );
135 FillRect( hDC, &rect, hBrush );
136
137 hPrevFont = SelectObject( hDC, hIconTitleFont );
138 if( hPrevFont )
139 {
140 WCHAR buffer[80];
141
143 SetTextColor( hDC, textColor );
145
148
149 SelectObject( hDC, hPrevFont );
150 }
151 return (hPrevFont != 0);
152}
153
154/***********************************************************************
155 * IconTitleWndProc_common
156 */
159{
160 HWND owner = GetWindow( hWnd, GW_OWNER );
161
162 if (!IsWindow(hWnd)) return 0;
163
164 switch( msg )
165 {
166 case WM_CREATE:
167 if (!hIconTitleFont)
168 {
169 LOGFONTA logFont;
173 }
174 return (hIconTitleFont ? 0 : -1);
175 case WM_NCHITTEST:
176 return HTCAPTION;
177 case WM_NCMOUSEMOVE:
179 return SendMessageW( owner, msg, wParam, lParam );
180 case WM_ACTIVATE:
181 if (wParam) NtUserSetActiveWindow( owner );
182 return 0;
183 case WM_CLOSE:
184 return 0;
185 case WM_SHOWWINDOW:
186 if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
187 return 0;
188 case WM_ERASEBKGND:
189 if( GetWindowLongPtrW( owner, GWL_STYLE ) & WS_CHILD )
190 lParam = SendMessageW( owner, WM_ISACTIVEICON, 0, 0 );
191 else
192 lParam = (owner == GetActiveWindow());
193 if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
195 return 1;
196 }
197 return 0;
198}
199
200/***********************************************************************
201 * IconTitleWndProcA
202 */
205{
206 switch (msg)
207 {
208 case WM_CREATE:
209 case WM_NCHITTEST:
210 case WM_NCMOUSEMOVE:
212 case WM_ACTIVATE:
213 case WM_CLOSE:
214 case WM_SHOWWINDOW:
215 case WM_ERASEBKGND:
217 }
218 return DefWindowProcA( hWnd, msg, wParam, lParam );
219}
220
221/***********************************************************************
222 * IconTitleWndProcW
223 */
226{
227 switch (msg)
228 {
229 case WM_CREATE:
230 case WM_NCHITTEST:
231 case WM_NCMOUSEMOVE:
233 case WM_ACTIVATE:
234 case WM_CLOSE:
235 case WM_SHOWWINDOW:
236 case WM_ERASEBKGND:
238 }
239 return DefWindowProcW( hWnd, msg, wParam, lParam );
240}
static HDC hDC
Definition: 3dtext.c:33
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
#define ARRAY_SIZE(A)
Definition: main.h:20
RECT rect
Definition: combotst.c:67
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define lstrcpyW
Definition: compat.h:749
#define lstrlenW
Definition: compat.h:750
#define pt(x, y)
Definition: drawing.c:79
#define RGB(r, g, b)
Definition: precomp.h:88
#define GetBValue(quad)
Definition: precomp.h:92
#define GetGValue(quad)
Definition: precomp.h:91
#define GetRValue(quad)
Definition: precomp.h:90
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
GLint level
Definition: gl.h:1546
GLuint buffer
Definition: glext.h:5915
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
unsigned int UINT
Definition: sysinfo.c:13
static BOOL ICONTITLE_SetTitlePos(HWND hwnd, HWND owner)
Definition: icontitle.c:45
static BOOL bMultiLineTitle
Definition: icontitle.c:23
static HFONT hIconTitleFont
Definition: icontitle.c:24
static LRESULT WINAPI IconTitleWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: icontitle.c:157
LRESULT WINAPI IconTitleWndProcW(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: icontitle.c:224
LRESULT WINAPI IconTitleWndProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: icontitle.c:203
static BOOL ICONTITLE_Paint(HWND hwnd, HWND owner, HDC hDC, BOOL bActive)
Definition: icontitle.c:95
BOOL NTAPI NtUserSetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
Definition: winpos.c:3573
BOOL NTAPI NtUserValidateRect(HWND hWnd, CONST RECT *lpRect)
HWND NTAPI NtUserSetActiveWindow(HWND Wnd)
Definition: focus.c:1658
HDC NTAPI NtUserGetDC(HWND hWnd)
Definition: windc.c:1014
LONG_PTR LPARAM
Definition: minwindef.h:175
LONG_PTR LRESULT
Definition: minwindef.h:176
UINT_PTR WPARAM
Definition: minwindef.h:174
static HDC
Definition: imagelist.c:88
INT WINAPI DrawTextW(HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags)
Definition: defwnd.c:16
#define WS_CHILD
Definition: pedump.c:617
short WCHAR
Definition: pedump.c:58
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
#define GW_OWNER
Definition: winuser.h:777
#define WM_ERASEBKGND
Definition: winuser.h:1653
DWORD WINAPI GetSysColor(_In_ int)
BOOL WINAPI IsWindow(_In_opt_ HWND)
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
#define WM_CLOSE
Definition: winuser.h:1649
#define SWP_NOACTIVATE
Definition: winuser.h:1253
#define DT_NOPREFIX
Definition: winuser.h:537
#define GetWindowLongPtrW
Definition: winuser.h:4983
#define DT_CENTER
Definition: winuser.h:527
#define HTCAPTION
Definition: winuser.h:2512
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_CREATE
Definition: winuser.h:1636
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define DT_SINGLELINE
Definition: winuser.h:540
#define COLOR_ACTIVECAPTION
Definition: winuser.h:926
#define IDC_ARROW
Definition: winuser.h:695
#define WM_NCHITTEST
Definition: winuser.h:1714
#define GetWindowLongPtrA
Definition: winuser.h:4982
#define SPI_GETICONTITLELOGFONT
Definition: winuser.h:1391
int WINAPI MapWindowPoints(_In_opt_ HWND hWndFrom, _In_opt_ HWND hWndTo, _Inout_updates_(cPoints) LPPOINT lpPoints, _In_ UINT cPoints)
#define WM_NCLBUTTONDBLCLK
Definition: winuser.h:1722
#define WM_ACTIVATE
Definition: winuser.h:1640
#define WM_SHOWWINDOW
Definition: winuser.h:1656
#define WM_NCMOUSEMOVE
Definition: winuser.h:1719
#define SM_CYBORDER
Definition: winuser.h:976
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define SM_CYICON
Definition: winuser.h:984
#define SM_CXBORDER
Definition: winuser.h:975
#define DT_WORDBREAK
Definition: winuser.h:544
#define SPI_GETICONTITLEWRAP
Definition: winuser.h:1385
HWND WINAPI GetParent(_In_ HWND)
#define GetClassLongPtrW
Definition: winuser.h:4718
HWND WINAPI GetWindow(_In_ HWND, _In_ UINT)
BOOL WINAPI SystemParametersInfoA(_In_ UINT uiAction, _In_ UINT uiParam, _Inout_opt_ PVOID pvParam, _In_ UINT fWinIni)
#define DT_CALCRECT
Definition: winuser.h:526
#define GWL_STYLE
Definition: winuser.h:863
#define COLOR_CAPTIONTEXT
Definition: winuser.h:933
#define SM_CXICON
Definition: winuser.h:983
#define GCLP_HBRBACKGROUND
Definition: winuser.h:680
int WINAPI GetSystemMetrics(_In_ int)
#define SM_CXICONSPACING
Definition: winuser.h:1012
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
PFNCLIENT pfnClientA
Definition: regcontrol.c:15
PFNCLIENT pfnClientW
Definition: regcontrol.c:16
const struct builtin_class_descr ICONTITLE_builtin_class
const WCHAR * str
Definition: dcommon.idl:28
long bottom
Definition: dcommon.idl:29
long right
Definition: dcommon.idl:29
long left
Definition: dcommon.idl:29
long top
Definition: dcommon.idl:29
WNDPROC pfnTitleWndProc
Definition: ntuser.h:801
COLORREF lbColor
Definition: wingdi.h:2194
int32_t INT
Definition: typedefs.h:58
#define WM_ISACTIVEICON
Definition: undocuser.h:35
#define WC_ICONTITLE
Definition: undocuser.h:15
#define NtUserReleaseDC(HWND, HDC)
Definition: user_x.h:120
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1382
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
DWORD COLORREF
Definition: windef.h:100
#define WINAPI
Definition: msvc.h:6
HGDIOBJ WINAPI GetStockObject(_In_ int)
HFONT WINAPI CreateFontIndirectA(_In_ const LOGFONTA *)
int WINAPI GetObjectA(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
BOOL WINAPI DPtoLP(_In_ HDC hdc, _Inout_updates_(c) LPPOINT lppt, _In_ int c)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
#define TRANSPARENT
Definition: wingdi.h:950
#define WHITE_BRUSH
Definition: wingdi.h:902
#define BLACK_BRUSH
Definition: wingdi.h:896
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:917