LOTs of changes, a few bug fixes, some code cleanup.

svn path=/trunk/; revision=4285
This commit is contained in:
Richard Campbell 2003-03-11 00:18:54 +00:00
parent 5a4eded72e
commit aee47209b1

View file

@ -1,4 +1,4 @@
/* $Id: defwnd.c,v 1.29 2003/03/07 04:50:42 rcampbell Exp $ /* $Id: defwnd.c,v 1.30 2003/03/11 00:18:54 rcampbell Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS user32.dll * PROJECT: ReactOS user32.dll
@ -20,14 +20,19 @@
/* GLOBALS *******************************************************************/ /* GLOBALS *******************************************************************/
static HBITMAP hbitmapClose; /* TODO: widgets will be cached here.
static HBITMAP hbitmapMinimize; static HBITMAP hbClose;
static HBITMAP hbitmapMinimizeD; static HBITMAP hbCloseD;
static HBITMAP hbitmapMaximize; static HBITMAP hbMinimize;
static HBITMAP hbitmapMaximizeD; static HBITMAP hbMinimizeD;
static HBITMAP hbitmapRestore; static HBITMAP hbRestore;
static HBITMAP hbitmapRestoreD; static HBITMAP hbRestoreD;
static HBITMAP hbMaximize;
static HBITMAP hbScrUp;
static HBITMAP hbScrDwn;
static HBITMAP hbScrLeft;
static HBITMAP hbScrRight;
*/
static COLORREF SysColours[] = static COLORREF SysColours[] =
{ {
RGB(224, 224, 224) /* COLOR_SCROLLBAR */, RGB(224, 224, 224) /* COLOR_SCROLLBAR */,
@ -65,6 +70,24 @@ static ATOM AtomInternalPos;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
BOOL IsMaxBoxActive(HWND hWnd)
{
ULONG uStyle = GetWindowLong(hWnd, GWL_STYLE);
return (uStyle & WS_MAXIMIZEBOX);
}
BOOL IsCloseBoxActive(HWND hWnd)
{
ULONG uStyle = GetWindowLong(hWnd, GWL_STYLE);
return (uStyle & WS_SYSMENU);
}
BOOL IsMinBoxActive(HWND hWnd)
{
ULONG uStyle = GetWindowLong(hWnd, GWL_STYLE);
return (uStyle & WS_MINIMIZEBOX);
}
VOID VOID
UserSetupInternalPos(VOID) UserSetupInternalPos(VOID)
{ {
@ -217,77 +240,78 @@ void UserDrawSysMenuButton( HWND hWnd, HDC hDC, BOOL down )
load default (OIC_SAMPLE I believe, not sure */ load default (OIC_SAMPLE I believe, not sure */
} }
static void UserDrawCloseButton ( HWND hWnd, HDC hDC, BOOL down ) /* FIXME: Cache bitmaps, then just bitblt instead of calling DFC() (and
wasting precious CPU cycles) every time */
static void UserDrawCloseButton ( HWND hWnd, HDC hDC, BOOL bDown )
{ {
/* ported from wine code */
RECT rect; RECT rect;
BOOL bInactive = FALSE; BOOL bToolWindow = GetWindowLongA( hWnd, GWL_EXSTYLE ) & WS_EX_TOOLWINDOW;
INT iBmpWidth = (bToolWindow ? GetSystemMetrics(SM_CXSMSIZE) :
GetSystemMetrics(SM_CXSIZE)) - 2;
INT iBmpHeight = (bToolWindow ? GetSystemMetrics(SM_CYSMSIZE) :
GetSystemMetrics(SM_CYSIZE)) - 4;
UserGetInsideRectNC( hWnd, &rect ); UserGetInsideRectNC( hWnd, &rect );
if (GetWindowLongA( hWnd, GWL_EXSTYLE ) & WS_EX_TOOLWINDOW) SetRect(&rect,
{ rect.right - iBmpWidth,
INT iBmpHeight = 11; /* Windows does not use SM_CXSMSIZE and SM_CYSMSIZE */ rect.top + 1,
INT iBmpWidth = 11; /* it uses 11x11 for the close button in tool window */ rect.right,
INT iCaptionHeight = GetSystemMetrics(SM_CYSMCAPTION); rect.top + iBmpHeight + 1 );
rect.top = rect.top + (iCaptionHeight - 1 - iBmpHeight) / 2;
rect.left = rect.right - (iCaptionHeight + 1 + iBmpWidth) / 2;
rect.bottom = rect.top + iBmpHeight;
rect.right = rect.left + iBmpWidth;
}
else
{
rect.top++;
rect.right--;
/* Standard close/min/max button sizes appear to be 16x14, though
these change with the caption size, I'll fix this soon */
rect.left = rect.right - 16;
rect.bottom = rect.top + 14;
}
DrawFrameControl( hDC, &rect, DFC_CAPTION, DrawFrameControl( hDC, &rect, DFC_CAPTION,
(DFCS_CAPTIONCLOSE | (DFCS_CAPTIONCLOSE |
(down ? DFCS_PUSHED : 0) | (bDown ? DFCS_PUSHED : 0) |
(bInactive ? DFCS_INACTIVE : 0)) ); (IsCloseBoxActive(hWnd) ? 0 : DFCS_INACTIVE)) );
} }
static void UserDrawMaxButton( HWND hWnd, HDC hDC, BOOL down ) static void UserDrawMaxButton( HWND hWnd, HDC hDC, BOOL bDown )
{ {
RECT rect; RECT rect;
UINT flags = IsZoomed(hWnd) ? DFCS_CAPTIONRESTORE : DFCS_CAPTIONMAX; INT iBmpWidth = GetSystemMetrics(SM_CXSIZE) - 2;
INT iBmpHeight = GetSystemMetrics(SM_CYSIZE) - 4;
if (!IsMinBoxActive(hWnd) && !IsMaxBoxActive(hWnd))
return;
if ((GetWindowLongA( hWnd, GWL_EXSTYLE ) & WS_EX_TOOLWINDOW) == TRUE)
return; /* ToolWindows don't have min/max buttons */
UserGetInsideRectNC(hWnd, &rect ); UserGetInsideRectNC(hWnd, &rect );
rect.top++;
rect.right--;
rect.left = rect.right - (GetSystemMetrics(SM_CXSIZE) - 1) * 2;
rect.right = rect.left + (GetSystemMetrics(SM_CXSIZE) - 2);
rect.bottom = rect.top + GetSystemMetrics(SM_CYSIZE) - 4;
if (down) flags |= DFCS_PUSHED; SetRect(&rect,
DrawFrameControl( hDC, &rect, DFC_CAPTION, flags ); rect.right - (iBmpWidth * 2) - 2,
rect.top + 1,
(rect.right - iBmpWidth) - 2,
rect.top + iBmpHeight + 1 );
DrawFrameControl( hDC, &rect, DFC_CAPTION,
(IsZoomed(hWnd) ? DFCS_CAPTIONMAX : DFCS_CAPTIONRESTORE) |
(bDown ? DFCS_PUSHED : 0) |
(IsMaxBoxActive(hWnd) ? 0 : DFCS_INACTIVE) );
} }
static void UserDrawMinButton( HWND hWnd, HDC hDC, BOOL down) static void UserDrawMinButton( HWND hWnd, HDC hDC, BOOL bDown )
{ {
RECT rect; RECT rect;
UINT flags = DFCS_CAPTIONMIN; INT iBmpWidth = GetSystemMetrics(SM_CXSIZE) - 2;
INT iBmpHeight = GetSystemMetrics(SM_CYSIZE) - 4;
if (!IsMinBoxActive(hWnd) && !IsMaxBoxActive(hWnd))
return;
if ((GetWindowLongA( hWnd, GWL_EXSTYLE ) & WS_EX_TOOLWINDOW) == TRUE)
return; /* ToolWindows don't have min/max buttons */
BOOL bInactive = FALSE;
UserGetInsideRectNC(hWnd, &rect ); UserGetInsideRectNC(hWnd, &rect );
rect.top++;
rect.right--;
rect.left = rect.right - ((GetSystemMetrics(SM_CXSIZE)) * 3) + 4;
rect.right = rect.left + (GetSystemMetrics(SM_CXSIZE) - 2);
rect.bottom = rect.top + GetSystemMetrics(SM_CYSIZE) - 4;
if (down) flags |= DFCS_PUSHED;
if (bInactive) flags |= DFCS_INACTIVE;
DrawFrameControl( hDC, &rect, DFC_CAPTION, flags );
SetRect(&rect,
rect.right - (iBmpWidth * 3) - 2,
rect.top + 1,
(rect.right - iBmpWidth * 2) - 2,
rect.top + iBmpHeight + 1 );
DrawFrameControl( hDC, &rect, DFC_CAPTION,
(IsZoomed(hWnd) ? DFCS_CAPTIONMAX : DFCS_CAPTIONRESTORE) |
(bDown ? DFCS_PUSHED : 0) |
(IsMinBoxActive(hWnd) ? 0 : DFCS_INACTIVE) );
} }
static void UserDrawCaptionNC( HDC hDC, RECT *rect, HWND hWnd, static void UserDrawCaptionNC( HDC hDC, RECT *rect, HWND hWnd,
@ -296,25 +320,7 @@ static void UserDrawCaptionNC( HDC hDC, RECT *rect, HWND hWnd,
RECT r = *rect; RECT r = *rect;
char buffer[256]; char buffer[256];
if (!hbitmapClose) /* Implement and Use DrawCaption() */
{
hbitmapClose = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_CLOSE));
hbitmapMinimize = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_REDUCE) );
hbitmapMinimizeD = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_REDUCED) );
hbitmapMaximize = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_ZOOM) );
hbitmapMaximizeD = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_ZOOMD) );
hbitmapRestore = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_RESTORE) );
hbitmapRestoreD = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_RESTORED) );
}
if (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_DLGMODALFRAME)
{
/* Unimplemented */
}
/* Fill the caption with COLOR_(IN)ACTIVECAPTION.
In the future this will be GradientFill() */
SelectObject( hDC, GetSysColorBrush(active ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION) ); SelectObject( hDC, GetSysColorBrush(active ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION) );
PatBlt(hDC,rect->left + 3, rect->top + 3, rect->right - 6, rect->bottom - 1, PATCOPY ); PatBlt(hDC,rect->left + 3, rect->top + 3, rect->right - 6, rect->bottom - 1, PATCOPY );
@ -323,19 +329,10 @@ static void UserDrawCaptionNC( HDC hDC, RECT *rect, HWND hWnd,
UserDrawSysMenuButton( hWnd, hDC, FALSE); UserDrawSysMenuButton( hWnd, hDC, FALSE);
r.left += GetSystemMetrics(SM_CXSIZE) + 1; r.left += GetSystemMetrics(SM_CXSIZE) + 1;
UserDrawCloseButton( hWnd, hDC, FALSE); UserDrawCloseButton( hWnd, hDC, FALSE);
}
if (style & WS_MAXIMIZEBOX)
{
UserDrawMaxButton( hWnd, hDC, FALSE );
r.right -= GetSystemMetrics(SM_CXSMSIZE) + 1; r.right -= GetSystemMetrics(SM_CXSMSIZE) + 1;
}
if (style & WS_MINIMIZEBOX)
{
UserDrawMinButton(hWnd, hDC, FALSE); UserDrawMinButton(hWnd, hDC, FALSE);
r.right -= GetSystemMetrics(SM_CXSMSIZE) + 1; UserDrawMaxButton(hWnd, hDC, FALSE);
} }
if (GetWindowTextA( hWnd, buffer, sizeof(buffer) )) if (GetWindowTextA( hWnd, buffer, sizeof(buffer) ))
{ {
NONCLIENTMETRICS nclm; NONCLIENTMETRICS nclm;
@ -458,9 +455,9 @@ DefWndHitTestNC(HWND hWnd, POINT Point)
ULONG ExStyle = GetWindowLong(hWnd, GWL_EXSTYLE); ULONG ExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
GetWindowRect(hWnd, &WindowRect); GetWindowRect(hWnd, &WindowRect);
if (!PtInRect(&WindowRect, Point)) if (!PtInRect(&WindowRect, Point))
{ {
return(HTNOWHERE); return(HTNOWHERE);
} }
if (Style & WS_MINIMIZE) if (Style & WS_MINIMIZE)
@ -561,7 +558,7 @@ DefWndHitTestNC(HWND hWnd, POINT Point)
return(HTCLOSE); return(HTCLOSE);
} }
if (Style & WS_MAXIMIZEBOX) if (Style & WS_MAXIMIZEBOX || Style & WS_MINIMIZEBOX)
{ {
WindowRect.right -= GetSystemMetrics(SM_CXSMSIZE) + 1; WindowRect.right -= GetSystemMetrics(SM_CXSMSIZE) + 1;
} }
@ -624,101 +621,9 @@ DefWndHitTestNC(HWND hWnd, POINT Point)
return(HTNOWHERE); return(HTNOWHERE);
} }
VOID
DefWndTrackMinMaxBox(HWND hWnd, WPARAM wParam)
{
HDC hDC = GetWindowDC(hWnd);
BOOL Pressed = TRUE;
MSG Msg;
SetCapture(hWnd);
if (wParam == HTMINBUTTON)
{
UserDrawMinButton(hWnd, hDC, TRUE);
}
else
{
UserDrawMaxButton(hWnd, hDC, TRUE);
}
for(;;)
{
BOOL OldState = Pressed;
GetMessageA(hWnd, &Msg, 0, 0);
if (Msg.message == WM_LBUTTONUP)
{
break;
}
if (Msg.message != WM_MOUSEMOVE)
{
continue;
}
Pressed = DefWndHitTestNC(hWnd, Msg.pt) == (LRESULT) wParam;
if (Pressed != OldState)
{
if (wParam == HTMINBUTTON)
{
UserDrawMinButton(hWnd, hDC, Pressed);
}
else
{
UserDrawMaxButton(hWnd, hDC, Pressed);
}
}
}
if (Pressed)
{
if (wParam == HTMINBUTTON)
{
UserDrawMinButton(hWnd, hDC, FALSE);
}
else
{
UserDrawMaxButton(hWnd, hDC, FALSE);
}
}
ReleaseCapture();
ReleaseDC(hWnd, hDC);
if (!Pressed)
{
return;
}
if (wParam == HTMINBUTTON)
{
SendMessageA(hWnd, WM_SYSCOMMAND, SC_MINIMIZE,
MAKELONG(Msg.pt.x, Msg.pt.y));
}
else
{
SendMessageA(hWnd, WM_SYSCOMMAND,
IsZoomed(hWnd) ? SC_RESTORE : SC_MAXIMIZE,
MAKELONG(Msg.pt.x, Msg.pt.y));
}
}
VOID VOID
DefWndDrawSysButton(HWND hWnd, HDC hDC, BOOL Down) DefWndDrawSysButton(HWND hWnd, HDC hDC, BOOL Down)
{ {
RECT Rect;
HDC hDCMem;
HBITMAP hSavedBitmap;
UserGetInsideRectNC(hWnd, &Rect);
hDCMem = CreateCompatibleDC(hDC);
hSavedBitmap = SelectObject(hDCMem, hbitmapClose);
BitBlt(hDC, Rect.left, Rect.top, GetSystemMetrics(SM_CXSIZE),
GetSystemMetrics(SM_CYSIZE), hDCMem,
(GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) ?
GetSystemMetrics(SM_CXSIZE): 0, 0, Down ? NOTSRCCOPY : SRCCOPY);
SelectObject(hDCMem, hSavedBitmap);
DeleteDC(hDCMem);
} }
LRESULT LRESULT
@ -750,28 +655,36 @@ DefWndHandleLButtonDownNC(HWND hWnd, WPARAM wParam, LPARAM lParam)
} }
break; break;
} }
case HTMENU: case HTMENU:
{
SendMessageA(hWnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam); SendMessageA(hWnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam);
break; break;
}
case HTHSCROLL: case HTHSCROLL:
{
SendMessageA(hWnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam); SendMessageA(hWnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam);
break; break;
}
case HTVSCROLL: case HTVSCROLL:
{
SendMessageA(hWnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam); SendMessageA(hWnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam);
break; break;
}
case HTMINBUTTON: case HTMINBUTTON:
UserDrawMinButton(hWnd, GetWindowDC(hWnd),TRUE); {
UserDrawMinButton(hWnd, GetWindowDC(hWnd), IsMinBoxActive(hWnd) );
break; break;
}
case HTMAXBUTTON: case HTMAXBUTTON:
UserDrawMaxButton(hWnd,GetWindowDC(hWnd),TRUE); {
UserDrawMaxButton(hWnd,GetWindowDC(hWnd), IsMaxBoxActive(hWnd) );
break; break;
}
case HTCLOSE: case HTCLOSE:
{
UserDrawCloseButton(hWnd,GetWindowDC(hWnd),TRUE); UserDrawCloseButton(hWnd,GetWindowDC(hWnd),TRUE);
break; break;
}
case HTLEFT: case HTLEFT:
case HTRIGHT: case HTRIGHT:
case HTTOP: case HTTOP:
@ -780,17 +693,17 @@ DefWndHandleLButtonDownNC(HWND hWnd, WPARAM wParam, LPARAM lParam)
case HTTOPRIGHT: case HTTOPRIGHT:
case HTBOTTOMLEFT: case HTBOTTOMLEFT:
case HTBOTTOMRIGHT: case HTBOTTOMRIGHT:
{
SendMessageA(hWnd, WM_SYSCOMMAND, SC_SIZE + wParam - 2, lParam); SendMessageA(hWnd, WM_SYSCOMMAND, SC_SIZE + wParam - 2, lParam);
break; break;
} }
}
return(0); return(0);
} }
LRESULT LRESULT
DefWndHandleLButtonDblClkNC(HWND hWnd, WPARAM wParam, LPARAM lParam) DefWndHandleLButtonDblClkNC(HWND hWnd, WPARAM wParam, LPARAM lParam)
{ {
/* FIXME: Implement this. */
return(0); return(0);
} }
@ -803,14 +716,22 @@ DefWndHandleLButtonUpNC(HWND hWnd, WPARAM wParam, LPARAM lParam)
switch (wParam) switch (wParam)
{ {
case HTMINBUTTON: case HTMINBUTTON:
break; {
case HTMAXBUTTON: SendMessageA(hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
break;
case HTCLOSE:
SendMessageA(hWnd, WM_CLOSE, 0, 0);
break; break;
} }
case HTMAXBUTTON:
{
SendMessageA(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
break;
}
case HTCLOSE:
{
SendMessageA(hWnd, WM_CLOSE, 0, 0);
SendMessageA(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
break;
}
}
return(0); return(0);
} }
@ -1271,13 +1192,13 @@ User32DefWindowProc(HWND hWnd,
{ {
return(0); return(0);
} }
/* FIXME: Check for a popup window. */ /* FIXME: Not done correctly */
if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_VISIBLE && !wParam) || if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_VISIBLE && !wParam) ||
(!(GetWindowLongW(hWnd, GWL_STYLE) & WS_VISIBLE) && wParam)) (!(GetWindowLongW(hWnd, GWL_STYLE) & WS_VISIBLE) && wParam))
{ {
return(0); return(0);
} }
ShowWindow(hWnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE); ShowWindow(hWnd, wParam ? SW_SHOWNA : SW_HIDE);
break; break;
} }
@ -1375,6 +1296,7 @@ User32DefWindowProc(HWND hWnd,
return 0; return 0;
} }
LRESULT STDCALL LRESULT STDCALL
DefWindowProcA(HWND hWnd, DefWindowProcA(HWND hWnd,
UINT Msg, UINT Msg,
@ -1466,7 +1388,6 @@ DefWindowProcA(HWND hWnd,
{ {
GlobalDeleteAtom((ATOM)(ULONG)WindowTextAtom); GlobalDeleteAtom((ATOM)(ULONG)WindowTextAtom);
} }
/* FIXME: Destroy scroll bars here as well. */
return(0); return(0);
} }
@ -1571,7 +1492,7 @@ DefWindowProcW(HWND hWnd,
{ {
GlobalDeleteAtom((ATOM)(DWORD)WindowTextAtom); GlobalDeleteAtom((ATOM)(DWORD)WindowTextAtom);
} }
/* FIXME: Destroy scroll bars here as well. */
return(0); return(0);
} }