ReactOS 0.4.15-dev-8145-ga541a46
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
25
26/*********************************************************************
27 * icon title class descriptor
28 */
30{
31 WC_ICONTITLE, /* name */
32 0, /* style */
33 NULL, /* procA (winproc is Unicode only) */
34 IconTitleWndProc, /* procW */
35 0, /* extra */
36 IDC_ARROW, /* cursor */
37 0 /* brush */
38};
39
40
41
42#ifndef __REACTOS__
43/***********************************************************************
44 * ICONTITLE_Create
45 */
47{
48 HWND hWnd;
51
52 if (!IsWindowEnabled(owner)) style |= WS_DISABLED;
53 if( GetWindowLongPtrA( owner, GWL_STYLE ) & WS_CHILD )
54 hWnd = CreateWindowExA( 0, (LPCSTR)ICONTITLE_CLASS_ATOM, NULL,
55 style | WS_CHILD, 0, 0, 1, 1,
56 GetParent(owner), 0, instance, NULL );
57 else
58 hWnd = CreateWindowExA( 0, (LPCSTR)ICONTITLE_CLASS_ATOM, NULL,
59 style, 0, 0, 1, 1,
60 owner, 0, instance, NULL );
61 WIN_SetOwner( hWnd, owner ); /* MDI depends on this */
64 return hWnd;
65}
66#endif
67
68/***********************************************************************
69 * ICONTITLE_SetTitlePos
70 */
72{
73 static const WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
74 WCHAR str[80];
75 HDC hDC;
76 HFONT hPrevFont;
77 RECT rect;
78 INT cx, cy;
79 POINT pt;
80
81 int length = GetWindowTextW( owner, str, sizeof(str)/sizeof(WCHAR) );
82
83 while (length && str[length - 1] == ' ') /* remove trailing spaces */
84 str[--length] = 0;
85
86 if( !length )
87 {
88 strcpyW( str, emptyTitleText );
89 length = strlenW( str );
90 }
91
92 if (!(hDC = GetDC( hwnd ))) return FALSE;
93
94 hPrevFont = SelectObject( hDC, hIconTitleFont );
95
99
101 (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
102
103 SelectObject( hDC, hPrevFont );
104 ReleaseDC( hwnd, hDC );
105
106 cx = rect.right - rect.left + 4 * GetSystemMetrics(SM_CXBORDER);
107 cy = rect.bottom - rect.top;
108
109 pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
111
112 /* point is relative to owner, make it relative to parent */
113 MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );
114
115 SetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
116 return TRUE;
117}
118
119/***********************************************************************
120 * ICONTITLE_Paint
121 */
122static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
123{
124 RECT rect;
125 HFONT hPrevFont;
126 HBRUSH hBrush;
127 COLORREF textColor = 0;
128
129 if( bActive )
130 {
132 textColor = GetSysColor(COLOR_CAPTIONTEXT);
133 }
134 else
135 {
137 {
138 hBrush = (HBRUSH) GetClassLongPtrW(hwnd, GCLP_HBRBACKGROUND);
139 if( hBrush )
140 {
141 INT level;
142 LOGBRUSH logBrush;
143 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
144 level = GetRValue(logBrush.lbColor) +
145 GetGValue(logBrush.lbColor) +
146 GetBValue(logBrush.lbColor);
147 if( level < (0x7F * 3) )
148 textColor = RGB( 0xFF, 0xFF, 0xFF );
149 }
150 else
151 hBrush = GetStockObject( WHITE_BRUSH );
152 }
153 else
154 {
155 hBrush = GetStockObject( BLACK_BRUSH );
156 textColor = RGB( 0xFF, 0xFF, 0xFF );
157 }
158 }
159
161 DPtoLP( hDC, (LPPOINT)&rect, 2 );
162 FillRect( hDC, &rect, hBrush );
163
164 hPrevFont = SelectObject( hDC, hIconTitleFont );
165 if( hPrevFont )
166 {
167 WCHAR buffer[80];
168
169 INT length = GetWindowTextW( owner, buffer, sizeof(buffer)/sizeof(buffer[0]) );
170 SetTextColor( hDC, textColor );
172
175
176 SelectObject( hDC, hPrevFont );
177 }
178 return (hPrevFont != 0);
179}
180
181/***********************************************************************
182 * IconTitleWndProc
183 */
186{
187 HWND owner = GetWindow( hWnd, GW_OWNER );
188
189 if (!IsWindow(hWnd)) return 0;
190
191 switch( msg )
192 {
193 case WM_CREATE:
194 if (!hIconTitleFont)
195 {
196 LOGFONTA logFont;
200 }
201 return (hIconTitleFont ? 0 : -1);
202 case WM_NCHITTEST:
203 return HTCAPTION;
204 case WM_NCMOUSEMOVE:
206 return SendMessageW( owner, msg, wParam, lParam );
207 case WM_ACTIVATE:
208 if( wParam ) SetActiveWindow( owner );
209 return 0;
210 case WM_CLOSE:
211 return 0;
212 case WM_SHOWWINDOW:
213 if (wParam) ICONTITLE_SetTitlePos( hWnd, owner );
214 return 0;
215 case WM_ERASEBKGND:
216 if( GetWindowLongPtrW( owner, GWL_STYLE ) & WS_CHILD )
217 lParam = SendMessageW( owner, WM_ISACTIVEICON, 0, 0 );
218 else
219 lParam = (owner == GetActiveWindow());
220 if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) )
222 return 1;
223 }
224 return DefWindowProcW( hWnd, msg, wParam, lParam );
225}
static HDC hDC
Definition: 3dtext.c:33
Arabic default style
Definition: afstyles.h:94
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
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
static HINSTANCE instance
Definition: main.c:40
#define pt(x, y)
Definition: drawing.c:79
#define RGB(r, g, b)
Definition: precomp.h:71
#define GetBValue(quad)
Definition: precomp.h:75
#define GetGValue(quad)
Definition: precomp.h:74
#define GetRValue(quad)
Definition: precomp.h:73
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
static BOOL ICONTITLE_SetTitlePos(HWND hwnd, HWND owner)
Definition: icontitle.c:71
LRESULT WINAPI IconTitleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: icontitle.c:184
static BOOL bMultiLineTitle
Definition: icontitle.c:23
static HFONT hIconTitleFont
Definition: icontitle.c:24
HWND ICONTITLE_Create(HWND owner)
Definition: icontitle.c:46
const struct builtin_class_descr ICONTITLE_builtin_class
Definition: icontitle.c:29
static BOOL ICONTITLE_Paint(HWND hwnd, HWND owner, HDC hDC, BOOL bActive)
Definition: icontitle.c:122
static HDC
Definition: imagelist.c:92
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
unsigned int UINT
Definition: ndis.h:50
INT WINAPI DrawTextW(HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags)
Definition: defwnd.c:16
#define WS_CHILD
Definition: pedump.c:617
#define WS_CAPTION
Definition: pedump.c:624
#define WS_BORDER
Definition: pedump.c:625
long LONG
Definition: pedump.c:60
#define WS_DISABLED
Definition: pedump.c:621
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
#define strlenW(s)
Definition: unicode.h:34
#define strcpyW(d, s)
Definition: unicode.h:35
const WCHAR * str
& rect
Definition: startmenu.cpp:1413
COLORREF lbColor
Definition: wingdi.h:1748
HANDLE HINSTANCE
Definition: typedefs.h:77
int32_t INT
Definition: typedefs.h:58
#define WM_ISACTIVEICON
Definition: undocuser.h:33
#define WC_ICONTITLE
Definition: undocuser.h:13
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1412
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
DWORD COLORREF
Definition: windef.h:300
#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:1539
#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:918
#define GW_OWNER
Definition: winuser.h:766
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define WM_ERASEBKGND
Definition: winuser.h:1625
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:1621
#define SWP_NOACTIVATE
Definition: winuser.h:1242
#define DT_NOPREFIX
Definition: winuser.h:537
#define GetWindowLongPtrW
Definition: winuser.h:4829
HWND WINAPI CreateWindowExA(_In_ DWORD dwExStyle, _In_opt_ LPCSTR lpClassName, _In_opt_ LPCSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define DT_CENTER
Definition: winuser.h:527
#define HTCAPTION
Definition: winuser.h:2476
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_CREATE
Definition: winuser.h:1608
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define DT_SINGLELINE
Definition: winuser.h:540
BOOL WINAPI ValidateRect(_In_opt_ HWND, _In_opt_ LPCRECT)
#define COLOR_ACTIVECAPTION
Definition: winuser.h:915
#define IDC_ARROW
Definition: winuser.h:687
#define WM_NCHITTEST
Definition: winuser.h:1686
#define GetWindowLongPtrA
Definition: winuser.h:4828
#define SPI_GETICONTITLELOGFONT
Definition: winuser.h:1380
int WINAPI MapWindowPoints(_In_opt_ HWND hWndFrom, _In_opt_ HWND hWndTo, _Inout_updates_(cPoints) LPPOINT lpPoints, _In_ UINT cPoints)
#define GWLP_HINSTANCE
Definition: winuser.h:856
#define WM_NCLBUTTONDBLCLK
Definition: winuser.h:1694
#define WM_ACTIVATE
Definition: winuser.h:1612
#define WM_SHOWWINDOW
Definition: winuser.h:1628
#define WM_NCMOUSEMOVE
Definition: winuser.h:1691
#define SM_CYBORDER
Definition: winuser.h:965
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define SM_CYICON
Definition: winuser.h:973
HWND WINAPI SetActiveWindow(_In_ HWND)
#define SM_CXBORDER
Definition: winuser.h:964
#define DT_WORDBREAK
Definition: winuser.h:544
#define SPI_GETICONTITLEWRAP
Definition: winuser.h:1374
HDC WINAPI GetDC(_In_opt_ HWND)
BOOL WINAPI IsWindowEnabled(_In_ HWND)
HWND WINAPI GetParent(_In_ HWND)
#define GetClassLongPtrW
Definition: winuser.h:4564
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 SetWindowLongPtrW
Definition: winuser.h:5346
#define GWL_STYLE
Definition: winuser.h:852
#define COLOR_CAPTIONTEXT
Definition: winuser.h:922
#define SM_CXICON
Definition: winuser.h:972
#define GCLP_HBRBACKGROUND
Definition: winuser.h:672
int WINAPI GetSystemMetrics(_In_ int)
#define SM_CXICONSPACING
Definition: winuser.h:1001
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180