2 * Non-client area window functions
4 * Copyright 1994 Alexandre Julliard
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
21 #include "user_private.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(nonclient
);
27 #define SC_ABOUTWINE (SC_SCREENSAVE+1)
30 static void adjust_window_rect( RECT
*rect
, DWORD style
, BOOL menu
, DWORD exStyle
, NONCLIENTMETRICSW
*ncm
)
34 if ((exStyle
& (WS_EX_STATICEDGE
|WS_EX_DLGMODALFRAME
)) == WS_EX_STATICEDGE
)
35 adjust
= 1; /* for the outer frame always present */
36 else if ((exStyle
& WS_EX_DLGMODALFRAME
) || (style
& (WS_THICKFRAME
|WS_DLGFRAME
)))
37 adjust
= 2; /* outer */
39 if (style
& WS_THICKFRAME
)
40 adjust
+= ncm
->iBorderWidth
+ ncm
->iPaddedBorderWidth
; /* The resize border */
42 if ((style
& (WS_BORDER
|WS_DLGFRAME
)) || (exStyle
& WS_EX_DLGMODALFRAME
))
43 adjust
++; /* The other border */
45 InflateRect (rect
, adjust
, adjust
);
47 if ((style
& WS_CAPTION
) == WS_CAPTION
)
49 if (exStyle
& WS_EX_TOOLWINDOW
)
50 rect
->top
-= ncm
->iSmCaptionHeight
+ 1;
52 rect
->top
-= ncm
->iCaptionHeight
+ 1;
54 if (menu
) rect
->top
-= ncm
->iMenuHeight
+ 1;
56 if (exStyle
& WS_EX_CLIENTEDGE
)
57 InflateRect(rect
, GetSystemMetrics(SM_CXEDGE
), GetSystemMetrics(SM_CYEDGE
));
61 /***********************************************************************
62 * DrawCaption (USER32.@) Draws a caption bar
64 BOOL WINAPI
DrawCaption( HWND hwnd
, HDC hdc
, const RECT
*rect
, UINT flags
)
66 return NtUserDrawCaptionTemp( hwnd
, hdc
, rect
, 0, 0, NULL
, flags
& 0x103f );
70 /***********************************************************************
71 * DrawCaptionTempA (USER32.@)
73 BOOL WINAPI
DrawCaptionTempA (HWND hwnd
, HDC hdc
, const RECT
*rect
, HFONT hFont
,
74 HICON hIcon
, LPCSTR str
, UINT uFlags
)
80 if (!(uFlags
& DC_TEXT
) || !str
)
81 return NtUserDrawCaptionTemp( hwnd
, hdc
, rect
, hFont
, hIcon
, NULL
, uFlags
);
83 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
84 if ((strW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
86 MultiByteToWideChar( CP_ACP
, 0, str
, -1, strW
, len
);
87 ret
= NtUserDrawCaptionTemp( hwnd
, hdc
, rect
, hFont
, hIcon
, strW
, uFlags
);
88 HeapFree( GetProcessHeap (), 0, strW
);
94 /***********************************************************************
95 * AdjustWindowRect (USER32.@)
97 BOOL WINAPI DECLSPEC_HOTPATCH
AdjustWindowRect( LPRECT rect
, DWORD style
, BOOL menu
)
99 return AdjustWindowRectEx( rect
, style
, menu
, 0 );
103 /***********************************************************************
104 * AdjustWindowRectEx (USER32.@)
106 BOOL WINAPI DECLSPEC_HOTPATCH
AdjustWindowRectEx( LPRECT rect
, DWORD style
, BOOL menu
, DWORD exStyle
)
108 NONCLIENTMETRICSW ncm
;
110 TRACE("(%s) %08lx %d %08lx\n", wine_dbgstr_rect(rect
), style
, menu
, exStyle
);
112 ncm
.cbSize
= sizeof(ncm
);
113 SystemParametersInfoW( SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0 );
115 adjust_window_rect( rect
, style
, menu
, exStyle
, &ncm
);
120 /***********************************************************************
121 * AdjustWindowRectExForDpi (USER32.@)
123 BOOL WINAPI DECLSPEC_HOTPATCH
AdjustWindowRectExForDpi( LPRECT rect
, DWORD style
, BOOL menu
,
124 DWORD exStyle
, UINT dpi
)
126 NONCLIENTMETRICSW ncm
;
128 TRACE("(%s) %08lx %d %08lx %u\n", wine_dbgstr_rect(rect
), style
, menu
, exStyle
, dpi
);
130 ncm
.cbSize
= sizeof(ncm
);
131 SystemParametersInfoForDpi( SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0, dpi
);
133 adjust_window_rect( rect
, style
, menu
, exStyle
, &ncm
);
139 /***********************************************************************
140 * NC_HandleSysCommand
142 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
144 LRESULT
NC_HandleSysCommand( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
146 if (!NtUserMessageCall( hwnd
, WM_SYSCOMMAND
, wParam
, lParam
, 0, NtUserDefWindowProc
, FALSE
))
149 switch (wParam
& 0xfff0)
152 WinExec( "taskman.exe", SW_SHOWNORMAL
);
156 if (wParam
== SC_ABOUTWINE
)
158 HMODULE hmodule
= LoadLibraryA( "shell32.dll" );
161 BOOL (WINAPI
*aboutproc
)(HWND
, LPCSTR
, LPCSTR
, HICON
);
162 extern const char * CDECL
wine_get_version(void);
165 sprintf( app
, "Wine %s", wine_get_version() );
166 aboutproc
= (void *)GetProcAddress( hmodule
, "ShellAboutA" );
167 if (aboutproc
) aboutproc( hwnd
, app
, NULL
, 0 );
168 FreeLibrary( hmodule
);
176 static void user_draw_mdi_button( HDC hdc
, enum NONCLIENT_BUTTON_TYPE type
, RECT rect
, BOOL down
, BOOL grayed
)
182 case MENU_CLOSE_BUTTON
:
183 flags
= DFCS_CAPTIONCLOSE
;
185 case MENU_MIN_BUTTON
:
186 flags
= DFCS_CAPTIONMIN
;
188 case MENU_MAX_BUTTON
:
189 flags
= DFCS_CAPTIONMAX
;
191 case MENU_RESTORE_BUTTON
:
192 flags
= DFCS_CAPTIONRESTORE
;
194 case MENU_HELP_BUTTON
:
195 flags
= DFCS_CAPTIONHELP
;
202 flags
|= DFCS_PUSHED
;
204 flags
|= DFCS_INACTIVE
;
206 DrawFrameControl( hdc
, &rect
, DFC_CAPTION
, flags
);
209 void WINAPI
USER_NonClientButtonDraw( HWND hwnd
, HDC hdc
, enum NONCLIENT_BUTTON_TYPE type
,
210 RECT rect
, BOOL down
, BOOL grayed
)
214 case MENU_CLOSE_BUTTON
:
215 case MENU_MIN_BUTTON
:
216 case MENU_MAX_BUTTON
:
217 case MENU_RESTORE_BUTTON
:
218 case MENU_HELP_BUTTON
:
219 user_draw_mdi_button( hdc
, type
, rect
, down
, grayed
);