ReactOS  0.4.15-dev-1206-g731eddf
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  */
122 static 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 
160  GetClientRect( hwnd, &rect );
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;
199  hIconTitleFont = CreateFontIndirectA( &logFont );
200  }
201  return (hIconTitleFont ? 0 : -1);
202  case WM_NCHITTEST:
203  return HTCAPTION;
204  case WM_NCMOUSEMOVE:
205  case WM_NCLBUTTONDBLCLK:
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 ) )
221  ValidateRect( hWnd, NULL );
222  return 1;
223  }
224  return DefWindowProcW( hWnd, msg, wParam, lParam );
225 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
int WINAPI GetObjectA(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
#define WS_DISABLED
Definition: pedump.c:621
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define SM_CXICONSPACING
Definition: winuser.h:991
GLint level
Definition: gl.h:1546
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
int WINAPI MapWindowPoints(_In_opt_ HWND hWndFrom, _In_opt_ HWND hWndTo, _Inout_updates_(cPoints) LPPOINT lpPoints, _In_ UINT cPoints)
static BOOL ICONTITLE_Paint(HWND hwnd, HWND owner, HDC hDC, BOOL bActive)
Definition: icontitle.c:122
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define RGB(r, g, b)
Definition: precomp.h:62
HDC WINAPI GetDC(_In_opt_ HWND)
HFONT WINAPI CreateFontIndirectA(_In_ const LOGFONTA *)
#define TRUE
Definition: types.h:120
#define pt(x, y)
Definition: drawing.c:79
#define WC_ICONTITLE
Definition: undocuser.h:13
#define DT_WORDBREAK
Definition: winuser.h:544
static HDC
Definition: imagelist.c:92
HWND hWnd
Definition: settings.c:17
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
#define WM_SHOWWINDOW
Definition: winuser.h:1610
#define COLOR_CAPTIONTEXT
Definition: winuser.h:912
#define GetRValue(quad)
Definition: precomp.h:64
GLuint buffer
Definition: glext.h:5915
#define WHITE_BRUSH
Definition: wingdi.h:901
#define WM_NCHITTEST
Definition: winuser.h:1668
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
#define GetWindowLongPtrW
Definition: winuser.h:4804
#define DT_NOPREFIX
Definition: winuser.h:537
BOOL WINAPI DPtoLP(_In_ HDC hdc, _Inout_updates_(c) LPPOINT lppt, _In_ int c)
int32_t INT
Definition: typedefs.h:58
DWORD WINAPI GetSysColor(_In_ int)
& rect
Definition: startmenu.cpp:1413
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static BOOL ICONTITLE_SetTitlePos(HWND hwnd, HWND owner)
Definition: icontitle.c:71
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1034
#define FALSE
Definition: types.h:117
HWND WINAPI SetActiveWindow(_In_ HWND)
#define DT_CALCRECT
Definition: winuser.h:526
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define SM_CXICON
Definition: winuser.h:962
#define TRANSPARENT
Definition: wingdi.h:949
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:581
const WCHAR * str
#define GCLP_HBRBACKGROUND
Definition: winuser.h:667
BOOL WINAPI SystemParametersInfoA(_In_ UINT, _In_ UINT, _Inout_opt_ PVOID, _In_ UINT)
smooth NULL
Definition: ftsmooth.c:416
#define COLOR_ACTIVECAPTION
Definition: winuser.h:905
LONG_PTR LPARAM
Definition: windef.h:208
#define GetBValue(quad)
Definition: precomp.h:66
BOOL WINAPI IsWindowEnabled(_In_ HWND)
const char * LPCSTR
Definition: xmlstorage.h:183
#define GetGValue(quad)
Definition: precomp.h:65
#define BLACK_BRUSH
Definition: wingdi.h:895
#define GetWindowLongPtrA
Definition: winuser.h:4803
#define WS_CAPTION
Definition: pedump.c:624
LRESULT WINAPI IconTitleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: icontitle.c:184
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define SWP_NOACTIVATE
Definition: winuser.h:1227
DWORD COLORREF
Definition: windef.h:300
#define SPI_GETICONTITLEWRAP
Definition: winuser.h:1356
#define WM_CLOSE
Definition: winuser.h:1603
COLORREF lbColor
Definition: wingdi.h:1747
#define WINAPI
Definition: msvc.h:6
BOOL WINAPI ValidateRect(_In_opt_ HWND, _In_opt_ LPCRECT)
int WINAPI GetSystemMetrics(_In_ int)
HANDLE HINSTANCE
Definition: typedefs.h:77
static HFONT hIconTitleFont
Definition: icontitle.c:24
#define SM_CYBORDER
Definition: winuser.h:955
#define SM_CYICON
Definition: winuser.h:963
HWND WINAPI GetWindow(_In_ HWND, _In_ UINT)
#define SM_CXBORDER
Definition: winuser.h:954
#define WM_ISACTIVEICON
Definition: undocuser.h:33
#define HTCAPTION
Definition: winuser.h:2451
#define GWL_STYLE
Definition: winuser.h:846
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:888
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define DT_SINGLELINE
Definition: winuser.h:540
HWND WINAPI GetParent(_In_ HWND)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
#define WS_BORDER
Definition: pedump.c:625
#define WM_ACTIVATE
Definition: winuser.h:1594
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1412
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static HINSTANCE instance
Definition: main.c:40
unsigned int UINT
Definition: ndis.h:50
#define GW_OWNER
Definition: winuser.h:761
#define SPI_GETICONTITLELOGFONT
Definition: winuser.h:1362
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
_Out_opt_ int * cx
Definition: commctrl.h:581
#define GWLP_HINSTANCE
Definition: winuser.h:850
#define WM_CREATE
Definition: winuser.h:1590
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)
HWND ICONTITLE_Create(HWND owner)
Definition: icontitle.c:46
#define DT_CENTER
Definition: winuser.h:527
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SetWindowLongPtrW
Definition: winuser.h:5321
#define WM_ERASEBKGND
Definition: winuser.h:1607
LONG_PTR LRESULT
Definition: windef.h:209
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
Arabic default style
Definition: afstyles.h:93
HBRUSH WINAPI GetSysColorBrush(_In_ int)
LPARAM lParam
Definition: combotst.c:139
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
#define GetClassLongPtrW
Definition: winuser.h:4539
#define WM_NCMOUSEMOVE
Definition: winuser.h:1673
const struct builtin_class_descr ICONTITLE_builtin_class
Definition: icontitle.c:29
#define WM_NCLBUTTONDBLCLK
Definition: winuser.h:1676
INT WINAPI DrawTextW(HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags)
Definition: defwnd.c:17
static BOOL bMultiLineTitle
Definition: icontitle.c:23